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

Side by Side Diff: Source/core/paint/SVGInlineTextBoxPainter.cpp

Issue 637503003: Prefer using RenderSVGResourceMode when possible (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/paint/SVGInlineTextBoxPainter.h" 6 #include "core/paint/SVGInlineTextBoxPainter.h"
7 7
8 #include "core/dom/DocumentMarkerController.h" 8 #include "core/dom/DocumentMarkerController.h"
9 #include "core/dom/RenderedDocumentMarker.h" 9 #include "core/dom/RenderedDocumentMarker.h"
10 #include "core/editing/Editor.h" 10 #include "core/editing/Editor.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 paintDecoration(paintInfo.context, TextDecorationUnderline, fragment ); 102 paintDecoration(paintInfo.context, TextDecorationUnderline, fragment );
103 if (decorations & TextDecorationOverline) 103 if (decorations & TextDecorationOverline)
104 paintDecoration(paintInfo.context, TextDecorationOverline, fragment) ; 104 paintDecoration(paintInfo.context, TextDecorationOverline, fragment) ;
105 105
106 for (int i = 0; i < 3; i++) { 106 for (int i = 0; i < 3; i++) {
107 switch (svgStyle.paintOrderType(i)) { 107 switch (svgStyle.paintOrderType(i)) {
108 case PT_FILL: 108 case PT_FILL:
109 // Fill text 109 // Fill text
110 if (hasFill) { 110 if (hasFill) {
111 paintText(paintInfo.context, style, selectionStyle, fragment , 111 paintText(paintInfo.context, style, selectionStyle, fragment ,
112 ApplyToFillMode | ApplyToTextMode, hasSelection, paintSe lectedTextOnly); 112 ApplyToFillMode, hasSelection, paintSelectedTextOnly);
113 } 113 }
114 break; 114 break;
115 case PT_STROKE: 115 case PT_STROKE:
116 // Stroke text 116 // Stroke text
117 if (hasVisibleStroke) { 117 if (hasVisibleStroke) {
118 paintText(paintInfo.context, style, selectionStyle, fragment , 118 paintText(paintInfo.context, style, selectionStyle, fragment ,
119 ApplyToStrokeMode | ApplyToTextMode, hasSelection, paint SelectedTextOnly); 119 ApplyToStrokeMode, hasSelection, paintSelectedTextOnly);
120 } 120 }
121 break; 121 break;
122 case PT_MARKERS: 122 case PT_MARKERS:
123 // Markers don't apply to text 123 // Markers don't apply to text
124 break; 124 break;
125 default: 125 default:
126 ASSERT_NOT_REACHED(); 126 ASSERT_NOT_REACHED();
127 break; 127 break;
128 } 128 }
129 } 129 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 300 }
301 301
302 static inline float thicknessForDecoration(TextDecoration, const Font& font) 302 static inline float thicknessForDecoration(TextDecoration, const Font& font)
303 { 303 {
304 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f ace> if specified. 304 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-f ace> if specified.
305 // Compatible with Batik/Presto 305 // Compatible with Batik/Presto
306 return font.fontDescription().computedSize() / 20.0f; 306 return font.fontDescription().computedSize() / 20.0f;
307 } 307 }
308 308
309 void SVGInlineTextBoxPainter::paintDecorationWithStyle(GraphicsContext* context, TextDecoration decoration, 309 void SVGInlineTextBoxPainter::paintDecorationWithStyle(GraphicsContext* context, TextDecoration decoration,
310 const SVGTextFragment& fragment, RenderObject* decorationRenderer, RenderSVG ResourceModeFlags resourceMode) 310 const SVGTextFragment& fragment, RenderObject* decorationRenderer, RenderSVG ResourceMode resourceMode)
311 { 311 {
312 RenderStyle* decorationStyle = decorationRenderer->style(); 312 RenderStyle* decorationStyle = decorationRenderer->style();
313 ASSERT(decorationStyle); 313 ASSERT(decorationStyle);
314 314
315 float scalingFactor = 1; 315 float scalingFactor = 1;
316 Font scaledFont; 316 Font scaledFont;
317 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decora tionStyle, scalingFactor, scaledFont); 317 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decora tionStyle, scalingFactor, scaledFont);
318 ASSERT(scalingFactor); 318 ASSERT(scalingFactor);
319 319
320 float thickness = thicknessForDecoration(decoration, scaledFont); 320 float thickness = thicknessForDecoration(decoration, scaledFont);
321 321
322 if (fragment.width <= 0 && thickness <= 0) 322 if (fragment.width <= 0 && thickness <= 0)
323 return; 323 return;
324 324
325 float decorationOffset = baselineOffsetForDecoration(decoration, scaledFont. fontMetrics(), thickness); 325 float decorationOffset = baselineOffsetForDecoration(decoration, scaledFont. fontMetrics(), thickness);
326 FloatPoint decorationOrigin(fragment.x, fragment.y - decorationOffset / scal ingFactor); 326 FloatPoint decorationOrigin(fragment.x, fragment.y - decorationOffset / scal ingFactor);
327 327
328 Path path; 328 Path path;
329 path.addRect(FloatRect(decorationOrigin, FloatSize(fragment.width, thickness / scalingFactor))); 329 path.addRect(FloatRect(decorationOrigin, FloatSize(fragment.width, thickness / scalingFactor)));
330 330
331 PaintingResourceScope resourceScope(*decorationRenderer); 331 PaintingResourceScope resourceScope(*decorationRenderer);
332 if (resourceScope.acquirePaintingResource(context, decorationStyle, resource Mode)) { 332 if (resourceScope.acquirePaintingResource(context, decorationStyle, resource Mode)) {
333 SVGRenderSupport::fillOrStrokePath(context, resourceMode, path); 333 SVGRenderSupport::fillOrStrokePath(context, resourceMode, path);
334 resourceScope.releasePaintingResource(context); 334 resourceScope.releasePaintingResource(context);
335 } 335 }
336 } 336 }
337 337
338 void SVGInlineTextBoxPainter::paintTextWithShadows(GraphicsContext* context, Ren derStyle* style, 338 void SVGInlineTextBoxPainter::paintTextWithShadows(GraphicsContext* context, Ren derStyle* style,
339 TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int en dPosition, 339 TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int en dPosition,
340 RenderSVGResourceModeFlags resourceMode) 340 RenderSVGResourceMode resourceMode)
341 { 341 {
342 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox .renderer()); 342 RenderSVGInlineText& textRenderer = toRenderSVGInlineText(m_svgInlineTextBox .renderer());
343 343
344 float scalingFactor = textRenderer.scalingFactor(); 344 float scalingFactor = textRenderer.scalingFactor();
345 ASSERT(scalingFactor); 345 ASSERT(scalingFactor);
346 346
347 const Font& scaledFont = textRenderer.scaledFont(); 347 const Font& scaledFont = textRenderer.scaledFont();
348 const ShadowList* shadowList = style->textShadow(); 348 const ShadowList* shadowList = style->textShadow();
349 349
350 // Text shadows are disabled when printing. http://crbug.com/258321 350 // Text shadows are disabled when printing. http://crbug.com/258321
351 bool hasShadow = shadowList && !context->printing(); 351 bool hasShadow = shadowList && !context->printing();
352 352
353 FloatPoint textOrigin(fragment.x, fragment.y); 353 FloatPoint textOrigin(fragment.x, fragment.y);
354 FloatSize textSize(fragment.width, fragment.height); 354 FloatSize textSize(fragment.width, fragment.height);
355 355
356 if (scalingFactor != 1) { 356 if (scalingFactor != 1) {
357 textOrigin.scale(scalingFactor, scalingFactor); 357 textOrigin.scale(scalingFactor, scalingFactor);
358 textSize.scale(scalingFactor); 358 textSize.scale(scalingFactor);
359 context->save(); 359 context->save();
360 context->scale(1 / scalingFactor, 1 / scalingFactor); 360 context->scale(1 / scalingFactor, 1 / scalingFactor);
361 } 361 }
362 362
363 if (hasShadow) 363 if (hasShadow)
364 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S hadowRespectsAlpha)); 364 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S hadowRespectsAlpha));
365 365
366 PaintingResourceScope resourceScope(m_svgInlineTextBox.parent()->renderer()) ; 366 PaintingResourceScope resourceScope(m_svgInlineTextBox.parent()->renderer()) ;
367 if (resourceScope.acquirePaintingResource(context, style, resourceMode)) { 367 if (resourceScope.acquirePaintingResource(context, style, resourceMode | App lyToTextMode)) {
368 if (scalingFactor != 1 && resourceMode & ApplyToStrokeMode) 368 context->setTextDrawingMode(resourceMode == ApplyToFillMode ? TextModeFi ll : TextModeStroke);
369
370 if (scalingFactor != 1 && resourceMode == ApplyToStrokeMode)
369 context->setStrokeThickness(context->strokeThickness() * scalingFact or); 371 context->setStrokeThickness(context->strokeThickness() * scalingFact or);
370 372
371 TextRunPaintInfo textRunPaintInfo(textRun); 373 TextRunPaintInfo textRunPaintInfo(textRun);
372 textRunPaintInfo.from = startPosition; 374 textRunPaintInfo.from = startPosition;
373 textRunPaintInfo.to = endPosition; 375 textRunPaintInfo.to = endPosition;
374 376
375 float baseline = scaledFont.fontMetrics().floatAscent(); 377 float baseline = scaledFont.fontMetrics().floatAscent();
376 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - bas eline, 378 textRunPaintInfo.bounds = FloatRect(textOrigin.x(), textOrigin.y() - bas eline,
377 textSize.width(), textSize.height()); 379 textSize.width(), textSize.height());
378 380
379 scaledFont.drawText(context, textRunPaintInfo, textOrigin); 381 scaledFont.drawText(context, textRunPaintInfo, textOrigin);
380 resourceScope.releasePaintingResource(context); 382 resourceScope.releasePaintingResource(context);
381 } 383 }
382 384
383 if (scalingFactor != 1) 385 if (scalingFactor != 1)
384 context->restore(); 386 context->restore();
385 else if (hasShadow) 387 else if (hasShadow)
386 context->clearShadow(); 388 context->clearShadow();
387 } 389 }
388 390
389 void SVGInlineTextBoxPainter::paintText(GraphicsContext* context, RenderStyle* s tyle, 391 void SVGInlineTextBoxPainter::paintText(GraphicsContext* context, RenderStyle* s tyle,
390 RenderStyle* selectionStyle, const SVGTextFragment& fragment, 392 RenderStyle* selectionStyle, const SVGTextFragment& fragment,
391 RenderSVGResourceModeFlags resourceMode, bool hasSelection, bool paintSelect edTextOnly) 393 RenderSVGResourceMode resourceMode, bool hasSelection, bool paintSelectedTex tOnly)
392 { 394 {
393 ASSERT(style); 395 ASSERT(style);
394 ASSERT(selectionStyle); 396 ASSERT(selectionStyle);
395 397
396 int startPosition = 0; 398 int startPosition = 0;
397 int endPosition = 0; 399 int endPosition = 0;
398 if (hasSelection) { 400 if (hasSelection) {
399 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition); 401 m_svgInlineTextBox.selectionStartEnd(startPosition, endPosition);
400 hasSelection = m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordi nates(fragment, startPosition, endPosition); 402 hasSelection = m_svgInlineTextBox.mapStartEndPositionsIntoFragmentCoordi nates(fragment, startPosition, endPosition);
401 } 403 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 482
481 fragmentRect = fragmentTransform.mapRect(fragmentRect); 483 fragmentRect = fragmentTransform.mapRect(fragmentRect);
482 markerRect.unite(fragmentRect); 484 markerRect.unite(fragmentRect);
483 } 485 }
484 } 486 }
485 487
486 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsolu teQuad(markerRect).enclosingBoundingBox()); 488 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer.localToAbsolu teQuad(markerRect).enclosingBoundingBox());
487 } 489 }
488 490
489 } // namespace blink 491 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/paint/SVGInlineTextBoxPainter.h ('k') | Source/core/rendering/svg/RenderSVGResource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698