Inkscape.org
Beyond the Basics SVG with Embedded Fonts
  1. #1
    Jason Morse Jason Morse @jberd126

    Hello all,

    I have an SVG that was exported from ESRI ArcGIS Pro that has embedded fonts. I am trying to import it into Microsoft Word but the fonts are not rendering properly.

    In Inkscape, is there a way to accomplish all of the following via the command line (headless)?

    1. In an SVG with embedded woff fonts (fonts not installed locally),
    2. For all text,
      • Duplicate text blocks as transparent (to make text searchable)
      • Convert objects to paths (to ensure correct rendering)
    3. And re-save as SVG.

    I have been able to hack together a script to do all of the above except "Duplicate text blocks as transparent".

    Any pointers would be appreciated.

  2. #2
    inklinea inklinea @inklinea⛰️

    I wasn't aware Inkscape 1.1 or 1.2 could access and display embedded fonts.

    In order to correctly display the fonts they would have to be installed locally at least on your machine.

    The only way I can think to do it, is to select by element : text, then duplicate, then convert that duplication to paths, then select by element : text again -

    however at that point it's a bit difficult to change the visibilty of the text - and the text selection would not line up with the original text unless the target system has the font installed or you are using a browser which supports embedded fonts.

    I've not actually tried calling an extension to act upon the current command line selection - that would allow the setting of the font fill ( and stroke if it has it ) to none.

     

  3. #3
    Jason Morse Jason Morse @jberd126

    The intent for the overlaid, invisible text is to make the SVG act like an OCR'd PDF file with searchable text. I am not overly concerned about the text not aligning perfectly.

    To make all this work (with exception of invisible text) is overly convoluted.
    Roughly, the steps are

    1. In SVG, extract embedded font-face data from styles into files [XML/CSS]
    2. Extract font info from font data files [Python/fonttools]
    3. In SVG, update font-family attribute to use extracted font family from above. Needed to keep font linkage. [XML/CSS]
    4. Convert font file (e.g. woff) to the underlying type as needed (OpenText or TrueType[Python/fonttools]
    5. Create a temporary directory to be used for Inkscape profile. The avoids having fonts needing to be installed into the system.
    6. Copy converted fonts into the temporary Inkscape profile\fonts directory.
    7. Set environment variable INKSCAPE_PROFILE_DIR = temporary Inkscape profile directory
    8. Execute Inkscape command line to convert SVG to SVG
      inkscape.com --export-filename EXPORT.SVG --export-type svg --export-plain-svg --export-text-to-path IMPORT.SVG
    9. Delete temporary Inkscape profiles directory
  4. #4
    inklinea inklinea @inklinea⛰️

    If you are using Inkscape 1.1, it's not possible to call verbs headlessly.

    If you are using Inkscape 1.2, verbs are now actions, so it can be done headlessly.

    There is an action in 1.2 'paste-style'

    So in 1.2 : 

    If you were to introduce a standard dummy element at the end of each svg using your script ( just before </svg>).

    For example a 1px <rect> with style="fill:none;stroke;none" with a known id.

    Then you could 

    select-by-id:rect_id

    copy

    select-by-element:text

    paste-style

    select-by-element:tspan ( this may not be required but allows for svgs with inline style on tspan )

    paste-style

    That would result in the none stroke and none fill being applied to all text and tspan elements

  5. #5
    inklinea inklinea @inklinea⛰️

    I probably should have explained, it's generally better to avoid using options ( unless there is no other option or it's just something simple )

    It's better to use --actions="action1:value;action2:value" - as it allows control of the order

    If you are using 1.2 - you can use 

    inkscape --action-list

    to get a list of actions