5 #include <WINGs/WUtil.h>
7 #include "../src/wconfig.h"
9 #define DEFAULT_FONT "sans:pixelsize=12"
12 countChar(char *str
, char c
)
19 for (; *str
!=0; str
++) {
34 #define XLFD_TOKENS 14
38 getXLFDTokens(char *xlfd
)
40 static str tokens
[XLFD_TOKENS
];
44 if (!xlfd
|| *xlfd
!='-' || countChar(xlfd
, '-')<XLFD_TOKENS
)
47 memset(tokens
, 0, sizeof(str
)*XLFD_TOKENS
);
51 for (ptr
=xlfd
, i
=0; i
<XLFD_TOKENS
&& len
>0; i
++) {
57 size
= strcspn(ptr
, "-");
73 if (token
->len
==0 || token
->str
[0]=='*') {
76 for (res
=0, pos
=0; pos
<token
->len
; pos
++) {
77 c
= token
->str
[pos
] - '0';
88 mapSlantToName(str
*slant
)
90 if (slant
->len
==0 || slant
->str
[0]=='*')
93 switch(slant
->str
[0]) {
106 xlfdToFc(char *xlfd
, char *useFamily
, Bool keepXLFD
)
108 str
*tokens
, *family
, *weight
, *slant
;
109 char *name
, buf
[512];
112 tokens
= getXLFDTokens(xlfd
);
114 return wstrdup(DEFAULT_FONT
);
116 family
= &(tokens
[1]);
117 weight
= &(tokens
[2]);
118 slant
= &(tokens
[3]);
121 name
= wstrdup(useFamily
);
123 if (family
->len
==0 || family
->str
[0]=='*')
124 return wstrdup(DEFAULT_FONT
);
126 sprintf(buf
, "%.*s", family
->len
, family
->str
);
130 pixelsize
= strToInt(&tokens
[6]);
131 size
= strToInt(&tokens
[7]);
133 if (size
<=0 && pixelsize
<=0) {
134 name
= wstrappend(name
, ":pixelsize=12");
135 } else if (pixelsize
>0) {
136 /* if pixelsize is present size will be ignored so we skip it */
137 sprintf(buf
, ":pixelsize=%d", pixelsize
);
138 name
= wstrappend(name
, buf
);
140 sprintf(buf
, "-%d", size
/10);
141 name
= wstrappend(name
, buf
);
144 if (weight
->len
>0 && weight
->str
[0]!='*') {
145 sprintf(buf
, ":weight=%.*s", weight
->len
, weight
->str
);
146 name
= wstrappend(name
, buf
);
149 if (slant
->len
>0 && slant
->str
[0]!='*') {
150 sprintf(buf
, ":slant=%s", mapSlantToName(slant
));
151 name
= wstrappend(name
, buf
);
155 name
= wstrappend(name
, ":xlfd=");
156 name
= wstrappend(name
, xlfd
);
163 /* return converted font (if conversion is needed) else the original font */
165 convertFont(char *font
, Bool keepXLFD
)
169 char *tmp
= wstrdup(font
);
171 if (MB_CUR_MAX
< 2) {
172 char *ptr
= strchr(tmp
, ',');
174 res
= xlfdToFc(tmp
, NULL
, keepXLFD
);
176 res
= xlfdToFc(tmp
, "sans", keepXLFD
);