File indexing completed on 2024-12-08 12:55:59

0001 /* This file is part of the KDE project
0002    Copyright (C) 2010 by Nokia
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "writer.h"
0021 
0022 #include "KoGenStyles.h"
0023 
0024 Writer::Writer(KoXmlWriter& xmlWriter, KoGenStyles& kostyles,
0025                bool stylesxml_)
0026         : xOffset(0),
0027         yOffset(0),
0028         scaleX(1),
0029         scaleY(1),
0030         g_rotation(0),
0031         g_flipH(0),
0032         g_flipV(0),
0033         xml(xmlWriter),
0034         styles(kostyles),
0035         stylesxml(stylesxml_)
0036 {
0037 }
0038 
0039 Writer Writer::transform(const QRectF& oldCoords, const QRectF &newCoords) const
0040 {
0041     Writer w(xml, styles, stylesxml);
0042     w.xOffset = xOffset + oldCoords.x() * scaleX;
0043     w.yOffset = yOffset + oldCoords.y() * scaleY;
0044     w.scaleX = scaleX * oldCoords.width() / newCoords.width();
0045     w.scaleY = scaleY * oldCoords.height() / newCoords.height();
0046     w.xOffset -= w.scaleX * newCoords.x();
0047     w.yOffset -= w.scaleY * newCoords.y();
0048     w.g_rotation = g_rotation;
0049     w.g_flipH = g_flipH;
0050     w.g_flipV = g_flipV;
0051     return w;
0052 }
0053 
0054 qreal Writer::vLength(qreal length) const
0055 {
0056     return length*scaleY;
0057 }
0058 
0059 qreal Writer::hLength(qreal length) const
0060 {
0061     return length*scaleX;
0062 }
0063 
0064 qreal Writer::vOffset(qreal offset) const
0065 {
0066     return yOffset + offset*scaleY;
0067 }
0068 
0069 qreal Writer::hOffset(qreal offset) const
0070 {
0071     return xOffset + offset*scaleX;
0072 }