]> git.wh0rd.org - fontconfig.git/blob - src/fcdefault.c
Initial revision
[fontconfig.git] / src / fcdefault.c
1 /*
2 * $XFree86: $
3 *
4 * Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
5 *
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 Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
15 *
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD 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.
23 */
24
25 #include "fcint.h"
26
27 static struct {
28 char *field;
29 FcBool value;
30 } FcBoolDefaults[] = {
31 { FC_HINTING, FcTrue }, /* !FT_LOAD_NO_HINTING */
32 { FC_VERTICAL_LAYOUT, FcFalse }, /* FC_LOAD_VERTICAL_LAYOUT */
33 { FC_AUTOHINT, FcFalse }, /* FC_LOAD_FORCE_AUTOHINT */
34 { FC_GLOBAL_ADVANCE, FcTrue }, /* !FC_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH */
35 };
36
37 #define NUM_FC_BOOL_DEFAULTS (sizeof FcBoolDefaults / sizeof FcBoolDefaults[0])
38
39 void
40 FcDefaultSubstitute (FcPattern *pattern)
41 {
42 FcValue v;
43 int i;
44
45 if (FcPatternGet (pattern, FC_STYLE, 0, &v) == FcResultNoMatch)
46 {
47 if (FcPatternGet (pattern, FC_WEIGHT, 0, &v) == FcResultNoMatch )
48 {
49 FcPatternAddInteger (pattern, FC_WEIGHT, FC_WEIGHT_MEDIUM);
50 }
51 if (FcPatternGet (pattern, FC_SLANT, 0, &v) == FcResultNoMatch)
52 {
53 FcPatternAddInteger (pattern, FC_SLANT, FC_SLANT_ROMAN);
54 }
55 }
56
57 for (i = 0; i < NUM_FC_BOOL_DEFAULTS; i++)
58 if (FcPatternGet (pattern, FcBoolDefaults[i].field, 0, &v) == FcResultNoMatch)
59 FcPatternAddBool (pattern, FcBoolDefaults[i].field, FcBoolDefaults[i].value);
60
61 if (FcPatternGet (pattern, FC_PIXEL_SIZE, 0, &v) == FcResultNoMatch)
62 {
63 double dpi, size, scale;
64
65 if (FcPatternGetDouble (pattern, FC_SIZE, 0, &size) != FcResultMatch)
66 {
67 size = 12.0;
68 (void) FcPatternDel (pattern, FC_SIZE);
69 FcPatternAddDouble (pattern, FC_SIZE, size);
70 }
71 if (FcPatternGetDouble (pattern, FC_SCALE, 0, &scale) != FcResultMatch)
72 {
73 scale = 1.0;
74 (void) FcPatternDel (pattern, FC_SCALE);
75 FcPatternAddDouble (pattern, FC_SCALE, scale);
76 }
77 size *= scale;
78 if (FcPatternGetDouble (pattern, FC_DPI, 0, &dpi) != FcResultMatch)
79 {
80 dpi = 75.0;
81 (void) FcPatternDel (pattern, FC_DPI);
82 FcPatternAddDouble (pattern, FC_DPI, dpi);
83 }
84 size *= dpi / 72.0;
85 FcPatternAddDouble (pattern, FC_PIXEL_SIZE, size);
86 }
87 }