예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
def get_pixel_size(text):
    '''
    Return (width, height) of text.
    >"As in the Adobe Font Metrics File Format Specification, all 
      dimensions are given in units of 1/1000 of the scale factor 
      (point size) of the font being used."
    '''
    from matplotlib.afm import AFM

    afm_path = Path(mpl.get_data_path(), 'fonts', 'afm', 'ptmr8a.afm')
    with afm_path.open('rb') as fh:
        afm = AFM(fh)
    return afm.string_width_height(text)
예제 #4
0
 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
예제 #5
0
    def initializeUtility() -> None:
        if Utility.initialized:
            return
        Utility.initialized = True

        # For finding visual lengths of text strings
        afm_filename = os.path.join(matplotlib.get_data_path(), "fonts", "afm",
                                    "ptmr8a.afm")
        Utility.afm = AFM(open(afm_filename, "rb"))
예제 #6
0
 def _get_font_afm(self, prop):
     key = hash(prop)
     font = self.afmfontd.get(key)
     if font is None:
         fname = findfont(prop, fontext='afm')
         font = self.afmfontd.get(fname)
         if font is None:
             font = AFM(file(findfont(prop, fontext='afm')))
             self.afmfontd[fname] = font
         self.afmfontd[key] = font
     return font
예제 #7
0
파일: font.py 프로젝트: alexgorji/musurgia
def _make_afm_path_dictionary():
    def check_entry():
        old_afm = output.get((family, weight, style))
        if old_afm is not None:
            old_header = old_afm._header
            new_header = afm._header
            diff = set(old_header) ^ set(new_header)
            if diff == {b'CapHeight'}:
                if new_header.get(b'CapHeight'):
                    return True
                #
                # print('old:', old_header.get(b'CapHeight'))
                # print('new:', new_header.get(b'CapHeight'))
            elif diff == set():
                return False
            else:
                raise AttributeError(
                    f'{family},  {weight}, {style} already in dict: {old_afm} differnce: {diff}'
                )
        else:
            return True

    output = {}
    directory = Path(mpl.get_data_path(), 'fonts', 'afm')
    for file in directory.iterdir():
        afm_path = file
        with afm_path.open('rb') as fh:
            afm = AFM(fh)
        family = afm.get_familyname()
        weight = afm.get_weight().lower()
        if afm.get_angle() < 0:
            style = 'italic'
        else:
            style = 'regular'
        if check_entry():
            output[family, weight, style] = afm

    return output
예제 #8
0
from matplotlib import rcParams
from matplotlib.afm import AFM

from pytz import timezone, UnknownTimeZoneError
from unidecode import unidecode

from essentials.exceptions import *
from essentials.settings import SETTINGS

# Helvetica is the closest font to Whitney (discord uses Whitney) in afm
# This is used to estimate text width and adjust the layout of the embeds
from utils.misc import possible_timezones

afm_fname = os.path.join(rcParams['datapath'], 'fonts', 'afm', 'phvr8a.afm')
with open(afm_fname, 'rb') as fh:
    afm = AFM(fh)

AZ_EMOJIS = [(b'\\U0001f1a'.replace(b'a',
                                    bytes(hex(224 + (6 + i))[2:],
                                          "utf-8"))).decode("unicode-escape")
             for i in range(26)]


class Task:
    def __init__(self, client, ctx=None, load=False, server=None):
        self.bot = client
        self.cursor_pos = 0
        self.ctx = ctx

        self.user_ids = []
        self.user_list = []
예제 #9
0
 def __init__(self):
     self.glyphd = {}
     self.fonts = dict([
         (name, AFM(file(os.path.join(self.basepath, name) + '.afm')))
         for name in self.fnames
     ])
예제 #10
0
"""A simple script to show some values of a font in matplotlib."""

from pathlib import Path
import matplotlib as mpl
from matplotlib.afm import AFM

print("matplotlib datapath:", mpl.get_data_path())
afm_path = Path(mpl.get_data_path(), "fonts", "afm", "ptmr8a.afm")
with afm_path.open("rb") as fh:
    afm = AFM(fh)
print(
    "compare the results with:",
    "https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/afm.py",
)
print(afm.string_width_height("What the heck?"))
print(afm.get_fontname())
print(afm.get_kern_dist("A", "f"))
print(afm.get_kern_dist("A", "y"))
print(afm.get_bbox_char("!"))
def get_graphical_width(s):
    afm_filename = os.path.join(mpl.rcParams['datapath'], 'fonts', 'afm',
                                'ptmr8a.afm')
    afm = AFM(open(afm_filename))
    return afm.string_width_height(s)
예제 #12
0
"""A simple script to show some values of a font in matplotlib."""

from pathlib import Path
import matplotlib as mpl
from matplotlib.afm import AFM

print('matplotlib datapath:', mpl.get_data_path())
afm_path = Path(mpl.get_data_path(), 'fonts', 'afm', 'ptmr8a.afm')
with afm_path.open('rb') as fh:
    afm = AFM(fh)
print(
    "compare the results with:",
    "https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/afm.py"
)
print(afm.string_width_height('What the heck?'))
print(afm.get_fontname())
print(afm.get_kern_dist('A', 'f'))
print(afm.get_kern_dist('A', 'y'))
print(afm.get_bbox_char('!'))