diff options
author | David Tardon <dtardon@redhat.com> | 2018-03-12 11:23:48 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2018-03-12 12:56:55 +0100 |
commit | 28c545e7d04d58af998bcf4af5d1bb326d29836c (patch) | |
tree | c9828443233e79036e0302fea9c844faadd53cdc | |
parent | fc3a3285a47433d599627b64c8b97aa16569663a (diff) |
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
-rw-r--r-- | src/lib/Coordinate.cpp | 36 | ||||
-rw-r--r-- | src/lib/Coordinate.h | 5 | ||||
-rw-r--r-- | src/lib/MSPUBCollector.cpp | 12 | ||||
-rw-r--r-- | src/lib/MSPUBParser.cpp | 1 | ||||
-rw-r--r-- | src/lib/Makefile.am | 1 |
5 files changed, 50 insertions, 5 deletions
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 \ |