SRL Archive - Jr. Member General Help and Discussion

Custom Fonts


doom0791

2014-11-09 22:02:15

Greetings,

It has been a couple years since I have posted here and things seem to have changed a bit and I can't seem to find a "scripting help" section. If this is the wrong place to post a help request please forgive me. I am delighted to see that the community is still active.

Anyhow, I'm having some troubles with custom fonts. I'm certain that it's the way I'm creating the bitmap font files because if I copy all of the bitmap files from an already existing font it works. Unfortunately, the best guide that I can find on creating custom fonts is so old that the images associated with the thread are long gone.

My custom font folder is: C:\Simba\Fonts\Arial
I've tried a couple of different things to create the bitmap images:

1. Using Microsoft Paint
I created a copy of the capital letter 'A' pixel-by-pixel in paint, black and white, and saved it as 65.bmp within the Arial folder. I then copy+paste all of the other characters from an already existing font and attempt to run the following script:
program customFontTest;
var
bmp, x, y : integer;
begin
loadFont('Arial', False);
bmp := bitmapFromText('X', 'Arial');
if( findBitmapMaskTolerance(bmp, x, y, 20, 20, 400, 400, 5, 5) ) then
writeLn('Success!');
end.

This script returns Error: The Points you passed to DrawATPA exceed the bitmap's bounds at line 6

2. Using Adobe Photoshop
Once again I create the character 'A', this time in photoshop, in black and white. I make it a 1-bit image and save it to the Arial folder as 65.bmp. I ran the same script as above and received the same error.

Does anyone have any ideas for what I can do? I'm trying to read fonts in a web browser. Attached is one of the bitmaps I created.

Thank you all,
DooM


Edit: After playing with it for awhile I realized that Simba automatically loads all of the fonts in the Fonts folder upon opening. Restarting Simba stopped this error from occurring. Is there something wrong with the LoadFont function or was I using it incorrectly?

bg5

2014-11-10 05:51:26

If you need system font, there is easier way… Like this one I used in my ETL

procedure MakeFont(FLabel,Name:string;Size:integer;Style :TFontStyles);
var f:Tfont;
begin
f := TFont.Create;
f.Name := Name;
f.Size := Size;
f.Style := Style;
LoadSystemFont(f,FLabel);
f.Free;
end;

MakeFont('ArialI','Arial',20,[fsItalic]);




Your error has nothing to do with OCR. You preassumed that bitmap has size of 401x401 and error says it's smaller. If you want your test function to work, you should ensure what the real size of bmp after bitmapFromText().

program customFontTest;
var
bmp, x, y, w, h : integer;
begin
loadFont('Arial', False);
bmp := bitmapFromText('X', 'Arial');

GetBitmapSize(bmp,w,h);

if( findBitmapMaskTolerance(bmp, x, y, 0,0 ,w-1,h-1, 5, 5) ) then
writeLn('Success!');
end.

doom0791

2014-11-10 22:22:57

bg5,

Thanks for the quick response! I am trying out LoadSystemFont right now. It works beautifully. I was able to draw a bitmap of text in the Arial font really easily. Now to figure out how to look for the text in a web browser. This is complicated because the web browser doesn't display text as simple, solid colors. Any suggestions?

For anyone reading this looking for assistance, please note that if you're using Lape as your interpreter TFonts are structured a little differently:


procedure MakeFont(FLabel,Name:string;Size:integer;Style :TFontStyles);
var f:Tfont;
begin
f.Init;
f.SetName(Name);
f.setSize(Size);
f.setStyle(Style);
LoadSystemFont(f,FLabel);
f.Free;
end;


As for the findBitmapMaskTolerance I was assuming that the TBox was the screen you're searching for the mask, not the bitmap. I'm still a little unclear on this, can you explain in a little more detail, or guide me in a direction where I can get more information?

Thanks again,
DooM

Edit: Here's an example of how the web browser draws fonts:

Edit again: After catching up on the forums I see this has recently become an issue in RS scripting as well. Maybe I'll try to work something out.