本文整理汇总了Python中matplotlib.dviread.find_tex_file函数的典型用法代码示例。如果您正苦于以下问题:Python find_tex_file函数的具体用法?Python find_tex_file怎么用?Python find_tex_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find_tex_file函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_ps_font_and_encoding
def _get_ps_font_and_encoding(texname):
tex_font_map = dviread.PsfontsMap(dviread.find_tex_file('pdftex.map'))
font_bunch = tex_font_map[texname]
if font_bunch.filename is None:
raise ValueError(
("No usable font file found for %s (%s). "
"The font may lack a Type-1 version.")
% (font_bunch.psname, texname))
font = get_font(font_bunch.filename)
for charmap_name, charmap_code in [("ADOBE_CUSTOM", 1094992451),
("ADOBE_STANDARD", 1094995778)]:
try:
font.select_charmap(charmap_code)
except (ValueError, RuntimeError):
pass
else:
break
else:
charmap_name = ""
warnings.warn("No supported encoding in font (%s)." %
font_bunch.filename)
if charmap_name == "ADOBE_STANDARD" and font_bunch.encoding:
enc0 = dviread.Encoding(font_bunch.encoding)
enc = {i: _get_adobe_standard_encoding().get(c, None)
for i, c in enumerate(enc0.encoding)}
else:
enc = {}
return font, enc
开发者ID:scott-vsi,项目名称:matplotlib,代码行数:32,代码来源:textpath.py
示例2: _get_ps_font_and_encoding
def _get_ps_font_and_encoding(texname):
tex_font_map = dviread.PsfontsMap(dviread.find_tex_file('pdftex.map'))
font_bunch = tex_font_map[texname]
if font_bunch.filename is None:
raise ValueError(
f"No usable font file found for {font_bunch.psname} "
f"({texname}). The font may lack a Type-1 version.")
font = get_font(font_bunch.filename)
if font_bunch.encoding:
# If psfonts.map specifies an encoding, use it: it gives us a
# mapping of glyph indices to Adobe glyph names; use it to convert
# dvi indices to glyph names and use the FreeType-synthesized
# unicode charmap to convert glyph names to glyph indices (with
# FT_Get_Name_Index/get_name_index), and load the glyph using
# FT_Load_Glyph/load_glyph. (That charmap has a coverage at least
# as good as, and possibly better than, the native charmaps.)
enc = dviread._parse_enc(font_bunch.encoding)
else:
# If psfonts.map specifies no encoding, the indices directly
# map to the font's "native" charmap; so don't use the
# FreeType-synthesized charmap but the native ones (we can't
# directly identify it but it's typically an Adobe charmap), and
# directly load the dvi glyph indices using FT_Load_Char/load_char.
for charmap_code in [
1094992451, # ADOBE_CUSTOM.
1094995778, # ADOBE_STANDARD.
]:
try:
font.select_charmap(charmap_code)
except (ValueError, RuntimeError):
pass
else:
break
else:
_log.warning("No supported encoding in font (%s).",
font_bunch.filename)
enc = None
return font, enc
开发者ID:QuLogic,项目名称:matplotlib,代码行数:41,代码来源:textpath.py
示例3: _get_adobe_standard_encoding
def _get_adobe_standard_encoding(self):
enc_name = dviread.find_tex_file('8a.enc')
enc = dviread.Encoding(enc_name)
return dict([(c, i) for i, c in enumerate(enc.encoding)])
开发者ID:WarrenWeckesser,项目名称:matplotlib,代码行数:4,代码来源:textpath.py
示例4: get_glyphs_tex
def get_glyphs_tex(self, prop, s, glyph_map=None,
return_new_glyphs_only=False):
"""
convert the string *s* to vertices and codes using matplotlib's usetex
mode.
"""
# codes are modstly borrowed from pdf backend.
texmanager = self.get_texmanager()
if self.tex_font_map is None:
self.tex_font_map = dviread.PsfontsMap(
dviread.find_tex_file('pdftex.map'))
if self._adobe_standard_encoding is None:
self._adobe_standard_encoding = self._get_adobe_standard_encoding()
fontsize = prop.get_size_in_points()
if hasattr(texmanager, "get_dvi"):
dvifilelike = texmanager.get_dvi(s, self.FONT_SCALE)
dvi = dviread.DviFromFileLike(dvifilelike, self.DPI)
else:
dvifile = texmanager.make_dvi(s, self.FONT_SCALE)
dvi = dviread.Dvi(dvifile, self.DPI)
with dvi:
page = next(iter(dvi))
if glyph_map is None:
glyph_map = dict()
if return_new_glyphs_only:
glyph_map_new = dict()
else:
glyph_map_new = glyph_map
glyph_ids, xpositions, ypositions, sizes = [], [], [], []
# Gather font information and do some setup for combining
# characters into strings.
# oldfont, seq = None, []
for x1, y1, dvifont, glyph, width in page.text:
font_and_encoding = self._ps_fontd.get(dvifont.texname)
font_bunch = self.tex_font_map[dvifont.texname]
if font_and_encoding is None:
font = get_font(font_bunch.filename)
for charmap_name, charmap_code in [("ADOBE_CUSTOM",
1094992451),
("ADOBE_STANDARD",
1094995778)]:
try:
font.select_charmap(charmap_code)
except (ValueError, RuntimeError):
pass
else:
break
else:
charmap_name = ""
warnings.warn("No supported encoding in font (%s)." %
font_bunch.filename)
if charmap_name == "ADOBE_STANDARD" and font_bunch.encoding:
enc0 = dviread.Encoding(font_bunch.encoding)
enc = dict([(i, self._adobe_standard_encoding.get(c, None))
for i, c in enumerate(enc0.encoding)])
else:
enc = dict()
self._ps_fontd[dvifont.texname] = font, enc
else:
font, enc = font_and_encoding
ft2font_flag = LOAD_TARGET_LIGHT
char_id = self._get_char_id_ps(font, glyph)
if char_id not in glyph_map:
font.clear()
font.set_size(self.FONT_SCALE, self.DPI)
if enc:
charcode = enc.get(glyph, None)
else:
charcode = glyph
if charcode is not None:
glyph0 = font.load_char(charcode, flags=ft2font_flag)
else:
warnings.warn("The glyph (%d) of font (%s) cannot be "
"converted with the encoding. Glyph may "
"be wrong" % (glyph, font_bunch.filename))
glyph0 = font.load_char(glyph, flags=ft2font_flag)
glyph_map_new[char_id] = self.glyph_to_path(font)
glyph_ids.append(char_id)
xpositions.append(x1)
ypositions.append(y1)
#.........这里部分代码省略.........
开发者ID:WarrenWeckesser,项目名称:matplotlib,代码行数:101,代码来源:textpath.py
示例5: tex_font_map
def tex_font_map(self):
return dviread.PsfontsMap(dviread.find_tex_file('pdftex.map'))
开发者ID:scott-vsi,项目名称:matplotlib,代码行数:2,代码来源:textpath.py
示例6: _get_adobe_standard_encoding
def _get_adobe_standard_encoding():
enc_name = dviread.find_tex_file('8a.enc')
enc = dviread.Encoding(enc_name)
return {c: i for i, c in enumerate(enc.encoding)}
开发者ID:scott-vsi,项目名称:matplotlib,代码行数:4,代码来源:textpath.py
示例7: get_glyphs_tex
def get_glyphs_tex(self, prop, s, glyph_map=None,
return_new_glyphs_only=False):
"""
convert the string *s* to vertices and codes using matplotlib's usetex mode.
"""
# codes are modstly borrowed from pdf backend.
texmanager = self.get_texmanager()
if self.tex_font_map is None:
self.tex_font_map = dviread.PsfontsMap(dviread.find_tex_file('pdftex.map'))
fontsize = prop.get_size_in_points()
if hasattr(texmanager, "get_dvi"): #
dvifilelike = texmanager.get_dvi(s, self.FONT_SCALE)
dvi = dviread.DviFromFileLike(dvifilelike, self.DPI)
else:
dvifile = texmanager.make_dvi(s, self.FONT_SCALE)
dvi = dviread.Dvi(dvifile, self.DPI)
page = iter(dvi).next()
dvi.close()
if glyph_map is None:
glyph_map = dict()
if return_new_glyphs_only:
glyph_map_new = dict()
else:
glyph_map_new = glyph_map
glyph_ids, xpositions, ypositions, sizes = [], [], [], []
# Gather font information and do some setup for combining
# characters into strings.
#oldfont, seq = None, []
for x1, y1, dvifont, glyph, width in page.text:
font_and_encoding = self._ps_fontd.get(dvifont.texname)
if font_and_encoding is None:
font_bunch = self.tex_font_map[dvifont.texname]
font = FT2Font(font_bunch.filename)
if font_bunch.encoding:
enc = dviread.Encoding(font_bunch.encoding)
else:
enc = None
self._ps_fontd[dvifont.texname] = font, enc
else:
font, enc = font_and_encoding
ft2font_flag = LOAD_TARGET_LIGHT
if enc:
ng = font.get_name_index(enc.encoding[glyph])
else:
ng = glyph
char_id = self._get_char_id_ps(font, ng)
if not char_id in glyph_map:
font.clear()
font.set_size(self.FONT_SCALE, self.DPI)
if ng == 0:
# While 0 is a valid index (e.g., "-", "\Gamma"),
# font.load_glyph(0) does not seem to work. This
# may not be a general solution.
glyph0 = font.load_glyph(128, flags=ft2font_flag)
else:
glyph0 = font.load_glyph(ng, flags=ft2font_flag)
glyph_map_new[char_id] = self.glyph_to_path(glyph0)
glyph_ids.append(char_id)
xpositions.append(x1)
ypositions.append(y1)
sizes.append(dvifont.size/self.FONT_SCALE)
myrects = []
for ox, oy, h, w in page.boxes:
vert1=[(ox, oy), (ox+w, oy), (ox+w, oy+h), (ox, oy+h), (ox, oy), (0,0)]
code1 = [Path.MOVETO,
Path.LINETO, Path.LINETO, Path.LINETO, Path.LINETO,
Path.CLOSEPOLY]
myrects.append((vert1, code1))
return zip(glyph_ids, xpositions, ypositions, sizes), glyph_map, myrects
开发者ID:zoccolan,项目名称:eyetracker,代码行数:91,代码来源:textpath.py
注:本文中的matplotlib.dviread.find_tex_file函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论