| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2006, 2007, 2008, Google Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. |
| 3 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com |
| 4 * Copyright (C) 2007 Holger Hans Peter Freyther |
| 5 * Copyright (C) 2007 Pioneer Research Center USA, Inc. |
| 6 * Copyright (C) 2010, 2011 Brent Fulgham <bfulgham@webkit.org> |
| 3 * | 7 * |
| 4 * Redistribution and use in source and binary forms, with or without | 8 * This library is free software; you can redistribute it and/or |
| 5 * modification, are permitted provided that the following conditions are | 9 * modify it under the terms of the GNU Library General Public |
| 6 * met: | 10 * License as published by the Free Software Foundation; either |
| 11 * version 2 of the License, or (at your option) any later version. |
| 7 * | 12 * |
| 8 * * Redistributions of source code must retain the above copyright | 13 * This library is distributed in the hope that it will be useful, |
| 9 * notice, this list of conditions and the following disclaimer. | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 * * Redistributions in binary form must reproduce the above | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 * copyright notice, this list of conditions and the following disclaimer | 16 * Library General Public License for more details. |
| 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 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * You should have received a copy of the GNU Library General Public License |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * along with this library; see the file COPYING.LIB. If not, write to |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * Boston, MA 02110-1301, USA. |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * |
| 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 */ | 23 */ |
| 30 | 24 |
| 25 // FIXME: This is temporary until mac switch to using FontPlatformDataHarfBuzz.h
and we merge it with this file. |
| 26 #if !OS(MACOSX) |
| 27 #include "platform/fonts/harfbuzz/FontPlatformDataHarfBuzz.h" |
| 28 |
| 29 #else |
| 30 |
| 31 #ifndef FontPlatformData_h | 31 #ifndef FontPlatformData_h |
| 32 #define FontPlatformData_h | 32 #define FontPlatformData_h |
| 33 | 33 |
| 34 #include "SkPaint.h" | |
| 35 #include "platform/PlatformExport.h" | 34 #include "platform/PlatformExport.h" |
| 36 #include "platform/SharedBuffer.h" | |
| 37 #include "platform/fonts/FontDescription.h" | |
| 38 #include "platform/fonts/FontOrientation.h" | 35 #include "platform/fonts/FontOrientation.h" |
| 39 #include "platform/fonts/FontRenderStyle.h" | 36 #include "platform/fonts/FontWidthVariant.h" |
| 40 #include "platform/fonts/opentype/OpenTypeVerticalData.h" | |
| 41 #include "wtf/Forward.h" | |
| 42 #include "wtf/HashTableDeletedValueType.h" | |
| 43 #include "wtf/RefPtr.h" | |
| 44 #include "wtf/text/CString.h" | |
| 45 #include "wtf/text/StringImpl.h" | |
| 46 | 37 |
| 47 #if OS(MACOSX) | |
| 48 OBJC_CLASS NSFont; | 38 OBJC_CLASS NSFont; |
| 49 | 39 |
| 50 typedef struct CGFont* CGFontRef; | 40 typedef struct CGFont* CGFontRef; |
| 51 typedef const struct __CTFont* CTFontRef; | 41 typedef const struct __CTFont* CTFontRef; |
| 52 | 42 |
| 53 #include "platform/fonts/mac/MemoryActivatedFont.h" | |
| 54 #include <CoreFoundation/CFBase.h> | 43 #include <CoreFoundation/CFBase.h> |
| 55 #include <objc/objc-auto.h> | 44 #include <objc/objc-auto.h> |
| 56 | 45 |
| 57 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef
>(nsFont); } | 46 #include "wtf/Forward.h" |
| 58 #endif // OS(MACOSX) | 47 #include "wtf/HashTableDeletedValueType.h" |
| 48 #include "wtf/PassRefPtr.h" |
| 49 #include "wtf/RefCounted.h" |
| 50 #include "wtf/RetainPtr.h" |
| 51 #include "wtf/text/StringImpl.h" |
| 59 | 52 |
| 60 class SkTypeface; | 53 #include "platform/fonts/mac/MemoryActivatedFont.h" |
| 61 typedef uint32_t SkFontID; | 54 #include "third_party/skia/include/core/SkTypeface.h" |
| 55 |
| 56 typedef struct CGFont* CGFontRef; |
| 57 typedef const struct __CTFont* CTFontRef; |
| 58 typedef UInt32 FMFont; |
| 59 typedef FMFont ATSUFontID; |
| 60 typedef UInt32 ATSFontRef; |
| 62 | 61 |
| 63 namespace blink { | 62 namespace blink { |
| 64 | 63 |
| 65 class GraphicsContext; | |
| 66 class HarfBuzzFace; | 64 class HarfBuzzFace; |
| 67 | 65 |
| 66 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef
>(nsFont); } |
| 67 |
| 68 class PLATFORM_EXPORT FontPlatformData { | 68 class PLATFORM_EXPORT FontPlatformData { |
| 69 public: | 69 public: |
| 70 // Used for deleted values in the font cache's hash tables. The hash table | |
| 71 // will create us with this structure, and it will compare other values | |
| 72 // to this "Deleted" one. It expects the Deleted one to be differentiable | |
| 73 // from the 0 one (created with the empty constructor), so we can't just | |
| 74 // set everything to 0. | |
| 75 FontPlatformData(WTF::HashTableDeletedValueType); | 70 FontPlatformData(WTF::HashTableDeletedValueType); |
| 76 FontPlatformData(); | 71 FontPlatformData(); |
| 77 FontPlatformData(const FontPlatformData&); | 72 FontPlatformData(const FontPlatformData&); |
| 78 #if OS(MACOSX) | 73 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, Font
Orientation = Horizontal, FontWidthVariant = RegularWidth); |
| 79 FontPlatformData(float size, bool syntheticBold, bool syntheticItalic, FontO
rientation = Horizontal, FontWidthVariant = RegularWidth); | 74 FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool synth
eticOblique = false, |
| 80 FontPlatformData(NSFont*, float size, bool syntheticBold = false, bool synth
eticItalic = false, | |
| 81 FontOrientation = Horizontal, FontWidthVariant = RegularWid
th); | 75 FontOrientation = Horizontal, FontWidthVariant = RegularWid
th); |
| 82 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOb
lique, FontOrientation, FontWidthVariant); | 76 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOb
lique, FontOrientation, FontWidthVariant); |
| 83 #else | 77 |
| 84 FontPlatformData(float textSize, bool syntheticBold, bool syntheticItalic); | |
| 85 FontPlatformData(PassRefPtr<SkTypeface>, const char* name, float textSize, b
ool syntheticBold, bool syntheticItalic, FontOrientation = Horizontal, bool subp
ixelTextPosition = defaultUseSubpixelPositioning()); | |
| 86 FontPlatformData(const FontPlatformData& src, float textSize); | |
| 87 #endif | |
| 88 ~FontPlatformData(); | 78 ~FontPlatformData(); |
| 89 | 79 |
| 90 #if OS(MACOSX) | |
| 91 NSFont* font() const { return m_font; } | 80 NSFont* font() const { return m_font; } |
| 92 void setFont(NSFont*); | 81 void setFont(NSFont*); |
| 93 | 82 |
| 94 CGFontRef cgFont() const { return m_cgFont.get(); } | 83 CGFontRef cgFont() const { return m_cgFont.get(); } |
| 95 CTFontRef ctFont() const; | 84 CTFontRef ctFont() const; |
| 85 SkTypeface* typeface() const; |
| 96 | 86 |
| 97 bool roundsGlyphAdvances() const; | 87 bool roundsGlyphAdvances() const; |
| 98 bool allowsLigatures() const; | 88 bool allowsLigatures() const; |
| 99 | 89 |
| 90 String fontFamilyName() const; |
| 91 bool isFixedPitch() const; |
| 92 float size() const { return m_size; } |
| 93 void setSize(float size) { m_size = size; } |
| 94 bool syntheticBold() const { return m_syntheticBold; } |
| 95 bool syntheticOblique() const { return m_syntheticOblique; } |
| 100 bool isColorBitmapFont() const { return m_isColorBitmapFont; } | 96 bool isColorBitmapFont() const { return m_isColorBitmapFont; } |
| 101 bool isCompositeFontReference() const { return m_isCompositeFontReference; } | 97 bool isCompositeFontReference() const { return m_isCompositeFontReference; } |
| 102 | 98 |
| 99 FontOrientation orientation() const { return m_orientation; } |
| 103 FontWidthVariant widthVariant() const { return m_widthVariant; } | 100 FontWidthVariant widthVariant() const { return m_widthVariant; } |
| 104 #endif | |
| 105 | 101 |
| 106 String fontFamilyName() const; | 102 void setOrientation(FontOrientation orientation) { m_orientation = orientati
on; } |
| 107 float size() const { return m_textSize; } | |
| 108 bool isFixedPitch() const; | |
| 109 bool syntheticBold() const { return m_syntheticBold; } | |
| 110 bool syntheticItalic() const { return m_syntheticItalic; } | |
| 111 | 103 |
| 112 SkTypeface* typeface() const; | 104 HarfBuzzFace* harfBuzzFace(); |
| 113 HarfBuzzFace* harfBuzzFace() const; | |
| 114 SkFontID uniqueID() const; | |
| 115 unsigned hash() const; | |
| 116 | 105 |
| 117 FontOrientation orientation() const { return m_orientation; } | 106 unsigned hash() const |
| 118 void setOrientation(FontOrientation orientation) { m_orientation = orientati
on; } | 107 { |
| 119 void setSyntheticBold(bool syntheticBold) { m_syntheticBold = syntheticBold;
} | 108 ASSERT(m_font || !m_cgFont); |
| 120 void setSyntheticItalic(bool syntheticItalic) { m_syntheticItalic = syntheti
cItalic; } | 109 uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cas
t<uintptr_t>(m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique) }; |
| 121 bool operator==(const FontPlatformData&) const; | 110 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); |
| 111 } |
| 112 |
| 122 const FontPlatformData& operator=(const FontPlatformData&); | 113 const FontPlatformData& operator=(const FontPlatformData&); |
| 123 bool isHashTableDeletedValue() const { return m_isHashTableDeletedValue; } | 114 |
| 124 #if OS(WIN) | 115 bool operator==(const FontPlatformData& other) const |
| 125 void setMinSizeForAntiAlias(unsigned size) { m_minSizeForAntiAlias = size; } | |
| 126 unsigned minSizeForAntiAlias() const { return m_minSizeForAntiAlias; } | |
| 127 void setHinting(SkPaint::Hinting style) | |
| 128 { | 116 { |
| 129 m_style.useAutoHint = 0; | 117 return platformIsEqual(other) |
| 130 m_style.hintStyle = style; | 118 && m_size == other.m_size |
| 119 && m_syntheticBold == other.m_syntheticBold |
| 120 && m_syntheticOblique == other.m_syntheticOblique |
| 121 && m_isColorBitmapFont == other.m_isColorBitmapFont |
| 122 && m_isCompositeFontReference == other.m_isCompositeFontReference |
| 123 && m_orientation == other.m_orientation |
| 124 && m_widthVariant == other.m_widthVariant; |
| 131 } | 125 } |
| 132 #endif | |
| 133 bool fontContainsCharacter(UChar32 character); | |
| 134 | 126 |
| 135 #if ENABLE(OPENTYPE_VERTICAL) | 127 bool isHashTableDeletedValue() const |
| 136 PassRefPtr<OpenTypeVerticalData> verticalData() const; | 128 { |
| 137 PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const; | 129 return m_font == hashTableDeletedFontValue(); |
| 138 #endif | 130 } |
| 139 | 131 |
| 140 #ifndef NDEBUG | 132 #ifndef NDEBUG |
| 141 String description() const; | 133 String description() const; |
| 142 #endif | 134 #endif |
| 143 | 135 |
| 144 #if !OS(MACOSX) | |
| 145 // The returned styles are all actual styles without FontRenderStyle::NoPref
erence. | |
| 146 const FontRenderStyle& fontRenderStyle() const { return m_style; } | |
| 147 void setupPaint(SkPaint*, GraphicsContext* = 0) const; | |
| 148 #endif | |
| 149 | |
| 150 #if OS(WIN) | |
| 151 int paintTextFlags() const { return m_paintTextFlags; } | |
| 152 #else | |
| 153 static void setHinting(SkPaint::Hinting); | |
| 154 static void setAutoHint(bool); | |
| 155 static void setUseBitmaps(bool); | |
| 156 static void setAntiAlias(bool); | |
| 157 static void setSubpixelRendering(bool); | |
| 158 #endif | |
| 159 | |
| 160 private: | 136 private: |
| 161 #if !OS(MACOSX) | 137 bool platformIsEqual(const FontPlatformData&) const; |
| 162 bool static defaultUseSubpixelPositioning(); | 138 void platformDataInit(const FontPlatformData&); |
| 163 void querySystemForRenderStyle(bool useSkiaSubpixelPositioning); | 139 const FontPlatformData& platformDataAssign(const FontPlatformData&); |
| 164 #else | 140 #if OS(MACOSX) |
| 165 // Load various data about the font specified by |nsFont| with the size font
Size into the following output paramters: | 141 // Load various data about the font specified by |nsFont| with the size font
Size into the following output paramters: |
| 166 // Note: Callers should always take into account that for the Chromium port,
|outNSFont| isn't necessarily the same | 142 // Note: Callers should always take into account that for the Chromium port,
|outNSFont| isn't necessarily the same |
| 167 // font as |nsFont|. This because the sandbox may block loading of the origi
nal font. | 143 // font as |nsFont|. This because the sandbox may block loading of the origi
nal font. |
| 168 // * outNSFont - The font that was actually loaded, for the Chromium port th
is may be different than nsFont. | 144 // * outNSFont - The font that was actually loaded, for the Chromium port th
is may be different than nsFont. |
| 169 // The caller is responsible for calling CFRelease() on this parameter when
done with it. | 145 // The caller is responsible for calling CFRelease() on this parameter when
done with it. |
| 170 // * cgFont - CGFontRef representing the input font at the specified point s
ize. | 146 // * cgFont - CGFontRef representing the input font at the specified point s
ize. |
| 171 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&); | 147 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&); |
| 172 | 148 static NSFont* hashTableDeletedFontValue() { return reinterpret_cast<NSFont
*>(-1); } |
| 173 bool platformIsEqual(const FontPlatformData&) const; | |
| 174 void platformDataInit(const FontPlatformData&); | |
| 175 const FontPlatformData& platformDataAssign(const FontPlatformData&); | |
| 176 #endif | |
| 177 | |
| 178 mutable RefPtr<SkTypeface> m_typeface; | |
| 179 #if !OS(WIN) | |
| 180 CString m_family; | |
| 181 #endif | 149 #endif |
| 182 | 150 |
| 183 public: | 151 public: |
| 184 float m_textSize; | |
| 185 bool m_syntheticBold; | 152 bool m_syntheticBold; |
| 186 bool m_syntheticItalic; | 153 bool m_syntheticOblique; |
| 187 FontOrientation m_orientation; | 154 FontOrientation m_orientation; |
| 188 #if OS(MACOSX) | 155 float m_size; |
| 189 bool m_isColorBitmapFont; | |
| 190 bool m_isCompositeFontReference; | |
| 191 FontWidthVariant m_widthVariant; | 156 FontWidthVariant m_widthVariant; |
| 192 #endif | 157 |
| 193 private: | 158 private: |
| 194 #if OS(MACOSX) | |
| 195 NSFont* m_font; | 159 NSFont* m_font; |
| 196 RetainPtr<CGFontRef> m_cgFont; | 160 RetainPtr<CGFontRef> m_cgFont; |
| 197 mutable RetainPtr<CTFontRef> m_CTFont; | 161 mutable RetainPtr<CTFontRef> m_CTFont; |
| 162 |
| 198 RefPtr<MemoryActivatedFont> m_inMemoryFont; | 163 RefPtr<MemoryActivatedFont> m_inMemoryFont; |
| 199 #else | 164 RefPtr<HarfBuzzFace> m_harfBuzzFace; |
| 200 FontRenderStyle m_style; | 165 mutable RefPtr<SkTypeface> m_typeface; |
| 201 #endif | |
| 202 | 166 |
| 203 mutable RefPtr<HarfBuzzFace> m_harfBuzzFace; | 167 bool m_isColorBitmapFont; |
| 204 bool m_isHashTableDeletedValue; | 168 bool m_isCompositeFontReference; |
| 205 #if OS(WIN) | |
| 206 int m_paintTextFlags; | |
| 207 bool m_useSubpixelPositioning; | |
| 208 unsigned m_minSizeForAntiAlias; | |
| 209 #endif | |
| 210 }; | 169 }; |
| 211 | 170 |
| 212 } // namespace blink | 171 } // namespace blink |
| 213 | 172 |
| 214 #endif // ifdef FontPlatformData_h | 173 #endif // FontPlatformData_h |
| 174 |
| 175 #endif |
| OLD | NEW |