2 * fontconfig/src/fcdefault.c
4 * Copyright © 2001 Keith Packard
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of the author(s) not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. The authors make no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
31 } FcBoolDefaults[] = {
32 { FC_HINTING_OBJECT, FcTrue }, /* !FT_LOAD_NO_HINTING */
33 { FC_VERTICAL_LAYOUT_OBJECT, FcFalse }, /* FC_LOAD_VERTICAL_LAYOUT */
34 { FC_AUTOHINT_OBJECT, FcFalse }, /* FC_LOAD_FORCE_AUTOHINT */
35 { FC_GLOBAL_ADVANCE_OBJECT, FcTrue }, /* !FC_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH */
36 { FC_EMBEDDED_BITMAP_OBJECT, FcTrue }, /* !FC_LOAD_NO_BITMAP */
37 { FC_DECORATIVE_OBJECT, FcFalse },
40 #define NUM_FC_BOOL_DEFAULTS (int) (sizeof FcBoolDefaults / sizeof FcBoolDefaults[0])
43 FcGetDefaultLangs (void)
45 FcStrSet *result = FcStrSetCreate ();
48 langs = getenv ("FC_LANG");
49 if (!langs || !langs[0])
50 langs = getenv ("LC_ALL");
51 if (!langs || !langs[0])
52 langs = getenv ("LC_CTYPE");
53 if (!langs || !langs[0])
54 langs = getenv ("LANG");
55 if (langs && langs[0])
57 if (!FcStrSetAddLangs (result, langs))
58 FcStrSetAdd (result, (const FcChar8 *) "en");
61 FcStrSetAdd (result, (const FcChar8 *) "en");
67 FcGetDefaultLang (void)
69 static FcChar8 lang_local[128] = {0};
74 langs = FcGetDefaultLangs ();
75 strncpy ((char *)lang_local, (const char *)langs->strs[0], 127);
77 FcStrSetDestroy (langs);
84 FcDefaultSubstitute (FcPattern *pattern)
86 FcValue v, namelang, v2;
89 if (FcPatternObjectGet (pattern, FC_WEIGHT_OBJECT, 0, &v) == FcResultNoMatch )
90 FcPatternObjectAddInteger (pattern, FC_WEIGHT_OBJECT, FC_WEIGHT_MEDIUM);
92 if (FcPatternObjectGet (pattern, FC_SLANT_OBJECT, 0, &v) == FcResultNoMatch)
93 FcPatternObjectAddInteger (pattern, FC_SLANT_OBJECT, FC_SLANT_ROMAN);
95 if (FcPatternObjectGet (pattern, FC_WIDTH_OBJECT, 0, &v) == FcResultNoMatch)
96 FcPatternObjectAddInteger (pattern, FC_WIDTH_OBJECT, FC_WIDTH_NORMAL);
98 for (i = 0; i < NUM_FC_BOOL_DEFAULTS; i++)
99 if (FcPatternObjectGet (pattern, FcBoolDefaults[i].field, 0, &v) == FcResultNoMatch)
100 FcPatternObjectAddBool (pattern, FcBoolDefaults[i].field, FcBoolDefaults[i].value);
102 if (FcPatternObjectGet (pattern, FC_PIXEL_SIZE_OBJECT, 0, &v) == FcResultNoMatch)
104 double dpi, size, scale;
106 if (FcPatternObjectGetDouble (pattern, FC_SIZE_OBJECT, 0, &size) != FcResultMatch)
109 (void) FcPatternObjectDel (pattern, FC_SIZE_OBJECT);
110 FcPatternObjectAddDouble (pattern, FC_SIZE_OBJECT, size);
112 if (FcPatternObjectGetDouble (pattern, FC_SCALE_OBJECT, 0, &scale) != FcResultMatch)
115 (void) FcPatternObjectDel (pattern, FC_SCALE_OBJECT);
116 FcPatternObjectAddDouble (pattern, FC_SCALE_OBJECT, scale);
119 if (FcPatternObjectGetDouble (pattern, FC_DPI_OBJECT, 0, &dpi) != FcResultMatch)
122 (void) FcPatternObjectDel (pattern, FC_DPI_OBJECT);
123 FcPatternObjectAddDouble (pattern, FC_DPI_OBJECT, dpi);
126 FcPatternObjectAddDouble (pattern, FC_PIXEL_SIZE_OBJECT, size);
129 if (FcPatternObjectGet (pattern, FC_FONTVERSION_OBJECT, 0, &v) == FcResultNoMatch)
131 FcPatternObjectAddInteger (pattern, FC_FONTVERSION_OBJECT, 0x7fffffff);
134 if (FcPatternObjectGet (pattern, FC_HINT_STYLE_OBJECT, 0, &v) == FcResultNoMatch)
136 FcPatternObjectAddInteger (pattern, FC_HINT_STYLE_OBJECT, FC_HINT_FULL);
138 if (FcPatternObjectGet (pattern, FC_NAMELANG_OBJECT, 0, &v) == FcResultNoMatch)
140 FcPatternObjectAddString (pattern, FC_NAMELANG_OBJECT, FcGetDefaultLang ());
142 /* shouldn't be failed. */
143 FcPatternObjectGet (pattern, FC_NAMELANG_OBJECT, 0, &namelang);
144 /* Add a fallback to ensure the english name when the requested language
145 * isn't available. this would helps for the fonts that have non-English
146 * name at the beginning.
148 /* Set "en-us" instead of "en" to avoid giving higher score to "en".
149 * This is a hack for the case that the orth is not like ll-cc, because,
150 * if no namelang isn't explicitly set, it will has something like ll-cc
151 * according to current locale. which may causes FcLangDifferentTerritory
152 * at FcLangCompare(). thus, the English name is selected so that
153 * exact matched "en" has higher score than ll-cc.
155 v2.type = FcTypeString;
156 v2.u.s = FcSharedStr ((FcChar8 *)"en-us");
157 if (FcPatternObjectGet (pattern, FC_FAMILYLANG_OBJECT, 0, &v) == FcResultNoMatch)
159 FcPatternObjectAdd (pattern, FC_FAMILYLANG_OBJECT, namelang, FcTrue);
160 FcPatternObjectAddWithBinding (pattern, FC_FAMILYLANG_OBJECT, v2, FcValueBindingWeak, FcTrue);
162 if (FcPatternObjectGet (pattern, FC_STYLELANG_OBJECT, 0, &v) == FcResultNoMatch)
164 FcPatternObjectAdd (pattern, FC_STYLELANG_OBJECT, namelang, FcTrue);
165 FcPatternObjectAddWithBinding (pattern, FC_STYLELANG_OBJECT, v2, FcValueBindingWeak, FcTrue);
167 if (FcPatternObjectGet (pattern, FC_FULLNAMELANG_OBJECT, 0, &v) == FcResultNoMatch)
169 FcPatternObjectAdd (pattern, FC_FULLNAMELANG_OBJECT, namelang, FcTrue);
170 FcPatternObjectAddWithBinding (pattern, FC_FULLNAMELANG_OBJECT, v2, FcValueBindingWeak, FcTrue);
172 FcSharedStrFree (v2.u.s);
174 #define __fcdefault__
175 #include "fcaliastail.h"