Two issues related to fcl-image lazarus / 64-FPC development ---------------------------------------------------------------------- lagprogramming · 2023-06-03 08:30 1/2 In order to show the bug I'm referring at point 2/2, I've tried to write the simplest program. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; uses sysutils, fpimage, fpimgCanv, ftfont, fpcanvas; procedure ExportBitmaps(FontParameter:TFreeTypeFont; ExportDirectory:string);var  ByteIndex:byte;  LocalImage:TFPMemoryImage;  LocalCanvas:TFPImageCanvas;begin  ExportDirectory:=IncludeTrailingPathDelimiter(ExportDirectory);  LocalImage:=TFPMemoryImage.Create(0,0);   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.S etSize(LocalCanvas.TextWidth(chr(ByteIndex)),LocalCanvas.TextHeight(ch r(ByteIndex)));    LocalCanvas.Rectangle(-1,-1,LocalImage.Width,LocalImage.Height);    LocalCanvas.TextOut(0,LocalImage.Height,chr(ByteIndex));    LocalImage.SaveToFile(ExportDirectory+inttostr(ByteIndex)+'.bmp');//IT DOESN'T SAVE THE FILE AND RETURNS FALSE!!!  end;  LocalCanvas.Free;LocalImage.Free;end; var  AFont: TFreeTypeFont;  AFontAbsolutePath:string = '/tmp/PublicPixel.ttf';  //AFontAbsolutePath:string = '/tmp/MasaoFree.otf'; begin  ftfont.InitEngine;  AFont:=TFreeTypeFont.Create;  AFont.Name:=AFontAbsolutePath;  AFont.FPColor:=colblack;  AFont.Size:=60;//Changing the value to 12 won't make a difference  //AFont.AntiAliased:=FALSE;//Changing the default AntiAliased value to false won't make a difference  ExportBitmaps(AFont,'/tmp/a/');  AFont.Free;  ftfont.DoneEngine;end. The above program didn't saved the files using "function SaveToFile (const filename:String): Boolean;", so I had to modify it to use "procedure SaveToFile (const filename:String; Handler:TFPCustomImageWriter);". Both routines are in TFPCustomImage, so it looks strange to me. A working code is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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.S etSize(LocalCanvas.TextWidth(chr(ByteIndex)),LocalCanvas.TextHeight(ch r(ByteIndex)));    LocalCanvas.Rectangle(-1,-1,LocalImage.Width,LocalImage.Height);    LocalCanvas.TextOut(0,LocalImage.Height,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';  //AFontAbsolutePath:string = '/tmp/MasaoFree.otf'; begin  ftfont.InitEngine;  AFont:=TFreeTypeFont.Create;  AFont.Name:=AFontAbsolutePath;  AFont.FPColor:=colblack;  AFont.Size:=60;//Changing the value to 12 won't make a difference  //AFont.AntiAliased:=FALSE;//Changing the default AntiAliased value to false won't make a difference  ExportBitmaps(AFont,'/tmp/a/');  AFont.Free;  ftfont.DoneEngine;end. The above code saves the files but it looks strange to me why the first program code didn't worked. There is no error at compile time and I would have expected the TFPWriterBMP to be created and used automatically inside the SaveToFile function. 2/2 The following program shows a font issue. Read the comment at the end. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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.S etSize(LocalCanvas.TextWidth(chr(ByteIndex)),LocalCanvas.TextHeight(ch r(ByteIndex)));    LocalCanvas.Rectangle(-1,-1,LocalImage.Width,LocalImage.Height);     LocalCanvas.TextOut(0,LocalImage.Height,chr(ByteIndex));    //LocalCanvas.TextOut(0,0,chr(ByteIndex));     LocalImage.SaveToFile(E xportDirectory+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.I attach the font files to the message. ---------------------------------------------------------------------- wp · 2023-06-03 09:07 Quote from: lagprogramming on June 03, 2023, 10:30:46 amThe above program didn't saved the files using "function SaveToFile (const filename:String): Boolean;", so I had to modify it to use "procedure SaveToFile (const filename:String; Handler:TFPCustomImageWriter);". Both routines are in TFPCustomImage, so it looks strange to me. No, that's fine because you did not specify any image writer unit in the uses clause. Doing so registers the writer so that fcl-image can determine from the file extension the image format to be written. From fpwritebmp (and any other reader/writer unit of fcl-image): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i initialization  ImageHandlers.RegisterImageWriter ('BMP Format', 'bmp', TFPWriterBMP);