Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / fonts / AlternateFontFamily.h
blob6a1eb991e0b77ba7b2f44a7713535b4afad08556
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.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
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.
31 #ifndef AlternateFontFamily_h
32 #define AlternateFontFamily_h
34 #include "platform/fonts/FontDescription.h"
35 #include "wtf/text/AtomicString.h"
37 namespace blink {
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
41 // certain common bitmap fonts to their truetype equivalent up front.
42 inline const AtomicString& adjustFamilyNameToAvoidUnsupportedFonts(const AtomicString& familyName)
44 #if OS(WIN)
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
47 // a truetype font. Thus pages asking for Courier are better of
48 // using 'Courier New' on windows.
49 DEFINE_STATIC_LOCAL(AtomicString, courier, ("Courier", AtomicString::ConstructFromLiteral));
50 DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New", AtomicString::ConstructFromLiteral));
51 if (equalIgnoringCase(familyName, courier))
52 return courierNew;
54 // Alias 'MS Sans Serif' (bitmap font) -> 'Microsoft Sans Serif'
55 // (truetype font).
56 DEFINE_STATIC_LOCAL(AtomicString, msSans, ("MS Sans Serif", AtomicString::ConstructFromLiteral));
57 DEFINE_STATIC_LOCAL(AtomicString, microsoftSans, ("Microsoft Sans Serif", AtomicString::ConstructFromLiteral));
58 if (equalIgnoringCase(familyName, msSans))
59 return microsoftSans;
61 // Alias 'MS Serif' (bitmap) -> 'Times New Roman' (truetype font).
62 // Alias 'Times' -> 'Times New Roman' (truetype font).
63 // There's no 'Microsoft Sans Serif-equivalent' for Serif.
64 DEFINE_STATIC_LOCAL(AtomicString, msSerif, ("MS Serif", AtomicString::ConstructFromLiteral));
65 DEFINE_STATIC_LOCAL(AtomicString, times, ("Times", AtomicString::ConstructFromLiteral));
66 DEFINE_STATIC_LOCAL(AtomicString, timesNewRoman, ("Times New Roman", AtomicString::ConstructFromLiteral));
67 if (equalIgnoringCase(familyName, msSerif) || equalIgnoringCase(familyName, times))
68 return timesNewRoman;
69 #endif
71 return familyName;
74 inline const AtomicString& alternateFamilyName(const AtomicString& familyName)
76 // Alias Courier <-> Courier New
77 DEFINE_STATIC_LOCAL(AtomicString, courier, ("Courier", AtomicString::ConstructFromLiteral));
78 DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New", AtomicString::ConstructFromLiteral));
79 if (equalIgnoringCase(familyName, courier))
80 return courierNew;
81 #if !OS(WIN)
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
84 // Courier.
85 if (equalIgnoringCase(familyName, courierNew))
86 return courier;
87 #endif
89 // Alias Times and Times New Roman.
90 DEFINE_STATIC_LOCAL(AtomicString, times, ("Times", AtomicString::ConstructFromLiteral));
91 DEFINE_STATIC_LOCAL(AtomicString, timesNewRoman, ("Times New Roman", AtomicString::ConstructFromLiteral));
92 if (equalIgnoringCase(familyName, times))
93 return timesNewRoman;
94 if (equalIgnoringCase(familyName, timesNewRoman))
95 return times;
97 // Alias Arial and Helvetica
98 DEFINE_STATIC_LOCAL(AtomicString, arial, ("Arial", AtomicString::ConstructFromLiteral));
99 DEFINE_STATIC_LOCAL(AtomicString, helvetica, ("Helvetica", AtomicString::ConstructFromLiteral));
100 if (equalIgnoringCase(familyName, arial))
101 return helvetica;
102 if (equalIgnoringCase(familyName, helvetica))
103 return arial;
105 return emptyAtom;
109 inline const AtomicString getFallbackFontFamily(const FontDescription& description)
111 DEFINE_STATIC_LOCAL(const AtomicString, sansStr, ("sans-serif", AtomicString::ConstructFromLiteral));
112 DEFINE_STATIC_LOCAL(const AtomicString, serifStr, ("serif", AtomicString::ConstructFromLiteral));
113 DEFINE_STATIC_LOCAL(const AtomicString, monospaceStr, ("monospace", AtomicString::ConstructFromLiteral));
114 DEFINE_STATIC_LOCAL(const AtomicString, cursiveStr, ("cursive", AtomicString::ConstructFromLiteral));
115 DEFINE_STATIC_LOCAL(const AtomicString, fantasyStr, ("fantasy", AtomicString::ConstructFromLiteral));
117 switch (description.genericFamily()) {
118 case FontDescription::SansSerifFamily:
119 return sansStr;
120 case FontDescription::SerifFamily:
121 return serifStr;
122 case FontDescription::MonospaceFamily:
123 return monospaceStr;
124 case FontDescription::CursiveFamily:
125 return cursiveStr;
126 case FontDescription::FantasyFamily:
127 return fantasyStr;
128 default:
129 // Let the caller use the system default font.
130 return emptyAtom;
134 } // namespace blink
136 #endif // AlternateFontFamily_h