Recent

Author Topic: BGRA, TextOut and Kerning  (Read 277 times)

winni

  • Hero Member
  • *****
  • Posts: 1992
BGRA, TextOut and Kerning
« on: August 30, 2020, 10:39:52 pm »
Hi!

There are situations where you want to control the kerning of some text as you now it from all the Desktop Publishers.
This means: Make the distance between the letters smaller or wider.

BGRAbitmap has not a straight solution. Only a diffused trick:
TextOutCurved has the parameter
ALetterSpacing: single

We "missuse" that. The Path wich is needed  by TextOutCurved is only made of 2 points:
Beginning and ending of the text.

Example in the attachment

Here we go:

Code: Pascal  [Select][+][-]
  1. Procedure TextOutKerning(dest : TBGRABitmap; x,y: single; txt: string;
  2.                                      col: TBGRAPixel; align: TAlignment; space : single);
  3. var P1,P2 : TPointF;
  4.     UtfLen : Integer;
  5.     len : single;
  6.     path : TBGRAPath;
  7. begin
  8. len := Dest.TextSize(txt).cx;
  9. UtfLen := UTF8Length(txt);
  10.  case align of
  11.  taLeftJustify : begin P1 := PointF(x,y);P2 := PointF(x+len +(UTFlen-1)*space,y); end;
  12.  taRightJustify: begin P2 := PointF(x,y);P1 := PointF(x-len -(UTFlen-1)*space,y); end;
  13.  taCenter      : begin P1 := PointF(x-(len +(UTFlen-1)*space)/2,y);
  14.                        P2 := PointF(x+(len +(UTFlen-1)*space)/2,y); end;
  15.  end; //case
  16.  path := TBGRAPath.Create(PointsF([P1,P2]));
  17.  dest.TextOutCurved(path,txt,col,align,space);
  18.  path.Free;
  19. end;
  20.  
  21.  


There is definitly a quicker way to do that.
Perhaps @circular can insert it in one of the next versions.

Winni


circular

  • Hero Member
  • *****
  • Posts: 3561
    • Personal webpage
Re: BGRA, TextOut and Kerning
« Reply #1 on: September 02, 2020, 01:02:53 pm »
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 3561
    • Personal webpage
Re: BGRA, TextOut and Kerning
« Reply #2 on: September 23, 2020, 12:09:03 pm »
Added TextOut with letter spacing parameter on dev branch.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018