OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | |
3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> | |
4 * Copyright (C) 2013 Google, Inc. All rights reserved. | |
5 * | |
6 * Redistribution and use in source and binary forms, with or without | |
7 * modification, are permitted provided that the following conditions | |
8 * are met: | |
9 * | |
10 * 1. Redistributions of source code must retain the above copyright | |
11 * notice, this list of conditions and the following disclaimer. | |
12 * 2. Redistributions in binary form must reproduce the above copyright | |
13 * notice, this list of conditions and the following disclaimer in the | |
14 * documentation and/or other materials provided with the distribution. | |
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
16 * its contributors may be used to endorse or promote products derived | |
17 * from this software without specific prior written permission. | |
18 * | |
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #ifndef AlternateFontFamily_h | |
32 #define AlternateFontFamily_h | |
33 | |
34 #include "platform/fonts/FontDescription.h" | |
35 #include "wtf/text/AtomicString.h" | |
36 | |
37 namespace WebCore { | |
38 | |
39 // We currently do not support bitmap fonts on windows (with GDI_FONTS_ON_WINDOW
S enabled). | |
40 // Instead of trying to construct a bitmap font and then going down the fallback
path map | |
41 // certain common bitmap fonts to their truetype equivalent up front. This also
allows the | |
42 // GDI_FONTS_ON_WINDOWS disabled code path to match our current behavior. | |
43 inline const AtomicString& alternateFamilyNameAvoidingBitmapFonts(const AtomicSt
ring& familyName) | |
44 { | |
45 #if OS(WIN) | |
46 // On Windows, 'Courier New' (truetype font) is always present and | |
47 // 'Courier' is a bitmap font. On Mac on the other hand 'Courier' is | |
48 // a truetype font. Thus pages asking for Courier are better of | |
49 // using 'Courier New' on windows. | |
50 DEFINE_STATIC_LOCAL(AtomicString, courier, ("Courier", AtomicString::Constru
ctFromLiteral)); | |
51 DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New", AtomicString::
ConstructFromLiteral)); | |
52 if (equalIgnoringCase(familyName, courier)) | |
53 return courierNew; | |
54 | |
55 // Alias 'MS Sans Serif' (bitmap font) -> 'Microsoft Sans Serif' | |
56 // (truetype font). | |
57 DEFINE_STATIC_LOCAL(AtomicString, msSans, ("MS Sans Serif", AtomicString::Co
nstructFromLiteral)); | |
58 DEFINE_STATIC_LOCAL(AtomicString, microsoftSans, ("Microsoft Sans Serif", At
omicString::ConstructFromLiteral)); | |
59 if (equalIgnoringCase(familyName, msSans)) | |
60 return microsoftSans; | |
61 | |
62 // Alias 'MS Serif' (bitmap) -> 'Times New Roman' (truetype font). | |
63 // There's no 'Microsoft Sans Serif-equivalent' for Serif. | |
64 DEFINE_STATIC_LOCAL(AtomicString, msSerif, ("MS Serif", AtomicString::Constr
uctFromLiteral)); | |
65 DEFINE_STATIC_LOCAL(AtomicString, timesNewRoman, ("Times New Roman", AtomicS
tring::ConstructFromLiteral)); | |
66 if (equalIgnoringCase(familyName, msSerif)) | |
67 return timesNewRoman; | |
68 #endif | |
69 | |
70 return emptyAtom; | |
71 } | |
72 | |
73 inline const AtomicString& alternateFamilyName(const AtomicString& familyName) | |
74 { | |
75 // Alias Courier <-> Courier New | |
76 DEFINE_STATIC_LOCAL(AtomicString, courier, ("Courier", AtomicString::Constru
ctFromLiteral)); | |
77 DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New", AtomicString::
ConstructFromLiteral)); | |
78 if (equalIgnoringCase(familyName, courier)) | |
79 return courierNew; | |
80 #if !OS(WIN) | |
81 // On Windows, Courier New (truetype font) is always present and | |
82 // Courier is a bitmap font. So, we don't want to map Courier New to | |
83 // Courier. | |
84 if (equalIgnoringCase(familyName, courierNew)) | |
85 return courier; | |
86 #endif | |
87 | |
88 // Alias Times and Times New Roman. | |
89 DEFINE_STATIC_LOCAL(AtomicString, times, ("Times", AtomicString::ConstructFr
omLiteral)); | |
90 DEFINE_STATIC_LOCAL(AtomicString, timesNewRoman, ("Times New Roman", AtomicS
tring::ConstructFromLiteral)); | |
91 if (equalIgnoringCase(familyName, times)) | |
92 return timesNewRoman; | |
93 if (equalIgnoringCase(familyName, timesNewRoman)) | |
94 return times; | |
95 | |
96 // Alias Arial and Helvetica | |
97 DEFINE_STATIC_LOCAL(AtomicString, arial, ("Arial", AtomicString::ConstructFr
omLiteral)); | |
98 DEFINE_STATIC_LOCAL(AtomicString, helvetica, ("Helvetica", AtomicString::Con
structFromLiteral)); | |
99 if (equalIgnoringCase(familyName, arial)) | |
100 return helvetica; | |
101 if (equalIgnoringCase(familyName, helvetica)) | |
102 return arial; | |
103 | |
104 return emptyAtom; | |
105 } | |
106 | |
107 | |
108 inline const AtomicString getFallbackFontFamily(const FontDescription& descripti
on) | |
109 { | |
110 DEFINE_STATIC_LOCAL(const AtomicString, sansStr, ("Sans", AtomicString::Cons
tructFromLiteral)); | |
111 DEFINE_STATIC_LOCAL(const AtomicString, serifStr, ("Serif", AtomicString::Co
nstructFromLiteral)); | |
112 DEFINE_STATIC_LOCAL(const AtomicString, monospaceStr, ("Monospace", AtomicSt
ring::ConstructFromLiteral)); | |
113 | |
114 switch (description.genericFamily()) { | |
115 case FontDescription::SerifFamily: | |
116 return serifStr; | |
117 case FontDescription::MonospaceFamily: | |
118 return monospaceStr; | |
119 case FontDescription::SansSerifFamily: | |
120 return sansStr; | |
121 default: | |
122 return AtomicString(); | |
123 } | |
124 } | |
125 | |
126 } // namespace WebCore | |
127 | |
128 #endif // AlternateFontFamily_h | |
OLD | NEW |