8 Display
* display_in
, int screen
,
9 double font_size_override
, bool skip_italics
)
15 FcPattern
* pattern
= FcNameParse((const FcChar8
*) spec
.c_str());
16 if (font_size_override
> 0) {
17 FcPatternDel(pattern
, FC_PIXEL_SIZE
);
18 FcPatternDel(pattern
, FC_SIZE
);
19 FcPatternAddDouble(pattern
, FC_PIXEL_SIZE
, font_size_override
);
21 XftDefaultSubstitute(display
, screen
, pattern
);
22 FcPattern
* match
= XftFontMatch(display
, screen
, pattern
, &result
);
24 FcChar8
* format_name
= FcPatternFormat(match
, (FcChar8
*) "%{=fcmatch} size: %{size} pixelsize: %{pixelsize}");
25 printf("Real font: \"%s\".\n", format_name
);
28 xft_fonts
[0] = XftFontOpenPattern(display
, match
);
29 if (xft_fonts
[0] == nullptr)
30 throw std::runtime_error("Couldn't open the font.");
32 // Get the font size used.
34 result
= FcPatternGetDouble(pattern
, FC_PIXEL_SIZE
, 0, &used_font_size
);
38 xft_fonts
[2] = xft_fonts
[0];
39 // We'll make bold-italic be the same as bold, below.
43 // (We do this first because we'll be clobbering the weight later.)
44 FcPatternDel(pattern
, FC_SLANT
);
45 FcPatternAddInteger(pattern
, FC_SLANT
, FC_SLANT_ITALIC
);
46 match
= XftFontMatch(display
, screen
, pattern
, &result
);
47 xft_fonts
[2] = XftFontOpenPattern(display
, match
);
48 if (xft_fonts
[2] == nullptr) {
49 fprintf(stderr
, "Couldn't open italic font.");
50 xft_fonts
[2] = xft_fonts
[0];
54 FcPatternDel(pattern
, FC_WEIGHT
);
55 FcPatternAddInteger(pattern
, FC_WEIGHT
, FC_WEIGHT_BOLD
);
56 match
= XftFontMatch(display
, screen
, pattern
, &result
);
57 xft_fonts
[3] = XftFontOpenPattern(display
, match
);
58 if (xft_fonts
[3] == nullptr) {
59 fprintf(stderr
, "Couldn't open bold italic font.");
60 xft_fonts
[3] = xft_fonts
[0];
66 FcPatternDel(pattern
, FC_WEIGHT
);
67 FcPatternAddInteger(pattern
, FC_WEIGHT
, FC_WEIGHT_BOLD
);
70 FcPatternDel(pattern
, FC_SLANT
);
71 FcPatternAddInteger(pattern
, FC_SLANT
, FC_SLANT_ROMAN
);
73 match
= XftFontMatch(display
, screen
, pattern
, &result
);
74 xft_fonts
[1] = XftFontOpenPattern(display
, match
);
75 if (xft_fonts
[1] == nullptr) {
76 fprintf(stderr
, "Couldn't open bold font.");
77 xft_fonts
[1] = xft_fonts
[0];
80 xft_fonts
[3] = xft_fonts
[1];
82 FcPatternDestroy(pattern
);
88 for (int i
= 3; i
>= 0; --i
) {
90 for (int j
= i
- 1; j
>= 0; --j
) {
91 if (xft_fonts
[i
] == xft_fonts
[j
]) {
97 XftFontClose(display
, xft_fonts
[i
]);
98 xft_fonts
[i
] = nullptr;