Forum > Graphics

Understanding and adjusting BGRABitmap's handling of line distances

(1/2) > >>

ArchChem:
Hello,

I am developing a program displaying song lyrics. In my current version, I am about to migrate the displaying of the lyrics from the default Graphics functions to BGRABitmap. So far, everything works well. There is only one thing which I notice and this is the different handling of line distances (font heights?).

The default Graphics functions draw multiline text with an appropriate line distance which comes from the Font I guess – see the first picture. BGRABitmap reduces this line height which results in not very beautiful results (see the second picture).

I would like BGRABitmap to display the font in the same way as the Canvas.TextRect function does concerning the size and distances.
How can I archieve that? This is my current code to display fonts with BGRA:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Bitmap.FontName  := Font.Name;Bitmap.FontStyle := Font.Style;Bitmap.FontQuality:=TBGRAFontQuality.fqSystemClearType;Bitmap.FontHeight:= Round(Font.Height/0.75);   Bitmap.TextRect(ContentRect, Slide.PartContent.MainText, TextStyle.Alignment, tlCenter,                               ColorToBgra(PresentationStyleSettings.TextColor));  
Thanks in advance!

ArchChem:
Dear mods, I am sorry – I didn't recognize the BGRA child board. Please feel free to move my topic there. Thanks!

Dzandaa:
Hi,

In BGRABitmap, you also have: FontFullHeight.

Try to play with it?

Also look at:

https://wiki.freepascal.org/BGRABitmap_tutorial_12

And

https://wiki.lazarus.freepascal.org/BGRABitmap_tutorial_Font_rendering

B->

ArchChem:
Hey Dzandaa,

Thank you for your reply! I did already play around with FullTextHeight, but it does not seem to have any effect on the line distance.

circular:
Hello ArchChem,

Welcome to the forum.  :)

To investigate, I would need to reproduce the different of line spacings. It may depend on the font family and the system.

Can you provide a simple example that displays both line spacing? Something like this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses BGRABitmap, BGRABitmapTypes; {$R *.lfm} { TForm1 } procedure TForm1.FormPaint(Sender: TObject);var  ts: TSize;  style: TTextStyle;  bmp: TBGRABitmap;  halfX: integer;begin  halfX := ClientWidth div 2;  with Canvas do  begin    Brush.Color := clWhite;    FillRect(0, 0, halfX, ClientHeight);    Brush.Style := bsClear;     Font.Color := clBlack;    Font.Height := 50;    Font.Name := 'Arial';    ts := Canvas.TextExtent('Hello world');    Rectangle(0, 0, ts.cx, ts.cy);    TextOut(0, 0, 'Hello world');     style := Canvas.TextStyle;    style.Wordbreak:= true;    style.SingleLine:= false;    TextRect(rect(0, 50, halfX, ClientHeight),      0, 50, 'Text with'#13#10'Line endings', style);  end;   bmp := TBGRABitmap.Create(halfX, ClientHeight, BGRAWhite);  with bmp.CanvasBGRA do  begin    Brush.Style := bsClear;     Font.Color := clBlack;    Font.Height := 50;    Font.Name := 'Arial';    ts := Canvas.TextExtent('Hello world');    Rectangle(0, 0, ts.cx, ts.cy);    TextOut(0, 0, 'Hello world');     style := Canvas.TextStyle;    style.Wordbreak:= true;    style.SingleLine:= false;    TextRect(rect(0, 50, halfX, ClientHeight),      0, 50, 'Text with'#13#10'Line endings', style);  end;  bmp.Draw(Canvas, halfX, 0);  bmp.Free;end;

Navigation

[0] Message Index

[#] Next page

Go to full version