summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2011-10-22 12:52:13 +0200
committerFridrich Štrba <fridrich.strba@bluewin.ch>2011-10-22 12:52:13 +0200
commitaa47678768eb1f5df86a1436088a26abc8fba5fb (patch)
treeea5df5f09d438fd957366a4b6b5ace6b24fbba2d
parentd5940cf4a67589ee3ff78e5563669f42e0eb0c35 (diff)
Initialize styles correctly and remove unnecessary variable
1. Initialize from Stencil's pointers to style sheet 2. If stencil overrides a style, override it 3. If shape has pointer to stylesheet, override again. 4. Override with the style in the shape properties.
-rw-r--r--src/lib/VSDXContentCollector.cpp123
-rw-r--r--src/lib/VSDXContentCollector.h7
-rw-r--r--src/lib/VSDXParser.cpp6
-rw-r--r--src/lib/VSDXStencils.cpp10
-rw-r--r--src/lib/VSDXStencils.h2
5 files changed, 82 insertions, 66 deletions
diff --git a/src/lib/VSDXContentCollector.cpp b/src/lib/VSDXContentCollector.cpp
index 6868449..9e10bf5 100644
--- a/src/lib/VSDXContentCollector.cpp
+++ b/src/lib/VSDXContentCollector.cpp
@@ -65,7 +65,7 @@ libvisio::VSDXContentCollector::VSDXContentCollector(
m_pageShapeOrder(documentPageShapeOrders[0]), m_isFirstGeometry(true),
m_NURBSData(), m_polylineData(), m_textStream(), m_textFormat(VSD_TEXT_ANSI),
m_charFormats(), m_paraFormats(), m_textBlockFormat(),
- m_defaultCharStyle(), m_defaultParaStyle(), m_styles(styles), m_hasLocalLineStyle(false), m_hasLocalFillStyle(false),
+ m_defaultCharStyle(), m_defaultParaStyle(), m_styles(styles),
m_stencils(stencils), m_stencilShape(0), m_isStencilStarted(false), m_currentGeometryCount(0),
m_backgroundPageID(0xffffffff), m_currentPageID(0), m_currentPage(), m_pages(),
m_splineControlPoints(), m_splineKnotVector(), m_splineX(0.0), m_splineY(0.0),
@@ -820,7 +820,6 @@ void libvisio::VSDXContentCollector::collectEllipse(unsigned /* id */, unsigned
void libvisio::VSDXContentCollector::collectLine(unsigned /* id */, unsigned level, double strokeWidth, Colour c, unsigned linePattern, unsigned char /*startMarker*/, unsigned char /*endMarker*/, unsigned lineCap)
{
_handleLevelChange(level);
- m_hasLocalLineStyle = true;
_lineProperties(strokeWidth, c, linePattern, lineCap);
}
@@ -829,7 +828,6 @@ void libvisio::VSDXContentCollector::collectFillAndShadow(unsigned /* id */, uns
unsigned shadowPattern, Colour shfgc, double shadowOffsetX, double shadowOffsetY)
{
_handleLevelChange(level);
- m_hasLocalFillStyle = true;
_fillAndShadowProperties(colourIndexFG, colourIndexBG, fillPattern, fillFGTransparency, fillBGTransparency, shadowPattern, shfgc, shadowOffsetX, shadowOffsetY);
}
@@ -959,24 +957,8 @@ void libvisio::VSDXContentCollector::collectGeometry(unsigned /* id */, unsigned
bool noShow = ((geomFlags & 4) == 4);
if ((m_noFill != noFill) || (m_noLine != noLine) || (m_noShow != noShow) || m_isFirstGeometry)
- {
- if (!m_hasLocalLineStyle && m_stencilShape)
- {
- if (m_stencilShape->m_lineStyle != 0 && !m_noLine)
- lineStyleFromStyleSheet(*(m_stencilShape->m_lineStyle));
- else if (m_stencilShape->m_lineStyleID != 0xffffffff)
- lineStyleFromStyleSheet(m_stencilShape->m_lineStyleID);
- }
-
- if (!m_hasLocalFillStyle && m_stencilShape && !m_noFill)
- {
- if (m_stencilShape->m_fillStyle != 0)
- fillStyleFromStyleSheet(*(m_stencilShape->m_fillStyle));
- else if (m_stencilShape->m_fillStyleID != 0xffffffff)
- fillStyleFromStyleSheet(m_stencilShape->m_fillStyleID);
- }
_flushCurrentPath();
- }
+
m_isFirstGeometry = false;
m_noFill = noFill;
m_noLine = noLine;
@@ -1437,16 +1419,22 @@ void libvisio::VSDXContentCollector::collectShape(unsigned id, unsigned level, u
// Reset style
m_styleProps.clear();
m_styleProps.insert("draw:fill", m_fillType);
+ // TODO: verify
m_styleProps.insert("svg:stroke-dasharray", "solid");
+ m_textStream.clear();
+ m_charFormats.clear();
+ m_paraFormats.clear();
+ m_textBlockFormat = VSDXTextBlockStyle();
+ m_defaultCharStyle = VSDXCharStyle();
+ m_defaultParaStyle = VSDXParaStyle();
+
m_currentShapeId = id;
m_pageOutput[m_currentShapeId] = VSDXOutputElementList();
m_shapeOutput = &m_pageOutput[m_currentShapeId];
m_isShapeStarted = true;
m_isFirstGeometry = true;
- m_textBlockFormat = VSDXTextBlockStyle();
-
// Get stencil shape
m_stencilShape = 0;
if (masterPage != 0xffffffff && masterShape != 0xffffffff)
@@ -1456,32 +1444,44 @@ void libvisio::VSDXContentCollector::collectShape(unsigned id, unsigned level, u
// Set the foreign types and foreign data if the stencil has foreign
// If the shape itself overrides them, they will be overwritten in the
// collectForeignDataType and collectForeignData calls
- if (m_stencilShape && m_stencilShape->m_foreign)
+ if (m_stencilShape)
{
- m_foreignType = m_stencilShape->m_foreign->type;
- m_foreignFormat = m_stencilShape->m_foreign->format;
- _handleForeignData(m_stencilShape->m_foreign->data);
+ if (m_stencilShape->m_foreign)
+ {
+ m_foreignType = m_stencilShape->m_foreign->type;
+ m_foreignFormat = m_stencilShape->m_foreign->format;
+ _handleForeignData(m_stencilShape->m_foreign->data);
+ }
+
+ if (m_stencilShape->m_lineStyleId)
+ lineStyleFromStyleSheet(m_stencilShape->m_lineStyleId);
+ if (m_stencilShape->m_lineStyle)
+ lineStyleFromStyleSheet(*(m_stencilShape->m_lineStyle));
+
+ if (m_stencilShape->m_fillStyleId)
+ fillStyleFromStyleSheet(m_stencilShape->m_fillStyleId);
+ if (m_stencilShape->m_fillStyle)
+ fillStyleFromStyleSheet(*(m_stencilShape->m_fillStyle));
+
+ if (m_stencilShape->m_textStyleId)
+ {
+ m_defaultCharStyle = m_styles.getCharStyle(m_stencilShape->m_textStyleId);
+ m_defaultParaStyle = m_styles.getParaStyle(m_stencilShape->m_textStyleId);
+ m_textBlockFormat = m_styles.getTextBlockStyle(m_stencilShape->m_textStyleId);
+ }
+ if (m_stencilShape->m_textBlockStyle)
+ m_textBlockFormat = *(m_stencilShape->m_textBlockStyle);
+ if (m_stencilShape->m_charStyle)
+ m_defaultCharStyle = *(m_stencilShape->m_charStyle);
+ if (m_stencilShape->m_paraStyle)
+ m_defaultParaStyle = *(m_stencilShape->m_paraStyle);
}
}
- m_hasLocalLineStyle = false;
- m_hasLocalFillStyle = false;
if (lineStyleId != 0xffffffff)
- {
lineStyleFromStyleSheet(lineStyleId);
- m_hasLocalLineStyle = true;
- }
if (fillStyleId != 0xffffffff)
- {
fillStyleFromStyleSheet(fillStyleId);
- m_hasLocalFillStyle = true;
- }
- m_textStream.clear();
- m_charFormats.clear();
- m_paraFormats.clear();
- m_textBlockFormat = VSDXTextBlockStyle();
- m_defaultCharStyle = VSDXCharStyle();
- m_defaultParaStyle = VSDXParaStyle();
if (textStyleId != 0xffffffff)
{
m_defaultCharStyle = m_styles.getCharStyle(textStyleId);
@@ -1663,6 +1663,33 @@ void libvisio::VSDXContentCollector::fillStyleFromStyleSheet(const VSDXFillStyle
style.shadowPattern, style.shadowFgColour, style.shadowOffsetX, style.shadowOffsetY);
}
+void libvisio::VSDXContentCollector::textBlockStyleFromStyleSheet(unsigned styleId)
+{
+ textBlockStyleFromStyleSheet(m_styles.getTextBlockStyle(styleId));
+}
+
+void libvisio::VSDXContentCollector::textBlockStyleFromStyleSheet(const VSDXTextBlockStyle &style)
+{
+}
+
+void libvisio::VSDXContentCollector::charStyleFromStyleSheet(unsigned styleId)
+{
+ charStyleFromStyleSheet(m_styles.getCharStyle(styleId));
+}
+
+void libvisio::VSDXContentCollector::charStyleFromStyleSheet(const VSDXCharStyle &style)
+{
+}
+
+void libvisio::VSDXContentCollector::paraStyleFromStyleSheet(unsigned styleId)
+{
+ paraStyleFromStyleSheet(m_styles.getParaStyle(styleId));
+}
+
+void libvisio::VSDXContentCollector::paraStyleFromStyleSheet(const VSDXParaStyle &style)
+{
+}
+
void libvisio::VSDXContentCollector::_handleLevelChange(unsigned level)
{
if (m_currentLevel == level)
@@ -1677,22 +1704,6 @@ void libvisio::VSDXContentCollector::_handleLevelChange(unsigned level)
m_NURBSData = m_stencilShape->m_nurbsData;
m_polylineData = m_stencilShape->m_polylineData;
- if (!m_hasLocalLineStyle && !m_noLine)
- {
- if (m_stencilShape->m_lineStyle != 0)
- lineStyleFromStyleSheet(*(m_stencilShape->m_lineStyle));
- else if (m_stencilShape->m_lineStyleID != 0xffffffff)
- lineStyleFromStyleSheet(m_stencilShape->m_lineStyleID);
- }
-
- if (!m_hasLocalFillStyle && !m_noFill)
- {
- if (m_stencilShape->m_fillStyle != 0)
- fillStyleFromStyleSheet(*(m_stencilShape->m_fillStyle));
- else if (m_stencilShape->m_fillStyleID != 0xffffffff)
- fillStyleFromStyleSheet(m_stencilShape->m_fillStyleID);
- }
-
if (m_currentGeometry.size() == 0)
{
for (unsigned i = 0; i < m_stencilShape->m_geometries.size(); i++)
diff --git a/src/lib/VSDXContentCollector.h b/src/lib/VSDXContentCollector.h
index 8f4b1de..d5c2d83 100644
--- a/src/lib/VSDXContentCollector.h
+++ b/src/lib/VSDXContentCollector.h
@@ -156,8 +156,14 @@ private:
void lineStyleFromStyleSheet(unsigned styleId);
void fillStyleFromStyleSheet(unsigned styleId);
+ void textBlockStyleFromStyleSheet(unsigned styleId);
+ void charStyleFromStyleSheet(unsigned styleId);
+ void paraStyleFromStyleSheet(unsigned styleId);
void lineStyleFromStyleSheet(const VSDXLineStyle &style);
void fillStyleFromStyleSheet(const VSDXFillStyle &style);
+ void textBlockStyleFromStyleSheet(const VSDXTextBlockStyle &style);
+ void charStyleFromStyleSheet(const VSDXCharStyle &style);
+ void paraStyleFromStyleSheet(const VSDXParaStyle &style);
void _lineProperties(double strokeWidth, Colour c, unsigned linePattern, unsigned lineCap);
void _fillAndShadowProperties(unsigned colourIndexFG, unsigned colourIndexBG, unsigned fillPattern,
@@ -221,7 +227,6 @@ private:
VSDXParaStyle m_defaultParaStyle;
VSDXStyles m_styles;
- bool m_hasLocalLineStyle, m_hasLocalFillStyle;
VSDXStencils m_stencils;
const VSDXStencilShape * m_stencilShape;
diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp
index f0937f1..56e550e 100644
--- a/src/lib/VSDXParser.cpp
+++ b/src/lib/VSDXParser.cpp
@@ -1039,9 +1039,9 @@ void libvisio::VSDXParser::readShape(WPXInputStream * input)
if (m_isStencilStarted)
{
- m_stencilShape.m_lineStyleID = lineStyle;
- m_stencilShape.m_fillStyleID = fillStyle;
- m_stencilShape.m_textStyleID = textStyle;
+ m_stencilShape.m_lineStyleId = lineStyle;
+ m_stencilShape.m_fillStyleId = fillStyle;
+ m_stencilShape.m_textStyleId = textStyle;
}
else
m_collector->collectShape(m_header.id, m_header.level, masterPage, masterShape, lineStyle, fillStyle, textStyle);
diff --git a/src/lib/VSDXStencils.cpp b/src/lib/VSDXStencils.cpp
index 62a55dc..b08a1b8 100644
--- a/src/lib/VSDXStencils.cpp
+++ b/src/lib/VSDXStencils.cpp
@@ -31,7 +31,7 @@
#include "libvisio_utils.h"
libvisio::VSDXStencilShape::VSDXStencilShape()
- : m_geometries(), m_foreign(0), m_lineStyleID(0xffffffff), m_fillStyleID(0xffffffff), m_textStyleID(0xffffffff),
+ : m_geometries(), m_foreign(0), m_lineStyleId(0xffffffff), m_fillStyleId(0xffffffff), m_textStyleId(0xffffffff),
m_lineStyle(0), m_fillStyle(0), m_textBlockStyle(0), m_charStyle(0), m_paraStyle(0),
m_text(), m_nurbsData(), m_polylineData()
{
@@ -39,7 +39,7 @@ libvisio::VSDXStencilShape::VSDXStencilShape()
libvisio::VSDXStencilShape::VSDXStencilShape(const libvisio::VSDXStencilShape &shape)
: m_geometries(shape.m_geometries), m_foreign(shape.m_foreign ? new ForeignData(*(shape.m_foreign)) : 0),
- m_lineStyleID(shape.m_lineStyleID), m_fillStyleID(shape.m_fillStyleID), m_textStyleID(shape.m_textStyleID),
+ m_lineStyleId(shape.m_lineStyleId), m_fillStyleId(shape.m_fillStyleId), m_textStyleId(shape.m_textStyleId),
m_lineStyle(shape.m_lineStyle ? new VSDXLineStyle(*(shape.m_lineStyle)) : 0),
m_fillStyle(shape.m_fillStyle ? new VSDXFillStyle(*(shape.m_fillStyle)) : 0),
m_textBlockStyle(shape.m_textBlockStyle ? new VSDXTextBlockStyle(*(shape.m_textBlockStyle)) : 0),
@@ -69,9 +69,9 @@ libvisio::VSDXStencilShape &libvisio::VSDXStencilShape::operator=(const libvisio
if (m_foreign)
delete m_foreign;
m_foreign = shape.m_foreign ? new ForeignData(*(shape.m_foreign)) : 0;
- m_lineStyleID = shape.m_lineStyleID;
- m_fillStyleID = shape.m_fillStyleID;
- m_textStyleID = shape.m_textStyleID;
+ m_lineStyleId = shape.m_lineStyleId;
+ m_fillStyleId = shape.m_fillStyleId;
+ m_textStyleId = shape.m_textStyleId;
if (m_lineStyle)
delete m_lineStyle;
m_lineStyle = shape.m_lineStyle ? new VSDXLineStyle(*(shape.m_lineStyle)) : 0;
diff --git a/src/lib/VSDXStencils.h b/src/lib/VSDXStencils.h
index e4a92b6..e66de59 100644
--- a/src/lib/VSDXStencils.h
+++ b/src/lib/VSDXStencils.h
@@ -48,7 +48,7 @@ class VSDXStencilShape
std::vector<VSDXGeometryList> m_geometries;
ForeignData * m_foreign;
- unsigned m_lineStyleID, m_fillStyleID, m_textStyleID;
+ unsigned m_lineStyleId, m_fillStyleId, m_textStyleId;
VSDXLineStyle * m_lineStyle;
VSDXFillStyle * m_fillStyle;
VSDXTextBlockStyle * m_textBlockStyle;