Exemplo n.º 1
0
def _load_ttglyph(g, ttfont, cmap):
    glyph = Glyph()
    glyph._name = g

    if g in cmap:
        glyph._unicodes = list(cmap[g])
    else:
        glyph._unicodes = []
    glyph._contours = []

    _load_ttcategory(glyph, ttfont, g)

    ttglyph = ttfont.getGlyphSet()[g]._glyph  # _TTGlyphGlyf object
    for i in range(0, max(ttglyph.numberOfContours, 0)):
        c = _load_contour(ttglyph, i)
        c._glyph = glyph
        glyph._contours.append(c)

    glyph._width = ttfont["hmtx"][g][0]
    glyph._leftMargin = ttfont["hmtx"][g][1]
    glyph._height = ttfont["hhea"].ascent
    if glyph.bounds:
        glyph._rightMargin = glyph._width - glyph.bounds[2]

    if hasattr(ttglyph, "components"):
        for c in ttglyph.components:
            comp = _load_component(c)
            comp._glyph = glyph
            glyph._components.append(comp)

    return glyph
Exemplo n.º 2
0
def _load_otglyph(g, ttfont, cmap):
    glyph = Glyph()
    glyph._name = g

    if g in cmap:
        glyph._unicodes = list(cmap[g])
    else:
        glyph._unicodes = []
    glyph._contours = []

    _load_ttcategory(glyph, ttfont, g)

    ttglyph = ttfont.getGlyphSet()[g]
    pen = RecordingPen()
    ttglyph.draw(pen)
    contours = pen.value
    lastcontour = []
    startPt = (0, 0)
    lastPt = (0, 0)
    index = 0
    for c in contours:
        if c[0] == "moveTo":
            startPt = c[1][0]
        elif c[0] == "closePath":
            if startPt != lastPt:
                lastcontour.append(_load_point(startPt, segmentType="line"))
            contour = Contour()
            contour._points = lastcontour
            contour._correct_direction()
            glyph._contours.append(contour)
            lastcontour = []
        elif c[0] == "curveTo":
            lastcontour.append(_load_point(c[1][0], segmentType="offcurve"))
            lastcontour.append(_load_point(c[1][1], segmentType="offcurve"))
            lastcontour.append(_load_point(c[1][2], segmentType="curve"))
            lastPt = c[1][2]
        elif c[0] == "lineTo":
            lastcontour.append(_load_point(c[1][0], segmentType="line"))
            lastPt = c[1][0]
        elif c[0] == "qCurveTo":
            self.raiseNotImplementedError()

    glyph._width = ttfont["hmtx"][g][0]
    glyph._leftMargin = ttfont["hmtx"][g][1]
    glyph._height = ttfont["hhea"].ascent
    if glyph.bounds:
        glyph._rightMargin = glyph._width - glyph.bounds[2]

    # CFF glyphs do not have components as such

    return glyph
Exemplo n.º 3
0
def _load_gslayer(gslayer, layer):  # -> Glyph
    glyph = Glyph()
    glyph._layer = layer
    glyph._name = gslayer.parent.name
    if gslayer.parent.unicode:
        glyph._unicodes = [int(gslayer.parent.unicode, 16)]
    else:
        glyph._unicodes = []
    glyph._width = gslayer.width
    glyph._height = gslayer.master.ascender - gslayer.master.descender  # ?
    glyph.exported = gslayer.parent.export
    glyph._lib = Lib()
    glyph._lib.glyph = glyph
    if gslayer.parent.lastChange:
        glyph._lib[
            "com.schriftgestaltung.lastChange"] = gslayer.parent.lastChange

    c = gslayer.parent.category
    sc = gslayer.parent.subCategory
    if c:
        glyph._lib["com.schriftgestaltung.Glyphs.category"] = c
    if sc:
        glyph._lib["com.schriftgestaltung.Glyphs.subcategory"] = sc
    if sc == "Ligature":
        glyph._lib["public.openTypeCategory"] = "ligature"
    if c == "Mark":
        glyph._lib["public.openTypeCategory"] = "mark"
    else:
        glyph._lib["public.openTypeCategory"] = "base"
    glyph._contours = [_load_gspath(p, glyph) for p in gslayer.paths]
    glyph._anchors = [_load_gsanchor(a, glyph) for a in gslayer.anchors]
    return glyph
Exemplo n.º 4
0
def _load_glyph(g, layer, master):  # -> Glyph
    glyph = Glyph()
    glyph._layer = layer
    glyph._name = g["name"]
    glayer = None

    for l in g["layers"]:
        if l["name"] == master["name"]:
            glayer = l
    if not glayer:
        raise ValueError

    if "unicode" in g:
        glyph._unicodes = [int(g["unicode"], 16)]
    else:
        glyph._unicodes = []
    glyph._width = glayer["advanceWidth"]
    glyph._height = master["ascender"] - master["descender"]  # ?
    glyph._lib = Lib()
    glyph._lib.glyph = glyph

    if hasattr(g, "openTypeGlyphClass"):
        if g.openTypeGlyphClass == 1:
            glyph._lib["public.openTypeCategory"] = "base"
        if g.openTypeGlyphClass == 2:
            glyph._lib["public.openTypeCategory"] = "ligature"
        if g.openTypeGlyphClass == 3:
            glyph._lib["public.openTypeCategory"] = "mark"

    glyph._contours = []
    glyph._components = []
    if "elements" in glayer:
        for element in glayer["elements"]:
            if "component" in element:
                glyph._components.append(_load_component(element, glyph))
            else:
                for c in element["elementData"]["contours"]:
                    glyph._contours.append(_load_contour(glyph, c["nodes"]))
    # Guidelines

    return glyph
Exemplo n.º 5
0
def _load_dcglyph(dcglyph, layer):
    glyph = Glyph()
    glyph._layer = layer
    glyph._lib = Lib()
    glyph._lib.glyph = glyph
    for k, v in dcglyph.lib.items():
        glyph._lib._setItem(k, copy(v))
    glyph._name = dcglyph.name
    glyph._unicodes = copy(dcglyph.unicodes)
    glyph._width = dcglyph.width
    glyph._height = dcglyph.height
    # components, anchors, guidelines, image
    glyph._components = [
        _load_dccomponent(c, glyph) for c in dcglyph.components
    ]
    glyph._contours = [_load_dccontour(p, glyph) for p in dcglyph]
    glyph._anchors = [_load_dcanchor(a, glyph) for a in dcglyph.anchors]
    return glyph