Command-line tool for converting TTF/OTF fonts to SVG

前端 未结 3 1385
南笙
南笙 2020-12-29 05:53

Does anyone know of a command-line tool that will convert both TTF and OTF fonts to SVG fonts?

相关标签:
3条回答
  • 2020-12-29 06:12

    The batik part of this answer is also out of date because batik gives you an svg output using the deprecated glyph element.

    If you run the latest version of batik on the nasa.ttf for example

    java -jar batik-ttf2svg-1.10.jar nasa.ttf -o myfont.svg
    

    you get an output that looks something like this

    <font horiz-adv-x="1045" ><font-face
    font-family="Nasa"
    units-per-em="2048"
    panose-1="2 11 5 0 0 0 0 0 0 0"
    ascent="1507"
    descent="-393"
    alphabetic="0" />
    

    ....followed by much more code representing every glyph in font

    the way to deal with this is represented in the answer at Use SVG glyph tag in HTML - turn glyphs into symbols and flip them.

    As far as why the fonts are flipped on their X axis refer to the superseded part of spec https://www.w3.org/TR/SVG11/fonts.html#SVGFontsOverview

    Unlike standard graphics in SVG, where the initial coordinate system has the y-axis pointing downward (see The initial coordinate system), the design grid for SVG fonts, along with the initial coordinate system for the glyphs, has the y-axis pointing upward for consistency with accepted industry practice for many popular font formats.

    0 讨论(0)
  • 2020-12-29 06:22

    The fontforge recipe given previously by @Erik no longer works - fontforge has switched to Python scripting.

    Here's how I converted a font from PFA to SVG on the command line - this will also work fine for TTF, etc.:

    fontforge -c 'import fontforge;fontforge.open("/usr/share/fonts/X11/Type1/NachlieliCLM-Bold.pfa").generate("NachlieliCLM-Bold.svg")'
    
    0 讨论(0)
  • 2020-12-29 06:28

    You can use fontforge or batik to do this from the commandline.

    With fontforge (see scripting documentation):

    #!/usr/bin/fontforge
    Open($1)
    Generate($1:r + ".svg")
    

    Save the above to convert2svgfont.pe file, then invoke as:

    convert2svgfont.pe myfont.ttf
    

    For batik see this documentation, install and then invoke as:

    java -jar batik-ttf2svg.jar myfont.ttf -o myfont.svg
    
    0 讨论(0)
提交回复
热议问题