Пример #1
0
 def test_glyph(self):
     self.assertIsNone(self.component.layer)
     self.glyph = self.font.newGlyph("A")
     self.component = Component(self.glyph)
     self.assertEqual(self.component.layer, self.glyph.layer)
     with self.assertRaises(AttributeError):
         self.component.layer = "foo"
Пример #2
0
 def test_glyph_dispatcher_new(self):
     font = Font()
     font.newGlyph("A")
     glyph = font["A"]
     pen = glyph.getPointPen()
     pen.beginPath()
     pen.addPoint((0, 0), segmentType="line")
     pen.addPoint((0, 100), segmentType="line")
     pen.addPoint((100, 100), segmentType="line")
     pen.addPoint((100, 0), segmentType="line")
     pen.endPath()
     contour = glyph[0]
     self.assertEqual(contour.getParent(), glyph)
     self.assertEqual(contour.dispatcher, font.dispatcher)
     component = Component()
     glyph.appendComponent(component)
     self.assertEqual(component.getParent(), glyph)
     self.assertEqual(component.dispatcher, font.dispatcher)
     anchor = Anchor()
     glyph.appendAnchor(anchor)
     self.assertEqual(anchor.getParent(), glyph)
     self.assertEqual(anchor.dispatcher, font.dispatcher)
     guideline = Guideline()
     glyph.appendGuideline(guideline)
     self.assertEqual(guideline.getParent(), glyph)
     self.assertEqual(guideline.dispatcher, font.dispatcher)
Пример #3
0
 def test_glyph_dispatcher_inserted(self):
     font = Font()
     font.newGlyph("A")
     glyph = font["A"]
     pen = glyph.getPointPen()
     pen.beginPath()
     pen.addPoint((0, 0), segmentType="line")
     pen.addPoint((0, 100), segmentType="line")
     pen.addPoint((100, 100), segmentType="line")
     pen.addPoint((100, 0), segmentType="line")
     pen.endPath()
     contour = glyph[0]
     component = Component()
     glyph.appendComponent(component)
     anchor = Anchor()
     glyph.appendAnchor(anchor)
     guideline = Guideline()
     glyph.appendGuideline(guideline)
     sourceGlyph = glyph
     newFont = Font()
     insertedGlyph = newFont.insertGlyph(sourceGlyph)
     contour = insertedGlyph[0]
     self.assertTrue(contour.getParent(), insertedGlyph)
     self.assertTrue(contour.dispatcher, newFont.dispatcher)
     component = insertedGlyph.components[0]
     self.assertTrue(component.getParent(), insertedGlyph)
     self.assertTrue(component.dispatcher, newFont.dispatcher)
     anchor = insertedGlyph.anchors[0]
     self.assertTrue(anchor.getParent(), insertedGlyph)
     self.assertTrue(anchor.dispatcher, newFont.dispatcher)
     guideline = insertedGlyph.guidelines[0]
     self.assertTrue(guideline.getParent(), insertedGlyph)
     self.assertTrue(guideline.dispatcher, newFont.dispatcher)
Пример #4
0
 def test_glyph_dispatcher_new(self):
     font = Font()
     font.newGlyph("A")
     glyph = font["A"]
     pen = glyph.getPointPen()
     pen.beginPath()
     pen.addPoint((0, 0), segmentType="line")
     pen.addPoint((0, 100), segmentType="line")
     pen.addPoint((100, 100), segmentType="line")
     pen.addPoint((100, 0), segmentType="line")
     pen.endPath()
     contour = glyph[0]
     self.assertEqual(contour.getParent(), glyph)
     self.assertEqual(contour.dispatcher, font.dispatcher)
     component = Component()
     glyph.appendComponent(component)
     self.assertEqual(component.getParent(), glyph)
     self.assertEqual(component.dispatcher, font.dispatcher)
     anchor = Anchor()
     glyph.appendAnchor(anchor)
     self.assertEqual(anchor.getParent(), glyph)
     self.assertEqual(anchor.dispatcher, font.dispatcher)
     guideline = Guideline()
     glyph.appendGuideline(guideline)
     self.assertEqual(guideline.getParent(), glyph)
     self.assertEqual(guideline.dispatcher, font.dispatcher)
Пример #5
0
 def test_glyph_dispatcher_inserted(self):
     font = Font()
     font.newGlyph("A")
     glyph = font["A"]
     pen = glyph.getPointPen()
     pen.beginPath()
     pen.addPoint((0, 0), segmentType="line")
     pen.addPoint((0, 100), segmentType="line")
     pen.addPoint((100, 100), segmentType="line")
     pen.addPoint((100, 0), segmentType="line")
     pen.endPath()
     contour = glyph[0]
     component = Component()
     glyph.appendComponent(component)
     anchor = Anchor()
     glyph.appendAnchor(anchor)
     guideline = Guideline()
     glyph.appendGuideline(guideline)
     sourceGlyph = glyph
     newFont = Font()
     insertedGlyph = newFont.insertGlyph(sourceGlyph)
     contour = insertedGlyph[0]
     self.assertTrue(contour.getParent(), insertedGlyph)
     self.assertTrue(contour.dispatcher, newFont.dispatcher)
     component = insertedGlyph.components[0]
     self.assertTrue(component.getParent(), insertedGlyph)
     self.assertTrue(component.dispatcher, newFont.dispatcher)
     anchor = insertedGlyph.anchors[0]
     self.assertTrue(anchor.getParent(), insertedGlyph)
     self.assertTrue(anchor.dispatcher, newFont.dispatcher)
     guideline = insertedGlyph.guidelines[0]
     self.assertTrue(guideline.getParent(), insertedGlyph)
     self.assertTrue(guideline.dispatcher, newFont.dispatcher)
Пример #6
0
 def test_appendComponent(self):
     glyph = Glyph()
     glyph.dirty = False
     component = Component()
     glyph.appendComponent(component)
     self.assertEqual(len(glyph.components), 1)
     self.assertTrue(glyph.dirty)
     self.assertEqual(component.getParent(), glyph)
Пример #7
0
 def test_appendComponent(self):
     glyph = Glyph()
     glyph.dirty = False
     component = Component()
     glyph.appendComponent(component)
     self.assertEqual(len(glyph.components), 1)
     self.assertTrue(glyph.dirty)
     self.assertEqual(component.getParent(), glyph)
Пример #8
0
    def test_copyDataFromGlyph(self):
        source = Glyph()
        source.name = "a"
        source.width = 1
        source.height = 2
        source.unicodes = [3, 4]
        source.note = "test image"
        source.image = dict(fileName="test image",
                            xScale=1,
                            xyScale=1,
                            yxScale=1,
                            yScale=1,
                            xOffset=0,
                            yOffset=0,
                            color=None)
        source.anchors = [dict(x=100, y=200, name="test anchor")]
        source.guidelines = [dict(x=10, y=20, name="test guideline")]
        source.lib = {"foo": "bar"}
        pen = source.getPointPen()
        pen.beginPath()
        pen.addPoint((100, 200), segmentType="line")
        pen.addPoint((300, 400), segmentType="line")
        pen.endPath()
        component = Component()
        component.base = "b"
        source.appendComponent(component)
        dest = Glyph()
        dest.copyDataFromGlyph(source)

        self.assertNotEqual(source.name, dest.name)
        self.assertEqual(source.width, dest.width)
        self.assertEqual(source.height, dest.height)
        self.assertEqual(source.unicodes, dest.unicodes)
        self.assertEqual(source.note, dest.note)
        self.assertEqual(source.image.items(), dest.image.items())
        self.assertEqual([g.items() for g in source.guidelines],
                         [g.items() for g in dest.guidelines])
        self.assertEqual([g.items() for g in source.anchors],
                         [g.items() for g in dest.anchors])
        self.assertEqual(len(source), len(dest))
        self.assertEqual(len(source.components), len(dest.components))
        sourceContours = []
        for contour in source:
            sourceContours.append([])
            for point in contour:
                sourceContours[-1].append(
                    (point.x, point.x, point.segmentType, point.name))
        destContours = []
        for contour in dest:
            destContours.append([])
            for point in contour:
                destContours[-1].append(
                    (point.x, point.x, point.segmentType, point.name))
        self.assertEqual(sourceContours, destContours)
        self.assertEqual(source.components[0].baseGlyph,
                         dest.components[0].baseGlyph)
Пример #9
0
    def test_copyDataFromGlyph(self):
        source = Glyph()
        source.name = "a"
        source.width = 1
        source.height = 2
        source.unicodes = [3, 4]
        source.note = "test image"
        source.image = dict(fileName="test image", xScale=1, xyScale=1,
                            yxScale=1, yScale=1, xOffset=0, yOffset=0,
                            color=None)
        source.anchors = [dict(x=100, y=200, name="test anchor")]
        source.guidelines = [dict(x=10, y=20, name="test guideline")]
        source.lib = {"foo": "bar"}
        pen = source.getPointPen()
        pen.beginPath()
        pen.addPoint((100, 200), segmentType="line")
        pen.addPoint((300, 400), segmentType="line")
        pen.endPath()
        component = Component()
        component.base = "b"
        source.appendComponent(component)
        dest = Glyph()
        dest.copyDataFromGlyph(source)

        self.assertNotEqual(source.name, dest.name)
        self.assertEqual(source.width, dest.width)
        self.assertEqual(source.height, dest.height)
        self.assertEqual(source.unicodes, dest.unicodes)
        self.assertEqual(source.note, dest.note)
        self.assertEqual(source.image.items(), dest.image.items())
        self.assertEqual([g.items() for g in source.guidelines],
                         [g.items() for g in dest.guidelines])
        self.assertEqual([g.items() for g in source.anchors],
                         [g.items() for g in dest.anchors])
        self.assertEqual(len(source), len(dest))
        self.assertEqual(len(source.components), len(dest.components))
        sourceContours = []
        for contour in source:
            sourceContours.append([])
            for point in contour:
                sourceContours[-1].append((point.x, point.x,
                                           point.segmentType, point.name))
        destContours = []
        for contour in dest:
            destContours.append([])
            for point in contour:
                destContours[-1].append((point.x, point.x,
                                         point.segmentType, point.name))
        self.assertEqual(sourceContours, destContours)
        self.assertEqual(source.components[0].baseGlyph,
                         dest.components[0].baseGlyph)
Пример #10
0
 def test_glyph(self):
     self.assertIsNone(self.component.layer)
     self.glyph = self.font.newGlyph("A")
     self.component = Component(self.glyph)
     self.assertEqual(self.component.layer, self.glyph.layer)
     with self.assertRaises(AttributeError):
         self.component.layer = "foo"
Пример #11
0
 def setUp(self):
     self.font = Font()
     self.glyph = self.font.newGlyph("A")
     # self.font.newGlyph("B")
     self.component = Component(self.glyph)
     self.component.name = "component1"
     self.notificationObject = NotificationTestObserver()
Пример #12
0
def getGlyphFromDict(glyph_dict):
    g = Glyph()
    
    # Set attributes
    
    g.height = glyph_dict.get('height', 0)
    g.lib = glyph_dict.get('lib', {})
    g.name = glyph_dict.get('name', '')
    g.note = glyph_dict.get('note', None)
    g.unicode = glyph_dict.get('unicode', None)
    g.unicodes = glyph_dict.get('unicodes', [])
    g.width = glyph_dict.get('width', 0)
    
    # Draw the outlines with a pen
    pen = g.getPointPen()
    
    for contour in glyph_dict.get('contours', []):
        pen.beginPath()
        for point in contour:
            pen.addPoint(
                (
                    point.get('x'),
                    point.get('y')
                ),
                segmentType = point.get('type', None),
                name = point.get('name', None),
                smooth = point.get('smooth', None),
            )
        pen.endPath()
    
    # Add components
    
    for component in glyph_dict.get('components', []):
        c = Component()
        c.baseGlyph = component.get('ref', '')
        c.transformation = component.get('transformation', (1, 0, 0, 1, 0, 0))
        g.appendComponent(c)
    
    # Add anchors
    
    for anchor in glyph_dict.get('anchors', []):
        a = Anchor(anchorDict = anchor)
        g.appendAnchor(a)
    
    # Return the completed glyph object
    
    return g
Пример #13
0
 def test_duplicate_identifier_error(self):
     glyph = self.glyph
     component = self.component
     component.identifier = "component 1"
     self.assertEqual(component.identifier, "component 1")
     component = Component(glyph)
     with self.assertRaises(AssertionError):
         component.identifier = "component 1"
     component.identifier = "component 2"
     self.assertEqual(sorted(glyph.identifiers),
                      ["component 1", "component 2"])
     component.identifier = "not component 2 anymore"
     self.assertEqual(component.identifier, "component 2")
     self.assertEqual(sorted(glyph.identifiers),
                      ["component 1", "component 2"])
     component.identifier = None
     self.assertEqual(component.identifier, "component 2")
     self.assertEqual(sorted(glyph.identifiers),
                      ["component 1", "component 2"])
Пример #14
0
def buildExtraGlyphs(ufo):
    """Builds some necessary glyphs at runtime that are derived from other
    glyphs, instead of having to update them manually."""

    # Build fallback glyphs, these are the base glyph that cmap maps to. We
    # decompose them immediately in the layout code, so they shouldn’t be used
    # for anything and we could just keep them blank, but then FontConfig will
    # think the font does not support these characters.
    addPlaceHolders(ufo)

    # Build Arabic comma and semicolon glyphs, by rotating the Latin 180°, so
    # that they are similar in design.
    for code, name in [(ord(u'،'), "comma"), (ord(u'؛'), "semicolon")]:
        glyph = ufo.newGlyph("uni%04X" % code)
        glyph.unicode = code
        enGlyph = ufo[name]
        colon = ufo["colon"]
        component = Component()
        component.transformation = tuple(Transform().rotate(math.radians(180)))
        component.baseGlyph = enGlyph.name
        glyph.appendComponent(component)
        glyph.move((0, colon.bounds[1] - glyph.bounds[1]))
        glyph.leftMargin = enGlyph.rightMargin
        glyph.rightMargin = enGlyph.leftMargin

    # Ditto for question mark, but here we flip.
    for code, name in [(ord(u'؟'), "question")]:
        glyph = ufo.newGlyph("uni%04X" % code)
        glyph.unicode = code
        enGlyph = ufo[name]
        component = Component()
        component.transformation = tuple(Transform().scale(-1, 1))
        component.baseGlyph = enGlyph.name
        glyph.appendComponent(component)
        glyph.leftMargin = enGlyph.rightMargin
        glyph.rightMargin = enGlyph.leftMargin
Пример #15
0
 def test_duplicate_identifier_error(self):
     glyph = self.glyph
     component = self.component
     component.identifier = "component 1"
     self.assertEqual(component.identifier, "component 1")
     component = Component(glyph)
     with self.assertRaises(AssertionError):
         component.identifier = "component 1"
     component.identifier = "component 2"
     self.assertEqual(sorted(glyph.identifiers),
                      ["component 1", "component 2"])
     component.identifier = "not component 2 anymore"
     self.assertEqual(component.identifier, "component 2")
     self.assertEqual(sorted(glyph.identifiers),
                      ["component 1", "component 2"])
     component.identifier = None
     self.assertEqual(component.identifier, "component 2")
     self.assertEqual(sorted(glyph.identifiers),
                      ["component 1", "component 2"])
Пример #16
0
def buildExtraGlyphs(ufo):
    """Builds some necessary glyphs at runtime that are derived from other
    glyphs, instead of having to update them manually."""

    # Build fallback glyphs, these are the base glyph that cmap maps to. We
    # decompose them immediately in the layout code, so they shouldn’t be used
    # for anything and we could just keep them blank, but then FontConfig will
    # think the font does not support these characters.
    buildEncoded(ufo)

    # Build Arabic comma and semicolon glyphs, by rotating the Latin 180°, so
    # that they are similar in design.
    for code, name in [(ord(u'،'), "comma"), (ord(u'؛'), "semicolon")]:
        glyph = ufo.newGlyph("uni%04X" % code)
        glyph.unicode = code
        enGlyph = ufo[name]
        colon = ufo["colon"]
        component = Component()
        component.transformation = tuple(Transform().rotate(math.radians(180)))
        component.baseGlyph = enGlyph.name
        glyph.appendComponent(component)
        glyph.move((0, colon.bounds[1] - glyph.bounds[1]))
        glyph.leftMargin = enGlyph.rightMargin
        glyph.rightMargin = enGlyph.leftMargin

    # Ditto for question mark, but here we flip.
    for code, name in [(ord(u'؟'), "question")]:
        glyph = ufo.newGlyph("uni%04X" % code)
        glyph.unicode = code
        enGlyph = ufo[name]
        component = Component()
        component.transformation = tuple(Transform().scale(-1, 1))
        component.baseGlyph = enGlyph.name
        glyph.appendComponent(component)
        glyph.leftMargin = enGlyph.rightMargin
        glyph.rightMargin = enGlyph.leftMargin
Пример #17
0
 def setUp(self):
     self.font = Font()
     self.glyph = Glyph()
     self.component = Component(self.glyph)
Пример #18
0
 def test_font(self):
     self.assertIsNone(self.component.font)
     self.component = Component(self.font.newGlyph("A"))
     self.assertEqual(self.component.font, self.font)
     with self.assertRaises(AttributeError):
         self.component.font = "foo"
Пример #19
0
class ComponentTest(unittest.TestCase):
    def __init__(self, methodName):
        unittest.TestCase.__init__(self, methodName)

    def setUp(self):
        self.font = Font()
        self.glyph = Glyph()
        self.component = Component(self.glyph)

    def tearDown(self):
        del self.component
        del self.glyph

    def test_getParent(self):
        self.assertEqual(self.component.getParent(), self.glyph)

    def test_font(self):
        self.assertIsNone(self.component.font)
        self.component = Component(self.font.newGlyph("A"))
        self.assertEqual(self.component.font, self.font)
        with self.assertRaises(AttributeError):
            self.component.font = "foo"

    def test_layerSet(self):
        self.assertIsNone(self.component.layerSet)
        self.glyph = self.font.newGlyph("A")
        self.component = Component(self.glyph)
        self.assertEqual(self.component.layerSet, self.glyph.layerSet)
        with self.assertRaises(AttributeError):
            self.component.layerSet = "foo"

    def test_layer(self):
        self.assertIsNone(self.component.layer)
        self.glyph = self.font.newGlyph("A")
        self.component = Component(self.glyph)
        self.assertEqual(self.component.layer, self.glyph.layer)
        with self.assertRaises(AttributeError):
            self.component.layer = "foo"

    def test_glyph(self):
        self.assertIsNone(self.component.layer)
        self.glyph = self.font.newGlyph("A")
        self.component = Component(self.glyph)
        self.assertEqual(self.component.layer, self.glyph.layer)
        with self.assertRaises(AttributeError):
            self.component.layer = "foo"

    def test_bounds(self):
        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(self.component.bounds, (0.0, 0.0, 350.0, 350.0))
        with self.assertRaises(AttributeError):
            self.component.layer = (0.0, 0.0, 350.0, 350.0)

    def test_controlPointBounds(self):
        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(self.component.controlPointBounds,
                         (0.0, 0.0, 350.0, 350.0))
        with self.assertRaises(AttributeError):
            self.component.layer = (0.0, 0.0, 350.0, 350.0)

    def test_baseGlyph(self):
        self.assertIsNone(self.component.baseGlyph)

        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(self.component.baseGlyph, "A")
        self.component.baseGlyph = "B"
        self.assertEqual(self.component.baseGlyph, "B")

    def test_transformation(self):
        self.assertEqual(self.component.transformation, (1, 0, 0, 1, 0, 0))

        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(self.component.transformation, (0.5, 0, 0, 0.5, 0, 0))
        self.component = self.glyph.components[1]
        self.assertEqual(self.component.transformation,
                         (0.5, 0, 0, 0.5, 350, 350))

    def test_identifier(self):
        self.assertIsNone(self.component.identifier)
        self.component.identifier = "component 1"
        self.assertEqual(self.component.identifier, "component 1")

    def test_identifiers(self):
        self.assertEqual(sorted(self.glyph.identifiers), [])
        self.component.identifier = "component 1"
        self.assertEqual(sorted(self.glyph.identifiers), ["component 1"])

    def test_duplicate_identifier_error(self):
        glyph = self.glyph
        component = self.component
        component.identifier = "component 1"
        self.assertEqual(component.identifier, "component 1")
        component = Component(glyph)
        with self.assertRaises(AssertionError):
            component.identifier = "component 1"
        component.identifier = "component 2"
        self.assertEqual(sorted(glyph.identifiers),
                         ["component 1", "component 2"])
        component.identifier = "not component 2 anymore"
        self.assertEqual(component.identifier, "component 2")
        self.assertEqual(sorted(glyph.identifiers),
                         ["component 1", "component 2"])
        component.identifier = None
        self.assertEqual(component.identifier, "component 2")
        self.assertEqual(sorted(glyph.identifiers),
                         ["component 1", "component 2"])
Пример #20
0
class ComponentTest(unittest.TestCase):

    def __init__(self, methodName):
        unittest.TestCase.__init__(self, methodName)

    def setUp(self):
        self.font = Font()
        self.glyph = Glyph()
        self.component = Component(self.glyph)

    def tearDown(self):
        del self.component
        del self.glyph

    def test_getParent(self):
        self.assertEqual(self.component.getParent(), self.glyph)

    def test_font(self):
        self.assertIsNone(self.component.font)
        self.component = Component(self.font.newGlyph("A"))
        self.assertEqual(self.component.font, self.font)
        with self.assertRaises(AttributeError):
            self.component.font = "foo"

    def test_layerSet(self):
        self.assertIsNone(self.component.layerSet)
        self.glyph = self.font.newGlyph("A")
        self.component = Component(self.glyph)
        self.assertEqual(self.component.layerSet, self.glyph.layerSet)
        with self.assertRaises(AttributeError):
            self.component.layerSet = "foo"

    def test_layer(self):
        self.assertIsNone(self.component.layer)
        self.glyph = self.font.newGlyph("A")
        self.component = Component(self.glyph)
        self.assertEqual(self.component.layer, self.glyph.layer)
        with self.assertRaises(AttributeError):
            self.component.layer = "foo"

    def test_glyph(self):
        self.assertIsNone(self.component.layer)
        self.glyph = self.font.newGlyph("A")
        self.component = Component(self.glyph)
        self.assertEqual(self.component.layer, self.glyph.layer)
        with self.assertRaises(AttributeError):
            self.component.layer = "foo"

    def test_bounds(self):
        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(
            self.component.bounds,
            (0.0, 0.0, 350.0, 350.0)
        )
        with self.assertRaises(AttributeError):
            self.component.layer = (0.0, 0.0, 350.0, 350.0)

    def test_controlPointBounds(self):
        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(
            self.component.controlPointBounds,
            (0.0, 0.0, 350.0, 350.0)
        )
        with self.assertRaises(AttributeError):
            self.component.layer = (0.0, 0.0, 350.0, 350.0)

    def test_baseGlyph(self):
        self.assertIsNone(self.component.baseGlyph)

        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(self.component.baseGlyph, "A")
        self.component.baseGlyph = "B"
        self.assertEqual(self.component.baseGlyph, "B")

    def test_transformation(self):
        self.assertEqual(
            self.component.transformation,
            (1, 0, 0, 1, 0, 0)
        )

        self.font = Font(getTestFontPath())
        self.glyph = self.font["C"]
        self.component = self.glyph.components[0]
        self.assertEqual(
            self.component.transformation,
            (0.5, 0, 0, 0.5, 0, 0)
        )
        self.component = self.glyph.components[1]
        self.assertEqual(
            self.component.transformation,
            (0.5, 0, 0, 0.5, 350, 350)
        )

    def test_identifier(self):
        self.assertIsNone(self.component.identifier)
        self.component.identifier = "component 1"
        self.assertEqual(self.component.identifier, "component 1")

    def test_identifiers(self):
        self.assertEqual(sorted(self.glyph.identifiers), [])
        self.component.identifier = "component 1"
        self.assertEqual(sorted(self.glyph.identifiers), ["component 1"])

    def test_duplicate_identifier_error(self):
        glyph = self.glyph
        component = self.component
        component.identifier = "component 1"
        self.assertEqual(component.identifier, "component 1")
        component = Component(glyph)
        with self.assertRaises(AssertionError):
            component.identifier = "component 1"
        component.identifier = "component 2"
        self.assertEqual(sorted(glyph.identifiers),
                         ["component 1", "component 2"])
        component.identifier = "not component 2 anymore"
        self.assertEqual(component.identifier, "component 2")
        self.assertEqual(sorted(glyph.identifiers),
                         ["component 1", "component 2"])
        component.identifier = None
        self.assertEqual(component.identifier, "component 2")
        self.assertEqual(sorted(glyph.identifiers),
                         ["component 1", "component 2"])
Пример #21
0
 def test_font(self):
     self.assertIsNone(self.component.font)
     self.component = Component(self.font.newGlyph("A"))
     self.assertEqual(self.component.font, self.font)
     with self.assertRaises(AttributeError):
         self.component.font = "foo"
Пример #22
0
def recomponet(path_to_orignal, path_to_new=None):
    assert os.path.exists(path_to_orignal)
    font = Font(path_to_orignal)
    if path_to_new is not None:
        assert os.path.exists(path_to_new)
        font.save(path_to_new)
        font = Font(path_to_new)
    else:
        new_path = _findAvailablePathName(path_to_orignal)
        font.save(new_path)
        font = Font(new_path)

    ordered_glyphs = {}
    clean_up = []
    for key in font.keys():
        parts = key.split('.')
        if len(parts) == 1:
            part = key
            if key.endswith('comb'):
                part = key[:-4]
                clean_up.append(key)
            if part not in ordered_glyphs:
                ordered_glyphs[part] = [
                    key,
                ]
            else:
                glyphs = ordered_glyphs[part]
                if key not in glyphs:
                    glyphs.append(key)
                    ordered_glyphs[part] = glyphs
        else:
            part = parts[0]
            if part.endswith('comb'):
                part = parts[0][:-4]
                clean_up.append(key)
            if part not in ordered_glyphs:
                ordered_glyphs[part] = [
                    key,
                ]
            else:
                glyphs = ordered_glyphs[part]
                if key not in glyphs:
                    glyphs.append(key)
                    ordered_glyphs[part] = glyphs
    for i in clean_up:
        if i not in ordered_glyphs:
            part = i[:-4]
            if part in ordered_glyphs:
                glyphs = ordered_glyphs[part]
                ordered_glyphs[i] = glyphs

    # Cleanup for the i
    i = ordered_glyphs['i']
    i.append('dotlessi')
    ordered_glyphs['i'] = i

    # Additional cleanup for the pesky commaaccent
    if 'uni0327' not in ordered_glyphs:
        ordered_glyphs['uni0327'] = [
            'uni0326',
        ]
    else:
        if 'uni0326' not in ordered_glyphs['uni0327']:
            glyphs = ordered_glyphs['uni0327']
            glyphs.append('uni0326')
            ordered_glyphs['uni0327'] = glyphs
    found = []
    for glyph in font:
        if len(glyph) is not 0:
            parts = decompose_glyph(font.unicodeData, glyph.name,
                                    ordered_glyphs)
            if len(parts) > 1:
                print 'normal'
                print glyph.name
                for part in parts:
                    if part in font.keys() and compare_glyph(
                            font, glyph, font[part]) is not -1:
                        orgin, delete = compare_glyph(font, glyph, font[part])
                        if len(font[part]) is 0 and len(
                                font[part].components) is not 0:
                            part = font[part].components[0].baseGlyph
                        found.append(glyph.name)
                        for x in [glyph[x] for x in delete]:
                            glyph.removeContour(x)
                        component = Component()
                        component.baseGlyph = part
                        glyph.appendComponent(component)
                        xMin, yMin, xMax, yMax = component.bounds
                        moveX = orgin[0] - xMin
                        moveY = orgin[1] - yMin
                        component.move((moveX, moveY))
            elif glyph.name in double_check.keys():
                parts = double_check[glyph.name]
                print glyph.name
                print 'double check'
                print parts
                for part in parts:
                    print part
                    if part in font.keys() and compare_glyph(
                            font, glyph, font[part]) is not -1:
                        orgin, delete = compare_glyph(font, glyph, font[part])
                        if len(font[part]) is 0 and len(
                                font[part].components) is not 0:
                            part = font[part].components[0].baseGlyph
                        found.append(glyph.name)
                        for x in [glyph[x] for x in delete]:
                            glyph.removeContour(x)
                        component = Component()
                        component.baseGlyph = part
                        glyph.appendComponent(component)
                        xMin, yMin, xMax, yMax = component.bounds
                        moveX = orgin[0] - xMin
                        moveY = orgin[1] - yMin
                        component.move((moveX, moveY))
                        print 'done'
                        break
                    else:
                        print part
                        print 'did not check out'
            elif glyph.name in composites.keys():
                preparts = composites[glyph.name]
                parts = []
                for p in preparts:
                    parts.append(p)
                    if p in ordered_glyphs:
                        for x in ordered_glyphs[p]:
                            parts.append(x)
                print glyph.name
                print 'composite'
                print parts
                for part in parts:
                    if compare_glyph(font, glyph, font[part]) is not -1:
                        orgin, delete = compare_glyph(font, glyph, font[part])
                        if len(font[part]) is 0 and len(
                                font[part].components) is not 0:
                            part = font[part].components[0].baseGlyph
                        found.append(glyph.name)
                        for x in [glyph[x] for x in delete]:
                            glyph.removeContour(x)
                        component = Component()
                        component.baseGlyph = part
                        glyph.appendComponent(component)
                        xMin, yMin, xMax, yMax = component.bounds
                        moveX = orgin[0] - xMin
                        moveY = orgin[1] - yMin
                        component.move((moveX, moveY))
    font.save()
    print 'Found:'
    print ' '
    for x in found:
        print x
    print '----------------'
    print str(len(found)) + ' Glyphs'
Пример #23
0
 def setUp(self):
     self.font = Font()
     self.glyph = Glyph()
     self.component = Component(self.glyph)
Пример #24
0
def merge(args):
    arabic = Font(args.arabicfile)

    latin = Font(args.latinfile)

    addPlaceHolders(arabic)

    unicodes = parseSubset(args.latin_subset)
    for glyph in arabic:
        unicodes.extend(glyph.unicodes)

    latin_locl = ""
    for name in latin.glyphOrder:
        glyph = latin[name]
        if name in arabic:
            glyph.unicode = None
            glyph.name = name + ".latn"
            latin_locl += "sub %s by %s;" % (name, glyph.name)
        arabic.insertGlyph(glyph)

    for attr in ("xHeight", "capHeight"):
        value = getattr(latin.info, attr)
        if value is not None:
            setattr(arabic.info, attr, getattr(latin.info, attr))

    arabic.features.text += latin.features.text

    if latin_locl:
        arabic.features.text += """
feature locl {
  lookupflag IgnoreMarks;
  script latn;
  %s
} locl;
""" % latin_locl

    for ch in [(ord(u'؟'), "question")]:
        arGlyph = arabic.newGlyph("uni%04X" % ch[0])
        arGlyph.unicode = ch[0]
        enGlyph = arabic[ch[1]]
        component = Component()
        component.transformation = tuple(Transform().scale(-1, 1))
        component.baseGlyph = enGlyph.name
        arGlyph.appendComponent(component)
        arGlyph.leftMargin = enGlyph.rightMargin
        arGlyph.rightMargin = enGlyph.leftMargin
        unicodes.append(arGlyph.unicode)

    arabic.lib[MADA_UNICODES] = unicodes

    # Set metadata
    arabic.info.versionMajor, arabic.info.versionMinor = map(
        int, args.version.split("."))

    copyright = u"Copyright © 2015-%s The Reem Kufi Project Authors." % datetime.now(
    ).year

    arabic.info.copyright = copyright

    arabic.info.openTypeNameDesigner = u"Khaled Hosny"
    arabic.info.openTypeNameLicenseURL = u"http://scripts.sil.org/OFL"
    arabic.info.openTypeNameLicense = u"This Font Software is licensed under the SIL Open Font License, Version 1.1. This license is available with a FAQ at: http://scripts.sil.org/OFL"
    arabic.info.openTypeNameDescription = u"Reem Kufi is a Fatimid-style decorative Kufic typeface as seen in the historical mosques of Cairo. Reem Kufi is based on the Kufic designs of the great Arabic calligrapher Mohammed Abdul Qadir who revived this art in the 20th century and formalised its rules."
    arabic.info.openTypeNameSampleText = u"ريم على القاع بين البان و العلم   أحل سفك دمي في الأشهر الحرم"

    return arabic