topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 11:39 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Delphi / Windows 7 / ColorFonts like Emoji  (Read 9674 times)

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Delphi / Windows 7 / ColorFonts like Emoji
« on: June 20, 2018, 05:57 AM »
Hi there,
i could need some coding advice for this problem:
I would like to program an Application that also shows Emoji like used on this Web-Site or WhatsApps or or or, hopefully you know what i mean.

My Problem is native those Fonts are supported by Windows 8.1 or higher (Segoe UI Emoji).
Example: 😱 🤡 👨 👩 🙈 🙉 🙊 🌈 💘 💖 🔞 🇩🇪 👍 🤘

All Windows 8.1+ will display proper Emoji while Windows 7 shows empty rectangle.
If you use Firefox, those Emojis will be rendered on any Machine.

So my question is: How does FireFox render a Font while Delphi cant (or Browsers Opera/IE)

Quick'n'Dirty i solved this by implementing proper Bitmaps, my Goal would be using Unicode ColorFonts.

ConstanceJill

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 205
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #1 on: June 20, 2018, 06:31 AM »
So my question is: How does FireFox render a Font while Delphi cant (or Browsers Opera/IE)
That would be because webpages can provide the font by hosting it somewhere and giving the path to download it from via .css : see https://www.w3school...r_font-face_rule.asp

Now there probably is a way to embed the font in your application too, as I remember there was a way to do it for graphic modes with Turbo Pascal back then.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #2 on: June 20, 2018, 07:05 AM »
So my question is: How does FireFox render a Font while Delphi cant (or Browsers Opera/IE)
That would be because webpages can provide the font by hosting it somewhere and giving the path to download it from via .css : see https://www.w3school...r_font-face_rule.asp

Now there probably is a way to embed the font in your application too, as I remember there was a way to do it for graphic modes with Turbo Pascal back then.
-ConstanceJill (June 20, 2018, 06:31 AM)

I stopped coding with Delphi at version 5 Pro.  But I think it must still be possible to create a "resource only" DLL with fonts,bitmaps,strings etc. and load it when the program runs.  The OP may have to check with the font maker if it is OK to redistribute the fonts in a DLL with the program.

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #3 on: June 20, 2018, 11:37 AM »
Sorry if i spelled question wrong.

I have already the Font. I am able to attach to that Font. I can show Text with that Font. What doesnt function yet is the part when i try show ColorFonts (like a smiley: yellow skin, white eyes, red lips, black outline).

When i try dispay such it end up with empty space or in bad cases with a transparent rectangle with black border.
After reading MSDN i know that its restricted to Windows 8.1 or higher.

My .exe will work on Windows 8.1, display everything like expected (Direct2d/Win2d used to do it), Windows 7 = white space
What makes me wuzzy is that FireFox can display and i am not able to do, equal how tricky i try.

I am pretty sure i can apopt Code from non-Delphi, i just mentioned it cause i use it  :-* so if someone has an Idea, please feed me  :D

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #4 on: June 20, 2018, 11:42 PM »
Sorry if i spelled question wrong.

I have already the Font. I am able to attach to that Font. I can show Text with that Font. What doesnt function yet is the part when i try show ColorFonts (like a smiley: yellow skin, white eyes, red lips, black outline).

When i try dispay such it end up with empty space or in bad cases with a transparent rectangle with black border.
After reading MSDN i know that its restricted to Windows 8.1 or higher.

My .exe will work on Windows 8.1, display everything like expected (Direct2d/Win2d used to do it), Windows 7 = white space
What makes me wuzzy is that FireFox can display and i am not able to do, equal how tricky i try.

I am pretty sure i can apopt Code from non-Delphi, i just mentioned it cause i use it  :-* so if someone has an Idea, please feed me  :D

Does Delphi show the font in the list of fonts in the property editor?

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #5 on: June 21, 2018, 12:33 AM »
Does Delphi show the font in the list of fonts in the property editor?
In short, yes.

Some news update: I am now able to render the emojis correct but Color is missing, look: Screenshot - 21_06.jpgDelphi / Windows 7 / ColorFonts like Emoji
What i found out is that Font uses Vector-Data to fill painted parts, maby i get it somehow working.

edit
More news, found out that FireFox uses own Library to render Fonts (cairo)..... I'm on it :-)
« Last Edit: June 21, 2018, 06:29 AM by KodeZwerg »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #6 on: June 21, 2018, 02:51 PM »
Just to be clear, I wasn't asking from an I don't know what Delphi is perspective, but from the perspective of someone that worked in it for years before jumping to C#, so I was just asking if it was in the list of fonts.  :-[

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #7 on: June 21, 2018, 03:41 PM »
Just to be clear, I wasn't asking from an I don't know what Delphi is perspective, but from the perspective of someone that worked in it for years before jumping to C#, so I was just asking if it was in the list of fonts.  :-[
I am sorry if my "In short, yes" reply was rude or did not satisfy. Please give me another chance to answer question more detailed.

Dear wraith808,
thank you for reading, your interest and try to help. Yes my Delphi show up the Emoji Font in Property Editor but cant handle its content correct.
Now i am able to do things with Font like Windows charmap.exe does. (limited/restricted to colorless mode only [black/white])

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #8 on: June 21, 2018, 07:07 PM »
No offense taken :)  Just thought it might be good to give the perspective from which I was asking.  Are you using a standard text control to show it?

Also, if you that's what you're doing, you might try to draw the font on a TCanvas, and see how that turns out, i.e.

Code: Delphi [Select]
  1. procedure WriteTextOnImage(imgResult: TImage, strTextToOutput: string);
  2. var
  3.     bmpText: TBitmap;
  4. begin
  5.      bmpText:= TBitmap.Create;
  6.      try
  7.         bmpText.Canvas.Font := <FontName>
  8.         bmpText.Canvas.TextOut(X, Y, textToOutput);
  9.         imgResult.Picture.Assign(bmpText);
  10.      finally
  11.         FreeAndNil(bmpText);
  12.      end;
  13.  end;

(Keep in mind, it's been many moons since I touched Delphi, so forgive any errors, but the theory should work)
« Last Edit: June 21, 2018, 07:17 PM by wraith808 »

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #9 on: June 21, 2018, 09:10 PM »
Thank you wraith808, code looks after that many moons quit good! :up:
My bad, i should have written already what i've tried, i've used this method to do Bitmap thingy like you suggested.
Code: Delphi [Select]
  1. const
  2.    CHESS_WHITE_QUEEN = #$2654;
  3.    CHESS_WHITE_KING = #$2655;
  4.    CHESS_WHITE_ROOK = #$2656;
  5.    CHESS_WHITE_BISHOP = #$2657;
  6.    CHESS_WHITE_KNIGHT = #$2658;
  7.    CHESS_WHITE_PAWN = #$2659;
  8.  
  9.    CHESS_BLACK_QUEEN = #$265A;
  10.    CHESS_BLACK_KING = #$265B;
  11.    CHESS_BLACK_ROOK = #$265C;
  12.    CHESS_BLACK_BISHOP = #$265D;
  13.    CHESS_BLACK_KNIGHT = #$265E;
  14.    CHESS_BLACK_PAWN = #$265F;
  15.  
  16. function CharToBitmap(sFontName: String; c: WideChar; cBackColor, cFontColor, cOutlineColor: TColor;
  17.   OutlineSize: Integer; bmp: TBitmap): Boolean;
  18. var
  19.   r: TRect;
  20.   OtmSize: Integer;
  21.   pTm: POutlineTextMetric;
  22.   LogFont: TLogFont;
  23. begin
  24.   Result := False;
  25.  
  26.   //destination rect
  27.   r := Rect(0, 0, bmp.Width, bmp.Height);
  28.  
  29.   //set new font
  30.   bmp.Canvas.Font.Name := sFontName;
  31.   bmp.Canvas.Font.Style := [fsBold];
  32.   bmp.Canvas.Font.Size := 10;
  33.  
  34.   //fill background
  35.   bmp.Canvas.Brush.color := cBackColor;
  36.   bmp.Canvas.FillRect(r);
  37.  
  38.   //get font metrics
  39.   OtmSize := GetOutlineTextMetrics(bmp.Canvas.Handle, SizeOf(TOutlineTextMetric), nil);
  40.   if OtmSize > 0 then
  41.   begin
  42.     //reserve memory
  43.     GetMem(pTm, OtmSize);
  44.     try
  45.       pTm^.otmSize := OtmSize; //set size
  46.  
  47.       if GetOutlineTextMetrics(bmp.Canvas.Handle, OtmSize, pTm) <> 0 then
  48.       begin
  49.         //fill whole height
  50.         bmp.Canvas.Font.Height := - bmp.Height;
  51.  
  52.         BeginPath(bmp.Canvas.handle);
  53.  
  54.         SetBKMode(bmp.Canvas.Handle, TRANSPARENT);
  55.  
  56.         DrawTextW(bmp.canvas.handle, @c, 1, r, DT_SINGLELINE or
  57.           DT_CENTER or DT_VCENTER);
  58.  
  59.         EndPath(bmp.Canvas.handle);
  60.         bmp.Canvas.Brush.color := cFontColor;
  61.         bmp.Canvas.pen.color := cOutlineColor;
  62.         bmp.Canvas.pen.width := OutlineSize;
  63.         StrokeAndFillPath(bmp.Canvas.Handle);
  64.  
  65.         Result := True;
  66.       end;
  67.     finally
  68.       FreeMem(pTm);
  69.     end;
  70.   end;
  71. end;
  72.  
  73. procedure TForm1.Button4Click(Sender: TObject);
  74. var
  75.   bmp: TBitmap;
  76. begin
  77.   bmp := TBitmap.create;
  78.   try
  79.     bmp.width := 100;
  80.     bmp.height := 100;
  81.     //white piece
  82.     CharToBitmap('Chess Merida Unicode', CHESS_WHITE_BISHOP,
  83.       clGreen,
  84.       clBlack,
  85.       clWhite,
  86.       bmp.height div 80,
  87.       bmp);
  88.   Image1.Picture.Assign(bmp);
  89.  
  90.     //black piece
  91.     CharToBitmap('Chess Merida Unicode', CHESS_BLACK_KING,
  92.       clGreen,
  93.       clBlack,
  94.       clWhite,
  95.       bmp.height div 80,
  96.       bmp);
  97.  
  98.     Image2.Picture.Assign(bmp);
  99.   finally
  100.     bmp.Free;
  101.   end;
  102. end;
That code would grab a chess figure out of a font file and render it to a bitmap. Adopted to my Emoji problem it result in B/W images (if at all... somehow buggy)
I guess that what i want to do isnt that easy at all :'(
FireFox lead my way to his cairo library wich lead to GTK+ wich lead to more sub-stuff.
For Windows 8.1 i have working code that draws everything like it should be (utilizing Direct2D) but prior Windows Version simply ignore it. MSDN writes same about ColorFonts.

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #10 on: June 22, 2018, 03:24 AM »
Are you using a standard text control to show it?
I've forgot to answer that, here we go:
I try to display "colored" either as Text via Edit/Memo or as Bitmap inside Text/Memo. For Bitmap testing i am using an Image control.

I think i have found a solution = Cairo Delphi Api Wrapper
Unfortunately its Download is currently..... lets say the Website has a PHP problem :-)

edit
PHP problem is fixed, download is up again. Lets see if i get it working......
« Last Edit: June 22, 2018, 03:56 AM by KodeZwerg »

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #11 on: June 22, 2018, 11:54 AM »
 :Thmbsup:  That looks like a good resource to get Cairo working if standard rendering doesn't work.  Hope it works out!

Zidankearney

  • Participant
  • Joined in 2019
  • *
  • Posts: 1
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #12 on: January 02, 2019, 12:57 AM »
I think Delphi at version 5 Pro is now outdated.

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Delphi / Windows 7 / ColorFonts like Emoji
« Reply #13 on: January 02, 2019, 08:04 AM »
I think Delphi at version 5 Pro is now outdated.

The concepts that Miles was talking about transcend version, so I think we're OK with that.  :Thmbsup:

Welcome to the site!