#Emoji export in PDF

255 messages Β· Page 1 of 1 (latest)

urban nexus
#

@reef star

urban nexus
#

good news, @stone harbor is working on this now!

fickle leaf
#

Wow πŸ”₯😱 it's going πŸƒ to be 🐝 so great πŸ’―πŸ‘Œ to finally 🍁 be 😹😹😹 able πŸ’ͺ to use πŸ˜πŸ€”πŸ˜΄ emojis ⌚ in 🍝πŸ₯« all 🧨 my 😘 papers

mortal creek
#

im too young for a stroke

strange kettle
urban nexus
fickle leaf
urban nexus
fickle leaf
#

unless typst would translate them to type 3 fonts on the fly

urban nexus
timber wigeon
#

Nice!

urban nexus
timber wigeon
#

I just saw the hacky workaround with Apple Color Emoji, I faced the exact same problem when implementing it for resvg πŸ™ƒ

fickle leaf
urban nexus
timber wigeon
urban nexus
#

That's nice

timber wigeon
urban nexus
timber wigeon
timber wigeon
urban nexus
#

hah, we also do black foreground for COLR

#

sorry, but not gonna write multiple glyphs per glyphs just for that

#

I see. 0.128 * self.font_size

timber wigeon
#

I basically tried a couple of different font sizes and it seems like this value is pretty on spot

urban nexus
#

slightly different value than Ana picked

timber wigeon
#

but great that we have emoji support in Typst now!

urban nexus
#

so now it's supported by Typst and resvg, but not svg2pdf science

timber wigeon
#

now I just need to steal the code for svg2pdf

urban nexus
#

we'd need that shared abstraction crate

timber wigeon
#

indeed :(

urban nexus
#

but Typst's implementation also makes use of the Frame infrastructure, so it's not exactly easily portable

#

Had I known that you worked on that, the two of you could have shared the pain of figuring out the transforms

#

wait, how did you handle SVG?

timber wigeon
#

haha sorry, maybe I should've mentioned it somewhere πŸ˜„ but it was pretty spontanous

urban nexus
#

The Typst code needs a hack to make the SVG unsized

#

with some string manipulation

timber wigeon
#

πŸ€” how so?

urban nexus
#

you have access to resvg internals, so that might change things

#

we can't just group.children.push(Node::Group(Box::new(tree.root)));

jaunty mesa
fickle leaf
#

I doubt that's typst's fault

timber wigeon
#

mm maybe, not sure I understood why it's necessary, but maybe I also haven't tested it thoroughly

#

but it seems to work fine with Twitter Color Emoji

jaunty mesa
jaunty mesa
# fickle leaf I doubt that's typst's fault

the font is the same and the PDF viewer is the same. The only difference is that typst's pdf file is v1.7 and lualatex's is v1.5. I'm not sure if those 2 new minor versions changed the way the selection works, but other than that, it's typst's fault, or rather the difference is only because different compilers were used.

urban nexus
fickle leaf
timber wigeon
#

maybe I can take a look if I find the time to do so

urban nexus
jaunty mesa
timber wigeon
#

I think this mighy be a resvg bug though. The above picture is what I get with this SVG:

<svg xmlns="http://www.w3.org/2000/svg" id="glyph878">
    <g transform="translate(0 -6.75) translate(0,-1638.4) scale(56.888888888888886)">
        <circle fill="#FFCC4D" cx="18" cy="18" r="18"/>
        <path fill="#664500"
              d="M18 21c-3.623 0-6.027-.422-9-1-.679-.131-2 0-2 2 0 4 4.595 9 11 9 6.404 0 11-5 11-9 0-2-1.321-2.132-2-2-2.973.578-5.377 1-9 1z"/>
        <path fill="#FFF" d="M9 22s3 1 9 1 9-1 9-1-2 4-9 4-9-4-9-4z"/>
        <ellipse fill="#664500" cx="12" cy="13.5" rx="2.5" ry="3.5"/>
        <ellipse fill="#664500" cx="24" cy="13.5" rx="2.5" ry="3.5"/>
    </g>
</svg>
#

but if I remove the outermost g group, it looks like that:

#

ok no its not a bug... Chrome shows it the same

#

im sure there is something we can do against this though, at the latest when I port the code to svg2pdf I will have to figure it out, so I can just post here if I have a solution

jaunty mesa
#

Each time for some reason I need to compile something or rather re-compile some old document in latex, I get anxiety, because I think that either I forgot to install the texlive distro or that I get some errors and the document won't compile.

#

But thankfully for that document everything was local and I indeed have texlive installed, so latexmk -lualatex -shell-escape worked like a charm.

fickle leaf
#

in sumatra pdf I can't select the ones in the lualatex one at all

#

while selection works in the typst one

#

same in firefox

fickle leaf
#

I think it's just the hellscape of pdf compatibility

jaunty mesa
#

mhm

fickle leaf
#

as an aside, we need subsetting @timber wigeon πŸ˜‚

jaunty mesa
#

well, at least the selection is always present in typst's version, so I guess that's the most important thing.

fickle leaf
#

1.68 MB for like five lines of text

jaunty mesa
#

1.68 MiB*

fickle leaf
#

and the former has one fewer letter

jaunty mesa
#

(I really gotta find time later to make a yet another script, which will change SI to IEC units in websites I use, so that I can relax more.)

jaunty mesa
fickle leaf
#

no, I just don't care very much

jaunty mesa
green verge
jaunty mesa
#

you can select some and in some PDF viewer

timber wigeon
urban nexus
jaunty mesa
#

for lualatex it doesn't even list the font. And even if I can select it, it isn't copyable. so I guess latex sucks even more, despite being powerful and mature.

stone harbor
#

"fully embedded" here is a bit misleading, as type3 fonts are custom fonts (they are not embedded ttf files), so they are always considered "complete" but they actually are a subset of the original font (we just copy emoji glyphs from here into another format that pdf readers understand)

#

not sure if this explanation makes things clearer to you, but all you should know is that it is a subset of the original font despite what your pdf reader says

fickle leaf
#

So that it's not displayed that way

stone harbor
#

I think the only thing preventing that is the "0" in the "COLOR0" at the beginning of the font name, the spec says it should be only capital letters

#

it also only mentions type 1 and truetype fonts, so not sure it would work with type3 fonts

fickle leaf
stone harbor
#

i mean the part that is circled

jaunty mesa
stone harbor
#

We embed part of the font (and after transforming it quite a lot), but not the original ttf file, I think that's what was meant with "we dont embed the font anyway"

timber wigeon
#

Yes maybe I should have been clearer, sorry

jaunty mesa
#

ok

timber wigeon
#

@stone harbor btw I just saw your message in quick-questions, in case you want to add COLRv1 as well, feel free to use this implementation I made which is a best-effort implementation to convert a COLRv1 glyph into a SVG file https://github.com/RazrFalcon/resvg/blob/master/crates/usvg/src/text/colr.rs. I think you could use this and treat it more or less the same as an SVG glyph. Maybe this helps, as there are quite a few things that are a bit tricky in terms of transform order and so on (and the API in ttf-parser could be improved too...). It's not perfect because a lot of things like conic gradients can't be represented directly in SVG, but it should work fine for like 99% of the cases πŸ˜„

stone harbor
#

cool, thanks a lot!

#

i will probably give it a look at some point, but it is not a priority right now as colorv1 emojis are still pretty new and not well supported in other softwares anyway

timber wigeon
#

oh yeah no worries, just wanted to point it out!

craggy talon
#

Does the current implementation not support SVG table, or I missed something?

#

seems svg export has color, but pdf doesn't

timber wigeon
#

works fine for me

#

maybe you're not running from main?

craggy talon
#

oh, I mistakenly thought this had already landed in 0.11.1. Thanks

#

I will try using main.

timber wigeon
#

@stone harbor would it be okay for you if I give the colrv1 thing a shot myself?

stone harbor
#

Yeah sure

timber wigeon
#

still a few issues I need to look into but looks promising at least!

timber wigeon
#

and damn they make the PDF veeery big

mortal creek
#

That segoe laughing emoji literally dips lmao

timber wigeon
#

Yeah…

strange kettle
#

overall, it looks stunning

#

but definitely needs some compression then?

#

Can't πŸ‘ wait πŸ‘ to πŸ‘ type πŸ‘ my πŸ‘ take-home πŸ‘ message πŸ‘ like πŸ‘ this πŸ‘ in πŸ‘ my πŸ‘ papers.

timber wigeon
#

Well I’m not sure how

#

The problem is that the 3d Emojis have like a billion different gradients

#

To emulate the 3d effect

#

And gradients are pretty big in pdf as you might already now

fickle leaf
fickle leaf
fickle leaf
# timber wigeon :D

Baseline looks a bit inconsistent. But that could be issues with the fonts of course

timber wigeon
fickle leaf
timber wigeon
#

Yeah

fickle leaf
# timber wigeon Yeah

Naive question: I know pdf uses deflate, but is the entire file compressed, or only parts of it?

#

I guess what I'm getting at is whether or not the emojis get compressed in the file

timber wigeon
#

The instructions get compressed

#

But not the gradients

#

As in the definition of gradients

#

I think pdf supports a feature where you can basically compress the whole file but I don’t think pdf writer supports that

fickle leaf
#

Anyway a realistic document will presumably use fewer emojis than in your picture

fickle leaf
#

Sorry for all the questions πŸ˜›

timber wigeon
timber wigeon
timber wigeon
fickle leaf
stone harbor
#

they should if two gradients are the same

fickle leaf
#

Or should as in "typst makes sure that's the case "

stone harbor
#

a bit of both πŸ˜› the gradient needs to have the same representation on typst's side, so the font needs to re-use the exact same gradient (but it can be duplicated in the font file, as long as it is always the same, even if that wouldn't be very smart), and then typst can properly deduplicate it when exporting to pdf

timber wigeon
#

the problem is that I'm converting the colr fonts to svg basically

stone harbor
#

oh

timber wigeon
#

I dont think there will be reuse then, since each svg is converted separately by svg2pdf

stone harbor
#

yeah

timber wigeon
#

but yeah I mean these are details that can all be improved upon in the future πŸ˜„

stone harbor
#

maybe it would be worth to implement it using pdf instructions directly, instead of converting to svg and using svg2pdf?

timber wigeon
#

would be very trouble some I'm afraid

#

especially because Typst doesn't support gradients with opacities

#

which are used heavily

fickle leaf
timber wigeon
#

idk I mean I think it should be okay for now, it's not like anyone will include 200 emojis in their documents...

#

as I mentioned, it can always be optimized in the futuer

fickle leaf
#

πŸ‘

fickle leaf
timber wigeon
#

and I hate Apple Preview for still not having fixed their annoying soft mask bug 😠

timber wigeon
#

also let's not forget about this one who looks like it just got beaten πŸ˜‚

fickle leaf
#

Apple preview just sounds bad in general

timber wigeon
strange kettle
#

Which is definitely easier said than done

urban nexus
#

PDF object streams would likely not be that hard to support in pdf-writer

timber wigeon
#

my only concern

#

is this

#

so I guess you can't just throw everything into a single object stream...

fickle leaf
#

Presumably that was more of a concern 20 years ago?

timber wigeon
#

who knows

#

I mean how old is Acrobat 6 πŸ˜‚

#

maybe I can sneakily ask on the Artifex Discord what mutool/ghostscript does

fickle leaf
timber wigeon
#

only after my exams though

strange kettle
olive inlet
#

If you reuse the exact same emoji does it incur the same costs?

olive inlet
#

awesome

#

So this definitely doesn't seem like that big a deal for most documents

timber wigeon
#

so looks like mupdf uses a limit of 256 objects per object strean

#

yeah that would be pretty ugly to implement...

urban nexus
#

@timber wigeon re #1208798893069045830 message: The position is top-left of the image, yes. As for how exactly the frame is positioned in a line of text, I'll have to defer to @stone harbor.

timber wigeon
#

no worries, I think I already figured it out! it seems to be the top left of the em box

urban nexus
#

btw, the first can be simplified to Point::zero()

#

yeah, that makes sense, since the frame is em-sized

timber wigeon
#

oh yeah, that was just for testing :p it wont stay zero

urban nexus
#

but the question is still where the baseline ends up

timber wigeon
#

yeah it's a bit tricky, but I think I figured it out

urban nexus
#

@timber wigeon is the COLRv1 stuff now also sorta duplicated across resvg and typst?

#

if yes, so much duplication across typst, svg2pdf, resvg, ... :/

timber wigeon
#

it's duplicated across resvg yes

#

it's not in svg2pdf and I don't plan on implementing it there for now

timber wigeon
#

I mean if you dont want to accept the PR I understand, but I still think it's better to have some support (which honestly should work in 98% of the cases) than none^^

urban nexus
urban nexus
#

could be used across resvg, svg2pdf, and Typst

timber wigeon
#

not sure how happy RazrFalcon would be about having this

#

it's very specific after all...

urban nexus
#

isn't the point of usvg to make it easy to render an SVG?

#

this is part of it after all

timber wigeon
#

well yeah but COLR fonts aren't really SVG right? πŸ˜„ the only reason we even convert it into SVG is because it's the easiest option for now

urban nexus
#

wait, wouldn't (shouldn't?) usvg's Text::flattened() already do that essentially?

timber wigeon
#

I think we are aneinander vorbeireden again πŸ˜‚

#

the thing that is duplicated is the implementation of the conversion from COLRv1 to an svg file, right?

urban nexus
#

yeah

#

why not generate an svg file with just the glyph text in it and take its flattened group?

timber wigeon
#

now that sounds like a hack πŸ˜‚ maybe it could work... but then we have to deal with fontdb stuff again

#

and make sure usvg selects the correct font

urban nexus
#

that'd be easy with the font provider

#

but yeah, it's a bit of a workaround

timber wigeon
#

I can try to look into it, but probably not today

urban nexus
timber wigeon
#

I think it would be better to leave it for the future if that's okay πŸ˜„

#

as I said, there shouldn't be any issues in most cases

#

and at some point we can hopefully implement it properly

urban nexus
#

we can revisit this when we're building a unified drawing crate

patent sequoia
urban nexus
strange kettle
#

But we would need an export to triangles + textures

fickle leaf
#

No?

#

Gpu accelerated rendering πŸ™‚

patent sequoia
#

Or like

#

actually, is there external script invoke support?

fickle leaf
patent sequoia
#

Probably.

patent sequoia
fickle leaf
#

You just destroyed part of @strange kettle's soul

patent sequoia
#

I'll do it again

fickle leaf
#

No there's no shell escape, but wasm plugins serve that purpose

patent sequoia
#

I think Discord's search really dislikes the threads in #contributors

#

so I can't conveniently search

#

but the reason I'm popping in here is to ask where there are plans to to use the platform specfic APIs for the color emojis since everybody implemented their own version

#

Apple has their own TTF extension, Google did theirs, and MS decided to work extra hard by making two color emoji standards (if I remember right)

#

And then there's the awful 3D emoji features mentioned earlier (I think)

urban nexus