Ejemplo n.º 1
0
async def test_openFonts(fileName,
                         expectedSortInfo,
                         featuresGSUB,
                         featuresGPOS,
                         scripts,
                         axes,
                         ext,
                         location,
                         text,
                         glyphNames,
                         ax):
    fontPath = getFontPath(fileName)
    numFonts, opener, getSortInfo = getOpener(fontPath)
    assert numFonts(fontPath) == 1
    font = opener(fontPath, 0)
    await font.load(None)
    sortInfo = getSortInfo(fontPath, 0)
    assert sortInfo == expectedSortInfo
    assert font.featuresGSUB == featuresGSUB
    assert font.featuresGPOS == featuresGPOS
    assert font.scripts == scripts
    assert font.axes == axes
    run = font.getGlyphRun(text, varLocation=location)
    assert [gi.name for gi in run] == glyphNames
    assert ext == [p.name for p in font.getExternalFiles()]
    if ax is not None:
        assert [gi.ax for gi in run] == ax
Ejemplo n.º 2
0
 def __init__(self, path, number=0, cacheable=False):
     self.path = Path(normalize_font_path(path))
     numFonts, opener, getSortInfo = getOpener(self.path)
     self.font: BaseFont = opener(self.path, number)
     self.font.cocoa = False
     self.cacheable = cacheable
     self._loaded = False
     self.load()
Ejemplo n.º 3
0
async def test_getGlyphRunFromTextInfo(text, expectedGlyphNames, expectedPositions):
    fontPath = getFontPath('IBMPlexSansArabic-Regular.ttf')
    numFonts, opener, getSortInfo = getOpener(fontPath)
    font = opener(fontPath, 0)
    await font.load(None)
    textInfo = TextInfo(text)
    glyphs = font.getGlyphRunFromTextInfo(textInfo)
    glyphNames = [g.name for g in glyphs]
    positions = [g.pos for g in glyphs]
    assert expectedGlyphNames == glyphNames
    assert expectedPositions == positions
Ejemplo n.º 4
0
async def test_mapGlyphsToChars():
    text = "عربي بِّ"
    fontPath = getFontPath('Amiri-Regular.ttf')
    numFonts, opener, getSortInfo = getOpener(fontPath)
    font = opener(fontPath, 0)
    await font.load(None)
    textInfo = TextInfo(text)
    glyphs = font.getGlyphRunFromTextInfo(textInfo)
    charIndices = []
    for glyphIndex in range(len(glyphs)):
        charIndices.append(glyphs.mapGlyphsToChars({glyphIndex}))
    expectedCharIndices = [{7}, {6}, {5}, {4}, {3}, {2}, {1}, {0}]
    assert expectedCharIndices == charIndices
    glyphIndices = []
    for charIndex in range(len(text)):
        glyphIndices.append(glyphs.mapCharsToGlyphs({charIndex}))
    expectedGlyphIndices = [{7}, {6}, {5}, {4}, {3}, {2}, {1}, {0}]
    assert expectedGlyphIndices == glyphIndices
Ejemplo n.º 5
0
async def test_verticalGlyphMetricsFromUFO():
    fontPath = getFontPath('MutatorSansBoldWideMutated.ufo')
    numFonts, opener, getSortInfo = getOpener(fontPath)
    font = opener(fontPath, 0)
    await font.load(None)
    textInfo = TextInfo("ABCDE")
    textInfo.directionOverride = "TTB"
    glyphs = font.getGlyphRunFromTextInfo(textInfo)
    ax = [g.ax for g in glyphs]
    ay = [g.ay for g in glyphs]
    dx = [g.dx for g in glyphs]
    dy = [g.dy for g in glyphs]
    expectedAX = [0, 0, 0, 0, 0]
    expectedAY = [-1022, -1000, -1000, -1000, -1000]
    expectedDX = [-645, -635, -687, -658, -560]
    expectedDY = [-822, -800, -800, -800, -800]
    assert expectedAX == ax
    assert expectedAY == ay
    assert expectedDX == dx
    assert expectedDY == dy
Ejemplo n.º 6
0
async def test_colrV1Font():
    fontPath = getFontPath("more_samples-glyf_colr_1.ttf")
    numFonts, opener, getSortInfo = getOpener(fontPath)
    font = opener(fontPath, 0)
    await font.load(None)
    textInfo = TextInfo("c")
    glyphs = font.getGlyphRunFromTextInfo(textInfo)
    glyphNames = [g.name for g in glyphs]
    glyphDrawing, *_ = font.getGlyphDrawings(glyphNames, True)
    boundingBox = glyphDrawing.bounds
    assert (100, 0, 900, 1000) == boundingBox
    surface = CoreGraphicsPixelSurface(boundingBox)
    context = NSGraphicsContext.graphicsContextWithCGContext_flipped_(
        surface.context, False)
    savedContext = NSGraphicsContext.currentContext()
    try:
        NSGraphicsContext.setCurrentContext_(context)
        glyphDrawing.draw(glyphs.colorPalette, (0, 0, 0, 1))
    finally:
        NSGraphicsContext.setCurrentContext_(savedContext)
Ejemplo n.º 7
0
 def __init__(self, path, number=0):
     #ufo = glyphsLib.load_to_ufos(self.fontFile)[0]
     self.path = Path(normalize_font_path(path))
     numFonts, opener, getSortInfo = getOpener(self.path)
     self.font: BaseFont = opener(self.path, number)
     self.font.cocoa = False