예제 #1
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        ctx = gc.ctx
        width, height, descent, glyphs, rects = self.mathtext_parser.parse(
            s, self.dpi, prop)

        ctx.save()
        ctx.translate(x, y)
        if angle:
            ctx.rotate(np.deg2rad(-angle))

        for font, fontsize, s, ox, oy in glyphs:
            ctx.new_path()
            ctx.move_to(ox, oy)

            fontProp = ttfFontProperty(font)
            ctx.select_font_face(fontProp.name,
                                 self.fontangles[fontProp.style],
                                 self.fontweights[fontProp.weight])

            size = fontsize * self.dpi / 72.0
            ctx.set_font_size(size)
            ctx.show_text(s)

        for ox, oy, w, h in rects:
            ctx.new_path()
            ctx.rectangle(ox, oy, w, h)
            ctx.set_source_rgb(0, 0, 0)
            ctx.fill_preserve()

        ctx.restore()
예제 #2
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        ctx = gc.ctx
        width, height, descent, glyphs, rects = self.mathtext_parser.parse(
            s, self.dpi, prop)

        ctx.save()
        ctx.translate(x, y)
        if angle:
            ctx.rotate(np.deg2rad(-angle))

        for font, fontsize, s, ox, oy in glyphs:
            ctx.new_path()
            ctx.move_to(ox, oy)

            fontProp = ttfFontProperty(font)
            ctx.select_font_face(fontProp.name,
                                 self.fontangles[fontProp.style],
                                 self.fontweights[fontProp.weight])

            size = fontsize * self.dpi / 72.0
            ctx.set_font_size(size)
            ctx.show_text(s)

        for ox, oy, w, h in rects:
            ctx.new_path()
            ctx.rectangle(ox, oy, w, h)
            ctx.set_source_rgb(0, 0, 0)
            ctx.fill_preserve()

        ctx.restore()
예제 #3
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        ctx = gc.ctx
        width, height, descent, glyphs, rects = \
            self._text2path.mathtext_parser.parse(s, self.dpi, prop)

        ctx.save()
        ctx.translate(x, y)
        if angle:
            ctx.rotate(np.deg2rad(-angle))

        for font, fontsize, idx, ox, oy in glyphs:
            ctx.new_path()
            ctx.move_to(ox, -oy)
            ctx.select_font_face(
                *_cairo_font_args_from_font_prop(ttfFontProperty(font)))
            ctx.set_font_size(fontsize * self.dpi / 72)
            ctx.show_text(chr(idx))

        for ox, oy, w, h in rects:
            ctx.new_path()
            ctx.rectangle(ox, -oy, w, -h)
            ctx.set_source_rgb(0, 0, 0)
            ctx.fill_preserve()

        ctx.restore()
예제 #4
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        if _debug: print '%s.%s()' % (self.__class__.__name__, _fn_name())

        ctx = gc.ctx
        width, height, descent, glyphs, rects = self.mathtext_parser.parse(
            s, self.dpi, prop)

        ctx.save()
        ctx.translate(x, y)
        if angle:
           ctx.rotate (-angle * npy.pi / 180)

        for font, fontsize, s, ox, oy in glyphs:
           ctx.new_path()
           ctx.move_to(ox, oy)

           fontProp = ttfFontProperty(font)
           ctx.save()
           ctx.select_font_face (fontProp.name,
                                 self.fontangles [fontProp.style],
                                 self.fontweights[fontProp.weight])

           size = fontsize * self.dpi / 72.0
           ctx.set_font_size(size)
           ctx.show_text(s.encode("utf-8"))
           ctx.restore()

        for ox, oy, w, h in rects:
           ctx.new_path()
           ctx.rectangle (ox, oy, w, h)
           ctx.set_source_rgb (0, 0, 0)
           ctx.fill_preserve()

        ctx.restore()
예제 #5
0
    def _draw_mathtext(self, gc, x, y, s, prop, angle):
        if _debug: print('%s.%s()' % (self.__class__.__name__, _fn_name()))

        ctx = gc.ctx
        width, height, descent, glyphs, rects = self.mathtext_parser.parse(
            s, self.dpi, prop)

        ctx.save()
        ctx.translate(x, y)
        if angle:
            ctx.rotate(-angle * np.pi / 180)

        for font, fontsize, s, ox, oy in glyphs:
            ctx.new_path()
            ctx.move_to(ox, oy)

            fontProp = ttfFontProperty(font)
            ctx.save()
            ctx.select_font_face(fontProp.name,
                                 self.fontangles[fontProp.style],
                                 self.fontweights[fontProp.weight])

            size = fontsize * self.dpi / 72.0
            ctx.set_font_size(size)
            ctx.show_text(s.encode("utf-8"))
            ctx.restore()

        for ox, oy, w, h in rects:
            ctx.new_path()
            ctx.rectangle(ox, oy, w, h)
            ctx.set_source_rgb(0, 0, 0)
            ctx.fill_preserve()

        ctx.restore()
예제 #6
0
def add_fonts(verbose: bool = False):

    # Remove fontlist:
    for file in glob.glob('~/.matplotlib/font*.json'):
        os.remove(file)

    # Fonts
    fontfiles = glob.glob(os.path.join(FONTS, "*.tt?"))

    # for name, fname in fontdict.items():
    for fname in fontfiles:

        font = ft.FT2Font(fname)

        # Just to verify what kind of fonts are added verifiably
        if verbose:
            print(fname, "Scalable:", font.scalable)
            for style in ('Italic', 'Bold', 'Scalable', 'Fixed sizes',
                          'Fixed width', 'SFNT', 'Horizontal', 'Vertical',
                          'Kerning', 'Fast glyphs', 'Multiple masters',
                          'Glyph names', 'External stream'):
                bitpos = getattr(ft, style.replace(' ', '_').upper()) - 1
                print(f"{style+':':17}",
                      bool(font.style_flags & (1 << bitpos)))

        # Actually adding the fonts
        fe = fm.ttfFontProperty(font)
        fm.fontManager.ttflist.insert(0, fe)
예제 #7
0
 def __init__(self, *args, **kwargs):
     # Initialize font
     # NOTE: Could also capture the 'default_font_prop' passed as positional
     # argument but want to guard against keyword changes. This entire API is
     # private and it is easier to do graceful fallback with _fonts dictionary.
     ctx = {}  # rc context
     regular = {}  # styles
     for texfont in ('cal', 'rm', 'tt', 'it', 'bf', 'sf'):
         key = 'mathtext.' + texfont
         prop = mpl.rcParams[key]
         if prop.startswith('regular'):
             ctx[key] = prop.replace('regular', 'sans', 1)
             regular[texfont] = prop
     with mpl.rc_context(ctx):
         super().__init__(*args, **kwargs)
     # Apply current font replacements
     global WARN_MATHPARSER
     if (hasattr(self, 'fontmap') and hasattr(self, '_fonts')
             and 'regular' in self._fonts):
         font = self._fonts['regular']  # an ft2font.FT2Font instance
         font = ttfFontProperty(font)
         for texfont, prop in regular.items():
             prop = prop.replace('regular', font.name)
             self.fontmap[texfont] = findfont(prop,
                                              fallback_to_default=False)
     elif WARN_MATHPARSER:
         # Suppress duplicate warnings in case API changes
         warnings._warn_proplot('Failed to update the math text parser.')
         WARN_MATHPARSER = False
예제 #8
0
def test_get_font_names():
    paths_mpl = [cbook._get_data_path('fonts', subdir) for subdir in ['ttf']]
    fonts_mpl = findSystemFonts(paths_mpl, fontext='ttf')
    fonts_system = findSystemFonts(fontext='ttf')
    ttf_fonts = []
    for path in fonts_mpl + fonts_system:
        try:
            font = ft2font.FT2Font(path)
            prop = ttfFontProperty(font)
            ttf_fonts.append(prop.name)
        except:
            pass
    available_fonts = sorted(list(set(ttf_fonts)))
    mpl_font_names = sorted(fontManager.get_font_names())
    assert len(available_fonts) == len(mpl_font_names)
    assert available_fonts == mpl_font_names
예제 #9
0
파일: fm.py 프로젝트: xufive/wxgl
    def __init__(self):
        self.fonts = dict()
        for item in mfm.fontManager.ttflist:
            if item.name in self.fonts:
                self.fonts[item.name].append(item)
            else:
                self.fonts.update({item.name: [item]})

        # 设置默认字体
        if 'Microsoft YaHei' in self.fonts:
            self.default_font = 'Microsoft YaHei'  # 微软雅黑
        elif 'STSong' in self.fonts:
            self.default_font = 'STSong'  # 宋体
        elif 'FangSong' in self.fonts:
            self.default_font = 'FangSong'  # 仿宋
        else:
            self.default_font = mfm.ttfFontProperty(
                mfm.get_font(mfm.findfont(''))).name  # matplotlib默认字体
예제 #10
0
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5 import NavigationToolbar2QT as NavigationToolbar
from matplotlib import ft2font
from bs4 import BeautifulSoup


LocationOfMySelf=os.path.dirname(__file__)

print(LocationOfMySelf)

fpath = LocationOfMySelf+('/geopython/wqy.ttf')

font = ft2font.FT2Font(fpath)
fprop = font_manager.FontProperties(fname=fpath)

ttfFontProp = ttfFontProperty(font)
fontprop = font_manager.FontProperties(family='sans-serif',
                            #name=ap.fontprop.name,
                            size=9,
                            fname=ttfFontProp.fname,
                            stretch=ttfFontProp.stretch,
                            style=ttfFontProp.style,
                            variant=ttfFontProp.variant,
                            weight=ttfFontProp.weight)

plt.rcParams['svg.fonttype'] = 'none'
plt.rcParams['pdf.fonttype'] = 'truetype'
plt.rcParams['axes.unicode_minus']=False


예제 #11
0
from matplotlib.backends.backend_qt5 import NavigationToolbar2QT as NavigationToolbar
from matplotlib import ft2font
from bs4 import BeautifulSoup
#from geopytool.TableViewer import TableViewer


LocationOfMySelf=os.path.dirname(__file__)

#print(LocationOfMySelf,'Import Denpendence')

fpath = LocationOfMySelf+('/wqy.ttf')

font = ft2font.FT2Font(fpath)
fprop = font_manager.FontProperties(fname=fpath)

ttfFontProp = ttfFontProperty(font)
fontprop = font_manager.FontProperties(family='sans-serif',
                            size=9,
                            fname=ttfFontProp.fname,
                            stretch=ttfFontProp.stretch,
                            style=ttfFontProp.style,
                            variant=ttfFontProp.variant,
                            weight=ttfFontProp.weight)


'''
fontprop = font_manager.FontProperties(family='sans-serif',
                            size=9,
                            fname=ttfFontProp.fname,
                            stretch=ttfFontProp.stretch,
                            style=ttfFontProp.style,