MCPcopy Create free account
hub / github.com/OpenBoard-org/OpenBoard / parseSvgRect

Method parseSvgRect

src/adaptors/UBCFFSubsetAdaptor.cpp:219–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &element)
220{
221 qreal x1 = element.attribute(aX).toDouble();
222 qreal y1 = element.attribute(aY).toDouble();
223 //rect dimensions
224 qreal width = element.attribute(aWidth).toDouble();
225 qreal height = element.attribute(aHeight).toDouble();
226
227 QString textFillColor = element.attribute(aFill);
228 QString textStrokeColor = element.attribute(aStroke);
229 QString textStrokeWidth = element.attribute(aStrokewidth);
230
231 QColor fillColor = !textFillColor.isNull() ? colorFromString(textFillColor) : QColor();
232 QColor strokeColor = !textStrokeColor.isNull() ? colorFromString(textStrokeColor) : QColor();
233 int strokeWidth = textStrokeWidth.toInt();
234
235 x1 -= strokeWidth/2;
236 y1 -= strokeWidth/2;
237 width += strokeWidth;
238 height += strokeWidth;
239
240 //init svg generator with temp file
241 QSvgGenerator *generator = createSvgGenerator(width, height);
242
243 //init painter to paint to svg
244 QPainter painter;
245
246 painter.begin(generator);
247
248 //fill rect
249 if (fillColor.isValid()) {
250 painter.setBrush(QBrush(fillColor));
251 painter.fillRect(0, 0, width, height, fillColor);
252 }
253 QPen pen;
254 if (strokeColor.isValid()) {
255 pen.setColor(strokeColor);
256 }
257 if (strokeWidth)
258 pen.setWidth(strokeWidth);
259 painter.setPen(pen);
260 painter.drawRect(0, 0, width, height);
261
262 painter.end();
263
264 UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName()));
265
266 QString uuid = QUuid::createUuid().toString();
267 mRefToUuidMap.insert(element.attribute(aId), uuid);
268 svgItem->setUuid(QUuid(uuid));
269
270 QTransform transform;
271 QString textTransform = element.attribute(aTransform);
272
273 svgItem->resetTransform();
274 if (!textTransform.isNull()) {
275 transform = transformFromString(textTransform, svgItem);
276 }

Callers

nothing calls this directly

Calls 6

setWidthMethod · 0.80
addSvgMethod · 0.80
isValidMethod · 0.45
setColorMethod · 0.45
insertMethod · 0.45
setUuidMethod · 0.45

Tested by

no test coverage detected