Python matplotlib.afm() Examples
The following are 19
code examples of matplotlib.afm().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib
, or try the search function
.
Example #1
Source File: backend_pdf.py From Computable with MIT License | 6 votes |
def writeFonts(self): fonts = {} for filename, Fx in self.fontNames.iteritems(): matplotlib.verbose.report('Embedding font %s' % filename, 'debug') if filename.endswith('.afm'): # from pdf.use14corefonts matplotlib.verbose.report('Writing AFM font', 'debug') fonts[Fx] = self._write_afm_font(filename) elif filename in self.dviFontInfo: # a Type 1 font from a dvi file; the filename is really the TeX name matplotlib.verbose.report('Writing Type-1 font', 'debug') fonts[Fx] = self.embedTeXFont(filename, self.dviFontInfo[filename]) else: # a normal TrueType font matplotlib.verbose.report('Writing TrueType font', 'debug') realpath, stat_key = get_realpath_and_stat(filename) chars = self.used_characters.get(stat_key) if chars is not None and len(chars[1]): fonts[Fx] = self.embedTTF(realpath, chars[1]) self.writeObject(self.fontObject, fonts)
Example #2
Source File: backend_pdf.py From Computable with MIT License | 6 votes |
def _get_font_afm(self, prop): key = hash(prop) font = self.afm_font_cache.get(key) if font is None: filename = findfont( prop, fontext='afm', directory=self.file._core14fontdir) if filename is None: filename = findfont( "Helvetica", fontext='afm', directory=self.file._core14fontdir) font = self.afm_font_cache.get(filename) if font is None: with open(filename, 'rb') as fh: font = AFM(fh) self.afm_font_cache[filename] = font self.afm_font_cache[key] = font return font
Example #3
Source File: backend_pdf.py From matplotlib-4-abaqus with MIT License | 6 votes |
def writeFonts(self): fonts = {} for filename, Fx in self.fontNames.iteritems(): matplotlib.verbose.report('Embedding font %s' % filename, 'debug') if filename.endswith('.afm'): # from pdf.use14corefonts matplotlib.verbose.report('Writing AFM font', 'debug') fonts[Fx] = self._write_afm_font(filename) elif filename in self.dviFontInfo: # a Type 1 font from a dvi file; the filename is really the TeX name matplotlib.verbose.report('Writing Type-1 font', 'debug') fonts[Fx] = self.embedTeXFont(filename, self.dviFontInfo[filename]) else: # a normal TrueType font matplotlib.verbose.report('Writing TrueType font', 'debug') realpath, stat_key = get_realpath_and_stat(filename) chars = self.used_characters.get(stat_key) if chars is not None and len(chars[1]): fonts[Fx] = self.embedTTF(realpath, chars[1]) self.writeObject(self.fontObject, fonts)
Example #4
Source File: backend_pdf.py From matplotlib-4-abaqus with MIT License | 6 votes |
def _get_font_afm(self, prop): key = hash(prop) font = self.afm_font_cache.get(key) if font is None: filename = findfont( prop, fontext='afm', directory=self.file._core14fontdir) if filename is None: filename = findfont( "Helvetica", fontext='afm', directory=self.file._core14fontdir) font = self.afm_font_cache.get(filename) if font is None: with open(filename, 'rb') as fh: font = AFM(fh) self.afm_font_cache[filename] = font self.afm_font_cache[key] = font return font
Example #5
Source File: backend_pdf.py From dnaplotlib with MIT License | 6 votes |
def _get_font_afm(self, prop): key = hash(prop) font = self.afm_font_cache.get(key) if font is None: filename = findfont( prop, fontext='afm', directory=self.file._core14fontdir) if filename is None: filename = findfont( "Helvetica", fontext='afm', directory=self.file._core14fontdir) font = self.afm_font_cache.get(filename) if font is None: with open(filename, 'rb') as fh: font = AFM(fh) self.afm_font_cache[filename] = font self.afm_font_cache[key] = font return font
Example #6
Source File: backend_pdf.py From neural-network-animation with MIT License | 6 votes |
def writeFonts(self): fonts = {} for filename, Fx in six.iteritems(self.fontNames): matplotlib.verbose.report('Embedding font %s' % filename, 'debug') if filename.endswith('.afm'): # from pdf.use14corefonts matplotlib.verbose.report('Writing AFM font', 'debug') fonts[Fx] = self._write_afm_font(filename) elif filename in self.dviFontInfo: # a Type 1 font from a dvi file; # the filename is really the TeX name matplotlib.verbose.report('Writing Type-1 font', 'debug') fonts[Fx] = self.embedTeXFont(filename, self.dviFontInfo[filename]) else: # a normal TrueType font matplotlib.verbose.report('Writing TrueType font', 'debug') realpath, stat_key = get_realpath_and_stat(filename) chars = self.used_characters.get(stat_key) if chars is not None and len(chars[1]): fonts[Fx] = self.embedTTF(realpath, chars[1]) self.writeObject(self.fontObject, fonts)
Example #7
Source File: backend_pdf.py From neural-network-animation with MIT License | 6 votes |
def _get_font_afm(self, prop): key = hash(prop) font = self.afm_font_cache.get(key) if font is None: filename = findfont( prop, fontext='afm', directory=self.file._core14fontdir) if filename is None: filename = findfont( "Helvetica", fontext='afm', directory=self.file._core14fontdir) font = self.afm_font_cache.get(filename) if font is None: with open(filename, 'rb') as fh: font = AFM(fh) self.afm_font_cache[filename] = font self.afm_font_cache[key] = font return font
Example #8
Source File: backend_pdf.py From dnaplotlib with MIT License | 6 votes |
def writeFonts(self): fonts = {} for filename, Fx in six.iteritems(self.fontNames): matplotlib.verbose.report('Embedding font %s' % filename, 'debug') if filename.endswith('.afm'): # from pdf.use14corefonts matplotlib.verbose.report('Writing AFM font', 'debug') fonts[Fx] = self._write_afm_font(filename) elif filename in self.dviFontInfo: # a Type 1 font from a dvi file; # the filename is really the TeX name matplotlib.verbose.report('Writing Type-1 font', 'debug') fonts[Fx] = self.embedTeXFont(filename, self.dviFontInfo[filename]) else: # a normal TrueType font matplotlib.verbose.report('Writing TrueType font', 'debug') realpath, stat_key = get_realpath_and_stat(filename) chars = self.used_characters.get(stat_key) if chars is not None and len(chars[1]): fonts[Fx] = self.embedTTF(realpath, chars[1]) self.writeObject(self.fontObject, fonts)
Example #9
Source File: backend_pdf.py From ImageFusion with MIT License | 6 votes |
def writeFonts(self): fonts = {} for filename, Fx in six.iteritems(self.fontNames): matplotlib.verbose.report('Embedding font %s' % filename, 'debug') if filename.endswith('.afm'): # from pdf.use14corefonts matplotlib.verbose.report('Writing AFM font', 'debug') fonts[Fx] = self._write_afm_font(filename) elif filename in self.dviFontInfo: # a Type 1 font from a dvi file; # the filename is really the TeX name matplotlib.verbose.report('Writing Type-1 font', 'debug') fonts[Fx] = self.embedTeXFont(filename, self.dviFontInfo[filename]) else: # a normal TrueType font matplotlib.verbose.report('Writing TrueType font', 'debug') realpath, stat_key = get_realpath_and_stat(filename) chars = self.used_characters.get(stat_key) if chars is not None and len(chars[1]): fonts[Fx] = self.embedTTF(realpath, chars[1]) self.writeObject(self.fontObject, fonts)
Example #10
Source File: backend_pdf.py From ImageFusion with MIT License | 6 votes |
def _get_font_afm(self, prop): key = hash(prop) font = self.afm_font_cache.get(key) if font is None: filename = findfont( prop, fontext='afm', directory=self.file._core14fontdir) if filename is None: filename = findfont( "Helvetica", fontext='afm', directory=self.file._core14fontdir) font = self.afm_font_cache.get(filename) if font is None: with open(filename, 'rb') as fh: font = AFM(fh) self.afm_font_cache[filename] = font self.afm_font_cache[key] = font return font
Example #11
Source File: test_text.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_afm_kerning(): from matplotlib.afm import AFM from matplotlib.font_manager import findfont fn = findfont("Helvetica", fontext="afm") with open(fn, 'rb') as fh: afm = AFM(fh) assert afm.string_width_height('VAVAVAVAVAVA') == (7174.0, 718)
Example #12
Source File: backend_pdf.py From Computable with MIT License | 5 votes |
def fontName(self, fontprop): """ Select a font based on fontprop and return a name suitable for Op.selectfont. If fontprop is a string, it will be interpreted as the filename (or dvi name) of the font. """ if is_string_like(fontprop): filename = fontprop elif rcParams['pdf.use14corefonts']: filename = findfont( fontprop, fontext='afm', directory=self._core14fontdir) if filename is None: filename = findfont( "Helvetica", fontext='afm', directory=self._core14fontdir) else: filename = findfont(fontprop) Fx = self.fontNames.get(filename) if Fx is None: Fx = Name('F%d' % self.nextFont) self.fontNames[filename] = Fx self.nextFont += 1 matplotlib.verbose.report( 'Assigning font %s = %s' % (Fx, filename), 'debug') return Fx
Example #13
Source File: backend_pdf.py From dnaplotlib with MIT License | 5 votes |
def fontName(self, fontprop): """ Select a font based on fontprop and return a name suitable for Op.selectfont. If fontprop is a string, it will be interpreted as the filename (or dvi name) of the font. """ if is_string_like(fontprop): filename = fontprop elif rcParams['pdf.use14corefonts']: filename = findfont( fontprop, fontext='afm', directory=self._core14fontdir) if filename is None: filename = findfont( "Helvetica", fontext='afm', directory=self._core14fontdir) else: filename = findfont(fontprop) Fx = self.fontNames.get(filename) if Fx is None: Fx = Name('F%d' % self.nextFont) self.fontNames[filename] = Fx self.nextFont += 1 matplotlib.verbose.report( 'Assigning font %s = %r' % (Fx, filename), 'debug') return Fx
Example #14
Source File: test_text.py From coffeegrindsize with MIT License | 5 votes |
def test_afm_kerning(): from matplotlib.afm import AFM from matplotlib.font_manager import findfont fn = findfont("Helvetica", fontext="afm") with open(fn, 'rb') as fh: afm = AFM(fh) assert afm.string_width_height('VAVAVAVAVAVA') == (7174.0, 718)
Example #15
Source File: backend_pdf.py From ImageFusion with MIT License | 5 votes |
def fontName(self, fontprop): """ Select a font based on fontprop and return a name suitable for Op.selectfont. If fontprop is a string, it will be interpreted as the filename (or dvi name) of the font. """ if is_string_like(fontprop): filename = fontprop elif rcParams['pdf.use14corefonts']: filename = findfont( fontprop, fontext='afm', directory=self._core14fontdir) if filename is None: filename = findfont( "Helvetica", fontext='afm', directory=self._core14fontdir) else: filename = findfont(fontprop) Fx = self.fontNames.get(filename) if Fx is None: Fx = Name('F%d' % self.nextFont) self.fontNames[filename] = Fx self.nextFont += 1 matplotlib.verbose.report( 'Assigning font %s = %r' % (Fx, filename), 'debug') return Fx
Example #16
Source File: test_text.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_afm_kerning(): from matplotlib.afm import AFM from matplotlib.font_manager import findfont fn = findfont("Helvetica", fontext="afm") with open(fn, 'rb') as fh: afm = AFM(fh) assert afm.string_width_height('VAVAVAVAVAVA') == (7174.0, 718)
Example #17
Source File: test_text.py From neural-network-animation with MIT License | 5 votes |
def test_afm_kerning(): from matplotlib.afm import AFM from matplotlib.font_manager import findfont fn = findfont("Helvetica", fontext="afm") with open(fn, 'rb') as fh: afm = AFM(fh) assert afm.string_width_height('VAVAVAVAVAVA') == (7174.0, 718)
Example #18
Source File: backend_pdf.py From neural-network-animation with MIT License | 5 votes |
def fontName(self, fontprop): """ Select a font based on fontprop and return a name suitable for Op.selectfont. If fontprop is a string, it will be interpreted as the filename (or dvi name) of the font. """ if is_string_like(fontprop): filename = fontprop elif rcParams['pdf.use14corefonts']: filename = findfont( fontprop, fontext='afm', directory=self._core14fontdir) if filename is None: filename = findfont( "Helvetica", fontext='afm', directory=self._core14fontdir) else: filename = findfont(fontprop) Fx = self.fontNames.get(filename) if Fx is None: Fx = Name('F%d' % self.nextFont) self.fontNames[filename] = Fx self.nextFont += 1 matplotlib.verbose.report( 'Assigning font %s = %r' % (Fx, filename), 'debug') return Fx
Example #19
Source File: backend_pdf.py From matplotlib-4-abaqus with MIT License | 5 votes |
def fontName(self, fontprop): """ Select a font based on fontprop and return a name suitable for Op.selectfont. If fontprop is a string, it will be interpreted as the filename (or dvi name) of the font. """ if is_string_like(fontprop): filename = fontprop elif rcParams['pdf.use14corefonts']: filename = findfont( fontprop, fontext='afm', directory=self._core14fontdir) if filename is None: filename = findfont( "Helvetica", fontext='afm', directory=self._core14fontdir) else: filename = findfont(fontprop) Fx = self.fontNames.get(filename) if Fx is None: Fx = Name('F%d' % self.nextFont) self.fontNames[filename] = Fx self.nextFont += 1 matplotlib.verbose.report( 'Assigning font %s = %s' % (Fx, filename), 'debug') return Fx