float draw_get_font_size (drawctx_t *ctx) { draw_init_font (ctx, NULL); GdkScreen *screen = gdk_screen_get_default (); float dpi = gdk_screen_get_resolution (screen); PangoFontDescription *desc = ctx->font_style->font_desc; return (float)(pango_font_description_get_size (desc) / PANGO_SCALE * dpi / 72); }
void draw_get_text_extents (drawctx_t *ctx, const char *text, int len, int *w, int *h) { draw_init_font (ctx, 0, 0); pango_layout_set_width (ctx->pangolayout, -1); pango_layout_set_alignment (ctx->pangolayout, PANGO_ALIGN_LEFT); pango_layout_set_text (ctx->pangolayout, text, len); draw_get_layout_extents (ctx, w, h); }
void draw_text (drawctx_t *ctx, float x, float y, int width, int align, const char *text) { draw_init_font (ctx, NULL); pango_layout_set_width (ctx->pangolayout, width*PANGO_SCALE); pango_layout_set_alignment (ctx->pangolayout, align ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT); pango_layout_set_text (ctx->pangolayout, text, -1); cairo_move_to (ctx->drawable, x, y); pango_cairo_show_layout (ctx->drawable, ctx->pangolayout); }
void draw_text (drawctx_t *ctx, float x, float y, int width, int align, const char *text) { draw_init_font (ctx, 0, 0); pango_layout_set_width (ctx->pangolayout, width*PANGO_SCALE); pango_layout_set_alignment (ctx->pangolayout, get_pango_alignment (align)); pango_layout_set_text (ctx->pangolayout, text, -1); cairo_move_to (ctx->drawable, x, y); pango_cairo_show_layout (ctx->drawable, ctx->pangolayout); }
void draw_get_text_extents (drawctx_t *ctx, const char *text, int len, int *w, int *h) { draw_init_font (ctx, NULL); pango_layout_set_width (ctx->pangolayout, 1000 * PANGO_SCALE); pango_layout_set_alignment (ctx->pangolayout, PANGO_ALIGN_LEFT); pango_layout_set_text (ctx->pangolayout, text, len); PangoRectangle ink; PangoRectangle log; pango_layout_get_pixel_extents (ctx->pangolayout, &ink, &log); *w = ink.width; *h = ink.height; }
void draw_text_custom (drawctx_t *ctx, float x, float y, int width, int align, int type, int bold, int italic, const char *text) { draw_init_font (ctx, type, 0); if (bold || italic) { draw_init_font_style (ctx, bold, italic, type); } pango_layout_set_width (ctx->pangolayout, width*PANGO_SCALE); pango_layout_set_alignment (ctx->pangolayout, get_pango_alignment (align)); pango_layout_set_text (ctx->pangolayout, text, -1); cairo_move_to (ctx->drawable, x, y); pango_cairo_show_layout (ctx->drawable, ctx->pangolayout); }