-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
color emojis #223
Comments
No current such intention. fonts are assumed to be monochrome, where the color is determined by the graphic context. |
reading about this exactly i see that what you suggest, as in drawing the glyphs as images or lineart, is a common practice in such cases. given that the regular font support in PDF doesn't allow for that. i wonder how this works with copying and pasting the text then. support of understanding text as text in PDF is pretty much reliant on defining text as something drawn with fonts. do you have an example of a PDF that shows the emojis correctly? like from maybe indesign or some app that might do it properly? |
i have attached 2 PDF files: one printed with Microsoft Print to PDF and one generated using Hummus PDF-Writer (with my fork more precisely). |
you can reproduce also by printing to PDF some text using font Segoe UI Emoji and emojis from Microsoft Word for instance. |
the font file is bigger in the printed PDF so i guess because of the emojis colored glyphs: they are not vectorized so in the page content but stored within the font file. |
by the way by tracing the Freetype font face with Segoe UI Emoji i found that it contains 3 cmaps: so i tried switching to the other cmap with the same platform id as the cmap selected by default, but it did not fix anything. Actually the 2 cmaps return the same glyph index from the unicode character code so i guess it is more complicated than switching the cmap with Freetype in order to fix this issue... |
it makes sense that switching cmaps didn't work. fonts in pdf (unless something changed recently) are inherently monochrome, meaning color info is expected to come from outside and all the PDF glyph drawing operators are just about creating paths. So there has to be some alternative implementation which might be exactly what you are trying to do. it'd be interesting to see waht word did (or indesign, if it supports those...this used to be my go to). one can use pdfhumuus recrypt method to create a version of a pdf with decrypted content streams. if i'll get to it, i'll check and let us know what they did. |
ok, so actually it's not as bad as i thought. if you read the text placement code in the page content stream you'll see that the way each emoji character is drawn (that starts in line 77) by superimposing 4 chars, each with different color values. 0451 with (1.000000 0.690196 0.180392) = [255, 176, 46] (the yellow part) So, a couple of conclusions from this:
p.s.
just terrific :) not ones weekend project exactly. i might start something, but can't make promises. there's some nice outcomes (especially the SVG rendering) if i go through with this...but it's a lot. |
Thanks for this detailed decrypt of colored emojis ;) |
i think what we need is using FT_Get_Color_Glyph_Layer to get each color layer glyph index and color from the base glyph index ? |
yes this could work |
@jacques-quidu I sat down to implement this colr table 0 version, which is the simplest one. if still useful to you, you can pull it. usage is like you originally did, but now the color emojis would show up. funny enough, copying and pasting the text from the pdf to someplace else both on my win and mac acrobats seem to correctly write the unicode text. im guessing that the word version doesn't set the original char value as the unicode value of the glyphs but rather attempts to map the parts, which creates the incorrect output. by some mysterious way (im guessing the algo of acrobat) this also doesn't result in multiplication of the chars per the layer, but just a nice single char per the text. so what i end up getting is the expected: anyways. figured i'll share. and we got an opacity setting operator now in content context as a side effect. |
oh. one thing. I did implement this on you can see the usage here. |
@galkahana thanks Gal i will give it a look when i find some time. |
ok it works well indeed with writeText method: so only with font Segoe UI Emoji on Windows i use now high-level writeText method instead of low-level text methods in order Segoe UI color emojis to be properly rendered in PDF: i still use low level methods with other fonts to avoid to reset font or color each time i write text. |
Thanks. Thats good input. |
Color emojis seem to not be supported: when i use emojis with "Segoe UI Emoji" font for instance, emojis are rendered as monochrome emojis in PDF.
I guess i can workaround by extracting a color bitmap image from the emoji character with Freetype (i think you can also extract svg image for some fonts) but i would like to know if you intend to add support for color emojis in PDF-Writer ? Or is there a option i missed in PDF text methods for enabling color emojis ?
The text was updated successfully, but these errors were encountered: