Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: Source/core/html/canvas/CanvasRenderingContext2D.cpp

Issue 14160005: Track the region where text is painted. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: implemented TextRun wrapper Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
8 * Copyright (C) 2012 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012 Intel Corporation. All rights reserved.
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
10 * 10 *
(...skipping 2168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2179 location.setX(location.x() - width / 2); 2179 location.setX(location.x() - width / 2);
2180 break; 2180 break;
2181 case RightTextAlign: 2181 case RightTextAlign:
2182 location.setX(location.x() - width); 2182 location.setX(location.x() - width);
2183 break; 2183 break;
2184 default: 2184 default:
2185 break; 2185 break;
2186 } 2186 }
2187 2187
2188 // The slop built in to this mask rect matches the heuristic used in FontCGW in.cpp for GDI text. 2188 // The slop built in to this mask rect matches the heuristic used in FontCGW in.cpp for GDI text.
2189 FloatRect textRect = FloatRect(location.x() - fontMetrics.height() / 2, loca tion.y() - fontMetrics.ascent() - fontMetrics.lineGap(), 2189 TextRunPaintInfo textRunPaintInfo(textRun);
2190 width + fontMetrics.height(), fontMetrics.lin eSpacing()); 2190 textRunPaintInfo.bounds = FloatRect(location.x() - fontMetrics.height() / 2,
2191 location.y() - fontMetrics.ascent() - fon tMetrics.lineGap(),
2192 width + fontMetrics.height(),
2193 fontMetrics.lineSpacing());
2191 if (!fill) 2194 if (!fill)
2192 inflateStrokeRect(textRect); 2195 inflateStrokeRect(textRunPaintInfo.bounds);
2193 2196
2194 c->setTextDrawingMode(fill ? TextModeFill : TextModeStroke); 2197 c->setTextDrawingMode(fill ? TextModeFill : TextModeStroke);
2195 if (useMaxWidth) { 2198 if (useMaxWidth) {
2196 GraphicsContextStateSaver stateSaver(*c); 2199 GraphicsContextStateSaver stateSaver(*c);
2197 c->translate(location.x(), location.y()); 2200 c->translate(location.x(), location.y());
2198 // We draw when fontWidth is 0 so compositing operations (eg, a "copy" o p) still work. 2201 // We draw when fontWidth is 0 so compositing operations (eg, a "copy" o p) still work.
2199 c->scale(FloatSize((fontWidth > 0 ? (width / fontWidth) : 0), 1)); 2202 c->scale(FloatSize((fontWidth > 0 ? (width / fontWidth) : 0), 1));
2200 c->drawBidiText(font, textRun, FloatPoint(0, 0), Font::UseFallbackIfFont NotReady); 2203 c->drawBidiText(font, textRunPaintInfo, FloatPoint(0, 0), Font::UseFallb ackIfFontNotReady);
2201 } else 2204 } else
2202 c->drawBidiText(font, textRun, location, Font::UseFallbackIfFontNotReady ); 2205 c->drawBidiText(font, textRunPaintInfo, location, Font::UseFallbackIfFon tNotReady);
2203 2206
2204 didDraw(textRect); 2207 didDraw(textRunPaintInfo.bounds);
2205 } 2208 }
2206 2209
2207 void CanvasRenderingContext2D::inflateStrokeRect(FloatRect& rect) const 2210 void CanvasRenderingContext2D::inflateStrokeRect(FloatRect& rect) const
2208 { 2211 {
2209 // Fast approximation of the stroke's bounding rect. 2212 // Fast approximation of the stroke's bounding rect.
2210 // This yields a slightly oversized rect but is very fast 2213 // This yields a slightly oversized rect but is very fast
2211 // compared to Path::strokeBoundingRect(). 2214 // compared to Path::strokeBoundingRect().
2212 static const float root2 = sqrtf(2); 2215 static const float root2 = sqrtf(2);
2213 float delta = state().m_lineWidth / 2; 2216 float delta = state().m_lineWidth / 2;
2214 if (state().m_lineJoin == MiterJoin) 2217 if (state().m_lineJoin == MiterJoin)
(...skipping 29 matching lines...) Expand all
2244 return; 2247 return;
2245 2248
2246 realizeSaves(); 2249 realizeSaves();
2247 modifiableState().m_imageSmoothingEnabled = enabled; 2250 modifiableState().m_imageSmoothingEnabled = enabled;
2248 GraphicsContext* c = drawingContext(); 2251 GraphicsContext* c = drawingContext();
2249 if (c) 2252 if (c)
2250 c->setImageInterpolationQuality(enabled ? DefaultInterpolationQuality : InterpolationNone); 2253 c->setImageInterpolationQuality(enabled ? DefaultInterpolationQuality : InterpolationNone);
2251 } 2254 }
2252 2255
2253 } // namespace WebCore 2256 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698