1 /* 2 * Copyright (c) 2006, 2007, 2008, 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 FontPlatformDataHarfBuzz_h 32 #define FontPlatformDataHarfBuzz_h 33 34 #include "SkPaint.h" 35 #include "core/platform/SharedBuffer.h" 36 #include "core/platform/graphics/FontOrientation.h" 37 #include "core/platform/graphics/chromium/FontRenderStyle.h" 38 #include "core/platform/graphics/opentype/OpenTypeVerticalData.h" 39 #include "wtf/Forward.h" 40 #include "wtf/HashTableDeletedValueType.h" 41 #include "wtf/RefPtr.h" 42 #include "wtf/text/CString.h" 43 #include "wtf/text/StringImpl.h" 44 45 class SkTypeface; 46 typedef uint32_t SkFontID; 47 48 namespace WebCore { 49 50 class FontDescription; 51 class HarfBuzzFace; 52 53 // ----------------------------------------------------------------------------- 54 // FontPlatformData is the handle which WebKit has on a specific face. A face 55 // is the tuple of (font, size, ...etc). Here we are just wrapping a Skia 56 // SkTypeface pointer and dealing with the reference counting etc. 57 // ----------------------------------------------------------------------------- 58 class FontPlatformData { 59 public: 60 // Used for deleted values in the font cache's hash tables. The hash table 61 // will create us with this structure, and it will compare other values 62 // to this "Deleted" one. It expects the Deleted one to be differentiable 63 // from the 0 one (created with the empty constructor), so we can't just 64 // set everything to 0. 65 FontPlatformData(WTF::HashTableDeletedValueType); 66 FontPlatformData(); 67 FontPlatformData(float textSize, bool fakeBold, bool fakeItalic); 68 FontPlatformData(const FontPlatformData&); 69 FontPlatformData(SkTypeface*, const char* name, float textSize, bool fakeBold, bool fakeItalic, FontOrientation = Horizontal); 70 FontPlatformData(const FontPlatformData& src, float textSize); 71 ~FontPlatformData(); 72 73 // ------------------------------------------------------------------------- 74 // Return true iff this font is monospaced (i.e. every glyph has an equal x 75 // advance) 76 // ------------------------------------------------------------------------- 77 bool isFixedPitch() const; 78 79 // ------------------------------------------------------------------------- 80 // Setup a Skia painting context to use this font. 81 // ------------------------------------------------------------------------- 82 void setupPaint(SkPaint*) const; 83 84 // ------------------------------------------------------------------------- 85 // Return Skia's unique id for this font. This encodes both the style and 86 // the font's file name so refers to a single face. 87 // ------------------------------------------------------------------------- 88 SkFontID uniqueID() const; 89 SkTypeface* typeface() const { return m_typeface.get(); } 90 91 unsigned hash() const; 92 float size() const { return m_textSize; } 93 int emSizeInFontUnits() const; 94 95 FontOrientation orientation() const { return m_orientation; } 96 void setOrientation(FontOrientation orientation) { m_orientation = orientation; } 97 void setFakeBold(bool fakeBold) { m_fakeBold = fakeBold; } 98 void setFakeItalic(bool fakeItalic) { m_fakeItalic = fakeItalic; } 99 bool operator==(const FontPlatformData&) const; 100 FontPlatformData& operator=(const FontPlatformData&); 101 bool isHashTableDeletedValue() const { return m_isHashTableDeletedValue; } 102 103 #if ENABLE(OPENTYPE_VERTICAL) 104 PassRefPtr<OpenTypeVerticalData> verticalData() const; 105 PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const; 106 #endif 107 108 #ifndef NDEBUG 109 String description() const; 110 #endif 111 112 HarfBuzzFace* harfBuzzFace() const; 113 114 // The returned styles are all actual styles without FontRenderStyle::NoPreference. 115 const FontRenderStyle& fontRenderStyle() const { return m_style; } 116 117 // ------------------------------------------------------------------------- 118 // Global font preferences... 119 120 static void setHinting(SkPaint::Hinting); 121 static void setAutoHint(bool); 122 static void setUseBitmaps(bool); 123 static void setAntiAlias(bool); 124 static void setSubpixelRendering(bool); 125 static void setSubpixelPositioning(bool); 126 127 private: 128 void getRenderStyleForStrike(const char*, int); 129 void querySystemForRenderStyle(); 130 131 RefPtr<SkTypeface> m_typeface; 132 CString m_family; 133 float m_textSize; 134 mutable int m_emSizeInFontUnits; 135 bool m_fakeBold; 136 bool m_fakeItalic; 137 FontOrientation m_orientation; 138 FontRenderStyle m_style; 139 mutable RefPtr<HarfBuzzFace> m_harfBuzzFace; 140 bool m_isHashTableDeletedValue; 141 }; 142 143 } // namespace WebCore 144 145 #endif // ifdef FontPlatformDataHarfBuzz_h 146