5 # include <X11/Xft/Xft.h>
13 #include <X11/Xlocale.h>
18 static char *makeFontSetOfSize(char *fontset
, int size
);
22 /* XLFD pattern matching */
24 getElementFromXLFD(const char *xlfd
, int index
)
28 if (*p
== '-' && --index
== 0) {
29 const char *end
= strchr(p
+ 1, '-');
32 if (end
== 0) end
= p
+ strlen(p
);
35 memcpy(buf
, p
+ 1, len
);
45 /* XLFD pattern matching */
47 generalizeXLFD(const char *xlfd
)
51 char *weight
= getElementFromXLFD(xlfd
, 3);
52 char *slant
= getElementFromXLFD(xlfd
, 4);
53 char *pxlsz
= getElementFromXLFD(xlfd
, 7);
55 #define Xstrlen(A) ((A)?strlen(A):0)
56 len
= Xstrlen(xlfd
)+Xstrlen(weight
)+Xstrlen(slant
)+Xstrlen(pxlsz
)*2+60;
59 buf
= wmalloc(len
+ 1);
60 snprintf(buf
, len
+ 1, "%s,-*-*-%s-%s-*-*-%s-*-*-*-*-*-*-*,"
61 "-*-*-*-*-*-*-%s-*-*-*-*-*-*-*,*",
62 xlfd
, weight
, slant
, pxlsz
, pxlsz
);
71 /* XLFD pattern matching */
73 W_CreateFontSetWithGuess(Display
*dpy
, char *xlfd
, char ***missing
,
74 int *nmissing
, char **def_string
)
76 XFontSet fs
= XCreateFontSet(dpy
, xlfd
, missing
, nmissing
, def_string
);
78 if (fs
!= NULL
&& *nmissing
== 0) return fs
;
80 /* for non-iso8859-1 language and iso8859-1 specification
81 (this fontset is only for pattern analysis) */
83 if (*nmissing
!= 0) XFreeStringList(*missing
);
84 setlocale(LC_CTYPE
, "C");
85 fs
= XCreateFontSet(dpy
, xlfd
, missing
, nmissing
, def_string
);
86 setlocale(LC_CTYPE
, "");
89 /* make XLFD font name for pattern analysis */
91 XFontStruct
**fontstructs
;
93 if (XFontsOfFontSet(fs
, &fontstructs
, &fontnames
) > 0)
97 xlfd
= generalizeXLFD(xlfd
);
99 if (*nmissing
!= 0) XFreeStringList(*missing
);
100 if (fs
!= NULL
) XFreeFontSet(dpy
, fs
);
102 fs
= XCreateFontSet(dpy
, xlfd
, missing
, nmissing
, def_string
);
110 xlfdFromFontName(char *fontName
, Bool antialiased
)
112 char *systemFont
, *boldSystemFont
;
117 systemFont
= WINGsConfiguration
.antialiasedSystemFont
;
118 boldSystemFont
= WINGsConfiguration
.antialiasedBoldSystemFont
;
120 systemFont
= WINGsConfiguration
.systemFont
;
121 boldSystemFont
= WINGsConfiguration
.boldSystemFont
;
124 size
= WINGsConfiguration
.defaultFontSize
;
126 if (strcmp(fontName
, "SystemFont")==0) {
128 size
= WINGsConfiguration
.defaultFontSize
;
129 } else if (strncmp(fontName
, "SystemFont-", 11)==0) {
131 if (sscanf(&fontName
[11], "%i", &size
)!=1) {
132 size
= WINGsConfiguration
.defaultFontSize
;
133 wwarning(_("Invalid size specification '%s' in %s. "
134 "Using default %d\n"), &fontName
[11], fontName
, size
);
136 } else if (strcmp(fontName
, "BoldSystemFont")==0) {
137 font
= boldSystemFont
;
138 size
= WINGsConfiguration
.defaultFontSize
;
139 } else if (strncmp(fontName
, "BoldSystemFont-", 15)==0) {
140 font
= boldSystemFont
;
141 if (sscanf(&fontName
[15], "%i", &size
)!=1) {
142 size
= WINGsConfiguration
.defaultFontSize
;
143 wwarning(_("Invalid size specification '%s' in %s. "
144 "Using default %d\n"), &fontName
[15], fontName
, size
);
150 return (font
!=NULL
? makeFontSetOfSize(font
, size
) : wstrdup(fontName
));
155 WMCreateFontSet(WMScreen
*scrPtr
, char *fontName
)
158 Display
*display
= scrPtr
->display
;
163 XFontSetExtents
*extents
;
165 fname
= xlfdFromFontName(fontName
, False
);
167 font
= WMHashGet(scrPtr
->fontSetCache
, fname
);
174 font
= wmalloc(sizeof(WMFont
));
175 memset(font
, 0, sizeof(WMFont
));
177 font
->notFontSet
= 0;
178 font
->antialiased
= 0;
180 font
->screen
= scrPtr
;
182 font
->font
.set
= W_CreateFontSetWithGuess(display
, fname
, &missing
,
183 &nmissing
, &defaultString
);
184 if (nmissing
> 0 && font
->font
.set
) {
187 wwarning(_("the following character sets are missing in %s:"), fname
);
188 for (i
= 0; i
< nmissing
; i
++) {
189 wwarning(missing
[i
]);
191 XFreeStringList(missing
);
193 wwarning(_("the string \"%s\" will be used in place of any characters from those sets."),
196 if (!font
->font
.set
) {
202 extents
= XExtentsOfFontSet(font
->font
.set
);
204 font
->height
= extents
->max_logical_extent
.height
;
205 font
->y
= font
->height
- (font
->height
+ extents
->max_logical_extent
.y
);
211 assert(WMHashInsert(scrPtr
->fontSetCache
, font
->name
, font
)==NULL
);
219 WMCreateNormalFont(WMScreen
*scrPtr
, char *fontName
)
222 Display
*display
= scrPtr
->display
;
225 fontName
= xlfdFromFontName(fontName
, False
);
227 if ((ptr
= strchr(fontName
, ','))) {
228 fname
= wmalloc(ptr
- fontName
+ 1);
229 strncpy(fname
, fontName
, ptr
- fontName
);
230 fname
[ptr
- fontName
] = 0;
232 fname
= wstrdup(fontName
);
237 font
= WMHashGet(scrPtr
->fontCache
, fname
);
244 font
= wmalloc(sizeof(WMFont
));
245 memset(font
, 0, sizeof(WMFont
));
247 font
->notFontSet
= 1;
248 font
->antialiased
= 0;
250 font
->screen
= scrPtr
;
252 font
->font
.normal
= XLoadQueryFont(display
, fname
);
253 if (!font
->font
.normal
) {
258 font
->height
= font
->font
.normal
->ascent
+font
->font
.normal
->descent
;
259 font
->y
= font
->font
.normal
->ascent
;
265 assert(WMHashInsert(scrPtr
->fontCache
, font
->name
, font
)==NULL
);
272 WMCreateAntialiasedFont(WMScreen
*scrPtr
, char *fontName
)
276 Display
*display
= scrPtr
->display
;
279 if (!scrPtr
->hasXftSupport
)
282 fontName
= xlfdFromFontName(fontName
, True
);
284 if ((ptr
= strchr(fontName
, ','))) {
285 fname
= wmalloc(ptr
- fontName
+ 1);
286 strncpy(fname
, fontName
, ptr
- fontName
);
287 fname
[ptr
- fontName
] = 0;
289 fname
= wstrdup(fontName
);
294 font
= WMHashGet(scrPtr
->xftFontCache
, fname
);
301 font
= wmalloc(sizeof(WMFont
));
302 memset(font
, 0, sizeof(WMFont
));
304 font
->notFontSet
= 1;
305 font
->antialiased
= 1;
307 font
->screen
= scrPtr
;
310 /* // Xft sux. Loading a font that doesn't exist will load the default
311 * defined in XftConfig without any warning or error */
312 font
->font
.normal
= XLoadQueryFont(display
, fname
);
313 if (!font
->font
.normal
) {
318 XFreeFont(display
, font
->font
.normal
);
321 font
->font
.xft
= XftFontOpenXlfd(display
, scrPtr
->screen
, fname
);
322 if (!font
->font
.xft
) {
327 font
->height
= font
->font
.xft
->ascent
+font
->font
.xft
->descent
;
328 font
->y
= font
->font
.xft
->ascent
;
334 assert(WMHashInsert(scrPtr
->xftFontCache
, font
->name
, font
)==NULL
);
344 WMCreateAntialiasedFontSet(WMScreen
*scrPtr
, char *fontName
)
348 Display
*display
= scrPtr
->display
;
351 if (!scrPtr
->hasXftSupport
)
354 fontName
= xlfdFromFontName(fontName
, True
);
356 // use the second in list if available, instead of first?
357 if ((ptr
= strchr(fontName
, ','))) {
358 fname
= wmalloc(ptr
- fontName
+ 1);
359 strncpy(fname
, fontName
, ptr
- fontName
);
360 fname
[ptr
- fontName
] = 0;
362 fname
= wstrdup(fontName
);
367 font
= WMHashGet(scrPtr
->xftFontSetCache
, fname
);
374 font
= wmalloc(sizeof(WMFont
));
375 memset(font
, 0, sizeof(WMFont
));
377 font
->notFontSet
= 0;
378 font
->antialiased
= 1;
380 font
->screen
= scrPtr
;
383 /* // Xft sux. Loading a font that doesn't exist will load the default
384 * defined in XftConfig without any warning or error */
385 font
->font
.normal
= XLoadQueryFont(display
, fname
);
386 if (!font
->font
.normal
) {
391 XFreeFont(display
, font
->font
.normal
);
394 font
->font
.xft
= XftFontOpenXlfd(display
, scrPtr
->screen
, fname
);
395 if (!font
->font
.xft
) {
400 font
->height
= font
->font
.xft
->ascent
+font
->font
.xft
->descent
;
401 font
->y
= font
->font
.xft
->ascent
;
407 assert(WMHashInsert(scrPtr
->xftFontSetCache
, font
->name
, font
)==NULL
);
417 WMCreateFont(WMScreen
*scrPtr
, char *fontName
)
419 return WMCreateFontWithFlags(scrPtr
, fontName
, WFDefaultFont
);
424 WMCreateFontWithFlags(WMScreen
*scrPtr
, char *fontName
, WMFontFlags flags
)
426 Bool multiByte
= scrPtr
->useMultiByte
;
427 Bool antialiased
= scrPtr
->antialiasedText
;
430 if (flags
& WFFontSet
) {
432 } else if (flags
& WFNormalFont
) {
435 if (flags
& WFAntialiased
) {
437 } else if (flags
& WFNotAntialiased
) {
441 if (antialiased
&& multiByte
) {
442 font
= WMCreateAntialiasedFontSet(scrPtr
, fontName
);
443 /* If we cannot create an antialiased font set and antialiasing is
444 * not explicitly requested in flags, fallback to standard font sets */
445 if (!font
&& (flags
& WFAntialiased
)==0) {
446 font
= WMCreateFontSet(scrPtr
, fontName
);
448 } else if (antialiased
) {
449 font
= WMCreateAntialiasedFont(scrPtr
, fontName
);
450 /* If we cannot create an antialiased font and antialiasing is
451 * not explicitly requested in flags, fallback to normal font */
452 if (!font
&& (flags
& WFAntialiased
)==0) {
453 font
= WMCreateNormalFont(scrPtr
, fontName
);
455 } else if (multiByte
) {
456 font
= WMCreateFontSet(scrPtr
, fontName
);
458 font
= WMCreateNormalFont(scrPtr
, fontName
);
466 WMRetainFont(WMFont
*font
)
468 wassertrv(font
!=NULL
, NULL
);
477 WMReleaseFont(WMFont
*font
)
479 wassertr(font
!=NULL
);
482 if (font
->refCount
< 1) {
483 if (font
->antialiased
) {
485 XftFontClose(font
->screen
->display
, font
->font
.xft
);
489 } else if (font
->notFontSet
) {
490 XFreeFont(font
->screen
->display
, font
->font
.normal
);
492 XFreeFontSet(font
->screen
->display
, font
->font
.set
);
496 if (font
->antialiased
&& !font
->notFontSet
) {
497 WMHashRemove(font
->screen
->xftFontSetCache
, font
->name
);
498 } else if (font
->antialiased
) {
499 WMHashRemove(font
->screen
->xftFontCache
, font
->name
);
500 } else if (font
->notFontSet
) {
501 WMHashRemove(font
->screen
->fontCache
, font
->name
);
503 WMHashRemove(font
->screen
->fontSetCache
, font
->name
);
513 WMHasAntialiasingSupport(WMScreen
*scrPtr
)
515 return scrPtr
->hasXftSupport
;
520 WMIsAntialiasingEnabled(WMScreen
*scrPtr
)
522 return scrPtr
->antialiasedText
;
527 WMIsAntialiasedFont(WMFont
*font
)
529 return font
->antialiased
;
534 WMFontHeight(WMFont
*font
)
536 wassertrv(font
!=NULL
, 0);
543 WMDefaultSystemFont(WMScreen
*scrPtr
)
545 return WMRetainFont(scrPtr
->normalFont
);
550 WMDefaultBoldSystemFont(WMScreen
*scrPtr
)
552 return WMRetainFont(scrPtr
->boldFont
);
557 makeSystemFontOfSize(WMScreen
*scrPtr
, int size
, Bool bold
)
560 char *fontSpec
, *xftFontSpec
;
562 #define WConf WINGsConfiguration
564 fontSpec
= makeFontSetOfSize(WConf
.boldSystemFont
, size
);
565 xftFontSpec
= makeFontSetOfSize(WConf
.antialiasedBoldSystemFont
, size
);
567 fontSpec
= makeFontSetOfSize(WConf
.systemFont
, size
);
568 xftFontSpec
= makeFontSetOfSize(WConf
.antialiasedSystemFont
, size
);
572 if (scrPtr
->antialiasedText
&& scrPtr
->useMultiByte
) {
573 font
= WMCreateAntialiasedFontSet(scrPtr
, xftFontSpec
);
574 } else if (scrPtr
->antialiasedText
) {
575 font
= WMCreateAntialiasedFont(scrPtr
, xftFontSpec
);
576 } else if (scrPtr
->useMultiByte
) {
577 font
= WMCreateFontSet(scrPtr
, fontSpec
);
579 font
= WMCreateNormalFont(scrPtr
, fontSpec
);
583 if (scrPtr
->antialiasedText
&& scrPtr
->useMultiByte
) {
584 // is arial a good fallback for multibyte?
585 wwarning(_("could not load font %s. Trying arial."), xftFontSpec
);
587 font
= WMCreateAntialiasedFontSet(scrPtr
, "-*-arial-bold-r-normal-*-12-*-*-*-*-*-*-*");
589 font
= WMCreateAntialiasedFontSet(scrPtr
, "-*-arial-medium-r-normal-*-12-*-*-*-*-*-*-*");
592 wwarning(_("could not load antialiased font set. Reverting to standard font sets."));
593 font
= WMCreateFontSet(scrPtr
, fontSpec
);
595 wwarning(_("could not load FontSet %s. Trying fixed."), fontSpec
);
596 font
= WMCreateFontSet(scrPtr
, "fixed");
599 } else if (scrPtr
->antialiasedText
) {
600 wwarning(_("could not load font %s. Trying arial."), xftFontSpec
);
602 font
= WMCreateAntialiasedFont(scrPtr
, "-*-arial-bold-r-normal-*-12-*-*-*-*-*-*-*");
604 font
= WMCreateAntialiasedFont(scrPtr
, "-*-arial-medium-r-normal-*-12-*-*-*-*-*-*-*");
607 wwarning(_("could not load antialiased fonts. Reverting to normal fonts."));
608 font
= WMCreateNormalFont(scrPtr
, fontSpec
);
610 wwarning(_("could not load font %s. Trying fixed."), fontSpec
);
611 font
= WMCreateNormalFont(scrPtr
, "fixed");
614 } else if (scrPtr
->useMultiByte
) {
615 wwarning(_("could not load font set %s. Trying fixed."), fontSpec
);
616 font
= WMCreateFontSet(scrPtr
, "fixed");
618 font
= WMCreateFontSet(scrPtr
, "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*");
621 wwarning(_("could not load font %s. Trying fixed."), fontSpec
);
622 font
= WMCreateNormalFont(scrPtr
, "fixed");
625 wwarning(_("could not load fixed font!"));
639 WMSystemFontOfSize(WMScreen
*scrPtr
, int size
)
641 return makeSystemFontOfSize(scrPtr
, size
, False
);
646 WMBoldSystemFontOfSize(WMScreen
*scrPtr
, int size
)
648 return makeSystemFontOfSize(scrPtr
, size
, True
);
653 WMGetFontFontSet(WMFont
*font
)
655 wassertrv(font
!=NULL
, NULL
);
657 if (!font
->notFontSet
&& !font
->antialiased
)
658 return font
->font
.set
;
665 WMWidthOfString(WMFont
*font
, char *text
, int length
)
667 wassertrv(font
!=NULL
, 0);
668 wassertrv(text
!=NULL
, 0);
670 if (font
->antialiased
) {
674 if (!font
->notFontSet
) {
679 /* Use mtext instead of text, because mbstrtowcs() alters it */
681 wtext
= (wchar_t *)wmalloc(4*length
+4);
682 /* pass a real ps instead of NULL below? for multithread safety
683 * as from manual page */
684 len
= mbsrtowcs(wtext
, (const char **) &mtext
, length
, NULL
);
686 XftTextExtents32(font
->screen
->display
, font
->font
.xft
,
687 (XftChar32
*)wtext
, len
, &extents
);
690 wwarning(_("Conversion to widechar failed (possible "
691 "invalid multibyte sequence): '%s':(pos %d)\n"),
698 XftTextExtents8(font
->screen
->display
, font
->font
.xft
,
699 (XftChar8
*)text
, length
, &extents
);
702 return extents
.xOff
; /* don't ask :P */
706 } else if (font
->notFontSet
) {
707 return XTextWidth(font
->font
.normal
, text
, length
);
712 XmbTextExtents(font
->font
.set
, text
, length
, &AIXsucks
, &rect
);
721 WMDrawString(WMScreen
*scr
, Drawable d
, WMColor
*color
, WMFont
*font
,
722 int x
, int y
, char *text
, int length
)
724 wassertr(font
!=NULL
);
726 if (font
->antialiased
) {
730 xftcolor
.color
.red
= color
->color
.red
;
731 xftcolor
.color
.green
= color
->color
.green
;
732 xftcolor
.color
.blue
= color
->color
.blue
;
733 xftcolor
.color
.alpha
= color
->alpha
;;
734 xftcolor
.pixel
= W_PIXEL(color
);
736 XftDrawChange(scr
->xftdraw
, d
);
738 if (!font
->notFontSet
) {
743 /* Use mtext instead of text, because mbstrtowcs() alters it */
745 wtext
= (wchar_t *)wmalloc(4*length
+4);
746 len
= mbsrtowcs(wtext
, (const char **) &mtext
, length
, NULL
);
748 XftDrawString32(scr
->xftdraw
, &xftcolor
, font
->font
.xft
,
749 x
, y
+ font
->y
, (XftChar32
*)wtext
, len
);
750 } else if (len
==-1) {
751 wwarning(_("Conversion to widechar failed (possible invalid "
752 "multibyte sequence): '%s':(pos %d)\n"),
754 /* we can draw normal text, or we can draw as much widechar
755 * text as was already converted until the error. go figure */
756 /*XftDrawString8(scr->xftdraw, &xftcolor, font->font.xft,
757 x, y + font->y, (XftChar8*)text, length);*/
761 XftDrawString8(scr
->xftdraw
, &xftcolor
, font
->font
.xft
,
762 x
, y
+ font
->y
, (XftChar8
*)text
, length
);
767 } else if (font
->notFontSet
) {
768 XSetFont(scr
->display
, scr
->drawStringGC
, font
->font
.normal
->fid
);
769 XSetForeground(scr
->display
, scr
->drawStringGC
, W_PIXEL(color
));
770 XDrawString(scr
->display
, d
, scr
->drawStringGC
, x
, y
+ font
->y
,
773 XSetForeground(scr
->display
, scr
->drawStringGC
, W_PIXEL(color
));
774 XmbDrawString(scr
->display
, d
, font
->font
.set
, scr
->drawStringGC
,
775 x
, y
+ font
->y
, text
, length
);
781 WMDrawImageString(WMScreen
*scr
, Drawable d
, WMColor
*color
, WMColor
*background
,
782 WMFont
*font
, int x
, int y
, char *text
, int length
)
784 wassertr(font
!=NULL
);
786 if (font
->antialiased
) {
791 textColor
.color
.red
= color
->color
.red
;
792 textColor
.color
.green
= color
->color
.green
;
793 textColor
.color
.blue
= color
->color
.blue
;
794 textColor
.color
.alpha
= color
->alpha
;;
795 textColor
.pixel
= W_PIXEL(color
);
797 bgColor
.color
.red
= background
->color
.red
;
798 bgColor
.color
.green
= background
->color
.green
;
799 bgColor
.color
.blue
= background
->color
.blue
;
800 bgColor
.color
.alpha
= background
->alpha
;;
801 bgColor
.pixel
= W_PIXEL(background
);
804 XftDrawChange(scr
->xftdraw
, d
);
806 XftDrawRect(scr
->xftdraw
, &bgColor
, x
, y
,
807 WMWidthOfString(font
, text
, length
), font
->height
);
809 if (!font
->notFontSet
) {
814 /* Use mtext instead of text, because mbstrtowcs() alters it */
816 wtext
= (wchar_t *)wmalloc(4*length
+4);
817 len
= mbsrtowcs(wtext
, (const char **) &mtext
, length
, NULL
);
819 XftDrawString32(scr
->xftdraw
, &textColor
, font
->font
.xft
,
820 x
, y
+ font
->y
, (XftChar32
*)wtext
, len
);
821 } else if (len
==-1) {
822 wwarning(_("Conversion to widechar failed (possible invalid "
823 "multibyte sequence): '%s':(pos %d)\n"),
825 /* we can draw normal text, or we can draw as much widechar
826 * text as was already converted until the error. go figure */
827 /*XftDrawString8(scr->xftdraw, &textColor, font->font.xft,
828 x, y + font->y, (XftChar8*)text, length);*/
832 XftDrawString8(scr
->xftdraw
, &textColor
, font
->font
.xft
,
833 x
, y
+ font
->y
, (XftChar8
*)text
, length
);
838 } else if (font
->notFontSet
) {
839 XSetForeground(scr
->display
, scr
->drawImStringGC
, W_PIXEL(color
));
840 XSetBackground(scr
->display
, scr
->drawImStringGC
, W_PIXEL(background
));
841 XSetFont(scr
->display
, scr
->drawImStringGC
, font
->font
.normal
->fid
);
842 XDrawImageString(scr
->display
, d
, scr
->drawImStringGC
,
843 x
, y
+ font
->y
, text
, length
);
845 XSetForeground(scr
->display
, scr
->drawImStringGC
, W_PIXEL(color
));
846 XSetBackground(scr
->display
, scr
->drawImStringGC
, W_PIXEL(background
));
847 XmbDrawImageString(scr
->display
, d
, font
->font
.set
, scr
->drawImStringGC
,
848 x
, y
+ font
->y
, text
, length
);
856 makeFontSetOfSize(char *fontset
, int size
)
868 ptr
= strchr(fontset
, ',');
870 int count
= ptr
-fontset
;
873 wwarning(_("font description %s is too large."), fontset
);
875 memcpy(font
, fontset
, count
);
886 tmp
= wmalloc(end
+ strlen(f
) + 8);
888 sprintf(tmp
, "%s,", newfs
);
889 sprintf(tmp
+ end
+ 1, f
, size
);
891 sprintf(tmp
+ end
, f
, size
);
905 #define FONT_PROPS 14
908 char *props
[FONT_PROPS
];
913 changeFontProp(char *buf
, char *newprop
, int position
)
916 char *ptr
, *pptr
, *rptr
;
920 // remove warning later. or maybe not
921 wwarning(_("Invalid font specification: '%s'\n"), buf
);
925 ptr
= pptr
= rptr
= buf
;
927 while (*ptr
&& *ptr
!=',') {
930 if (count
-1==position
+1) {
934 if (count
-1==position
) {
940 if (position
==FONT_PROPS
-1) {
945 snprintf(buf2
, 512, "%s%s%s", buf
, newprop
, rptr
);
951 getOptions(char *options
)
953 char *ptr
, *ptr2
, *str
;
957 result
= WMCreateArrayWithDestructor(2, (WMFreeDataProc
*)wfree
);
961 ptr2
= strchr(ptr
, ',');
963 WMAddToArray(result
, wstrdup(ptr
));
967 str
= wmalloc(count
+1);
968 memcpy(str
, ptr
, count
);
970 WMAddToArray(result
, str
);
980 WMCopyFontWithChanges(WMScreen
*scrPtr
, WMFont
*font
,
981 const WMFontAttributes
*changes
)
983 int index
[FONT_PROPS
], count
[FONT_PROPS
];
984 int totalProps
, i
, j
, carry
;
992 snprintf(fname
, 512, "%s", font
->name
);
994 fFlags
= (font
->antialiased
? WFAntialiased
: WFNotAntialiased
);
995 fFlags
|= (font
->notFontSet
? WFNormalFont
: WFFontSet
);
997 props
= WMCreateBagWithDestructor(1, (WMFreeDataProc
*)WMFreeArray
);
1000 for (i
=0; i
<FONT_PROPS
; i
++) {
1001 prop
= ((W_FontAttributes
*)changes
)->props
[i
];
1002 count
[i
] = index
[i
] = 0;
1004 /* No change for this property */
1006 } else if (strchr(prop
, ',')==NULL
) {
1008 changeFontProp(fname
, prop
, i
);
1010 /* Option with fallback alternatives */
1011 if ((changes
==WFAEmphasized
|| changes
==WFABoldEmphasized
) &&
1012 font
->antialiased
&& strcmp(prop
, "o,i")==0) {
1013 options
= getOptions("i,o");
1015 options
= getOptions(prop
);
1017 WMInsertInBag(props
, i
, options
);
1018 count
[i
] = WMGetArrayItemCount(options
);
1021 totalProps
= totalProps
* count
[i
];
1025 if (totalProps
== 0) {
1026 /* No options with fallback alternatives at all */
1028 //printf("try: '%s'\n '%s'\n", font->name, fname);
1029 return WMCreateFontWithFlags(scrPtr
, fname
, fFlags
);
1032 for (i
=0; i
<totalProps
; i
++) {
1033 for (j
=0; j
<FONT_PROPS
; j
++) {
1035 options
= WMGetFromBag(props
, j
);
1036 prop
= WMGetFromArray(options
, index
[j
]);
1038 changeFontProp(fname
, prop
, j
);
1042 result
= WMCreateFontWithFlags(scrPtr
, fname
, fFlags
);
1043 //printf("try: '%s'\n '%s'\n", font->name, fname);
1048 for (j
=FONT_PROPS
-1, carry
=1; j
>=0; j
--) {
1051 carry
= (index
[j
]==count
[j
]);
1052 index
[j
] %= count
[j
];
1064 // should WFANormal also set "normal" or leave it alone?
1065 static const WMFontAttributes W_FANormal
= {
1066 WFAUnchanged
, WFAUnchanged
, "medium,normal,regular", "r", "normal",
1067 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
,
1068 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
1072 static const WMFontAttributes W_FABold
= {
1073 WFAUnchanged
, WFAUnchanged
, "bold", WFAUnchanged
,
1074 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
,
1075 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
1079 static const WMFontAttributes W_FANotBold
= {
1080 WFAUnchanged
, WFAUnchanged
, "medium,normal,regular", WFAUnchanged
,
1081 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
,
1082 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
1086 static const WMFontAttributes W_FAEmphasized
= {
1087 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, "o,i",
1088 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
,
1089 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
1093 static const WMFontAttributes W_FANotEmphasized
= {
1094 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, "r",
1095 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
,
1096 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
1100 static const WMFontAttributes W_FABoldEmphasized
= {
1101 WFAUnchanged
, WFAUnchanged
, "bold", "o,i",
1102 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
,
1103 WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
, WFAUnchanged
1107 const WMFontAttributes
*WFANormal
= &W_FANormal
;
1108 const WMFontAttributes
*WFABold
= &W_FABold
;
1109 const WMFontAttributes
*WFANotBold
= &W_FANotBold
;
1110 const WMFontAttributes
*WFAEmphasized
= &W_FAEmphasized
;
1111 const WMFontAttributes
*WFANotEmphasized
= &W_FANotEmphasized
;
1112 const WMFontAttributes
*WFABoldEmphasized
= &W_FABoldEmphasized
;