<commit_before>import math
import types
import system_logger
import unicode
import tables
import rect_packer
import nimx.resource
import nimx.timer

when defined(js):
    import dom
    import private.js_font_metrics
else:
    import ttf
    import os
    import write_image_impl

import private.edtaa3func # From ttf library
import private.simple_table

import opengl
import portable_gl

const charChunkLength = 200

type BackedCharComponent = enum
    compX = 0
    compY
    compAdvance
    compTexX
    compTexY
    compWidth
    compHeight

type Baseline* = enum
    bTop
    bAlphabetic
    bBottom

const numberOfComponents = ord(high(BackedCharComponent)) + 1
type BakedCharInfo = array[numberOfComponents * charChunkLength, int16]

template charOff(i: int): int = i * numberOfComponents
template charOffComp(bc: var BakedCharInfo, charOffset: int, comp: BackedCharComponent): var int16 =
    bc[charOffset + ord(comp)]

type CharInfo = ref object
    bakedChars: BakedCharInfo
    tempBitmap: seq[byte]
    texture: TextureRef
    texWidth, texHeight: uint16
    dfDoneForGlyph: seq[bool]

when defined(js):
    type FastString = cstring
else:
    type FastString = string


template charHeightForSize(s: float): float =
    if s > 128: 128
    else: 64

template scaleForSize(s: float): float = s / charHeightForSize(s)

type FontImpl = ref object
    chars: SimpleTable[int32, CharInfo]
    ascent: float32
    descent: float32

var fontCache : SimpleTable[FastString, FontImpl]

proc cachedImplForFont(face: string, sz: float): FontImpl =
    if fontCache.isNil:
        fontCache = newSimpleTable(FastString, FontImpl)
    var key : FastString = face & "_" & $charHeightForSize(sz).int
    if fontCache.hasKey(key):
        result = fontCache[key]
    else:
        result.new()
        result.chars = newSimpleTable(int32, CharInfo)
        fontCache[key] = result

type Font* = ref object
    impl: FontImpl
    mSize: float
    isHorizontal*: bool
    scale*: float
    filePath: string<commit_msg>Disable 128 glyph size again<commit_after>import math
import types
import system_logger
import unicode
import tables
import rect_packer
import nimx.resource
import nimx.timer

when defined(js):
    import dom
    import private.js_font_metrics
else:
    import ttf
    import os
    import write_image_impl

import private.edtaa3func # From ttf library
import private.simple_table

import opengl
import portable_gl

const charChunkLength = 200

type BackedCharComponent = enum
    compX = 0
    compY
    compAdvance
    compTexX
    compTexY
    compWidth
    compHeight

type Baseline* = enum
    bTop
    bAlphabetic
    bBottom

const numberOfComponents = ord(high(BackedCharComponent)) + 1
type BakedCharInfo = array[numberOfComponents * charChunkLength, int16]

template charOff(i: int): int = i * numberOfComponents
template charOffComp(bc: var BakedCharInfo, charOffset: int, comp: BackedCharComponent): var int16 =
    bc[charOffset + ord(comp)]

type CharInfo = ref object
    bakedChars: BakedCharInfo
    tempBitmap: seq[byte]
    texture: TextureRef
    texWidth, texHeight: uint16
    dfDoneForGlyph: seq[bool]

when defined(js):
    type FastString = cstring
else:
    type FastString = string


template charHeightForSize(s: float): float =
    #if s > 128: 128
    #else: 64
    64 # TODO: Think some more about df generation because its still slow for
       # 128 glyph size

template scaleForSize(s: float): float = s / charHeightForSize(s)

type FontImpl = ref object
    chars: SimpleTable[int32, CharInfo]
    ascent: float32
    descent: float32

var fontCache : SimpleTable[FastString, FontImpl]

proc cachedImplForFont(face: string, sz: float): FontImpl =
    if fontCache.isNil:
        fontCache = newSimpleTable(FastString, FontImpl)
    var key : FastString = face & "_" & $charHeightForSize(sz).int
    if fontCache.hasKey(key):
        result = fontCache[key]
    else:
        result.new()
        result.chars = newSimpleTable(int32, CharInfo)
        fontCache[key] = result

type Font* = ref object
    impl: FontImpl
    mSize: float
    isHorizontal*: bool
    scale*: float
    filePath: string
{'fraction_non_alphanumeric': 0.0706534844465879, 'fraction_numerical': 0.015432843019049916, 'mean_word_length': 3.6294642857142856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4687573', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1269, 'n_words': 385}