Beispiel #1
0
 def get_tt_glyph(self):
     """Return a special TT Glyph record for the sbix format. It contains
     two dummy contours with one point (bottom left and top right) each."""
     # make dummy contours
     glyph = TTGlyph()
     glyph.program = NoProgram()
     glyph.numberOfContours = 0
     box = self.get_box()
     if box is not None:
         contours = [
             [(box[0], box[1], 1)],
             [(box[2], box[3], 1)],
         ]
         for contour in contours:
             coordinates = []
             flags = []
             for x, y, flag in contour:
                 if not hasattr(glyph, "xMin"):
                     glyph.xMin = x
                     glyph.yMin = y
                     glyph.xMax = x
                     glyph.yMax = y
                 else:
                     glyph.xMin = min(glyph.xMin, x)
                     glyph.yMin = min(glyph.yMin, y)
                     glyph.xMax = max(glyph.xMax, x)
                     glyph.yMax = max(glyph.yMax, y)
                 coordinates.append([x, y])
                 flags.append(flag)
             coordinates = GlyphCoordinates(coordinates)
             flags = array.array("B", flags)
             if not hasattr(glyph, "coordinates"):
                 glyph.coordinates = coordinates
                 glyph.flags = flags
                 glyph.endPtsOfContours = [len(coordinates) - 1]
             else:
                 glyph.coordinates.extend(coordinates)
                 glyph.flags.extend(flags)
                 glyph.endPtsOfContours.append(len(glyph.coordinates) - 1)
             glyph.numberOfContours += 1
     return glyph
Beispiel #2
0
 def get_tt_glyph(self):
     """Return a special TT Glyph record for the sbix format. It contains
     two dummy contours with one point (bottom left and top right) each."""
     # make dummy contours
     glyph = TTGlyph()
     glyph.program = NoProgram()
     glyph.numberOfContours = 0
     box = self.get_box()
     if box is not None:
         contours = [
             [(box[0], box[1], 1)],
             [(box[2], box[3], 1)],
         ]
         for contour in contours:
             coordinates = []
             flags = []
             for x, y, flag in contour:
                 if not hasattr(glyph, "xMin"):
                     glyph.xMin = x
                     glyph.yMin = y
                     glyph.xMax = x
                     glyph.yMax = y
                 else:
                     glyph.xMin = min(glyph.xMin, x)
                     glyph.yMin = min(glyph.yMin, y)
                     glyph.xMax = max(glyph.xMax, x)
                     glyph.yMax = max(glyph.yMax, y)
                 coordinates.append([x, y])
                 flags.append(flag)
             coordinates = GlyphCoordinates(coordinates)
             flags = array.array("B", flags)
             if not hasattr(glyph, "coordinates"):
                 glyph.coordinates = coordinates
                 glyph.flags = flags
                 glyph.endPtsOfContours = [len(coordinates)-1]
             else:
                 glyph.coordinates.extend(coordinates)
                 glyph.flags.extend(flags)
                 glyph.endPtsOfContours.append(len(glyph.coordinates)-1)
             glyph.numberOfContours += 1
     return glyph
Beispiel #3
0
    def _newGlyph(self, name, **kwargs):
        import array
        layer = self.naked()
        self._trashPost(layer)

        layer["hmtx"][name] = (0, 0)
        layer.glyphOrder.append(name)
        # newId = layer["maxp"].numGlyphs
        # layer["maxp"].numGlyphs = newId + 1
        if "hdmx" in layer:
            del (layer["hdmx"])  # Obviously this is wrong. XXX
        layer["glyf"][name] = Glyph()  # XXX Only TTF
        layer["glyf"][name].numberOfContours = -1  # Only components right now
        layer["glyf"][name].flags = array.array("B", [])
        layer["glyf"][name].coordinates = GlyphCoordinates([])
        layer["glyf"][name].endPtsOfContours = []
        layer["glyf"][name].program = ttProgram.Program()
        layer["glyf"][name].program.fromBytecode([])
        layer["glyf"][name].xMin = 0
        layer["glyf"][name].yMin = 0
        layer["glyf"][name].xMax = 0
        layer["glyf"][name].yMax = 0
        return self[name]