Lazarus

Programming => LCL => Topic started by: Gustavo 'Gus' Carreno on September 24, 2021, 03:42:01 am

Title: How to display coloured emojis on Windows?
Post by: Gustavo 'Gus' Carreno on September 24, 2021, 03:42:01 am
Hey Y'all,

I was able to convince a couple of user over at the Discord server Unofficial Free Pascal(https://discord.gg/yQhwhfZS) to compile the attached project and they provided me with a screenshot of what it looks like under Windows 10. I'm also attaching how it looks under Ubuntu 21.04 64b.

If we go over to emojipedia.org, they use both UTF8 emojis and images to display their information.
When I was testing my project under a Windows Server 2012 VPS, I pointer Google Chrome at it and the UTF8 emojis where coloured.

So, what do I have to do to have my app tap into the coloured UTF8 emojis?

Is it a matter of font? Or something else like a codepage?

I'm lost and a complete ignorant of both how Windows renders UTF8 glyphs and the whole UTF8 thing to be honest, so any hint and/or pointer to some helpful implementation would be very welcomed!!

Cheers,
Gus

PS: I sure wish we could have a BBCode tag to include an image in the text and not only on the attachments...
Maybe I'm being spoiled by GitHub's Markdown editor or the Discord client LOL!!
Title: Re: How to display coloured emojis on Windows?
Post by: Jurassic Pork on September 24, 2021, 10:08:06 am
hello,
i don't know if you can use this option in Lazarus :
Quote
D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT
In Windows 8.1 and later, text is rendered using color versions of glyphs, if defined by the font.

Friendly, J.P
Title: Re: How to display coloured emojis on Windows?
Post by: Gustavo 'Gus' Carreno on September 25, 2021, 03:58:38 pm
Hey J.P.,

i don't know if you can use this option in Lazarus :
Quote
D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT
In Windows 8.1 and later, text is rendered using color versions of glyphs, if defined by the font.

Thanks, I'll try and look this up. I hope I can suss this out even without access to a Windows machine :)

Cheer,
Gus
Title: Re: How to display coloured emojis on Windows?
Post by: Martin_fr on September 25, 2021, 04:15:05 pm
The "old" API does not support this according to my google searches. So functions like TextOutA / TextOutW (Afaik used by the LCL) will not do the trick.

https://stackoverflow.com/questions/46892844/gdi-can-i-use-the-new-windows-10-segoe-ui-emoji-colored-font-with-drawtext
The answer seems to lead to this: https://docs.microsoft.com/en-us/windows/win32/directwrite/direct-write-portal
Title: Re: How to display coloured emojis on Windows?
Post by: Gustavo 'Gus' Carreno on September 25, 2021, 04:28:31 pm
Hey Martin,

The "old" API does not support this according to my google searches. So functions like TextOutA / TextOutW (Afaik used by the LCL) will not do the trick.

That's a bummer :(

https://stackoverflow.com/questions/46892844/gdi-can-i-use-the-new-windows-10-segoe-ui-emoji-colored-font-with-drawtext
The answer seems to lead to this: https://docs.microsoft.com/en-us/windows/win32/directwrite/direct-write-portal

This looks quite more complicated than just drop some TLabels on a TFlowPanel...

Is there anything in laz-main that I can look at that uses this new approach?

And, Martin, THANK you SOOOO very much for doing the leg work, I really appreciate it :) really I DO!!

Well, if all else fails, the place I'm extracting the data for these lists has a *.png file that illustrates an example.
So a solid plan B would be to use TImages on the TFlowPanel instead of the current TLabels when it comes to Windows.

It's a pity that Windows always has to be de odd one out :(

Cheers,
Gus
Title: Re: How to display coloured emojis on Windows?
Post by: Jurassic Pork on September 27, 2021, 02:13:19 pm
hello,
on windows, webbrowsers can display colored emojis, so here is two possibilities.
1 -  Generate html code to display the emojis which you want :
Code: Pascal  [Select][+][-]
  1.   s:= TStringList.Create;
  2.   htmlString := '<!DOCTYPE html><html lang="en">' +
  3.                 '<head><meta charset="UTF-8"></head>' +
  4.                 '<body><p style="font-size:32px;font-family: segoe ui emoji;">';
  5.  
  6.   For index := 0 to 79 do
  7.     htmlString += '<span id =' + inttostr(index) + '>&#' + IntToStr($1F600 + index) + ';</span>';
  8.   htmlString += '</p></body></html>';
  9.   s.add(htmlString);
  10.   s.SaveToFile('D:\temp\emojis.html');
  11.   s.Free;                            
Attention displayed code is wrong :
Quote
   '>&#38;#'  ->  '>&#'
then two possibilities  :
1 - Display the page in Lazarus with a webbrowser Activex (IE).
2 - Launch chrome with selenium in Lazarus then get all the span elements. Take a screenshot of each element. Put the bitmap in a TimageList. Then Display the imageList in a TListView.
see the result in Attachment.
Friendly, J.P
Title: Re: How to display coloured emojis on Windows?
Post by: engkin on September 27, 2021, 04:25:49 pm
I think the browser uses FreeType?
Title: Re: How to display coloured emojis on Windows?
Post by: Gustavo 'Gus' Carreno on September 27, 2021, 07:04:43 pm
Hey J.P.,

Thank you very much for the effort in getting it to work with ActiveX Internet Explorer, it looks FAB!!

My main goal is to not have any dependencies on external stuff, including ActiveX or the bloatware of an external Browser Engine.

As I've mentioned before, the source I'm extracting from(https://unicode.org/emoji/charts/emoji-list.html) already has the images embedded in base64 PNGs.
If I can't solve this with just a font change or messing about with the TextOut(A/W) to use DirectWrite, like @Martin_fr suggested, I'll just include the samples on the data I'm extracting and use the PNGs.

Nonetheless, I thank you VERY much for the effort you made :)

Cheers,
Gus
Title: Re: How to display coloured emojis on Windows?
Post by: Gustavo 'Gus' Carreno on September 27, 2021, 07:08:29 pm
Hey Engkin,

I think the browser uses FreeType?

I'm a complete noob in terms of Fonts/UTF8 and Graphics in general, so I have a noob question:

Isn't FreeType a Font Format, or a list of fonts in an accepted font format that is free and without royalties?

If so, how do I make sure I'm selecting a FreeType font on Windows?
Does Windows even have ANY FreeType font installed by default?

Thanks for the suggestion, but being a noob, it posed more questions than it solved, sorry Engkin :)

Cheers,
Gus
Title: Re: How to display coloured emojis on Windows?
Post by: dsiders on September 27, 2021, 07:12:56 pm
Hey Engkin,

I think the browser uses FreeType?

I'm a complete noob in terms of Fonts/UTF8 and Graphics in general, so I have a noob question:

Isn't FreeType a Font Format, or a list of fonts in an accepted font format that is free and without royalties?

If so, how do I make sure I'm selecting a FreeType font on Windows?
Does Windows even have ANY FreeType font installed by default?

Thanks for the suggestion, but being a noob, it posed more questions than it solved, sorry Engkin :)

Cheers,
Gus

What is FreeType?
https://www.freetype.org/freetype2/docs/index.html
Title: Re: How to display coloured emojis on Windows?
Post by: wp on September 27, 2021, 07:30:36 pm
Have a look at the demo in folder examples/lazfreetype. It shows how fonts can be rendered by a Lazarus program bypassing the system font machinery.

I had already tried to display an emoji with this program but was not successful since I am an emoji noob and don't know neither emoji codes nor complete fonts which contain emojis.
Title: Re: How to display coloured emojis on Windows?
Post by: winni on September 27, 2021, 07:37:11 pm

......nor complete fonts which contain emojis.

Hi!

Use the Liberation Fonts: Sans/Serif/Mono
They contain emojis.

Download here:

https://github.com/liberationfonts/liberation-fonts
 (https://github.com/liberationfonts/liberation-fonts)

Winni
Title: Re: How to display coloured emojis on Windows?
Post by: Gustavo 'Gus' Carreno on September 27, 2021, 08:02:15 pm
Hey dsiders,

What is FreeType?
https://www.freetype.org/freetype2/docs/index.html

Thank you very much for the link!!
I'll have a read just to pad my knowledge of this matter, which is very lacking I must admit :(

Cheers,
Gus
Title: Re: How to display coloured emojis on Windows?
Post by: Gustavo 'Gus' Carreno on September 27, 2021, 08:19:28 pm
Hey WP,

Have a look at the demo in folder examples/lazfreetype. It shows how fonts can be rendered by a Lazarus program bypassing the system font machinery.

Thank you SOOOO very much for this!!!!
I haven't had a look at the code, I just ran it to see what it can do and my head exploded on the speed of it!!!
Now I need to have a look at the code and see if I can make the coloured emojis to come out on a Windows program.
If this is the solution, as usual, WP, YOU DA MAN :hugs:

I had already tried to display an emoji with this program but was not successful since I am an emoji noob and don't know neither emoji codes nor complete fonts which contain emojis.

Welcome to the club ;)
I'm just crawling from the primordial ooze myself, LOL ;)

Cheers,
Gus
Title: Re: How to display coloured emojis on Windows?
Post by: Gustavo 'Gus' Carreno on September 27, 2021, 08:23:46 pm
Hey Winni,

Use the Liberation Fonts: Sans/Serif/Mono
They contain emojis.

Download here:
https://github.com/liberationfonts/liberation-fonts
 (https://github.com/liberationfonts/liberation-fonts)

Thanks mate, I'll have a good look at those!!

This then, ofc, gets me into the how-do-I-use-a-font-without-installing-it territory of things.
Well, for the regular TextOut on the LCL, cuz if I use the code @WP suggested from the FreeType example, I just need to include the file and some kind of LICENSE file...

Nonetheless, thanks for giving me a font file that, for sure, has emojis!!

Cheers,
Gus
Title: Re: How to display coloured emojis on Windows?
Post by: engkin on September 27, 2021, 11:54:29 pm
Here is the code that I had found long ago on a Japanese website. I made a class of the original code:
Code: Pascal  [Select][+][-]
  1. unit uColorEmoji;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Graphics, freetypehdyn;
  9.  
  10. type
  11.  
  12.   { TEmoji }
  13.  
  14.   TEmoji=class
  15.   protected
  16.     FLibrary: PFT_Library;
  17.     FError: FT_Error;
  18.     FFace: PFT_Face;
  19.     procedure DrawFreeTypeBitmap(ACanvas: TCanvas ;AFTBitmap: FT_Bitmap; X, Y: integer);
  20.   public
  21.     constructor Create(AFontFileName: String);
  22.     destructor Destroy; override;
  23.     procedure DrawUnicodeCodePoint(ACanvas: TCanvas; ACodePoint: FT_ULong; ALineHeight: integer; AX: integer);
  24.   end;
  25.  
  26. //Test
  27. //DrawUnicodeCodePoint(Label1.Canvas, $1F61C, 160);
  28.  
  29. implementation
  30.  
  31. { TEmoji }
  32.  
  33. constructor TEmoji.Create(AFontFileName: String);
  34. begin
  35.   inherited Create;
  36.  
  37.   InitializeFreetype('freetype.dll');
  38.   FError := FT_Init_FreeType(FLibrary);
  39.   {if LError <> 0 then
  40.     Exit;//}
  41.   FT_New_Face(FLibrary, PChar(AFontFileName), 0, FFace);
  42. end;
  43.  
  44. destructor TEmoji.Destroy;
  45. begin
  46.   //FT_Done_Face(Face);
  47.   ReleaseFreetype;
  48.   inherited Destroy;
  49. end;
  50.  
  51. procedure TEmoji.DrawFreeTypeBitmap(ACanvas: TCanvas ;AFTBitmap: FT_Bitmap; X, Y: integer);
  52. type
  53.   RGBQUAD = packed record
  54.     rgbRed, rgbGreen, rgbBlue, rgbReserved: byte
  55.   end;
  56.   TRGBQArray = array [0..High(integer) div 4 - 1] of RGBQUAD;
  57.   PRGBQArray = ^TRGBQArray;
  58. var
  59.   LIsColor: boolean;
  60.   LIncValue: integer;
  61.   LBitmap: TBitmap;
  62.   LBytePos: integer;
  63.   LPosX: integer;
  64.   LPosY: integer;
  65.   LScanArray: PRGBQArray;
  66.   LColorQuad: RGBQUAD;
  67.   LByte: byte;
  68.   LBValue: byte;
  69.   LGValue: byte;
  70.   LRValue: byte;
  71.   LAValue: byte;
  72. begin
  73.   LBitmap := TBitmap.Create;
  74.   try
  75.     LBitmap.SetSize(AFTBitmap.Width, AFTBitmap.rows);
  76.     LBitmap.PixelFormat := pf32bit;
  77.     //LBitmap.AlphaFormat := afDefined;
  78.  
  79.     LIncValue := 1;
  80.     LIsColor := AFTBitmap.Width = AFTBitmap.pitch div 4;
  81.     if LIsColor then
  82.       LIncValue := 4;
  83.  
  84.     LBytePos := 0;
  85.     for LPosY := 0 to LBitmap.Height - 1 do
  86.     begin
  87.       LScanArray := LBitmap.ScanLine[LPosY];
  88.  
  89.       for LPosX := 0 to LBitmap.Width - 1 do
  90.       begin
  91.         if LIsColor then
  92.         begin
  93.           LRValue := PByte(AFTBitmap.buffer)[LBytePos + 0];
  94.           LGValue := PByte(AFTBitmap.buffer)[LBytePos + 1];
  95.           LBValue := PByte(AFTBitmap.buffer)[LBytePos + 2];
  96.           LAValue := PByte(AFTBitmap.buffer)[LBytePos + 3];
  97.         end
  98.         else
  99.         begin
  100.           LByte := pByte(AFTBitmap.buffer)[LBytePos];
  101.           if LByte <> $00 then
  102.           begin
  103.             LRValue := $00;
  104.             LGValue := $00;
  105.             LBValue := $00;
  106.             LAValue := $FF;
  107.           end
  108.           else
  109.           begin
  110.             LRValue := $FF;
  111.             LGValue := $FF;
  112.             LBValue := $FF;
  113.             LAValue := $FF;
  114.           end;
  115.         end;
  116.  
  117.         LColorQuad.rgbRed := LRValue;
  118.         LColorQuad.rgbGreen := LGValue;
  119.         LColorQuad.rgbBlue := LBValue;
  120.         LColorQuad.rgbReserved := LAValue;
  121.  
  122.         LScanArray^[LPosX] := LColorQuad;
  123.  
  124.         Inc(LBytePos, LIncValue);
  125.       end;
  126.     end;
  127.  
  128.     ACanvas.Draw(X, y, LBitmap);
  129.   finally
  130.     FreeAndNil(LBitmap);
  131.   end;
  132. end;
  133.  
  134. procedure TEmoji.DrawUnicodeCodePoint(ACanvas: TCanvas; ACodePoint: FT_ULong;
  135.   ALineHeight: integer; AX: integer);
  136.  
  137. const
  138.   FT_LOAD_COLOR = 1 shl 20;//<--missing from freetypehdyn
  139.  
  140. var
  141.   LGlyphIndex: FT_UInt;
  142.   LGlyphSlot: PFT_GlyphSlot;
  143.   LDrawLeft: integer;
  144.   LDrawTop: integer;
  145. begin
  146. {  ACanvas.Brush.Style := bsClear;
  147.   ACanvas.Brush.Color := clSilver;
  148.   //ACanvas.FillRect(ACanvas.ClipRect);
  149.  
  150.  //}
  151.   FT_Set_Pixel_Sizes(FFace, 0, ALineHeight);
  152.  
  153.   LGlyphIndex := FT_Get_Char_Index(FFace, ACodePoint);
  154.   if LGlyphIndex=0 then
  155.     exit;
  156.  
  157.   FError := FT_Load_Glyph(FFace, LGlyphIndex, FT_LOAD_COLOR {or FT_LOAD_RENDER});
  158.  
  159.   LGlyphSlot := FFace^.glyph;
  160.   FError := FT_Render_Glyph(LGlyphSlot, FT_RENDER_MODE_NORMAL);
  161.  
  162.   LDrawLeft := AX;
  163.   LDrawTop := ALineHeight - FFace^.glyph^.bitmap_top;
  164.  
  165.   ACanvas.FillRect(AX,0, AX+10+FFace^.glyph^.bitmap.width,ACanvas.Height);
  166.  
  167.   DrawFreeTypeBitmap(ACanvas, LGlyphSlot^.bitmap, LDrawLeft, LDrawTop);
  168. end;
  169.  
  170. end.

Test it with a button and a label, like:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   Emoji: TEmoji;
  4.   fileName: String;
  5. begin
  6.   fileName := 'c:\Windows\Fonts\seguiemj.ttf';
  7.   //fileName := 'c:\Windows\Fonts\OpenSansEmoji.otf';
  8.   //fileName := 'c:\Windows\Fonts\unifont-13.0.06.ttf';
  9.   //fileName := 'c:\Windows\Fonts\TwitterColorEmoji-SVGinOT.ttf';//<--- complete list
  10.   Emoji := TEmoji.Create(fileName);
  11.   try
  12.     Emoji.DrawUnicodeCodePoint(Label1.Canvas, $1F61C, 160, 10);
  13.   finally
  14.     Emoji.Free;
  15.   end;
  16. end;

I think I needed it on a system that does not support colored emojis.

1st Edit:
You still need a FreeType library, if you don't already have it on your system.

2nd Edit:
I just realized freetypehdyn is missing one needed function: FT_Render_Glyph.
I modified freetypehdyn to include it.
Title: Re: How to display coloured emojis on Windows?
Post by: wp on September 28, 2021, 12:12:03 am
That's interesting code, thanks for sharing. However, the compiler (3.2.2, 3.2.0) chokes on FT_Render_Glyph.
Title: Re: How to display coloured emojis on Windows?
Post by: engkin on September 28, 2021, 02:33:49 am
Sorry, I meant to provide that function as well. Add the attached files to your project.
Title: Re: How to display coloured emojis on Windows?
Post by: Jurassic Pork on September 28, 2021, 01:42:41 pm
hello,
strange, it seems that with use of freetypefont (engkin's unit) , the emojis are not the same that the segoe ui emojis ( see attachment 1). And i have some trouble with transparency.
I have a new method to display emojis  in lazarus :
1 - get the internet page where you have seen the emojis which you want (ex : https://unicode.org/emoji/charts/emoji-list.html ) with fpthttpclient
2 - parse the html to extract all the lines of the table with emojis (with sax_html)
3 - on each line get the caption of the emoji and the base64 string of the emoji's image. Convert the base64 string to bitmap. put the bitmap in an imagelist. Put the caption in a listview (with imagelist as largeimages).
See the result in attachment 2.

Friendly, J.P
Title: Re: How to display coloured emojis on Windows?
Post by: PascalDragon on September 28, 2021, 01:56:07 pm
strange, it seems that with use of freetypefont (engkin's unit) , the emojis are not the same that the segoe ui emojis ( see attachment 1).

That's because there are different styles of Emojis. The Segoe UI emojis are those designed by Microsoft (https://emojipedia.org/microsoft/) while the ones you loaded from the internet look like the Apple (https://emojipedia.org/apple/) ones. There are many more of course...
Title: Re: How to display coloured emojis on Windows?
Post by: Jurassic Pork on September 28, 2021, 02:32:56 pm
That's because there are different styles of Emojis. The Segoe UI emojis are those designed by Microsoft (https://emojipedia.org/microsoft/) while the ones you loaded from the internet look like the Apple (https://emojipedia.org/apple/) ones. There are many more of course.
but the freetypefont is "linked" to segoe ui emojis font :
Code: Pascal  [Select][+][-]
  1.  fileName := extractfiledir(paramstr(0))+ '\seguiemj.ttf';
  2.    Emoji := TEmoji.Create(fileName);
Title: Re: How to display coloured emojis on Windows?
Post by: engkin on September 28, 2021, 04:08:11 pm
strange, it seems that with use of freetypefont (engkin's unit) , the emojis are not the same that the segoe ui emojis ( see attachment 1).

I vaguely remember discovering the browser "cheating" when it comes to displaying emojis.

Also,, I think I had another function included in the attached file above to help find an emoji based on its name.
Title: Re: How to display coloured emojis on Windows?
Post by: wp on September 28, 2021, 04:10:08 pm
Add the attached files to your project.
Engkin, thanks for this nice code. Are you planning to file a feature request to the fpc project so that the missing procedures are added to the "official" libfreetype?

BTW, there is also a LazFreeType library (in components/freetype of the Laz installation). I guess your code can be adapted to work with this lib as well?
Title: Re: How to display coloured emojis on Windows?
Post by: Jurassic Pork on September 28, 2021, 04:31:20 pm
wp,
have you try the uColorEmoji unit ?
i have some trouble with transparency : may be my code is wrong :
here is the code :
Code: Pascal  [Select][+][-]
  1. // uses uColorEmoji;
  2. var
  3.     bmp: TBitmap;
  4.     LI: TListItem;
  5.     Emoji: TEmoji;
  6.     fileName: String;
  7.    index: Integer;
  8. begin
  9.    bmp := TBitmap.Create;
  10.    bmp.SetSize(32,32);
  11.    fileName := extractfiledir(paramstr(0))+ '\seguiemj.ttf';
  12.    Emoji := TEmoji.Create(fileName);
  13.    try
  14.       For index:=0 to 79 do
  15.        begin
  16.           Emoji.DrawUnicodeCodePoint(bmp.Canvas, $1F600 + index, 32, 0); //[EDIT] oops index forgotten
  17.           LI := ListView1.Items.Add;
  18.           LI.Caption    := 'Emoji' + IntToStr(index);
  19.           LI.ImageIndex := index;
  20.           ImageList1.Add(bmp,nil);
  21.         end;
  22.    finally
  23.     bmp.Free;
  24.     Emoji.Free;
  25.   end;      

and for the use of EasyLazFreeType

Code: Pascal  [Select][+][-]
  1. // uses fpimage,IntfGraphics, GraphType,  EasyLazFreeType,  LazFreeTypeIntfDrawer;
  2. var
  3.   charIndex: integer;
  4.   lazimg: TLazIntfImage;
  5.   FTTFFont: TFreeTypeFont;
  6.   drawer: TIntfFreeTypeDrawer;    
  7. begin
  8.   lazimg := TLazIntfImage.Create(0,0, [riqfRGB]);
  9.   lazimg.SetSize(Image1.Width,Image1.Height);
  10.   FTTFFont:=TFreeTypeFont.create;
  11.   FTTFFont.Hinted:=false;
  12.   FTTFFont.Name:= extractfiledir(paramstr(0))+'\seguiemj.ttf';
  13.   ShowMessage(inttoStr(FTTFFont.GlyphCount));
  14.   FTTFFont.SizeInPoints := 24;
  15.   drawer := TIntfFreeTypeDrawer.Create(lazimg);
  16.   drawer.FillPixels(TColorToFPColor(clYellow));
  17.   charIndex :=  FTTFFont.CharIndex[$1F600]; // not working
  18.   drawer.DrawGlyph(2093,FTTFFont,0,30,TColorToFPColor(clBlack)); // force to index 2093
  19.   Image1.Picture.Bitmap.LoadFromIntfImage(lazimg);
  20.   drawer.free;
  21.   FTTFFont.Free;
  22.  
CharIndex return 0 and of course the emoji is black ( DrawGlyph).

Friendly, J.P
Title: Re: How to display coloured emojis on Windows?
Post by: wp on September 28, 2021, 05:27:26 pm
Sorry I don't know what to do with these code snippets. Could you upload them in a compilable project?

Yes I tried Engkin's uColorEmoji unit, and it works correctly regarding transparency - see attchment
Title: Re: How to display coloured emojis on Windows?
Post by: Jurassic Pork on September 28, 2021, 05:39:26 pm
ok thanks wp i have found the error in my code --> i have put wrong args in the DrawUnicodeCodePoint procedure and wrong ttf . it is for that i have the wrong emojis.
With your project it is OK !
in Attachment my project with a better code.
Title: Re: How to display coloured emojis on Windows?
Post by: Jurassic Pork on September 29, 2021, 12:48:51 pm
hello,
and for the use of EasyLazFreeType :
Code: Pascal  [Select][+][-]
  1. // uses fpimage,IntfGraphics, GraphType,  EasyLazFreeType,  LazFreeTypeIntfDrawer;
  2. var
  3.   charIndex: integer;
  4.   lazimg: TLazIntfImage;
  5.   FTTFFont: TFreeTypeFont;
  6.   drawer: TIntfFreeTypeDrawer;    
  7. begin
  8.   lazimg := TLazIntfImage.Create(0,0, [riqfRGB]);
  9.   lazimg.SetSize(Image1.Width,Image1.Height);
  10.   FTTFFont:=TFreeTypeFont.create;
  11.   FTTFFont.Hinted:=false;
  12.   FTTFFont.Name:= extractfiledir(paramstr(0))+'\seguiemj.ttf';
  13.   ShowMessage(inttoStr(FTTFFont.GlyphCount));
  14.   FTTFFont.SizeInPoints := 24;
  15.   drawer := TIntfFreeTypeDrawer.Create(lazimg);
  16.   drawer.FillPixels(TColorToFPColor(clYellow));
  17.   charIndex :=  FTTFFont.CharIndex[$1F600]; // not working
  18.   drawer.DrawGlyph(11680,FTTFFont,0,30,TColorToFPColor(clBlack)); // force to index 11680
  19.   Image1.Picture.Bitmap.LoadFromIntfImage(lazimg);
  20.   drawer.free;
  21.   FTTFFont.Free;
  22.  
CharIndex return 0 and of course the emoji is black ( DrawGlyph).

Friendly, J.P
CharIndex returns 0 because LazFreeType isn't up to date. The file ttcmap.pas (https://sourceforge.net/p/lazarus-ccr/svn/3704/tree/components/freetypepascal/ttcmap.pas) contains only 4 formats of cmap (0,2,4,6). In the latest file ttcmap.c (https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/src/sfnt/ttcmap.c) of freetype project we have   9 formats (0,2,4,6,8,10,12,13,14).
The font segoe ui emojis uses the formats  4,12,14.

Friendly, J.P
Title: Re: How to display coloured emojis on Windows?
Post by: PascalDragon on September 29, 2021, 01:17:50 pm
That's because there are different styles of Emojis. The Segoe UI emojis are those designed by Microsoft (https://emojipedia.org/microsoft/) while the ones you loaded from the internet look like the Apple (https://emojipedia.org/apple/) ones. There are many more of course.
but the freetypefont is "linked" to segoe ui emojis font :
Code: Pascal  [Select][+][-]
  1.  fileName := extractfiledir(paramstr(0))+ '\seguiemj.ttf';
  2.    Emoji := TEmoji.Create(fileName);

And Segoe UI contains the Microsoft Emojis so I don't know why you're confused here?
Title: Re: How to display coloured emojis on Windows?
Post by: engkin on October 03, 2021, 08:30:43 am
Are you planning to file a feature request to the fpc project so that the missing procedures are added to the "official" libfreetype?

Yes, sure. As soon as I get a chance unless you beat me to it.

It needs the static version of these functions to be added as well, a missing constant, and testing it on Windows as least.
TinyPortal © 2005-2018