OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> | 3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> |
4 * Copyright (C) 2013 Google, Inc. All rights reserved. | 4 * Copyright (C) 2013 Google, Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * | 9 * |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 28 matching lines...) Expand all Loading... |
39 // We currently do not support bitmap fonts on windows. | 39 // We currently do not support bitmap fonts on windows. |
40 // Instead of trying to construct a bitmap font and then going down the fallback
path map | 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. | 41 // certain common bitmap fonts to their truetype equivalent up front. |
42 inline const AtomicString& adjustFamilyNameToAvoidUnsupportedFonts(const AtomicS
tring& familyName) | 42 inline const AtomicString& adjustFamilyNameToAvoidUnsupportedFonts(const AtomicS
tring& familyName) |
43 { | 43 { |
44 #if OS(WIN) | 44 #if OS(WIN) |
45 // On Windows, 'Courier New' (truetype font) is always present and | 45 // On Windows, 'Courier New' (truetype font) is always present and |
46 // 'Courier' is a bitmap font. On Mac on the other hand 'Courier' is | 46 // 'Courier' is a bitmap font. On Mac on the other hand 'Courier' is |
47 // a truetype font. Thus pages asking for Courier are better of | 47 // a truetype font. Thus pages asking for Courier are better of |
48 // using 'Courier New' on windows. | 48 // using 'Courier New' on windows. |
49 DEFINE_STATIC_LOCAL(AtomicString, courier, ("Courier", AtomicString::Constru
ctFromLiteral)); | 49 DEFINE_STATIC_LOCAL(AtomicString, courier, ("Courier")); |
50 DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New", AtomicString::
ConstructFromLiteral)); | 50 DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New")); |
51 if (equalIgnoringCase(familyName, courier)) | 51 if (equalIgnoringCase(familyName, courier)) |
52 return courierNew; | 52 return courierNew; |
53 | 53 |
54 // Alias 'MS Sans Serif' (bitmap font) -> 'Microsoft Sans Serif' | 54 // Alias 'MS Sans Serif' (bitmap font) -> 'Microsoft Sans Serif' |
55 // (truetype font). | 55 // (truetype font). |
56 DEFINE_STATIC_LOCAL(AtomicString, msSans, ("MS Sans Serif", AtomicString::Co
nstructFromLiteral)); | 56 DEFINE_STATIC_LOCAL(AtomicString, msSans, ("MS Sans Serif")); |
57 DEFINE_STATIC_LOCAL(AtomicString, microsoftSans, ("Microsoft Sans Serif", At
omicString::ConstructFromLiteral)); | 57 DEFINE_STATIC_LOCAL(AtomicString, microsoftSans, ("Microsoft Sans Serif")); |
58 if (equalIgnoringCase(familyName, msSans)) | 58 if (equalIgnoringCase(familyName, msSans)) |
59 return microsoftSans; | 59 return microsoftSans; |
60 | 60 |
61 // Alias 'MS Serif' (bitmap) -> 'Times New Roman' (truetype font). | 61 // Alias 'MS Serif' (bitmap) -> 'Times New Roman' (truetype font). |
62 // Alias 'Times' -> 'Times New Roman' (truetype font). | 62 // Alias 'Times' -> 'Times New Roman' (truetype font). |
63 // There's no 'Microsoft Sans Serif-equivalent' for Serif. | 63 // There's no 'Microsoft Sans Serif-equivalent' for Serif. |
64 DEFINE_STATIC_LOCAL(AtomicString, msSerif, ("MS Serif", AtomicString::Constr
uctFromLiteral)); | 64 DEFINE_STATIC_LOCAL(AtomicString, msSerif, ("MS Serif")); |
65 DEFINE_STATIC_LOCAL(AtomicString, times, ("Times", AtomicString::ConstructFr
omLiteral)); | 65 DEFINE_STATIC_LOCAL(AtomicString, times, ("Times")); |
66 DEFINE_STATIC_LOCAL(AtomicString, timesNewRoman, ("Times New Roman", AtomicS
tring::ConstructFromLiteral)); | 66 DEFINE_STATIC_LOCAL(AtomicString, timesNewRoman, ("Times New Roman")); |
67 if (equalIgnoringCase(familyName, msSerif) || equalIgnoringCase(familyName,
times)) | 67 if (equalIgnoringCase(familyName, msSerif) || equalIgnoringCase(familyName,
times)) |
68 return timesNewRoman; | 68 return timesNewRoman; |
69 #endif | 69 #endif |
70 | 70 |
71 return familyName; | 71 return familyName; |
72 } | 72 } |
73 | 73 |
74 inline const AtomicString& alternateFamilyName(const AtomicString& familyName) | 74 inline const AtomicString& alternateFamilyName(const AtomicString& familyName) |
75 { | 75 { |
76 // Alias Courier <-> Courier New | 76 // Alias Courier <-> Courier New |
77 DEFINE_STATIC_LOCAL(AtomicString, courier, ("Courier", AtomicString::Constru
ctFromLiteral)); | 77 DEFINE_STATIC_LOCAL(AtomicString, courier, ("Courier")); |
78 DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New", AtomicString::
ConstructFromLiteral)); | 78 DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New")); |
79 if (equalIgnoringCase(familyName, courier)) | 79 if (equalIgnoringCase(familyName, courier)) |
80 return courierNew; | 80 return courierNew; |
81 #if !OS(WIN) | 81 #if !OS(WIN) |
82 // On Windows, Courier New (truetype font) is always present and | 82 // On Windows, Courier New (truetype font) is always present and |
83 // Courier is a bitmap font. So, we don't want to map Courier New to | 83 // Courier is a bitmap font. So, we don't want to map Courier New to |
84 // Courier. | 84 // Courier. |
85 if (equalIgnoringCase(familyName, courierNew)) | 85 if (equalIgnoringCase(familyName, courierNew)) |
86 return courier; | 86 return courier; |
87 #endif | 87 #endif |
88 | 88 |
89 // Alias Times and Times New Roman. | 89 // Alias Times and Times New Roman. |
90 DEFINE_STATIC_LOCAL(AtomicString, times, ("Times", AtomicString::ConstructFr
omLiteral)); | 90 DEFINE_STATIC_LOCAL(AtomicString, times, ("Times")); |
91 DEFINE_STATIC_LOCAL(AtomicString, timesNewRoman, ("Times New Roman", AtomicS
tring::ConstructFromLiteral)); | 91 DEFINE_STATIC_LOCAL(AtomicString, timesNewRoman, ("Times New Roman")); |
92 if (equalIgnoringCase(familyName, times)) | 92 if (equalIgnoringCase(familyName, times)) |
93 return timesNewRoman; | 93 return timesNewRoman; |
94 if (equalIgnoringCase(familyName, timesNewRoman)) | 94 if (equalIgnoringCase(familyName, timesNewRoman)) |
95 return times; | 95 return times; |
96 | 96 |
97 // Alias Arial and Helvetica | 97 // Alias Arial and Helvetica |
98 DEFINE_STATIC_LOCAL(AtomicString, arial, ("Arial", AtomicString::ConstructFr
omLiteral)); | 98 DEFINE_STATIC_LOCAL(AtomicString, arial, ("Arial")); |
99 DEFINE_STATIC_LOCAL(AtomicString, helvetica, ("Helvetica", AtomicString::Con
structFromLiteral)); | 99 DEFINE_STATIC_LOCAL(AtomicString, helvetica, ("Helvetica")); |
100 if (equalIgnoringCase(familyName, arial)) | 100 if (equalIgnoringCase(familyName, arial)) |
101 return helvetica; | 101 return helvetica; |
102 if (equalIgnoringCase(familyName, helvetica)) | 102 if (equalIgnoringCase(familyName, helvetica)) |
103 return arial; | 103 return arial; |
104 | 104 |
105 return emptyAtom; | 105 return emptyAtom; |
106 } | 106 } |
107 | 107 |
108 | 108 |
109 inline const AtomicString getFallbackFontFamily(const FontDescription& descripti
on) | 109 inline const AtomicString getFallbackFontFamily(const FontDescription& descripti
on) |
110 { | 110 { |
111 DEFINE_STATIC_LOCAL(const AtomicString, sansStr, ("sans-serif", AtomicString
::ConstructFromLiteral)); | 111 DEFINE_STATIC_LOCAL(const AtomicString, sansStr, ("sans-serif")); |
112 DEFINE_STATIC_LOCAL(const AtomicString, serifStr, ("serif", AtomicString::Co
nstructFromLiteral)); | 112 DEFINE_STATIC_LOCAL(const AtomicString, serifStr, ("serif")); |
113 DEFINE_STATIC_LOCAL(const AtomicString, monospaceStr, ("monospace", AtomicSt
ring::ConstructFromLiteral)); | 113 DEFINE_STATIC_LOCAL(const AtomicString, monospaceStr, ("monospace")); |
114 DEFINE_STATIC_LOCAL(const AtomicString, cursiveStr, ("cursive", AtomicString
::ConstructFromLiteral)); | 114 DEFINE_STATIC_LOCAL(const AtomicString, cursiveStr, ("cursive")); |
115 DEFINE_STATIC_LOCAL(const AtomicString, fantasyStr, ("fantasy", AtomicString
::ConstructFromLiteral)); | 115 DEFINE_STATIC_LOCAL(const AtomicString, fantasyStr, ("fantasy")); |
116 | 116 |
117 switch (description.genericFamily()) { | 117 switch (description.genericFamily()) { |
118 case FontDescription::SansSerifFamily: | 118 case FontDescription::SansSerifFamily: |
119 return sansStr; | 119 return sansStr; |
120 case FontDescription::SerifFamily: | 120 case FontDescription::SerifFamily: |
121 return serifStr; | 121 return serifStr; |
122 case FontDescription::MonospaceFamily: | 122 case FontDescription::MonospaceFamily: |
123 return monospaceStr; | 123 return monospaceStr; |
124 case FontDescription::CursiveFamily: | 124 case FontDescription::CursiveFamily: |
125 return cursiveStr; | 125 return cursiveStr; |
126 case FontDescription::FantasyFamily: | 126 case FontDescription::FantasyFamily: |
127 return fantasyStr; | 127 return fantasyStr; |
128 default: | 128 default: |
129 // Let the caller use the system default font. | 129 // Let the caller use the system default font. |
130 return emptyAtom; | 130 return emptyAtom; |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 } // namespace blink | 134 } // namespace blink |
135 | 135 |
136 #endif // AlternateFontFamily_h | 136 #endif // AlternateFontFamily_h |
OLD | NEW |