| OLD | NEW |
| 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/SVGShapePainter.h" | 6 #include "core/paint/SVGShapePainter.h" |
| 7 | 7 |
| 8 #include "core/layout/svg/LayoutSVGPath.h" | |
| 9 #include "core/layout/svg/LayoutSVGResourceMarker.h" | 8 #include "core/layout/svg/LayoutSVGResourceMarker.h" |
| 10 #include "core/layout/svg/LayoutSVGShape.h" | 9 #include "core/layout/svg/LayoutSVGShape.h" |
| 11 #include "core/layout/svg/SVGLayoutSupport.h" | 10 #include "core/layout/svg/SVGLayoutSupport.h" |
| 12 #include "core/layout/svg/SVGMarkerData.h" | 11 #include "core/layout/svg/SVGMarkerData.h" |
| 13 #include "core/layout/svg/SVGResources.h" | 12 #include "core/layout/svg/SVGResources.h" |
| 14 #include "core/layout/svg/SVGResourcesCache.h" | 13 #include "core/layout/svg/SVGResourcesCache.h" |
| 15 #include "core/paint/FloatClipRecorder.h" | 14 #include "core/paint/FloatClipRecorder.h" |
| 16 #include "core/paint/LayoutObjectDrawingRecorder.h" | 15 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 17 #include "core/paint/ObjectPainter.h" | 16 #include "core/paint/ObjectPainter.h" |
| 18 #include "core/paint/PaintInfo.h" | 17 #include "core/paint/PaintInfo.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 context->drawRect(m_layoutSVGShape.objectBoundingBox(), paint); | 165 context->drawRect(m_layoutSVGShape.objectBoundingBox(), paint); |
| 167 break; | 166 break; |
| 168 case EllipseGeometryFastPath: | 167 case EllipseGeometryFastPath: |
| 169 context->drawOval(m_layoutSVGShape.objectBoundingBox(), paint); | 168 context->drawOval(m_layoutSVGShape.objectBoundingBox(), paint); |
| 170 break; | 169 break; |
| 171 default: | 170 default: |
| 172 Path* usePath = &m_layoutSVGShape.path(); | 171 Path* usePath = &m_layoutSVGShape.path(); |
| 173 if (m_layoutSVGShape.hasNonScalingStroke()) | 172 if (m_layoutSVGShape.hasNonScalingStroke()) |
| 174 usePath = m_layoutSVGShape.nonScalingStrokePath(usePath, m_layoutSVG
Shape.nonScalingStrokeTransform()); | 173 usePath = m_layoutSVGShape.nonScalingStrokePath(usePath, m_layoutSVG
Shape.nonScalingStrokeTransform()); |
| 175 context->drawPath(usePath->skPath(), paint); | 174 context->drawPath(usePath->skPath(), paint); |
| 176 strokeZeroLengthLineCaps(context, paint); | |
| 177 } | 175 } |
| 178 } | 176 } |
| 179 | 177 |
| 180 void SVGShapePainter::paintMarkers(const PaintInfo& paintInfo, const FloatRect&
boundingBox) | 178 void SVGShapePainter::paintMarkers(const PaintInfo& paintInfo, const FloatRect&
boundingBox) |
| 181 { | 179 { |
| 182 const Vector<MarkerPosition>* markerPositions = m_layoutSVGShape.markerPosit
ions(); | 180 const Vector<MarkerPosition>* markerPositions = m_layoutSVGShape.markerPosit
ions(); |
| 183 if (!markerPositions || markerPositions->isEmpty()) | 181 if (!markerPositions || markerPositions->isEmpty()) |
| 184 return; | 182 return; |
| 185 | 183 |
| 186 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(
&m_layoutSVGShape); | 184 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(
&m_layoutSVGShape); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 return; | 220 return; |
| 223 | 221 |
| 224 TransformRecorder transformRecorder(*paintInfo.context, marker, marker.marke
rTransformation(position.origin, position.angle, strokeWidth)); | 222 TransformRecorder transformRecorder(*paintInfo.context, marker, marker.marke
rTransformation(position.origin, position.angle, strokeWidth)); |
| 225 Optional<FloatClipRecorder> clipRecorder; | 223 Optional<FloatClipRecorder> clipRecorder; |
| 226 if (SVGLayoutSupport::isOverflowHidden(&marker)) | 224 if (SVGLayoutSupport::isOverflowHidden(&marker)) |
| 227 clipRecorder.emplace(*paintInfo.context, marker, paintInfo.phase, marker
.viewport()); | 225 clipRecorder.emplace(*paintInfo.context, marker, paintInfo.phase, marker
.viewport()); |
| 228 | 226 |
| 229 SVGContainerPainter(marker).paint(paintInfo); | 227 SVGContainerPainter(marker).paint(paintInfo); |
| 230 } | 228 } |
| 231 | 229 |
| 232 void SVGShapePainter::strokeZeroLengthLineCaps(GraphicsContext* context, const S
kPaint& strokePaint) | |
| 233 { | |
| 234 const Vector<FloatPoint>* zeroLengthLineCaps = m_layoutSVGShape.zeroLengthLi
neCaps(); | |
| 235 if (!zeroLengthLineCaps || zeroLengthLineCaps->isEmpty()) | |
| 236 return; | |
| 237 | |
| 238 // We need a paint for filling. | |
| 239 SkPaint fillPaint = strokePaint; | |
| 240 fillPaint.setStyle(SkPaint::kFill_Style); | |
| 241 | |
| 242 AffineTransform nonScalingTransform; | |
| 243 bool hasNonScalingStroke = m_layoutSVGShape.hasNonScalingStroke(); | |
| 244 if (hasNonScalingStroke) | |
| 245 nonScalingTransform = m_layoutSVGShape.nonScalingStrokeTransform(); | |
| 246 | |
| 247 for (const FloatPoint& capPosition : *zeroLengthLineCaps) { | |
| 248 FloatPoint position = capPosition; | |
| 249 // If non-scaling-stroke is in effect, apply the transform to the | |
| 250 // position (being the non-stroke geometry), and then paint the | |
| 251 // requested shape. The CTM should've been adjusted in | |
| 252 // SVGShapePainter::paint. | |
| 253 if (hasNonScalingStroke) | |
| 254 position = nonScalingTransform.mapPoint(position); | |
| 255 FloatRect subpathRect = LayoutSVGPath::zeroLengthSubpathRect(position, m
_layoutSVGShape.strokeWidth()); | |
| 256 if (m_layoutSVGShape.style()->svgStyle().capStyle() == SquareCap) | |
| 257 context->drawRect(subpathRect, fillPaint); | |
| 258 else | |
| 259 context->drawOval(subpathRect, fillPaint); | |
| 260 } | |
| 261 } | |
| 262 | |
| 263 } // namespace blink | 230 } // namespace blink |
| OLD | NEW |