Use font metrics for wcwidth()
This commit is contained in:
parent
b4730e747a
commit
ca57eb9d05
@ -14,7 +14,7 @@ from freetype import (
|
|||||||
FT_LOAD_NO_HINTING, FT_PIXEL_MODE_GRAY
|
FT_LOAD_NO_HINTING, FT_PIXEL_MODE_GRAY
|
||||||
)
|
)
|
||||||
|
|
||||||
from .utils import get_logical_dpi
|
from .utils import get_logical_dpi, set_current_font_metrics
|
||||||
|
|
||||||
|
|
||||||
def escape_family_name(name):
|
def escape_family_name(name):
|
||||||
@ -92,6 +92,7 @@ def set_font_family(family, size_in_pts):
|
|||||||
underline_thickness = font_units_to_pixels(face.underline_thickness, face.units_per_EM, size_in_pts, dpi[1])
|
underline_thickness = font_units_to_pixels(face.underline_thickness, face.units_per_EM, size_in_pts, dpi[1])
|
||||||
CharTexture = ctypes.c_ubyte * (cell_width * cell_height)
|
CharTexture = ctypes.c_ubyte * (cell_width * cell_height)
|
||||||
glyph_cache = GlyphCache()
|
glyph_cache = GlyphCache()
|
||||||
|
set_current_font_metrics(glyph_cache.width)
|
||||||
return cell_width, cell_height
|
return cell_width, cell_height
|
||||||
|
|
||||||
CharBitmap = namedtuple('CharBitmap', 'data bearingX bearingY advance rows columns')
|
CharBitmap = namedtuple('CharBitmap', 'data bearingX bearingY advance rows columns')
|
||||||
|
|||||||
@ -33,12 +33,13 @@ def wcwidth(c: str) -> int:
|
|||||||
return 0
|
return 0
|
||||||
if wcwidth.current_font is None:
|
if wcwidth.current_font is None:
|
||||||
return min(2, wcwidth_native(c))
|
return min(2, wcwidth_native(c))
|
||||||
wcwidth.current_font = wcwidth.cell_width = None
|
return wcwidth.current_font(c)
|
||||||
|
wcwidth.current_font = None
|
||||||
|
|
||||||
|
|
||||||
def set_current_font_metrics(current_font, cw: int) -> None:
|
def set_current_font_metrics(current_font) -> None:
|
||||||
wcwidth.cache_clear()
|
wcwidth.cache_clear()
|
||||||
wcwidth.current_font, wcwidth.cell_width = current_font, cw
|
wcwidth.current_font = current_font
|
||||||
|
|
||||||
|
|
||||||
def create_pty():
|
def create_pty():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user