24#ifdef HAVE_GD_FREETYPE
27#define FONTSIZE_MUCH_TOO_SMALL 0.15
29#define FONTSIZE_TOO_SMALL 1.5
31#ifndef HAVE_GD_FONTCONFIG
37char *gd_alternate_fontlist(
const char *
font) {
42 if ((p = strchr(
font,
'-')) || (p = strchr(
font,
'_')))
45 if (strcasecmp(
font,
"times-bold") == 0
48 fontlist =
strview(
"timesbd;Timesbd;TIMESBD;timesb;Timesb;TIMESB",
'\0');
50 else if (strcasecmp(
font,
"times-italic") == 0
52 fontlist =
strview(
"timesi;Timesi;TIMESI",
'\0');
54 else if (strcasecmp(
font,
"timesnewroman") == 0
55 || strcasecmp(
font,
"timesnew") == 0
56 || strcasecmp(
font,
"timesroman") == 0
58 fontlist =
strview(
"times;Times;TIMES",
'\0');
60 else if (strcasecmp(
font,
"arial-bold") == 0
62 fontlist =
strview(
"arialb;Arialb;ARIALB",
'\0');
64 else if (strcasecmp(
font,
"arial-italic") == 0
66 fontlist =
strview(
"ariali;Ariali;ARIALI",
'\0');
69 fontlist =
strview(
"helvetica;Helvetica;HELVETICA;arial;Arial;ARIAL",
'\0');
72 fontlist =
strview(
"arial;Arial;ARIAL",
'\0');
75 fontlist =
strview(
"courier;Courier;COURIER;cour",
'\0');
87 const char *separator =
" ";
89 for (
size_t i = 0; i <
sizeof(attributes) /
sizeof(attributes[0]); ++i) {
90 const char *
const a = attributes[i];
100static bool gd_textlayout(
textspan_t * span,
char **fontpath)
102 char *
err, *fontlist, *fontname;
105 gdFTStringExtra strex;
106#ifdef HAVE_GD_FONTCONFIG
113 strex.fontpath =
NULL;
114 strex.flags = gdFTEX_RETURNFONTPATHNAME | gdFTEX_RESOLUTION;
117 if (strchr(fontname,
'/'))
118 strex.flags |= gdFTEX_FONTPATHNAME;
120 strex.flags |= gdFTEX_FONTCONFIG;
140 bool fontlist_needs_free =
false;
141#ifdef HAVE_GD_FONTCONFIG
142 gdFTUseFontConfig(1);
149 fontlist = gd_alternate_fontlist(fontname);
150 fontlist_needs_free =
true;
153 err = gdImageStringFTEx(
NULL, brect, -1, fontlist,
154 fontsize, 0, 0, 0, span->
str, &strex);
155 if (fontlist_needs_free) {
165 *fontpath = strex.fontpath;
167 free (strex.fontpath);
169 if (span->
str && span->
str[0]) {
171 span->
size.
x = (double) (brect[4] - brect[0]);
185#ifdef HAVE_GD_FREETYPE
186 {0,
"textlayout", 2, &gd_textlayout_engine,
NULL},
Dynamically expanding string buffers.
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
static char * agxbdisown(agxbuf *xb)
#define FONTSIZE_MUCH_TOO_SMALL
#define FONTSIZE_TOO_SMALL
char * gd_psfontResolve(PostscriptAlias *pa)
void agerrorf(const char *fmt,...)
gvplugin_installed_t gvtextlayout_gd_types[]
platform abstraction for case-insensitive string functions
a non-owning string reference
size_t size
extent of the string in bytes
PostscriptAlias * postscript_alias
double yoffset_centerline
void(* free_layout)(void *layout)
Non-owning string references.
static char * strview_str(strview_t source)
make a heap-allocated string from this string view
static strview_t strview(const char *referent, char terminator)
create a string reference
static bool strview_case_str_eq(strview_t a, const char *b)
compare a string reference to a string for case insensitive equality