Home | History | Annotate | Download | only in fonts
      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 #include "SkLanguage.h"
     37 #include "SkPaint.h"
     38 
     39 #ifndef NDEBUG
     40 #include "PlatformString.h"
     41 #endif
     42 
     43 class SkTypeface;
     44 
     45 struct HB_FaceRec_;
     46 
     47 namespace WebCore {
     48 
     49 class FontPlatformData {
     50 public:
     51     static FontPlatformData Deleted() {
     52         return FontPlatformData(NULL, -1, false, false);
     53     }
     54 
     55     FontPlatformData();
     56     FontPlatformData(const FontPlatformData&);
     57     FontPlatformData(SkTypeface*, float textSize, bool fakeBold, bool fakeItalic,
     58                      FontOrientation = Horizontal, TextOrientation = TextOrientationVerticalRight);
     59     FontPlatformData(const FontPlatformData& src, float textSize);
     60     FontPlatformData(float size, bool syntheticBold, bool syntheticOblique);
     61     FontPlatformData(const FontPlatformData& src, SkTypeface* typeface);
     62 
     63     ~FontPlatformData();
     64 
     65     FontPlatformData(WTF::HashTableDeletedValueType)
     66         : m_typeface(hashTableDeletedFontValue()) { }
     67     bool isHashTableDeletedValue() const {
     68         return m_typeface == hashTableDeletedFontValue();
     69     }
     70 
     71     FontOrientation orientation() const { return m_orientation; }
     72     void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
     73     FontPlatformData& operator=(const FontPlatformData&);
     74     bool operator==(const FontPlatformData& a) const;
     75 
     76     void     setupPaint(SkPaint*) const;
     77 
     78     // -------------------------------------------------------------------------
     79     // Return Skia's unique id for this font. This encodes both the style and
     80     // the font's file name so refers to a single face.
     81     // -------------------------------------------------------------------------
     82     uint32_t uniqueID() const;
     83 
     84     float size() const { return m_textSize; }
     85     unsigned hash() const;
     86     int emSizeInFontUnits() const;
     87     bool isFixedPitch() const;
     88 
     89 #ifndef NDEBUG
     90     String description() const { return ""; }
     91 #endif
     92 
     93     HB_FaceRec_* harfbuzzFace() const;
     94     SkTypeface* typeface() const { return m_typeface; }
     95 
     96     bool isFakeBold() const { return m_fakeBold; }
     97     bool isFakeItalic() const { return m_fakeItalic; }
     98 
     99     static void setDefaultLanguage(const char* language);
    100 
    101 private:
    102     class RefCountedHarfbuzzFace : public RefCounted<RefCountedHarfbuzzFace> {
    103     public:
    104         static PassRefPtr<RefCountedHarfbuzzFace> create(HB_FaceRec_* harfbuzzFace)
    105         {
    106             return adoptRef(new RefCountedHarfbuzzFace(harfbuzzFace));
    107         }
    108 
    109         ~RefCountedHarfbuzzFace();
    110 
    111         HB_FaceRec_* face() const { return m_harfbuzzFace; }
    112 
    113     private:
    114         RefCountedHarfbuzzFace(HB_FaceRec_* harfbuzzFace) : m_harfbuzzFace(harfbuzzFace)
    115         {
    116         }
    117 
    118         HB_FaceRec_* m_harfbuzzFace;
    119     };
    120 
    121     SkTypeface* m_typeface;
    122     float       m_textSize;
    123     mutable int m_emSizeInFontUnits;
    124     bool        m_fakeBold;
    125     bool        m_fakeItalic;
    126     FontOrientation m_orientation;
    127     TextOrientation m_textOrientation;
    128     mutable RefPtr<RefCountedHarfbuzzFace> m_harfbuzzFace;
    129     static SkLanguage s_defaultLanguage;
    130 
    131     static SkTypeface* hashTableDeletedFontValue() {
    132         return reinterpret_cast<SkTypeface*>(-1);
    133     }
    134 };
    135 
    136 } /* namespace */
    137 
    138 #endif
    139