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

Side by Side Diff: Source/core/svg/SVGPathParser.cpp

Issue 1013183002: Stop mutating inputs to decomposeArcToCubic (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 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
« no previous file with comments | « Source/core/svg/SVGPathParser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2002, 2003 The Karbon Developers 2 * Copyright (C) 2002, 2003 The Karbon Developers
3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> 4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org>
5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. 5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 389
390 m_consumer->incrementPathSegmentCount(); 390 m_consumer->incrementPathSegmentCount();
391 } 391 }
392 392
393 return false; 393 return false;
394 } 394 }
395 395
396 // This works by converting the SVG arc to "simple" beziers. 396 // This works by converting the SVG arc to "simple" beziers.
397 // Partly adapted from Niko's code in kdelibs/kdecore/svgicons. 397 // Partly adapted from Niko's code in kdelibs/kdecore/svgicons.
398 // See also SVG implementation notes: http://www.w3.org/TR/SVG/implnote.html#Arc ConversionEndpointToCenter 398 // See also SVG implementation notes: http://www.w3.org/TR/SVG/implnote.html#Arc ConversionEndpointToCenter
399 bool SVGPathParser::decomposeArcToCubic(float angle, float rx, float ry, FloatPo int& point1, FloatPoint& point2, bool largeArcFlag, bool sweepFlag) 399 bool SVGPathParser::decomposeArcToCubic(float angle, float rx, float ry, const F loatPoint& start, const FloatPoint& end, bool largeArcFlag, bool sweepFlag)
400 { 400 {
401 FloatSize midPointDistance = point1 - point2; 401 FloatSize midPointDistance = start - end;
402 midPointDistance.scale(0.5f); 402 midPointDistance.scale(0.5f);
403 403
404 AffineTransform pointTransform; 404 AffineTransform pointTransform;
405 pointTransform.rotate(-angle); 405 pointTransform.rotate(-angle);
406 406
407 FloatPoint transformedMidPoint = pointTransform.mapPoint(FloatPoint(midPoint Distance.width(), midPointDistance.height())); 407 FloatPoint transformedMidPoint = pointTransform.mapPoint(FloatPoint(midPoint Distance.width(), midPointDistance.height()));
408 float squareRx = rx * rx; 408 float squareRx = rx * rx;
409 float squareRy = ry * ry; 409 float squareRy = ry * ry;
410 float squareX = transformedMidPoint.x() * transformedMidPoint.x(); 410 float squareX = transformedMidPoint.x() * transformedMidPoint.x();
411 float squareY = transformedMidPoint.y() * transformedMidPoint.y(); 411 float squareY = transformedMidPoint.y() * transformedMidPoint.y();
412 412
413 // Check if the radii are big enough to draw the arc, scale radii if not. 413 // Check if the radii are big enough to draw the arc, scale radii if not.
414 // http://www.w3.org/TR/SVG/implnote.html#ArcCorrectionOutOfRangeRadii 414 // http://www.w3.org/TR/SVG/implnote.html#ArcCorrectionOutOfRangeRadii
415 float radiiScale = squareX / squareRx + squareY / squareRy; 415 float radiiScale = squareX / squareRx + squareY / squareRy;
416 if (radiiScale > 1) { 416 if (radiiScale > 1) {
417 rx *= sqrtf(radiiScale); 417 rx *= sqrtf(radiiScale);
418 ry *= sqrtf(radiiScale); 418 ry *= sqrtf(radiiScale);
419 } 419 }
420 420
421 pointTransform.makeIdentity(); 421 pointTransform.makeIdentity();
422 pointTransform.scale(1 / rx, 1 / ry); 422 pointTransform.scale(1 / rx, 1 / ry);
423 pointTransform.rotate(-angle); 423 pointTransform.rotate(-angle);
424 424
425 point1 = pointTransform.mapPoint(point1); 425 FloatPoint point1 = pointTransform.mapPoint(start);
426 point2 = pointTransform.mapPoint(point2); 426 FloatPoint point2 = pointTransform.mapPoint(end);
427 FloatSize delta = point2 - point1; 427 FloatSize delta = point2 - point1;
428 428
429 float d = delta.width() * delta.width() + delta.height() * delta.height(); 429 float d = delta.width() * delta.width() + delta.height() * delta.height();
430 float scaleFactorSquared = std::max(1 / d - 0.25f, 0.f); 430 float scaleFactorSquared = std::max(1 / d - 0.25f, 0.f);
431 431
432 float scaleFactor = sqrtf(scaleFactorSquared); 432 float scaleFactor = sqrtf(scaleFactorSquared);
433 if (sweepFlag == largeArcFlag) 433 if (sweepFlag == largeArcFlag)
434 scaleFactor = -scaleFactor; 434 scaleFactor = -scaleFactor;
435 435
436 delta.scale(scaleFactor); 436 delta.scale(scaleFactor);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 point2 = targetPoint; 473 point2 = targetPoint;
474 point2.move(t * sinEndTheta, -t * cosEndTheta); 474 point2.move(t * sinEndTheta, -t * cosEndTheta);
475 475
476 m_consumer->curveToCubic(pointTransform.mapPoint(point1), pointTransform .mapPoint(point2), 476 m_consumer->curveToCubic(pointTransform.mapPoint(point1), pointTransform .mapPoint(point2),
477 pointTransform.mapPoint(targetPoint), AbsoluteC oordinates); 477 pointTransform.mapPoint(targetPoint), AbsoluteC oordinates);
478 } 478 }
479 return true; 479 return true;
480 } 480 }
481 481
482 } 482 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGPathParser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698