Пример #1
0
    def draw(self, saving=False, saveTo=None, fmt="pdf", layers=[], fill=None):
        savingToFont = isinstance(fmt, defcon.Font)
        if saving:
            db.newDrawing()
            self.saving = True
        else:
            self.saving = False

        db.newPage(*self.animation.dimensions)
        self.page = Rect.page()

        self.bps = {}
        for l in layers:
            self.bps[l] = RichBezier()

        with db.savedState():
            if fill and not saveTo:
                with db.savedState():
                    db.fill(*fill)
                    db.rect(*self.page)
            self.layers = layers
            self.animation.fn(self)
            self.layers = None
        if self.animation.burn:
            box = self.page.take(64,
                                 Edge.MinY).take(120,
                                                 Edge.MaxX).offset(-24, 24)
            db.fontSize(20)
            db.lineHeight(20)
            db.font("Menlo-Bold")
            db.fill(0, 0.8)
            db.rect(*box.inset(-14, -14).offset(0, 2))
            db.fill(1)
            db.textBox("{:07.2f}\n{:04d}\n{:%H:%M:%S}".format(
                self.time, self.i, datetime.datetime.now()),
                       box,
                       align="center")

        for k, bez in self.bps.items():
            with db.savedState():
                db.fill(*bez.fill)
                db.drawPath(bez.bp)

        if saving:
            if savingToFont:
                for k, bez in self.bps.items():
                    g = defcon.Glyph()
                    g.name = "frame_" + str(self.i)
                    g.unicode = self.i + 48  # to get to 0
                    g.width = self.animation.dimensions[0]
                    bez.bp.drawToPen(g.getPen())
                    fmt.insertGlyph(g)
            else:
                db.saveImage(f"{saveTo}/{self.i}.{fmt}")
            db.endDrawing()

        self.saving = False
Пример #2
0
def DISABLED_test_check_glyphnames_max_length():
    """ Check that glyph names do not exceed max length. """
    from fontbakery.profiles.universal import com_google_fonts_check_glyphnames_max_length as check
    import defcon
    import ufo2ft

    # TTF
    test_font = defcon.Font(TEST_FILE("test.ufo"))
    test_ttf = ufo2ft.compileTTF(test_font)
    status, _ = list(check(test_ttf))[-1]
    assert status == PASS

    test_glyph = defcon.Glyph()
    test_glyph.unicode = 0x1234
    test_glyph.name = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
                       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
                       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    test_font.insertGlyph(test_glyph)

    test_ttf = ufo2ft.compileTTF(test_font, useProductionNames=False)
    status, _ = list(check(test_ttf))[-1]
    assert status == FAIL

    test_ttf = ufo2ft.compileTTF(test_font, useProductionNames=True)
    status, _ = list(check(test_ttf))[-1]
    assert status == PASS

    # Upgrade to post format 3.0 and roundtrip data to update TTF object.
    test_ttf["post"].formatType = 3.0
    test_file = io.BytesIO()
    test_ttf.save(test_file)
    test_ttf = TTFont(test_file)
    status, message = list(check(test_ttf))[-1]
    assert status == PASS
    assert "format 3.0" in message

    del test_font, test_ttf, test_file  # Prevent copypasta errors.

    # CFF
    test_font = defcon.Font(TEST_FILE("test.ufo"))
    test_otf = ufo2ft.compileOTF(test_font)
    status, _ = list(check(test_otf))[-1]
    assert status == PASS

    test_font.insertGlyph(test_glyph)

    test_otf = ufo2ft.compileOTF(test_font, useProductionNames=False)
    status, _ = list(check(test_otf))[-1]
    assert status == FAIL

    test_otf = ufo2ft.compileOTF(test_font, useProductionNames=True)
    status, _ = list(check(test_otf))[-1]
    assert status == PASS
Пример #3
0
def DISABLED_test_check_glyphnames_max_length():
    """ Check that glyph names do not exceed max length. """
    check = CheckTester(universal_profile,
                        "com.google.fonts/check/glyphnames_max_length")
    import defcon
    import ufo2ft

    # TTF
    test_font = defcon.Font(TEST_FILE("test.ufo"))
    ttFont = ufo2ft.compileTTF(test_font)
    assert_PASS(check(ttFont))

    test_glyph = defcon.Glyph()
    test_glyph.unicode = 0x1234
    test_glyph.name = ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
                       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
                       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    test_font.insertGlyph(test_glyph)
    ttFont = ufo2ft.compileTTF(test_font, useProductionNames=False)
    assert_results_contain(check(ttFont), FAIL,
                           None)  # FIXME: This needs a message keyword

    ttFont = ufo2ft.compileTTF(test_font, useProductionNames=True)
    assert_PASS(check(ttFont))

    # Upgrade to post format 3.0 and roundtrip data to update TTF object.
    ttFont["post"].formatType = 3.0
    _file = io.BytesIO()
    _file.name = ttFont.reader.file.name
    ttFont.save(_file)
    ttFont = TTFont(_file)
    message = assert_PASS(check(ttFont))
    assert "format 3.0" in message

    del test_font, ttFont, _file  # Prevent copypasta errors.

    # CFF
    test_font = defcon.Font(TEST_FILE("test.ufo"))
    ttFont = ufo2ft.compileOTF(test_font)
    assert_PASS(check(ttFont))

    test_font.insertGlyph(test_glyph)
    ttFont = ufo2ft.compileOTF(test_font, useProductionNames=False)
    assert_results_contain(check(ttFont), FAIL,
                           None)  # FIXME: This needs a message keyword

    ttFont = ufo2ft.compileOTF(test_font, useProductionNames=True)
    assert_PASS(check(ttFont))
Пример #4
0
def _save_glyph(glyph):
    dcglyph = defcon.Glyph()
    dcglyph.unicodes = copy(glyph._unicodes)
    for c in glyph.contours:
        dccontour = _save_contour(c)
        dcglyph.appendContour(dccontour)
    # Anchors
    for a in glyph.anchors:
        dcglyph.appendAnchor(_save_anchor(a))

    for k, v in glyph.lib._dict.items():
        if k == "glyph":
            continue
        dcglyph.lib[k] = copy(v)
    dcglyph.rightMargin = glyph.rightMargin
    dcglyph.leftMargin = glyph.leftMargin
    dcglyph.width = glyph.width
    dcglyph.name = glyph.name
    return dcglyph
Пример #5
0
def mergeContours(glyph):
    # remember stuff that get's lost when drawing to a fontforge glyph
    width = glyph.width
    vwidth = glyph.vwidth
    anchorPoints = tuple(glyph.anchorPoints)

    # make a defcon glyph
    dcGlyph = defcon.Glyph()
    dcGlyphPen = dcGlyph.getPen()

    # draw to dcGlyph
    glyph.draw(dcGlyphPen)

    # union of dcGlyph
    result = BooleanGlyph(dcGlyph).removeOverlap()
    targetPen = glyph.glyphPen()
    result.draw(targetPen)

    # restore stuff that a pen should rather not change automagically
    # in fact, the pen should not reset anything besides outline and components.
    glyph.width = width
    glyph.vwidth = vwidth
    [glyph.addAnchorPoint(*p) for p in anchorPoints]
Пример #6
0
versionFigures = [mapping[x] for x in version]
majorVersion, minorVersion = version.split(".")

for ufo in glob.glob("source/*.ufo"):
    print(ufo)
    font = defcon.Font(ufo)

    # Set metadata
    font.info.versionMajor = int(majorVersion)
    font.info.versionMinor = int(minorVersion)
    font.info.openTypeNameVersion = "Version " + version + versionExtraInfo
    font.info.openTypeNameUniqueID = None

    # Insert version glyph
    versionGlyph = defcon.Glyph()
    versionGlyph.unicode = 0xEFFD
    advanceWidth = 0

    if "Mono" not in ufo:
        for figure in versionFigures:
            if "period" in figure:
                glyph = figure
            else:
                glyph = figure + "inferior"
            c = defcon.Component()
            c.baseGlyph = glyph
            c.transformation = (1, 0, 0, 1, advanceWidth, 0)
            advanceWidth += font[glyph].width
            versionGlyph.appendComponent(c)
    else: