Qt 4.8
Public Types | Public Functions | Private Types | Private Functions | Properties | List of all members
QSvgHandler Class Reference

#include <qsvghandler_p.h>

Public Types

enum  LengthType {
  LT_PERCENT, LT_PX, LT_PC, LT_PT,
  LT_MM, LT_CM, LT_IN, LT_OTHER
}
 

Public Functions

int animationDuration () const
 
bool characters (const QStringRef &str)
 
QColor currentColor () const
 
LengthType defaultCoordinateSystem () const
 
QPen defaultPen () const
 
QSvgTinyDocumentdocument () const
 
bool endElement (const QStringRef &localName)
 
QString errorString () const
 
bool inStyle () const
 
int lineNumber () const
 
bool ok () const
 
void parseCSStoXMLAttrs (QString css, QVector< QSvgCssAttribute > *attributes)
 
void popColor ()
 
bool processingInstruction (const QString &target, const QString &data)
 
void pushColor (const QColor &color)
 
void pushColorCopy ()
 
 QSvgHandler (QIODevice *device)
 
 QSvgHandler (const QByteArray &data)
 
 QSvgHandler (QXmlStreamReader *const data)
 
QSvgStyleSelectorselector () const
 
void setAnimPeriod (int start, int end)
 
void setDefaultCoordinateSystem (LengthType type)
 
void setInStyle (bool b)
 
bool startElement (const QString &localName, const QXmlStreamAttributes &attributes)
 
 ~QSvgHandler ()
 

Private Types

enum  CurrentNode { Unknown, Graphics, Style }
 

Private Functions

void init ()
 
void parse ()
 
void resolveGradients (QSvgNode *node)
 

Properties

int m_animEnd
 
QStack< QColorm_colorStack
 
QStack< int > m_colorTagCount
 
QCss::Parser m_cssParser
 
LengthType m_defaultCoords
 
QPen m_defaultPen
 
QSvgTinyDocumentm_doc
 
bool m_inStyle
 
QStack< QSvgNode * > m_nodes
 
const bool m_ownsReader
 
QList< QSvgNode * > m_resolveNodes
 
QSvgStyleSelectorm_selector
 
QStack< CurrentNodem_skipNodes
 
QSvgRefCounter< QSvgStylePropertym_style
 
QStack< QSvgText::WhitespaceModem_whitespaceMode
 Follows the depths of elements. More...
 
QXmlStreamReader *const xml
 

Detailed Description

Definition at line 81 of file qsvghandler_p.h.

Enumerations

◆ CurrentNode

Enumerator
Unknown 
Graphics 
Style 

Definition at line 145 of file qsvghandler_p.h.

◆ LengthType

Enumerator
LT_PERCENT 
LT_PX 
LT_PC 
LT_PT 
LT_MM 
LT_CM 
LT_IN 
LT_OTHER 

Definition at line 84 of file qsvghandler_p.h.

Constructors and Destructors

◆ QSvgHandler() [1/3]

QSvgHandler::QSvgHandler ( QIODevice device)

Definition at line 3513 of file qsvghandler.cpp.

3513  : xml(new QXmlStreamReader(device))
3514  , m_ownsReader(true)
3515 {
3516  init();
3517 }
const bool m_ownsReader
QXmlStreamReader *const xml
The QXmlStreamReader class provides a fast parser for reading well-formed XML via a simple streaming ...
Definition: qxmlstream.h:290

◆ QSvgHandler() [2/3]

QSvgHandler::QSvgHandler ( const QByteArray data)

Definition at line 3519 of file qsvghandler.cpp.

3519  : xml(new QXmlStreamReader(data))
3520  , m_ownsReader(true)
3521 {
3522  init();
3523 }
const bool m_ownsReader
QXmlStreamReader *const xml
The QXmlStreamReader class provides a fast parser for reading well-formed XML via a simple streaming ...
Definition: qxmlstream.h:290

◆ QSvgHandler() [3/3]

QSvgHandler::QSvgHandler ( QXmlStreamReader *const  data)

Definition at line 3525 of file qsvghandler.cpp.

3525  : xml(reader)
3526  , m_ownsReader(false)
3527 {
3528  init();
3529 }
const bool m_ownsReader
QXmlStreamReader *const xml

◆ ~QSvgHandler()

QSvgHandler::~QSvgHandler ( )

Definition at line 3912 of file qsvghandler.cpp.

3913 {
3914  delete m_selector;
3915  m_selector = 0;
3916 
3917  if(m_ownsReader)
3918  delete xml;
3919 }
const bool m_ownsReader
QXmlStreamReader *const xml
QSvgStyleSelector * m_selector

Functions

◆ animationDuration()

int QSvgHandler::animationDuration ( ) const

Definition at line 3907 of file qsvghandler.cpp.

Referenced by QSvgTinyDocument::load().

3908 {
3909  return m_animEnd;
3910 }

◆ characters()

bool QSvgHandler::characters ( const QStringRef str)

Definition at line 3777 of file qsvghandler.cpp.

Referenced by parse().

3778 {
3779  if (m_inStyle) {
3780  QString css = str.toString();
3781  QCss::StyleSheet sheet;
3782  QCss::Parser(css).parse(&sheet);
3783  m_selector->styleSheets.append(sheet);
3784  return true;
3785  } else if (m_skipNodes.isEmpty() || m_skipNodes.top() == Unknown || m_nodes.isEmpty())
3786  return true;
3787 
3788  if (m_nodes.top()->type() == QSvgNode::TEXT || m_nodes.top()->type() == QSvgNode::TEXTAREA) {
3789  static_cast<QSvgText*>(m_nodes.top())->addText(str.toString());
3790  } else if (m_nodes.top()->type() == QSvgNode::TSPAN) {
3791  static_cast<QSvgTspan*>(m_nodes.top())->addText(str.toString());
3792  }
3793 
3794  return true;
3795 }
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
virtual Type type() const =0
The QString class provides a Unicode character string.
Definition: qstring.h:83
QStack< QSvgNode * > m_nodes
QVector< StyleSheet > styleSheets
Definition: qcssparser_p.h:675
QStack< CurrentNode > m_skipNodes
bool parse(StyleSheet *styleSheet, Qt::CaseSensitivity nameCaseSensitivity=Qt::CaseSensitive)
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
QSvgStyleSelector * m_selector
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ currentColor()

QColor QSvgHandler::currentColor ( ) const

Definition at line 3836 of file qsvghandler.cpp.

Referenced by resolveColor().

3837 {
3838  if (!m_colorStack.isEmpty())
3839  return m_colorStack.top();
3840  else
3841  return QColor(0, 0, 0);
3842 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
QStack< QColor > m_colorStack
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ defaultCoordinateSystem()

QSvgHandler::LengthType QSvgHandler::defaultCoordinateSystem ( ) const

Definition at line 3802 of file qsvghandler.cpp.

Referenced by parseLength().

3803 {
3804  return m_defaultCoords;
3805 }
LengthType m_defaultCoords

◆ defaultPen()

QPen QSvgHandler::defaultPen ( ) const
inline

Definition at line 128 of file qsvghandler_p.h.

129  { return m_defaultPen; }

◆ document()

QSvgTinyDocument * QSvgHandler::document ( ) const

Definition at line 3797 of file qsvghandler.cpp.

Referenced by QSvgTinyDocument::load(), and parseBaseGradient().

3798 {
3799  return m_doc;
3800 }
QSvgTinyDocument * m_doc

◆ endElement()

bool QSvgHandler::endElement ( const QStringRef localName)

Definition at line 3716 of file qsvghandler.cpp.

Referenced by parse().

3717 {
3718  CurrentNode node = m_skipNodes.top();
3719  m_skipNodes.pop();
3721 
3722  popColor();
3723 
3724  if (node == Unknown) {
3725  return true;
3726  }
3727 
3728  if (m_inStyle && localName == QLatin1String("style"))
3729  m_inStyle = false;
3730 
3731  if (node == Graphics)
3732  m_nodes.pop();
3733  else if (m_style && !m_skipNodes.isEmpty() && m_skipNodes.top() != Style)
3734  m_style = 0;
3735 
3736  return true;
3737 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QStack< QSvgNode * > m_nodes
QStack< CurrentNode > m_skipNodes
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
QSvgRefCounter< QSvgStyleProperty > m_style
QStack< QSvgText::WhitespaceMode > m_whitespaceMode
Follows the depths of elements.
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ errorString()

QString QSvgHandler::errorString ( ) const
inline

Definition at line 107 of file qsvghandler_p.h.

Referenced by QSvgTinyDocument::load().

107 { return xml->errorString(); }
QXmlStreamReader *const xml
QString errorString() const
Returns the error message that was set with raiseError().

◆ init()

void QSvgHandler::init ( )
private

Definition at line 3531 of file qsvghandler.cpp.

Referenced by QSvgHandler().

3532 {
3533  m_doc = 0;
3534  m_style = 0;
3535  m_animEnd = 0;
3539  parse();
3540 }
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
LengthType m_defaultCoords
QSvgRefCounter< QSvgStyleProperty > m_style
QSvgTinyDocument * m_doc
void setMiterLimit(qreal limit)
Sets the miter limit of this pen to the given limit.
Definition: qpen.cpp:611

◆ inStyle()

bool QSvgHandler::inStyle ( ) const

Definition at line 3849 of file qsvghandler.cpp.

3850 {
3851  return m_inStyle;
3852 }

◆ lineNumber()

int QSvgHandler::lineNumber ( ) const
inline

Definition at line 108 of file qsvghandler_p.h.

Referenced by QSvgTinyDocument::load().

108 { return xml->lineNumber(); }
qint64 lineNumber() const
Returns the current line number, starting with 1.
QXmlStreamReader *const xml

◆ ok()

bool QSvgHandler::ok ( ) const
inline

Definition at line 103 of file qsvghandler_p.h.

Referenced by QSvgTinyDocument::load().

103  {
104  return document() != 0 && !xml->hasError();
105  }
QSvgTinyDocument * document() const
QXmlStreamReader *const xml
bool hasError() const
Returns true if an error has occurred, otherwise false.
Definition: qxmlstream.h:396

◆ parse()

void QSvgHandler::parse ( )
private

Definition at line 3542 of file qsvghandler.cpp.

Referenced by init().

3543 {
3544  xml->setNamespaceProcessing(false);
3546  m_inStyle = false;
3547  bool done = false;
3548  while (!xml->atEnd() && !done) {
3549  switch (xml->readNext()) {
3551  // he we could/should verify the namespaces, and simply
3552  // call m_skipNodes(Unknown) if we don't know the
3553  // namespace. We do support http://www.w3.org/2000/svg
3554  // but also http://www.w3.org/2000/svg-20000303-stylable
3555  // And if the document uses an external dtd, the reported
3556  // namespaceUri is empty. The only possible strategy at
3557  // this point is to do what everyone else seems to do and
3558  // ignore the reported namespaceUri completely.
3559  if (!startElement(xml->name().toString(), xml->attributes())) {
3560  delete m_doc;
3561  m_doc = 0;
3562  return;
3563  }
3564  break;
3566  endElement(xml->name());
3567  // if we are using somebody else's qxmlstreamreader
3568  // we should not read until the end of the stream
3569  done = !m_ownsReader && (xml->name() == QLatin1String("svg"));
3570  break;
3572  characters(xml->text());
3573  break;
3576  break;
3577  default:
3578  break;
3579  }
3580  }
3582 }
QString toString() const
Returns a copy of the string reference as a QString object.
Definition: qstring.cpp:8653
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QStringRef name() const
Returns the local name of a StartElement, EndElement, or an EntityReference.
bool atEnd() const
Returns true if the reader has read until the end of the XML document, or if an error() has occurred ...
Definition: qxmlstream.cpp:590
const bool m_ownsReader
QXmlStreamReader *const xml
void resolveGradients(QSvgNode *node)
bool endElement(const QStringRef &localName)
TokenType readNext()
Reads the next token and returns its type.
Definition: qxmlstream.cpp:623
QStringRef processingInstructionData() const
Returns the data of a ProcessingInstruction.
bool startElement(const QString &localName, const QXmlStreamAttributes &attributes)
bool characters(const QStringRef &str)
bool processingInstruction(const QString &target, const QString &data)
QStringRef processingInstructionTarget() const
Returns the target of a ProcessingInstruction.
QStringRef text() const
Returns the text of Characters , Comment , DTD , or EntityReference.
void setNamespaceProcessing(bool)
Definition: qxmlstream.cpp:782
QXmlStreamAttributes attributes() const
Returns the attributes of a StartElement.
QSvgStyleSelector * m_selector
QSvgTinyDocument * m_doc

◆ parseCSStoXMLAttrs()

void QSvgHandler::parseCSStoXMLAttrs ( QString  css,
QVector< QSvgCssAttribute > *  attributes 
)

Definition at line 1923 of file qsvghandler.cpp.

Referenced by QSvgAttributes::QSvgAttributes().

1924 {
1925  // preprocess (for unicode escapes), tokenize and remove comments
1926  m_cssParser.init(css);
1927  QString key;
1928 
1929  attributes->reserve(10);
1930 
1931  while (m_cssParser.hasNext()) {
1933 
1934  if (!m_cssParser.hasNext())
1935  break;
1936  m_cssParser.next();
1937 
1938  QStringRef name;
1940  key = m_cssParser.lexem();
1941  name = QStringRef(&key, 0, key.length());
1942  } else {
1943  const QCss::Symbol &sym = m_cssParser.symbol();
1944  name = QStringRef(&sym.text, sym.start, sym.len);
1945  }
1946 
1949  break;
1950 
1952  if (!m_cssParser.hasNext())
1953  break;
1954 
1955  QSvgCssAttribute attribute;
1956  attribute.name = QXmlStreamStringRef(name);
1957 
1958  const int firstSymbol = m_cssParser.index;
1959  int symbolCount = 0;
1960  do {
1961  m_cssParser.next();
1962  ++symbolCount;
1964 
1965  bool canExtractValueByRef = !m_cssParser.hasEscapeSequences;
1966  if (canExtractValueByRef) {
1967  int len = m_cssParser.symbols.at(firstSymbol).len;
1968  for (int i = firstSymbol + 1; i < firstSymbol + symbolCount; ++i) {
1969  len += m_cssParser.symbols.at(i).len;
1970 
1971  if (m_cssParser.symbols.at(i - 1).start + m_cssParser.symbols.at(i - 1).len
1972  != m_cssParser.symbols.at(i).start) {
1973  canExtractValueByRef = false;
1974  break;
1975  }
1976  }
1977  if (canExtractValueByRef) {
1978  const QCss::Symbol &sym = m_cssParser.symbols.at(firstSymbol);
1979  attribute.value = QXmlStreamStringRef(QStringRef(&sym.text, sym.start, len));
1980  }
1981  }
1982  if (!canExtractValueByRef) {
1983  QString value;
1984  for (int i = firstSymbol; i < m_cssParser.index - 1; ++i)
1985  value += m_cssParser.symbols.at(i).lexem();
1986  attribute.value = QXmlStreamStringRef(QStringRef(&value, 0, value.length()));
1987  }
1988 
1989  attributes->append(attribute);
1990 
1992  }
1993 }
QXmlStreamStringRef name
Definition: qsvghandler_p.h:77
QString text
Definition: qcssparser_p.h:737
bool hasNext() const
Definition: qcssparser_p.h:811
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QCss::Parser m_cssParser
The QString class provides a Unicode character string.
Definition: qstring.h:83
void skipSpace()
Definition: qcssparser_p.h:809
QVector< Symbol > symbols
Definition: qcssparser_p.h:829
const Symbol & symbol() const
Definition: qcssparser_p.h:816
TokenType next()
Definition: qcssparser_p.h:812
const char * name
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
int key
QString lexem() const
Definition: qcssparser_p.h:817
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
bool test(TokenType t)
bool hasEscapeSequences
Definition: qcssparser_p.h:832
QXmlStreamStringRef value
Definition: qsvghandler_p.h:78
void init(const QString &css, bool file=false)

◆ popColor()

void QSvgHandler::popColor ( )

Definition at line 3826 of file qsvghandler.cpp.

Referenced by endElement(), parseBaseGradient(), and parseColor().

3827 {
3828  if (m_colorTagCount.count()) {
3829  if (!--m_colorTagCount.top()) {
3830  m_colorStack.pop();
3831  m_colorTagCount.pop();
3832  }
3833  }
3834 }
QStack< int > m_colorTagCount
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QStack< QColor > m_colorStack
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ processingInstruction()

bool QSvgHandler::processingInstruction ( const QString target,
const QString data 
)

Definition at line 3859 of file qsvghandler.cpp.

Referenced by parse().

3860 {
3861  if (target == QLatin1String("xml-stylesheet")) {
3862  QRegExp rx(QLatin1String("type=\\\"(.+)\\\""));
3863  rx.setMinimal(true);
3864  bool isCss = false;
3865  int pos = 0;
3866  while ((pos = rx.indexIn(data, pos)) != -1) {
3867  QString type = rx.cap(1);
3868  if (type.toLower() == QLatin1String("text/css")) {
3869  isCss = true;
3870  }
3871  pos += rx.matchedLength();
3872  }
3873 
3874  if (isCss) {
3875  QRegExp rx(QLatin1String("href=\\\"(.+)\\\""));
3876  rx.setMinimal(true);
3877  pos = 0;
3878  pos = rx.indexIn(data, pos);
3879  QString addr = rx.cap(1);
3880  QFileInfo fi(addr);
3881  //qDebug()<<"External CSS file "<<fi.absoluteFilePath()<<fi.exists();
3882  if (fi.exists()) {
3883  QFile file(fi.absoluteFilePath());
3884  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
3885  return true;
3886  }
3887  QByteArray cssData = file.readAll();
3888  QString css = QString::fromUtf8(cssData);
3889 
3890  QCss::StyleSheet sheet;
3891  QCss::Parser(css).parse(&sheet);
3892  m_selector->styleSheets.append(sheet);
3893  }
3894 
3895  }
3896  }
3897 
3898  return true;
3899 }
int type
Definition: qmetatype.cpp:239
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
QVector< StyleSheet > styleSheets
Definition: qcssparser_p.h:675
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
bool parse(StyleSheet *styleSheet, Qt::CaseSensitivity nameCaseSensitivity=Qt::CaseSensitive)
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
QSvgStyleSelector * m_selector

◆ pushColor()

void QSvgHandler::pushColor ( const QColor color)

Definition at line 3812 of file qsvghandler.cpp.

Referenced by parseBaseGradient(), parseColor(), and pushColorCopy().

3813 {
3814  m_colorStack.push(color);
3815  m_colorTagCount.push(1);
3816 }
QStack< int > m_colorTagCount
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
QStack< QColor > m_colorStack

◆ pushColorCopy()

void QSvgHandler::pushColorCopy ( )

Definition at line 3818 of file qsvghandler.cpp.

Referenced by startElement().

3819 {
3820  if (m_colorTagCount.count())
3821  ++m_colorTagCount.top();
3822  else
3824 }
QStack< int > m_colorTagCount
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
void pushColor(const QColor &color)
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

◆ resolveGradients()

void QSvgHandler::resolveGradients ( QSvgNode node)
private

Definition at line 3739 of file qsvghandler.cpp.

Referenced by parse().

3740 {
3741  if (!node || (node->type() != QSvgNode::DOC && node->type() != QSvgNode::G
3742  && node->type() != QSvgNode::DEFS && node->type() != QSvgNode::SWITCH)) {
3743  return;
3744  }
3745  QSvgStructureNode *structureNode = static_cast<QSvgStructureNode *>(node);
3746 
3747  QList<QSvgNode *> ren = structureNode->renderers();
3748  for (QList<QSvgNode *>::iterator it = ren.begin(); it != ren.end(); ++it) {
3749  QSvgFillStyle *fill = static_cast<QSvgFillStyle *>((*it)->styleProperty(QSvgStyleProperty::FILL));
3750  if (fill && !fill->isGradientResolved()) {
3751  QString id = fill->gradientId();
3752  QSvgFillStyleProperty *style = structureNode->styleProperty(id);
3753  if (style) {
3754  fill->setFillStyle(style);
3755  } else {
3756  qWarning("Could not resolve property : %s", qPrintable(id));
3757  fill->setBrush(Qt::NoBrush);
3758  }
3759  }
3760 
3761  QSvgStrokeStyle *stroke = static_cast<QSvgStrokeStyle *>((*it)->styleProperty(QSvgStyleProperty::STROKE));
3762  if (stroke && !stroke->isGradientResolved()) {
3763  QString id = stroke->gradientId();
3764  QSvgFillStyleProperty *style = structureNode->styleProperty(id);
3765  if (style) {
3766  stroke->setStyle(style);
3767  } else {
3768  qWarning("Could not resolve property : %s", qPrintable(id));
3769  stroke->setStroke(Qt::NoBrush);
3770  }
3771  }
3772 
3773  resolveGradients(*it);
3774  }
3775 }
bool isGradientResolved() const
Definition: qsvgstyle_p.h:506
virtual Type type() const =0
#define it(className, varName)
QString gradientId() const
Definition: qsvgstyle_p.h:270
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QList< QSvgNode * > renderers() const
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setFillStyle(QSvgFillStyleProperty *style)
Definition: qsvgstyle.cpp:126
void setBrush(QBrush brush)
Definition: qsvgstyle.cpp:132
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
void resolveGradients(QSvgNode *node)
Q_CORE_EXPORT void qWarning(const char *,...)
The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.
Definition: qlist.h:181
QString gradientId() const
Definition: qsvgstyle_p.h:496
QSvgStyleProperty * styleProperty(QSvgStyleProperty::Type type) const
Definition: qsvgnode.cpp:128
void setStyle(QSvgFillStyleProperty *style)
Definition: qsvgstyle_p.h:424
void setStroke(QBrush brush)
Definition: qsvgstyle_p.h:417
bool isGradientResolved() const
Definition: qsvgstyle_p.h:280
#define qPrintable(string)
Definition: qglobal.h:1750
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ selector()

QSvgStyleSelector * QSvgHandler::selector ( ) const

Definition at line 3854 of file qsvghandler.cpp.

Referenced by parseStopNode().

3855 {
3856  return m_selector;
3857 }
QSvgStyleSelector * m_selector

◆ setAnimPeriod()

void QSvgHandler::setAnimPeriod ( int  start,
int  end 
)

Definition at line 3901 of file qsvghandler.cpp.

Referenced by parseAnimateColorNode(), and parseAnimateTransformNode().

3902 {
3903  Q_UNUSED(start);
3905 }
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
static const KeyPair *const end
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ setDefaultCoordinateSystem()

void QSvgHandler::setDefaultCoordinateSystem ( LengthType  type)

Definition at line 3807 of file qsvghandler.cpp.

Referenced by createSvgNode().

3808 {
3810 }
int type
Definition: qmetatype.cpp:239
LengthType m_defaultCoords

◆ setInStyle()

void QSvgHandler::setInStyle ( bool  b)

Definition at line 3844 of file qsvghandler.cpp.

Referenced by parseStyleNode().

3845 {
3846  m_inStyle = b;
3847 }

◆ startElement()

bool QSvgHandler::startElement ( const QString localName,
const QXmlStreamAttributes attributes 
)

Definition at line 3584 of file qsvghandler.cpp.

Referenced by parse().

3586 {
3587  QSvgNode *node = 0;
3588 
3589  pushColorCopy();
3590 
3591  /* The xml:space attribute may appear on any element. We do
3592  * a lookup by the qualified name here, but this is namespace aware, since
3593  * the XML namespace can only be bound to prefix "xml." */
3594  const QStringRef xmlSpace(attributes.value(QLatin1String("xml:space")));
3595  if (xmlSpace.isNull()) {
3596  // This element has no xml:space attribute.
3598  } else if (xmlSpace == QLatin1String("preserve")) {
3600  } else if (xmlSpace == QLatin1String("default")) {
3602  } else {
3603  qWarning() << QString::fromLatin1("\"%1\" is an invalid value for attribute xml:space. "
3604  "Valid values are \"preserve\" and \"default\".").arg(xmlSpace.toString());
3606  }
3607 
3608  if (!m_doc && localName != QLatin1String("svg"))
3609  return false;
3610 
3611  if (FactoryMethod method = findGroupFactory(localName)) {
3612  //group
3613  node = method(m_doc ? m_nodes.top() : 0, attributes, this);
3614  Q_ASSERT(node);
3615  if (!m_doc) {
3616  Q_ASSERT(node->type() == QSvgNode::DOC);
3617  m_doc = static_cast<QSvgTinyDocument*>(node);
3618  } else {
3619  switch (m_nodes.top()->type()) {
3620  case QSvgNode::DOC:
3621  case QSvgNode::G:
3622  case QSvgNode::DEFS:
3623  case QSvgNode::SWITCH:
3624  {
3625  QSvgStructureNode *group =
3626  static_cast<QSvgStructureNode*>(m_nodes.top());
3627  group->addChild(node, someId(attributes));
3628  }
3629  break;
3630  default:
3631  break;
3632  }
3633  }
3634  parseCoreNode(node, attributes);
3635  cssStyleLookup(node, this, m_selector);
3636  parseStyle(node, attributes, this);
3637  } else if (FactoryMethod method = findGraphicsFactory(localName)) {
3638  //rendering element
3639  Q_ASSERT(!m_nodes.isEmpty());
3640  node = method(m_nodes.top(), attributes, this);
3641  if (node) {
3642  switch (m_nodes.top()->type()) {
3643  case QSvgNode::DOC:
3644  case QSvgNode::G:
3645  case QSvgNode::DEFS:
3646  case QSvgNode::SWITCH:
3647  {
3648  QSvgStructureNode *group =
3649  static_cast<QSvgStructureNode*>(m_nodes.top());
3650  group->addChild(node, someId(attributes));
3651  }
3652  break;
3653  case QSvgNode::TEXT:
3654  case QSvgNode::TEXTAREA:
3655  if (node->type() == QSvgNode::TSPAN) {
3656  static_cast<QSvgText *>(m_nodes.top())->addTspan(static_cast<QSvgTspan *>(node));
3657  } else {
3658  qWarning("\'text\' or \'textArea\' element contains invalid element type.");
3659  delete node;
3660  node = 0;
3661  }
3662  break;
3663  default:
3664  qWarning("Could not add child element to parent element because the types are incorrect.");
3665  delete node;
3666  node = 0;
3667  break;
3668  }
3669 
3670  if (node) {
3671  parseCoreNode(node, attributes);
3672  cssStyleLookup(node, this, m_selector);
3673  parseStyle(node, attributes, this);
3674  if (node->type() == QSvgNode::TEXT || node->type() == QSvgNode::TEXTAREA) {
3675  static_cast<QSvgText *>(node)->setWhitespaceMode(m_whitespaceMode.top());
3676  } else if (node->type() == QSvgNode::TSPAN) {
3677  static_cast<QSvgTspan *>(node)->setWhitespaceMode(m_whitespaceMode.top());
3678  }
3679  }
3680  }
3681  } else if (ParseMethod method = findUtilFactory(localName)) {
3682  Q_ASSERT(!m_nodes.isEmpty());
3683  if (!method(m_nodes.top(), attributes, this)) {
3684  qWarning("Problem parsing %s", qPrintable(localName));
3685  }
3686  } else if (StyleFactoryMethod method = findStyleFactoryMethod(localName)) {
3687  QSvgStyleProperty *prop = method(m_nodes.top(), attributes, this);
3688  if (prop) {
3689  m_style = prop;
3690  m_nodes.top()->appendStyleProperty(prop, someId(attributes));
3691  } else {
3692  qWarning("Could not parse node: %s", qPrintable(localName));
3693  }
3694  } else if (StyleParseMethod method = findStyleUtilFactoryMethod(localName)) {
3695  if (m_style) {
3696  if (!method(m_style, attributes, this)) {
3697  qWarning("Problem parsing %s", qPrintable(localName));
3698  }
3699  }
3700  } else {
3701  //qWarning()<<"Skipping unknown element!"<<namespaceURI<<"::"<<localName;
3703  return true;
3704  }
3705 
3706  if (node) {
3707  m_nodes.push(node);
3709  } else {
3710  //qDebug()<<"Skipping "<<localName;
3712  }
3713  return true;
3714 }
virtual Type type() const =0
void appendStyleProperty(QSvgStyleProperty *prop, const QString &id)
Definition: qsvgnode.cpp:64
bool(* ParseMethod)(QSvgNode *, const QXmlStreamAttributes &, QSvgHandler *)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static StyleParseMethod findStyleUtilFactoryMethod(const QString &name)
QSvgNode *(* FactoryMethod)(QSvgNode *, const QXmlStreamAttributes &, QSvgHandler *)
static ParseMethod findUtilFactory(const QString &name)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QString someId(const QXmlStreamAttributes &attributes)
static bool parseStyle(QSvgNode *node, const QXmlStreamAttributes &attributes, QSvgHandler *)
QStringRef value(const QString &namespaceUri, const QString &name) const
Returns the value of the attribute name in the namespace described with namespaceUri, or an empty string reference if the attribute is not defined.
bool(* StyleParseMethod)(QSvgStyleProperty *, const QXmlStreamAttributes &, QSvgHandler *)
QSvgStyleProperty *(* StyleFactoryMethod)(QSvgNode *, const QXmlStreamAttributes &, QSvgHandler *)
void addChild(QSvgNode *child, const QString &id)
Q_CORE_EXPORT void qWarning(const char *,...)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QStack< QSvgNode * > m_nodes
static bool parseCoreNode(QSvgNode *node, const QXmlStreamAttributes &attributes)
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
static FactoryMethod findGroupFactory(const QString &name)
The QStringRef class provides a thin wrapper around QString substrings.
Definition: qstring.h:1099
static FactoryMethod findGraphicsFactory(const QString &name)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QStack< CurrentNode > m_skipNodes
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static void cssStyleLookup(QSvgNode *node, QSvgHandler *handler, QSvgStyleSelector *selector)
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
static StyleFactoryMethod findStyleFactoryMethod(const QString &name)
void pushColorCopy()
#define qPrintable(string)
Definition: qglobal.h:1750
QSvgRefCounter< QSvgStyleProperty > m_style
QSvgStyleSelector * m_selector
QStack< QSvgText::WhitespaceMode > m_whitespaceMode
Follows the depths of elements.
QSvgTinyDocument * m_doc
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72

Properties

◆ m_animEnd

int QSvgHandler::m_animEnd
private

Definition at line 170 of file qsvghandler_p.h.

Referenced by animationDuration(), init(), and setAnimPeriod().

◆ m_colorStack

QStack<QColor> QSvgHandler::m_colorStack
private

Definition at line 163 of file qsvghandler_p.h.

Referenced by currentColor(), popColor(), and pushColor().

◆ m_colorTagCount

QStack<int> QSvgHandler::m_colorTagCount
private

Definition at line 164 of file qsvghandler_p.h.

Referenced by popColor(), pushColor(), and pushColorCopy().

◆ m_cssParser

QCss::Parser QSvgHandler::m_cssParser
private

Definition at line 173 of file qsvghandler_p.h.

◆ m_defaultCoords

LengthType QSvgHandler::m_defaultCoords
private

Definition at line 161 of file qsvghandler_p.h.

Referenced by defaultCoordinateSystem(), init(), and setDefaultCoordinateSystem().

◆ m_defaultPen

QPen QSvgHandler::m_defaultPen
private

Definition at line 177 of file qsvghandler_p.h.

Referenced by init().

◆ m_doc

QSvgTinyDocument* QSvgHandler::m_doc
private

Definition at line 140 of file qsvghandler_p.h.

Referenced by document(), init(), parse(), and startElement().

◆ m_inStyle

bool QSvgHandler::m_inStyle
private

Definition at line 166 of file qsvghandler_p.h.

Referenced by characters(), endElement(), inStyle(), parse(), and setInStyle().

◆ m_nodes

QStack<QSvgNode*> QSvgHandler::m_nodes
private

Definition at line 141 of file qsvghandler_p.h.

Referenced by characters(), endElement(), and startElement().

◆ m_ownsReader

const bool QSvgHandler::m_ownsReader
private

Whether we own the variable xml, and hence whether we need to delete it.

Definition at line 182 of file qsvghandler_p.h.

Referenced by parse(), and ~QSvgHandler().

◆ m_resolveNodes

QList<QSvgNode*> QSvgHandler::m_resolveNodes
private

Definition at line 143 of file qsvghandler_p.h.

◆ m_selector

QSvgStyleSelector* QSvgHandler::m_selector
private

◆ m_skipNodes

QStack<CurrentNode> QSvgHandler::m_skipNodes
private

Definition at line 151 of file qsvghandler_p.h.

Referenced by characters(), endElement(), and startElement().

◆ m_style

QSvgRefCounter<QSvgStyleProperty> QSvgHandler::m_style
private

Definition at line 159 of file qsvghandler_p.h.

Referenced by endElement(), init(), and startElement().

◆ m_whitespaceMode

QStack<QSvgText::WhitespaceMode> QSvgHandler::m_whitespaceMode
private

Follows the depths of elements.

The top is current xml:space value that applies for a given element.

Definition at line 157 of file qsvghandler_p.h.

Referenced by endElement(), and startElement().

◆ xml

QXmlStreamReader* const QSvgHandler::xml
private

Definition at line 172 of file qsvghandler_p.h.

Referenced by parse(), and ~QSvgHandler().


The documentation for this class was generated from the following files: