Hallo again,
here are two patches for improving libmspub
Greetings,
Franz Schmid
From c24205bf034a5f4759638f5c2c7d7e09823d32ab Mon Sep 17 00:00:00 2001
From: Franz Schmid <franz@linux-hp-i7.site>
Date: Sun, 14 Apr 2013 10:51:31 +0200
Subject: [PATCH 2/3] Added output of the wrap path as an svg clip path.
---
src/lib/EscherFieldIds.h | 1 +
src/lib/MSPUBCollector.cpp | 18 +++++++++++++++++-
src/lib/MSPUBCollector.h | 1 +
src/lib/MSPUBParser.cpp | 8 ++++++++
src/lib/PolygonUtils.cpp | 25 +++++++++++++++++++++++++
src/lib/PolygonUtils.h | 1 +
src/lib/ShapeInfo.h | 3 ++-
7 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/src/lib/EscherFieldIds.h b/src/lib/EscherFieldIds.h
index 7c7446e..7b3ff22 100644
--- a/src/lib/EscherFieldIds.h
+++ b/src/lib/EscherFieldIds.h
@@ -78,6 +78,7 @@
#define FIELDID_GEO_BOTTOM 0x0143
#define FIELDID_P_VERTICES 0xC145
#define FIELDID_P_SEGMENTS 0xC146
+#define FIELDID_P_WRAPPOLYGONVERTICES 0xC383
#define FIELDID_P_CONNECTION_SITES 0xC151
#define FIELDID_P_ADJUST_HANDLES 0xC155
#define FIELDID_P_GUIDES 0xC156
diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp
index 82b7cca..36f51ca 100644
--- a/src/lib/MSPUBCollector.cpp
+++ b/src/lib/MSPUBCollector.cpp
@@ -222,6 +222,11 @@ void libmspub::MSPUBCollector::setShapeCustomPath(unsigned seqNum,
m_shapeInfosBySeqNum[seqNum].m_customShape = shape;
}
+void libmspub::MSPUBCollector::setShapeClipPath(unsigned seqNum, const
std::vector<libmspub::Vertex> &clip)
+{
+ m_shapeInfosBySeqNum[seqNum].m_clipPath = clip;
+}
+
void libmspub::MSPUBCollector::beginGroup()
{
ShapeGroupElement *tmp = new ShapeGroupElement(m_currentShapeGroup);
@@ -409,7 +414,18 @@ boost::function<void(void)> libmspub::MSPUBCollector::paintShape(const
ShapeInfo
(hasStroke && hasFill) || (hasStroke && hasText) || (hasFill && hasText);
if (makeLayer)
{
- m_painter->startLayer(WPXPropertyList());
+ if (info.m_clipPath.size() > 0)
+ {
+ const Coordinate &coord = info.m_coordinates.get_value_or(Coordinate());
+ double x, y, height, width;
+ x = coord.getXIn(m_width);
+ y = coord.getYIn(m_height);
+ height = coord.getHeightIn();
+ width = coord.getWidthIn();
+ m_painter->startLayer(calcClipPath(info.m_clipPath, x, y, height, width, foldedTransform,
info.getCustomShape()));
+ }
+ else
+ m_painter->startLayer(WPXPropertyList());
}
graphicsProps.insert("draw:stroke", "none");
const Coordinate &coord = info.m_coordinates.get_value_or(Coordinate());
diff --git a/src/lib/MSPUBCollector.h b/src/lib/MSPUBCollector.h
index 719eb1e..5755043 100644
--- a/src/lib/MSPUBCollector.h
+++ b/src/lib/MSPUBCollector.h
@@ -105,6 +105,7 @@ public:
void setShapeCoordinatesRotated90(unsigned seqNum);
void setShapeCustomPath(unsigned seqNum,
const DynamicCustomShape &shape);
+ void setShapeClipPath(unsigned seqNum, const std::vector<libmspub::Vertex> &clip);
void setShapeVerticalTextAlign(unsigned seqNum, VerticalAlign va);
void designateMasterPage(unsigned seqNum);
void setMasterPage(unsigned pageSeqNum, unsigned masterSeqNum);
diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index 21ade39..9050a1c 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -1767,6 +1767,13 @@ void libmspub::MSPUBParser::parseEscherShape(WPXInputStream *input, const
Escher
guideData, p_geoRight ? *p_geoRight : 21600,
p_geoBottom ? *p_geoBottom : 21600));
}
+ const std::vector<unsigned char> wrapVertexData =
foptValues.m_complexValues[FIELDID_P_WRAPPOLYGONVERTICES];
+ if (!wrapVertexData.empty())
+ {
+ std::vector<libmspub::Vertex> ret = parseVertices(wrapVertexData);
+ m_collector->setShapeClipPath(*shapeSeqNum, ret);
+ MSPUB_DEBUG_MSG(("Current Escher shape has wrap Path\n"));
+ }
}
if (foundAnchor)
{
@@ -2161,6 +2168,7 @@ libmspub::FOPTValues libmspub::MSPUBParser::extractFOPTValues(WPXInputStream
*in
unsigned short id = readU16(input);
unsigned value = readU32(input);
ret.m_scalarValues[id] = value;
+ MSPUB_DEBUG_MSG(("EscherFopt ID %u Value %u\n", id, value));
bool complex = id & 0x8000;
if (complex)
{
diff --git a/src/lib/PolygonUtils.cpp b/src/lib/PolygonUtils.cpp
index 8fb4c7c..df72a16 100644
--- a/src/lib/PolygonUtils.cpp
+++ b/src/lib/PolygonUtils.cpp
@@ -5896,6 +5896,31 @@ void getRayEllipseIntersection(double initX, double initY, double rx, double
ry,
yOut += cy;
}
+WPXPropertyList libmspub::calcClipPath(const std::vector<libmspub::Vertex> &verts, double x,
double y, double height, double width, VectorTransformation2D transform, boost::shared_ptr<const
CustomShape> shape)
+{
+ WPXPropertyList vertices;
+ Vector2D center(x + width / 2, y + height / 2);
+ double scaleX = width / shape->m_coordWidth;
+ double scaleY = height / shape->m_coordHeight;
+ WPXString clipString;
+ Vector2D vector(x + scaleX * verts[0].m_x, y + scaleY * verts[0].m_y);
+ vector = transform.transformWithOrigin(vector, center);
+ WPXString sValue;
+ sValue.sprintf("M %f %f", (double)vector.m_x, (double)vector.m_y);
+ clipString.append(sValue);
+ for (unsigned i = 1; i < verts.size(); ++i)
+ {
+ Vector2D vector2(x + scaleX * verts[i].m_x, y + scaleY * verts[i].m_y);
+ vector2 = transform.transformWithOrigin(vector2, center);
+ WPXString sValue2;
+ sValue2.sprintf(" L %f %f", (double)vector2.m_x, (double)vector2.m_y);
+ clipString.append(sValue2);
+ }
+ clipString.append(" Z");
+ vertices.insert("svg:clip-path", clipString);
+ return vertices;
+}
+
void libmspub::writeCustomShape(ShapeType shapeType, WPXPropertyList &graphicsProps,
libwpg::WPGPaintInterface *painter, double x, double y, double height, double width, bool
closeEverything, VectorTransformation2D transform, std::vector<Line> lines,
boost::function<double(unsigned index)> calculator, const std::vector<Color> &palette,
boost::shared_ptr<const CustomShape> shape)
{
MSPUB_DEBUG_MSG(("***STARTING CUSTOM SHAPE***\n"));
diff --git a/src/lib/PolygonUtils.h b/src/lib/PolygonUtils.h
index 73d652d..f4ed419 100644
--- a/src/lib/PolygonUtils.h
+++ b/src/lib/PolygonUtils.h
@@ -133,6 +133,7 @@ boost::shared_ptr<const CustomShape> getFromDynamicCustomShape(const DynamicCust
const CustomShape *getCustomShape(ShapeType type);
bool isShapeTypeRectangle(ShapeType type);
+WPXPropertyList calcClipPath(const std::vector<libmspub::Vertex> &verts, double x, double y,
double height, double width, VectorTransformation2D transform, boost::shared_ptr<const CustomShape>
shape);
void writeCustomShape(ShapeType shapeType, WPXPropertyList &graphicsProps,
libwpg::WPGPaintInterface *painter, double x, double y, double height, double width, bool
closeEverything, VectorTransformation2D transform, std::vector<Line> lines,
boost::function<double(unsigned index)> calculator, const std::vector<Color> &palette,
boost::shared_ptr<const CustomShape> shape);
} // libmspub
diff --git a/src/lib/ShapeInfo.h b/src/lib/ShapeInfo.h
index 8f33247..9bbac5c 100644
--- a/src/lib/ShapeInfo.h
+++ b/src/lib/ShapeInfo.h
@@ -80,6 +80,7 @@ struct ShapeInfo
boost::optional<ColorReference> m_pictureRecolor;
boost::optional<Shadow> m_shadow;
boost::optional<int> m_innerRotation;
+ std::vector<libmspub::Vertex> m_clipPath;
ShapeInfo() : m_type(), m_cropType(), m_imgIndex(), m_borderImgIndex(),
m_coordinates(), m_lines(), m_pageSeqNum(),
m_textId(), m_adjustValuesByIndex(), m_adjustValues(),
@@ -88,7 +89,7 @@ struct ShapeInfo
m_lineBackColor(), m_dash(), m_tableInfo(),
m_tableCellTextEnds(), m_numColumns(),
m_columnSpacing(0), m_beginArrow(), m_endArrow(),
- m_verticalAlign(), m_pictureRecolor(), m_shadow(), m_innerRotation()
+ m_verticalAlign(), m_pictureRecolor(), m_shadow(), m_innerRotation(), m_clipPath()
{
}
boost::shared_ptr<const CustomShape> getCustomShape() const
--
1.7.1
From f8657d35a0d7658f42b5c00794df521b3e69e24f Mon Sep 17 00:00:00 2001
From: Franz Schmid <franz@linux-hp-i7.site>
Date: Sun, 14 Apr 2013 12:17:12 +0200
Subject: [PATCH 3/3] Added output of the dash style value as libmspub:dashstyle property
---
src/lib/MSPUBCollector.cpp | 9 ++++++++-
src/lib/MSPUBCollector.h | 2 +-
src/lib/MSPUBParser.cpp | 4 ++--
src/lib/ShapeInfo.h | 3 ++-
4 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp
index 36f51ca..032908b 100644
--- a/src/lib/MSPUBCollector.cpp
+++ b/src/lib/MSPUBCollector.cpp
@@ -760,6 +760,12 @@ boost::function<void(void)> libmspub::MSPUBCollector::paintShape(const
ShapeInfo
graphicsProps.insert(length.cstr(), dash.m_dots[i].m_length.get(), WPX_INCH);
}
}
+ if (info.m_dashStyle.is_initialized())
+ {
+ WPXString dst;
+ dst.sprintf("%d", info.m_dashStyle.get());
+ graphicsProps.insert("libmspub:dashstyle", dst);
+ }
}
else
{
@@ -1101,9 +1107,10 @@ void libmspub::MSPUBCollector::setShapeImgIndex(unsigned seqNum, unsigned
index)
m_shapeInfosBySeqNum[seqNum].m_imgIndex = index;
}
-void libmspub::MSPUBCollector::setShapeDash(unsigned seqNum, const Dash &dash)
+void libmspub::MSPUBCollector::setShapeDash(unsigned seqNum, unsigned dashStyle, const Dash &dash)
{
m_shapeInfosBySeqNum[seqNum].m_dash = dash;
+ m_shapeInfosBySeqNum[seqNum].m_dashStyle = dashStyle;
}
void libmspub::MSPUBCollector::setShapeFill(unsigned seqNum, boost::shared_ptr<Fill> fill, bool
skipIfNotBg)
diff --git a/src/lib/MSPUBCollector.h b/src/lib/MSPUBCollector.h
index 5755043..e23ba5e 100644
--- a/src/lib/MSPUBCollector.h
+++ b/src/lib/MSPUBCollector.h
@@ -96,7 +96,7 @@ public:
void setShapeCoordinatesInEmu(unsigned seqNum, int xs, int ys, int xe, int ye);
void setShapeImgIndex(unsigned seqNum, unsigned index);
void setShapeFill(unsigned seqNum, boost::shared_ptr<Fill> fill, bool skipIfNotBg);
- void setShapeDash(unsigned seqNum, const Dash &dash);
+ void setShapeDash(unsigned seqNum, unsigned dashStyle, const Dash &dash);
void setAdjustValue(unsigned seqNum, unsigned index, int adjust);
void setShapeRotation(unsigned seqNum, double rotation);
void setShapeFlip(unsigned, bool, bool);
diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index 9050a1c..a02915f 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -1679,7 +1679,7 @@ void libmspub::MSPUBParser::parseEscherShape(WPXInputStream *input, const
Escher
}
if (ptr_lineDashing)
{
- m_collector->setShapeDash(*shapeSeqNum, getDash(
+ m_collector->setShapeDash(*shapeSeqNum, *ptr_lineDashing, getDash(
static_cast<MSPUBDashStyle>(*ptr_lineDashing), lineWidth,
dotStyle));
}
@@ -1901,7 +1901,7 @@ boost::shared_ptr<libmspub::Fill> libmspub::MSPUBParser::getNewFill(const
std::m
boost::shared_ptr<GradientFill> ret(new GradientFill(m_collector, angle, (int)fillType));
ret->setFillCenter(fillLeftVal, fillTopVal, fillRightVal, fillBottomVal);
-
+
const unsigned *ptr_fillGrad = getIfExists_const(foptProperties, FIELDID_FILL_SHADE_COMPLEX);
if (ptr_fillGrad)
{
diff --git a/src/lib/ShapeInfo.h b/src/lib/ShapeInfo.h
index 9bbac5c..fd4eaad 100644
--- a/src/lib/ShapeInfo.h
+++ b/src/lib/ShapeInfo.h
@@ -70,6 +70,7 @@ struct ShapeInfo
bool m_stretchBorderArt;
boost::optional<ColorReference> m_lineBackColor;
boost::optional<Dash> m_dash;
+ boost::optional<unsigned> m_dashStyle;
boost::optional<TableInfo> m_tableInfo;
boost::optional<std::vector<unsigned> > m_tableCellTextEnds;
boost::optional<unsigned> m_numColumns;
@@ -86,7 +87,7 @@ struct ShapeInfo
m_textId(), m_adjustValuesByIndex(), m_adjustValues(),
m_rotation(), m_flips(), m_margins(), m_borderPosition(),
m_fill(), m_customShape(), m_stretchBorderArt(false),
- m_lineBackColor(), m_dash(), m_tableInfo(),
+ m_lineBackColor(), m_dash(), m_dashStyle(0), m_tableInfo(),
m_tableCellTextEnds(), m_numColumns(),
m_columnSpacing(0), m_beginArrow(), m_endArrow(),
m_verticalAlign(), m_pictureRecolor(), m_shadow(), m_innerRotation(), m_clipPath()
--
1.7.1
Context
- 2 Patches for libmspub · Franz Schmid
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.