1- _FL_TEX = Graphics .loadImage (libDir .. " fnt.png" )
2- _FL_LEN = string.len
3- _FL_SUB = string.sub
4- _FL_SUP = string.upper
5- _FL_SIN = math.sin
6- _FL_COS = math.cos
7- _FL_DPI = Graphics .drawPartialImage
8- _FL_DIE = Graphics .drawImageExtended
9- _FL_DEF = 1
1+ local _FL_TEX = Graphics .loadImage (libDir .. " fnt.png" )
2+ local _FL_LEN = function (str ) return # (tostring (str ):gsub (' [\128 -\191 ]' , ' ' )) end
3+ local _FL_SUB = string.sub
4+ local _FL_SUP = string.upper
5+ local _FL_SIN = math.sin
6+ local _FL_COS = math.cos
7+ local _FL_DPI = Graphics .drawPartialImage
8+ local _FL_DIE = Graphics .drawImageExtended
9+ local _FL_DEF = 1
10+
1011FontLib = {
1112 [1 ]= {
1213 width = 8 ,
@@ -41,37 +42,63 @@ FontLib = {
4142 " " ," ." ," !" ," ?" ," -" ," +" ," (" ," )" ," %" ," $" ," #" ," |" ," ~" ," :" ," /" ," <" ," >" ," ^" ," @" ," ,"
4243 }
4344 },
44-
45- [0 ] = {
46- extrafunc = function (l ) return _FL_SUP (l ) end ,
47- width = 10 ,
48- height = 15 ,
49- startY = 14 ,
45+ [4 ]= {
46+ width = 16 ,
47+ height = 16 ,
48+ startY = 62 ,
49+ maxSyms = 37 ,
5050 letters = {
51- " 0" ," 1" ," 2" ," 3" ," 4" ," 5" ," 6" ," 7" ," 8" ," 9"
51+ ' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' , ' 8' , ' 9' , ' ' , ' .' , ' !' , ' ?' , ' -' , ' +' , ' (' ,
52+ ' )' , ' %' , ' $' , ' #' , ' E' , ' ~' , ' :' , ' /' , ' <' , ' >' , ' ^' , ' @' , ' ,' , ' N' , ' O' , ' P' , ' Q' , ' R' , ' S' , ' T' , ' U' , ' V' , ' W' , ' X' , ' Y' , ' Z' , ' [' , ' \\ ' , ' ]' , ' Ĉ' , ' _' , ' `' ,
53+ ' a' , ' b' , ' c' , ' d' , ' e' , ' f' , ' g' , ' h' , ' i' , ' j' , ' k' , ' l' , ' m' , ' n' , ' o' , ' p' , ' q' , ' r' , ' s' , ' t' , ' u' , ' v' , ' w' , ' x' , ' y' , ' z' , ' {' , ' |' , ' }' , ' ~' ,
54+ ' а' , ' б' , ' в' , ' г' , ' д' , ' е' , ' ё' , ' ж' , ' з' , ' и' , ' й' , ' к' , ' л' , ' м' , ' н' , ' о' , ' п' ,
55+ ' р' , ' с' , ' т' , ' у' , ' ф' , ' х' , ' ц' , ' ч' , ' ш' , ' щ' , ' ы' , ' ъ' , ' ь' , ' э' , ' ю' , ' я' , ' А' ,
56+ ' ¡' , ' ¢' , ' £' , ' ¤' , ' ¥' , ' ¦' , ' §' , ' ¨' , ' ©' , ' ª' , ' «' , ' ¬' , ' Б' , ' ®' , ' ¯' , ' °' , ' ±' , ' ²' , ' ³' , ' ´' , ' µ' , ' ¶' , ' ·' , ' ¸' , ' ¹' , ' º' , ' »' ,
57+ ' ¼' , ' ½' , ' ¾' , ' ¿' , ' À' , ' Á' , ' Â' , ' Ã' , ' Ä' , ' Å' , ' Æ' , ' Ç' , ' È' , ' É' , ' Ê' , ' Ë' , ' Ì' , ' Í' , ' Î' , ' Ï' , ' Ð' , ' Ñ' , ' Ò' , ' Ó' , ' Ô' , ' Õ' , ' Ö' , ' ×' ,
58+ ' Ø' , ' Ù' , ' Ú' , ' Û' , ' Ü' , ' Ý' , ' Þ' , ' ß' , ' à' , ' á' , ' â' , ' ã' , ' ä' , ' å' , ' æ' , ' ç' , ' è' , ' é' , ' ê' , ' ë' , ' ì' , ' í' , ' î' , ' ï' , ' ð' , ' ñ' , ' ò' , ' ó' ,
59+ ' ô' , ' õ' , ' ö' , ' ÷' , ' ø' , ' ù' , ' ú' , ' û' , ' ü' , ' ý' , ' þ' , ' ÿ' , ' Ā' , ' ā' , ' Ă' , ' ă' , ' Ą' , ' ą' , ' Ć' , ' ć' ,
5260 }
61+ },
62+ [0 ] = {
63+ extrafunc = function (l ) return _FL_SUP (l ) end ,
64+ width = 10 ,
65+ height = 15 ,
66+ startY = 14 ,
67+ letters = {
68+ " 0" ," 1" ," 2" ," 3" ," 4" ," 5" ," 6" ," 7" ," 8" ," 9"
69+ }
70+ }
5371}
54- }
55- function FontLib_setLetter (fnt , _x , l )
56- FontLib [fnt ][l ] = {x = _x }
72+
73+ function FontLib_setLetter (fnt , _x , l , _y )
74+ FontLib [fnt ][l ] = {x = _x , y = _y or 0 }
5775end
76+
5877for i = 0 , # FontLib do
5978 local x , w = 0 , FontLib [i ].width
6079 for j = 1 , # FontLib [i ].letters do
61- FontLib_setLetter (i , x , FontLib [i ].letters [j ])
62- x = x + w
80+ if i == 4 then
81+ if (j - 1 ) % FontLib [i ].maxSyms == 0 and j > 1 then
82+ x = 0
83+ end
84+ FontLib_setLetter (i , x , FontLib [i ].letters [j ], math.floor ((j - 1 ) / FontLib [i ].maxSyms )* FontLib [i ].height + math.floor ((j - 1 ) / FontLib [i ].maxSyms ))
85+ x = x + w
86+ else
87+ FontLib_setLetter (i , x , FontLib [i ].letters [j ])
88+ x = x + w
89+ end
6390 end
6491end
92+ local utf8charPattern = " [%z\1 -\127\194 -\244 ][\128 -\191 ]*"
6593function FontLib_print (x , y , text , clr , fnt )
6694 fnt = fnt or _FL_DEF
6795 local w , h , s , f = FontLib [fnt ].width , FontLib [fnt ].height , FontLib [fnt ].startY , FontLib [fnt ].extrafunc
68- for i = 1 , _FL_LEN (text ) do
69- local l = _FL_SUB (text , i , i )
96+ for l in tostring (text ):gmatch (utf8charPattern ) do
7097 if f then l = f (l ) end
7198 if not FontLib [fnt ][l ] then
7299 l = ' ^'
73100 end
74- _FL_DPI (x , y ,_FL_TEX ,FontLib [fnt ][l ].x , s , w , h , clr )
101+ _FL_DPI (x , y ,_FL_TEX ,FontLib [fnt ][l ].x , s + FontLib [ fnt ][ l ]. y , w , h , clr )
75102 x = x + w
76103 end
77104end
@@ -80,11 +107,10 @@ function FontLib_printScaled(x, y, text, size_x, size_y, clr, fnt)
80107 local w , h , s , f = FontLib [fnt ].width , FontLib [fnt ].height , FontLib [fnt ].startY , FontLib [fnt ].extrafunc
81108 local wS = w * size_x
82109 local Sx , Sy = wS / 2 , h * size_y / 2
83- for i = 1 , _FL_LEN (text ) do
84- local l = _FL_SUB (text , i , i )
110+ for l in tostring (text ):gmatch (utf8charPattern ) do
85111 if f then l = f (l ) end
86112 if FontLib [fnt ][l ] ~= nil then
87- _FL_DIE (x + Sx , y + Sy , _FL_TEX , FontLib [fnt ][l ].x , s , w , h , 0 , size_x , size_y , clr )
113+ _FL_DIE (x + Sx , y + Sy , _FL_TEX , FontLib [fnt ][l ].x , s + FontLib [ fnt ][ l ]. y , w , h , 0 , size_x , size_y , clr )
88114 end
89115 x = x + wS
90116 end
@@ -95,11 +121,10 @@ function FontLib_printRotated(x, y, text, rot, clr, fnt)
95121 local sin , cos , len = _FL_SIN (rot ), _FL_COS (rot ), _FL_LEN (text )
96122 local wS , hS = w * cos , w * sin
97123 local Sx , Sy = (len - 1 ) * wS / 2 , (len - 1 ) * hS / 2
98- for i = 1 , len do
99- local l = _FL_SUB (text , i , i )
124+ for l in tostring (text ):gmatch (utf8charPattern ) do
100125 if f then l = f (l ) end
101126 if FontLib [fnt ][l ] ~= nil then
102- _FL_DIE (x - Sx , y - Sy , _FL_TEX , FontLib [fnt ][l ].x , s , w , h , rot , 1 , 1 , clr )
127+ _FL_DIE (x - Sx , y - Sy , _FL_TEX , FontLib [fnt ][l ].x , s + FontLib [ fnt ][ l ]. y , w , h , rot , 1 , 1 , clr )
103128 end
104129 x = x + wS
105130 y = y + hS
@@ -112,11 +137,10 @@ function FontLib_printExtended(x, y, text, size_x, size_y, rot, clr, fnt)
112137 local wS , hS = w * size_x * cos , w * size_x * sin
113138 local Sx , Sy = (len - 1 ) * wS / 2 , (len - 1 ) * hS / 2
114139 x , y = x - Sx , y - Sy
115- for i = 1 , len do
116- local l = _FL_SUB (text , i , i )
140+ for l in tostring (text ):gmatch (utf8charPattern ) do
117141 if f then l = f (l ) end
118142 if FontLib [fnt ][l ] ~= nil then
119- _FL_DIE (x , y , _FL_TEX , FontLib [fnt ][l ].x , s , w , h , rot , size_x , size_y , clr )
143+ _FL_DIE (x , y , _FL_TEX , FontLib [fnt ][l ].x , s + FontLib [ fnt ][ l ]. y , w , h , rot , size_x , size_y , clr )
120144 end
121145 x = x + wS
122146 y = y + hS
0 commit comments