Skip to content
Advertisement

How can I get a glyph with holes(Python)?

These are frameworks that I use:

from pdf2image import convert_from_path
from PIL import Image, ImageChops
import cv2
import numpy as np
from shapely.geometry import Polygon
import svgwrite
import json
from defcon import Font
import ufo2ft
from fontTools import svgLib

I have a svg file looks like the image below this sentence(The image is upside-down).

SVG file

I load this file and add to Defcon.Font like this:

glyph = font.newGlyph(name=korean_unicode_list[int(key)])
glyph.unicode = int(korean_unicode_list[int(key)], 16)
pen = glyph.getPen()
svg = svgLib.SVGPath("svg_files/" + str(key) + ".svg")
svg.draw(pen)

But after I export this Font object with ufo2ft, The glyph’s hole has disappeared :(

ttf = ufo2ft.compileTTF(font)
ttf.save('myFont.ttf')

After Export

I don’t know how to make holes at glyphs. I’m guessing that there is a solution at pen object and its methods, but there is no example about glyph with holes. How can I get a glyph with holes?

Advertisement

Answer

I got a solution myself :)

I tested with Adobe Illustrator. I made ‘0’-shaped object and saved in svg file. When I export a font file with the svg file, there was a hole.

So I opened the svg file at PyCharm, there’s a option name ‘xml:space’. If its option set to “preserve”, svgPath can draw a path with holes.

I hope this article help you.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement