Changeset 61253 in webkit
- Timestamp:
- Jun 16, 2010 6:51:21 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r61252 r61253 1 2010-06-16 Nikolas Zimmermann <nzimmermann@rim.com> 2 3 Reviewed by Dirk Schulze. 4 5 Provide floating-point support for text selection framework 6 https://bugs.webkit.org/show_bug.cgi?id=40665 7 8 This is the first chunk of the SVG Text rewrite patches. 9 offsetForPosition() / selectionRectForText() should accept float/FloatPoint arguments instead 10 of int/IntPoint. offsetForPosition() already worked with floats internally in Qt and Mac. 11 selectionRectForText() was already returning a FloatRect, but the passed in origin was an integer. 12 Fixing these problems in order to support sub-pixel positioning in the upcoming SVG Text rewrite patch. 13 14 Add a glyphScale parameter to TextRun, that will be used to support text selection 15 in lengthAdjust/textLength scenarios in SVG text, soon. 16 17 Doesn't affect any testcases so far. HTML is not affected in any way, 18 as it only ever passes integers to these functions. 19 20 * platform/graphics/Font.cpp: 21 (WebCore::Font::selectionRectForText): 22 (WebCore::Font::offsetForPosition): 23 * platform/graphics/Font.h: 24 * platform/graphics/FontFastPath.cpp: 25 (WebCore::Font::selectionRectForSimpleText): 26 (WebCore::Font::offsetForPositionForSimpleText): 27 * platform/graphics/TextRun.h: 28 (WebCore::TextRun::TextRun): 29 (WebCore::TextRun::glyphScale): 30 (WebCore::TextRun::setGlyphScale): 31 (WebCore::TextRun::applyGlyphScaling): 32 * platform/graphics/WidthIterator.cpp: 33 (WebCore::WidthIterator::advance): 34 * platform/graphics/chromium/FontChromiumWin.cpp: 35 (WebCore::Font::selectionRectForComplexText): 36 (WebCore::Font::offsetForPositionForComplexText): 37 * platform/graphics/chromium/FontLinux.cpp: 38 (WebCore::Font::offsetForPositionForComplexText): 39 (WebCore::Font::selectionRectForComplexText): 40 * platform/graphics/efl/FontEfl.cpp: 41 (WebCore::Font::offsetForPositionForComplexText): 42 (WebCore::Font::selectionRectForComplexText): 43 * platform/graphics/gtk/FontGtk.cpp: 44 (WebCore::Font::offsetForPositionForComplexText): 45 (WebCore::Font::selectionRectForComplexText): 46 * platform/graphics/haiku/FontHaiku.cpp: 47 (WebCore::Font::selectionRectForComplexText): 48 (WebCore::Font::offsetForPositionForComplexText): 49 * platform/graphics/mac/ComplexTextController.cpp: 50 (WebCore::ComplexTextController::offsetForPosition): 51 * platform/graphics/mac/ComplexTextController.h: 52 * platform/graphics/mac/FontComplexTextMac.cpp: 53 (WebCore::Font::selectionRectForComplexText): 54 (WebCore::Font::offsetForPositionForComplexText): 55 * platform/graphics/qt/FontQt.cpp: 56 (WebCore::Font::offsetForPositionForSimpleText): 57 (WebCore::Font::offsetForPositionForComplexText): 58 (WebCore::Font::selectionRectForSimpleText): 59 (WebCore::Font::selectionRectForComplexText): 60 * platform/graphics/win/FontWin.cpp: 61 (WebCore::Font::selectionRectForComplexText): 62 (WebCore::Font::offsetForPositionForComplexText): 63 * platform/graphics/wince/FontWince.cpp: 64 (WebCore::Font::offsetForPositionForComplexText): 65 (WebCore::Font::selectionRectForComplexText): 66 * platform/graphics/wx/FontWx.cpp: 67 (WebCore::Font::selectionRectForComplexText): 68 (WebCore::Font::offsetForPositionForComplexText): 69 * svg/SVGFont.cpp: 70 (WebCore::Font::selectionRectForTextUsingSVGFont): 71 (WebCore::Font::offsetForPositionForTextUsingSVGFont): 72 1 73 2010-06-16 Anton Muhin <antonm@chromium.org> 2 74 -
trunk/WebCore/platform/graphics/Font.cpp
r61002 r61253 192 192 } 193 193 194 FloatRect Font::selectionRectForText(const TextRun& run, const IntPoint& point, int h, int from, int to) const194 FloatRect Font::selectionRectForText(const TextRun& run, const FloatPoint& point, int h, int from, int to) const 195 195 { 196 196 #if ENABLE(SVG_FONTS) … … 207 207 } 208 208 209 int Font::offsetForPosition(const TextRun& run, int x, bool includePartialGlyphs) const209 int Font::offsetForPosition(const TextRun& run, float x, bool includePartialGlyphs) const 210 210 { 211 211 #if ENABLE(SVG_FONTS) -
trunk/WebCore/platform/graphics/Font.h
r61002 r61253 51 51 class GlyphPageTreeNode; 52 52 class GraphicsContext; 53 class IntPoint;54 53 class SVGFontElement; 55 54 … … 100 99 float floatWidth(const TextRun& run, int extraCharsAvailable, int& charsConsumed, String& glyphName) const; 101 100 102 int offsetForPosition(const TextRun&, int position, bool includePartialGlyphs) const;103 FloatRect selectionRectForText(const TextRun&, const IntPoint&, int h, int from = 0, int to = -1) const;101 int offsetForPosition(const TextRun&, float position, bool includePartialGlyphs) const; 102 FloatRect selectionRectForText(const TextRun&, const FloatPoint&, int h, int from = 0, int to = -1) const; 104 103 105 104 bool isSmallCaps() const { return m_fontDescription.smallCaps(); } … … 159 158 float floatWidthUsingSVGFont(const TextRun&) const; 160 159 float floatWidthUsingSVGFont(const TextRun&, int extraCharsAvailable, int& charsConsumed, String& glyphName) const; 161 FloatRect selectionRectForTextUsingSVGFont(const TextRun&, const IntPoint&, int h, int from, int to) const;162 int offsetForPositionForTextUsingSVGFont(const TextRun&, int position, bool includePartialGlyphs) const;160 FloatRect selectionRectForTextUsingSVGFont(const TextRun&, const FloatPoint&, int h, int from, int to) const; 161 int offsetForPositionForTextUsingSVGFont(const TextRun&, float position, bool includePartialGlyphs) const; 163 162 #endif 164 163 … … 167 166 void drawGlyphBuffer(GraphicsContext*, const GlyphBuffer&, const TextRun&, const FloatPoint&) const; 168 167 float floatWidthForSimpleText(const TextRun&, GlyphBuffer*, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* = 0) const; 169 int offsetForPositionForSimpleText(const TextRun&, int position, bool includePartialGlyphs) const;170 FloatRect selectionRectForSimpleText(const TextRun&, const IntPoint&, int h, int from, int to) const;168 int offsetForPositionForSimpleText(const TextRun&, float position, bool includePartialGlyphs) const; 169 FloatRect selectionRectForSimpleText(const TextRun&, const FloatPoint&, int h, int from, int to) const; 171 170 172 171 static bool canReturnFallbackFontsForComplexText(); … … 175 174 void drawComplexText(GraphicsContext*, const TextRun&, const FloatPoint&, int from, int to) const; 176 175 float floatWidthForComplexText(const TextRun&, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* = 0) const; 177 int offsetForPositionForComplexText(const TextRun&, int position, bool includePartialGlyphs) const;178 FloatRect selectionRectForComplexText(const TextRun&, const IntPoint&, int h, int from, int to) const;176 int offsetForPositionForComplexText(const TextRun&, float position, bool includePartialGlyphs) const; 177 FloatRect selectionRectForComplexText(const TextRun&, const FloatPoint&, int h, int from, int to) const; 179 178 180 179 friend struct WidthIterator; -
trunk/WebCore/platform/graphics/FontFastPath.cpp
r61001 r61253 30 30 #include "GlyphBuffer.h" 31 31 #include "GlyphPageTreeNode.h" 32 #include "IntPoint.h"33 32 #include "SimpleFontData.h" 34 33 #include "WidthIterator.h" … … 258 257 } 259 258 260 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const IntPoint& point, int h, int from, int to) const259 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to) const 261 260 { 262 261 WidthIterator it(this, run); … … 266 265 float afterWidth = it.m_runWidthSoFar; 267 266 268 // Using roundf() rather than ceilf() for the right edge as a compromise to ensure correct caret positioning 267 // Using roundf() rather than ceilf() for the right edge as a compromise to ensure correct caret positioning. 269 268 if (run.rtl()) { 270 269 it.advance(run.length()); 271 270 float totalWidth = it.m_runWidthSoFar; 272 271 return FloatRect(point.x() + floorf(totalWidth - afterWidth), point.y(), roundf(totalWidth - beforeWidth) - floorf(totalWidth - afterWidth), h); 273 } else {274 return FloatRect(point.x() + floorf(beforeWidth), point.y(), roundf(afterWidth) - floorf(beforeWidth), h); 275 }276 } 277 278 int Font::offsetForPositionForSimpleText(const TextRun& run, int x, bool includePartialGlyphs) const279 { 280 float delta = (float)x;272 } 273 274 return FloatRect(point.x() + floorf(beforeWidth), point.y(), roundf(afterWidth) - floorf(beforeWidth), h); 275 } 276 277 int Font::offsetForPositionForSimpleText(const TextRun& run, float x, bool includePartialGlyphs) const 278 { 279 float delta = x; 281 280 282 281 WidthIterator it(this, run); -
trunk/WebCore/platform/graphics/TextRun.h
r58212 r61253 40 40 , m_xpos(xpos) 41 41 , m_padding(padding) 42 , m_glyphScale(1.0f) 42 43 , m_allowTabs(allowTabs) 43 44 , m_rtl(rtl) … … 59 60 , m_xpos(xpos) 60 61 , m_padding(padding) 62 , m_glyphScale(1.0f) 61 63 , m_allowTabs(allowTabs) 62 64 , m_rtl(rtl) … … 80 82 void setText(const UChar* c, int len) { m_characters = c; m_len = len; } 81 83 84 float glyphScale() const { return m_glyphScale; } 85 void setGlyphScale(float scale) { m_glyphScale = scale; } 86 82 87 bool allowTabs() const { return m_allowTabs; } 83 88 int xPos() const { return m_xpos; } … … 89 94 bool applyWordRounding() const { return m_applyWordRounding; } 90 95 bool spacingDisabled() const { return m_disableSpacing; } 96 bool applyGlyphScaling() const { return m_glyphScale != 1.0f; } 91 97 92 98 void disableSpacing() { m_disableSpacing = true; } … … 109 115 int m_xpos; 110 116 int m_padding; 117 float m_glyphScale; 111 118 bool m_allowTabs; 112 119 bool m_rtl; -
trunk/WebCore/platform/graphics/WidthIterator.cpp
r61128 r61253 135 135 } else { 136 136 width = fontData->widthForGlyph(glyph); 137 138 // SVG uses glyphScale(), when textLength is used to stretch/squeeze text. 139 if (m_run.applyGlyphScaling()) 140 width *= m_run.glyphScale(); 141 137 142 // We special case spaces in two ways when applying word rounding. 138 143 // First, we round spaces to an adjusted width in all fonts. -
trunk/WebCore/platform/graphics/chromium/FontChromiumWin.cpp
r61129 r61253 435 435 436 436 FloatRect Font::selectionRectForComplexText(const TextRun& run, 437 const IntPoint& point,437 const FloatPoint& point, 438 438 int h, 439 439 int from, … … 446 446 // If the text is RTL, left will actually be after right. 447 447 if (left < right) 448 return FloatRect(left, static_cast<float>(point.y()),448 return FloatRect(left, point.y(), 449 449 right - left, static_cast<float>(h)); 450 450 451 return FloatRect(right, static_cast<float>(point.y()),451 return FloatRect(right, point.y(), 452 452 left - right, static_cast<float>(h)); 453 453 } … … 510 510 } 511 511 512 int Font::offsetForPositionForComplexText(const TextRun& run, int x,512 int Font::offsetForPositionForComplexText(const TextRun& run, float xFloat, 513 513 bool includePartialGlyphs) const 514 514 { 515 // FIXME: This truncation is not a problem for HTML, but only affects SVG, which passes floating-point numbers 516 // to Font::offsetForPosition(). Bug http://webkit.org/b/40673 tracks fixing this problem. 517 int x = static_cast<int>(xFloat); 518 515 519 // Mac code ignores includePartialGlyphs, and they don't know what it's 516 520 // supposed to do, so we just ignore it as well. -
trunk/WebCore/platform/graphics/chromium/FontLinux.cpp
r58916 r61253 565 565 566 566 // Return the code point index for the given |x| offset into the text run. 567 int Font::offsetForPositionForComplexText(const TextRun& run, int x,567 int Font::offsetForPositionForComplexText(const TextRun& run, float xFloat, 568 568 bool includePartialGlyphs) const 569 569 { 570 // FIXME: This truncation is not a problem for HTML, but only affects SVG, which passes floating-point numbers 571 // to Font::offsetForPosition(). Bug http://webkit.org/b/40673 tracks fixing this problem. 572 int x = static_cast<int>(xFloat); 573 570 574 // (Mac code ignores includePartialGlyphs, and they don't know what it's 571 575 // supposed to do, so we just ignore it as well.) … … 642 646 // Return the rectangle for selecting the given range of code-points in the TextRun. 643 647 FloatRect Font::selectionRectForComplexText(const TextRun& run, 644 const IntPoint& point, int height,648 const FloatPoint& point, int height, 645 649 int from, int to) const 646 650 { -
trunk/WebCore/platform/graphics/efl/FontEfl.cpp
r57215 r61253 52 52 } 53 53 54 int Font::offsetForPositionForComplexText(const TextRun&, int, bool) const54 int Font::offsetForPositionForComplexText(const TextRun&, float, bool) const 55 55 { 56 56 notImplemented(); … … 58 58 } 59 59 60 FloatRect Font::selectionRectForComplexText(const TextRun&, const IntPoint&, int, int, int) const60 FloatRect Font::selectionRectForComplexText(const TextRun&, const FloatPoint&, int, int, int) const 61 61 { 62 62 notImplemented(); -
trunk/WebCore/platform/graphics/gtk/FontGtk.cpp
r61129 r61253 309 309 } 310 310 311 int Font::offsetForPositionForComplexText(const TextRun& run, int x, bool includePartialGlyphs) const 312 { 311 int Font::offsetForPositionForComplexText(const TextRun& run, float xFloat, bool includePartialGlyphs) const 312 { 313 // FIXME: This truncation is not a problem for HTML, but only affects SVG, which passes floating-point numbers 314 // to Font::offsetForPosition(). Bug http://webkit.org/b/40673 tracks fixing this problem. 315 int x = static_cast<int>(xFloat); 316 313 317 PangoLayout* layout = getDefaultPangoLayout(run); 314 318 setPangoAttributes(this, run, layout); … … 329 333 } 330 334 331 FloatRect Font::selectionRectForComplexText(const TextRun& run, const IntPoint& point, int h, int from, int to) const335 FloatRect Font::selectionRectForComplexText(const TextRun& run, const FloatPoint& point, int h, int from, int to) const 332 336 { 333 337 PangoLayout* layout = getDefaultPangoLayout(run); -
trunk/WebCore/platform/graphics/haiku/FontHaiku.cpp
r57215 r61253 101 101 } 102 102 103 FloatRect Font::selectionRectForComplexText(const TextRun&, const IntPoint&, int, int, int) const103 FloatRect Font::selectionRectForComplexText(const TextRun&, const FloatPoint&, int, int, int) const 104 104 { 105 105 notImplemented(); … … 107 107 } 108 108 109 int Font::offsetForPositionForComplexText(const TextRun&, int, bool) const109 int Font::offsetForPositionForComplexText(const TextRun&, float, bool) const 110 110 { 111 111 notImplemented(); -
trunk/WebCore/platform/graphics/mac/ComplexTextController.cpp
r61128 r61253 97 97 } 98 98 99 int ComplexTextController::offsetForPosition( int h, bool includePartialGlyphs)99 int ComplexTextController::offsetForPosition(float h, bool includePartialGlyphs) 100 100 { 101 101 if (h >= m_totalWidth) -
trunk/WebCore/platform/graphics/mac/ComplexTextController.h
r58707 r61253 54 54 55 55 // Compute the character offset for a given x coordinate. 56 int offsetForPosition( int x, bool includePartialGlyphs);56 int offsetForPosition(float x, bool includePartialGlyphs); 57 57 58 58 // Returns the width of everything we've consumed so far. -
trunk/WebCore/platform/graphics/mac/FontComplexTextMac.cpp
r57215 r61253 38 38 namespace WebCore { 39 39 40 FloatRect Font::selectionRectForComplexText(const TextRun& run, const IntPoint& point, int h,40 FloatRect Font::selectionRectForComplexText(const TextRun& run, const FloatPoint& point, int h, 41 41 int from, int to) const 42 42 { … … 98 98 } 99 99 100 int Font::offsetForPositionForComplexText(const TextRun& run, int x, bool includePartialGlyphs) const100 int Font::offsetForPositionForComplexText(const TextRun& run, float x, bool includePartialGlyphs) const 101 101 { 102 102 ComplexTextController controller(this, run); -
trunk/WebCore/platform/graphics/qt/FontQt.cpp
r61129 r61253 248 248 } 249 249 250 int Font::offsetForPositionForSimpleText(const TextRun& run, int position, bool includePartialGlyphs) const250 int Font::offsetForPositionForSimpleText(const TextRun& run, float position, bool includePartialGlyphs) const 251 251 { 252 252 #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) … … 255 255 256 256 QFontMetrics fm(font()); 257 float delta = (float)position;257 float delta = position; 258 258 int curPos = 0; 259 259 do { … … 276 276 } 277 277 278 int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool) const278 int Font::offsetForPositionForComplexText(const TextRun& run, float position, bool) const 279 279 { 280 280 String sanitized = Font::normalizeSpaces(String(run.characters(), run.length())); … … 286 286 } 287 287 288 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const IntPoint& pt, int h, int from, int to) const288 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& pt, int h, int from, int to) const 289 289 { 290 290 #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) … … 303 303 } 304 304 305 FloatRect Font::selectionRectForComplexText(const TextRun& run, const IntPoint& pt, int h, int from, int to) const305 FloatRect Font::selectionRectForComplexText(const TextRun& run, const FloatPoint& pt, int h, int from, int to) const 306 306 { 307 307 String sanitized = Font::normalizeSpaces(String(run.characters(), run.length())); -
trunk/WebCore/platform/graphics/win/FontWin.cpp
r57215 r61253 44 44 } 45 45 46 FloatRect Font::selectionRectForComplexText(const TextRun& run, const IntPoint& point, int h,46 FloatRect Font::selectionRectForComplexText(const TextRun& run, const FloatPoint& point, int h, 47 47 int from, int to) const 48 48 { … … 105 105 } 106 106 107 int Font::offsetForPositionForComplexText(const TextRun& run, int x, bool includePartialGlyphs) const107 int Font::offsetForPositionForComplexText(const TextRun& run, float xFloat, bool includePartialGlyphs) const 108 108 { 109 // FIXME: This truncation is not a problem for HTML, but only affects SVG, which passes floating-point numbers 110 // to Font::offsetForPosition(). Bug http://webkit.org/b/40673 tracks fixing this problem. 111 int x = static_cast<int>(xFloat); 112 109 113 UniscribeController controller(this, run); 110 114 return controller.offsetForPosition(x, includePartialGlyphs); -
trunk/WebCore/platform/graphics/wince/FontWince.cpp
r57215 r61253 243 243 } 244 244 245 int Font::offsetForPositionForComplexText(const TextRun& run, int position, bool includePartialGlyphs) const 246 { 245 int Font::offsetForPositionForComplexText(const TextRun& run, float xFloat, bool includePartialGlyphs) const 246 { 247 // FIXME: This truncation is not a problem for HTML, but only affects SVG, which passes floating-point numbers 248 // to Font::offsetForPosition(). Bug http://webkit.org/b/40673 tracks fixing this problem. 249 int position = static_cast<int>(xFloat); 250 247 251 TextRunComponents components; 248 252 int w = generateComponents(&components, *this, run); … … 309 313 } 310 314 311 FloatRect Font::selectionRectForComplexText(const TextRun& run, const IntPoint& pt,315 FloatRect Font::selectionRectForComplexText(const TextRun& run, const FloatPoint& pt, 312 316 int h, int from, int to) const 313 317 { -
trunk/WebCore/platform/graphics/wx/FontWx.cpp
r60315 r61253 71 71 } 72 72 73 FloatRect Font::selectionRectForComplexText(const TextRun& run, const IntPoint& point, int h, int from, int to) const73 FloatRect Font::selectionRectForComplexText(const TextRun& run, const FloatPoint& point, int h, int from, int to) const 74 74 { 75 75 #if OS(WINDOWS) || OS(DARWIN) … … 154 154 } 155 155 156 int Font::offsetForPositionForComplexText(const TextRun& run, int x, bool includePartialGlyphs) const156 int Font::offsetForPositionForComplexText(const TextRun& run, float x, bool includePartialGlyphs) const 157 157 { 158 158 #if OS(WINDOWS) || OS(DARWIN) -
trunk/WebCore/svg/SVGFont.cpp
r58212 r61253 572 572 } 573 573 574 FloatRect Font::selectionRectForTextUsingSVGFont(const TextRun& run, const IntPoint& point, int height, int from, int to) const574 FloatRect Font::selectionRectForTextUsingSVGFont(const TextRun& run, const FloatPoint& point, int height, int from, int to) const 575 575 { 576 576 int charsConsumed; … … 581 581 } 582 582 583 int Font::offsetForPositionForTextUsingSVGFont(const TextRun&, int, bool) const583 int Font::offsetForPositionForTextUsingSVGFont(const TextRun&, float, bool) const 584 584 { 585 585 // TODO: Fix text selection when HTML text is drawn using a SVG Font
Note: See TracChangeset
for help on using the changeset viewer.