From 8365f2f7a627ebb9a6948e272adbcedbe58f9727 Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Sat, 5 Nov 2016 16:38:31 -0400 Subject: [PATCH] Fix saving of polygons' fill rule Up until now, the fill rule of a polygon was always saved as even-odd, despite the fact that in most if not all cases, polygons are drawn with winding fill within OpenBoard. Saving is now fixed, but there is no way to know upon loading whether the polygon was correctly saved or whether; so for now, we just set the fill rule to Winding when loading a polygon. --- src/adaptors/UBSvgSubsetAdaptor.cpp | 23 +++++++++++++++++++++++ src/domain/UBGraphicsPolygonItem.cpp | 1 + 2 files changed, 24 insertions(+) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index e0dbb4e2..4f0a1860 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -1599,6 +1599,8 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::polygonItemToSvgPolygon(UBGraphicsPo if (polygonItem->fillRule() == Qt::OddEvenFill) mXmlWriter.writeAttribute("fill-rule", "evenodd"); + else + mXmlWriter.writeAttribute("fill-rule", "winding"); if (!groupHoldsInfo) { @@ -1720,6 +1722,27 @@ UBGraphicsPolygonItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItemFromPol color.setAlphaF(opacity); polygonItem->setColorOnLightBackground(color); } + + /* + + Unfortunately the fill rule was never saved correctly until OpenBoard v1.4, + before then, it was always saved as even-odd. So we can't load it safely here. + Saving is now fixed, but any old documents would be loaded incorrectly if the code + below is used. It should be activated at some point in the future though. + + QStringRef fillRule = mXmlReader.attributes().value("fill-rule"); + + if (!fillRule.isNull()) { + QString value = fillRule.toString(); + + if (value == "evenodd") + polygonItem->setFillRule(Qt::OddEvenFill); + else + polygonItem->setFillRule(Qt::WindingFill); + } + */ + polygonItem->setFillRule(Qt::WindingFill); + return polygonItem; } diff --git a/src/domain/UBGraphicsPolygonItem.cpp b/src/domain/UBGraphicsPolygonItem.cpp index 320da3f3..4e74420a 100644 --- a/src/domain/UBGraphicsPolygonItem.cpp +++ b/src/domain/UBGraphicsPolygonItem.cpp @@ -171,6 +171,7 @@ void UBGraphicsPolygonItem::copyItemParameters(UBItem *copy) const cp->setBrush(this->brush()); cp->setPen(this->pen()); cp->mHasAlpha = this->mHasAlpha; + cp->setFillRule(this->fillRule()); cp->setColorOnDarkBackground(this->colorOnDarkBackground()); cp->setColorOnLightBackground(this->colorOnLightBackground());