def text(self, txt, position, align=None):
        if not txt:
            # Hard Skia crash otherwise
            return

        glyphsInfo = self._gstate.textStyle.shape(txt)
        builder = skia.TextBlobBuilder()
        builder.allocRunPos(self._gstate.textStyle.font, glyphsInfo.gids,
                            glyphsInfo.positions)
        blob = builder.make()

        x, y = position
        textWidth = glyphsInfo.endPos[0]
        if align is None:
            align = "left" if not glyphsInfo.baseLevel else "right"
        if align == "right":
            x -= textWidth
        elif align == "center":
            x -= textWidth / 2

        self._canvas.save()
        try:
            self._canvas.translate(x, y)
            if self._flipCanvas:
                self._canvas.scale(1, -1)
            self._drawItem(self._canvas.drawTextBlob, blob, 0, 0)
        finally:
            self._canvas.restore()
def shapeStringToSkBlob(s, text_font, font_manager):
    txt_runs = getTextRuns(s, text_font, font_manager)
    tbb_ = skia.TextBlobBuilder()
    adv = 0.0
    for run in txt_runs:
        font = run['font']
        tf = font.getTypeface()
        fontSize = font.getSize()
        text = ''.join(run['str'])
        glyphs, positions = shaper(text,
                                   TypefaceTableCache.getTypefaceData(tf),
                                   fontSize)
        spositions = []
        su = adv
        for p in positions:
            spositions.append(su)
            su += p[0]
        tbb_.allocRunPosH(font, glyphs, spositions, 0.0)
        adv += su  # sum([x[0]+x[1] for x in positions],0.0)
    return (tbb_.make(), adv)
Exemple #3
0
def test_TextBlobBuilder_init():
    assert isinstance(skia.TextBlobBuilder(), skia.TextBlobBuilder)
Exemple #4
0
def builder():
    return skia.TextBlobBuilder()
Exemple #5
0
 def makeTextBlob(self, glyphsInfo, align):
     self.alignGlyphPositions(glyphsInfo, align)
     builder = skia.TextBlobBuilder()
     builder.allocRunPos(self.skFont, glyphsInfo.gids, glyphsInfo.positions)
     return builder.make()