[SOLVED] How can I inject an emoji code point into a TMemo? lazarus / 31-LCL ---------------------------------------------------------------------- Gustavo 'Gus' Carreno 路 2021-09-16 15:32 Hey Y'all, I'm thinking about doing an emoji map app like the ones we have for regular characters, the well known and now forgotten char map application. I've found out about these sites that list the emoji's code points: https://emojipedia.org/https://ge]"]>Blockedji.com/ And I've also found out about the Unicode CLDR Project that has JSON formatted lists of Unicode stuff, including emojis. My question is: How do I inject, programmatically, one of these code points into a TMemo? Many thanks in advance!! Cheers, Gus PS: Don't really know if this is the right forum section. If not, I more than welcome our great team of moderators to move it to the appropriate section. THANKS!! ---------------------------------------------------------------------- Gustavo 'Gus' Carreno 路 2021-09-16 16:59 Hey Y'all, After a bit of Googling I've found my answer. There 2 ways of doing it: Without using any unit related to UTF8Using LazUTF8 Without using any unit related to UTF8 Code: Pascal 聽[Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Memo1.Text := Memo1.Text + char(240)+ char(159) + char(152) + char(128);This will append the Grinning Face Emoji (馃榾) to the memo. But this requires you to translate the code point U+1F600 to the 4 individual chars. I've found that it's not that easy when I found the UnicodeToUTF8Inline function on the LazUTF8 unit: Code: Pascal 聽[Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function UnicodeToUTF8Inline(CodePoint: cardinal; Buf: PChar): integer;begin聽 case CodePoint of聽 聽 0..$7f:聽 聽 聽 begin聽 聽 聽 聽 Result:=1;聽 聽 聽 聽 Buf[0]:=char(byte(CodePoint));聽 聽 聽 end;聽 聽 $80..$7ff:聽 聽 聽 begin聽 聽 聽 Result:=2;聽 聽 聽 聽 Buf[0]:=char(byte($c0 or (CodePoint shr 6)));聽 聽 聽 Buf[1]:=char(byte($80 or (CodePoint and $3f)));聽 聽 聽 end;聽 聽 $800..$ffff:聽 聽 聽 begin聽 聽 聽 聽 Result:=3;聽 聽 聽 聽 Buf[0]:=char(byte($e0 or (CodePoint shr 12)));聽 聽 聽 聽 Buf[1]:=char(byte((CodePoint shr 6) and $3f) or $80);聽 聽 聽 聽 Buf[2]:=char(byte(CodePoint and $3f) or $80);聽 聽 聽 end;聽 聽 $10000..$10ffff:聽 聽 聽 begin聽 聽 聽 聽 Result:=4;聽 聽 聽 Buf[0]:=char(byte($f0 or (CodePoint shr 18)));聽 聽 聽 聽 Buf[1]:=char(byte((CodePoint shr 12) and $3f) or $80);聽 聽 聽 聽 Buf[2]:=char(byte((CodePoint shr 6) and $3f) or $80);聽 聽 聽 聽 Buf[3]:=char(byte(CodePoint and $3f) or $80);聽 聽 聽 end;聽 else聽 聽 Result:=0;聽 end;end;There is A LOT of bit shifting and ORing in there, LOL!!! Using LazzUTF8 Code: Pascal 聽[Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses聽 LazUTF8, StrUtils;聽Memo1.Text := Memo1.Text + UnicodeToUTF8(Hex2Dec('1F600'));// ORMemo1.Text := Memo1.Text + UnicodeToUTF8($1F600); So I guess I have my answer and I'll be doing some more Googling to see if I can find a neat little list of the code points with the names and categories. If not, I guess I can always scrape https://emojipedia.org, right? LOL !! 馃ぃ 馃お Cheers, Gus ---------------------------------------------------------------------- winni 路 2021-09-16 18:08 Hi! There is an easier solution but the syntax聽 for that is not nice: The rocket emoticon has an hex聽 value of聽 $F09F9A80 Code: Pascal 聽[Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const rocket = #$F0#$9F#$9A#$80; 聽....Edit1.text := Edit1.text + #32 + rocket; Have a pleasant flight! Winni ---------------------------------------------------------------------- winni 路 2021-09-16 18:17 Hi! The page with all UTF8 code ,points with a bad design: https://www.utf8-chartable.de/unicode-utf8-table.pl The third line in the box is a ComboBox with all code blocks The emoticons are nearly at the end of the list. Winni ---------------------------------------------------------------------- Gustavo 'Gus' Carreno 路 2021-09-16 18:19 Hey winni, Quote from: winni on September 16, 2021, 08:08:21 pmCode: Pascal 聽[Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const rocket = #$F0#$9F#$9A#$80; Hummmm, I was unaware that we could use non base 10 numbers after the hash(#) to define a character, so I'm very thankful for this hint!!! Thanks, Winni, you gave me another morsel of knowledge I was missing and for that I'm quite grateful!! Cheers, Gus ---------------------------------------------------------------------- Gustavo 'Gus' Carreno 路 2021-09-16 18:27 Hey winni, Quote from: winni on September 16, 2021, 08:17:45 pmThe page with all UTF8 code ,points with a bad design: https://www.utf8-chartable.de/unicode-utf8-table.pl Thanks for this link!! I prefer the better formatted and more up to date tables from the Unicode site: https://unicode.org/emoji/charts/emoji- list.htmlhttps://unicode.org/emoji/charts/full-emoji-list.html The first is around 5MB and the second is about 33MB in size. Both have the emojis and the second one even has the diff emojis by platform(Apple, Samnsung, etc) in base64 format. So scrapping from them is a bit better. Combining the info on both will give me quite a nice dataset of emojis. And because that's the official site for Unicode, every time they update the specs, I'll come back and download it again. I've downloaded version 14.0 of both and will try and scrape the info latter. All these lists are made from the CLDR repository and I'm still curious on how I can use it. Need to dig a bit more on the Unicode site and also the CLDR part of the Unicode site. Cheers, Gus