summaryrefslogtreecommitdiff
path: root/src/svg
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-02-27 09:12:14 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-02-27 09:08:35 +0000
commit967536c12d8a8684899117aafd63faf8d831b656 (patch)
treea29a8d3c27f89ed0465042bb02b963656cf3143e /src/svg
parentf4554e29a44af2cdd9e518f5931e28cf349883c6 (diff)
downloadqtsvg-967536c12d8a8684899117aafd63faf8d831b656.tar.gz
Fix warning when encountering font-size="none"
Extend existing enum by "none" and extract a function to return the specification so that "none" can be cleanly handled. Task-number: QTBUG-66646 Change-Id: If4ec1056c6f0fa407f76b747634bb898e75a5474 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/svg')
-rw-r--r--src/svg/qsvghandler.cpp78
1 files changed, 51 insertions, 27 deletions
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp
index 6c0e742..0862b05 100644
--- a/src/svg/qsvghandler.cpp
+++ b/src/svg/qsvghandler.cpp
@@ -1288,6 +1288,49 @@ static void parsePen(QSvgNode *node,
}
}
+enum FontSizeSpec { XXSmall, XSmall, Small, Medium, Large, XLarge, XXLarge,
+ FontSizeNone, FontSizeValue };
+
+static const qreal sizeTable[] =
+{ qreal(6.9), qreal(8.3), qreal(10.0), qreal(12.0), qreal(14.4), qreal(17.3), qreal(20.7) };
+
+Q_STATIC_ASSERT(sizeof(sizeTable)/sizeof(sizeTable[0]) == FontSizeNone);
+
+static FontSizeSpec fontSizeSpec(const QStringRef &spec)
+{
+ switch (spec.at(0).unicode()) {
+ case 'x':
+ if (spec == QLatin1String("xx-small"))
+ return XXSmall;
+ if (spec == QLatin1String("x-small"))
+ return XSmall;
+ if (spec == QLatin1String("x-large"))
+ return XLarge;
+ if (spec == QLatin1String("xx-large"))
+ return XXLarge;
+ break;
+ case 's':
+ if (spec == QLatin1String("small"))
+ return Small;
+ break;
+ case 'm':
+ if (spec == QLatin1String("medium"))
+ return Medium;
+ break;
+ case 'l':
+ if (spec == QLatin1String("large"))
+ return Large;
+ break;
+ case 'n':
+ if (spec == QLatin1String("none"))
+ return FontSizeNone;
+ break;
+ default:
+ break;
+ }
+ return FontSizeValue;
+}
+
static void parseFont(QSvgNode *node,
const QSvgAttributes &attributes,
QSvgHandler *handler)
@@ -1311,38 +1354,19 @@ static void parseFont(QSvgNode *node,
if (!attributes.fontSize.isEmpty() && attributes.fontSize != QT_INHERIT) {
// TODO: Support relative sizes 'larger' and 'smaller'.
- QSvgHandler::LengthType dummy; // should always be pixel size
- qreal size = 0;
- static const qreal sizeTable[] = { qreal(6.9), qreal(8.3), qreal(10.0), qreal(12.0), qreal(14.4), qreal(17.3), qreal(20.7) };
- enum AbsFontSize { XXSmall, XSmall, Small, Medium, Large, XLarge, XXLarge };
- switch (attributes.fontSize.at(0).unicode()) {
- case 'x':
- if (attributes.fontSize == QLatin1String("xx-small"))
- size = sizeTable[XXSmall];
- else if (attributes.fontSize == QLatin1String("x-small"))
- size = sizeTable[XSmall];
- else if (attributes.fontSize == QLatin1String("x-large"))
- size = sizeTable[XLarge];
- else if (attributes.fontSize == QLatin1String("xx-large"))
- size = sizeTable[XXLarge];
+ const FontSizeSpec spec = fontSizeSpec(attributes.fontSize);
+ switch (spec) {
+ case FontSizeNone:
break;
- case 's':
- if (attributes.fontSize == QLatin1String("small"))
- size = sizeTable[Small];
- break;
- case 'm':
- if (attributes.fontSize == QLatin1String("medium"))
- size = sizeTable[Medium];
- break;
- case 'l':
- if (attributes.fontSize == QLatin1String("large"))
- size = sizeTable[Large];
+ case FontSizeValue: {
+ QSvgHandler::LengthType dummy; // should always be pixel size
+ fontStyle->setSize(parseLength(attributes.fontSize.toString(), dummy, handler));
+ }
break;
default:
- size = parseLength(attributes.fontSize.toString(), dummy, handler);
+ fontStyle->setSize(sizeTable[spec]);
break;
}
- fontStyle->setSize(size);
}
if (!attributes.fontStyle.isEmpty() && attributes.fontStyle != QT_INHERIT) {