Changeset 39207 in webkit
- Timestamp:
- Dec 11, 2008, 6:46:52 AM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 added
- 13 edited
- 1 copied
-
ChangeLog (modified) (1 diff)
-
WebCore.pro (modified) (7 diffs)
-
platform/graphics/Font.h (modified) (10 diffs)
-
platform/graphics/SimpleFontData.cpp (modified) (6 diffs)
-
platform/graphics/SimpleFontData.h (modified) (3 diffs)
-
platform/graphics/qt/FontCacheQt.cpp (modified) (4 diffs)
-
platform/graphics/qt/FontCustomPlatformData.cpp (modified) (3 diffs)
-
platform/graphics/qt/FontCustomPlatformData.h (modified) (1 diff)
-
platform/graphics/qt/FontFallbackListQt.cpp (added)
-
platform/graphics/qt/FontPlatformData.h (modified) (3 diffs)
-
platform/graphics/qt/FontPlatformDataQt.cpp (added)
-
platform/graphics/qt/FontQt.cpp (modified) (10 diffs)
-
platform/graphics/qt/FontQt43.cpp (copied) (copied from trunk/WebCore/platform/graphics/qt/FontQt.cpp ) (9 diffs)
-
platform/graphics/qt/GlyphPageTreeNodeQt.cpp (modified) (2 diffs)
-
platform/graphics/qt/SimpleFontDataQt.cpp (modified) (2 diffs)
-
platform/qt/RenderThemeQt.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r39206 r39207 1 2008-12-11 Holger Freyther <zecke@selfish.org> 2 3 Reviewed by Simon Hausmann. 4 5 https://bugs.webkit.org/show_bug.cgi?id=20953 6 7 Make the Qt port follow the Win, Mac, Gtk+ port in regard to Font 8 handling. FontQt.cpp from now on is only implementing the complex path. Create 9 FontFallbackListQt.cpp and FontPlatformDataQt.cpp to work within 10 the framework set by the Font code. 11 12 Sharing the Font.cpp implementation allows the Qt port to support 13 the CSS font faces and SVG fonts. 14 15 Split out the Qt4.3 Font handling into FonQt43.cpp to allow to more 16 easily deprecate it. 17 18 This commit is removing a lot of #ifdefs from Font.h as the Qt Font 19 implementation is now in line with the rest of WebCore. 20 21 * WebCore.pro: 22 * platform/graphics/Font.h: Remove #ifdefs 23 (WebCore::Font::letterSpacing): 24 (WebCore::Font::setLetterSpacing): 25 (WebCore::Font::isPlatformFont): 26 * platform/graphics/FontFallbackList.h: 27 * platform/graphics/SimpleFontData.cpp: 28 (WebCore::SimpleFontData::SimpleFontData): 29 (WebCore::SimpleFontData::platformGlyphInit): There is no GlyphCache 30 on Qt, move the initialisation over. 31 (WebCore::SimpleFontData::~SimpleFontData): 32 * platform/graphics/SimpleFontData.h: 33 (WebCore::SimpleFontData::getQtFont): 34 * platform/graphics/qt/FontCacheQt.cpp: 35 (WebCore::FontCache::getCachedFontPlatformData): Remove unused parameter 36 (WebCore::FontCache::releaseFontData): Add to build 37 * platform/graphics/qt/FontCustomPlatformData.cpp: 38 (WebCore::FontCustomPlatformData::~FontCustomPlatformData): 39 (WebCore::FontCustomPlatformData::fontPlatformData): 40 (WebCore::createFontCustomPlatformData): 41 * platform/graphics/qt/FontCustomPlatformData.h: 42 * platform/graphics/qt/FontFallbackListQt.cpp: Added. 43 (WebCore::FontFallbackList::FontFallbackList): 44 (WebCore::FontFallbackList::invalidate): 45 (WebCore::FontFallbackList::releaseFontData): 46 (WebCore::FontFallbackList::determinePitch): 47 (WebCore::FontFallbackList::fontDataAt): 48 (WebCore::FontFallbackList::fontDataForCharacters): 49 (WebCore::FontFallbackList::setPlatformFont): 50 * platform/graphics/qt/FontPlatformData.h: 51 (WebCore::FontPlatformData::font): 52 (WebCore::FontPlatformData::size): 53 * platform/graphics/qt/FontPlatformDataQt.cpp: Added. 54 (WebCore::FontPlatformData::FontPlatformData): 55 * platform/graphics/qt/FontQt.cpp: 56 (WebCore::Font::drawComplexText): 57 (WebCore::Font::floatWidthForComplexText): 58 (WebCore::Font::offsetForPositionForComplexText): 59 (WebCore::Font::selectionRectForComplexText): 60 (WebCore::Font::font): 61 * platform/graphics/qt/FontQt43.cpp: Added. Moved Qt4.3 code from FontQt.cpp 62 (WebCore::Font::drawComplexText): 63 (WebCore::Font::floatWidthForComplexText): 64 (WebCore::Font::offsetForPositionForComplexText): 65 (WebCore::Font::selectionRectForComplexText): 66 * platform/graphics/qt/GlyphPageTreeNodeQt.cpp: 67 (WebCore::GlyphPageTreeNode::pruneTreeCustomFontData): 68 (WebCore::GlyphPageTreeNode::pruneTreeFontData): 69 * platform/graphics/qt/SimpleFontDataQt.cpp: 70 (WebCore::SimpleFontData::determinePitch): 71 (WebCore::SimpleFontData::containsCharacters): 72 (WebCore::SimpleFontData::platformInit): 73 (WebCore::SimpleFontData::platformGlyphInit): 74 (WebCore::SimpleFontData::platformDestroy): 75 * platform/qt/RenderThemeQt.cpp: 76 (WebCore::RenderThemeQt::adjustButtonStyle): Avoid crashes. 77 1 78 2008-12-11 Holger Freyther <zecke@selfish.org> 2 79 -
trunk/WebCore/WebCore.pro
r39171 r39207 78 78 !contains(DEFINES, ENABLE_WML=.): DEFINES += ENABLE_WML=0 79 79 !contains(DEFINES, ENABLE_SVG=.): DEFINES += ENABLE_SVG=1 80 #!contains(DEFINES, ENABLE_SVG_FONTS=.): DEFINES += ENABLE_SVG_FONTS=180 !contains(DEFINES, ENABLE_SVG_FONTS=.): DEFINES += ENABLE_SVG_FONTS=1 81 81 !contains(DEFINES, ENABLE_SVG_FILTERS=.): DEFINES += ENABLE_SVG_FILTERS=1 82 82 !contains(DEFINES, ENABLE_SVG_FOREIGN_OBJECT=.): DEFINES += ENABLE_SVG_FOREIGN_OBJECT=1 … … 837 837 platform/graphics/FloatSize.cpp \ 838 838 platform/graphics/FontData.cpp \ 839 platform/graphics/Font.cpp \ 839 840 platform/graphics/GeneratedImage.cpp \ 840 841 platform/graphics/Gradient.cpp \ … … 848 849 platform/graphics/Pen.cpp \ 849 850 platform/graphics/SegmentedFontData.cpp \ 851 platform/graphics/SimpleFontData.cpp \ 850 852 platform/KURL.cpp \ 851 853 platform/Length.cpp \ … … 1039 1041 platform/graphics/qt/AffineTransformQt.cpp \ 1040 1042 platform/graphics/qt/ColorQt.cpp \ 1043 platform/graphics/qt/FontQt.cpp \ 1044 platform/graphics/qt/FontQt43.cpp \ 1045 platform/graphics/qt/FontPlatformDataQt.cpp \ 1041 1046 platform/graphics/qt/FloatPointQt.cpp \ 1042 1047 platform/graphics/qt/FloatRectQt.cpp \ … … 1071 1076 platform/graphics/qt/FontCacheQt.cpp \ 1072 1077 platform/graphics/qt/FontCustomPlatformData.cpp \ 1073 platform/graphics/qt/Font Qt.cpp \1078 platform/graphics/qt/FontFallbackListQt.cpp \ 1074 1079 platform/graphics/qt/GlyphPageTreeNodeQt.cpp \ 1075 1080 platform/graphics/qt/SimpleFontDataQt.cpp \ … … 1488 1493 svg/SVGGlyphElement.idl \ 1489 1494 svg/SVGGradientElement.idl \ 1495 svg/SVGHKernElement.idl \ 1490 1496 svg/SVGImageElement.idl \ 1491 1497 svg/SVGLength.idl \ … … 1636 1642 svg/SVGGlyphElement.cpp \ 1637 1643 svg/SVGGradientElement.cpp \ 1644 svg/SVGHKernElement.cpp \ 1638 1645 svg/SVGImageElement.cpp \ 1639 1646 svg/SVGLangSpace.cpp \ -
trunk/WebCore/platform/graphics/Font.h
r39206 r39207 4 4 * (C) 2000 Dirk Mueller (mueller@kde.org) 5 5 * Copyright (C) 2003, 2006, 2007 Apple Computer, Inc. 6 * Copyright (C) 2008 Holger Hans Peter Freyther 6 7 * 7 8 * This library is free software; you can redistribute it and/or … … 30 31 31 32 #if PLATFORM(QT) 32 #include <QtGui/qfont.h> 33 #include <QtGui/qfontmetrics.h> 33 #include <QFont> 34 34 #endif 35 35 … … 55 55 Font(); 56 56 Font(const FontDescription&, short letterSpacing, short wordSpacing); 57 #if !PLATFORM(QT) 58 Font(const FontPlatformData&, bool isPrinting); // This constructor is only used if the platform wants to start with a native font. 59 #endif 57 // This constructor is only used if the platform wants to start with a native font. 58 Font(const FontPlatformData&, bool isPrinting); 60 59 ~Font(); 61 60 … … 88 87 short wordSpacing() const { return m_wordSpacing; } 89 88 short letterSpacing() const { return m_letterSpacing; } 90 #if !PLATFORM(QT)91 89 void setWordSpacing(short s) { m_wordSpacing = s; } 92 90 void setLetterSpacing(short s) { m_letterSpacing = s; } 93 #else94 void setWordSpacing(short s);95 void setLetterSpacing(short s);96 #endif97 91 bool isFixedPitch() const; 98 92 bool isPrinterFont() const { return m_fontDescription.usePrinterFont(); } … … 106 100 FontWeight weight() const { return m_fontDescription.weight(); } 107 101 108 #if !PLATFORM(QT)109 102 bool isPlatformFont() const { return m_isPlatformFont; } 110 #endif111 112 #if PLATFORM(QT)113 inline const QFont &font() const { return m_font; }114 inline const QFont &scFont() const { return m_scFont; }115 #endif116 103 117 104 // Metrics that we query the FontFallbackList for. … … 126 113 int tabWidth() const { return 8 * spaceWidth(); } 127 114 128 #if !PLATFORM(QT)129 115 const SimpleFontData* primaryFont() const { 130 116 if (!m_cachedPrimaryFont) … … 137 123 // Used for complex text, and does not utilize the glyph map cache. 138 124 const FontData* fontDataForCharacters(const UChar*, int length) const; 125 126 #if PLATFORM(QT) 127 QFont font() const; 139 128 #endif 140 129 … … 167 156 168 157 public: 169 #if PLATFORM(QT)170 FontSelector* fontSelector() const { return 0; }171 #else172 158 // Useful for debugging the different font rendering code paths. 173 159 #if USE(FONT_FAST_PATH) … … 185 171 186 172 FontSelector* fontSelector() const; 187 #endif188 173 static bool treatAsSpace(UChar c) { return c == ' ' || c == '\t' || c == '\n' || c == 0x00A0; } 189 174 static bool treatAsZeroWidthSpace(UChar c) { return c < 0x20 || (c >= 0x7F && c < 0xA0) || c == 0x200e || c == 0x200f || (c >= 0x202a && c <= 0x202e) || c == 0xFFFC; } … … 196 181 private: 197 182 FontDescription m_fontDescription; 198 #if !PLATFORM(QT)199 183 mutable RefPtr<FontFallbackList> m_fontList; 200 184 mutable HashMap<int, GlyphPageTreeNode*> m_pages; 201 185 mutable GlyphPageTreeNode* m_pageZero; 202 186 mutable const SimpleFontData* m_cachedPrimaryFont; 203 #endif204 187 short m_letterSpacing; 205 188 short m_wordSpacing; 206 #if !PLATFORM(QT)207 189 bool m_isPlatformFont; 208 #else209 QFont m_font;210 QFont m_scFont;211 int m_spaceWidth;212 #endif213 190 }; 214 191 -
trunk/WebCore/platform/graphics/SimpleFontData.cpp
r33056 r39207 51 51 , m_smallCapsFontData(0) 52 52 { 53 #if ENABLE(SVG_FONTS) && !PLATFORM(QT)53 #if ENABLE(SVG_FONTS) 54 54 if (SVGFontFaceElement* svgFontFaceElement = svgFontData ? svgFontData->svgFontFaceElement() : 0) { 55 55 m_unitsPerEm = svgFontFaceElement->unitsPerEm(); … … 76 76 77 77 platformInit(); 78 platformGlyphInit(); 79 } 78 80 81 #if !PLATFORM(QT) 82 void SimpleFontData::platformGlyphInit() 83 { 79 84 GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page(); 80 85 if (!glyphPageZero) { … … 114 119 m_missingGlyphData.glyph = 0; 115 120 } 121 #endif 116 122 117 123 SimpleFontData::~SimpleFontData() … … 123 129 } 124 130 125 #if ENABLE(SVG_FONTS) && !PLATFORM(QT)131 #if ENABLE(SVG_FONTS) 126 132 if (!m_svgFontData || !m_svgFontData->svgFontFaceElement()) 127 133 #endif … … 129 135 } 130 136 137 #if !PLATFORM(QT) 131 138 float SimpleFontData::widthForGlyph(Glyph glyph) const 132 139 { … … 140 147 return width; 141 148 } 149 #endif 142 150 143 151 const SimpleFontData* SimpleFontData::fontDataForCharacter(UChar32) const -
trunk/WebCore/platform/graphics/SimpleFontData.h
r37801 r39207 40 40 #if PLATFORM(CAIRO) 41 41 #include <cairo.h> 42 #endif 43 44 #if PLATFORM(QT) 45 #include <QFont> 42 46 #endif 43 47 … … 110 114 #endif 111 115 116 #if PLATFORM(QT) 117 QFont getQtFont() const { return m_font.font(); } 118 #endif 119 112 120 #if PLATFORM(WIN) 113 121 bool isSystemFont() const { return m_isSystemFont; } … … 129 137 private: 130 138 void platformInit(); 139 void platformGlyphInit(); 131 140 void platformDestroy(); 132 141 -
trunk/WebCore/platform/graphics/qt/FontCacheQt.cpp
r37061 r39207 1 1 /* 2 2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 Copyright (C) 2008 Holger Hans Peter Freyther 3 4 4 5 This library is free software; you can redistribute it and/or … … 22 23 #include "config.h" 23 24 #include "FontCache.h" 25 24 26 #include "FontDescription.h" 27 #include "FontPlatformData.h" 25 28 #include "Font.h" 26 29 … … 31 34 } 32 35 33 FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& , const AtomicString& family, bool checkingAlternateName)36 FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& description, const AtomicString& family, bool checkingAlternateName) 34 37 { 35 return 0;38 return new FontPlatformData(description); 36 39 } 37 40 … … 46 49 } 47 50 51 void FontCache::releaseFontData(const WebCore::SimpleFontData*) 52 { 53 } 54 48 55 void FontCache::addClient(FontSelector*) 49 56 { -
trunk/WebCore/platform/graphics/qt/FontCustomPlatformData.cpp
r37061 r39207 26 26 #include "SharedBuffer.h" 27 27 #include <QFontDatabase> 28 #include <QStringList> 28 29 29 30 namespace WebCore { … … 31 32 FontCustomPlatformData::~FontCustomPlatformData() 32 33 { 33 QFontDatabase::removeApplicationFont( handle);34 QFontDatabase::removeApplicationFont(m_handle); 34 35 } 35 36 36 37 FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, FontRenderingMode) 37 38 { 38 FontPlatformData result; 39 result.handle = handle; 40 return result; 39 QFont font; 40 font.setFamily(QFontDatabase::applicationFontFamilies(m_handle)[0]); 41 font.setPixelSize(size); 42 if (bold) 43 font.setWeight(QFont::Bold); 44 font.setItalic(italic); 45 46 return FontPlatformData(font, bold); 41 47 } 42 48 … … 48 54 if (id == -1) 49 55 return 0; 56 57 Q_ASSERT(QFontDatabase::applicationFontFamilies(id).size() > 0); 58 50 59 FontCustomPlatformData *data = new FontCustomPlatformData; 51 data-> handle = id;60 data->m_handle = id; 52 61 return data; 53 62 } -
trunk/WebCore/platform/graphics/qt/FontCustomPlatformData.h
r37061 r39207 34 34 ~FontCustomPlatformData(); 35 35 36 int handle; // for use with QFontDatabase::addApplicationFont/removeApplicationFont 36 // for use with QFontDatabase::addApplicationFont/removeApplicationFont 37 int m_handle; 37 38 38 39 FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontRenderingMode = NormalRenderingMode); -
trunk/WebCore/platform/graphics/qt/FontPlatformData.h
r37061 r39207 1 1 /* 2 2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 Copyright (C) 2008 Holger Hans Peter Freyther 3 4 4 5 This library is free software; you can redistribute it and/or … … 23 24 #define FontPlatformData_h 24 25 26 #include "FontDescription.h" 27 28 #include <QFont> 29 25 30 namespace WebCore { 26 31 … … 28 33 { 29 34 public: 30 // this is only used for custom loaded fonts and represents the id handle passed to 31 // QFontDatabase::addApplicationFont/removeApplicationFont 32 int handle; 35 #if ENABLE(SVG_FONTS) 36 FontPlatformData(float size, bool bold, bool oblique); 37 #endif 38 FontPlatformData(); 39 FontPlatformData(const FontDescription&, int wordSpacing = 0, int letterSpacing = 0); 40 FontPlatformData(const QFont&, bool bold); 41 42 QFont font() const { return m_font; } 43 float size() const { return m_size; } 44 45 float m_size; 46 bool m_bold; 47 bool m_oblique; 48 QFont m_font; 33 49 }; 34 50 -
trunk/WebCore/platform/graphics/qt/FontQt.cpp
r37061 r39207 1 1 /* 2 2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 Copyright (C) 2008 Holger Hans Peter Freyther 3 4 4 5 This library is free software; you can redistribute it and/or … … 21 22 #include "Font.h" 22 23 #include "FontDescription.h" 24 #include "FontFallbackList.h" 23 25 #include "FontSelector.h" 24 26 … … 32 34 33 35 #include <limits.h> 34 namespace WebCore {35 36 36 37 #if QT_VERSION >= 0x040400 37 38 Font::Font() 39 : m_letterSpacing(0) 40 , m_wordSpacing(0) 41 , m_font() 42 , m_scFont() 43 { 44 QFontMetrics metrics(m_font); 45 m_spaceWidth = metrics.width(QLatin1Char(' ')); 46 } 47 48 Font::Font(const FontDescription& description, short letterSpacing, short wordSpacing) 49 : m_fontDescription(description) 50 , m_letterSpacing(letterSpacing) 51 , m_wordSpacing(wordSpacing) 52 { 53 const FontFamily* family = &description.family(); 54 QString familyName; 55 while (family) { 56 familyName += family->family(); 57 family = family->next(); 58 if (family) 59 familyName += QLatin1Char(','); 60 } 61 62 m_font.setFamily(familyName); 63 m_font.setPixelSize(qRound(description.computedSize())); 64 m_font.setItalic(description.italic()); 65 // FIXME: Map all FontWeight values to QFont weights. 66 if (description.weight() >= FontWeight600) 67 m_font.setWeight(QFont::Bold); 68 else 69 m_font.setWeight(QFont::Normal); 70 71 bool smallCaps = description.smallCaps(); 72 m_font.setCapitalization(smallCaps ? QFont::SmallCaps : QFont::MixedCase); 73 74 QFontMetrics metrics = QFontMetrics(m_font); 75 m_spaceWidth = metrics.width(QLatin1Char(' ')); 76 77 if (wordSpacing) 78 m_font.setWordSpacing(wordSpacing); 79 if (letterSpacing) 80 m_font.setLetterSpacing(QFont::AbsoluteSpacing, letterSpacing); 81 } 82 83 void Font::setWordSpacing(short s) 84 { 85 m_font.setWordSpacing(s); 86 m_wordSpacing = s; 87 } 88 void Font::setLetterSpacing(short s) 89 { 90 m_font.setLetterSpacing(QFont::AbsoluteSpacing, s); 91 m_letterSpacing = s; 92 } 93 38 namespace WebCore { 94 39 95 40 static QString qstring(const TextRun& run) … … 122 67 } 123 68 124 void Font::draw Text(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const69 void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const 125 70 { 126 71 if (to < 0) 127 72 to = run.length(); 73 128 74 QPainter *p = ctx->platformContext(); 129 75 Color color = ctx->fillColor(); … … 139 85 140 86 if (from > 0 || to < run.length()) { 141 QTextLayout layout(string, m_font);87 QTextLayout layout(string, font()); 142 88 QTextLine line = setupLayout(&layout, run); 143 89 float x1 = line.cursorToX(from); … … 146 92 qSwap(x1, x2); 147 93 148 QFontMetrics fm( m_font);94 QFontMetrics fm(font()); 149 95 int ascent = fm.ascent(); 150 96 QRectF clip(point.x() + x1, point.y() - ascent, x2 - x1, fm.height()); … … 180 126 } 181 127 182 p->setFont( m_font);128 p->setFont(font()); 183 129 184 130 QPointF pt(point.x(), point.y()); … … 195 141 } 196 142 197 int Font::width(const TextRun& run) const143 float Font::floatWidthForComplexText(const TextRun& run) const 198 144 { 199 145 if (!run.length()) 200 146 return 0; 201 147 QString string = qstring(run); 202 QTextLayout layout(string, m_font);148 QTextLayout layout(string, font()); 203 149 QTextLine line = setupLayout(&layout, run); 204 150 int w = int(line.naturalTextWidth()); … … 210 156 } 211 157 212 float Font::floatWidth(const TextRun& run) const 213 { 214 return width(run); 215 } 216 217 float Font::floatWidth(const TextRun& run, int /*extraCharsAvailable*/, int& charsConsumed, String& glyphName) const 218 { 219 charsConsumed = run.length(); 220 glyphName = ""; 221 return width(run); 222 } 223 224 int Font::offsetForPosition(const TextRun& run, int position, bool /*includePartialGlyphs*/) const 158 int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool includePartialGlyphs) const 225 159 { 226 160 QString string = qstring(run); 227 QTextLayout layout(string, m_font);161 QTextLayout layout(string, font()); 228 162 QTextLine line = setupLayout(&layout, run); 229 163 return line.xToCursor(position); 230 164 } 231 165 232 FloatRect Font::selectionRectFor Text(const TextRun& run, const IntPoint& pt, int h, int from, int to) const166 FloatRect Font::selectionRectForComplexText(const TextRun& run, const IntPoint& pt, int h, int from, int to) const 233 167 { 234 168 QString string = qstring(run); 235 QTextLayout layout(string, m_font);169 QTextLayout layout(string, font()); 236 170 QTextLine line = setupLayout(&layout, run); 237 171 … … 244 178 } 245 179 246 #else 247 248 249 struct TextRunComponent { 250 TextRunComponent() : font(0) {} 251 TextRunComponent(const UChar *start, int length, bool rtl, const QFont *font, int offset, bool sc = false); 252 TextRunComponent(int spaces, bool rtl, const QFont *font, int offset); 253 254 inline bool isSpace() const { return spaces != 0; } 255 256 QString string; 257 const QFont *font; 258 int width; 259 int offset; 260 int spaces; 261 }; 262 263 TextRunComponent::TextRunComponent(const UChar *start, int length, bool rtl, const QFont *f, int o, bool sc) 264 : string(reinterpret_cast<const QChar*>(start), length) 265 , font(f) 266 , offset(o) 267 , spaces(0) 180 QFont Font::font() const 268 181 { 269 if (sc) 270 string = string.toUpper(); 271 string.prepend(rtl ? QChar(0x202e) : QChar(0x202d)); 272 width = QFontMetrics(*font).width(string); 273 } 274 275 TextRunComponent::TextRunComponent(int s, bool rtl, const QFont *f, int o) 276 : string(s, QLatin1Char(' ')) 277 , font(f) 278 , offset(o) 279 , spaces(s) 280 { 281 string.prepend(rtl ? QChar(0x202e) : QChar(0x202d)); 282 width = spaces * QFontMetrics(*font).width(QLatin1Char(' ')); 283 } 284 285 286 Font::Font() 287 : m_letterSpacing(0) 288 , m_wordSpacing(0) 289 , m_font() 290 , m_scFont() 291 { 292 QFontMetrics metrics(m_font); 293 m_spaceWidth = metrics.width(QLatin1Char(' ')); 294 qreal pointsize = m_font.pointSizeF(); 295 if (pointsize > 0) 296 m_scFont.setPointSizeF(pointsize*0.7); 297 else 298 m_scFont.setPixelSize(qRound(m_font.pixelSize()*.7)); 299 } 300 301 Font::Font(const FontDescription& description, short letterSpacing, short wordSpacing) 302 : m_fontDescription(description) 303 , m_letterSpacing(letterSpacing) 304 , m_wordSpacing(wordSpacing) 305 { 306 const FontFamily* family = &description.family(); 307 QString familyName; 308 while (family) { 309 familyName += family->family(); 310 family = family->next(); 311 if (family) 312 familyName += QLatin1Char(','); 313 } 314 315 m_font.setFamily(familyName); 316 m_font.setPixelSize(qRound(description.computedSize())); 317 m_font.setItalic(description.italic()); 318 // FIXME: Map all FontWeight values to QFont weights. 319 if (description.weight() >= FontWeight600) 320 m_font.setWeight(QFont::Bold); 321 else 322 m_font.setWeight(QFont::Normal); 323 324 QFontMetrics metrics = QFontMetrics(m_font); 325 m_spaceWidth = metrics.width(QLatin1Char(' ')); 326 m_scFont = m_font; 327 m_scFont.setPixelSize(qRound(description.computedSize()*.7)); 328 } 329 330 void Font::setWordSpacing(short s) 331 { 332 m_wordSpacing = s; 333 } 334 void Font::setLetterSpacing(short s) 335 { 336 m_letterSpacing = s; 337 } 338 339 static int generateComponents(Vector<TextRunComponent, 1024>* components, const Font &font, const TextRun &run) 340 { 341 // qDebug() << "generateComponents" << QString((const QChar *)run.characters(), run.length()); 342 int letterSpacing = font.letterSpacing(); 343 int wordSpacing = font.wordSpacing(); 344 bool smallCaps = font.fontDescription().smallCaps(); 345 int padding = run.padding(); 346 int numSpaces = 0; 347 if (padding) { 348 for (int i = 0; i < run.length(); i++) 349 if (Font::treatAsSpace(run[i])) 350 ++numSpaces; 351 } 352 353 int offset = 0; 354 const QFont *f = &font.font(); 355 if (letterSpacing || smallCaps) { 356 // need to draw every letter on it's own 357 int start = 0; 358 if (Font::treatAsSpace(run[0])) { 359 int add = 0; 360 if (numSpaces) { 361 add = padding/numSpaces; 362 padding -= add; 363 --numSpaces; 364 } 365 components->append(TextRunComponent(1, run.rtl(), &font.font(), offset)); 366 offset += add + letterSpacing + components->last().width; 367 start = 1; 368 // qDebug() << "space at 0" << offset; 369 } else if (smallCaps) { 370 f = (QChar::category(run[0]) == QChar::Letter_Lowercase ? &font.scFont() : &font.font()); 371 } 372 for (int i = 1; i < run.length(); ++i) { 373 uint ch = run[i]; 374 if (QChar(ch).isHighSurrogate() && QChar(run[i-1]).isLowSurrogate()) 375 ch = QChar::surrogateToUcs4(ch, run[i-1]); 376 if (QChar(ch).isLowSurrogate() || QChar::category(ch) == QChar::Mark_NonSpacing) 377 continue; 378 if (Font::treatAsSpace(run[i])) { 379 int add = 0; 380 // qDebug() << " treatAsSpace:" << i << start; 381 if (i - start > 0) { 382 components->append(TextRunComponent(run.characters() + start, i - start, 383 run.rtl(), 384 f, offset, f == &font.scFont())); 385 offset += components->last().width + letterSpacing; 386 // qDebug() << " appending(1) " << components->last().string << components->last().width; 387 } 388 if (numSpaces) { 389 add = padding/numSpaces; 390 padding -= add; 391 --numSpaces; 392 } 393 components->append(TextRunComponent(1, run.rtl(), &font.font(), offset)); 394 offset += wordSpacing + add + components->last().width + letterSpacing; 395 start = i + 1; 396 continue; 397 } else if (!letterSpacing) { 398 // qDebug() << i << char(run[i]) << (QChar::category(ch) == QChar::Letter_Lowercase) << 399 // QFontInfo(*f).pointSizeF(); 400 if (QChar::category(ch) == QChar::Letter_Lowercase) { 401 if (f == &font.scFont()) 402 continue; 403 } else { 404 if (f == &font.font()) 405 continue; 406 } 407 } 408 if (i - start > 0) { 409 components->append(TextRunComponent(run.characters() + start, i - start, 410 run.rtl(), 411 f, offset, f == &font.scFont())); 412 offset += components->last().width + letterSpacing; 413 // qDebug() << " appending(2) " << components->last().string << components->last().width; 414 } 415 if (smallCaps) 416 f = (QChar::category(ch) == QChar::Letter_Lowercase ? &font.scFont() : &font.font()); 417 start = i; 418 } 419 if (run.length() - start > 0) { 420 components->append(TextRunComponent(run.characters() + start, run.length() - start, 421 run.rtl(), 422 f, offset, f == &font.scFont())); 423 offset += components->last().width; 424 // qDebug() << " appending(3) " << components->last().string << components->last().width; 425 } 426 offset += letterSpacing; 427 } else { 428 int start = 0; 429 for (int i = 0; i < run.length(); ++i) { 430 if (Font::treatAsSpace(run[i])) { 431 if (i - start > 0) { 432 components->append(TextRunComponent(run.characters() + start, i - start, 433 run.rtl(), 434 f, offset)); 435 offset += components->last().width; 436 } 437 int add = 0; 438 if (numSpaces) { 439 add = padding/numSpaces; 440 padding -= add; 441 --numSpaces; 442 } 443 components->append(TextRunComponent(1, run.rtl(), &font.font(), offset)); 444 offset += add + components->last().width; 445 if (i) 446 offset += wordSpacing; 447 start = i + 1; 448 } 449 } 450 if (run.length() - start > 0) { 451 components->append(TextRunComponent(run.characters() + start, run.length() - start, 452 run.rtl(), 453 f, offset)); 454 offset += components->last().width; 455 } 456 } 457 return offset; 458 } 459 460 void Font::drawText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const 461 { 462 if (to < 0) 463 to = run.length(); 464 QPainter *p = ctx->platformContext(); 465 Color color = ctx->fillColor(); 466 p->setPen(QColor(color)); 467 468 Vector<TextRunComponent, 1024> components; 469 int w = generateComponents(&components, *this, run); 470 471 if (from > 0 || to < run.length()) { 472 FloatRect clip = selectionRectForText(run, 473 IntPoint(qRound(point.x()), qRound(point.y())), 474 QFontMetrics(m_font).height(), from, to); 475 QRectF rect(clip.x(), clip.y() - ascent(), clip.width(), clip.height()); 476 p->save(); 477 p->setClipRect(rect.toRect()); 478 } 479 480 if (run.rtl()) { 481 for (int i = 0; i < components.size(); ++i) { 482 if (!components.at(i).isSpace()) { 483 p->setFont(*components.at(i).font); 484 QPointF pt(point.x() + w - components.at(i).offset - components.at(i).width, point.y()); 485 p->drawText(pt, components.at(i).string); 486 } 487 } 488 } else { 489 for (int i = 0; i < components.size(); ++i) { 490 if (!components.at(i).isSpace()) { 491 p->setFont(*components.at(i).font); 492 QPointF pt(point.x() + components.at(i).offset, point.y()); 493 p->drawText(pt, components.at(i).string); 494 } 495 } 496 } 497 if (from > 0 || to < run.length()) 498 p->restore(); 499 } 500 501 int Font::width(const TextRun& run) const 502 { 503 Vector<TextRunComponent, 1024> components; 504 int w = generateComponents(&components, *this, run); 505 506 // qDebug() << " width=" << w; 507 return w; 508 } 509 510 float Font::floatWidth(const TextRun& run) const 511 { 512 return width(run); 513 } 514 515 float Font::floatWidth(const TextRun& run, int /*extraCharsAvailable*/, int& charsConsumed, String& glyphName) const 516 { 517 charsConsumed = run.length(); 518 glyphName = ""; 519 return width(run); 520 } 521 522 int Font::offsetForPosition(const TextRun& run, int position, bool includePartialGlyphs) const 523 { 524 Vector<TextRunComponent, 1024> components; 525 int w = generateComponents(&components, *this, run); 526 527 int offset = 0; 528 if (run.rtl()) { 529 for (int i = 0; i < components.size(); ++i) { 530 int xe = w - components.at(i).offset; 531 int xs = xe - components.at(i).width; 532 if (position >= xs) { 533 QTextLayout layout(components.at(i).string, *components.at(i).font); 534 layout.beginLayout(); 535 QTextLine l = layout.createLine(); 536 if (!l.isValid()) 537 return offset; 538 539 l.setLineWidth(INT_MAX/256); 540 layout.endLayout(); 541 542 if (position - xs >= l.width()) 543 return offset; 544 int cursor = l.xToCursor(position - xs); 545 if (cursor > 1) 546 --cursor; 547 return offset + cursor; 548 } else { 549 offset += components.at(i).string.length() - 1; 550 } 551 } 552 } else { 553 for (int i = 0; i < components.size(); ++i) { 554 int xs = components.at(i).offset; 555 int xe = xs + components.at(i).width; 556 if (position <= xe) { 557 QTextLayout layout(components.at(i).string, *components.at(i).font); 558 layout.beginLayout(); 559 QTextLine l = layout.createLine(); 560 if (!l.isValid()) 561 return offset; 562 563 l.setLineWidth(INT_MAX/256); 564 layout.endLayout(); 565 566 if (position - xs >= l.width()) 567 return offset + components.at(i).string.length() - 1; 568 int cursor = l.xToCursor(position - xs); 569 if (cursor > 1) 570 --cursor; 571 return offset + cursor; 572 } else { 573 offset += components.at(i).string.length() - 1; 574 } 575 } 576 } 577 return run.length(); 578 } 579 580 static float cursorToX(const Vector<TextRunComponent, 1024>& components, int width, bool rtl, int cursor) 581 { 582 int start = 0; 583 for (int i = 0; i < components.size(); ++i) { 584 if (start + components.at(i).string.length() - 1 < cursor) { 585 start += components.at(i).string.length() - 1; 586 continue; 587 } 588 int xs = components.at(i).offset; 589 if (rtl) 590 xs = width - xs - components.at(i).width; 591 QTextLayout layout(components.at(i).string, *components.at(i).font); 592 layout.beginLayout(); 593 QTextLine l = layout.createLine(); 594 if (!l.isValid()) 595 return 0; 596 597 l.setLineWidth(INT_MAX/256); 598 layout.endLayout(); 599 600 return xs + l.cursorToX(cursor - start + 1); 601 } 602 return width; 603 } 604 605 FloatRect Font::selectionRectForText(const TextRun& run, const IntPoint& pt, 606 int h, int from, int to) const 607 { 608 Vector<TextRunComponent, 1024> components; 609 int w = generateComponents(&components, *this, run); 610 611 if (from == 0 && to == run.length()) 612 return FloatRect(pt.x(), pt.y(), w, h); 613 614 float x1 = cursorToX(components, w, run.rtl(), from); 615 float x2 = cursorToX(components, w, run.rtl(), to); 616 if (x2 < x1) 617 qSwap(x1, x2); 618 619 return FloatRect(pt.x() + x1, pt.y(), x2 - x1, h); 620 } 621 #endif 622 623 624 Font::~Font() 625 { 626 } 627 628 Font::Font(const Font& other) 629 : m_fontDescription(other.m_fontDescription) 630 , m_letterSpacing(other.m_letterSpacing) 631 , m_wordSpacing(other.m_wordSpacing) 632 , m_font(other.m_font) 633 , m_scFont(other.m_scFont) 634 , m_spaceWidth(other.m_spaceWidth) 635 { 636 } 637 638 Font& Font::operator=(const Font& other) 639 { 640 m_fontDescription = other.m_fontDescription; 641 m_letterSpacing = other.m_letterSpacing; 642 m_wordSpacing = other.m_wordSpacing; 643 m_font = other.m_font; 644 m_scFont = other.m_scFont; 645 m_spaceWidth = other.m_spaceWidth; 646 return *this; 647 } 648 649 bool Font::operator==(const Font& other) const 650 { 651 return m_fontDescription == other.m_fontDescription 652 && m_letterSpacing == other.m_letterSpacing 653 && m_wordSpacing == other.m_wordSpacing 654 && m_font == other.m_font 655 && m_scFont == other.m_scFont 656 && m_spaceWidth == other.m_spaceWidth; 657 } 658 659 void Font::update(PassRefPtr<FontSelector>) const 660 { 661 // don't think we need this 662 } 663 664 665 bool Font::isFixedPitch() const 666 { 667 return QFontInfo(m_font).fixedPitch(); 668 } 669 670 // Metrics that we query the FontFallbackList for. 671 int Font::ascent() const 672 { 673 return QFontMetrics(m_font).ascent(); 674 } 675 676 int Font::descent() const 677 { 678 return QFontMetrics(m_font).descent(); 679 } 680 681 int Font::lineSpacing() const 682 { 683 return QFontMetrics(m_font).lineSpacing(); 684 } 685 686 int Font::lineGap() const 687 { 688 return QFontMetrics(m_font).leading(); 689 } 690 691 float Font::xHeight() const 692 { 693 return QFontMetrics(m_font).xHeight(); 694 } 695 696 unsigned Font::unitsPerEm() const 697 { 698 return 1; // FIXME! 699 } 700 701 int Font::spaceWidth() const 702 { 703 return m_spaceWidth; 182 return primaryFont()->getQtFont(); 704 183 } 705 184 706 185 } 186 187 #endif 188 -
trunk/WebCore/platform/graphics/qt/FontQt43.cpp
r39205 r39207 1 1 /* 2 2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 Copyright (C) 2008 Holger Hans Peter Freyther 3 4 4 5 This library is free software; you can redistribute it and/or … … 21 22 #include "Font.h" 22 23 #include "FontDescription.h" 24 #include "FontFallbackList.h" 23 25 #include "FontSelector.h" 24 26 … … 32 34 33 35 #include <limits.h> 36 37 #if QT_VERSION < 0x040400 38 34 39 namespace WebCore { 35 36 #if QT_VERSION >= 0x04040037 38 Font::Font()39 : m_letterSpacing(0)40 , m_wordSpacing(0)41 , m_font()42 , m_scFont()43 {44 QFontMetrics metrics(m_font);45 m_spaceWidth = metrics.width(QLatin1Char(' '));46 }47 48 Font::Font(const FontDescription& description, short letterSpacing, short wordSpacing)49 : m_fontDescription(description)50 , m_letterSpacing(letterSpacing)51 , m_wordSpacing(wordSpacing)52 {53 const FontFamily* family = &description.family();54 QString familyName;55 while (family) {56 familyName += family->family();57 family = family->next();58 if (family)59 familyName += QLatin1Char(',');60 }61 62 m_font.setFamily(familyName);63 m_font.setPixelSize(qRound(description.computedSize()));64 m_font.setItalic(description.italic());65 // FIXME: Map all FontWeight values to QFont weights.66 if (description.weight() >= FontWeight600)67 m_font.setWeight(QFont::Bold);68 else69 m_font.setWeight(QFont::Normal);70 71 bool smallCaps = description.smallCaps();72 m_font.setCapitalization(smallCaps ? QFont::SmallCaps : QFont::MixedCase);73 74 QFontMetrics metrics = QFontMetrics(m_font);75 m_spaceWidth = metrics.width(QLatin1Char(' '));76 77 if (wordSpacing)78 m_font.setWordSpacing(wordSpacing);79 if (letterSpacing)80 m_font.setLetterSpacing(QFont::AbsoluteSpacing, letterSpacing);81 }82 83 void Font::setWordSpacing(short s)84 {85 m_font.setWordSpacing(s);86 m_wordSpacing = s;87 }88 void Font::setLetterSpacing(short s)89 {90 m_font.setLetterSpacing(QFont::AbsoluteSpacing, s);91 m_letterSpacing = s;92 }93 94 95 static QString qstring(const TextRun& run)96 {97 QString string((QChar *)run.characters(), run.length());98 QChar *uc = string.data();99 for (int i = 0; i < string.length(); ++i) {100 if (Font::treatAsSpace(uc[i].unicode()))101 uc[i] = 0x20;102 else if (Font::treatAsZeroWidthSpace(uc[i].unicode()))103 uc[i] = 0x200c;104 }105 return string;106 }107 108 109 static QTextLine setupLayout(QTextLayout* layout, const TextRun& style)110 {111 int flags = style.rtl() ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight;112 if (style.padding())113 flags |= Qt::TextJustificationForced;114 layout->setFlags(flags);115 layout->beginLayout();116 QTextLine line = layout->createLine();117 line.setLineWidth(INT_MAX/256);118 if (style.padding())119 line.setLineWidth(line.naturalTextWidth() + style.padding());120 layout->endLayout();121 return line;122 }123 124 void Font::drawText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const125 {126 if (to < 0)127 to = run.length();128 QPainter *p = ctx->platformContext();129 Color color = ctx->fillColor();130 p->setPen(QColor(color));131 132 QString string = qstring(run);133 134 // text shadow135 IntSize shadowSize;136 int shadowBlur;137 Color shadowColor;138 bool hasShadow = ctx->textDrawingMode() == cTextFill && ctx->getShadow(shadowSize, shadowBlur, shadowColor);139 140 if (from > 0 || to < run.length()) {141 QTextLayout layout(string, m_font);142 QTextLine line = setupLayout(&layout, run);143 float x1 = line.cursorToX(from);144 float x2 = line.cursorToX(to);145 if (x2 < x1)146 qSwap(x1, x2);147 148 QFontMetrics fm(m_font);149 int ascent = fm.ascent();150 QRectF clip(point.x() + x1, point.y() - ascent, x2 - x1, fm.height());151 152 if (hasShadow) {153 // TODO: when blur support is added, the clip will need to account154 // for the blur radius155 qreal dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;156 if (shadowSize.width() > 0)157 dx2 = shadowSize.width();158 else159 dx1 = -shadowSize.width();160 if (shadowSize.height() > 0)161 dy2 = shadowSize.height();162 else163 dy1 = -shadowSize.height();164 // expand the clip rect to include the text shadow as well165 clip.adjust(dx1, dx2, dy1, dy2);166 }167 p->save();168 p->setClipRect(clip.toRect());169 QPointF pt(point.x(), point.y() - ascent);170 if (hasShadow) {171 p->save();172 p->setPen(QColor(shadowColor));173 p->translate(shadowSize.width(), shadowSize.height());174 line.draw(p, pt);175 p->restore();176 }177 line.draw(p, pt);178 p->restore();179 return;180 }181 182 p->setFont(m_font);183 184 QPointF pt(point.x(), point.y());185 int flags = run.rtl() ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight;186 if (hasShadow) {187 // TODO: text shadow blur support188 p->save();189 p->setPen(QColor(shadowColor));190 p->translate(shadowSize.width(), shadowSize.height());191 p->drawText(pt, string, flags, run.padding());192 p->restore();193 }194 p->drawText(pt, string, flags, run.padding());195 }196 197 int Font::width(const TextRun& run) const198 {199 if (!run.length())200 return 0;201 QString string = qstring(run);202 QTextLayout layout(string, m_font);203 QTextLine line = setupLayout(&layout, run);204 int w = int(line.naturalTextWidth());205 // WebKit expects us to ignore word spacing on the first character (as opposed to what Qt does)206 if (treatAsSpace(run[0]))207 w -= m_wordSpacing;208 209 return w + run.padding();210 }211 212 float Font::floatWidth(const TextRun& run) const213 {214 return width(run);215 }216 217 float Font::floatWidth(const TextRun& run, int /*extraCharsAvailable*/, int& charsConsumed, String& glyphName) const218 {219 charsConsumed = run.length();220 glyphName = "";221 return width(run);222 }223 224 int Font::offsetForPosition(const TextRun& run, int position, bool /*includePartialGlyphs*/) const225 {226 QString string = qstring(run);227 QTextLayout layout(string, m_font);228 QTextLine line = setupLayout(&layout, run);229 return line.xToCursor(position);230 }231 232 FloatRect Font::selectionRectForText(const TextRun& run, const IntPoint& pt, int h, int from, int to) const233 {234 QString string = qstring(run);235 QTextLayout layout(string, m_font);236 QTextLine line = setupLayout(&layout, run);237 238 float x1 = line.cursorToX(from);239 float x2 = line.cursorToX(to);240 if (x2 < x1)241 qSwap(x1, x2);242 243 return FloatRect(pt.x() + x1, pt.y(), x2 - x1, h);244 }245 246 #else247 248 40 249 41 struct TextRunComponent { … … 283 75 } 284 76 285 286 Font::Font()287 : m_letterSpacing(0)288 , m_wordSpacing(0)289 , m_font()290 , m_scFont()291 {292 QFontMetrics metrics(m_font);293 m_spaceWidth = metrics.width(QLatin1Char(' '));294 qreal pointsize = m_font.pointSizeF();295 if (pointsize > 0)296 m_scFont.setPointSizeF(pointsize*0.7);297 else298 m_scFont.setPixelSize(qRound(m_font.pixelSize()*.7));299 }300 301 Font::Font(const FontDescription& description, short letterSpacing, short wordSpacing)302 : m_fontDescription(description)303 , m_letterSpacing(letterSpacing)304 , m_wordSpacing(wordSpacing)305 {306 const FontFamily* family = &description.family();307 QString familyName;308 while (family) {309 familyName += family->family();310 family = family->next();311 if (family)312 familyName += QLatin1Char(',');313 }314 315 m_font.setFamily(familyName);316 m_font.setPixelSize(qRound(description.computedSize()));317 m_font.setItalic(description.italic());318 // FIXME: Map all FontWeight values to QFont weights.319 if (description.weight() >= FontWeight600)320 m_font.setWeight(QFont::Bold);321 else322 m_font.setWeight(QFont::Normal);323 324 QFontMetrics metrics = QFontMetrics(m_font);325 m_spaceWidth = metrics.width(QLatin1Char(' '));326 m_scFont = m_font;327 m_scFont.setPixelSize(qRound(description.computedSize()*.7));328 }329 330 void Font::setWordSpacing(short s)331 {332 m_wordSpacing = s;333 }334 void Font::setLetterSpacing(short s)335 {336 m_letterSpacing = s;337 }338 77 339 78 static int generateComponents(Vector<TextRunComponent, 1024>* components, const Font &font, const TextRun &run) … … 458 197 } 459 198 460 void Font::draw Text(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const199 void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const 461 200 { 462 201 if (to < 0) 463 202 to = run.length(); 203 464 204 QPainter *p = ctx->platformContext(); 465 205 Color color = ctx->fillColor(); … … 470 210 471 211 if (from > 0 || to < run.length()) { 472 FloatRect clip = selectionRectFor Text(run,212 FloatRect clip = selectionRectForComplexText(run, 473 213 IntPoint(qRound(point.x()), qRound(point.y())), 474 QFontMetrics( m_font).height(), from, to);214 QFontMetrics(font()).height(), from, to); 475 215 QRectF rect(clip.x(), clip.y() - ascent(), clip.width(), clip.height()); 476 216 p->save(); … … 499 239 } 500 240 501 int Font::width(const TextRun& run) const241 float Font::floatWidthForComplexText(const TextRun& run) const 502 242 { 503 243 Vector<TextRunComponent, 1024> components; 504 244 int w = generateComponents(&components, *this, run); 505 245 506 // qDebug() << " width=" << w;507 246 return w; 508 247 } 509 248 510 float Font::floatWidth(const TextRun& run) const 511 { 512 return width(run); 513 } 514 515 float Font::floatWidth(const TextRun& run, int /*extraCharsAvailable*/, int& charsConsumed, String& glyphName) const 516 { 517 charsConsumed = run.length(); 518 glyphName = ""; 519 return width(run); 520 } 521 522 int Font::offsetForPosition(const TextRun& run, int position, bool includePartialGlyphs) const 249 int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool includePartialGlyphs) const 523 250 { 524 251 Vector<TextRunComponent, 1024> components; … … 603 330 } 604 331 605 FloatRect Font::selectionRectFor Text(const TextRun& run, const IntPoint& pt,332 FloatRect Font::selectionRectForComplexText(const TextRun& run, const IntPoint& pt, 606 333 int h, int from, int to) const 607 334 { … … 619 346 return FloatRect(pt.x() + x1, pt.y(), x2 - x1, h); 620 347 } 348 349 int Font::lineGap() const 350 { 351 return QFontMetrics(m_font).leading(); 352 } 353 354 } 355 621 356 #endif 622 623 624 Font::~Font()625 {626 }627 628 Font::Font(const Font& other)629 : m_fontDescription(other.m_fontDescription)630 , m_letterSpacing(other.m_letterSpacing)631 , m_wordSpacing(other.m_wordSpacing)632 , m_font(other.m_font)633 , m_scFont(other.m_scFont)634 , m_spaceWidth(other.m_spaceWidth)635 {636 }637 638 Font& Font::operator=(const Font& other)639 {640 m_fontDescription = other.m_fontDescription;641 m_letterSpacing = other.m_letterSpacing;642 m_wordSpacing = other.m_wordSpacing;643 m_font = other.m_font;644 m_scFont = other.m_scFont;645 m_spaceWidth = other.m_spaceWidth;646 return *this;647 }648 649 bool Font::operator==(const Font& other) const650 {651 return m_fontDescription == other.m_fontDescription652 && m_letterSpacing == other.m_letterSpacing653 && m_wordSpacing == other.m_wordSpacing654 && m_font == other.m_font655 && m_scFont == other.m_scFont656 && m_spaceWidth == other.m_spaceWidth;657 }658 659 void Font::update(PassRefPtr<FontSelector>) const660 {661 // don't think we need this662 }663 664 665 bool Font::isFixedPitch() const666 {667 return QFontInfo(m_font).fixedPitch();668 }669 670 // Metrics that we query the FontFallbackList for.671 int Font::ascent() const672 {673 return QFontMetrics(m_font).ascent();674 }675 676 int Font::descent() const677 {678 return QFontMetrics(m_font).descent();679 }680 681 int Font::lineSpacing() const682 {683 return QFontMetrics(m_font).lineSpacing();684 }685 686 int Font::lineGap() const687 {688 return QFontMetrics(m_font).leading();689 }690 691 float Font::xHeight() const692 {693 return QFontMetrics(m_font).xHeight();694 }695 696 unsigned Font::unitsPerEm() const697 {698 return 1; // FIXME!699 }700 701 int Font::spaceWidth() const702 {703 return m_spaceWidth;704 }705 706 } -
trunk/WebCore/platform/graphics/qt/GlyphPageTreeNodeQt.cpp
r37061 r39207 1 1 /* 2 2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 Copyright (C) 2008 Holger Hans Peter Freyther 3 4 4 5 This library is free software; you can redistribute it and/or … … 25 26 namespace WebCore { 26 27 27 void GlyphPageTreeNode::pruneTreeCustomFontData(const FontData* fontData) 28 void GlyphPageTreeNode::pruneTreeCustomFontData(const FontData*) 29 { 30 } 31 32 void GlyphPageTreeNode::pruneTreeFontData(const WebCore::SimpleFontData*) 28 33 { 29 34 } -
trunk/WebCore/platform/graphics/qt/SimpleFontDataQt.cpp
r37061 r39207 1 1 /* 2 2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 Copyright (C) 2008 Holger Hans Peter Freyther 3 4 4 5 This library is free software; you can redistribute it and/or … … 20 21 pages from the web. It has a memory cache for these objects. 21 22 */ 23 22 24 #include "config.h" 23 25 #include "SimpleFontData.h" 24 26 25 #include "SVGFontData.h"27 #include <QFontMetrics> 26 28 27 29 namespace WebCore { 28 30 29 SimpleFontData::SimpleFontData(const FontPlatformData& font, bool customFont, bool loading, SVGFontData*) 30 : m_font(font) 31 , m_isCustomFont(customFont) 32 , m_isLoading(loading) 31 void SimpleFontData::determinePitch() 33 32 { 33 m_treatAsFixedPitch = m_font.font().fixedPitch(); 34 34 } 35 35 36 SimpleFontData::~SimpleFontData() 37 { 38 } 39 40 bool SimpleFontData::containsCharacters(const UChar* characters, int length) const 36 bool SimpleFontData::containsCharacters(unsigned short const*, int) const 41 37 { 42 38 return true; 43 39 } 44 40 45 const SimpleFontData* SimpleFontData::fontDataForCharacter(UChar32) const 41 void SimpleFontData::platformInit() 46 42 { 47 return this; 43 QFontMetrics fm(m_font.font()); 44 45 m_ascent = fm.ascent(); 46 m_descent = fm.descent(); 47 m_lineSpacing = fm.lineSpacing(); 48 m_xHeight = fm.xHeight(); 49 m_spaceWidth = fm.width(' '); 50 m_lineGap = fm.leading(); 48 51 } 49 52 50 bool SimpleFontData::isSegmented() const 53 void SimpleFontData::platformGlyphInit() 51 54 { 52 return false; 55 m_spaceGlyph = 0; 56 m_adjustedSpaceWidth = m_spaceWidth; 57 determinePitch(); 58 m_missingGlyphData.fontData = this; 59 m_missingGlyphData.glyph = 0; 60 } 61 62 void SimpleFontData::platformDestroy() 63 { 53 64 } 54 65 -
trunk/WebCore/platform/qt/RenderThemeQt.cpp
r39200 r39207 7 7 * 2006 Dirk Mueller <mueller@kde.org> 8 8 * 2006 Nikolas Zimmermann <zimmermann@kde.org> 9 * Copyright (C) 2008 Holger Hans Peter Freyther 9 10 * 10 11 * All rights reserved. … … 46 47 47 48 #include "Color.h" 49 #include "CSSStyleSelector.h" 48 50 #include "CSSStyleSheet.h" 51 #include "FontSelector.h" 49 52 #include "Document.h" 50 53 #include "Page.h" … … 399 402 fontDescription.setFamily(fontFamily); 400 403 style->setFontDescription(fontDescription); 404 style->font().update(selector->fontSelector()); 401 405 style->setLineHeight(RenderStyle::initialLineHeight()); 402 406
Note:
See TracChangeset
for help on using the changeset viewer.