1 /* 2 * Copyright 2009, The Android Open Source Project 3 * Copyright (C) 2006 Apple Computer, Inc. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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 copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 // This file is part of the internal font implementation. It should not be included by anyone other than 28 // FontMac.cpp, FontWin.cpp and Font.cpp. 29 30 #ifndef FontPlatformData_h 31 #define FontPlatformData_h 32 33 #include "FontOrientation.h" 34 #include "TextOrientation.h" 35 #include <wtf/text/StringImpl.h> 36 37 #ifndef NDEBUG 38 #include "PlatformString.h" 39 #endif 40 41 class SkPaint; 42 class SkTypeface; 43 44 struct HB_FaceRec_; 45 46 namespace WebCore { 47 48 class FontPlatformData { 49 public: 50 static FontPlatformData Deleted() { 51 return FontPlatformData(NULL, -1, false, false); 52 } 53 54 FontPlatformData(); 55 FontPlatformData(const FontPlatformData&); 56 FontPlatformData(SkTypeface*, float textSize, bool fakeBold, bool fakeItalic, 57 FontOrientation = Horizontal, TextOrientation = TextOrientationVerticalRight); 58 FontPlatformData(const FontPlatformData& src, float textSize); 59 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique); 60 FontPlatformData(const FontPlatformData& src, SkTypeface* typeface); 61 62 ~FontPlatformData(); 63 64 FontPlatformData(WTF::HashTableDeletedValueType) 65 : mTypeface(hashTableDeletedFontValue()) { } 66 bool isHashTableDeletedValue() const { 67 return mTypeface == hashTableDeletedFontValue(); 68 } 69 70 FontOrientation orientation() const { return mOrientation; } 71 void setOrientation(FontOrientation orientation) { mOrientation = orientation; } 72 FontPlatformData& operator=(const FontPlatformData&); 73 bool operator==(const FontPlatformData& a) const; 74 75 void setupPaint(SkPaint*) const; 76 77 // ------------------------------------------------------------------------- 78 // Return Skia's unique id for this font. This encodes both the style and 79 // the font's file name so refers to a single face. 80 // ------------------------------------------------------------------------- 81 uint32_t uniqueID() const; 82 83 float size() const { return mTextSize; } 84 unsigned hash() const; 85 int emSizeInFontUnits() const; 86 bool isFixedPitch() const; 87 88 #ifndef NDEBUG 89 String description() const { return ""; } 90 #endif 91 92 HB_FaceRec_* harfbuzzFace() const; 93 SkTypeface* typeface() const { return mTypeface; } 94 95 bool isFakeBold() const { return mFakeBold; } 96 bool isFakeItalic() const { return mFakeItalic; } 97 98 private: 99 class RefCountedHarfbuzzFace : public RefCounted<RefCountedHarfbuzzFace> { 100 public: 101 static PassRefPtr<RefCountedHarfbuzzFace> create(HB_FaceRec_* harfbuzzFace) 102 { 103 return adoptRef(new RefCountedHarfbuzzFace(harfbuzzFace)); 104 } 105 106 ~RefCountedHarfbuzzFace(); 107 108 HB_FaceRec_* face() const { return m_harfbuzzFace; } 109 110 private: 111 RefCountedHarfbuzzFace(HB_FaceRec_* harfbuzzFace) : m_harfbuzzFace(harfbuzzFace) 112 { 113 } 114 115 HB_FaceRec_* m_harfbuzzFace; 116 }; 117 118 SkTypeface* mTypeface; 119 float mTextSize; 120 mutable int mEmSizeInFontUnits; 121 bool mFakeBold; 122 bool mFakeItalic; 123 FontOrientation mOrientation; 124 TextOrientation mTextOrientation; 125 mutable RefPtr<RefCountedHarfbuzzFace> m_harfbuzzFace; 126 127 static SkTypeface* hashTableDeletedFontValue() { 128 return reinterpret_cast<SkTypeface*>(-1); 129 } 130 }; 131 132 } /* namespace */ 133 134 #endif 135