src/lib/Coordinate.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/lib/Coordinate.h | 5 ++++- src/lib/MSPUBCollector.cpp | 14 +++++++++----- src/lib/MSPUBParser.cpp | 1 + src/lib/Makefile.am | 1 + src/lib/PolygonUtils.cpp | 17 ----------------- src/lib/PolygonUtils.h | 2 -- 7 files changed, 51 insertions(+), 25 deletions(-)
New commits: commit 28c545e7d04d58af998bcf4af5d1bb326d29836c Author: David Tardon <dtar...@redhat.com> Date: Mon Mar 12 11:23:48 2018 +0100 ofz#6469 ensure coords are in correct order I.e., xs <= xe and ys <= ye. The previous situation could lead to surprises like negative width/height. Change-Id: I23fc2786292d9eebe713870a69e577c9324da09f diff --git a/src/lib/Coordinate.cpp b/src/lib/Coordinate.cpp new file mode 100644 index 0000000..b865632 --- /dev/null +++ b/src/lib/Coordinate.cpp @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * This file is part of the libmspub project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "Coordinate.h" + +#include <utility> + +namespace libmspub +{ + +Coordinate::Coordinate(int xs, int ys, int xe, int ye) + : m_xs(xs) + , m_ys(ys) + , m_xe(xe) + , m_ye(ye) +{ + arrange(); +} + +void Coordinate::arrange() +{ + if (m_xs > m_xe) + std::swap(m_xs, m_xe); + if (m_ys > m_ye) + std::swap(m_ys, m_ye); +} + +} + +/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/Coordinate.h b/src/lib/Coordinate.h index bec3fe2..4471f86 100644 --- a/src/lib/Coordinate.h +++ b/src/lib/Coordinate.h @@ -10,14 +10,17 @@ #ifndef INCLUDED_COORDINATE_H #define INCLUDED_COORDINATE_H +#include <boost/cstdint.hpp> + #include "MSPUBConstants.h" namespace libmspub { struct Coordinate { - Coordinate(int xs, int ys, int xe, int ye) : m_xs(xs), m_ys(ys), m_xe(xe), m_ye(ye) { } + Coordinate(int xs, int ys, int xe, int ye); Coordinate() : m_xs(0), m_ys(0), m_xe(0), m_ye(0) { } + void arrange(); int m_xs, m_ys, m_xe, m_ye; double getXIn(double pageWidth) const { diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp index c050930..a2efb2c 100644 --- a/src/lib/MSPUBCollector.cpp +++ b/src/lib/MSPUBCollector.cpp @@ -459,10 +459,14 @@ Coordinate getFudgedCoordinates(Coordinate coord, const std::vector<Line> &lines } else { - fudged.m_xs += leftFudge; - fudged.m_xe -= rightFudge; - fudged.m_ys += topFudge; - fudged.m_ye -= bottomFudge; + if (unsigned(fudged.m_xe - fudged.m_xs) > leftFudge) + fudged.m_xs += leftFudge; + if (unsigned(fudged.m_xe - fudged.m_xs) > rightFudge) + fudged.m_xe -= rightFudge; + if (unsigned(fudged.m_ye - fudged.m_ys) > topFudge) + fudged.m_ys += topFudge; + if (unsigned(fudged.m_ye - fudged.m_ys) > bottomFudge) + fudged.m_ye -= bottomFudge; } return fudged; } diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp index 883cf67..b13bb47 100644 --- a/src/lib/MSPUBParser.cpp +++ b/src/lib/MSPUBParser.cpp @@ -1622,6 +1622,7 @@ void MSPUBParser::parseEscherShape(librevenge::RVNGInputStream *input, const Esc parentCoordinateSystem.m_ys = readU32(input); parentCoordinateSystem.m_xe = readU32(input); parentCoordinateSystem.m_ye = readU32(input); + parentCoordinateSystem.arrange(); definesRelativeCoordinates = true; } input->seek(sp.contentsOffset, librevenge::RVNG_SEEK_SET); diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 2573363..bd8a68a 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -16,6 +16,7 @@ libmspub_@MSPUB_MAJOR_VERSION@_@MSPUB_MINOR_VERSION@_la_SOURCES = \ BorderArtInfo.h \ ColorReference.cpp \ ColorReference.h \ + Coordinate.cpp \ Coordinate.h \ Dash.cpp \ Dash.h \ commit fc3a3285a47433d599627b64c8b97aa16569663a Author: David Tardon <dtar...@redhat.com> Date: Mon Mar 12 11:10:41 2018 +0100 drop unused function Change-Id: I5a64871e16d755496b69f749cc2a4a11d833bc00 diff --git a/src/lib/PolygonUtils.cpp b/src/lib/PolygonUtils.cpp index b5e47e9..7738809 100644 --- a/src/lib/PolygonUtils.cpp +++ b/src/lib/PolygonUtils.cpp @@ -5680,23 +5680,6 @@ double getSpecialIfNecessary(std::function<double(unsigned index)> calculator, i return special ? calculator(val ^ 0x80000000) : val; } -Coordinate CustomShape::getTextRectangle(double x, double y, double width, double height, std::function<double(unsigned index)> calculator) const -{ - double scaleX = width * m_coordWidth; - double scaleY = height * m_coordHeight; - if (m_numTextRectangles == 0) - { - return Coordinate(x, y, x + width, y + height); - } - const Vertex &start = mp_textRectangles[0].first; - const Vertex &end = mp_textRectangles[0].second; - double startX = x + scaleX * getSpecialIfNecessary(calculator, start.m_x); - double startY = y + scaleY * getSpecialIfNecessary(calculator, start.m_y); - double endX = x + scaleX * getSpecialIfNecessary(calculator, end.m_x); - double endY = y + scaleY * getSpecialIfNecessary(calculator, end.m_y); - return Coordinate(startX, startY, endX, endY); -} - namespace { diff --git a/src/lib/PolygonUtils.h b/src/lib/PolygonUtils.h index bf956d3..df0e05e 100644 --- a/src/lib/PolygonUtils.h +++ b/src/lib/PolygonUtils.h @@ -74,8 +74,6 @@ struct CustomShape unsigned m_numGluePoints; unsigned char m_adjustShiftMask; - Coordinate getTextRectangle(double x, double y, double width, double height, std::function<double(unsigned index)> calculator) const; - CustomShape(const Vertex *p_vertices, unsigned numVertices, const unsigned short *p_elements, unsigned numElements, const Calculation *p_calculations, unsigned numCalculations, const int *p_defaultAdjustValues, unsigned numDefaultAdjustValues, const TextRectangle *p_textRectangles, unsigned numTextRectangles, unsigned coordWidth, unsigned coordHeight, const Vertex *p_gluePoints, unsigned numGluePoints, unsigned char adjustShiftMask = 0) : mp_vertices(p_vertices), m_numVertices(numVertices), mp_elements(p_elements), m_numElements(numElements), commit b16a16cdb63c811dc860417bc8db9b012b7dd19f Author: David Tardon <dtar...@redhat.com> Date: Wed Mar 7 09:56:06 2018 +0100 ofz#6777 fix division by zero Change-Id: I62bd09260b448a585ef5864181b2c6bceb5b361c diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp index 405470e..c050930 100644 --- a/src/lib/MSPUBCollector.cpp +++ b/src/lib/MSPUBCollector.cpp @@ -1352,7 +1352,7 @@ double MSPUBCollector::getSpecialValue(const ShapeInfo &info, const CustomShape if (arg == ASPECT_RATIO) { const Coordinate coord = info.m_coordinates.get_value_or(Coordinate()); - return (double)coord.getWidthIn() / coord.getHeightIn(); + return coord.getHeightIn() != 0 ? double(coord.getWidthIn()) / coord.getHeightIn() : 0; } if (arg & OTHER_CALC_VAL) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits