Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: Source/platform/fonts/FontFaceCreationParams.h

Issue 307243002: Fix font family based fallback font selection (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Windows link fix. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2009, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef FontFaceCreationParams_h
32 #define FontFaceCreationParams_h
33
34 #include "wtf/Assertions.h"
35 #include "wtf/HashFunctions.h"
36 #include "wtf/text/AtomicString.h"
37 #include "wtf/text/StringHash.h"
38
39 namespace WebCore {
40
41 enum FontFaceCreationType {
42 CreateFontByFamily,
43 CreateFontByFciIdAndTtcIndex
44 };
45
46 class FontFaceCreationParams {
47 FontFaceCreationType m_creationType;
48 AtomicString m_family;
49 int m_fontconfigInterfaceId;
50 int m_ttcIndex;
51
52 public:
53 FontFaceCreationParams()
54 : m_creationType(CreateFontByFamily), m_family(AtomicString()), m_fontco nfigInterfaceId(0), m_ttcIndex(0)
55 {
56 }
57
58 explicit FontFaceCreationParams(AtomicString family)
59 : m_creationType(CreateFontByFamily), m_family(family), m_fontconfigInte rfaceId(0), m_ttcIndex(0)
60 {
61 #if OS(WIN) && ENABLE(OPENTYPE_VERTICAL)
62 // Leading "@" in the font name enables Windows vertical flow flag for the f ont.
63 // Because we do vertical flow by ourselves, we don't want to use the Window s feature.
64 // IE disregards "@" regardless of the orientation, so we follow the behavio r and
65 // normalize the family name.
66 m_family = (m_family.isEmpty() || m_family[0] != '@') ? m_family : AtomicStr ing(m_family.impl()->substring(1));
67 #endif
68 }
69
70 FontFaceCreationParams(int fontconfigInterfaceId, int ttcIndex = 0)
71 : m_creationType(CreateFontByFciIdAndTtcIndex), m_fontconfigInterfaceId( fontconfigInterfaceId), m_ttcIndex(ttcIndex)
72 {
73 }
74
75 FontFaceCreationType creationType() const { return m_creationType; }
76 AtomicString family() const
77 {
78 ASSERT(m_creationType == CreateFontByFamily);
79 return m_family;
80 }
81 int fontconfigInterfaceId() const
82 {
83 ASSERT(m_creationType == CreateFontByFciIdAndTtcIndex);
84 return m_fontconfigInterfaceId;
85 }
86 int ttcIndex() const
87 {
88 ASSERT(m_creationType == CreateFontByFciIdAndTtcIndex);
89 return m_ttcIndex;
90 }
91
92 unsigned hash() const
93 {
94 if (m_creationType == CreateFontByFciIdAndTtcIndex) {
95 return WTF::IntHash<int>::hash(m_fontconfigInterfaceId);
96 }
97 return CaseFoldingHash::hash(m_family.isEmpty() ? "" : m_family);
98 }
99
100 bool operator==(const FontFaceCreationParams& other) const
101 {
102 return m_creationType == other.m_creationType
103 && equalIgnoringCase(m_family, other.m_family)
104 && m_fontconfigInterfaceId == other.m_fontconfigInterfaceId
105 && m_ttcIndex == other.m_ttcIndex;
106 }
107
108 };
109
110 } // namespace WebCore
111
112 #endif // FontFaceCreationParams_h
OLDNEW
« no previous file with comments | « Source/platform/fonts/FontDescription.cpp ('k') | Source/platform/fonts/android/FontCacheAndroid.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698