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

Side by Side Diff: Source/core/rendering/svg/RenderSVGResourceGradient.cpp

Issue 230443003: Fix application of OBB paint-servers when device scale != 1 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase. Created 6 years, 8 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) 2006 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 3 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
4 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 4 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
5 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 5 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // Spec: When the geometry of the applicable element has no width or height and objectBoundingBox is specified, 78 // Spec: When the geometry of the applicable element has no width or height and objectBoundingBox is specified,
79 // then the given effect (e.g. a gradient or a filter) will be ignored. 79 // then the given effect (e.g. a gradient or a filter) will be ignored.
80 FloatRect objectBoundingBox = object->objectBoundingBox(); 80 FloatRect objectBoundingBox = object->objectBoundingBox();
81 if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && obje ctBoundingBox.isEmpty()) 81 if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && obje ctBoundingBox.isEmpty())
82 return false; 82 return false;
83 83
84 OwnPtr<GradientData>& gradientData = m_gradientMap.add(object, nullptr).stor edValue->value; 84 OwnPtr<GradientData>& gradientData = m_gradientMap.add(object, nullptr).stor edValue->value;
85 if (!gradientData) 85 if (!gradientData)
86 gradientData = adoptPtr(new GradientData); 86 gradientData = adoptPtr(new GradientData);
87 87
88 bool isPaintingText = resourceMode & ApplyToTextMode;
89
90 // Create gradient object 88 // Create gradient object
91 if (!gradientData->gradient) { 89 if (!gradientData->gradient) {
92 buildGradient(gradientData.get()); 90 buildGradient(gradientData.get());
93 91
94 // We want the text bounding box applied to the gradient space transform now, so the gradient shader can use it. 92 // We want the text bounding box applied to the gradient space transform now, so the gradient shader can use it.
95 if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty()) { 93 if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty()) {
96 gradientData->userspaceTransform.translate(objectBoundingBox.x(), ob jectBoundingBox.y()); 94 gradientData->userspaceTransform.translate(objectBoundingBox.x(), ob jectBoundingBox.y());
97 gradientData->userspaceTransform.scaleNonUniform(objectBoundingBox.w idth(), objectBoundingBox.height()); 95 gradientData->userspaceTransform.scaleNonUniform(objectBoundingBox.w idth(), objectBoundingBox.height());
98 } 96 }
99 97
100 AffineTransform gradientTransform; 98 AffineTransform gradientTransform;
101 calculateGradientTransform(gradientTransform); 99 calculateGradientTransform(gradientTransform);
102 100
103 gradientData->userspaceTransform *= gradientTransform; 101 gradientData->userspaceTransform *= gradientTransform;
104 if (isPaintingText) {
105 // Depending on font scaling factor, we may need to rescale the grad ient here since
106 // text painting removes the scale factor from the context.
107 AffineTransform additionalTextTransform;
108 if (shouldTransformOnTextPainting(object, additionalTextTransform))
109 gradientData->userspaceTransform *= additionalTextTransform;
110 }
111 gradientData->gradient->setGradientSpaceTransform(gradientData->userspac eTransform);
112 } 102 }
113 103
114 if (!gradientData->gradient) 104 if (!gradientData->gradient)
115 return false; 105 return false;
116 106
107 const SVGRenderStyle* svgStyle = style->svgStyle();
108 ASSERT(svgStyle);
109
110 AffineTransform computedGradientSpaceTransform = computeResourceSpaceTransfo rm(object, gradientData->userspaceTransform, svgStyle, resourceMode);
111 gradientData->gradient->setGradientSpaceTransform(computedGradientSpaceTrans form);
112
117 // Draw gradient 113 // Draw gradient
118 context->save(); 114 context->save();
119 115
120 if (isPaintingText) 116 if (resourceMode & ApplyToTextMode)
121 context->setTextDrawingMode(resourceMode & ApplyToFillMode ? TextModeFil l : TextModeStroke); 117 context->setTextDrawingMode(resourceMode & ApplyToFillMode ? TextModeFil l : TextModeStroke);
122 118
123 const SVGRenderStyle* svgStyle = style->svgStyle();
124 ASSERT(svgStyle);
125
126 if (resourceMode & ApplyToFillMode) { 119 if (resourceMode & ApplyToFillMode) {
127 context->setAlphaAsFloat(svgStyle->fillOpacity()); 120 context->setAlphaAsFloat(svgStyle->fillOpacity());
128 context->setFillGradient(gradientData->gradient); 121 context->setFillGradient(gradientData->gradient);
129 context->setFillRule(svgStyle->fillRule()); 122 context->setFillRule(svgStyle->fillRule());
130 } else if (resourceMode & ApplyToStrokeMode) { 123 } else if (resourceMode & ApplyToStrokeMode) {
131 if (svgStyle->vectorEffect() == VE_NON_SCALING_STROKE)
132 gradientData->gradient->setGradientSpaceTransform(transformOnNonScal ingStroke(object, gradientData->userspaceTransform));
133 context->setAlphaAsFloat(svgStyle->strokeOpacity()); 124 context->setAlphaAsFloat(svgStyle->strokeOpacity());
134 context->setStrokeGradient(gradientData->gradient); 125 context->setStrokeGradient(gradientData->gradient);
135 SVGRenderSupport::applyStrokeStyleToContext(context, style, object); 126 SVGRenderSupport::applyStrokeStyleToContext(context, style, object);
136 } 127 }
137 128
138 return true; 129 return true;
139 } 130 }
140 131
141 void RenderSVGResourceGradient::postApplyResource(RenderObject*, GraphicsContext *& context, unsigned short resourceMode, const Path* path, const RenderSVGShape* shape) 132 void RenderSVGResourceGradient::postApplyResource(RenderObject*, GraphicsContext *& context, unsigned short resourceMode, const Path* path, const RenderSVGShape* shape)
142 { 133 {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return SpreadMethodReflect; 169 return SpreadMethodReflect;
179 case SVGSpreadMethodRepeat: 170 case SVGSpreadMethodRepeat:
180 return SpreadMethodRepeat; 171 return SpreadMethodRepeat;
181 } 172 }
182 173
183 ASSERT_NOT_REACHED(); 174 ASSERT_NOT_REACHED();
184 return SpreadMethodPad; 175 return SpreadMethodPad;
185 } 176 }
186 177
187 } 178 }
OLDNEW
« no previous file with comments | « Source/core/rendering/svg/RenderSVGResourceContainer.cpp ('k') | Source/core/rendering/svg/RenderSVGResourcePattern.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698