def render_special(underline=0, strikethrough=False, missing=False): s = set_font_family.state cell_width, cell_height, baseline = s.cell_width, s.cell_height, s.baseline underline_position, underline_thickness = s.underline_position, s.underline_thickness underline_position = min(underline_position, cell_height - underline_thickness) CharTexture = ctypes.c_ubyte * (cell_width * cell_height) ans = CharTexture if missing else CharTexture() def dl(f, *a): f(ans, cell_width, *a) if underline: t = underline_thickness if underline == 2: t = max(1, min(cell_height - underline_position - 1, t)) dl(add_curl if underline == 2 else add_line, underline_position, t, cell_height) if strikethrough: pos = int(0.65 * baseline) dl(add_line, pos, underline_thickness, cell_height) if missing: buf = bytearray(cell_width * cell_height) render_missing_glyph(buf, cell_width, cell_height) ans = CharTexture.from_buffer(buf) return ans
def render_special(underline=0, strikethrough=False, missing=False, cell_width=None, cell_height=None, baseline=None, underline_position=None, underline_thickness=None): underline_position = min(underline_position, cell_height - underline_thickness) CharTexture = ctypes.c_ubyte * (cell_width * cell_height) ans = CharTexture if missing else CharTexture() def dl(f, *a): f(ans, cell_width, *a) if underline: t = underline_thickness if underline > 1: t = max(1, min(cell_height - underline_position - 1, t)) dl([None, add_line, add_dline, add_curl][underline], underline_position, t, cell_height) if strikethrough: pos = int(0.65 * baseline) dl(add_line, pos, underline_thickness, cell_height) if missing: buf = bytearray(cell_width * cell_height) render_missing_glyph(buf, cell_width, cell_height) ans = CharTexture.from_buffer(buf) return ans
def missing_glyph(width): w = cell_width * width ans = bytearray(w * cell_height) render_missing_glyph(ans, w, cell_height) first, second = CharBitmap(ans, 0, 0, 0, cell_height, w), None if width == 2: first, second = split_char_bitmap(first) second = create_cell_buffer(second, 0, 0, second.rows, 0, 0, second.columns) first = create_cell_buffer(first, 0, 0, first.rows, 0, 0, first.columns) return first, second
def missing_glyph(num_cells, cell_width, cell_height): w = cell_width * num_cells ans = bytearray(w * cell_height) render_missing_glyph(ans, w, cell_height) buf = (ctypes.c_ubyte * w * cell_height).from_buffer(ans) face = current_font_family['regular'].face bufs = tuple(CharTexture() for i in range(num_cells)) face.split_cells(cell_width, cell_height, ctypes.addressof(buf), *(ctypes.addressof(x) for x in bufs)) if num_cells == 2: first, second = bufs else: first, second = bufs[0], None return first, second
def render_special( underline: int = 0, strikethrough: bool = False, missing: bool = False, cell_width: int = 0, cell_height: int = 0, baseline: int = 0, underline_position: int = 0, underline_thickness: int = 0, strikethrough_position: int = 0, strikethrough_thickness: int = 0, dpi_x: float = 96., dpi_y: float = 96., ) -> ctypes.Array: underline_position = min(underline_position, cell_height - underline_thickness) CharTexture = ctypes.c_ubyte * (cell_width * cell_height) if missing: buf = bytearray(cell_width * cell_height) render_missing_glyph(buf, cell_width, cell_height) return CharTexture.from_buffer(buf) ans = CharTexture() def dl(f: UnderlineCallback, *a: Any) -> None: try: f(ans, cell_width, *a) except Exception as e: log_error( 'Failed to render {} at cell_width={} and cell_height={} with error: {}' .format(f.__name__, cell_width, cell_height, e)) if underline: t = underline_thickness if underline > 1: t = max(1, min(cell_height - underline_position - 1, t)) dl([add_line, add_line, add_dline, add_curl][underline], underline_position, t, cell_height) if strikethrough: dl(add_line, strikethrough_position, strikethrough_thickness, cell_height) return ans
def render_special(underline=0, strikethrough=False, missing=False, cell_width=None, cell_height=None, baseline=None, underline_position=None, underline_thickness=None): underline_position = min(underline_position, cell_height - underline_thickness) CharTexture = ctypes.c_ubyte * (cell_width * cell_height) ans = CharTexture if missing else CharTexture() def dl(f, *a): try: f(ans, cell_width, *a) except Exception as e: log_error( 'Failed to render {} at cell_width={} and cell_height={} with error: {}' .format(f.__name__, cell_width, cell_height, e)) if underline: t = underline_thickness if underline > 1: t = max(1, min(cell_height - underline_position - 1, t)) dl([None, add_line, add_dline, add_curl][underline], underline_position, t, cell_height) if strikethrough: pos = int(0.65 * baseline) dl(add_line, pos, underline_thickness, cell_height) if missing: buf = bytearray(cell_width * cell_height) render_missing_glyph(buf, cell_width, cell_height) ans = CharTexture.from_buffer(buf) return ans