-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
feature request: use of @font-face #2
Comments
Thanks for your suggestion. I have to think about it a bit more before I assess whether it works in a generic way. Launchpad Details: #LPC Martin Gieseking - 2013-08-23 15:02:50 +0200 |
This would indeed be an awesome addition. Especially since it allows us to use tex directly to produce vector images of formulas, which could be embedded on a web page. The real challenge would be unencoded glyphs, such as big math operators, which cannot be accessed directly from SVG. The easiest way of solving this problem is to create a slightly modified copy of the font, where all the glyphs are encoded (possibly with unused glyphs removed). The font license could be a problem, but I guess most math fonts are free to use and modify. |
Hi, I just started playing with dvisvgm and came across the same idea as presented here. |
@thomas001 You might be interested in the tex.sx question http://tex.stackexchange.com/questions/282340/how-to-create-non-outlined-svg-files-from-latex-formulae where I and Martin discuss the matter. Some main points:
|
I would like to make the following suggestions:
|
@tantau Good to hear that others are interested in this feature as well :-) |
I agree that a feature to support native font references would be useful. However, it requires a lot of code refactorings to implement it properly. Because of other commitments I don't have enough free time to work on it at the moment. So please don't expect this feature to be available soon. Here is a first list of things to be considered when implementing the new option
The support of LuaTeX is a different story. Unfortunately, there's no easy way to determine the glyph indexes of the unmapped characters from the LuaTeX DVI files. Some stuff of the LuaTeX code had to be duplicated to get the proper information. Maybe it's possible to add further information about the characters to the DVI file (via specials, for example). But this should be implemented by the LuaTeX team first. |
@mgieseki I can easily imagine that it takes a lot of effort to do this properly, especially because of the stretch/slant/embolden properties that might be present in the dvi file. In the meantime, would you consider adding descriptive names to the fonts that you embed in the svg file? At the moment, they are all named 'nf0', 'nf1' etc. If I could only get hold of the font name, I could post-process the SVG so that it only uses native fonts. I'm not going to need the stretch/slant/embolden features anyway. |
@pnsaevik Would it help to add a comment with the file names to each CSS font rule (see this patch)? I can't use the font family name as ID because it's not unique across font files and would require some fiddling to derive a valid ID. |
What about a slight different proposal: |
As far as I know, pdf2htmlEX uses FontForge to handle all the font stuff. I don't know much about the FontForge internals and can't estimate yet how much work it would be to add WOFF font generation. Probably much more than I can currently afford. But if you're aware of a C/C++ library or FontForge wrapper that can easily be used to re-encode OTF fonts and wrap them into WOFF files, let me know. |
@mgieski Yeah, that looks like precisely what I need! I haven't tried to build your code though, is it hard to set up? Or could you possibly release a new version with the proposed patch...? @thomas001 As long as we have a code to generate custom font files, it is a secondary issue whether the font is .woff or .otf (they are quite similar, although .woff is better for web usage). I have already a python script that creates custom .otf files, and could probably extend it to .woff as well. It uses the font library FontTools/ttx. Don't know how easy it would be to integrate with Martin's code. |
I hacked a bit font support using fontforge. I don't know if the generation is really correct, but maybe it is a good starting point. You can have a look at https://github.com/thomas001/dvisvgm . |
@thomas001 This looks like awsome stuff indeed 👍 A couple of questions:
|
@thomas001 Thank you for taking the time to dig into the details of FontForge and for patching the dvisvgm code to create WOFF files. Since FontForge is a big font editor application that doesn't work well on Windows systems (mostly because of its X11 dependencies), I'm a bit reluctant to rely on this external application. I'd rather link only a portion of the required FontForge code, e.g. as done by LuaTeX and pdf2htmlEX. Maybe pdf2htmlEX' FontForge wrapper ffw can be used here. I have to investigate this further. @pnsaevik I'll add a new option |
@mgieseki Thanks Martin, the new option works like a charm and is exactly what I need. I'll be sure to make good use of it :-) @thomas001 I can understand Martin's reluctancy towards relying on fontforge being correctly installed on the system. Still, your solution with base64-encoded woff fonts is exactly what is needed here. Would it be an idea if you rewrite your patch as a standalone tool, which parses Martin's svg files, finds the embedded svg font information, and converts them to base64 woff? This would be equally useful to end users, and possibly have a broader domain of application as well. And Martin can keep his code clean and lean :-) |
Yesterday, I had a closer look at the FonfForge sources. It seems that it shouldn't be too complicated to remove all the GUI and most unused gnulib stuff from libfontforge and create a stripped-down variant. I have already a first version that compiles successfully on Windows as well. It needs some more testing, though. |
I finally found some time to add support for embedding the fonts in TTF, WOFF, or WOFF2 format rather than SVG (new option |
This is great news! I'm very much looking forward to seeing the new release ;-) |
dvisvgm 2.0.1 is already available in the Release section. :-) A few more information on how to use the new option can be found on the news page and in the manual. |
Martin, this is truly marvelous :-) I now intend to write an extension to Python-Markdown, which would allow us to write Markdown with LaTeX math, and convert it to HTML/SVG using dvisvgm. I believe this would produce superior results compared to MathJax and KaTeX for static documents, since these alternatives renders math on-the-fly. But with upcoming conferences and submission deadlines, I'll have to wait a couple of weeks... |
I couldn't let go of this... so I've spent some time fiddling around with it anyway. I now have a python script that grabs I have a problem though: It seems that dvisvgm doesn't like math that is created with the unicode-math package. The svg images seems to be cropped to the wrong size, for some reason. To reproduce, use the following MWE:
|
I'm glad to hear that you find the new additions helpful and that you're trying them out. |
Thanks, this certainly solves the problem with the bounding box. But is there a way to extract the baseline of the text from the svg? For an inline equation, I need to shift the svg slightly downwards in order to make it align with the baseline of the surrounding text. |
OK, I see. The easiest way to get height/depth values is to use the \documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}
\usepackage[dvips,active,tightpage]{preview}
\begin{document}
\begin{preview}
$E = mc^2$
\end{preview}
\end{document} Since a plain DVI/XDV file doesn't contain any explicit information about the baselines, it's hard to extract reliable values from it. The preview package adds some more data that helps to compute the proper width, height and depth of the graphics. If dvisvgm finds preview data in a DVI file, it prints two additional lines of output to the console, e.g.
You can parse them and use the depth value to adjust the vertical position of the graphics to line them up with surrounding text. The |
A very good suggestion, but unfortunately this does not seem to work when --exact is used (I get a depth of zero..). On the other hand, when --exact is used, it seems like the viewBox attribute of |
I just had a closer look at the problem and found a stupid sign bug introduced with version 2.0. It leads to negative depth values for native fonts. That's why the equation is cropped without |
Hi, this is not a bug, but a feature request. However, I did not find a special forum for posting feature requests, so I put this here...
I would like to request that future versions of dvisvgm support the
@font-face
feature of CSS (http://www.w3.org/TR/2008/REC-CSS2-20080411/fonts.html#font-descriptions) to embed a link to the original OpenType / Type1 / whatever fonts into the generated SVG files alongside the embedded<font>
element.The idea would be that
produces something like this:
Note the added
@font-face
. At least on Safari, this causes the fonts to be rendered using the real OpenType font, if the font is available at the specified URL and, if not, the embedded font is used as a fallback.I know this is kind of tough to implement since it is hard to "tell" where the actual fonts are and it is not clear what the URLs should look like (absolute? relative? should the fonts be copied?). However, if one wishes to use SVG as a replacement for PDF during a presentation or for longer text to be read online, high-quality fonts would be a real plus.
Launchpad Details: #LP1215875 Till Tantau - 2013-08-23 12:52:29 +0200
The text was updated successfully, but these errors were encountered: