program Project1;
uses sysutils, fpimage, fpimgCanv, ftfont, fpcanvas, FPWriteBMP;
procedure ExportBitmaps(FontParameter:TFreeTypeFont; ExportDirectory:string);
var
ByteIndex:byte;
LocalImage:TFPMemoryImage;
LocalCanvas:TFPImageCanvas;
BMPWriter: TFPWriterBMP;
begin
ExportDirectory:=IncludeTrailingPathDelimiter(ExportDirectory);
LocalImage:=TFPMemoryImage.Create(0,0);
BMPWriter:=TFPWriterBMP.Create;
LocalCanvas:=TFPImageCanvas.create(LocalImage);
LocalCanvas.Brush.FPColor:=colwhite;
LocalCanvas.Brush.Style:=bssolid;
LocalCanvas.Font:=FontParameter;
for ByteIndex:=0 to 255 do
begin//Write the character
LocalImage.SetSize(LocalCanvas.TextWidth(chr(ByteIndex)),LocalCanvas.TextHeight(chr(ByteIndex)));
LocalCanvas.Rectangle(-1,-1,LocalImage.Width,LocalImage.Height);
LocalCanvas.TextOut(0,LocalImage.Height,chr(ByteIndex));
//LocalCanvas.TextOut(0,0,chr(ByteIndex));
LocalImage.SaveToFile(ExportDirectory+inttostr(ByteIndex)+'.bmp',BMPWriter);
end;
BMPWriter.Free;
LocalCanvas.Free;
LocalImage.Free;
end;
var
AFont: TFreeTypeFont;
AFontAbsolutePath:string = '/tmp/PublicPixel.ttf';//Make sure you use a valid absolute path
//AFontAbsolutePath:string = '/tmp/MasaoFree.otf';//Make sure you use a valid absolute path
begin
ftfont.InitEngine;
AFont:=TFreeTypeFont.Create;
AFont.Name:=AFontAbsolutePath;
AFont.FPColor:=colblack;
AFont.Size:=60;//Changing the value to 12 won't make a significant difference
//AFont.AntiAliased:=FALSE;//Changing the default AntiAliased value to false won't make a difference
ExportBitmaps(AFont,'/tmp/a/');//Make sure you use an existing temporary directory
AFont.Free;
ftfont.DoneEngine;
{
Using PublicPixel ttf file and "LocalCanvas.TextOut(0,LocalImage.Height,chr(ByteIndex));", notice that:
42.bmp doesn't show the asterisk;
45.bmp doesn't show the minus sign;
61.bmp shows a minus instead of equal sign.
No matter the TFreeTypeFont.Size value, it appears like an amount of percent of the glyph height is trimmed at top.
Now, if we change the font from PublicPixel to MasaoFree and at the same time we modify
LocalCanvas.TextOut(0,LocalImage.Height,chr(ByteIndex)); with
LocalCanvas.TextOut(0,0,chr(ByteIndex)); in procedure ExportBitmaps, we notice that there is a delay, like a delta value of glyph bytes, for both x and y axes. Look at the 40.bmp"(" and 41.bmp")".
Using the MasaoFree font it appears like an amount of percent of the glyph is trimmed at bottom or left.
Overall, it might be that the bitmap size is computed ok but when it comes to filling it, the origin of the coordinate system of the glyph bytes is computed wrong.
}
end.