[Libreoffice-commits] libvisio.git: 7 commits - src/lib
David Tardon
dtardon at redhat.com
Sat Apr 15 09:49:26 UTC 2017
src/lib/VSDContentCollector.cpp | 29 ++++---------
src/lib/VSDContentCollector.h | 7 ---
src/lib/VSDOutputElementList.cpp | 81 ++++++++++++++++++++++-----------------
src/lib/VSDOutputElementList.h | 5 +-
4 files changed, 62 insertions(+), 60 deletions(-)
New commits:
commit a77d75a76538c0217613ec59bff8a2494b61601b
Author: David Tardon <dtardon at redhat.com>
Date: Sat Apr 15 11:45:21 2017 +0200
avoid self-assignment
Change-Id: I57eb9e74fbe3430fb99d13505865e7b5633d85bf
diff --git a/src/lib/VSDOutputElementList.cpp b/src/lib/VSDOutputElementList.cpp
index a25da51..1d1ecde 100644
--- a/src/lib/VSDOutputElementList.cpp
+++ b/src/lib/VSDOutputElementList.cpp
@@ -519,10 +519,13 @@ libvisio::VSDOutputElementList::VSDOutputElementList(const libvisio::VSDOutputEl
libvisio::VSDOutputElementList &libvisio::VSDOutputElementList::operator=(const libvisio::VSDOutputElementList &elementList)
{
- m_elements.clear();
+ if (&elementList != this)
+ {
+ m_elements.clear();
- for (const auto &elem : elementList.m_elements)
- m_elements.push_back(clone(elem));
+ for (const auto &elem : elementList.m_elements)
+ m_elements.push_back(clone(elem));
+ }
return *this;
}
commit 66854863c4ea412f2ce11c2ca4c4dc4fa373f9fa
Author: David Tardon <dtardon at redhat.com>
Date: Sat Apr 15 11:42:24 2017 +0200
simplify container traversal
Change-Id: Id2e19536a679a62f0ff7da398e44aeeca0de8ce5
diff --git a/src/lib/VSDOutputElementList.cpp b/src/lib/VSDOutputElementList.cpp
index 7556dad..a25da51 100644
--- a/src/lib/VSDOutputElementList.cpp
+++ b/src/lib/VSDOutputElementList.cpp
@@ -513,24 +513,24 @@ libvisio::VSDOutputElementList::VSDOutputElementList()
libvisio::VSDOutputElementList::VSDOutputElementList(const libvisio::VSDOutputElementList &elementList)
: m_elements()
{
- for (auto iter = elementList.m_elements.begin(); iter != elementList.m_elements.end(); ++iter)
- m_elements.push_back(clone(*iter));
+ for (const auto &elem : elementList.m_elements)
+ m_elements.push_back(clone(elem));
}
libvisio::VSDOutputElementList &libvisio::VSDOutputElementList::operator=(const libvisio::VSDOutputElementList &elementList)
{
m_elements.clear();
- for (auto cstiter = elementList.m_elements.begin(); cstiter != elementList.m_elements.end(); ++cstiter)
- m_elements.push_back(clone(*cstiter));
+ for (const auto &elem : elementList.m_elements)
+ m_elements.push_back(clone(elem));
return *this;
}
void libvisio::VSDOutputElementList::append(const libvisio::VSDOutputElementList &elementList)
{
- for (auto cstiter = elementList.m_elements.begin(); cstiter != elementList.m_elements.end(); ++cstiter)
- m_elements.push_back(clone(*cstiter));
+ for (const auto &elem : elementList.m_elements)
+ m_elements.push_back(clone(elem));
}
libvisio::VSDOutputElementList::~VSDOutputElementList()
@@ -539,8 +539,8 @@ libvisio::VSDOutputElementList::~VSDOutputElementList()
void libvisio::VSDOutputElementList::draw(librevenge::RVNGDrawingInterface *painter) const
{
- for (auto iter = m_elements.begin(); iter != m_elements.end(); ++iter)
- (*iter)->draw(painter);
+ for (const auto &elem : m_elements)
+ elem->draw(painter);
}
void libvisio::VSDOutputElementList::addStyle(const librevenge::RVNGPropertyList &propList)
commit ac6dd7ff5f0156e3f5ed322a1d8c96b93bf04fbd
Author: David Tardon <dtardon at redhat.com>
Date: Sat Apr 15 11:43:29 2017 +0200
the dtor does not need to be virtual
Change-Id: I57cdfd7469b979d29da7f82e2495c183e08ac299
diff --git a/src/lib/VSDOutputElementList.h b/src/lib/VSDOutputElementList.h
index aef0bab..3222596 100644
--- a/src/lib/VSDOutputElementList.h
+++ b/src/lib/VSDOutputElementList.h
@@ -27,7 +27,7 @@ public:
VSDOutputElementList();
VSDOutputElementList(const VSDOutputElementList &elementList);
VSDOutputElementList &operator=(const VSDOutputElementList &elementList);
- virtual ~VSDOutputElementList();
+ ~VSDOutputElementList();
void append(const VSDOutputElementList &elementList);
void draw(librevenge::RVNGDrawingInterface *painter) const;
void addStyle(const librevenge::RVNGPropertyList &propList);
commit 0a9bbb5cd3d9d9fec4b2e7cc81f89cfff6c27e44
Author: David Tardon <dtardon at redhat.com>
Date: Sat Apr 15 11:39:56 2017 +0200
avoid manual memory management
Change-Id: Idd0c24ea2008303b948040d3cca9faf97481426c
diff --git a/src/lib/VSDOutputElementList.cpp b/src/lib/VSDOutputElementList.cpp
index 59cf392..7556dad 100644
--- a/src/lib/VSDOutputElementList.cpp
+++ b/src/lib/VSDOutputElementList.cpp
@@ -320,6 +320,23 @@ public:
} // namespace libvisio
+namespace
+{
+
+template<typename T, typename... Args>
+std::unique_ptr<T> make_unique(Args &&... args)
+{
+ return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+
+template<typename T>
+std::unique_ptr<T> clone(const std::unique_ptr<T> &other)
+{
+ return std::unique_ptr<T>(other->clone());
+}
+
+}
+
libvisio::VSDStyleOutputElement::VSDStyleOutputElement(const librevenge::RVNGPropertyList &propList) :
m_propList(propList) {}
@@ -496,131 +513,124 @@ libvisio::VSDOutputElementList::VSDOutputElementList()
libvisio::VSDOutputElementList::VSDOutputElementList(const libvisio::VSDOutputElementList &elementList)
: m_elements()
{
- std::vector<libvisio::VSDOutputElement *>::const_iterator iter;
- for (iter = elementList.m_elements.begin(); iter != elementList.m_elements.end(); ++iter)
- m_elements.push_back((*iter)->clone());
+ for (auto iter = elementList.m_elements.begin(); iter != elementList.m_elements.end(); ++iter)
+ m_elements.push_back(clone(*iter));
}
libvisio::VSDOutputElementList &libvisio::VSDOutputElementList::operator=(const libvisio::VSDOutputElementList &elementList)
{
- for (std::vector<VSDOutputElement *>::iterator iter = m_elements.begin(); iter != m_elements.end(); ++iter)
- delete (*iter);
-
m_elements.clear();
- for (std::vector<VSDOutputElement *>::const_iterator cstiter = elementList.m_elements.begin(); cstiter != elementList.m_elements.end(); ++cstiter)
- m_elements.push_back((*cstiter)->clone());
+ for (auto cstiter = elementList.m_elements.begin(); cstiter != elementList.m_elements.end(); ++cstiter)
+ m_elements.push_back(clone(*cstiter));
return *this;
}
void libvisio::VSDOutputElementList::append(const libvisio::VSDOutputElementList &elementList)
{
- for (std::vector<VSDOutputElement *>::const_iterator cstiter = elementList.m_elements.begin(); cstiter != elementList.m_elements.end(); ++cstiter)
- m_elements.push_back((*cstiter)->clone());
+ for (auto cstiter = elementList.m_elements.begin(); cstiter != elementList.m_elements.end(); ++cstiter)
+ m_elements.push_back(clone(*cstiter));
}
libvisio::VSDOutputElementList::~VSDOutputElementList()
{
- for (std::vector<VSDOutputElement *>::iterator iter = m_elements.begin(); iter != m_elements.end(); ++iter)
- delete (*iter);
- m_elements.clear();
}
void libvisio::VSDOutputElementList::draw(librevenge::RVNGDrawingInterface *painter) const
{
- for (std::vector<VSDOutputElement *>::const_iterator iter = m_elements.begin(); iter != m_elements.end(); ++iter)
+ for (auto iter = m_elements.begin(); iter != m_elements.end(); ++iter)
(*iter)->draw(painter);
}
void libvisio::VSDOutputElementList::addStyle(const librevenge::RVNGPropertyList &propList)
{
- m_elements.push_back(new VSDStyleOutputElement(propList));
+ m_elements.push_back(make_unique<VSDStyleOutputElement>(propList));
}
void libvisio::VSDOutputElementList::addPath(const librevenge::RVNGPropertyList &propList)
{
- m_elements.push_back(new VSDPathOutputElement(propList));
+ m_elements.push_back(make_unique<VSDPathOutputElement>(propList));
}
void libvisio::VSDOutputElementList::addGraphicObject(const librevenge::RVNGPropertyList &propList)
{
- m_elements.push_back(new VSDGraphicObjectOutputElement(propList));
+ m_elements.push_back(make_unique<VSDGraphicObjectOutputElement>(propList));
}
void libvisio::VSDOutputElementList::addStartTextObject(const librevenge::RVNGPropertyList &propList)
{
- m_elements.push_back(new VSDStartTextObjectOutputElement(propList));
+ m_elements.push_back(make_unique<VSDStartTextObjectOutputElement>(propList));
}
void libvisio::VSDOutputElementList::addOpenParagraph(const librevenge::RVNGPropertyList &propList)
{
- m_elements.push_back(new VSDOpenParagraphOutputElement(propList));
+ m_elements.push_back(make_unique<VSDOpenParagraphOutputElement>(propList));
}
void libvisio::VSDOutputElementList::addOpenSpan(const librevenge::RVNGPropertyList &propList)
{
- m_elements.push_back(new VSDOpenSpanOutputElement(propList));
+ m_elements.push_back(make_unique<VSDOpenSpanOutputElement>(propList));
}
void libvisio::VSDOutputElementList::addInsertText(const librevenge::RVNGString &text)
{
- m_elements.push_back(new VSDInsertTextOutputElement(text));
+ m_elements.push_back(make_unique<VSDInsertTextOutputElement>(text));
}
void libvisio::VSDOutputElementList::addInsertLineBreak()
{
- m_elements.push_back(new VSDInsertLineBreakOutputElement());
+ m_elements.push_back(make_unique<VSDInsertLineBreakOutputElement>());
}
void libvisio::VSDOutputElementList::addInsertTab()
{
- m_elements.push_back(new VSDInsertTabOutputElement());
+ m_elements.push_back(make_unique<VSDInsertTabOutputElement>());
}
void libvisio::VSDOutputElementList::addCloseSpan()
{
- m_elements.push_back(new VSDCloseSpanOutputElement());
+ m_elements.push_back(make_unique<VSDCloseSpanOutputElement>());
}
void libvisio::VSDOutputElementList::addCloseParagraph()
{
- m_elements.push_back(new VSDCloseParagraphOutputElement());
+ m_elements.push_back(make_unique<VSDCloseParagraphOutputElement>());
}
void libvisio::VSDOutputElementList::addEndTextObject()
{
- m_elements.push_back(new VSDEndTextObjectOutputElement());
+ m_elements.push_back(make_unique<VSDEndTextObjectOutputElement>());
}
void libvisio::VSDOutputElementList::addStartLayer(const librevenge::RVNGPropertyList &propList)
{
- m_elements.push_back(new VSDStartLayerOutputElement(propList));
+ m_elements.push_back(make_unique<VSDStartLayerOutputElement>(propList));
}
void libvisio::VSDOutputElementList::addEndLayer()
{
- m_elements.push_back(new VSDEndLayerOutputElement());
+ m_elements.push_back(make_unique<VSDEndLayerOutputElement>());
}
void libvisio::VSDOutputElementList::addOpenListElement(const librevenge::RVNGPropertyList &propList)
{
- m_elements.push_back(new VSDOpenListElementOutputElement(propList));
+ m_elements.push_back(make_unique<VSDOpenListElementOutputElement>(propList));
}
void libvisio::VSDOutputElementList::addOpenUnorderedListLevel(const librevenge::RVNGPropertyList &propList)
{
- m_elements.push_back(new VSDOpenUnorderedListLevelOutputElement(propList));
+ m_elements.push_back(make_unique<VSDOpenUnorderedListLevelOutputElement>(propList));
}
void libvisio::VSDOutputElementList::addCloseListElement()
{
- m_elements.push_back(new VSDCloseListElementOutputElement());
+ m_elements.push_back(make_unique<VSDCloseListElementOutputElement>());
}
void libvisio::VSDOutputElementList::addCloseUnorderedListLevel()
{
- m_elements.push_back(new VSDCloseUnorderedListLevelOutputElement());
+ m_elements.push_back(make_unique<VSDCloseUnorderedListLevelOutputElement>());
}
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/VSDOutputElementList.h b/src/lib/VSDOutputElementList.h
index 0a500e2..aef0bab 100644
--- a/src/lib/VSDOutputElementList.h
+++ b/src/lib/VSDOutputElementList.h
@@ -11,6 +11,7 @@
#define __VSDOUTPUTELEMENTLIST_H__
#include <map>
+#include <memory>
#include <list>
#include <vector>
#include <librevenge/librevenge.h>
@@ -52,7 +53,7 @@ public:
return m_elements.empty();
}
private:
- std::vector<VSDOutputElement *> m_elements;
+ std::vector<std::unique_ptr<VSDOutputElement>> m_elements;
};
commit 3bc1019910b759c4f27e0ff5f070eec1eeddc2a2
Author: David Tardon <dtardon at redhat.com>
Date: Sat Apr 15 11:07:12 2017 +0200
avoid manual memory management
Change-Id: If6557a9222cf6183b6e14ff2bcab134d8215dce5
diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index dd5ef82..2716b64 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -118,7 +118,7 @@ libvisio::VSDContentCollector::VSDContentCollector(
) :
m_painter(painter), m_isPageStarted(false), m_pageWidth(0.0), m_pageHeight(0.0),
m_shadowOffsetX(0.0), m_shadowOffsetY(0.0),
- m_scale(1.0), m_x(0.0), m_y(0.0), m_originalX(0.0), m_originalY(0.0), m_xform(), m_txtxform(0), m_misc(),
+ m_scale(1.0), m_x(0.0), m_y(0.0), m_originalX(0.0), m_originalY(0.0), m_xform(), m_txtxform(), m_misc(),
m_currentFillGeometry(), m_currentLineGeometry(), m_groupXForms(groupXFormsSequence.empty() ? 0 : &groupXFormsSequence[0]),
m_currentForeignData(), m_currentOLEData(), m_currentForeignProps(), m_currentShapeId(0), m_foreignType((unsigned)-1),
m_foreignFormat(0), m_foreignOffsetX(0.0), m_foreignOffsetY(0.0), m_foreignWidth(0.0), m_foreignHeight(0.0),
@@ -617,13 +617,13 @@ void libvisio::VSDContentCollector::_flushText()
double xmiddle = m_txtxform ? m_txtxform->width / 2.0 : m_xform.width / 2.0;
double ymiddle = m_txtxform ? m_txtxform->height / 2.0 : m_xform.height / 2.0;
- transformPoint(xmiddle,ymiddle, m_txtxform);
+ transformPoint(xmiddle,ymiddle, m_txtxform.get());
double x = xmiddle - (m_txtxform ? m_txtxform->width / 2.0 : m_xform.width / 2.0);
double y = ymiddle - (m_txtxform ? m_txtxform->height / 2.0 : m_xform.height / 2.0);
double angle = 0.0;
- transformAngle(angle, m_txtxform);
+ transformAngle(angle, m_txtxform.get());
librevenge::RVNGPropertyList textBlockProps;
@@ -2329,9 +2329,7 @@ void libvisio::VSDContentCollector::collectXFormData(unsigned level, const XForm
void libvisio::VSDContentCollector::collectTxtXForm(unsigned level, const XForm &txtxform)
{
_handleLevelChange(level);
- if (m_txtxform)
- delete (m_txtxform);
- m_txtxform = new XForm(txtxform);
+ m_txtxform.reset(new XForm(txtxform));
m_txtxform->x = m_txtxform->pinX - m_txtxform->pinLocX;
m_txtxform->y = m_txtxform->pinY - m_txtxform->pinLocY;
}
@@ -2569,11 +2567,7 @@ void libvisio::VSDContentCollector::collectShape(unsigned id, unsigned level, un
}
if (m_stencilShape->m_txtxform)
- {
- if (m_txtxform)
- delete m_txtxform;
- m_txtxform = new XForm(*(m_stencilShape->m_txtxform));
- }
+ m_txtxform.reset(new XForm(*(m_stencilShape->m_txtxform)));
m_stencilFields = m_stencilShape->m_fields;
for (unsigned i = 0; i < m_stencilFields.size(); i++)
@@ -3477,9 +3471,7 @@ void libvisio::VSDContentCollector::_handleLevelChange(unsigned level)
m_originalY = 0.0;
m_x = 0;
m_y = 0;
- if (m_txtxform)
- delete (m_txtxform);
- m_txtxform = 0;
+ m_txtxform.reset();
m_xform = XForm();
m_NURBSData.clear();
m_polylineData.clear();
@@ -3499,9 +3491,7 @@ void libvisio::VSDContentCollector::startPage(unsigned pageId)
_flushShape();
m_originalX = 0.0;
m_originalY = 0.0;
- if (m_txtxform)
- delete (m_txtxform);
- m_txtxform = 0;
+ m_txtxform.reset();
m_xform = XForm();
m_x = 0;
m_y = 0;
diff --git a/src/lib/VSDContentCollector.h b/src/lib/VSDContentCollector.h
index edf7b2a..049223c 100644
--- a/src/lib/VSDContentCollector.h
+++ b/src/lib/VSDContentCollector.h
@@ -15,6 +15,7 @@
#include <string>
#include <cmath>
#include <map>
+#include <memory>
#include <list>
#include <vector>
#include "libvisio_utils.h"
@@ -37,10 +38,6 @@ public:
std::vector<std::list<unsigned> > &documentPageShapeOrders,
VSDStyles &styles, VSDStencils &stencils
);
- virtual ~VSDContentCollector()
- {
- if (m_txtxform) delete (m_txtxform);
- };
void collectDocumentTheme(const VSDXTheme *theme);
void collectEllipticalArcTo(unsigned id, unsigned level, double x3, double y3, double x2, double y2, double angle, double ecc);
@@ -246,7 +243,7 @@ private:
double m_originalX;
double m_originalY;
XForm m_xform;
- XForm *m_txtxform;
+ std::unique_ptr<XForm> m_txtxform;
VSDMisc m_misc;
std::vector<librevenge::RVNGPropertyList> m_currentFillGeometry;
std::vector<librevenge::RVNGPropertyList> m_currentLineGeometry;
commit 511dcb3dd6525f501ebed2f3f33472982972e34e
Author: David Tardon <dtardon at redhat.com>
Date: Sat Apr 15 11:02:27 2017 +0200
explain what is being done
Change-Id: I9036aba359ce62bd7b3cbbd912626dcc12f7819f
diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index 34192bd..dd5ef82 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -84,7 +84,8 @@ unsigned computeBMPDataOffset(librevenge::RVNGInputStream *const input, const un
// determine palette size
input->seek(10, librevenge::RVNG_SEEK_CUR);
unsigned bpp = readU16(input);
- // sanitize bpp
+ // sanitize bpp - limit to the allowed range and then round up to one
+ // of the allowed values
if (bpp > 32)
bpp = 32;
const unsigned allowedBpp[] = {1, 4, 8, 16, 24, 32};
commit d23fcf032369c9d68ce0d8e2262e3f25a5a83342
Author: David Tardon <dtardon at redhat.com>
Date: Sat Apr 15 10:59:44 2017 +0200
ofz#1109 fix thinko
Change-Id: I45375acaf09e3bd9ce821c7aa7edcd357e120d2d
diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index ab37c41..34192bd 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -89,7 +89,7 @@ unsigned computeBMPDataOffset(librevenge::RVNGInputStream *const input, const un
bpp = 32;
const unsigned allowedBpp[] = {1, 4, 8, 16, 24, 32};
size_t bppIdx = 0;
- while (bppIdx < VSD_NUM_ELEMENTS(allowedBpp) && bpp < allowedBpp[bppIdx])
+ while (bppIdx < VSD_NUM_ELEMENTS(allowedBpp) && bpp > allowedBpp[bppIdx])
++bppIdx;
if (bpp < allowedBpp[bppIdx])
bpp = allowedBpp[bppIdx];
More information about the Libreoffice-commits
mailing list