13 int count = path.elementCount();
15 VGPath vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
21 VG_PATH_CAPABILITY_ALL);
26 QVector<VGfloat> coords;
27 QVector<VGubyte> segments;
40 bool haveStart =
false;
43 for (
int i = 0; i < count; ++i) {
44 const QPainterPath::Element element = path.elementAt(i);
45 switch (element.type) {
47 case QPainterPath::MoveToElement:
49 if (haveStart && haveEnd && startx == endx && starty == endy) {
51 segments.append(VG_CLOSE_PATH);
53 temp = QPointF(element.x, element.y);
56 coords.append(startx);
57 coords.append(starty);
60 segments.append(VG_MOVE_TO_ABS);
64 case QPainterPath::LineToElement:
66 temp = QPointF(element.x, element.y);
72 segments.append(VG_LINE_TO_ABS);
76 case QPainterPath::CurveToElement:
78 temp = QPointF(element.x, element.y);
79 coords.append(temp.x());
80 coords.append(temp.y());
86 case QPainterPath::CurveToDataElement:
88 temp = QPointF(element.x, element.y);
89 coords.append(temp.x());
90 coords.append(temp.y());
95 segments.append(VG_CUBIC_TO_ABS);
103 if (haveStart && haveEnd && startx == endx && starty == endy) {
105 segments.append(VG_CLOSE_PATH);
108 vgAppendPathData(vgpath, segments.count(),
109 segments.constData(), coords.constData());
115void qDrawTiled(VGImage image,
const QSize imageSize,
const QRectF &targetRect,
const QPointF offset,
float scaleX,
float scaleY) {
118 if (imageSize.width() <= 0 || imageSize.height() <= 0)
120 if (targetRect.width() <= 0 || targetRect.height() <= 0)
128 qreal yPos = targetRect.y();
132 yOff = imageSize.height() - qRound(-offset.y()) % imageSize.height();
134 yOff = qRound(offset.y()) % imageSize.height();
138 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
139 QVector<
float> originalMatrix(9);
140 vgGetMatrix(originalMatrix.data());
142 while (!qFuzzyCompare(yPos, targetRect.y() + targetRect.height()) &&
143 yPos < targetRect.y() + targetRect.height()) {
144 drawH = imageSize.height() - yOff;
145 if (yPos + drawH * scaleY > targetRect.y() + targetRect.height()) {
147 if (!qFuzzyCompare((
float)(yPos + drawH * scaleY), (
float)(targetRect.y() + targetRect.height())))
148 drawH = targetRect.y() + targetRect.height() - yPos;
150 xPos = targetRect.x();
152 xOff = imageSize.width() - qRound(-offset.x()) % imageSize.width();
154 xOff = qRound(offset.x()) % imageSize.width();
156 while (!qFuzzyCompare(xPos, targetRect.x() + targetRect.width()) &&
157 xPos < targetRect.x() + targetRect.width()) {
158 drawW = imageSize.width() - xOff;
159 if (xPos + drawW * scaleX > targetRect.x() + targetRect.width()) {
161 if (!qFuzzyCompare((
float)(xPos + drawW * scaleX), (
float)(targetRect.x() + targetRect.width())))
162 drawW = targetRect.x() + targetRect.width() - xPos;
164 if (round(drawW) > 0 && round(drawH) > 0) {
166 VGImage childRectImage = vgChildImage(image, xOff, yOff, round(drawW), round(drawH));
167 vgTranslate(xPos, yPos);
168 vgScale(scaleX, scaleY);
169 vgDrawImage(childRectImage);
170 vgDestroyImage(childRectImage);
171 vgLoadMatrix(originalMatrix.constData());
174 xPos += drawW * scaleX;
178 yPos += drawH * scaleY;
184void qDrawBorderImage(VGImage image,
const QSizeF &textureSize,
const QRectF &targetRect,
const QRectF &innerTargetRect,
const QRectF &subSourceRect)
187 QMarginsF margins(qMax(innerTargetRect.left() - targetRect.left(), qreal(0.0)),
188 qMax(innerTargetRect.top() - targetRect.top(), qreal(0.0)),
189 qMax(targetRect.right() - innerTargetRect.right(), qreal(0.0)),
190 qMax(targetRect.bottom() - innerTargetRect.bottom(), qreal(0.0)));
192 QRectF sourceRect(0, 0, textureSize.width(), textureSize.height());
195 QRectF topLeftSourceRect(sourceRect.topLeft(), QSizeF(margins.left(), margins.top()));
196 QRectF topRightSourceRect(sourceRect.width() - margins.right(), sourceRect.top(), margins.right(), margins.top());
197 QRectF bottomLeftSourceRect(sourceRect.left(), sourceRect.height() - margins.bottom(), margins.left(), margins.bottom());
198 QRectF bottomRightSourceRect(sourceRect.width() - margins.right(), sourceRect.height() - margins.bottom(), margins.right(), margins.bottom());
200 QRectF topSourceRect(margins.left(), 0.0, sourceRect.width() - (margins.right() + margins.left()), margins.top());
201 QRectF topTargetRect(margins.left(), 0.0, innerTargetRect.width(), margins.top());
202 QRectF bottomSourceRect(margins.left(), sourceRect.height() - margins.bottom(), sourceRect.width() - (margins.right() + margins.left()), margins.bottom());
203 QRectF bottomTargetRect(margins.left(), targetRect.height() - margins.bottom(), innerTargetRect.width(), margins.bottom());
204 QRectF leftSourceRect(0.0, margins.top(), margins.left(), sourceRect.height() - (margins.bottom() + margins.top()));
205 QRectF leftTargetRect(0.0, margins.top(), margins.left(), innerTargetRect.height());
206 QRectF rightSourceRect(sourceRect.width() - margins.right(), margins.top(), margins.right(), sourceRect.height() - (margins.bottom() + margins.top()));
207 QRectF rightTargetRect(targetRect.width() - margins.right(), margins.top(), margins.right(), innerTargetRect.height());
209 QRectF centerSourceRect(margins.left(), margins.top(), sourceRect.width() - (margins.right() + margins.left()), sourceRect.height() - (margins.top() + margins.bottom()));
215 targetRect.topLeft());
220 QPointF(targetRect.width() - margins.right(), 0.0));
224 bottomLeftSourceRect,
225 QPointF(targetRect.left(), targetRect.height() - margins.bottom()));
229 bottomRightSourceRect,
230 QPointF(targetRect.width() - margins.right(), targetRect.height() - margins.bottom()));
232 double scaledWidth = 1.0;
233 double scaledHeight = 1.0;
236 VGImage topImage = vgChildImage(image, topSourceRect.x(), topSourceRect.y(), topSourceRect.width(), topSourceRect.height());
237 scaledWidth = (topTargetRect.width() / subSourceRect.width()) / topSourceRect.width();
241 vgDestroyImage(topImage);
244 VGImage bottomImage = vgChildImage(image, bottomSourceRect.x(), bottomSourceRect.y(), bottomSourceRect.width(), bottomSourceRect.height());
245 scaledWidth = (bottomTargetRect.width() / subSourceRect.width()) / bottomSourceRect.width();
249 vgDestroyImage(bottomImage);
252 VGImage leftImage = vgChildImage(image, leftSourceRect.x(), leftSourceRect.y(), leftSourceRect.width(), leftSourceRect.height());
253 scaledHeight = (leftTargetRect.height() / subSourceRect.height()) / leftSourceRect.height();
256 vgDestroyImage(leftImage);
259 VGImage rightImage = vgChildImage(image, rightSourceRect.x(), rightSourceRect.y(), rightSourceRect.width(), rightSourceRect.height());
260 scaledHeight = (rightTargetRect.height() / subSourceRect.height()) / rightSourceRect.height();
264 vgDestroyImage(rightImage);
267 VGImage centerImage = vgChildImage(image, centerSourceRect.x(), centerSourceRect.y(), centerSourceRect.width(), centerSourceRect.height());
269 scaledWidth = (innerTargetRect.width() / subSourceRect.width()) / centerSourceRect.width();
270 scaledHeight = (innerTargetRect.height() / subSourceRect.height()) / centerSourceRect.height();
274 vgDestroyImage(centerImage);