Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
glpangofont.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <glcomp/glpangofont.h>
12#include <stddef.h>
13
14static PangoLayout *get_pango_layout(char *markup_text,
15 char *fontdescription, int fontsize,
16 double *width, double *height)
17{
18 PangoFontDescription *desc;
19 PangoFontMap *fontmap;
20 PangoContext *context;
21 PangoLayout *layout;
22 int pango_width, pango_height;
23 char *text;
24 PangoAttrList *attr_list;
25 cairo_font_options_t *options;
26 fontmap = pango_cairo_font_map_get_default();
27 context = pango_font_map_create_context(fontmap);
28 options = cairo_font_options_create();
29
30 cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY);
31
32 cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_FULL);
33 cairo_font_options_set_hint_metrics(options, CAIRO_HINT_METRICS_ON);
34 cairo_font_options_set_subpixel_order(options,
35 CAIRO_SUBPIXEL_ORDER_BGR);
36
37 desc = pango_font_description_from_string(fontdescription);
38 pango_font_description_set_size(desc, (gint) (fontsize * PANGO_SCALE));
39
40 if (!pango_parse_markup
41 (markup_text, -1, '\0', &attr_list, &text, NULL, NULL))
42 return NULL;
43 layout = pango_layout_new(context);
44 pango_layout_set_text(layout, text, -1);
45 pango_layout_set_font_description(layout, desc);
46 pango_layout_set_attributes(layout, attr_list);
47 pango_font_description_free(desc);
48 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
49
50 pango_layout_get_size(layout, &pango_width, &pango_height);
51
52 *width = (double) pango_width / PANGO_SCALE;
53 *height = (double) pango_height / PANGO_SCALE;
54
55 return layout;
56}
57
58unsigned char *glCompCreatePangoTexture(char *fontdescription, int fontsize,
59 char *txt, cairo_surface_t * surface,
60 int *w, int *h)
61{
62 cairo_t *cr;
63 PangoLayout *layout;
64 double width, height;
65
66 layout =
67 get_pango_layout(txt, fontdescription, fontsize, &width, &height);
68 if (layout == NULL) {
69 return NULL;
70 }
71 //create the right size canvas for character set
72 surface =
73 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (int) width,
74 (int) height);
75
76 cr = cairo_create(surface);
77 //set pen color to white
78 cairo_set_source_rgba(cr, 1, 1, 1, 1);
79 //draw the text
80 pango_cairo_show_layout(cr, layout);
81
82
83
84 *w = (int) width;
85 *h = (int) height;
86 g_object_unref(layout);
87 cairo_destroy(cr);
88
89 return cairo_image_surface_get_data(surface);
90}
static PangoLayout * get_pango_layout(char *markup_text, char *fontdescription, int fontsize, double *width, double *height)
Definition glpangofont.c:14
unsigned char * glCompCreatePangoTexture(char *fontdescription, int fontsize, char *txt, cairo_surface_t *surface, int *w, int *h)
Definition glpangofont.c:58
node NULL
Definition grammar.y:149
static int layout(graph_t *g, layout_info *infop)
Definition layout.c:809
Definition gvpr.c:66