* * *

Author Topic: ExtTextOut doesn't render fonts with ligatures on Windows  (Read 238 times)

vhanla

  • New member
  • *
  • Posts: 6
ExtTextOut doesn't render fonts with ligatures on Windows
« on: April 15, 2017, 11:19:01 pm »
Hello  :)
I'm having some difficulties trying to render text with ligatures (FiraCode font e.g.) on Windows using ExtTextOut and here are some details:

OSes: Windows 10 x64 Ent. Creator Update / Ubuntu 16.04 x64
Lazarus Version: 1.6.4 / FPC: 3.0.2
Units: LCLType, LCLIntf
-----------------------------------------------------------------------
On Windows:
I have tested ExtTextOut with Delphi Tokyo and Lazarus, with Delphi it renders FiraCode ligatures correctly, but with Lazarus it doesn't.

However, DrawText render text with ligatures just as expected, both on Delphi / Lazarus.

Snaphost (with first line rendered with ExtTextOut and the second one with DrawText) using the code sample below:
(https://i.imgur.com/fDORkHz.png) (attached img below)

On Linux:
No problems here, ExtTextOut renders with ligatures, as expected.


Code Sample:

Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, LCLType, LCLIntf;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     procedure FormCreate(Sender: TObject);
  16.     procedure FormPaint(Sender: TObject);
  17.   private
  18.     { private declarations }
  19.   public
  20.     { public declarations }
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.FormCreate(Sender: TObject);
  33. begin
  34.   Font.Name := 'Fira Code';
  35.   Font.Size := 12;
  36. end;
  37.  
  38. procedure TForm1.FormPaint(Sender: TObject);
  39. var
  40.   R : TRect;
  41.   msg: AnsiString;
  42. begin
  43.   R.Left := 12;
  44.   R.Top := 12;
  45.   R.Width := 400;
  46.   R.Height := 100;
  47.   msg := '    <!-- tag html -->';
  48.   ExtTextOut(Canvas.Handle,12,12,ETO_CLIPPED or ETO_OPAQUE,@R,pchar(msg),length(msg),nil);
  49.   R.Top := 42;
  50.   DrawText(Canvas.Handle, PChar(msg), Length(msg), R, DT_NOCLIP);
  51. end;
  52.  
  53. end.
  54.  

Any suggestions apart from switching to DrawText?
« Last Edit: April 15, 2017, 11:31:37 pm by vhanla »

ASerge

  • Sr. Member
  • ****
  • Posts: 266
Re: ExtTextOut doesn't render fonts with ligatures on Windows
« Reply #1 on: April 21, 2017, 08:15:55 pm »
I'm having some difficulties trying to render text with ligatures (FiraCode font e.g.) on Windows using ExtTextOut and here are some details:
I have tested ExtTextOut with Delphi Tokyo and Lazarus, with Delphi it renders FiraCode ligatures correctly, but with Lazarus it doesn't.
I test Delphi 10.2 Tokyo and Delphi 7.0 - it's draw the same as Lazarus. But this code may help you:
Code: Pascal  [Select]
  1. procedure TForm1.FormPaint(Sender: TObject);
  2. var
  3.   R: TRect;
  4.   Msg: AnsiString;
  5.   CharPlaceInfo: TGCPResults;
  6.   Glyphs: array of WideChar;
  7. begin
  8.   R.Left := 12;
  9.   R.Top := 12;
  10.   R.Width := 400;
  11.   R.Bottom := 100;
  12.   Msg := '   <!-- tag html -->';
  13.   ZeroMemory(@CharPlaceInfo, SizeOf(CharPlaceInfo));
  14.   CharPlaceInfo.lStructSize := SizeOf(CharPlaceInfo);
  15.   SetLength(Glyphs, Length(Msg));
  16.   CharPlaceInfo.lpGlyphs := @Glyphs[0];
  17.   CharPlaceInfo.nGlyphs := Length(Glyphs);
  18.   if GetCharacterPlacement(Canvas.Handle, PChar(Msg), Length(Msg), 0, @CharPlaceInfo, GCP_LIGATE) <> 0 then
  19.   begin
  20.     ExtTextOut(Canvas.Handle, R.Left, R.Top, ETO_CLIPPED or ETO_OPAQUE or ETO_GLYPH_INDEX, @R, Pointer(Glyphs), Length(Glyphs), nil);
  21.   end;
  22.   R.Top := 42;
  23.   DrawText(Canvas.Handle, PChar(Msg), Length(Msg), R, DT_NOCLIP);
  24. end;

vhanla

  • New member
  • *
  • Posts: 6
Re: ExtTextOut doesn't render fonts with ligatures on Windows
« Reply #2 on: April 21, 2017, 09:53:35 pm »
Awesome,  :) Thank you, now it shows ligatures.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus