Skip to content
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

SVG font: extract SVG per character #1192

Closed
alisa-patotskaya opened this issue Sep 28, 2018 · 18 comments
Closed

SVG font: extract SVG per character #1192

alisa-patotskaya opened this issue Sep 28, 2018 · 18 comments

Comments

@alisa-patotskaya
Copy link

Hello!

I have a question regarding mapping of SVG to UTF character: I need to extract from a font SVG corresponding to a UTF character. In hb-ot-color-svg-table.hh I found the way to load all the SVGs, but that's not particularly what I need, cause it's very memory consuming + there is no understanding between UTFs and SVGs mapping.
Here is a vector emojis font I am using: https://drive.google.com/file/d/1p2Z1WLrbYZX_LWJPD0bXfus27cd4bFqM/view?usp=sharing

Do you have any suggestions?
Thank you in advance.

@ebraminio
Copy link
Collaborator

Memory consuming? How? :)

You can download them from https://github.com/twitter/twemoji/tree/gh-pages/2/svg also

@ebraminio
Copy link
Collaborator

You can go for this

  1. Use dump-emoji from harfbuzz to dump all the SVGs
  2. Pass all the known SVGs to hb-shape (from harfbuzz), and get their glyph ids numbers
  3. Match those numbers with the file saved by dump-emoji

You know, creating a perfect dumper is not that easy but I guess that suits your need

Am closing this issue but feel free to continue the discussion if you had any question :)

@alisa-patotskaya
Copy link
Author

alisa-patotskaya commented Oct 1, 2018

Hello @ebraminio,

Thank you for your reply.

Memory consuming? How? :)

Instead of loading SVGs one by one to memory when a user requested a character to be rendered, I will have to load into memory all SVGs no matter whether or not they were actually used. Thus generation of all SVGs from the font does not solve the problem, because what we need is to load only specific SVG per character. Does this functionality exist?

Pass all the known SVGs to hb-shape (from harfbuzz), and get their glyph ids numbers

I wasn't able to find the part of hb_shape which takes SVG as an input. Could you please give more details here?

I would consider this problem as still open, as a main issue - loading SVGs one by one is not solved.

Thank you.

@ebraminio
Copy link
Collaborator

Instead of loading SVGs one by one to memory when a user requested a character to be rendered, I will have to load into memory all SVGs no matter whether or not they were actually used. Thus generation of all SVGs from the font does not solve the problem, because what we need is to load only specific SVG per character. Does this functionality exist?

Oh, you don't have to. If you glyph id, you can retrieve that glyph like this https://github.com/harfbuzz/harfbuzz/blob/master/src/hb-ot-color-svg-table.hh#L118-L119 see "entry.startGlyphID, entry.endGlyphID)" part, one can write a binary search

The issue is however use of SVG is not publicly available till the fix #881. If you can't private API of harfbuzz (that is likely going to break) you should follow that issue.

I wasn't able to find the part of hb_shape which takes SVG as an input. Could you please give more details here?

Oh that's not what harfbuzz as a library is responsible for. HarfBuzz main business is to get characters and give glyph ids from fonts and their [relative] position. What we like to implement on HarfBuzz for SVG table is to just return SVG blob for a given SVG but even if we don't, our client are able to do already without HarfBuzz, they just have the same logic by their own, which could be easy or hard given utilities they have on their project.

Generally this is out of scope for harfbuzz (except #881 part) a as a project but I personally really like to help you so feel free to continue if you had question :)

@alisa-patotskaya
Copy link
Author

Hello @ebraminio ,

Thank you for your response!

Oh, you don't have to. If you glyph id, you can retrieve that glyph like this https://github.com/harfbuzz/harfbuzz/blob/master/src/hb-ot-color-svg-table.hh#L118-L119 see "entry.startGlyphID, entry.endGlyphID)" part, one can write a binary search

How should I get the glyph ID per character if we are talking about vector font? Does the regular font parsing from harfbuzz work for SVG fonts as well?

Thanks 👍

@ebraminio
Copy link
Collaborator

ebraminio commented Oct 2, 2018 via email

@alisa-patotskaya
Copy link
Author

Thanks a lot @ebraminio!

@ebraminio
Copy link
Collaborator

ebraminio commented Oct 2, 2018 via email

@ebraminio
Copy link
Collaborator

Next version of HarfBuzz will support SVGs publicly, let me know if anything needed.

@scientificware
Copy link

@ebraminio Sorry to intrude in this conversation but :
What do you mean by

Next version of HarfBuzz will support SVGs

Can we send a SVG file to HarfBuzz ?

@ebraminio
Copy link
Collaborator

SVG-in-OT is a technique to embed SVG files inside font files for Emojis, the next version of harfbuzz can offer that embedded SVG files access to HarfBuzz library clients, but that is just a small part of the work as clients should render those files for themelves. It will be easy for browsers as they already are able to render those but other clients should incorporate something like librsvg to render those.

@scientificware
Copy link

@ebraminio Thank you very much for all information.
But I'm a bit confuse with HarfBuzz, Freetype ... could you give me some links where I can find documentations :
I'm trying to implement Stretchy Glyphs for a mathematical application.
I'm aware that Fred. Wang from Igalia made a proposition to render these glyphs in HarfBuzz but it was refused.
I want to explore another way : have a glyph factory embedded in my application which will send the sized glyph to the rendering engine. I already built these glyphs as SVG path in my Java Application but I'm using the graphic API and I lost all effects apply to other glyphs.
In fact, I wanted to know if I can directly send a glyph shape to the font engine.
Regards.

@ebraminio
Copy link
Collaborator

http://behdad.org/text/

Math is not my area of expertise :)

I wanted to know if I can directly send a glyph shape to the font engine.

That is freetype, nothing to do with harfbuzz AFAICS, I guess not

@khaledhosny
Copy link
Collaborator

HarfBuzz does not (currently) do rasterization, and even if it did it is very highly unlikely it will be supporting SVG outlines. You can simply add the stretchy glyph to a font file and use it in your application (directly accessing the font and the glyphs).

The above proposed math shaping API is a high level one, but if your application supports OpenType MATH table, HarfBuzz provides enough API to get the data from the table ans do the shaping part yourself, XeTeX, Firefox and Webkit do this AFAIK.

@scientificware
Copy link

@ebraminio @khaledhosny Great thanks a lot for answers and all information.

  • I know this Behdad text but may be I should read it again :)
  • I also know how Webkit works because I repaired MathML support in Java and JavaFX/OpenJFX last versions.
  • Of course, I could implement this second solution and shape by myself but I think that it's "ancestral" method.
  • I already implement the first method for big signs like sum, integral, ... . But I'm writing an editor and it's not appropriate.

That why I want to do the same thing but without using a font file.
If Harfbuzz doesn't support SVG, may I can use the format that Harfbuzz use after loading the font file ?
I'm just looking for an entry point in the code explore that way.

@ebraminio
Copy link
Collaborator

ebraminio commented Oct 31, 2018

I think we are a bit confused on what you want, harfbuzz is not doing any rendering and freetype is where you should have a look, maybe you can pick some parts of their renderer to feed it to your paths. Or maybe https://github.com/behdad/glyphy can help you, who knows :)

@scientificware
Copy link

@ebraminio Thanks for suggestions.

@ebraminio
Copy link
Collaborator

Given my Android experience [not JavaFX], I may have a good suggestion for you, have a look at PathParser, it parses SVG like paths. It translated path data to Android's Path API if you can find something similar on standard Java--I am sure there should be--you can render your SVG like paths by your own also I believe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants