Example #1
0
    def glyphs(self):
        x = 0
        y = (self.position[3] - self.fontSize) * (1000 / self.fontSize)

        for char in self.text:
            charName = files.unicodeName(char)
            try:
                rglyph = self.RCJKI.currentFont[charName]
                glyph = RGlyph()
                if not self.sourceList:
                    # rglyph.preview.computeDeepComponents(update = False)
                    for atomicInstance in rglyph.preview(self.sourceList):
                        atomicInstance = atomicInstance.glyph
                        atomicInstance.draw(glyph.getPen())
                        # for c in atomicInstance.getTransformedGlyph():
                        #     glyph.appendContour(c)
                else:
                    for atomicInstance in rglyph.preview():
                        atomicInstance = atomicInstance.glyph
                        atomicInstance.draw(glyph.getPen())

                yield (x, y), glyph

                for c in rglyph.flatComponents:
                    g = self.RCJKI.currentFont[c.baseGlyph]
                    glyph = RGlyph()
                    if not self.sourceList:
                        # g.preview.computeDeepComponents(update = False)
                        for atomicInstance in g.preview(self.sourceList):
                            atomicInstance = atomicInstance.glyph
                            atomicInstance.draw(glyph.getPen())
                            # for c in atomicInstance.getTransformedGlyph():
                            #     glyph.appendContour(c)
                    else:
                        for atomicInstance in g.preview():
                            atomicInstance = atomicInstance.glyph
                            atomicInstance.draw(glyph.getPen())

                    yield (x, y), glyph

                x += rglyph.width + self.tracking * (1000 / self.fontSize)
                if (x + rglyph.width) // (1000 /
                                          self.fontSize) > self.position[2]:
                    y -= self.lineHeight
                    x = 0
            except:  # Exception as e:
                # raise e
                continue
Example #2
0
    def trace_path(self, out_glyph):
        from mojo.roboFont import RGlyph

        tmp = RGlyph()
        p = tmp.getPen()
        first = True
        for path in self.path:
            if first:
                first = False
            else:
                p.closePath()
                out_glyph.appendGlyph(tmp)
                tmp.clear()
            p.moveTo(self.round_pt(path[0][0]))
            for segment in path[1:]:
                if len(segment) == 1:
                    p.lineTo(self.round_pt(segment[0]))
                elif len(segment) == 3:
                    p.curveTo(
                        self.round_pt(segment[0]),
                        self.round_pt(segment[1]),
                        self.round_pt(segment[2]),
                    )

                else:
                    print("Unknown segment type:", segment)
        p.closePath()
        # tmp.correctDirection()
        out_glyph.appendGlyph(tmp)
        # out_glyph.removeOverlap()
        # out_glyph.removeOverlap()
        out_glyph.update()
Example #3
0
    def _makeOvershoot(self, glyph: RGlyph, origin_x: int, origin_y: int,
                       width: int, height: int, inside: int, outside: int, ty):
        ox = origin_x - outside
        oy = origin_y - outside
        width += outside
        height += outside
        pen = glyph.getPen()
        pen.moveTo((ox, oy))
        pen.lineTo((ox + width + outside, oy))
        pen.lineTo((ox + width + outside, oy + height + outside))
        pen.lineTo((ox, oy + height + outside))
        pen.closePath()
        ox = origin_x + inside
        oy = origin_y + inside
        width -= outside + inside
        height -= outside + inside
        pen.moveTo((ox, oy))
        pen.lineTo((ox, oy + height - inside))
        pen.lineTo((ox + width - inside, oy + height - inside))
        pen.lineTo((ox + width - inside, oy))
        pen.closePath()
        glyph.round()
        glyph.moveBy((0, ty))

        self.elements.append((glyph, (0.4, .75, 1, .1), 'fill'))
Example #4
0
 def _makeVerGrid(self, glyph: RGlyph, x: int, y: int, w: int, h: int,
                  ty: int, step: int):
     pen = glyph.getPen()
     dist = x + w / step
     for i in range(step - 1):
         pen.moveTo((dist, y))
         pen.lineTo((dist, y + h))
         pen.closePath()
         dist += w / step
     # db.drawGlyph(glyph)
     glyph.moveBy((0, ty))
     self.elements.append((glyph, (.80, 0.56, .66, 1), 'stroke'))
Example #5
0
 def _makeVerSecLine(self, glyph: RGlyph, origin_x: int, origin_y: int,
                     width: int, height: int, ty):
     pen = glyph.getPen()
     pen.moveTo((origin_x, origin_y))
     pen.lineTo((origin_x, origin_y + height))
     pen.closePath()
     pen.moveTo((width, origin_y))
     pen.lineTo((width, origin_y + height))
     pen.closePath()
     glyph.round()
     glyph.moveBy((0, ty))
     self.elements.append((glyph, (.80, 0.56, .66, 1), 'stroke'))
Example #6
0
    def _getFrame(self, x: int, y: int, w: int, h: int, ty) -> tuple:
        glyph = RGlyph()
        pen = glyph.getPen()
        pen.moveTo((x, y))
        pen.lineTo((w + x, y))
        pen.lineTo((w + x, h + y))
        pen.lineTo((x, h + y))
        pen.closePath()

        glyph.round()
        glyph.moveBy((0, ty))

        self.elements.append((glyph, (0, 0, 0, 1), 'stroke'))
Example #7
0
    def _getEmRatioFrame(self, frame: int, w: int, h: int, ty) -> tuple:
        charfaceW = w * frame / 100
        charfaceH = h * frame / 100
        x = (w - charfaceW) * .5
        y = (h - charfaceH) * .5

        glyph = RGlyph()
        pen = glyph.getPen()
        pen.moveTo((x, y))
        pen.lineTo((charfaceW + x, y))
        pen.lineTo((charfaceW + x, charfaceH + y))
        pen.lineTo((x, charfaceH + y))
        pen.closePath()

        glyph.round()
        glyph.moveBy((0, ty))

        self.elements.append((glyph, (0, 0, 0, 1), 'stroke'))

        return x, y, charfaceW, charfaceH