24 #include "wtf/Platform.h"
34 SVGPreserveAspectRatio::SVGPreserveAspectRatio()
35 : m_align(SVG_PRESERVEASPECTRATIO_XMIDYMID)
36 , m_meetOrSlice(SVG_MEETORSLICE_MEET)
41 SVGPreserveAspectRatio::~SVGPreserveAspectRatio()
45 void SVGPreserveAspectRatio::setAlign(
unsigned short align)
50 unsigned short SVGPreserveAspectRatio::align()
const
55 void SVGPreserveAspectRatio::setMeetOrSlice(
unsigned short meetOrSlice)
57 m_meetOrSlice = meetOrSlice;
60 unsigned short SVGPreserveAspectRatio::meetOrSlice()
const
65 bool SVGPreserveAspectRatio::parsePreserveAspectRatio(
const UChar*& currParam,
const UChar* end,
bool validate)
67 SVGPreserveAspectRatioType align = SVG_PRESERVEASPECTRATIO_NONE;
68 SVGMeetOrSliceType meetOrSlice = SVG_MEETORSLICE_MEET;
71 if (!skipOptionalSpaces(currParam, end))
74 if (*currParam ==
'd') {
82 if (*currParam ==
'n') {
85 skipOptionalSpaces(currParam, end);
86 }
else if (*currParam ==
'x') {
87 if ((end - currParam) < 8)
89 if (currParam[1] !=
'M' || currParam[4] !=
'Y' || currParam[5] !=
'M')
91 if (currParam[2] ==
'i') {
92 if (currParam[3] ==
'n') {
93 if (currParam[6] ==
'i') {
94 if (currParam[7] ==
'n')
95 align = SVG_PRESERVEASPECTRATIO_XMINYMIN;
96 else if (currParam[7] ==
'd')
97 align = SVG_PRESERVEASPECTRATIO_XMINYMID;
100 }
else if (currParam[6] ==
'a' && currParam[7] ==
'x')
101 align = SVG_PRESERVEASPECTRATIO_XMINYMAX;
104 }
else if (currParam[3] ==
'd') {
105 if (currParam[6] ==
'i') {
106 if (currParam[7] ==
'n')
107 align = SVG_PRESERVEASPECTRATIO_XMIDYMIN;
108 else if (currParam[7] ==
'd')
109 align = SVG_PRESERVEASPECTRATIO_XMIDYMID;
112 }
else if (currParam[6] ==
'a' && currParam[7] ==
'x')
113 align = SVG_PRESERVEASPECTRATIO_XMIDYMAX;
118 }
else if (currParam[2] ==
'a' && currParam[3] ==
'x') {
119 if (currParam[6] ==
'i') {
120 if (currParam[7] ==
'n')
121 align = SVG_PRESERVEASPECTRATIO_XMAXYMIN;
122 else if (currParam[7] ==
'd')
123 align = SVG_PRESERVEASPECTRATIO_XMAXYMID;
126 }
else if (currParam[6] ==
'a' && currParam[7] ==
'x')
127 align = SVG_PRESERVEASPECTRATIO_XMAXYMAX;
133 skipOptionalSpaces(currParam, end);
137 if (currParam < end) {
138 if (*currParam ==
'm') {
142 }
else if (*currParam ==
's') {
151 if (end != currParam && validate) {
154 align = SVG_PRESERVEASPECTRATIO_NONE;
155 meetOrSlice = SVG_MEETORSLICE_MEET;
159 if (m_align == align && m_meetOrSlice == meetOrSlice)
163 m_meetOrSlice = meetOrSlice;
167 AffineTransform SVGPreserveAspectRatio::getCTM(
double logicX,
double logicY,
168 double logicWidth,
double logicHeight,
170 double physWidth,
double physHeight)
172 AffineTransform temp;
174 if (align() == SVG_PRESERVEASPECTRATIO_UNKNOWN)
177 double vpar = logicWidth / logicHeight;
178 double svgar = physWidth / physHeight;
180 if (align() == SVG_PRESERVEASPECTRATIO_NONE) {
181 temp.scale(physWidth / logicWidth, physHeight / logicHeight);
182 temp.translate(-logicX, -logicY);
183 }
else if ((vpar < svgar && meetOrSlice() == SVG_MEETORSLICE_MEET) || (vpar >= svgar && meetOrSlice() == SVG_MEETORSLICE_SLICE)) {
184 temp.scale(physHeight / logicHeight, physHeight / logicHeight);
186 if (align() == SVG_PRESERVEASPECTRATIO_XMINYMIN || align() == SVG_PRESERVEASPECTRATIO_XMINYMID || align() == SVG_PRESERVEASPECTRATIO_XMINYMAX)
187 temp.translate(-logicX, -logicY);
188 else if (align() == SVG_PRESERVEASPECTRATIO_XMIDYMIN || align() == SVG_PRESERVEASPECTRATIO_XMIDYMID || align() == SVG_PRESERVEASPECTRATIO_XMIDYMAX)
189 temp.translate(-logicX - (logicWidth - physWidth * logicHeight / physHeight) / 2, -logicY);
191 temp.translate(-logicX - (logicWidth - physWidth * logicHeight / physHeight), -logicY);
193 temp.scale(physWidth / logicWidth, physWidth / logicWidth);
195 if (align() == SVG_PRESERVEASPECTRATIO_XMINYMIN || align() == SVG_PRESERVEASPECTRATIO_XMIDYMIN || align() == SVG_PRESERVEASPECTRATIO_XMAXYMIN)
196 temp.translate(-logicX, -logicY);
197 else if (align() == SVG_PRESERVEASPECTRATIO_XMINYMID || align() == SVG_PRESERVEASPECTRATIO_XMIDYMID || align() == SVG_PRESERVEASPECTRATIO_XMAXYMID)
198 temp.translate(-logicX, -logicY - (logicHeight - physHeight * logicWidth / physWidth) / 2);
200 temp.translate(-logicX, -logicY - (logicHeight - physHeight * logicWidth / physWidth));
208 #endif // ENABLE(SVG)