6 * build/parse X Font name strings
11 #include "XFontName.h"
15 extractStringField (char *name
, char *buffer
, int size
,
16 unsigned int *attrp
, unsigned int bit
)
22 while (*name
&& *name
!= '-' && size
> 0) {
29 if (buffer
[0] != '*' || buffer
[1] != '\0')
37 extractUnsignedField (char *name
, unsigned int *result
,
38 unsigned int *attrp
, unsigned int bit
)
44 name
= extractStringField (name
, buf
, sizeof (buf
), attrp
, bit
);
50 for (c
= buf
; *c
; c
++) {
53 i
= i
* 10 + (*c
- '0');
60 XParseFontName (XFontNameString fontNameString
, XFontName
*fontName
,
61 unsigned int *fontNameAttributes
)
63 char *name
= fontNameString
;
65 unsigned int attributes
= 0;
67 #define GetString(field,bit)\
68 if (!(name = extractStringField \
69 (name, temp.field, sizeof (temp.field),\
73 #define GetUnsigned(field,bit)\
74 if (!(name = extractUnsignedField \
79 GetString (Registry
, FontNameRegistry
)
80 GetString (Foundry
, FontNameFoundry
)
81 GetString (FamilyName
, FontNameFamilyName
)
82 GetString (WeightName
, FontNameWeightName
)
83 GetString (Slant
, FontNameSlant
)
84 GetString (SetwidthName
, FontNameSetwidthName
)
85 GetString (AddStyleName
, FontNameAddStyleName
)
86 GetUnsigned (PixelSize
, FontNamePixelSize
)
87 GetUnsigned (PointSize
, FontNamePointSize
)
88 GetUnsigned (ResolutionX
, FontNameResolutionX
)
89 GetUnsigned (ResolutionY
, FontNameResolutionY
)
90 GetString (Spacing
, FontNameSpacing
)
91 GetUnsigned (AverageWidth
, FontNameAverageWidth
)
92 GetString (CharSetRegistry
, FontNameCharSetRegistry
)
94 temp
.CharSetEncoding
[0] = '\0';
95 attributes
|= FontNameCharSetEncoding
;
97 GetString (CharSetEncoding
, FontNameCharSetEncoding
)
100 *fontNameAttributes
= attributes
;
105 utoa (unsigned int u
, char *s
, int size
)
112 *--t
= (u
% 10) + '0';
118 XFormatFontName (XFontName
*fontName
, unsigned int fontNameAttributes
,
119 XFontNameString fontNameString
)
122 char *name
= tmp
, *f
;
123 int left
= sizeof (tmp
) - 1;
126 #define PutString(field, bit)\
127 f = (fontNameAttributes & bit) ? \
130 if ((left -= strlen (f)) < 0) \
133 if ((*name++ = *f++) == '-') \
140 #define PutUnsigned(field, bit) \
141 f = (fontNameAttributes & bit) ? \
142 utoa (fontName->field, number, sizeof (number)) \
144 if ((left -= strlen (f)) < 0) \
149 PutString (Registry
, FontNameRegistry
)
151 PutString (Foundry
, FontNameFoundry
)
153 PutString (FamilyName
, FontNameFamilyName
)
155 PutString (WeightName
, FontNameWeightName
)
157 PutString (Slant
, FontNameSlant
)
159 PutString (SetwidthName
, FontNameSetwidthName
)
161 PutString (AddStyleName
, FontNameAddStyleName
)
163 PutUnsigned (PixelSize
, FontNamePixelSize
)
165 PutUnsigned (PointSize
, FontNamePointSize
)
167 PutUnsigned (ResolutionX
, FontNameResolutionX
)
169 PutUnsigned (ResolutionY
, FontNameResolutionY
)
171 PutString (Spacing
, FontNameSpacing
)
173 PutUnsigned (AverageWidth
, FontNameAverageWidth
)
175 PutString (CharSetRegistry
, FontNameCharSetRegistry
)
177 PutString (CharSetEncoding
, FontNameCharSetEncoding
)
179 strcpy (fontNameString
, tmp
);
184 XCompareFontName (XFontName
*name1
, XFontName
*name2
,
185 unsigned int fontNameAttributes
)
187 #define CompareString(field,bit) \
188 if (fontNameAttributes & bit) \
189 if (strcmp (name1->field, name2->field)) \
192 #define CompareUnsigned(field,bit) \
193 if (fontNameAttributes & bit) \
194 if (name1->field != name2->field) \
197 CompareString (Registry
, FontNameRegistry
)
198 CompareString (Foundry
, FontNameFoundry
)
199 CompareString (FamilyName
, FontNameFamilyName
)
200 CompareString (WeightName
, FontNameWeightName
)
201 CompareString (Slant
, FontNameSlant
)
202 CompareString (SetwidthName
, FontNameSetwidthName
)
203 CompareString (AddStyleName
, FontNameAddStyleName
)
204 CompareUnsigned (PixelSize
, FontNamePixelSize
)
205 CompareUnsigned (PointSize
, FontNamePointSize
)
206 CompareUnsigned (ResolutionX
, FontNameResolutionX
)
207 CompareUnsigned (ResolutionY
, FontNameResolutionY
)
208 CompareString (Spacing
, FontNameSpacing
)
209 CompareUnsigned (AverageWidth
, FontNameAverageWidth
)
210 CompareString (CharSetRegistry
, FontNameCharSetRegistry
)
211 CompareString (CharSetEncoding
, FontNameCharSetEncoding
)
216 XCopyFontName (XFontName
*name1
, XFontName
*name2
,
217 unsigned int fontNameAttributes
)
219 #define CopyString(field,bit) \
220 if (fontNameAttributes & bit) \
221 strcpy (name2->field, name1->field);
223 #define CopyUnsigned(field,bit) \
224 if (fontNameAttributes & bit) \
225 name2->field = name1->field;
227 CopyString (Registry
, FontNameRegistry
)
228 CopyString (Foundry
, FontNameFoundry
)
229 CopyString (FamilyName
, FontNameFamilyName
)
230 CopyString (WeightName
, FontNameWeightName
)
231 CopyString (Slant
, FontNameSlant
)
232 CopyString (SetwidthName
, FontNameSetwidthName
)
233 CopyString (AddStyleName
, FontNameAddStyleName
)
234 CopyUnsigned (PixelSize
, FontNamePixelSize
)
235 CopyUnsigned (PointSize
, FontNamePointSize
)
236 CopyUnsigned (ResolutionX
, FontNameResolutionX
)
237 CopyUnsigned (ResolutionY
, FontNameResolutionY
)
238 CopyString (Spacing
, FontNameSpacing
)
239 CopyUnsigned (AverageWidth
, FontNameAverageWidth
)
240 CopyString (CharSetRegistry
, FontNameCharSetRegistry
)
241 CopyString (CharSetEncoding
, FontNameCharSetEncoding
)