本文整理汇总了Python中defcon.Font方法的典型用法代码示例。如果您正苦于以下问题:Python defcon.Font方法的具体用法?Python defcon.Font怎么用?Python defcon.Font使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类defcon
的用法示例。
在下文中一共展示了defcon.Font方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def setUp(self):
libFolder = os.path.dirname(os.path.dirname((os.path.dirname(os.path.abspath(__file__)))))
libFolder = os.path.join(libFolder, 'testFonts/')
self.scalers = []
self.loadedFonts = []
self.glyphNames = ['H','I']
for fontsFolder in ['two-axes','isotropic-anisotropic']:
fonts = []
fontsPath = os.path.join(libFolder, fontsFolder)
os.chdir(fontsPath)
for singleFontPath in glob.glob('*.ufo'):
font = Font(singleFontPath)
if 'Italic' not in font.info.styleName:
fonts.append(font)
self.loadedFonts.append(font)
scaler = MutatorScaleEngine(fonts)
self.scalers.append(scaler)
示例2: test_adding_master
# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def test_adding_master(self):
libFolder = os.path.dirname(os.path.dirname((os.path.dirname(os.path.abspath(__file__)))))
libFolder = os.path.join(libFolder, 'testFonts/')
newFontPath = os.path.join(libFolder, 'isotropic-anisotropic/bold-mid-contrast.ufo')
newFont = Font(newFontPath)
scaler = self.scalers[0]
scaler.addMaster(newFont)
self.assertEqual(len(scaler), 5)
示例3: setUp
# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def setUp(self):
self.glyphNames = ['H', 'Aacute', 'A', 'O', 'B']
libFolder = os.path.dirname(os.path.dirname((os.path.dirname(os.path.abspath(__file__)))))
singleFontPath = u'testFonts/two-axes/regular-low-contrast.ufo'
fontPath = os.path.join(libFolder, singleFontPath)
font = Font(fontPath)
self.smallFont = ScaleFont(font, (0.5, 0.4))
self.stemedSmallFont = MutatorScaleFont(font, (0.5, 0.4))
self.stemedSmallFont = MutatorScaleFont(font, (0.5, 0.4), stemsWithSlantedSection=True)
self.stemedSmallFont = MutatorScaleFont(font, (0.5, 0.4), vstem=100, stemsWithSlantedSection=True)
self.stemedSmallFont = MutatorScaleFont(font, (0.5, 0.4), vstem=120, hstem=140, stemsWithSlantedSection=True)
示例4: setUp
# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def setUp(self):
libFolder = os.path.dirname(os.path.dirname((os.path.dirname(os.path.abspath(__file__)))))
singleFontPath = u'testFonts/isotropic-anisotropic/regular-mid-contrast.ufo'
fontPath = os.path.join(libFolder, singleFontPath)
self.font = Font(fontPath)
示例5: testDummyFont
# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def testDummyFont():
from defcon import Font
font = Font()
for i, glyphName in enumerate(("a", "grave", "f", "i", "agrave")):
font.newGlyph(glyphName)
testDummyGlyph(font[glyphName], i)
font[glyphName].width = 60 + 10 * i
return font
示例6: _font_to_quadratic
# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def _font_to_quadratic(zipped_paths, **kwargs):
input_path, output_path = zipped_paths
ufo = defcon.Font(input_path)
logger.info('Converting curves for %s', input_path)
if font_to_quadratic(ufo, **kwargs):
logger.info("Saving %s", output_path)
ufo.save(output_path)
else:
_copytree(input_path, output_path)
示例7: test_single_input_no_output
# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def test_single_input_no_output(self, test_paths):
ufo_path = test_paths[0]
self.run_main(ufo_path)
font = defcon.Font(str(ufo_path))
assert font.lib[CURVE_TYPE_LIB_KEY] == "quadratic"
示例8: fonts
# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def fonts():
return [Font(ufo) for ufo in TEST_UFOS]
示例9: test_incompatible_fonts
# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def test_incompatible_fonts(self):
font1 = Font()
font1.info.unitsPerEm = 1000
glyph1 = font1.newGlyph("a")
pen1 = glyph1.getPen()
for operator, args in [("moveTo", ((0, 0),)),
("lineTo", ((1, 1),)),
("endPath", ())]:
getattr(pen1, operator)(*args)
font2 = Font()
font2.info.unitsPerEm = 1000
glyph2 = font2.newGlyph("a")
pen2 = glyph2.getPen()
for operator, args in [("moveTo", ((0, 0),)),
("curveTo", ((1, 1), (2, 2), (3, 3))),
("endPath", ())]:
getattr(pen2, operator)(*args)
with pytest.raises(IncompatibleFontsError) as excinfo:
fonts_to_quadratic([font1, font2])
assert excinfo.match("fonts contains incompatible glyphs: 'a'")
assert hasattr(excinfo.value, "glyph_errors")
error = excinfo.value.glyph_errors['a']
assert isinstance(error, IncompatibleSegmentTypesError)
assert error.segments == {1: ["line", "curve"]}
示例10: setup_fonts_to_quadratic_defcon
# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def setup_fonts_to_quadratic_defcon():
from defcon import Font
return [[Font(os.path.join(DATADIR, 'RobotoSubset-Regular.ufo'))],
MAX_ERR_EM]
示例11: buildStatic
# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def buildStatic(self,
ufo, # input UFO as filename string or defcon.Font object
outputFilename, # output filename string
cff=True, # true = makes CFF outlines. false = makes TTF outlines.
**kwargs, # passed along to ufo2ft.compile*()
):
if isinstance(ufo, str):
ufo = Font(ufo)
# update version to actual, real version. Must come after any call to setFontInfo.
updateFontVersion(ufo, dummy=False, isVF=False)
compilerOptions = dict(
useProductionNames=True,
inplace=True, # avoid extra copy
removeOverlaps=True,
overlapsBackend='pathops', # use Skia's pathops
)
log.info("compiling %s -> %s (%s)", _LazyFontName(ufo), outputFilename,
"OTF/CFF-2" if cff else "TTF")
if cff:
font = ufo2ft.compileOTF(ufo, **compilerOptions)
else: # ttf
font = ufo2ft.compileTTF(ufo, **compilerOptions)
log.debug("writing %s", outputFilename)
font.save(outputFilename)
示例12: _loadDesignspace
# 需要导入模块: import defcon [as 别名]
# 或者: from defcon import Font [as 别名]
def _loadDesignspace(designspace):
log.info("loading designspace sources")
if isinstance(designspace, str):
designspace = DesignSpaceDocument.fromfile(designspace)
else:
# copy that we can mess with
designspace = DesignSpaceDocument.fromfile(designspace.path)
masters = designspace.loadSourceFonts(opener=Font)
# masters = [s.font for s in designspace.sources] # list of UFO font objects
# Update the default source's full name to not include style name
defaultFont = designspace.default.font
defaultFont.info.openTypeNameCompatibleFullName = defaultFont.info.familyName
for ufo in masters:
# update font version
updateFontVersion(ufo, dummy=False, isVF=True)
log.info("Preprocessing glyphs")
# find glyphs subject to decomposition and/or overlap removal
# TODO: Find out why this loop is SO DAMN SLOW. It might just be so that defcon is
# really slow when reading glyphs. Perhaps we can sidestep defcon and just
# read & parse the .glif files ourselves.
glyphNamesToDecompose = set() # glyph names
glyphsToRemoveOverlaps = set() # glyph objects
for ufo in masters:
for g in ufo:
if g.components and not composedGlyphIsTrivial(g):
glyphNamesToDecompose.add(g.name)
if 'removeoverlap' in findGlyphDirectives(g.note):
if g.components and len(g.components) > 0:
glyphNamesToDecompose.add(g.name)
glyphsToRemoveOverlaps.add(g)
# decompose
if glyphNamesToDecompose:
if log.isEnabledFor(logging.DEBUG):
log.debug('Decomposing glyphs:\n %s', "\n ".join(glyphNamesToDecompose))
elif log.isEnabledFor(logging.INFO):
log.info('Decomposing %d glyphs', len(glyphNamesToDecompose))
decomposeGlyphs(masters, glyphNamesToDecompose)
# remove overlaps
if glyphsToRemoveOverlaps:
rmoverlapFilter = RemoveOverlapsFilter(backend='pathops')
rmoverlapFilter.start()
if log.isEnabledFor(logging.DEBUG):
log.debug(
'Removing overlaps in glyphs:\n %s',
"\n ".join(set([g.name for g in glyphsToRemoveOverlaps])),
)
elif log.isEnabledFor(logging.INFO):
log.info('Removing overlaps in %d glyphs', len(glyphsToRemoveOverlaps))
for g in glyphsToRemoveOverlaps:
rmoverlapFilter.filter(g)
# handle control back to fontmake
return designspace