2 * Copyright (c) 2009, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef FontFaceCreationParams_h
32 #define FontFaceCreationParams_h
34 #include "wtf/Assertions.h"
35 #include "wtf/StringHasher.h"
36 #include "wtf/text/AtomicString.h"
37 #include "wtf/text/StringHash.h"
41 enum FontFaceCreationType
{
43 CreateFontByFciIdAndTtcIndex
46 class FontFaceCreationParams
{
47 FontFaceCreationType m_creationType
;
48 AtomicString m_family
;
50 int m_fontconfigInterfaceId
;
54 FontFaceCreationParams()
55 : m_creationType(CreateFontByFamily
), m_family(AtomicString()), m_filename(CString()), m_fontconfigInterfaceId(0), m_ttcIndex(0)
59 explicit FontFaceCreationParams(AtomicString family
)
60 : m_creationType(CreateFontByFamily
), m_family(family
), m_filename(CString()), m_fontconfigInterfaceId(0), m_ttcIndex(0)
63 // Leading "@" in the font name enables Windows vertical flow flag for the font.
64 // Because we do vertical flow by ourselves, we don't want to use the Windows feature.
65 // IE disregards "@" regardless of the orientation, so we follow the behavior and
66 // normalize the family name.
67 m_family
= (m_family
.isEmpty() || m_family
[0] != '@') ? m_family
: AtomicString(m_family
.impl()->substring(1));
71 FontFaceCreationParams(CString filename
, int fontconfigInterfaceId
, int ttcIndex
= 0)
72 : m_creationType(CreateFontByFciIdAndTtcIndex
), m_filename(filename
), m_fontconfigInterfaceId(fontconfigInterfaceId
), m_ttcIndex(ttcIndex
)
76 FontFaceCreationType
creationType() const { return m_creationType
; }
77 AtomicString
family() const
79 ASSERT(m_creationType
== CreateFontByFamily
);
82 CString
filename() const
84 ASSERT(m_creationType
== CreateFontByFciIdAndTtcIndex
);
87 int fontconfigInterfaceId() const
89 ASSERT(m_creationType
== CreateFontByFciIdAndTtcIndex
);
90 return m_fontconfigInterfaceId
;
94 ASSERT(m_creationType
== CreateFontByFciIdAndTtcIndex
);
100 if (m_creationType
== CreateFontByFciIdAndTtcIndex
) {
102 // Hashing the filename and ints in this way is sensitive to character encoding
103 // and endianness. However, since the hash is not transferred over a network
104 // or permanently stored and only used for the runtime of Chromium,
105 // this is not a concern.
106 hasher
.addCharacters(reinterpret_cast<const LChar
*>(m_filename
.data()), m_filename
.length());
107 hasher
.addCharacters(reinterpret_cast<const LChar
*>(&m_ttcIndex
), sizeof(m_ttcIndex
));
108 hasher
.addCharacters(reinterpret_cast<const LChar
*>(&m_fontconfigInterfaceId
), sizeof(m_fontconfigInterfaceId
));
109 return hasher
.hash();
111 return CaseFoldingHash::hash(m_family
.isEmpty() ? "" : m_family
);
114 bool operator==(const FontFaceCreationParams
& other
) const
116 return m_creationType
== other
.m_creationType
117 && equalIgnoringCase(m_family
, other
.m_family
)
118 && m_filename
== other
.m_filename
119 && m_fontconfigInterfaceId
== other
.m_fontconfigInterfaceId
120 && m_ttcIndex
== other
.m_ttcIndex
;
127 #endif // FontFaceCreationParams_h