예제 #1
0
    def _system_fonts_get(self, cr, uid, context=None):
        ''' get fonts list on server '''
        # consider both windows and unix like systems
        # get all folders under fonts/ directory
        res = []
        ff = FontFinder(useCache=False)
        fontdirs = []
        if not context:
            context = {}
        #if context.get('custom_font_path'):
            #fontdirs.append(context['custom_font_path'])
        fontdirs += rl_config.TTFSearchPath[:] + \
            rl_config.T1SearchPath[:] + \
            rl_config.CMapSearchPath[:]
        ff.addDirectories(set(fontdirs))
        ff.search()
        for familyName in ff.getFamilyNames():
            for font in ff.getFontsInFamily(familyName):
                if font.fileName[-4:].lower() in (".ttf", ".ttc"):
                    try:
                        fileName = font.fileName.decode('utf-8')
                    except UnicodeDecodeError:
                        #for Chinese file name(Windows OS)
                        fileName = font.fileName.decode('gbk')
                    res.append((fileName, font.name))

        #cache the font list in class variable
        oecn_base_fonts_map.system_fonts = res
        return res
예제 #2
0
def getFontList():
    global _fontfinder
    #iPhoneのフォントパスの一覧
    FPR = '/System/Library/Fonts'

    dirs = getChildDirectories(FPR)
    #DLしたフォントのパス
    _fontfinder = FontFinder(dirs)
    p = getAbsolutePath('~/Documents/fonts/ipag00303')
    _fontfinder.addDirectory(p)

    p = getAbsolutePath('~/Documents/fonts/ipam00303')
    _fontfinder.addDirectory(p)

    #利用可能なフォントを検索
    _fontfinder.search()

    #print(_fontfinder.getFamilyNames())
    for f in _fontfinder._fonts:
        familyName = _b2s(f.familyName)
        fileName = f.fileName
        fullName = _b2s(f.fullName)
        if fullName:
            atr = 'name:{}, familt:{}, file:{}'.format(fullName, familyName,
                                                       fileName)
            #print(atr)
            yield {'name': fullName, 'family': familyName, 'file': fileName}
        else:
            yield {'name': None, 'family': familyName, 'file': fileName}
예제 #3
0
    def _system_fonts_get(self, cr, uid, context=None):
        ''' get fonts list on server '''
        # consider both windows and unix like systems
        # get all folders under fonts/ directory
        res = []
        ff = FontFinder(useCache=False)
        fontdirs = []
        if not context:
            context = {}
        fontdirs += rl_config.TTFSearchPath[:] + \
            rl_config.T1SearchPath[:] + \
            rl_config.CMapSearchPath[:]
        ff.addDirectories(set(fontdirs))
        ff.search()
        for familyName in ff.getFamilyNames():
            for font in ff.getFontsInFamily(familyName):
                if font.fileName[-4:].lower() in (".ttf", ".ttc"):
                    try:
                        fileName = font.fileName.decode('utf-8')
                    except UnicodeDecodeError:
                        #for Chinese file name(Windows OS)
                        fileName = font.fileName.decode('gbk')
                    res.append((fileName, font.name))

        #cache the font list in class variable
        oecn_base_fonts_map.system_fonts = res
        return res
예제 #4
0
파일: fonts.py 프로젝트: svilendobrev/rl2wx
    "/usr/share/fonts/X11/Type1",  # X fonts
    "%(home)s/tmp/corefonts",  # extra
]

from reportlab.lib.fontfinder import FontFinder
from reportlab.lib import fonts
from reportlab import rl_config
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

import os

env = {"windir": os.environ.get("windir", os.getcwd()), "home": os.environ.get("HOME", os.getcwd())}

folders = [s % env for s in FontFolders]
ff = FontFinder(useCache=False)
paths = (rl_config.TTFSearchPath, rl_config.T1SearchPath, rl_config.CMapSearchPath)
for p in paths:
    if isinstance(p, list):
        folders += p
    else:
        folders.append(p)

ff.addDirectories(set(folders))
ff.search()


_registered_font_names = {}


def register_font(font_name, family=""):