Example #1
0
def list_fonts():
    for fd in coretext_all_fonts():
        f = fd['family']
        if f:
            fn = (f + ' ' + (fd['style'] or '')).strip()
            is_mono = bool(fd['monospace'])
            yield {'family': f, 'full_name': fn, 'is_monospace': is_mono}
Example #2
0
def list_fonts() -> Generator[ListedFont, None, None]:
    for fd in coretext_all_fonts():
        f = fd['family']
        if f:
            fn = (f + ' ' + (fd['style'] or '')).strip()
            is_mono = bool(fd['monospace'])
            yield {'family': f, 'full_name': fn, 'postscript_name': fd['postscript_name'] or '', 'is_monospace': is_mono}
Example #3
0
def set_font_family(opts, override_font_size=None, ignore_dpi_failure=False):
    global cell_width, cell_height, baseline, CellTexture, WideCellTexture, underline_thickness, underline_position
    try:
        dpi = get_logical_dpi()
    except Exception:
        if not ignore_dpi_failure:
            raise
        dpi = (72, 72)  # Happens when running via develop() in an ssh session
    dpi = sum(dpi) / 2.0
    font_size = override_font_size or opts.font_size
    all_fonts = create_font_map(coretext_all_fonts())

    for (bold, italic), attr in attr_map.items():
        main_font[(bold, italic)] = get_face(all_fonts, getattr(opts, attr),
                                             opts.font_family, font_size, dpi,
                                             bold, italic)

    install_symbol_map(all_fonts, opts.symbol_map, font_size, dpi)
    mf = main_font[(False, False)]
    cell_width, cell_height = mf.cell_size()
    cell_height = adjust_line_height(cell_height, opts.adjust_line_height)
    CellTexture = ctypes.c_ubyte * (cell_width * cell_height)
    WideCellTexture = ctypes.c_ubyte * (2 * cell_width * cell_height)
    baseline = int(round(mf.ascent))
    underline_position = int(round(baseline - mf.underline_position))
    underline_thickness = ceil_int(mf.underline_thickness)
    return cell_width, cell_height
Example #4
0
def test_family_matching(name='Menlo', dpi=72.0, font_size=11.0):
    all_fonts = create_font_map(coretext_all_fonts())
    for bold in (False, True):
        for italic in (False, True):
            face = get_face(all_fonts, name, 'Menlo', font_size, dpi, bold,
                            italic)
            print(bold, italic, face)
Example #5
0
def test_font_matching(name='Menlo',
                       bold=False,
                       italic=False,
                       dpi=72.0,
                       font_size=11.0):
    all_fonts = create_font_map(coretext_all_fonts())
    face = get_face(all_fonts, name, 'Menlo', font_size, dpi, bold, italic)
    return face
Example #6
0
def all_fonts_map() -> FontMap:
    ans: Optional[FontMap] = getattr(all_fonts_map, 'ans', None)
    if ans is None:
        ans = create_font_map(coretext_all_fonts())
        setattr(all_fonts_map, 'ans', ans)
    return ans
Example #7
0
def all_fonts_map():
    ans = getattr(all_fonts_map, 'ans', None)
    if ans is None:
        ans = all_fonts_map.ans = create_font_map(coretext_all_fonts())
    return ans