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

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

Issue 132233010: [SVG] SVGAnimatedRect migration to new SVG property impl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebsaed Created 6 years, 11 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/SVGFitToViewBox.h ('k') | Source/core/svg/SVGGraphicsElement.h » ('j') | 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) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Rob Buis <buis@kde.org>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 14 matching lines...) Expand all
25 #include "core/dom/Attribute.h" 25 #include "core/dom/Attribute.h"
26 #include "core/dom/Document.h" 26 #include "core/dom/Document.h"
27 #include "core/svg/SVGDocumentExtensions.h" 27 #include "core/svg/SVGDocumentExtensions.h"
28 #include "core/svg/SVGParserUtilities.h" 28 #include "core/svg/SVGParserUtilities.h"
29 #include "platform/geometry/FloatRect.h" 29 #include "platform/geometry/FloatRect.h"
30 #include "platform/transforms/AffineTransform.h" 30 #include "platform/transforms/AffineTransform.h"
31 #include "wtf/text/StringImpl.h" 31 #include "wtf/text/StringImpl.h"
32 32
33 namespace WebCore { 33 namespace WebCore {
34 34
35 template<typename CharType>
36 static bool parseViewBoxInternal(Document* document, const CharType*& ptr, const CharType* end, FloatRect& viewBox, bool validate)
37 {
38 const CharType* start = ptr;
39
40 skipOptionalSVGSpaces(ptr, end);
41
42 float x = 0.0f;
43 float y = 0.0f;
44 float width = 0.0f;
45 float height = 0.0f;
46 bool valid = parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && parseNu mber(ptr, end, width) && parseNumber(ptr, end, height, false);
47 if (!validate) {
48 viewBox = FloatRect(x, y, width, height);
49 return true;
50 }
51 if (!valid) {
52 document->accessSVGExtensions()->reportWarning("Problem parsing viewBox= \"" + String(start, end - start) + "\"");
53 return false;
54 }
55
56 if (width < 0.0) { // check that width is positive
57 document->accessSVGExtensions()->reportError("A negative value for ViewB ox width is not allowed");
58 return false;
59 }
60 if (height < 0.0) { // check that height is positive
61 document->accessSVGExtensions()->reportError("A negative value for ViewB ox height is not allowed");
62 return false;
63 }
64 skipOptionalSVGSpaces(ptr, end);
65 if (ptr < end) { // nothing should come after the last, fourth number
66 document->accessSVGExtensions()->reportWarning("Problem parsing viewBox= \"" + String(start, end - start) + "\"");
67 return false;
68 }
69
70 viewBox = FloatRect(x, y, width, height);
71 return true;
72 }
73
74 bool SVGFitToViewBox::parseViewBox(Document* document, const LChar*& ptr, const LChar* end, FloatRect& viewBox, bool validate)
75 {
76 return parseViewBoxInternal(document, ptr, end, viewBox, validate);
77 }
78
79 bool SVGFitToViewBox::parseViewBox(Document* document, const UChar*& ptr, const UChar* end, FloatRect& viewBox, bool validate)
80 {
81 return parseViewBoxInternal(document, ptr, end, viewBox, validate);
82 }
83
84 bool SVGFitToViewBox::parseViewBox(Document* document, const String& string, Flo atRect& viewBox)
85 {
86 if (string.isEmpty()) {
87 const LChar* ptr = 0;
88 return parseViewBoxInternal<LChar>(document, ptr, ptr, viewBox, true);
89 }
90 if (string.is8Bit()) {
91 const LChar* ptr = string.characters8();
92 const LChar* end = ptr + string.length();
93 return parseViewBox(document, ptr, end, viewBox, true);
94 }
95 const UChar* ptr = string.characters16();
96 const UChar* end = ptr + string.length();
97 return parseViewBox(document, ptr, end, viewBox, true);
98 }
99
100 AffineTransform SVGFitToViewBox::viewBoxToViewTransform(const FloatRect& viewBox Rect, const SVGPreserveAspectRatio& preserveAspectRatio, float viewWidth, float viewHeight) 35 AffineTransform SVGFitToViewBox::viewBoxToViewTransform(const FloatRect& viewBox Rect, const SVGPreserveAspectRatio& preserveAspectRatio, float viewWidth, float viewHeight)
101 { 36 {
102 if (!viewBoxRect.width() || !viewBoxRect.height()) 37 if (!viewBoxRect.width() || !viewBoxRect.height())
103 return AffineTransform(); 38 return AffineTransform();
104 39
105 return preserveAspectRatio.getCTM(viewBoxRect.x(), viewBoxRect.y(), viewBoxR ect.width(), viewBoxRect.height(), viewWidth, viewHeight); 40 return preserveAspectRatio.getCTM(viewBoxRect.x(), viewBoxRect.y(), viewBoxR ect.width(), viewBoxRect.height(), viewWidth, viewHeight);
106 } 41 }
107 42
108 bool SVGFitToViewBox::isKnownAttribute(const QualifiedName& attrName) 43 bool SVGFitToViewBox::isKnownAttribute(const QualifiedName& attrName)
109 { 44 {
110 return attrName == SVGNames::viewBoxAttr || attrName == SVGNames::preserveAs pectRatioAttr; 45 return attrName == SVGNames::viewBoxAttr || attrName == SVGNames::preserveAs pectRatioAttr;
111 } 46 }
112 47
113 void SVGFitToViewBox::addSupportedAttributes(HashSet<QualifiedName>& supportedAt tributes) 48 void SVGFitToViewBox::addSupportedAttributes(HashSet<QualifiedName>& supportedAt tributes)
114 { 49 {
115 supportedAttributes.add(SVGNames::viewBoxAttr); 50 supportedAttributes.add(SVGNames::viewBoxAttr);
116 supportedAttributes.add(SVGNames::preserveAspectRatioAttr); 51 supportedAttributes.add(SVGNames::preserveAspectRatioAttr);
117 } 52 }
118 53
119 } 54 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGFitToViewBox.h ('k') | Source/core/svg/SVGGraphicsElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698