23 #include <pango/pangocairo.h>
25 #ifdef HAVE_PANGO_FC_FONT_LOCK_FACE
26 #include <pango/pangofc-font.h>
29 #define N_NEW(n,t) (t*)malloc((n)*sizeof(t))
31 static void pango_free_layout (
void *
layout)
33 g_object_unref((PangoLayout*)layout);
38 static char buf[1024];
51 strcat(buf, pa->
style);
58 #define ENABLE_PANGO_MARKUP
59 #ifdef ENABLE_PANGO_MARKUP
60 #define FULL_MARKUP "<span weight=\"bold\" style=\"italic\" underline=\"single\"><sup><sub></sub></sup></span>"
63 static boolean pango_textlayout(
textspan_t * span,
char **fontpath)
65 static char buf[1024];
66 static PangoFontMap *fontmap;
67 static PangoContext *context;
68 static PangoFontDescription *desc;
69 static char *fontname;
70 static double fontsize;
72 char *fnt, *psfnt =
NULL;
74 PangoRectangle logical_rect;
75 cairo_font_options_t* options;
77 #ifdef ENABLE_PANGO_MARKUP
83 double textlayout_scale;
87 fontmap = pango_cairo_font_map_new();
89 #ifdef HAVE_PANGO_FONT_MAP_CREATE_CONTEXT
90 context = pango_font_map_create_context (fontmap);
92 context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP(fontmap));
94 options=cairo_font_options_create();
95 cairo_font_options_set_antialias(options,CAIRO_ANTIALIAS_GRAY);
96 cairo_font_options_set_hint_style(options,CAIRO_HINT_STYLE_FULL);
97 cairo_font_options_set_hint_metrics(options,CAIRO_HINT_METRICS_ON);
98 cairo_font_options_set_subpixel_order(options,CAIRO_SUBPIXEL_ORDER_BGR);
99 pango_cairo_context_set_font_options(context, options);
100 pango_cairo_context_set_resolution(context,
FONT_DPI);
101 cairo_font_options_destroy(options);
102 g_object_unref(fontmap);
105 if (!fontname || strcmp(fontname, span->
font->
name) != 0 || fontsize != span->
font->
size) {
108 pango_font_description_free (desc);
114 psfnt = fnt = pango_psfontResolve (pA);
119 desc = pango_font_description_from_string(fnt);
121 pango_font_description_set_size (desc, (gint)(fontsize * PANGO_SCALE));
123 if (fontpath && (font = pango_font_map_load_font(fontmap, context, desc))) {
124 const char *fontclass;
126 fontclass = G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(font));
130 strcat(buf,
"(ps:pango ");
135 strcat(buf, fontclass);
137 #ifdef HAVE_PANGO_FC_FONT_LOCK_FACE
138 if (strcmp(fontclass,
"PangoCairoFcFont") == 0) {
142 FT_StreamDesc streamdesc;
143 fcfont = PANGO_FC_FONT(font);
144 face = pango_fc_font_lock_face(fcfont);
147 strcat(buf, face->family_name);
149 strcat(buf, face->style_name);
152 stream = face->stream;
154 streamdesc = stream->pathname;
155 if (streamdesc.pointer)
156 strcat(buf, (
char*)streamdesc.pointer);
158 strcat(buf,
"*no pathname available*");
161 strcat(buf,
"*no stream available*");
163 pango_fc_font_unlock_face(fcfont);
168 PangoFontDescription *tdesc;
171 tdesc = pango_font_describe(font);
172 tfont = pango_font_description_to_string(tdesc);
182 #ifdef ENABLE_PANGO_MARKUP
184 unsigned char buf[BUFSIZ];
191 agxbput(&xb,
" weight=\"bold\"");
193 agxbput(&xb,
" style=\"italic\"");
195 agxbput(&xb,
" underline=\"single\"");
197 agxbput(&xb,
" strikethrough=\"true\"");
207 if (flags & HTML_SUB)
209 if (flags & HTML_SUP)
213 if (!pango_parse_markup (
agxbuse(&xb), -1, 0, &attrs, &text,
NULL, &error)) {
214 fprintf (stderr,
"Error - pango_parse_markup: %s\n", error->message);
228 layout = pango_layout_new (context);
229 span->
layout = (
void *)layout;
232 pango_layout_set_text (layout, text, -1);
233 pango_layout_set_font_description (layout, desc);
234 #ifdef ENABLE_PANGO_MARKUP
236 pango_layout_set_attributes (layout, attrs);
239 pango_layout_get_extents (layout,
NULL, &logical_rect);
242 if (logical_rect.width == 0)
243 logical_rect.height = 0;
246 span->
size.
x = (
int)(logical_rect.width * textlayout_scale + 1);
247 span->
size.
y = (
int)(logical_rect.height * textlayout_scale + 1);
259 #if !defined(_WIN32) && defined PANGO_VERSION_MAJOR && (PANGO_VERSION_MAJOR >= 1)
260 span->
yoffset_layout = pango_layout_get_baseline (layout) * textlayout_scale;
264 PangoLayoutIter *iter = pango_layout_get_iter (layout);
265 span->
yoffset_layout = pango_layout_iter_get_baseline (iter) * textlayout_scale;
272 if (logical_rect.width == 0)
282 {0,
"textlayout", 10, &pango_textlayout_engine,
NULL},
bool layout(Agraph_t *g, const char *engine)
size_t agxbput(agxbuf *xb, const char *s)
gvplugin_installed_t gvtextlayout_pango_types[]
double yoffset_centerline
PostscriptAlias * postscript_alias
void agxbinit(agxbuf *xb, unsigned int hint, unsigned char *init)
gv_font_map * get_font_mapping(PangoFontMap *pfm)
void(* free_layout)(void *layout)
void agxbfree(agxbuf *xb)
char * xml_string0(char *s, boolean raw)