40 SVGTransformable::SVGTransformable() : SVGLocatable()
44 SVGTransformable::~SVGTransformable()
48 AffineTransform SVGTransformable::getCTM(
const SVGElement* element)
const
50 AffineTransform ctm = SVGLocatable::getCTM(element);
51 return animatedLocalTransform() * ctm;
54 AffineTransform SVGTransformable::getScreenCTM(
const SVGElement* element)
const
56 AffineTransform ctm = SVGLocatable::getScreenCTM(element);
57 return animatedLocalTransform() * ctm;
60 int parseTransformParamList(
const UChar*& ptr,
const UChar* end,
float* values,
int required,
int optional)
62 int optionalParams = 0, requiredParams = 0;
64 if (!skipOptionalSpaces(ptr, end) || *ptr !=
'(')
69 skipOptionalSpaces(ptr, end);
71 while (requiredParams < required) {
72 if (ptr >= end || !parseNumber(ptr, end, values[requiredParams],
false))
75 if (requiredParams < required)
76 skipOptionalSpacesOrDelimiter(ptr, end);
78 if (!skipOptionalSpaces(ptr, end))
81 bool delimParsed = skipOptionalSpacesOrDelimiter(ptr, end);
91 while (optionalParams < optional) {
92 if (ptr >= end || !parseNumber(ptr, end, values[requiredParams + optionalParams],
false))
95 if (optionalParams < optional)
96 skipOptionalSpacesOrDelimiter(ptr, end);
99 if (!skipOptionalSpaces(ptr, end))
102 delimParsed = skipOptionalSpacesOrDelimiter(ptr, end);
104 if (ptr >= end || *ptr !=
')' || delimParsed)
109 return requiredParams + optionalParams;
113 static const int requiredValuesForType[] = {0, 6, 1, 1, 1, 1, 1};
114 static const int optionalValuesForType[] = {0, 0, 1, 1, 2, 0, 0};
116 bool SVGTransformable::parseTransformValue(
unsigned type,
const UChar*& ptr,
const UChar* end, SVGTransform& t)
118 if (type == SVGTransform::SVG_TRANSFORM_UNKNOWN)
122 float values[] = {0, 0, 0, 0, 0, 0};
123 if ((valueCount = parseTransformParamList(ptr, end, values, requiredValuesForType[type], optionalValuesForType[type])) < 0)
127 case SVGTransform::SVG_TRANSFORM_SKEWX:
128 t.setSkewX(values[0]);
130 case SVGTransform::SVG_TRANSFORM_SKEWY:
131 t.setSkewY(values[0]);
133 case SVGTransform::SVG_TRANSFORM_SCALE:
135 t.setScale(values[0], values[0]);
137 t.setScale(values[0], values[1]);
139 case SVGTransform::SVG_TRANSFORM_TRANSLATE:
141 t.setTranslate(values[0], 0);
143 t.setTranslate(values[0], values[1]);
145 case SVGTransform::SVG_TRANSFORM_ROTATE:
147 t.setRotate(values[0], 0, 0);
149 t.setRotate(values[0], values[1], values[2]);
151 case SVGTransform::SVG_TRANSFORM_MATRIX:
152 t.setMatrix(AffineTransform(values[0], values[1], values[2], values[3], values[4], values[5]));
159 static const UChar skewXDesc[] = {
's',
'k',
'e',
'w',
'X'};
160 static const UChar skewYDesc[] = {
's',
'k',
'e',
'w',
'Y'};
161 static const UChar scaleDesc[] = {
's',
'c',
'a',
'l',
'e'};
162 static const UChar translateDesc[] = {
't',
'r',
'a',
'n',
's',
'l',
'a',
't',
'e'};
163 static const UChar rotateDesc[] = {
'r',
'o',
't',
'a',
't',
'e'};
164 static const UChar matrixDesc[] = {
'm',
'a',
't',
'r',
'i',
'x'};
182 static inline bool parseAndSkipType(
const UChar*& currTransform,
const UChar* end,
unsigned short& type)
184 if (currTransform >= end)
187 if (*currTransform ==
's') {
188 if (
skipString(currTransform, end, skewXDesc,
sizeof(skewXDesc) /
sizeof(UChar)))
189 type = SVGTransform::SVG_TRANSFORM_SKEWX;
190 else if (
skipString(currTransform, end, skewYDesc,
sizeof(skewYDesc) /
sizeof(UChar)))
191 type = SVGTransform::SVG_TRANSFORM_SKEWY;
192 else if (
skipString(currTransform, end, scaleDesc,
sizeof(scaleDesc) /
sizeof(UChar)))
193 type = SVGTransform::SVG_TRANSFORM_SCALE;
196 }
else if (
skipString(currTransform, end, translateDesc,
sizeof(translateDesc) /
sizeof(UChar)))
197 type = SVGTransform::SVG_TRANSFORM_TRANSLATE;
198 else if (
skipString(currTransform, end, rotateDesc,
sizeof(rotateDesc) /
sizeof(UChar)))
199 type = SVGTransform::SVG_TRANSFORM_ROTATE;
200 else if (
skipString(currTransform, end, matrixDesc,
sizeof(matrixDesc) /
sizeof(UChar)))
201 type = SVGTransform::SVG_TRANSFORM_MATRIX;
208 bool SVGTransformable::parseTransformAttribute(SVGTransformList* list,
const AtomicString& transform)
210 const UChar* start = transform.characters();
211 const UChar* end = start + transform.length();
212 return parseTransformAttribute(list, start, end);
215 bool SVGTransformable::parseTransformAttribute(SVGTransformList* list,
const UChar*& currTransform,
const UChar* end)
217 bool delimParsed =
false;
218 while (currTransform < end) {
220 unsigned short type = SVGTransform::SVG_TRANSFORM_UNKNOWN;
221 skipOptionalSpaces(currTransform, end);
223 if (!parseAndSkipType(currTransform, end, type))
227 if (!parseTransformValue(type, currTransform, end, t))
230 ExceptionCode ec = 0;
231 list->appendItem(t, ec);
232 skipOptionalSpaces(currTransform, end);
233 if (currTransform < end && *currTransform ==
',') {
237 skipOptionalSpaces(currTransform, end);
243 bool SVGTransformable::isKnownAttribute(
const QualifiedName& attrName)
250 #endif // ENABLE(SVG)
DOM::QualifiedName transformAttr
bool skipString(const QChar *&ptr, const QChar *end, const QChar *name, int length)