def get_resolution(context: Context) -> float: """ Returns the resolution for the Pango context. :param context: a Pango context :return: the resolution in "dots per inch". A negative value will be returned if no resolution has previously been set. """ return pangocairo.pango_cairo_context_get_resolution(context.get_pointer())
def get_text_height(pctx: pangocffi.Context, style: TextStyle, resolution_scale: float): font = FontDescription() font.set_family(style.font) font.set_absolute_size(to_pango_units(style.size)) ret = pangocffi.pango.pango_context_get_metrics(pctx.get_pointer(), font.get_pointer(), pangocffi.ffi.NULL) descent = from_pango_units( pangocffi.pango.pango_font_metrics_get_descent(ret)) ascent = from_pango_units( pangocffi.pango.pango_font_metrics_get_ascent(ret)) return (ascent + descent) * resolution_scale
def set_resolution(context: Context, dpi: float) -> None: """ Sets the resolution for the context. This is a scale factor between points specified in a PangoFontDescription and Cairo units. The default value is 96, meaning that a 10 point font will be 13 units high. (10 * 96. / 72. = 13.3). :param context: a Pango context :param dpi: the resolution in "dots per inch". (Physical inches aren't actually involved; the terminology is conventional.) A 0 or negative value means to use the resolution from the font map. """ pangocairo.pango_cairo_context_set_resolution(context.get_pointer(), dpi)
def update_context(cairo_context: cairocffi.Context, pango_context: pangocffi.Context) -> None: """ Updates a PangoContext previously created for use with Cairo to match the current transformation and target surface of a Cairo context. If any layouts have been created for the context, it's necessary to call pango_layout_context_changed() on those layouts. :param cairo_context: a Cairo context :param pango_context: a Pango context, from a pango-cairo font map """ cairo_t_pointer = _get_cairo_t_from_cairo_ctx(cairo_context) pangocairo.pango_cairo_update_context(cairo_t_pointer, pango_context.get_pointer())
def set_font_options( context: Context, options: Optional[ffi.CData] ) -> None: """ Sets the font options used when rendering text with this context. These options override any options that pango_cairo_update_context() derives from the target surface. :param context: a Pango context :param options: a cairo_font_options_t, or ``None`` to unset any previously set options. """ if options is None: options = ffi.NULL context_pointer = context.get_pointer() pangocairo.pango_cairo_context_set_font_options(context_pointer, options)
def get_font_options(context: Context) -> Optional[ffi.CData]: """ Retrieves any font rendering options previously set with pango_cairo_context_set_font_options(). This function does not report options that are derived from the target surface by pango_cairo_update_context() :param context: a Pango Context :return: a cairo_font_options_t pointer previously set on the context, otherwise ``None``. """ context_pointer = context.get_pointer() font_option_pointer = pangocairo.pango_cairo_context_get_font_options( context_pointer ) if font_option_pointer == ffi.NULL: return None return font_option_pointer
def test_layout_returns_identical_context(): context = Context() layout = Layout(context) identical_context = layout.get_context() assert identical_context.get_pointer() == context.get_pointer()
def test_context_init_identical_context(self): context = Context() identical_context = Context.from_pointer(context.get_pointer()) assert identical_context == context