2 * Copyright © 2000 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
25 static XftSymbolic XftXlfdWeights[] = {
26 { "light", FC_WEIGHT_LIGHT },
27 { "medium", FC_WEIGHT_MEDIUM },
28 { "regular", FC_WEIGHT_MEDIUM },
29 { "demibold", FC_WEIGHT_DEMIBOLD },
30 { "bold", FC_WEIGHT_BOLD },
31 { "black", FC_WEIGHT_BLACK },
34 #define NUM_XLFD_WEIGHTS (sizeof XftXlfdWeights/sizeof XftXlfdWeights[0])
36 static XftSymbolic XftXlfdSlants[] = {
37 { "r", FC_SLANT_ROMAN },
38 { "i", FC_SLANT_ITALIC },
39 { "o", FC_SLANT_OBLIQUE },
42 #define NUM_XLFD_SLANTS (sizeof XftXlfdSlants/sizeof XftXlfdSlants[0])
45 * Cut out one XLFD field, placing it in 'save' and return
49 XftSplitStr (const char *field, char *save)
66 * convert one XLFD numeric field. Return -1 if the field is '*'
70 XftGetInt(const char *ptr, int *val)
76 for (*val = 0; *ptr >= '0' && *ptr <= '9';)
77 *val = *val * 10 + *ptr++ - '0';
84 XftXlfdParse (const char *xlfd_orig, FcBool ignore_scalable, FcBool complete)
87 const char *xlfd = xlfd_orig;
90 const char *weight_name;
99 int slant_value, weight_value;
104 if (!(xlfd = strchr (foundry = ++xlfd, '-'))) return NULL;
105 if (!(xlfd = strchr (family = ++xlfd, '-'))) return NULL;
106 if (!(xlfd = strchr (weight_name = ++xlfd, '-'))) return NULL;
107 if (!(xlfd = strchr (slant = ++xlfd, '-'))) return NULL;
108 if (!(xlfd = strchr (/* setwidth_name = */ ++xlfd, '-'))) return NULL;
109 if (!(xlfd = strchr (/* add_style_name = */ ++xlfd, '-'))) return NULL;
110 if (!(xlfd = XftGetInt (++xlfd, &pixel))) return NULL;
111 if (!(xlfd = XftGetInt (++xlfd, &point))) return NULL;
112 if (!(xlfd = XftGetInt (++xlfd, &resx))) return NULL;
113 if (!(xlfd = XftGetInt (++xlfd, &resy))) return NULL;
114 if (!(xlfd = strchr (/* spacing = */ ++xlfd, '-'))) return NULL;
115 if (!(xlfd = strchr (/* average_width = */ ++xlfd, '-'))) return NULL;
116 if (!(xlfd = strchr (registry = ++xlfd, '-'))) return NULL;
117 /* make sure no fields follow this one */
118 if ((xlfd = strchr (encoding = ++xlfd, '-'))) return NULL;
123 pat = FcPatternCreate ();
127 save = (char *) malloc (strlen (foundry) + 1);
130 FcPatternDestroy (pat);
134 if (!FcPatternAddString (pat, XFT_XLFD, (FcChar8 *) xlfd_orig)) goto bail;
136 XftSplitStr (foundry, save);
137 if (save[0] && strcmp (save, "*") != 0)
138 if (!FcPatternAddString (pat, FC_FOUNDRY, (FcChar8 *) save)) goto bail;
140 XftSplitStr (family, save);
141 if (save[0] && strcmp (save, "*") != 0)
142 if (!FcPatternAddString (pat, FC_FAMILY, (FcChar8 *) save)) goto bail;
144 weight_value = _XftMatchSymbolic (XftXlfdWeights, NUM_XLFD_WEIGHTS,
145 XftSplitStr (weight_name, save),
147 if (!FcPatternAddInteger (pat, FC_WEIGHT, weight_value))
150 slant_value = _XftMatchSymbolic (XftXlfdSlants, NUM_XLFD_SLANTS,
151 XftSplitStr (slant, save),
153 if (!FcPatternAddInteger (pat, FC_SLANT, slant_value))
156 dpixel = (double) pixel;
160 if (!FcPatternAddDouble (pat, FC_SIZE, ((double) point) / 10.0)) goto bail;
161 if (pixel <= 0 && resy > 0)
163 dpixel = (double) point * (double) resy / 720.0;
168 if (!FcPatternAddDouble (pat, FC_PIXEL_SIZE, dpixel)) goto bail;
175 FcPatternDestroy (pat);