00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef BTFont_h
00027 #define BTFont_h
00028
00029 #include "FontDescription.h"
00030 #ifdef __OWB__
00031 #include "FontData.h"
00032 #include "FontPlatformData.h"
00033 #include "GraphicsContext.h"
00034 #endif //__OWB__
00035 #include <wtf/HashMap.h>
00036
00037 #if PLATFORM(QT)
00038 #include <QtGui/qfont.h>
00039 #include <QtGui/qfontmetrics.h>
00040 #endif
00041
00042 namespace WebCore {
00043
00044 class FloatPoint;
00045 class FloatRect;
00046 #ifndef __OWB__
00047 class FontData;
00048 #endif //__OWB__
00049 class FontFallbackList;
00050 class FontPlatformData;
00051 class FontSelector;
00052 class GlyphBuffer;
00053 class GlyphPageTreeNode;
00054 class GraphicsContext;
00055 class IntPoint;
00056 class TextStyle;
00057
00058 #ifdef __OWB__
00059 }
00060
00061 using BAL::BTFontData;
00062 using BAL::BTFontPlatformData;
00063 using WebCore::FloatPoint;
00064 using WebCore::FloatRect;
00065 using WebCore::FontDescription;
00066 using WebCore::FontFallbackList;
00067 using WebCore::FontFamily;
00068 using WebCore::FontSelector;
00069 using WebCore::GlyphBuffer;
00070 using WebCore::GlyphPageTreeNode;
00071 using WebCore::IntPoint;
00072 using WebCore::String;
00073 using WebCore::TextStyle;
00074
00075 namespace BAL {
00076 #endif //__OWB__
00077
00078 struct GlyphData;
00079
00080 class TextRun {
00081 public:
00082 TextRun(const UChar* c, int len)
00083 :m_characters(c), m_len(len)
00084 {}
00085
00086 TextRun(const String& s)
00087 :m_characters(s.characters()), m_len(s.length())
00088 {}
00089
00090 const UChar operator[](int i) const { return m_characters[i]; }
00091 const UChar* data(int i) const { return &m_characters[i]; }
00092
00093 const UChar* characters() const { return m_characters; }
00094 int length() const { return m_len; }
00095
00096 private:
00097 const UChar* m_characters;
00098 int m_len;
00099 };
00100
00101 class BTFont {
00102 public:
00103 BTFont();
00104 BTFont(const FontDescription&, short letterSpacing, short wordSpacing);
00105 #if !PLATFORM(QT)
00106 BTFont(const FontPlatformData&, bool isPrinting);
00107 #endif
00108 ~BTFont();
00109
00110 BTFont(const BTFont&);
00111 BTFont& operator=(const BTFont&);
00112
00113 bool operator==(const BTFont& other) const;
00114 bool operator!=(const BTFont& other) const {
00115 return !(*this == other);
00116 }
00117
00118 const FontDescription& fontDescription() const { return m_fontDescription; }
00119
00120 int pixelSize() const { return fontDescription().computedPixelSize(); }
00121 float size() const { return fontDescription().computedSize(); }
00122
00123 void update(PassRefPtr<FontSelector>) const;
00124
00125 void drawText(GraphicsContext*, const TextRun&, const TextStyle&, const FloatPoint&, int from = 0, int to = -1) const;
00126
00127 int width(const TextRun&, const TextStyle&) const;
00128 int width(const TextRun&) const;
00129 float floatWidth(const TextRun&, const TextStyle&) const;
00130 float floatWidth(const TextRun&) const;
00131
00132 int offsetForPosition(const TextRun&, const TextStyle&, int position, bool includePartialGlyphs) const;
00133 FloatRect selectionRectForText(const TextRun&, const TextStyle&, const IntPoint&, int h, int from = 0, int to = -1) const;
00134
00135 bool isSmallCaps() const { return m_fontDescription.smallCaps(); }
00136
00137 short wordSpacing() const { return m_wordSpacing; }
00138 short letterSpacing() const { return m_letterSpacing; }
00139 void setWordSpacing(short s) { m_wordSpacing = s; }
00140 void setLetterSpacing(short s) { m_letterSpacing = s; }
00141
00142 bool isFixedPitch() const;
00143 bool isPrinterFont() const { return m_fontDescription.usePrinterFont(); }
00144
00145 FontFamily& firstFamily() { return m_fontDescription.firstFamily(); }
00146 const FontFamily& family() const { return m_fontDescription.family(); }
00147
00148 bool italic() const { return m_fontDescription.italic(); }
00149 unsigned weight() const { return m_fontDescription.weight(); }
00150 bool bold() const { return m_fontDescription.bold(); }
00151
00152 #if !PLATFORM(QT)
00153 bool isPlatformFont() const { return m_isPlatformFont; }
00154 #endif
00155
00156 #if PLATFORM(QT)
00157 inline const QFont &font() const { return m_font; }
00158 inline const QFont &scFont() const { return m_scFont; }
00159 #endif
00160
00161
00162 int ascent() const;
00163 int descent() const;
00164 int height() const { return ascent() + descent(); }
00165 int lineSpacing() const;
00166 float xHeight() const;
00167 unsigned unitsPerEm() const;
00168 int spaceWidth() const;
00169 int tabWidth() const { return 8 * spaceWidth(); }
00170
00171 #if !PLATFORM(QT)
00172 const FontData* primaryFont() const;
00173 const FontData* fontDataAt(unsigned) const;
00174 const GlyphData& glyphDataForCharacter(UChar32, bool mirror) const;
00175
00176 const FontData* fontDataForCharacters(const UChar*, int length) const;
00177
00178 private:
00179 bool canUseGlyphCache(const TextRun&) const;
00180 void drawSimpleText(GraphicsContext*, const TextRun&, const TextStyle&, const FloatPoint&, int from, int to) const;
00181 void drawGlyphs(GraphicsContext*, const FontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const;
00182 void drawGlyphBuffer(GraphicsContext*, const GlyphBuffer&, const TextRun&, const TextStyle&, const FloatPoint&) const;
00183 void drawComplexText(GraphicsContext*, const TextRun&, const TextStyle&, const FloatPoint&, int from, int to) const;
00184 float floatWidthForSimpleText(const TextRun&, const TextStyle&, GlyphBuffer*) const;
00185 float floatWidthForComplexText(const TextRun&, const TextStyle&) const;
00186 int offsetForPositionForSimpleText(const TextRun&, const TextStyle&, int position, bool includePartialGlyphs) const;
00187 int offsetForPositionForComplexText(const TextRun&, const TextStyle&, int position, bool includePartialGlyphs) const;
00188 FloatRect selectionRectForSimpleText(const TextRun&, const TextStyle&, const IntPoint&, int h, int from, int to) const;
00189 FloatRect selectionRectForComplexText(const TextRun&, const TextStyle&, const IntPoint&, int h, int from, int to) const;
00190 #endif
00191 friend struct WidthIterator;
00192
00193
00194 public:
00195 #if !PLATFORM(QT)
00196 enum CodePath { Auto, Simple, Complex };
00197 static void setCodePath(CodePath);
00198 static CodePath codePath;
00199
00200 static const uint8_t gRoundingHackCharacterTable[256];
00201 static bool isRoundingHackCharacter(UChar32 c)
00202 {
00203 return (((c & ~0xFF) == 0 && gRoundingHackCharacterTable[c]));
00204 }
00205 #endif
00206 static bool treatAsSpace(UChar c) { return c == ' ' || c == '\t' || c == '\n' || c == 0x00A0; }
00207 static bool treatAsZeroWidthSpace(UChar c) { return c < 0x20 || (c >= 0x7F && c < 0xA0) || c == 0x200e || c == 0x200f; }
00208 private:
00209 FontDescription m_fontDescription;
00210 #if !PLATFORM(QT)
00211 mutable RefPtr<FontFallbackList> m_fontList;
00212 mutable HashMap<int, GlyphPageTreeNode*> m_pages;
00213 mutable GlyphPageTreeNode* m_pageZero;
00214 #endif
00215 short m_letterSpacing;
00216 short m_wordSpacing;
00217 #if !PLATFORM(QT)
00218 bool m_isPlatformFont;
00219 #else
00220 QFont m_font;
00221 QFont m_scFont;
00222 int m_spaceWidth;
00223 #endif
00224 };
00225
00226 }
00227
00228 #endif