本文整理汇总了Python中matplotlib.dviread.Dvi方法的典型用法代码示例。如果您正苦于以下问题:Python dviread.Dvi方法的具体用法?Python dviread.Dvi怎么用?Python dviread.Dvi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.dviread
的用法示例。
在下文中一共展示了dviread.Dvi方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dviread
# 需要导入模块: from matplotlib import dviread [as 别名]
# 或者: from matplotlib.dviread import Dvi [as 别名]
def test_dviread():
dir = os.path.join(os.path.dirname(__file__), 'baseline_images', 'dviread')
with open(os.path.join(dir, 'test.json')) as f:
correct = json.load(f)
for entry in correct:
entry['text'] = [[a, b, c, d.encode('ascii'), e]
for [a, b, c, d, e] in entry['text']]
with dr.Dvi(os.path.join(dir, 'test.dvi'), None) as dvi:
data = [{'text': [[t.x, t.y,
six.unichr(t.glyph),
t.font.texname,
round(t.font.size, 2)]
for t in page.text],
'boxes': [[b.x, b.y, b.height, b.width] for b in page.boxes]}
for page in dvi]
assert data == correct
示例2: get_text_width_height_descent
# 需要导入模块: from matplotlib import dviread [as 别名]
# 或者: from matplotlib.dviread import Dvi [as 别名]
def get_text_width_height_descent(self, tex, fontsize, renderer=None):
"""
return width, heigth and descent of the text.
"""
if tex.strip() == '':
return 0, 0, 0
if renderer:
dpi_fraction = renderer.points_to_pixels(1.)
else:
dpi_fraction = 1.
if rcParams['text.latex.preview']:
# use preview.sty
basefile = self.get_basefile(tex, fontsize)
baselinefile = '%s.baseline' % basefile
if DEBUG or not os.path.exists(baselinefile):
dvifile = self.make_dvi_preview(tex, fontsize)
with open(baselinefile) as fh:
l = fh.read().split()
height, depth, width = [float(l1) * dpi_fraction for l1 in l]
return width, height + depth, depth
else:
# use dviread. It sometimes returns a wrong descent.
dvifile = self.make_dvi(tex, fontsize)
dvi = dviread.Dvi(dvifile, 72 * dpi_fraction)
try:
page = next(iter(dvi))
finally:
dvi.close()
# A total height (including the descent) needs to be returned.
return page.width, page.height + page.descent, page.descent
示例3: get_text_width_height_descent
# 需要导入模块: from matplotlib import dviread [as 别名]
# 或者: from matplotlib.dviread import Dvi [as 别名]
def get_text_width_height_descent(self, tex, fontsize, renderer=None):
"""Return width, height and descent of the text."""
if tex.strip() == '':
return 0, 0, 0
dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
if rcParams['text.latex.preview']:
# use preview.sty
basefile = self.get_basefile(tex, fontsize)
baselinefile = '%s.baseline' % basefile
if not os.path.exists(baselinefile):
dvifile = self.make_dvi_preview(tex, fontsize)
with open(baselinefile) as fh:
l = fh.read().split()
height, depth, width = [float(l1) * dpi_fraction for l1 in l]
return width, height + depth, depth
else:
# use dviread. It sometimes returns a wrong descent.
dvifile = self.make_dvi(tex, fontsize)
with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
page, = dvi
# A total height (including the descent) needs to be returned.
return page.width, page.height + page.descent, page.descent
示例4: get_text_width_height_descent
# 需要导入模块: from matplotlib import dviread [as 别名]
# 或者: from matplotlib.dviread import Dvi [as 别名]
def get_text_width_height_descent(self, tex, fontsize, renderer=None):
"""Return width, height and descent of the text."""
if tex.strip() == '':
return 0, 0, 0
dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
if rcParams['text.latex.preview']:
# use preview.sty
basefile = self.get_basefile(tex, fontsize)
baselinefile = '%s.baseline' % basefile
if not os.path.exists(baselinefile):
dvifile = self.make_dvi_preview(tex, fontsize)
with open(baselinefile) as fh:
l = fh.read().split()
height, depth, width = [float(l1) * dpi_fraction for l1 in l]
return width, height + depth, depth
else:
# use dviread. It sometimes returns a wrong descent.
dvifile = self.make_dvi(tex, fontsize)
with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
page = next(iter(dvi))
# A total height (including the descent) needs to be returned.
return page.width, page.height + page.descent, page.descent
示例5: test_dviread
# 需要导入模块: from matplotlib import dviread [as 别名]
# 或者: from matplotlib.dviread import Dvi [as 别名]
def test_dviread():
dirpath = Path(__file__).parent / 'baseline_images/dviread'
with (dirpath / 'test.json').open() as f:
correct = json.load(f)
with dr.Dvi(str(dirpath / 'test.dvi'), None) as dvi:
data = [{'text': [[t.x, t.y,
chr(t.glyph),
t.font.texname.decode('ascii'),
round(t.font.size, 2)]
for t in page.text],
'boxes': [[b.x, b.y, b.height, b.width] for b in page.boxes]}
for page in dvi]
assert data == correct
示例6: get_glyphs_tex
# 需要导入模块: from matplotlib import dviread [as 别名]
# 或者: from matplotlib.dviread import Dvi [as 别名]
def get_glyphs_tex(self, prop, s, glyph_map=None,
return_new_glyphs_only=False):
"""Convert the string *s* to vertices and codes using usetex mode."""
# Mostly borrowed from pdf backend.
dvifile = self.get_texmanager().make_dvi(s, self.FONT_SCALE)
with dviread.Dvi(dvifile, self.DPI) as dvi:
page, = dvi
if glyph_map is None:
glyph_map = OrderedDict()
if return_new_glyphs_only:
glyph_map_new = OrderedDict()
else:
glyph_map_new = glyph_map
glyph_ids, xpositions, ypositions, sizes = [], [], [], []
# Gather font information and do some setup for combining
# characters into strings.
for x1, y1, dvifont, glyph, width in page.text:
font, enc = self._get_ps_font_and_encoding(dvifont.texname)
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)
# See comments in _get_ps_font_and_encoding.
if enc is not None:
index = font.get_name_index(enc[glyph])
font.load_glyph(index, flags=LOAD_TARGET_LIGHT)
else:
font.load_char(glyph, flags=LOAD_TARGET_LIGHT)
glyph_map_new[char_id] = font.get_path()
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 (list(zip(glyph_ids, xpositions, ypositions, sizes)),
glyph_map_new, myrects)