• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

libkdegames/libkdegamesprivate

  • sources
  • kde-4.14
  • kdegames
  • libkdegames
  • libkdegamesprivate
kgamesvgdocument.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2007 Mark A. Taff <kde@marktaff.com> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU Library General Public License *
6  * version 2 as published by the Free Software Foundation *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU Library General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU Library General Public *
14  * License along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
17  ***************************************************************************/
18 
19 #include "kgamesvgdocument.h"
20 #include "kgamesvgdocument_p.h"
21 
22 #include <kfilterdev.h>
23 #include <kdebug.h>
24 
25 #include <QtCore/QBuffer>
26 #include <QtCore/QFile>
27 #include <QtCore/QString>
28 #include <QtCore/QStringList>
29 #include <QtXml/QDomElement>
30 #include <QtXml/QDomNode>
31 
32 #include <math.h>
33 
34 //
35 // Public
36 //
37 
45 class KGameSvgDocumentPrivate
46 {
47  public:
48 
52  KGameSvgDocumentPrivate()
53  {}
54 
55  ~KGameSvgDocumentPrivate()
56  {}
57 
66  QDomNode findElementById(const QString& attributeName, const QString& attributeValue, const QDomNode& node);
67 
72  QDomElement currentElement() const;
73 
79  void setCurrentElement();
80 
85  bool styleHasTrailingSemicolon() const;
86 
93  void setStyleHasTrailingSemicolon(bool hasSemicolon);
94 
98  QDomNode m_currentNode;
99 
103  QDomElement m_currentElement;
104 
112  QStringList m_inkscapeOrder;
113 
119  static const QString SVG_XML_PREPEND;
120 
126  static const QString SVG_XML_APPEND;
127 
131  QString m_svgFilename;
132 
136  bool m_hasSemicolon;
137 
138 
139 };
140 
141 const QString KGameSvgDocumentPrivate::SVG_XML_PREPEND = QLatin1String("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><svg>");
142 const QString KGameSvgDocumentPrivate::SVG_XML_APPEND = QLatin1String("</svg>");
143 
144 KGameSvgDocument::KGameSvgDocument()
145  : QDomDocument(), d(new KGameSvgDocumentPrivate)
146 {}
147 
148 KGameSvgDocument::KGameSvgDocument(const KGameSvgDocument &doc)
149  : QDomDocument(), d(new KGameSvgDocumentPrivate(*doc.d))
150 {
151 }
152 
153 KGameSvgDocument::~KGameSvgDocument()
154 {
155  delete d;
156 }
157 
158 KGameSvgDocument& KGameSvgDocument::operator=(const KGameSvgDocument &doc)
159 {
160  QDomDocument::operator=(doc);
161  *d = *doc.d;
162  return *this;
163 }
164 
165 QDomNode KGameSvgDocument::elementByUniqueAttributeValue(const QString& attributeName, const QString& attributeValue)
166 {
167  /* DOM is always "live", so there maybe a new root node. We always have to ask for the
168  * root node instead of keeping a pointer to it.
169  */
170  QDomElement docElem = documentElement();
171  QDomNode n = docElem.firstChild();
172 
173  QDomNode node = d->findElementById(attributeName, attributeValue, n);
174  setCurrentNode(node);
175  return node;
176 }
177 
178 QDomNode KGameSvgDocument::elementById(const QString& attributeValue)
179 {
180  return elementByUniqueAttributeValue(QLatin1String( "id" ), attributeValue);
181 }
182 
183 void KGameSvgDocument::load()
184 {
185  if (d->m_svgFilename.isNull())
186  {
187  kDebug(11000) << "KGameSvgDocument::load(): Filename not specified.";
188  return;
189  }
190 
191  QFile file(d->m_svgFilename);
192  if (!file.open(QIODevice::ReadOnly))
193  {
194  return;
195  }
196  QByteArray content = file.readAll();
197 
198  // If the file is compressed, decompress the contents before loading it.
199  if (!content.startsWith("<?xml"))
200  {
201  QBuffer buf(&content);
202  QIODevice *flt = KFilterDev::device(&buf, QString::fromLatin1("application/x-gzip"), false);
203  if (!flt || !flt->open(QIODevice::ReadOnly))
204  {
205  delete flt;
206  return;
207  }
208  QByteArray ar = flt->readAll();
209  delete flt;
210  content = ar;
211  }
212 
213  if (!setContent(content))
214  {
215  file.close();
216  kDebug(11000) << "DOM content not set.";
217  return;
218  }
219  file.close();
220 }
221 
222 void KGameSvgDocument::load(const QString& svgFilename)
223 {
224  setSvgFilename(svgFilename);
225  load();
226 }
227 
228 void KGameSvgDocument::rotate(double degrees, const MatrixOptions& options)
229 {
230  QMatrix matrix;
231 
232  if (options == ApplyToCurrentMatrix)
233  {
234  matrix = transformMatrix().QMatrix::rotate(degrees);
235  }
236  else
237  {
238  matrix = QMatrix();
239  matrix.QMatrix::rotate(degrees);
240  }
241  setTransformMatrix(matrix, ReplaceCurrentMatrix);
242 }
243 
244 void KGameSvgDocument::translate(int xPixels, int yPixels, const MatrixOptions& options)
245 {
246  QMatrix matrix;
247 
248  if (options == ApplyToCurrentMatrix)
249  {
250  matrix = transformMatrix().QMatrix::translate(xPixels, yPixels);
251  }
252  else
253  {
254  matrix = QMatrix();
255  matrix.QMatrix::translate(xPixels, yPixels);
256  }
257  setTransformMatrix(matrix, ReplaceCurrentMatrix);
258 }
259 
260 void KGameSvgDocument::shear(double xRadians, double yRadians, const MatrixOptions& options)
261 {
262  QMatrix matrix;
263 
264  if (options == ApplyToCurrentMatrix)
265  {
266  matrix = transformMatrix().QMatrix::shear(xRadians, yRadians);
267  }
268  else
269  {
270  matrix = QMatrix();
271  matrix.QMatrix::shear(xRadians, yRadians);
272  }
273  setTransformMatrix(matrix, ReplaceCurrentMatrix);
274 }
275 
276 void KGameSvgDocument::skew(double xDegrees, double yDegrees, const MatrixOptions& options)
277 {
278  double xRadians = xDegrees * (M_PI / 180);
279  double yRadians = yDegrees * (M_PI / 180);
280 
281  shear(xRadians, yRadians, options);
282 }
283 
284 void KGameSvgDocument::scale(double xFactor, double yFactor, const MatrixOptions& options)
285 {
286  QMatrix matrix;
287  if ((xFactor == 0) || (yFactor == 0))
288  {
289  kWarning () << "KGameSvgDocument::scale: You cannnot scale by zero";
290  }
291 
292  if (options == ApplyToCurrentMatrix)
293  {
294  matrix = transformMatrix().QMatrix::scale(xFactor, yFactor);
295  }
296  else
297  {
298  matrix = QMatrix();
299  matrix.QMatrix::scale(xFactor, yFactor);
300  }
301  setTransformMatrix(matrix, ReplaceCurrentMatrix);
302 }
303 
304 QDomNode KGameSvgDocument::currentNode() const
305 {
306  return d->m_currentNode;
307 }
308 
309 void KGameSvgDocument::setCurrentNode(const QDomNode& node)
310 {
311  d->m_currentNode = node;
312  d->setCurrentElement();
313 }
314 
315 QString KGameSvgDocument::svgFilename() const
316 {
317  return d->m_svgFilename;
318 }
319 
320 void KGameSvgDocument::setSvgFilename(const QString& svgFilename)
321 {
322  d->m_svgFilename = svgFilename;
323 }
324 
325 QString KGameSvgDocument::styleProperty(const QString& propertyName) const
326 {
327  return styleProperties().value(propertyName);
328 }
329 
330 void KGameSvgDocument::setStyleProperty(const QString& propertyName, const QString& propertyValue)
331 {
332  QHash<QString, QString> properties;
333 
334  properties = styleProperties();
335  properties.insert(propertyName, propertyValue);
336 
337  setStyleProperties(properties, UseInkscapeOrder);
338 }
339 
340 QString KGameSvgDocument::nodeToSvg() const
341 {
342  QString s, t, xml, defs, pattern;
343  QTextStream str(&s);
344  QTextStream str_t(&t);
345  QStringList defsAdded;
346  int result = 0;
347  QRegExp rx;
348 
349  currentNode().save(str, 1);
350  xml = *str.string();
351 
352  // Find and add any required gradients or patterns
353  pattern = QLatin1String( "url" ) + WSP_ASTERISK + OPEN_PARENS + WSP_ASTERISK + QLatin1String( "#(.*)" ) + WSP_ASTERISK + CLOSE_PARENS;
354  rx.setPattern(pattern);
355  if (rx.indexIn(xml, result) != -1)
356  {
357  QDomNode node, nodeBase;
358  QString baseId;
359  QDomNode n = def();
360 
361  result = 0;
362  while ((result = rx.indexIn(xml, result)) != -1)
363  {
364  // Find the pattern or gradient referenced
365  result += rx.matchedLength();
366  if (!defsAdded.contains(rx.cap(1)))
367  {
368  node = d->findElementById(QLatin1String( "id" ), rx.cap(1), n);
369  node.save(str_t, 1);
370  defsAdded.append(rx.cap(1));
371  }
372 
373  // Find the gradient the above gradient is based on
374  baseId = node.toElement().attribute(QLatin1String( "xlink:href" )).mid(1);
375  if (!defsAdded.contains(baseId))
376  {
377  nodeBase = d->findElementById(QLatin1String( "id" ), baseId, n);
378  nodeBase.save(str_t, 1);
379  defsAdded.append(baseId);
380  }
381  }
382  defs = *str_t.string();
383  defs = QLatin1String( "<defs>" ) + defs + QLatin1String( "</defs>" );
384  }
385 
386  // Need to make node be a real svg document, so prepend and append required tags.
387  xml = d->SVG_XML_PREPEND + defs + xml + d->SVG_XML_APPEND;
388  return xml;
389 }
390 
391 QByteArray KGameSvgDocument::nodeToByteArray() const
392 {
393  return nodeToSvg().toUtf8();
394 }
395 
396 QString KGameSvgDocument::style() const
397 {
398  return d->m_currentElement.attribute( QLatin1String( "style" ), QLatin1String( "Element has no style attribute." ));
399 }
400 
401 void KGameSvgDocument::setStyle(const QString& styleAttribute)
402 {
403  d->m_currentElement.setAttribute(QLatin1String( "style" ), styleAttribute);
404 }
405 
406 QDomNodeList KGameSvgDocument::patterns() const
407 {
408  return elementsByTagName(QLatin1String( "pattern" ));
409 }
410 
411 QDomNodeList KGameSvgDocument::linearGradients() const
412 {
413  return elementsByTagName(QLatin1String( "linearGradient" ));
414 }
415 
416 QDomNodeList KGameSvgDocument::radialGradients() const
417 {
418  return elementsByTagName(QLatin1String( "radialGradient" ));
419 }
420 
421 QDomNodeList KGameSvgDocument::defs() const
422 {
423  return elementsByTagName(QLatin1String( "defs" ));
424 }
425 
426 QDomNode KGameSvgDocument::def() const
427 {
428  return defs().at(0);
429 }
430 
431 QString KGameSvgDocument::transform() const
432 {
433  return d->m_currentElement.attribute( QLatin1String( "transform" ), QLatin1String( "Element has no transform attribute." ) );
434 }
435 
436 void KGameSvgDocument::setTransform(const QString& transformAttribute)
437 {
438  d->m_currentElement.setAttribute(QLatin1String( "transform" ), transformAttribute);
439 }
440 
441 QHash<QString, QString> KGameSvgDocument::styleProperties() const
442 {
443  QHash<QString, QString> stylePropertiesHash;
444  QStringList styleProperties, keyValuePair;
445  QString styleProperty;
446 
447  styleProperties = style().split(QLatin1Char( ';' ));
448 
449  /* The style attr may have a trailing semi-colon. If it does, split()
450  * gives us an empty final element. Remove it or we get 'index out of range' errors
451  */
452  if (styleProperties.at((styleProperties.count()-1)).isEmpty())
453  {
454  styleProperties.removeAt((styleProperties.count()-1));
455  d->setStyleHasTrailingSemicolon(true);
456  }
457  else {d->setStyleHasTrailingSemicolon(false);}
458 
459  for (int i = 0; i < styleProperties.size(); i++)
460  {
461  styleProperty = styleProperties.at(i);
462  keyValuePair = styleProperty.split(QLatin1Char( ':' ));
463  stylePropertiesHash.insert(keyValuePair.at(0), keyValuePair.at(1));
464  }
465  return stylePropertiesHash;
466 }
467 
468 void KGameSvgDocument::setStyleProperties(const QHash<QString, QString>& _styleProperties, const StylePropertySortOptions& options)
469 {
470  QHash<QString, QString> styleProperties = _styleProperties;
471  QString styleBuffer, property;
472 
473  d->m_inkscapeOrder << QLatin1String( "fill" ) << QLatin1String( "fill-opacity" ) << QLatin1String( "fill-rule" ) << QLatin1String( "stroke" ) << QLatin1String( "stroke-width" ) << QLatin1String( "stroke-linecap" )
474  << QLatin1String( "stroke-linejoin" ) << QLatin1String( "stroke-miterlimit" ) << QLatin1String( "stroke-dasharray" ) << QLatin1String( "stroke-opacity" );
475 
476  if (options == UseInkscapeOrder)
477  {
478  for (int i = 0; i < d->m_inkscapeOrder.size(); i++)
479  {
480  property = d->m_inkscapeOrder.at(i);
481  if (styleProperties.contains(property))
482  {
483  styleBuffer += property + QLatin1Char( ':' ) + styleProperties.take(property) + QLatin1Char( ';' );
484  }
485  else
486  {
487  // Do Nothing
488  }
489  }
490  }
491 
492  // Append any style properties
493  if (!styleProperties.isEmpty())
494  {
495  QHashIterator<QString, QString> it(styleProperties);
496  while (it.hasNext())
497  {
498  it.next();
499  styleBuffer += it.key() + QLatin1Char( ':' ) + it.value() + QLatin1Char( ';' );
500  }
501  }
502 
503  // Remove trailing semicolon if original didn't have one
504  if (!d->styleHasTrailingSemicolon()) {styleBuffer.chop(1);}
505  setStyle(styleBuffer);
506 }
507 
508 QMatrix KGameSvgDocument::transformMatrix() const
509 {
510  /*
511  * Transform attributes can be quite complex. Here, we assemble this tangled web of
512  * complexity into an single matrix.
513  *
514  * The regex's that make this bearable live in kgamesvgdocument_p.h. As these regex's
515  * get quite complex, we have some code in tests/kgamesvgdocumenttest.cpp to help verify
516  * they are still correct after being edited.
517  *
518  * Warning: This code depends on the capturing parenthesis in the regex's not changing.
519  *
520  * For all the gory details, see http://www.w3.org/TR/SVG/coords.html#TransformAttribute
521  */
522  QRegExp rx;
523  QString transformAttribute;
524  int result;
525  int i = 0;
526  QMatrix baseMatrix = QMatrix();
527 
528  transformAttribute = transform();
529  if (transformAttribute == QLatin1String( "Element has no transform attribute." ))
530  {
531  return QMatrix();
532  }
533  transformAttribute.trimmed();
534 
535  rx.setPattern(TRANSFORMS);
536  if (!rx.exactMatch(transformAttribute))
537  {
538  kWarning () << "Transform attribute seems to be invalid. Check your SVG file.";
539  return QMatrix();
540  }
541 
542  rx.setPattern(TRANSFORM);
543 
544  while (transformAttribute.size() > 0 && i < 32) // 32 is an arbitrary limit for the number of transforms for a single node
545  {
546  result = rx.indexIn(transformAttribute);
547  if (result != -1) // Found left-most transform
548  {
549  if (rx.cap(1) == QLatin1String( "matrix" ))
550  {
551  // If the first transform found is a matrix, use it as the base,
552  // else we use a null matrix.
553  if (i == 0)
554  {
555  baseMatrix = QMatrix(rx.cap(2).toDouble(), rx.cap(3).toDouble(), rx.cap(4).toDouble(),
556  rx.cap(5).toDouble(), rx.cap(6).toDouble(), rx.cap(7).toDouble());
557  }
558  else
559  {
560  baseMatrix = QMatrix(rx.cap(2).toDouble(), rx.cap(3).toDouble(), rx.cap(4).toDouble(),
561  rx.cap(5).toDouble(), rx.cap(6).toDouble(), rx.cap(7).toDouble()) * baseMatrix;
562  }
563  }
564 
565  if (rx.cap(8) == QLatin1String( "translate" ))
566  {
567  double x = rx.cap(9).toDouble();
568  double y = rx.cap(10).toDouble();
569  if (rx.cap(10).isEmpty()) // y defaults to zero per SVG standard
570  {
571  y = 0;
572  }
573  baseMatrix = baseMatrix.translate(x, y);
574  }
575 
576  if (rx.cap(11) == QLatin1String( "scale" ))
577  {
578  double x = rx.cap(12).toDouble();
579  double y = rx.cap(12).toDouble();
580  if (rx.cap(13).isEmpty()) // y defaults to x per SVG standard
581  {
582  y = x;
583  }
584  baseMatrix = baseMatrix.scale(x, y);
585  }
586 
587  if (rx.cap(14) == QLatin1String( "rotate" ))
588  {
589  double a = rx.cap(15).toDouble();
590  double cx = rx.cap(16).toDouble();
591  double cy = rx.cap(17).toDouble();
592 
593  if ((cx > 0) || (cy > 0)) // rotate around point (cx, cy)
594  {
595  baseMatrix.translate(cx, cy);
596  baseMatrix.rotate(a);
597  baseMatrix.translate((cx * -1), (cy * -1));
598  }
599  else
600  {
601  baseMatrix = baseMatrix.rotate(a); // rotate around origin
602  }
603  }
604 
605  if (rx.cap(18) == QLatin1String( "skewX" ))
606  {
607  baseMatrix = baseMatrix.shear(rx.cap(19).toDouble() * (M_PI / 180), 0);
608  }
609 
610  if (rx.cap(20) == QLatin1String( "skewY" ))
611  {
612  baseMatrix = baseMatrix.shear(0, rx.cap(21).toDouble() * (M_PI / 180));
613  }
614  }
615  transformAttribute = transformAttribute.mid(rx.matchedLength() + result);
616  i++;
617  }
618 
619  return baseMatrix;
620 }
621 
622 void KGameSvgDocument::setTransformMatrix(QMatrix& matrix, const MatrixOptions& options)
623 {
624  QString transformBuffer, tmp;
625  QMatrix null = QMatrix();
626 
627  if (options == ApplyToCurrentMatrix)
628  {
629  matrix = transformMatrix() * matrix;
630  }
631 
632  transformBuffer = QLatin1String( "matrix(" );
633  transformBuffer += tmp.setNum(matrix.m11(),'g',7) + QLatin1Char( ',' );
634  transformBuffer += tmp.setNum(matrix.m12(),'g',7) + QLatin1Char( ',' );
635  transformBuffer += tmp.setNum(matrix.m21(),'g',7) + QLatin1Char( ',' );
636  transformBuffer += tmp.setNum(matrix.m22(),'g',7) + QLatin1Char( ',' );
637  transformBuffer += tmp.setNum(matrix.dx(),'g',7) + QLatin1Char( ',' );
638  transformBuffer += tmp.setNum(matrix.dy(),'g',7) + QLatin1Char( ')' );
639 
640  if ((transform() == QLatin1String( "Element has no transform attribute." )) && (matrix == null))
641  {
642  // Do not write a meaningless matrix to DOM
643  }
644  else
645  {
646  setTransform(transformBuffer);
647  }
648 }
649 
650 
651 //
652 // Private
653 //
654 
655 QDomNode KGameSvgDocumentPrivate::findElementById(const QString& attributeName, const QString& attributeValue, const QDomNode& node)
656 {
657  QDomElement e = node.toElement(); // try to convert the node to an element.
658  QString value = e.attribute( attributeName, QLatin1String( "Element has no attribute with that name." ));
659 
660  if (value == attributeValue)
661  {
662  // We found our node. Stop recursion and return it.
663  return node;
664  }
665 
666  if (!node.firstChild().isNull())
667  {
668  QDomNode result = findElementById(attributeName, attributeValue, node.firstChild());
672  if (!result.isNull()) return result; // If we found the node with id, then return it
673  }
674  if (!node.nextSibling().isNull())
675  {
676  QDomNode result = findElementById(attributeName, attributeValue, node.nextSibling());
679  if (!result.isNull()) return result;
680  }
681  if (!node.firstChild().isNull() && !node.nextSibling().isNull())
682  {
683  // Do Nothing
684  //kDebug(11000) << "No children or siblings.";
685  }
686 
687  // Matching node not found, so return a null node.
688  return QDomNode();
689 }
690 
691 QDomElement KGameSvgDocumentPrivate::currentElement() const
692 {
693  return m_currentElement;
694 }
695 
696 void KGameSvgDocumentPrivate::setCurrentElement()
697 {
698  m_currentElement = m_currentNode.toElement();
699 }
700 
701 bool KGameSvgDocumentPrivate::styleHasTrailingSemicolon() const
702 {
703  return m_hasSemicolon;
704 }
705 
706 void KGameSvgDocumentPrivate::setStyleHasTrailingSemicolon(bool hasSemicolon)
707 {
708  m_hasSemicolon = hasSemicolon;
709 }
710 
QIODevice
QRegExp::cap
QString cap(int nth) const
QHash::insert
iterator insert(const Key &key, const T &value)
KGameSvgDocument::svgFilename
QString svgFilename() const
Returns the name of the SVG file this DOM represents.
Definition: kgamesvgdocument.cpp:315
KGameSvgDocument::setSvgFilename
void setSvgFilename(const QString &svgFilename)
Sets the current SVG filename.
Definition: kgamesvgdocument.cpp:320
QByteArray
QHashIterator::key
const Key & key() const
KGameSvgDocument::setTransform
void setTransform(const QString &transformAttribute)
Sets the transform attribute of the current node.
Definition: kgamesvgdocument.cpp:436
QDomElement::attribute
QString attribute(const QString &name, const QString &defValue) const
kgamesvgdocument_p.h
This file contains the regexs for parsing the transform attribute of an SVG file using DOM...
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QHashIterator::hasNext
bool hasNext() const
KGameSvgDocument::transformMatrix
QMatrix transformMatrix() const
Returns the transform attribute of the current node as a matrix.
Definition: kgamesvgdocument.cpp:508
QDomNodeList
QList::at
const T & at(int i) const
QString::size
int size() const
QList::removeAt
void removeAt(int i)
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
KGameSvgDocument::styleProperty
QString styleProperty(const QString &propertyName) const
Returns the value of the style property given for the current node.
Definition: kgamesvgdocument.cpp:325
QByteArray::startsWith
bool startsWith(const QByteArray &ba) const
KGameSvgDocument::styleProperties
QHash< QString, QString > styleProperties() const
Returns a hash of the style properties of the current node.
Definition: kgamesvgdocument.cpp:441
KGameSvgDocument::style
QString style() const
Returns the style attribute of the current node.
Definition: kgamesvgdocument.cpp:396
QBuffer
QDomDocument::documentElement
QDomElement documentElement() const
QDomNode
KGameSvgDocument::defs
QDomNodeList defs() const
Returns the defs in the document.
Definition: kgamesvgdocument.cpp:421
KGameSvgDocument::radialGradients
QDomNodeList radialGradients() const
Returns the radialGradients in the document.
Definition: kgamesvgdocument.cpp:416
QIODevice::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QString::chop
void chop(int n)
QString::toDouble
double toDouble(bool *ok) const
KGameSvgDocument::setTransformMatrix
void setTransformMatrix(QMatrix &matrix, const MatrixOptions &options=ApplyToCurrentMatrix)
Sets the transform attribute of the current node.
Definition: kgamesvgdocument.cpp:622
QFile
QTextStream
QList::size
int size() const
QDomNode::nextSibling
QDomNode nextSibling() const
QRegExp::setPattern
void setPattern(const QString &pattern)
QDomNode::toElement
QDomElement toElement() const
QRegExp::matchedLength
int matchedLength() const
QMatrix::m21
qreal m21() const
QMatrix::m22
qreal m22() const
QMatrix::m11
qreal m11() const
QMatrix::m12
qreal m12() const
QRegExp::indexIn
int indexIn(const QString &str, int offset, CaretMode caretMode) const
QRegExp
QFlags
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
QMatrix::dx
qreal dx() const
QMatrix::dy
qreal dy() const
KGameSvgDocument::UseInkscapeOrder
When building a style attribute, sort properties the same way Inkscape does.
Definition: kgamesvgdocument.h:165
KGameSvgDocument::shear
void shear(double xRadians, double yRadians, const MatrixOptions &options=ApplyToCurrentMatrix)
Shears the origin of the current node.
Definition: kgamesvgdocument.cpp:260
QHash
TRANSFORMS
static const QString TRANSFORMS
A regex that matches the entire transform attribute.
Definition: kgamesvgdocument_p.h:121
QMatrix::translate
QMatrix & translate(qreal dx, qreal dy)
QDomDocument::elementsByTagName
QDomNodeList elementsByTagName(const QString &tagname) const
QHashIterator
QString::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
KGameSvgDocument::~KGameSvgDocument
virtual ~KGameSvgDocument()
Destructor.
Definition: kgamesvgdocument.cpp:153
QIODevice::readAll
QByteArray readAll()
TRANSFORM
static const QString TRANSFORM
A regex that matches any single transform.
Definition: kgamesvgdocument_p.h:115
KGameSvgDocument
A class for manipulating an SVG file using DOM.
Definition: kgamesvgdocument.h:115
KGameSvgDocument::currentNode
QDomNode currentNode() const
Returns the last node found by elementById, or null if node not found.
Definition: kgamesvgdocument.cpp:304
KGameSvgDocument::operator=
KGameSvgDocument & operator=(const KGameSvgDocument &doc)
Assignment Operator.
Definition: kgamesvgdocument.cpp:158
QString
KGameSvgDocument::setStyleProperties
void setStyleProperties(const QHash< QString, QString > &_styleProperties, const StylePropertySortOptions &options=Unsorted)
Sets the style properties of the current node.
Definition: kgamesvgdocument.cpp:468
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
kgamesvgdocument.h
This file contains the KGameSvgDocument class, used for manipulating an SVG file using DOM...
QStringList
KGameSvgDocument::transform
QString transform() const
Returns the transform attribute of the current node.
Definition: kgamesvgdocument.cpp:431
QHashIterator::next
Item next()
QLatin1Char
KGameSvgDocument::skew
void skew(double xDegrees, double yDegrees, const MatrixOptions &options=ApplyToCurrentMatrix)
Skews the origin of the current node.
Definition: kgamesvgdocument.cpp:276
QDomDocument
KGameSvgDocument::load
void load()
Reads the SVG file svgFilename() into DOM.
Definition: kgamesvgdocument.cpp:183
WSP_ASTERISK
static const QString WSP_ASTERISK
A regex that matches zero or more whitespace.
Definition: kgamesvgdocument_p.h:38
QFile::close
virtual void close()
KGameSvgDocument::scale
void scale(double xFactor, double yFactor, const MatrixOptions &options=ApplyToCurrentMatrix)
Scales the origin of the current node.
Definition: kgamesvgdocument.cpp:284
QDomNode::isNull
bool isNull() const
QMatrix::rotate
QMatrix & rotate(qreal degrees)
KGameSvgDocument::ReplaceCurrentMatrix
Replace the current matrix.
Definition: kgamesvgdocument.h:149
KGameSvgDocument::translate
void translate(int xPixels, int yPixels, const MatrixOptions &options=ApplyToCurrentMatrix)
Moves the origin of the current node.
Definition: kgamesvgdocument.cpp:244
QTextStream::string
QString * string() const
QDomNode::save
void save(QTextStream &str, int indent) const
QDomNode::firstChild
QDomNode firstChild() const
QString::mid
QString mid(int position, int n) const
QHash::take
T take(const Key &key)
KGameSvgDocument::KGameSvgDocument
KGameSvgDocument()
Constructor.
Definition: kgamesvgdocument.cpp:144
QLatin1String
QHash::isEmpty
bool isEmpty() const
QDomDocument::operator=
QDomDocument & operator=(const QDomDocument &x)
QString::setNum
QString & setNum(short n, int base)
OPEN_PARENS
static const QString OPEN_PARENS
A regex that matches opening parenthesis.
Definition: kgamesvgdocument_p.h:60
CLOSE_PARENS
static const QString CLOSE_PARENS
A regex that matches closing parenthesis.
Definition: kgamesvgdocument_p.h:65
QMatrix
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KGameSvgDocument::nodeToSvg
QString nodeToSvg() const
Returns the current node and it's children as a new xml svg document.
Definition: kgamesvgdocument.cpp:340
QHash::contains
bool contains(const Key &key) const
KGameSvgDocument::ApplyToCurrentMatrix
Apply to current matrix.
Definition: kgamesvgdocument.h:145
KGameSvgDocument::elementByUniqueAttributeValue
QDomNode elementByUniqueAttributeValue(const QString &attributeName, const QString &attributeValue)
Returns the node with the given value for the given attribute.
Definition: kgamesvgdocument.cpp:165
QHashIterator::value
const T & value() const
KGameSvgDocument::def
QDomNode def() const
Returns the first def in the document.
Definition: kgamesvgdocument.cpp:426
KGameSvgDocument::patterns
QDomNodeList patterns() const
Returns the patterns in the document.
Definition: kgamesvgdocument.cpp:406
KGameSvgDocument::linearGradients
QDomNodeList linearGradients() const
Returns the linearGradients in the document.
Definition: kgamesvgdocument.cpp:411
KGameSvgDocument::nodeToByteArray
QByteArray nodeToByteArray() const
Builds a new svg document and returns a QByteArray suitable for passing to QSvgRenderer::load().
Definition: kgamesvgdocument.cpp:391
KGameSvgDocument::setCurrentNode
void setCurrentNode(const QDomNode &node)
Sets the current node.
Definition: kgamesvgdocument.cpp:309
KGameSvgDocument::elementById
QDomNode elementById(const QString &attributeValue)
Returns a node with the given id.
Definition: kgamesvgdocument.cpp:178
KGameSvgDocument::setStyle
void setStyle(const QString &styleAttribute)
Sets the style attribute of the current node.
Definition: kgamesvgdocument.cpp:401
QDomElement
KGameSvgDocument::rotate
void rotate(double degrees, const MatrixOptions &options=ApplyToCurrentMatrix)
Rotates the origin of the current node counterclockwise.
Definition: kgamesvgdocument.cpp:228
QRegExp::exactMatch
bool exactMatch(const QString &str) const
KGameSvgDocument::setStyleProperty
void setStyleProperty(const QString &propertyName, const QString &propertyValue)
Sets the value of the style property given for the current node.
Definition: kgamesvgdocument.cpp:330
QMatrix::scale
QMatrix & scale(qreal sx, qreal sy)
QDomNodeList::at
QDomNode at(int index) const
QDomDocument::setContent
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
QMatrix::shear
QMatrix & shear(qreal sh, qreal sv)
QString::toUtf8
QByteArray toUtf8() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdegames/libkdegamesprivate

Skip menu "libkdegames/libkdegamesprivate"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal