Recent

Author Topic: FreeType & BGRABitmap  (Read 1424 times)

mosquito

  • Full Member
  • ***
  • Posts: 141
FreeType & BGRABitmap
« on: February 18, 2021, 12:23:04 pm »
FreeType works perfect on a TBGRAVirtualScreen or tbgragraphiccontrol.
begin .

But can I use FreeType (or other technique) in pre-made BGRAControls, like for example a TBCListBox?

« Last Edit: February 18, 2021, 06:20:01 pm by mosquito »

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: FreeType & BGRABitmap
« Reply #1 on: February 19, 2021, 03:41:19 am »
No you can't. We use normal bgrabitmap text functions or normal canvas text functions.
There is some reason to use that?

Feel free to fork the repository and play with the source code if you want to.

Actually it's a bit stopped the development of bgracontrols. Last release has @circular fixes and nothing on my side. Last time we worked together in svg controls but that was a long time ago.

mosquito

  • Full Member
  • ***
  • Posts: 141
Re: FreeType & BGRABitmap
« Reply #2 on: February 19, 2021, 08:43:35 am »
Thanks, well knowing that this is not possible, I think I will play a new control with this ability. Unfortunately I have a serious problem with (BGRAGraphicControl + FreeType), the form explodes when resized. I sent a PM to Circular, since I do not know how to report this possible failure, although it is surely the result of my inexperience. Greetings.

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: FreeType & BGRABitmap
« Reply #3 on: February 19, 2021, 11:22:52 pm »
There is the bgrabitmap / bgracontrols repository at GitHub, you can talk there as well. But a PM is ok as well.  :)

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: FreeType & BGRABitmap
« Reply #4 on: February 21, 2021, 06:23:00 am »
Hello,

I don't know how to report this (it could be a bug, or maybe I'm a bug);

This code breaks when the form is resized in Windows. In GNU/Linux directly crash;

It is only with GraphicControl (VirtualScreen behaves OK).

You need Arial.ttf!

---------------------

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   BGRAVirtualScreen, BGRAGraphicControl,
  10.  
  11.   BGRABITMAP, BGRABITMAPTYPES,
  12.  
  13.   EasyLazFreeType, LazFreeTypeFontCollection,
  14.   BGRAFreeType
  15.   , BCTypes;
  16.  
  17. type
  18.  
  19.   { TForm1 }
  20.  
  21.   TForm1 = class(TForm)
  22.     BGRAGraphicControl1: TBGRAGraphicControl;
  23.     BGRAVirtualScreen1: TBGRAVirtualScreen;
  24.     BGRAVirtualScreen2: TBGRAVirtualScreen;
  25.     procedure BGRAGraphicControl1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  26.     procedure BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  27.     procedure BGRAVirtualScreen2Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  28.     procedure FormCreate(Sender: TObject);
  29.     procedure FormResize(Sender: TObject);
  30.   private
  31.  
  32.   public
  33.  
  34.   end;
  35.  
  36. var
  37.   Form1: TForm1;
  38.  
  39. implementation
  40.  
  41. {$R *.lfm}
  42.  
  43. { TForm1 }
  44.  
  45. VAR
  46. FONTFAMILYNAME : STRING ;
  47. MYFONT        : TFREETYPEFONT ;
  48.  
  49. procedure TForm1.FormCreate(Sender: TObject);
  50. begin
  51. FONTFAMILYNAME := FontCollection.AddFile('Arial.ttf').Family.FamilyName;
  52. MYFONT := TFreeTypeFont.Create;
  53. MYFONT.NAME := FontFamilyName;
  54. end;
  55.  
  56. procedure TForm1.BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  57. VAR
  58. RENDERER: TBGRAFreeTypeFontRenderer;
  59. begin
  60.  
  61.  RENDERER:=TBGRAFreeTypeFontRenderer.Create;
  62.  BITMAP.FILL(CLBLACK);
  63.  BITMAP.FONTRENDERER:=RENDERER;
  64.  BITMAP.FONTNAME := fontfamilyname;
  65.  bitmap.FontHeight:=10;
  66.  BITMAP.TEXTOUT(1,1,'Connected',CLRED);
  67.  
  68. end;
  69.  
  70. procedure TForm1.BGRAVirtualScreen2Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  71. VAR
  72. RENDERER: TBGRAFreeTypeFontRenderer;
  73. begin
  74. RENDERER:=TBGRAFreeTypeFontRenderer.Create;
  75.  BITMAP.FILL(CLBLACK);
  76.  BITMAP.FONTRENDERER:=RENDERER;
  77.  BITMAP.FONTNAME := fontfamilyname;
  78.  bitmap.FontHeight:=10;
  79.  BITMAP.TEXTOUT(1,1,'Connected',CLRED);
  80. END;
  81.  
  82. procedure TForm1.BGRAGraphicControl1Redraw(Sender: TObject; Bitmap: TBGRABitmap
  83.   );
  84. VAR
  85. RENDERER: TBGRAFreeTypeFontRenderer;
  86. begin
  87. RENDERER:=TBGRAFreeTypeFontRenderer.Create;
  88.  BITMAP.FILL(CLBLACK);
  89.  BITMAP.FONTRENDERER:=RENDERER;
  90.  BITMAP.FONTNAME := fontfamilyname;
  91.  bitmap.FontHeight:=10;
  92.  BITMAP.TEXTOUT(1,1,'Connected',CLRED);
  93. END;
  94. end.
  95.  
  96.  


Hello Mosquito,

What error do you get?

It is not easy for me to test it on my computer as recompiling Lazarus with custom controls on Linux doesn't work well. With the full project I could to launch it though.
Conscience is the debugger of the mind

mosquito

  • Full Member
  • ***
  • Posts: 141
Re: FreeType & BGRABitmap
« Reply #5 on: February 21, 2021, 08:05:34 am »
There it goes.
Thanks.

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: FreeType & BGRABitmap
« Reply #6 on: February 21, 2021, 03:55:53 pm »
Thanks.

Ok so what happens is that there is a Caption in those controls and that the font is set to "default" which is not recognized in BGRAFreeType.

Either remove the caption or set the font to Arial for example.
Conscience is the debugger of the mind

mosquito

  • Full Member
  • ***
  • Posts: 141
Re: FreeType & BGRABitmap
« Reply #7 on: February 21, 2021, 05:02:38 pm »
Code: Pascal  [Select][+][-]
  1. Works !!
  2. Sorry to have occupied your Sunday.
  3. You made mine happy.
  4.  ___  ___ ___    _  _ _  [ThX]  
  5. | _ )/ __| _ \  /_\| | | _____ _____ _ _
  6. | _ \ (_ |   / / _ \_  _/ -_) V / -_) '_|
  7. |___/\___|_|_\/_/ \_\|_|\___|\_/\___|_|
  8.  

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: FreeType & BGRABitmap
« Reply #8 on: February 21, 2021, 09:43:15 pm »
You're welcome  :)

No problem

Conscience is the debugger of the mind

 

TinyPortal © 2005-2018