Problem when retrieving characters in font
Posted: Sun Aug 16, 2020 11:00 am
I'm writing a program that uses fonts with drawings and symbols instead of letters, so I've written the following code segment to test TrueType fonts, to have a way to pull all possible characters out of them:
This code makes the user select a TTF file and returns in a single PNG file saved on HD all the characters of it for ASCII codes from 1 to 255, in a grid.
However, it doesn't always work. It often happens that some characters are missing, and in one case they were all missing too! I also tried Chr () alone, without ENCODING_RAW and #ENCODING_UTF8 and ByteChr () instead of Chr (). All in vain, I can't get the entire character set contained in the font. This code has been executed under Hollywood 7.1.
How could I do?
Code: Select all
Function testFont(fileTTF)
/* Test all chars in a font */
Picture = CreateBrush(Nil, 2480, 3507, #WHITE)
SelectBrush(Picture)
OpenFont(1, fileTTF, 120, {Engine = #FONTENGINE_INBUILT})
UseFont(1)
SetFontColor(#BLACK)
SetFontStyle(#NORMAL|#ANTIALIAS)
For i=0 To 15
For j=0 To 15
car=i*16+j
/* codes 0,91 and 93 gives problem */
If car<>0 And car<>91 And car<>93
TextOut(j*150,i*200,ConvertStr(Chr(car), #ENCODING_RAW, #ENCODING_UTF8))
EndIf
Next
Next
saveFile = "C:\\Temp\\FontTest.png"
SaveBrush(Picture, saveFile, #WHITE, #IMGFMT_PNG)
EndSelect()
FreeBrush(Picture)
CloseFont(1)
EndFunction
f$ = FileRequest("Select a TTF font")
testFont(f$)
End
However, it doesn't always work. It often happens that some characters are missing, and in one case they were all missing too! I also tried Chr () alone, without ENCODING_RAW and #ENCODING_UTF8 and ByteChr () instead of Chr (). All in vain, I can't get the entire character set contained in the font. This code has been executed under Hollywood 7.1.
How could I do?