source: trunk/poppler/fontconfig-2.3.2-os2/src/fcdefault.c @ 2

Last change on this file since 2 was 2, checked in by Eugene Romanenko, 15 years ago

First import

File size: 4.7 KB
Line 
1/*
2 * $RCSId: xc/lib/fontconfig/src/fcdefault.c,v 1.2 2002/07/09 22:08:14 keithp Exp $
3 *
4 * Copyright © 2001 Keith Packard
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#include <locale.h>
27
28static struct {
29    char        *field;
30    FcBool      value;
31} FcBoolDefaults[] = {
32    { FC_HINTING,           FcTrue      },  /* !FT_LOAD_NO_HINTING */
33    { FC_VERTICAL_LAYOUT,   FcFalse     },  /* FC_LOAD_VERTICAL_LAYOUT */
34    { FC_AUTOHINT,          FcFalse     },  /* FC_LOAD_FORCE_AUTOHINT */
35    { FC_GLOBAL_ADVANCE,    FcTrue      },  /* !FC_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH */
36};
37
38#define NUM_FC_BOOL_DEFAULTS    (sizeof FcBoolDefaults / sizeof FcBoolDefaults[0])
39
40void
41FcDefaultSubstitute (FcPattern *pattern)
42{
43    FcValue v;
44    int     i;
45
46    if (FcPatternGet (pattern, FC_STYLE, 0, &v) == FcResultNoMatch)
47    {
48        if (FcPatternGet (pattern, FC_WEIGHT, 0, &v) == FcResultNoMatch )
49        {
50            FcPatternAddInteger (pattern, FC_WEIGHT, FC_WEIGHT_MEDIUM);
51        }
52        if (FcPatternGet (pattern, FC_SLANT, 0, &v) == FcResultNoMatch)
53        {
54            FcPatternAddInteger (pattern, FC_SLANT, FC_SLANT_ROMAN);
55        }
56    }
57
58    if (FcPatternGet (pattern, FC_WIDTH, 0, &v) == FcResultNoMatch)
59        FcPatternAddInteger (pattern, FC_WIDTH, FC_WIDTH_NORMAL);
60
61    for (i = 0; i < NUM_FC_BOOL_DEFAULTS; i++)
62        if (FcPatternGet (pattern, FcBoolDefaults[i].field, 0, &v) == FcResultNoMatch)
63            FcPatternAddBool (pattern, FcBoolDefaults[i].field, FcBoolDefaults[i].value);
64   
65    if (FcPatternGet (pattern, FC_PIXEL_SIZE, 0, &v) == FcResultNoMatch)
66    {
67        double  dpi, size, scale;
68
69        if (FcPatternGetDouble (pattern, FC_SIZE, 0, &size) != FcResultMatch)
70        {
71            size = 12.0;
72            (void) FcPatternDel (pattern, FC_SIZE);
73            FcPatternAddDouble (pattern, FC_SIZE, size);
74        }
75        if (FcPatternGetDouble (pattern, FC_SCALE, 0, &scale) != FcResultMatch)
76        {
77            scale = 1.0;
78            (void) FcPatternDel (pattern, FC_SCALE);
79            FcPatternAddDouble (pattern, FC_SCALE, scale);
80        }
81        size *= scale;
82        if (FcPatternGetDouble (pattern, FC_DPI, 0, &dpi) != FcResultMatch)
83        {
84            dpi = 75.0;
85            (void) FcPatternDel (pattern, FC_DPI);
86            FcPatternAddDouble (pattern, FC_DPI, dpi);
87        }
88        size *= dpi / 72.0;
89        FcPatternAddDouble (pattern, FC_PIXEL_SIZE, size);
90    }
91
92    if (FcPatternGet (pattern, FC_LANG, 0, &v) == FcResultNoMatch)
93    {
94        char    *lang;
95        char    *territory;
96        char    *after;
97        int     lang_len, territory_len;
98        char    lang_local[128];
99        char    *ctype = setlocale (LC_CTYPE, NULL);
100
101        /*
102         * Check if setlocale (LC_ALL, "") has been called
103         */
104        if (!ctype || !strcmp (ctype, "C"))
105        {
106            ctype = getenv ("LC_ALL");
107            if (!ctype)
108            {
109                ctype = getenv ("LC_CTYPE");
110                if (!ctype)
111                    ctype = getenv ("LANG");
112            }
113        }
114        if (ctype)
115        {
116            lang = ctype;
117            territory = strchr (ctype, '_');
118            if (territory)
119            {
120                lang_len = territory - lang;
121                territory = territory + 1;
122                after = strchr (territory, '.');
123                if (!after)
124                {
125                    after = strchr (territory, '@');
126                    if (!after)
127                        after = territory + strlen (territory);
128                }
129                territory_len = after - territory;
130                if (lang_len + 1 + territory_len + 1 <= sizeof (lang_local))
131                {
132                    strncpy (lang_local, lang, lang_len);
133                    lang_local[lang_len] = '-';
134                    strncpy (lang_local + lang_len + 1, territory, territory_len);
135                    lang_local[lang_len + 1 + territory_len] = '\0';
136                    FcPatternAddString (pattern, FC_LANG, (FcChar8 *) lang_local);
137                }
138            }
139            else
140                FcPatternAddString (pattern, FC_LANG, (FcChar8 *) lang);
141        }
142    }
143    if (FcPatternGet (pattern, FC_FONTVERSION, 0, &v) == FcResultNoMatch)
144    {
145        FcPatternAddInteger (pattern, FC_FONTVERSION, 0x7fffffff);
146    }
147
148    if (FcPatternGet (pattern, FC_HINT_STYLE, 0, &v) == FcResultNoMatch)
149    {
150        FcPatternAddInteger (pattern, FC_HINT_STYLE, FC_HINT_FULL);
151    }
152}
Note: See TracBrowser for help on using the repository browser.