wader / ansisvg

Convert ANSI to SVG
MIT License
89 stars 9 forks source link

Support embedded and external fonts #15

Closed wader closed 10 months ago

wader commented 10 months ago

@patrislav1 with this you should be able to do ... | ansisvg -fontfile UbuntuMono.woff2 but maybe you wanted to be able to refer to an external file also? i also noticed inkscape was not happy about it, not sure why yet

patrislav1 commented 10 months ago

This works for opening in browsers but, AFAICS, Inkscape does not support embedded fonts at all.

So I think to cover all use cases it would be even better to have two options (embedding & external linking)

wader commented 10 months ago

This works for opening in browsers but, AFAICS, Inkscape does not support embedded fonts at all.

Ok I should probably document that somehow.

So I think to cover all use cases it would be even better to have two options (embedding & external linking)

Should be quite easy add. Hardest is probably to decide on how the arguments should work. Any ideas? curl-ish -fontfile @path to embeds, -fontfile path to reference? or having -fontfile and -fontref etc is clearer?

Hmm get a feeling i should redo the whole argument parsing, why it looks and works the way it does now is mostly because how the standard library flags package works in golang.

patrislav1 commented 10 months ago

I like -fontfile and -fontref.

wader commented 10 months ago

Noticed now that this is probably broken, i got fooled by the fallback to monospace.

wader commented 10 months ago

Now it should work better. But i'm not sure if the "copy with control sequences" option in iterm2 that i used is weird or if i'm doing something.

This is how iterm2 renders the copied powerline ansi output:

Screenshot 2023-12-14 at 12 37 46

Same thru go run . -fontfile UbuntuMono.woff2 displayed in chrome:

Screenshot 2023-12-14 at 12 37 22

Same color mismatch hmm. Anyways let me know how it goes!

Also this brach have been rebased on top of master to have the params and color fixes

patrislav1 commented 10 months ago

Today I couldn't reproduce the color mismatch, but looked into an alignment issue of the filled background rects. One issue was that they were too big, b/c of the extra stroke around them but that was easy to fix. A much more difficult issue is vertical alignment. Turns out that the powerline symbols stretch over the whole character height, and this is somewhat offset to the ansisvg's model of how the text on screen looks like, as in "if you place text at y=0 it may well stretch into negative y territory"

When experimenting with different values for the offset it also turns out that it can have arbitrary (non-integer) numbers, so to apply it to the SVG template it will be necessary to support float (or at least fixed-point-integer) for coordinates. I'm afraid to fully understand this offset problem I first have to write a PhD about typesetting and reverse engineer how woff2 works internally. :rofl:

wader commented 10 months ago

Today I couldn't reproduce the color mismatch

With the param and colors fixes in master? without the param fix i think it probably was very broken.

but looked into an alignment issue of the filled background rects. One issue was that they were too big, b/c of the extra stroke around them but that was easy to fix.

🥳

A much more difficult issue is vertical alignment. Turns out that the powerline symbols stretch over the whole character height, and this is somewhat offset to the ansisvg's model of how the text on screen looks like, as in "if you place text at y=0 it may well stretch into negative y territory"

Oh hmm yes it's quiet hard to follow how all these things interact. Did you try to tweak and remove these https://github.com/wader/ansisvg/blob/master/svgscreen/template.svg?short_path=dc1f9da#L12-L13 i think they might control some of what your describing, not that i really understand what the different values does.

You mean this difference?

Screenshot 2023-12-14 at 20 44 07

When experimenting with different values for the offset it also turns out that it can have arbitrary (non-integer) numbers, so to apply it to the SVG template it will be necessary to support float (or at least fixed-point-integer) for coordinates. I'm afraid to fully understand this offset problem I first have to write a PhD about typesetting and reverse engineer how woff2 works internally. 🤣

😄 if it would help we can probably support some kind of decimal numbers somehow, maybe also for font size.

wader commented 10 months ago

If i look at the arrow codepoint 0xe0b0 in some font inspector like https://fontdrop.info/ it seem like it should be full-height-ish.

Screenshot 2023-12-14 at 21 03 57

Ah now i think i see what you mean by background rect alignment and negative y territory:

Screenshot 2023-12-14 at 21 08 08
patrislav1 commented 10 months ago

You mean this difference?

Screenshot 2023-12-14 at 20 44 07 Screenshot 2023-12-14 at 21 08 08

What you can see there (in both examples, IMHO) is two bugs on top of each other, the stroke bug (solved in the PR) and the vertical alignment bug. The vertical alignment bug is much easier to spot when the stroke bug is fixed. I'll try to look into these baseline attributes you pointed at - would be much easier to fix that way, than to retrieve a magic offset value from the font :exploding_head:

patrislav1 commented 10 months ago

Today I couldn't reproduce the color mismatch

With the param and colors fixes in master? without the param fix i think it probably was very broken.

Yep I tested with today’s master branch, seems your latest patches fixed it. 👍

wader commented 10 months ago

Looks ok to merge this btw? Good to not end up with too many parallell branches