def _get_font_afm(self, prop): key = hash(prop) font = _afmfontd.get(key) if font is None: font = AFM(file(fontManager.findfont(prop, fontext='afm'))) _afmfontd[key] = font return font
def _get_font_afm(self, prop): key = hash(prop) font = _afmfontd.get(key) if font is None: font = AFM(file(fontManager.findfont(prop, fontext='afm'))) _afmfontd[key] = font return font
def test_json_serialization(): # on windows, we can't open a file twice, so save the name and unlink # manually... try: name = None with tempfile.NamedTemporaryFile(delete=False) as temp: name = temp.name json_dump(fontManager, name) copy = json_load(name) finally: if name and os.path.exists(name): os.remove(name) with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'findfont: Font family.*not found') for prop in ({ 'family': 'STIXGeneral' }, { 'family': 'Bitstream Vera Sans', 'weight': 700 }, { 'family': 'no such font family' }): fp = FontProperties(**prop) assert (fontManager.findfont( fp, rebuild_if_missing=False) == copy.findfont( fp, rebuild_if_missing=False))
def _get_font_ttf(self, prop): font = self.fonts.get(prop) if font is None: font = FT2Font(fontManager.findfont(prop)) self.fonts[prop] = font font.clear() font.set_size(prop.get_size_in_points(), 72.0) return font
def _get_font_ttf(self, prop): font = self.fonts.get(prop) if font is None: font = FT2Font(fontManager.findfont(prop)) self.fonts[prop] = font font.clear() font.set_size(prop.get_size_in_points(), 72.0) return font
def _get_font(self, prop): key = hash(prop) font = _fontd.get(key) if font is None: fname = fontManager.findfont(prop) font = FT2Font(str(fname)) _fontd[key] = font font.clear() size = prop.get_size_in_points() font.set_size(size, 72.0) return font
def fontName(self, fontprop): if is_string_like(fontprop): filename = fontprop else: filename = fontManager.findfont(fontprop) Fx = self.fontNames.get(filename, None) if Fx is None: Fx = Name('F%d' % self.nextFont) self.fontNames[filename] = Fx self.nextFont += 1 return Fx
def fontName(self, fontprop): if is_string_like(fontprop): filename = fontprop else: filename = fontManager.findfont(fontprop) Fx = self.fontNames.get(filename, None) if Fx is None: Fx = Name('F%d' % self.nextFont) self.fontNames[filename] = Fx self.nextFont += 1 return Fx
def _get_font(self, prop): key = hash(prop) font = _fontd.get(key) if font is None: fname = fontManager.findfont(prop) font = FT2Font(str(fname)) _fontd[key] = font font.clear() size = prop.get_size_in_points() font.set_size(size, 72.0) return font
def _get_font(self, prop): key = hash(prop) font = _fontd.get(key) if font is None: fname = fontManager.findfont(prop) try: font = FT2Font(str(fname)) except RuntimeError, msg: print >> sys.stderr, 'Could not load filename for text',fname return None else: _fontd[key] = font
def _get_font(self, prop): key = hash(prop) font = _fontd.get(key) if font is None: fname = fontManager.findfont(prop) try: font = FT2Font(str(fname)) except RuntimeError, msg: verbose.report_error('Could not load filename for text "%s"'%fname) return None else: _fontd[key] = font
def test_json_serialization(): with tempfile.NamedTemporaryFile() as temp: json_dump(fontManager, temp.name) copy = json_load(temp.name) with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'findfont: Font family.*not found') for prop in ({'family': 'STIXGeneral'}, {'family': 'Bitstream Vera Sans', 'weight': 700}, {'family': 'no such font family'}): fp = FontProperties(**prop) assert_equal(fontManager.findfont(fp, rebuild_if_missing=False), copy.findfont(fp, rebuild_if_missing=False))
def test_json_serialization(tmpdir): # Can't open a NamedTemporaryFile twice on Windows, so use a temporary # directory instead. path = Path(tmpdir, "fontlist.json") json_dump(fontManager, path) copy = json_load(path) with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'findfont: Font family.*not found') for prop in ({'family': 'STIXGeneral'}, {'family': 'Bitstream Vera Sans', 'weight': 700}, {'family': 'no such font family'}): fp = FontProperties(**prop) assert (fontManager.findfont(fp, rebuild_if_missing=False) == copy.findfont(fp, rebuild_if_missing=False))
def test_json_serialization(tmpdir): # Can't open a NamedTemporaryFile twice on Windows, so use a temporary # directory instead. path = Path(tmpdir, "fontlist.json") json_dump(fontManager, path) copy = json_load(path) with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'findfont: Font family.*not found') for prop in ({'family': 'STIXGeneral'}, {'family': 'Bitstream Vera Sans', 'weight': 700}, {'family': 'no such font family'}): fp = FontProperties(**prop) assert (fontManager.findfont(fp, rebuild_if_missing=False) == copy.findfont(fp, rebuild_if_missing=False))
def _get_font(self, prop): key = hash(prop) font = _fontd.get(key) if font is None: fname = fontManager.findfont(prop) try: font = FT2Font(str(fname)) except RuntimeError, msg: print >> sys.stderr, 'Could not load filename for text', fname return None else: _fontd[key] = font if fname not in _type42: _type42.append(fname)
def _get_paint_font(self, s, prop, angle): """ Get the paint font for text instance t, cacheing for efficiency """ fname = fontManager.findfont(prop) size = self.get_text_scale() * prop.get_size_in_points() props = fname, size, angle font = self.fontd.get(props) if font is None: font = paint.font(*props) self.fontd[props] = font return font
def _get_paint_font(self, s, prop, angle): """ Get the paint font for text instance t, cacheing for efficiency """ fname = fontManager.findfont(prop) size = self.get_text_scale() * prop.get_size_in_points() props = fname, size, angle font = self.fontd.get(props) if font is None: font = paint.font(*props) self.fontd[props] = font return font
def _get_font_ttf(self, prop): """ get the true type font properties, used because EMFs on windows will use true type fonts. """ key = hash(prop) font = _fontd.get(key) if font is None: fname = fontManager.findfont(prop) if debugText: print "_get_font_ttf: name=%s" % fname font = FT2Font(str(fname)) _fontd[key] = font font.clear() size = prop.get_size_in_points() font.set_size(size, self.dpi) return font
def test_json_serialization(): with tempfile.NamedTemporaryFile() as temp: json_dump(fontManager, temp.name) copy = json_load(temp.name) with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'findfont: Font family.*not found') for prop in ({ 'family': 'STIXGeneral' }, { 'family': 'Bitstream Vera Sans', 'weight': 700 }, { 'family': 'no such font family' }): fp = FontProperties(**prop) assert_equal(fontManager.findfont(fp, rebuild_if_missing=False), copy.findfont(fp, rebuild_if_missing=False))
def _get_font_ttf(self, prop): """ get the true type font properties, used because EMFs on windows will use true type fonts. """ key = hash(prop) font = _fontd.get(key) if font is None: fname = fontManager.findfont(prop) if debugText: print "_get_font_ttf: name=%s" % fname font = FT2Font(str(fname)) _fontd[key] = font font.clear() size = prop.get_size_in_points() font.set_size(size, self.dpi) return font
def draw_text(self, gc, x, y, s, prop, angle, ismath): """ Render the text using the RendererGD instance """ size = prop.get_size_in_points() font = fontManager.findfont(prop) x = int(x) y = int(y) color = self.get_gd_color(gc.get_rgb()) angle *= math.pi / 180.0 scale = self.get_text_scale() self.im.string_ft(font, scale * size, angle, (x, y), s, color) self.flush_clip()
def draw_text(self, gc, x, y, s, prop, angle, ismath): """ Render the text using the RendererGD instance """ size = prop.get_size_in_points() font = fontManager.findfont(prop) x = int(x) y = int(y) color = self.get_gd_color( gc.get_rgb() ) angle *= math.pi/180.0 scale = self.get_text_scale() self.im.string_ft(font, scale*size, angle, (x, y), s, color) self.flush_clip()
def _get_agg_font(self, prop): """ Get the font for text instance t, cacheing for efficiency """ if __debug__: verbose.report('RendererAgg._get_agg_font', 'debug-annoying') key = hash(prop) font = _fontd.get(key) if font is None: fname = fontManager.findfont(prop) font = FT2Font(str(fname)) _fontd[key] = font font.clear() size = prop.get_size_in_points() font.set_size(size, self.dpi.get()) return font
def _get_agg_font(self, prop): """ Get the font for text instance t, cacheing for efficiency """ if DEBUG: print 'RendererAgg._get_agg_font' key = hash(prop) font = _fontd.get(key) if font is None: fname = fontManager.findfont(prop) font = FT2Font(str(fname)) _fontd[key] = font font.clear() size = prop.get_size_in_points() font.set_size(size, self.dpi.get()) return font
def get_text_width_height(self, s, prop, ismath): """ get the width and height in display coords of the string s with fontsize in points """ size = prop.get_size_in_points() font = fontManager.findfont(prop) scale = self.get_text_scale() try: llx, lly, lrx, lry, urx, ury, ulx, uly = \ self.im.get_bounding_rect( font, scale*size, 0.0, (0,0), s) except ValueError: error_msg_gd('Could not load font %s. Try setting TTFFONTPATH to include this font' % fontname) w = abs(lrx - llx) h = abs(lly - uly) return w, h
def get_text_width_height(self, s, prop, ismath): """ get the width and height in display coords of the string s with fontsize in points """ size = prop.get_size_in_points() font = fontManager.findfont(prop) scale = self.get_text_scale() try: llx, lly, lrx, lry, urx, ury, ulx, uly = \ self.im.get_bounding_rect( font, scale*size, 0.0, (0,0), s) except ValueError: error_msg_gd('Could not load font %s. Try setting TTFFONTPATH to include this font' % fontname) w = abs(lrx - llx) h = abs(lly - uly) return w, h
def test_json_serialization(): # on windows, we can't open a file twice, so save the name and unlink # manually... try: name = None with tempfile.NamedTemporaryFile(delete=False) as temp: name = temp.name json_dump(fontManager, name) copy = json_load(name) finally: if name and os.path.exists(name): os.remove(name) with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'findfont: Font family.*not found') for prop in ({'family': 'STIXGeneral'}, {'family': 'Bitstream Vera Sans', 'weight': 700}, {'family': 'no such font family'}): fp = FontProperties(**prop) assert (fontManager.findfont(fp, rebuild_if_missing=False) == copy.findfont(fp, rebuild_if_missing=False))