+
+/******** Font Properties ********/
+
+void QssParser::parseFont(const QString& value, QTextCharFormat* format) {
+ QRegExp rx("((?:(?:normal|italic|oblique|underline|bold|100|200|300|400|500|600|700|800|900) ){0,2}) ?(\\d+)(pt|px)? \"(.*)\"");
+ if(!rx.exactMatch(value)) {
+ qWarning() << Q_FUNC_INFO << tr("Invalid font specification: %1").arg(value);
+ return;
+ }
+ format->setFontItalic(false);
+ format->setFontWeight(QFont::Normal);
+ QStringList proplist = rx.cap(1).split(' ', QString::SkipEmptyParts);
+ foreach(QString prop, proplist) {
+ if(prop == "italic")
+ format->setFontItalic(true);
+ else if(prop == "underline")
+ format->setFontUnderline(true);
+ //else if(prop == "oblique")
+ // format->setStyle(QFont::StyleOblique);
+ else if(prop == "bold")
+ format->setFontWeight(QFont::Bold);
+ else { // number
+ int w = prop.toInt();
+ format->setFontWeight(qMin(w / 8, 99)); // taken from Qt's qss parser
+ }
+ }
+
+ if(rx.cap(3) == "px")
+ format->setProperty(QTextFormat::FontPixelSize, rx.cap(2).toInt());
+ else
+ format->setFontPointSize(rx.cap(2).toInt());
+
+ format->setFontFamily(rx.cap(4));
+}
+
+void QssParser::parseFontStyle(const QString& value, QTextCharFormat* format) {
+ if(value == "normal")
+ format->setFontItalic(false);
+ else if(value == "italic")
+ format->setFontItalic(true);
+ else if(value == "underline")
+ format->setFontUnderline(true);
+ //else if(value == "oblique")
+ // format->setStyle(QFont::StyleOblique);
+ else {
+ qWarning() << Q_FUNC_INFO << tr("Invalid font style specification: %1").arg(value);
+ }
+}
+
+void QssParser::parseFontWeight(const QString& value, QTextCharFormat* format) {
+ if(value == "normal")
+ format->setFontWeight(QFont::Normal);
+ else if(value == "bold")
+ format->setFontWeight(QFont::Bold);
+ else {
+ bool ok;
+ int w = value.toInt(&ok);
+ if(!ok) {
+ qWarning() << Q_FUNC_INFO << tr("Invalid font weight specification: %1").arg(value);
+ return;
+ }
+ format->setFontWeight(qMin(w / 8, 99)); // taken from Qt's qss parser
+ }
+}
+
+void QssParser::parseFontSize(const QString& value, QTextCharFormat* format) {
+ QRegExp rx("\\(d+)(pt|px)");
+ if(!rx.exactMatch(value)) {
+ qWarning() << Q_FUNC_INFO << tr("Invalid font size specification: %1").arg(value);
+ return;
+ }
+ if(rx.cap(2) == "px")
+ format->setProperty(QTextFormat::FontPixelSize, rx.cap(1).toInt());
+ else
+ format->setFontPointSize(rx.cap(1).toInt());
+}
+
+void QssParser::parseFontFamily(const QString& value, QTextCharFormat* format) {
+ QString family = value;
+ if(family.startsWith('"') && family.endsWith('"')) {
+ family = family.mid(1, family.length() - 2);
+ }
+ format->setFontFamily(family);
+}