2 * Copyright (c) 2006, 2007, 2008, 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.
32 #include "platform/fonts/harfbuzz/FontPlatformDataHarfBuzz.h"
34 #include "SkTypeface.h"
35 #include "platform/fonts/harfbuzz/HarfBuzzFace.h"
36 #include "wtf/text/WTFString.h"
40 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
42 , m_syntheticBold(false)
43 , m_syntheticItalic(false)
44 , m_orientation(Horizontal)
45 , m_isHashTableDeletedValue(true)
48 , m_minSizeForAntiAlias(0)
49 , m_minSizeForSubpixel(0)
50 , m_useSubpixelPositioning(false)
55 FontPlatformData::FontPlatformData()
57 , m_syntheticBold(false)
58 , m_syntheticItalic(false)
59 , m_orientation(Horizontal)
60 , m_isHashTableDeletedValue(false)
63 , m_minSizeForAntiAlias(0)
64 , m_minSizeForSubpixel(0)
65 , m_useSubpixelPositioning(false)
70 FontPlatformData::FontPlatformData(float textSize, bool syntheticBold, bool syntheticItalic)
71 : m_textSize(textSize)
72 , m_syntheticBold(syntheticBold)
73 , m_syntheticItalic(syntheticItalic)
74 , m_orientation(Horizontal)
75 , m_isHashTableDeletedValue(false)
78 , m_minSizeForAntiAlias(0)
79 , m_minSizeForSubpixel(0)
80 , m_useSubpixelPositioning(false)
85 FontPlatformData::FontPlatformData(const FontPlatformData& src)
86 : m_typeface(src.m_typeface)
88 , m_family(src.m_family)
90 , m_textSize(src.m_textSize)
91 , m_syntheticBold(src.m_syntheticBold)
92 , m_syntheticItalic(src.m_syntheticItalic)
93 , m_orientation(src.m_orientation)
94 , m_style(src.m_style)
95 , m_harfBuzzFace(nullptr)
96 , m_isHashTableDeletedValue(false)
98 , m_paintTextFlags(src.m_paintTextFlags)
99 , m_minSizeForAntiAlias(src.m_minSizeForAntiAlias)
100 , m_minSizeForSubpixel(src.m_minSizeForSubpixel)
101 , m_useSubpixelPositioning(src.m_useSubpixelPositioning)
106 FontPlatformData::FontPlatformData(PassRefPtr<SkTypeface> tf, const char* family, float textSize, bool syntheticBold, bool syntheticItalic, FontOrientation orientation, bool subpixelTextPosition)
111 , m_textSize(textSize)
112 , m_syntheticBold(syntheticBold)
113 , m_syntheticItalic(syntheticItalic)
114 , m_orientation(orientation)
115 , m_isHashTableDeletedValue(false)
117 , m_paintTextFlags(0)
118 , m_minSizeForAntiAlias(0)
119 , m_minSizeForSubpixel(0)
120 , m_useSubpixelPositioning(subpixelTextPosition)
123 querySystemForRenderStyle(subpixelTextPosition);
126 FontPlatformData::FontPlatformData(const FontPlatformData& src, float textSize)
127 : m_typeface(src.m_typeface)
129 , m_family(src.m_family)
131 , m_textSize(textSize)
132 , m_syntheticBold(src.m_syntheticBold)
133 , m_syntheticItalic(src.m_syntheticItalic)
134 , m_orientation(src.m_orientation)
135 , m_harfBuzzFace(nullptr)
136 , m_isHashTableDeletedValue(false)
138 , m_paintTextFlags(src.m_paintTextFlags)
139 , m_minSizeForAntiAlias(src.m_minSizeForAntiAlias)
140 , m_minSizeForSubpixel(src.m_minSizeForSubpixel)
141 , m_useSubpixelPositioning(src.m_useSubpixelPositioning)
144 querySystemForRenderStyle(FontDescription::subpixelPositioning());
147 FontPlatformData::~FontPlatformData()
151 FontPlatformData& FontPlatformData::operator=(const FontPlatformData& src)
153 m_typeface = src.m_typeface;
155 m_family = src.m_family;
157 m_textSize = src.m_textSize;
158 m_syntheticBold = src.m_syntheticBold;
159 m_syntheticItalic = src.m_syntheticItalic;
160 m_harfBuzzFace = nullptr;
161 m_orientation = src.m_orientation;
162 m_style = src.m_style;
164 m_paintTextFlags = 0;
165 m_minSizeForAntiAlias = src.m_minSizeForAntiAlias;
166 m_minSizeForSubpixel = src.m_minSizeForSubpixel;
167 m_useSubpixelPositioning = src.m_useSubpixelPositioning;
174 String FontPlatformData::description() const
180 SkFontID FontPlatformData::uniqueID() const
182 return m_typeface->uniqueID();
185 String FontPlatformData::fontFamilyName() const
187 // FIXME(crbug.com/326582): come up with a proper way of handling SVG.
188 if (!this->typeface())
190 SkTypeface::LocalizedStrings* fontFamilyIterator = this->typeface()->createFamilyNameIterator();
191 SkTypeface::LocalizedString localizedString;
192 while (fontFamilyIterator->next(&localizedString) && !localizedString.fString.size()) { }
193 fontFamilyIterator->unref();
194 return String(localizedString.fString.c_str());
197 bool FontPlatformData::operator==(const FontPlatformData& a) const
199 // If either of the typeface pointers are null then we test for pointer
200 // equality. Otherwise, we call SkTypeface::Equal on the valid pointers.
202 if (!m_typeface || !a.m_typeface)
203 typefacesEqual = m_typeface == a.m_typeface;
205 typefacesEqual = SkTypeface::Equal(m_typeface.get(), a.m_typeface.get());
207 return typefacesEqual
208 && m_textSize == a.m_textSize
209 && m_syntheticBold == a.m_syntheticBold
210 && m_syntheticItalic == a.m_syntheticItalic
211 && m_orientation == a.m_orientation
212 && m_style == a.m_style
213 && m_isHashTableDeletedValue == a.m_isHashTableDeletedValue;
216 bool FontPlatformData::isFixedPitch() const
218 return typeface() && typeface()->isFixedPitch();
221 HarfBuzzFace* FontPlatformData::harfBuzzFace() const
224 m_harfBuzzFace = HarfBuzzFace::create(const_cast<FontPlatformData*>(this), uniqueID());
226 return m_harfBuzzFace.get();