r13951 by fschmid - Removed the use of deprecated QMatrix class.
scribus-commit
scribus-commit at lists.scribus.net
Thu Sep 3 13:53:07 CEST 2009
Revision: 13951
Author: fschmid
Date: 2009-09-03T11:50:33.780309Z
Commit message: Removed the use of deprecated QMatrix class.
Changeset:
M /trunk/Scribus/scribus/ui/propertiespalette.cpp
M /trunk/Scribus/scribus/scpageoutput.h
M /trunk/Scribus/scribus/ui/arrowchooser.cpp
M /trunk/Scribus/scribus/canvasgesture_resize.cpp
M /trunk/Scribus/scribus/plugins/tools/pathstroker/pathstroker.cpp
M /trunk/Scribus/scribus/scpainter.h
M /trunk/Scribus/scribus/canvasmode_rotate.cpp
M /trunk/Scribus/scribus/scribusdoc.cpp
M /trunk/Scribus/scribus/pageitem.h
M /trunk/Scribus/scribus/plugins/aiimplugin/importai.cpp
M /trunk/Scribus/scribus/fpointarray.h
M /trunk/Scribus/scribus/canvasmode_editgradient.cpp
M /trunk/Scribus/scribus/fpoint.h
M /trunk/Scribus/scribus/scpageoutput_ps2.cpp
M /trunk/Scribus/scribus/scpainterex_gdi.cpp
M /trunk/Scribus/scribus/pdflib_core.cpp
M /trunk/Scribus/scribus/pageitem_imageframe.cpp
M /trunk/Scribus/scribus/plugins/svgimplugin/svgplugin.h
M /trunk/Scribus/scribus/scpainterex_ps2.cpp
M /trunk/Scribus/scribus/prefsmanager.cpp
M /trunk/Scribus/scribus/scribus.cpp
M /trunk/Scribus/scribus/plugins/xfigimplugin/importxfig.cpp
M /trunk/Scribus/scribus/fonts/scfontmetrics.cpp
M /trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
M /trunk/Scribus/scribus/plugins/wpgimplugin/importwpg.h
M /trunk/Scribus/scribus/scpainterex_gdiplus.h
M /trunk/Scribus/scribus/scpageoutput.cpp
M /trunk/Scribus/scribus/canvasmode_edit.cpp
M /trunk/Scribus/scribus/util_math.cpp
M /trunk/Scribus/scribus/pageitem.cpp
M /trunk/Scribus/scribus/canvasmode_drawbezier.cpp
M /trunk/Scribus/scribus/fpoint.cpp
M /trunk/Scribus/scribus/plugins/colorwheel/colorwheelwidget.h
M /trunk/Scribus/scribus/canvasmode_nodeedit.h
M /trunk/Scribus/scribus/plugins/svgimplugin/svgplugin.cpp
M /trunk/Scribus/scribus/plugins/tools/lenseffects/lensdialog.cpp
M /trunk/Scribus/scribus/canvasmode_legacy.cpp
M /trunk/Scribus/scribus/ui/extimageprops.cpp
M /trunk/Scribus/scribus/pageitem_textframe.cpp
M /trunk/Scribus/scribus/plugins/wpgimplugin/importwpg.cpp
M /trunk/Scribus/scribus/pageitem_pathtext.cpp
M /trunk/Scribus/scribus/scpainterex_gdi.h
M /trunk/Scribus/scribus/pdflib_core.h
M /trunk/Scribus/scribus/pslib.h
M /trunk/Scribus/scribus/ui/pageitemrotationsetter.cpp
M /trunk/Scribus/scribus/plugins/wmfimplugin/wmfcontext.h
M /trunk/Scribus/scribus/plugins/tools/transform/transformeffect.cpp
M /trunk/Scribus/scribus/scpainterexbase.h
M /trunk/Scribus/scribus/vgradient.h
M /trunk/Scribus/scribus/util_math.h
M /trunk/Scribus/scribus/scprintengine_gdi.cpp
M /trunk/Scribus/scribus/plugins/colorwheel/colorwheelwidget.cpp
M /trunk/Scribus/scribus/canvasmode_nodeedit.cpp
M /trunk/Scribus/scribus/scribusXml.cpp
M /trunk/Scribus/scribus/plugins/tools/pathconnect/pathconnect.cpp
M /trunk/Scribus/scribus/plugins/tools/2geomtools/pathalongpath/pathalongpath.cpp
M /trunk/Scribus/scribus/plugins/tools/pathcut/pathcut.cpp
M /trunk/Scribus/scribus/scpainterex_cairo.cpp
M /trunk/Scribus/scribus/plugins/wmfimplugin/wmfimport.cpp
M /trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp
M /trunk/Scribus/scribus/chartablemodel.cpp
M /trunk/Scribus/scribus/scpreview.cpp
M /trunk/Scribus/scribus/plugins/tools/pathfinder/pathfinderdialog.cpp
M /trunk/Scribus/scribus/pslib.cpp
M /trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
M /trunk/Scribus/scribus/scribusview.h
M /trunk/Scribus/scribus/plugins/svgexplugin/svgexplugin.h
M /trunk/Scribus/scribus/plugins/wmfimplugin/wmfcontext.cpp
M /trunk/Scribus/scribus/vgradientex.cpp
M /trunk/Scribus/scribus/canvas.h
M /trunk/Scribus/scribus/plugins/fileloader/oodraw/oodrawimp.cpp
M /trunk/Scribus/scribus/vgradient.cpp
M /trunk/Scribus/scribus/scimgdataloader_ps.cpp
M /trunk/Scribus/scribus/canvasmode_normal.cpp
M /trunk/Scribus/scribus/scpainter.cpp
M /trunk/Scribus/scribus/canvasmode_drawfreehand.cpp
M /trunk/Scribus/scribus/exif.cpp
M /trunk/Scribus/scribus/canvasmode_framelinks.cpp
M /trunk/Scribus/scribus/plugins/tools/transform/transformdialog.h
M /trunk/Scribus/scribus/fpointarray.cpp
M /trunk/Scribus/scribus/ui/charzoom.cpp
M /trunk/Scribus/scribus/pageitem_line.cpp
M /trunk/Scribus/scribus/scribusview.cpp
M /trunk/Scribus/scribus/pageitem_polyline.cpp
M /trunk/Scribus/scribus/plugins/svgexplugin/svgexplugin.cpp
M /trunk/Scribus/scribus/scpainterex_cairo.h
M /trunk/Scribus/scribus/ui/polygonwidget.cpp
M /trunk/Scribus/scribus/plugins/aiimplugin/importai.h
M /trunk/Scribus/scribus/canvas.cpp
M /trunk/Scribus/scribus/scpainterex_gdiplus.cpp
M /trunk/Scribus/scribus/scpainterex_ps2.h
M /trunk/Scribus/scribus/plugins/xfigimplugin/importxfig.h
M /trunk/Scribus/scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp
M /trunk/Scribus/scribus/plugins/cvgimplugin/importcvg.h
M /trunk/Scribus/scribus/vgradientex.h
M /trunk/Scribus/scribus/plugins/tools/transform/transformdialog.cpp
Diffs:
Index: scribus/fpointarray.h
===================================================================
--- scribus/fpointarray.h (revision 13950)
+++ scribus/fpointarray.h (revision 13951)
@@ -24,7 +24,7 @@
#ifndef FPOINTARRAY_H
#define FPOINTARRAY_H
-#include <QMatrix>
+#include <QTransform>
#include <QPainterPath>
#include <QPoint>
#include <QPointF>
@@ -59,7 +59,7 @@
void translate( double dx, double dy );
void scale( double sx, double sy );
FPoint WidthHeight() const;
- void map(QMatrix m);
+ void map(QTransform m);
FPointArray &operator=( const FPointArray &a );
FPointArray copy() const;
void setMarker();
Index: scribus/canvasmode_editgradient.cpp
===================================================================
--- scribus/canvasmode_editgradient.cpp (revision 13950)
+++ scribus/canvasmode_editgradient.cpp (revision 13951)
@@ -219,7 +219,7 @@
m_view->DrawNew();
return;
}
- QMatrix itemMatrix;
+ QTransform itemMatrix;
PageItem *currItem = m_doc->m_Selection->itemAt(0);
itemMatrix.translate(currItem->xPos(), currItem->yPos());
itemMatrix.rotate(currItem->rotation());
Index: scribus/pdflib_core.cpp
===================================================================
--- scribus/pdflib_core.cpp (revision 13950)
+++ scribus/pdflib_core.cpp (revision 13951)
@@ -1070,7 +1070,7 @@
if (ig.value().size() > 3)
{
FPointArray gly = ig.value();
- QMatrix mat;
+ QTransform mat;
mat.scale(100.0, -100.0);
gly.map(mat);
gly.translate(0, 1000);
@@ -1185,7 +1185,7 @@
if (ig.value().size() > 3)
{
FPointArray gly = ig.value();
- QMatrix mat;
+ QTransform mat;
mat.scale(0.1, 0.1);
gly.map(mat);
for (uint poi = 0; poi < gly.size()-3; poi += 4)
@@ -1976,13 +1976,13 @@
}
if (ite->startArrowIndex() != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.scale(-1,1);
PutPage(drawArrow(ite, arrowTrans, ite->startArrowIndex()));
}
if (ite->endArrowIndex() != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
PutPage(drawArrow(ite, arrowTrans, ite->endArrowIndex()));
}
break;
@@ -2081,7 +2081,7 @@
if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
{
double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(Start.x(), Start.y());
arrowTrans.rotate(r);
PutPage(drawArrow(ite, arrowTrans, ite->startArrowIndex()));
@@ -2098,7 +2098,7 @@
if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
{
double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(End.x(), End.y());
arrowTrans.rotate(r);
PutPage(drawArrow(ite, arrowTrans, ite->endArrowIndex()));
@@ -2773,7 +2773,7 @@
PutPage("q\n");
FPointArray cl = ite->PoLine.copy();
FPointArray clb = ite->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(ite->xPos() - mPage->xOffset(), (ite->yPos() - mPage->yOffset()) - mPage->height());
mm.rotate(ite->rotation());
cl.map( mm );
@@ -2872,7 +2872,7 @@
grcon += "q\n";
FPointArray cl = ite->PoLine.copy();
FPointArray clb = ite->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(ite->xPos() - pag->xOffset(), (ite->yPos() - pag->yOffset()) - pag->height());
mm.rotate(ite->rotation());
cl.map( mm );
@@ -3440,13 +3440,13 @@
}
if (ite->startArrowIndex() != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.scale(-1,1);
tmp += drawArrow(ite, arrowTrans, ite->startArrowIndex());
}
if (ite->endArrowIndex() != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(ite->width(), 0);
tmp += drawArrow(ite, arrowTrans, ite->endArrowIndex());
}
@@ -3555,7 +3555,7 @@
if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
{
double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(Start.x(), Start.y());
arrowTrans.rotate(r);
tmp += drawArrow(ite, arrowTrans, ite->startArrowIndex());
@@ -3572,7 +3572,7 @@
if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
{
double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(End.x(), End.y());
arrowTrans.rotate(r);
tmp += drawArrow(ite, arrowTrans, ite->endArrowIndex());
@@ -3629,7 +3629,7 @@
return true;
}
-QString PDFLibCore::drawArrow(PageItem *ite, QMatrix &arrowTrans, int arrowIndex)
+QString PDFLibCore::drawArrow(PageItem *ite, QTransform &arrowTrans, int arrowIndex)
{
QString tmp = "";
FPointArray arrow = doc.arrowStyles.at(arrowIndex-1).points.copy();
@@ -4187,13 +4187,13 @@
{
tmp += "q\n";
QPointF tangt = QPointF( cos(hl->PRot), sin(hl->PRot) );
- QMatrix trafo = QMatrix( 1, 0, 0, -1, -hl->PDx, 0 );
+ QTransform trafo = QTransform( 1, 0, 0, -1, -hl->PDx, 0 );
if (ite->textPathFlipped)
- trafo *= QMatrix(1, 0, 0, -1, 0, 0);
+ trafo *= QTransform(1, 0, 0, -1, 0, 0);
if (ite->textPathType == 0)
- trafo *= QMatrix( tangt.x(), -tangt.y(), -tangt.y(), -tangt.x(), hl->PtransX, -hl->PtransY );
+ trafo *= QTransform( tangt.x(), -tangt.y(), -tangt.y(), -tangt.x(), hl->PtransX, -hl->PtransY );
else if (ite->textPathType == 1)
- trafo *= QMatrix(1, 0, 0, -1, hl->PtransX, -hl->PtransY );
+ trafo *= QTransform(1, 0, 0, -1, hl->PtransX, -hl->PtransY );
else if (ite->textPathType == 2)
{
double a = 1;
@@ -4204,9 +4204,9 @@
b = 1;
}
if (fabs(tangt.x()) > 0.1)
- trafo *= QMatrix( a, (tangt.y() / tangt.x()) * b, 0, -1, hl->PtransX, -hl->PtransY ); // ID's Skew mode
+ trafo *= QTransform( a, (tangt.y() / tangt.x()) * b, 0, -1, hl->PtransX, -hl->PtransY ); // ID's Skew mode
else
- trafo *= QMatrix( a, 6 * b, 0, -1, hl->PtransX, -hl->PtransY );
+ trafo *= QTransform( a, 6 * b, 0, -1, hl->PtransX, -hl->PtransY );
}
tmp += FToStr(trafo.m11())+" "+FToStr(trafo.m12())+" "+FToStr(trafo.m21())+" "+FToStr(trafo.m22())+" "+FToStr(trafo.dx())+" "+FToStr(trafo.dy())+" cm\n";
if (ite->BaseOffs != 0)
@@ -4254,7 +4254,7 @@
tmp2 += "q\n";
FPointArray cl = embedded->PoLine.copy();
FPointArray clb = embedded->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
if (ite->asPathText())
mm.translate(embedded->gXpos * (style.scaleH() / 1000.0), ((embedded->gHeight * (style.scaleV() / 1000.0)) - embedded->gYpos * (style.scaleV() / 1000.0)) * -1);
else
@@ -4486,13 +4486,13 @@
/*if (ite->itemType() == PageItem::PathText)
{
QPointF tangt = QPointF( cos(hl->PRot), sin(hl->PRot) );
- QMatrix trafo = QMatrix( 1, 0, 0, -1, -hl->PDx, 0 );
+ QTransform trafo = QTransform( 1, 0, 0, -1, -hl->PDx, 0 );
if (ite->textPathFlipped)
- trafo *= QMatrix(1, 0, 0, -1, 0, 0);
+ trafo *= QTransform(1, 0, 0, -1, 0, 0);
if (ite->textPathType == 0)
- trafo *= QMatrix(tangt.x(), -tangt.y(), -tangt.y(), -tangt.x(), hl->PtransX, -hl->PtransY);
+ trafo *= QTransform(tangt.x(), -tangt.y(), -tangt.y(), -tangt.x(), hl->PtransX, -hl->PtransY);
else if (ite->textPathType == 1)
- trafo *= QMatrix(1, 0, 0, -1, hl->PtransX, -hl->PtransY );
+ trafo *= QTransform(1, 0, 0, -1, hl->PtransX, -hl->PtransY );
tmp2 += FToStr(trafo.m11())+" "+FToStr(trafo.m12())+" "+FToStr(trafo.m21())+" "+FToStr(trafo.m22())+" "+FToStr(trafo.dx())+" "+FToStr(trafo.dy())+" cm\n";
}*/
if (!ite->asPathText())
@@ -4524,7 +4524,7 @@
if (style.effects() & ScStyle_Outline)
{
FPointArray gly = style.font().glyphOutline(glyph);
- QMatrix mat;
+ QTransform mat;
mat.scale(0.1, 0.1);
gly.map(mat);
bool nPath = true;
@@ -4591,13 +4591,13 @@
/*if (ite->itemType() == PageItem::PathText)
{
QPointF tangt = QPointF( cos(hl->PRot), sin(hl->PRot) );
- QMatrix trafo = QMatrix( 1, 0, 0, -1, -hl->PDx, 0 );
+ QTransform trafo = QTransform( 1, 0, 0, -1, -hl->PDx, 0 );
if (ite->textPathFlipped)
- trafo *= QMatrix(1, 0, 0, -1, 0, 0);
+ trafo *= QTransform(1, 0, 0, -1, 0, 0);
if (ite->textPathType == 0)
- trafo *= QMatrix(tangt.x(), -tangt.y(), -tangt.y(), -tangt.x(), hl->PtransX, -hl->PtransY);
+ trafo *= QTransform(tangt.x(), -tangt.y(), -tangt.y(), -tangt.x(), hl->PtransX, -hl->PtransY);
else if (ite->textPathType == 1)
- trafo *= QMatrix(1, 0, 0, -1, hl->PtransX, -hl->PtransY );
+ trafo *= QTransform(1, 0, 0, -1, hl->PtransX, -hl->PtransY );
tmp2 += FToStr(trafo.m11())+" "+FToStr(trafo.m12())+" "+FToStr(trafo.m21())+" "+FToStr(trafo.m22())+" "+FToStr(trafo.dx())+" "+FToStr(trafo.dy())+" cm\n";
}*/
if (!ite->asPathText())
@@ -4625,7 +4625,7 @@
tmp2 += "1 0 0 1 0 "+FToStr( (((tsz / 10.0) - (tsz / 10.0) * (hl->glyph.scaleV)) / (tsz / 10.0)) * -1)+" cm\n";
tmp2 += FToStr(qMax(hl->glyph.scaleH, 0.1))+" 0 0 "+FToStr(qMax(hl->glyph.scaleV, 0.1))+" 0 0 cm\n";
FPointArray gly = style.font().glyphOutline(glyph);
- QMatrix mat;
+ QTransform mat;
mat.scale(0.1, 0.1);
gly.map(mat);
bool nPath = true;
@@ -5075,7 +5075,7 @@
tmp2 += "q\n";
FPointArray cl = item->PoLine.copy();
FPointArray clb = item->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(item->gXpos, item->gYpos - pat->height);
mm.rotate(item->rotation());
cl.map( mm );
@@ -5205,7 +5205,7 @@
PutDoc("/PaintType 1\n");
PutDoc("/TilingType 1\n");
PutDoc("/BBox [ 0 0 "+FToStr(pat->width)+" "+FToStr(pat->height)+" ]\n");
- QMatrix mpa;
+ QTransform mpa;
if (inPattern == 0)
{
mpa.translate(currItem->xPos() - ActPageP->xOffset(), ActPageP->height() - (currItem->yPos() - ActPageP->yOffset()));
@@ -6435,7 +6435,7 @@
PutDoc("<<\n/Type /XObject\n/Subtype /Form\n/FormType 1");
PoDoFo::PdfRect pagesize = page->GetPageSize();
int rotation = page->GetRotation();
- QMatrix pageM;
+ QTransform pageM;
pageM.scale(1.0/pagesize.GetWidth(), 1.0/pagesize.GetHeight());
pageM.rotate(-rotation);
PutDoc("\n/BBox [" + QString::number(pagesize.GetLeft()));
Index: scribus/scpainterex_ps2.cpp
===================================================================
--- scribus/scpainterex_ps2.cpp (revision 13950)
+++ scribus/scpainterex_ps2.cpp (revision 13951)
@@ -1,1391 +1,1391 @@
-
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-/* This file is part of the KDE project.
- Copyright (C) 2001, 2002, 2003 The Karbon Developers
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-/* Adapted for Scribus 22.08.2003 by Franz Schmid */
-// kopainter/libart wrapper
-
-#include "scpainterex_ps2.h"
-
-#include <cfloat>
-#include <QPaintDevice>
-#include <QPixmap>
-#include <QImage>
-
-#include <iostream>
-#include <memory>
-using namespace std;
-
-#include <cmath>
-#include "util.h"
-#include "sccolorengine.h"
-
-ScPs2OutputParams::ScPs2OutputParams(ScribusDoc* doc)
-{
- document = doc;
- colorMode = ScPainterExBase::rgbMode;
- reloadImages = true;
- resolution = 72;
- useProfiles = false;
- toGray = false;
- mirrorH = false;
- mirrorV = false;
- hProfile = NULL;
- rgbToOutputColorTransform = NULL;
- rgbToOutputImageTransform = NULL;
- cmykToOutputColorTransform = NULL;
- cmykToOutputImageTransform = NULL;
-}
-
-ScPainterEx_Ps2::ScPainterEx_Ps2(QIODevice* iodev, QRect& rect, ScPs2OutputParams& options ) : ScPainterExBase()
-{
- m_stream.setDevice( iodev );
- m_colorMode = options.colorMode;
- m_encoding = Ascii85Encoding;
- m_options = options;
- m_width = rect.width();
- m_height= rect.height();
- m_x = rect.left();
- m_y = rect.top();
- m_fillColor = ScColorShade( QColor(0,0,0), 100 );
- m_strokeColor = ScColorShade( QColor(0,0,0), 100 );
- m_fillTrans = 1.0;
- m_strokeTrans = 1.0;
- m_fillRule = true;
- m_fillMode = 1;
- m_lineWidth = 1.0;
- m_offset = 0;
- m_array.clear();
- m_lineEnd = Qt::SquareCap;
- m_lineJoin = Qt::RoundJoin;
- m_fillGradient = VGradientEx(VGradientEx::linear);
- m_strokeGradient = VGradientEx(VGradientEx::linear);
- m_matrix = QMatrix();
- m_pageTrans = QMatrix();
- // Path state
- m_pathIsClosed = true;
- m_drawingClosedPath = false;
- // TODO : set proper values
- m_deviceDimX = 0;
- m_deviceDimY = 0;
- m_deviceResX = 0;
- m_deviceResY = 0;
- clear();
-}
-
-ScPainterEx_Ps2::~ScPainterEx_Ps2()
-{
-}
-
-ScPainterExBase::ImageMode ScPainterEx_Ps2::imageMode()
-{
- ImageMode imageMode;
- if (m_options.hProfile && m_options.rgbToOutputImageTransform && m_options.cmykToOutputImageTransform)
- imageMode = rawImages;
- else if (m_colorMode == cmykMode)
- imageMode = cmykImages;
- else
- imageMode = rgbImages;
- return imageMode;
-}
-
-void ScPainterEx_Ps2::transformImage( QImage* image, uchar* data, int scan)
-{
- int rgb, grey;
- int imageWidth = image->width();
- int imageHeight = image->height();
-
- QRgb* pscani;
- uchar *pscand;
-
- pscand = data;
- for ( int j = 0; j < imageHeight; j++ )
- {
- pscani = (QRgb *) image->scanLine(j);
- for (int i = 0; i < imageWidth; i++ )
- {
- rgb = pscani[i];
- grey = qRound(0.3 * qRed(rgb)) + qRound(0.59 * qGreen(rgb)) + qRound(0.11 * qBlue(rgb));
- pscand[i] = grey;
- }
- pscand += scan;
- }
-
-}
-
-void ScPainterEx_Ps2::begin()
-{
-}
-
-void ScPainterEx_Ps2::end()
-{
-
-}
-
-void ScPainterEx_Ps2::clear()
-{
-
-}
-
-void ScPainterEx_Ps2::clear( ScColorShade &c )
-{
-
-}
-
-const QMatrix ScPainterEx_Ps2::worldMatrix()
-{
- return m_matrix;
-}
-
-void ScPainterEx_Ps2::setWorldMatrix( const QMatrix &mat )
-{
- m_matrix = mat;
-}
-
-void ScPainterEx_Ps2::transformPoint( const FPoint& in, FPoint& out )
-{
- double x, y;
- x = in.x() * m_matrix.m11() + in.y() * m_matrix.m21() + m_matrix.dx();
- y = in.x() * m_matrix.m12() + in.y() * m_matrix.m22() + m_matrix.dy();
- out.setX( x );
- out.setY( y );
-}
-
-void ScPainterEx_Ps2::transformPoints( const FPoint* ArrayIn, FPoint* ArrayOut, uint length )
-{
- for( uint i = 0; i < length; i++ )
- {
- transformPoint( ArrayIn[i], ArrayOut[i] );
- }
-}
-
-void ScPainterEx_Ps2::translate( double x, double y )
-{
- m_matrix.translate(x, y);
-}
-
-void ScPainterEx_Ps2::rotate( double r )
-{
- m_matrix.rotate(r);
-}
-
-void ScPainterEx_Ps2::scale( double x, double y )
-{
- m_matrix.scale(x, y);
-}
-
-void ScPainterEx_Ps2::moveTo( const double &x, const double &y )
-{
- FPoint pp( x, y );
- transformPoint( pp, pp );
- m_stream << QString("%1 %2 moveto\n").arg(pp.x()).arg(pp.y());
-}
-
-void ScPainterEx_Ps2::lineTo( const double &x, const double &y )
-{
- FPoint pp( x, y );
- transformPoint( pp, pp );
- m_stream << QString("%1 %2 lineto\n").arg(pp.x()).arg(pp.y());
-}
-
-void ScPainterEx_Ps2::curveTo( FPoint p1, FPoint p2, FPoint p3 )
-{
- FPoint pps[3];
- pps[0].setXY( p1.x(), p1.y() );
- pps[1].setXY( p2.x(), p2.y() );
- pps[2].setXY( p3.x(), p3.y() );
- transformPoints( pps, pps, 3 );
- m_stream << QString("%1 %2 %3 %4 %5 %6 curveto\n").arg(pps[0].x()).arg(pps[0].y()).arg(pps[1].x()).arg(pps[1].y()).arg(pps[2].x()).arg(pps[2].y());
-}
-
-void ScPainterEx_Ps2::newPath()
-{
- m_stream << "newpath\n";
- //pathIsClosed = false;
-}
-
-void ScPainterEx_Ps2::closePath()
-{
- m_stream << "closepath\n";
- m_pathIsClosed = true;
-}
-
-void ScPainterEx_Ps2::setFillRule( bool fillRule )
-{
- m_fillRule = fillRule;
-}
-
-void ScPainterEx_Ps2::setFillMode( int fill )
-{
- m_fillMode = fill;
-}
-
-void ScPainterEx_Ps2::setGradient(VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc)
-{
- m_fillGradient.setType(mode);
- m_fillGradient.setOrigin(orig);
- m_fillGradient.setVector(vec);
- m_fillGradient.setFocalPoint(foc);
-}
-
-void ScPainterEx_Ps2::setPattern( ScPattern* pattern, QMatrix& patternTransform )
-{
- m_pattern = pattern;
- m_patternTransform = patternTransform;
-}
-
-void ScPainterEx_Ps2::fillTextPath()
-{
- drawVPath( 0 );
-}
-
-void ScPainterEx_Ps2::strokeTextPath()
-{
- if( m_lineWidth == 0 )
- return;
- drawVPath( 1 );
-}
-
-void ScPainterEx_Ps2::fillPath()
-{
- if(!m_pathIsClosed)
- closePath();
- if( m_fillMode != 0)
- drawVPath( 0 );
-}
-
-void ScPainterEx_Ps2::strokePath()
-{
- if( m_lineWidth == 0 )
- return;
- save();
- if(!m_pathIsClosed)
- closePath();
- drawVPath( 1 );
- restore();
-}
-
-ScColorShade ScPainterEx_Ps2::pen()
-{
- return m_strokeColor;
-}
-
-ScColorShade ScPainterEx_Ps2::brush()
-{
- return m_fillColor;
-}
-
-void ScPainterEx_Ps2::setPen( const ScColorShade &c )
-{
- m_strokeColor = c;
-}
-
-void ScPainterEx_Ps2::setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo )
-{
- m_offset = 0;
- m_strokeColor = c;
- m_lineWidth = w;
- m_lineEnd = ca;
- m_lineJoin = jo;
- double Dt = qMax(2*w, 1.0);
- double Da = qMax(6*w, 1.0);
- m_array.clear();
- if (st == Qt::DashLine)
- m_array << Da << Dt;
- else if (st == Qt::DotLine)
- m_array << Dt;
- else if (st == Qt::DashDotLine)
- m_array << Da << Dt << Dt << Dt;
- else if (st == Qt::DashDotDotLine)
- m_array << Da << Dt << Dt << Dt << Dt << Dt;
-}
-
-void ScPainterEx_Ps2::setLineWidth( double w )
-{
- m_lineWidth = w;
-}
-
-void ScPainterEx_Ps2::setPenOpacity( double op )
-{
- m_strokeTrans = op;
-}
-
-void ScPainterEx_Ps2::setDash(const QVector<double>& array, double ofs)
-{
- m_array = array;
- m_offset = ofs;
-}
-
-void ScPainterEx_Ps2::setBrush( const ScColorShade &c )
-{
- m_fillColor = c;
-}
-
-void ScPainterEx_Ps2::setBrushOpacity( double op )
-{
- m_fillTrans = op;
-}
-
-void ScPainterEx_Ps2::setOpacity( double op )
-{
- m_fillTrans = op;
- m_strokeTrans = op;
-}
-
-void ScPainterEx_Ps2::setFont( const QFont &f)
-{
- m_font = f;
-}
-
-QFont ScPainterEx_Ps2::font()
-{
- return m_font;
-}
-
-void ScPainterEx_Ps2::save()
-{
- m_stack.push( m_matrix );
- m_stream << "gsave\n";
-}
-
-void ScPainterEx_Ps2::restore()
-{
- m_matrix = m_stack.pop();
- m_stream << "grestore\n";
-}
-
-void ScPainterEx_Ps2::setRasterOp( int )
-{
-}
-
-void ScPainterEx_Ps2::drawVPath( int mode )
-{
- save();
- if (mode == 0)
- {
- if (m_fillMode == ScPainterExBase::Gradient)
- drawGradient( m_fillGradient );
- else
- putColor( m_fillColor, true );
- }
- else
- {
- double m11 = m_matrix.m11();
- double m12 = m_matrix.m12();
- double m21 = m_matrix.m21();
- double m22 = m_matrix.m22();
- double norm2 = m11 * m11 + m12 * m12 + m21 * m21 + m22 * m22;
- double penScale = sqrt(norm2 /2.0);
- double penWidth = (int) (m_lineWidth * penScale);
- m_stream << QString("%1 setlinewidth\n").arg(penWidth);
-
- m_stream << "[";
- for( int i = 0; i < m_array.count();++ i )
- {
- m_stream << QString("%1").arg(m_array[i]) << " ";
- }
- m_stream << "]";
- m_stream << " 0 setdash\n";
-
- if( m_lineEnd == Qt::RoundCap )
- m_stream << "1 setlinecap\n";
- else if( m_lineEnd == Qt::SquareCap )
- m_stream << "2 setlinecap\n";
- else if( m_lineEnd == Qt::FlatCap )
- m_stream << "0 setlinecap\n";
- else
- m_stream << "0 setlinecap\n";
-
- if( m_lineJoin == Qt::RoundJoin )
- m_stream << "1 setlinejoin\n";
- else if( m_lineJoin == Qt::BevelJoin )
- m_stream << "2 setlinejoin\n";
- else if( m_lineJoin == Qt::MiterJoin )
- m_stream << "0 setlinejoin\n";
- else
- m_stream << "0 setlinejoin\n";
-
- putColor(m_strokeColor, false);
- }
- restore();
-}
-
-void ScPainterEx_Ps2::setClipPath()
-{
- //TODO eoclip or clip?
- m_stream << "clip newpath\n";
- m_clipBBox = m_pathBBox;
-}
-
-void ScPainterEx_Ps2::putColor( ScColorShade& colorShade, bool doFill )
-{
- ColorMode colorMode = m_colorMode;
- int r = 0, g = 0, b = 0, gray = 0;
- int c = 0, m = 0, y = 0, k = 0;
- if ( m_options.toGray )
- {
- RGBColor rgb;
- ScColorEngine::getShadeColorRGB(colorShade.color, m_options.document, rgb, colorShade.shade);
- rgb.getValues(r, g, b);
- gray = qRound(0.3 * r + 0.59 * g + 0.11 * b);
- if ( doFill && m_fillRule )
- m_stream << QString("%1 setgray eofill\n").arg(gray/255.0);
- else if ( doFill )
- m_stream << QString("%1 setgray fill\n").arg(gray/255.0);
- else
- m_stream << QString("%1 setgray stroke\n").arg(gray/255.0);
- return;
- }
- else if ( m_options.hProfile && m_options.rgbToOutputColorTransform && m_options.cmykToOutputColorTransform)
- {
- DWORD colorIn[4];
- DWORD colorOut[4];
- cmsHTRANSFORM cmsTranform = NULL;
- if( colorShade.color.getColorModel() == colorModelRGB )
- {
- RGBColor rgb;
- ScColorEngine::getShadeColorRGB(colorShade.color, m_options.document, rgb, colorShade.shade);
- colorIn[0] = rgb.r;
- colorIn[1] = rgb.g;
- colorIn[2] = rgb.b;
- colorMode = rgbMode;
- cmsTranform = m_options.rgbToOutputColorTransform;
- }
- else
- {
- CMYKColor cmyk;
- ScColorEngine::getShadeColorCMYK(colorShade.color, m_options.document, cmyk, colorShade.shade);
- colorIn[0] = cmyk.c;
- colorIn[1] = cmyk.m;
- colorIn[2] = cmyk.y;
- colorIn[3] = cmyk.k;
- colorMode = cmykMode;
- cmsTranform = m_options.cmykToOutputColorTransform;
- }
- cmsDoTransform( cmsTranform, colorIn, colorOut, 1 );
- if (static_cast<int>(cmsGetColorSpace(m_options.hProfile)) == icSigRgbData)
- {
- r = colorOut[0] / 257;
- g = colorOut[1] / 257;
- b = colorOut[2] / 257;
- colorMode = rgbMode;
- }
- else if (static_cast<int>(cmsGetColorSpace(m_options.hProfile)) == icSigCmykData)
- {
- c = colorOut[0] / 257;
- m = colorOut[1] / 257;
- y = colorOut[2] / 257;
- k = colorOut[3] / 257;
- colorMode = cmykMode;
- }
- }
- else if ( m_colorMode == rgbMode )
- {
- RGBColor rgb;
- colorMode = rgbMode;
- ScColorEngine::getShadeColorRGB(colorShade.color, m_options.document, rgb, colorShade.shade);
- rgb.getValues(r, g, b);
- }
- else if ( m_colorMode == cmykMode )
- {
- CMYKColor cmyk;
- colorMode = cmykMode;
- ScColorEngine::getShadeColorCMYK(colorShade.color, m_options.document, cmyk, colorShade.shade);
- cmyk.getValues(c, m, y, k);
- }
-
- // Finally output to file
- if ( colorMode == rgbMode )
- {
- if ( doFill && m_fillRule )
- m_stream << QString("%1 %2 %3 setrgbcolor eofill\n").arg(r/255.0).arg(g/255.0).arg(b/255.0);
- else if ( doFill )
- m_stream << QString("%1 %2 %3 setrgbcolor fill\n").arg(r/255.0).arg(g/255.0).arg(b/255.0);
- else
- m_stream << QString("%1 %2 %3 setrgbcolor stroke\n").arg(r/255.0).arg(g/255.0).arg(b/255.0);
- }
- else if ( colorMode == cmykMode )
- {
- QString colstr1 = QString("%1 %2 %3 %4 setcmykcolor").arg(c/255.0).arg(m/255.0).arg(y/255.0).arg(k/255.0);
- if ( doFill && m_fillRule )
- m_stream << colstr1 << " eofill\n";
- else if ( doFill )
- m_stream << colstr1 << " fill\n";
- else
- m_stream << colstr1 << " stroke\n";
- }
-}
-
-void ScPainterEx_Ps2::drawImage( ScImage *image, ScPainterExBase::ImageMode mode )
-{
- bool rgbMode = (mode == ScPainterExBase::rgbImages || mode == ScPainterExBase::rgbProofImages);
- bool rgbPicture = rgbMode || (mode == ScPainterExBase::rawImages && image->imgInfo.colorspace == ColorSpaceRGB);
- bool cmykPicture = (mode == ScPainterExBase::cmykImages || (mode == ScPainterExBase::rawImages && image->imgInfo.colorspace == ColorSpaceCMYK));
-
- if( rgbPicture )
- drawRGBImage_ps2( image );
- else if( cmykPicture )
- drawCMYKImage_ps2( image );
- else
- qDebug( "ScPainterEx_Ps2::drawImage() : unknown image type" );
-}
-
-void ScPainterEx_Ps2::drawRGBImage_ps2( ScImage *image )
-{
- save();
- QString sc("[%1 %2 %3 %4 %5 %6] concat\n");
- m_stream << sc.arg(m_matrix.m11()).arg(m_matrix.m12()).arg(m_matrix.m21()).arg(m_matrix.m22()).arg(m_matrix.dx()).arg(m_matrix.dy());
- m_stream << QString("%1 %2 scale\n").arg(image->width()).arg(image->height());
- m_stream << "/DeviceRGB setcolorspace\n";
- if (hasAlphaChannel(image))
- {
- QImage imgTemp = image->qImage();
- QImage mask = imgTemp.createAlphaMask();
- if (m_encoding == Ascii85Encoding)
- {
- m_stream << "currentfile /ASCII85Decode filter /ReusableStreamDecode filter\n";
- writeRGBImageToStream_Ascii85(image);
- }
- else
- {
- m_stream << "currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n";
- writeRGBImageToStream_AsciiHex(image);
- }
- m_stream << "/myImage exch def\n";
- m_stream << "currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n";
- writeMaskToStream(&mask);
- m_stream << "/myMask exch def\n";
- m_stream << QString("<<\n");
- m_stream << QString(" /PaintType 1\n");
- m_stream << QString(" /PatternType 1\n");
- m_stream << QString(" /TilingType 3\n");
- m_stream << QString(" /BBox [ 0 0 1 1 ]\n");
- m_stream << QString(" /XStep 2\n");
- m_stream << QString(" /YStep 2\n");
- m_stream << QString(" /PaintProc {\n");
- m_stream << QString(" pop\n");
- m_stream << QString(" 0 0 0 setrgbcolor\n");
- m_stream << QString(" <<\n");
- m_stream << QString(" /ImageType 1\n");
- m_stream << QString(" /Width %1\n").arg(image->width());
- m_stream << QString(" /Height %1\n").arg(image->height());
- m_stream << QString(" /ImageMatrix [ %1 0 0 %2 0 0 ]\n").arg(image->width()).arg(image->height());
- m_stream << QString(" /BitsPerComponent 8\n");
- m_stream << QString(" /Decode [0 1 0 1 0 1]\n");
- m_stream << QString(" /DataSource myImage\n");
- m_stream << QString(" >>\n");
- m_stream << QString(" image\n");
- m_stream << QString(" }\n");
- m_stream << QString(">> matrix makepattern setpattern\n");
- m_stream << QString("<<\n");
- m_stream << QString(" /ImageType 1\n");
- m_stream << QString(" /Width %1 \n").arg(image->width());
- m_stream << QString(" /Height %1 \n").arg(image->height());
- m_stream << QString(" /BitsPerComponent 1\n");
- m_stream << QString(" /Decode [1 0]\n");
- m_stream << QString(" /ImageMatrix [ %1 0 0 %2 0 0 ]\n").arg(image->width()).arg(image->height());
- m_stream << QString(" /DataSource myMask\n");
- m_stream << QString(">>\n");
- m_stream << QString("imagemask\n");
- }
- else
- {
- m_stream << QString("<<\n");
- m_stream << QString(" /ImageType 1\n");
- m_stream << QString(" /Width %1\n").arg(image->width());
- m_stream << QString(" /Height %1\n").arg(image->height());
- m_stream << QString(" /ImageMatrix [ %1 0 0 %2 0 0 ]\n").arg(image->width()).arg(image->height());
- m_stream << QString(" /Decode [0 1 0 1 0 1]\n");
- m_stream << QString(" /BitsPerComponent 8\n");
- //TODO case where compression is available
- if (m_encoding == Ascii85Encoding)
- {
- m_stream << QString(" /DataSource currentfile /ASCII85Decode filter\n");
- m_stream << QString(">>\n");
- m_stream << "image\n";
- writeRGBImageToStream_Ascii85(image);
- }
- else
- {
- m_stream << QString(" /DataSource currentfile /ASCIIHexDecode filter\n");
- m_stream << QString(">>\n");
- m_stream << "image\n";
- writeRGBImageToStream_AsciiHex(image);
- }
- }
- restore();
-}
-
-void ScPainterEx_Ps2::drawCMYKImage_ps2( ScImage *image )
-{
- save();
- QString sc("[%1 %2 %3 %4 %5 %6] concat\n");
- m_stream << sc.arg(m_matrix.m11()).arg(m_matrix.m12()).arg(m_matrix.m21()).arg(m_matrix.m22()).arg(m_matrix.dx()).arg(m_matrix.dy());
- m_stream << QString("%1 %2 scale\n").arg(image->width()).arg(image->height());
- m_stream << "/DeviceCMYK setcolorspace\n";
- // TODO case where image have a mask
- bool haveMask = false;
- if (haveMask)
- {
-
- }
- else
- {
- m_stream << "<<\n";
- m_stream << QString(" /ImageType 1\n");
- m_stream << QString(" /Width %1\n").arg(image->width());
- m_stream << QString(" /Height %1\n").arg(image->height());
- m_stream << QString(" /ImageMatrix [ %1 0 0 %2 0 0 ]\n").arg(image->width()).arg(image->height());
- m_stream << QString(" /Decode [0 1 0 1 0 1 0 1]\n");
- m_stream << QString(" /BitsPerComponent 8\n");
- //TODO case where compression is available
- if (m_encoding == Ascii85Encoding)
- {
- m_stream << QString(" /DataSource currentfile /ASCII85Decode filter\n");
- m_stream << QString(">>\n");
- m_stream << "image\n";
- writeCMYKImageToStream_Ascii85(image);
- }
- else
- {
- m_stream << QString(" /DataSource currentfile /ASCIIHexDecode filter\n");
- m_stream << QString(">>\n");
- m_stream << "image\n";
- writeCMYKImageToStream_AsciiHex(image);
- }
- }
- restore();
-}
-
-bool ScPainterEx_Ps2::hasAlphaChannel( ScImage* image )
-{
- bool hasAlpha = false;
- int width = image->width();
- int height = image->height();
- for( int y = 0; y < height; y++ )
- {
- QRgb* imageBits = (QRgb*)(image->qImage().scanLine(y));
- for( int x = 0; x < width; ++x )
- {
- if( qAlpha(*imageBits) != 255 )
- {
- hasAlpha = true;
- break;
- }
- imageBits++;
- }
- }
- return hasAlpha;
-}
-
-void ScPainterEx_Ps2::writeMaskToStream( QImage* image )
-{
- int length = 0;
- unsigned char bits;
- int width = image->width() / 8;
- int height = image->height();
- if ((image->width() % 8) != 0)
- width++;
- for( int y = 0; y < height; ++y )
- {
- unsigned char* imageBits = image->scanLine(y);
- for( int x = 0; x < width; x++ )
- {
- length++;
- bits = imageBits[x];
- m_stream << toHex(bits);
- if ( (length % 49) == 0 )
- m_stream << "\n";
- }
- }
- m_stream << "\n>\n";
-}
-
-void ScPainterEx_Ps2::writeRGBImageToStream_Ascii85( ScImage* image )
-{
- int cindex;
- int pending = 0, written = 0;
- bool allZero = true;
- unsigned char four_tuple[4];
- const char* ascii85;
- quint32 value;
-
- int width = image->width();
- int height = image->height();
- for( int y = 0; y < height; ++y )
- {
- QRgb* imageBits = (QRgb*)(image->qImage().scanLine(y));
- for( int x = 0; x < width; ++x )
- {
- cindex = 0;
- while (cindex < 3)
- {
- if (cindex == 0)
- four_tuple[pending++] = (uchar) qRed(*imageBits);
- else if (cindex == 1)
- four_tuple[pending++] = (uchar) qGreen(*imageBits);
- else if (cindex == 2)
- four_tuple[pending++] = (uchar) qBlue(*imageBits);
- if (pending == 4)
- {
- value = four_tuple[0] << 24 | four_tuple[1] << 16 | four_tuple[2] << 8 | four_tuple[3];
- ascii85 = toAscii85(value, allZero);
- if (allZero)
- m_stream << "z";
- else
- m_stream << ascii85;
- written += ((allZero) ? 1 : 5);
- if (written > 75)
- {
- m_stream << "\n";
- written = 0;
- }
- pending = 0;
- }
- ++cindex;
- }
-
- }
- }
- if (pending)
- {
- unsigned char five_tuple[6];
- memset (four_tuple + pending, 0, 4 - pending);
- value = four_tuple[0] << 24 | four_tuple[1] << 16 | four_tuple[2] << 8 | four_tuple[3];
- ascii85 = toAscii85(value, allZero);
- memcpy (five_tuple, ascii85, 5);
- five_tuple[pending + 1] = 0;
- m_stream << (const char*) five_tuple;
- }
- m_stream << "~>\n";
-}
-
-void ScPainterEx_Ps2::writeRGBImageToStream_AsciiHex ( ScImage* image )
-{
- int length = 0;
- int width = image->width();
- int height = image->height();
- for( int y = 0; y < height; ++y )
- {
- QRgb* imageBits = (QRgb*)(image->qImage().scanLine(y));
- for( int x = 0; x < width; ++x )
- {
- length++;
- uchar r = (uchar) qRed(*imageBits);
- m_stream << toHex(r);
- uchar g = (uchar) qGreen(*imageBits);
- m_stream << toHex(g);
- uchar b = (uchar) qBlue(*imageBits);
- m_stream << toHex(b);
- if ( (length % 17) == 0 )
- m_stream << "\n";
- imageBits++;
- }
- }
- m_stream << "\n>\n";
-}
-
-void ScPainterEx_Ps2::writeCMYKImageToStream_Ascii85( ScImage* image )
-{
- int written = 0;
- bool allZero = true;
- unsigned char four_tuple[4];
- const char* ascii85;
- quint32 value;
-
- int width = image->width();
- int height = image->height();
- for( int y = 0; y < height; y++ )
- {
- QRgb* imageBits = (QRgb*)(image->qImage().scanLine(y));
- for( int x = 0; x < width; x++ )
- {
- four_tuple[0] = (uchar) qRed(*imageBits);
- four_tuple[1] = (uchar) qGreen(*imageBits);
- four_tuple[2] = (uchar) qBlue(*imageBits);
- four_tuple[3] = (uchar) qAlpha(*imageBits);
- value = four_tuple[0] << 24 | four_tuple[1] << 16 | four_tuple[2] << 8 | four_tuple[3];
- ascii85 = toAscii85(value, allZero);
- if (allZero)
- m_stream << "z";
- else
- m_stream << ascii85;
- written += ((allZero) ? 1 : 5);
- if (written > 75)
- {
- m_stream << "\n";
- written = 0;
- }
- imageBits++;
- }
- }
- m_stream << "~>\n";
-}
-
-void ScPainterEx_Ps2::writeCMYKImageToStream_AsciiHex( ScImage* image )
-{
- int length = 0;
- int width = image->width();
- int height = image->height();
- for( int y = 0; y < height; ++y )
- {
- QRgb* imageBits = (QRgb*)(image->qImage().scanLine(y));
- for( int x = 0; x < width; ++x )
- {
- length++;
- uchar c = (uchar) qRed(*imageBits);
- m_stream << toHex(c);
- uchar m = (uchar) qGreen(*imageBits);
- m_stream << toHex(m);
- uchar y = (uchar) qBlue(*imageBits);
- m_stream << toHex(y);
- uchar k = (uchar) qAlpha(*imageBits);
- m_stream << toHex(k);
- if ( (length % 13) == 0 )
- m_stream << "\n";
- imageBits++;
- }
- }
- m_stream << "\n>\n";
-}
-
-void ScPainterEx_Ps2::setupPolygon(FPointArray *points, bool closed)
-{
- bool nPath = true;
- FPoint np, np1, np2, np3;
- if (points->size() > 3)
- {
- newPath();
- for (uint poi=0; poi<points->size()-3; poi += 4)
- {
- if (points->point(poi).x() > 900000)
- {
- nPath = true;
- continue;
- }
- if (nPath)
- {
- np = points->point(poi);
- // TODO startfigure needed?
- moveTo( np.x(), np.y() );
- nPath = false;
- }
- np = points->point(poi);
- np1 = points->point(poi+1);
- np2 = points->point(poi+3);
- np3 = points->point(poi+2);
- if ((np == np1) && (np2 == np3))
- lineTo( np3.x(), np3.y() );
- else
- curveTo(np1, np2, np3);
- }
- if (closed)
- {
- closePath();
- m_drawingClosedPath = true;
- }
- }
- getPathBoundingBox( points, m_pathBBox );
-}
-
-void ScPainterEx_Ps2::drawPolygon()
-{
- fillPath();
-}
-
-void ScPainterEx_Ps2::drawPolyLine()
-{
- strokePath();
-}
-
-void ScPainterEx_Ps2::drawLine(FPoint start, FPoint end)
-{
- newPath();
- moveTo(start.x(), start.y());
- lineTo(end.x(), end.y());
- strokePath();
-}
-
-void ScPainterEx_Ps2::drawRect(double x, double y, double w, double h)
-{
- newPath();
- moveTo( x, y );
- lineTo( x+w, y );
- lineTo( x+w, y+h );
- lineTo( x, y+h );
- lineTo( x, y );
- closePath();
- m_drawingClosedPath = true;
- fillPath();
- strokePath();
-}
-
-void ScPainterEx_Ps2::drawGradient( VGradientEx& gradient )
-{
- QRect clipPathRect;
- save();
- //setClipPath();
- m_stream << "clip\n";
- m_clipBBox = m_pathBBox;
- if ( gradient.type() == VGradientEx::linear )
- drawLinearGradient( gradient, m_clipBBox );
- else if ( gradient.type() == VGradientEx::radial )
- drawCircularGradient( gradient, m_clipBBox );
- restore();
-}
-
-void ScPainterEx_Ps2::drawLinearGradient( VGradientEx& gradient, const QRect& rect )
-{
- if (m_colorMode == cmykMode)
- drawLinearGradient_CMYK(gradient, rect);
- else
- drawLinearGradient_RGB(gradient, rect);
-}
-
-void ScPainterEx_Ps2::drawLinearGradient_RGB( VGradientEx& gradient, const QRect& rect )
-{
- int r1, g1, b1;
- int r2, g2, b2;
- double cosa, sina;
- double ramp1, ramp2;
- double scale1, scale2;
- double length, scale;
- double x1, y1, x2, y2, dx, dy;
- int clipBoxWidth, clipBoxHeight, maxDim;
- QList<VColorStopEx*> colorStops = gradient.colorStops();
- VColorStopEx stop1( *colorStops[0] );
- VColorStopEx stop2( *colorStops[0] );
- RGBColor rgb;
- FPoint p1, p2;
- QColor color;
-
- if ( gradient.Stops() < 2 )
- return;
-
- clipBoxWidth = rect.width();
- clipBoxHeight = rect.height();
- maxDim = qRound(sqrt( (double) (clipBoxWidth * clipBoxWidth + clipBoxHeight * clipBoxHeight) )) * 2;
- if ( maxDim <= 0 ) return;
-
- scale1 = sqrt( m_matrix.m11() * m_matrix.m11() + m_matrix.m12() * m_matrix.m12() );
- scale2 = sqrt( m_matrix.m21() * m_matrix.m21() + m_matrix.m22() * m_matrix.m22() );
-
- x1 = m_matrix.dx() + gradient.origin().x() * m_matrix.m11();
- y1 = m_matrix.dy() + gradient.origin().y() * m_matrix.m22();
- x2 = m_matrix.dx() + gradient.vector().x() * m_matrix.m11();
- y2 = m_matrix.dy() + gradient.vector().y() * m_matrix.m22();
- p1.setXY( x1, y1 );
- p2.setXY( x2, y2 );
-
- dx = ( p2.x() - p1.x() );
- dy = ( p2.y() - p1.y() );
- length = sqrt(( dx * dx + dy * dy ));
- if ( length == 0.0 )
- scale = 1.0;
- else
- scale = 1.0 / length;
- cosa = dx * scale;
- sina = dy * scale;
-
- QString sc("[%1 %2 %3 %4 %5 %6] concat\n");
- m_stream << sc.arg(cosa).arg(sina).arg(-sina).arg(cosa).arg(x1).arg(y1);
-
- ramp1 = stop1.rampPoint;
- ScColorEngine::getShadeColorRGB(stop1.color, m_options.document, rgb, stop1.shade);
- rgb.getValues(r1, g1, b1);
- m_stream << QString("%1 %2 %3 setrgbcolor fill\n").arg(r1/255.0).arg(g1/255.0).arg(b1/255.0);
-
- for( uint index = 1; index < gradient.Stops(); index++)
- {
- stop2 = *colorStops[index];
- ramp2 = stop2.rampPoint;
- ScColorEngine::getShadeColorRGB(stop2.color, m_options.document, rgb, stop2.shade);
- rgb.getValues(r2, g2, b2);
- double xMin = length * ramp1;
- double xMax = length * ramp2;
-
- m_stream << QString("/x1 %1 def\n").arg(xMin);
- m_stream << QString("/x2 %1 def\n").arg(xMax);
- m_stream << QString("/r1 %1 def\n").arg(r1/255.0);
- m_stream << QString("/g1 %1 def\n").arg(g1/255.0);
- m_stream << QString("/b1 %1 def\n").arg(b1/255.0);
- m_stream << QString("/r2 %1 def\n").arg(r2/255.0);
- m_stream << QString("/g2 %1 def\n").arg(g2/255.0);
- m_stream << QString("/b2 %1 def\n").arg(b2/255.0);
- m_stream << QString("/maxd %1 def\n").arg(maxDim);
- m_stream << QString("/mmaxd %1 def\n").arg(-maxDim/2.0);
- m_stream << "r1 r2 sub abs 255 mul /dr exch def\n";
- m_stream << "g1 g2 sub abs 255 mul /dg exch def\n";
- m_stream << "b1 b2 sub abs 255 mul /db exch def\n";
- m_stream << "dr dg add db add /colsteps exch def\n";
- m_stream << "colsteps 0.0 eq { /colsteps 1 def } if\n";
- m_stream << "x2 x1 sub colsteps div /xinc exch def\n";
- m_stream << "xinc 2 mul /xinc2 exch def\n";
- m_stream << "x2 xinc2 lt { /xinc2 x2 def } if\n";
- m_stream << "r2 r1 sub colsteps div /rinc exch def\n";
- m_stream << "g2 g1 sub colsteps div /ginc exch def\n";
- m_stream << "b2 b1 sub colsteps div /binc exch def\n";
- //m_stream << "r1 g1 b1 setrgbcolor\n";
- //m_stream << "0 mmaxd maxd maxd rectfill\n";
- m_stream << "0 1 colsteps\n";
- m_stream << "{\n";
- m_stream << " r1 g1 b1 setrgbcolor\n";
- m_stream << " x1 mmaxd xinc2 maxd rectfill\n"; //rectfill is a ps2 operator
- m_stream << " x1 xinc add /x1 exch def\n";
- m_stream << " r1 rinc add /r1 exch def\n";
- m_stream << " g1 ginc add /g1 exch def\n";
- m_stream << " b1 binc add /b1 exch def\n";
- m_stream << "} for\n";
- m_stream << "x2 mmaxd maxd maxd rectfill\n";
-
- stop1 = stop2;
- ramp1 = ramp2;
- r1 = r2;
- g1 = g2;
- b1 = b2;
- }
-}
-
-void ScPainterEx_Ps2::drawLinearGradient_CMYK( VGradientEx& gradient, const QRect& rect )
-{
- int c1, m1, j1, n1;
- int c2, m2, j2, n2;
- double cosa, sina;
- double ramp1, ramp2;
- double scale1, scale2;
- double length, scale;
- double x1, y1, x2, y2, dx, dy;
- int clipBoxWidth, clipBoxHeight, maxDim;
- QList<VColorStopEx*> colorStops = gradient.colorStops();
- VColorStopEx stop1( *colorStops[0] );
- VColorStopEx stop2( *colorStops[0] );
- CMYKColor cmyk;
- FPoint p1, p2;
- QColor color;
-
- if ( gradient.Stops() < 2 )
- return;
-
- clipBoxWidth = rect.width();
- clipBoxHeight = rect.height();
- maxDim = qRound(sqrt( (double) (clipBoxWidth * clipBoxWidth + clipBoxHeight * clipBoxHeight) )) * 2;
- if ( maxDim <= 0 ) return;
-
- scale1 = sqrt( m_matrix.m11() * m_matrix.m11() + m_matrix.m12() * m_matrix.m12() );
- scale2 = sqrt( m_matrix.m21() * m_matrix.m21() + m_matrix.m22() * m_matrix.m22() );
-
- x1 = m_matrix.dx() + gradient.origin().x() * m_matrix.m11();
- y1 = m_matrix.dy() + gradient.origin().y() * m_matrix.m22();
- x2 = m_matrix.dx() + gradient.vector().x() * m_matrix.m11();
- y2 = m_matrix.dy() + gradient.vector().y() * m_matrix.m22();
- p1.setXY( x1, y1 );
- p2.setXY( x2, y2 );
-
- dx = ( p2.x() - p1.x() );
- dy = ( p2.y() - p1.y() );
- length = sqrt(( dx * dx + dy * dy ));
- if ( length == 0.0 )
- scale = 1.0;
- else
- scale = 1.0 / length;
- cosa = dx * scale;
- sina = dy * scale;
-
- QString sc("[%1 %2 %3 %4 %5 %6] concat\n");
- m_stream << sc.arg(cosa).arg(sina).arg(-sina).arg(cosa).arg(x1).arg(y1);
-
- ramp1 = stop1.rampPoint;
- ScColorEngine::getShadeColorCMYK(stop1.color, m_options.document, cmyk, stop1.shade);
- cmyk.getValues(c1, m1, j1, n1);
- m_stream << QString("/DeviceCMYK setcolorspace\n");
- m_stream << QString("%1 %2 %3 %4 setcolor fill\n").arg(c1/255.0).arg(m1/255.0).arg(j1/255.0).arg(n1/255.0);
-
- for( uint index = 1; index < gradient.Stops(); index++)
- {
- stop2 = *colorStops[index];
- ramp2 = stop2.rampPoint;
- ScColorEngine::getShadeColorCMYK(stop2.color, m_options.document, cmyk, stop2.shade);
- cmyk.getValues(c2, m2, j2, n2);
- double xMin = length * ramp1;
- double xMax = length * ramp2;
-
- m_stream << QString("/x1 %1 def\n").arg(xMin);
- m_stream << QString("/x2 %1 def\n").arg(xMax);
- m_stream << QString("/c1 %1 def\n").arg(c1/255.0);
- m_stream << QString("/m1 %1 def\n").arg(m1/255.0);
- m_stream << QString("/y1 %1 def\n").arg(j1/255.0);
- m_stream << QString("/k1 %1 def\n").arg(n1/255.0);
- m_stream << QString("/c2 %1 def\n").arg(c2/255.0);
- m_stream << QString("/m2 %1 def\n").arg(m2/255.0);
- m_stream << QString("/y2 %1 def\n").arg(j2/255.0);
- m_stream << QString("/k2 %1 def\n").arg(n2/255.0);
- m_stream << QString("/maxd %1 def\n").arg(maxDim);
- m_stream << QString("/mmaxd %1 def\n").arg(-maxDim/2.0);
- m_stream << "c1 c2 sub abs 255 mul /dc exch def\n";
- m_stream << "m1 m2 sub abs 255 mul /dm exch def\n";
- m_stream << "y1 y2 sub abs 255 mul /dy exch def\n";
- m_stream << "k1 k2 sub abs 255 mul /dk exch def\n";
- m_stream << "dc dm add dy add dk add /colsteps exch def\n";
- m_stream << "colsteps 0.0 eq { /colsteps 1 def } if\n";
- m_stream << "x2 x1 sub colsteps div /xinc exch def\n";
- m_stream << "xinc 2 mul /xinc2 exch def\n";
- m_stream << "x2 xinc2 lt { /xinc2 x2 def } if\n";
- m_stream << "c2 c1 sub colsteps div /cinc exch def\n";
- m_stream << "m2 m1 sub colsteps div /minc exch def\n";
- m_stream << "y2 y1 sub colsteps div /yinc exch def\n";
- m_stream << "k2 k1 sub colsteps div /kinc exch def\n";
- //m_stream << "r1 g1 b1 setrgbcolor\n";
- //m_stream << "0 mmaxd maxd maxd rectfill\n";
- m_stream << "0 1 colsteps\n";
- m_stream << "{\n";
- m_stream << " c1 m1 y1 k1 setcolor\n";
- m_stream << " x1 mmaxd xinc2 maxd rectfill\n"; //rectfill is a ps2 operator
- m_stream << " x1 xinc add /x1 exch def\n";
- m_stream << " c1 cinc add /c1 exch def\n";
- m_stream << " m1 minc add /m1 exch def\n";
- m_stream << " y1 yinc add /y1 exch def\n";
- m_stream << " k1 kinc add /k1 exch def\n";
- m_stream << "} for\n";
- m_stream << "x2 mmaxd maxd maxd rectfill\n";
-
- stop1 = stop2;
- ramp1 = ramp2;
- c1 = c2;
- m1 = m2;
- j1 = j2;
- n1 = n2;
- }
-}
-
-void ScPainterEx_Ps2::drawCircularGradient( VGradientEx& gradient, const QRect& rect )
-{
- if (m_colorMode == cmykMode)
- drawCircularGradient_CMYK(gradient, rect);
- else
- drawCircularGradient_RGB(gradient, rect);
-}
-
-void ScPainterEx_Ps2::drawCircularGradient_RGB( VGradientEx& gradient, const QRect& rect )
-{
- int r1, g1, b1;
- int r2, g2, b2;
- double ramp1, ramp2;
- double scale1, scale2;
- int clipBoxWidth, clipBoxHeight, maxDim;
- QList<VColorStopEx*> colorStops = gradient.colorStops();
- VColorStopEx stop1( *colorStops[gradient.Stops() - 1] );
- VColorStopEx stop2( *colorStops[gradient.Stops() - 1] );
- RGBColor rgb;
- QColor color;
-
- clipBoxWidth = rect.width();
- clipBoxHeight = rect.height();
- maxDim = qRound(sqrt( (double) (clipBoxWidth * clipBoxWidth + clipBoxHeight * clipBoxHeight) )) * 2;
- if ( maxDim <= 0 ) return;
-
- scale1 = sqrt( m_matrix.m11() * m_matrix.m11() + m_matrix.m21() * m_matrix.m21() );
- scale2 = sqrt( m_matrix.m12() * m_matrix.m12() + m_matrix.m22() * m_matrix.m22() );
-
- FPoint pc( gradient.origin().x(), gradient.origin().y() );
- FPoint pcz( gradient.origin().x(), gradient.origin().y() );
- FPoint pf( gradient.focalPoint().x(), gradient.focalPoint().y() );
- FPoint pfz( gradient.focalPoint().x(), gradient.focalPoint().y() );
- FPoint pv( gradient.vector().x(), gradient.vector().y() );
- transformPoint( pc, pc );
- transformPoint( pf, pf );
- transformPoint( pv, pv );
- transformPoint( pcz, pcz );
- transformPoint( pfz, pfz );
- double cx = pcz.x();
- double cy = pcz.y();
- double rad = sqrt( pow(pv.x() -pc.x(), 2) + pow(pv.y() - pc.y(), 2) );
-
- ramp2 = stop2.rampPoint;
- ScColorEngine::getShadeColorRGB(stop2.color, m_options.document, rgb, stop2.shade);
- rgb.getValues(r2, g2, b2);
- m_stream << QString("%1 %2 %3 setrgbcolor fill\n").arg(r2).arg(g2).arg(b2);
- if ( gradient.Stops() < 2 ) return;
-
- for( int index = gradient.Stops() - 2; index >= 0; index--)
- {
- stop1 = *colorStops[index];
- ramp1 = stop1.rampPoint;
- ScColorEngine::getShadeColorRGB(stop1.color, m_options.document, rgb, stop1.shade);
- rgb.getValues(r1, g1, b1);
- int radMax = qRound(rad * ramp2);
- int radMin = qRound(rad * ramp1);
-
- m_stream << QString("/rad1 %1 def\n").arg(radMax);
- m_stream << QString("/rad2 %1 def\n").arg(radMin);
- m_stream << QString("/circx %1 def\n").arg(cx);
- m_stream << QString("/circy %1 def\n").arg(cy);
- m_stream << QString("/r1 %1 def\n").arg(r1/255.0);
- m_stream << QString("/g1 %1 def\n").arg(g1/255.0);
- m_stream << QString("/b1 %1 def\n").arg(b1/255.0);
- m_stream << QString("/r2 %1 def\n").arg(r2/255.0);
- m_stream << QString("/g2 %1 def\n").arg(g2/255.0);
- m_stream << QString("/b2 %1 def\n").arg(b2/255.0);
- m_stream << "r1 r2 sub abs 255 mul /dr exch def\n";
- m_stream << "g1 g2 sub abs 255 mul /dg exch def\n";
- m_stream << "b1 b2 sub abs 255 mul /db exch def\n";
- m_stream << "dr dg add db add /colsteps exch def\n";
- m_stream << "colsteps 0.0 eq { /colsteps 1 def } if\n";
- m_stream << "rad2 rad1 sub colsteps div /radinc exch def\n";
- m_stream << "r1 r2 sub colsteps div /rinc exch def\n";
- m_stream << "g1 g2 sub colsteps div /ginc exch def\n";
- m_stream << "b1 b2 sub colsteps div /binc exch def\n";
- m_stream << "0 1 colsteps\n";
- m_stream << "{\n";
- m_stream << " r2 g2 b2 setrgbcolor\n";
- m_stream << " circx circy rad1 0 360 arc closepath fill\n";
- m_stream << " rad1 radinc add /rad1 exch def\n";
- m_stream << " r2 rinc add /r2 exch def\n";
- m_stream << " g2 ginc add /g2 exch def\n";
- m_stream << " b2 binc add /b2 exch def\n";
- m_stream << "} for\n";
-
- stop2 = stop1;
- ramp2 = ramp1;
- r2 = r1;
- g2 = g1;
- b2 = b1;
- }
-}
-
-void ScPainterEx_Ps2::drawCircularGradient_CMYK( VGradientEx& gradient, const QRect& rect )
-{
- int c1, m1, y1, k1;
- int c2, m2, y2, k2;
- double ramp1, ramp2;
- double scale1, scale2;
- int clipBoxWidth, clipBoxHeight, maxDim;
- QList<VColorStopEx*> colorStops = gradient.colorStops();
- VColorStopEx stop1( *colorStops[gradient.Stops() - 1] );
- VColorStopEx stop2( *colorStops[gradient.Stops() - 1] );
- CMYKColor cmyk;
- QColor color;
-
- clipBoxWidth = rect.width();
- clipBoxHeight = rect.height();
- maxDim = qRound(sqrt( (double) (clipBoxWidth * clipBoxWidth + clipBoxHeight * clipBoxHeight) )) * 2;
- if ( maxDim <= 0 ) return;
-
- scale1 = sqrt( m_matrix.m11() * m_matrix.m11() + m_matrix.m21() * m_matrix.m21() );
- scale2 = sqrt( m_matrix.m12() * m_matrix.m12() + m_matrix.m22() * m_matrix.m22() );
-
- FPoint pc( gradient.origin().x(), gradient.origin().y() );
- FPoint pcz( gradient.origin().x(), gradient.origin().y() );
- FPoint pf( gradient.focalPoint().x(), gradient.focalPoint().y() );
- FPoint pfz( gradient.focalPoint().x(), gradient.focalPoint().y() );
- FPoint pv( gradient.vector().x(), gradient.vector().y() );
- transformPoint( pc, pc );
- transformPoint( pf, pf );
- transformPoint( pv, pv );
- transformPoint( pcz, pcz );
- transformPoint( pfz, pfz );
- double cx = pcz.x();
- double cy = pcz.y();
- double rad = sqrt( pow(pv.x() -pc.x(), 2) + pow(pv.y() - pc.y(), 2) );
-
- ramp2 = stop2.rampPoint;
- ScColorEngine::getShadeColorCMYK(stop2.color, m_options.document, cmyk, stop2.shade);
- cmyk.getValues(c2, m2, y2, k2);
- m_stream << QString("/DeviceCMYK setcolorspace\n");
- m_stream << QString("%0 %1 %2 %3 setcolor fill\n").arg(c2).arg(m2).arg(y2).arg(k2);
- if ( gradient.Stops() < 2 ) return;
-
- for( int index = gradient.Stops() - 2; index >= 0; index--)
- {
- stop1 = *colorStops[index];
- ramp1 = stop1.rampPoint;
- ScColorEngine::getShadeColorCMYK(stop1.color, m_options.document, cmyk, stop1.shade);
- cmyk.getValues(c1, m1, y1, k1);
- int radMax = qRound(rad * ramp2);
- int radMin = qRound(rad * ramp1);
-
- m_stream << QString("/rad1 %1 def\n").arg(radMax);
- m_stream << QString("/rad2 %1 def\n").arg(radMin);
- m_stream << QString("/circx %1 def\n").arg(cx);
- m_stream << QString("/circy %1 def\n").arg(cy);
- m_stream << QString("/c1 %1 def\n").arg(c1/255.0);
- m_stream << QString("/m1 %1 def\n").arg(m1/255.0);
- m_stream << QString("/y1 %1 def\n").arg(y1/255.0);
- m_stream << QString("/k1 %1 def\n").arg(k1/255.0);
- m_stream << QString("/c2 %1 def\n").arg(c2/255.0);
- m_stream << QString("/m2 %1 def\n").arg(m2/255.0);
- m_stream << QString("/y2 %1 def\n").arg(y2/255.0);
- m_stream << QString("/k2 %1 def\n").arg(k2/255.0);
- m_stream << "c1 c2 sub abs 255 mul /dc exch def\n";
- m_stream << "m1 m2 sub abs 255 mul /dm exch def\n";
- m_stream << "y1 y2 sub abs 255 mul /dy exch def\n";
- m_stream << "k1 k2 sub abs 255 mul /dk exch def\n";
- m_stream << "dc dm add dy add dk add /colsteps exch def\n";
- m_stream << "colsteps 0.0 eq { /colsteps 1 def } if\n";
- m_stream << "rad2 rad1 sub colsteps div /radinc exch def\n";
- m_stream << "c1 c2 sub colsteps div /cinc exch def\n";
- m_stream << "m1 m2 sub colsteps div /minc exch def\n";
- m_stream << "y1 y2 sub colsteps div /yinc exch def\n";
- m_stream << "k1 k2 sub colsteps div /kinc exch def\n";
- m_stream << "0 1 colsteps\n";
- m_stream << "{\n";
- m_stream << " c2 m2 y2 k2 setcolor\n";
- m_stream << " circx circy rad1 0 360 arc closepath fill\n";
- m_stream << " rad1 radinc add /rad1 exch def\n";
- m_stream << " c2 cinc add /c2 exch def\n";
- m_stream << " m2 minc add /m2 exch def\n";
- m_stream << " y2 yinc add /y2 exch def\n";
- m_stream << " k2 kinc add /k2 exch def\n";
- m_stream << "} for\n";
-
- stop2 = stop1;
- ramp2 = ramp1;
- c2 = c1;
- m2 = m1;
- y2 = y1;
- k2 = k1;
- }
-}
-
-void ScPainterEx_Ps2::getPathBoundingBox( FPointArray* points, QRect& r )
-{
- FPoint point;
- double bottom = DBL_MAX, top = DBL_MIN;
- double left = DBL_MAX, right = DBL_MIN;
-
- r.setCoords(0, 0, 0, 0);
-
- for( uint i = 0; i < points->size(); i++ )
- {
- point = points->point(i);
- if( point.x() > 900000 )
- continue;
- transformPoint(point, point);
- if( point.x() < left ) left = point.x();
- if( point.x() > right ) right = point.x();
- if( point.y() < bottom ) bottom = point.y();
- if( point.y() > top ) top = point.y();
- }
- r.setCoords( qRound(left), qRound(bottom), qRound(right), qRound(top) );
-}
-
+
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+/* This file is part of the KDE project.
+ Copyright (C) 2001, 2002, 2003 The Karbon Developers
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/* Adapted for Scribus 22.08.2003 by Franz Schmid */
+// kopainter/libart wrapper
+
+#include "scpainterex_ps2.h"
+
+#include <cfloat>
+#include <QPaintDevice>
+#include <QPixmap>
+#include <QImage>
+
+#include <iostream>
+#include <memory>
+using namespace std;
+
+#include <cmath>
+#include "util.h"
+#include "sccolorengine.h"
+
+ScPs2OutputParams::ScPs2OutputParams(ScribusDoc* doc)
+{
+ document = doc;
+ colorMode = ScPainterExBase::rgbMode;
+ reloadImages = true;
+ resolution = 72;
+ useProfiles = false;
+ toGray = false;
+ mirrorH = false;
+ mirrorV = false;
+ hProfile = NULL;
+ rgbToOutputColorTransform = NULL;
+ rgbToOutputImageTransform = NULL;
+ cmykToOutputColorTransform = NULL;
+ cmykToOutputImageTransform = NULL;
+}
+
+ScPainterEx_Ps2::ScPainterEx_Ps2(QIODevice* iodev, QRect& rect, ScPs2OutputParams& options ) : ScPainterExBase()
+{
+ m_stream.setDevice( iodev );
+ m_colorMode = options.colorMode;
+ m_encoding = Ascii85Encoding;
+ m_options = options;
+ m_width = rect.width();
+ m_height= rect.height();
+ m_x = rect.left();
+ m_y = rect.top();
+ m_fillColor = ScColorShade( QColor(0,0,0), 100 );
+ m_strokeColor = ScColorShade( QColor(0,0,0), 100 );
+ m_fillTrans = 1.0;
+ m_strokeTrans = 1.0;
+ m_fillRule = true;
+ m_fillMode = 1;
+ m_lineWidth = 1.0;
+ m_offset = 0;
+ m_array.clear();
+ m_lineEnd = Qt::SquareCap;
+ m_lineJoin = Qt::RoundJoin;
+ m_fillGradient = VGradientEx(VGradientEx::linear);
+ m_strokeGradient = VGradientEx(VGradientEx::linear);
+ m_matrix = QTransform();
+ m_pageTrans = QTransform();
+ // Path state
+ m_pathIsClosed = true;
+ m_drawingClosedPath = false;
+ // TODO : set proper values
+ m_deviceDimX = 0;
+ m_deviceDimY = 0;
+ m_deviceResX = 0;
+ m_deviceResY = 0;
+ clear();
+}
+
+ScPainterEx_Ps2::~ScPainterEx_Ps2()
+{
+}
+
+ScPainterExBase::ImageMode ScPainterEx_Ps2::imageMode()
+{
+ ImageMode imageMode;
+ if (m_options.hProfile && m_options.rgbToOutputImageTransform && m_options.cmykToOutputImageTransform)
+ imageMode = rawImages;
+ else if (m_colorMode == cmykMode)
+ imageMode = cmykImages;
+ else
+ imageMode = rgbImages;
+ return imageMode;
+}
+
+void ScPainterEx_Ps2::transformImage( QImage* image, uchar* data, int scan)
+{
+ int rgb, grey;
+ int imageWidth = image->width();
+ int imageHeight = image->height();
+
+ QRgb* pscani;
+ uchar *pscand;
+
+ pscand = data;
+ for ( int j = 0; j < imageHeight; j++ )
+ {
+ pscani = (QRgb *) image->scanLine(j);
+ for (int i = 0; i < imageWidth; i++ )
+ {
+ rgb = pscani[i];
+ grey = qRound(0.3 * qRed(rgb)) + qRound(0.59 * qGreen(rgb)) + qRound(0.11 * qBlue(rgb));
+ pscand[i] = grey;
+ }
+ pscand += scan;
+ }
+
+}
+
+void ScPainterEx_Ps2::begin()
+{
+}
+
+void ScPainterEx_Ps2::end()
+{
+
+}
+
+void ScPainterEx_Ps2::clear()
+{
+
+}
+
+void ScPainterEx_Ps2::clear( ScColorShade &c )
+{
+
+}
+
+const QTransform ScPainterEx_Ps2::worldMatrix()
+{
+ return m_matrix;
+}
+
+void ScPainterEx_Ps2::setWorldMatrix( const QTransform &mat )
+{
+ m_matrix = mat;
+}
+
+void ScPainterEx_Ps2::transformPoint( const FPoint& in, FPoint& out )
+{
+ double x, y;
+ x = in.x() * m_matrix.m11() + in.y() * m_matrix.m21() + m_matrix.dx();
+ y = in.x() * m_matrix.m12() + in.y() * m_matrix.m22() + m_matrix.dy();
+ out.setX( x );
+ out.setY( y );
+}
+
+void ScPainterEx_Ps2::transformPoints( const FPoint* ArrayIn, FPoint* ArrayOut, uint length )
+{
+ for( uint i = 0; i < length; i++ )
+ {
+ transformPoint( ArrayIn[i], ArrayOut[i] );
+ }
+}
+
+void ScPainterEx_Ps2::translate( double x, double y )
+{
+ m_matrix.translate(x, y);
+}
+
+void ScPainterEx_Ps2::rotate( double r )
+{
+ m_matrix.rotate(r);
+}
+
+void ScPainterEx_Ps2::scale( double x, double y )
+{
+ m_matrix.scale(x, y);
+}
+
+void ScPainterEx_Ps2::moveTo( const double &x, const double &y )
+{
+ FPoint pp( x, y );
+ transformPoint( pp, pp );
+ m_stream << QString("%1 %2 moveto\n").arg(pp.x()).arg(pp.y());
+}
+
+void ScPainterEx_Ps2::lineTo( const double &x, const double &y )
+{
+ FPoint pp( x, y );
+ transformPoint( pp, pp );
+ m_stream << QString("%1 %2 lineto\n").arg(pp.x()).arg(pp.y());
+}
+
+void ScPainterEx_Ps2::curveTo( FPoint p1, FPoint p2, FPoint p3 )
+{
+ FPoint pps[3];
+ pps[0].setXY( p1.x(), p1.y() );
+ pps[1].setXY( p2.x(), p2.y() );
+ pps[2].setXY( p3.x(), p3.y() );
+ transformPoints( pps, pps, 3 );
+ m_stream << QString("%1 %2 %3 %4 %5 %6 curveto\n").arg(pps[0].x()).arg(pps[0].y()).arg(pps[1].x()).arg(pps[1].y()).arg(pps[2].x()).arg(pps[2].y());
+}
+
+void ScPainterEx_Ps2::newPath()
+{
+ m_stream << "newpath\n";
+ //pathIsClosed = false;
+}
+
+void ScPainterEx_Ps2::closePath()
+{
+ m_stream << "closepath\n";
+ m_pathIsClosed = true;
+}
+
+void ScPainterEx_Ps2::setFillRule( bool fillRule )
+{
+ m_fillRule = fillRule;
+}
+
+void ScPainterEx_Ps2::setFillMode( int fill )
+{
+ m_fillMode = fill;
+}
+
+void ScPainterEx_Ps2::setGradient(VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc)
+{
+ m_fillGradient.setType(mode);
+ m_fillGradient.setOrigin(orig);
+ m_fillGradient.setVector(vec);
+ m_fillGradient.setFocalPoint(foc);
+}
+
+void ScPainterEx_Ps2::setPattern( ScPattern* pattern, QTransform& patternTransform )
+{
+ m_pattern = pattern;
+ m_patternTransform = patternTransform;
+}
+
+void ScPainterEx_Ps2::fillTextPath()
+{
+ drawVPath( 0 );
+}
+
+void ScPainterEx_Ps2::strokeTextPath()
+{
+ if( m_lineWidth == 0 )
+ return;
+ drawVPath( 1 );
+}
+
+void ScPainterEx_Ps2::fillPath()
+{
+ if(!m_pathIsClosed)
+ closePath();
+ if( m_fillMode != 0)
+ drawVPath( 0 );
+}
+
+void ScPainterEx_Ps2::strokePath()
+{
+ if( m_lineWidth == 0 )
+ return;
+ save();
+ if(!m_pathIsClosed)
+ closePath();
+ drawVPath( 1 );
+ restore();
+}
+
+ScColorShade ScPainterEx_Ps2::pen()
+{
+ return m_strokeColor;
+}
+
+ScColorShade ScPainterEx_Ps2::brush()
+{
+ return m_fillColor;
+}
+
+void ScPainterEx_Ps2::setPen( const ScColorShade &c )
+{
+ m_strokeColor = c;
+}
+
+void ScPainterEx_Ps2::setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo )
+{
+ m_offset = 0;
+ m_strokeColor = c;
+ m_lineWidth = w;
+ m_lineEnd = ca;
+ m_lineJoin = jo;
+ double Dt = qMax(2*w, 1.0);
+ double Da = qMax(6*w, 1.0);
+ m_array.clear();
+ if (st == Qt::DashLine)
+ m_array << Da << Dt;
+ else if (st == Qt::DotLine)
+ m_array << Dt;
+ else if (st == Qt::DashDotLine)
+ m_array << Da << Dt << Dt << Dt;
+ else if (st == Qt::DashDotDotLine)
+ m_array << Da << Dt << Dt << Dt << Dt << Dt;
+}
+
+void ScPainterEx_Ps2::setLineWidth( double w )
+{
+ m_lineWidth = w;
+}
+
+void ScPainterEx_Ps2::setPenOpacity( double op )
+{
+ m_strokeTrans = op;
+}
+
+void ScPainterEx_Ps2::setDash(const QVector<double>& array, double ofs)
+{
+ m_array = array;
+ m_offset = ofs;
+}
+
+void ScPainterEx_Ps2::setBrush( const ScColorShade &c )
+{
+ m_fillColor = c;
+}
+
+void ScPainterEx_Ps2::setBrushOpacity( double op )
+{
+ m_fillTrans = op;
+}
+
+void ScPainterEx_Ps2::setOpacity( double op )
+{
+ m_fillTrans = op;
+ m_strokeTrans = op;
+}
+
+void ScPainterEx_Ps2::setFont( const QFont &f)
+{
+ m_font = f;
+}
+
+QFont ScPainterEx_Ps2::font()
+{
+ return m_font;
+}
+
+void ScPainterEx_Ps2::save()
+{
+ m_stack.push( m_matrix );
+ m_stream << "gsave\n";
+}
+
+void ScPainterEx_Ps2::restore()
+{
+ m_matrix = m_stack.pop();
+ m_stream << "grestore\n";
+}
+
+void ScPainterEx_Ps2::setRasterOp( int )
+{
+}
+
+void ScPainterEx_Ps2::drawVPath( int mode )
+{
+ save();
+ if (mode == 0)
+ {
+ if (m_fillMode == ScPainterExBase::Gradient)
+ drawGradient( m_fillGradient );
+ else
+ putColor( m_fillColor, true );
+ }
+ else
+ {
+ double m11 = m_matrix.m11();
+ double m12 = m_matrix.m12();
+ double m21 = m_matrix.m21();
+ double m22 = m_matrix.m22();
+ double norm2 = m11 * m11 + m12 * m12 + m21 * m21 + m22 * m22;
+ double penScale = sqrt(norm2 /2.0);
+ double penWidth = (int) (m_lineWidth * penScale);
+ m_stream << QString("%1 setlinewidth\n").arg(penWidth);
+
+ m_stream << "[";
+ for( int i = 0; i < m_array.count();++ i )
+ {
+ m_stream << QString("%1").arg(m_array[i]) << " ";
+ }
+ m_stream << "]";
+ m_stream << " 0 setdash\n";
+
+ if( m_lineEnd == Qt::RoundCap )
+ m_stream << "1 setlinecap\n";
+ else if( m_lineEnd == Qt::SquareCap )
+ m_stream << "2 setlinecap\n";
+ else if( m_lineEnd == Qt::FlatCap )
+ m_stream << "0 setlinecap\n";
+ else
+ m_stream << "0 setlinecap\n";
+
+ if( m_lineJoin == Qt::RoundJoin )
+ m_stream << "1 setlinejoin\n";
+ else if( m_lineJoin == Qt::BevelJoin )
+ m_stream << "2 setlinejoin\n";
+ else if( m_lineJoin == Qt::MiterJoin )
+ m_stream << "0 setlinejoin\n";
+ else
+ m_stream << "0 setlinejoin\n";
+
+ putColor(m_strokeColor, false);
+ }
+ restore();
+}
+
+void ScPainterEx_Ps2::setClipPath()
+{
+ //TODO eoclip or clip?
+ m_stream << "clip newpath\n";
+ m_clipBBox = m_pathBBox;
+}
+
+void ScPainterEx_Ps2::putColor( ScColorShade& colorShade, bool doFill )
+{
+ ColorMode colorMode = m_colorMode;
+ int r = 0, g = 0, b = 0, gray = 0;
+ int c = 0, m = 0, y = 0, k = 0;
+ if ( m_options.toGray )
+ {
+ RGBColor rgb;
+ ScColorEngine::getShadeColorRGB(colorShade.color, m_options.document, rgb, colorShade.shade);
+ rgb.getValues(r, g, b);
+ gray = qRound(0.3 * r + 0.59 * g + 0.11 * b);
+ if ( doFill && m_fillRule )
+ m_stream << QString("%1 setgray eofill\n").arg(gray/255.0);
+ else if ( doFill )
+ m_stream << QString("%1 setgray fill\n").arg(gray/255.0);
+ else
+ m_stream << QString("%1 setgray stroke\n").arg(gray/255.0);
+ return;
+ }
+ else if ( m_options.hProfile && m_options.rgbToOutputColorTransform && m_options.cmykToOutputColorTransform)
+ {
+ DWORD colorIn[4];
+ DWORD colorOut[4];
+ cmsHTRANSFORM cmsTranform = NULL;
+ if( colorShade.color.getColorModel() == colorModelRGB )
+ {
+ RGBColor rgb;
+ ScColorEngine::getShadeColorRGB(colorShade.color, m_options.document, rgb, colorShade.shade);
+ colorIn[0] = rgb.r;
+ colorIn[1] = rgb.g;
+ colorIn[2] = rgb.b;
+ colorMode = rgbMode;
+ cmsTranform = m_options.rgbToOutputColorTransform;
+ }
+ else
+ {
+ CMYKColor cmyk;
+ ScColorEngine::getShadeColorCMYK(colorShade.color, m_options.document, cmyk, colorShade.shade);
+ colorIn[0] = cmyk.c;
+ colorIn[1] = cmyk.m;
+ colorIn[2] = cmyk.y;
+ colorIn[3] = cmyk.k;
+ colorMode = cmykMode;
+ cmsTranform = m_options.cmykToOutputColorTransform;
+ }
+ cmsDoTransform( cmsTranform, colorIn, colorOut, 1 );
+ if (static_cast<int>(cmsGetColorSpace(m_options.hProfile)) == icSigRgbData)
+ {
+ r = colorOut[0] / 257;
+ g = colorOut[1] / 257;
+ b = colorOut[2] / 257;
+ colorMode = rgbMode;
+ }
+ else if (static_cast<int>(cmsGetColorSpace(m_options.hProfile)) == icSigCmykData)
+ {
+ c = colorOut[0] / 257;
+ m = colorOut[1] / 257;
+ y = colorOut[2] / 257;
+ k = colorOut[3] / 257;
+ colorMode = cmykMode;
+ }
+ }
+ else if ( m_colorMode == rgbMode )
+ {
+ RGBColor rgb;
+ colorMode = rgbMode;
+ ScColorEngine::getShadeColorRGB(colorShade.color, m_options.document, rgb, colorShade.shade);
+ rgb.getValues(r, g, b);
+ }
+ else if ( m_colorMode == cmykMode )
+ {
+ CMYKColor cmyk;
+ colorMode = cmykMode;
+ ScColorEngine::getShadeColorCMYK(colorShade.color, m_options.document, cmyk, colorShade.shade);
+ cmyk.getValues(c, m, y, k);
+ }
+
+ // Finally output to file
+ if ( colorMode == rgbMode )
+ {
+ if ( doFill && m_fillRule )
+ m_stream << QString("%1 %2 %3 setrgbcolor eofill\n").arg(r/255.0).arg(g/255.0).arg(b/255.0);
+ else if ( doFill )
+ m_stream << QString("%1 %2 %3 setrgbcolor fill\n").arg(r/255.0).arg(g/255.0).arg(b/255.0);
+ else
+ m_stream << QString("%1 %2 %3 setrgbcolor stroke\n").arg(r/255.0).arg(g/255.0).arg(b/255.0);
+ }
+ else if ( colorMode == cmykMode )
+ {
+ QString colstr1 = QString("%1 %2 %3 %4 setcmykcolor").arg(c/255.0).arg(m/255.0).arg(y/255.0).arg(k/255.0);
+ if ( doFill && m_fillRule )
+ m_stream << colstr1 << " eofill\n";
+ else if ( doFill )
+ m_stream << colstr1 << " fill\n";
+ else
+ m_stream << colstr1 << " stroke\n";
+ }
+}
+
+void ScPainterEx_Ps2::drawImage( ScImage *image, ScPainterExBase::ImageMode mode )
+{
+ bool rgbMode = (mode == ScPainterExBase::rgbImages || mode == ScPainterExBase::rgbProofImages);
+ bool rgbPicture = rgbMode || (mode == ScPainterExBase::rawImages && image->imgInfo.colorspace == ColorSpaceRGB);
+ bool cmykPicture = (mode == ScPainterExBase::cmykImages || (mode == ScPainterExBase::rawImages && image->imgInfo.colorspace == ColorSpaceCMYK));
+
+ if( rgbPicture )
+ drawRGBImage_ps2( image );
+ else if( cmykPicture )
+ drawCMYKImage_ps2( image );
+ else
+ qDebug( "ScPainterEx_Ps2::drawImage() : unknown image type" );
+}
+
+void ScPainterEx_Ps2::drawRGBImage_ps2( ScImage *image )
+{
+ save();
+ QString sc("[%1 %2 %3 %4 %5 %6] concat\n");
+ m_stream << sc.arg(m_matrix.m11()).arg(m_matrix.m12()).arg(m_matrix.m21()).arg(m_matrix.m22()).arg(m_matrix.dx()).arg(m_matrix.dy());
+ m_stream << QString("%1 %2 scale\n").arg(image->width()).arg(image->height());
+ m_stream << "/DeviceRGB setcolorspace\n";
+ if (hasAlphaChannel(image))
+ {
+ QImage imgTemp = image->qImage();
+ QImage mask = imgTemp.createAlphaMask();
+ if (m_encoding == Ascii85Encoding)
+ {
+ m_stream << "currentfile /ASCII85Decode filter /ReusableStreamDecode filter\n";
+ writeRGBImageToStream_Ascii85(image);
+ }
+ else
+ {
+ m_stream << "currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n";
+ writeRGBImageToStream_AsciiHex(image);
+ }
+ m_stream << "/myImage exch def\n";
+ m_stream << "currentfile /ASCIIHexDecode filter /ReusableStreamDecode filter\n";
+ writeMaskToStream(&mask);
+ m_stream << "/myMask exch def\n";
+ m_stream << QString("<<\n");
+ m_stream << QString(" /PaintType 1\n");
+ m_stream << QString(" /PatternType 1\n");
+ m_stream << QString(" /TilingType 3\n");
+ m_stream << QString(" /BBox [ 0 0 1 1 ]\n");
+ m_stream << QString(" /XStep 2\n");
+ m_stream << QString(" /YStep 2\n");
+ m_stream << QString(" /PaintProc {\n");
+ m_stream << QString(" pop\n");
+ m_stream << QString(" 0 0 0 setrgbcolor\n");
+ m_stream << QString(" <<\n");
+ m_stream << QString(" /ImageType 1\n");
+ m_stream << QString(" /Width %1\n").arg(image->width());
+ m_stream << QString(" /Height %1\n").arg(image->height());
+ m_stream << QString(" /ImageMatrix [ %1 0 0 %2 0 0 ]\n").arg(image->width()).arg(image->height());
+ m_stream << QString(" /BitsPerComponent 8\n");
+ m_stream << QString(" /Decode [0 1 0 1 0 1]\n");
+ m_stream << QString(" /DataSource myImage\n");
+ m_stream << QString(" >>\n");
+ m_stream << QString(" image\n");
+ m_stream << QString(" }\n");
+ m_stream << QString(">> matrix makepattern setpattern\n");
+ m_stream << QString("<<\n");
+ m_stream << QString(" /ImageType 1\n");
+ m_stream << QString(" /Width %1 \n").arg(image->width());
+ m_stream << QString(" /Height %1 \n").arg(image->height());
+ m_stream << QString(" /BitsPerComponent 1\n");
+ m_stream << QString(" /Decode [1 0]\n");
+ m_stream << QString(" /ImageMatrix [ %1 0 0 %2 0 0 ]\n").arg(image->width()).arg(image->height());
+ m_stream << QString(" /DataSource myMask\n");
+ m_stream << QString(">>\n");
+ m_stream << QString("imagemask\n");
+ }
+ else
+ {
+ m_stream << QString("<<\n");
+ m_stream << QString(" /ImageType 1\n");
+ m_stream << QString(" /Width %1\n").arg(image->width());
+ m_stream << QString(" /Height %1\n").arg(image->height());
+ m_stream << QString(" /ImageMatrix [ %1 0 0 %2 0 0 ]\n").arg(image->width()).arg(image->height());
+ m_stream << QString(" /Decode [0 1 0 1 0 1]\n");
+ m_stream << QString(" /BitsPerComponent 8\n");
+ //TODO case where compression is available
+ if (m_encoding == Ascii85Encoding)
+ {
+ m_stream << QString(" /DataSource currentfile /ASCII85Decode filter\n");
+ m_stream << QString(">>\n");
+ m_stream << "image\n";
+ writeRGBImageToStream_Ascii85(image);
+ }
+ else
+ {
+ m_stream << QString(" /DataSource currentfile /ASCIIHexDecode filter\n");
+ m_stream << QString(">>\n");
+ m_stream << "image\n";
+ writeRGBImageToStream_AsciiHex(image);
+ }
+ }
+ restore();
+}
+
+void ScPainterEx_Ps2::drawCMYKImage_ps2( ScImage *image )
+{
+ save();
+ QString sc("[%1 %2 %3 %4 %5 %6] concat\n");
+ m_stream << sc.arg(m_matrix.m11()).arg(m_matrix.m12()).arg(m_matrix.m21()).arg(m_matrix.m22()).arg(m_matrix.dx()).arg(m_matrix.dy());
+ m_stream << QString("%1 %2 scale\n").arg(image->width()).arg(image->height());
+ m_stream << "/DeviceCMYK setcolorspace\n";
+ // TODO case where image have a mask
+ bool haveMask = false;
+ if (haveMask)
+ {
+
+ }
+ else
+ {
+ m_stream << "<<\n";
+ m_stream << QString(" /ImageType 1\n");
+ m_stream << QString(" /Width %1\n").arg(image->width());
+ m_stream << QString(" /Height %1\n").arg(image->height());
+ m_stream << QString(" /ImageMatrix [ %1 0 0 %2 0 0 ]\n").arg(image->width()).arg(image->height());
+ m_stream << QString(" /Decode [0 1 0 1 0 1 0 1]\n");
+ m_stream << QString(" /BitsPerComponent 8\n");
+ //TODO case where compression is available
+ if (m_encoding == Ascii85Encoding)
+ {
+ m_stream << QString(" /DataSource currentfile /ASCII85Decode filter\n");
+ m_stream << QString(">>\n");
+ m_stream << "image\n";
+ writeCMYKImageToStream_Ascii85(image);
+ }
+ else
+ {
+ m_stream << QString(" /DataSource currentfile /ASCIIHexDecode filter\n");
+ m_stream << QString(">>\n");
+ m_stream << "image\n";
+ writeCMYKImageToStream_AsciiHex(image);
+ }
+ }
+ restore();
+}
+
+bool ScPainterEx_Ps2::hasAlphaChannel( ScImage* image )
+{
+ bool hasAlpha = false;
+ int width = image->width();
+ int height = image->height();
+ for( int y = 0; y < height; y++ )
+ {
+ QRgb* imageBits = (QRgb*)(image->qImage().scanLine(y));
+ for( int x = 0; x < width; ++x )
+ {
+ if( qAlpha(*imageBits) != 255 )
+ {
+ hasAlpha = true;
+ break;
+ }
+ imageBits++;
+ }
+ }
+ return hasAlpha;
+}
+
+void ScPainterEx_Ps2::writeMaskToStream( QImage* image )
+{
+ int length = 0;
+ unsigned char bits;
+ int width = image->width() / 8;
+ int height = image->height();
+ if ((image->width() % 8) != 0)
+ width++;
+ for( int y = 0; y < height; ++y )
+ {
+ unsigned char* imageBits = image->scanLine(y);
+ for( int x = 0; x < width; x++ )
+ {
+ length++;
+ bits = imageBits[x];
+ m_stream << toHex(bits);
+ if ( (length % 49) == 0 )
+ m_stream << "\n";
+ }
+ }
+ m_stream << "\n>\n";
+}
+
+void ScPainterEx_Ps2::writeRGBImageToStream_Ascii85( ScImage* image )
+{
+ int cindex;
+ int pending = 0, written = 0;
+ bool allZero = true;
+ unsigned char four_tuple[4];
+ const char* ascii85;
+ quint32 value;
+
+ int width = image->width();
+ int height = image->height();
+ for( int y = 0; y < height; ++y )
+ {
+ QRgb* imageBits = (QRgb*)(image->qImage().scanLine(y));
+ for( int x = 0; x < width; ++x )
+ {
+ cindex = 0;
+ while (cindex < 3)
+ {
+ if (cindex == 0)
+ four_tuple[pending++] = (uchar) qRed(*imageBits);
+ else if (cindex == 1)
+ four_tuple[pending++] = (uchar) qGreen(*imageBits);
+ else if (cindex == 2)
+ four_tuple[pending++] = (uchar) qBlue(*imageBits);
+ if (pending == 4)
+ {
+ value = four_tuple[0] << 24 | four_tuple[1] << 16 | four_tuple[2] << 8 | four_tuple[3];
+ ascii85 = toAscii85(value, allZero);
+ if (allZero)
+ m_stream << "z";
+ else
+ m_stream << ascii85;
+ written += ((allZero) ? 1 : 5);
+ if (written > 75)
+ {
+ m_stream << "\n";
+ written = 0;
+ }
+ pending = 0;
+ }
+ ++cindex;
+ }
+
+ }
+ }
+ if (pending)
+ {
+ unsigned char five_tuple[6];
+ memset (four_tuple + pending, 0, 4 - pending);
+ value = four_tuple[0] << 24 | four_tuple[1] << 16 | four_tuple[2] << 8 | four_tuple[3];
+ ascii85 = toAscii85(value, allZero);
+ memcpy (five_tuple, ascii85, 5);
+ five_tuple[pending + 1] = 0;
+ m_stream << (const char*) five_tuple;
+ }
+ m_stream << "~>\n";
+}
+
+void ScPainterEx_Ps2::writeRGBImageToStream_AsciiHex ( ScImage* image )
+{
+ int length = 0;
+ int width = image->width();
+ int height = image->height();
+ for( int y = 0; y < height; ++y )
+ {
+ QRgb* imageBits = (QRgb*)(image->qImage().scanLine(y));
+ for( int x = 0; x < width; ++x )
+ {
+ length++;
+ uchar r = (uchar) qRed(*imageBits);
+ m_stream << toHex(r);
+ uchar g = (uchar) qGreen(*imageBits);
+ m_stream << toHex(g);
+ uchar b = (uchar) qBlue(*imageBits);
+ m_stream << toHex(b);
+ if ( (length % 17) == 0 )
+ m_stream << "\n";
+ imageBits++;
+ }
+ }
+ m_stream << "\n>\n";
+}
+
+void ScPainterEx_Ps2::writeCMYKImageToStream_Ascii85( ScImage* image )
+{
+ int written = 0;
+ bool allZero = true;
+ unsigned char four_tuple[4];
+ const char* ascii85;
+ quint32 value;
+
+ int width = image->width();
+ int height = image->height();
+ for( int y = 0; y < height; y++ )
+ {
+ QRgb* imageBits = (QRgb*)(image->qImage().scanLine(y));
+ for( int x = 0; x < width; x++ )
+ {
+ four_tuple[0] = (uchar) qRed(*imageBits);
+ four_tuple[1] = (uchar) qGreen(*imageBits);
+ four_tuple[2] = (uchar) qBlue(*imageBits);
+ four_tuple[3] = (uchar) qAlpha(*imageBits);
+ value = four_tuple[0] << 24 | four_tuple[1] << 16 | four_tuple[2] << 8 | four_tuple[3];
+ ascii85 = toAscii85(value, allZero);
+ if (allZero)
+ m_stream << "z";
+ else
+ m_stream << ascii85;
+ written += ((allZero) ? 1 : 5);
+ if (written > 75)
+ {
+ m_stream << "\n";
+ written = 0;
+ }
+ imageBits++;
+ }
+ }
+ m_stream << "~>\n";
+}
+
+void ScPainterEx_Ps2::writeCMYKImageToStream_AsciiHex( ScImage* image )
+{
+ int length = 0;
+ int width = image->width();
+ int height = image->height();
+ for( int y = 0; y < height; ++y )
+ {
+ QRgb* imageBits = (QRgb*)(image->qImage().scanLine(y));
+ for( int x = 0; x < width; ++x )
+ {
+ length++;
+ uchar c = (uchar) qRed(*imageBits);
+ m_stream << toHex(c);
+ uchar m = (uchar) qGreen(*imageBits);
+ m_stream << toHex(m);
+ uchar y = (uchar) qBlue(*imageBits);
+ m_stream << toHex(y);
+ uchar k = (uchar) qAlpha(*imageBits);
+ m_stream << toHex(k);
+ if ( (length % 13) == 0 )
+ m_stream << "\n";
+ imageBits++;
+ }
+ }
+ m_stream << "\n>\n";
+}
+
+void ScPainterEx_Ps2::setupPolygon(FPointArray *points, bool closed)
+{
+ bool nPath = true;
+ FPoint np, np1, np2, np3;
+ if (points->size() > 3)
+ {
+ newPath();
+ for (uint poi=0; poi<points->size()-3; poi += 4)
+ {
+ if (points->point(poi).x() > 900000)
+ {
+ nPath = true;
+ continue;
+ }
+ if (nPath)
+ {
+ np = points->point(poi);
+ // TODO startfigure needed?
+ moveTo( np.x(), np.y() );
+ nPath = false;
+ }
+ np = points->point(poi);
+ np1 = points->point(poi+1);
+ np2 = points->point(poi+3);
+ np3 = points->point(poi+2);
+ if ((np == np1) && (np2 == np3))
+ lineTo( np3.x(), np3.y() );
+ else
+ curveTo(np1, np2, np3);
+ }
+ if (closed)
+ {
+ closePath();
+ m_drawingClosedPath = true;
+ }
+ }
+ getPathBoundingBox( points, m_pathBBox );
+}
+
+void ScPainterEx_Ps2::drawPolygon()
+{
+ fillPath();
+}
+
+void ScPainterEx_Ps2::drawPolyLine()
+{
+ strokePath();
+}
+
+void ScPainterEx_Ps2::drawLine(FPoint start, FPoint end)
+{
+ newPath();
+ moveTo(start.x(), start.y());
+ lineTo(end.x(), end.y());
+ strokePath();
+}
+
+void ScPainterEx_Ps2::drawRect(double x, double y, double w, double h)
+{
+ newPath();
+ moveTo( x, y );
+ lineTo( x+w, y );
+ lineTo( x+w, y+h );
+ lineTo( x, y+h );
+ lineTo( x, y );
+ closePath();
+ m_drawingClosedPath = true;
+ fillPath();
+ strokePath();
+}
+
+void ScPainterEx_Ps2::drawGradient( VGradientEx& gradient )
+{
+ QRect clipPathRect;
+ save();
+ //setClipPath();
+ m_stream << "clip\n";
+ m_clipBBox = m_pathBBox;
+ if ( gradient.type() == VGradientEx::linear )
+ drawLinearGradient( gradient, m_clipBBox );
+ else if ( gradient.type() == VGradientEx::radial )
+ drawCircularGradient( gradient, m_clipBBox );
+ restore();
+}
+
+void ScPainterEx_Ps2::drawLinearGradient( VGradientEx& gradient, const QRect& rect )
+{
+ if (m_colorMode == cmykMode)
+ drawLinearGradient_CMYK(gradient, rect);
+ else
+ drawLinearGradient_RGB(gradient, rect);
+}
+
+void ScPainterEx_Ps2::drawLinearGradient_RGB( VGradientEx& gradient, const QRect& rect )
+{
+ int r1, g1, b1;
+ int r2, g2, b2;
+ double cosa, sina;
+ double ramp1, ramp2;
+ double scale1, scale2;
+ double length, scale;
+ double x1, y1, x2, y2, dx, dy;
+ int clipBoxWidth, clipBoxHeight, maxDim;
+ QList<VColorStopEx*> colorStops = gradient.colorStops();
+ VColorStopEx stop1( *colorStops[0] );
+ VColorStopEx stop2( *colorStops[0] );
+ RGBColor rgb;
+ FPoint p1, p2;
+ QColor color;
+
+ if ( gradient.Stops() < 2 )
+ return;
+
+ clipBoxWidth = rect.width();
+ clipBoxHeight = rect.height();
+ maxDim = qRound(sqrt( (double) (clipBoxWidth * clipBoxWidth + clipBoxHeight * clipBoxHeight) )) * 2;
+ if ( maxDim <= 0 ) return;
+
+ scale1 = sqrt( m_matrix.m11() * m_matrix.m11() + m_matrix.m12() * m_matrix.m12() );
+ scale2 = sqrt( m_matrix.m21() * m_matrix.m21() + m_matrix.m22() * m_matrix.m22() );
+
+ x1 = m_matrix.dx() + gradient.origin().x() * m_matrix.m11();
+ y1 = m_matrix.dy() + gradient.origin().y() * m_matrix.m22();
+ x2 = m_matrix.dx() + gradient.vector().x() * m_matrix.m11();
+ y2 = m_matrix.dy() + gradient.vector().y() * m_matrix.m22();
+ p1.setXY( x1, y1 );
+ p2.setXY( x2, y2 );
+
+ dx = ( p2.x() - p1.x() );
+ dy = ( p2.y() - p1.y() );
+ length = sqrt(( dx * dx + dy * dy ));
+ if ( length == 0.0 )
+ scale = 1.0;
+ else
+ scale = 1.0 / length;
+ cosa = dx * scale;
+ sina = dy * scale;
+
+ QString sc("[%1 %2 %3 %4 %5 %6] concat\n");
+ m_stream << sc.arg(cosa).arg(sina).arg(-sina).arg(cosa).arg(x1).arg(y1);
+
+ ramp1 = stop1.rampPoint;
+ ScColorEngine::getShadeColorRGB(stop1.color, m_options.document, rgb, stop1.shade);
+ rgb.getValues(r1, g1, b1);
+ m_stream << QString("%1 %2 %3 setrgbcolor fill\n").arg(r1/255.0).arg(g1/255.0).arg(b1/255.0);
+
+ for( uint index = 1; index < gradient.Stops(); index++)
+ {
+ stop2 = *colorStops[index];
+ ramp2 = stop2.rampPoint;
+ ScColorEngine::getShadeColorRGB(stop2.color, m_options.document, rgb, stop2.shade);
+ rgb.getValues(r2, g2, b2);
+ double xMin = length * ramp1;
+ double xMax = length * ramp2;
+
+ m_stream << QString("/x1 %1 def\n").arg(xMin);
+ m_stream << QString("/x2 %1 def\n").arg(xMax);
+ m_stream << QString("/r1 %1 def\n").arg(r1/255.0);
+ m_stream << QString("/g1 %1 def\n").arg(g1/255.0);
+ m_stream << QString("/b1 %1 def\n").arg(b1/255.0);
+ m_stream << QString("/r2 %1 def\n").arg(r2/255.0);
+ m_stream << QString("/g2 %1 def\n").arg(g2/255.0);
+ m_stream << QString("/b2 %1 def\n").arg(b2/255.0);
+ m_stream << QString("/maxd %1 def\n").arg(maxDim);
+ m_stream << QString("/mmaxd %1 def\n").arg(-maxDim/2.0);
+ m_stream << "r1 r2 sub abs 255 mul /dr exch def\n";
+ m_stream << "g1 g2 sub abs 255 mul /dg exch def\n";
+ m_stream << "b1 b2 sub abs 255 mul /db exch def\n";
+ m_stream << "dr dg add db add /colsteps exch def\n";
+ m_stream << "colsteps 0.0 eq { /colsteps 1 def } if\n";
+ m_stream << "x2 x1 sub colsteps div /xinc exch def\n";
+ m_stream << "xinc 2 mul /xinc2 exch def\n";
+ m_stream << "x2 xinc2 lt { /xinc2 x2 def } if\n";
+ m_stream << "r2 r1 sub colsteps div /rinc exch def\n";
+ m_stream << "g2 g1 sub colsteps div /ginc exch def\n";
+ m_stream << "b2 b1 sub colsteps div /binc exch def\n";
+ //m_stream << "r1 g1 b1 setrgbcolor\n";
+ //m_stream << "0 mmaxd maxd maxd rectfill\n";
+ m_stream << "0 1 colsteps\n";
+ m_stream << "{\n";
+ m_stream << " r1 g1 b1 setrgbcolor\n";
+ m_stream << " x1 mmaxd xinc2 maxd rectfill\n"; //rectfill is a ps2 operator
+ m_stream << " x1 xinc add /x1 exch def\n";
+ m_stream << " r1 rinc add /r1 exch def\n";
+ m_stream << " g1 ginc add /g1 exch def\n";
+ m_stream << " b1 binc add /b1 exch def\n";
+ m_stream << "} for\n";
+ m_stream << "x2 mmaxd maxd maxd rectfill\n";
+
+ stop1 = stop2;
+ ramp1 = ramp2;
+ r1 = r2;
+ g1 = g2;
+ b1 = b2;
+ }
+}
+
+void ScPainterEx_Ps2::drawLinearGradient_CMYK( VGradientEx& gradient, const QRect& rect )
+{
+ int c1, m1, j1, n1;
+ int c2, m2, j2, n2;
+ double cosa, sina;
+ double ramp1, ramp2;
+ double scale1, scale2;
+ double length, scale;
+ double x1, y1, x2, y2, dx, dy;
+ int clipBoxWidth, clipBoxHeight, maxDim;
+ QList<VColorStopEx*> colorStops = gradient.colorStops();
+ VColorStopEx stop1( *colorStops[0] );
+ VColorStopEx stop2( *colorStops[0] );
+ CMYKColor cmyk;
+ FPoint p1, p2;
+ QColor color;
+
+ if ( gradient.Stops() < 2 )
+ return;
+
+ clipBoxWidth = rect.width();
+ clipBoxHeight = rect.height();
+ maxDim = qRound(sqrt( (double) (clipBoxWidth * clipBoxWidth + clipBoxHeight * clipBoxHeight) )) * 2;
+ if ( maxDim <= 0 ) return;
+
+ scale1 = sqrt( m_matrix.m11() * m_matrix.m11() + m_matrix.m12() * m_matrix.m12() );
+ scale2 = sqrt( m_matrix.m21() * m_matrix.m21() + m_matrix.m22() * m_matrix.m22() );
+
+ x1 = m_matrix.dx() + gradient.origin().x() * m_matrix.m11();
+ y1 = m_matrix.dy() + gradient.origin().y() * m_matrix.m22();
+ x2 = m_matrix.dx() + gradient.vector().x() * m_matrix.m11();
+ y2 = m_matrix.dy() + gradient.vector().y() * m_matrix.m22();
+ p1.setXY( x1, y1 );
+ p2.setXY( x2, y2 );
+
+ dx = ( p2.x() - p1.x() );
+ dy = ( p2.y() - p1.y() );
+ length = sqrt(( dx * dx + dy * dy ));
+ if ( length == 0.0 )
+ scale = 1.0;
+ else
+ scale = 1.0 / length;
+ cosa = dx * scale;
+ sina = dy * scale;
+
+ QString sc("[%1 %2 %3 %4 %5 %6] concat\n");
+ m_stream << sc.arg(cosa).arg(sina).arg(-sina).arg(cosa).arg(x1).arg(y1);
+
+ ramp1 = stop1.rampPoint;
+ ScColorEngine::getShadeColorCMYK(stop1.color, m_options.document, cmyk, stop1.shade);
+ cmyk.getValues(c1, m1, j1, n1);
+ m_stream << QString("/DeviceCMYK setcolorspace\n");
+ m_stream << QString("%1 %2 %3 %4 setcolor fill\n").arg(c1/255.0).arg(m1/255.0).arg(j1/255.0).arg(n1/255.0);
+
+ for( uint index = 1; index < gradient.Stops(); index++)
+ {
+ stop2 = *colorStops[index];
+ ramp2 = stop2.rampPoint;
+ ScColorEngine::getShadeColorCMYK(stop2.color, m_options.document, cmyk, stop2.shade);
+ cmyk.getValues(c2, m2, j2, n2);
+ double xMin = length * ramp1;
+ double xMax = length * ramp2;
+
+ m_stream << QString("/x1 %1 def\n").arg(xMin);
+ m_stream << QString("/x2 %1 def\n").arg(xMax);
+ m_stream << QString("/c1 %1 def\n").arg(c1/255.0);
+ m_stream << QString("/m1 %1 def\n").arg(m1/255.0);
+ m_stream << QString("/y1 %1 def\n").arg(j1/255.0);
+ m_stream << QString("/k1 %1 def\n").arg(n1/255.0);
+ m_stream << QString("/c2 %1 def\n").arg(c2/255.0);
+ m_stream << QString("/m2 %1 def\n").arg(m2/255.0);
+ m_stream << QString("/y2 %1 def\n").arg(j2/255.0);
+ m_stream << QString("/k2 %1 def\n").arg(n2/255.0);
+ m_stream << QString("/maxd %1 def\n").arg(maxDim);
+ m_stream << QString("/mmaxd %1 def\n").arg(-maxDim/2.0);
+ m_stream << "c1 c2 sub abs 255 mul /dc exch def\n";
+ m_stream << "m1 m2 sub abs 255 mul /dm exch def\n";
+ m_stream << "y1 y2 sub abs 255 mul /dy exch def\n";
+ m_stream << "k1 k2 sub abs 255 mul /dk exch def\n";
+ m_stream << "dc dm add dy add dk add /colsteps exch def\n";
+ m_stream << "colsteps 0.0 eq { /colsteps 1 def } if\n";
+ m_stream << "x2 x1 sub colsteps div /xinc exch def\n";
+ m_stream << "xinc 2 mul /xinc2 exch def\n";
+ m_stream << "x2 xinc2 lt { /xinc2 x2 def } if\n";
+ m_stream << "c2 c1 sub colsteps div /cinc exch def\n";
+ m_stream << "m2 m1 sub colsteps div /minc exch def\n";
+ m_stream << "y2 y1 sub colsteps div /yinc exch def\n";
+ m_stream << "k2 k1 sub colsteps div /kinc exch def\n";
+ //m_stream << "r1 g1 b1 setrgbcolor\n";
+ //m_stream << "0 mmaxd maxd maxd rectfill\n";
+ m_stream << "0 1 colsteps\n";
+ m_stream << "{\n";
+ m_stream << " c1 m1 y1 k1 setcolor\n";
+ m_stream << " x1 mmaxd xinc2 maxd rectfill\n"; //rectfill is a ps2 operator
+ m_stream << " x1 xinc add /x1 exch def\n";
+ m_stream << " c1 cinc add /c1 exch def\n";
+ m_stream << " m1 minc add /m1 exch def\n";
+ m_stream << " y1 yinc add /y1 exch def\n";
+ m_stream << " k1 kinc add /k1 exch def\n";
+ m_stream << "} for\n";
+ m_stream << "x2 mmaxd maxd maxd rectfill\n";
+
+ stop1 = stop2;
+ ramp1 = ramp2;
+ c1 = c2;
+ m1 = m2;
+ j1 = j2;
+ n1 = n2;
+ }
+}
+
+void ScPainterEx_Ps2::drawCircularGradient( VGradientEx& gradient, const QRect& rect )
+{
+ if (m_colorMode == cmykMode)
+ drawCircularGradient_CMYK(gradient, rect);
+ else
+ drawCircularGradient_RGB(gradient, rect);
+}
+
+void ScPainterEx_Ps2::drawCircularGradient_RGB( VGradientEx& gradient, const QRect& rect )
+{
+ int r1, g1, b1;
+ int r2, g2, b2;
+ double ramp1, ramp2;
+ double scale1, scale2;
+ int clipBoxWidth, clipBoxHeight, maxDim;
+ QList<VColorStopEx*> colorStops = gradient.colorStops();
+ VColorStopEx stop1( *colorStops[gradient.Stops() - 1] );
+ VColorStopEx stop2( *colorStops[gradient.Stops() - 1] );
+ RGBColor rgb;
+ QColor color;
+
+ clipBoxWidth = rect.width();
+ clipBoxHeight = rect.height();
+ maxDim = qRound(sqrt( (double) (clipBoxWidth * clipBoxWidth + clipBoxHeight * clipBoxHeight) )) * 2;
+ if ( maxDim <= 0 ) return;
+
+ scale1 = sqrt( m_matrix.m11() * m_matrix.m11() + m_matrix.m21() * m_matrix.m21() );
+ scale2 = sqrt( m_matrix.m12() * m_matrix.m12() + m_matrix.m22() * m_matrix.m22() );
+
+ FPoint pc( gradient.origin().x(), gradient.origin().y() );
+ FPoint pcz( gradient.origin().x(), gradient.origin().y() );
+ FPoint pf( gradient.focalPoint().x(), gradient.focalPoint().y() );
+ FPoint pfz( gradient.focalPoint().x(), gradient.focalPoint().y() );
+ FPoint pv( gradient.vector().x(), gradient.vector().y() );
+ transformPoint( pc, pc );
+ transformPoint( pf, pf );
+ transformPoint( pv, pv );
+ transformPoint( pcz, pcz );
+ transformPoint( pfz, pfz );
+ double cx = pcz.x();
+ double cy = pcz.y();
+ double rad = sqrt( pow(pv.x() -pc.x(), 2) + pow(pv.y() - pc.y(), 2) );
+
+ ramp2 = stop2.rampPoint;
+ ScColorEngine::getShadeColorRGB(stop2.color, m_options.document, rgb, stop2.shade);
+ rgb.getValues(r2, g2, b2);
+ m_stream << QString("%1 %2 %3 setrgbcolor fill\n").arg(r2).arg(g2).arg(b2);
+ if ( gradient.Stops() < 2 ) return;
+
+ for( int index = gradient.Stops() - 2; index >= 0; index--)
+ {
+ stop1 = *colorStops[index];
+ ramp1 = stop1.rampPoint;
+ ScColorEngine::getShadeColorRGB(stop1.color, m_options.document, rgb, stop1.shade);
+ rgb.getValues(r1, g1, b1);
+ int radMax = qRound(rad * ramp2);
+ int radMin = qRound(rad * ramp1);
+
+ m_stream << QString("/rad1 %1 def\n").arg(radMax);
+ m_stream << QString("/rad2 %1 def\n").arg(radMin);
+ m_stream << QString("/circx %1 def\n").arg(cx);
+ m_stream << QString("/circy %1 def\n").arg(cy);
+ m_stream << QString("/r1 %1 def\n").arg(r1/255.0);
+ m_stream << QString("/g1 %1 def\n").arg(g1/255.0);
+ m_stream << QString("/b1 %1 def\n").arg(b1/255.0);
+ m_stream << QString("/r2 %1 def\n").arg(r2/255.0);
+ m_stream << QString("/g2 %1 def\n").arg(g2/255.0);
+ m_stream << QString("/b2 %1 def\n").arg(b2/255.0);
+ m_stream << "r1 r2 sub abs 255 mul /dr exch def\n";
+ m_stream << "g1 g2 sub abs 255 mul /dg exch def\n";
+ m_stream << "b1 b2 sub abs 255 mul /db exch def\n";
+ m_stream << "dr dg add db add /colsteps exch def\n";
+ m_stream << "colsteps 0.0 eq { /colsteps 1 def } if\n";
+ m_stream << "rad2 rad1 sub colsteps div /radinc exch def\n";
+ m_stream << "r1 r2 sub colsteps div /rinc exch def\n";
+ m_stream << "g1 g2 sub colsteps div /ginc exch def\n";
+ m_stream << "b1 b2 sub colsteps div /binc exch def\n";
+ m_stream << "0 1 colsteps\n";
+ m_stream << "{\n";
+ m_stream << " r2 g2 b2 setrgbcolor\n";
+ m_stream << " circx circy rad1 0 360 arc closepath fill\n";
+ m_stream << " rad1 radinc add /rad1 exch def\n";
+ m_stream << " r2 rinc add /r2 exch def\n";
+ m_stream << " g2 ginc add /g2 exch def\n";
+ m_stream << " b2 binc add /b2 exch def\n";
+ m_stream << "} for\n";
+
+ stop2 = stop1;
+ ramp2 = ramp1;
+ r2 = r1;
+ g2 = g1;
+ b2 = b1;
+ }
+}
+
+void ScPainterEx_Ps2::drawCircularGradient_CMYK( VGradientEx& gradient, const QRect& rect )
+{
+ int c1, m1, y1, k1;
+ int c2, m2, y2, k2;
+ double ramp1, ramp2;
+ double scale1, scale2;
+ int clipBoxWidth, clipBoxHeight, maxDim;
+ QList<VColorStopEx*> colorStops = gradient.colorStops();
+ VColorStopEx stop1( *colorStops[gradient.Stops() - 1] );
+ VColorStopEx stop2( *colorStops[gradient.Stops() - 1] );
+ CMYKColor cmyk;
+ QColor color;
+
+ clipBoxWidth = rect.width();
+ clipBoxHeight = rect.height();
+ maxDim = qRound(sqrt( (double) (clipBoxWidth * clipBoxWidth + clipBoxHeight * clipBoxHeight) )) * 2;
+ if ( maxDim <= 0 ) return;
+
+ scale1 = sqrt( m_matrix.m11() * m_matrix.m11() + m_matrix.m21() * m_matrix.m21() );
+ scale2 = sqrt( m_matrix.m12() * m_matrix.m12() + m_matrix.m22() * m_matrix.m22() );
+
+ FPoint pc( gradient.origin().x(), gradient.origin().y() );
+ FPoint pcz( gradient.origin().x(), gradient.origin().y() );
+ FPoint pf( gradient.focalPoint().x(), gradient.focalPoint().y() );
+ FPoint pfz( gradient.focalPoint().x(), gradient.focalPoint().y() );
+ FPoint pv( gradient.vector().x(), gradient.vector().y() );
+ transformPoint( pc, pc );
+ transformPoint( pf, pf );
+ transformPoint( pv, pv );
+ transformPoint( pcz, pcz );
+ transformPoint( pfz, pfz );
+ double cx = pcz.x();
+ double cy = pcz.y();
+ double rad = sqrt( pow(pv.x() -pc.x(), 2) + pow(pv.y() - pc.y(), 2) );
+
+ ramp2 = stop2.rampPoint;
+ ScColorEngine::getShadeColorCMYK(stop2.color, m_options.document, cmyk, stop2.shade);
+ cmyk.getValues(c2, m2, y2, k2);
+ m_stream << QString("/DeviceCMYK setcolorspace\n");
+ m_stream << QString("%0 %1 %2 %3 setcolor fill\n").arg(c2).arg(m2).arg(y2).arg(k2);
+ if ( gradient.Stops() < 2 ) return;
+
+ for( int index = gradient.Stops() - 2; index >= 0; index--)
+ {
+ stop1 = *colorStops[index];
+ ramp1 = stop1.rampPoint;
+ ScColorEngine::getShadeColorCMYK(stop1.color, m_options.document, cmyk, stop1.shade);
+ cmyk.getValues(c1, m1, y1, k1);
+ int radMax = qRound(rad * ramp2);
+ int radMin = qRound(rad * ramp1);
+
+ m_stream << QString("/rad1 %1 def\n").arg(radMax);
+ m_stream << QString("/rad2 %1 def\n").arg(radMin);
+ m_stream << QString("/circx %1 def\n").arg(cx);
+ m_stream << QString("/circy %1 def\n").arg(cy);
+ m_stream << QString("/c1 %1 def\n").arg(c1/255.0);
+ m_stream << QString("/m1 %1 def\n").arg(m1/255.0);
+ m_stream << QString("/y1 %1 def\n").arg(y1/255.0);
+ m_stream << QString("/k1 %1 def\n").arg(k1/255.0);
+ m_stream << QString("/c2 %1 def\n").arg(c2/255.0);
+ m_stream << QString("/m2 %1 def\n").arg(m2/255.0);
+ m_stream << QString("/y2 %1 def\n").arg(y2/255.0);
+ m_stream << QString("/k2 %1 def\n").arg(k2/255.0);
+ m_stream << "c1 c2 sub abs 255 mul /dc exch def\n";
+ m_stream << "m1 m2 sub abs 255 mul /dm exch def\n";
+ m_stream << "y1 y2 sub abs 255 mul /dy exch def\n";
+ m_stream << "k1 k2 sub abs 255 mul /dk exch def\n";
+ m_stream << "dc dm add dy add dk add /colsteps exch def\n";
+ m_stream << "colsteps 0.0 eq { /colsteps 1 def } if\n";
+ m_stream << "rad2 rad1 sub colsteps div /radinc exch def\n";
+ m_stream << "c1 c2 sub colsteps div /cinc exch def\n";
+ m_stream << "m1 m2 sub colsteps div /minc exch def\n";
+ m_stream << "y1 y2 sub colsteps div /yinc exch def\n";
+ m_stream << "k1 k2 sub colsteps div /kinc exch def\n";
+ m_stream << "0 1 colsteps\n";
+ m_stream << "{\n";
+ m_stream << " c2 m2 y2 k2 setcolor\n";
+ m_stream << " circx circy rad1 0 360 arc closepath fill\n";
+ m_stream << " rad1 radinc add /rad1 exch def\n";
+ m_stream << " c2 cinc add /c2 exch def\n";
+ m_stream << " m2 minc add /m2 exch def\n";
+ m_stream << " y2 yinc add /y2 exch def\n";
+ m_stream << " k2 kinc add /k2 exch def\n";
+ m_stream << "} for\n";
+
+ stop2 = stop1;
+ ramp2 = ramp1;
+ c2 = c1;
+ m2 = m1;
+ y2 = y1;
+ k2 = k1;
+ }
+}
+
+void ScPainterEx_Ps2::getPathBoundingBox( FPointArray* points, QRect& r )
+{
+ FPoint point;
+ double bottom = DBL_MAX, top = DBL_MIN;
+ double left = DBL_MAX, right = DBL_MIN;
+
+ r.setCoords(0, 0, 0, 0);
+
+ for( uint i = 0; i < points->size(); i++ )
+ {
+ point = points->point(i);
+ if( point.x() > 900000 )
+ continue;
+ transformPoint(point, point);
+ if( point.x() < left ) left = point.x();
+ if( point.x() > right ) right = point.x();
+ if( point.y() < bottom ) bottom = point.y();
+ if( point.y() > top ) top = point.y();
+ }
+ r.setCoords( qRound(left), qRound(bottom), qRound(right), qRound(top) );
+}
+
Index: scribus/scimgdataloader_ps.cpp
===================================================================
--- scribus/scimgdataloader_ps.cpp (revision 13950)
+++ scribus/scimgdataloader_ps.cpp (revision 13951)
@@ -384,7 +384,7 @@
m_imageInfoRecord.valid = (m_imageInfoRecord.PDSpathData.size()) > 0 ? true : false;
if (m_imageInfoRecord.PDSpathData.size() > 0)
{
- QMatrix mm;
+ QTransform mm;
mm.scale(m_imageInfoRecord.xres / 72.0, m_imageInfoRecord.yres / 72.0);
QMap<QString, FPointArray>::Iterator it;
for (it = m_imageInfoRecord.PDSpathData.begin(); it != m_imageInfoRecord.PDSpathData.end(); ++it)
Index: scribus/exif.cpp
===================================================================
--- scribus/exif.cpp (revision 13950)
+++ scribus/exif.cpp (revision 13951)
@@ -15,7 +15,7 @@
#include "exif.h"
-#include <QMatrix>
+#include <QTransform>
//--------------------------------------------------------------------------
// Table of Jpeg encoding process names
@@ -967,8 +967,8 @@
if ( !Orientation || Orientation == 1 ) return Thumbnail;
// now fix orientation
- QMatrix M;
- QMatrix flip = QMatrix ( -1,0,0,1,0,0 );
+ QTransform M;
+ QTransform flip = QTransform ( -1,0,0,1,0,0 );
switch ( Orientation )
{ // notice intentional fallthroughs
case 2: M = flip; break;
Index: scribus/canvasmode_nodeedit.h
===================================================================
--- scribus/canvasmode_nodeedit.h (revision 13950)
+++ scribus/canvasmode_nodeedit.h (revision 13951)
@@ -20,7 +20,7 @@
#include "canvasmode.h"
-#include <QMatrix>
+#include <QTransform>
#include <QRect>
class PageItem;
@@ -57,7 +57,7 @@
inline bool GetItem(PageItem** pi);
void handleNodeEditPress(QMouseEvent*, QRect);
void handleNodeEditDrag(QMouseEvent*, PageItem*);
- bool handleNodeEditMove(QMouseEvent*, QRect, PageItem*, QMatrix);
+ bool handleNodeEditMove(QMouseEvent*, QRect, PageItem*, QTransform);
ScribusMainWindow* m_ScMW;
Index: scribus/scpainterex_gdi.h
===================================================================
--- scribus/scpainterex_gdi.h (revision 13950)
+++ scribus/scpainterex_gdi.h (revision 13951)
@@ -34,7 +34,7 @@
#include <QFont>
#include <QGlobalStatic>
#include <QList>
-#include <QMatrix>
+#include <QTransform>
#include <QPixmap>
#include <QStack>
@@ -74,8 +74,8 @@
virtual void clear( ScColorShade & );
// matrix manipulation
- virtual void setWorldMatrix( const QMatrix & );
- virtual const QMatrix worldMatrix();
+ virtual void setWorldMatrix( const QTransform & );
+ virtual const QTransform worldMatrix();
virtual void translate( double, double );
virtual void rotate( double );
virtual void scale( double, double );
@@ -94,7 +94,7 @@
virtual void setFillMode( int fill );
virtual int fillMode() { return m_fillMode; }
virtual void setGradient( VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc = FPoint(0,0));
- virtual void setPattern ( ScPattern* pattern, QMatrix& patternTransform );
+ virtual void setPattern ( ScPattern* pattern, QTransform& patternTransform );
virtual void setClipPath();
virtual void drawImage( ScImage *image, ScPainterExBase::ImageMode mode );
@@ -142,7 +142,7 @@
unsigned int m_width;
unsigned int m_height;
- QMatrix m_matrix;
+ QTransform m_matrix;
QFont m_font;
/* Filling */
ScColorShade m_fillColor;
@@ -165,7 +165,7 @@
QList<double> m_array;
double m_offset;
/* Transformation Stack */
- QStack<QMatrix> m_stack;
+ QStack<QTransform> m_stack;
/* Some data to describe state of drawing */
bool m_pathIsClosed;
Index: scribus/pslib.h
===================================================================
--- scribus/pslib.h (revision 13950)
+++ scribus/pslib.h (revision 13951)
@@ -126,7 +126,7 @@
virtual void ProcessPage(ScribusDoc* Doc, Page* a, uint PNr, bool sep = false, bool farb = true, bool ic = false, bool gcr = true);
virtual bool ProcessMasterPageLayer(ScribusDoc* Doc, Page* a, ScLayer& ll, uint PNr, bool sep = false, bool farb = true, bool ic = false, bool gcr = true);
virtual bool ProcessPageLayer(ScribusDoc* Doc, Page* a, ScLayer& ll, uint PNr, bool sep = false, bool farb = true, bool ic = false, bool gcr = true);
- virtual void drawArrow(PageItem *ite, QMatrix &arrowTrans, int arrowIndex, bool gcr);
+ virtual void drawArrow(PageItem *ite, QTransform &arrowTrans, int arrowIndex, bool gcr);
virtual void putColor(const QString& color, double shade, bool fill);
virtual void GetBleeds(Page* page, double& left, double& right);
virtual void GetBleeds(Page* page, double& left, double& right, double& bottom, double& top);
Index: scribus/canvasmode_nodeedit.cpp
===================================================================
--- scribus/canvasmode_nodeedit.cpp (revision 13950)
+++ scribus/canvasmode_nodeedit.cpp (revision 13951)
@@ -305,7 +305,7 @@
{
if (!currItem->locked())
{
- QMatrix p; // = currItem->getTransform();
+ QTransform p; // = currItem->getTransform();
QRect mpo; // = QRect(m->globalX()-m_doc->guidesSettings.grabRad, m->globalY()-m_doc->guidesSettings.grabRad, m_doc->guidesSettings.grabRad*2, m_doc->guidesSettings.grabRad*2);
// mpo.moveBy(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
handleNodeEditMove(m, mpo, currItem, p);
@@ -661,12 +661,12 @@
FPointArray Clip = m_doc->nodeEdit.beginTransaction(currItem);
bool edited = false;
bool pfound = false;
-// QMatrix pm;
+// QTransform pm;
// pm.translate(-m_doc->minCanvasCoordinate.x()*m_canvas->scale(), -m_doc->minCanvasCoordinate.y()*m_canvas->scale());
// m_canvas->Transform(currItem, pm);
// npf2 = FPoint(m->pos() * pm.inverted());
npf2 = m_canvas->globalToCanvas(m->globalPos()).transformPoint(currItem->xPos(), currItem->yPos(), currItem->rotation(), 1.0, 1.0, true);
- QMatrix pm2 = currItem->getTransform();
+ QTransform pm2 = currItem->getTransform();
for (int a=0; a < signed(Clip.size()); ++a)
{
if (((m_doc->nodeEdit.EdPoints) && (a % 2 != 0)) || ((!m_doc->nodeEdit.EdPoints) && (a % 2 == 0)))
@@ -1100,9 +1100,9 @@
-bool CanvasMode_NodeEdit::handleNodeEditMove(QMouseEvent* m, QRect, PageItem* currItem, QMatrix)
+bool CanvasMode_NodeEdit::handleNodeEditMove(QMouseEvent* m, QRect, PageItem* currItem, QTransform)
{
- QMatrix itemPos = currItem->getTransform();
+ QTransform itemPos = currItem->getTransform();
FPointArray Clip;
m_doc->nodeEdit.ClRe2 = -1;
m_doc->nodeEdit.SegP1 = -1;
Index: scribus/fpoint.h
===================================================================
--- scribus/fpoint.h (revision 13950)
+++ scribus/fpoint.h (revision 13951)
@@ -24,7 +24,7 @@
#ifndef FPOINT_H
#define FPOINT_H
-#include <QMatrix>
+#include <QTransform>
#include <QPoint>
#include "scribusapi.h"
/**
@@ -59,7 +59,7 @@
//Transform an existing point
void transform(const double dx, const double dy, const double rot, const double sx, const double sy, const bool invert);
//Transform an existing point, return a new one
- FPoint transformPoint(const QMatrix& m, const bool invert) const;
+ FPoint transformPoint(const QTransform& m, const bool invert) const;
FPoint transformPoint(const double dx, const double dy, const double rot, const double sx, const double sy, const bool invert) const;
friend class FPointArray;
Index: scribus/canvasmode_drawfreehand.cpp
===================================================================
--- scribus/canvasmode_drawfreehand.cpp (revision 13950)
+++ scribus/canvasmode_drawfreehand.cpp (revision 13951)
@@ -1,1058 +1,1058 @@
-/*
- For general Scribus (>=1.3.2) copyright and licensing information please refer
- to the COPYING file provided with the program. Following this notice may exist
- a copyright and/or license notice that predates the release of Scribus 1.3.2
- for which a new license (GPL+exception) is in place.
- */
-/***************************************************************************
-* *
-* This program is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-* *
-***************************************************************************/
-
-
-#include "canvasmode_drawfreehand.h"
-
-#include <QApplication>
-#include <QButtonGroup>
-#include <QCheckBox>
-#include <QCursor>
-#include <QEvent>
-#include <QMessageBox>
-#include <QMouseEvent>
-#include <QPainterPath>
-#include <QPoint>
-#include <QRect>
-#include <QWidgetAction>
-
-#include "ui/basepointwidget.h"
-#include "canvas.h"
-#include "canvasgesture_resize.h"
-#include "fpoint.h"
-#include "fpointarray.h"
-#include "hyphenator.h"
-#include "ui/insertTable.h"
-#include "KarbonCurveFit.h"
-#include "ui/oneclick.h"
-#include "pageitem_textframe.h"
-#include "ui/pageselector.h"
-#include "prefscontext.h"
-#include "prefsfile.h"
-#include "prefsmanager.h"
-#include "ui/propertiespalette.h"
-#include "scraction.h"
-#include "ui/scrapbookpalette.h"
-#include "scribus.h"
-#include "scribusdoc.h"
-#include "scribusview.h"
-#include "scribusXml.h"
-#include "selection.h"
-#include "undomanager.h"
-#include "units.h"
-#include "util.h"
-#include "util_icon.h"
-#include "util_math.h"
-
-
-
-FreehandMode::FreehandMode(ScribusView* view) : CanvasMode(view)
-{
- GxM = GyM = -1;
- Mxp = Myp = -1;
- Dxp = Dyp = -1;
- MoveGX = MoveGY = false;
- oldCp = Cp = -1;
- frameResizeHandle = -1;
- RotMode = 0;
- inItemCreation = false;
- shiftSelItems = false;
- FirstPoly = true;
-}
-
-
-void FreehandMode::drawControls(QPainter* p)
-{
- //
-}
-
-inline bool FreehandMode::GetItem(PageItem** pi)
-{
- *pi = m_doc->m_Selection->itemAt(0);
- return (*pi) != NULL;
-}
-
-
-
-
-// the following code was moved from scribusview.cpp:
-
-
-void FreehandMode::enterEvent(QEvent *)
-{
- if (!m_MouseButtonPressed)
- {
- setModeCursor();
- }
-}
-
-
-void FreehandMode::leaveEvent(QEvent *e)
-{
- if (!m_MouseButtonPressed)
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
-}
-
-
-void FreehandMode::activate(bool flag)
-{
-// qDebug() << "FreehandMode::activate" << flag;
- GxM = GyM = -1;
- Mxp = Myp = -1;
- Dxp = Dyp = -1;
- MoveGX = MoveGY = false;
- oldCp = Cp = -1;
- frameResizeHandle = -1;
- RotMode = 0;
- inItemCreation = false;
- shiftSelItems = false;
- FirstPoly = true;
- setModeCursor();
-}
-
-void FreehandMode::deactivate(bool flag)
-{
-// qDebug() << "FreehandMode::deactivate" << flag;
- m_view->redrawMarker->hide();
-}
-
-void FreehandMode::mouseDoubleClickEvent(QMouseEvent *m)
-{
- m->accept();
- m_MouseButtonPressed = false;
- m_canvas->resetRenderMode();
- mousePressEvent(m);
-}
-
-
-void FreehandMode::mouseMoveEvent(QMouseEvent *m)
-{
- const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
-
- double newX, newY;
- PageItem *currItem;
- QPoint np, np2, mop;
- FPoint npf, npf2;
- QRect tx;
- m->accept();
- m_canvas->displayCorrectedXYHUD(m->globalPos(), mousePointDoc.x(), mousePointDoc.y());
-// qDebug() << "legacy mode move:" << m->x() << m->y() << m_canvas->globalToCanvas(m->globalPos()).x() << m_canvas->globalToCanvas(m->globalPos()).y();
-// emit MousePos(m->x()/m_canvas->scale(),// + m_doc->minCanvasCoordinate.x(),
-// m->y()/m_canvas->scale()); // + m_doc->minCanvasCoordinate.y());
-/* if (m_doc->guidesSettings.guidesShown)
- {
- if (MoveGY)
- {
- m_view->FromHRuler(m);
- return;
- }
- if (MoveGX)
- {
- m_view->FromVRuler(m);
- return;
- }
- }
-*/
-
- if (commonMouseMove(m))
- return;
-
- if (m_MouseButtonPressed && (m_doc->appMode == modeDrawFreehandLine))
- {
- //newX = m->x();
- //newY = m->y();
- double newXF = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
- double newYF = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
- if (RecordP.size() > 0)
- {
- if (FPoint(newXF, newYF) != RecordP.point(RecordP.size()-1))
- RecordP.addPoint(FPoint(newXF, newYF));
- }
- else
- RecordP.addPoint(FPoint(newXF, newYF));
- QPolygon& redrawPolygon(m_canvas->newRedrawPolygon());
- for (uint pp = 0; pp < RecordP.size(); pp++)
- {
- redrawPolygon << RecordP.pointQ(pp);
- }
-//FIXME
- m_canvas->m_viewMode.operItemResizing = true;
- QRect bRect = m_canvas->redrawPolygon().boundingRect();
-// QPoint in(qRound(bRect.x()*m_canvas->scale()), qRound(bRect.y()*m_canvas->scale()));
-// in -= QPoint(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
-// QPoint out = contentsToViewport(in);
-// m_view->updateContents(QRect(out.x()+0*contentsX(), out.y()+0*contentsY(), qRound(bRect.width()*m_canvas->scale()), qRound(bRect.height()*m_canvas->scale())).adjusted(-10, -10, 20, 20));
- // m_canvas->update(bRect);
- m_view->updateCanvas(bRect);
- return;
- }
-
- if ((GetItem(&currItem)) && (!shiftSelItems))
- {
- newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
- newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
-
- if (m_doc->DragP)
- return;
-
- if ((!m_MouseButtonPressed) && (m_doc->appMode != modeDrawBezierLine))
- {
- if (m_doc->m_Selection->isMultipleSelection())
- {
- setModeCursor();
- return;
- }
- for (int a = 0; a < m_doc->m_Selection->count(); ++a)
- {
- currItem = m_doc->m_Selection->itemAt(a);
- if (currItem->locked())
- break;
- setModeCursor();
- }
- }
- }
- else
- {
- if ((m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton) && (GyM == -1) && (GxM == -1))
- {
- newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
- newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
- SeRx = newX;
- SeRy = newY;
- /*
- if (m_doc->appMode == modeDrawTable)
- m_view->redrawMarker->setGeometry(QRect(Dxp, Dyp, m->globalPos().x() - Dxp, m->globalPos().y() - Dyp).normalized());
- else
- m_view->redrawMarker->setGeometry(QRect(Mxp, Myp, m->globalPos().x() - Mxp, m->globalPos().y() - Myp).normalized());
- */
- QPoint startP = m_canvas->canvasToGlobal(m_doc->appMode == modeDrawTable? QPointF(Dxp, Dyp) : QPointF(Mxp, Myp));
- m_view->redrawMarker->setGeometry(QRect(startP, m->globalPos()).normalized());
- if (!m_view->redrawMarker->isVisible())
- m_view->redrawMarker->show();
- m_view->HaveSelRect = true;
- return;
- }
- }
-}
-
-void FreehandMode::mousePressEvent(QMouseEvent *m)
-{
- const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
- double Rxp = 0;
- double Ryp = 0;
- double Rxpd = 0;
- double Rypd = 0;
-// m_canvas->PaintSizeRect(QRect());
- FPoint npf, npf2;
- QRect tx;
- QMatrix pm;
- m_MouseButtonPressed = true;
- m_view->HaveSelRect = false;
- m_doc->DragP = false;
- m_doc->leaveDrag = false;
- MoveGX = MoveGY = false;
- inItemCreation = false;
-// oldClip = 0;
- m->accept();
- m_view->registerMousePress(m->globalPos());
- Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
- Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
- QRect mpo(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
-// mpo.moveBy(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
- Rxp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).x();
- Rxpd = Mxp - Rxp;
- Mxp = qRound(Rxp);
- Ryp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).y();
- Rypd = Myp - Ryp;
- Myp = qRound(Ryp);
- SeRx = Mxp;
- SeRy = Myp;
- if (m->button() == Qt::MidButton)
- {
- m_view->MidButt = true;
- if (m->modifiers() & Qt::ControlModifier)
- m_view->DrawNew();
- return;
- }
- if (m->button() != Qt::LeftButton)
- {
- m_view->stopGesture();
- return;
- }
- RecordP.resize(0);
- m_view->Deselect(false);
- Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
- Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
- SeRx = Mxp;
- SeRy = Myp;
- m_canvas->setRenderModeFillBuffer();
-}
-
-
-
-void FreehandMode::mouseReleaseEvent(QMouseEvent *m)
-{
- const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
-
-
- PageItem *currItem;
- m_MouseButtonPressed = false;
- m_canvas->resetRenderMode();
- m->accept();
-// m_view->stopDragTimer();
-
- if (m_doc->appMode == modeDrawFreehandLine)
- {
- if (RecordP.size() > 1)
- {
- UndoTransaction createTransaction(UndoManager::instance()->beginTransaction());
- uint z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, Mxp, Myp, 1, 1, m_doc->toolSettings.dWidthLine, CommonStrings::None, m_doc->toolSettings.dPenLine, true);
- currItem = m_doc->Items->at(z);
- currItem->PoLine.resize(0);
- if (m->modifiers() & Qt::ControlModifier)
- {
- QList<QPointF> clip;
- for (uint px = 0; px < RecordP.size()-1; ++px)
- {
- FPoint clp = RecordP.point(px);
- clip.append(QPointF(clp.x(), clp.y()));
- }
- QPainterPath pp = bezierFit(clip, 5.0);
- currItem->PoLine.fromQPainterPath(pp);
- }
- else
- {
- currItem->PoLine.addPoint(RecordP.point(0));
- currItem->PoLine.addPoint(RecordP.point(0));
- for (uint px = 1; px < RecordP.size()-1; ++px)
- {
- currItem->PoLine.addPoint(RecordP.point(px));
- currItem->PoLine.addPoint(RecordP.point(px));
- currItem->PoLine.addPoint(RecordP.point(px));
- currItem->PoLine.addPoint(RecordP.point(px));
- }
- currItem->PoLine.addPoint(RecordP.point(RecordP.size()-1));
- currItem->PoLine.addPoint(RecordP.point(RecordP.size()-1));
- }
- FPoint tp2(getMinClipF(&currItem->PoLine));
- currItem->setXYPos(tp2.x(), tp2.y(), true);
- currItem->PoLine.translate(-tp2.x(), -tp2.y());
- FPoint tp(getMaxClipF(&currItem->PoLine));
- m_doc->SizeItem(tp.x(), tp.y(), currItem->ItemNr, false, false, false);
- m_doc->AdjustItemSize(currItem);
- m_doc->m_Selection->clear();
- m_doc->m_Selection->addItem(currItem);
- currItem->ClipEdited = true;
- currItem->FrameType = 3;
- currItem->OwnPage = m_doc->OnPage(currItem);
- m_view->resetMousePressed();
- currItem->checkChanges();
- QString targetName = Um::ScratchSpace;
- if (currItem->OwnPage > -1)
- targetName = m_doc->Pages->at(currItem->OwnPage)->getUName();
- createTransaction.commit(targetName, currItem->getUPixmap(),
- Um::Create + " " + currItem->getUName(), "", Um::ICreate);
- //FIXME
- m_canvas->m_viewMode.operItemResizing = false;
- inItemCreation = false;
- m_doc->changed();
-// m_view->updateContents(currItem->getRedrawBounding(m_canvas->scale()).adjusted(-10, -10, 20, 20));
- }
- if (!PrefsManager::instance()->appPrefs.stickyTools)
- {
- m_view->requestMode(modeNormal);
-// m_view->requestMode(submodePaintingDone);
- }
- else
- m_view->requestMode(m_doc->appMode);
-// itemAdd calls PageItem::update emit DocChanged();
- return;
- }
-
-
- assert(false);
- if (m_doc->appMode != modeDrawBezierLine) //FIXME: that should be dead - av
- {
- if (inItemCreation)
- {
- currItem = m_doc->m_Selection->itemAt(0);
- double itemX = 0.0;
- double itemY = 0.0;
- if (m_doc->appMode == modeDrawLine)
- {
- QMatrix p = currItem->getTransform();
- FPoint np = m_doc->ApplyGridF(mousePointDoc).transformPoint(p, true);
- itemX = sqrt(pow(np.x(),2.0)+pow(np.y(),2.0));
- itemY = 1.0;
- }
- else if (m_doc->appMode == modeDrawRegularPolygon)
- {
- FPoint np1(mousePointDoc); //m_view->translateToDoc(m->x(), m->y()));
- np1 = m_doc->ApplyGridF(np1);
- itemX = fabs(np1.x() - currItem->xPos());
- itemY = fabs(np1.y() - currItem->yPos());
- }
- else
- {
- itemX = fabs(currItem->width());
- itemY = fabs(currItem->height());
- }
- if ((!m_view->moveTimerElapsed()) || ((itemX < 2.0) && (itemY < 2.0)) || ((m_doc->appMode == modeDrawLine) && (itemX < 2.0)))
- {
- int lmode = 0;
- if (m_doc->appMode == modeDrawLine)
- lmode = 1;
- PrefsContext* sizes = PrefsManager::instance()->prefsFile->getContext("ObjectSize");
- double xSize, ySize;
- int originPoint;
- if (lmode == 0)
- {
- xSize = sizes->getDouble("defWidth", 100.0);
- ySize = sizes->getDouble("defHeight", 100.0);
- originPoint = sizes->getInt("Origin", 0);
- }
- else
- {
- xSize = sizes->getDouble("defLength", 100.0);
- ySize = sizes->getDouble("defAngle", 0.0);
- originPoint = sizes->getInt("OriginL", 0);
- }
- bool doRemember = sizes->getBool("Remember", true);
- bool doCreate = false;
- if (m->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier))
- doCreate = true;
- else
- {
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- OneClick *dia = new OneClick(m_view, ScribusView::tr("Enter Object Size"), m_doc->unitIndex(), xSize, ySize, doRemember, originPoint, lmode);
- if (dia->exec())
- {
- doRemember = dia->checkRemember->isChecked();
- if (lmode == 0)
- {
- xSize = dia->spinWidth->value() / unitGetRatioFromIndex(m_doc->unitIndex());
- ySize = dia->spinHeight->value() / unitGetRatioFromIndex(m_doc->unitIndex());
- originPoint = dia->RotationGroup->checkedId();
- if (doRemember)
- {
- sizes->set("defWidth", xSize);
- sizes->set("defHeight", ySize);
- sizes->set("Origin", originPoint);
- }
- }
- else
- {
- xSize = dia->spinWidth->value() / unitGetRatioFromIndex(m_doc->unitIndex());
- ySize = dia->spinHeight->value();
- originPoint = dia->RotationGroup->checkedId();
- if (doRemember)
- {
- sizes->set("defLength", xSize);
- sizes->set("defAngle", ySize);
- sizes->set("OriginL", originPoint);
- }
- }
- sizes->set("Remember", doRemember);
- doCreate = true;
- }
- else
- {
- m_view->Deselect(false);
- m_doc->Items->removeAt(currItem->ItemNr);
- }
- delete dia;
- }
- if (doCreate)
- {
- bool oldSnap = m_doc->SnapGuides;
- m_doc->SnapGuides = false;
- m_doc->SizeItem(xSize, ySize, currItem->ItemNr, false, false, false);
- currItem->updateClip();
- currItem->ContourLine = currItem->PoLine.copy();
- switch (originPoint)
- {
- case 0:
- break;
- case 1:
- if (lmode == 0)
- m_doc->MoveItem(-currItem->width(), 0.0, currItem, false);
- else
- m_doc->MoveRotated(currItem, FPoint(-currItem->width() / 2.0, 0.0), false);
- break;
- case 2:
- if (lmode == 0)
- m_doc->MoveItem(-currItem->width() / 2.0, -currItem->height() / 2.0, currItem, false);
- else
- m_doc->MoveRotated(currItem, FPoint(-currItem->width(), 0.0), false);
- break;
- case 3:
- m_doc->MoveItem(0.0, -currItem->height(), currItem, false);
- break;
- case 4:
- m_doc->MoveItem(-currItem->width(), -currItem->height(), currItem, false);
- break;
- }
- m_doc->setRedrawBounding(currItem);
- currItem->OwnPage = m_doc->OnPage(currItem);
- currItem->OldB2 = currItem->width();
- currItem->OldH2 = currItem->height();
- currItem->Sizing = false;
- m_doc->SnapGuides = oldSnap;
- if (!PrefsManager::instance()->appPrefs.stickyTools)
- {
- m_view->requestMode(modeNormal);
-// m_view->requestMode(submodePaintingDone);
- }
- else
- {
- int appMode = m_doc->appMode;
- if ((inItemCreation) && (appMode == modeNormal))
- {
- currItem = m_doc->m_Selection->itemAt(0);
- if (currItem->asTextFrame())
- appMode = modeDrawText;
- else if (currItem->asImageFrame())
- appMode = modeDrawImage;
- else if (m_doc->SubMode != -1)
- appMode = modeDrawShapes;
- }
- m_view->requestMode(appMode);
- }
- currItem->update();
- m_doc->changed();
-// emit DocChanged();
- }
- else
- {
- m_view->requestMode(submodePaintingDone);
-// emit HaveSel(-1);
- }
- inItemCreation = false;
- m_doc->DragP = false;
- m_doc->leaveDrag = false;
-//FIXME m_canvas->m_viewMode.operItemResizing = false;
- m_canvas->setRenderModeUseBuffer(false);
- m_view->MidButt = false;
- shiftSelItems = false;
- m_view->updateCanvas();
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- }
- }
- if (m_view->moveTimerElapsed() && (GetItem(&currItem)))
- {
- m_canvas->setRenderModeUseBuffer(false);
- if (m_doc->m_Selection->isMultipleSelection())
- {
-
- }
- else
- {
- //Where a single frame resize stops when the mouse buttno is released
- //FIXME: reduce code!
- if (currItem->Sizing)
- {
- FPoint npx;
- double nx = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
- double ny = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
- if (m_doc->SnapGuides)
- {
- m_doc->ApplyGuides(&nx, &ny);
- npx = FPoint(nx, ny, currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true);
- }
- else
- {
- npx = m_doc->ApplyGridF(FPoint(nx, ny));
- npx = FPoint(npx.x(), npx.y(), currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true);
- }
- if ((frameResizeHandle == 1) && !(currItem->asLine()) && (m_doc->SnapGuides))
- m_doc->SizeItem(npx.x(), npx.y(), currItem->ItemNr);
- bool sav = m_doc->SnapGuides;
- m_doc->SnapGuides = false;
- UndoTransaction* activeTransaction = NULL;
- if (UndoManager::undoEnabled())
- {
- activeTransaction = new UndoTransaction(m_view->undoManager->beginTransaction(currItem->getUName(), currItem->getUPixmap(),
- Um::Resize, QString(Um::ResizeFromTo).arg(currItem->width()).arg(currItem->height()).arg(currItem->width() - npx.x()).arg(currItem->height() - npx.y()), Um::IResize));
- }
-// m_canvas->m_viewMode.operItemResizing = false;
- switch (frameResizeHandle)
- {
- case 1:
- if (!currItem->asLine())
- {
- //<<Swap location if width/height is <0
- if (currItem->width()<0)
- {
- currItem->setWidth(-currItem->width());
- currItem->setXPos(currItem->xPos()-currItem->width());
- }
- if (currItem->height()<0)
- {
- currItem->setHeight(-currItem->height());
- currItem->setYPos(currItem->yPos()-currItem->height());
- }
- //>>
- if (currItem->imageFlippedH())
- currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
- if (currItem->imageFlippedV())
- currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
- }
- else
- {
- if (sav)
- {
- double nx = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
- double ny = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
- if (m_doc->useRaster)
- {
- FPoint ra(m_doc->ApplyGridF(FPoint(nx, ny)));
- nx = ra.x();
- ny = ra.y();
- }
- m_doc->SnapGuides = sav;
- m_doc->ApplyGuides(&nx, &ny);
- m_doc->SnapGuides = false;
- double r = atan2(ny - currItem->yPos(), nx - currItem->xPos())*(180.0/M_PI);
- m_doc->RotateItem(r, currItem->ItemNr);
- double w = sqrt(pow(nx - currItem->xPos(), 2) + pow(ny - currItem->yPos(),2));
- m_doc->SizeItem(w, currItem->height(), currItem->ItemNr, true);
- }
- }
- currItem->Sizing = false;
- break;
- case 2:
- if (!currItem->asLine())
- {
- m_doc->MoveSizeItem(npx, npx, currItem->ItemNr);
-
- //<<Swap location if width/height is <0
- if (currItem->width()<0)
- {
- currItem->setWidth(-currItem->width());
- currItem->setXPos(currItem->xPos()-currItem->width());
- }
- if (currItem->height()<0)
- {
- currItem->setHeight(-currItem->height());
- currItem->setYPos(currItem->yPos()-currItem->height());
- }
- //>>
-
- currItem->Sizing = false;
- if (!currItem->imageFlippedH())
- {
- currItem->moveImageInFrame((currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
- currItem->update();
- }
- if (!currItem->imageFlippedV())
- {
- currItem->moveImageInFrame(0, (currItem->height() - currItem->OldH2)/currItem->imageYScale());
- currItem->update();
- }
- }
- else
- {
- if (sav)
- {
- double nx = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
- double ny = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
- if (m_doc->useRaster)
- {
- FPoint ra(m_doc->ApplyGridF(FPoint(nx, ny)));
- nx = ra.x();
- ny = ra.y();
- }
- m_doc->SnapGuides = sav;
- m_doc->ApplyGuides(&nx, &ny);
- m_doc->SnapGuides = false;
- QMatrix ma;
- ma.translate(currItem->xPos(), currItem->yPos());
- ma.rotate(currItem->rotation());
- double mx = ma.m11() * currItem->width() + ma.m21() * currItem->height() + ma.dx();
- double my = ma.m22() * currItem->height() + ma.m12() * currItem->width() + ma.dy();
- double r = atan2(my-ny,mx-nx)*(180.0/M_PI);
- double w = sqrt(pow(mx-nx,2)+pow(my-ny,2));
- m_doc->MoveItem(nx - currItem->xPos(), ny - currItem->yPos(), currItem, true);
- m_doc->SizeItem(w, currItem->height(), currItem->ItemNr, true);
- m_doc->RotateItem(r, currItem->ItemNr);
- currItem->Sizing = false;
- }
- }
- break;
- case 3:
- m_doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(currItem->width() - npx.x(), npx.y()), currItem->ItemNr);
-
- //<<Swap location if width/height is <0
- if (currItem->width()<0)
- {
- currItem->setWidth(-currItem->width());
- currItem->setXPos(currItem->xPos()-currItem->width());
- }
- if (currItem->height()<0)
- {
- currItem->setHeight(-currItem->height());
- currItem->setYPos(currItem->yPos()-currItem->height());
- }
- //>>
-
- currItem->Sizing = false;
- if (currItem->imageFlippedH())
- currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
- if (!currItem->imageFlippedV())
- currItem->moveImageInFrame(0, (currItem->height() - currItem->OldH2)/currItem->imageYScale());
- break;
- case 4:
-
- m_doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), currItem->height() - npx.y()), currItem->ItemNr);
-
- //<<Swap location if width/height is <0
- if (currItem->width()<0)
- {
- currItem->setWidth(-currItem->width());
- currItem->setXPos(currItem->xPos()-currItem->width());
- }
- if (currItem->height()<0)
- {
- currItem->setHeight(-currItem->height());
- currItem->setYPos(currItem->yPos()-currItem->height());
- }
- //>>
-
- currItem->Sizing = false;
- if (!currItem->imageFlippedH())
- currItem->moveImageInFrame((currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
- if (currItem->imageFlippedV())
- currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
- break;
- case 5:
- m_doc->MoveSizeItem(FPoint(0, 0), FPoint(0, currItem->height() - npx.y()), currItem->ItemNr);
- if (currItem->imageFlippedV())
- currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
-
- //<<Swap location if width/height is <0
- if (currItem->width()<0)
- {
- currItem->setWidth(-currItem->width());
- currItem->setXPos(currItem->xPos()-currItem->width());
- }
- if (currItem->height()<0)
- {
- currItem->setHeight(-currItem->height());
- currItem->setYPos(currItem->yPos()-currItem->height());
- }
- //>>
-
- currItem->Sizing = false;
- break;
- case 6:
- m_doc->MoveSizeItem(FPoint(0, 0), FPoint(currItem->width() - npx.x(), 0), currItem->ItemNr);
- if (currItem->imageFlippedH())
- currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
-
- //<<Swap location if width/height is <0
- if (currItem->width()<0)
- {
- currItem->setWidth(-currItem->width());
- currItem->setXPos(currItem->xPos()-currItem->width());
- }
- if (currItem->height()<0)
- {
- currItem->setHeight(-currItem->height());
- currItem->setYPos(currItem->yPos()-currItem->height());
- }
- //>>
-
- currItem->Sizing = false;
- break;
- case 7:
- m_doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), 0), currItem->ItemNr);
-
- //<<Swap location if width/height is <0
- if (currItem->width()<0)
- {
- currItem->setWidth(-currItem->width());
- currItem->setXPos(currItem->xPos()-currItem->width());
- }
- if (currItem->height()<0)
- {
- currItem->setHeight(-currItem->height());
- currItem->setYPos(currItem->yPos()-currItem->height());
- }
- //>>
-
- currItem->Sizing = false;
- if (!currItem->imageFlippedH())
- currItem->moveImageInFrame((currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
- if (currItem->imageFlippedV())
- currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
- break;
- case 8:
- m_doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(0, npx.y()), currItem->ItemNr);
-
- //<<Swap location if width/height is <0
- if (currItem->width()<0)
- {
- currItem->setWidth(-currItem->width());
- currItem->setXPos(currItem->xPos()-currItem->width());
- }
- if (currItem->height()<0)
- {
- currItem->setHeight(-currItem->height());
- currItem->setYPos(currItem->yPos()-currItem->height());
- }
- //>>
-
- currItem->Sizing = false;
- if (currItem->imageFlippedH())
- currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
- if (!currItem->imageFlippedV())
- currItem->moveImageInFrame(0, (currItem->height() - currItem->OldH2)/currItem->imageYScale());
- break;
- }
-
- currItem->updateClip();
-// emit ItemTextCols(currItem->Cols, currItem->ColGap);
- m_doc->SnapGuides = sav;
-// evSpon = false;
- currItem->update(); // MoveSizeItem *should* call PageItem::update
- m_view->updateCanvas();
-// emit DocChanged();
- currItem->checkChanges();
- if (activeTransaction)
- {
- activeTransaction->commit();
- delete activeTransaction;
- activeTransaction = NULL;
- }
- }
- m_doc->setRedrawBounding(currItem);
- currItem->OwnPage = m_doc->OnPage(currItem);
-// m_canvas->m_viewMode.operItemResizing = false;
- if (currItem->asLine())
- m_view->updateCanvas();
- }
- }
- //CB Drag selection performed here
- if (((m_doc->m_Selection->count() == 0) && (m_view->HaveSelRect) && (!m_view->MidButt)) || ((shiftSelItems) && (m_view->HaveSelRect) && (!m_view->MidButt)))
- {
- QRectF Sele = QRectF(Dxp, Dyp, SeRx-Dxp, SeRy-Dyp).normalized();
- if (!m_doc->masterPageMode())
- {
- uint docPagesCount=m_doc->Pages->count();
- uint docCurrPageNo=m_doc->currentPageNumber();
- for (uint i = 0; i < docPagesCount; ++i)
- {
- if (QRectF(m_doc->Pages->at(i)->xOffset(), m_doc->Pages->at(i)->yOffset(), m_doc->Pages->at(i)->width(), m_doc->Pages->at(i)->height()).intersects(Sele))
- {
- if (docCurrPageNo != i)
- {
- m_doc->setCurrentPage(m_doc->Pages->at(i));
- m_view->setMenTxt(i);
- }
- break;
- }
- }
-//FIXME m_view->setRulerPos(m_view->contentsX(), m_view->contentsY());
- }
-/* FIXME
- int docItemCount=m_doc->Items->count();
- if (docItemCount != 0)
- {
- m_doc->m_Selection->setIsGUISelection(false);
- for (int a = 0; a < docItemCount; ++a)
- {
- PageItem* docItem = m_doc->Items->at(a);
- QMatrix p;
- m_canvas->Transform(docItem, p);
- QRegion apr = QRegion(docItem->Clip * p);
- QRect apr2(docItem->getRedrawBounding(1.0));
- if ((m_doc->masterPageMode()) && (docItem->OnMasterPage != m_doc->currentPage()->pageName()))
- continue;
- //CB Finally Items are selected here
- if (((Sele.contains(apr.boundingRect())) || (Sele.contains(apr2))) && (docItem->LayerID == m_doc->activeLayer()) && (!m_doc->layerLocked(docItem->LayerID)))
- {
- //CB set draw to true to (dis)enable some actions via emit to HaveNewSel in scapp.
- //CB FIXME emit from selection when multiple selected instead
- //CB #3523 bool redrawSelection=(a==docItemCount-1);
- bool redrawSelection=false;
- m_view->SelectItemNr(a, redrawSelection);
- }
- }
- m_doc->m_Selection->setIsGUISelection(true);
- m_doc->m_Selection->connectItemToGUI();
- if (m_doc->m_Selection->count() > 1)
- {
- m_doc->m_Selection->setGroupRect();
- double x, y, w, h;
- m_doc->m_Selection->getGroupRect(&x, &y, &w, &h);
-// emit ItemPos(x, y);
-// emit ItemGeom(w, h);
- m_view->getGroupRectScreen(&x, &y, &w, &h);
- }
-// if (m_doc->m_Selection->count() > 0)
-// emit HaveSel(m_doc->m_Selection->itemAt(0)->itemType());
- }*/
-
- m_view->HaveSelRect = false;
- shiftSelItems = false;
- m_view->redrawMarker->hide();
- m_view->updateCanvas();
- }
- if (m_doc->appMode != modeEdit)
- {
- if (!PrefsManager::instance()->appPrefs.stickyTools)
- {
-// qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- m_view->requestMode(modeNormal);
-// m_view->requestMode(submodePaintingDone);
- }
- else
- {
- int appMode = m_doc->appMode;
- if ((inItemCreation) && (appMode == modeNormal))
- {
- currItem = m_doc->m_Selection->itemAt(0);
- if (currItem->asTextFrame())
- appMode = modeDrawText;
- else if (currItem->asImageFrame())
- appMode = modeDrawImage;
- else if (m_doc->SubMode != -1)
- appMode = modeDrawShapes;
- }
- m_view->requestMode(appMode);
- }
- }
- if (GetItem(&currItem))
- {
- if (m_doc->m_Selection->count() > 1)
- {
- m_doc->m_Selection->setGroupRect();
- //CB shouldnt need this i think
- //emit HaveSel(currItem->itemType());
- double x, y, w, h;
- m_doc->m_Selection->getGroupRect(&x, &y, &w, &h);
-// emit ItemPos(x, y);
-// emit ItemGeom(w, h);
-// m_view->getGroupRectScreen(&x, &y, &w, &h);
-
-// m_canvas->m_viewMode.operItemResizing = false;
- m_canvas->update(QRect(static_cast<int>(x-5), static_cast<int>(y-5), static_cast<int>(w+10), static_cast<int>(h+10)));
- }
- else
- currItem->emitAllToGUI();
-
- /*else
- {
- //CB Dont think we need this here with the new selection code
- //For a select, deselect operation, this will cause 2x emit
- //emit HaveSel(currItem->itemType());
- //EmitValues(currItem);
- //currItem->emitAllToGUI();
- }*/
- }
- }
-
-
- m_canvas->setRenderModeUseBuffer(false);
-
- m_doc->DragP = false;
- m_doc->leaveDrag = false;
-// m_canvas->m_viewMode.operItemResizing = false;
- m_view->MidButt = false;
- shiftSelItems = false;
- inItemCreation = false;
-// m_doc->SubMode = -1;
- if (m_view->groupTransactionStarted())
- {
- for (int i = 0; i < m_doc->m_Selection->count(); ++i)
- m_doc->m_Selection->itemAt(i)->checkChanges(true);
- m_view->endGroupTransaction();
- }
-
- for (int i = 0; i < m_doc->m_Selection->count(); ++i)
- m_doc->m_Selection->itemAt(i)->checkChanges(true);
-
- //Commit drag created items to undo manager.
- if (m_doc->m_Selection->itemAt(0)!=NULL)
- {
- m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0)->ItemNr);
- }
- //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas
- m_view->zoomSpinBox->clearFocus();
- m_view->pageSelector->clearFocus();
- if (m_doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action
- {
- currItem = m_doc->m_Selection->itemAt(0);
- m_doc->nodeEdit.finishTransaction(currItem);
- }
- else
- {
- //delete oldClip;
- //oldClip = 0;
- }
-}
-
-
-
-void FreehandMode::selectPage(QMouseEvent *m)
-{
- m_MouseButtonPressed = true;
- FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
- Mxp = mousePointDoc.x(); //static_cast<int>(m->x()/m_canvas->scale());
- Myp = mousePointDoc.y(); //static_cast<int>(m->y()/m_canvas->scale());
- QRect mpo(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
-// mpo.moveBy(qRound(Doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
- m_doc->nodeEdit.deselect();
- m_view->Deselect(false);
- if (!m_doc->masterPageMode())
- {
- int i = m_doc->OnPage(Mxp, Myp);
- if (i!=-1)
- {
- uint docCurrPageNo=m_doc->currentPageNumber();
- uint j=static_cast<uint>(i);
- if (docCurrPageNo != j)
- {
- m_doc->setCurrentPage(m_doc->Pages->at(j));
- m_view->setMenTxt(j);
- m_view->DrawNew();
- }
- }
-/* uint docPagesCount=m_doc->Pages->count();
- uint docCurrPageNo=m_doc->currentPageNumber();
- for (uint i = 0; i < docPagesCount; ++i)
- {
- int x = static_cast<int>(m_doc->Pages->at(i)->xOffset() * m_canvas->scale());
- int y = static_cast<int>(m_doc->Pages->at(i)->yOffset() * m_canvas->scale());
- int w = static_cast<int>(m_doc->Pages->at(i)->width() * m_canvas->scale());
- int h = static_cast<int>(m_doc->Pages->at(i)->height() * m_canvas->scale());
- if (QRect(x, y, w, h).intersects(mpo))
- {
- if (docCurrPageNo != i)
- {
- m_doc->setCurrentPage(m_doc->Pages->at(i));
- setMenTxt(i);
- DrawNew();
- }
- break;
- }
- } */
-
- //FIXME m_view->setRulerPos(m_view->contentsX(), m_view->contentsY());
- }
-}
-
-
-
+/*
+ For general Scribus (>=1.3.2) copyright and licensing information please refer
+ to the COPYING file provided with the program. Following this notice may exist
+ a copyright and/or license notice that predates the release of Scribus 1.3.2
+ for which a new license (GPL+exception) is in place.
+ */
+/***************************************************************************
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+***************************************************************************/
+
+
+#include "canvasmode_drawfreehand.h"
+
+#include <QApplication>
+#include <QButtonGroup>
+#include <QCheckBox>
+#include <QCursor>
+#include <QEvent>
+#include <QMessageBox>
+#include <QMouseEvent>
+#include <QPainterPath>
+#include <QPoint>
+#include <QRect>
+#include <QWidgetAction>
+
+#include "ui/basepointwidget.h"
+#include "canvas.h"
+#include "canvasgesture_resize.h"
+#include "fpoint.h"
+#include "fpointarray.h"
+#include "hyphenator.h"
+#include "ui/insertTable.h"
+#include "KarbonCurveFit.h"
+#include "ui/oneclick.h"
+#include "pageitem_textframe.h"
+#include "ui/pageselector.h"
+#include "prefscontext.h"
+#include "prefsfile.h"
+#include "prefsmanager.h"
+#include "ui/propertiespalette.h"
+#include "scraction.h"
+#include "ui/scrapbookpalette.h"
+#include "scribus.h"
+#include "scribusdoc.h"
+#include "scribusview.h"
+#include "scribusXml.h"
+#include "selection.h"
+#include "undomanager.h"
+#include "units.h"
+#include "util.h"
+#include "util_icon.h"
+#include "util_math.h"
+
+
+
+FreehandMode::FreehandMode(ScribusView* view) : CanvasMode(view)
+{
+ GxM = GyM = -1;
+ Mxp = Myp = -1;
+ Dxp = Dyp = -1;
+ MoveGX = MoveGY = false;
+ oldCp = Cp = -1;
+ frameResizeHandle = -1;
+ RotMode = 0;
+ inItemCreation = false;
+ shiftSelItems = false;
+ FirstPoly = true;
+}
+
+
+void FreehandMode::drawControls(QPainter* p)
+{
+ //
+}
+
+inline bool FreehandMode::GetItem(PageItem** pi)
+{
+ *pi = m_doc->m_Selection->itemAt(0);
+ return (*pi) != NULL;
+}
+
+
+
+
+// the following code was moved from scribusview.cpp:
+
+
+void FreehandMode::enterEvent(QEvent *)
+{
+ if (!m_MouseButtonPressed)
+ {
+ setModeCursor();
+ }
+}
+
+
+void FreehandMode::leaveEvent(QEvent *e)
+{
+ if (!m_MouseButtonPressed)
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+}
+
+
+void FreehandMode::activate(bool flag)
+{
+// qDebug() << "FreehandMode::activate" << flag;
+ GxM = GyM = -1;
+ Mxp = Myp = -1;
+ Dxp = Dyp = -1;
+ MoveGX = MoveGY = false;
+ oldCp = Cp = -1;
+ frameResizeHandle = -1;
+ RotMode = 0;
+ inItemCreation = false;
+ shiftSelItems = false;
+ FirstPoly = true;
+ setModeCursor();
+}
+
+void FreehandMode::deactivate(bool flag)
+{
+// qDebug() << "FreehandMode::deactivate" << flag;
+ m_view->redrawMarker->hide();
+}
+
+void FreehandMode::mouseDoubleClickEvent(QMouseEvent *m)
+{
+ m->accept();
+ m_MouseButtonPressed = false;
+ m_canvas->resetRenderMode();
+ mousePressEvent(m);
+}
+
+
+void FreehandMode::mouseMoveEvent(QMouseEvent *m)
+{
+ const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+
+ double newX, newY;
+ PageItem *currItem;
+ QPoint np, np2, mop;
+ FPoint npf, npf2;
+ QRect tx;
+ m->accept();
+ m_canvas->displayCorrectedXYHUD(m->globalPos(), mousePointDoc.x(), mousePointDoc.y());
+// qDebug() << "legacy mode move:" << m->x() << m->y() << m_canvas->globalToCanvas(m->globalPos()).x() << m_canvas->globalToCanvas(m->globalPos()).y();
+// emit MousePos(m->x()/m_canvas->scale(),// + m_doc->minCanvasCoordinate.x(),
+// m->y()/m_canvas->scale()); // + m_doc->minCanvasCoordinate.y());
+/* if (m_doc->guidesSettings.guidesShown)
+ {
+ if (MoveGY)
+ {
+ m_view->FromHRuler(m);
+ return;
+ }
+ if (MoveGX)
+ {
+ m_view->FromVRuler(m);
+ return;
+ }
+ }
+*/
+
+ if (commonMouseMove(m))
+ return;
+
+ if (m_MouseButtonPressed && (m_doc->appMode == modeDrawFreehandLine))
+ {
+ //newX = m->x();
+ //newY = m->y();
+ double newXF = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
+ double newYF = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
+ if (RecordP.size() > 0)
+ {
+ if (FPoint(newXF, newYF) != RecordP.point(RecordP.size()-1))
+ RecordP.addPoint(FPoint(newXF, newYF));
+ }
+ else
+ RecordP.addPoint(FPoint(newXF, newYF));
+ QPolygon& redrawPolygon(m_canvas->newRedrawPolygon());
+ for (uint pp = 0; pp < RecordP.size(); pp++)
+ {
+ redrawPolygon << RecordP.pointQ(pp);
+ }
+//FIXME
+ m_canvas->m_viewMode.operItemResizing = true;
+ QRect bRect = m_canvas->redrawPolygon().boundingRect();
+// QPoint in(qRound(bRect.x()*m_canvas->scale()), qRound(bRect.y()*m_canvas->scale()));
+// in -= QPoint(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
+// QPoint out = contentsToViewport(in);
+// m_view->updateContents(QRect(out.x()+0*contentsX(), out.y()+0*contentsY(), qRound(bRect.width()*m_canvas->scale()), qRound(bRect.height()*m_canvas->scale())).adjusted(-10, -10, 20, 20));
+ // m_canvas->update(bRect);
+ m_view->updateCanvas(bRect);
+ return;
+ }
+
+ if ((GetItem(&currItem)) && (!shiftSelItems))
+ {
+ newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
+ newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
+
+ if (m_doc->DragP)
+ return;
+
+ if ((!m_MouseButtonPressed) && (m_doc->appMode != modeDrawBezierLine))
+ {
+ if (m_doc->m_Selection->isMultipleSelection())
+ {
+ setModeCursor();
+ return;
+ }
+ for (int a = 0; a < m_doc->m_Selection->count(); ++a)
+ {
+ currItem = m_doc->m_Selection->itemAt(a);
+ if (currItem->locked())
+ break;
+ setModeCursor();
+ }
+ }
+ }
+ else
+ {
+ if ((m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton) && (GyM == -1) && (GxM == -1))
+ {
+ newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
+ newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
+ SeRx = newX;
+ SeRy = newY;
+ /*
+ if (m_doc->appMode == modeDrawTable)
+ m_view->redrawMarker->setGeometry(QRect(Dxp, Dyp, m->globalPos().x() - Dxp, m->globalPos().y() - Dyp).normalized());
+ else
+ m_view->redrawMarker->setGeometry(QRect(Mxp, Myp, m->globalPos().x() - Mxp, m->globalPos().y() - Myp).normalized());
+ */
+ QPoint startP = m_canvas->canvasToGlobal(m_doc->appMode == modeDrawTable? QPointF(Dxp, Dyp) : QPointF(Mxp, Myp));
+ m_view->redrawMarker->setGeometry(QRect(startP, m->globalPos()).normalized());
+ if (!m_view->redrawMarker->isVisible())
+ m_view->redrawMarker->show();
+ m_view->HaveSelRect = true;
+ return;
+ }
+ }
+}
+
+void FreehandMode::mousePressEvent(QMouseEvent *m)
+{
+ const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+ double Rxp = 0;
+ double Ryp = 0;
+ double Rxpd = 0;
+ double Rypd = 0;
+// m_canvas->PaintSizeRect(QRect());
+ FPoint npf, npf2;
+ QRect tx;
+ QTransform pm;
+ m_MouseButtonPressed = true;
+ m_view->HaveSelRect = false;
+ m_doc->DragP = false;
+ m_doc->leaveDrag = false;
+ MoveGX = MoveGY = false;
+ inItemCreation = false;
+// oldClip = 0;
+ m->accept();
+ m_view->registerMousePress(m->globalPos());
+ Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
+ Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
+ QRect mpo(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
+// mpo.moveBy(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
+ Rxp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).x();
+ Rxpd = Mxp - Rxp;
+ Mxp = qRound(Rxp);
+ Ryp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).y();
+ Rypd = Myp - Ryp;
+ Myp = qRound(Ryp);
+ SeRx = Mxp;
+ SeRy = Myp;
+ if (m->button() == Qt::MidButton)
+ {
+ m_view->MidButt = true;
+ if (m->modifiers() & Qt::ControlModifier)
+ m_view->DrawNew();
+ return;
+ }
+ if (m->button() != Qt::LeftButton)
+ {
+ m_view->stopGesture();
+ return;
+ }
+ RecordP.resize(0);
+ m_view->Deselect(false);
+ Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
+ Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
+ SeRx = Mxp;
+ SeRy = Myp;
+ m_canvas->setRenderModeFillBuffer();
+}
+
+
+
+void FreehandMode::mouseReleaseEvent(QMouseEvent *m)
+{
+ const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+
+
+ PageItem *currItem;
+ m_MouseButtonPressed = false;
+ m_canvas->resetRenderMode();
+ m->accept();
+// m_view->stopDragTimer();
+
+ if (m_doc->appMode == modeDrawFreehandLine)
+ {
+ if (RecordP.size() > 1)
+ {
+ UndoTransaction createTransaction(UndoManager::instance()->beginTransaction());
+ uint z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, Mxp, Myp, 1, 1, m_doc->toolSettings.dWidthLine, CommonStrings::None, m_doc->toolSettings.dPenLine, true);
+ currItem = m_doc->Items->at(z);
+ currItem->PoLine.resize(0);
+ if (m->modifiers() & Qt::ControlModifier)
+ {
+ QList<QPointF> clip;
+ for (uint px = 0; px < RecordP.size()-1; ++px)
+ {
+ FPoint clp = RecordP.point(px);
+ clip.append(QPointF(clp.x(), clp.y()));
+ }
+ QPainterPath pp = bezierFit(clip, 5.0);
+ currItem->PoLine.fromQPainterPath(pp);
+ }
+ else
+ {
+ currItem->PoLine.addPoint(RecordP.point(0));
+ currItem->PoLine.addPoint(RecordP.point(0));
+ for (uint px = 1; px < RecordP.size()-1; ++px)
+ {
+ currItem->PoLine.addPoint(RecordP.point(px));
+ currItem->PoLine.addPoint(RecordP.point(px));
+ currItem->PoLine.addPoint(RecordP.point(px));
+ currItem->PoLine.addPoint(RecordP.point(px));
+ }
+ currItem->PoLine.addPoint(RecordP.point(RecordP.size()-1));
+ currItem->PoLine.addPoint(RecordP.point(RecordP.size()-1));
+ }
+ FPoint tp2(getMinClipF(&currItem->PoLine));
+ currItem->setXYPos(tp2.x(), tp2.y(), true);
+ currItem->PoLine.translate(-tp2.x(), -tp2.y());
+ FPoint tp(getMaxClipF(&currItem->PoLine));
+ m_doc->SizeItem(tp.x(), tp.y(), currItem->ItemNr, false, false, false);
+ m_doc->AdjustItemSize(currItem);
+ m_doc->m_Selection->clear();
+ m_doc->m_Selection->addItem(currItem);
+ currItem->ClipEdited = true;
+ currItem->FrameType = 3;
+ currItem->OwnPage = m_doc->OnPage(currItem);
+ m_view->resetMousePressed();
+ currItem->checkChanges();
+ QString targetName = Um::ScratchSpace;
+ if (currItem->OwnPage > -1)
+ targetName = m_doc->Pages->at(currItem->OwnPage)->getUName();
+ createTransaction.commit(targetName, currItem->getUPixmap(),
+ Um::Create + " " + currItem->getUName(), "", Um::ICreate);
+ //FIXME
+ m_canvas->m_viewMode.operItemResizing = false;
+ inItemCreation = false;
+ m_doc->changed();
+// m_view->updateContents(currItem->getRedrawBounding(m_canvas->scale()).adjusted(-10, -10, 20, 20));
+ }
+ if (!PrefsManager::instance()->appPrefs.stickyTools)
+ {
+ m_view->requestMode(modeNormal);
+// m_view->requestMode(submodePaintingDone);
+ }
+ else
+ m_view->requestMode(m_doc->appMode);
+// itemAdd calls PageItem::update emit DocChanged();
+ return;
+ }
+
+
+ assert(false);
+ if (m_doc->appMode != modeDrawBezierLine) //FIXME: that should be dead - av
+ {
+ if (inItemCreation)
+ {
+ currItem = m_doc->m_Selection->itemAt(0);
+ double itemX = 0.0;
+ double itemY = 0.0;
+ if (m_doc->appMode == modeDrawLine)
+ {
+ QTransform p = currItem->getTransform();
+ FPoint np = m_doc->ApplyGridF(mousePointDoc).transformPoint(p, true);
+ itemX = sqrt(pow(np.x(),2.0)+pow(np.y(),2.0));
+ itemY = 1.0;
+ }
+ else if (m_doc->appMode == modeDrawRegularPolygon)
+ {
+ FPoint np1(mousePointDoc); //m_view->translateToDoc(m->x(), m->y()));
+ np1 = m_doc->ApplyGridF(np1);
+ itemX = fabs(np1.x() - currItem->xPos());
+ itemY = fabs(np1.y() - currItem->yPos());
+ }
+ else
+ {
+ itemX = fabs(currItem->width());
+ itemY = fabs(currItem->height());
+ }
+ if ((!m_view->moveTimerElapsed()) || ((itemX < 2.0) && (itemY < 2.0)) || ((m_doc->appMode == modeDrawLine) && (itemX < 2.0)))
+ {
+ int lmode = 0;
+ if (m_doc->appMode == modeDrawLine)
+ lmode = 1;
+ PrefsContext* sizes = PrefsManager::instance()->prefsFile->getContext("ObjectSize");
+ double xSize, ySize;
+ int originPoint;
+ if (lmode == 0)
+ {
+ xSize = sizes->getDouble("defWidth", 100.0);
+ ySize = sizes->getDouble("defHeight", 100.0);
+ originPoint = sizes->getInt("Origin", 0);
+ }
+ else
+ {
+ xSize = sizes->getDouble("defLength", 100.0);
+ ySize = sizes->getDouble("defAngle", 0.0);
+ originPoint = sizes->getInt("OriginL", 0);
+ }
+ bool doRemember = sizes->getBool("Remember", true);
+ bool doCreate = false;
+ if (m->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier))
+ doCreate = true;
+ else
+ {
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ OneClick *dia = new OneClick(m_view, ScribusView::tr("Enter Object Size"), m_doc->unitIndex(), xSize, ySize, doRemember, originPoint, lmode);
+ if (dia->exec())
+ {
+ doRemember = dia->checkRemember->isChecked();
+ if (lmode == 0)
+ {
+ xSize = dia->spinWidth->value() / unitGetRatioFromIndex(m_doc->unitIndex());
+ ySize = dia->spinHeight->value() / unitGetRatioFromIndex(m_doc->unitIndex());
+ originPoint = dia->RotationGroup->checkedId();
+ if (doRemember)
+ {
+ sizes->set("defWidth", xSize);
+ sizes->set("defHeight", ySize);
+ sizes->set("Origin", originPoint);
+ }
+ }
+ else
+ {
+ xSize = dia->spinWidth->value() / unitGetRatioFromIndex(m_doc->unitIndex());
+ ySize = dia->spinHeight->value();
+ originPoint = dia->RotationGroup->checkedId();
+ if (doRemember)
+ {
+ sizes->set("defLength", xSize);
+ sizes->set("defAngle", ySize);
+ sizes->set("OriginL", originPoint);
+ }
+ }
+ sizes->set("Remember", doRemember);
+ doCreate = true;
+ }
+ else
+ {
+ m_view->Deselect(false);
+ m_doc->Items->removeAt(currItem->ItemNr);
+ }
+ delete dia;
+ }
+ if (doCreate)
+ {
+ bool oldSnap = m_doc->SnapGuides;
+ m_doc->SnapGuides = false;
+ m_doc->SizeItem(xSize, ySize, currItem->ItemNr, false, false, false);
+ currItem->updateClip();
+ currItem->ContourLine = currItem->PoLine.copy();
+ switch (originPoint)
+ {
+ case 0:
+ break;
+ case 1:
+ if (lmode == 0)
+ m_doc->MoveItem(-currItem->width(), 0.0, currItem, false);
+ else
+ m_doc->MoveRotated(currItem, FPoint(-currItem->width() / 2.0, 0.0), false);
+ break;
+ case 2:
+ if (lmode == 0)
+ m_doc->MoveItem(-currItem->width() / 2.0, -currItem->height() / 2.0, currItem, false);
+ else
+ m_doc->MoveRotated(currItem, FPoint(-currItem->width(), 0.0), false);
+ break;
+ case 3:
+ m_doc->MoveItem(0.0, -currItem->height(), currItem, false);
+ break;
+ case 4:
+ m_doc->MoveItem(-currItem->width(), -currItem->height(), currItem, false);
+ break;
+ }
+ m_doc->setRedrawBounding(currItem);
+ currItem->OwnPage = m_doc->OnPage(currItem);
+ currItem->OldB2 = currItem->width();
+ currItem->OldH2 = currItem->height();
+ currItem->Sizing = false;
+ m_doc->SnapGuides = oldSnap;
+ if (!PrefsManager::instance()->appPrefs.stickyTools)
+ {
+ m_view->requestMode(modeNormal);
+// m_view->requestMode(submodePaintingDone);
+ }
+ else
+ {
+ int appMode = m_doc->appMode;
+ if ((inItemCreation) && (appMode == modeNormal))
+ {
+ currItem = m_doc->m_Selection->itemAt(0);
+ if (currItem->asTextFrame())
+ appMode = modeDrawText;
+ else if (currItem->asImageFrame())
+ appMode = modeDrawImage;
+ else if (m_doc->SubMode != -1)
+ appMode = modeDrawShapes;
+ }
+ m_view->requestMode(appMode);
+ }
+ currItem->update();
+ m_doc->changed();
+// emit DocChanged();
+ }
+ else
+ {
+ m_view->requestMode(submodePaintingDone);
+// emit HaveSel(-1);
+ }
+ inItemCreation = false;
+ m_doc->DragP = false;
+ m_doc->leaveDrag = false;
+//FIXME m_canvas->m_viewMode.operItemResizing = false;
+ m_canvas->setRenderModeUseBuffer(false);
+ m_view->MidButt = false;
+ shiftSelItems = false;
+ m_view->updateCanvas();
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ }
+ }
+ if (m_view->moveTimerElapsed() && (GetItem(&currItem)))
+ {
+ m_canvas->setRenderModeUseBuffer(false);
+ if (m_doc->m_Selection->isMultipleSelection())
+ {
+
+ }
+ else
+ {
+ //Where a single frame resize stops when the mouse buttno is released
+ //FIXME: reduce code!
+ if (currItem->Sizing)
+ {
+ FPoint npx;
+ double nx = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
+ double ny = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
+ if (m_doc->SnapGuides)
+ {
+ m_doc->ApplyGuides(&nx, &ny);
+ npx = FPoint(nx, ny, currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true);
+ }
+ else
+ {
+ npx = m_doc->ApplyGridF(FPoint(nx, ny));
+ npx = FPoint(npx.x(), npx.y(), currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true);
+ }
+ if ((frameResizeHandle == 1) && !(currItem->asLine()) && (m_doc->SnapGuides))
+ m_doc->SizeItem(npx.x(), npx.y(), currItem->ItemNr);
+ bool sav = m_doc->SnapGuides;
+ m_doc->SnapGuides = false;
+ UndoTransaction* activeTransaction = NULL;
+ if (UndoManager::undoEnabled())
+ {
+ activeTransaction = new UndoTransaction(m_view->undoManager->beginTransaction(currItem->getUName(), currItem->getUPixmap(),
+ Um::Resize, QString(Um::ResizeFromTo).arg(currItem->width()).arg(currItem->height()).arg(currItem->width() - npx.x()).arg(currItem->height() - npx.y()), Um::IResize));
+ }
+// m_canvas->m_viewMode.operItemResizing = false;
+ switch (frameResizeHandle)
+ {
+ case 1:
+ if (!currItem->asLine())
+ {
+ //<<Swap location if width/height is <0
+ if (currItem->width()<0)
+ {
+ currItem->setWidth(-currItem->width());
+ currItem->setXPos(currItem->xPos()-currItem->width());
+ }
+ if (currItem->height()<0)
+ {
+ currItem->setHeight(-currItem->height());
+ currItem->setYPos(currItem->yPos()-currItem->height());
+ }
+ //>>
+ if (currItem->imageFlippedH())
+ currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
+ if (currItem->imageFlippedV())
+ currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
+ }
+ else
+ {
+ if (sav)
+ {
+ double nx = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
+ double ny = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
+ if (m_doc->useRaster)
+ {
+ FPoint ra(m_doc->ApplyGridF(FPoint(nx, ny)));
+ nx = ra.x();
+ ny = ra.y();
+ }
+ m_doc->SnapGuides = sav;
+ m_doc->ApplyGuides(&nx, &ny);
+ m_doc->SnapGuides = false;
+ double r = atan2(ny - currItem->yPos(), nx - currItem->xPos())*(180.0/M_PI);
+ m_doc->RotateItem(r, currItem->ItemNr);
+ double w = sqrt(pow(nx - currItem->xPos(), 2) + pow(ny - currItem->yPos(),2));
+ m_doc->SizeItem(w, currItem->height(), currItem->ItemNr, true);
+ }
+ }
+ currItem->Sizing = false;
+ break;
+ case 2:
+ if (!currItem->asLine())
+ {
+ m_doc->MoveSizeItem(npx, npx, currItem->ItemNr);
+
+ //<<Swap location if width/height is <0
+ if (currItem->width()<0)
+ {
+ currItem->setWidth(-currItem->width());
+ currItem->setXPos(currItem->xPos()-currItem->width());
+ }
+ if (currItem->height()<0)
+ {
+ currItem->setHeight(-currItem->height());
+ currItem->setYPos(currItem->yPos()-currItem->height());
+ }
+ //>>
+
+ currItem->Sizing = false;
+ if (!currItem->imageFlippedH())
+ {
+ currItem->moveImageInFrame((currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
+ currItem->update();
+ }
+ if (!currItem->imageFlippedV())
+ {
+ currItem->moveImageInFrame(0, (currItem->height() - currItem->OldH2)/currItem->imageYScale());
+ currItem->update();
+ }
+ }
+ else
+ {
+ if (sav)
+ {
+ double nx = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x();
+ double ny = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y();
+ if (m_doc->useRaster)
+ {
+ FPoint ra(m_doc->ApplyGridF(FPoint(nx, ny)));
+ nx = ra.x();
+ ny = ra.y();
+ }
+ m_doc->SnapGuides = sav;
+ m_doc->ApplyGuides(&nx, &ny);
+ m_doc->SnapGuides = false;
+ QTransform ma;
+ ma.translate(currItem->xPos(), currItem->yPos());
+ ma.rotate(currItem->rotation());
+ double mx = ma.m11() * currItem->width() + ma.m21() * currItem->height() + ma.dx();
+ double my = ma.m22() * currItem->height() + ma.m12() * currItem->width() + ma.dy();
+ double r = atan2(my-ny,mx-nx)*(180.0/M_PI);
+ double w = sqrt(pow(mx-nx,2)+pow(my-ny,2));
+ m_doc->MoveItem(nx - currItem->xPos(), ny - currItem->yPos(), currItem, true);
+ m_doc->SizeItem(w, currItem->height(), currItem->ItemNr, true);
+ m_doc->RotateItem(r, currItem->ItemNr);
+ currItem->Sizing = false;
+ }
+ }
+ break;
+ case 3:
+ m_doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(currItem->width() - npx.x(), npx.y()), currItem->ItemNr);
+
+ //<<Swap location if width/height is <0
+ if (currItem->width()<0)
+ {
+ currItem->setWidth(-currItem->width());
+ currItem->setXPos(currItem->xPos()-currItem->width());
+ }
+ if (currItem->height()<0)
+ {
+ currItem->setHeight(-currItem->height());
+ currItem->setYPos(currItem->yPos()-currItem->height());
+ }
+ //>>
+
+ currItem->Sizing = false;
+ if (currItem->imageFlippedH())
+ currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
+ if (!currItem->imageFlippedV())
+ currItem->moveImageInFrame(0, (currItem->height() - currItem->OldH2)/currItem->imageYScale());
+ break;
+ case 4:
+
+ m_doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), currItem->height() - npx.y()), currItem->ItemNr);
+
+ //<<Swap location if width/height is <0
+ if (currItem->width()<0)
+ {
+ currItem->setWidth(-currItem->width());
+ currItem->setXPos(currItem->xPos()-currItem->width());
+ }
+ if (currItem->height()<0)
+ {
+ currItem->setHeight(-currItem->height());
+ currItem->setYPos(currItem->yPos()-currItem->height());
+ }
+ //>>
+
+ currItem->Sizing = false;
+ if (!currItem->imageFlippedH())
+ currItem->moveImageInFrame((currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
+ if (currItem->imageFlippedV())
+ currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
+ break;
+ case 5:
+ m_doc->MoveSizeItem(FPoint(0, 0), FPoint(0, currItem->height() - npx.y()), currItem->ItemNr);
+ if (currItem->imageFlippedV())
+ currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
+
+ //<<Swap location if width/height is <0
+ if (currItem->width()<0)
+ {
+ currItem->setWidth(-currItem->width());
+ currItem->setXPos(currItem->xPos()-currItem->width());
+ }
+ if (currItem->height()<0)
+ {
+ currItem->setHeight(-currItem->height());
+ currItem->setYPos(currItem->yPos()-currItem->height());
+ }
+ //>>
+
+ currItem->Sizing = false;
+ break;
+ case 6:
+ m_doc->MoveSizeItem(FPoint(0, 0), FPoint(currItem->width() - npx.x(), 0), currItem->ItemNr);
+ if (currItem->imageFlippedH())
+ currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
+
+ //<<Swap location if width/height is <0
+ if (currItem->width()<0)
+ {
+ currItem->setWidth(-currItem->width());
+ currItem->setXPos(currItem->xPos()-currItem->width());
+ }
+ if (currItem->height()<0)
+ {
+ currItem->setHeight(-currItem->height());
+ currItem->setYPos(currItem->yPos()-currItem->height());
+ }
+ //>>
+
+ currItem->Sizing = false;
+ break;
+ case 7:
+ m_doc->MoveSizeItem(FPoint(npx.x(), 0), FPoint(npx.x(), 0), currItem->ItemNr);
+
+ //<<Swap location if width/height is <0
+ if (currItem->width()<0)
+ {
+ currItem->setWidth(-currItem->width());
+ currItem->setXPos(currItem->xPos()-currItem->width());
+ }
+ if (currItem->height()<0)
+ {
+ currItem->setHeight(-currItem->height());
+ currItem->setYPos(currItem->yPos()-currItem->height());
+ }
+ //>>
+
+ currItem->Sizing = false;
+ if (!currItem->imageFlippedH())
+ currItem->moveImageInFrame((currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
+ if (currItem->imageFlippedV())
+ currItem->moveImageInFrame(0, -(currItem->height() - currItem->OldH2)/currItem->imageYScale());
+ break;
+ case 8:
+ m_doc->MoveSizeItem(FPoint(0, npx.y()), FPoint(0, npx.y()), currItem->ItemNr);
+
+ //<<Swap location if width/height is <0
+ if (currItem->width()<0)
+ {
+ currItem->setWidth(-currItem->width());
+ currItem->setXPos(currItem->xPos()-currItem->width());
+ }
+ if (currItem->height()<0)
+ {
+ currItem->setHeight(-currItem->height());
+ currItem->setYPos(currItem->yPos()-currItem->height());
+ }
+ //>>
+
+ currItem->Sizing = false;
+ if (currItem->imageFlippedH())
+ currItem->moveImageInFrame(-(currItem->width() - currItem->OldB2)/currItem->imageXScale(), 0);
+ if (!currItem->imageFlippedV())
+ currItem->moveImageInFrame(0, (currItem->height() - currItem->OldH2)/currItem->imageYScale());
+ break;
+ }
+
+ currItem->updateClip();
+// emit ItemTextCols(currItem->Cols, currItem->ColGap);
+ m_doc->SnapGuides = sav;
+// evSpon = false;
+ currItem->update(); // MoveSizeItem *should* call PageItem::update
+ m_view->updateCanvas();
+// emit DocChanged();
+ currItem->checkChanges();
+ if (activeTransaction)
+ {
+ activeTransaction->commit();
+ delete activeTransaction;
+ activeTransaction = NULL;
+ }
+ }
+ m_doc->setRedrawBounding(currItem);
+ currItem->OwnPage = m_doc->OnPage(currItem);
+// m_canvas->m_viewMode.operItemResizing = false;
+ if (currItem->asLine())
+ m_view->updateCanvas();
+ }
+ }
+ //CB Drag selection performed here
+ if (((m_doc->m_Selection->count() == 0) && (m_view->HaveSelRect) && (!m_view->MidButt)) || ((shiftSelItems) && (m_view->HaveSelRect) && (!m_view->MidButt)))
+ {
+ QRectF Sele = QRectF(Dxp, Dyp, SeRx-Dxp, SeRy-Dyp).normalized();
+ if (!m_doc->masterPageMode())
+ {
+ uint docPagesCount=m_doc->Pages->count();
+ uint docCurrPageNo=m_doc->currentPageNumber();
+ for (uint i = 0; i < docPagesCount; ++i)
+ {
+ if (QRectF(m_doc->Pages->at(i)->xOffset(), m_doc->Pages->at(i)->yOffset(), m_doc->Pages->at(i)->width(), m_doc->Pages->at(i)->height()).intersects(Sele))
+ {
+ if (docCurrPageNo != i)
+ {
+ m_doc->setCurrentPage(m_doc->Pages->at(i));
+ m_view->setMenTxt(i);
+ }
+ break;
+ }
+ }
+//FIXME m_view->setRulerPos(m_view->contentsX(), m_view->contentsY());
+ }
+/* FIXME
+ int docItemCount=m_doc->Items->count();
+ if (docItemCount != 0)
+ {
+ m_doc->m_Selection->setIsGUISelection(false);
+ for (int a = 0; a < docItemCount; ++a)
+ {
+ PageItem* docItem = m_doc->Items->at(a);
+ QTransform p;
+ m_canvas->Transform(docItem, p);
+ QRegion apr = QRegion(docItem->Clip * p);
+ QRect apr2(docItem->getRedrawBounding(1.0));
+ if ((m_doc->masterPageMode()) && (docItem->OnMasterPage != m_doc->currentPage()->pageName()))
+ continue;
+ //CB Finally Items are selected here
+ if (((Sele.contains(apr.boundingRect())) || (Sele.contains(apr2))) && (docItem->LayerID == m_doc->activeLayer()) && (!m_doc->layerLocked(docItem->LayerID)))
+ {
+ //CB set draw to true to (dis)enable some actions via emit to HaveNewSel in scapp.
+ //CB FIXME emit from selection when multiple selected instead
+ //CB #3523 bool redrawSelection=(a==docItemCount-1);
+ bool redrawSelection=false;
+ m_view->SelectItemNr(a, redrawSelection);
+ }
+ }
+ m_doc->m_Selection->setIsGUISelection(true);
+ m_doc->m_Selection->connectItemToGUI();
+ if (m_doc->m_Selection->count() > 1)
+ {
+ m_doc->m_Selection->setGroupRect();
+ double x, y, w, h;
+ m_doc->m_Selection->getGroupRect(&x, &y, &w, &h);
+// emit ItemPos(x, y);
+// emit ItemGeom(w, h);
+ m_view->getGroupRectScreen(&x, &y, &w, &h);
+ }
+// if (m_doc->m_Selection->count() > 0)
+// emit HaveSel(m_doc->m_Selection->itemAt(0)->itemType());
+ }*/
+
+ m_view->HaveSelRect = false;
+ shiftSelItems = false;
+ m_view->redrawMarker->hide();
+ m_view->updateCanvas();
+ }
+ if (m_doc->appMode != modeEdit)
+ {
+ if (!PrefsManager::instance()->appPrefs.stickyTools)
+ {
+// qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ m_view->requestMode(modeNormal);
+// m_view->requestMode(submodePaintingDone);
+ }
+ else
+ {
+ int appMode = m_doc->appMode;
+ if ((inItemCreation) && (appMode == modeNormal))
+ {
+ currItem = m_doc->m_Selection->itemAt(0);
+ if (currItem->asTextFrame())
+ appMode = modeDrawText;
+ else if (currItem->asImageFrame())
+ appMode = modeDrawImage;
+ else if (m_doc->SubMode != -1)
+ appMode = modeDrawShapes;
+ }
+ m_view->requestMode(appMode);
+ }
+ }
+ if (GetItem(&currItem))
+ {
+ if (m_doc->m_Selection->count() > 1)
+ {
+ m_doc->m_Selection->setGroupRect();
+ //CB shouldnt need this i think
+ //emit HaveSel(currItem->itemType());
+ double x, y, w, h;
+ m_doc->m_Selection->getGroupRect(&x, &y, &w, &h);
+// emit ItemPos(x, y);
+// emit ItemGeom(w, h);
+// m_view->getGroupRectScreen(&x, &y, &w, &h);
+
+// m_canvas->m_viewMode.operItemResizing = false;
+ m_canvas->update(QRect(static_cast<int>(x-5), static_cast<int>(y-5), static_cast<int>(w+10), static_cast<int>(h+10)));
+ }
+ else
+ currItem->emitAllToGUI();
+
+ /*else
+ {
+ //CB Dont think we need this here with the new selection code
+ //For a select, deselect operation, this will cause 2x emit
+ //emit HaveSel(currItem->itemType());
+ //EmitValues(currItem);
+ //currItem->emitAllToGUI();
+ }*/
+ }
+ }
+
+
+ m_canvas->setRenderModeUseBuffer(false);
+
+ m_doc->DragP = false;
+ m_doc->leaveDrag = false;
+// m_canvas->m_viewMode.operItemResizing = false;
+ m_view->MidButt = false;
+ shiftSelItems = false;
+ inItemCreation = false;
+// m_doc->SubMode = -1;
+ if (m_view->groupTransactionStarted())
+ {
+ for (int i = 0; i < m_doc->m_Selection->count(); ++i)
+ m_doc->m_Selection->itemAt(i)->checkChanges(true);
+ m_view->endGroupTransaction();
+ }
+
+ for (int i = 0; i < m_doc->m_Selection->count(); ++i)
+ m_doc->m_Selection->itemAt(i)->checkChanges(true);
+
+ //Commit drag created items to undo manager.
+ if (m_doc->m_Selection->itemAt(0)!=NULL)
+ {
+ m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0)->ItemNr);
+ }
+ //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas
+ m_view->zoomSpinBox->clearFocus();
+ m_view->pageSelector->clearFocus();
+ if (m_doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action
+ {
+ currItem = m_doc->m_Selection->itemAt(0);
+ m_doc->nodeEdit.finishTransaction(currItem);
+ }
+ else
+ {
+ //delete oldClip;
+ //oldClip = 0;
+ }
+}
+
+
+
+void FreehandMode::selectPage(QMouseEvent *m)
+{
+ m_MouseButtonPressed = true;
+ FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+ Mxp = mousePointDoc.x(); //static_cast<int>(m->x()/m_canvas->scale());
+ Myp = mousePointDoc.y(); //static_cast<int>(m->y()/m_canvas->scale());
+ QRect mpo(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
+// mpo.moveBy(qRound(Doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
+ m_doc->nodeEdit.deselect();
+ m_view->Deselect(false);
+ if (!m_doc->masterPageMode())
+ {
+ int i = m_doc->OnPage(Mxp, Myp);
+ if (i!=-1)
+ {
+ uint docCurrPageNo=m_doc->currentPageNumber();
+ uint j=static_cast<uint>(i);
+ if (docCurrPageNo != j)
+ {
+ m_doc->setCurrentPage(m_doc->Pages->at(j));
+ m_view->setMenTxt(j);
+ m_view->DrawNew();
+ }
+ }
+/* uint docPagesCount=m_doc->Pages->count();
+ uint docCurrPageNo=m_doc->currentPageNumber();
+ for (uint i = 0; i < docPagesCount; ++i)
+ {
+ int x = static_cast<int>(m_doc->Pages->at(i)->xOffset() * m_canvas->scale());
+ int y = static_cast<int>(m_doc->Pages->at(i)->yOffset() * m_canvas->scale());
+ int w = static_cast<int>(m_doc->Pages->at(i)->width() * m_canvas->scale());
+ int h = static_cast<int>(m_doc->Pages->at(i)->height() * m_canvas->scale());
+ if (QRect(x, y, w, h).intersects(mpo))
+ {
+ if (docCurrPageNo != i)
+ {
+ m_doc->setCurrentPage(m_doc->Pages->at(i));
+ setMenTxt(i);
+ DrawNew();
+ }
+ break;
+ }
+ } */
+
+ //FIXME m_view->setRulerPos(m_view->contentsX(), m_view->contentsY());
+ }
+}
+
+
+
Index: scribus/pageitem_line.cpp
===================================================================
--- scribus/pageitem_line.cpp (revision 13950)
+++ scribus/pageitem_line.cpp (revision 13951)
@@ -78,14 +78,14 @@
}
if (m_startArrowIndex != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(0, 0);
arrowTrans.scale(-1,1);
drawArrow(p, arrowTrans, m_startArrowIndex);
}
if (m_endArrowIndex != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(Width, 0);
drawArrow(p, arrowTrans, m_endArrowIndex);
}
Index: scribus/scpainterex_ps2.h
===================================================================
--- scribus/scpainterex_ps2.h (revision 13950)
+++ scribus/scpainterex_ps2.h (revision 13951)
@@ -1,233 +1,233 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-/* This file is part of the KDE project
- Copyright (C) 2001, 2002, 2003 The Karbon Developers
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-/* Adapted for Scribus 22.08.2003 by Franz Schmid */
-/* Adapted for Scribus 15.01.2006 by Jean Ghali */
-
-#ifndef __SCPAINTEREX_PS2_H__
-#define __SCPAINTEREX_PS2_H__
-
-// libart wrapper
-
-#include <QGlobalStatic>
-#include <QColor>
-#include <QFont>
-#include <QMatrix>
-#include <QList>
-#include <QPixmap>
-#include <QStack>
-#include <QTextStream>
-
-#include "scribusapi.h"
-#include "scconfig.h"
-#include "fpoint.h"
-#include "fpointarray.h"
-#include "vgradient.h"
-
-#include "scpainterexbase.h"
-#include CMS_INC
-
-class ScribusDoc;
-
-class ScPs2OutputParams
-{
-public:
- ScPs2OutputParams(ScribusDoc* doc = NULL);
- ScPainterExBase::ColorMode colorMode;
- ScribusDoc* document;
- bool reloadImages;
- int resolution;
- bool useProfiles;
- bool toGray;
- bool mirrorH;
- bool mirrorV;
- QString outputProfile;
- cmsHPROFILE hProfile;
- cmsHTRANSFORM rgbToOutputColorTransform;
- cmsHTRANSFORM rgbToOutputImageTransform;
- cmsHTRANSFORM cmykToOutputColorTransform;
- cmsHTRANSFORM cmykToOutputImageTransform;
-};
-
-class SCRIBUS_API ScPainterEx_Ps2 : public ScPainterExBase
-{
-public:
-
- ScPainterEx_Ps2( QIODevice* iodev, QRect& rect, ScPs2OutputParams& options );
- virtual ~ScPainterEx_Ps2();
-
- virtual int supportedColorModes() { return (int) (rgbMode|cmykMode); }
- virtual ColorMode preferredColorMode() { return m_colorMode; }
- virtual void setPreferredColorMode(ScPainterEx_Ps2::ColorMode colorMode) { m_colorMode = colorMode; }
- virtual ImageMode imageMode();
-
- virtual void begin();
- virtual void end();
- virtual void clear();
- virtual void clear( ScColorShade & );
-
- // matrix manipulation
- virtual void setWorldMatrix( const QMatrix & );
- virtual const QMatrix worldMatrix();
- virtual void translate( double, double );
- virtual void rotate( double );
- virtual void scale( double, double );
-
- // drawing
- virtual void moveTo( const double &, const double & );
- virtual void lineTo( const double &, const double & );
- virtual void curveTo( FPoint p1, FPoint p2, FPoint p3 );
- virtual void newPath();
- virtual void closePath();
- virtual void fillTextPath();
- virtual void strokeTextPath();
- virtual void fillPath();
- virtual void strokePath();
- virtual void setFillRule( bool fillRule );
- virtual bool fillRule() { return m_fillRule; }
- virtual void setFillMode( int fill );
- virtual int fillMode() { return m_fillMode; }
- virtual void setGradient( VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc = FPoint(0,0));
- virtual void setPattern ( ScPattern* pattern, QMatrix& patternTransform );
- virtual void setClipPath();
-
- virtual void drawImage( ScImage *image, ScPainterExBase::ImageMode mode );
- virtual void drawRGBImage_ps2( ScImage *image );
- virtual void drawCMYKImage_ps2( ScImage *image );
-
- virtual bool hasAlphaChannel( ScImage* image );
-
- virtual void setupPolygon(FPointArray *points, bool closed = true);
- virtual void drawPolygon();
- virtual void drawPolyLine();
- virtual void drawLine(FPoint start, FPoint end);
- virtual void drawRect(double, double, double, double);
-
- // pen + brush
- virtual ScColorShade pen();
- virtual ScColorShade brush();
- virtual void setPen( const ScColorShade & );
- virtual void setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo );
- virtual void setPenOpacity( double op );
- virtual void setLineWidth( double w);
- virtual void setDash(const QVector<double>& array, double ofs);
- virtual void setBrush( const ScColorShade & );
- virtual void setBrushOpacity( double op );
- virtual void setOpacity( double op );
- virtual void setFont( const QFont &f );
- virtual QFont font();
-
- // stack management
- virtual void save();
- virtual void restore();
-
- virtual void setRasterOp( int op );
-
-protected:
-
- virtual void writeRGBImageToStream_Ascii85 ( ScImage* image );
- virtual void writeRGBImageToStream_AsciiHex ( ScImage* image );
- virtual void writeCMYKImageToStream_Ascii85( ScImage* image );
- virtual void writeCMYKImageToStream_AsciiHex( ScImage* image );
- virtual void writeMaskToStream ( QImage* image );
-
-private:
-
- typedef enum {
- Ascii85Encoding,
- AsciiHexEncoding
- } AsciiEncoding;
-
- /* Output stream */
- QTextStream m_stream;
- ColorMode m_colorMode;
- AsciiEncoding m_encoding;
-
- /* Path bounding boxes*/
- QRect m_pathBBox;
- QRect m_clipBBox;
-
- /* General output options */
- ScPs2OutputParams m_options;
-
- /* Basic drawing functions*/
- void drawVPath( int mode );
- void drawGradient( VGradientEx& gradient );
- void drawLinearGradient( VGradientEx& gradient, const QRect& rect );
- void drawLinearGradient_RGB( VGradientEx& gradient, const QRect& rect );
- void drawLinearGradient_CMYK( VGradientEx& gradient, const QRect& rect );
- void drawCircularGradient( VGradientEx& gradient, const QRect& rect );
- void drawCircularGradient_RGB( VGradientEx& gradient, const QRect& rect );
- void drawCircularGradient_CMYK( VGradientEx& gradient, const QRect& rect );
- void getPathBoundingBox( FPointArray* points, QRect& r );
- void transformPoint( const FPoint& in, FPoint& out );
- void transformPoints( const FPoint* in, FPoint* out, uint length );
-
- void putColor( ScColorShade& colorShade, bool doFill );
-
- unsigned int m_width;
- unsigned int m_height;
- unsigned int m_x;
- unsigned int m_y;
- QMatrix m_pageTrans;
- QMatrix m_matrix;
- QFont m_font;
-/* Filling */
- ScColorShade m_fillColor;
- double m_fillTrans;
- bool m_fillRule;
- int m_fillMode; // 0 = none, 1 = solid, 2 = gradient
- int m_gradientMode; // 1 = linear, 2 = radial
-/* Stroking */
- ScColorShade m_strokeColor;
- double m_strokeTrans;
- double m_lineWidth;
-
-/* Line End Style */
- Qt::PenCapStyle m_lineEnd;
-/* Line Join Style */
- Qt::PenJoinStyle m_lineJoin;
-/* The Dash Array */
- QVector<double> m_array;
- double m_offset;
-/* Transformation Stack */
- QStack<QMatrix> m_stack;
-/* Zoom Factor of the Painter */
- double m_zoomFactor;
-
-/* Some data to describe state of drawing */
- bool m_pathIsClosed;
- bool m_drawingClosedPath;
-/* Drawing surface dimensions */
- double m_deviceDimX;
- double m_deviceDimY;
-/* Device resolutions */
- double m_deviceResX;
- double m_deviceResY;
-
-/* Color conversion function */
- void transformImage( QImage* image, uchar* data, int scan);
-};
-
-#endif
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+/* This file is part of the KDE project
+ Copyright (C) 2001, 2002, 2003 The Karbon Developers
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/* Adapted for Scribus 22.08.2003 by Franz Schmid */
+/* Adapted for Scribus 15.01.2006 by Jean Ghali */
+
+#ifndef __SCPAINTEREX_PS2_H__
+#define __SCPAINTEREX_PS2_H__
+
+// libart wrapper
+
+#include <QGlobalStatic>
+#include <QColor>
+#include <QFont>
+#include <QTransform>
+#include <QList>
+#include <QPixmap>
+#include <QStack>
+#include <QTextStream>
+
+#include "scribusapi.h"
+#include "scconfig.h"
+#include "fpoint.h"
+#include "fpointarray.h"
+#include "vgradient.h"
+
+#include "scpainterexbase.h"
+#include CMS_INC
+
+class ScribusDoc;
+
+class ScPs2OutputParams
+{
+public:
+ ScPs2OutputParams(ScribusDoc* doc = NULL);
+ ScPainterExBase::ColorMode colorMode;
+ ScribusDoc* document;
+ bool reloadImages;
+ int resolution;
+ bool useProfiles;
+ bool toGray;
+ bool mirrorH;
+ bool mirrorV;
+ QString outputProfile;
+ cmsHPROFILE hProfile;
+ cmsHTRANSFORM rgbToOutputColorTransform;
+ cmsHTRANSFORM rgbToOutputImageTransform;
+ cmsHTRANSFORM cmykToOutputColorTransform;
+ cmsHTRANSFORM cmykToOutputImageTransform;
+};
+
+class SCRIBUS_API ScPainterEx_Ps2 : public ScPainterExBase
+{
+public:
+
+ ScPainterEx_Ps2( QIODevice* iodev, QRect& rect, ScPs2OutputParams& options );
+ virtual ~ScPainterEx_Ps2();
+
+ virtual int supportedColorModes() { return (int) (rgbMode|cmykMode); }
+ virtual ColorMode preferredColorMode() { return m_colorMode; }
+ virtual void setPreferredColorMode(ScPainterEx_Ps2::ColorMode colorMode) { m_colorMode = colorMode; }
+ virtual ImageMode imageMode();
+
+ virtual void begin();
+ virtual void end();
+ virtual void clear();
+ virtual void clear( ScColorShade & );
+
+ // matrix manipulation
+ virtual void setWorldMatrix( const QTransform & );
+ virtual const QTransform worldMatrix();
+ virtual void translate( double, double );
+ virtual void rotate( double );
+ virtual void scale( double, double );
+
+ // drawing
+ virtual void moveTo( const double &, const double & );
+ virtual void lineTo( const double &, const double & );
+ virtual void curveTo( FPoint p1, FPoint p2, FPoint p3 );
+ virtual void newPath();
+ virtual void closePath();
+ virtual void fillTextPath();
+ virtual void strokeTextPath();
+ virtual void fillPath();
+ virtual void strokePath();
+ virtual void setFillRule( bool fillRule );
+ virtual bool fillRule() { return m_fillRule; }
+ virtual void setFillMode( int fill );
+ virtual int fillMode() { return m_fillMode; }
+ virtual void setGradient( VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc = FPoint(0,0));
+ virtual void setPattern ( ScPattern* pattern, QTransform& patternTransform );
+ virtual void setClipPath();
+
+ virtual void drawImage( ScImage *image, ScPainterExBase::ImageMode mode );
+ virtual void drawRGBImage_ps2( ScImage *image );
+ virtual void drawCMYKImage_ps2( ScImage *image );
+
+ virtual bool hasAlphaChannel( ScImage* image );
+
+ virtual void setupPolygon(FPointArray *points, bool closed = true);
+ virtual void drawPolygon();
+ virtual void drawPolyLine();
+ virtual void drawLine(FPoint start, FPoint end);
+ virtual void drawRect(double, double, double, double);
+
+ // pen + brush
+ virtual ScColorShade pen();
+ virtual ScColorShade brush();
+ virtual void setPen( const ScColorShade & );
+ virtual void setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo );
+ virtual void setPenOpacity( double op );
+ virtual void setLineWidth( double w);
+ virtual void setDash(const QVector<double>& array, double ofs);
+ virtual void setBrush( const ScColorShade & );
+ virtual void setBrushOpacity( double op );
+ virtual void setOpacity( double op );
+ virtual void setFont( const QFont &f );
+ virtual QFont font();
+
+ // stack management
+ virtual void save();
+ virtual void restore();
+
+ virtual void setRasterOp( int op );
+
+protected:
+
+ virtual void writeRGBImageToStream_Ascii85 ( ScImage* image );
+ virtual void writeRGBImageToStream_AsciiHex ( ScImage* image );
+ virtual void writeCMYKImageToStream_Ascii85( ScImage* image );
+ virtual void writeCMYKImageToStream_AsciiHex( ScImage* image );
+ virtual void writeMaskToStream ( QImage* image );
+
+private:
+
+ typedef enum {
+ Ascii85Encoding,
+ AsciiHexEncoding
+ } AsciiEncoding;
+
+ /* Output stream */
+ QTextStream m_stream;
+ ColorMode m_colorMode;
+ AsciiEncoding m_encoding;
+
+ /* Path bounding boxes*/
+ QRect m_pathBBox;
+ QRect m_clipBBox;
+
+ /* General output options */
+ ScPs2OutputParams m_options;
+
+ /* Basic drawing functions*/
+ void drawVPath( int mode );
+ void drawGradient( VGradientEx& gradient );
+ void drawLinearGradient( VGradientEx& gradient, const QRect& rect );
+ void drawLinearGradient_RGB( VGradientEx& gradient, const QRect& rect );
+ void drawLinearGradient_CMYK( VGradientEx& gradient, const QRect& rect );
+ void drawCircularGradient( VGradientEx& gradient, const QRect& rect );
+ void drawCircularGradient_RGB( VGradientEx& gradient, const QRect& rect );
+ void drawCircularGradient_CMYK( VGradientEx& gradient, const QRect& rect );
+ void getPathBoundingBox( FPointArray* points, QRect& r );
+ void transformPoint( const FPoint& in, FPoint& out );
+ void transformPoints( const FPoint* in, FPoint* out, uint length );
+
+ void putColor( ScColorShade& colorShade, bool doFill );
+
+ unsigned int m_width;
+ unsigned int m_height;
+ unsigned int m_x;
+ unsigned int m_y;
+ QTransform m_pageTrans;
+ QTransform m_matrix;
+ QFont m_font;
+/* Filling */
+ ScColorShade m_fillColor;
+ double m_fillTrans;
+ bool m_fillRule;
+ int m_fillMode; // 0 = none, 1 = solid, 2 = gradient
+ int m_gradientMode; // 1 = linear, 2 = radial
+/* Stroking */
+ ScColorShade m_strokeColor;
+ double m_strokeTrans;
+ double m_lineWidth;
+
+/* Line End Style */
+ Qt::PenCapStyle m_lineEnd;
+/* Line Join Style */
+ Qt::PenJoinStyle m_lineJoin;
+/* The Dash Array */
+ QVector<double> m_array;
+ double m_offset;
+/* Transformation Stack */
+ QStack<QTransform> m_stack;
+/* Zoom Factor of the Painter */
+ double m_zoomFactor;
+
+/* Some data to describe state of drawing */
+ bool m_pathIsClosed;
+ bool m_drawingClosedPath;
+/* Drawing surface dimensions */
+ double m_deviceDimX;
+ double m_deviceDimY;
+/* Device resolutions */
+ double m_deviceResX;
+ double m_deviceResY;
+
+/* Color conversion function */
+ void transformImage( QImage* image, uchar* data, int scan);
+};
+
+#endif
Index: scribus/canvasmode_legacy.cpp
===================================================================
--- scribus/canvasmode_legacy.cpp (revision 13950)
+++ scribus/canvasmode_legacy.cpp (revision 13951)
@@ -649,12 +649,12 @@
newX = qRound(newX / m_doc->guidesSettings.minorGridSpacing) * m_doc->guidesSettings.minorGridSpacing;
newY = qRound(newY / m_doc->guidesSettings.minorGridSpacing) * m_doc->guidesSettings.minorGridSpacing;
}
- QMatrix mp = currItem->getTransform();
+ QTransform mp = currItem->getTransform();
// mp.translate(currItem->xPos(),// - m_doc->minCanvasCoordinate.x(),
// currItem->yPos()); // - m_doc->minCanvasCoordinate.y());
// mp.rotate(currItem->rotation());
np2 = QPoint(static_cast<int>(newX), static_cast<int>(newY)) * mp.inverted();
- QMatrix pm;
+ QTransform pm;
m_canvas->Transform(currItem, pm);
m_canvas->PaintSizeRect(pm.mapToPolygon(QRect(QPoint(0, 0), np2)));
// emit ItemGeom(newX - currItem->xPos(), newY - currItem->yPos());
@@ -695,7 +695,7 @@
{
if (currItem->asImageFrame())
{
- QMatrix ro;
+ QTransform ro;
ro.rotate(-currItem->rotation());
QPointF rota = ro.map(QPointF(newX-Mxp,newY-Myp));
currItem->moveImageInFrame(rota.x()/currItem->imageXScale(), rota.y()/currItem->imageYScale());
@@ -760,7 +760,7 @@
double ny = np2.y();
m_doc->ApplyGuides(&nx, &ny);
np2 = FPoint(qRound(nx*sc), qRound(ny*sc));
- QMatrix pm;
+ QTransform pm;
switch (frameResizeHandle)
{
case 1:
@@ -809,7 +809,7 @@
double nh = currItem->height();
if ((frameResizeHandle == 1) || (frameResizeHandle == 2))
{
- QMatrix mp;
+ QTransform mp;
switch (frameResizeHandle)
{
case 1:
@@ -818,7 +818,7 @@
//Shift proportional square resize
if ((m->modifiers() & Qt::ShiftModifier) && (!(m->modifiers() & Qt::ControlModifier)))
{
- QMatrix ma;
+ QTransform ma;
ma.translate(currItem->xPos(), currItem->yPos());
ma.rotate(currItem->rotation());
ma = ma.inverted();
@@ -830,7 +830,7 @@
//Control proportional resize
if ((m->modifiers() & Qt::ControlModifier) && (!(m->modifiers() & Qt::ShiftModifier)))
{
- QMatrix ma;
+ QTransform ma;
ma.translate(currItem->xPos(), currItem->yPos());
ma.rotate(currItem->rotation());
ma = ma.inverted();
@@ -866,12 +866,12 @@
erf = m_doc->SizeItem(nx, nh, currItem->ItemNr);
else
erf = m_doc->SizeItem(nx, ny, currItem->ItemNr);
- QMatrix mp;
+ QTransform mp;
mp.translate(currItem->xPos(),// - m_doc->minCanvasCoordinate.x(),
currItem->yPos());// - m_doc->minCanvasCoordinate.y());
mp.rotate(currItem->rotation());
np2 = QPoint(qRound(nx), qRound(ny));
- QMatrix pm;
+ QTransform pm;
m_canvas->Transform(currItem, pm);
m_canvas->PaintSizeRect(pm.mapToPolygon(QRect(QPoint(0, 0), np2)));
}
@@ -879,7 +879,7 @@
{
double rba = currItem->rotation();
currItem->setRotation(0.0);
- QMatrix mp;
+ QTransform mp;
m_canvas->Transform(currItem, mp);
// mp.translate(-m_doc->minCanvasCoordinate.x(), -m_doc->minCanvasCoordinate.y());
np = QPoint(m->x(), m->y()) * mp.inverted();
@@ -896,7 +896,7 @@
currItem->setRotation(rba);
np = m_doc->ApplyGrid(np);
erf = m_doc->SizeItem(sizeItemX, sizeItemY, currItem->ItemNr);
- QMatrix pm;
+ QTransform pm;
// pm.translate(-m_doc->minCanvasCoordinate.x() * m_canvas->scale(),-m_doc->minCanvasCoordinate.y() * m_canvas->scale());
m_canvas->Transform(currItem, pm);
m_canvas->newRedrawPolygon() << pm.map(QPoint(0, 0)) << pm.map(QPoint(qRound(currItem->width()), qRound(currItem->height())));
@@ -913,7 +913,7 @@
m_doc->SnapGuides = sav;
if (sav)
currItem->Sizing = true;
- QMatrix pm;
+ QTransform pm;
// pm.translate(-m_doc->minCanvasCoordinate.x() * m_canvas->scale(),-m_doc->minCanvasCoordinate.y() * m_canvas->scale());
m_canvas->Transform(currItem, pm);
m_canvas->newRedrawPolygon() << pm.map(QPoint(0, 0)) << pm.map(QPoint(qRound(currItem->width()), qRound(currItem->height())));
@@ -928,11 +928,11 @@
double nx = newP.x();
double ny = newP.y();
m_doc->ApplyGuides(&nx, &ny);
- QMatrix mp;
+ QTransform mp;
// mp.translate(currItem->xPos() - m_doc->minCanvasCoordinate.x(), currItem->yPos() - m_doc->minCanvasCoordinate.y());
mp.rotate(currItem->rotation());
np2 = QPoint(qRound(nx), qRound(ny)) * mp.inverted();
- QMatrix pm;
+ QTransform pm;
m_canvas->Transform(currItem, pm);
m_canvas->PaintSizeRect(pm.mapToPolygon(QRect(np2, QPoint(qRound(currItem->width()), qRound(currItem->height())))));
// p.end();
@@ -947,11 +947,11 @@
double nx = newP.x();
double ny = newP.y();
m_doc->ApplyGuides(&nx, &ny);
- QMatrix mp;
+ QTransform mp;
// mp.translate(currItem->xPos() - m_doc->minCanvasCoordinate.x(), currItem->yPos() - m_doc->minCanvasCoordinate.y());
mp.rotate(currItem->rotation());
np2 = QPoint(qRound(nx), qRound(ny)) * mp.inverted();
- QMatrix pm;
+ QTransform pm;
m_canvas->Transform(currItem, pm);
switch (frameResizeHandle)
{
@@ -1227,7 +1227,7 @@
currItem = m_doc->m_Selection->itemAt(a);
if (currItem->locked())
break;
- QMatrix p;
+ QTransform p;
m_canvas->Transform(currItem, p);
QRect mpo = QRect(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
// mpo.moveBy(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
@@ -1328,7 +1328,7 @@
m_canvas->PaintSizeRect(QRect());
FPoint npf, npf2;
QRect tx;
- QMatrix pm;
+ QTransform pm;
m_canvas->m_viewMode.m_MouseButtonPressed = true;
m_canvas->m_viewMode.operItemMoving = false;
m_view->HaveSelRect = false;
@@ -1898,7 +1898,7 @@
}
else
{
- QMatrix mat;
+ QTransform mat;
m_canvas->Transform(currItem, mat);
m_doc->RotMode ( 2);
// RCenter = FPoint(currItem->xPos()+currItem->width()/2, currItem->yPos()+currItem->height()/2, 0, 0, currItem->rotation(), 1, 1, true);
@@ -2385,7 +2385,7 @@
for (int a = 0; a < docItemCount; ++a)
{
PageItem* docItem = m_doc->Items->at(a);
- QMatrix p;
+ QTransform p;
m_canvas->Transform(docItem, p);
QRegion apr = QRegion(docItem->Clip * p);
QRect apr2(docItem->getRedrawBounding(1.0));
@@ -2781,7 +2781,7 @@
double itemY = 0.0;
if (m_doc->appMode == modeDrawLine)
{
- QMatrix p;
+ QTransform p;
m_canvas->Transform(currItem, p);
QPoint np = m->pos() * p.inverted();
np = m_doc->ApplyGrid(np);
@@ -2974,7 +2974,7 @@
if ((m_doc->appMode == modeDrawLine) && (inItemCreation))
{
currItem = m_doc->m_Selection->itemAt(0);
- QMatrix p;
+ QTransform p;
m_canvas->Transform(currItem, p);
QPoint np = m->pos() * p.inverted();
np = m_doc->ApplyGrid(np);
@@ -3356,7 +3356,7 @@
m_doc->SnapGuides = sav;
m_doc->ApplyGuides(&nx, &ny);
m_doc->SnapGuides = false;
- QMatrix ma;
+ QTransform ma;
ma.translate(currItem->xPos(), currItem->yPos());
ma.rotate(currItem->rotation());
double mx = ma.m11() * currItem->width() + ma.m21() * currItem->height() + ma.dx();
@@ -3924,7 +3924,7 @@
for (int a = 0; a < docItemCount; ++a)
{
PageItem* docItem = m_doc->Items->at(a);
- QMatrix p;
+ QTransform p;
m_canvas->Transform(docItem, p);
QRegion apr = QRegion(docItem->Clip * p);
QRect apr2(docItem->getRedrawBounding(1.0));
@@ -4085,7 +4085,7 @@
currItem = m_doc->m_Selection->itemAt(0);
currItem->ClipEdited = true;
currItem->FrameType = 3;
- QMatrix pm;
+ QTransform pm;
// pm.translate(-m_doc->minCanvasCoordinate.x()*m_canvas->scale(), -m_doc->minCanvasCoordinate.y()*m_canvas->scale());
m_canvas->Transform(currItem, pm);
FPoint npf = FPoint(m->pos() * pm.inverted());
@@ -4263,7 +4263,7 @@
const unsigned SELECT_IN_GROUP = Qt::AltModifier;
const unsigned SELECT_MULTIPLE = Qt::ShiftModifier;
const unsigned SELECT_BENEATH = Qt::ControlModifier;
- QMatrix p;
+ QTransform p;
QRectF tx, mpo;
PageItem *currItem;
m_canvas->m_viewMode.m_MouseButtonPressed = true;
@@ -4485,7 +4485,7 @@
int currNr = m_doc->currentPage()->FromMaster.count()-1;
for (a = 0; a < m_doc->currentPage()->FromMaster.count(); ++a)
{
- p = QMatrix();
+ p = QTransform();
if ((currItem->LayerID == m_doc->activeLayer()) && (!m_doc->layerLocked(currItem->LayerID)))
{
double OldX = currItem->xPos();
@@ -4640,7 +4640,7 @@
continue;
if ((currItem->LayerID == m_doc->activeLayer()) && (!m_doc->layerLocked(currItem->LayerID)))
{
- p = QMatrix();
+ p = QTransform();
m_canvas->Transform(currItem, p);
if ((QRegion(p.map(QPolygon(QRect(0, 0, static_cast<int>(currItem->width()), static_cast<int>(currItem->height()))))).contains(mpo.toRect())) ||
(QRegion(currItem->Clip * p).contains(mpo.toRect())))
Index: scribus/pdflib_core.h
===================================================================
--- scribus/pdflib_core.h (revision 13950)
+++ scribus/pdflib_core.h (revision 13951)
@@ -149,7 +149,7 @@
bool PDF_ProcessItem(QString& output, PageItem* ite, const Page* pag, uint PNr, bool embedded = false, bool pattern = false);
QString PDF_ProcessTableItem(PageItem* ite, const Page* pag);
- QString drawArrow(PageItem *ite, QMatrix &arrowTrans, int arrowIndex);
+ QString drawArrow(PageItem *ite, QTransform &arrowTrans, int arrowIndex);
void PDF_Bookmark(PageItem *currItem, double ypos);
bool PDF_Gradient(QString& output, PageItem *currItem);
QString PDF_DoLinGradient(PageItem *currItem, QList<double> Stops, QList<double> Trans, const QStringList& Colors, QStringList colorNames, QList<int> colorShades);
Index: scribus/scprintengine_gdi.cpp
===================================================================
--- scribus/scprintengine_gdi.cpp (revision 13950)
+++ scribus/scprintengine_gdi.cpp (revision 13951)
@@ -193,7 +193,7 @@
dy *= scale;
// Set the world transformation matrix
- QMatrix matrix( scalex, 0.0, 0.0, scaley, dx, dy );
+ QTransform matrix( scalex, 0.0, 0.0, scaley, dx, dy );
painter.setWorldMatrix( matrix );
image->fill( qRgba(255, 255, 255, 255) );
@@ -410,7 +410,7 @@
scaley *= ( logPixelsY / 72.0 );
dx *= ( logPixelsX / 72.0 );
dy *= ( logPixelsY / 72.0 );
- QMatrix matrix( scalex, 0.0, 0.0, scaley, dx, dy );
+ QTransform matrix( scalex, 0.0, 0.0, scaley, dx, dy );
painter.setWorldMatrix( matrix );
pageOutput.drawPage(page, &painter);
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp (revision 13950)
+++ scribus/scribusdoc.cpp (revision 13951)
@@ -4516,7 +4516,7 @@
newItem->ClipEdited = true;
if(oldItem->itemType()==PageItem::Line)
{
- QMatrix ma;
+ QTransform ma;
newItem->Frame = false;
newItem->FrameType = 3;
ma.rotate(newItem->rotation());
@@ -6303,7 +6303,7 @@
void ScribusDoc::MirrorPolyH(PageItem* currItem)
{
currItem->ClipEdited = true;
- QMatrix ma;
+ QTransform ma;
if (nodeEdit.isContourLine)
{
if (UndoManager::undoEnabled())
@@ -6352,7 +6352,7 @@
void ScribusDoc::MirrorPolyV(PageItem* currItem)
{
currItem->ClipEdited = true;
- QMatrix ma;
+ QTransform ma;
if (nodeEdit.isContourLine)
{
if (UndoManager::undoEnabled())
@@ -7651,7 +7651,7 @@
if (currItem->imageClip.size() != 0)
{
currItem->imageClip = currItem->pixm.imgInfo.PDSpathData[currItem->pixm.imgInfo.usedPath].copy();
- QMatrix cl;
+ QTransform cl;
cl.translate(currItem->imageXOffset()*currItem->imageXScale(), currItem->imageYOffset()*currItem->imageYScale());
cl.scale(currItem->imageXScale(), currItem->imageYScale());
currItem->imageClip.map(cl);
@@ -7697,7 +7697,7 @@
if (currItem->imageClip.size() != 0)
{
currItem->imageClip = currItem->pixm.imgInfo.PDSpathData[currItem->pixm.imgInfo.usedPath].copy();
- QMatrix cl;
+ QTransform cl;
cl.translate(currItem->imageXOffset()*currItem->imageXScale(), currItem->imageYOffset()*currItem->imageYScale());
cl.scale(currItem->imageXScale(), currItem->imageYScale());
currItem->imageClip.map(cl);
@@ -7747,7 +7747,7 @@
if (currItem->imageClip.size() != 0)
{
currItem->imageClip = currItem->pixm.imgInfo.PDSpathData[currItem->pixm.imgInfo.usedPath].copy();
- QMatrix cl;
+ QTransform cl;
cl.translate(currItem->imageXOffset()*currItem->imageXScale(), currItem->imageYOffset()*currItem->imageYScale());
cl.scale(currItem->imageXScale(), currItem->imageYScale());
currItem->imageClip.map(cl);
@@ -9472,7 +9472,7 @@
currItem->setYPos(yout+page->yOffset());
if (currItem->asLine())
{
- QMatrix ma;
+ QTransform ma;
ma.translate(currItem->xPos(), currItem->yPos());
ma.rotate(currItem->rotation());
// double my = ma.m22() * currItem->height() + ma.m12() * currItem->width() + ma.dy();
@@ -9492,7 +9492,7 @@
currItem->setXPos(xout+page->xOffset());
if (currItem->asLine())
{
- QMatrix ma;
+ QTransform ma;
ma.translate(currItem->xPos(), currItem->yPos());
ma.rotate(currItem->rotation());
double mx = ma.m11() * currItem->width() + ma.dx();
@@ -9622,7 +9622,7 @@
// if ((Doc->RotMode != 0) && (m_MouseButtonPressed))
if (rotMode != 0)
{
- QMatrix ma;
+ QTransform ma;
ma.translate(currItem->xPos(), currItem->yPos());
ma.scale(1, 1);
ma.rotate(currItem->rotation());
@@ -9673,7 +9673,7 @@
void ScribusDoc::MoveRotated(PageItem *currItem, FPoint npv, bool fromMP)
{
- QMatrix ma;
+ QTransform ma;
ma.translate(currItem->xPos(), currItem->yPos());
ma.rotate(currItem->rotation());
double mxc = currItem->xPos() - (ma.m11() * npv.x() + ma.m21() * npv.y() + ma.dx());
@@ -9705,7 +9705,7 @@
}
*/
int ph = static_cast<int>(qMax(1.0, currItem->lineWidth() / 2.0));
- QMatrix ma;
+ QTransform ma;
ma.rotate(currItem->rotation());
double dX = ma.m11() * (currItem->width() - newX) + ma.m21() * (currItem->height() - newY) + ma.dx();
double dY = ma.m22() * (currItem->height() - newY) + ma.m12() * (currItem->width() - newX) + ma.dy();
@@ -9847,7 +9847,7 @@
QRectF oldR(currItem->getBoundingRect());
if (currItem->asLine())
{
- QMatrix ma;
+ QTransform ma;
ma.translate(currItem->xPos(), currItem->yPos());
ma.rotate(currItem->rotation());
double mx = ma.m11() * currItem->width() + ma.dx();
@@ -9876,7 +9876,7 @@
if (currItem->rotation() != 0)
{
FPoint npv(newX.x(), newX.y());
- QMatrix ma3;
+ QTransform ma3;
ma3.translate(currItem->xPos(), currItem->yPos());
ma3.rotate(currItem->rotation());
double mxc3 = currItem->xPos() - (ma3.m11() * npv.x() + ma3.m21() * npv.y() + ma3.dx());
@@ -9981,7 +9981,7 @@
double sc = 1; // FIXME:av Scale;
PageItem* currItem;
m_Selection->getGroupRect(&gxS, &gyS, &gwS, &ghS);
- QMatrix ma;
+ QTransform ma;
ma.translate(RCenter.x(), RCenter.y());
ma.scale(1, 1);
ma.rotate(angle);
@@ -10067,17 +10067,17 @@
else
{
FPoint oldPos(bb->xPos(), bb->yPos());
- QMatrix ma;
+ QTransform ma;
ma.rotate(bb->rotation());
bb->PoLine.map(ma);
- QMatrix ma2;
+ QTransform ma2;
ma2.translate(gx-bb->xPos(), gy-bb->yPos());
ma2.scale(scx, scy);
bb->PoLine.map(ma2);
bb->setRotation(0.0);
bb->ClipEdited = true;
AdjustItemSize(bb);
- QMatrix ma3;
+ QTransform ma3;
ma3.translate(gx, gy);
ma3.scale(scx, scy);
FPoint n(gx-oldPos.x(), gy-oldPos.y());
@@ -10087,7 +10087,7 @@
if (oldRot != 0)
{
bb->setRotation(atan2(t1.y()-b1.y(),t1.x()-b1.x())*(180.0/M_PI));
- QMatrix ma;
+ QTransform ma;
ma.rotate(-bb->rotation());
bb->PoLine.map(ma);
AdjustItemSize(bb);
@@ -10110,7 +10110,7 @@
bb->setImageXYOffset(oldLocalX, oldLocalY);
bb->OldB2 = bb->width();
bb->OldH2 = bb->height();
- QMatrix ma4;
+ QTransform ma4;
ma4.rotate(oldRot);
ma4.scale(scx, scy);
gr.map(ma4);
@@ -10413,11 +10413,11 @@
{
bb = m_Selection->itemAt(a);
toDel.append(bb->ItemNr);
- QMatrix ma;
+ QTransform ma;
ma.translate(bb->xPos(), bb->yPos());
ma.rotate(bb->rotation());
bb->PoLine.map(ma);
- QMatrix ma2;
+ QTransform ma2;
ma2.translate(currItem->xPos(), currItem->yPos());
ma2.rotate(currItem->rotation());
ma2 = ma2.inverted();
Index: scribus/scpainterex_cairo.cpp
===================================================================
--- scribus/scpainterex_cairo.cpp (revision 13950)
+++ scribus/scpainterex_cairo.cpp (revision 13951)
@@ -1,511 +1,511 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-#include <cmath>
-#include "scpainterex_cairo.h"
-#include "sccolorengine.h"
-#include "util.h"
-
-ScPainterEx_Cairo::ScPainterEx_Cairo( cairo_t* context, QRect& rect, ScribusDoc* doc, bool gray ) : ScPainterExBase()
-{
- m_doc = doc;
- m_width = rect.width();
- m_height = rect.height();
- m_strokeColor = ScColorShade( QColor(0,0,0), 100 );
- m_fillColor = ScColorShade( QColor(0,0,0), 100 );
- m_fillTrans = 1.0;
- m_strokeTrans = 1.0;
- m_fillRule = true;
- m_fillMode = 1;
- m_lineWidth = 1.0;
- m_offset = 0;
- m_lineEnd = Qt::SquareCap;
- m_lineJoin = Qt::RoundJoin;
- m_fillGradient = VGradientEx(VGradientEx::linear);
- m_strokeGradient = VGradientEx(VGradientEx::linear);
- // Grayscale conversion parameter
- m_convertToGray = gray;
- // Initialization of Windows GDI data
- m_cr = context;
- m_positionX = m_positionY = 0;
- clear();
-}
-
-ScPainterEx_Cairo::~ScPainterEx_Cairo()
-{
-
-}
-
-QColor ScPainterEx_Cairo::transformColor( ScColorShade& colorShade, double trans )
-{
- QColor c, color;
- c = ScColorEngine::getShadeColor(colorShade.color, m_doc, colorShade.shade);
- color = qRgba( qRed(c.rgb()), qGreen(c.rgb()), qBlue(c.rgb()), qAlpha(trans * 255));
- if ( m_convertToGray )
- {
- int grayLevel;
- QColor grayColor;
- grayLevel = 0.3 * color.red() + 0.59 * color.green() + 0.11 * color.blue();
- grayColor = qRgba( grayLevel, grayLevel, grayLevel, qAlpha(color.rgb()));
- color = grayColor;
- }
- return color;
-}
-
-void ScPainterEx_Cairo::transformImage(QImage& image)
-{
- int rgb, grey;
- int imageWidth = image.width();
- int imageHeight = image.height();
- QRgb *pscan;
-
- for ( int j = 0; j < imageHeight; j++ )
- {
- pscan = (QRgb *) image.scanLine(j);
- for (int i = 0; i < imageWidth; i++ )
- {
- rgb = pscan[i];
- grey = 0.3 * qRed(rgb) + 0.59 * qGreen(rgb) + 0.11 * qBlue(rgb);
- pscan[i] = qRgba(grey, grey, grey, qAlpha(rgb));
- }
- }
-}
-
-void ScPainterEx_Cairo::begin()
-{
-}
-
-void ScPainterEx_Cairo::end()
-{
-}
-
-void ScPainterEx_Cairo::clear()
-{
- /*SolidBrush brush( Color(255,255,255) );
- m_graphics->FillRectangle(&brush, 0, 0, m_width, m_height);*/
-}
-
-void ScPainterEx_Cairo::clear( ScColorShade &c )
-{
- /*QColor color = transformColor( c, 1.0 );
- QRgb cs = color.rgb();
- SolidBrush brush( Color(qAlpha(cs), qRed(cs), qGreen(cs),qBlue(cs)) );
- m_graphics->FillRectangle(&brush, 0, 0, m_width, m_height);*/
-}
-
-const QMatrix ScPainterEx_Cairo::worldMatrix()
-{
- cairo_matrix_t matrix;
- cairo_get_matrix(m_cr, &matrix);
- QMatrix mat(matrix.xx, matrix.yx, matrix.xy, matrix.yy, matrix.x0, matrix.y0);
- return mat;
-}
-
-void ScPainterEx_Cairo::setWorldMatrix( const QMatrix &mat )
-{
- cairo_matrix_t matrix;
- cairo_matrix_init(&matrix, mat.m11(), mat.m12(), mat.m21(), mat.m22(), mat.dx(), mat.dy());
- cairo_set_matrix(m_cr, &matrix);
-}
-
-void ScPainterEx_Cairo::translate( double x, double y )
-{
- cairo_translate(m_cr, x, y);
-}
-
-void ScPainterEx_Cairo::rotate( double r )
-{
- cairo_rotate(m_cr, r * 3.1415927 / 180.0);
-}
-
-void ScPainterEx_Cairo::scale( double x, double y )
-{
- cairo_scale(m_cr, x, y);
-}
-
-void ScPainterEx_Cairo::moveTo( const double &x, const double &y )
-{
- cairo_move_to(m_cr, x, y);
-}
-
-void ScPainterEx_Cairo::lineTo( const double &x, const double &y )
-{
- cairo_line_to(m_cr, x, y);
-}
-
-void ScPainterEx_Cairo::curveTo( FPoint p1, FPoint p2, FPoint p3 )
-{
- cairo_curve_to(m_cr, p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y() );
-}
-
-void ScPainterEx_Cairo::newPath()
-{
- cairo_new_path( m_cr );
-}
-
-void ScPainterEx_Cairo::closePath()
-{
- cairo_close_path( m_cr);
-}
-
-void ScPainterEx_Cairo::setFillRule( bool fillRule )
-{
- m_fillRule = fillRule;
-}
-
-void ScPainterEx_Cairo::setFillMode( int fill )
-{
- m_fillMode = fill;
-}
-
-void ScPainterEx_Cairo::setGradient(VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc)
-{
- m_fillGradient.setType(mode);
- m_fillGradient.setOrigin(orig);
- m_fillGradient.setVector(vec);
- m_fillGradient.setFocalPoint(foc);
-}
-
-void ScPainterEx_Cairo::setPattern( ScPattern* pattern, QMatrix& patternTransform )
-{
- m_pattern = pattern;
- m_patternTransform = patternTransform;
-}
-
-void ScPainterEx_Cairo::fillTextPath()
-{
- drawVPath( 0 );
-}
-
-void ScPainterEx_Cairo::strokeTextPath()
-{
- if( m_lineWidth == 0 )
- return;
- drawVPath( 1 );
-}
-
-void ScPainterEx_Cairo::fillPath()
-{
- if( m_fillMode != 0)
- drawVPath( 0 );
-}
-
-void ScPainterEx_Cairo::strokePath()
-{
- if( m_lineWidth == 0 )
- return;
- drawVPath( 1 );
-}
-
-ScColorShade ScPainterEx_Cairo::pen()
-{
- return m_strokeColor;
-}
-
-ScColorShade ScPainterEx_Cairo::brush()
-{
- return m_fillColor;
-}
-
-void ScPainterEx_Cairo::setPen( const ScColorShade &c )
-{
- m_strokeColor = c;
-}
-
-void ScPainterEx_Cairo::setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo )
-{
- m_strokeColor = c;
- m_lineWidth = w;
- m_lineEnd = ca;
- m_lineJoin = jo;
- m_array.clear();
- m_offset = 0;
- getDashArray(st, w, m_array);
-}
-
-void ScPainterEx_Cairo::setLineWidth( double w )
-{
- m_lineWidth = w;
-}
-
-void ScPainterEx_Cairo::setPenOpacity( double op )
-{
- m_strokeTrans = op;
-}
-
-void ScPainterEx_Cairo::setDash(const QVector<double>& array, double ofs)
-{
- m_array = array;
- m_offset = ofs;
-}
-
-void ScPainterEx_Cairo::setBrush( const ScColorShade &c )
-{
- m_fillColor = c;
-}
-
-void ScPainterEx_Cairo::setBrushOpacity( double op )
-{
- m_fillTrans = op;
-}
-
-void ScPainterEx_Cairo::setOpacity( double op )
-{
- m_fillTrans = op;
- m_strokeTrans = op;
-}
-
-void ScPainterEx_Cairo::setFont( const QFont &f)
-{
- m_font = f;
-}
-
-QFont ScPainterEx_Cairo::font()
-{
- return m_font;
-}
-
-void ScPainterEx_Cairo::save()
-{
- cairo_save(m_cr);
-}
-
-void ScPainterEx_Cairo::restore()
-{
- cairo_restore( m_cr );
-}
-
-void ScPainterEx_Cairo::setRasterOp( int )
-{
-}
-
-void ScPainterEx_Cairo::drawVPath( int mode )
-{
- cairo_save( m_cr );
- if (mode == 0)
- {
- if( m_fillRule )
- cairo_set_fill_rule (m_cr, CAIRO_FILL_RULE_EVEN_ODD);
- else
- cairo_set_fill_rule (m_cr, CAIRO_FILL_RULE_WINDING);
- if (m_fillMode == ScPainterExBase::Gradient)
- {
- drawGradient( m_fillGradient );
- }
- else
- {
- double r, g, b;
- QColor fillColor = transformColor(m_fillColor, 1.0);
- fillColor.getRgbF(&r, &g, &b);
- cairo_set_source_rgba( m_cr, r, g, b, m_fillTrans );
- if (m_fillTrans != 1.0)
- cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
- else
- cairo_set_operator(m_cr, CAIRO_OPERATOR_SOURCE);
- cairo_fill_preserve( m_cr );
- }
- }
- else
- {
- double r, g, b;
- QColor strokeColor = transformColor( m_strokeColor, 1.0 );
- strokeColor.getRgbF(&r, &g, &b);
- cairo_set_source_rgba( m_cr, r, g, b, m_strokeTrans );
-
- cairo_set_line_width( m_cr, m_lineWidth );
- if( m_array.count() > 0 )
- cairo_set_dash( m_cr, m_array.data(), m_array.count(), static_cast<double>(m_offset));
- else
- cairo_set_dash( m_cr, NULL, 0, 0 );
- if (m_strokeTrans != 1.0)
- cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
- else
- cairo_set_operator(m_cr, CAIRO_OPERATOR_SOURCE);
- if( m_lineEnd == Qt::RoundCap )
- cairo_set_line_cap (m_cr, CAIRO_LINE_CAP_ROUND);
- else if( m_lineEnd == Qt::SquareCap )
- cairo_set_line_cap (m_cr, CAIRO_LINE_CAP_SQUARE);
- else if( m_lineEnd == Qt::FlatCap )
- cairo_set_line_cap (m_cr, CAIRO_LINE_CAP_BUTT);
- if( m_lineJoin == Qt::RoundJoin )
- cairo_set_line_join( m_cr, CAIRO_LINE_JOIN_ROUND );
- else if( m_lineJoin == Qt::BevelJoin )
- cairo_set_line_join( m_cr, CAIRO_LINE_JOIN_BEVEL );
- else if( m_lineJoin == Qt::MiterJoin )
- cairo_set_line_join( m_cr, CAIRO_LINE_JOIN_MITER );
- cairo_stroke_preserve( m_cr );
- }
- cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
- cairo_restore( m_cr );
-}
-
-void ScPainterEx_Cairo::setClipPath()
-{
- cairo_clip (m_cr);
-}
-
-void ScPainterEx_Cairo::drawImage( ScImage *image, ScPainterExBase::ImageMode mode )
-{
- QImage qImage(image->qImage());
- if (m_convertToGray)
- transformImage(qImage);
- cairo_save(m_cr);
- cairo_set_fill_rule(m_cr, cairo_get_fill_rule(m_cr));
- cairo_surface_t *image2 = cairo_image_surface_create_for_data ((uchar*)qImage.bits(), CAIRO_FORMAT_ARGB32, qImage.width(), qImage.height(), qImage.width()*4);
- cairo_set_source_surface (m_cr, image2, 0, 0);
- cairo_paint_with_alpha (m_cr, m_fillTrans);
- cairo_surface_destroy (image2);
- cairo_restore(m_cr);
-}
-
-void ScPainterEx_Cairo::setupPolygon(FPointArray *points, bool closed)
-{
- bool nPath = true, first = true;
- FPoint np, np1, np2, np3;
- if (points->size() > 3)
- {
- newPath();
- for (uint poi=0; poi<points->size()-3; poi += 4)
- {
- if (points->point(poi).x() > 900000)
- {
- nPath = true;
- continue;
- }
- if (nPath)
- {
- np = points->point(poi);
- if ((!first) && (closed))
- cairo_close_path( m_cr );
- moveTo( np.x(), np.y() );
- nPath = first = false;
- }
- np = points->point(poi);
- np1 = points->point(poi+1);
- np2 = points->point(poi+3);
- np3 = points->point(poi+2);
- if ((np == np1) && (np2 == np3))
- lineTo( np3.x(), np3.y() );
- else
- curveTo(np1, np2, np3);
- }
- if (closed)
- cairo_close_path( m_cr );
- }
-}
-
-void ScPainterEx_Cairo::drawPolygon()
-{
- fillPath();
-}
-
-void ScPainterEx_Cairo::drawPolyLine()
-{
- strokePath();
-}
-
-void ScPainterEx_Cairo::drawLine(FPoint start, FPoint end)
-{
- newPath();
- moveTo(start.x(), start.y());
- lineTo(end.x(), end.y());
- strokePath();
-}
-
-void ScPainterEx_Cairo::drawRect(double x, double y, double w, double h)
-{
- newPath();
- moveTo( x, y );
- lineTo( x+w, y );
- lineTo( x+w, y+h );
- lineTo( x, y+h );
- lineTo( x, y );
- cairo_close_path( m_cr );
- fillPath();
- strokePath();
-}
-
-void ScPainterEx_Cairo::drawGradient( VGradientEx& gradient )
-{
- QRect clipPathRect;
- save();
- setClipPath();
- getClipPathDimensions( clipPathRect );
- if ( gradient.type() == VGradientEx::linear )
- drawLinearGradient( gradient, clipPathRect );
- else if ( gradient.type() == VGradientEx::radial )
- drawCircularGradient( gradient, clipPathRect );
- restore();
-}
-
-void ScPainterEx_Cairo::drawLinearGradient( VGradientEx& gradient, const QRect& rect )
-{
- int index = 0;
- double r, g, b;
- QList<VColorStopEx*> colorStops = gradient.colorStops();
- VColorStopEx* stop = NULL;
- QColor color;
-
- if ( gradient.Stops() < 2 )
- return;
-
- FPoint p1( gradient.origin().x(), gradient.origin().y() );
- FPoint p2( gradient.vector().x(), gradient.vector().y() );
- cairo_pattern_t *pat = cairo_pattern_create_linear (p1.x(), p1.y(), p2.x(), p2.y());
-
- for( uint index = 0 ; index < gradient.Stops(); index++)
- {
- stop = colorStops.at(index);
- color = transformColor( ScColorShade(stop->color, stop->shade), 1.0 );
- color.getRgbF(&r, &g, &b);
- cairo_pattern_add_color_stop_rgba (pat, stop->rampPoint, r, g, b, stop->opacity);
- }
-
- cairo_set_source (m_cr, pat);
- //cairo_clip_preserve (m_cr);
- cairo_paint_with_alpha (m_cr, m_fillTrans);
- cairo_pattern_destroy (pat);
-}
-
-void ScPainterEx_Cairo::drawCircularGradient( VGradientEx& gradient, const QRect& rect )
-{
- int offset = 0;
- double r, g, b;
- QList<VColorStopEx*> colorStops = gradient.colorStops();
- VColorStopEx* stop = NULL;
- QColor color;
-
- FPoint pc( gradient.origin().x(), gradient.origin().y() );
- FPoint pf( gradient.focalPoint().x(), gradient.focalPoint().y() );
- FPoint pv( gradient.vector().x(), gradient.vector().y() );
- double rad = sqrt( pow(pv.x() - pc.x(), 2) + pow(pv.y() - pc.y(), 2) );
-
- cairo_pattern_t* pat = cairo_pattern_create_radial (pc.x(), pc.y(), 0.1, pc.x(), pc.y(), rad);
-
- for( uint index = 0 ; index < gradient.Stops() ; index++)
- {
- stop = colorStops.at(index);
- color = transformColor( ScColorShade(stop->color, stop->shade), 1.0 );
- color.getRgbF(&r, &g, &b);
- cairo_pattern_add_color_stop_rgba (pat, stop->rampPoint, r, g, b, stop->opacity);
- }
-
- cairo_set_source (m_cr, pat);
- //cairo_clip_preserve (m_cr);
- cairo_paint_with_alpha (m_cr, m_fillTrans);
- cairo_pattern_destroy (pat);
-}
-
-void ScPainterEx_Cairo::getClipPathDimensions( QRect& r )
-{
- double left = 0.0, right = 0.0, bottom = 0.0, top = 0.0;
- cairo_clip_extents(m_cr, &left, &bottom, &right, &top);
- r.setLeft( left );
- r.setRight( right );
- r.setBottom( bottom );
- r.setTop( top );
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#include <cmath>
+#include "scpainterex_cairo.h"
+#include "sccolorengine.h"
+#include "util.h"
+
+ScPainterEx_Cairo::ScPainterEx_Cairo( cairo_t* context, QRect& rect, ScribusDoc* doc, bool gray ) : ScPainterExBase()
+{
+ m_doc = doc;
+ m_width = rect.width();
+ m_height = rect.height();
+ m_strokeColor = ScColorShade( QColor(0,0,0), 100 );
+ m_fillColor = ScColorShade( QColor(0,0,0), 100 );
+ m_fillTrans = 1.0;
+ m_strokeTrans = 1.0;
+ m_fillRule = true;
+ m_fillMode = 1;
+ m_lineWidth = 1.0;
+ m_offset = 0;
+ m_lineEnd = Qt::SquareCap;
+ m_lineJoin = Qt::RoundJoin;
+ m_fillGradient = VGradientEx(VGradientEx::linear);
+ m_strokeGradient = VGradientEx(VGradientEx::linear);
+ // Grayscale conversion parameter
+ m_convertToGray = gray;
+ // Initialization of Windows GDI data
+ m_cr = context;
+ m_positionX = m_positionY = 0;
+ clear();
}
+
+ScPainterEx_Cairo::~ScPainterEx_Cairo()
+{
+
+}
+
+QColor ScPainterEx_Cairo::transformColor( ScColorShade& colorShade, double trans )
+{
+ QColor c, color;
+ c = ScColorEngine::getShadeColor(colorShade.color, m_doc, colorShade.shade);
+ color = qRgba( qRed(c.rgb()), qGreen(c.rgb()), qBlue(c.rgb()), qAlpha(trans * 255));
+ if ( m_convertToGray )
+ {
+ int grayLevel;
+ QColor grayColor;
+ grayLevel = 0.3 * color.red() + 0.59 * color.green() + 0.11 * color.blue();
+ grayColor = qRgba( grayLevel, grayLevel, grayLevel, qAlpha(color.rgb()));
+ color = grayColor;
+ }
+ return color;
+}
+
+void ScPainterEx_Cairo::transformImage(QImage& image)
+{
+ int rgb, grey;
+ int imageWidth = image.width();
+ int imageHeight = image.height();
+ QRgb *pscan;
+
+ for ( int j = 0; j < imageHeight; j++ )
+ {
+ pscan = (QRgb *) image.scanLine(j);
+ for (int i = 0; i < imageWidth; i++ )
+ {
+ rgb = pscan[i];
+ grey = 0.3 * qRed(rgb) + 0.59 * qGreen(rgb) + 0.11 * qBlue(rgb);
+ pscan[i] = qRgba(grey, grey, grey, qAlpha(rgb));
+ }
+ }
+}
+
+void ScPainterEx_Cairo::begin()
+{
+}
+
+void ScPainterEx_Cairo::end()
+{
+}
+
+void ScPainterEx_Cairo::clear()
+{
+ /*SolidBrush brush( Color(255,255,255) );
+ m_graphics->FillRectangle(&brush, 0, 0, m_width, m_height);*/
+}
+
+void ScPainterEx_Cairo::clear( ScColorShade &c )
+{
+ /*QColor color = transformColor( c, 1.0 );
+ QRgb cs = color.rgb();
+ SolidBrush brush( Color(qAlpha(cs), qRed(cs), qGreen(cs),qBlue(cs)) );
+ m_graphics->FillRectangle(&brush, 0, 0, m_width, m_height);*/
+}
+
+const QTransform ScPainterEx_Cairo::worldMatrix()
+{
+ cairo_matrix_t matrix;
+ cairo_get_matrix(m_cr, &matrix);
+ QTransform mat(matrix.xx, matrix.yx, matrix.xy, matrix.yy, matrix.x0, matrix.y0);
+ return mat;
+}
+
+void ScPainterEx_Cairo::setWorldMatrix( const QTransform &mat )
+{
+ cairo_matrix_t matrix;
+ cairo_matrix_init(&matrix, mat.m11(), mat.m12(), mat.m21(), mat.m22(), mat.dx(), mat.dy());
+ cairo_set_matrix(m_cr, &matrix);
+}
+
+void ScPainterEx_Cairo::translate( double x, double y )
+{
+ cairo_translate(m_cr, x, y);
+}
+
+void ScPainterEx_Cairo::rotate( double r )
+{
+ cairo_rotate(m_cr, r * 3.1415927 / 180.0);
+}
+
+void ScPainterEx_Cairo::scale( double x, double y )
+{
+ cairo_scale(m_cr, x, y);
+}
+
+void ScPainterEx_Cairo::moveTo( const double &x, const double &y )
+{
+ cairo_move_to(m_cr, x, y);
+}
+
+void ScPainterEx_Cairo::lineTo( const double &x, const double &y )
+{
+ cairo_line_to(m_cr, x, y);
+}
+
+void ScPainterEx_Cairo::curveTo( FPoint p1, FPoint p2, FPoint p3 )
+{
+ cairo_curve_to(m_cr, p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y() );
+}
+
+void ScPainterEx_Cairo::newPath()
+{
+ cairo_new_path( m_cr );
+}
+
+void ScPainterEx_Cairo::closePath()
+{
+ cairo_close_path( m_cr);
+}
+
+void ScPainterEx_Cairo::setFillRule( bool fillRule )
+{
+ m_fillRule = fillRule;
+}
+
+void ScPainterEx_Cairo::setFillMode( int fill )
+{
+ m_fillMode = fill;
+}
+
+void ScPainterEx_Cairo::setGradient(VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc)
+{
+ m_fillGradient.setType(mode);
+ m_fillGradient.setOrigin(orig);
+ m_fillGradient.setVector(vec);
+ m_fillGradient.setFocalPoint(foc);
+}
+
+void ScPainterEx_Cairo::setPattern( ScPattern* pattern, QTransform& patternTransform )
+{
+ m_pattern = pattern;
+ m_patternTransform = patternTransform;
+}
+
+void ScPainterEx_Cairo::fillTextPath()
+{
+ drawVPath( 0 );
+}
+
+void ScPainterEx_Cairo::strokeTextPath()
+{
+ if( m_lineWidth == 0 )
+ return;
+ drawVPath( 1 );
+}
+
+void ScPainterEx_Cairo::fillPath()
+{
+ if( m_fillMode != 0)
+ drawVPath( 0 );
+}
+
+void ScPainterEx_Cairo::strokePath()
+{
+ if( m_lineWidth == 0 )
+ return;
+ drawVPath( 1 );
+}
+
+ScColorShade ScPainterEx_Cairo::pen()
+{
+ return m_strokeColor;
+}
+
+ScColorShade ScPainterEx_Cairo::brush()
+{
+ return m_fillColor;
+}
+
+void ScPainterEx_Cairo::setPen( const ScColorShade &c )
+{
+ m_strokeColor = c;
+}
+
+void ScPainterEx_Cairo::setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo )
+{
+ m_strokeColor = c;
+ m_lineWidth = w;
+ m_lineEnd = ca;
+ m_lineJoin = jo;
+ m_array.clear();
+ m_offset = 0;
+ getDashArray(st, w, m_array);
+}
+
+void ScPainterEx_Cairo::setLineWidth( double w )
+{
+ m_lineWidth = w;
+}
+
+void ScPainterEx_Cairo::setPenOpacity( double op )
+{
+ m_strokeTrans = op;
+}
+
+void ScPainterEx_Cairo::setDash(const QVector<double>& array, double ofs)
+{
+ m_array = array;
+ m_offset = ofs;
+}
+
+void ScPainterEx_Cairo::setBrush( const ScColorShade &c )
+{
+ m_fillColor = c;
+}
+
+void ScPainterEx_Cairo::setBrushOpacity( double op )
+{
+ m_fillTrans = op;
+}
+
+void ScPainterEx_Cairo::setOpacity( double op )
+{
+ m_fillTrans = op;
+ m_strokeTrans = op;
+}
+
+void ScPainterEx_Cairo::setFont( const QFont &f)
+{
+ m_font = f;
+}
+
+QFont ScPainterEx_Cairo::font()
+{
+ return m_font;
+}
+
+void ScPainterEx_Cairo::save()
+{
+ cairo_save(m_cr);
+}
+
+void ScPainterEx_Cairo::restore()
+{
+ cairo_restore( m_cr );
+}
+
+void ScPainterEx_Cairo::setRasterOp( int )
+{
+}
+
+void ScPainterEx_Cairo::drawVPath( int mode )
+{
+ cairo_save( m_cr );
+ if (mode == 0)
+ {
+ if( m_fillRule )
+ cairo_set_fill_rule (m_cr, CAIRO_FILL_RULE_EVEN_ODD);
+ else
+ cairo_set_fill_rule (m_cr, CAIRO_FILL_RULE_WINDING);
+ if (m_fillMode == ScPainterExBase::Gradient)
+ {
+ drawGradient( m_fillGradient );
+ }
+ else
+ {
+ double r, g, b;
+ QColor fillColor = transformColor(m_fillColor, 1.0);
+ fillColor.getRgbF(&r, &g, &b);
+ cairo_set_source_rgba( m_cr, r, g, b, m_fillTrans );
+ if (m_fillTrans != 1.0)
+ cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
+ else
+ cairo_set_operator(m_cr, CAIRO_OPERATOR_SOURCE);
+ cairo_fill_preserve( m_cr );
+ }
+ }
+ else
+ {
+ double r, g, b;
+ QColor strokeColor = transformColor( m_strokeColor, 1.0 );
+ strokeColor.getRgbF(&r, &g, &b);
+ cairo_set_source_rgba( m_cr, r, g, b, m_strokeTrans );
+
+ cairo_set_line_width( m_cr, m_lineWidth );
+ if( m_array.count() > 0 )
+ cairo_set_dash( m_cr, m_array.data(), m_array.count(), static_cast<double>(m_offset));
+ else
+ cairo_set_dash( m_cr, NULL, 0, 0 );
+ if (m_strokeTrans != 1.0)
+ cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
+ else
+ cairo_set_operator(m_cr, CAIRO_OPERATOR_SOURCE);
+ if( m_lineEnd == Qt::RoundCap )
+ cairo_set_line_cap (m_cr, CAIRO_LINE_CAP_ROUND);
+ else if( m_lineEnd == Qt::SquareCap )
+ cairo_set_line_cap (m_cr, CAIRO_LINE_CAP_SQUARE);
+ else if( m_lineEnd == Qt::FlatCap )
+ cairo_set_line_cap (m_cr, CAIRO_LINE_CAP_BUTT);
+ if( m_lineJoin == Qt::RoundJoin )
+ cairo_set_line_join( m_cr, CAIRO_LINE_JOIN_ROUND );
+ else if( m_lineJoin == Qt::BevelJoin )
+ cairo_set_line_join( m_cr, CAIRO_LINE_JOIN_BEVEL );
+ else if( m_lineJoin == Qt::MiterJoin )
+ cairo_set_line_join( m_cr, CAIRO_LINE_JOIN_MITER );
+ cairo_stroke_preserve( m_cr );
+ }
+ cairo_set_operator(m_cr, CAIRO_OPERATOR_OVER);
+ cairo_restore( m_cr );
+}
+
+void ScPainterEx_Cairo::setClipPath()
+{
+ cairo_clip (m_cr);
+}
+
+void ScPainterEx_Cairo::drawImage( ScImage *image, ScPainterExBase::ImageMode mode )
+{
+ QImage qImage(image->qImage());
+ if (m_convertToGray)
+ transformImage(qImage);
+ cairo_save(m_cr);
+ cairo_set_fill_rule(m_cr, cairo_get_fill_rule(m_cr));
+ cairo_surface_t *image2 = cairo_image_surface_create_for_data ((uchar*)qImage.bits(), CAIRO_FORMAT_ARGB32, qImage.width(), qImage.height(), qImage.width()*4);
+ cairo_set_source_surface (m_cr, image2, 0, 0);
+ cairo_paint_with_alpha (m_cr, m_fillTrans);
+ cairo_surface_destroy (image2);
+ cairo_restore(m_cr);
+}
+
+void ScPainterEx_Cairo::setupPolygon(FPointArray *points, bool closed)
+{
+ bool nPath = true, first = true;
+ FPoint np, np1, np2, np3;
+ if (points->size() > 3)
+ {
+ newPath();
+ for (uint poi=0; poi<points->size()-3; poi += 4)
+ {
+ if (points->point(poi).x() > 900000)
+ {
+ nPath = true;
+ continue;
+ }
+ if (nPath)
+ {
+ np = points->point(poi);
+ if ((!first) && (closed))
+ cairo_close_path( m_cr );
+ moveTo( np.x(), np.y() );
+ nPath = first = false;
+ }
+ np = points->point(poi);
+ np1 = points->point(poi+1);
+ np2 = points->point(poi+3);
+ np3 = points->point(poi+2);
+ if ((np == np1) && (np2 == np3))
+ lineTo( np3.x(), np3.y() );
+ else
+ curveTo(np1, np2, np3);
+ }
+ if (closed)
+ cairo_close_path( m_cr );
+ }
+}
+
+void ScPainterEx_Cairo::drawPolygon()
+{
+ fillPath();
+}
+
+void ScPainterEx_Cairo::drawPolyLine()
+{
+ strokePath();
+}
+
+void ScPainterEx_Cairo::drawLine(FPoint start, FPoint end)
+{
+ newPath();
+ moveTo(start.x(), start.y());
+ lineTo(end.x(), end.y());
+ strokePath();
+}
+
+void ScPainterEx_Cairo::drawRect(double x, double y, double w, double h)
+{
+ newPath();
+ moveTo( x, y );
+ lineTo( x+w, y );
+ lineTo( x+w, y+h );
+ lineTo( x, y+h );
+ lineTo( x, y );
+ cairo_close_path( m_cr );
+ fillPath();
+ strokePath();
+}
+
+void ScPainterEx_Cairo::drawGradient( VGradientEx& gradient )
+{
+ QRect clipPathRect;
+ save();
+ setClipPath();
+ getClipPathDimensions( clipPathRect );
+ if ( gradient.type() == VGradientEx::linear )
+ drawLinearGradient( gradient, clipPathRect );
+ else if ( gradient.type() == VGradientEx::radial )
+ drawCircularGradient( gradient, clipPathRect );
+ restore();
+}
+
+void ScPainterEx_Cairo::drawLinearGradient( VGradientEx& gradient, const QRect& rect )
+{
+ int index = 0;
+ double r, g, b;
+ QList<VColorStopEx*> colorStops = gradient.colorStops();
+ VColorStopEx* stop = NULL;
+ QColor color;
+
+ if ( gradient.Stops() < 2 )
+ return;
+
+ FPoint p1( gradient.origin().x(), gradient.origin().y() );
+ FPoint p2( gradient.vector().x(), gradient.vector().y() );
+ cairo_pattern_t *pat = cairo_pattern_create_linear (p1.x(), p1.y(), p2.x(), p2.y());
+
+ for( uint index = 0 ; index < gradient.Stops(); index++)
+ {
+ stop = colorStops.at(index);
+ color = transformColor( ScColorShade(stop->color, stop->shade), 1.0 );
+ color.getRgbF(&r, &g, &b);
+ cairo_pattern_add_color_stop_rgba (pat, stop->rampPoint, r, g, b, stop->opacity);
+ }
+
+ cairo_set_source (m_cr, pat);
+ //cairo_clip_preserve (m_cr);
+ cairo_paint_with_alpha (m_cr, m_fillTrans);
+ cairo_pattern_destroy (pat);
+}
+
+void ScPainterEx_Cairo::drawCircularGradient( VGradientEx& gradient, const QRect& rect )
+{
+ int offset = 0;
+ double r, g, b;
+ QList<VColorStopEx*> colorStops = gradient.colorStops();
+ VColorStopEx* stop = NULL;
+ QColor color;
+
+ FPoint pc( gradient.origin().x(), gradient.origin().y() );
+ FPoint pf( gradient.focalPoint().x(), gradient.focalPoint().y() );
+ FPoint pv( gradient.vector().x(), gradient.vector().y() );
+ double rad = sqrt( pow(pv.x() - pc.x(), 2) + pow(pv.y() - pc.y(), 2) );
+
+ cairo_pattern_t* pat = cairo_pattern_create_radial (pc.x(), pc.y(), 0.1, pc.x(), pc.y(), rad);
+
+ for( uint index = 0 ; index < gradient.Stops() ; index++)
+ {
+ stop = colorStops.at(index);
+ color = transformColor( ScColorShade(stop->color, stop->shade), 1.0 );
+ color.getRgbF(&r, &g, &b);
+ cairo_pattern_add_color_stop_rgba (pat, stop->rampPoint, r, g, b, stop->opacity);
+ }
+
+ cairo_set_source (m_cr, pat);
+ //cairo_clip_preserve (m_cr);
+ cairo_paint_with_alpha (m_cr, m_fillTrans);
+ cairo_pattern_destroy (pat);
+}
+
+void ScPainterEx_Cairo::getClipPathDimensions( QRect& r )
+{
+ double left = 0.0, right = 0.0, bottom = 0.0, top = 0.0;
+ cairo_clip_extents(m_cr, &left, &bottom, &right, &top);
+ r.setLeft( left );
+ r.setRight( right );
+ r.setBottom( bottom );
+ r.setTop( top );
+}
Index: scribus/scpageoutput_ps2.cpp
===================================================================
--- scribus/scpageoutput_ps2.cpp (revision 13950)
+++ scribus/scpageoutput_ps2.cpp (revision 13951)
@@ -1,79 +1,79 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-#include <QPainter>
-
-#include "commonstrings.h"
-#include "fonts/scfontmetrics.h"
-#include "page.h"
-#include "pageitem.h"
-#include "scimage.h"
-#include "scpageoutput_ps2.h"
-#include "scpainterex_ps2.h"
-#include "scribus.h"
-#include "util.h"
-
-ScPageOutput_Ps2::ScPageOutput_Ps2(QIODevice* dev, ScribusDoc* doc, int pageIndex, ScPs2OutputParams& options)
- : ScPageOutput(doc, options.reloadImages, options.resolution, options.useProfiles)
-{
- m_device = dev;
- m_pageIndex = pageIndex;
- m_options = options;
- m_options.document = doc;
- initStream(dev);
-}
-
-ScPageOutput_Ps2::~ScPageOutput_Ps2()
-{
-}
-
-void ScPageOutput_Ps2::initStream(QIODevice* dev)
-{
- m_stream.setDevice(m_device);
-}
-
-void ScPageOutput_Ps2::begin(void)
-{
- m_stream << QString("%%Page: %1 %2\n").arg(m_pageIndex).arg(m_pageIndex);
- m_stream << QString("/saveobj save def \n");
- if (m_clip.width() > 0 && m_clip.height() > 0)
- {
- m_stream << QString("%1 %2 moveto\n").arg(m_clip.left()).arg(m_clip.bottom());
- m_stream << QString("%1 %2 lineto\n").arg(m_clip.right()).arg(m_clip.bottom());
- m_stream << QString("%1 %2 lineto\n").arg(m_clip.right()).arg(m_clip.top());
- m_stream << QString("%1 %2 lineto closepath clip newpath\n").arg(m_clip.left()).arg(m_clip.top());
- }
-}
-
-void ScPageOutput_Ps2::drawPage(Page* page)
-{
- // Get page position
- int clipx = static_cast<int>(page->xOffset());
- int clipy = static_cast<int>(page->yOffset());
- int clipw = qRound(page->width());
- int cliph = qRound(page->height());
- // Create painter
- ScPainterEx_Ps2 painter(m_device, m_clip, m_options);
- // Set transformation matrix
- double scalex = m_options.mirrorH ? -1.0 : 1.0;
- double scaley = m_options.mirrorV ? 1.0 : -1.0;
- double dx = -clipx * scalex;
- double dy = -clipy * scaley;
- if ( m_options.mirrorH ) dx += clipw;
- if ( !m_options.mirrorV ) dy += cliph;
- QMatrix matrix( scalex, 0.0, 0.0, scaley, dx, dy );
- painter.setWorldMatrix( matrix );
- // Draw page
- ScPageOutput::drawPage(page, &painter);
-}
-
-void ScPageOutput_Ps2::end(void)
-{
- m_stream << "%%PageTrailer\n";
- m_stream << "saveobj restore\n";
- m_stream << "showpage\n";
-}
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#include <QPainter>
+
+#include "commonstrings.h"
+#include "fonts/scfontmetrics.h"
+#include "page.h"
+#include "pageitem.h"
+#include "scimage.h"
+#include "scpageoutput_ps2.h"
+#include "scpainterex_ps2.h"
+#include "scribus.h"
+#include "util.h"
+
+ScPageOutput_Ps2::ScPageOutput_Ps2(QIODevice* dev, ScribusDoc* doc, int pageIndex, ScPs2OutputParams& options)
+ : ScPageOutput(doc, options.reloadImages, options.resolution, options.useProfiles)
+{
+ m_device = dev;
+ m_pageIndex = pageIndex;
+ m_options = options;
+ m_options.document = doc;
+ initStream(dev);
+}
+
+ScPageOutput_Ps2::~ScPageOutput_Ps2()
+{
+}
+
+void ScPageOutput_Ps2::initStream(QIODevice* dev)
+{
+ m_stream.setDevice(m_device);
+}
+
+void ScPageOutput_Ps2::begin(void)
+{
+ m_stream << QString("%%Page: %1 %2\n").arg(m_pageIndex).arg(m_pageIndex);
+ m_stream << QString("/saveobj save def \n");
+ if (m_clip.width() > 0 && m_clip.height() > 0)
+ {
+ m_stream << QString("%1 %2 moveto\n").arg(m_clip.left()).arg(m_clip.bottom());
+ m_stream << QString("%1 %2 lineto\n").arg(m_clip.right()).arg(m_clip.bottom());
+ m_stream << QString("%1 %2 lineto\n").arg(m_clip.right()).arg(m_clip.top());
+ m_stream << QString("%1 %2 lineto closepath clip newpath\n").arg(m_clip.left()).arg(m_clip.top());
+ }
+}
+
+void ScPageOutput_Ps2::drawPage(Page* page)
+{
+ // Get page position
+ int clipx = static_cast<int>(page->xOffset());
+ int clipy = static_cast<int>(page->yOffset());
+ int clipw = qRound(page->width());
+ int cliph = qRound(page->height());
+ // Create painter
+ ScPainterEx_Ps2 painter(m_device, m_clip, m_options);
+ // Set transformation matrix
+ double scalex = m_options.mirrorH ? -1.0 : 1.0;
+ double scaley = m_options.mirrorV ? 1.0 : -1.0;
+ double dx = -clipx * scalex;
+ double dy = -clipy * scaley;
+ if ( m_options.mirrorH ) dx += clipw;
+ if ( !m_options.mirrorV ) dy += cliph;
+ QTransform matrix( scalex, 0.0, 0.0, scaley, dx, dy );
+ painter.setWorldMatrix( matrix );
+ // Draw page
+ ScPageOutput::drawPage(page, &painter);
+}
+
+void ScPageOutput_Ps2::end(void)
+{
+ m_stream << "%%PageTrailer\n";
+ m_stream << "saveobj restore\n";
+ m_stream << "showpage\n";
+}
Index: scribus/fonts/scfontmetrics.cpp
===================================================================
--- scribus/fonts/scfontmetrics.cpp (revision 13950)
+++ scribus/fonts/scfontmetrics.cpp (revision 13951)
@@ -7,7 +7,7 @@
#include <QColor>
#include <QDebug>
#include <QMap>
-#include <QMatrix>
+#include <QTransform>
#include <QPainter>
#include <QPixmap>
#include <QRegExp>
@@ -200,7 +200,7 @@
}
*x = face->glyph->metrics.horiBearingX / 6400.0;
*y = face->glyph->metrics.horiBearingY / 6400.0;
- QMatrix ma;
+ QTransform ma;
ma.scale(0.01, -0.01);
pts.map(ma);
pts.translate(0, chs);
Index: scribus/scribusview.h
===================================================================
--- scribus/scribusview.h (revision 13950)
+++ scribus/scribusview.h (revision 13951)
@@ -192,7 +192,7 @@
void getDragRectScreen(double *x, double *y, double *w, double *h);
void getGroupRectScreen(double *x, double *y, double *w, double *h);
// void ToView(QPainter *p);
-// void ToView(QMatrix& m);
+// void ToView(QTransform& m);
// bool MoveItem(double newX, double newY, PageItem* ite, bool fromMP = false);
bool PointOnLine(QPoint Start, QPoint Ende, QRect MArea);
void TransformPoly(int mode, int rot = 1, double scaling = 1.0);
Index: scribus/prefsmanager.cpp
===================================================================
--- scribus/prefsmanager.cpp (revision 13950)
+++ scribus/prefsmanager.cpp (revision 13951)
@@ -24,7 +24,7 @@
#include <QDir>
#include <QDomDocument>
#include <QFile>
-#include <QMatrix>
+#include <QTransform>
#include <QList>
#include <QString>
#include <QStringList>
@@ -528,9 +528,9 @@
{
struct ArrowDesc arrow;
FPointArray points;
- QMatrix arrowScaling;
+ QTransform arrowScaling;
arrowScaling.scale(0.5, 0.5);
- QMatrix arrowRotate;
+ QTransform arrowRotate;
arrowRotate.rotate(180);
arrow.name = "Arrow1L";
arrow.userArrow = false;
Index: scribus/vgradientex.cpp
===================================================================
--- scribus/vgradientex.cpp (revision 13950)
+++ scribus/vgradientex.cpp (revision 13951)
@@ -174,7 +174,7 @@
delete m_colorStops.takeAt(n);
}
-void VGradientEx::transform( const QMatrix &m )
+void VGradientEx::transform( const QTransform &m )
{
double mx, my;
mx = m.m11() * m_origin.x() + m.m21() * m_origin.y() + m.dx();
Index: scribus/fpointarray.cpp
===================================================================
--- scribus/fpointarray.cpp (revision 13950)
+++ scribus/fpointarray.cpp (revision 13951)
@@ -241,7 +241,7 @@
return FPoint(maxx - minx,maxy - miny);
}
-void FPointArray::map( QMatrix m )
+void FPointArray::map( QTransform m )
{
const double m11 = m.m11();
const double m12 = m.m12();
Index: scribus/pageitem_polyline.cpp
===================================================================
--- scribus/pageitem_polyline.cpp (revision 13950)
+++ scribus/pageitem_polyline.cpp (revision 13951)
@@ -121,7 +121,7 @@
if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
{
double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(Start.x(), Start.y());
arrowTrans.rotate(r);
drawArrow(p, arrowTrans, m_startArrowIndex);
@@ -138,7 +138,7 @@
if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
{
double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(End.x(), End.y());
arrowTrans.rotate(r);
drawArrow(p, arrowTrans, m_endArrowIndex);
Index: scribus/scpainterex_cairo.h
===================================================================
--- scribus/scpainterex_cairo.h (revision 13950)
+++ scribus/scpainterex_cairo.h (revision 13951)
@@ -1,132 +1,132 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-#ifndef SCPAINTEREX_CAIRO_H
-#define SCPAINTEREX_CAIRO_H
-
-#include <cairo.h>
-#include "scpainterexbase.h"
-
-class ScPainterEx_Cairo : public ScPainterExBase
-{
-public:
- ScPainterEx_Cairo(cairo_t* context, QRect& rect, ScribusDoc* doc, bool gray );
- virtual ~ScPainterEx_Cairo();
-
- virtual Capabilities capabilities() { return transparencies; }
-
- virtual int supportedColorModes() { return (int) rgbMode; }
- virtual ColorMode preferredColorMode() { return rgbMode; }
- virtual ImageMode imageMode() { return rgbImages; }
-
- virtual void begin();
- virtual void end();
- virtual void clear();
- virtual void clear( ScColorShade & );
-
- // matrix manipulation
- virtual void setWorldMatrix( const QMatrix & );
- virtual const QMatrix worldMatrix();
- virtual void translate( double, double );
- virtual void rotate( double );
- virtual void scale( double, double );
-
- // drawing
- virtual void moveTo( const double &, const double & );
- virtual void lineTo( const double &, const double & );
- virtual void curveTo( FPoint p1, FPoint p2, FPoint p3 );
- virtual void newPath();
- virtual void closePath();
- virtual void fillTextPath();
- virtual void strokeTextPath();
- virtual void fillPath();
- virtual void strokePath();
- virtual void setFillRule( bool fillRule );
- virtual bool fillRule() { return m_fillRule; }
- virtual void setFillMode( int fill );
- virtual int fillMode() { return m_fillMode; }
- virtual void setGradient( VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc = FPoint(0,0));
- virtual void setPattern ( ScPattern* pattern, QMatrix& patternTransform );
- virtual void setClipPath();
-
- virtual void drawImage( ScImage *image, ScPainterExBase::ImageMode mode );
- virtual void setupPolygon(FPointArray *points, bool closed = true);
- virtual void drawPolygon();
- virtual void drawPolyLine();
- virtual void drawLine(FPoint start, FPoint end);
- virtual void drawRect(double, double, double, double);
-
- // pen + brush
- virtual ScColorShade pen();
- virtual ScColorShade brush();
- virtual void setPen( const ScColorShade & );
- virtual void setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo );
- virtual void setPenOpacity( double op );
- virtual void setLineWidth( double w);
- virtual void setDash(const QVector<double>& array, double ofs);
- virtual void setBrush( const ScColorShade & );
- virtual void setBrushOpacity( double op );
- virtual void setOpacity( double op );
- virtual void setFont( const QFont &f );
- virtual QFont font();
-
- // stack management
- virtual void save();
- virtual void restore();
-
- virtual void setRasterOp( int op );
-
-private:
-
- void drawVPath( int mode );
- void drawGradient( VGradientEx& gradient );
- void drawLinearGradient( VGradientEx& gradient, const QRect& rect );
- void drawCircularGradient( VGradientEx& gradient, const QRect& rect );
- void getClipPathDimensions( QRect& r );
-
- ScribusDoc* m_doc;
-
- unsigned int m_width;
- unsigned int m_height;
- QMatrix m_matrix;
- QFont m_font;
-/* Filling */
- ScColorShade m_fillColor;
- double m_fillTrans;
- bool m_fillRule;
- int m_fillMode; // 0 = none, 1 = solid, 2 = gradient
- int m_gradientMode; // 1 = linear, 2 = radial
-/* Stroking */
- ScColorShade m_strokeColor;
- double m_strokeTrans;
- double m_lineWidth;
-/* Grayscale conversion option */
- bool m_convertToGray;
-
-/* Line End Style */
- Qt::PenCapStyle m_lineEnd;
-/* Line Join Style */
- Qt::PenJoinStyle m_lineJoin;
-/* The Dash Array */
- QVector<double> m_array;
- double m_offset;
-/* Transformation Stack */
- QStack<QMatrix> m_stack;
-
-/* Cairo context */
- cairo_t* m_cr;
-
-/* Color conversion function */
- QColor transformColor( ScColorShade& colorShade, double trans );
- void transformImage( QImage& image );
-
- QStack<int> m_gStates;
- double m_positionX;
- double m_positionY;
-};
-
-#endif
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#ifndef SCPAINTEREX_CAIRO_H
+#define SCPAINTEREX_CAIRO_H
+
+#include <cairo.h>
+#include "scpainterexbase.h"
+
+class ScPainterEx_Cairo : public ScPainterExBase
+{
+public:
+ ScPainterEx_Cairo(cairo_t* context, QRect& rect, ScribusDoc* doc, bool gray );
+ virtual ~ScPainterEx_Cairo();
+
+ virtual Capabilities capabilities() { return transparencies; }
+
+ virtual int supportedColorModes() { return (int) rgbMode; }
+ virtual ColorMode preferredColorMode() { return rgbMode; }
+ virtual ImageMode imageMode() { return rgbImages; }
+
+ virtual void begin();
+ virtual void end();
+ virtual void clear();
+ virtual void clear( ScColorShade & );
+
+ // matrix manipulation
+ virtual void setWorldMatrix( const QTransform & );
+ virtual const QTransform worldMatrix();
+ virtual void translate( double, double );
+ virtual void rotate( double );
+ virtual void scale( double, double );
+
+ // drawing
+ virtual void moveTo( const double &, const double & );
+ virtual void lineTo( const double &, const double & );
+ virtual void curveTo( FPoint p1, FPoint p2, FPoint p3 );
+ virtual void newPath();
+ virtual void closePath();
+ virtual void fillTextPath();
+ virtual void strokeTextPath();
+ virtual void fillPath();
+ virtual void strokePath();
+ virtual void setFillRule( bool fillRule );
+ virtual bool fillRule() { return m_fillRule; }
+ virtual void setFillMode( int fill );
+ virtual int fillMode() { return m_fillMode; }
+ virtual void setGradient( VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc = FPoint(0,0));
+ virtual void setPattern ( ScPattern* pattern, QTransform& patternTransform );
+ virtual void setClipPath();
+
+ virtual void drawImage( ScImage *image, ScPainterExBase::ImageMode mode );
+ virtual void setupPolygon(FPointArray *points, bool closed = true);
+ virtual void drawPolygon();
+ virtual void drawPolyLine();
+ virtual void drawLine(FPoint start, FPoint end);
+ virtual void drawRect(double, double, double, double);
+
+ // pen + brush
+ virtual ScColorShade pen();
+ virtual ScColorShade brush();
+ virtual void setPen( const ScColorShade & );
+ virtual void setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo );
+ virtual void setPenOpacity( double op );
+ virtual void setLineWidth( double w);
+ virtual void setDash(const QVector<double>& array, double ofs);
+ virtual void setBrush( const ScColorShade & );
+ virtual void setBrushOpacity( double op );
+ virtual void setOpacity( double op );
+ virtual void setFont( const QFont &f );
+ virtual QFont font();
+
+ // stack management
+ virtual void save();
+ virtual void restore();
+
+ virtual void setRasterOp( int op );
+
+private:
+
+ void drawVPath( int mode );
+ void drawGradient( VGradientEx& gradient );
+ void drawLinearGradient( VGradientEx& gradient, const QRect& rect );
+ void drawCircularGradient( VGradientEx& gradient, const QRect& rect );
+ void getClipPathDimensions( QRect& r );
+
+ ScribusDoc* m_doc;
+
+ unsigned int m_width;
+ unsigned int m_height;
+ QTransform m_matrix;
+ QFont m_font;
+/* Filling */
+ ScColorShade m_fillColor;
+ double m_fillTrans;
+ bool m_fillRule;
+ int m_fillMode; // 0 = none, 1 = solid, 2 = gradient
+ int m_gradientMode; // 1 = linear, 2 = radial
+/* Stroking */
+ ScColorShade m_strokeColor;
+ double m_strokeTrans;
+ double m_lineWidth;
+/* Grayscale conversion option */
+ bool m_convertToGray;
+
+/* Line End Style */
+ Qt::PenCapStyle m_lineEnd;
+/* Line Join Style */
+ Qt::PenJoinStyle m_lineJoin;
+/* The Dash Array */
+ QVector<double> m_array;
+ double m_offset;
+/* Transformation Stack */
+ QStack<QTransform> m_stack;
+
+/* Cairo context */
+ cairo_t* m_cr;
+
+/* Color conversion function */
+ QColor transformColor( ScColorShade& colorShade, double trans );
+ void transformImage( QImage& image );
+
+ QStack<int> m_gStates;
+ double m_positionX;
+ double m_positionY;
+};
+
+#endif
Index: scribus/scribusXml.cpp
===================================================================
--- scribus/scribusXml.cpp (revision 13950)
+++ scribus/scribusXml.cpp (revision 13951)
@@ -1467,7 +1467,7 @@
{
Neu->imageClip = Neu->pixm.imgInfo.PDSpathData[itemClip].copy();
Neu->pixm.imgInfo.usedPath = itemClip;
- QMatrix cl;
+ QTransform cl;
cl.translate(Neu->imageXOffset()*Neu->imageXScale(), Neu->imageYOffset()*Neu->imageYScale());
cl.scale(Neu->imageXScale(), Neu->imageYScale());
Neu->imageClip.map(cl);
@@ -1765,7 +1765,7 @@
{
Neu->imageClip = Neu->pixm.imgInfo.PDSpathData[patClipPath].copy();
Neu->pixm.imgInfo.usedPath = patClipPath;
- QMatrix cl;
+ QTransform cl;
cl.translate(Neu->imageXOffset()*Neu->imageXScale(), Neu->imageYOffset()*Neu->imageYScale());
cl.scale(Neu->imageXScale(), Neu->imageYScale());
Neu->imageClip.map(cl);
@@ -1931,7 +1931,7 @@
{
painter->save();
FPointArray cl = embedded->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(embedded->gXpos, embedded->gYpos);
mm.rotate(embedded->rotation());
cl.map( mm );
Index: scribus/chartablemodel.cpp
===================================================================
--- scribus/chartablemodel.cpp (revision 13950)
+++ scribus/chartablemodel.cpp (revision 13951)
@@ -62,7 +62,7 @@
{
// m_cols should not become 0. Never.
int baseSize = m_viewWidth / m_cols;
- QMatrix chma;
+ QTransform chma;
chma.scale(baseSize/10, baseSize/10);
ScFace face = (*m_doc->AllFonts)[m_fontInUse];
Index: scribus/util_math.cpp
===================================================================
--- scribus/util_math.cpp (revision 13950)
+++ scribus/util_math.cpp (revision 13951)
@@ -294,7 +294,7 @@
return newAngle;
}
-double getRotationFromMatrix(QMatrix& matrix, double def)
+double getRotationFromMatrix(QTransform& matrix, double def)
{
double value = def;
double norm = sqrt(fabs(matrix.det()));
@@ -306,7 +306,7 @@
double m22 = matrix.m22() / norm;
if (fabs(m11) <= 1.0 && fabs(m12) <= 1.0 && fabs(m21) <= 1.0 && fabs(m22) <= 1.0)
{
- QMatrix mat(m11, m12, m21, m22, 0, 0);
+ QTransform mat(m11, m12, m21, m22, 0, 0);
if (abs(mat.det()-1.0) < 0.00001 && (mat.m12() == -mat.m21()))
{
double ac = acos(mat.m11());
Index: scribus/ui/pageitemrotationsetter.cpp
===================================================================
--- scribus/ui/pageitemrotationsetter.cpp (revision 13950)
+++ scribus/ui/pageitemrotationsetter.cpp (revision 13951)
@@ -138,7 +138,7 @@
int rotMode = item->m_Doc->RotMode();
if (rotMode != 0)
{
- QMatrix ma;
+ QTransform ma;
ma.translate(item->xPos(), item->yPos());
ma.scale(1, 1);
ma.rotate(item->rotation());
Index: scribus/ui/extimageprops.cpp
===================================================================
--- scribus/ui/extimageprops.cpp (revision 13950)
+++ scribus/ui/extimageprops.cpp (revision 13951)
@@ -242,7 +242,7 @@
FPoint min = getMinClipF(&Path);
Path.translate(-min.x(), -min.y());
FPoint max = Path.WidthHeight();
- QMatrix mm;
+ QTransform mm;
mm.scale(34.0 / qMax(max.x(), max.y()), 34.0 / qMax(max.x(), max.y()));
Path.map(mm);
p->setupPolygon(&Path);
@@ -313,7 +313,7 @@
{
currentItem->imageClip = currentItem->pixm.imgInfo.PDSpathData[sel[0]->text()].copy();
currentItem->pixm.imgInfo.usedPath = sel[0]->text();
- QMatrix cl;
+ QTransform cl;
cl.translate(currentItem->imageXOffset()*currentItem->imageXScale(), currentItem->imageYOffset()*currentItem->imageYScale());
cl.scale(currentItem->imageXScale(), currentItem->imageYScale());
currentItem->imageClip.map(cl);
@@ -352,7 +352,7 @@
{
currentItem->imageClip = currentItem->pixm.imgInfo.PDSpathData[sel[0]->text()].copy();
currentItem->pixm.imgInfo.usedPath = sel[0]->text();
- QMatrix cl;
+ QTransform cl;
cl.translate(currentItem->imageXOffset()*currentItem->imageXScale(), currentItem->imageYOffset()*currentItem->imageYScale());
cl.scale(currentItem->imageXScale(), currentItem->imageYScale());
currentItem->imageClip.map(cl);
@@ -444,7 +444,7 @@
{
currentItem->imageClip = currentItem->pixm.imgInfo.PDSpathData[c->text()].copy();
currentItem->pixm.imgInfo.usedPath = c->text();
- QMatrix cl;
+ QTransform cl;
cl.translate(currentItem->imageXOffset()*currentItem->imageXScale(), currentItem->imageYOffset()*currentItem->imageYScale());
cl.scale(currentItem->imageXScale(), currentItem->imageYScale());
currentItem->imageClip.map(cl);
Index: scribus/ui/propertiespalette.cpp
===================================================================
--- scribus/ui/propertiespalette.cpp (revision 13950)
+++ scribus/ui/propertiespalette.cpp (revision 13951)
@@ -22,7 +22,7 @@
#include <QKeyEvent>
#include <QLabel>
#include <QListView>
-#include <QMatrix>
+#include <QTransform>
#include <QMenu>
#include <QMessageBox>
#include <QObject>
@@ -2822,7 +2822,7 @@
disconnect(Ypos, SIGNAL(valueChanged(double)), this, SLOT(NewY()));
bool tmp = HaveItem;
double inX, inY, b, h, r, dummy1, dummy2;
- QMatrix ma;
+ QTransform ma;
FPoint n;
if (HaveItem)
{
@@ -2888,7 +2888,7 @@
return;
bool tmp = HaveItem;
HaveItem = false;
- QMatrix ma;
+ QTransform ma;
QPoint dp;
if ((LMode) && (CurItem->asLine()))
{
@@ -3451,7 +3451,7 @@
if ((HaveDoc) && (HaveItem))
{
double x,y,w,h, gx, gy, gh, gw, base;
- QMatrix ma;
+ QTransform ma;
x = Xpos->value() / m_unitRatio;
y = Ypos->value() / m_unitRatio;
w = Width->value() / m_unitRatio;
@@ -3532,7 +3532,7 @@
return;
double x,y,w,h, gx, gy, gh, gw, base;
- QMatrix ma;
+ QTransform ma;
x = Xpos->value() / m_unitRatio;
y = Ypos->value() / m_unitRatio;
w = Width->value() / m_unitRatio;
@@ -4432,7 +4432,7 @@
else
{
double b, h, r;
- QMatrix ma;
+ QTransform ma;
FPoint n;
b = CurItem->width();
h = CurItem->height();
Index: scribus/ui/charzoom.cpp
===================================================================
--- scribus/ui/charzoom.cpp (revision 13950)
+++ scribus/ui/charzoom.cpp (revision 13951)
@@ -25,7 +25,7 @@
ScPainter *p = new ScPainter(&pix, size, size);
p->clear();
pixm.fill(Qt::white);
- QMatrix chma;
+ QTransform chma;
chma.scale(4.8, 4.8);
uint gl = face.char2CMap(currentChar);
Index: scribus/canvasmode_rotate.cpp
===================================================================
--- scribus/canvasmode_rotate.cpp (revision 13950)
+++ scribus/canvasmode_rotate.cpp (revision 13951)
@@ -1,511 +1,511 @@
-/*
- For general Scribus (>=1.3.2) copyright and licensing information please refer
- to the COPYING file provided with the program. Following this notice may exist
- a copyright and/or license notice that predates the release of Scribus 1.3.2
- for which a new license (GPL+exception) is in place.
- */
-/***************************************************************************
-* *
-* This program is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-* *
-***************************************************************************/
-
-#include "canvasmode_rotate.h"
-
-#include <QMouseEvent>
-#include <QPainter>
-#include <QTimer>
-
-#include "canvas.h"
-#include "ui/contextmenu.h"
-#include "ui/scrspinbox.h"
-#include "fpoint.h"
-#include "pageitem.h"
-#include "ui/pageselector.h"
-#include "prefsmanager.h"
-#include "scribusdoc.h"
-#include "scribusview.h"
-#include "selection.h"
-#include "undomanager.h"
-#include "util_icon.h"
-#include "util_math.h"
-
-CanvasMode_Rotate::CanvasMode_Rotate(ScribusView* view) : CanvasMode(view)
-{
- m_canvasPressCoord.setXY(-1.0, -1.0);
- m_oldRotMode = 0;
- m_oldRotCenter = FPoint(0.0, 0.0);
- m_angleConstrained = false;
- m_inItemRotation = false;
-
- m_rotMode = 0;
- m_rotCenter = FPoint(0.0, 0.0);
- m_startAngle = 0.0;
-}
-
-inline bool CanvasMode_Rotate::GetItem(PageItem** pi)
-{
- *pi = m_doc->m_Selection->itemAt(0);
- return (*pi) != NULL;
-}
-
-void CanvasMode_Rotate::drawControls(QPainter* p)
-{
- drawSelection(p);
- if (m_inItemRotation)
- {
- drawItemOutlines(p);
- }
-}
-
-void CanvasMode_Rotate::drawItemOutlines(QPainter* p)
-{
- FPoint itemPos;
- double itemRotation;
-
- p->save();
- /*p->scale(m_canvas->scale(), m_canvas->scale());
- p->translate(-m_doc->minCanvasCoordinate.x(), -m_doc->minCanvasCoordinate.y());*/
-
- QColor drawColor = qApp->palette().color(QPalette::Active, QPalette::Highlight);
- p->setRenderHint(QPainter::Antialiasing);
- p->setBrush(Qt::NoBrush);
- p->setPen(QPen(drawColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
-
- uint docSelectionCount = m_doc->m_Selection->count();
- for (uint i = 0; i < docSelectionCount; ++i)
- {
- PageItem * currItem = m_doc->m_Selection->itemAt(i);
- getNewItemPosition(currItem, itemPos, itemRotation);
- p->save();
- p->translate(itemPos.x(), itemPos.y());
- p->rotate(itemRotation);
- currItem->DrawPolyL(p, currItem->Clip);
- p->restore();
- }
-
- p->restore();
-}
-
-void CanvasMode_Rotate::getNewItemPosition(PageItem* item, FPoint& pos, double& rotation)
-{
- double newAngle = xy2Deg(m_canvasCurrCoord.x() - m_rotCenter.x(), m_canvasCurrCoord.y() - m_rotCenter.y());
- if (m_angleConstrained)
- {
- newAngle = constrainAngle(newAngle, m_doc->toolSettings.constrain);
- /*double oldAngle = constrainAngle(m_startAngle, m_doc->toolSettings.constrain);
- newAngle = m_doc->m_Selection->isMultipleSelection() ? (newAngle - oldAngle) : newAngle;*/
- m_view->oldW = constrainAngle(m_view->oldW, m_doc->toolSettings.constrain);
- newAngle = m_doc->m_Selection->isMultipleSelection() ? (newAngle - m_view->oldW) : newAngle;
- }
- else if (m_doc->m_Selection->isMultipleSelection())
- newAngle = (newAngle - m_startAngle);
- else
- newAngle = item->rotation() - (m_startAngle - newAngle);
- if (m_doc->m_Selection->isMultipleSelection())
- {
- QMatrix ma;
- ma.translate(m_rotCenter.x(), m_rotCenter.y());
- ma.scale(1, 1);
- ma.rotate(newAngle);
- FPoint n(item->xPos() - m_rotCenter.x(), item->yPos() - m_rotCenter.y());
- pos.setXY(ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(), ma.m22() * n.y() + ma.m12() * n.x() + ma.dy());
- rotation = item->rotation() + newAngle;
- }
- else if (m_rotMode != 0)
- {
- FPoint n(0,0);
- QMatrix ma;
- ma.translate(item->xPos(), item->yPos());
- ma.scale(1, 1);
- ma.rotate(item->rotation());
- double ro = newAngle - item->rotation();
- switch (m_rotMode)
- {
- case 2:
- ma.translate(item->width()/2.0, item->height()/2.0);
- n = FPoint(-item->width()/2.0, -item->height()/2.0);
- break;
- case 4:
- ma.translate(item->width(), item->height());
- n = FPoint(-item->width(), -item->height());
- break;
- case 3:
- ma.translate(0, item->height());
- n = FPoint(0, -item->height());
- break;
- case 1:
- ma.translate(item->width(), 0);
- n = FPoint(-item->width(), 0);
- break;
- }
- ma.rotate(ro);
- pos.setXY(ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(), ma.m22() * n.y() + ma.m12() * n.x() + ma.dy());
- rotation = newAngle;
- }
- else
- {
- pos.setXY(item->xPos(), item->yPos());
- rotation = newAngle;
- }
-}
-
-void CanvasMode_Rotate::activate(bool fromGesture)
-{
- m_canvas->m_viewMode.m_MouseButtonPressed = false;
- m_canvas->resetRenderMode();
- m_doc->leaveDrag = false;
- m_view->MidButt = false;
- m_inItemRotation = false;
- m_canvasPressCoord.setXY(-1.0, -1.0);
- m_oldRotMode = m_rotMode = 0;
- m_oldRotCenter = m_rotCenter = FPoint(0.0, 0.0);
- m_startAngle = 0.0;
- setModeCursor();
- if (fromGesture)
- {
- m_canvas->m_viewMode.operItemResizeInEditMode = false;
- m_view->update();
- }
-}
-
-void CanvasMode_Rotate::deactivate(bool)
-{
- m_view->redrawMarker->hide();
- m_inItemRotation = false;
-}
-
-void CanvasMode_Rotate::enterEvent(QEvent *)
-{
- if (!m_canvas->m_viewMode.m_MouseButtonPressed)
- {
- setModeCursor();
- }
-}
-
-void CanvasMode_Rotate::leaveEvent(QEvent *)
-{
- if (!m_canvas->m_viewMode.m_MouseButtonPressed)
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
-}
-
-void CanvasMode_Rotate::mousePressEvent(QMouseEvent *m)
-{
- const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
- m_canvasPressCoord = mousePointDoc;
-
- double Rxp = 0, Ryp = 0;
- double Rxpd = 0, Rypd = 0;
- PageItem *currItem;
- m_canvas->PaintSizeRect(QRect());
- QRect tx;
- QMatrix pm;
- m_canvas->m_viewMode.m_MouseButtonPressed = true;
- m_canvas->m_viewMode.operItemMoving = false;
- m_view->HaveSelRect = false;
- m_doc->leaveDrag = false;
- m->accept();
- m_view->registerMousePress(m->globalPos());
- QRect mpo(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
- Rxp = m_doc->ApplyGridF(m_canvasPressCoord).x();
- Rxpd = m_canvasPressCoord.x() - Rxp;
- m_canvasPressCoord.setX( qRound(Rxp) );
- Ryp = m_doc->ApplyGridF(m_canvasPressCoord).y();
- Rypd = m_canvasPressCoord.y() - Ryp;
- m_canvasPressCoord.setY( qRound(Ryp) );
- if (m->button() == Qt::MidButton)
- {
- m_view->MidButt = true;
- if (m->modifiers() & Qt::ControlModifier)
- m_view->DrawNew();
- return;
- }
- if (m->button() != Qt::LeftButton)
- return;
- if (GetItem(&currItem))
- {
- m_inItemRotation = true;
- m_oldRotMode = m_rotMode = m_doc->RotMode();
- m_oldRotCenter = m_rotCenter = m_view->RCenter;
- if (m_doc->m_Selection->isMultipleSelection())
- {
- double gx, gy, gh, gw;
- double gxR, gyR, ghR, gwR;
- m_view->getGroupRectScreen(&gx, &gy, &gw, &gh);
- m_doc->m_Selection->getGroupRect(&gxR, &gyR, &gwR, &ghR);
- if (QRect(static_cast<int>(gx), static_cast<int>(gy), static_cast<int>(gw), static_cast<int>(gh)).intersects(mpo))
- {
- m_rotMode = 2;
- m_rotCenter = FPoint(gxR+gwR/2.0, gyR+ghR/2.0);
- if (QRect(static_cast<int>(gx+gw)-6, static_cast<int>(gy+gh)-6, 6, 6).intersects(mpo))
- {
- m_rotCenter = FPoint(gxR, gyR);
- m_rotMode = 0;
- }
- m_doc->RotMode ( m_rotMode );
- m_view->RCenter = m_rotCenter;
- }
- m_startAngle = xy2Deg(mousePointDoc.x() - m_view->RCenter.x(), mousePointDoc.y() - m_view->RCenter.y());
- m_view->oldW = m_startAngle;
- }
- else
- {
- QMatrix mat;
- m_canvas->Transform(currItem, mat);
- m_rotMode = 2;
- m_rotCenter = FPoint(currItem->width()/2, currItem->height()/2, 0, 0, currItem->rotation(), 1, 1, false);
-// if (!currItem->asLine())
-// {
- if (QRegion(mat.map(QPolygon(QRect(0, 0, static_cast<int>(currItem->width()), static_cast<int>(currItem->height()))))).contains(mpo))
- {
- if (mat.mapRect(QRect(0, 0, 6, 6)).intersects(mpo))
- {
- m_rotCenter = FPoint(currItem->width(), currItem->height(), 0, 0, currItem->rotation(), 1, 1, false);
- m_rotMode = 4;
- }
- else if (mat.mapRect(QRect(static_cast<int>(currItem->width())-6, 0, 6, 6)).intersects(mpo))
- {
- m_rotCenter = FPoint(0, currItem->height(), 0, 0, currItem->rotation(), 1, 1, false);
- m_rotMode = 3;
- }
- else if (mat.mapRect(QRect(static_cast<int>(currItem->width())-6, static_cast<int>(currItem->height())-6, 6, 6)).intersects(mpo))
- {
- m_rotCenter = FPoint(0, 0);
- m_rotMode = 0;
- }
- else if (mat.mapRect(QRect(0, static_cast<int>(currItem->height())-6, 6, 6)).intersects(mpo))
- {
- m_rotCenter = FPoint(currItem->width(), 0, 0, 0, currItem->rotation(), 1, 1, false);
- m_rotMode = 1;
- }
- }
- m_doc->RotMode ( m_rotMode );
- m_view->RCenter = m_rotCenter;
-// }
- m_view->RCenter = m_rotCenter = FPoint(currItem->xPos()+ m_view->RCenter.x(), currItem->yPos()+ m_view->RCenter.y()); //?????
- m_view->oldW = m_startAngle = xy2Deg(mousePointDoc.x() - m_view->RCenter.x(), mousePointDoc.y() - m_view->RCenter.y());
- }
- }
-}
-
-void CanvasMode_Rotate::mouseReleaseEvent(QMouseEvent *m)
-{
-#ifdef GESTURE_FRAME_PREVIEW
- clearPixmapCache();
-#endif // GESTURE_FRAME_PREVIEW
- const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
- PageItem *currItem;
- m_canvas->m_viewMode.m_MouseButtonPressed = false;
- m_canvas->resetRenderMode();
- m->accept();
-// m_view->stopDragTimer();
- if ((GetItem(&currItem)) && (m->button() == Qt::RightButton))
- {
- createContextMenu(currItem, mousePointDoc.x(), mousePointDoc.y());
- return;
- }
- m_inItemRotation = false;
- if (m_view->moveTimerElapsed() && (GetItem(&currItem)))
- {
-// m_view->stopDragTimer();
- //Always start group transaction as a rotate action is generally a combination of
- //a change of rotation + a change of position
- if (!m_view->groupTransactionStarted() /*&& m_doc->m_Selection->isMultipleSelection()*/)
- {
- m_view->startGroupTransaction(Um::Rotate, "", Um::IRotate);
- }
- double newW = xy2Deg(mousePointDoc.x()-m_view->RCenter.x(), mousePointDoc.y()-m_view->RCenter.y()); //xy2Deg(m->x()/sc - m_view->RCenter.x(), m->y()/sc - m_view->RCenter.y());
- if (m->modifiers() & Qt::ControlModifier)
- {
- newW=constrainAngle(newW, m_doc->toolSettings.constrain);
- m_view->oldW=constrainAngle(m_view->oldW, m_doc->toolSettings.constrain);
- //RotateGroup uses MoveBy so its pretty hard to constrain the result
- if (m_doc->m_Selection->isMultipleSelection())
- m_doc->rotateGroup(newW-m_view->oldW, m_view->RCenter);
- else
- m_doc->RotateItem(newW, currItem->ItemNr);
- }
- else
- {
- if (m_doc->m_Selection->isMultipleSelection())
- m_doc->rotateGroup(newW - m_view->oldW, m_view->RCenter);
- else
- m_doc->RotateItem(currItem->rotation() - (m_view->oldW - newW), currItem->ItemNr);
- }
- m_view->oldW = newW;
- m_canvas->setRenderModeUseBuffer(false);
- if (!m_doc->m_Selection->isMultipleSelection())
- {
- m_doc->setRedrawBounding(currItem);
- currItem->OwnPage = m_doc->OnPage(currItem);
- if (currItem->asLine())
- m_view->updateContents();
- }
- }
- m_doc->RotMode( m_oldRotMode );
- m_view->RCenter = m_oldRotCenter;
- if (!PrefsManager::instance()->appPrefs.stickyTools)
- m_view->requestMode(modeNormal);
- else
- {
- int appMode = m_doc->appMode;
- m_view->requestMode(appMode);
- }
- if (GetItem(&currItem))
- {
- if (m_doc->m_Selection->count() > 1)
- {
- m_doc->m_Selection->setGroupRect();
- double x, y, w, h;
- m_doc->m_Selection->getGroupRect(&x, &y, &w, &h);
- m_view->updateContents(QRect(static_cast<int>(x-5), static_cast<int>(y-5), static_cast<int>(w+10), static_cast<int>(h+10)));
- }
- // Handled normally automatically by Selection in sendSignals()
- /*else
- currItem->emitAllToGUI();*/
- }
- m_canvas->setRenderModeUseBuffer(false);
- m_doc->leaveDrag = false;
- m_view->MidButt = false;
- if (m_view->groupTransactionStarted())
- {
- for (int i = 0; i < m_doc->m_Selection->count(); ++i)
- m_doc->m_Selection->itemAt(i)->checkChanges(true);
- m_view->endGroupTransaction();
- }
- for (int i = 0; i < m_doc->m_Selection->count(); ++i)
- m_doc->m_Selection->itemAt(i)->checkChanges(true);
- //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas
- m_view->zoomSpinBox->clearFocus();
- m_view->pageSelector->clearFocus();
-}
-
-void CanvasMode_Rotate::mouseMoveEvent(QMouseEvent *m)
-{
- const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
- m_canvasCurrCoord = mousePointDoc;
- m_angleConstrained = false;
-
- double newX, newY;
- PageItem *currItem;
- QRect tx;
- m->accept();
-
- if (GetItem(&currItem))
- {
- newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
- newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
- m_angleConstrained = ((m->modifiers() & Qt::ControlModifier) != Qt::NoModifier);
- if (m_view->moveTimerElapsed() && m_canvas->m_viewMode.m_MouseButtonPressed)
- {
- m_canvas->repaint();
- double itemRotation;
- FPoint itemPos;
- getNewItemPosition(currItem, itemPos, itemRotation);
- m_canvas->displayRotHUD(m->globalPos(), itemRotation);
- }
- if (!m_canvas->m_viewMode.m_MouseButtonPressed)
- {
- if (m_doc->m_Selection->isMultipleSelection())
- {
- double gx, gy, gh, gw;
- m_doc->m_Selection->getVisualGroupRect(&gx, &gy, &gw, &gh);
- int how = m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), QRectF(gx, gy, gw, gh));
- if (how >= 0)
- {
- if (how > 0)
- {
- setResizeCursor(how);
- }
- qApp->changeOverrideCursor(QCursor(loadIcon("Rotieren2.png")));
- }
- else
- {
- setModeCursor();
- }
- return;
- }
- for (int a = 0; a < m_doc->m_Selection->count(); ++a)
- {
- currItem = m_doc->m_Selection->itemAt(a);
- if (currItem->locked())
- break;
- QMatrix p;
- m_canvas->Transform(currItem, p);
- QRect mpo = QRect(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
- if ((QRegion(p.map(QPolygon(QRect(-3, -3, static_cast<int>(currItem->width()+6), static_cast<int>(currItem->height()+6))))).contains(mpo)))
- {
- tx = p.mapRect(QRect(0, 0, static_cast<int>(currItem->width()), static_cast<int>(currItem->height())));
- if ((tx.intersects(mpo)) && (!currItem->locked()))
- {
- qApp->changeOverrideCursor(QCursor(loadIcon("Rotieren2.png")));
- if (!currItem->sizeLocked())
- m_view->HandleCurs(currItem, mpo);
- }
- }
- else
- {
-// setModeCursor();
- }
- }
- }
- }
- else
- {
- if ((m_canvas->m_viewMode.m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton))
- {
- newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
- newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
- QPoint startP = m_canvas->canvasToGlobal(m_canvasPressCoord);
- m_view->redrawMarker->setGeometry(QRect(startP, m->globalPos()).normalized());
- if (!m_view->redrawMarker->isVisible())
- m_view->redrawMarker->show();
- m_view->HaveSelRect = true;
- }
- }
-}
-
-void CanvasMode_Rotate::createContextMenu(PageItem* currItem, double mx, double my)
-{
- ContextMenu* cmen=NULL;
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- m_view->setObjectUndoMode();
- m_canvasPressCoord.setXY(mx, my);
- if(currItem!=NULL)
- cmen = new ContextMenu(*(m_doc->m_Selection), m_view->m_ScMW, m_doc);
- else
- cmen = new ContextMenu(m_view->m_ScMW, m_doc, mx, my);
- if (cmen)
- cmen->exec(QCursor::pos());
- m_view->setGlobalUndoMode();
- delete cmen;
-}
-
-// void CanvasMode_Rotate::setResizeCursor(int how)
-// {
-// switch (how)
-// {
-// case 1:
-// case 2:
-// qApp->changeOverrideCursor(QCursor(Qt::SizeFDiagCursor));
-// break;
-// case 3:
-// case 4:
-// qApp->changeOverrideCursor(QCursor(Qt::SizeBDiagCursor));
-// break;
-// case 5:
-// case 8:
-// qApp->changeOverrideCursor(QCursor(Qt::SizeVerCursor));
-// break;
-// case 6:
-// case 7:
-// qApp->changeOverrideCursor(QCursor(Qt::SizeHorCursor));
-// break;
-// default:
-// qApp->changeOverrideCursor(QCursor(Qt::SizeAllCursor));
-// break;
-// }
-// }
+/*
+ For general Scribus (>=1.3.2) copyright and licensing information please refer
+ to the COPYING file provided with the program. Following this notice may exist
+ a copyright and/or license notice that predates the release of Scribus 1.3.2
+ for which a new license (GPL+exception) is in place.
+ */
+/***************************************************************************
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+***************************************************************************/
+
+#include "canvasmode_rotate.h"
+
+#include <QMouseEvent>
+#include <QPainter>
+#include <QTimer>
+
+#include "canvas.h"
+#include "ui/contextmenu.h"
+#include "ui/scrspinbox.h"
+#include "fpoint.h"
+#include "pageitem.h"
+#include "ui/pageselector.h"
+#include "prefsmanager.h"
+#include "scribusdoc.h"
+#include "scribusview.h"
+#include "selection.h"
+#include "undomanager.h"
+#include "util_icon.h"
+#include "util_math.h"
+
+CanvasMode_Rotate::CanvasMode_Rotate(ScribusView* view) : CanvasMode(view)
+{
+ m_canvasPressCoord.setXY(-1.0, -1.0);
+ m_oldRotMode = 0;
+ m_oldRotCenter = FPoint(0.0, 0.0);
+ m_angleConstrained = false;
+ m_inItemRotation = false;
+
+ m_rotMode = 0;
+ m_rotCenter = FPoint(0.0, 0.0);
+ m_startAngle = 0.0;
+}
+
+inline bool CanvasMode_Rotate::GetItem(PageItem** pi)
+{
+ *pi = m_doc->m_Selection->itemAt(0);
+ return (*pi) != NULL;
+}
+
+void CanvasMode_Rotate::drawControls(QPainter* p)
+{
+ drawSelection(p);
+ if (m_inItemRotation)
+ {
+ drawItemOutlines(p);
+ }
+}
+
+void CanvasMode_Rotate::drawItemOutlines(QPainter* p)
+{
+ FPoint itemPos;
+ double itemRotation;
+
+ p->save();
+ /*p->scale(m_canvas->scale(), m_canvas->scale());
+ p->translate(-m_doc->minCanvasCoordinate.x(), -m_doc->minCanvasCoordinate.y());*/
+
+ QColor drawColor = qApp->palette().color(QPalette::Active, QPalette::Highlight);
+ p->setRenderHint(QPainter::Antialiasing);
+ p->setBrush(Qt::NoBrush);
+ p->setPen(QPen(drawColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
+
+ uint docSelectionCount = m_doc->m_Selection->count();
+ for (uint i = 0; i < docSelectionCount; ++i)
+ {
+ PageItem * currItem = m_doc->m_Selection->itemAt(i);
+ getNewItemPosition(currItem, itemPos, itemRotation);
+ p->save();
+ p->translate(itemPos.x(), itemPos.y());
+ p->rotate(itemRotation);
+ currItem->DrawPolyL(p, currItem->Clip);
+ p->restore();
+ }
+
+ p->restore();
+}
+
+void CanvasMode_Rotate::getNewItemPosition(PageItem* item, FPoint& pos, double& rotation)
+{
+ double newAngle = xy2Deg(m_canvasCurrCoord.x() - m_rotCenter.x(), m_canvasCurrCoord.y() - m_rotCenter.y());
+ if (m_angleConstrained)
+ {
+ newAngle = constrainAngle(newAngle, m_doc->toolSettings.constrain);
+ /*double oldAngle = constrainAngle(m_startAngle, m_doc->toolSettings.constrain);
+ newAngle = m_doc->m_Selection->isMultipleSelection() ? (newAngle - oldAngle) : newAngle;*/
+ m_view->oldW = constrainAngle(m_view->oldW, m_doc->toolSettings.constrain);
+ newAngle = m_doc->m_Selection->isMultipleSelection() ? (newAngle - m_view->oldW) : newAngle;
+ }
+ else if (m_doc->m_Selection->isMultipleSelection())
+ newAngle = (newAngle - m_startAngle);
+ else
+ newAngle = item->rotation() - (m_startAngle - newAngle);
+ if (m_doc->m_Selection->isMultipleSelection())
+ {
+ QTransform ma;
+ ma.translate(m_rotCenter.x(), m_rotCenter.y());
+ ma.scale(1, 1);
+ ma.rotate(newAngle);
+ FPoint n(item->xPos() - m_rotCenter.x(), item->yPos() - m_rotCenter.y());
+ pos.setXY(ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(), ma.m22() * n.y() + ma.m12() * n.x() + ma.dy());
+ rotation = item->rotation() + newAngle;
+ }
+ else if (m_rotMode != 0)
+ {
+ FPoint n(0,0);
+ QTransform ma;
+ ma.translate(item->xPos(), item->yPos());
+ ma.scale(1, 1);
+ ma.rotate(item->rotation());
+ double ro = newAngle - item->rotation();
+ switch (m_rotMode)
+ {
+ case 2:
+ ma.translate(item->width()/2.0, item->height()/2.0);
+ n = FPoint(-item->width()/2.0, -item->height()/2.0);
+ break;
+ case 4:
+ ma.translate(item->width(), item->height());
+ n = FPoint(-item->width(), -item->height());
+ break;
+ case 3:
+ ma.translate(0, item->height());
+ n = FPoint(0, -item->height());
+ break;
+ case 1:
+ ma.translate(item->width(), 0);
+ n = FPoint(-item->width(), 0);
+ break;
+ }
+ ma.rotate(ro);
+ pos.setXY(ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(), ma.m22() * n.y() + ma.m12() * n.x() + ma.dy());
+ rotation = newAngle;
+ }
+ else
+ {
+ pos.setXY(item->xPos(), item->yPos());
+ rotation = newAngle;
+ }
+}
+
+void CanvasMode_Rotate::activate(bool fromGesture)
+{
+ m_canvas->m_viewMode.m_MouseButtonPressed = false;
+ m_canvas->resetRenderMode();
+ m_doc->leaveDrag = false;
+ m_view->MidButt = false;
+ m_inItemRotation = false;
+ m_canvasPressCoord.setXY(-1.0, -1.0);
+ m_oldRotMode = m_rotMode = 0;
+ m_oldRotCenter = m_rotCenter = FPoint(0.0, 0.0);
+ m_startAngle = 0.0;
+ setModeCursor();
+ if (fromGesture)
+ {
+ m_canvas->m_viewMode.operItemResizeInEditMode = false;
+ m_view->update();
+ }
+}
+
+void CanvasMode_Rotate::deactivate(bool)
+{
+ m_view->redrawMarker->hide();
+ m_inItemRotation = false;
+}
+
+void CanvasMode_Rotate::enterEvent(QEvent *)
+{
+ if (!m_canvas->m_viewMode.m_MouseButtonPressed)
+ {
+ setModeCursor();
+ }
+}
+
+void CanvasMode_Rotate::leaveEvent(QEvent *)
+{
+ if (!m_canvas->m_viewMode.m_MouseButtonPressed)
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+}
+
+void CanvasMode_Rotate::mousePressEvent(QMouseEvent *m)
+{
+ const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+ m_canvasPressCoord = mousePointDoc;
+
+ double Rxp = 0, Ryp = 0;
+ double Rxpd = 0, Rypd = 0;
+ PageItem *currItem;
+ m_canvas->PaintSizeRect(QRect());
+ QRect tx;
+ QTransform pm;
+ m_canvas->m_viewMode.m_MouseButtonPressed = true;
+ m_canvas->m_viewMode.operItemMoving = false;
+ m_view->HaveSelRect = false;
+ m_doc->leaveDrag = false;
+ m->accept();
+ m_view->registerMousePress(m->globalPos());
+ QRect mpo(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
+ Rxp = m_doc->ApplyGridF(m_canvasPressCoord).x();
+ Rxpd = m_canvasPressCoord.x() - Rxp;
+ m_canvasPressCoord.setX( qRound(Rxp) );
+ Ryp = m_doc->ApplyGridF(m_canvasPressCoord).y();
+ Rypd = m_canvasPressCoord.y() - Ryp;
+ m_canvasPressCoord.setY( qRound(Ryp) );
+ if (m->button() == Qt::MidButton)
+ {
+ m_view->MidButt = true;
+ if (m->modifiers() & Qt::ControlModifier)
+ m_view->DrawNew();
+ return;
+ }
+ if (m->button() != Qt::LeftButton)
+ return;
+ if (GetItem(&currItem))
+ {
+ m_inItemRotation = true;
+ m_oldRotMode = m_rotMode = m_doc->RotMode();
+ m_oldRotCenter = m_rotCenter = m_view->RCenter;
+ if (m_doc->m_Selection->isMultipleSelection())
+ {
+ double gx, gy, gh, gw;
+ double gxR, gyR, ghR, gwR;
+ m_view->getGroupRectScreen(&gx, &gy, &gw, &gh);
+ m_doc->m_Selection->getGroupRect(&gxR, &gyR, &gwR, &ghR);
+ if (QRect(static_cast<int>(gx), static_cast<int>(gy), static_cast<int>(gw), static_cast<int>(gh)).intersects(mpo))
+ {
+ m_rotMode = 2;
+ m_rotCenter = FPoint(gxR+gwR/2.0, gyR+ghR/2.0);
+ if (QRect(static_cast<int>(gx+gw)-6, static_cast<int>(gy+gh)-6, 6, 6).intersects(mpo))
+ {
+ m_rotCenter = FPoint(gxR, gyR);
+ m_rotMode = 0;
+ }
+ m_doc->RotMode ( m_rotMode );
+ m_view->RCenter = m_rotCenter;
+ }
+ m_startAngle = xy2Deg(mousePointDoc.x() - m_view->RCenter.x(), mousePointDoc.y() - m_view->RCenter.y());
+ m_view->oldW = m_startAngle;
+ }
+ else
+ {
+ QTransform mat;
+ m_canvas->Transform(currItem, mat);
+ m_rotMode = 2;
+ m_rotCenter = FPoint(currItem->width()/2, currItem->height()/2, 0, 0, currItem->rotation(), 1, 1, false);
+// if (!currItem->asLine())
+// {
+ if (QRegion(mat.map(QPolygon(QRect(0, 0, static_cast<int>(currItem->width()), static_cast<int>(currItem->height()))))).contains(mpo))
+ {
+ if (mat.mapRect(QRect(0, 0, 6, 6)).intersects(mpo))
+ {
+ m_rotCenter = FPoint(currItem->width(), currItem->height(), 0, 0, currItem->rotation(), 1, 1, false);
+ m_rotMode = 4;
+ }
+ else if (mat.mapRect(QRect(static_cast<int>(currItem->width())-6, 0, 6, 6)).intersects(mpo))
+ {
+ m_rotCenter = FPoint(0, currItem->height(), 0, 0, currItem->rotation(), 1, 1, false);
+ m_rotMode = 3;
+ }
+ else if (mat.mapRect(QRect(static_cast<int>(currItem->width())-6, static_cast<int>(currItem->height())-6, 6, 6)).intersects(mpo))
+ {
+ m_rotCenter = FPoint(0, 0);
+ m_rotMode = 0;
+ }
+ else if (mat.mapRect(QRect(0, static_cast<int>(currItem->height())-6, 6, 6)).intersects(mpo))
+ {
+ m_rotCenter = FPoint(currItem->width(), 0, 0, 0, currItem->rotation(), 1, 1, false);
+ m_rotMode = 1;
+ }
+ }
+ m_doc->RotMode ( m_rotMode );
+ m_view->RCenter = m_rotCenter;
+// }
+ m_view->RCenter = m_rotCenter = FPoint(currItem->xPos()+ m_view->RCenter.x(), currItem->yPos()+ m_view->RCenter.y()); //?????
+ m_view->oldW = m_startAngle = xy2Deg(mousePointDoc.x() - m_view->RCenter.x(), mousePointDoc.y() - m_view->RCenter.y());
+ }
+ }
+}
+
+void CanvasMode_Rotate::mouseReleaseEvent(QMouseEvent *m)
+{
+#ifdef GESTURE_FRAME_PREVIEW
+ clearPixmapCache();
+#endif // GESTURE_FRAME_PREVIEW
+ const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+ PageItem *currItem;
+ m_canvas->m_viewMode.m_MouseButtonPressed = false;
+ m_canvas->resetRenderMode();
+ m->accept();
+// m_view->stopDragTimer();
+ if ((GetItem(&currItem)) && (m->button() == Qt::RightButton))
+ {
+ createContextMenu(currItem, mousePointDoc.x(), mousePointDoc.y());
+ return;
+ }
+ m_inItemRotation = false;
+ if (m_view->moveTimerElapsed() && (GetItem(&currItem)))
+ {
+// m_view->stopDragTimer();
+ //Always start group transaction as a rotate action is generally a combination of
+ //a change of rotation + a change of position
+ if (!m_view->groupTransactionStarted() /*&& m_doc->m_Selection->isMultipleSelection()*/)
+ {
+ m_view->startGroupTransaction(Um::Rotate, "", Um::IRotate);
+ }
+ double newW = xy2Deg(mousePointDoc.x()-m_view->RCenter.x(), mousePointDoc.y()-m_view->RCenter.y()); //xy2Deg(m->x()/sc - m_view->RCenter.x(), m->y()/sc - m_view->RCenter.y());
+ if (m->modifiers() & Qt::ControlModifier)
+ {
+ newW=constrainAngle(newW, m_doc->toolSettings.constrain);
+ m_view->oldW=constrainAngle(m_view->oldW, m_doc->toolSettings.constrain);
+ //RotateGroup uses MoveBy so its pretty hard to constrain the result
+ if (m_doc->m_Selection->isMultipleSelection())
+ m_doc->rotateGroup(newW-m_view->oldW, m_view->RCenter);
+ else
+ m_doc->RotateItem(newW, currItem->ItemNr);
+ }
+ else
+ {
+ if (m_doc->m_Selection->isMultipleSelection())
+ m_doc->rotateGroup(newW - m_view->oldW, m_view->RCenter);
+ else
+ m_doc->RotateItem(currItem->rotation() - (m_view->oldW - newW), currItem->ItemNr);
+ }
+ m_view->oldW = newW;
+ m_canvas->setRenderModeUseBuffer(false);
+ if (!m_doc->m_Selection->isMultipleSelection())
+ {
+ m_doc->setRedrawBounding(currItem);
+ currItem->OwnPage = m_doc->OnPage(currItem);
+ if (currItem->asLine())
+ m_view->updateContents();
+ }
+ }
+ m_doc->RotMode( m_oldRotMode );
+ m_view->RCenter = m_oldRotCenter;
+ if (!PrefsManager::instance()->appPrefs.stickyTools)
+ m_view->requestMode(modeNormal);
+ else
+ {
+ int appMode = m_doc->appMode;
+ m_view->requestMode(appMode);
+ }
+ if (GetItem(&currItem))
+ {
+ if (m_doc->m_Selection->count() > 1)
+ {
+ m_doc->m_Selection->setGroupRect();
+ double x, y, w, h;
+ m_doc->m_Selection->getGroupRect(&x, &y, &w, &h);
+ m_view->updateContents(QRect(static_cast<int>(x-5), static_cast<int>(y-5), static_cast<int>(w+10), static_cast<int>(h+10)));
+ }
+ // Handled normally automatically by Selection in sendSignals()
+ /*else
+ currItem->emitAllToGUI();*/
+ }
+ m_canvas->setRenderModeUseBuffer(false);
+ m_doc->leaveDrag = false;
+ m_view->MidButt = false;
+ if (m_view->groupTransactionStarted())
+ {
+ for (int i = 0; i < m_doc->m_Selection->count(); ++i)
+ m_doc->m_Selection->itemAt(i)->checkChanges(true);
+ m_view->endGroupTransaction();
+ }
+ for (int i = 0; i < m_doc->m_Selection->count(); ++i)
+ m_doc->m_Selection->itemAt(i)->checkChanges(true);
+ //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas
+ m_view->zoomSpinBox->clearFocus();
+ m_view->pageSelector->clearFocus();
+}
+
+void CanvasMode_Rotate::mouseMoveEvent(QMouseEvent *m)
+{
+ const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+ m_canvasCurrCoord = mousePointDoc;
+ m_angleConstrained = false;
+
+ double newX, newY;
+ PageItem *currItem;
+ QRect tx;
+ m->accept();
+
+ if (GetItem(&currItem))
+ {
+ newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
+ newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
+ m_angleConstrained = ((m->modifiers() & Qt::ControlModifier) != Qt::NoModifier);
+ if (m_view->moveTimerElapsed() && m_canvas->m_viewMode.m_MouseButtonPressed)
+ {
+ m_canvas->repaint();
+ double itemRotation;
+ FPoint itemPos;
+ getNewItemPosition(currItem, itemPos, itemRotation);
+ m_canvas->displayRotHUD(m->globalPos(), itemRotation);
+ }
+ if (!m_canvas->m_viewMode.m_MouseButtonPressed)
+ {
+ if (m_doc->m_Selection->isMultipleSelection())
+ {
+ double gx, gy, gh, gw;
+ m_doc->m_Selection->getVisualGroupRect(&gx, &gy, &gw, &gh);
+ int how = m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), QRectF(gx, gy, gw, gh));
+ if (how >= 0)
+ {
+ if (how > 0)
+ {
+ setResizeCursor(how);
+ }
+ qApp->changeOverrideCursor(QCursor(loadIcon("Rotieren2.png")));
+ }
+ else
+ {
+ setModeCursor();
+ }
+ return;
+ }
+ for (int a = 0; a < m_doc->m_Selection->count(); ++a)
+ {
+ currItem = m_doc->m_Selection->itemAt(a);
+ if (currItem->locked())
+ break;
+ QTransform p;
+ m_canvas->Transform(currItem, p);
+ QRect mpo = QRect(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
+ if ((QRegion(p.map(QPolygon(QRect(-3, -3, static_cast<int>(currItem->width()+6), static_cast<int>(currItem->height()+6))))).contains(mpo)))
+ {
+ tx = p.mapRect(QRect(0, 0, static_cast<int>(currItem->width()), static_cast<int>(currItem->height())));
+ if ((tx.intersects(mpo)) && (!currItem->locked()))
+ {
+ qApp->changeOverrideCursor(QCursor(loadIcon("Rotieren2.png")));
+ if (!currItem->sizeLocked())
+ m_view->HandleCurs(currItem, mpo);
+ }
+ }
+ else
+ {
+// setModeCursor();
+ }
+ }
+ }
+ }
+ else
+ {
+ if ((m_canvas->m_viewMode.m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton))
+ {
+ newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
+ newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
+ QPoint startP = m_canvas->canvasToGlobal(m_canvasPressCoord);
+ m_view->redrawMarker->setGeometry(QRect(startP, m->globalPos()).normalized());
+ if (!m_view->redrawMarker->isVisible())
+ m_view->redrawMarker->show();
+ m_view->HaveSelRect = true;
+ }
+ }
+}
+
+void CanvasMode_Rotate::createContextMenu(PageItem* currItem, double mx, double my)
+{
+ ContextMenu* cmen=NULL;
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ m_view->setObjectUndoMode();
+ m_canvasPressCoord.setXY(mx, my);
+ if(currItem!=NULL)
+ cmen = new ContextMenu(*(m_doc->m_Selection), m_view->m_ScMW, m_doc);
+ else
+ cmen = new ContextMenu(m_view->m_ScMW, m_doc, mx, my);
+ if (cmen)
+ cmen->exec(QCursor::pos());
+ m_view->setGlobalUndoMode();
+ delete cmen;
+}
+
+// void CanvasMode_Rotate::setResizeCursor(int how)
+// {
+// switch (how)
+// {
+// case 1:
+// case 2:
+// qApp->changeOverrideCursor(QCursor(Qt::SizeFDiagCursor));
+// break;
+// case 3:
+// case 4:
+// qApp->changeOverrideCursor(QCursor(Qt::SizeBDiagCursor));
+// break;
+// case 5:
+// case 8:
+// qApp->changeOverrideCursor(QCursor(Qt::SizeVerCursor));
+// break;
+// case 6:
+// case 7:
+// qApp->changeOverrideCursor(QCursor(Qt::SizeHorCursor));
+// break;
+// default:
+// qApp->changeOverrideCursor(QCursor(Qt::SizeAllCursor));
+// break;
+// }
+// }
Index: scribus/pageitem_imageframe.cpp
===================================================================
--- scribus/pageitem_imageframe.cpp (revision 13950)
+++ scribus/pageitem_imageframe.cpp (revision 13951)
@@ -267,7 +267,7 @@
if (imageClip.size() != 0)
{
imageClip = pixm.imgInfo.PDSpathData[pixm.imgInfo.usedPath].copy();
- QMatrix cl;
+ QTransform cl;
cl.translate(imageXOffset()*imageXScale(), imageYOffset()*imageYScale());
cl.scale(imageXScale(), imageYScale());
imageClip.map(cl);
Index: scribus/scpainterex_gdi.cpp
===================================================================
--- scribus/scpainterex_gdi.cpp (revision 13950)
+++ scribus/scpainterex_gdi.cpp (revision 13951)
@@ -72,7 +72,7 @@
m_lineJoin = Qt::RoundJoin;
m_fillGradient = VGradientEx(VGradientEx::linear);
m_strokeGradient = VGradientEx(VGradientEx::linear);
- m_matrix = QMatrix();
+ m_matrix = QTransform();
// Grayscale conversion parameter
m_convertToGray = gray;
// Initialization of Windows GDI data
@@ -179,12 +179,12 @@
DeleteObject( brush );
}
-const QMatrix ScPainterEx_GDI::worldMatrix()
+const QTransform ScPainterEx_GDI::worldMatrix()
{
return m_matrix;
}
-void ScPainterEx_GDI::setWorldMatrix( const QMatrix &mat )
+void ScPainterEx_GDI::setWorldMatrix( const QTransform &mat )
{
m_matrix = mat;
}
@@ -279,7 +279,7 @@
m_fillGradient.setFocalPoint(foc);
}
-void ScPainterEx_GDI::setPattern( ScPattern* pattern, QMatrix& patternTransform )
+void ScPainterEx_GDI::setPattern( ScPattern* pattern, QTransform& patternTransform )
{
m_pattern = pattern;
m_patternTransform = patternTransform;
Index: scribus/scribus.cpp
===================================================================
--- scribus/scribus.cpp (revision 13950)
+++ scribus/scribus.cpp (revision 13951)
@@ -2413,7 +2413,8 @@
{
if (w == NULL)
{
- ActWin = NULL;
+ if ( wsp->subWindowList().count() == 0)
+ ActWin = NULL;
return;
}
if (doc!=0 && doc->appMode == modeEditClip)
Index: scribus/plugins/cvgimplugin/importcvg.h
===================================================================
--- scribus/plugins/cvgimplugin/importcvg.h (revision 13950)
+++ scribus/plugins/cvgimplugin/importcvg.h (revision 13951)
@@ -16,7 +16,7 @@
#include "sccolor.h"
#include "fpointarray.h"
#include <QList>
-#include <QMatrix>
+#include <QTransform>
#include <QMultiMap>
class MultiProgressDialog;
Index: scribus/plugins/wmfimplugin/wmfcontext.cpp
===================================================================
--- scribus/plugins/wmfimplugin/wmfcontext.cpp (revision 13950)
+++ scribus/plugins/wmfimplugin/wmfcontext.cpp (revision 13951)
@@ -55,7 +55,7 @@
double yscale = (windowExt.height() != 0.0) ? (viewportExt.height() / windowExt.height()) : 1.0;
double dx = viewportOrg.x() - xscale * windowOrg.x();
double dy = viewportOrg.y() - yscale * windowOrg.y();
- worldMatrix.setMatrix( xscale, 0, 0, yscale, dx, dy );
+ worldMatrix = QTransform( xscale, 0.0, 0.0, yscale, dx, dy );
}
WMFContext::WMFContext(void)
Index: scribus/plugins/wmfimplugin/wmfcontext.h
===================================================================
--- scribus/plugins/wmfimplugin/wmfcontext.h (revision 13950)
+++ scribus/plugins/wmfimplugin/wmfcontext.h (revision 13951)
@@ -1,107 +1,107 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-#ifndef WMFCONTEXT_H
-#define WMFCONTEXT_H
-
-#include <QBrush>
-#include <QFont>
-#include <QMatrix>
-#include <QPen>
-#include <QPoint>
-#include <QSize>
-#include <QStack>
-#include "fpointarray.h"
-
-class WMFGraphicsState
-{
-protected:
-
- QPointF windowOrg;
- QSizeF windowExt;
- QPointF viewportOrg;
- QSizeF viewportExt;
-
- void updateWorldMatrix(void);
-
-public:
- QFont font;
- QPoint position;
- QPen pen;
- QBrush brush;
- QColor backgroundColor;
- Qt::BGMode backgroundMode;
- QColor textColor;
- int textAlign;
- int textCharset;
- double textRotation;
- bool windingFill;
- FPointArray path;
- QMatrix worldMatrix;
-
-public:
- WMFGraphicsState(void);
-
- void setWindowOrg(double x, double y);
- void setWindowExt(double x, double y);
- void setViewportOrg(double x, double y);
- void setViewportExt(double x, double y);
-};
-
-class WMFContext : public QStack<WMFGraphicsState>
-{
-public:
-
- WMFContext(void);
-
- void save(void);
- void restore(void);
- void reset(void);
-
- WMFGraphicsState& current(void);
-
- QFont font(void) { return current().font; }
- QPoint position(void) { return current().position; }
- QPen pen(void) { return current().pen; }
- QBrush brush(void) { return current().brush; }
- QColor backgroundColor(void) { return current().backgroundColor; }
- Qt::BGMode backgroundMode(void) { return current().backgroundMode; }
- QColor textColor(void) { return current().textColor; }
- int textAlign(void) { return current().textAlign; }
- int textCharSet(void) { return current().textCharset; }
- double textRotation(void) { return current().textRotation; }
- bool windingFill(void) { return current().windingFill; }
- FPointArray& path (void) { return current().path; }
- QMatrix& worldMatrix (void) { return current().worldMatrix; }
- void setFont (const QFont& font) { current().font = font; }
- void setPosition (const QPoint& pos) { current().position = pos; }
- void setPen (const QPen& pen) { current().pen = pen; }
- void setBrush (const QBrush& brush) { current().brush = brush; }
- void setBackgroundColor (const QColor& color) { current().backgroundColor = color; }
- void setBackgroundMode (const Qt::BGMode& mode) { current().backgroundMode = mode; }
- void setTextColor (const QColor& color) { current().textColor = color; }
- void setTextAlign (int align) { current().textAlign = align; }
- void setTextCharset(int align) { current().textCharset = align; }
- void setTextRotation (double rot) { current().textRotation = rot; }
- void setWindingFill (const bool winding) { current().windingFill = winding; }
- void setPath (const FPointArray& path) { current().path = path; }
- void setWorldMatrix (const QMatrix& matrix) { current().worldMatrix = matrix; }
-
- // window operations
- void setWindowOrg(double x, double y) { current().setWindowOrg(x, y); }
- void setWindowExt(double x, double y) { current().setWindowExt(x, y); }
- void setViewportOrg(double x, double y) { current().setViewportOrg(x, y); }
- void setViewportExt(double x, double y) { current().setViewportExt(x, y); }
-
- // matrix operations
- void translate (double x, double y) { current().worldMatrix.translate(x, y); }
- void scale (double x, double y) { current().worldMatrix.scale(x, y); }
- void rotate (double deg) { current().worldMatrix.rotate(deg); }
-};
-
-
-#endif
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#ifndef WMFCONTEXT_H
+#define WMFCONTEXT_H
+
+#include <QBrush>
+#include <QFont>
+#include <QTransform>
+#include <QPen>
+#include <QPoint>
+#include <QSize>
+#include <QStack>
+#include "fpointarray.h"
+
+class WMFGraphicsState
+{
+protected:
+
+ QPointF windowOrg;
+ QSizeF windowExt;
+ QPointF viewportOrg;
+ QSizeF viewportExt;
+
+ void updateWorldMatrix(void);
+
+public:
+ QFont font;
+ QPoint position;
+ QPen pen;
+ QBrush brush;
+ QColor backgroundColor;
+ Qt::BGMode backgroundMode;
+ QColor textColor;
+ int textAlign;
+ int textCharset;
+ double textRotation;
+ bool windingFill;
+ FPointArray path;
+ QTransform worldMatrix;
+
+public:
+ WMFGraphicsState(void);
+
+ void setWindowOrg(double x, double y);
+ void setWindowExt(double x, double y);
+ void setViewportOrg(double x, double y);
+ void setViewportExt(double x, double y);
+};
+
+class WMFContext : public QStack<WMFGraphicsState>
+{
+public:
+
+ WMFContext(void);
+
+ void save(void);
+ void restore(void);
+ void reset(void);
+
+ WMFGraphicsState& current(void);
+
+ QFont font(void) { return current().font; }
+ QPoint position(void) { return current().position; }
+ QPen pen(void) { return current().pen; }
+ QBrush brush(void) { return current().brush; }
+ QColor backgroundColor(void) { return current().backgroundColor; }
+ Qt::BGMode backgroundMode(void) { return current().backgroundMode; }
+ QColor textColor(void) { return current().textColor; }
+ int textAlign(void) { return current().textAlign; }
+ int textCharSet(void) { return current().textCharset; }
+ double textRotation(void) { return current().textRotation; }
+ bool windingFill(void) { return current().windingFill; }
+ FPointArray& path (void) { return current().path; }
+ QTransform& worldMatrix (void) { return current().worldMatrix; }
+ void setFont (const QFont& font) { current().font = font; }
+ void setPosition (const QPoint& pos) { current().position = pos; }
+ void setPen (const QPen& pen) { current().pen = pen; }
+ void setBrush (const QBrush& brush) { current().brush = brush; }
+ void setBackgroundColor (const QColor& color) { current().backgroundColor = color; }
+ void setBackgroundMode (const Qt::BGMode& mode) { current().backgroundMode = mode; }
+ void setTextColor (const QColor& color) { current().textColor = color; }
+ void setTextAlign (int align) { current().textAlign = align; }
+ void setTextCharset(int align) { current().textCharset = align; }
+ void setTextRotation (double rot) { current().textRotation = rot; }
+ void setWindingFill (const bool winding) { current().windingFill = winding; }
+ void setPath (const FPointArray& path) { current().path = path; }
+ void setWorldMatrix (const QTransform& matrix) { current().worldMatrix = matrix; }
+
+ // window operations
+ void setWindowOrg(double x, double y) { current().setWindowOrg(x, y); }
+ void setWindowExt(double x, double y) { current().setWindowExt(x, y); }
+ void setViewportOrg(double x, double y) { current().setViewportOrg(x, y); }
+ void setViewportExt(double x, double y) { current().setViewportExt(x, y); }
+
+ // matrix operations
+ void translate (double x, double y) { current().worldMatrix.translate(x, y); }
+ void scale (double x, double y) { current().worldMatrix.scale(x, y); }
+ void rotate (double deg) { current().worldMatrix.rotate(deg); }
+};
+
+
+#endif
Index: scribus/plugins/wmfimplugin/wmfimport.cpp
===================================================================
--- scribus/plugins/wmfimplugin/wmfimport.cpp (revision 13950)
+++ scribus/plugins/wmfimplugin/wmfimport.cpp (revision 13951)
@@ -1,1474 +1,1474 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-/* Code inspired by KOffice libwmf and adapted for Scribus by Jean Ghali */
-
-#include "scconfig.h"
-#include "wmfimport.h"
-
-#include <QCursor>
-#include <QDrag>
-#include <QBuffer>
-#include <QDataStream>
-#include <QFile>
-#include <QMimeData>
-#include <QPainterPath>
-#include <QRegExp>
-
-#include "ui/customfdialog.h"
-#include "scribus.h"
-#include "scribusXml.h"
-#include "ui/propertiespalette.h"
-#include "prefsfile.h"
-
-#include <cmath>
-#include "commonstrings.h"
-#include "fpointarray.h"
-#include "menumanager.h"
-#include "prefsmanager.h"
-#include "pageitem.h"
-#include "scmimedata.h"
-#include "scraction.h"
-#include "scribuscore.h"
-#include "scribusdoc.h"
-#include "selection.h"
-#include "undomanager.h"
-#include "loadsaveplugin.h"
-#include "util.h"
-#include "util_icon.h"
-#include "util_math.h"
-#include "fonts/scfontmetrics.h"
-
-using namespace std;
-
-#include "wmfstruct.h"
-#include "wmfcmd.h"
-#include "wmfcontext.h"
-#include "wmfhandle.h"
-#include "metafuncs.h"
-
-#define WMFIMPORT_DEBUG 0
-#define MAX_OBJHANDLE 128
-
-#define ANSI_CHARSET 0 // ANSI charset (Windows-1252)
-#define DEFAULT_CHARSET 1
-#define SYMBOL_CHARSET 2
-#define MAC_CHARSET 77
-#define SHIFTJIS_CHARSET 128 // Shift JIS charset (Windows-932)
-#define HANGEUL_CHARSET 129 // Hangeul charset (Windows-949)
-#define JOHAB_CHARSET 130 // Johab charset (Windows-1361)
-#define GB2312_CHARSET 134 // GB2312 charset (Windows-936)
-#define CHINESEBIG5_CHARSET 136 // Chinese Big5 charset (Windows-950)
-#define GREEK_CHARSET 161 // Greek charset (Windows-1253)
-#define TURKISH_CHARSET 162 // Turkish charset (Windows-1254)
-#define VIETNAMESE_CHARSET 163 // Vietnamese charset (Windows-1258)
-#define HEBREW_CHARSET 177 // Hebrew charset (Windows-1255)
-#define ARABIC_CHARSET 178 // Arabic charset (Windows-1256)
-#define BALTIC_CHARSET 186 // Baltic charset (Windows-1257)
-#define RUSSIAN_CHARSET 204 // Cyrillic charset (Windows-1251)
-#define THAI_CHARSET 222 // Thai charset (Windows-874)
-#define EASTEUROPE_CHARSET 238 // Eastern european charset (Windows-1250)
-#define OEM_CHARSET 255
-
-/* Symbol to unicode conversion table copied from http://root.cern.ch/viewvc/trunk/qt/src/TQtSymbolCodec.cxx
-This code is placed under GPL licence (http://root.cern.ch/viewvc/trunk/LICENSE) */
-static const ushort greek_symbol_to_unicode[64] = {
-//
-// upper case letters:
-// ----------------
-// Alpha Beta Chi Delta Epsilon Phi Gamma Eta
- 0x0391, 0x0392, 0x03A7, 0x0394, 0x0395, 0x03A6, 0x0393, 0x0397,
-// Iota Theta(S) Kappa Lambda Mu Nu Omicron Pi
- 0x0399, 0x03D1, 0x039A, 0x039B, 0x039C, 0x039D, 0x039F, 0x03A0,
-// Theta Rho Sigma Tau Upsilon Stigma Omega Xi
- 0x0398, 0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03DB, 0x03A9, 0x039E,
-// Psi Zeta Sigma Tau Upsilon ???? Omega Xi
- 0x03A8, 0x0396, 0x03EA, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
-//
-// lower case letters:
-// ----------------
-// Alpha Beta Chi Delta Epsilon Phi Gamma Eta
- 0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x03B5, 0x03D5, 0x03B3, 0x03B7,
-// Iota Phi (2) Kappa Lambda Mu Nu Omicron Pi
- 0x03B9, 0x03C6, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF, 0x03C0,
-// Theta Rho Sigma Tau Upsilon OmegaPi Omega Xi
- 0x03B8, 0x03C1, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03B9, 0x03BE,
-// Psi Zeta Sigma Tau Upsilon ???? Omega Xi
- 0x03C8, 0x03B6, 0x03EA, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD
-};
-
-/* Symbol to unicode conversion table copied from http://root.cern.ch/viewvc/trunk/qt/src/TQtSymbolCodec.cxx
-This code is placed under GPL licence (http://root.cern.ch/viewvc/trunk/LICENSE) */
-static const ushort symbol_to_unicode[96] = {
-//
-// upper case letters:
-// ----------------
-// UPSILON NUMBER LessEq Div INFINITY ??????? CLUB DIAMOND
- 0x03D2, 0x0374, 0x2264, 0x2215, 0x221E, 0x0395, 0x2663, 0x2666,
-// HEART SPADE <---> <--- --> RING
- 0x2665, 0x2660, 0x2194, 0x2190, 0x2191, 0x2192, 0x2193, 0x2218,
-// Theta Rho Great ???? Propor diff bullet ????
- 0x0398, 0x03A1, 0x2265, 0x03A4, 0x221D, 0x2202, 0x2219, 0x03A8,
-// NonEq Ident ???? ellips div minus ????? aleph
- 0x2260, 0x2261, 0xFFFD, 0x22EF, 0x2223, 0x2212, 0xFFFD, 0xFFFD,
-//
-// lower case letters:
-// ----------------
-// Alpha Beta Chi Delta Epsilon Phi Gamma Eta
- 0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x03B5, 0x03D5, 0x03B3, 0x03B7,
-// Iota Phi (2) Kappa Lambda Mu Nu Omicron Pi
- 0x03B9, 0x03C6, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF, 0x03C0,
-// Theta Rho Sigma Tau Upsilon OmegaPi Omega Xi
- 0x03B8, 0x03C1, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03B9, 0x03BE,
-// Psi Zeta arrow Tau Upsilon ???? Omega Xi
- 0x03C8, 0x03B6, 0x21D4, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
-// lower case letters:
-// ----------------
-// Alpha Beta Chi Delta Sigma Phi Gamma Eta
- 0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x2211, 0x03D5, 0x03B3, 0x03B7,
-// Iota Phi (2) Kappa Lambda Mu Nu Omicron Pi
- 0x03B9, 0x03C6, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF, 0x03C0,
-// Theta Integr Sigma Tau Upsilon OmegaPi Omega Xi
- 0x03B8, 0x222b, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03B9, 0x03BE,
-// Psi Zeta Sigma Tau Upsilon ???? Omega Xi
- 0x03C8, 0x03B6, 0x03EA, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD
-};
-
-WMFImport::WMFImport( ScribusMainWindow* mw, int flags ) :
- QObject(mw)
-{
- m_tmpSel = new Selection(this, false);
- m_Doc = mw->doc;
- unsupported = false;
- importFailed = false;
- importCanceled = true;
- importedColors.clear();
- m_docDesc = "";
- m_docTitle = "";
- interactive = (flags & LoadSavePlugin::lfInteractive);
-
- m_Valid = false;
- m_ObjHandleTab = NULL;
- m_Dpi = 1440;
-}
-
-WMFImport::~WMFImport()
-{
- qDeleteAll(m_commands);
- m_commands.clear();
- if ( m_tmpSel) delete m_tmpSel;
- if ( m_ObjHandleTab )
- {
- for (int i = 0; i < MAX_OBJHANDLE; ++i)
- {
- if (m_ObjHandleTab[i])
- delete m_ObjHandleTab[i];
- }
- delete[] m_ObjHandleTab;
- }
-}
-
-QString WMFImport::importColor(const QColor& color)
-{
- bool found = false;
- int r, g, b;
- QColor tmpColor;
- QString retColorName;
- ColorList::Iterator it;
- for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
- {
- if (it.value().getColorModel() == colorModelRGB)
- {
- it.value().getRGB(&r, &g, &b);
- tmpColor.setRgb(r, g, b);
- if (color == tmpColor)
- {
- retColorName = it.key();
- found = true;
- break;
- }
- }
- }
- if (!found)
- {
- ScColor tmp;
- tmp.fromQColor(color);
- tmp.setSpotColor(false);
- tmp.setRegistrationColor(false);
- m_Doc->PageColors.insert("FromWMF"+color.name(), tmp);
- importedColors.append("FromWMF"+color.name());
- retColorName = "FromWMF"+color.name();
- }
- return retColorName;
-}
-
-QColor WMFImport::colorFromParam( short* params )
-{
- unsigned int colorRef;
- int red, green, blue;
-
- colorRef = toDWord( params ) & 0xffffff;
- red = colorRef & 255;
- green = ( colorRef>>8 ) & 255;
- blue = ( colorRef>>16 ) & 255;
-
- return QColor( red, green, blue );
-}
-
-QTextCodec* WMFImport::codecFromCharset( int charset )
-{
- QTextCodec* codec = NULL;
- if (charset == DEFAULT_CHARSET || charset == OEM_CHARSET)
- codec = QTextCodec::codecForLocale();
- else if (charset == ANSI_CHARSET)
- codec = QTextCodec::codecForName("windows-1252");
- /*else if (charset == SYMBOL_CHARSET)
- codec = QTextCodec::codecForLocale();// Not supported yet*/
- else if (charset == MAC_CHARSET)
- codec = QTextCodec::codecForName("Apple Roman");
- else if (charset == SHIFTJIS_CHARSET)
- codec = QTextCodec::codecForName("Shift-JIS");
- else if (charset == HANGEUL_CHARSET)
- codec = QTextCodec::codecForName("CP949");
- else if (charset == GB2312_CHARSET)
- codec = QTextCodec::codecForName("CP936");
- else if (charset == CHINESEBIG5_CHARSET)
- codec = QTextCodec::codecForName("Big5");
- else if (charset == GREEK_CHARSET)
- codec = QTextCodec::codecForName("windows-1253");
- else if (charset == TURKISH_CHARSET)
- codec = QTextCodec::codecForName("windows-1254");
- else if (charset == VIETNAMESE_CHARSET)
- codec = QTextCodec::codecForName("windows-1258");
- else if (charset == HEBREW_CHARSET)
- codec = QTextCodec::codecForName("windows-1255");
- else if (charset == ARABIC_CHARSET)
- codec = QTextCodec::codecForName("windows-1256");
- else if (charset == BALTIC_CHARSET)
- codec = QTextCodec::codecForName("windows-1257");
- else if (charset == RUSSIAN_CHARSET)
- codec = QTextCodec::codecForName("windows-1251");
- else if (charset == THAI_CHARSET)
- codec = QTextCodec::codecForName("CP874");
- else if (charset == EASTEUROPE_CHARSET)
- codec = QTextCodec::codecForName("windows-1250");
- return codec;
-}
-
-QString WMFImport::symbolToUnicode ( const QByteArray& chars )
-{
- /*Code under GPL licence (http://root.cern.ch/viewvc/trunk/LICENSE)
- taken from http://root.cern.ch/viewvc/trunk/qt/src/TQtSymbolCodec.cxx*/
- QString r;
- const unsigned char * c = (const unsigned char *) chars.data();
-
- if( chars.size() == 0 ) return r;
-
- for (int i = 0; i < chars.size(); ++i)
- {
- if ( 64 < c[i] && c[i] <= 64+32 )
- r.append( QChar(greek_symbol_to_unicode[c[i]-65]) );
- else if (64+32+1 <= c[i] && c[i] < 64+32+32+1)
- r.append( QChar(greek_symbol_to_unicode[c[i]-65-32]+32) );
- else if (161 <= c[i] )
- r.append( QChar(symbol_to_unicode[c[i]-161]) );
- else
- r.append( QChar(c[i]) );
- }
- return r;
-}
-
-FPointArray WMFImport::pointsFromParam( short num, short* params )
-{
- FPointArray points;
- points.resize( num );
-
- for ( int i = 0; i < num; i++, params += 2 )
- points.setPoint( i, params[ 0 ], params[ 1 ] );
-
- return points;
-}
-
-FPointArray WMFImport::pointsToPolyline( const FPointArray& points, bool closePath )
-{
- bool bFirst = true;
- double x = 0.0, y = 0.0;
- FPointArray polyline;
- polyline.svgInit();
- for( uint i = 0; i < points.size(); ++i )
- {
- FPoint point = points.point(i);
- if( bFirst )
- {
- x = point.x();
- y = point.y();
- polyline.svgMoveTo(x, y);
- bFirst = false;
- }
- else
- {
- x = point.x();
- y = point.y();
- polyline.svgLineTo(x, y);
- }
- }
- if (closePath && (points.size() > 4))
- polyline.svgClosePath();
- return polyline;
-}
-
-void WMFImport::pointsToAngle( double xStart, double yStart, double xEnd, double yEnd, double& angleStart, double& angleLength )
-{
- double aStart = atan2( yStart, xStart );
- double aLength = atan2( yEnd, xEnd ) - aStart;
-
- angleStart = (int)(aStart * 180.0 / 3.14166);
- angleLength = (int)(aLength * 180.0 / 3.14166);
- if ( angleLength < 0 ) angleLength = 360.0 + angleLength;
-}
-
-bool WMFImport::import(QString fname, const TransactionSettings& trSettings, int flags)
-{
- if (!loadWMF(fname))
- {
- importFailed = true;
- return false;
- }
- QString CurDirP = QDir::currentPath();
- QFileInfo efp(fname);
- QDir::setCurrent(efp.path());
- bool success = importWMF(trSettings, flags);
- QDir::setCurrent(CurDirP);
- return success;
-}
-
-bool WMFImport::loadWMF( const QString &fileName )
-{
- QFile file( fileName );
-
- if ( !file.exists() )
- {
- cerr << "File " << QFile::encodeName(fileName).data() << " does not exist" << endl;
- return false;
- }
-
- if ( !file.open( QIODevice::ReadOnly ) )
- {
- cerr << "Cannot open file " << QFile::encodeName(fileName).data() << endl;
- return false;
- }
-
- QByteArray ba = file.readAll();
- file.close();
-
- QBuffer buffer( &ba );
- buffer.open( QIODevice::ReadOnly );
- return loadWMF( buffer );
-}
-
-bool WMFImport::loadWMF( QBuffer &buffer )
-{
- QDataStream st;
- WmfEnhMetaHeader eheader;
- WmfMetaHeader header;
- WmfPlaceableHeader pheader;
- WORD16 checksum;
- int filePos, idx, i;
- WmfCmd *cmd;
- WORD32 rdSize;
- WORD16 rdFunc;
-
- header.mtSize = 0;
- header.mtHeaderSize = 0;
- header.mtNoParameters = 0;
-
- qDeleteAll(m_commands);
- m_commands.clear();
-
- st.setDevice( &buffer );
- st.setByteOrder( QDataStream::LittleEndian ); // Great, I love Qt !
-
- //----- Read placeable metafile header
- st >> pheader.key;
- m_IsPlaceable = (pheader.key == (WORD32) APMHEADER_KEY);
- if ( m_IsPlaceable )
- {
- st >> pheader.hmf;
- st >> pheader.bbox.left;
- st >> pheader.bbox.top;
- st >> pheader.bbox.right;
- st >> pheader.bbox.bottom;
- st >> pheader.inch;
- st >> pheader.reserved;
- st >> pheader.checksum;
- checksum = calcCheckSum( &pheader );
- if ( pheader.checksum!=checksum ) m_IsPlaceable = false;
-
- m_Dpi = pheader.inch;
- m_BBox.setLeft( pheader.bbox.left );
- m_BBox.setTop( pheader.bbox.top );
- m_BBox.setRight( pheader.bbox.right );
- m_BBox.setBottom( pheader.bbox.bottom );
- m_HeaderBoundingBox = m_BBox;
- if ( WMFIMPORT_DEBUG )
- {
- cerr << endl << "-------------------------------------------------" << endl;
- cerr << "WMF Placeable Header ( " << static_cast<int>(sizeof( pheader ) ) << "):" << endl;
- cerr << " bbox=( " << m_BBox.left() << "; " << m_BBox.top() << "; " << m_BBox.width() << "; " << m_BBox.height() << ")" << endl;
- cerr << " inch=" << pheader.inch << endl;
- cerr << " checksum=" << pheader.checksum << "( " << (pheader.checksum==checksum?"ok":"wrong") << " )" << endl;
- }
- }
- else buffer.seek( 0 );
-
- //----- Read as enhanced metafile header
- filePos = buffer.pos();
- st >> eheader.iType;
- st >> eheader.nSize;
- st >> eheader.rclBounds.left;
- st >> eheader.rclBounds.top;
- st >> eheader.rclBounds.right;
- st >> eheader.rclBounds.bottom;
- st >> eheader.rclFrame.left;
- st >> eheader.rclFrame.top;
- st >> eheader.rclFrame.right;
- st >> eheader.rclFrame.bottom;
- st >> eheader.dSignature;
- m_IsEnhanced = ( eheader.dSignature==ENHMETA_SIGNATURE );
- if ( m_IsEnhanced ) // is it really enhanced ?
- {
- st >> eheader.nVersion;
- st >> eheader.nBytes;
- st >> eheader.nRecords;
- st >> eheader.nHandles;
- st >> eheader.sReserved;
- st >> eheader.nDescription;
- st >> eheader.offDescription;
- st >> eheader.nPalEntries;
- st >> eheader.szlDevice.width;
- st >> eheader.szlDevice.height;
- st >> eheader.szlMillimeters.width;
- st >> eheader.szlMillimeters.height;
-
- if ( WMFIMPORT_DEBUG )
- {
- cerr << endl << "-------------------------------------------------" << endl;
- cerr << "WMF Extended Header:" << endl;
- cerr << " iType=" << eheader.iType << endl;
- cerr << " nSize=" << eheader.nSize << endl;
- cerr << " rclBounds=( " << eheader.rclBounds.left << "; " << eheader.rclBounds.top << "; "
- << eheader.rclBounds.right << "; " << eheader.rclBounds.bottom << ")" << endl;
- cerr << " rclFrame=( " << eheader.rclFrame.left << "; " << eheader.rclFrame.top << "; "
- << eheader.rclFrame.right << "; " << eheader.rclFrame.bottom << ")" << endl;
- cerr << " nBytes=" << eheader.nBytes << endl;
- cerr << "\nNOT YET IMPLEMENTED, SORRY." << endl;
- }
- }
- else // no, not enhanced
- {
- //----- Read as standard metafile header
- buffer.seek( filePos );
- st >> header.mtType;
- st >> header.mtHeaderSize;
- st >> header.mtVersion;
- st >> header.mtSize;
- st >> header.mtNoObjects;
- st >> header.mtMaxRecord;
- st >> header.mtNoParameters;
- if ( WMFIMPORT_DEBUG ) {
- cerr << "WMF Header: " << "mtSize=" << header.mtSize << endl;
- }
- }
-
- //----- Test header validity
- m_Valid = ((header.mtHeaderSize == 9) && (header.mtNoParameters == 0)) || m_IsEnhanced || m_IsPlaceable;
- if ( m_Valid )
- {
- //----- Read Metafile Records
- rdFunc = -1;
- while ( !st.atEnd() && (rdFunc != 0) )
- {
- st >> rdSize;
- st >> rdFunc;
- idx = findFunc( rdFunc );
- rdSize -= 3;
-
- cmd = new WmfCmd;
- m_commands.append(cmd);
-
- cmd->funcIndex = idx;
- cmd->numParam = rdSize;
- cmd->params = new WORD16[ rdSize ];
-
- for ( i=0; i<rdSize && !st.atEnd(); i++ )
- st >> cmd->params[ i ];
-
-
- if ( rdFunc == 0x020B && !m_IsPlaceable) { // SETWINDOWORG: dimensions
- m_BBox.setLeft( qMin((int) cmd->params[ 1 ], m_BBox.left()) );
- m_BBox.setTop ( qMin((int) cmd->params[ 0 ], m_BBox.top()) );
- }
- if ( rdFunc == 0x020C && !m_IsPlaceable ) { // SETWINDOWEXT: dimensions
- m_BBox.setWidth ( qMax((int) cmd->params[ 1 ], m_BBox.width()) );
- m_BBox.setHeight( qMax((int) cmd->params[ 0 ], m_BBox.height()));
- }
-
- if ( i<rdSize )
- {
- cerr << "WMF : file truncated !" << endl;
- return false;
- }
- }
- //----- Test records validities
- m_Valid = (rdFunc == 0) && (m_BBox.width() != 0) && (m_BBox.height() != 0);
- if ( !m_Valid ) {
- cerr << "WMF : incorrect file format !" << endl;
- }
- }
- else {
- cerr << "WMF Header : incorrect header !" << endl;
- }
-
- buffer.close();
- return m_Valid;
-}
-
-bool WMFImport::importWMF(const TransactionSettings& trSettings, int flags)
-{
- bool ret = false;
- //double scale = (m_Dpi > 288) ? 288.0 / m_Dpi : 1.0;
- double scale = (m_Dpi > 0) ? 72.0 / m_Dpi : 0.05;
- double width = m_BBox.width() * scale;
- double height = m_BBox.height() * scale;
- if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
- {
- m_Doc->setPage(fabs(width), fabs(height), 0, 0, 0, 0, 0, 0, false, false);
- m_Doc->addPage(0);
- m_Doc->view()->addPage(0);
- }
- else
- {
- if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
- {
- m_Doc=ScCore->primaryMainWindow()->doFileNew(fabs(width), fabs(height), 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
- ScCore->primaryMainWindow()->HaveNewDoc();
- ret = true;
- }
- }
- if ((ret) || (!interactive))
- {
- if (width > height)
- m_Doc->PageOri = 1;
- else
- m_Doc->PageOri = 0;
- m_Doc->m_pageSize = "Custom";
- }
- FPoint minSize = m_Doc->minCanvasCoordinate;
- FPoint maxSize = m_Doc->maxCanvasCoordinate;
- FPoint cOrigin = m_Doc->view()->canvasOrigin();
- m_Doc->view()->Deselect();
- m_Doc->setLoading(true);
- m_Doc->DoDrawing = false;
- m_Doc->view()->updatesOn(false);
- m_Doc->scMW()->ScriptRunning = true;
- qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
- //gc->Family = m_Doc->toolSettings.defFont;
- m_Doc->PageColors.ensureBlackAndWhite();
- //m_gc.push( gc );
- QList<PageItem*> Elements = parseWmfCommands();
- if (flags & LoadSavePlugin::lfCreateDoc)
- {
- m_Doc->documentInfo.setTitle(m_docTitle);
- m_Doc->documentInfo.setComments(m_docDesc);
- }
- m_tmpSel->clear();
- if (Elements.count() == 0)
- {
- importFailed = true;
- if (importedColors.count() != 0)
- {
- for (int cd = 0; cd < importedColors.count(); cd++)
- {
- m_Doc->PageColors.remove(importedColors[cd]);
- }
- }
- }
- if (Elements.count() > 1)
- {
- bool isGroup = true;
- int firstElem = -1;
- if (Elements.at(0)->Groups.count() != 0)
- firstElem = Elements.at(0)->Groups.top();
- for (int bx = 0; bx < Elements.count(); ++bx)
- {
- PageItem* bxi = Elements.at(bx);
- if (bxi->Groups.count() != 0)
- {
- if (bxi->Groups.top() != firstElem)
- isGroup = false;
- }
- else
- isGroup = false;
- }
- if (!isGroup)
- {
- double minx = 99999.9;
- double miny = 99999.9;
- double maxx = -99999.9;
- double maxy = -99999.9;
- uint lowestItem = 999999;
- uint highestItem = 0;
- for (int a = 0; a < Elements.count(); ++a)
- {
- Elements.at(a)->Groups.push(m_Doc->GroupCounter);
- PageItem* currItem = Elements.at(a);
- lowestItem = qMin(lowestItem, currItem->ItemNr);
- highestItem = qMax(highestItem, currItem->ItemNr);
- double x1, x2, y1, y2;
- currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
- minx = qMin(minx, x1);
- miny = qMin(miny, y1);
- maxx = qMax(maxx, x2);
- maxy = qMax(maxy, y2);
- }
- double gx = minx;
- double gy = miny;
- double gw = maxx - minx;
- double gh = maxy - miny;
- PageItem *high = m_Doc->Items->at(highestItem);
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, m_Doc->toolSettings.dBrush, m_Doc->toolSettings.dPen, true);
- PageItem *neu = m_Doc->Items->takeAt(z);
- m_Doc->Items->insert(lowestItem, neu);
- neu->Groups.push(m_Doc->GroupCounter);
- neu->setItemName( tr("Group%1").arg(neu->Groups.top()));
- neu->AutoName = false;
- neu->isGroupControl = true;
- neu->groupsLastItem = high;
- for (int a = 0; a < m_Doc->Items->count(); ++a)
- {
- m_Doc->Items->at(a)->ItemNr = a;
- }
- neu->setRedrawBounding();
- neu->setTextFlowMode(PageItem::TextFlowDisabled);
- Elements.prepend(neu);
- m_Doc->GroupCounter++;
- }
- }
- m_Doc->DoDrawing = true;
- m_Doc->scMW()->ScriptRunning = false;
- if (interactive)
- m_Doc->setLoading(false);
- qApp->setOverrideCursor(QCursor(Qt::ArrowCursor));
- if ((Elements.count() > 0) && (!ret) && (interactive))
- {
- if (flags & LoadSavePlugin::lfScripted)
- {
- bool loadF = m_Doc->isLoading();
- m_Doc->setLoading(false);
- m_Doc->changed();
- m_Doc->setLoading(loadF);
- m_Doc->m_Selection->delaySignalsOn();
- for (int dre=0; dre<Elements.count(); ++dre)
- {
- m_Doc->m_Selection->addItem(Elements.at(dre), true);
- }
- m_Doc->m_Selection->delaySignalsOff();
- m_Doc->m_Selection->setGroupRect();
- m_Doc->view()->updatesOn(true);
- importCanceled = false;
- }
- else
- {
- m_Doc->DragP = true;
- m_Doc->DraggedElem = 0;
- m_Doc->DragElements.clear();
- m_Doc->m_Selection->delaySignalsOn();
- for (int dre=0; dre<Elements.count(); ++dre)
- {
- m_Doc->DragElements.append(Elements.at(dre)->ItemNr);
- m_tmpSel->addItem(Elements.at(dre), true);
- }
- ScriXmlDoc *ss = new ScriXmlDoc();
- m_tmpSel->setGroupRect();
- ScElemMimeData* md = new ScElemMimeData();
- md->setScribusElem(ss->WriteElem(m_Doc, m_Doc->view(), m_tmpSel));
- delete ss;
-/*#ifndef QT_MAC*/
-// see #2526
- m_Doc->itemSelection_DeleteItem(m_tmpSel);
-/*#endif*/
- m_Doc->view()->updatesOn(true);
- m_Doc->m_Selection->delaySignalsOff();
- // We must copy the TransationSettings object as it is owned
- // by handleObjectImport method afterwards
- TransactionSettings* transacSettings = new TransactionSettings(trSettings);
- m_Doc->view()->handleObjectImport(md, transacSettings);
- m_Doc->DragP = false;
- m_Doc->DraggedElem = 0;
- m_Doc->DragElements.clear();
- }
- }
- else
- {
- bool loadF = m_Doc->isLoading();
- m_Doc->setLoading(false);
- m_Doc->changed();
- m_Doc->reformPages();
- m_Doc->view()->updatesOn(true);
- m_Doc->setLoading(loadF);
- }
- return true;
-}
-
-QList<PageItem*> WMFImport::parseWmfCommands(void)
-{
- int idx, i;
- const WmfCmd* cmd;
- QList<PageItem*> elements;
-
- m_context.reset();
-
- if ( !m_Valid ) return elements;
-
- if ( m_ObjHandleTab ) delete[] m_ObjHandleTab;
- m_ObjHandleTab = new WmfObjHandle* [ MAX_OBJHANDLE ];
- for ( i = MAX_OBJHANDLE-1; i >= 0; i-- )
- m_ObjHandleTab[ i ] = NULL;
-
- if ( WMFIMPORT_DEBUG ) {
- cerr << "Bounding box : " << m_BBox.left() << " " << m_BBox.top() << " " << m_BBox.right() << " " << m_BBox.bottom() << endl;
- }
-
- double scale = (m_Dpi > 0) ? 72.0 / m_Dpi : 0.05;
- m_context.setViewportOrg( 0, 0 );
- m_context.setViewportExt( m_BBox.width() * scale, m_BBox.height() * scale );
- m_context.setWindowOrg( m_BBox.left(), m_BBox.bottom() );
- m_context.setWindowExt( m_BBox.width(), m_BBox.height() );
-
- for (int index = 0; index < m_commands.count(); ++index)
- {
- cmd = m_commands.at(index);
- idx = cmd->funcIndex;
- ( this->*metaFuncTab[ idx ].method )( elements, cmd->numParam, cmd->params );
-
- if ( WMFIMPORT_DEBUG ) {
- QString str = "", param;
- if ( metaFuncTab[ idx ].name == NULL ) {
- str += "UNKNOWN ";
- }
- if ( metaFuncTab[ idx ].method == &WMFImport::noop ) {
- str += "UNIMPLEMENTED ";
- }
- str += metaFuncTab[ idx ].name;
- str += " : ";
-
- for ( i=0 ; i < cmd->numParam ; i++ ) {
- param.setNum( cmd->params[ i ] );
- str += param;
- str += " ";
- }
- cerr << str.toAscii().data() << endl;
- }
- }
- return elements;
-}
-
-void WMFImport::finishCmdParsing( PageItem* item )
-{
- QMatrix gcm = m_context.worldMatrix();
- double coeff1 = sqrt(gcm.m11() * gcm.m11() + gcm.m12() * gcm.m12());
- double coeff2 = sqrt(gcm.m21() * gcm.m21() + gcm.m22() * gcm.m22());
- if( item->asImageFrame() )
- {
- item->moveBy(gcm.dx(), gcm.dy());
- item->setWidthHeight(item->width() * gcm.m11(), item->height() * gcm.m22());
- item->setLineWidth(qMax(item->lineWidth() * (coeff1 + coeff2) / 2.0, 0.25));
- if (item->PictureIsAvailable)
- item->setImageXYScale(item->width() / item->pixm.width(), item->height() / item->pixm.height());
- }
- else if( item->asTextFrame() )
- {
- item->setLineWidth(qMax(item->lineWidth() * (coeff1 + coeff2) / 2.0, 0.25));
- }
- else
- {
- item->ClipEdited = true;
- item->FrameType = 3;
- item->PoLine.map(gcm);
- item->setLineWidth(qMax(item->lineWidth() * (coeff1 + coeff2) / 2.0, 0.25));
- FPoint wh = getMaxClipF(&item->PoLine);
- item->setWidthHeight(wh.x(), wh.y());
- m_Doc->AdjustItemSize(item);
- }
- item->setRedrawBounding();
- item->OwnPage = m_Doc->OnPage(item);
- item->PLineEnd = m_context.pen().capStyle();
- item->PLineJoin = m_context.pen().joinStyle();
- item->setTextFlowMode(PageItem::TextFlowDisabled);
- //item->DashOffset = gc->dashOffset;
- //item->DashValues = gc->dashArray;
-}
-
-void WMFImport::setWindowOrg( QList<PageItem*>& /*items*/, long, short* params )
-{
- m_context.setWindowOrg( params[ 1 ], params[ 0 ] );
-}
-
-void WMFImport::setWindowExt( QList<PageItem*>& /*items*/, long, short* params )
-{
- m_context.setWindowExt( params[ 1 ], params[ 0 ] );
-}
-
-void WMFImport::lineTo( QList<PageItem*>& items, long, short* params )
-{
- double BaseX = m_Doc->currentPage()->xOffset();
- double BaseY = m_Doc->currentPage()->yOffset();
- QPoint currentPos = m_context.position();
- bool doStroke = (m_context.pen().style() != Qt::NoPen);
- if (doStroke)
- {
- double x1 = currentPos.x();
- double y1 = currentPos.y();
- double x2 = params[1];
- double y2 = params[0];
- double lineWidth = m_context.pen().width();
- QString lineColor = importColor(m_context.pen().color());
- int z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, CommonStrings::None, lineColor, true);
- PageItem* ite = m_Doc->Items->at(z);
- ite->PoLine.resize(4);
- ite->PoLine.setPoint(0, FPoint(x1, y1));
- ite->PoLine.setPoint(1, FPoint(x1, y1));
- ite->PoLine.setPoint(2, FPoint(x2, y2));
- ite->PoLine.setPoint(3, FPoint(x2, y2));
- finishCmdParsing(ite);
- items.append(ite);
- }
- m_context.setPosition( QPoint(params[1], params[0]) );
-}
-
-void WMFImport::moveTo( QList<PageItem*>& /*items*/, long, short* params )
-{
- m_context.setPosition( QPoint(params[1], params[0]) );
-}
-
-void WMFImport::ellipse( QList<PageItem*>& items, long, short* params )
-{
- double BaseX = m_Doc->currentPage()->xOffset();
- double BaseY = m_Doc->currentPage()->yOffset();
- double rx = (params[ 1 ] - params[ 3 ]) / 2.0;
- double ry = (params[ 0 ] - params[ 2 ]) / 2.0;
- double px = (params[ 1 ] + params[ 3 ]) / 2.0 - rx;
- double py = (params[ 0 ] + params[ 2 ]) / 2.0 - ry;
- bool doFill = m_context.brush().style() != Qt::NoBrush;
- bool doStroke = m_context.pen().style() != Qt::NoPen;
- QString fillColor = doFill ? importColor( m_context.brush().color() ) : CommonStrings::None;
- QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
- double lineWidth = m_context.pen().width();
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, BaseX, BaseY, rx * 2.0, ry * 2.0, lineWidth, fillColor, strokeColor, true);
- PageItem* ite = m_Doc->Items->at(z);
- QMatrix mm(1.0, 0.0, 0.0, 1.0, px, py);
- ite->PoLine.map(mm);
- finishCmdParsing(ite);
- items.append(ite);
-}
-
-void WMFImport::polygon( QList<PageItem*>& items, long, short* params )
-{
- //cerr << "WMFImport::polygon unimplemented" << endl;
- double BaseX = m_Doc->currentPage()->xOffset();
- double BaseY = m_Doc->currentPage()->yOffset();
- bool doFill = m_context.brush().style() != Qt::NoBrush;
- bool doStroke = m_context.pen().style() != Qt::NoPen;
- QString fillColor = doFill ? importColor( m_context.brush().color() ) : CommonStrings::None;
- QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
- double lineWidth = m_context.pen().width();
- if (doStroke && lineWidth <= 0.0 )
- lineWidth = 1.0;
- FPointArray paramPoints = pointsFromParam( params[0], ¶ms[1] );
- FPointArray points = pointsToPolyline( paramPoints, true );
- if( paramPoints.size() > 0 )
- {
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, fillColor, strokeColor, true);
- PageItem* ite = m_Doc->Items->at(z);
- ite->PoLine = points;
- ite->fillRule = !m_context.windingFill();
- finishCmdParsing(ite);
- items.append(ite);
- }
-}
-
-void WMFImport::polyPolygon( QList<PageItem*>& items, long num, short* params )
-{
- int numPolys = params[0];
- int pointIndex = params[0] + 1;
- for (int i = 0; i < numPolys; ++i)
- {
- short numPoints = params[i + 1];
- short* paramArray = new short[1 + 2 * numPoints];
- paramArray[0] = numPoints;
- memcpy(¶mArray[1], ¶ms[pointIndex], 2 * numPoints * sizeof(short));
- polygon(items, num, paramArray);
- delete[] paramArray;
- pointIndex += (2 * numPoints);
- }
-}
-
-void WMFImport::polyline( QList<PageItem*>& items, long, short* params )
-{
- //cerr << "WMFImport::polyline unimplemented" << endl;
- double BaseX = m_Doc->currentPage()->xOffset();
- double BaseY = m_Doc->currentPage()->yOffset();
- bool doStroke = m_context.pen().style() != Qt::NoPen;
- QString fillColor = CommonStrings::None;
- QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
- double lineWidth = m_context.pen().width();
- if (doStroke && lineWidth <= 0.0 )
- lineWidth = 1.0;
- FPointArray paramPoints = pointsFromParam( params[0], ¶ms[1] );
- FPointArray points = pointsToPolyline( paramPoints, false );
- if( paramPoints.size() > 0 )
- {
- int z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, fillColor, strokeColor, true);
- PageItem* ite = m_Doc->Items->at(z);
- ite->PoLine = points;
- finishCmdParsing(ite);
- items.append(ite);
- }
-}
-
-void WMFImport::rectangle( QList<PageItem*>& items, long, short* params )
-{
- //cerr << "WMFImport::rectangle unimplemented" << endl;
- double BaseX = m_Doc->currentPage()->xOffset();
- double BaseY = m_Doc->currentPage()->yOffset();
- bool doFill = m_context.brush().style() != Qt::NoBrush;
- bool doStroke = m_context.pen().style() != Qt::NoPen;
- QString fillColor = doFill ? importColor( m_context.brush().color() ) : CommonStrings::None;
- QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
- double lineWidth = m_context.pen().width();
- if (doStroke && lineWidth <= 0.0 )
- lineWidth = 1.0;
- double x = ((params[3] - params[1]) > 0) ? params[1] : params[3];
- double y = ((params[2] - params[0]) > 0) ? params[0] : params[2];
- double width = fabs((double) params[3] - params[1]);
- double height = fabs((double) params[2] - params[0]);
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, BaseX, BaseY, width, height, lineWidth, fillColor, strokeColor, true);
- PageItem* ite = m_Doc->Items->at(z);
- QMatrix mm(1.0, 0.0, 0.0, 1.0, x, y);
- ite->PoLine.map(mm);
- finishCmdParsing(ite);
- items.append(ite);
-}
-
-void WMFImport::roundRect( QList<PageItem*>& items, long, short* params )
-{
- //cerr << "WMFImport::roundRect unimplemented" << endl;
- double BaseX = m_Doc->currentPage()->xOffset();
- double BaseY = m_Doc->currentPage()->yOffset();
- bool doFill = m_context.brush().style() != Qt::NoBrush;
- bool doStroke = m_context.pen().style() != Qt::NoPen;
- QString fillColor = doFill ? importColor( m_context.brush().color() ) : CommonStrings::None;
- QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
- double lineWidth = m_context.pen().width();
- if (doStroke && lineWidth <= 0.0 )
- lineWidth = 1.0;
- double x = ((params[5] - params[3]) > 0) ? params[3] : params[5];
- double y = ((params[4] - params[2]) > 0) ? params[2] : params[4];
- double width = fabs((double) params[5] - params[3]);
- double height = fabs((double) params[4] - params[2]);
- double rx = params[1] / 2.0;
- double ry = params[0] / 2.0;
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, BaseX, BaseY, width, height, lineWidth, fillColor, strokeColor, true);
- PageItem* ite = m_Doc->Items->at(z);
- if ((rx != 0.0) || (ry != 0.0))
- {
- ite->setCornerRadius(qMax(rx, ry));
- ite->SetFrameRound();
- m_Doc->setRedrawBounding(ite);
- }
- QMatrix mm(1.0, 0.0, 0.0, 1.0, x, y);
- ite->PoLine.map(mm);
- finishCmdParsing(ite);
- items.append(ite);
-}
-
-void WMFImport::arc( QList<PageItem*>& items, long, short* params )
-{
- FPointArray pointArray;
- QPainterPath painterPath;
- double BaseX = m_Doc->currentPage()->xOffset();
- double BaseY = m_Doc->currentPage()->yOffset();
- bool doStroke = m_context.pen().style() != Qt::NoPen;
- QString fillColor = CommonStrings::None;
- QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
- double lineWidth = m_context.pen().width();
- if (doStroke && lineWidth <= 0.0 )
- lineWidth = 1.0;
- double angleStart, angleLength;
- double x = ((params[7] - params[5]) > 0) ? params[5] : params[7];
- double y = ((params[6] - params[4]) > 0) ? params[4] : params[6];
- double xCenter = (params[5] + params[7]) / 2.0;
- double yCenter = (params[4] + params[6]) / 2.0;
- double xWidth = fabs((double) params[5] - params[7]);
- double yHeight = fabs((double) params[4] - params[6]);
- pointsToAngle(params[3] - xCenter, yCenter - params[2], params[1] - xCenter, yCenter - params[0], angleStart, angleLength);
- painterPath.arcMoveTo(x, y, xWidth, yHeight, angleStart);
- painterPath.arcTo(x, y, xWidth, yHeight, angleStart, angleLength);
- pointArray.fromQPainterPath(painterPath);
- if( pointArray.size() > 0 )
- {
- int z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, fillColor, strokeColor, true);
- PageItem* ite = m_Doc->Items->at(z);
- ite->PoLine = pointArray;
- finishCmdParsing(ite);
- items.append(ite);
- }
-}
-
-void WMFImport::chord( QList<PageItem*>& items, long, short* params )
-{
- QPointF firstPoint;
- FPointArray pointArray;
- QPainterPath painterPath;
- double BaseX = m_Doc->currentPage()->xOffset();
- double BaseY = m_Doc->currentPage()->yOffset();
- bool doFill = m_context.brush().style() != Qt::NoBrush;
- bool doStroke = m_context.pen().style() != Qt::NoPen;
- QString fillColor = doFill ? importColor( m_context.brush().color() ) : CommonStrings::None;
- QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
- double lineWidth = m_context.pen().width();
- if (doStroke && lineWidth <= 0.0 )
- lineWidth = 1.0;
- double angleStart, angleLength;
- double x = ((params[7] - params[5]) > 0) ? params[5] : params[7];
- double y = ((params[6] - params[4]) > 0) ? params[4] : params[6];
- double xCenter = (params[5] + params[7]) / 2.0;
- double yCenter = (params[4] + params[6]) / 2.0;
- double xWidth = fabs((double) params[5] - params[7]);
- double yHeight = fabs((double) params[4] - params[6]);
- pointsToAngle(params[3] - xCenter, yCenter - params[2], params[1] - xCenter, yCenter - params[0], angleStart, angleLength);
- painterPath.arcMoveTo(x, y, xWidth, yHeight, angleStart);
- firstPoint = painterPath.currentPosition();
- painterPath.arcTo (x, y, xWidth, yHeight, angleStart, angleLength);
- painterPath.lineTo(firstPoint);
- pointArray.fromQPainterPath(painterPath);
- if( pointArray.size() > 0 )
- {
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, fillColor, strokeColor, true);
- PageItem* ite = m_Doc->Items->at(z);
- ite->PoLine = pointArray;
- finishCmdParsing(ite);
- items.append(ite);
- }
-}
-
-void WMFImport::pie( QList<PageItem*>& items, long, short* params )
-{
- QPointF firstPoint;
- FPointArray pointArray;
- QPainterPath painterPath;
- double BaseX = m_Doc->currentPage()->xOffset();
- double BaseY = m_Doc->currentPage()->yOffset();
- bool doFill = m_context.brush().style() != Qt::NoBrush;
- bool doStroke = m_context.pen().style() != Qt::NoPen;
- QString fillColor = doFill ? importColor( m_context.brush().color() ) : CommonStrings::None;
- QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
- double lineWidth = m_context.pen().width();
- if (doStroke && lineWidth <= 0.0 )
- lineWidth = 1.0;
- double angleStart, angleLength;
- double x = ((params[7] - params[5]) > 0) ? params[5] : params[7];
- double y = ((params[6] - params[4]) > 0) ? params[4] : params[6];
- double xCenter = (params[5] + params[7]) / 2.0;
- double yCenter = (params[4] + params[6]) / 2.0;
- double xWidth = fabs((double) params[5] - params[7]);
- double yHeight = fabs((double) params[4] - params[6]);
- pointsToAngle(params[3] - xCenter, yCenter - params[2], params[1] - xCenter, yCenter - params[0], angleStart, angleLength);
- painterPath.arcMoveTo(x,y, xWidth, yHeight, angleStart);
- firstPoint = painterPath.currentPosition();
- painterPath.arcTo (x, y, xWidth, yHeight, angleStart, angleLength);
- painterPath.lineTo(xCenter, yCenter);
- painterPath.lineTo(firstPoint);
- pointArray.fromQPainterPath(painterPath);
- if( pointArray.size() > 0 )
- {
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, fillColor, strokeColor, true);
- PageItem* ite = m_Doc->Items->at(z);
- ite->PoLine = pointArray;
- finishCmdParsing(ite);
- items.append(ite);
- }
-}
-
-void WMFImport::setPolyFillMode( QList<PageItem*>& /*items*/, long, short* params )
-{
- m_context.setWindingFill( params[0] );
-}
-
-void WMFImport::setBkColor( QList<PageItem*>& /*items*/, long, short* params )
-{
- m_context.setBackgroundColor( colorFromParam( params ) );
-}
-
-void WMFImport::setBkMode( QList<PageItem*>& /*items*/, long, short* params )
-{
- if ( params[ 0 ]==1 )
- m_context.setBackgroundMode( Qt::TransparentMode );
- else
- m_context.setBackgroundMode( Qt::OpaqueMode );
-}
-
-void WMFImport::saveDC( QList<PageItem*>& /*items*/, long, short* )
-{
- m_context.save();
-}
-
-void WMFImport::restoreDC( QList<PageItem*>& /*items*/, long, short *params )
-{
- for ( int i=0; i > params[ 0 ] ; i-- )
- m_context.restore();
-}
-
-void WMFImport::intersectClipRect( QList<PageItem*>& /*items*/, long, short* /*params*/ )
-{
- cerr << "WMFImport::intersectClipRect unimplemented" << endl;
-}
-
-void WMFImport::excludeClipRect( QList<PageItem*>& /*items*/, long, short* /*params*/ )
-{
- cerr << "WMFImport::excludeClipRect unimplemented" << endl;
-}
-
-void WMFImport::setTextColor( QList<PageItem*>& /*items*/, long, short* params )
-{
- m_context.setTextColor( colorFromParam(params) );
-}
-
-void WMFImport::setTextAlign( QList<PageItem*>& /*items*/, long, short* params )
-{
- m_context.setTextAlign(params[ 0 ]);
-}
-
-void WMFImport::textOut( QList<PageItem*>& items, long num, short* params )
-{
- short *copyParm = new short[num + 1];
-
- // re-order parameters
- int idxOffset = (params[0] / 2) + 1 + (params[0] & 1);
- copyParm[0] = params[idxOffset];
- copyParm[1] = params[idxOffset + 1];
- copyParm[2] = params[0];
- copyParm[3] = 0;
- memcpy( ©Parm[4], ¶ms[1], params[0] );
-
- extTextOut(items, num + 1, copyParm );
- delete [] copyParm;
-}
-
-void WMFImport::extTextOut( QList<PageItem*>& items, long num, short* params )
-{
- QString textString;
- double BaseX = m_Doc->currentPage()->xOffset();
- double BaseY = m_Doc->currentPage()->yOffset();
-
- if (params[3] & 0x0010) // ETO_GLYPH_INDEX
- {
- cerr << "WMFImport::extTextOut: ETO_GLYPH_INDEX option not supported " << endl;
- unsupported = true;
- return;
- }
-
- // ETO_CLIPPED flag add 4 parameters
- char* ptStr = (params[3] & 0x0004) ? ((char*)¶ms[8]) : ((char*)¶ms[4]);
- QByteArray textArray( ptStr, params[2] );
-
- QTextCodec* codec = codecFromCharset( m_context.textCharSet() );
- if (codec)
- textString = codec->toUnicode(textArray);
- else if ( m_context.textCharSet() == SYMBOL_CHARSET )
- textString = symbolToUnicode(textArray);
- else
- textString = QString::fromLocal8Bit(textArray.data());
-
- QFontMetrics fm( m_context.font() );
- int width = fm.width(textString) + fm.descent(); // because fm.width(text) isn't rigth with Italic text
- /*int height = fm.height();
- int ascent = fm.ascent();*/
-
- double startX = params[1], startY = params[0];
- int textAlign = m_context.textAlign();
- double textRotation = m_context.textRotation();
- if ( textAlign & 0x01 ) { // (left, top) position = current logical position
- QPoint pos = m_context.position();
- startX = pos.x();
- startY = pos.y();
- }
-
- m_context.save();
- // A bit hacky but should be sufficient to have text not flipped
- // top down in some wmfs (see cell.wmf sample from libwmf)
- if ( m_context.worldMatrix().m22() < 0.0)
- {
- m_context.translate(startX, startY);
- m_context.scale (1.0, -1.0);
- m_context.translate( -startX, -startY);
- }
- if ( textRotation != 0.0) {
- m_context.translate(startX, startY);
- m_context.rotate ( textRotation );
- m_context.translate( -startX, -startY);
- }
-
- if ( (textAlign & 0x04) && (textAlign & 0x02) ) // TA_CENTER 0x06
- startX -= (width / 2);
- else if ( textAlign & 0x02 ) // TA_RIGHT 0x02
- startX -= width;
- if ( textAlign == 0 ) // TA_TOP
- startY += fm.ascent();
-
- bool eto_empty = (params[3] == 0);
- bool eto_clipped_set = (params[3] & 0x0004);
- bool eto_pdy_set = (params[3] & 0x2000);
-
- int idxOffset = (params[ 2 ] / 2) + 4 + (params[ 2 ] & 1) + (eto_clipped_set ? 4 : 0);
- int minParams = eto_pdy_set ? (idxOffset + 2 * (params[2] - 1)) : (idxOffset + params[2]);
- bool useCharInterdistances = (num >= minParams) && (eto_empty || eto_pdy_set);
- if ((params[2] > 1) && useCharInterdistances)
- {
- double xpos = startX;
- double ypos = startY;
- double lineWidth = 0.0;
- FPointArray textPath;
- QString textColor = importColor( m_context.textColor() );
- for (int index = 0; (index < params[2] && index < textString.length()); ++index)
- {
- QPainterPath painterPath;
- if (index > 0 && eto_pdy_set)
- {
- xpos += params[idxOffset + index * 2 - 1];
- ypos += params[idxOffset + index * 2];
- }
- else if (index > 0)
- xpos += params[idxOffset + index - 1];
- painterPath.addText(xpos, ypos, m_context.font(), textString.at(index));
- textPath.fromQPainterPath(painterPath);
- if (textPath.size() > 0)
- {
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, textColor, CommonStrings::None, true);
- PageItem* ite = m_Doc->Items->at(z);
- ite->PoLine = textPath;
- finishCmdParsing(ite);
- items.append(ite);
- }
- }
- }
- else
- {
- FPointArray textPath;
- QString textColor = importColor( m_context.textColor() );
- QPainterPath painterPath;
- painterPath.addText( startX, startY, m_context.font(), textString );
- textPath.fromQPainterPath(painterPath);
- if (textPath.size() > 0)
- {
- double lineWidth = 0.0;
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, textColor, CommonStrings::None, true);
- PageItem* ite = m_Doc->Items->at(z);
- ite->PoLine = textPath;
- finishCmdParsing(ite);
- items.append(ite);
- }
- }
- m_context.restore();
-}
-
-void WMFImport::selectObject( QList<PageItem*>& /*items*/, long, short* params )
-{
- int idx = params[ 0 ];
- if ( idx >= 0 && idx < MAX_OBJHANDLE && m_ObjHandleTab[ idx ] )
- m_ObjHandleTab[ idx ]->apply( m_context );
-}
-
-void WMFImport::deleteObject( QList<PageItem*>& /*items*/, long, short* params )
-{
- deleteHandle( params[ 0 ] );
-}
-
-void WMFImport::createEmptyObject( QList<PageItem*>& /*items*/, long, short* )
-{
- // allocation of an empty object (to keep object counting in sync)
- WmfObjPenHandle* handle = new WmfObjPenHandle();
- addHandle( handle );
- cerr << "WMFImport: unimplemented createObject " << endl;
-}
-
-void WMFImport::createBrushIndirect( QList<PageItem*>& /*items*/, long, short* params )
-{
- static Qt::BrushStyle hatchedStyleTab[] =
- {
- Qt::HorPattern,
- Qt::FDiagPattern,
- Qt::BDiagPattern,
- Qt::CrossPattern,
- Qt::DiagCrossPattern
- };
- static Qt::BrushStyle styleTab[] =
- { Qt::SolidPattern,
- Qt::NoBrush,
- Qt::FDiagPattern, /* hatched */
- Qt::Dense4Pattern, /* should be custom bitmap pattern */
- Qt::HorPattern, /* should be BS_INDEXED (?) */
- Qt::VerPattern, /* should be device-independent bitmap */
- Qt::Dense6Pattern, /* should be device-independent packed-bitmap */
- Qt::Dense2Pattern, /* should be BS_PATTERN8x8 */
- Qt::Dense3Pattern /* should be device-independent BS_DIBPATTERN8x8 */
- };
- Qt::BrushStyle style;
- short arg;
- WmfObjBrushHandle* handle = new WmfObjBrushHandle();
- addHandle( handle );
-
- arg = params[0];
- if ( arg == 2 )
- {
- arg = params[3];
- if ( arg >= 0 && arg < 5 )
- style = hatchedStyleTab[ arg ];
- else
- {
- cerr << "WMFImport::createBrushIndirect: invalid hatched brush " << arg << endl;
- style = Qt::SolidPattern;
- }
- }
- else if ( arg >= 0 && arg < 9 )
- style = styleTab[arg];
- else
- {
- cerr << "WMFImport::createBrushIndirect: invalid brush " << arg << endl;
- style = Qt::SolidPattern;
- }
- handle->brush.setStyle( style );
- handle->brush.setColor( colorFromParam( params+1 ) );
-}
-
-void WMFImport::createPenIndirect( QList<PageItem*>& /*items*/, long, short* params )
-{
- static Qt::PenStyle styleTab[] = { Qt::SolidLine, Qt::DashLine, Qt::DotLine, Qt::DashDotLine, Qt::DashDotDotLine,
- Qt::NoPen, Qt::SolidLine };
- Qt::PenStyle style;
- WmfObjPenHandle* handle = new WmfObjPenHandle();
- addHandle( handle );
-
- if ( params[0] >= 0 && params[0] < 6 )
- style = styleTab[ params[0] ];
- else
- {
- cerr << "WMFImport::createPenIndirect: invalid pen " << params[ 0 ] << endl;
- style = Qt::SolidLine;
- }
-
- handle->pen.setStyle( style );
- handle->pen.setWidth( params[1] );
- handle->pen.setColor( colorFromParam( params+3 ) );
- handle->pen.setCapStyle( Qt::RoundCap );
-}
-
-void WMFImport::createFontIndirect( QList<PageItem*>& /*items*/, long , short* params)
-{
- WmfObjFontHandle* handle = new WmfObjFontHandle();
- addHandle( handle );
-
- QString family( (const char*)¶ms[ 9 ] );
-
- handle->rotation = -params[ 2 ] / 10; // text rotation (in 1/10 degree)
- handle->font.setFamily( family );
- handle->font.setStyleStrategy( QFont::PreferOutline );
- handle->font.setFixedPitch( ((params[ 8 ] & 0x01) == 0) );
- // TODO: investigation why some test case need -2. (size of font in logical point)
- int fontSize = (params[0] != 0) ? (qAbs(params[0]) - 2) : 12;
- handle->font.setPixelSize( fontSize );
- handle->font.setWeight( (params[ 4 ] >> 3) );
- handle->font.setItalic( (params[ 5 ] & 0x01) );
- handle->font.setUnderline( (params[ 5 ] & 0x100) );
- handle->font.setStrikeOut( (params[ 6 ] & 0x01) );
- handle->charset = (params[ 6 ] & 0xFF00) >> 8;
-}
-
-void WMFImport::noop( QList<PageItem*>& /*items*/, long, short* )
-{
-}
-
-void WMFImport::end( QList<PageItem*>& /*items*/, long, short* )
-{
- //cerr << "WMFImport::end unimplemented" << endl;
-}
-
-void WMFImport::addHandle( WmfObjHandle* handle )
-{
- int idx;
-
- for ( idx =0; idx < MAX_OBJHANDLE ; idx++ )
- if ( m_ObjHandleTab[ idx ] == NULL ) break;
-
- if ( idx < MAX_OBJHANDLE )
- m_ObjHandleTab[ idx ] = handle;
- else
- cerr << "WMFImport error: handle table full !" << endl;
-}
-
-void WMFImport::deleteHandle( int idx )
-{
- if ( idx >= 0 && idx < MAX_OBJHANDLE && m_ObjHandleTab[ idx ] )
- {
- delete m_ObjHandleTab[ idx ];
- m_ObjHandleTab[ idx ] = NULL;
- }
-}
-
-unsigned short WMFImport::calcCheckSum( WmfPlaceableHeader* apmfh )
-{
- WORD16* lpWord;
- WORD16 wResult, i;
-
- // Start with the first word
- wResult = *( lpWord = ( WORD16* )( apmfh ) );
- // XOR in each of the other 9 words
- for( i=1; i<=9; i++ )
- {
- wResult ^= lpWord[ i ];
- }
- return wResult;
-}
-
-int WMFImport::findFunc( unsigned short aFunc ) const
-{
- int i = 0;
-
- for ( i=0; metaFuncTab[ i ].name; i++ )
- if ( metaFuncTab[ i ].func == aFunc ) return i;
-
- // here : unknown function
- return i;
-}
-
-unsigned int WMFImport::toDWord( short* params )
-{
- unsigned int l;
-#if !defined( WORDS_BIGENDIAN )
- l = *( unsigned int* )( params );
-#else
- char *bytes;
- char swap[ 4 ];
- bytes = ( char* )params;
- swap[ 0 ] = bytes[ 2 ];
- swap[ 1 ] = bytes[ 3 ];
- swap[ 2 ] = bytes[ 0 ];
- swap[ 3 ] = bytes[ 1 ];
- l = *( unsigned int* )( swap );
-#endif
- return l;
-}
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+/* Code inspired by KOffice libwmf and adapted for Scribus by Jean Ghali */
+
+#include "scconfig.h"
+#include "wmfimport.h"
+
+#include <QCursor>
+#include <QDrag>
+#include <QBuffer>
+#include <QDataStream>
+#include <QFile>
+#include <QMimeData>
+#include <QPainterPath>
+#include <QRegExp>
+
+#include "ui/customfdialog.h"
+#include "scribus.h"
+#include "scribusXml.h"
+#include "ui/propertiespalette.h"
+#include "prefsfile.h"
+
+#include <cmath>
+#include "commonstrings.h"
+#include "fpointarray.h"
+#include "menumanager.h"
+#include "prefsmanager.h"
+#include "pageitem.h"
+#include "scmimedata.h"
+#include "scraction.h"
+#include "scribuscore.h"
+#include "scribusdoc.h"
+#include "selection.h"
+#include "undomanager.h"
+#include "loadsaveplugin.h"
+#include "util.h"
+#include "util_icon.h"
+#include "util_math.h"
+#include "fonts/scfontmetrics.h"
+
+using namespace std;
+
+#include "wmfstruct.h"
+#include "wmfcmd.h"
+#include "wmfcontext.h"
+#include "wmfhandle.h"
+#include "metafuncs.h"
+
+#define WMFIMPORT_DEBUG 0
+#define MAX_OBJHANDLE 128
+
+#define ANSI_CHARSET 0 // ANSI charset (Windows-1252)
+#define DEFAULT_CHARSET 1
+#define SYMBOL_CHARSET 2
+#define MAC_CHARSET 77
+#define SHIFTJIS_CHARSET 128 // Shift JIS charset (Windows-932)
+#define HANGEUL_CHARSET 129 // Hangeul charset (Windows-949)
+#define JOHAB_CHARSET 130 // Johab charset (Windows-1361)
+#define GB2312_CHARSET 134 // GB2312 charset (Windows-936)
+#define CHINESEBIG5_CHARSET 136 // Chinese Big5 charset (Windows-950)
+#define GREEK_CHARSET 161 // Greek charset (Windows-1253)
+#define TURKISH_CHARSET 162 // Turkish charset (Windows-1254)
+#define VIETNAMESE_CHARSET 163 // Vietnamese charset (Windows-1258)
+#define HEBREW_CHARSET 177 // Hebrew charset (Windows-1255)
+#define ARABIC_CHARSET 178 // Arabic charset (Windows-1256)
+#define BALTIC_CHARSET 186 // Baltic charset (Windows-1257)
+#define RUSSIAN_CHARSET 204 // Cyrillic charset (Windows-1251)
+#define THAI_CHARSET 222 // Thai charset (Windows-874)
+#define EASTEUROPE_CHARSET 238 // Eastern european charset (Windows-1250)
+#define OEM_CHARSET 255
+
+/* Symbol to unicode conversion table copied from http://root.cern.ch/viewvc/trunk/qt/src/TQtSymbolCodec.cxx
+This code is placed under GPL licence (http://root.cern.ch/viewvc/trunk/LICENSE) */
+static const ushort greek_symbol_to_unicode[64] = {
+//
+// upper case letters:
+// ----------------
+// Alpha Beta Chi Delta Epsilon Phi Gamma Eta
+ 0x0391, 0x0392, 0x03A7, 0x0394, 0x0395, 0x03A6, 0x0393, 0x0397,
+// Iota Theta(S) Kappa Lambda Mu Nu Omicron Pi
+ 0x0399, 0x03D1, 0x039A, 0x039B, 0x039C, 0x039D, 0x039F, 0x03A0,
+// Theta Rho Sigma Tau Upsilon Stigma Omega Xi
+ 0x0398, 0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03DB, 0x03A9, 0x039E,
+// Psi Zeta Sigma Tau Upsilon ???? Omega Xi
+ 0x03A8, 0x0396, 0x03EA, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+//
+// lower case letters:
+// ----------------
+// Alpha Beta Chi Delta Epsilon Phi Gamma Eta
+ 0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x03B5, 0x03D5, 0x03B3, 0x03B7,
+// Iota Phi (2) Kappa Lambda Mu Nu Omicron Pi
+ 0x03B9, 0x03C6, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF, 0x03C0,
+// Theta Rho Sigma Tau Upsilon OmegaPi Omega Xi
+ 0x03B8, 0x03C1, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03B9, 0x03BE,
+// Psi Zeta Sigma Tau Upsilon ???? Omega Xi
+ 0x03C8, 0x03B6, 0x03EA, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD
+};
+
+/* Symbol to unicode conversion table copied from http://root.cern.ch/viewvc/trunk/qt/src/TQtSymbolCodec.cxx
+This code is placed under GPL licence (http://root.cern.ch/viewvc/trunk/LICENSE) */
+static const ushort symbol_to_unicode[96] = {
+//
+// upper case letters:
+// ----------------
+// UPSILON NUMBER LessEq Div INFINITY ??????? CLUB DIAMOND
+ 0x03D2, 0x0374, 0x2264, 0x2215, 0x221E, 0x0395, 0x2663, 0x2666,
+// HEART SPADE <---> <--- --> RING
+ 0x2665, 0x2660, 0x2194, 0x2190, 0x2191, 0x2192, 0x2193, 0x2218,
+// Theta Rho Great ???? Propor diff bullet ????
+ 0x0398, 0x03A1, 0x2265, 0x03A4, 0x221D, 0x2202, 0x2219, 0x03A8,
+// NonEq Ident ???? ellips div minus ????? aleph
+ 0x2260, 0x2261, 0xFFFD, 0x22EF, 0x2223, 0x2212, 0xFFFD, 0xFFFD,
+//
+// lower case letters:
+// ----------------
+// Alpha Beta Chi Delta Epsilon Phi Gamma Eta
+ 0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x03B5, 0x03D5, 0x03B3, 0x03B7,
+// Iota Phi (2) Kappa Lambda Mu Nu Omicron Pi
+ 0x03B9, 0x03C6, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF, 0x03C0,
+// Theta Rho Sigma Tau Upsilon OmegaPi Omega Xi
+ 0x03B8, 0x03C1, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03B9, 0x03BE,
+// Psi Zeta arrow Tau Upsilon ???? Omega Xi
+ 0x03C8, 0x03B6, 0x21D4, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
+// lower case letters:
+// ----------------
+// Alpha Beta Chi Delta Sigma Phi Gamma Eta
+ 0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x2211, 0x03D5, 0x03B3, 0x03B7,
+// Iota Phi (2) Kappa Lambda Mu Nu Omicron Pi
+ 0x03B9, 0x03C6, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF, 0x03C0,
+// Theta Integr Sigma Tau Upsilon OmegaPi Omega Xi
+ 0x03B8, 0x222b, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03B9, 0x03BE,
+// Psi Zeta Sigma Tau Upsilon ???? Omega Xi
+ 0x03C8, 0x03B6, 0x03EA, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD
+};
+
+WMFImport::WMFImport( ScribusMainWindow* mw, int flags ) :
+ QObject(mw)
+{
+ m_tmpSel = new Selection(this, false);
+ m_Doc = mw->doc;
+ unsupported = false;
+ importFailed = false;
+ importCanceled = true;
+ importedColors.clear();
+ m_docDesc = "";
+ m_docTitle = "";
+ interactive = (flags & LoadSavePlugin::lfInteractive);
+
+ m_Valid = false;
+ m_ObjHandleTab = NULL;
+ m_Dpi = 1440;
+}
+
+WMFImport::~WMFImport()
+{
+ qDeleteAll(m_commands);
+ m_commands.clear();
+ if ( m_tmpSel) delete m_tmpSel;
+ if ( m_ObjHandleTab )
+ {
+ for (int i = 0; i < MAX_OBJHANDLE; ++i)
+ {
+ if (m_ObjHandleTab[i])
+ delete m_ObjHandleTab[i];
+ }
+ delete[] m_ObjHandleTab;
+ }
+}
+
+QString WMFImport::importColor(const QColor& color)
+{
+ bool found = false;
+ int r, g, b;
+ QColor tmpColor;
+ QString retColorName;
+ ColorList::Iterator it;
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelRGB)
+ {
+ it.value().getRGB(&r, &g, &b);
+ tmpColor.setRgb(r, g, b);
+ if (color == tmpColor)
+ {
+ retColorName = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ {
+ ScColor tmp;
+ tmp.fromQColor(color);
+ tmp.setSpotColor(false);
+ tmp.setRegistrationColor(false);
+ m_Doc->PageColors.insert("FromWMF"+color.name(), tmp);
+ importedColors.append("FromWMF"+color.name());
+ retColorName = "FromWMF"+color.name();
+ }
+ return retColorName;
+}
+
+QColor WMFImport::colorFromParam( short* params )
+{
+ unsigned int colorRef;
+ int red, green, blue;
+
+ colorRef = toDWord( params ) & 0xffffff;
+ red = colorRef & 255;
+ green = ( colorRef>>8 ) & 255;
+ blue = ( colorRef>>16 ) & 255;
+
+ return QColor( red, green, blue );
+}
+
+QTextCodec* WMFImport::codecFromCharset( int charset )
+{
+ QTextCodec* codec = NULL;
+ if (charset == DEFAULT_CHARSET || charset == OEM_CHARSET)
+ codec = QTextCodec::codecForLocale();
+ else if (charset == ANSI_CHARSET)
+ codec = QTextCodec::codecForName("windows-1252");
+ /*else if (charset == SYMBOL_CHARSET)
+ codec = QTextCodec::codecForLocale();// Not supported yet*/
+ else if (charset == MAC_CHARSET)
+ codec = QTextCodec::codecForName("Apple Roman");
+ else if (charset == SHIFTJIS_CHARSET)
+ codec = QTextCodec::codecForName("Shift-JIS");
+ else if (charset == HANGEUL_CHARSET)
+ codec = QTextCodec::codecForName("CP949");
+ else if (charset == GB2312_CHARSET)
+ codec = QTextCodec::codecForName("CP936");
+ else if (charset == CHINESEBIG5_CHARSET)
+ codec = QTextCodec::codecForName("Big5");
+ else if (charset == GREEK_CHARSET)
+ codec = QTextCodec::codecForName("windows-1253");
+ else if (charset == TURKISH_CHARSET)
+ codec = QTextCodec::codecForName("windows-1254");
+ else if (charset == VIETNAMESE_CHARSET)
+ codec = QTextCodec::codecForName("windows-1258");
+ else if (charset == HEBREW_CHARSET)
+ codec = QTextCodec::codecForName("windows-1255");
+ else if (charset == ARABIC_CHARSET)
+ codec = QTextCodec::codecForName("windows-1256");
+ else if (charset == BALTIC_CHARSET)
+ codec = QTextCodec::codecForName("windows-1257");
+ else if (charset == RUSSIAN_CHARSET)
+ codec = QTextCodec::codecForName("windows-1251");
+ else if (charset == THAI_CHARSET)
+ codec = QTextCodec::codecForName("CP874");
+ else if (charset == EASTEUROPE_CHARSET)
+ codec = QTextCodec::codecForName("windows-1250");
+ return codec;
+}
+
+QString WMFImport::symbolToUnicode ( const QByteArray& chars )
+{
+ /*Code under GPL licence (http://root.cern.ch/viewvc/trunk/LICENSE)
+ taken from http://root.cern.ch/viewvc/trunk/qt/src/TQtSymbolCodec.cxx*/
+ QString r;
+ const unsigned char * c = (const unsigned char *) chars.data();
+
+ if( chars.size() == 0 ) return r;
+
+ for (int i = 0; i < chars.size(); ++i)
+ {
+ if ( 64 < c[i] && c[i] <= 64+32 )
+ r.append( QChar(greek_symbol_to_unicode[c[i]-65]) );
+ else if (64+32+1 <= c[i] && c[i] < 64+32+32+1)
+ r.append( QChar(greek_symbol_to_unicode[c[i]-65-32]+32) );
+ else if (161 <= c[i] )
+ r.append( QChar(symbol_to_unicode[c[i]-161]) );
+ else
+ r.append( QChar(c[i]) );
+ }
+ return r;
+}
+
+FPointArray WMFImport::pointsFromParam( short num, short* params )
+{
+ FPointArray points;
+ points.resize( num );
+
+ for ( int i = 0; i < num; i++, params += 2 )
+ points.setPoint( i, params[ 0 ], params[ 1 ] );
+
+ return points;
+}
+
+FPointArray WMFImport::pointsToPolyline( const FPointArray& points, bool closePath )
+{
+ bool bFirst = true;
+ double x = 0.0, y = 0.0;
+ FPointArray polyline;
+ polyline.svgInit();
+ for( uint i = 0; i < points.size(); ++i )
+ {
+ FPoint point = points.point(i);
+ if( bFirst )
+ {
+ x = point.x();
+ y = point.y();
+ polyline.svgMoveTo(x, y);
+ bFirst = false;
+ }
+ else
+ {
+ x = point.x();
+ y = point.y();
+ polyline.svgLineTo(x, y);
+ }
+ }
+ if (closePath && (points.size() > 4))
+ polyline.svgClosePath();
+ return polyline;
+}
+
+void WMFImport::pointsToAngle( double xStart, double yStart, double xEnd, double yEnd, double& angleStart, double& angleLength )
+{
+ double aStart = atan2( yStart, xStart );
+ double aLength = atan2( yEnd, xEnd ) - aStart;
+
+ angleStart = (int)(aStart * 180.0 / 3.14166);
+ angleLength = (int)(aLength * 180.0 / 3.14166);
+ if ( angleLength < 0 ) angleLength = 360.0 + angleLength;
+}
+
+bool WMFImport::import(QString fname, const TransactionSettings& trSettings, int flags)
+{
+ if (!loadWMF(fname))
+ {
+ importFailed = true;
+ return false;
+ }
+ QString CurDirP = QDir::currentPath();
+ QFileInfo efp(fname);
+ QDir::setCurrent(efp.path());
+ bool success = importWMF(trSettings, flags);
+ QDir::setCurrent(CurDirP);
+ return success;
+}
+
+bool WMFImport::loadWMF( const QString &fileName )
+{
+ QFile file( fileName );
+
+ if ( !file.exists() )
+ {
+ cerr << "File " << QFile::encodeName(fileName).data() << " does not exist" << endl;
+ return false;
+ }
+
+ if ( !file.open( QIODevice::ReadOnly ) )
+ {
+ cerr << "Cannot open file " << QFile::encodeName(fileName).data() << endl;
+ return false;
+ }
+
+ QByteArray ba = file.readAll();
+ file.close();
+
+ QBuffer buffer( &ba );
+ buffer.open( QIODevice::ReadOnly );
+ return loadWMF( buffer );
+}
+
+bool WMFImport::loadWMF( QBuffer &buffer )
+{
+ QDataStream st;
+ WmfEnhMetaHeader eheader;
+ WmfMetaHeader header;
+ WmfPlaceableHeader pheader;
+ WORD16 checksum;
+ int filePos, idx, i;
+ WmfCmd *cmd;
+ WORD32 rdSize;
+ WORD16 rdFunc;
+
+ header.mtSize = 0;
+ header.mtHeaderSize = 0;
+ header.mtNoParameters = 0;
+
+ qDeleteAll(m_commands);
+ m_commands.clear();
+
+ st.setDevice( &buffer );
+ st.setByteOrder( QDataStream::LittleEndian ); // Great, I love Qt !
+
+ //----- Read placeable metafile header
+ st >> pheader.key;
+ m_IsPlaceable = (pheader.key == (WORD32) APMHEADER_KEY);
+ if ( m_IsPlaceable )
+ {
+ st >> pheader.hmf;
+ st >> pheader.bbox.left;
+ st >> pheader.bbox.top;
+ st >> pheader.bbox.right;
+ st >> pheader.bbox.bottom;
+ st >> pheader.inch;
+ st >> pheader.reserved;
+ st >> pheader.checksum;
+ checksum = calcCheckSum( &pheader );
+ if ( pheader.checksum!=checksum ) m_IsPlaceable = false;
+
+ m_Dpi = pheader.inch;
+ m_BBox.setLeft( pheader.bbox.left );
+ m_BBox.setTop( pheader.bbox.top );
+ m_BBox.setRight( pheader.bbox.right );
+ m_BBox.setBottom( pheader.bbox.bottom );
+ m_HeaderBoundingBox = m_BBox;
+ if ( WMFIMPORT_DEBUG )
+ {
+ cerr << endl << "-------------------------------------------------" << endl;
+ cerr << "WMF Placeable Header ( " << static_cast<int>(sizeof( pheader ) ) << "):" << endl;
+ cerr << " bbox=( " << m_BBox.left() << "; " << m_BBox.top() << "; " << m_BBox.width() << "; " << m_BBox.height() << ")" << endl;
+ cerr << " inch=" << pheader.inch << endl;
+ cerr << " checksum=" << pheader.checksum << "( " << (pheader.checksum==checksum?"ok":"wrong") << " )" << endl;
+ }
+ }
+ else buffer.seek( 0 );
+
+ //----- Read as enhanced metafile header
+ filePos = buffer.pos();
+ st >> eheader.iType;
+ st >> eheader.nSize;
+ st >> eheader.rclBounds.left;
+ st >> eheader.rclBounds.top;
+ st >> eheader.rclBounds.right;
+ st >> eheader.rclBounds.bottom;
+ st >> eheader.rclFrame.left;
+ st >> eheader.rclFrame.top;
+ st >> eheader.rclFrame.right;
+ st >> eheader.rclFrame.bottom;
+ st >> eheader.dSignature;
+ m_IsEnhanced = ( eheader.dSignature==ENHMETA_SIGNATURE );
+ if ( m_IsEnhanced ) // is it really enhanced ?
+ {
+ st >> eheader.nVersion;
+ st >> eheader.nBytes;
+ st >> eheader.nRecords;
+ st >> eheader.nHandles;
+ st >> eheader.sReserved;
+ st >> eheader.nDescription;
+ st >> eheader.offDescription;
+ st >> eheader.nPalEntries;
+ st >> eheader.szlDevice.width;
+ st >> eheader.szlDevice.height;
+ st >> eheader.szlMillimeters.width;
+ st >> eheader.szlMillimeters.height;
+
+ if ( WMFIMPORT_DEBUG )
+ {
+ cerr << endl << "-------------------------------------------------" << endl;
+ cerr << "WMF Extended Header:" << endl;
+ cerr << " iType=" << eheader.iType << endl;
+ cerr << " nSize=" << eheader.nSize << endl;
+ cerr << " rclBounds=( " << eheader.rclBounds.left << "; " << eheader.rclBounds.top << "; "
+ << eheader.rclBounds.right << "; " << eheader.rclBounds.bottom << ")" << endl;
+ cerr << " rclFrame=( " << eheader.rclFrame.left << "; " << eheader.rclFrame.top << "; "
+ << eheader.rclFrame.right << "; " << eheader.rclFrame.bottom << ")" << endl;
+ cerr << " nBytes=" << eheader.nBytes << endl;
+ cerr << "\nNOT YET IMPLEMENTED, SORRY." << endl;
+ }
+ }
+ else // no, not enhanced
+ {
+ //----- Read as standard metafile header
+ buffer.seek( filePos );
+ st >> header.mtType;
+ st >> header.mtHeaderSize;
+ st >> header.mtVersion;
+ st >> header.mtSize;
+ st >> header.mtNoObjects;
+ st >> header.mtMaxRecord;
+ st >> header.mtNoParameters;
+ if ( WMFIMPORT_DEBUG ) {
+ cerr << "WMF Header: " << "mtSize=" << header.mtSize << endl;
+ }
+ }
+
+ //----- Test header validity
+ m_Valid = ((header.mtHeaderSize == 9) && (header.mtNoParameters == 0)) || m_IsEnhanced || m_IsPlaceable;
+ if ( m_Valid )
+ {
+ //----- Read Metafile Records
+ rdFunc = -1;
+ while ( !st.atEnd() && (rdFunc != 0) )
+ {
+ st >> rdSize;
+ st >> rdFunc;
+ idx = findFunc( rdFunc );
+ rdSize -= 3;
+
+ cmd = new WmfCmd;
+ m_commands.append(cmd);
+
+ cmd->funcIndex = idx;
+ cmd->numParam = rdSize;
+ cmd->params = new WORD16[ rdSize ];
+
+ for ( i=0; i<rdSize && !st.atEnd(); i++ )
+ st >> cmd->params[ i ];
+
+
+ if ( rdFunc == 0x020B && !m_IsPlaceable) { // SETWINDOWORG: dimensions
+ m_BBox.setLeft( qMin((int) cmd->params[ 1 ], m_BBox.left()) );
+ m_BBox.setTop ( qMin((int) cmd->params[ 0 ], m_BBox.top()) );
+ }
+ if ( rdFunc == 0x020C && !m_IsPlaceable ) { // SETWINDOWEXT: dimensions
+ m_BBox.setWidth ( qMax((int) cmd->params[ 1 ], m_BBox.width()) );
+ m_BBox.setHeight( qMax((int) cmd->params[ 0 ], m_BBox.height()));
+ }
+
+ if ( i<rdSize )
+ {
+ cerr << "WMF : file truncated !" << endl;
+ return false;
+ }
+ }
+ //----- Test records validities
+ m_Valid = (rdFunc == 0) && (m_BBox.width() != 0) && (m_BBox.height() != 0);
+ if ( !m_Valid ) {
+ cerr << "WMF : incorrect file format !" << endl;
+ }
+ }
+ else {
+ cerr << "WMF Header : incorrect header !" << endl;
+ }
+
+ buffer.close();
+ return m_Valid;
+}
+
+bool WMFImport::importWMF(const TransactionSettings& trSettings, int flags)
+{
+ bool ret = false;
+ //double scale = (m_Dpi > 288) ? 288.0 / m_Dpi : 1.0;
+ double scale = (m_Dpi > 0) ? 72.0 / m_Dpi : 0.05;
+ double width = m_BBox.width() * scale;
+ double height = m_BBox.height() * scale;
+ if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
+ {
+ m_Doc->setPage(fabs(width), fabs(height), 0, 0, 0, 0, 0, 0, false, false);
+ m_Doc->addPage(0);
+ m_Doc->view()->addPage(0);
+ }
+ else
+ {
+ if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
+ {
+ m_Doc=ScCore->primaryMainWindow()->doFileNew(fabs(width), fabs(height), 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
+ ScCore->primaryMainWindow()->HaveNewDoc();
+ ret = true;
+ }
+ }
+ if ((ret) || (!interactive))
+ {
+ if (width > height)
+ m_Doc->PageOri = 1;
+ else
+ m_Doc->PageOri = 0;
+ m_Doc->m_pageSize = "Custom";
+ }
+ FPoint minSize = m_Doc->minCanvasCoordinate;
+ FPoint maxSize = m_Doc->maxCanvasCoordinate;
+ FPoint cOrigin = m_Doc->view()->canvasOrigin();
+ m_Doc->view()->Deselect();
+ m_Doc->setLoading(true);
+ m_Doc->DoDrawing = false;
+ m_Doc->view()->updatesOn(false);
+ m_Doc->scMW()->ScriptRunning = true;
+ qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
+ //gc->Family = m_Doc->toolSettings.defFont;
+ m_Doc->PageColors.ensureBlackAndWhite();
+ //m_gc.push( gc );
+ QList<PageItem*> Elements = parseWmfCommands();
+ if (flags & LoadSavePlugin::lfCreateDoc)
+ {
+ m_Doc->documentInfo.setTitle(m_docTitle);
+ m_Doc->documentInfo.setComments(m_docDesc);
+ }
+ m_tmpSel->clear();
+ if (Elements.count() == 0)
+ {
+ importFailed = true;
+ if (importedColors.count() != 0)
+ {
+ for (int cd = 0; cd < importedColors.count(); cd++)
+ {
+ m_Doc->PageColors.remove(importedColors[cd]);
+ }
+ }
+ }
+ if (Elements.count() > 1)
+ {
+ bool isGroup = true;
+ int firstElem = -1;
+ if (Elements.at(0)->Groups.count() != 0)
+ firstElem = Elements.at(0)->Groups.top();
+ for (int bx = 0; bx < Elements.count(); ++bx)
+ {
+ PageItem* bxi = Elements.at(bx);
+ if (bxi->Groups.count() != 0)
+ {
+ if (bxi->Groups.top() != firstElem)
+ isGroup = false;
+ }
+ else
+ isGroup = false;
+ }
+ if (!isGroup)
+ {
+ double minx = 99999.9;
+ double miny = 99999.9;
+ double maxx = -99999.9;
+ double maxy = -99999.9;
+ uint lowestItem = 999999;
+ uint highestItem = 0;
+ for (int a = 0; a < Elements.count(); ++a)
+ {
+ Elements.at(a)->Groups.push(m_Doc->GroupCounter);
+ PageItem* currItem = Elements.at(a);
+ lowestItem = qMin(lowestItem, currItem->ItemNr);
+ highestItem = qMax(highestItem, currItem->ItemNr);
+ double x1, x2, y1, y2;
+ currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
+ minx = qMin(minx, x1);
+ miny = qMin(miny, y1);
+ maxx = qMax(maxx, x2);
+ maxy = qMax(maxy, y2);
+ }
+ double gx = minx;
+ double gy = miny;
+ double gw = maxx - minx;
+ double gh = maxy - miny;
+ PageItem *high = m_Doc->Items->at(highestItem);
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, m_Doc->toolSettings.dBrush, m_Doc->toolSettings.dPen, true);
+ PageItem *neu = m_Doc->Items->takeAt(z);
+ m_Doc->Items->insert(lowestItem, neu);
+ neu->Groups.push(m_Doc->GroupCounter);
+ neu->setItemName( tr("Group%1").arg(neu->Groups.top()));
+ neu->AutoName = false;
+ neu->isGroupControl = true;
+ neu->groupsLastItem = high;
+ for (int a = 0; a < m_Doc->Items->count(); ++a)
+ {
+ m_Doc->Items->at(a)->ItemNr = a;
+ }
+ neu->setRedrawBounding();
+ neu->setTextFlowMode(PageItem::TextFlowDisabled);
+ Elements.prepend(neu);
+ m_Doc->GroupCounter++;
+ }
+ }
+ m_Doc->DoDrawing = true;
+ m_Doc->scMW()->ScriptRunning = false;
+ if (interactive)
+ m_Doc->setLoading(false);
+ qApp->setOverrideCursor(QCursor(Qt::ArrowCursor));
+ if ((Elements.count() > 0) && (!ret) && (interactive))
+ {
+ if (flags & LoadSavePlugin::lfScripted)
+ {
+ bool loadF = m_Doc->isLoading();
+ m_Doc->setLoading(false);
+ m_Doc->changed();
+ m_Doc->setLoading(loadF);
+ m_Doc->m_Selection->delaySignalsOn();
+ for (int dre=0; dre<Elements.count(); ++dre)
+ {
+ m_Doc->m_Selection->addItem(Elements.at(dre), true);
+ }
+ m_Doc->m_Selection->delaySignalsOff();
+ m_Doc->m_Selection->setGroupRect();
+ m_Doc->view()->updatesOn(true);
+ importCanceled = false;
+ }
+ else
+ {
+ m_Doc->DragP = true;
+ m_Doc->DraggedElem = 0;
+ m_Doc->DragElements.clear();
+ m_Doc->m_Selection->delaySignalsOn();
+ for (int dre=0; dre<Elements.count(); ++dre)
+ {
+ m_Doc->DragElements.append(Elements.at(dre)->ItemNr);
+ m_tmpSel->addItem(Elements.at(dre), true);
+ }
+ ScriXmlDoc *ss = new ScriXmlDoc();
+ m_tmpSel->setGroupRect();
+ ScElemMimeData* md = new ScElemMimeData();
+ md->setScribusElem(ss->WriteElem(m_Doc, m_Doc->view(), m_tmpSel));
+ delete ss;
+/*#ifndef QT_MAC*/
+// see #2526
+ m_Doc->itemSelection_DeleteItem(m_tmpSel);
+/*#endif*/
+ m_Doc->view()->updatesOn(true);
+ m_Doc->m_Selection->delaySignalsOff();
+ // We must copy the TransationSettings object as it is owned
+ // by handleObjectImport method afterwards
+ TransactionSettings* transacSettings = new TransactionSettings(trSettings);
+ m_Doc->view()->handleObjectImport(md, transacSettings);
+ m_Doc->DragP = false;
+ m_Doc->DraggedElem = 0;
+ m_Doc->DragElements.clear();
+ }
+ }
+ else
+ {
+ bool loadF = m_Doc->isLoading();
+ m_Doc->setLoading(false);
+ m_Doc->changed();
+ m_Doc->reformPages();
+ m_Doc->view()->updatesOn(true);
+ m_Doc->setLoading(loadF);
+ }
+ return true;
+}
+
+QList<PageItem*> WMFImport::parseWmfCommands(void)
+{
+ int idx, i;
+ const WmfCmd* cmd;
+ QList<PageItem*> elements;
+
+ m_context.reset();
+
+ if ( !m_Valid ) return elements;
+
+ if ( m_ObjHandleTab ) delete[] m_ObjHandleTab;
+ m_ObjHandleTab = new WmfObjHandle* [ MAX_OBJHANDLE ];
+ for ( i = MAX_OBJHANDLE-1; i >= 0; i-- )
+ m_ObjHandleTab[ i ] = NULL;
+
+ if ( WMFIMPORT_DEBUG ) {
+ cerr << "Bounding box : " << m_BBox.left() << " " << m_BBox.top() << " " << m_BBox.right() << " " << m_BBox.bottom() << endl;
+ }
+
+ double scale = (m_Dpi > 0) ? 72.0 / m_Dpi : 0.05;
+ m_context.setViewportOrg( 0, 0 );
+ m_context.setViewportExt( m_BBox.width() * scale, m_BBox.height() * scale );
+ m_context.setWindowOrg( m_BBox.left(), m_BBox.bottom() );
+ m_context.setWindowExt( m_BBox.width(), m_BBox.height() );
+
+ for (int index = 0; index < m_commands.count(); ++index)
+ {
+ cmd = m_commands.at(index);
+ idx = cmd->funcIndex;
+ ( this->*metaFuncTab[ idx ].method )( elements, cmd->numParam, cmd->params );
+
+ if ( WMFIMPORT_DEBUG ) {
+ QString str = "", param;
+ if ( metaFuncTab[ idx ].name == NULL ) {
+ str += "UNKNOWN ";
+ }
+ if ( metaFuncTab[ idx ].method == &WMFImport::noop ) {
+ str += "UNIMPLEMENTED ";
+ }
+ str += metaFuncTab[ idx ].name;
+ str += " : ";
+
+ for ( i=0 ; i < cmd->numParam ; i++ ) {
+ param.setNum( cmd->params[ i ] );
+ str += param;
+ str += " ";
+ }
+ cerr << str.toAscii().data() << endl;
+ }
+ }
+ return elements;
+}
+
+void WMFImport::finishCmdParsing( PageItem* item )
+{
+ QTransform gcm = m_context.worldMatrix();
+ double coeff1 = sqrt(gcm.m11() * gcm.m11() + gcm.m12() * gcm.m12());
+ double coeff2 = sqrt(gcm.m21() * gcm.m21() + gcm.m22() * gcm.m22());
+ if( item->asImageFrame() )
+ {
+ item->moveBy(gcm.dx(), gcm.dy());
+ item->setWidthHeight(item->width() * gcm.m11(), item->height() * gcm.m22());
+ item->setLineWidth(qMax(item->lineWidth() * (coeff1 + coeff2) / 2.0, 0.25));
+ if (item->PictureIsAvailable)
+ item->setImageXYScale(item->width() / item->pixm.width(), item->height() / item->pixm.height());
+ }
+ else if( item->asTextFrame() )
+ {
+ item->setLineWidth(qMax(item->lineWidth() * (coeff1 + coeff2) / 2.0, 0.25));
+ }
+ else
+ {
+ item->ClipEdited = true;
+ item->FrameType = 3;
+ item->PoLine.map(gcm);
+ item->setLineWidth(qMax(item->lineWidth() * (coeff1 + coeff2) / 2.0, 0.25));
+ FPoint wh = getMaxClipF(&item->PoLine);
+ item->setWidthHeight(wh.x(), wh.y());
+ m_Doc->AdjustItemSize(item);
+ }
+ item->setRedrawBounding();
+ item->OwnPage = m_Doc->OnPage(item);
+ item->PLineEnd = m_context.pen().capStyle();
+ item->PLineJoin = m_context.pen().joinStyle();
+ item->setTextFlowMode(PageItem::TextFlowDisabled);
+ //item->DashOffset = gc->dashOffset;
+ //item->DashValues = gc->dashArray;
+}
+
+void WMFImport::setWindowOrg( QList<PageItem*>& /*items*/, long, short* params )
+{
+ m_context.setWindowOrg( params[ 1 ], params[ 0 ] );
+}
+
+void WMFImport::setWindowExt( QList<PageItem*>& /*items*/, long, short* params )
+{
+ m_context.setWindowExt( params[ 1 ], params[ 0 ] );
+}
+
+void WMFImport::lineTo( QList<PageItem*>& items, long, short* params )
+{
+ double BaseX = m_Doc->currentPage()->xOffset();
+ double BaseY = m_Doc->currentPage()->yOffset();
+ QPoint currentPos = m_context.position();
+ bool doStroke = (m_context.pen().style() != Qt::NoPen);
+ if (doStroke)
+ {
+ double x1 = currentPos.x();
+ double y1 = currentPos.y();
+ double x2 = params[1];
+ double y2 = params[0];
+ double lineWidth = m_context.pen().width();
+ QString lineColor = importColor(m_context.pen().color());
+ int z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, CommonStrings::None, lineColor, true);
+ PageItem* ite = m_Doc->Items->at(z);
+ ite->PoLine.resize(4);
+ ite->PoLine.setPoint(0, FPoint(x1, y1));
+ ite->PoLine.setPoint(1, FPoint(x1, y1));
+ ite->PoLine.setPoint(2, FPoint(x2, y2));
+ ite->PoLine.setPoint(3, FPoint(x2, y2));
+ finishCmdParsing(ite);
+ items.append(ite);
+ }
+ m_context.setPosition( QPoint(params[1], params[0]) );
+}
+
+void WMFImport::moveTo( QList<PageItem*>& /*items*/, long, short* params )
+{
+ m_context.setPosition( QPoint(params[1], params[0]) );
+}
+
+void WMFImport::ellipse( QList<PageItem*>& items, long, short* params )
+{
+ double BaseX = m_Doc->currentPage()->xOffset();
+ double BaseY = m_Doc->currentPage()->yOffset();
+ double rx = (params[ 1 ] - params[ 3 ]) / 2.0;
+ double ry = (params[ 0 ] - params[ 2 ]) / 2.0;
+ double px = (params[ 1 ] + params[ 3 ]) / 2.0 - rx;
+ double py = (params[ 0 ] + params[ 2 ]) / 2.0 - ry;
+ bool doFill = m_context.brush().style() != Qt::NoBrush;
+ bool doStroke = m_context.pen().style() != Qt::NoPen;
+ QString fillColor = doFill ? importColor( m_context.brush().color() ) : CommonStrings::None;
+ QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
+ double lineWidth = m_context.pen().width();
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, BaseX, BaseY, rx * 2.0, ry * 2.0, lineWidth, fillColor, strokeColor, true);
+ PageItem* ite = m_Doc->Items->at(z);
+ QTransform mm(1.0, 0.0, 0.0, 1.0, px, py);
+ ite->PoLine.map(mm);
+ finishCmdParsing(ite);
+ items.append(ite);
+}
+
+void WMFImport::polygon( QList<PageItem*>& items, long, short* params )
+{
+ //cerr << "WMFImport::polygon unimplemented" << endl;
+ double BaseX = m_Doc->currentPage()->xOffset();
+ double BaseY = m_Doc->currentPage()->yOffset();
+ bool doFill = m_context.brush().style() != Qt::NoBrush;
+ bool doStroke = m_context.pen().style() != Qt::NoPen;
+ QString fillColor = doFill ? importColor( m_context.brush().color() ) : CommonStrings::None;
+ QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
+ double lineWidth = m_context.pen().width();
+ if (doStroke && lineWidth <= 0.0 )
+ lineWidth = 1.0;
+ FPointArray paramPoints = pointsFromParam( params[0], ¶ms[1] );
+ FPointArray points = pointsToPolyline( paramPoints, true );
+ if( paramPoints.size() > 0 )
+ {
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, fillColor, strokeColor, true);
+ PageItem* ite = m_Doc->Items->at(z);
+ ite->PoLine = points;
+ ite->fillRule = !m_context.windingFill();
+ finishCmdParsing(ite);
+ items.append(ite);
+ }
+}
+
+void WMFImport::polyPolygon( QList<PageItem*>& items, long num, short* params )
+{
+ int numPolys = params[0];
+ int pointIndex = params[0] + 1;
+ for (int i = 0; i < numPolys; ++i)
+ {
+ short numPoints = params[i + 1];
+ short* paramArray = new short[1 + 2 * numPoints];
+ paramArray[0] = numPoints;
+ memcpy(¶mArray[1], ¶ms[pointIndex], 2 * numPoints * sizeof(short));
+ polygon(items, num, paramArray);
+ delete[] paramArray;
+ pointIndex += (2 * numPoints);
+ }
+}
+
+void WMFImport::polyline( QList<PageItem*>& items, long, short* params )
+{
+ //cerr << "WMFImport::polyline unimplemented" << endl;
+ double BaseX = m_Doc->currentPage()->xOffset();
+ double BaseY = m_Doc->currentPage()->yOffset();
+ bool doStroke = m_context.pen().style() != Qt::NoPen;
+ QString fillColor = CommonStrings::None;
+ QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
+ double lineWidth = m_context.pen().width();
+ if (doStroke && lineWidth <= 0.0 )
+ lineWidth = 1.0;
+ FPointArray paramPoints = pointsFromParam( params[0], ¶ms[1] );
+ FPointArray points = pointsToPolyline( paramPoints, false );
+ if( paramPoints.size() > 0 )
+ {
+ int z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, fillColor, strokeColor, true);
+ PageItem* ite = m_Doc->Items->at(z);
+ ite->PoLine = points;
+ finishCmdParsing(ite);
+ items.append(ite);
+ }
+}
+
+void WMFImport::rectangle( QList<PageItem*>& items, long, short* params )
+{
+ //cerr << "WMFImport::rectangle unimplemented" << endl;
+ double BaseX = m_Doc->currentPage()->xOffset();
+ double BaseY = m_Doc->currentPage()->yOffset();
+ bool doFill = m_context.brush().style() != Qt::NoBrush;
+ bool doStroke = m_context.pen().style() != Qt::NoPen;
+ QString fillColor = doFill ? importColor( m_context.brush().color() ) : CommonStrings::None;
+ QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
+ double lineWidth = m_context.pen().width();
+ if (doStroke && lineWidth <= 0.0 )
+ lineWidth = 1.0;
+ double x = ((params[3] - params[1]) > 0) ? params[1] : params[3];
+ double y = ((params[2] - params[0]) > 0) ? params[0] : params[2];
+ double width = fabs((double) params[3] - params[1]);
+ double height = fabs((double) params[2] - params[0]);
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, BaseX, BaseY, width, height, lineWidth, fillColor, strokeColor, true);
+ PageItem* ite = m_Doc->Items->at(z);
+ QTransform mm(1.0, 0.0, 0.0, 1.0, x, y);
+ ite->PoLine.map(mm);
+ finishCmdParsing(ite);
+ items.append(ite);
+}
+
+void WMFImport::roundRect( QList<PageItem*>& items, long, short* params )
+{
+ //cerr << "WMFImport::roundRect unimplemented" << endl;
+ double BaseX = m_Doc->currentPage()->xOffset();
+ double BaseY = m_Doc->currentPage()->yOffset();
+ bool doFill = m_context.brush().style() != Qt::NoBrush;
+ bool doStroke = m_context.pen().style() != Qt::NoPen;
+ QString fillColor = doFill ? importColor( m_context.brush().color() ) : CommonStrings::None;
+ QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
+ double lineWidth = m_context.pen().width();
+ if (doStroke && lineWidth <= 0.0 )
+ lineWidth = 1.0;
+ double x = ((params[5] - params[3]) > 0) ? params[3] : params[5];
+ double y = ((params[4] - params[2]) > 0) ? params[2] : params[4];
+ double width = fabs((double) params[5] - params[3]);
+ double height = fabs((double) params[4] - params[2]);
+ double rx = params[1] / 2.0;
+ double ry = params[0] / 2.0;
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, BaseX, BaseY, width, height, lineWidth, fillColor, strokeColor, true);
+ PageItem* ite = m_Doc->Items->at(z);
+ if ((rx != 0.0) || (ry != 0.0))
+ {
+ ite->setCornerRadius(qMax(rx, ry));
+ ite->SetFrameRound();
+ m_Doc->setRedrawBounding(ite);
+ }
+ QTransform mm(1.0, 0.0, 0.0, 1.0, x, y);
+ ite->PoLine.map(mm);
+ finishCmdParsing(ite);
+ items.append(ite);
+}
+
+void WMFImport::arc( QList<PageItem*>& items, long, short* params )
+{
+ FPointArray pointArray;
+ QPainterPath painterPath;
+ double BaseX = m_Doc->currentPage()->xOffset();
+ double BaseY = m_Doc->currentPage()->yOffset();
+ bool doStroke = m_context.pen().style() != Qt::NoPen;
+ QString fillColor = CommonStrings::None;
+ QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
+ double lineWidth = m_context.pen().width();
+ if (doStroke && lineWidth <= 0.0 )
+ lineWidth = 1.0;
+ double angleStart, angleLength;
+ double x = ((params[7] - params[5]) > 0) ? params[5] : params[7];
+ double y = ((params[6] - params[4]) > 0) ? params[4] : params[6];
+ double xCenter = (params[5] + params[7]) / 2.0;
+ double yCenter = (params[4] + params[6]) / 2.0;
+ double xWidth = fabs((double) params[5] - params[7]);
+ double yHeight = fabs((double) params[4] - params[6]);
+ pointsToAngle(params[3] - xCenter, yCenter - params[2], params[1] - xCenter, yCenter - params[0], angleStart, angleLength);
+ painterPath.arcMoveTo(x, y, xWidth, yHeight, angleStart);
+ painterPath.arcTo(x, y, xWidth, yHeight, angleStart, angleLength);
+ pointArray.fromQPainterPath(painterPath);
+ if( pointArray.size() > 0 )
+ {
+ int z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, fillColor, strokeColor, true);
+ PageItem* ite = m_Doc->Items->at(z);
+ ite->PoLine = pointArray;
+ finishCmdParsing(ite);
+ items.append(ite);
+ }
+}
+
+void WMFImport::chord( QList<PageItem*>& items, long, short* params )
+{
+ QPointF firstPoint;
+ FPointArray pointArray;
+ QPainterPath painterPath;
+ double BaseX = m_Doc->currentPage()->xOffset();
+ double BaseY = m_Doc->currentPage()->yOffset();
+ bool doFill = m_context.brush().style() != Qt::NoBrush;
+ bool doStroke = m_context.pen().style() != Qt::NoPen;
+ QString fillColor = doFill ? importColor( m_context.brush().color() ) : CommonStrings::None;
+ QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
+ double lineWidth = m_context.pen().width();
+ if (doStroke && lineWidth <= 0.0 )
+ lineWidth = 1.0;
+ double angleStart, angleLength;
+ double x = ((params[7] - params[5]) > 0) ? params[5] : params[7];
+ double y = ((params[6] - params[4]) > 0) ? params[4] : params[6];
+ double xCenter = (params[5] + params[7]) / 2.0;
+ double yCenter = (params[4] + params[6]) / 2.0;
+ double xWidth = fabs((double) params[5] - params[7]);
+ double yHeight = fabs((double) params[4] - params[6]);
+ pointsToAngle(params[3] - xCenter, yCenter - params[2], params[1] - xCenter, yCenter - params[0], angleStart, angleLength);
+ painterPath.arcMoveTo(x, y, xWidth, yHeight, angleStart);
+ firstPoint = painterPath.currentPosition();
+ painterPath.arcTo (x, y, xWidth, yHeight, angleStart, angleLength);
+ painterPath.lineTo(firstPoint);
+ pointArray.fromQPainterPath(painterPath);
+ if( pointArray.size() > 0 )
+ {
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, fillColor, strokeColor, true);
+ PageItem* ite = m_Doc->Items->at(z);
+ ite->PoLine = pointArray;
+ finishCmdParsing(ite);
+ items.append(ite);
+ }
+}
+
+void WMFImport::pie( QList<PageItem*>& items, long, short* params )
+{
+ QPointF firstPoint;
+ FPointArray pointArray;
+ QPainterPath painterPath;
+ double BaseX = m_Doc->currentPage()->xOffset();
+ double BaseY = m_Doc->currentPage()->yOffset();
+ bool doFill = m_context.brush().style() != Qt::NoBrush;
+ bool doStroke = m_context.pen().style() != Qt::NoPen;
+ QString fillColor = doFill ? importColor( m_context.brush().color() ) : CommonStrings::None;
+ QString strokeColor = doStroke ? importColor( m_context.pen().color() ) : CommonStrings::None;
+ double lineWidth = m_context.pen().width();
+ if (doStroke && lineWidth <= 0.0 )
+ lineWidth = 1.0;
+ double angleStart, angleLength;
+ double x = ((params[7] - params[5]) > 0) ? params[5] : params[7];
+ double y = ((params[6] - params[4]) > 0) ? params[4] : params[6];
+ double xCenter = (params[5] + params[7]) / 2.0;
+ double yCenter = (params[4] + params[6]) / 2.0;
+ double xWidth = fabs((double) params[5] - params[7]);
+ double yHeight = fabs((double) params[4] - params[6]);
+ pointsToAngle(params[3] - xCenter, yCenter - params[2], params[1] - xCenter, yCenter - params[0], angleStart, angleLength);
+ painterPath.arcMoveTo(x,y, xWidth, yHeight, angleStart);
+ firstPoint = painterPath.currentPosition();
+ painterPath.arcTo (x, y, xWidth, yHeight, angleStart, angleLength);
+ painterPath.lineTo(xCenter, yCenter);
+ painterPath.lineTo(firstPoint);
+ pointArray.fromQPainterPath(painterPath);
+ if( pointArray.size() > 0 )
+ {
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, fillColor, strokeColor, true);
+ PageItem* ite = m_Doc->Items->at(z);
+ ite->PoLine = pointArray;
+ finishCmdParsing(ite);
+ items.append(ite);
+ }
+}
+
+void WMFImport::setPolyFillMode( QList<PageItem*>& /*items*/, long, short* params )
+{
+ m_context.setWindingFill( params[0] );
+}
+
+void WMFImport::setBkColor( QList<PageItem*>& /*items*/, long, short* params )
+{
+ m_context.setBackgroundColor( colorFromParam( params ) );
+}
+
+void WMFImport::setBkMode( QList<PageItem*>& /*items*/, long, short* params )
+{
+ if ( params[ 0 ]==1 )
+ m_context.setBackgroundMode( Qt::TransparentMode );
+ else
+ m_context.setBackgroundMode( Qt::OpaqueMode );
+}
+
+void WMFImport::saveDC( QList<PageItem*>& /*items*/, long, short* )
+{
+ m_context.save();
+}
+
+void WMFImport::restoreDC( QList<PageItem*>& /*items*/, long, short *params )
+{
+ for ( int i=0; i > params[ 0 ] ; i-- )
+ m_context.restore();
+}
+
+void WMFImport::intersectClipRect( QList<PageItem*>& /*items*/, long, short* /*params*/ )
+{
+ cerr << "WMFImport::intersectClipRect unimplemented" << endl;
+}
+
+void WMFImport::excludeClipRect( QList<PageItem*>& /*items*/, long, short* /*params*/ )
+{
+ cerr << "WMFImport::excludeClipRect unimplemented" << endl;
+}
+
+void WMFImport::setTextColor( QList<PageItem*>& /*items*/, long, short* params )
+{
+ m_context.setTextColor( colorFromParam(params) );
+}
+
+void WMFImport::setTextAlign( QList<PageItem*>& /*items*/, long, short* params )
+{
+ m_context.setTextAlign(params[ 0 ]);
+}
+
+void WMFImport::textOut( QList<PageItem*>& items, long num, short* params )
+{
+ short *copyParm = new short[num + 1];
+
+ // re-order parameters
+ int idxOffset = (params[0] / 2) + 1 + (params[0] & 1);
+ copyParm[0] = params[idxOffset];
+ copyParm[1] = params[idxOffset + 1];
+ copyParm[2] = params[0];
+ copyParm[3] = 0;
+ memcpy( ©Parm[4], ¶ms[1], params[0] );
+
+ extTextOut(items, num + 1, copyParm );
+ delete [] copyParm;
+}
+
+void WMFImport::extTextOut( QList<PageItem*>& items, long num, short* params )
+{
+ QString textString;
+ double BaseX = m_Doc->currentPage()->xOffset();
+ double BaseY = m_Doc->currentPage()->yOffset();
+
+ if (params[3] & 0x0010) // ETO_GLYPH_INDEX
+ {
+ cerr << "WMFImport::extTextOut: ETO_GLYPH_INDEX option not supported " << endl;
+ unsupported = true;
+ return;
+ }
+
+ // ETO_CLIPPED flag add 4 parameters
+ char* ptStr = (params[3] & 0x0004) ? ((char*)¶ms[8]) : ((char*)¶ms[4]);
+ QByteArray textArray( ptStr, params[2] );
+
+ QTextCodec* codec = codecFromCharset( m_context.textCharSet() );
+ if (codec)
+ textString = codec->toUnicode(textArray);
+ else if ( m_context.textCharSet() == SYMBOL_CHARSET )
+ textString = symbolToUnicode(textArray);
+ else
+ textString = QString::fromLocal8Bit(textArray.data());
+
+ QFontMetrics fm( m_context.font() );
+ int width = fm.width(textString) + fm.descent(); // because fm.width(text) isn't rigth with Italic text
+ /*int height = fm.height();
+ int ascent = fm.ascent();*/
+
+ double startX = params[1], startY = params[0];
+ int textAlign = m_context.textAlign();
+ double textRotation = m_context.textRotation();
+ if ( textAlign & 0x01 ) { // (left, top) position = current logical position
+ QPoint pos = m_context.position();
+ startX = pos.x();
+ startY = pos.y();
+ }
+
+ m_context.save();
+ // A bit hacky but should be sufficient to have text not flipped
+ // top down in some wmfs (see cell.wmf sample from libwmf)
+ if ( m_context.worldMatrix().m22() < 0.0)
+ {
+ m_context.translate(startX, startY);
+ m_context.scale (1.0, -1.0);
+ m_context.translate( -startX, -startY);
+ }
+ if ( textRotation != 0.0) {
+ m_context.translate(startX, startY);
+ m_context.rotate ( textRotation );
+ m_context.translate( -startX, -startY);
+ }
+
+ if ( (textAlign & 0x04) && (textAlign & 0x02) ) // TA_CENTER 0x06
+ startX -= (width / 2);
+ else if ( textAlign & 0x02 ) // TA_RIGHT 0x02
+ startX -= width;
+ if ( textAlign == 0 ) // TA_TOP
+ startY += fm.ascent();
+
+ bool eto_empty = (params[3] == 0);
+ bool eto_clipped_set = (params[3] & 0x0004);
+ bool eto_pdy_set = (params[3] & 0x2000);
+
+ int idxOffset = (params[ 2 ] / 2) + 4 + (params[ 2 ] & 1) + (eto_clipped_set ? 4 : 0);
+ int minParams = eto_pdy_set ? (idxOffset + 2 * (params[2] - 1)) : (idxOffset + params[2]);
+ bool useCharInterdistances = (num >= minParams) && (eto_empty || eto_pdy_set);
+ if ((params[2] > 1) && useCharInterdistances)
+ {
+ double xpos = startX;
+ double ypos = startY;
+ double lineWidth = 0.0;
+ FPointArray textPath;
+ QString textColor = importColor( m_context.textColor() );
+ for (int index = 0; (index < params[2] && index < textString.length()); ++index)
+ {
+ QPainterPath painterPath;
+ if (index > 0 && eto_pdy_set)
+ {
+ xpos += params[idxOffset + index * 2 - 1];
+ ypos += params[idxOffset + index * 2];
+ }
+ else if (index > 0)
+ xpos += params[idxOffset + index - 1];
+ painterPath.addText(xpos, ypos, m_context.font(), textString.at(index));
+ textPath.fromQPainterPath(painterPath);
+ if (textPath.size() > 0)
+ {
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, textColor, CommonStrings::None, true);
+ PageItem* ite = m_Doc->Items->at(z);
+ ite->PoLine = textPath;
+ finishCmdParsing(ite);
+ items.append(ite);
+ }
+ }
+ }
+ else
+ {
+ FPointArray textPath;
+ QString textColor = importColor( m_context.textColor() );
+ QPainterPath painterPath;
+ painterPath.addText( startX, startY, m_context.font(), textString );
+ textPath.fromQPainterPath(painterPath);
+ if (textPath.size() > 0)
+ {
+ double lineWidth = 0.0;
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, BaseX, BaseY, 10, 10, lineWidth, textColor, CommonStrings::None, true);
+ PageItem* ite = m_Doc->Items->at(z);
+ ite->PoLine = textPath;
+ finishCmdParsing(ite);
+ items.append(ite);
+ }
+ }
+ m_context.restore();
+}
+
+void WMFImport::selectObject( QList<PageItem*>& /*items*/, long, short* params )
+{
+ int idx = params[ 0 ];
+ if ( idx >= 0 && idx < MAX_OBJHANDLE && m_ObjHandleTab[ idx ] )
+ m_ObjHandleTab[ idx ]->apply( m_context );
+}
+
+void WMFImport::deleteObject( QList<PageItem*>& /*items*/, long, short* params )
+{
+ deleteHandle( params[ 0 ] );
+}
+
+void WMFImport::createEmptyObject( QList<PageItem*>& /*items*/, long, short* )
+{
+ // allocation of an empty object (to keep object counting in sync)
+ WmfObjPenHandle* handle = new WmfObjPenHandle();
+ addHandle( handle );
+ cerr << "WMFImport: unimplemented createObject " << endl;
+}
+
+void WMFImport::createBrushIndirect( QList<PageItem*>& /*items*/, long, short* params )
+{
+ static Qt::BrushStyle hatchedStyleTab[] =
+ {
+ Qt::HorPattern,
+ Qt::FDiagPattern,
+ Qt::BDiagPattern,
+ Qt::CrossPattern,
+ Qt::DiagCrossPattern
+ };
+ static Qt::BrushStyle styleTab[] =
+ { Qt::SolidPattern,
+ Qt::NoBrush,
+ Qt::FDiagPattern, /* hatched */
+ Qt::Dense4Pattern, /* should be custom bitmap pattern */
+ Qt::HorPattern, /* should be BS_INDEXED (?) */
+ Qt::VerPattern, /* should be device-independent bitmap */
+ Qt::Dense6Pattern, /* should be device-independent packed-bitmap */
+ Qt::Dense2Pattern, /* should be BS_PATTERN8x8 */
+ Qt::Dense3Pattern /* should be device-independent BS_DIBPATTERN8x8 */
+ };
+ Qt::BrushStyle style;
+ short arg;
+ WmfObjBrushHandle* handle = new WmfObjBrushHandle();
+ addHandle( handle );
+
+ arg = params[0];
+ if ( arg == 2 )
+ {
+ arg = params[3];
+ if ( arg >= 0 && arg < 5 )
+ style = hatchedStyleTab[ arg ];
+ else
+ {
+ cerr << "WMFImport::createBrushIndirect: invalid hatched brush " << arg << endl;
+ style = Qt::SolidPattern;
+ }
+ }
+ else if ( arg >= 0 && arg < 9 )
+ style = styleTab[arg];
+ else
+ {
+ cerr << "WMFImport::createBrushIndirect: invalid brush " << arg << endl;
+ style = Qt::SolidPattern;
+ }
+ handle->brush.setStyle( style );
+ handle->brush.setColor( colorFromParam( params+1 ) );
+}
+
+void WMFImport::createPenIndirect( QList<PageItem*>& /*items*/, long, short* params )
+{
+ static Qt::PenStyle styleTab[] = { Qt::SolidLine, Qt::DashLine, Qt::DotLine, Qt::DashDotLine, Qt::DashDotDotLine,
+ Qt::NoPen, Qt::SolidLine };
+ Qt::PenStyle style;
+ WmfObjPenHandle* handle = new WmfObjPenHandle();
+ addHandle( handle );
+
+ if ( params[0] >= 0 && params[0] < 6 )
+ style = styleTab[ params[0] ];
+ else
+ {
+ cerr << "WMFImport::createPenIndirect: invalid pen " << params[ 0 ] << endl;
+ style = Qt::SolidLine;
+ }
+
+ handle->pen.setStyle( style );
+ handle->pen.setWidth( params[1] );
+ handle->pen.setColor( colorFromParam( params+3 ) );
+ handle->pen.setCapStyle( Qt::RoundCap );
+}
+
+void WMFImport::createFontIndirect( QList<PageItem*>& /*items*/, long , short* params)
+{
+ WmfObjFontHandle* handle = new WmfObjFontHandle();
+ addHandle( handle );
+
+ QString family( (const char*)¶ms[ 9 ] );
+
+ handle->rotation = -params[ 2 ] / 10; // text rotation (in 1/10 degree)
+ handle->font.setFamily( family );
+ handle->font.setStyleStrategy( QFont::PreferOutline );
+ handle->font.setFixedPitch( ((params[ 8 ] & 0x01) == 0) );
+ // TODO: investigation why some test case need -2. (size of font in logical point)
+ int fontSize = (params[0] != 0) ? (qAbs(params[0]) - 2) : 12;
+ handle->font.setPixelSize( fontSize );
+ handle->font.setWeight( (params[ 4 ] >> 3) );
+ handle->font.setItalic( (params[ 5 ] & 0x01) );
+ handle->font.setUnderline( (params[ 5 ] & 0x100) );
+ handle->font.setStrikeOut( (params[ 6 ] & 0x01) );
+ handle->charset = (params[ 6 ] & 0xFF00) >> 8;
+}
+
+void WMFImport::noop( QList<PageItem*>& /*items*/, long, short* )
+{
+}
+
+void WMFImport::end( QList<PageItem*>& /*items*/, long, short* )
+{
+ //cerr << "WMFImport::end unimplemented" << endl;
+}
+
+void WMFImport::addHandle( WmfObjHandle* handle )
+{
+ int idx;
+
+ for ( idx =0; idx < MAX_OBJHANDLE ; idx++ )
+ if ( m_ObjHandleTab[ idx ] == NULL ) break;
+
+ if ( idx < MAX_OBJHANDLE )
+ m_ObjHandleTab[ idx ] = handle;
+ else
+ cerr << "WMFImport error: handle table full !" << endl;
+}
+
+void WMFImport::deleteHandle( int idx )
+{
+ if ( idx >= 0 && idx < MAX_OBJHANDLE && m_ObjHandleTab[ idx ] )
+ {
+ delete m_ObjHandleTab[ idx ];
+ m_ObjHandleTab[ idx ] = NULL;
+ }
+}
+
+unsigned short WMFImport::calcCheckSum( WmfPlaceableHeader* apmfh )
+{
+ WORD16* lpWord;
+ WORD16 wResult, i;
+
+ // Start with the first word
+ wResult = *( lpWord = ( WORD16* )( apmfh ) );
+ // XOR in each of the other 9 words
+ for( i=1; i<=9; i++ )
+ {
+ wResult ^= lpWord[ i ];
+ }
+ return wResult;
+}
+
+int WMFImport::findFunc( unsigned short aFunc ) const
+{
+ int i = 0;
+
+ for ( i=0; metaFuncTab[ i ].name; i++ )
+ if ( metaFuncTab[ i ].func == aFunc ) return i;
+
+ // here : unknown function
+ return i;
+}
+
+unsigned int WMFImport::toDWord( short* params )
+{
+ unsigned int l;
+#if !defined( WORDS_BIGENDIAN )
+ l = *( unsigned int* )( params );
+#else
+ char *bytes;
+ char swap[ 4 ];
+ bytes = ( char* )params;
+ swap[ 0 ] = bytes[ 2 ];
+ swap[ 1 ] = bytes[ 3 ];
+ swap[ 2 ] = bytes[ 0 ];
+ swap[ 3 ] = bytes[ 1 ];
+ l = *( unsigned int* )( swap );
+#endif
+ return l;
+}
Index: scribus/plugins/aiimplugin/importai.cpp
===================================================================
--- scribus/plugins/aiimplugin/importai.cpp (revision 13950)
+++ scribus/plugins/aiimplugin/importai.cpp (revision 13951)
@@ -1,2502 +1,2502 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-#include <QByteArray>
-#include <QCursor>
-#include <QDrag>
-#include <QFile>
-#include <QList>
-#include <QMimeData>
-#include <QRegExp>
-#include <QStack>
-#include <QStack>
-#include <QTemporaryFile>
-#include <QDebug>
-
-#include <cmath>
-#include <cstdlib>
-#include <tiffio.h>
-#include <zlib.h>
-
-#include "commonstrings.h"
-#include "ui/customfdialog.h"
-#include "importai.h"
-#include "loadsaveplugin.h"
-#include "ui/missing.h"
-#include "ui/multiprogressdialog.h"
-#include "prefscontext.h"
-#include "prefsfile.h"
-#include "prefsmanager.h"
-#include "prefsmanager.h"
-#include "prefstable.h"
-#include "ui/propertiespalette.h"
-#include "rawimage.h"
-#include "sccolorengine.h"
-#include "scconfig.h"
-#include "scclocale.h"
-#include "scmimedata.h"
-#include "scpaths.h"
-#include "scpattern.h"
-#include "scribus.h"
-#include "scribusXml.h"
-#include "scribuscore.h"
-#include "scribusdoc.h"
-#include "sctextstream.h"
-#include "selection.h"
-#include "text/specialchars.h"
-#include "undomanager.h"
-#include "util.h"
-#include "util_color.h"
-#include "util_file.h"
-#include "util_formats.h"
-#include "util_icon.h"
-#include "util_math.h"
-
-
-#ifdef HAVE_PODOFO
- #include <podofo/podofo.h>
-#endif
-
-extern SCRIBUS_API ScribusQApp * ScQApp;
-
-AIPlug::AIPlug(ScribusDoc* doc, int flags)
-{
- tmpSel=new Selection(this, false);
- m_Doc=doc;
- interactive = (flags & LoadSavePlugin::lfInteractive);
- progressDialog = NULL;
-}
-
-bool AIPlug::import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
-{
- QString fName = fNameIn;
- bool success = false;
- interactive = (flags & LoadSavePlugin::lfInteractive);
- importerFlags = flags;
- cancel = false;
- double x, y, b, h;
- bool ret = false;
- convertedPDF = false;
- CustColors.clear();
- QFileInfo fi = QFileInfo(fName);
-// QString ext = fi.suffix().toLower();
- if ( !ScCore->usingGUI() )
- {
- interactive = false;
- showProgress = false;
- }
-
-/* Check if the file is an old style AI or one of the newer PDF wrapped ones */
- QFile fT(fName);
- if (fT.open(QIODevice::ReadOnly))
- {
- QByteArray tempBuf(9, ' ');
- fT.read(tempBuf.data(), 8);
- fT.close();
- if (tempBuf.startsWith("%PDF"))
- {
- QFileInfo bF2(fName);
- QString tmpFile = ScPaths::getTempFileDir()+ "/"+bF2.baseName()+"_tmp.ai";
- if (!extractFromPDF(fName, tmpFile))
- return false;
- convertedPDF = true;
- fName = tmpFile;
- }
- }
- QFile fT2(fName);
- if (fT2.open(QIODevice::ReadOnly))
- {
- QByteArray tempBuf(25, ' ');
- fT2.read(tempBuf.data(), 20);
- fT2.close();
- /* Illustrator CS files might be compressed
- the compressed Data starts right after the "%AI12_CompressedData" comment
- Compression is a simple zlib compression */
- if (tempBuf.startsWith("%AI12_CompressedData"))
- decompressAIData(fName);
- }
- if ( showProgress )
- {
- ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
- progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw );
- QStringList barNames, barTexts;
- barNames << "GI";
- barTexts << tr("Analyzing File:");
- QList<bool> barsNumeric;
- barsNumeric << false;
- progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
- progressDialog->setOverallTotalSteps(3);
- progressDialog->setOverallProgress(0);
- progressDialog->setProgress("GI", 0);
- progressDialog->show();
- connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
- qApp->processEvents();
- }
- else
- progressDialog = NULL;
-/* Set default Page to size defined in Preferences */
- x = 0.0;
- y = 0.0;
- b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth;
- h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight;
- if (progressDialog)
- {
- progressDialog->setOverallProgress(1);
- qApp->processEvents();
- }
- parseHeader(fName, x, y, b, h);
- docX = x;
- docY = y;
- docWidth = b - x;
- docHeight = h - y;
- baseX = 0;
- baseY = 0;
- if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
- {
- m_Doc->setPage(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false);
- m_Doc->addPage(0);
- m_Doc->view()->addPage(0, true);
- baseX = 0;
- baseY = 0;
- }
- else
- {
- if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
- {
- m_Doc=ScCore->primaryMainWindow()->doFileNew(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
- ScCore->primaryMainWindow()->HaveNewDoc();
- ret = true;
- baseX = 0;
- baseY = 0;
- }
- }
- if (flags & LoadSavePlugin::lfCreateDoc)
- {
- m_Doc->documentInfo.setAuthor(docCreator);
- m_Doc->documentInfo.setPublisher(docOrganisation);
- m_Doc->documentInfo.setTitle(docTitle);
- m_Doc->documentInfo.setDate(docDate+" "+docTime);
- }
- if ((!ret) && (interactive))
- {
- baseX = m_Doc->currentPage()->xOffset();
- baseY = m_Doc->currentPage()->yOffset();
- }
- if ((ret) || (!interactive))
- {
- if (b-x > h-y)
- m_Doc->PageOri = 1;
- else
- m_Doc->PageOri = 0;
- m_Doc->m_pageSize = "Custom";
- }
- ColorList::Iterator it;
- for (it = CustColors.begin(); it != CustColors.end(); ++it)
- {
- if (!m_Doc->PageColors.contains(it.key()))
- m_Doc->PageColors.insert(it.key(), it.value());
- }
- Elements.clear();
- FPoint minSize = m_Doc->minCanvasCoordinate;
- FPoint maxSize = m_Doc->maxCanvasCoordinate;
- FPoint cOrigin = m_Doc->view()->canvasOrigin();
- m_Doc->setLoading(true);
- m_Doc->DoDrawing = false;
- m_Doc->view()->updatesOn(false);
- m_Doc->scMW()->ScriptRunning = true;
- qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
- QString CurDirP = QDir::currentPath();
- QDir::setCurrent(fi.path());
- if (convert(fName))
- {
- tmpSel->clear();
- QDir::setCurrent(CurDirP);
- if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc)))
- {
- bool isGroup = true;
- int firstElem = -1;
- if (Elements.at(0)->Groups.count() != 0)
- firstElem = Elements.at(0)->Groups.top();
- for (int bx = 0; bx < Elements.count(); ++bx)
- {
- PageItem* bxi = Elements.at(bx);
- if (bxi->Groups.count() != 0)
- {
- if (bxi->Groups.top() != firstElem)
- isGroup = false;
- }
- else
- isGroup = false;
- }
- if (!isGroup)
- {
- double minx = 99999.9;
- double miny = 99999.9;
- double maxx = -99999.9;
- double maxy = -99999.9;
- uint lowestItem = 999999;
- uint highestItem = 0;
- for (int a = 0; a < Elements.count(); ++a)
- {
- Elements.at(a)->Groups.push(m_Doc->GroupCounter);
- PageItem* currItem = Elements.at(a);
- lowestItem = qMin(lowestItem, currItem->ItemNr);
- highestItem = qMax(highestItem, currItem->ItemNr);
- double x1, x2, y1, y2;
- currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
- minx = qMin(minx, x1);
- miny = qMin(miny, y1);
- maxx = qMax(maxx, x2);
- maxy = qMax(maxy, y2);
- }
- double gx = minx;
- double gy = miny;
- double gw = maxx - minx;
- double gh = maxy - miny;
- PageItem *high = m_Doc->Items->at(highestItem);
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, m_Doc->toolSettings.dBrush, m_Doc->toolSettings.dPen, true);
- PageItem *neu = m_Doc->Items->takeAt(z);
- m_Doc->Items->insert(lowestItem, neu);
- neu->Groups.push(m_Doc->GroupCounter);
- neu->setItemName( tr("Group%1").arg(neu->Groups.top()));
- neu->isGroupControl = true;
- neu->groupsLastItem = high;
- neu->setTextFlowMode(PageItem::TextFlowDisabled);
- for (int a = 0; a < m_Doc->Items->count(); ++a)
- {
- m_Doc->Items->at(a)->ItemNr = a;
- }
- Elements.prepend(neu);
- m_Doc->GroupCounter++;
- }
- }
- m_Doc->DoDrawing = true;
- m_Doc->scMW()->ScriptRunning = false;
- m_Doc->setLoading(false);
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- if ((Elements.count() > 0) && (!ret) && (interactive))
- {
- if (flags & LoadSavePlugin::lfScripted)
- {
- bool loadF = m_Doc->isLoading();
- m_Doc->setLoading(false);
- m_Doc->changed();
- m_Doc->setLoading(loadF);
- m_Doc->m_Selection->delaySignalsOn();
- for (int dre=0; dre<Elements.count(); ++dre)
- {
- m_Doc->m_Selection->addItem(Elements.at(dre), true);
- }
- m_Doc->m_Selection->delaySignalsOff();
- m_Doc->m_Selection->setGroupRect();
- m_Doc->view()->updatesOn(true);
- }
- else
- {
- m_Doc->DragP = true;
- m_Doc->DraggedElem = 0;
- m_Doc->DragElements.clear();
- m_Doc->m_Selection->delaySignalsOn();
- for (int dre=0; dre<Elements.count(); ++dre)
- {
- m_Doc->DragElements.append(Elements.at(dre)->ItemNr);
- tmpSel->addItem(Elements.at(dre), true);
- }
- tmpSel->setGroupRect();
- ScriXmlDoc *ss = new ScriXmlDoc();
- ScElemMimeData* md = new ScElemMimeData();
- md->setScribusElem(ss->WriteElem(m_Doc, m_Doc->view(), tmpSel));
- delete ss;
-/*#ifndef Q_WS_MAC*/
-// see #2196
- m_Doc->itemSelection_DeleteItem(tmpSel);
-/*#else
- qDebug("aiimport: leaving items on page");
-#endif*/
- m_Doc->view()->updatesOn(true);
- m_Doc->m_Selection->delaySignalsOff();
- // We must copy the TransationSettings object as it is owned
- // by handleObjectImport method afterwards
- TransactionSettings* transacSettings = new TransactionSettings(trSettings);
- m_Doc->view()->handleObjectImport(md, transacSettings);
- m_Doc->DragP = false;
- m_Doc->DraggedElem = 0;
- m_Doc->DragElements.clear();
- }
- }
- else
- {
- m_Doc->changed();
- m_Doc->reformPages();
- m_Doc->view()->updatesOn(true);
- }
- success = true;
- }
- else
- {
- QDir::setCurrent(CurDirP);
- m_Doc->DoDrawing = true;
- m_Doc->scMW()->ScriptRunning = false;
- m_Doc->view()->updatesOn(true);
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- }
- if (interactive)
- m_Doc->setLoading(false);
- //CB If we have a gui we must refresh it if we have used the progressbar
- if ((showProgress) && (!interactive))
- m_Doc->view()->DrawNew();
- if (convertedPDF)
- QFile::remove(fName);
- return success;
-}
-
-AIPlug::~AIPlug()
-{
- if (progressDialog)
- delete progressDialog;
- delete tmpSel;
-}
-
-bool AIPlug::extractFromPDF(QString infile, QString outfile)
-{
- bool ret = false;
-#ifdef HAVE_PODOFO
- QFile outf(outfile);
- outf.open(QIODevice::WriteOnly);
- try
- {
- PoDoFo::PdfError::EnableDebug( false );
-#if (PODOFO_VERSION == 0 && PODOFO_MINOR > 6)
- PoDoFo::PdfError::EnableLogging( false );
-#endif
-#if (PODOFO_VERSION == 0 && PODOFO_MINOR == 5 && PODOFO_REVISION == 99) || PODOFO_MINOR > 5
- PoDoFo::PdfMemDocument doc( infile.toLocal8Bit().data() );
-#else
- PoDoFo::PdfDocument doc( infile.toLocal8Bit().data() );
-#endif
- PoDoFo::PdfPage *curPage = doc.GetPage(0);
- if (curPage != NULL)
- {
- PoDoFo::PdfObject *piece = curPage->GetObject()->GetIndirectKey("PieceInfo");
- if (piece != NULL)
- {
- PoDoFo::PdfObject *illy = piece->GetIndirectKey("Illustrator");
- if (illy != NULL)
- {
- PoDoFo::PdfObject *priv = illy->GetIndirectKey("Private");
- if (priv == NULL)
- priv = illy;
- int num = 0;
- PoDoFo::PdfObject *numBl = priv->GetIndirectKey("NumBlock");
- if (numBl != NULL)
- num = numBl->GetNumber() + 1;
- if (num == 0)
- num = 99999;
- QString name = "AIPrivateData%1";
- QString Key = name.arg(1);
- PoDoFo::PdfObject *data = priv->GetIndirectKey(PoDoFo::PdfName(Key.toUtf8().data()));
- if (data == NULL)
- {
- name = "AIPDFPrivateData%1";
- Key = name.arg(1);
- data = priv->GetIndirectKey(PoDoFo::PdfName(Key.toUtf8().data()));
- }
- if (data != NULL)
- {
- if (num == 2)
- {
- Key = name.arg(1);
- data = priv->GetIndirectKey(PoDoFo::PdfName(Key.toUtf8().data()));
- PoDoFo::PdfStream const *stream = data->GetStream();
- PoDoFo::PdfMemoryOutputStream oStream(1);
- stream->GetFilteredCopy(&oStream);
- oStream.Close();
- long bLen = oStream.GetLength();
- char *Buffer = oStream.TakeBuffer();
- outf.write(Buffer, bLen);
- free( Buffer );
- }
- else
- {
- for (int a = 2; a < num; a++)
- {
- Key = name.arg(a);
- data = priv->GetIndirectKey(PoDoFo::PdfName(Key.toUtf8().data()));
- if (data == NULL)
- break;
- PoDoFo::PdfStream const *stream = data->GetStream();
- PoDoFo::PdfMemoryOutputStream oStream(1);
- stream->GetFilteredCopy(&oStream);
- oStream.Close();
- long bLen = oStream.GetLength();
- char *Buffer = oStream.TakeBuffer();
- outf.write(Buffer, bLen);
- free( Buffer );
- }
- }
- }
- ret = true;
- }
- }
- }
- outf.close();
- }
- catch (PoDoFo::PdfError& e)
- {
- outf.close();
- qDebug("Scribus caught and handled the following exception from PoDoFo while processing a PDF format ai file:\n----\n");
- e.PrintErrorMsg();
- qDebug("----\nThe ai file could not be imported.\n");
- QFile::remove(outfile);
- return false;
- }
-#endif
- return ret;
-}
-
-bool AIPlug::decompressAIData(QString &fName)
-{
- QString f2 = fName+"_decom.ai";
- FILE *source = fopen(fName.toLocal8Bit().constData(), "rb");
- fseek(source, 20, SEEK_SET);
- FILE *dest = fopen(f2.toLocal8Bit().constData(), "wb");
- int ret;
- unsigned have;
- z_stream strm;
- char in[4096];
- char out[4096];
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit(&strm);
- if (ret != Z_OK)
- return false;
- do
- {
- strm.avail_in = fread(in, 1, 4096, source);
- if (ferror(source))
- {
- (void)inflateEnd(&strm);
- return false;
- }
- if (strm.avail_in == 0)
- break;
- strm.next_in = (Bytef*)in;
- do
- {
- strm.avail_out = 4096;
- strm.next_out = (Bytef*)out;
- ret = inflate(&strm, Z_NO_FLUSH);
- assert(ret != Z_STREAM_ERROR);
- switch (ret)
- {
- case Z_NEED_DICT:
- ret = Z_DATA_ERROR;
- case Z_DATA_ERROR:
- case Z_MEM_ERROR:
- (void)inflateEnd(&strm);
- return false;
- }
- have = 4096 - strm.avail_out;
- if (fwrite(out, 1, have, dest) != have || ferror(dest))
- {
- (void)inflateEnd(&strm);
- return false;
- }
- }
- while (strm.avail_out == 0);
- }
- while (ret != Z_STREAM_END);
- (void)inflateEnd(&strm);
- fclose(source);
- fclose(dest);
- if (!convertedPDF)
- {
- QFileInfo bF2(fName);
- QString tmpFile = ScPaths::getTempFileDir()+ "/"+bF2.baseName()+"_tmp.ai";
- moveFile(f2, tmpFile);
- fName = tmpFile;
- convertedPDF = true;
- }
- else
- {
- QFile::remove(fName);
- fName = f2;
- }
- return true;
-}
-
-bool AIPlug::parseHeader(QString fName, double &x, double &y, double &b, double &h)
-{
- QString tmp, BBox, tmp2, FarNam;
- ScColor cc;
-// double c, m, yc, k;
- bool found = false;
- QFile f(fName);
- if (f.open(QIODevice::ReadOnly))
- {
-/* Try to find Bounding Box */
- QDataStream ts(&f);
- while (!ts.atEnd())
- {
- tmp = readLinefromDataStream(ts);
- if (tmp.startsWith("%%BoundingBox:"))
- {
- found = true;
- BBox = tmp.remove("%%BoundingBox:");
- }
- if (!found)
- {
- if (tmp.startsWith("%%BoundingBox"))
- {
- found = true;
- BBox = tmp.remove("%%BoundingBox");
- }
- }
- if (tmp.startsWith("%%HiResBoundingBox:"))
- {
- found = true;
- BBox = tmp.remove("%%HiResBoundingBox:");
- }
- if (tmp.startsWith("%%For"))
- {
- QStringList res = getStrings(tmp);
- if (res.count() > 1)
- {
- docCreator = res[0];
- docOrganisation = res[1];
- }
- }
- if (tmp.startsWith("%%CreationDate:"))
- {
- QStringList res = getStrings(tmp);
- if (res.count() > 1)
- {
- docDate = res[0];
- docTime = res[1];
- }
- else
- {
- docDate = tmp.remove("%%CreationDate: ");
- docTime = "";
- }
- }
- if (tmp.startsWith("%%Title"))
- {
- QStringList res = getStrings(tmp);
- if (res.count() > 0)
- docTitle = res[0];
- }
- if (tmp.startsWith("%%EndComments"))
- break;
- }
- f.close();
- if (found)
- {
- QStringList bb = BBox.split(" ", QString::SkipEmptyParts);
- if (bb.count() == 4)
- {
- x = ScCLocale::toDoubleC(bb[0]);
- y = ScCLocale::toDoubleC(bb[1]);
- b = ScCLocale::toDoubleC(bb[2]);
- h = ScCLocale::toDoubleC(bb[3]);
- }
- }
- importColorsFromFile(fName, CustColors);
- }
- return found;
-}
-
-QString AIPlug::removeAIPrefix(QString comment)
-{
- QString tmp;
- if (comment.startsWith("%AI"))
- {
- int an = comment.indexOf("_");
- tmp = comment.remove(0, an+1);
- }
- else
- tmp = comment;
- return tmp;
-}
-
-QString AIPlug::parseColor(QString data)
-{
- QString ret = CommonStrings::None;
- if (data.isEmpty())
- return ret;
- double c, m, y, k;
- ScColor tmp;
- ColorList::Iterator it;
- ScTextStream Code(&data, QIODevice::ReadOnly);
- bool found = false;
- Code >> c;
- Code >> m;
- Code >> y;
- Code >> k;
- int Cc = qRound(c * 255);
- int Mc = qRound(m * 255);
- int Yc = qRound(y * 255);
- int Kc = qRound(k * 255);
- int hC, hM, hY, hK;
- tmp.setColor(Cc, Mc, Yc, Kc);
- for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
- {
- if (it.value().getColorModel() == colorModelCMYK)
- {
- it.value().getCMYK(&hC, &hM, &hY, &hK);
- if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
- {
- ret = it.key();
- found = true;
- break;
- }
- }
- }
- if (!found)
- {
- tmp.setSpotColor(false);
- tmp.setRegistrationColor(false);
- QString namPrefix = "FromAI";
- m_Doc->PageColors.insert(namPrefix+tmp.name(), tmp);
-// importedColors.append(namPrefix+tmp.name());
- ret = namPrefix+tmp.name();
- }
- return ret;
-}
-
-QString AIPlug::parseColorGray(QString data)
-{
- QString ret = CommonStrings::None;
- if (data.isEmpty())
- return ret;
- double k;
- ScColor tmp;
- ColorList::Iterator it;
- ScTextStream Code(&data, QIODevice::ReadOnly);
- bool found = false;
- Code >> k;
- int Kc = 255 - qRound(k * 255);
- int hC, hM, hY, hK;
- tmp.setColor(0, 0, 0, Kc);
- for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
- {
- if (it.value().getColorModel() == colorModelCMYK)
- {
- it.value().getCMYK(&hC, &hM, &hY, &hK);
- if ((hC == 0) && (hM == 0) && (hY == 0) && (Kc == hK))
- {
- ret = it.key();
- found = true;
- break;
- }
- }
- }
- if (!found)
- {
- tmp.setSpotColor(false);
- tmp.setRegistrationColor(false);
- QString namPrefix = "FromAI";
- m_Doc->PageColors.insert(namPrefix+tmp.name(), tmp);
-// importedColors.append(namPrefix+tmp.name());
- ret = namPrefix+tmp.name();
- }
- return ret;
-}
-
-QString AIPlug::parseColorRGB(QString data)
-{
- QString ret = CommonStrings::None;
- if (data.isEmpty())
- return ret;
- double r, g, b;
- ScColor tmp;
- ColorList::Iterator it;
- ScTextStream Code(&data, QIODevice::ReadOnly);
- bool found = false;
- Code >> r;
- Code >> g;
- Code >> b;
- int Rc = qRound(r * 255);
- int Gc = qRound(g * 255);
- int Bc = qRound(b * 255);
- int hR, hG, hB;
- tmp.setColorRGB(Rc, Gc, Bc);
- for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
- {
- if (it.value().getColorModel() == colorModelRGB)
- {
- it.value().getRGB(&hR, &hG, &hB);
- if ((Rc == hR) && (Gc == hG) && (Bc == hB))
- {
- ret = it.key();
- found = true;
- break;
- }
- }
- }
- if (!found)
- {
- tmp.setSpotColor(false);
- tmp.setRegistrationColor(false);
- QString namPrefix = "FromAI";
- m_Doc->PageColors.insert(namPrefix+tmp.name(), tmp);
-// importedColors.append(namPrefix+tmp.name());
- ret = namPrefix+tmp.name();
- }
- return ret;
-}
-
-QString AIPlug::parseCustomColor(QString data, double &shade)
-{
- QString ret = CommonStrings::None;
- if (data.isEmpty())
- return ret;
- double c, m, y, k, sh;
- ScColor tmp;
- ColorList::Iterator it;
- ScTextStream Code(&data, QIODevice::ReadOnly);
- bool found = false;
- Code >> c;
- Code >> m;
- Code >> y;
- Code >> k;
- QString tmpS = data;
- int an = data.indexOf("(");
- int en = data.lastIndexOf(")");
- QString FarNam = data.mid(an+1, en-an-1);
- FarNam.remove("\\");
- QString FarSha = data.mid(en+1, data.size() - en);
- ScTextStream Val(&FarSha, QIODevice::ReadOnly);
- Val >> sh;
- shade = (1.0 - sh) * 100.0;
- int Cc = qRound(c * 255);
- int Mc = qRound(m * 255);
- int Yc = qRound(y * 255);
- int Kc = qRound(k * 255);
- int hC, hM, hY, hK;
- tmp.setColor(Cc, Mc, Yc, Kc);
- for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
- {
- if (it.value().getColorModel() == colorModelCMYK)
- {
- it.value().getCMYK(&hC, &hM, &hY, &hK);
- if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
- {
- ret = it.key();
- found = true;
- break;
- }
- }
- }
- if (!found)
- {
- tmp.setSpotColor(true);
- tmp.setRegistrationColor(false);
- m_Doc->PageColors.insert(FarNam, tmp);
-// importedColors.append(FarNam);
- ret = FarNam;
- }
- return ret;
-}
-
-QString AIPlug::parseCustomColorX(QString data, double &shade, QString type)
-{
- QString ret = CommonStrings::None;
- if (data.isEmpty())
- return ret;
- double c, m, y, k, sh, r, g, b;
- ScColor tmp;
- ColorList::Iterator it;
- ScTextStream Code(&data, QIODevice::ReadOnly);
- bool found = false;
- if (type == "1")
- {
- Code >> r;
- Code >> g;
- Code >> b;
- int Rc = qRound(r * 255);
- int Gc = qRound(g * 255);
- int Bc = qRound(b * 255);
- int hR, hG, hB;
- tmp.setColorRGB(Rc, Gc, Bc);
- for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
- {
- if (it.value().getColorModel() == colorModelRGB)
- {
- it.value().getRGB(&hR, &hG, &hB);
- if ((Rc == hR) && (Gc == hG) && (Bc == hB))
- {
- ret = it.key();
- found = true;
- break;
- }
- }
- }
- }
- else
- {
- Code >> c;
- Code >> m;
- Code >> y;
- Code >> k;
- int Cc = qRound(c * 255);
- int Mc = qRound(m * 255);
- int Yc = qRound(y * 255);
- int Kc = qRound(k * 255);
- int hC, hM, hY, hK;
- tmp.setColor(Cc, Mc, Yc, Kc);
- for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
- {
- if (it.value().getColorModel() == colorModelCMYK)
- {
- it.value().getCMYK(&hC, &hM, &hY, &hK);
- if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
- {
- ret = it.key();
- found = true;
- break;
- }
- }
- }
- }
- QString tmpS = data;
- int an = data.indexOf("(");
- int en = data.lastIndexOf(")");
- QString FarNam = data.mid(an+1, en-an-1);
- FarNam.remove("\\");
- QString FarSha = data.mid(en+1, data.size() - en);
- ScTextStream Val(&FarSha, QIODevice::ReadOnly);
- Val >> sh;
- shade = (1.0 - sh) * 100.0;
- if (!found)
- {
- if (type == "0")
- tmp.setSpotColor(true);
- tmp.setRegistrationColor(false);
- m_Doc->PageColors.insert(FarNam, tmp);
-// importedColors.append(FarNam);
- ret = FarNam;
- }
- return ret;
-}
-
-QStringList AIPlug::getStrings(QString data)
-{
- QStringList result;
- result.clear();
- QChar tmp;
- QString tmp2 = "";
- QString tmp3 = "";
- bool paran = false;
- bool skip = false;
- int digitCount = 0;
- for (int a = 0; a < data.count(); a++)
- {
- tmp = data[a];
- if (skip)
- {
- if (paran)
- {
- if (tmp.isDigit())
- {
- tmp3 += tmp;
- digitCount++;
- if (digitCount == 3)
- {
- bool ok = false;
- int code = tmp3.toInt(&ok, 8);
- if (ok)
- tmp2 += QChar(code);
- digitCount = 0;
- tmp3 = "";
- skip = false;
- }
- }
- else
- {
- if (tmp == 'r')
- tmp = SpecialChars::PARSEP;
- tmp2 += tmp;
- skip = false;
- }
- }
- continue;
- }
- if (tmp == '(')
- {
- paran = true;
- continue;
- }
- if (tmp == ')')
- {
- paran = false;
- result.append(tmp2);
- tmp2 = "";
- continue;
- }
- if (tmp == '\\')
- {
- skip = true;
- continue;
- }
- if (paran)
- tmp2 += tmp;
- }
- return result;
-}
-
-void AIPlug::getCommands(QString data, QStringList &commands)
-{
- QString tmp;
- QString tmp2;
- QString tmp3;
- bool paran = false;
- bool arra = false;
- bool skip = false;
- for (int a = 0; a < data.count(); a++)
- {
- tmp = data[a];
- if (skip)
- {
- tmp2 += tmp;
- skip = false;
- continue;
- }
- if (tmp == "(")
- {
- paran = true;
- tmp2 += tmp;
- continue;
- }
- if (tmp == ")")
- {
- paran = false;
- tmp2 += tmp;
- continue;
- }
- if (tmp == "[")
- {
- arra = true;
- tmp2 += tmp;
- continue;
- }
- if (tmp == "]")
- {
- arra = false;
- tmp2 += tmp;
- continue;
- }
-// if (tmp == "\\")
-// {
-// skip = true;
-// continue;
-// }
- if (!paran)
- {
- if (tmp == " ")
- {
- tmp3 += " " + tmp2;
- if (commandList.contains(tmp2))
- {
- commands.append(tmp3);
- tmp3 = "";
- }
- tmp2 = "";
- continue;
- }
- }
- tmp2 += tmp;
- }
- if (!tmp2.isEmpty())
- {
- tmp3 += " " + tmp2;
- commands.append(tmp3);
- }
-}
-
-void AIPlug::processData(QString data)
-{
- double x, y, x1, y1, x2, y2;
- int z, tmpInt;
- PageItem *ite;
- QString command = "";
- QString Cdata = "";
- QStringList da;
- getCommands(data, da);
- for (int a = 0; a < da.count(); a++)
- {
- Cdata = da[a];
- if (((Cdata.startsWith("%")) || (Cdata.startsWith(" %"))) && (!meshMode))
- continue;
- QStringList da2 = Cdata.split(" ", QString::SkipEmptyParts);
- if (da2.count() == 0)
- return;
- command = da2[da2.count()-1];
-/* Start Path construction commands */
- if (command == "m")
- {
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> x >> y;
- Coords.svgMoveTo(x - docX, docHeight - (y - docY));
- currentPoint = FPoint(x - docX, docHeight - (y - docY));
- }
- else if ((command == "L") || (command == "l"))
- {
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> x >> y;
- Coords.svgLineTo(x - docX, docHeight - (y - docY));
- currentPoint = FPoint(x - docX, docHeight - (y - docY));
- }
- else if ((command == "C") || (command == "c"))
- {
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> x >> y >> x1 >> y1 >> x2 >> y2;
- Coords.svgCurveToCubic(x - docX, docHeight - (y - docY),
- x1 - docX, docHeight - (y1 - docY),
- x2 - docX, docHeight - (y2 - docY));
- currentPoint = FPoint(x2 - docX, docHeight - (y2 - docY));
- }
- else if ((command == "Y") || (command == "y"))
- {
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> x1 >> y1 >> x2 >> y2;
- Coords.svgCurveToCubic(currentPoint.x(), currentPoint.y(),
- x1 - docX, docHeight - (y1 - docY),
- x2 - docX, docHeight - (y2 - docY));
- currentPoint = FPoint(x2 - docX, docHeight - (y2 - docY));
- }
- else if ((command == "V") || (command == "v"))
- {
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> x >> y >> x2 >> y2;
- Coords.svgCurveToCubic(x - docX, docHeight - (y - docY),
- currentPoint.x(), currentPoint.y(),
- x2 - docX, docHeight - (y2 - docY));
- currentPoint = FPoint(x2 - docX, docHeight - (y2 - docY));
- }
-/* End Path construction commands */
-/* Start Object creation commands */
- else if ((command == "b") || (command == "B") || (command == "f") || (command == "F") || (command == "s") || (command == "S"))
- {
- if (Coords.size() > 3)
- {
- if ((!WasU) || ((WasU) && (FirstU)))
- {
- if ((command == "B") || (command == "F") || (command == "S"))
- {
- if (command == "F")
- z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CommonStrings::None, true);
- else if (command == "B")
- z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
- else
- z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CommonStrings::None, CurrColorStroke, true);
- }
- else
- {
- if (command == "f")
- z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CommonStrings::None, true);
- else if (command == "b")
- z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
- else
- z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CommonStrings::None, CurrColorStroke, true);
- }
- ite = m_Doc->Items->at(z);
- ite->PoLine = Coords.copy();
- ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
- ite->ClipEdited = true;
- ite->FrameType = 3;
- ite->setFillShade(CurrFillShade);
- ite->setLineShade(CurrStrokeShade);
- ite->setFillEvenOdd(fillRule);
- ite->setFillTransparency(1.0 - Opacity);
- ite->setLineTransparency(1.0 - Opacity);
- // ite->setFillBlendmode(blendMode);
- // ite->setLineBlendmode(blendMode);
- if (!currentPatternName.isEmpty())
- {
- ite->setPattern(currentPatternName);
- ite->setPatternTransform(currentPatternXScale * 100, currentPatternYScale * 100, currentPatternX, currentPatternY, currentPatternRotation);
- ite->GrType = 8;
- currentPatternName = "";
- }
- ite->setLineEnd(CapStyle);
- ite->setLineJoin(JoinStyle);
- if (importerFlags & LoadSavePlugin::lfCreateDoc)
- ite->setLocked(itemLocked);
- if (!WasU)
- {
- FPoint wh = getMaxClipF(&ite->PoLine);
- ite->setWidthHeight(wh.x(),wh.y());
- ite->setTextFlowMode(PageItem::TextFlowDisabled);
- m_Doc->AdjustItemSize(ite);
- }
- if (patternMode)
- PatternElements.append(ite);
- else
- Elements.append(ite);
- if (groupStack.count() != 0)
- groupStack.top().append(ite);
-
- }
- else
- {
- ite = m_Doc->Items->at(m_Doc->Items->count()-1);
- ite->PoLine.setMarker();
- Coords.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
- ite->PoLine.putPoints(ite->PoLine.size(), Coords.size(), Coords);
- }
- Coords.resize(0);
- Coords.svgInit();
- FirstU = false;
- itemRendered = true;
- }
- }
- else if (command == "*u")
- {
- FirstU = true;
- WasU = true;
- }
- else if (command == "*U")
- {
- WasU = false;
- ite = m_Doc->Items->at(m_Doc->Items->count()-1);
- FPoint wh = getMaxClipF(&ite->PoLine);
- ite->setWidthHeight(wh.x(),wh.y());
- m_Doc->AdjustItemSize(ite);
- }
- else if ((command == "u") || (command == "q"))
- {
- QList<PageItem*> gElements;
- groupStack.push(gElements);
- }
- else if ((command == "U") || (command == "Q"))
- {
- if (groupStack.count() != 0)
- {
- QList<PageItem*> gElements = groupStack.pop();
- tmpSel->clear();
- if (gElements.count() > 0)
- {
- for (int dre = 0; dre < gElements.count(); ++dre)
- {
- tmpSel->addItem(gElements.at(dre), true);
- }
- m_Doc->itemSelection_GroupObjects(false, false, tmpSel);
- ite = tmpSel->itemAt(0);
- if ((clipCoords.size() > 4) && (command == "Q"))
- {
- ite = tmpSel->itemAt(0);
- clipCoords.translate(m_Doc->currentPage()->xOffset()-ite->xPos(), m_Doc->currentPage()->yOffset()-ite->yPos());
- ite->PoLine = clipCoords.copy();
- ite->PoLine.translate(baseX, baseY);
- }
- if (patternMode)
- PatternElements.append(ite);
- else
- Elements.append(ite);
- }
- if (groupStack.count() != 0)
- {
- for (int as = 0; as < tmpSel->count(); ++as)
- {
- groupStack.top().append(tmpSel->itemAt(as));
- }
- }
- tmpSel->clear();
- }
- if (command == "Q")
- {
- clipCoords.resize(0);
- clipCoords.svgInit();
- }
- }
- else if (command == "W")
- {
- if (clipCoords.size() > 0)
- clipCoords.setMarker();
- clipCoords.putPoints(clipCoords.size(), Coords.size(), Coords);
- }
-/* End Object construction commands */
-/* Start Graphics state commands */
- else if (command == "A")
- {
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> tmpInt;
- if (tmpInt == 1)
- itemLocked = true;
- else
- itemLocked = false;
- }
- else if (command == "w")
- {
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> LineW;
- }
- else if (command == "j")
- {
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> tmpInt;
- if (tmpInt == 0)
- JoinStyle = Qt::MiterJoin;
- else if (tmpInt == 1)
- JoinStyle = Qt::RoundJoin;
- else if (tmpInt == 1)
- JoinStyle = Qt::BevelJoin;
- }
- else if (command == "J")
- {
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> tmpInt;
- if (tmpInt == 0)
- CapStyle = Qt::FlatCap;
- else if (tmpInt == 1)
- CapStyle = Qt::RoundCap;
- else if (tmpInt == 1)
- CapStyle = Qt::SquareCap;
- }
- /* undocumented Command Xy
- - has up to 5 Parameters
- - first Parameter might be the Blendmode
- - second Parameter is the Opacity
- */
- else if (command == "Xy")
- {
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> blendMode >> Opacity;
- }
- else if (command == "XR")
- {
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> tmpInt;
- if (tmpInt == 1)
- fillRule = true;
- else
- fillRule = false;
- }
- else if (command == "Bb")
- {
- gradientMode = true;
- wasBC = false;
- itemRendered = false;
- startMatrix = QMatrix();
- endMatrix = QMatrix();
- }
- else if (command == "Xm")
- {
- ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
- double m1, m2, m3, m4, m5, m6;
- gVals >> m1 >> m2 >> m3 >> m4 >> m5 >> m6;
- startMatrix.translate(m5, -m6);
- endMatrix.scale(m1, m4);
- wasBC = true;
- }
- else if (command == "Bm")
- {
- if (m_gradients[currentGradientName].type() == 1)
- {
- ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
- double m1, m2, m3, m4, m5, m6;
- gVals >> m1 >> m2 >> m3 >> m4 >> m5 >> m6;
- startMatrix.translate(m5, -m6);
-// endMatrix.scale(m1, m4);
- endMatrix *= QMatrix(m1, m2, m3, m4, 0, 0);
-// endMatrix = QMatrix(m1, m2, m3, m4, m5, m6);
- wasBC = true;
- }
- }
- else if (command == "BB")
- {
- if (itemRendered)
- {
- gradientMode = false;
- ite = m_Doc->Items->at(m_Doc->Items->count()-1);
- ite->fill_gradient = m_gradients[currentGradientName];
- if (ite->fill_gradient.type() == 0)
- ite->GrType = 6;
- else
- ite->GrType = 7;
- QMatrix m1;
- m1.translate(currentGradientOrigin.x() - ite->xPos(), currentGradientOrigin.y() - ite->yPos());
- m1.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
- m1.rotate(-currentGradientAngle);
- ite->GrStartX = currentGradientOrigin.x() - ite->xPos() + m_Doc->currentPage()->xOffset();
- ite->GrStartY = currentGradientOrigin.y() - ite->yPos() + m_Doc->currentPage()->yOffset();
- QPointF target = m1.map(QPointF(currentGradientLenght, 0.0));
- ite->GrEndX = target.x();
- ite->GrEndY = target.y();
- if (wasBC)
- {
- QPointF newS = startMatrix.map(QPointF(ite->GrStartX, ite->GrStartY));
- ite->GrStartX = newS.x();
- ite->GrStartY = newS.y();
- QMatrix m2;
-// m2.translate(ite->GrStartX, ite->GrStartY);
- m2.rotate(-currentGradientAngle);
- m2 *= endMatrix;
- QPointF target = m2.map(QPointF(currentGradientLenght, 0.0));
- ite->GrEndX = target.x();
- ite->GrEndY = target.y();
- }
- }
- wasBC = false;
- currentGradientMatrix = QMatrix();
- currentGradientOrigin = QPointF(0.0, 0.0);
- currentGradientAngle = 0.0;
- currentGradientLenght = 1.0;
- itemRendered = false;
- }
- else if (command == "Bg")
- {
- int an = Cdata.indexOf("(");
- int en = Cdata.lastIndexOf(")");
- currentGradientName = Cdata.mid(an+1, en-an-1);
- currentGradientName.remove("\\");
- QString tmpS = Cdata.mid(en+1, Cdata.size() - en);
- ScTextStream gVals(&tmpS, QIODevice::ReadOnly);
- double xOrig, yOrig, m1, m2, m3, m4, m5, m6;
- gVals >> xOrig >> yOrig >> currentGradientAngle >> currentGradientLenght >> m1 >> m2 >> m3 >> m4 >> m5 >> m6;
- currentGradientOrigin = QPointF(xOrig - docX, docHeight - (yOrig - docY));
- currentGradientMatrix = QMatrix(m1, m2, m3, m4, m5, m6);
- }
-/* End Graphics state commands */
-/* Start Color commands */
- else if ((command == "G") || (command == "g"))
- {
- if (command == "G")
- CurrColorStroke = parseColorGray(Cdata);
- else
- CurrColorFill = parseColorGray(Cdata);
- }
- else if ((command == "K") || (command == "k"))
- {
- if (command == "K")
- CurrColorStroke = parseColor(Cdata);
- else
- CurrColorFill = parseColor(Cdata);
- }
- else if ((command == "XA") || (command == "Xa"))
- {
- QString Xdata = da2[da2.count()-4] + " " + da2[da2.count()-3] + " " + da2[da2.count()-2];
- if (command == "XA")
- CurrColorStroke = parseColorRGB(Xdata);
- else
- CurrColorFill = parseColorRGB(Xdata);
- }
- else if ((command == "XX") || (command == "Xx") || (command == "Xk"))
- {
- if (command == "XX")
- CurrColorStroke = parseCustomColorX(Cdata, CurrStrokeShade, da2[da2.count()-2]);
- else
- CurrColorFill = parseCustomColorX(Cdata, CurrFillShade, da2[da2.count()-2]);
- }
- else if ((command == "X") || (command == "x"))
- {
- if (command == "X")
- CurrColorStroke = parseCustomColor(Cdata, CurrStrokeShade);
- else
- CurrColorFill = parseCustomColor(Cdata, CurrFillShade);
- }
- else if (command == "p")
- {
- int an = Cdata.indexOf("(");
- int en = Cdata.lastIndexOf(")");
- currentPatternName = Cdata.mid(an+1, en-an-1);
- currentPatternName.remove("\\");
- currentPatternName = currentPatternName.trimmed().simplified().replace(" ", "_");
- QString tmpS = Cdata.mid(en+1, Cdata.size() - en);
- ScTextStream gVals(&tmpS, QIODevice::ReadOnly);
- gVals >> currentPatternX >> currentPatternY >> currentPatternXScale >> currentPatternYScale >> currentPatternRotation;
- }
- else if (command == "X!")
- {
- if (Cdata.contains("/Mesh"))
- {
- QList<PageItem*> gElements;
- groupStack.push(gElements);
- meshMode = true;
- meshNodeCounter = 0;
- accumColorC = 0.0;
- accumColorM = 0.0;
- accumColorY = 0.0;
- accumColorK = 0.0;
- meshColorMode = 0;
- // meshBoundingPath = QPainterPath();
- }
- if (Cdata.contains("/End"))
- {
- meshMode = false;
- if (groupStack.count() != 0)
- {
- QList<PageItem*> gElements = groupStack.pop();
- tmpSel->clear();
- if (gElements.count() > 0)
- {
- for (int dre = 0; dre < gElements.count(); ++dre)
- {
- tmpSel->addItem(gElements.at(dre), true);
- }
- m_Doc->itemSelection_GroupObjects(false, false, tmpSel);
- ite = tmpSel->itemAt(0);
- /* if (!meshBoundingPath.isEmpty())
- {
- ite = tmpSel->itemAt(0);
- clipCoords.fromQPainterPath(meshBoundingPath);
- clipCoords.translate(m_Doc->currentPage()->xOffset()-ite->xPos(), m_Doc->currentPage()->yOffset()-ite->yPos());
- ite->PoLine = clipCoords.copy();
- ite->PoLine.translate(baseX, baseY);
- } */
- if (patternMode)
- PatternElements.append(ite);
- else
- Elements.append(ite);
- }
- if (groupStack.count() != 0)
- {
- for (int as = 0; as < tmpSel->count(); ++as)
- {
- groupStack.top().append(tmpSel->itemAt(as));
- }
- }
- tmpSel->clear();
- }
- }
- }
- else if (command == "X#")
- {
- int an = Cdata.indexOf("_");
- QString cmdLine = Cdata.remove(0, an+1);
- an = cmdLine.lastIndexOf("/");
- QString tmpS = cmdLine.mid(an+1, Cdata.size());
- ScTextStream mVals(&tmpS, QIODevice::ReadOnly);
- QString mKey;
- mVals >> mKey;
- if (mKey == "Size")
- {
- int ans = cmdLine.indexOf("[");
- int ens = cmdLine.lastIndexOf("]");
- QString sizeVals = cmdLine.mid(ans+1, ens-ans-1);
- ScTextStream mVals2(&sizeVals, QIODevice::ReadOnly);
- mVals2 >> meshXSize >> meshYSize;
- }
- if (mKey == "P")
- {
- int ans = cmdLine.indexOf("[");
- int ens = cmdLine.lastIndexOf("]");
- QString posVals = cmdLine.mid(ans+1, ens-ans-1);
- ScTextStream mVals3(&posVals, QIODevice::ReadOnly);
- mVals3 >> currentMeshXPos >> currentMeshYPos;
- accumColorC = 0.0;
- accumColorM = 0.0;
- accumColorY = 0.0;
- accumColorK = 0.0;
- }
- if (mKey == "CS")
- {
- if (Cdata.contains("CMYK"))
- meshColorMode = 0;
- else if (Cdata.contains("RGB"))
- meshColorMode = 1;
- }
- if (mKey == "E")
- {
- ScColor tmpColor;
- ColorList::Iterator it;
- int Cc = qRound((accumColorC / 4.0) * 255);
- int Mc = qRound((accumColorM / 4.0) * 255);
- int Yc = qRound((accumColorY / 4.0) * 255);
- int Kc = qRound((accumColorK / 4.0) * 255);
- int hC, hM, hY, hK;
- bool found = false;
- if (meshColorMode == 0)
- {
- tmpColor.setColor(Cc, Mc, Yc, Kc);
- for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
- {
- if (it.value().getColorModel() == colorModelCMYK)
- {
- it.value().getCMYK(&hC, &hM, &hY, &hK);
- if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
- {
- CurrColorFill = it.key();
- found = true;
- break;
- }
- }
- }
- }
- else
- {
- tmpColor.setColorRGB(Cc, Mc, Yc);
- for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
- {
- if (it.value().getColorModel() == colorModelRGB)
- {
- it.value().getRGB(&hC, &hM, &hY);
- if ((Cc == hC) && (Mc == hM) && (Yc == hY))
- {
- CurrColorFill = it.key();
- found = true;
- break;
- }
- }
- }
- }
- if (!found)
- {
- tmpColor.setSpotColor(false);
- tmpColor.setRegistrationColor(false);
- QString namPrefix = "FromAI";
- m_Doc->PageColors.insert(namPrefix+tmpColor.name(), tmpColor);
- CurrColorFill = namPrefix+tmpColor.name();
- }
- meshNodeCounter = 0;
- Coords.resize(0);
- Coords.svgInit();
- Coords.svgMoveTo(meshNode1PointX, meshNode1PointY);
- Coords.svgCurveToCubic(meshNode1Control2X, meshNode1Control2Y, meshNode2Control1X, meshNode2Control1Y, meshNode2PointX, meshNode2PointY);
- Coords.svgCurveToCubic(meshNode2Control2X, meshNode2Control2Y, meshNode3Control1X, meshNode3Control1Y, meshNode3PointX, meshNode3PointY);
- Coords.svgCurveToCubic(meshNode3Control2X, meshNode3Control2Y, meshNode4Control1X, meshNode4Control1Y, meshNode4PointX, meshNode4PointY);
- Coords.svgCurveToCubic(meshNode4Control2X, meshNode4Control2Y, meshNode1Control1X, meshNode1Control1Y, meshNode1PointX, meshNode1PointY);
- z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, 0, CurrColorFill, CurrColorFill, true);
- ite = m_Doc->Items->at(z);
- ite->PoLine = Coords.copy();
- // QPainterPath tmpPath = Coords.toQPainterPath(true);
- // meshBoundingPath = meshBoundingPath.united(tmpPath);
- ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
- ite->ClipEdited = true;
- ite->FrameType = 3;
- ite->setFillShade(CurrFillShade);
- ite->setLineShade(CurrFillShade);
- ite->setFillEvenOdd(fillRule);
- ite->setFillTransparency(1.0 - Opacity);
- ite->setLineTransparency(1.0 - Opacity);
- ite->setLineEnd(CapStyle);
- ite->setLineJoin(JoinStyle);
- if (importerFlags & LoadSavePlugin::lfCreateDoc)
- ite->setLocked(itemLocked);
- FPoint wh = getMaxClipF(&ite->PoLine);
- ite->setWidthHeight(wh.x(),wh.y());
- ite->setTextFlowMode(PageItem::TextFlowDisabled);
- m_Doc->AdjustItemSize(ite);
- if (patternMode)
- PatternElements.append(ite);
- else
- Elements.append(ite);
- if (groupStack.count() != 0)
- groupStack.top().append(ite);
- Coords.resize(0);
- Coords.svgInit();
- }
- if (mKey == "N")
- {
- double cVal, mVal, yVal, kVal, coorX1, coorY1, coorX2, coorY2, coorX3, coorY3;
- int dummy;
- meshNodeCounter++;
- int ans = cmdLine.indexOf("[");
- int ens = cmdLine.lastIndexOf("]");
- QString nodeVals = cmdLine.mid(ans+1, ens-ans-1);
- ScTextStream mVals4(&nodeVals, QIODevice::ReadOnly);
- kVal = 0.0;
- if (meshColorMode == 0)
- mVals4 >> cVal >> mVal >> yVal >> kVal >> coorX1 >> coorY1 >> coorX2 >> coorY2 >> dummy >> coorX3 >> coorY3;
- else
- mVals4 >> cVal >> mVal >> yVal >> coorX1 >> coorY1 >> coorX2 >> coorY2 >> dummy >> coorX3 >> coorY3;
- accumColorC += cVal;
- accumColorM += mVal;
- accumColorY += yVal;
- accumColorK += kVal;
- if (meshNodeCounter == 1)
- {
- meshNode1PointX = coorX1 - docX;
- meshNode1PointY = docHeight - (coorY1 - docY);
- meshNode1Control2X = coorX2 - docX;
- meshNode1Control2Y = docHeight - (coorY2 - docY);
- meshNode1Control1X = coorX3 - docX;
- meshNode1Control1Y = docHeight - (coorY3 - docY);
- }
- if (meshNodeCounter == 2)
- {
- meshNode2PointX = coorX1 - docX;
- meshNode2PointY = docHeight - (coorY1 - docY);
- meshNode2Control2X = coorX2 - docX;
- meshNode2Control2Y = docHeight - (coorY2 - docY);
- meshNode2Control1X = coorX3 - docX;
- meshNode2Control1Y = docHeight - (coorY3 - docY);
- }
- if (meshNodeCounter == 3)
- {
- meshNode3PointX = coorX1 - docX;
- meshNode3PointY = docHeight - (coorY1 - docY);
- meshNode3Control2X = coorX2 - docX;
- meshNode3Control2Y = docHeight - (coorY2 - docY);
- meshNode3Control1X = coorX3 - docX;
- meshNode3Control1Y = docHeight - (coorY3 - docY);
- }
- if (meshNodeCounter == 4)
- {
- meshNode4PointX = coorX1 - docX;
- meshNode4PointY = docHeight - (coorY1 - docY);
- meshNode4Control2X = coorX2 - docX;
- meshNode4Control2Y = docHeight - (coorY2 - docY);
- meshNode4Control1X = coorX3 - docX;
- meshNode4Control1Y = docHeight - (coorY3 - docY);
- }
- }
- }
-/* End Color commands */
-/* Start Layer commands */
- else if (command == "Lb")
- {
- if (importerFlags & LoadSavePlugin::lfCreateDoc)
- {
- int visible, preview, enabled, printing, dummy, rc, gc, bc;
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> visible >> preview >> enabled >> printing >> dummy >> dummy >> dummy >> rc >> gc >> bc;
- if (!firstLayer)
- currentLayer = m_Doc->addLayer("Layer", true);
- m_Doc->setLayerVisible(currentLayer, static_cast<bool>(visible));
- m_Doc->setLayerOutline(currentLayer, static_cast<bool>(!preview));
- m_Doc->setLayerLocked(currentLayer, static_cast<bool>(!enabled));
- m_Doc->setLayerPrintable(currentLayer, static_cast<bool>(printing));
- m_Doc->setLayerMarker(currentLayer, QColor(rc, gc, bc));
- firstLayer = false;
- }
- Coords.resize(0);
- Coords.svgInit();
- }
- else if (command == "LB")
- {
- Coords.resize(0);
- Coords.svgInit();
- }
- else if (command == "Ln")
- {
- if (importerFlags & LoadSavePlugin::lfCreateDoc)
- {
- int an = Cdata.indexOf("(");
- int en = Cdata.lastIndexOf(")");
- QString LayerNam = Cdata.mid(an+1, en-an-1);
- LayerNam.remove("\\");
- m_Doc->changeLayerName(currentLayer, LayerNam);
- }
- }
-/* End Layer commands */
-/* Start Text commands */
- else if (command == "To")
- {
- ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
- ts2 >> textMode;
- textData.clear();
- textMatrix = QMatrix();
- maxWidth = 0;
- tempW = 0;
- maxHeight = 0;
- textKern = 0;
- startCurrentTextRange = 0;
- endCurrentTextRange = 0;
- textScaleH = 1000;
- textScaleV = 1000;
- }
- else if (command == "Tp")
- {
- ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
- double m1, m2, m3, m4, m5, m6;
- gVals >> m1 >> m2 >> m3 >> m4 >> m5 >> m6;
- textMatrix = QMatrix(m1, m2, m3, m4, m5, m6);
- }
- else if (command == "Tx") // || (command == "TX"))
- {
- QStringList res = getStrings(Cdata);
- if (res.count() > 0)
- {
- QString tex = res[0];
- double tempH = 0;
- startCurrentTextRange = textData.length();
- for (int tt = 0; tt < tex.length(); ++tt)
- {
- CharStyle nstyle;
- QString ch = tex.mid(tt,1);
- nstyle.setFont((*m_Doc->AllFonts)[textFont]);
- nstyle.setFontSize(textSize);
- nstyle.setFillColor(CurrColorFill);
- nstyle.setTracking(textKern);
- nstyle.setFillShade(100);
- nstyle.setStrokeColor(CurrColorStroke);
- nstyle.setStrokeShade(100);
- nstyle.setScaleH(textScaleH);
- nstyle.setScaleV(textScaleV);
- nstyle.setBaselineOffset(0);
- nstyle.setShadowXOffset(50);
- nstyle.setShadowYOffset(-50);
- nstyle.setOutlineWidth(10);
- nstyle.setUnderlineOffset(-1);
- nstyle.setUnderlineWidth(-1);
- nstyle.setStrikethruOffset(-1);
- nstyle.setStrikethruWidth(-1);
- nstyle.setFeatures(StyleFlag(ScStyle_Default).featureList());
- int pot = textData.length();
- textData.insertChars(pot, ch);
- textData.applyCharStyle(pot, 1, nstyle);
- tempW += nstyle.font().realCharWidth(ch[0], nstyle.fontSize() / 10.0)+1;
- tempH = qMax(tempH, nstyle.font().height(nstyle.fontSize() / 10.0) + 2.0);
- maxWidth = qMax(tempW, maxWidth);
- maxHeight = qMax(tempH, maxHeight);
- if ((ch == SpecialChars::PARSEP) || (ch == SpecialChars::LINEBREAK))
- {
- maxHeight += nstyle.font().height(nstyle.fontSize() / 10.0);
- tempW = 0;
- }
- endCurrentTextRange = pot;
- }
- }
- }
- else if (command == "Tk")
- {
- int flag;
- double val;
- ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
- gVals >> flag >> val;
- if (flag == 1)
- val = 0;
- double oldval = textData.charStyle(startCurrentTextRange).tracking();
- CharStyle nstyle = textData.charStyle(startCurrentTextRange);
- nstyle.setTracking(oldval + val);
- textData.applyCharStyle(startCurrentTextRange, 1, nstyle);
- }
- else if (command == "Tc")
- {
- ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
- gVals >> textKern;
- textKern *= 100.0;
- }
- else if (command == "Tz")
- {
- ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
- gVals >> textScaleH >> textScaleV;
- textScaleH *= 10.0;
- textScaleV *= 10.0;
- }
- else if (command == "T*")
- {
- CharStyle nstyle;
- QString ch = SpecialChars::LINEBREAK;
- nstyle.setFont((*m_Doc->AllFonts)[textFont]);
- nstyle.setFontSize(textSize);
- nstyle.setFillColor(CurrColorFill);
- nstyle.setTracking(textKern);
- nstyle.setFillShade(100);
- nstyle.setStrokeColor(CurrColorStroke);
- nstyle.setStrokeShade(100);
- nstyle.setScaleH(textScaleH);
- nstyle.setScaleV(textScaleV);
- nstyle.setBaselineOffset(0);
- nstyle.setShadowXOffset(50);
- nstyle.setShadowYOffset(-50);
- nstyle.setOutlineWidth(10);
- nstyle.setUnderlineOffset(-1);
- nstyle.setUnderlineWidth(-1);
- nstyle.setStrikethruOffset(-1);
- nstyle.setStrikethruWidth(-1);
- nstyle.setFeatures(StyleFlag(ScStyle_Default).featureList());
- int pot = textData.length();
- textData.insertChars(pot, ch);
- textData.applyCharStyle(pot, 1, nstyle);
- maxHeight += nstyle.font().height(nstyle.fontSize() / 10.0) + 2.0;
- tempW = 0;
- }
- else if (command == "Tf")
- {
- ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
- gVals >> textFont >> textSize;
- textFont.remove(0, 2);
- QString family = textFont;
- QString ret = "";
- family.replace( QRegExp( "'" ) , QChar( ' ' ) );
- textFont = m_Doc->toolSettings.defFont;
- bool found = false;
- SCFontsIterator it(PrefsManager::instance()->appPrefs.AvailFonts);
- for ( ; it.hasNext(); it.next())
- {
- QString fam;
- QString fn = it.current().scName();
- int pos = fn.indexOf(" ");
- fam = fn.left(pos);
- if (fam == family)
- {
- found = true;
- ret = fn;
- }
- }
- if (found)
- textFont = family;
- else
- {
- if (!PrefsManager::instance()->appPrefs.GFontSub.contains(family))
- {
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- MissingFont *dia = new MissingFont(0, family, m_Doc);
- dia->exec();
- QString tmpf = dia->getReplacementFont();
- delete dia;
- qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
- PrefsManager::instance()->appPrefs.GFontSub[family] = tmpf;
- }
- else
- textFont = PrefsManager::instance()->appPrefs.GFontSub[family];
- }
- textSize *= 10.0;
- }
- else if (command == "TO")
- {
- if (textData.length() > 0)
- {
- if (!((textData.length() == 1) && (textData.text(0) == SpecialChars::PARSEP)))
- {
- QPointF pos = QPointF(textMatrix.dx(), textMatrix.dy());
- pos += QPointF(m_Doc->currentPage()->xOffset(), -m_Doc->currentPage()->yOffset());
- pos += QPointF(0.0, textSize / 10.0 + 2.0);
- z = m_Doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, pos.x() - docX, docHeight - (pos.y() - docY), 10, 10, 0, CommonStrings::None, CommonStrings::None, true);
- ite = m_Doc->Items->at(z);
- ite->setTextToFrameDist(0.0, 0.0, 0.0, 0.0);
- ite->itemText.append(textData);
- double xpos = ite->xPos();
- double ypos = ite->yPos();
- ite->setWidthHeight(qMax(ite->width(), maxWidth), qMax(ite->height(), maxHeight));
- double xoffset = 0.0, yoffset = 0.0;
- double rotation = getRotationFromMatrix(textMatrix, 0.0);
- if (rotation != 0.0)
- {
- double temp = textSize / 10.0 + 2.0;
- xoffset = sin(rotation) * temp;
- yoffset = cos(rotation) * temp;
- }
- ite->setXPos(xpos + xoffset);
- ite->setYPos(ypos + yoffset);
- ite->setRotation(rotation * 180 / M_PI);
- ite->SetRectFrame();
- m_Doc->setRedrawBounding(ite);
- ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
- ite->setTextFlowMode(PageItem::TextFlowDisabled);
- ite->setFillShade(CurrFillShade);
- ite->setLineShade(CurrStrokeShade);
- ite->setFillEvenOdd(fillRule);
- ite->setFillTransparency(1.0 - Opacity);
- ite->setLineTransparency(1.0 - Opacity);
- ite->setLineEnd(CapStyle);
- ite->setLineJoin(JoinStyle);
- if (importerFlags & LoadSavePlugin::lfCreateDoc)
- ite->setLocked(itemLocked);
- if (patternMode)
- PatternElements.append(ite);
- else
- Elements.append(ite);
- if (groupStack.count() != 0)
- groupStack.top().append(ite);
- }
- }
- }
-/* End Text commands */
-/* Start special Commands */
- else if (command == "*")
- {
- Coords.resize(0);
- Coords.svgInit();
- }
- else if ((command == "N") || (command == "n"))
- {
- Coords.resize(0);
- Coords.svgInit();
- }
- else if (command == "[")
- {
- Coords.resize(0);
- Coords.svgInit();
- int an = Cdata.indexOf("(");
- int en = Cdata.lastIndexOf(")");
- if ((an != -1) && (en != -1))
- {
- patternMode = true;
- currentPatternDefName = Cdata.mid(an+1, en-an-1);
- currentPatternDefName.remove("\\");
- currentPatternDefName = currentPatternDefName.trimmed().simplified().replace(" ", "_");
- QString tmpS = Cdata.mid(en+1, Cdata.size() - en);
- ScTextStream gVals(&tmpS, QIODevice::ReadOnly);
- gVals >> patternX1 >> patternY1 >> patternX2 >> patternY2;
- }
- }
-/* End special Commands */
-/* Skip everything else */
-// else
-// qDebug(command);
- }
-}
-
-void AIPlug::processGradientData(QString data)
-{
- QString command = "";
- QString Cdata = "";
- QStringList da;
- getCommands(data, da);
- for (int a = 0; a < da.count(); a++)
- {
- Cdata = da[a];
- QStringList da2 = Cdata.split(" ", QString::SkipEmptyParts);
- command = da2[da2.count()-1];
- if (command == "Bd")
- {
- QString tmpS = Cdata;
- int an = Cdata.indexOf("(");
- int en = Cdata.lastIndexOf(")");
- currentGradientName = Cdata.mid(an+1, en-an-1);
- currentGradientName.remove("\\");
- if (da2[da2.count()-3] == "0")
- currentGradient = VGradient(VGradient::linear);
- else
- currentGradient = VGradient(VGradient::radial);
- currentGradient.clearStops();
- }
- else if ((command == "%_Bs") || (command == "%_BS"))
- {
- QString stopName = "";
- double stop = ScCLocale::toDoubleC(da2[da2.count()-2]) / 100.0;
- double colorShade = 100.0;
- int colortype = da2[da2.count()-4].toInt();
- if (colortype == 0)
- {
- stopName = parseColorGray(Cdata);
- const ScColor& gradC = m_Doc->PageColors[stopName];
- currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), stop, 0.5, 1.0, stopName, 100 );
- }
- else if (colortype == 1)
- {
- stopName = parseColor(Cdata);
- const ScColor& gradC = m_Doc->PageColors[stopName];
- currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), stop, 0.5, 1.0, stopName, 100 );
- }
- else if (colortype == 2)
- {
- stopName = parseColor(Cdata);
- const ScColor& gradC = m_Doc->PageColors[stopName];
- currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), stop, 0.5, 1.0, stopName, 100 );
- }
- else if (colortype == 3)
- {
- stopName = parseCustomColor(Cdata, colorShade);
- const ScColor& gradC = m_Doc->PageColors[stopName];
- currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), stop, 0.5, 1.0, stopName, qRound(colorShade));
- }
- else if (colortype == 4)
- {
- stopName = parseCustomColorX(Cdata, colorShade, "0");
- const ScColor& gradC = m_Doc->PageColors[stopName];
- currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), stop, 0.5, 1.0, stopName, qRound(colorShade));
- }
- }
- else if (command == "BD")
- {
- m_gradients.insert(currentGradientName, currentGradient);
- currentGradient = VGradient(VGradient::linear);
- currentGradient.clearStops();
- currentGradient.setRepeatMethod( VGradient::none );
- currentGradientName = "";
- }
- }
-}
-
-void AIPlug::processPattern(QDataStream &ts)
-{
- QString tmp = "";
- QString tmpData = "";
- while (!ts.atEnd())
- {
- tmp = removeAIPrefix(readLinefromDataStream(ts));
- if (patternMode)
- {
- if (tmp == "EndPattern")
- {
- tmpSel->clear();
- if (PatternElements.count() > 0)
- {
- for (int dre = 0; dre < PatternElements.count(); ++dre)
- {
- tmpSel->addItem(PatternElements.at(dre), true);
- }
- if (PatternElements.count() > 1)
- m_Doc->itemSelection_GroupObjects(false, false, tmpSel);
- ScPattern pat = ScPattern();
- pat.setDoc(m_Doc);
- PageItem* currItem = tmpSel->itemAt(0);
- currItem->setItemName(currentPatternDefName);
- currItem->AutoName = false;
- m_Doc->DoDrawing = true;
- QImage tmpImg = currItem->DrawObj_toImage();
- QImage retImg = QImage(qRound(patternX2 - patternX1), qRound(patternY2 - patternY1), QImage::Format_ARGB32);
- retImg.fill( qRgba(255, 255, 255, 0) );
- QPainter p;
- p.begin(&retImg);
- if (PatternElements.count() > 1)
- p.drawImage(qRound(-patternX1), qRound(-patternY1), tmpImg);
- else
- p.drawImage(0, 0, tmpImg);
- p.end();
- pat.pattern = retImg;
-// pat.pattern = currItem->DrawObj_toImage();
- m_Doc->DoDrawing = false;
- // pat.width = currItem->gWidth;
- // pat.height = currItem->gHeight;
- pat.width = patternX2 - patternX1;
- pat.height = patternY2 - patternY1;
- pat.xoffset = -patternX1;
- pat.yoffset = -patternY1;
- for (int as = 0; as < tmpSel->count(); ++as)
- {
- PageItem* Neu = tmpSel->itemAt(as);
- Neu->moveBy(-patternX1, -patternY1, true);
- Neu->gXpos -= patternX1;
- Neu->gYpos -= patternY1;
- pat.items.append(Neu);
- }
- m_Doc->itemSelection_DeleteItem(tmpSel);
- m_Doc->addPattern(currentPatternDefName, pat);
- }
- PatternElements.clear();
- currentPatternDefName = "";
- break;
- }
- else if (tmp.startsWith("Tile"))
- continue;
- else if (tmp.contains(") @"))
- {
- tmpData += tmp;
- tmpData.remove(") @");
- processData(tmpData);
- tmpData = "";
- }
- else if (tmp.contains(") &"))
- {
- tmpData += tmp;
- tmpData.remove(") &");
- processData(tmpData);
- tmpData = "";
- }
- else
- {
- if (tmp.startsWith("("))
- tmp.remove(0, 1);
- tmpData += " "+tmp;
- }
- }
- else if (tmp == "EndPattern")
- {
- PatternElements.clear();
- currentPatternDefName = "";
- break;
- }
- else
- processData(tmp);
- }
- patternMode = false;
-}
-
-void AIPlug::processRaster(QDataStream &ts)
-{
- double m1, m2, m3, m4, m5, m6, x1, y1, x2, y2, dummy;
- int w, h, type, alpha, bin, bits;
- QString tmp = "";
- QString cumulated = "";
- while (!ts.atEnd())
- {
- tmp = readLinefromDataStream(ts);
- if (tmp.startsWith("%"))
- break;
- tmp.remove("[");
- tmp.remove("]");
- if (!tmp.isEmpty())
- cumulated += " " + tmp;
- }
- QString Cdata = "";
- QStringList da;
- getCommands(cumulated, da);
- Cdata = da[da.count()-1];
- ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
- gVals >> m1 >> m2 >> m3 >> m4 >> m5 >> m6 >> x1 >> y1 >> x2 >> y2 >> w >> h >> bits >> type >> alpha >> dummy >> bin;
-// qDebug() << QString("Matrix: %1 %2 %3 %4 %5 %6").arg(m1).arg(m2).arg(m3).arg(m4).arg(m5).arg(m6);
-// qDebug() << QString("Bounds: %1 %2 %3 %4").arg(x1).arg(y1).arg(x2).arg(y2);
-// qDebug() << QString("Size: %1 %2").arg(w).arg(h);
-// qDebug() << QString("Bits: %1").arg(bits);
-// qDebug() << QString("Typ: %1").arg(type);
-// qDebug() << QString("Alpha-Channels: %1").arg(alpha);
-// qDebug() << QString("Encoding: %1").arg(bin);
- uint dataSize = w * h * (type + alpha);
- uint alphaData = w * h * type;
- bool cmyk = false;
- if (type == 4)
- cmyk = true;
- if (tmp.startsWith("%%BeginData"))
- {
- QString dummyS;
- ScTextStream gVals2(&tmp, QIODevice::ReadOnly);
- tmp = readLinefromDataStream(ts);
- }
- QByteArray psdata;
- psdata.resize(dataSize);
- RawImage m_image;
- if (type == 4)
- {
- if (alpha > 0)
- m_image.create(w, 1, 5);
- else
- m_image.create(w, 1, 4);
- }
- else
- {
- if (alpha > 0)
- m_image.create(w, 1, 4);
- else
- m_image.create(w, 1, 3);
- }
- bool first = false;
- if (bin == 0) // 0 = ASCII encoded data
- {
- uint dataPointer = 0;
- while (!ts.atEnd())
- {
- if (first)
- tmp = readLinefromDataStream(ts);
- first = true;
- if (tmp.startsWith("%AI5_EndRaster"))
- break;
- for (int a = 1; a < tmp.length(); a += 2)
- {
- bool ok;
- ushort data = tmp.mid(a, 2).toUShort(&ok, 16);
- psdata[dataPointer++] = data;
- }
- }
- }
- else
- {
- psdata.resize(dataSize);
- ts.readRawData(psdata.data(), dataSize);
- }
- QMatrix imgMatrix = QMatrix(m1, m2, m3, m4, m5, m6);
- QPointF pos = QPointF(imgMatrix.dx(), imgMatrix.dy());
- pos += QPointF(m_Doc->currentPage()->xOffset(), -m_Doc->currentPage()->yOffset());
- pos += QPointF(baseX, -baseY);
- int z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, pos.x() - docX, docHeight - (pos.y() - docY), 10, 10, 0, CurrColorFill, CurrColorStroke, true);
- PageItem* ite = m_Doc->Items->at(z);
- ite->setWidthHeight(w * m1, h * m4);
- double rotation = getRotationFromMatrix(imgMatrix, 0.0);
- ite->setRotation(rotation * 180 / M_PI);
- ite->SetRectFrame();
- m_Doc->setRedrawBounding(ite);
- ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
- ite->setTextFlowMode(PageItem::TextFlowDisabled);
- ite->setFillShade(CurrFillShade);
- ite->setLineShade(CurrStrokeShade);
- ite->setFillEvenOdd(fillRule);
- ite->setFillTransparency(1.0 - Opacity);
- ite->setLineTransparency(1.0 - Opacity);
- ite->setLineEnd(CapStyle);
- ite->setLineJoin(JoinStyle);
- uchar *p;
- uint yCount = 0;
- ite->tempImageFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_ai_XXXXXX.tif");
- ite->tempImageFile->open();
- QString imgName = getLongPathName(ite->tempImageFile->fileName());
- ite->tempImageFile->close();
- ite->isInlineImage = true;
- TIFF* tif = TIFFOpen(imgName.toLocal8Bit().data(), "w");
- if (tif)
- {
- TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, w);
- TIFFSetField(tif, TIFFTAG_IMAGELENGTH, h);
- TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
- TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, m_image.channels());
- TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
- if (type == 4)
- TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_SEPARATED);
- else
- TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
- TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
- for (int y = 0; y < h; ++y)
- {
- p = m_image.scanLine( 0 );
- for (int xh = 0; xh < m_image.width(); ++xh )
- {
- p[0] = psdata[yCount++];
- if (type > 1)
- {
- p[1] = psdata[yCount++];
- p[2] = psdata[yCount++];
- if (type == 4)
- p[3] = psdata[yCount++];
- }
- else
- {
- p[1] = p[0];
- p[2] = p[0];
- }
- if (alpha == 1)
- {
- if (type == 4)
- p[4] = psdata[alphaData++];
- else
- p[3] = psdata[alphaData++];
- }
- p += m_image.channels();
- }
- TIFFWriteScanline(tif, m_image.scanLine(0), y);
- }
- TIFFClose(tif);
- }
- m_Doc->LoadPict(imgName, z);
- if (ite->PictureIsAvailable)
- ite->setImageXYScale(ite->width() / ite->pixm.width(), ite->height() / ite->pixm.height());
- if (importerFlags & LoadSavePlugin::lfCreateDoc)
- ite->setLocked(itemLocked);
- if (patternMode)
- PatternElements.append(ite);
- else
- Elements.append(ite);
- if (groupStack.count() != 0)
- groupStack.top().append(ite);
-}
-
-void AIPlug::processComment(QDataStream &ts, QString comment)
-{
- QString tmp = removeAIPrefix(comment);
- if (tmp.startsWith("Begin_NonPrinting"))
- {
- while (!ts.atEnd())
- {
- tmp = removeAIPrefix(readLinefromDataStream(ts));
- if (tmp.startsWith("BeginGradient"))
- {
- while (!ts.atEnd())
- {
- tmp = removeAIPrefix(readLinefromDataStream(ts));
- if (tmp.startsWith("EndGradient"))
- break;
- else
- processGradientData(tmp);
- }
- }
- if (tmp.startsWith("BeginPattern:"))
- processPattern(ts);
- if (tmp.startsWith("End_NonPrinting"))
- break;
- progressDialog->setProgress("GI", ts.device()->pos());
- qApp->processEvents();
- }
- }
- else if (tmp.startsWith("BeginPattern:"))
- processPattern(ts);
- else if (tmp.startsWith("BeginGradient"))
- {
- while (!ts.atEnd())
- {
- tmp = removeAIPrefix(readLinefromDataStream(ts));
- if (tmp.startsWith("EndGradient"))
- break;
- else
- processGradientData(tmp);
- progressDialog->setProgress("GI", ts.device()->pos());
- qApp->processEvents();
- }
- }
- else if (tmp.startsWith("BeginPalette"))
- {
- while (!ts.atEnd())
- {
- tmp = removeAIPrefix(readLinefromDataStream(ts));
- if (tmp.startsWith("EndPalette"))
- break;
- progressDialog->setProgress("GI", ts.device()->pos());
- qApp->processEvents();
- }
- }
- else if (tmp.startsWith("BeginSymbol"))
- {
- while (!ts.atEnd())
- {
- tmp = removeAIPrefix(readLinefromDataStream(ts));
- if (tmp.startsWith("EndSymbol"))
- break;
- progressDialog->setProgress("GI", ts.device()->pos());
- qApp->processEvents();
- }
- }
- else if (tmp.startsWith("BeginDocumentData"))
- {
- while (!ts.atEnd())
- {
- tmp = removeAIPrefix(readLinefromDataStream(ts));
- if (tmp.startsWith("EndDocumentData"))
- break;
- progressDialog->setProgress("GI", ts.device()->pos());
- qApp->processEvents();
- }
- }
- else if (tmp.startsWith("%%BeginProlog"))
- {
- while (!ts.atEnd())
- {
- tmp = removeAIPrefix(readLinefromDataStream(ts));
- if (tmp.startsWith("%%EndProlog"))
- break;
- progressDialog->setProgress("GI", ts.device()->pos());
- qApp->processEvents();
- }
- }
- else if (tmp.startsWith("%%BeginData"))
- {
- while (!ts.atEnd())
- {
- tmp = removeAIPrefix(readLinefromDataStream(ts));
- if (tmp.startsWith("%%EndData"))
- break;
- progressDialog->setProgress("GI", ts.device()->pos());
- qApp->processEvents();
- }
- }
- else if (tmp.startsWith("%%BeginCrops"))
- {
- while (!ts.atEnd())
- {
- tmp = removeAIPrefix(readLinefromDataStream(ts));
- if (tmp.startsWith("%%EndCrops"))
- break;
- progressDialog->setProgress("GI", ts.device()->pos());
- qApp->processEvents();
- }
- }
- else if (tmp.startsWith("BeginRaster"))
- {
- processRaster(ts);
- progressDialog->setProgress("GI", ts.device()->pos());
- qApp->processEvents();
- }
- else if (tmp.startsWith("BeginLayer"))
- {
- while (!ts.atEnd())
- {
- tmp = removeAIPrefix(readLinefromDataStream(ts));
- if (tmp.startsWith("BeginRaster"))
- {
- processRaster(ts);
- continue;
- }
- if (tmp.startsWith("EndLayer"))
- break;
- else
- processData(tmp);
- progressDialog->setProgress("GI", ts.device()->pos());
- qApp->processEvents();
- }
- }
-}
-
-bool AIPlug::convert(QString fn)
-{
- QString tmp;
- LineW = 1.0;
- Opacity = 1.0;
- blendMode = 0;
- CurrColorFill = "White";
- CurrFillShade = 100.0;
- CurrColorStroke = "Black";
- CurrStrokeShade = 100.0;
- JoinStyle = Qt::MiterJoin;
- CapStyle = Qt::FlatCap;
- DashPattern.clear();
- DashOffset = 0.0;
- fillRule = false;
- FirstU = false;
- WasU = false;
- firstLayer = true;
- patternMode = false;
- meshMode = false;
- itemLocked = false;
- patternX1 = 0.0;
- patternY1 = 0.0;
- patternX2 = 0.0;
- patternY2 = 0.0;
- Coords.resize(0);
- Coords.svgInit();
- clipCoords.resize(0);
- clipCoords.svgInit();
- currentPoint = FPoint(0.0, 0.0);
- currentLayer = 0;
- currentGradient = VGradient(VGradient::linear);
- currentGradient.clearStops();
- currentGradient.setRepeatMethod( VGradient::none );
- currentGradientName = "";
- currentGradientMatrix = QMatrix();
- currentGradientOrigin = QPointF(0.0, 0.0);
- currentGradientAngle = 0.0;
- currentGradientLenght = 1.0;
- currentPatternName = "";
- currentPatternX = 0.0;
- currentPatternY = 0.0;
- currentPatternXScale = 1.0;
- currentPatternYScale = 1.0;
- currentPatternRotation = 0.0;
- QList<PageItem*> gElements;
- groupStack.push(gElements);
- commandList << "m" << "l" << "L" << "c" << "C" << "v" << "V" << "y" << "Y"; // Path construction
- commandList << "b" << "B" << "f" << "F" << "s" << "S" << "*u" << "*U"; // Object creation
- commandList << "u" << "U" << "W" << "q" << "Q"; // Object creation
- commandList << "A" << "w" << "j" << "J" << "Xy" << "XR"; // Graphic state
- commandList << "k" << "K" << "Xa" << "XA" << "x" << "X" << "XX" << "Xx"; // Color commands
- commandList << "Xk" << "g" << "G" << "p"; // Color commands
- commandList << "Ln" << "Lb" << "LB"; // Layer commands
- commandList << "Bd" << "BD" << "%_Bs" << "Bg" << "Bb" << "BB" << "Bm" << "Xm"; // Gradient commands
- commandList << "To" << "TO" << "Tf" << "Tp" << "Tx" << "TX" << "T*" << "Tk"; // Text commands
- commandList << "Tc" << "Tz"; // Text commands
- commandList << "XI" << "XG" << "Xh"; // Image commands
- commandList << "n" << "N" << "*" << "["; // Special commands
- commandList << "X!" << "X#"; // Mesh commands
- commandList << "M" << "d" << "D" << "E"; // unimplemented
- commandList << "h" << "H" << "i" << "I" << "Np" << "O"; // unimplemented
- commandList << "P" << "R"; // unimplemented
- commandList << "XI" << "XF" << "XG" << "XT" << "Z" << "`" << "~" << "_" << "@"; // unimplemented
- commandList << "&" << "*w" << "*W" << "Ap" << "Ar"; // unimplemented
- if(progressDialog)
- {
- progressDialog->setOverallProgress(2);
- progressDialog->setLabel("GI", tr("Generating Items"));
- qApp->processEvents();
- }
- QFile f(fn);
- if (f.open(QIODevice::ReadOnly))
- {
- int fSize = (int) f.size();
- if (progressDialog)
- {
- progressDialog->setTotalSteps("GI", fSize);
- qApp->processEvents();
- }
- QDataStream ts(&f);
- while (!ts.atEnd())
- {
- tmp = readLinefromDataStream(ts);
- if (tmp.startsWith("%"))
- processComment(ts, tmp);
- else
- processData(tmp);
- progressDialog->setProgress("GI", ts.device()->pos());
- qApp->processEvents();
- }
- }
- if (progressDialog)
- progressDialog->close();
- return true;
-}
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#include <QByteArray>
+#include <QCursor>
+#include <QDrag>
+#include <QFile>
+#include <QList>
+#include <QMimeData>
+#include <QRegExp>
+#include <QStack>
+#include <QStack>
+#include <QTemporaryFile>
+#include <QDebug>
+
+#include <cmath>
+#include <cstdlib>
+#include <tiffio.h>
+#include <zlib.h>
+
+#include "commonstrings.h"
+#include "ui/customfdialog.h"
+#include "importai.h"
+#include "loadsaveplugin.h"
+#include "ui/missing.h"
+#include "ui/multiprogressdialog.h"
+#include "prefscontext.h"
+#include "prefsfile.h"
+#include "prefsmanager.h"
+#include "prefsmanager.h"
+#include "prefstable.h"
+#include "ui/propertiespalette.h"
+#include "rawimage.h"
+#include "sccolorengine.h"
+#include "scconfig.h"
+#include "scclocale.h"
+#include "scmimedata.h"
+#include "scpaths.h"
+#include "scpattern.h"
+#include "scribus.h"
+#include "scribusXml.h"
+#include "scribuscore.h"
+#include "scribusdoc.h"
+#include "sctextstream.h"
+#include "selection.h"
+#include "text/specialchars.h"
+#include "undomanager.h"
+#include "util.h"
+#include "util_color.h"
+#include "util_file.h"
+#include "util_formats.h"
+#include "util_icon.h"
+#include "util_math.h"
+
+
+#ifdef HAVE_PODOFO
+ #include <podofo/podofo.h>
+#endif
+
+extern SCRIBUS_API ScribusQApp * ScQApp;
+
+AIPlug::AIPlug(ScribusDoc* doc, int flags)
+{
+ tmpSel=new Selection(this, false);
+ m_Doc=doc;
+ interactive = (flags & LoadSavePlugin::lfInteractive);
+ progressDialog = NULL;
+}
+
+bool AIPlug::import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
+{
+ QString fName = fNameIn;
+ bool success = false;
+ interactive = (flags & LoadSavePlugin::lfInteractive);
+ importerFlags = flags;
+ cancel = false;
+ double x, y, b, h;
+ bool ret = false;
+ convertedPDF = false;
+ CustColors.clear();
+ QFileInfo fi = QFileInfo(fName);
+// QString ext = fi.suffix().toLower();
+ if ( !ScCore->usingGUI() )
+ {
+ interactive = false;
+ showProgress = false;
+ }
+
+/* Check if the file is an old style AI or one of the newer PDF wrapped ones */
+ QFile fT(fName);
+ if (fT.open(QIODevice::ReadOnly))
+ {
+ QByteArray tempBuf(9, ' ');
+ fT.read(tempBuf.data(), 8);
+ fT.close();
+ if (tempBuf.startsWith("%PDF"))
+ {
+ QFileInfo bF2(fName);
+ QString tmpFile = ScPaths::getTempFileDir()+ "/"+bF2.baseName()+"_tmp.ai";
+ if (!extractFromPDF(fName, tmpFile))
+ return false;
+ convertedPDF = true;
+ fName = tmpFile;
+ }
+ }
+ QFile fT2(fName);
+ if (fT2.open(QIODevice::ReadOnly))
+ {
+ QByteArray tempBuf(25, ' ');
+ fT2.read(tempBuf.data(), 20);
+ fT2.close();
+ /* Illustrator CS files might be compressed
+ the compressed Data starts right after the "%AI12_CompressedData" comment
+ Compression is a simple zlib compression */
+ if (tempBuf.startsWith("%AI12_CompressedData"))
+ decompressAIData(fName);
+ }
+ if ( showProgress )
+ {
+ ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
+ progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw );
+ QStringList barNames, barTexts;
+ barNames << "GI";
+ barTexts << tr("Analyzing File:");
+ QList<bool> barsNumeric;
+ barsNumeric << false;
+ progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
+ progressDialog->setOverallTotalSteps(3);
+ progressDialog->setOverallProgress(0);
+ progressDialog->setProgress("GI", 0);
+ progressDialog->show();
+ connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
+ qApp->processEvents();
+ }
+ else
+ progressDialog = NULL;
+/* Set default Page to size defined in Preferences */
+ x = 0.0;
+ y = 0.0;
+ b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth;
+ h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight;
+ if (progressDialog)
+ {
+ progressDialog->setOverallProgress(1);
+ qApp->processEvents();
+ }
+ parseHeader(fName, x, y, b, h);
+ docX = x;
+ docY = y;
+ docWidth = b - x;
+ docHeight = h - y;
+ baseX = 0;
+ baseY = 0;
+ if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
+ {
+ m_Doc->setPage(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false);
+ m_Doc->addPage(0);
+ m_Doc->view()->addPage(0, true);
+ baseX = 0;
+ baseY = 0;
+ }
+ else
+ {
+ if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
+ {
+ m_Doc=ScCore->primaryMainWindow()->doFileNew(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
+ ScCore->primaryMainWindow()->HaveNewDoc();
+ ret = true;
+ baseX = 0;
+ baseY = 0;
+ }
+ }
+ if (flags & LoadSavePlugin::lfCreateDoc)
+ {
+ m_Doc->documentInfo.setAuthor(docCreator);
+ m_Doc->documentInfo.setPublisher(docOrganisation);
+ m_Doc->documentInfo.setTitle(docTitle);
+ m_Doc->documentInfo.setDate(docDate+" "+docTime);
+ }
+ if ((!ret) && (interactive))
+ {
+ baseX = m_Doc->currentPage()->xOffset();
+ baseY = m_Doc->currentPage()->yOffset();
+ }
+ if ((ret) || (!interactive))
+ {
+ if (b-x > h-y)
+ m_Doc->PageOri = 1;
+ else
+ m_Doc->PageOri = 0;
+ m_Doc->m_pageSize = "Custom";
+ }
+ ColorList::Iterator it;
+ for (it = CustColors.begin(); it != CustColors.end(); ++it)
+ {
+ if (!m_Doc->PageColors.contains(it.key()))
+ m_Doc->PageColors.insert(it.key(), it.value());
+ }
+ Elements.clear();
+ FPoint minSize = m_Doc->minCanvasCoordinate;
+ FPoint maxSize = m_Doc->maxCanvasCoordinate;
+ FPoint cOrigin = m_Doc->view()->canvasOrigin();
+ m_Doc->setLoading(true);
+ m_Doc->DoDrawing = false;
+ m_Doc->view()->updatesOn(false);
+ m_Doc->scMW()->ScriptRunning = true;
+ qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
+ QString CurDirP = QDir::currentPath();
+ QDir::setCurrent(fi.path());
+ if (convert(fName))
+ {
+ tmpSel->clear();
+ QDir::setCurrent(CurDirP);
+ if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc)))
+ {
+ bool isGroup = true;
+ int firstElem = -1;
+ if (Elements.at(0)->Groups.count() != 0)
+ firstElem = Elements.at(0)->Groups.top();
+ for (int bx = 0; bx < Elements.count(); ++bx)
+ {
+ PageItem* bxi = Elements.at(bx);
+ if (bxi->Groups.count() != 0)
+ {
+ if (bxi->Groups.top() != firstElem)
+ isGroup = false;
+ }
+ else
+ isGroup = false;
+ }
+ if (!isGroup)
+ {
+ double minx = 99999.9;
+ double miny = 99999.9;
+ double maxx = -99999.9;
+ double maxy = -99999.9;
+ uint lowestItem = 999999;
+ uint highestItem = 0;
+ for (int a = 0; a < Elements.count(); ++a)
+ {
+ Elements.at(a)->Groups.push(m_Doc->GroupCounter);
+ PageItem* currItem = Elements.at(a);
+ lowestItem = qMin(lowestItem, currItem->ItemNr);
+ highestItem = qMax(highestItem, currItem->ItemNr);
+ double x1, x2, y1, y2;
+ currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
+ minx = qMin(minx, x1);
+ miny = qMin(miny, y1);
+ maxx = qMax(maxx, x2);
+ maxy = qMax(maxy, y2);
+ }
+ double gx = minx;
+ double gy = miny;
+ double gw = maxx - minx;
+ double gh = maxy - miny;
+ PageItem *high = m_Doc->Items->at(highestItem);
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, m_Doc->toolSettings.dBrush, m_Doc->toolSettings.dPen, true);
+ PageItem *neu = m_Doc->Items->takeAt(z);
+ m_Doc->Items->insert(lowestItem, neu);
+ neu->Groups.push(m_Doc->GroupCounter);
+ neu->setItemName( tr("Group%1").arg(neu->Groups.top()));
+ neu->isGroupControl = true;
+ neu->groupsLastItem = high;
+ neu->setTextFlowMode(PageItem::TextFlowDisabled);
+ for (int a = 0; a < m_Doc->Items->count(); ++a)
+ {
+ m_Doc->Items->at(a)->ItemNr = a;
+ }
+ Elements.prepend(neu);
+ m_Doc->GroupCounter++;
+ }
+ }
+ m_Doc->DoDrawing = true;
+ m_Doc->scMW()->ScriptRunning = false;
+ m_Doc->setLoading(false);
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ if ((Elements.count() > 0) && (!ret) && (interactive))
+ {
+ if (flags & LoadSavePlugin::lfScripted)
+ {
+ bool loadF = m_Doc->isLoading();
+ m_Doc->setLoading(false);
+ m_Doc->changed();
+ m_Doc->setLoading(loadF);
+ m_Doc->m_Selection->delaySignalsOn();
+ for (int dre=0; dre<Elements.count(); ++dre)
+ {
+ m_Doc->m_Selection->addItem(Elements.at(dre), true);
+ }
+ m_Doc->m_Selection->delaySignalsOff();
+ m_Doc->m_Selection->setGroupRect();
+ m_Doc->view()->updatesOn(true);
+ }
+ else
+ {
+ m_Doc->DragP = true;
+ m_Doc->DraggedElem = 0;
+ m_Doc->DragElements.clear();
+ m_Doc->m_Selection->delaySignalsOn();
+ for (int dre=0; dre<Elements.count(); ++dre)
+ {
+ m_Doc->DragElements.append(Elements.at(dre)->ItemNr);
+ tmpSel->addItem(Elements.at(dre), true);
+ }
+ tmpSel->setGroupRect();
+ ScriXmlDoc *ss = new ScriXmlDoc();
+ ScElemMimeData* md = new ScElemMimeData();
+ md->setScribusElem(ss->WriteElem(m_Doc, m_Doc->view(), tmpSel));
+ delete ss;
+/*#ifndef Q_WS_MAC*/
+// see #2196
+ m_Doc->itemSelection_DeleteItem(tmpSel);
+/*#else
+ qDebug("aiimport: leaving items on page");
+#endif*/
+ m_Doc->view()->updatesOn(true);
+ m_Doc->m_Selection->delaySignalsOff();
+ // We must copy the TransationSettings object as it is owned
+ // by handleObjectImport method afterwards
+ TransactionSettings* transacSettings = new TransactionSettings(trSettings);
+ m_Doc->view()->handleObjectImport(md, transacSettings);
+ m_Doc->DragP = false;
+ m_Doc->DraggedElem = 0;
+ m_Doc->DragElements.clear();
+ }
+ }
+ else
+ {
+ m_Doc->changed();
+ m_Doc->reformPages();
+ m_Doc->view()->updatesOn(true);
+ }
+ success = true;
+ }
+ else
+ {
+ QDir::setCurrent(CurDirP);
+ m_Doc->DoDrawing = true;
+ m_Doc->scMW()->ScriptRunning = false;
+ m_Doc->view()->updatesOn(true);
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ }
+ if (interactive)
+ m_Doc->setLoading(false);
+ //CB If we have a gui we must refresh it if we have used the progressbar
+ if ((showProgress) && (!interactive))
+ m_Doc->view()->DrawNew();
+ if (convertedPDF)
+ QFile::remove(fName);
+ return success;
+}
+
+AIPlug::~AIPlug()
+{
+ if (progressDialog)
+ delete progressDialog;
+ delete tmpSel;
+}
+
+bool AIPlug::extractFromPDF(QString infile, QString outfile)
+{
+ bool ret = false;
+#ifdef HAVE_PODOFO
+ QFile outf(outfile);
+ outf.open(QIODevice::WriteOnly);
+ try
+ {
+ PoDoFo::PdfError::EnableDebug( false );
+#if (PODOFO_VERSION == 0 && PODOFO_MINOR > 6)
+ PoDoFo::PdfError::EnableLogging( false );
+#endif
+#if (PODOFO_VERSION == 0 && PODOFO_MINOR == 5 && PODOFO_REVISION == 99) || PODOFO_MINOR > 5
+ PoDoFo::PdfMemDocument doc( infile.toLocal8Bit().data() );
+#else
+ PoDoFo::PdfDocument doc( infile.toLocal8Bit().data() );
+#endif
+ PoDoFo::PdfPage *curPage = doc.GetPage(0);
+ if (curPage != NULL)
+ {
+ PoDoFo::PdfObject *piece = curPage->GetObject()->GetIndirectKey("PieceInfo");
+ if (piece != NULL)
+ {
+ PoDoFo::PdfObject *illy = piece->GetIndirectKey("Illustrator");
+ if (illy != NULL)
+ {
+ PoDoFo::PdfObject *priv = illy->GetIndirectKey("Private");
+ if (priv == NULL)
+ priv = illy;
+ int num = 0;
+ PoDoFo::PdfObject *numBl = priv->GetIndirectKey("NumBlock");
+ if (numBl != NULL)
+ num = numBl->GetNumber() + 1;
+ if (num == 0)
+ num = 99999;
+ QString name = "AIPrivateData%1";
+ QString Key = name.arg(1);
+ PoDoFo::PdfObject *data = priv->GetIndirectKey(PoDoFo::PdfName(Key.toUtf8().data()));
+ if (data == NULL)
+ {
+ name = "AIPDFPrivateData%1";
+ Key = name.arg(1);
+ data = priv->GetIndirectKey(PoDoFo::PdfName(Key.toUtf8().data()));
+ }
+ if (data != NULL)
+ {
+ if (num == 2)
+ {
+ Key = name.arg(1);
+ data = priv->GetIndirectKey(PoDoFo::PdfName(Key.toUtf8().data()));
+ PoDoFo::PdfStream const *stream = data->GetStream();
+ PoDoFo::PdfMemoryOutputStream oStream(1);
+ stream->GetFilteredCopy(&oStream);
+ oStream.Close();
+ long bLen = oStream.GetLength();
+ char *Buffer = oStream.TakeBuffer();
+ outf.write(Buffer, bLen);
+ free( Buffer );
+ }
+ else
+ {
+ for (int a = 2; a < num; a++)
+ {
+ Key = name.arg(a);
+ data = priv->GetIndirectKey(PoDoFo::PdfName(Key.toUtf8().data()));
+ if (data == NULL)
+ break;
+ PoDoFo::PdfStream const *stream = data->GetStream();
+ PoDoFo::PdfMemoryOutputStream oStream(1);
+ stream->GetFilteredCopy(&oStream);
+ oStream.Close();
+ long bLen = oStream.GetLength();
+ char *Buffer = oStream.TakeBuffer();
+ outf.write(Buffer, bLen);
+ free( Buffer );
+ }
+ }
+ }
+ ret = true;
+ }
+ }
+ }
+ outf.close();
+ }
+ catch (PoDoFo::PdfError& e)
+ {
+ outf.close();
+ qDebug("Scribus caught and handled the following exception from PoDoFo while processing a PDF format ai file:\n----\n");
+ e.PrintErrorMsg();
+ qDebug("----\nThe ai file could not be imported.\n");
+ QFile::remove(outfile);
+ return false;
+ }
+#endif
+ return ret;
+}
+
+bool AIPlug::decompressAIData(QString &fName)
+{
+ QString f2 = fName+"_decom.ai";
+ FILE *source = fopen(fName.toLocal8Bit().constData(), "rb");
+ fseek(source, 20, SEEK_SET);
+ FILE *dest = fopen(f2.toLocal8Bit().constData(), "wb");
+ int ret;
+ unsigned have;
+ z_stream strm;
+ char in[4096];
+ char out[4096];
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ strm.avail_in = 0;
+ strm.next_in = Z_NULL;
+ ret = inflateInit(&strm);
+ if (ret != Z_OK)
+ return false;
+ do
+ {
+ strm.avail_in = fread(in, 1, 4096, source);
+ if (ferror(source))
+ {
+ (void)inflateEnd(&strm);
+ return false;
+ }
+ if (strm.avail_in == 0)
+ break;
+ strm.next_in = (Bytef*)in;
+ do
+ {
+ strm.avail_out = 4096;
+ strm.next_out = (Bytef*)out;
+ ret = inflate(&strm, Z_NO_FLUSH);
+ assert(ret != Z_STREAM_ERROR);
+ switch (ret)
+ {
+ case Z_NEED_DICT:
+ ret = Z_DATA_ERROR;
+ case Z_DATA_ERROR:
+ case Z_MEM_ERROR:
+ (void)inflateEnd(&strm);
+ return false;
+ }
+ have = 4096 - strm.avail_out;
+ if (fwrite(out, 1, have, dest) != have || ferror(dest))
+ {
+ (void)inflateEnd(&strm);
+ return false;
+ }
+ }
+ while (strm.avail_out == 0);
+ }
+ while (ret != Z_STREAM_END);
+ (void)inflateEnd(&strm);
+ fclose(source);
+ fclose(dest);
+ if (!convertedPDF)
+ {
+ QFileInfo bF2(fName);
+ QString tmpFile = ScPaths::getTempFileDir()+ "/"+bF2.baseName()+"_tmp.ai";
+ moveFile(f2, tmpFile);
+ fName = tmpFile;
+ convertedPDF = true;
+ }
+ else
+ {
+ QFile::remove(fName);
+ fName = f2;
+ }
+ return true;
+}
+
+bool AIPlug::parseHeader(QString fName, double &x, double &y, double &b, double &h)
+{
+ QString tmp, BBox, tmp2, FarNam;
+ ScColor cc;
+// double c, m, yc, k;
+ bool found = false;
+ QFile f(fName);
+ if (f.open(QIODevice::ReadOnly))
+ {
+/* Try to find Bounding Box */
+ QDataStream ts(&f);
+ while (!ts.atEnd())
+ {
+ tmp = readLinefromDataStream(ts);
+ if (tmp.startsWith("%%BoundingBox:"))
+ {
+ found = true;
+ BBox = tmp.remove("%%BoundingBox:");
+ }
+ if (!found)
+ {
+ if (tmp.startsWith("%%BoundingBox"))
+ {
+ found = true;
+ BBox = tmp.remove("%%BoundingBox");
+ }
+ }
+ if (tmp.startsWith("%%HiResBoundingBox:"))
+ {
+ found = true;
+ BBox = tmp.remove("%%HiResBoundingBox:");
+ }
+ if (tmp.startsWith("%%For"))
+ {
+ QStringList res = getStrings(tmp);
+ if (res.count() > 1)
+ {
+ docCreator = res[0];
+ docOrganisation = res[1];
+ }
+ }
+ if (tmp.startsWith("%%CreationDate:"))
+ {
+ QStringList res = getStrings(tmp);
+ if (res.count() > 1)
+ {
+ docDate = res[0];
+ docTime = res[1];
+ }
+ else
+ {
+ docDate = tmp.remove("%%CreationDate: ");
+ docTime = "";
+ }
+ }
+ if (tmp.startsWith("%%Title"))
+ {
+ QStringList res = getStrings(tmp);
+ if (res.count() > 0)
+ docTitle = res[0];
+ }
+ if (tmp.startsWith("%%EndComments"))
+ break;
+ }
+ f.close();
+ if (found)
+ {
+ QStringList bb = BBox.split(" ", QString::SkipEmptyParts);
+ if (bb.count() == 4)
+ {
+ x = ScCLocale::toDoubleC(bb[0]);
+ y = ScCLocale::toDoubleC(bb[1]);
+ b = ScCLocale::toDoubleC(bb[2]);
+ h = ScCLocale::toDoubleC(bb[3]);
+ }
+ }
+ importColorsFromFile(fName, CustColors);
+ }
+ return found;
+}
+
+QString AIPlug::removeAIPrefix(QString comment)
+{
+ QString tmp;
+ if (comment.startsWith("%AI"))
+ {
+ int an = comment.indexOf("_");
+ tmp = comment.remove(0, an+1);
+ }
+ else
+ tmp = comment;
+ return tmp;
+}
+
+QString AIPlug::parseColor(QString data)
+{
+ QString ret = CommonStrings::None;
+ if (data.isEmpty())
+ return ret;
+ double c, m, y, k;
+ ScColor tmp;
+ ColorList::Iterator it;
+ ScTextStream Code(&data, QIODevice::ReadOnly);
+ bool found = false;
+ Code >> c;
+ Code >> m;
+ Code >> y;
+ Code >> k;
+ int Cc = qRound(c * 255);
+ int Mc = qRound(m * 255);
+ int Yc = qRound(y * 255);
+ int Kc = qRound(k * 255);
+ int hC, hM, hY, hK;
+ tmp.setColor(Cc, Mc, Yc, Kc);
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelCMYK)
+ {
+ it.value().getCMYK(&hC, &hM, &hY, &hK);
+ if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
+ {
+ ret = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ {
+ tmp.setSpotColor(false);
+ tmp.setRegistrationColor(false);
+ QString namPrefix = "FromAI";
+ m_Doc->PageColors.insert(namPrefix+tmp.name(), tmp);
+// importedColors.append(namPrefix+tmp.name());
+ ret = namPrefix+tmp.name();
+ }
+ return ret;
+}
+
+QString AIPlug::parseColorGray(QString data)
+{
+ QString ret = CommonStrings::None;
+ if (data.isEmpty())
+ return ret;
+ double k;
+ ScColor tmp;
+ ColorList::Iterator it;
+ ScTextStream Code(&data, QIODevice::ReadOnly);
+ bool found = false;
+ Code >> k;
+ int Kc = 255 - qRound(k * 255);
+ int hC, hM, hY, hK;
+ tmp.setColor(0, 0, 0, Kc);
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelCMYK)
+ {
+ it.value().getCMYK(&hC, &hM, &hY, &hK);
+ if ((hC == 0) && (hM == 0) && (hY == 0) && (Kc == hK))
+ {
+ ret = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ {
+ tmp.setSpotColor(false);
+ tmp.setRegistrationColor(false);
+ QString namPrefix = "FromAI";
+ m_Doc->PageColors.insert(namPrefix+tmp.name(), tmp);
+// importedColors.append(namPrefix+tmp.name());
+ ret = namPrefix+tmp.name();
+ }
+ return ret;
+}
+
+QString AIPlug::parseColorRGB(QString data)
+{
+ QString ret = CommonStrings::None;
+ if (data.isEmpty())
+ return ret;
+ double r, g, b;
+ ScColor tmp;
+ ColorList::Iterator it;
+ ScTextStream Code(&data, QIODevice::ReadOnly);
+ bool found = false;
+ Code >> r;
+ Code >> g;
+ Code >> b;
+ int Rc = qRound(r * 255);
+ int Gc = qRound(g * 255);
+ int Bc = qRound(b * 255);
+ int hR, hG, hB;
+ tmp.setColorRGB(Rc, Gc, Bc);
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelRGB)
+ {
+ it.value().getRGB(&hR, &hG, &hB);
+ if ((Rc == hR) && (Gc == hG) && (Bc == hB))
+ {
+ ret = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ {
+ tmp.setSpotColor(false);
+ tmp.setRegistrationColor(false);
+ QString namPrefix = "FromAI";
+ m_Doc->PageColors.insert(namPrefix+tmp.name(), tmp);
+// importedColors.append(namPrefix+tmp.name());
+ ret = namPrefix+tmp.name();
+ }
+ return ret;
+}
+
+QString AIPlug::parseCustomColor(QString data, double &shade)
+{
+ QString ret = CommonStrings::None;
+ if (data.isEmpty())
+ return ret;
+ double c, m, y, k, sh;
+ ScColor tmp;
+ ColorList::Iterator it;
+ ScTextStream Code(&data, QIODevice::ReadOnly);
+ bool found = false;
+ Code >> c;
+ Code >> m;
+ Code >> y;
+ Code >> k;
+ QString tmpS = data;
+ int an = data.indexOf("(");
+ int en = data.lastIndexOf(")");
+ QString FarNam = data.mid(an+1, en-an-1);
+ FarNam.remove("\\");
+ QString FarSha = data.mid(en+1, data.size() - en);
+ ScTextStream Val(&FarSha, QIODevice::ReadOnly);
+ Val >> sh;
+ shade = (1.0 - sh) * 100.0;
+ int Cc = qRound(c * 255);
+ int Mc = qRound(m * 255);
+ int Yc = qRound(y * 255);
+ int Kc = qRound(k * 255);
+ int hC, hM, hY, hK;
+ tmp.setColor(Cc, Mc, Yc, Kc);
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelCMYK)
+ {
+ it.value().getCMYK(&hC, &hM, &hY, &hK);
+ if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
+ {
+ ret = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ {
+ tmp.setSpotColor(true);
+ tmp.setRegistrationColor(false);
+ m_Doc->PageColors.insert(FarNam, tmp);
+// importedColors.append(FarNam);
+ ret = FarNam;
+ }
+ return ret;
+}
+
+QString AIPlug::parseCustomColorX(QString data, double &shade, QString type)
+{
+ QString ret = CommonStrings::None;
+ if (data.isEmpty())
+ return ret;
+ double c, m, y, k, sh, r, g, b;
+ ScColor tmp;
+ ColorList::Iterator it;
+ ScTextStream Code(&data, QIODevice::ReadOnly);
+ bool found = false;
+ if (type == "1")
+ {
+ Code >> r;
+ Code >> g;
+ Code >> b;
+ int Rc = qRound(r * 255);
+ int Gc = qRound(g * 255);
+ int Bc = qRound(b * 255);
+ int hR, hG, hB;
+ tmp.setColorRGB(Rc, Gc, Bc);
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelRGB)
+ {
+ it.value().getRGB(&hR, &hG, &hB);
+ if ((Rc == hR) && (Gc == hG) && (Bc == hB))
+ {
+ ret = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ Code >> c;
+ Code >> m;
+ Code >> y;
+ Code >> k;
+ int Cc = qRound(c * 255);
+ int Mc = qRound(m * 255);
+ int Yc = qRound(y * 255);
+ int Kc = qRound(k * 255);
+ int hC, hM, hY, hK;
+ tmp.setColor(Cc, Mc, Yc, Kc);
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelCMYK)
+ {
+ it.value().getCMYK(&hC, &hM, &hY, &hK);
+ if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
+ {
+ ret = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ }
+ QString tmpS = data;
+ int an = data.indexOf("(");
+ int en = data.lastIndexOf(")");
+ QString FarNam = data.mid(an+1, en-an-1);
+ FarNam.remove("\\");
+ QString FarSha = data.mid(en+1, data.size() - en);
+ ScTextStream Val(&FarSha, QIODevice::ReadOnly);
+ Val >> sh;
+ shade = (1.0 - sh) * 100.0;
+ if (!found)
+ {
+ if (type == "0")
+ tmp.setSpotColor(true);
+ tmp.setRegistrationColor(false);
+ m_Doc->PageColors.insert(FarNam, tmp);
+// importedColors.append(FarNam);
+ ret = FarNam;
+ }
+ return ret;
+}
+
+QStringList AIPlug::getStrings(QString data)
+{
+ QStringList result;
+ result.clear();
+ QChar tmp;
+ QString tmp2 = "";
+ QString tmp3 = "";
+ bool paran = false;
+ bool skip = false;
+ int digitCount = 0;
+ for (int a = 0; a < data.count(); a++)
+ {
+ tmp = data[a];
+ if (skip)
+ {
+ if (paran)
+ {
+ if (tmp.isDigit())
+ {
+ tmp3 += tmp;
+ digitCount++;
+ if (digitCount == 3)
+ {
+ bool ok = false;
+ int code = tmp3.toInt(&ok, 8);
+ if (ok)
+ tmp2 += QChar(code);
+ digitCount = 0;
+ tmp3 = "";
+ skip = false;
+ }
+ }
+ else
+ {
+ if (tmp == 'r')
+ tmp = SpecialChars::PARSEP;
+ tmp2 += tmp;
+ skip = false;
+ }
+ }
+ continue;
+ }
+ if (tmp == '(')
+ {
+ paran = true;
+ continue;
+ }
+ if (tmp == ')')
+ {
+ paran = false;
+ result.append(tmp2);
+ tmp2 = "";
+ continue;
+ }
+ if (tmp == '\\')
+ {
+ skip = true;
+ continue;
+ }
+ if (paran)
+ tmp2 += tmp;
+ }
+ return result;
+}
+
+void AIPlug::getCommands(QString data, QStringList &commands)
+{
+ QString tmp;
+ QString tmp2;
+ QString tmp3;
+ bool paran = false;
+ bool arra = false;
+ bool skip = false;
+ for (int a = 0; a < data.count(); a++)
+ {
+ tmp = data[a];
+ if (skip)
+ {
+ tmp2 += tmp;
+ skip = false;
+ continue;
+ }
+ if (tmp == "(")
+ {
+ paran = true;
+ tmp2 += tmp;
+ continue;
+ }
+ if (tmp == ")")
+ {
+ paran = false;
+ tmp2 += tmp;
+ continue;
+ }
+ if (tmp == "[")
+ {
+ arra = true;
+ tmp2 += tmp;
+ continue;
+ }
+ if (tmp == "]")
+ {
+ arra = false;
+ tmp2 += tmp;
+ continue;
+ }
+// if (tmp == "\\")
+// {
+// skip = true;
+// continue;
+// }
+ if (!paran)
+ {
+ if (tmp == " ")
+ {
+ tmp3 += " " + tmp2;
+ if (commandList.contains(tmp2))
+ {
+ commands.append(tmp3);
+ tmp3 = "";
+ }
+ tmp2 = "";
+ continue;
+ }
+ }
+ tmp2 += tmp;
+ }
+ if (!tmp2.isEmpty())
+ {
+ tmp3 += " " + tmp2;
+ commands.append(tmp3);
+ }
+}
+
+void AIPlug::processData(QString data)
+{
+ double x, y, x1, y1, x2, y2;
+ int z, tmpInt;
+ PageItem *ite;
+ QString command = "";
+ QString Cdata = "";
+ QStringList da;
+ getCommands(data, da);
+ for (int a = 0; a < da.count(); a++)
+ {
+ Cdata = da[a];
+ if (((Cdata.startsWith("%")) || (Cdata.startsWith(" %"))) && (!meshMode))
+ continue;
+ QStringList da2 = Cdata.split(" ", QString::SkipEmptyParts);
+ if (da2.count() == 0)
+ return;
+ command = da2[da2.count()-1];
+/* Start Path construction commands */
+ if (command == "m")
+ {
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> x >> y;
+ Coords.svgMoveTo(x - docX, docHeight - (y - docY));
+ currentPoint = FPoint(x - docX, docHeight - (y - docY));
+ }
+ else if ((command == "L") || (command == "l"))
+ {
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> x >> y;
+ Coords.svgLineTo(x - docX, docHeight - (y - docY));
+ currentPoint = FPoint(x - docX, docHeight - (y - docY));
+ }
+ else if ((command == "C") || (command == "c"))
+ {
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> x >> y >> x1 >> y1 >> x2 >> y2;
+ Coords.svgCurveToCubic(x - docX, docHeight - (y - docY),
+ x1 - docX, docHeight - (y1 - docY),
+ x2 - docX, docHeight - (y2 - docY));
+ currentPoint = FPoint(x2 - docX, docHeight - (y2 - docY));
+ }
+ else if ((command == "Y") || (command == "y"))
+ {
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> x1 >> y1 >> x2 >> y2;
+ Coords.svgCurveToCubic(currentPoint.x(), currentPoint.y(),
+ x1 - docX, docHeight - (y1 - docY),
+ x2 - docX, docHeight - (y2 - docY));
+ currentPoint = FPoint(x2 - docX, docHeight - (y2 - docY));
+ }
+ else if ((command == "V") || (command == "v"))
+ {
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> x >> y >> x2 >> y2;
+ Coords.svgCurveToCubic(x - docX, docHeight - (y - docY),
+ currentPoint.x(), currentPoint.y(),
+ x2 - docX, docHeight - (y2 - docY));
+ currentPoint = FPoint(x2 - docX, docHeight - (y2 - docY));
+ }
+/* End Path construction commands */
+/* Start Object creation commands */
+ else if ((command == "b") || (command == "B") || (command == "f") || (command == "F") || (command == "s") || (command == "S"))
+ {
+ if (Coords.size() > 3)
+ {
+ if ((!WasU) || ((WasU) && (FirstU)))
+ {
+ if ((command == "B") || (command == "F") || (command == "S"))
+ {
+ if (command == "F")
+ z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CommonStrings::None, true);
+ else if (command == "B")
+ z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ else
+ z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CommonStrings::None, CurrColorStroke, true);
+ }
+ else
+ {
+ if (command == "f")
+ z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CommonStrings::None, true);
+ else if (command == "b")
+ z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ else
+ z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CommonStrings::None, CurrColorStroke, true);
+ }
+ ite = m_Doc->Items->at(z);
+ ite->PoLine = Coords.copy();
+ ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ ite->ClipEdited = true;
+ ite->FrameType = 3;
+ ite->setFillShade(CurrFillShade);
+ ite->setLineShade(CurrStrokeShade);
+ ite->setFillEvenOdd(fillRule);
+ ite->setFillTransparency(1.0 - Opacity);
+ ite->setLineTransparency(1.0 - Opacity);
+ // ite->setFillBlendmode(blendMode);
+ // ite->setLineBlendmode(blendMode);
+ if (!currentPatternName.isEmpty())
+ {
+ ite->setPattern(currentPatternName);
+ ite->setPatternTransform(currentPatternXScale * 100, currentPatternYScale * 100, currentPatternX, currentPatternY, currentPatternRotation);
+ ite->GrType = 8;
+ currentPatternName = "";
+ }
+ ite->setLineEnd(CapStyle);
+ ite->setLineJoin(JoinStyle);
+ if (importerFlags & LoadSavePlugin::lfCreateDoc)
+ ite->setLocked(itemLocked);
+ if (!WasU)
+ {
+ FPoint wh = getMaxClipF(&ite->PoLine);
+ ite->setWidthHeight(wh.x(),wh.y());
+ ite->setTextFlowMode(PageItem::TextFlowDisabled);
+ m_Doc->AdjustItemSize(ite);
+ }
+ if (patternMode)
+ PatternElements.append(ite);
+ else
+ Elements.append(ite);
+ if (groupStack.count() != 0)
+ groupStack.top().append(ite);
+
+ }
+ else
+ {
+ ite = m_Doc->Items->at(m_Doc->Items->count()-1);
+ ite->PoLine.setMarker();
+ Coords.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ ite->PoLine.putPoints(ite->PoLine.size(), Coords.size(), Coords);
+ }
+ Coords.resize(0);
+ Coords.svgInit();
+ FirstU = false;
+ itemRendered = true;
+ }
+ }
+ else if (command == "*u")
+ {
+ FirstU = true;
+ WasU = true;
+ }
+ else if (command == "*U")
+ {
+ WasU = false;
+ ite = m_Doc->Items->at(m_Doc->Items->count()-1);
+ FPoint wh = getMaxClipF(&ite->PoLine);
+ ite->setWidthHeight(wh.x(),wh.y());
+ m_Doc->AdjustItemSize(ite);
+ }
+ else if ((command == "u") || (command == "q"))
+ {
+ QList<PageItem*> gElements;
+ groupStack.push(gElements);
+ }
+ else if ((command == "U") || (command == "Q"))
+ {
+ if (groupStack.count() != 0)
+ {
+ QList<PageItem*> gElements = groupStack.pop();
+ tmpSel->clear();
+ if (gElements.count() > 0)
+ {
+ for (int dre = 0; dre < gElements.count(); ++dre)
+ {
+ tmpSel->addItem(gElements.at(dre), true);
+ }
+ m_Doc->itemSelection_GroupObjects(false, false, tmpSel);
+ ite = tmpSel->itemAt(0);
+ if ((clipCoords.size() > 4) && (command == "Q"))
+ {
+ ite = tmpSel->itemAt(0);
+ clipCoords.translate(m_Doc->currentPage()->xOffset()-ite->xPos(), m_Doc->currentPage()->yOffset()-ite->yPos());
+ ite->PoLine = clipCoords.copy();
+ ite->PoLine.translate(baseX, baseY);
+ }
+ if (patternMode)
+ PatternElements.append(ite);
+ else
+ Elements.append(ite);
+ }
+ if (groupStack.count() != 0)
+ {
+ for (int as = 0; as < tmpSel->count(); ++as)
+ {
+ groupStack.top().append(tmpSel->itemAt(as));
+ }
+ }
+ tmpSel->clear();
+ }
+ if (command == "Q")
+ {
+ clipCoords.resize(0);
+ clipCoords.svgInit();
+ }
+ }
+ else if (command == "W")
+ {
+ if (clipCoords.size() > 0)
+ clipCoords.setMarker();
+ clipCoords.putPoints(clipCoords.size(), Coords.size(), Coords);
+ }
+/* End Object construction commands */
+/* Start Graphics state commands */
+ else if (command == "A")
+ {
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> tmpInt;
+ if (tmpInt == 1)
+ itemLocked = true;
+ else
+ itemLocked = false;
+ }
+ else if (command == "w")
+ {
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> LineW;
+ }
+ else if (command == "j")
+ {
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> tmpInt;
+ if (tmpInt == 0)
+ JoinStyle = Qt::MiterJoin;
+ else if (tmpInt == 1)
+ JoinStyle = Qt::RoundJoin;
+ else if (tmpInt == 1)
+ JoinStyle = Qt::BevelJoin;
+ }
+ else if (command == "J")
+ {
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> tmpInt;
+ if (tmpInt == 0)
+ CapStyle = Qt::FlatCap;
+ else if (tmpInt == 1)
+ CapStyle = Qt::RoundCap;
+ else if (tmpInt == 1)
+ CapStyle = Qt::SquareCap;
+ }
+ /* undocumented Command Xy
+ - has up to 5 Parameters
+ - first Parameter might be the Blendmode
+ - second Parameter is the Opacity
+ */
+ else if (command == "Xy")
+ {
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> blendMode >> Opacity;
+ }
+ else if (command == "XR")
+ {
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> tmpInt;
+ if (tmpInt == 1)
+ fillRule = true;
+ else
+ fillRule = false;
+ }
+ else if (command == "Bb")
+ {
+ gradientMode = true;
+ wasBC = false;
+ itemRendered = false;
+ startMatrix = QTransform();
+ endMatrix = QTransform();
+ }
+ else if (command == "Xm")
+ {
+ ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
+ double m1, m2, m3, m4, m5, m6;
+ gVals >> m1 >> m2 >> m3 >> m4 >> m5 >> m6;
+ startMatrix.translate(m5, -m6);
+ endMatrix.scale(m1, m4);
+ wasBC = true;
+ }
+ else if (command == "Bm")
+ {
+ if (m_gradients[currentGradientName].type() == 1)
+ {
+ ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
+ double m1, m2, m3, m4, m5, m6;
+ gVals >> m1 >> m2 >> m3 >> m4 >> m5 >> m6;
+ startMatrix.translate(m5, -m6);
+// endMatrix.scale(m1, m4);
+ endMatrix *= QTransform(m1, m2, m3, m4, 0, 0);
+// endMatrix = QTransform(m1, m2, m3, m4, m5, m6);
+ wasBC = true;
+ }
+ }
+ else if (command == "BB")
+ {
+ if (itemRendered)
+ {
+ gradientMode = false;
+ ite = m_Doc->Items->at(m_Doc->Items->count()-1);
+ ite->fill_gradient = m_gradients[currentGradientName];
+ if (ite->fill_gradient.type() == 0)
+ ite->GrType = 6;
+ else
+ ite->GrType = 7;
+ QTransform m1;
+ m1.translate(currentGradientOrigin.x() - ite->xPos(), currentGradientOrigin.y() - ite->yPos());
+ m1.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ m1.rotate(-currentGradientAngle);
+ ite->GrStartX = currentGradientOrigin.x() - ite->xPos() + m_Doc->currentPage()->xOffset();
+ ite->GrStartY = currentGradientOrigin.y() - ite->yPos() + m_Doc->currentPage()->yOffset();
+ QPointF target = m1.map(QPointF(currentGradientLenght, 0.0));
+ ite->GrEndX = target.x();
+ ite->GrEndY = target.y();
+ if (wasBC)
+ {
+ QPointF newS = startMatrix.map(QPointF(ite->GrStartX, ite->GrStartY));
+ ite->GrStartX = newS.x();
+ ite->GrStartY = newS.y();
+ QTransform m2;
+// m2.translate(ite->GrStartX, ite->GrStartY);
+ m2.rotate(-currentGradientAngle);
+ m2 *= endMatrix;
+ QPointF target = m2.map(QPointF(currentGradientLenght, 0.0));
+ ite->GrEndX = target.x();
+ ite->GrEndY = target.y();
+ }
+ }
+ wasBC = false;
+ currentGradientMatrix = QTransform();
+ currentGradientOrigin = QPointF(0.0, 0.0);
+ currentGradientAngle = 0.0;
+ currentGradientLenght = 1.0;
+ itemRendered = false;
+ }
+ else if (command == "Bg")
+ {
+ int an = Cdata.indexOf("(");
+ int en = Cdata.lastIndexOf(")");
+ currentGradientName = Cdata.mid(an+1, en-an-1);
+ currentGradientName.remove("\\");
+ QString tmpS = Cdata.mid(en+1, Cdata.size() - en);
+ ScTextStream gVals(&tmpS, QIODevice::ReadOnly);
+ double xOrig, yOrig, m1, m2, m3, m4, m5, m6;
+ gVals >> xOrig >> yOrig >> currentGradientAngle >> currentGradientLenght >> m1 >> m2 >> m3 >> m4 >> m5 >> m6;
+ currentGradientOrigin = QPointF(xOrig - docX, docHeight - (yOrig - docY));
+ currentGradientMatrix = QTransform(m1, m2, m3, m4, m5, m6);
+ }
+/* End Graphics state commands */
+/* Start Color commands */
+ else if ((command == "G") || (command == "g"))
+ {
+ if (command == "G")
+ CurrColorStroke = parseColorGray(Cdata);
+ else
+ CurrColorFill = parseColorGray(Cdata);
+ }
+ else if ((command == "K") || (command == "k"))
+ {
+ if (command == "K")
+ CurrColorStroke = parseColor(Cdata);
+ else
+ CurrColorFill = parseColor(Cdata);
+ }
+ else if ((command == "XA") || (command == "Xa"))
+ {
+ QString Xdata = da2[da2.count()-4] + " " + da2[da2.count()-3] + " " + da2[da2.count()-2];
+ if (command == "XA")
+ CurrColorStroke = parseColorRGB(Xdata);
+ else
+ CurrColorFill = parseColorRGB(Xdata);
+ }
+ else if ((command == "XX") || (command == "Xx") || (command == "Xk"))
+ {
+ if (command == "XX")
+ CurrColorStroke = parseCustomColorX(Cdata, CurrStrokeShade, da2[da2.count()-2]);
+ else
+ CurrColorFill = parseCustomColorX(Cdata, CurrFillShade, da2[da2.count()-2]);
+ }
+ else if ((command == "X") || (command == "x"))
+ {
+ if (command == "X")
+ CurrColorStroke = parseCustomColor(Cdata, CurrStrokeShade);
+ else
+ CurrColorFill = parseCustomColor(Cdata, CurrFillShade);
+ }
+ else if (command == "p")
+ {
+ int an = Cdata.indexOf("(");
+ int en = Cdata.lastIndexOf(")");
+ currentPatternName = Cdata.mid(an+1, en-an-1);
+ currentPatternName.remove("\\");
+ currentPatternName = currentPatternName.trimmed().simplified().replace(" ", "_");
+ QString tmpS = Cdata.mid(en+1, Cdata.size() - en);
+ ScTextStream gVals(&tmpS, QIODevice::ReadOnly);
+ gVals >> currentPatternX >> currentPatternY >> currentPatternXScale >> currentPatternYScale >> currentPatternRotation;
+ }
+ else if (command == "X!")
+ {
+ if (Cdata.contains("/Mesh"))
+ {
+ QList<PageItem*> gElements;
+ groupStack.push(gElements);
+ meshMode = true;
+ meshNodeCounter = 0;
+ accumColorC = 0.0;
+ accumColorM = 0.0;
+ accumColorY = 0.0;
+ accumColorK = 0.0;
+ meshColorMode = 0;
+ // meshBoundingPath = QPainterPath();
+ }
+ if (Cdata.contains("/End"))
+ {
+ meshMode = false;
+ if (groupStack.count() != 0)
+ {
+ QList<PageItem*> gElements = groupStack.pop();
+ tmpSel->clear();
+ if (gElements.count() > 0)
+ {
+ for (int dre = 0; dre < gElements.count(); ++dre)
+ {
+ tmpSel->addItem(gElements.at(dre), true);
+ }
+ m_Doc->itemSelection_GroupObjects(false, false, tmpSel);
+ ite = tmpSel->itemAt(0);
+ /* if (!meshBoundingPath.isEmpty())
+ {
+ ite = tmpSel->itemAt(0);
+ clipCoords.fromQPainterPath(meshBoundingPath);
+ clipCoords.translate(m_Doc->currentPage()->xOffset()-ite->xPos(), m_Doc->currentPage()->yOffset()-ite->yPos());
+ ite->PoLine = clipCoords.copy();
+ ite->PoLine.translate(baseX, baseY);
+ } */
+ if (patternMode)
+ PatternElements.append(ite);
+ else
+ Elements.append(ite);
+ }
+ if (groupStack.count() != 0)
+ {
+ for (int as = 0; as < tmpSel->count(); ++as)
+ {
+ groupStack.top().append(tmpSel->itemAt(as));
+ }
+ }
+ tmpSel->clear();
+ }
+ }
+ }
+ else if (command == "X#")
+ {
+ int an = Cdata.indexOf("_");
+ QString cmdLine = Cdata.remove(0, an+1);
+ an = cmdLine.lastIndexOf("/");
+ QString tmpS = cmdLine.mid(an+1, Cdata.size());
+ ScTextStream mVals(&tmpS, QIODevice::ReadOnly);
+ QString mKey;
+ mVals >> mKey;
+ if (mKey == "Size")
+ {
+ int ans = cmdLine.indexOf("[");
+ int ens = cmdLine.lastIndexOf("]");
+ QString sizeVals = cmdLine.mid(ans+1, ens-ans-1);
+ ScTextStream mVals2(&sizeVals, QIODevice::ReadOnly);
+ mVals2 >> meshXSize >> meshYSize;
+ }
+ if (mKey == "P")
+ {
+ int ans = cmdLine.indexOf("[");
+ int ens = cmdLine.lastIndexOf("]");
+ QString posVals = cmdLine.mid(ans+1, ens-ans-1);
+ ScTextStream mVals3(&posVals, QIODevice::ReadOnly);
+ mVals3 >> currentMeshXPos >> currentMeshYPos;
+ accumColorC = 0.0;
+ accumColorM = 0.0;
+ accumColorY = 0.0;
+ accumColorK = 0.0;
+ }
+ if (mKey == "CS")
+ {
+ if (Cdata.contains("CMYK"))
+ meshColorMode = 0;
+ else if (Cdata.contains("RGB"))
+ meshColorMode = 1;
+ }
+ if (mKey == "E")
+ {
+ ScColor tmpColor;
+ ColorList::Iterator it;
+ int Cc = qRound((accumColorC / 4.0) * 255);
+ int Mc = qRound((accumColorM / 4.0) * 255);
+ int Yc = qRound((accumColorY / 4.0) * 255);
+ int Kc = qRound((accumColorK / 4.0) * 255);
+ int hC, hM, hY, hK;
+ bool found = false;
+ if (meshColorMode == 0)
+ {
+ tmpColor.setColor(Cc, Mc, Yc, Kc);
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelCMYK)
+ {
+ it.value().getCMYK(&hC, &hM, &hY, &hK);
+ if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
+ {
+ CurrColorFill = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ tmpColor.setColorRGB(Cc, Mc, Yc);
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelRGB)
+ {
+ it.value().getRGB(&hC, &hM, &hY);
+ if ((Cc == hC) && (Mc == hM) && (Yc == hY))
+ {
+ CurrColorFill = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ }
+ if (!found)
+ {
+ tmpColor.setSpotColor(false);
+ tmpColor.setRegistrationColor(false);
+ QString namPrefix = "FromAI";
+ m_Doc->PageColors.insert(namPrefix+tmpColor.name(), tmpColor);
+ CurrColorFill = namPrefix+tmpColor.name();
+ }
+ meshNodeCounter = 0;
+ Coords.resize(0);
+ Coords.svgInit();
+ Coords.svgMoveTo(meshNode1PointX, meshNode1PointY);
+ Coords.svgCurveToCubic(meshNode1Control2X, meshNode1Control2Y, meshNode2Control1X, meshNode2Control1Y, meshNode2PointX, meshNode2PointY);
+ Coords.svgCurveToCubic(meshNode2Control2X, meshNode2Control2Y, meshNode3Control1X, meshNode3Control1Y, meshNode3PointX, meshNode3PointY);
+ Coords.svgCurveToCubic(meshNode3Control2X, meshNode3Control2Y, meshNode4Control1X, meshNode4Control1Y, meshNode4PointX, meshNode4PointY);
+ Coords.svgCurveToCubic(meshNode4Control2X, meshNode4Control2Y, meshNode1Control1X, meshNode1Control1Y, meshNode1PointX, meshNode1PointY);
+ z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, 0, CurrColorFill, CurrColorFill, true);
+ ite = m_Doc->Items->at(z);
+ ite->PoLine = Coords.copy();
+ // QPainterPath tmpPath = Coords.toQPainterPath(true);
+ // meshBoundingPath = meshBoundingPath.united(tmpPath);
+ ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ ite->ClipEdited = true;
+ ite->FrameType = 3;
+ ite->setFillShade(CurrFillShade);
+ ite->setLineShade(CurrFillShade);
+ ite->setFillEvenOdd(fillRule);
+ ite->setFillTransparency(1.0 - Opacity);
+ ite->setLineTransparency(1.0 - Opacity);
+ ite->setLineEnd(CapStyle);
+ ite->setLineJoin(JoinStyle);
+ if (importerFlags & LoadSavePlugin::lfCreateDoc)
+ ite->setLocked(itemLocked);
+ FPoint wh = getMaxClipF(&ite->PoLine);
+ ite->setWidthHeight(wh.x(),wh.y());
+ ite->setTextFlowMode(PageItem::TextFlowDisabled);
+ m_Doc->AdjustItemSize(ite);
+ if (patternMode)
+ PatternElements.append(ite);
+ else
+ Elements.append(ite);
+ if (groupStack.count() != 0)
+ groupStack.top().append(ite);
+ Coords.resize(0);
+ Coords.svgInit();
+ }
+ if (mKey == "N")
+ {
+ double cVal, mVal, yVal, kVal, coorX1, coorY1, coorX2, coorY2, coorX3, coorY3;
+ int dummy;
+ meshNodeCounter++;
+ int ans = cmdLine.indexOf("[");
+ int ens = cmdLine.lastIndexOf("]");
+ QString nodeVals = cmdLine.mid(ans+1, ens-ans-1);
+ ScTextStream mVals4(&nodeVals, QIODevice::ReadOnly);
+ kVal = 0.0;
+ if (meshColorMode == 0)
+ mVals4 >> cVal >> mVal >> yVal >> kVal >> coorX1 >> coorY1 >> coorX2 >> coorY2 >> dummy >> coorX3 >> coorY3;
+ else
+ mVals4 >> cVal >> mVal >> yVal >> coorX1 >> coorY1 >> coorX2 >> coorY2 >> dummy >> coorX3 >> coorY3;
+ accumColorC += cVal;
+ accumColorM += mVal;
+ accumColorY += yVal;
+ accumColorK += kVal;
+ if (meshNodeCounter == 1)
+ {
+ meshNode1PointX = coorX1 - docX;
+ meshNode1PointY = docHeight - (coorY1 - docY);
+ meshNode1Control2X = coorX2 - docX;
+ meshNode1Control2Y = docHeight - (coorY2 - docY);
+ meshNode1Control1X = coorX3 - docX;
+ meshNode1Control1Y = docHeight - (coorY3 - docY);
+ }
+ if (meshNodeCounter == 2)
+ {
+ meshNode2PointX = coorX1 - docX;
+ meshNode2PointY = docHeight - (coorY1 - docY);
+ meshNode2Control2X = coorX2 - docX;
+ meshNode2Control2Y = docHeight - (coorY2 - docY);
+ meshNode2Control1X = coorX3 - docX;
+ meshNode2Control1Y = docHeight - (coorY3 - docY);
+ }
+ if (meshNodeCounter == 3)
+ {
+ meshNode3PointX = coorX1 - docX;
+ meshNode3PointY = docHeight - (coorY1 - docY);
+ meshNode3Control2X = coorX2 - docX;
+ meshNode3Control2Y = docHeight - (coorY2 - docY);
+ meshNode3Control1X = coorX3 - docX;
+ meshNode3Control1Y = docHeight - (coorY3 - docY);
+ }
+ if (meshNodeCounter == 4)
+ {
+ meshNode4PointX = coorX1 - docX;
+ meshNode4PointY = docHeight - (coorY1 - docY);
+ meshNode4Control2X = coorX2 - docX;
+ meshNode4Control2Y = docHeight - (coorY2 - docY);
+ meshNode4Control1X = coorX3 - docX;
+ meshNode4Control1Y = docHeight - (coorY3 - docY);
+ }
+ }
+ }
+/* End Color commands */
+/* Start Layer commands */
+ else if (command == "Lb")
+ {
+ if (importerFlags & LoadSavePlugin::lfCreateDoc)
+ {
+ int visible, preview, enabled, printing, dummy, rc, gc, bc;
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> visible >> preview >> enabled >> printing >> dummy >> dummy >> dummy >> rc >> gc >> bc;
+ if (!firstLayer)
+ currentLayer = m_Doc->addLayer("Layer", true);
+ m_Doc->setLayerVisible(currentLayer, static_cast<bool>(visible));
+ m_Doc->setLayerOutline(currentLayer, static_cast<bool>(!preview));
+ m_Doc->setLayerLocked(currentLayer, static_cast<bool>(!enabled));
+ m_Doc->setLayerPrintable(currentLayer, static_cast<bool>(printing));
+ m_Doc->setLayerMarker(currentLayer, QColor(rc, gc, bc));
+ firstLayer = false;
+ }
+ Coords.resize(0);
+ Coords.svgInit();
+ }
+ else if (command == "LB")
+ {
+ Coords.resize(0);
+ Coords.svgInit();
+ }
+ else if (command == "Ln")
+ {
+ if (importerFlags & LoadSavePlugin::lfCreateDoc)
+ {
+ int an = Cdata.indexOf("(");
+ int en = Cdata.lastIndexOf(")");
+ QString LayerNam = Cdata.mid(an+1, en-an-1);
+ LayerNam.remove("\\");
+ m_Doc->changeLayerName(currentLayer, LayerNam);
+ }
+ }
+/* End Layer commands */
+/* Start Text commands */
+ else if (command == "To")
+ {
+ ScTextStream ts2(&Cdata, QIODevice::ReadOnly);
+ ts2 >> textMode;
+ textData.clear();
+ textMatrix = QTransform();
+ maxWidth = 0;
+ tempW = 0;
+ maxHeight = 0;
+ textKern = 0;
+ startCurrentTextRange = 0;
+ endCurrentTextRange = 0;
+ textScaleH = 1000;
+ textScaleV = 1000;
+ }
+ else if (command == "Tp")
+ {
+ ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
+ double m1, m2, m3, m4, m5, m6;
+ gVals >> m1 >> m2 >> m3 >> m4 >> m5 >> m6;
+ textMatrix = QTransform(m1, m2, m3, m4, m5, m6);
+ }
+ else if (command == "Tx") // || (command == "TX"))
+ {
+ QStringList res = getStrings(Cdata);
+ if (res.count() > 0)
+ {
+ QString tex = res[0];
+ double tempH = 0;
+ startCurrentTextRange = textData.length();
+ for (int tt = 0; tt < tex.length(); ++tt)
+ {
+ CharStyle nstyle;
+ QString ch = tex.mid(tt,1);
+ nstyle.setFont((*m_Doc->AllFonts)[textFont]);
+ nstyle.setFontSize(textSize);
+ nstyle.setFillColor(CurrColorFill);
+ nstyle.setTracking(textKern);
+ nstyle.setFillShade(100);
+ nstyle.setStrokeColor(CurrColorStroke);
+ nstyle.setStrokeShade(100);
+ nstyle.setScaleH(textScaleH);
+ nstyle.setScaleV(textScaleV);
+ nstyle.setBaselineOffset(0);
+ nstyle.setShadowXOffset(50);
+ nstyle.setShadowYOffset(-50);
+ nstyle.setOutlineWidth(10);
+ nstyle.setUnderlineOffset(-1);
+ nstyle.setUnderlineWidth(-1);
+ nstyle.setStrikethruOffset(-1);
+ nstyle.setStrikethruWidth(-1);
+ nstyle.setFeatures(StyleFlag(ScStyle_Default).featureList());
+ int pot = textData.length();
+ textData.insertChars(pot, ch);
+ textData.applyCharStyle(pot, 1, nstyle);
+ tempW += nstyle.font().realCharWidth(ch[0], nstyle.fontSize() / 10.0)+1;
+ tempH = qMax(tempH, nstyle.font().height(nstyle.fontSize() / 10.0) + 2.0);
+ maxWidth = qMax(tempW, maxWidth);
+ maxHeight = qMax(tempH, maxHeight);
+ if ((ch == SpecialChars::PARSEP) || (ch == SpecialChars::LINEBREAK))
+ {
+ maxHeight += nstyle.font().height(nstyle.fontSize() / 10.0);
+ tempW = 0;
+ }
+ endCurrentTextRange = pot;
+ }
+ }
+ }
+ else if (command == "Tk")
+ {
+ int flag;
+ double val;
+ ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
+ gVals >> flag >> val;
+ if (flag == 1)
+ val = 0;
+ double oldval = textData.charStyle(startCurrentTextRange).tracking();
+ CharStyle nstyle = textData.charStyle(startCurrentTextRange);
+ nstyle.setTracking(oldval + val);
+ textData.applyCharStyle(startCurrentTextRange, 1, nstyle);
+ }
+ else if (command == "Tc")
+ {
+ ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
+ gVals >> textKern;
+ textKern *= 100.0;
+ }
+ else if (command == "Tz")
+ {
+ ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
+ gVals >> textScaleH >> textScaleV;
+ textScaleH *= 10.0;
+ textScaleV *= 10.0;
+ }
+ else if (command == "T*")
+ {
+ CharStyle nstyle;
+ QString ch = SpecialChars::LINEBREAK;
+ nstyle.setFont((*m_Doc->AllFonts)[textFont]);
+ nstyle.setFontSize(textSize);
+ nstyle.setFillColor(CurrColorFill);
+ nstyle.setTracking(textKern);
+ nstyle.setFillShade(100);
+ nstyle.setStrokeColor(CurrColorStroke);
+ nstyle.setStrokeShade(100);
+ nstyle.setScaleH(textScaleH);
+ nstyle.setScaleV(textScaleV);
+ nstyle.setBaselineOffset(0);
+ nstyle.setShadowXOffset(50);
+ nstyle.setShadowYOffset(-50);
+ nstyle.setOutlineWidth(10);
+ nstyle.setUnderlineOffset(-1);
+ nstyle.setUnderlineWidth(-1);
+ nstyle.setStrikethruOffset(-1);
+ nstyle.setStrikethruWidth(-1);
+ nstyle.setFeatures(StyleFlag(ScStyle_Default).featureList());
+ int pot = textData.length();
+ textData.insertChars(pot, ch);
+ textData.applyCharStyle(pot, 1, nstyle);
+ maxHeight += nstyle.font().height(nstyle.fontSize() / 10.0) + 2.0;
+ tempW = 0;
+ }
+ else if (command == "Tf")
+ {
+ ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
+ gVals >> textFont >> textSize;
+ textFont.remove(0, 2);
+ QString family = textFont;
+ QString ret = "";
+ family.replace( QRegExp( "'" ) , QChar( ' ' ) );
+ textFont = m_Doc->toolSettings.defFont;
+ bool found = false;
+ SCFontsIterator it(PrefsManager::instance()->appPrefs.AvailFonts);
+ for ( ; it.hasNext(); it.next())
+ {
+ QString fam;
+ QString fn = it.current().scName();
+ int pos = fn.indexOf(" ");
+ fam = fn.left(pos);
+ if (fam == family)
+ {
+ found = true;
+ ret = fn;
+ }
+ }
+ if (found)
+ textFont = family;
+ else
+ {
+ if (!PrefsManager::instance()->appPrefs.GFontSub.contains(family))
+ {
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ MissingFont *dia = new MissingFont(0, family, m_Doc);
+ dia->exec();
+ QString tmpf = dia->getReplacementFont();
+ delete dia;
+ qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
+ PrefsManager::instance()->appPrefs.GFontSub[family] = tmpf;
+ }
+ else
+ textFont = PrefsManager::instance()->appPrefs.GFontSub[family];
+ }
+ textSize *= 10.0;
+ }
+ else if (command == "TO")
+ {
+ if (textData.length() > 0)
+ {
+ if (!((textData.length() == 1) && (textData.text(0) == SpecialChars::PARSEP)))
+ {
+ QPointF pos = QPointF(textMatrix.dx(), textMatrix.dy());
+ pos += QPointF(m_Doc->currentPage()->xOffset(), -m_Doc->currentPage()->yOffset());
+ pos += QPointF(0.0, textSize / 10.0 + 2.0);
+ z = m_Doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, pos.x() - docX, docHeight - (pos.y() - docY), 10, 10, 0, CommonStrings::None, CommonStrings::None, true);
+ ite = m_Doc->Items->at(z);
+ ite->setTextToFrameDist(0.0, 0.0, 0.0, 0.0);
+ ite->itemText.append(textData);
+ double xpos = ite->xPos();
+ double ypos = ite->yPos();
+ ite->setWidthHeight(qMax(ite->width(), maxWidth), qMax(ite->height(), maxHeight));
+ double xoffset = 0.0, yoffset = 0.0;
+ double rotation = getRotationFromMatrix(textMatrix, 0.0);
+ if (rotation != 0.0)
+ {
+ double temp = textSize / 10.0 + 2.0;
+ xoffset = sin(rotation) * temp;
+ yoffset = cos(rotation) * temp;
+ }
+ ite->setXPos(xpos + xoffset);
+ ite->setYPos(ypos + yoffset);
+ ite->setRotation(rotation * 180 / M_PI);
+ ite->SetRectFrame();
+ m_Doc->setRedrawBounding(ite);
+ ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
+ ite->setTextFlowMode(PageItem::TextFlowDisabled);
+ ite->setFillShade(CurrFillShade);
+ ite->setLineShade(CurrStrokeShade);
+ ite->setFillEvenOdd(fillRule);
+ ite->setFillTransparency(1.0 - Opacity);
+ ite->setLineTransparency(1.0 - Opacity);
+ ite->setLineEnd(CapStyle);
+ ite->setLineJoin(JoinStyle);
+ if (importerFlags & LoadSavePlugin::lfCreateDoc)
+ ite->setLocked(itemLocked);
+ if (patternMode)
+ PatternElements.append(ite);
+ else
+ Elements.append(ite);
+ if (groupStack.count() != 0)
+ groupStack.top().append(ite);
+ }
+ }
+ }
+/* End Text commands */
+/* Start special Commands */
+ else if (command == "*")
+ {
+ Coords.resize(0);
+ Coords.svgInit();
+ }
+ else if ((command == "N") || (command == "n"))
+ {
+ Coords.resize(0);
+ Coords.svgInit();
+ }
+ else if (command == "[")
+ {
+ Coords.resize(0);
+ Coords.svgInit();
+ int an = Cdata.indexOf("(");
+ int en = Cdata.lastIndexOf(")");
+ if ((an != -1) && (en != -1))
+ {
+ patternMode = true;
+ currentPatternDefName = Cdata.mid(an+1, en-an-1);
+ currentPatternDefName.remove("\\");
+ currentPatternDefName = currentPatternDefName.trimmed().simplified().replace(" ", "_");
+ QString tmpS = Cdata.mid(en+1, Cdata.size() - en);
+ ScTextStream gVals(&tmpS, QIODevice::ReadOnly);
+ gVals >> patternX1 >> patternY1 >> patternX2 >> patternY2;
+ }
+ }
+/* End special Commands */
+/* Skip everything else */
+// else
+// qDebug(command);
+ }
+}
+
+void AIPlug::processGradientData(QString data)
+{
+ QString command = "";
+ QString Cdata = "";
+ QStringList da;
+ getCommands(data, da);
+ for (int a = 0; a < da.count(); a++)
+ {
+ Cdata = da[a];
+ QStringList da2 = Cdata.split(" ", QString::SkipEmptyParts);
+ command = da2[da2.count()-1];
+ if (command == "Bd")
+ {
+ QString tmpS = Cdata;
+ int an = Cdata.indexOf("(");
+ int en = Cdata.lastIndexOf(")");
+ currentGradientName = Cdata.mid(an+1, en-an-1);
+ currentGradientName.remove("\\");
+ if (da2[da2.count()-3] == "0")
+ currentGradient = VGradient(VGradient::linear);
+ else
+ currentGradient = VGradient(VGradient::radial);
+ currentGradient.clearStops();
+ }
+ else if ((command == "%_Bs") || (command == "%_BS"))
+ {
+ QString stopName = "";
+ double stop = ScCLocale::toDoubleC(da2[da2.count()-2]) / 100.0;
+ double colorShade = 100.0;
+ int colortype = da2[da2.count()-4].toInt();
+ if (colortype == 0)
+ {
+ stopName = parseColorGray(Cdata);
+ const ScColor& gradC = m_Doc->PageColors[stopName];
+ currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), stop, 0.5, 1.0, stopName, 100 );
+ }
+ else if (colortype == 1)
+ {
+ stopName = parseColor(Cdata);
+ const ScColor& gradC = m_Doc->PageColors[stopName];
+ currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), stop, 0.5, 1.0, stopName, 100 );
+ }
+ else if (colortype == 2)
+ {
+ stopName = parseColor(Cdata);
+ const ScColor& gradC = m_Doc->PageColors[stopName];
+ currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), stop, 0.5, 1.0, stopName, 100 );
+ }
+ else if (colortype == 3)
+ {
+ stopName = parseCustomColor(Cdata, colorShade);
+ const ScColor& gradC = m_Doc->PageColors[stopName];
+ currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), stop, 0.5, 1.0, stopName, qRound(colorShade));
+ }
+ else if (colortype == 4)
+ {
+ stopName = parseCustomColorX(Cdata, colorShade, "0");
+ const ScColor& gradC = m_Doc->PageColors[stopName];
+ currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), stop, 0.5, 1.0, stopName, qRound(colorShade));
+ }
+ }
+ else if (command == "BD")
+ {
+ m_gradients.insert(currentGradientName, currentGradient);
+ currentGradient = VGradient(VGradient::linear);
+ currentGradient.clearStops();
+ currentGradient.setRepeatMethod( VGradient::none );
+ currentGradientName = "";
+ }
+ }
+}
+
+void AIPlug::processPattern(QDataStream &ts)
+{
+ QString tmp = "";
+ QString tmpData = "";
+ while (!ts.atEnd())
+ {
+ tmp = removeAIPrefix(readLinefromDataStream(ts));
+ if (patternMode)
+ {
+ if (tmp == "EndPattern")
+ {
+ tmpSel->clear();
+ if (PatternElements.count() > 0)
+ {
+ for (int dre = 0; dre < PatternElements.count(); ++dre)
+ {
+ tmpSel->addItem(PatternElements.at(dre), true);
+ }
+ if (PatternElements.count() > 1)
+ m_Doc->itemSelection_GroupObjects(false, false, tmpSel);
+ ScPattern pat = ScPattern();
+ pat.setDoc(m_Doc);
+ PageItem* currItem = tmpSel->itemAt(0);
+ currItem->setItemName(currentPatternDefName);
+ currItem->AutoName = false;
+ m_Doc->DoDrawing = true;
+ QImage tmpImg = currItem->DrawObj_toImage();
+ QImage retImg = QImage(qRound(patternX2 - patternX1), qRound(patternY2 - patternY1), QImage::Format_ARGB32);
+ retImg.fill( qRgba(255, 255, 255, 0) );
+ QPainter p;
+ p.begin(&retImg);
+ if (PatternElements.count() > 1)
+ p.drawImage(qRound(-patternX1), qRound(-patternY1), tmpImg);
+ else
+ p.drawImage(0, 0, tmpImg);
+ p.end();
+ pat.pattern = retImg;
+// pat.pattern = currItem->DrawObj_toImage();
+ m_Doc->DoDrawing = false;
+ // pat.width = currItem->gWidth;
+ // pat.height = currItem->gHeight;
+ pat.width = patternX2 - patternX1;
+ pat.height = patternY2 - patternY1;
+ pat.xoffset = -patternX1;
+ pat.yoffset = -patternY1;
+ for (int as = 0; as < tmpSel->count(); ++as)
+ {
+ PageItem* Neu = tmpSel->itemAt(as);
+ Neu->moveBy(-patternX1, -patternY1, true);
+ Neu->gXpos -= patternX1;
+ Neu->gYpos -= patternY1;
+ pat.items.append(Neu);
+ }
+ m_Doc->itemSelection_DeleteItem(tmpSel);
+ m_Doc->addPattern(currentPatternDefName, pat);
+ }
+ PatternElements.clear();
+ currentPatternDefName = "";
+ break;
+ }
+ else if (tmp.startsWith("Tile"))
+ continue;
+ else if (tmp.contains(") @"))
+ {
+ tmpData += tmp;
+ tmpData.remove(") @");
+ processData(tmpData);
+ tmpData = "";
+ }
+ else if (tmp.contains(") &"))
+ {
+ tmpData += tmp;
+ tmpData.remove(") &");
+ processData(tmpData);
+ tmpData = "";
+ }
+ else
+ {
+ if (tmp.startsWith("("))
+ tmp.remove(0, 1);
+ tmpData += " "+tmp;
+ }
+ }
+ else if (tmp == "EndPattern")
+ {
+ PatternElements.clear();
+ currentPatternDefName = "";
+ break;
+ }
+ else
+ processData(tmp);
+ }
+ patternMode = false;
+}
+
+void AIPlug::processRaster(QDataStream &ts)
+{
+ double m1, m2, m3, m4, m5, m6, x1, y1, x2, y2, dummy;
+ int w, h, type, alpha, bin, bits;
+ QString tmp = "";
+ QString cumulated = "";
+ while (!ts.atEnd())
+ {
+ tmp = readLinefromDataStream(ts);
+ if (tmp.startsWith("%"))
+ break;
+ tmp.remove("[");
+ tmp.remove("]");
+ if (!tmp.isEmpty())
+ cumulated += " " + tmp;
+ }
+ QString Cdata = "";
+ QStringList da;
+ getCommands(cumulated, da);
+ Cdata = da[da.count()-1];
+ ScTextStream gVals(&Cdata, QIODevice::ReadOnly);
+ gVals >> m1 >> m2 >> m3 >> m4 >> m5 >> m6 >> x1 >> y1 >> x2 >> y2 >> w >> h >> bits >> type >> alpha >> dummy >> bin;
+// qDebug() << QString("Matrix: %1 %2 %3 %4 %5 %6").arg(m1).arg(m2).arg(m3).arg(m4).arg(m5).arg(m6);
+// qDebug() << QString("Bounds: %1 %2 %3 %4").arg(x1).arg(y1).arg(x2).arg(y2);
+// qDebug() << QString("Size: %1 %2").arg(w).arg(h);
+// qDebug() << QString("Bits: %1").arg(bits);
+// qDebug() << QString("Typ: %1").arg(type);
+// qDebug() << QString("Alpha-Channels: %1").arg(alpha);
+// qDebug() << QString("Encoding: %1").arg(bin);
+ uint dataSize = w * h * (type + alpha);
+ uint alphaData = w * h * type;
+ bool cmyk = false;
+ if (type == 4)
+ cmyk = true;
+ if (tmp.startsWith("%%BeginData"))
+ {
+ QString dummyS;
+ ScTextStream gVals2(&tmp, QIODevice::ReadOnly);
+ tmp = readLinefromDataStream(ts);
+ }
+ QByteArray psdata;
+ psdata.resize(dataSize);
+ RawImage m_image;
+ if (type == 4)
+ {
+ if (alpha > 0)
+ m_image.create(w, 1, 5);
+ else
+ m_image.create(w, 1, 4);
+ }
+ else
+ {
+ if (alpha > 0)
+ m_image.create(w, 1, 4);
+ else
+ m_image.create(w, 1, 3);
+ }
+ bool first = false;
+ if (bin == 0) // 0 = ASCII encoded data
+ {
+ uint dataPointer = 0;
+ while (!ts.atEnd())
+ {
+ if (first)
+ tmp = readLinefromDataStream(ts);
+ first = true;
+ if (tmp.startsWith("%AI5_EndRaster"))
+ break;
+ for (int a = 1; a < tmp.length(); a += 2)
+ {
+ bool ok;
+ ushort data = tmp.mid(a, 2).toUShort(&ok, 16);
+ psdata[dataPointer++] = data;
+ }
+ }
+ }
+ else
+ {
+ psdata.resize(dataSize);
+ ts.readRawData(psdata.data(), dataSize);
+ }
+ QTransform imgMatrix = QTransform(m1, m2, m3, m4, m5, m6);
+ QPointF pos = QPointF(imgMatrix.dx(), imgMatrix.dy());
+ pos += QPointF(m_Doc->currentPage()->xOffset(), -m_Doc->currentPage()->yOffset());
+ pos += QPointF(baseX, -baseY);
+ int z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, pos.x() - docX, docHeight - (pos.y() - docY), 10, 10, 0, CurrColorFill, CurrColorStroke, true);
+ PageItem* ite = m_Doc->Items->at(z);
+ ite->setWidthHeight(w * m1, h * m4);
+ double rotation = getRotationFromMatrix(imgMatrix, 0.0);
+ ite->setRotation(rotation * 180 / M_PI);
+ ite->SetRectFrame();
+ m_Doc->setRedrawBounding(ite);
+ ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
+ ite->setTextFlowMode(PageItem::TextFlowDisabled);
+ ite->setFillShade(CurrFillShade);
+ ite->setLineShade(CurrStrokeShade);
+ ite->setFillEvenOdd(fillRule);
+ ite->setFillTransparency(1.0 - Opacity);
+ ite->setLineTransparency(1.0 - Opacity);
+ ite->setLineEnd(CapStyle);
+ ite->setLineJoin(JoinStyle);
+ uchar *p;
+ uint yCount = 0;
+ ite->tempImageFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_ai_XXXXXX.tif");
+ ite->tempImageFile->open();
+ QString imgName = getLongPathName(ite->tempImageFile->fileName());
+ ite->tempImageFile->close();
+ ite->isInlineImage = true;
+ TIFF* tif = TIFFOpen(imgName.toLocal8Bit().data(), "w");
+ if (tif)
+ {
+ TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, w);
+ TIFFSetField(tif, TIFFTAG_IMAGELENGTH, h);
+ TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
+ TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, m_image.channels());
+ TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
+ if (type == 4)
+ TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_SEPARATED);
+ else
+ TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
+ TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
+ for (int y = 0; y < h; ++y)
+ {
+ p = m_image.scanLine( 0 );
+ for (int xh = 0; xh < m_image.width(); ++xh )
+ {
+ p[0] = psdata[yCount++];
+ if (type > 1)
+ {
+ p[1] = psdata[yCount++];
+ p[2] = psdata[yCount++];
+ if (type == 4)
+ p[3] = psdata[yCount++];
+ }
+ else
+ {
+ p[1] = p[0];
+ p[2] = p[0];
+ }
+ if (alpha == 1)
+ {
+ if (type == 4)
+ p[4] = psdata[alphaData++];
+ else
+ p[3] = psdata[alphaData++];
+ }
+ p += m_image.channels();
+ }
+ TIFFWriteScanline(tif, m_image.scanLine(0), y);
+ }
+ TIFFClose(tif);
+ }
+ m_Doc->LoadPict(imgName, z);
+ if (ite->PictureIsAvailable)
+ ite->setImageXYScale(ite->width() / ite->pixm.width(), ite->height() / ite->pixm.height());
+ if (importerFlags & LoadSavePlugin::lfCreateDoc)
+ ite->setLocked(itemLocked);
+ if (patternMode)
+ PatternElements.append(ite);
+ else
+ Elements.append(ite);
+ if (groupStack.count() != 0)
+ groupStack.top().append(ite);
+}
+
+void AIPlug::processComment(QDataStream &ts, QString comment)
+{
+ QString tmp = removeAIPrefix(comment);
+ if (tmp.startsWith("Begin_NonPrinting"))
+ {
+ while (!ts.atEnd())
+ {
+ tmp = removeAIPrefix(readLinefromDataStream(ts));
+ if (tmp.startsWith("BeginGradient"))
+ {
+ while (!ts.atEnd())
+ {
+ tmp = removeAIPrefix(readLinefromDataStream(ts));
+ if (tmp.startsWith("EndGradient"))
+ break;
+ else
+ processGradientData(tmp);
+ }
+ }
+ if (tmp.startsWith("BeginPattern:"))
+ processPattern(ts);
+ if (tmp.startsWith("End_NonPrinting"))
+ break;
+ progressDialog->setProgress("GI", ts.device()->pos());
+ qApp->processEvents();
+ }
+ }
+ else if (tmp.startsWith("BeginPattern:"))
+ processPattern(ts);
+ else if (tmp.startsWith("BeginGradient"))
+ {
+ while (!ts.atEnd())
+ {
+ tmp = removeAIPrefix(readLinefromDataStream(ts));
+ if (tmp.startsWith("EndGradient"))
+ break;
+ else
+ processGradientData(tmp);
+ progressDialog->setProgress("GI", ts.device()->pos());
+ qApp->processEvents();
+ }
+ }
+ else if (tmp.startsWith("BeginPalette"))
+ {
+ while (!ts.atEnd())
+ {
+ tmp = removeAIPrefix(readLinefromDataStream(ts));
+ if (tmp.startsWith("EndPalette"))
+ break;
+ progressDialog->setProgress("GI", ts.device()->pos());
+ qApp->processEvents();
+ }
+ }
+ else if (tmp.startsWith("BeginSymbol"))
+ {
+ while (!ts.atEnd())
+ {
+ tmp = removeAIPrefix(readLinefromDataStream(ts));
+ if (tmp.startsWith("EndSymbol"))
+ break;
+ progressDialog->setProgress("GI", ts.device()->pos());
+ qApp->processEvents();
+ }
+ }
+ else if (tmp.startsWith("BeginDocumentData"))
+ {
+ while (!ts.atEnd())
+ {
+ tmp = removeAIPrefix(readLinefromDataStream(ts));
+ if (tmp.startsWith("EndDocumentData"))
+ break;
+ progressDialog->setProgress("GI", ts.device()->pos());
+ qApp->processEvents();
+ }
+ }
+ else if (tmp.startsWith("%%BeginProlog"))
+ {
+ while (!ts.atEnd())
+ {
+ tmp = removeAIPrefix(readLinefromDataStream(ts));
+ if (tmp.startsWith("%%EndProlog"))
+ break;
+ progressDialog->setProgress("GI", ts.device()->pos());
+ qApp->processEvents();
+ }
+ }
+ else if (tmp.startsWith("%%BeginData"))
+ {
+ while (!ts.atEnd())
+ {
+ tmp = removeAIPrefix(readLinefromDataStream(ts));
+ if (tmp.startsWith("%%EndData"))
+ break;
+ progressDialog->setProgress("GI", ts.device()->pos());
+ qApp->processEvents();
+ }
+ }
+ else if (tmp.startsWith("%%BeginCrops"))
+ {
+ while (!ts.atEnd())
+ {
+ tmp = removeAIPrefix(readLinefromDataStream(ts));
+ if (tmp.startsWith("%%EndCrops"))
+ break;
+ progressDialog->setProgress("GI", ts.device()->pos());
+ qApp->processEvents();
+ }
+ }
+ else if (tmp.startsWith("BeginRaster"))
+ {
+ processRaster(ts);
+ progressDialog->setProgress("GI", ts.device()->pos());
+ qApp->processEvents();
+ }
+ else if (tmp.startsWith("BeginLayer"))
+ {
+ while (!ts.atEnd())
+ {
+ tmp = removeAIPrefix(readLinefromDataStream(ts));
+ if (tmp.startsWith("BeginRaster"))
+ {
+ processRaster(ts);
+ continue;
+ }
+ if (tmp.startsWith("EndLayer"))
+ break;
+ else
+ processData(tmp);
+ progressDialog->setProgress("GI", ts.device()->pos());
+ qApp->processEvents();
+ }
+ }
+}
+
+bool AIPlug::convert(QString fn)
+{
+ QString tmp;
+ LineW = 1.0;
+ Opacity = 1.0;
+ blendMode = 0;
+ CurrColorFill = "White";
+ CurrFillShade = 100.0;
+ CurrColorStroke = "Black";
+ CurrStrokeShade = 100.0;
+ JoinStyle = Qt::MiterJoin;
+ CapStyle = Qt::FlatCap;
+ DashPattern.clear();
+ DashOffset = 0.0;
+ fillRule = false;
+ FirstU = false;
+ WasU = false;
+ firstLayer = true;
+ patternMode = false;
+ meshMode = false;
+ itemLocked = false;
+ patternX1 = 0.0;
+ patternY1 = 0.0;
+ patternX2 = 0.0;
+ patternY2 = 0.0;
+ Coords.resize(0);
+ Coords.svgInit();
+ clipCoords.resize(0);
+ clipCoords.svgInit();
+ currentPoint = FPoint(0.0, 0.0);
+ currentLayer = 0;
+ currentGradient = VGradient(VGradient::linear);
+ currentGradient.clearStops();
+ currentGradient.setRepeatMethod( VGradient::none );
+ currentGradientName = "";
+ currentGradientMatrix = QTransform();
+ currentGradientOrigin = QPointF(0.0, 0.0);
+ currentGradientAngle = 0.0;
+ currentGradientLenght = 1.0;
+ currentPatternName = "";
+ currentPatternX = 0.0;
+ currentPatternY = 0.0;
+ currentPatternXScale = 1.0;
+ currentPatternYScale = 1.0;
+ currentPatternRotation = 0.0;
+ QList<PageItem*> gElements;
+ groupStack.push(gElements);
+ commandList << "m" << "l" << "L" << "c" << "C" << "v" << "V" << "y" << "Y"; // Path construction
+ commandList << "b" << "B" << "f" << "F" << "s" << "S" << "*u" << "*U"; // Object creation
+ commandList << "u" << "U" << "W" << "q" << "Q"; // Object creation
+ commandList << "A" << "w" << "j" << "J" << "Xy" << "XR"; // Graphic state
+ commandList << "k" << "K" << "Xa" << "XA" << "x" << "X" << "XX" << "Xx"; // Color commands
+ commandList << "Xk" << "g" << "G" << "p"; // Color commands
+ commandList << "Ln" << "Lb" << "LB"; // Layer commands
+ commandList << "Bd" << "BD" << "%_Bs" << "Bg" << "Bb" << "BB" << "Bm" << "Xm"; // Gradient commands
+ commandList << "To" << "TO" << "Tf" << "Tp" << "Tx" << "TX" << "T*" << "Tk"; // Text commands
+ commandList << "Tc" << "Tz"; // Text commands
+ commandList << "XI" << "XG" << "Xh"; // Image commands
+ commandList << "n" << "N" << "*" << "["; // Special commands
+ commandList << "X!" << "X#"; // Mesh commands
+ commandList << "M" << "d" << "D" << "E"; // unimplemented
+ commandList << "h" << "H" << "i" << "I" << "Np" << "O"; // unimplemented
+ commandList << "P" << "R"; // unimplemented
+ commandList << "XI" << "XF" << "XG" << "XT" << "Z" << "`" << "~" << "_" << "@"; // unimplemented
+ commandList << "&" << "*w" << "*W" << "Ap" << "Ar"; // unimplemented
+ if(progressDialog)
+ {
+ progressDialog->setOverallProgress(2);
+ progressDialog->setLabel("GI", tr("Generating Items"));
+ qApp->processEvents();
+ }
+ QFile f(fn);
+ if (f.open(QIODevice::ReadOnly))
+ {
+ int fSize = (int) f.size();
+ if (progressDialog)
+ {
+ progressDialog->setTotalSteps("GI", fSize);
+ qApp->processEvents();
+ }
+ QDataStream ts(&f);
+ while (!ts.atEnd())
+ {
+ tmp = readLinefromDataStream(ts);
+ if (tmp.startsWith("%"))
+ processComment(ts, tmp);
+ else
+ processData(tmp);
+ progressDialog->setProgress("GI", ts.device()->pos());
+ qApp->processEvents();
+ }
+ }
+ if (progressDialog)
+ progressDialog->close();
+ return true;
+}
Index: scribus/plugins/aiimplugin/importai.h
===================================================================
--- scribus/plugins/aiimplugin/importai.h (revision 13950)
+++ scribus/plugins/aiimplugin/importai.h (revision 13951)
@@ -8,7 +8,7 @@
#define IMPORTAI_H
#include <QList>
-#include <QMatrix>
+#include <QTransform>
#include <QObject>
#include <QString>
@@ -123,15 +123,15 @@
QMap<QString, VGradient> m_gradients;
VGradient currentGradient;
QString currentGradientName;
- QMatrix currentGradientMatrix;
+ QTransform currentGradientMatrix;
QPointF currentGradientOrigin;
double currentGradientAngle;
double currentGradientLenght;
bool gradientMode;
bool wasBC;
bool itemRendered;
- QMatrix startMatrix;
- QMatrix endMatrix;
+ QTransform startMatrix;
+ QTransform endMatrix;
bool patternMode;
QString currentPatternDefName;
QString currentPatternName;
@@ -169,7 +169,7 @@
QString docOrganisation;
QString docTitle;
int textMode;
- QMatrix textMatrix;
+ QTransform textMatrix;
StoryText textData;
QString textFont;
double textSize;
Index: scribus/plugins/xfigimplugin/importxfig.cpp
===================================================================
--- scribus/plugins/xfigimplugin/importxfig.cpp (revision 13950)
+++ scribus/plugins/xfigimplugin/importxfig.cpp (revision 13951)
@@ -1,1592 +1,1592 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-#include <QByteArray>
-#include <QCursor>
-#include <QDrag>
-#include <QFile>
-#include <QList>
-#include <QMimeData>
-#include <QRegExp>
-#include <QStack>
-#include <QDebug>
-
-#include <cmath>
-#include <cstdlib>
-
-#include "commonstrings.h"
-#include "ui/customfdialog.h"
-#include "importxfig.h"
-#include "loadsaveplugin.h"
-#include "ui/missing.h"
-#include "ui/multiprogressdialog.h"
-#include "pagesize.h"
-#include "pageitem.h"
-#include "prefscontext.h"
-#include "prefsfile.h"
-#include "prefsmanager.h"
-#include "prefsmanager.h"
-#include "prefstable.h"
-#include "ui/propertiespalette.h"
-#include "rawimage.h"
-#include "scclocale.h"
-#include "sccolorengine.h"
-#include "scconfig.h"
-#include "scmimedata.h"
-#include "scpaths.h"
-#include "scpattern.h"
-#include "scpattern.h"
-#include "scribus.h"
-#include "scribusXml.h"
-#include "scribuscore.h"
-#include "sctextstream.h"
-#include "selection.h"
-#include "undomanager.h"
-#include "util.h"
-#include "util_formats.h"
-#include "util_icon.h"
-#include "util_math.h"
-
-extern SCRIBUS_API ScribusQApp * ScQApp;
-
-XfigPlug::XfigPlug(ScribusDoc* doc, int flags)
-{
- tmpSel=new Selection(this, false);
- m_Doc=doc;
- interactive = (flags & LoadSavePlugin::lfInteractive);
-}
-
-bool XfigPlug::import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
-{
- QString fName = fNameIn;
- bool success = false;
- interactive = (flags & LoadSavePlugin::lfInteractive);
- importerFlags = flags;
- cancel = false;
- double x, y, b, h;
- bool ret = false;
- CustColors.clear();
- importedColors.insert(0, "Black");
- importedColors.insert(1, "Blue");
- importedColors.insert(2, "Green");
- importedColors.insert(3, "Cyan");
- importedColors.insert(4, "Red");
- importedColors.insert(5, "Magenta");
- importedColors.insert(6, "Yellow");
- importedColors.insert(7, "White");
- importedColors.insert(8, "Blue4");
- importedColors.insert(9, "Blue3");
- importedColors.insert(10, "Blue2");
- importedColors.insert(11, "LtBlue");
- importedColors.insert(12, "Green4");
- importedColors.insert(13, "Green3");
- importedColors.insert(14, "Green2");
- importedColors.insert(15, "Cyan4");
- importedColors.insert(16, "Cyan3");
- importedColors.insert(17, "Cyan2");
- importedColors.insert(18, "Red4");
- importedColors.insert(19, "Red3");
- importedColors.insert(20, "Red2");
- importedColors.insert(21, "Magenta4");
- importedColors.insert(22, "Magenta3");
- importedColors.insert(23, "Magenta2");
- importedColors.insert(24, "Brown4");
- importedColors.insert(25, "Brown3");
- importedColors.insert(26, "Brown2");
- importedColors.insert(27, "Pink4");
- importedColors.insert(28, "Pink3");
- importedColors.insert(29, "Pink2");
- importedColors.insert(30, "Pink");
- importedColors.insert(31, "Gold");
- CustColors.insert("Blue", ScColor(255, 0, 0, 0));
- CustColors.insert("Blue4", ScColor(0, 0, 144));
- CustColors.insert("Blue3", ScColor(0, 0, 176));
- CustColors.insert("Blue2", ScColor(0, 0, 208));
- CustColors.insert("LtBlue", ScColor(135, 206, 255));
- CustColors.insert("Cyan", ScColor(255, 0, 0, 0));
- CustColors.insert("Cyan4", ScColor(0, 144, 144));
- CustColors.insert("Cyan3", ScColor(0, 176, 176));
- CustColors.insert("Cyan2", ScColor(0, 208, 208));
- CustColors.insert("Green", ScColor(255, 0, 255, 0));
- CustColors.insert("Green4", ScColor(0, 144, 0));
- CustColors.insert("Green3", ScColor(0, 176, 0));
- CustColors.insert("Green2", ScColor(0, 208, 0));
- CustColors.insert("Red", ScColor(0, 255, 255, 0));
- CustColors.insert("Red4", ScColor(144, 0, 0));
- CustColors.insert("Red3", ScColor(176, 0, 0));
- CustColors.insert("Red2", ScColor(208, 0, 0));
- CustColors.insert("Yellow", ScColor(0, 0, 255, 0));
- CustColors.insert("Magenta", ScColor(0, 255, 0, 0));
- CustColors.insert("Magenta4", ScColor(144, 0, 144));
- CustColors.insert("Magenta3", ScColor(176, 0, 176));
- CustColors.insert("Magenta2", ScColor(208, 0, 208));
- CustColors.insert("Brown4", ScColor(128, 48, 0));
- CustColors.insert("Brown3", ScColor(160, 64, 0));
- CustColors.insert("Brown2", ScColor(192, 96, 0));
- CustColors.insert("Pink4", ScColor(255, 128, 128));
- CustColors.insert("Pink3", ScColor(255, 160, 160));
- CustColors.insert("Pink2", ScColor(255, 192, 192));
- CustColors.insert("Pink", ScColor(255, 224, 224));
- CustColors.insert("Gold", ScColor(255, 215, 0));
- QFileInfo fi = QFileInfo(fName);
- if ( !ScCore->usingGUI() )
- {
- interactive = false;
- showProgress = false;
- }
- baseFile = QDir::cleanPath(QDir::toNativeSeparators(fi.absolutePath()+"/"));
- if ( showProgress )
- {
- ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
- progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw );
- QStringList barNames, barTexts;
- barNames << "GI";
- barTexts << tr("Analyzing File:");
- QList<bool> barsNumeric;
- barsNumeric << false;
- progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
- progressDialog->setOverallTotalSteps(3);
- progressDialog->setOverallProgress(0);
- progressDialog->setProgress("GI", 0);
- progressDialog->show();
- connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
- qApp->processEvents();
- }
- else
- progressDialog = NULL;
-/* Set default Page to size defined in Preferences */
- x = 0.0;
- y = 0.0;
- b = 0.0;
- h = 0.0;
- if (progressDialog)
- {
- progressDialog->setOverallProgress(1);
- qApp->processEvents();
- }
- parseHeader(fName, x, y, b, h);
- docX = x;
- docY = y;
- if (b == 0.0)
- b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth;
- if (h == 0.0)
- h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight;
- docWidth = b - x;
- docHeight = h - y;
- baseX = 0;
- baseY = 0;
- if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
- {
- m_Doc->setPage(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false);
- m_Doc->addPage(0);
- m_Doc->view()->addPage(0, true);
- baseX = 0;
- baseY = 0;
- }
- else
- {
- if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
- {
- m_Doc=ScCore->primaryMainWindow()->doFileNew(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
- ScCore->primaryMainWindow()->HaveNewDoc();
- ret = true;
- baseX = 0;
- baseY = 0;
- }
- }
- if (flags & LoadSavePlugin::lfCreateDoc)
- {
- m_Doc->documentInfo.setAuthor(docCreator);
- m_Doc->documentInfo.setPublisher(docOrganisation);
- m_Doc->documentInfo.setTitle(docTitle);
- m_Doc->documentInfo.setDate(docDate+" "+docTime);
- }
- if ((!ret) && (interactive))
- {
- baseX = m_Doc->currentPage()->xOffset();
- baseY = m_Doc->currentPage()->yOffset();
- }
- if ((ret) || (!interactive))
- {
- if (b-x > h-y)
- m_Doc->PageOri = 1;
- else
- m_Doc->PageOri = 0;
- m_Doc->m_pageSize = "Custom";
- }
- Elements.clear();
- FPoint minSize = m_Doc->minCanvasCoordinate;
- FPoint maxSize = m_Doc->maxCanvasCoordinate;
- FPoint cOrigin = m_Doc->view()->canvasOrigin();
- m_Doc->setLoading(true);
- m_Doc->DoDrawing = false;
- m_Doc->view()->updatesOn(false);
- m_Doc->scMW()->ScriptRunning = true;
- qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
- QString CurDirP = QDir::currentPath();
- QDir::setCurrent(fi.path());
- if (convert(fName))
- {
- tmpSel->clear();
- QDir::setCurrent(CurDirP);
- if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc)))
- {
- bool isGroup = true;
- int firstElem = -1;
- if (Elements.at(0)->Groups.count() != 0)
- firstElem = Elements.at(0)->Groups.top();
- for (int bx = 0; bx < Elements.count(); ++bx)
- {
- PageItem* bxi = Elements.at(bx);
- if (bxi->Groups.count() != 0)
- {
- if (bxi->Groups.top() != firstElem)
- isGroup = false;
- }
- else
- isGroup = false;
- }
- if (!isGroup)
- {
- double minx = 99999.9;
- double miny = 99999.9;
- double maxx = -99999.9;
- double maxy = -99999.9;
- uint lowestItem = 999999;
- uint highestItem = 0;
- for (int a = 0; a < Elements.count(); ++a)
- {
- Elements.at(a)->Groups.push(m_Doc->GroupCounter);
- PageItem* currItem = Elements.at(a);
- lowestItem = qMin(lowestItem, currItem->ItemNr);
- highestItem = qMax(highestItem, currItem->ItemNr);
- double x1, x2, y1, y2;
- currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
- minx = qMin(minx, x1);
- miny = qMin(miny, y1);
- maxx = qMax(maxx, x2);
- maxy = qMax(maxy, y2);
- }
- double gx = minx;
- double gy = miny;
- double gw = maxx - minx;
- double gh = maxy - miny;
- PageItem *high = m_Doc->Items->at(highestItem);
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, m_Doc->toolSettings.dBrush, m_Doc->toolSettings.dPen, true);
- PageItem *neu = m_Doc->Items->takeAt(z);
- m_Doc->Items->insert(lowestItem, neu);
- neu->Groups.push(m_Doc->GroupCounter);
- neu->setItemName( tr("Group%1").arg(neu->Groups.top()));
- neu->AutoName = false;
- neu->isGroupControl = true;
- neu->groupsLastItem = high;
- neu->setTextFlowMode(PageItem::TextFlowDisabled);
- for (int a = 0; a < m_Doc->Items->count(); ++a)
- {
- m_Doc->Items->at(a)->ItemNr = a;
- }
- Elements.prepend(neu);
- m_Doc->GroupCounter++;
- }
- }
- m_Doc->DoDrawing = true;
- m_Doc->scMW()->ScriptRunning = false;
- m_Doc->setLoading(false);
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- if ((Elements.count() > 0) && (!ret) && (interactive))
- {
- if (flags & LoadSavePlugin::lfScripted)
- {
- bool loadF = m_Doc->isLoading();
- m_Doc->setLoading(false);
- m_Doc->changed();
- m_Doc->setLoading(loadF);
- m_Doc->m_Selection->delaySignalsOn();
- for (int dre=0; dre<Elements.count(); ++dre)
- {
- m_Doc->m_Selection->addItem(Elements.at(dre), true);
- }
- m_Doc->m_Selection->delaySignalsOff();
- m_Doc->m_Selection->setGroupRect();
- m_Doc->view()->updatesOn(true);
- }
- else
- {
- m_Doc->DragP = true;
- m_Doc->DraggedElem = 0;
- m_Doc->DragElements.clear();
- m_Doc->m_Selection->delaySignalsOn();
- for (int dre=0; dre<Elements.count(); ++dre)
- {
- m_Doc->DragElements.append(Elements.at(dre)->ItemNr);
- tmpSel->addItem(Elements.at(dre), true);
- }
- tmpSel->setGroupRect();
- ScriXmlDoc *ss = new ScriXmlDoc();
- ScElemMimeData* md = new ScElemMimeData();
- md->setScribusElem(ss->WriteElem(m_Doc, m_Doc->view(), tmpSel));
- delete ss;
-/*#ifndef Q_WS_MAC*/
-// see #2196
- m_Doc->itemSelection_DeleteItem(tmpSel);
-/*#else
- qDebug("xfigimport: leaving items on page");
-#endif*/
- m_Doc->view()->updatesOn(true);
- m_Doc->m_Selection->delaySignalsOff();
- // We must copy the TransationSettings object as it is owned
- // by handleObjectImport method afterwards
- TransactionSettings* transacSettings = new TransactionSettings(trSettings);
- m_Doc->view()->handleObjectImport(md, transacSettings);
- m_Doc->DragP = false;
- m_Doc->DraggedElem = 0;
- m_Doc->DragElements.clear();
- }
- }
- else
- {
- m_Doc->changed();
- m_Doc->reformPages();
- m_Doc->view()->updatesOn(true);
- }
- success = true;
- }
- else
- {
- QDir::setCurrent(CurDirP);
- m_Doc->DoDrawing = true;
- m_Doc->scMW()->ScriptRunning = false;
- m_Doc->view()->updatesOn(true);
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- }
- if (interactive)
- m_Doc->setLoading(false);
- //CB If we have a gui we must refresh it if we have used the progressbar
- if ((showProgress) && (!interactive))
- m_Doc->view()->DrawNew();
- return success;
-}
-
-XfigPlug::~XfigPlug()
-{
- if (progressDialog)
- delete progressDialog;
- delete tmpSel;
-}
-
-bool XfigPlug::parseHeader(QString fName, double &x, double &y, double &b, double &h)
-{
- QString tmp, BBox, tmp2, FarNam;
- ScColor cc;
- bool found = false;
- QFile f(fName);
- if (f.open(QIODevice::ReadOnly))
- {
- QDataStream ts(&f);
- QString version = readLinefromDataStream(ts);
- if (!version.startsWith("#FIG 3"))
- {
- f.close();
- return false;
- }
- QString orientation = readLinefromDataStream(ts);
- QString justification = readLinefromDataStream(ts);
- QString units = readLinefromDataStream(ts);
- QString papersize = readLinefromDataStream(ts);
- PageSize ps(papersize);
- if (orientation.startsWith("Landscape"))
- {
- h = ps.width();
- b = ps.height();
- }
- else
- {
- b = ps.width();
- h = ps.height();
- }
- f.close();
- found = true;
- }
- return found;
-}
-
-void XfigPlug::parseColor(QString data)
-{
- if (data.isEmpty())
- return;
- int colorNum, dummy;
- QString colorValues;
- ScColor tmp;
- ScTextStream Code(&data, QIODevice::ReadOnly);
- Code >> dummy >> colorNum >> colorValues;
- tmp.setNamedColor(colorValues);
- tmp.setSpotColor(false);
- tmp.setRegistrationColor(false);
- QString namPrefix = "FromXfig%1-"+colorValues;
- CustColors.insert(namPrefix.arg(colorNum), tmp);
- importedColors.insert(colorNum, namPrefix.arg(colorNum));
-}
-
-void XfigPlug::useColor(int colorNum, int area_fill, bool forFill)
-{
- QString color = CommonStrings::None;
- int shade = 100;
- if (forFill)
- {
- if (area_fill == -1)
- color = CommonStrings::None;
- else
- {
- if ((colorNum == -1) || (colorNum == 0))
- {
- if (area_fill == 0)
- {
- color = "White";
- shade = 100;
- }
- else if (area_fill == 20)
- {
- color = "Black";
- shade = 100;
- }
- else if ((area_fill > 0) && (area_fill < 20))
- {
- color = "Black";
- shade = qRound(100.0 / 19.0 * area_fill);
- }
- }
- else if (colorNum == 7)
- {
- if (area_fill == 0)
- {
- color = "Black";
- shade = 100;
- }
- else if (area_fill == 20)
- {
- color = "White";
- shade = 100;
- }
- else if ((area_fill > 0) && (area_fill < 20))
- {
- color = "Black";
- shade = qRound(100.0 / 19.0 * (20 - area_fill));
- }
- }
- else
- {
- if (importedColors.contains(colorNum))
- {
- color = importedColors[colorNum];
- if (!m_Doc->PageColors.contains(color))
- m_Doc->PageColors.insert(color, CustColors[color]);
- int sat = area_fill - 20;
- if ((sat > 0) && (sat < 20))
- shade = qRound(100.0 / 19.0 * sat);
- }
- else
- color = CommonStrings::None;
- }
- }
- CurrColorFill = color;
- CurrFillShade = shade;
- }
- else
- {
- if (area_fill == -1)
- CurrColorStroke = CommonStrings::None;
- else
- {
- if ((colorNum == -1) || (colorNum == 0))
- CurrColorStroke = "Black";
- else
- {
- if (importedColors.contains(colorNum))
- {
- CurrColorStroke = importedColors[colorNum];
- if (!m_Doc->PageColors.contains(CurrColorStroke))
- m_Doc->PageColors.insert(CurrColorStroke, CustColors[CurrColorStroke]);
- }
- else
- CurrColorStroke = CommonStrings::None;
- }
- }
- }
-}
-
-QVector<double> XfigPlug::getDashValues(double linewidth, int code)
-{
- QVector<double> tmp;
- if (code == 1)
- {
- tmp << qMax(4.0 * linewidth, 0.1);
- tmp << qMax(2.0 * linewidth, 0.1);
- }
- else if (code == 2)
- {
- tmp << qMax(1.0 * linewidth, 0.1);
- tmp << qMax(2.0 * linewidth, 0.1);
- }
- else if (code == 3)
- {
- tmp << qMax(4.0 * linewidth, 0.1);
- tmp << qMax(2.0 * linewidth, 0.1);
- tmp << qMax(1.0 * linewidth, 0.1);
- tmp << qMax(2.0 * linewidth, 0.1);
- }
- else if (code == 4)
- {
- tmp << qMax(4.0 * linewidth, 0.1);
- tmp << qMax(2.0 * linewidth, 0.1);
- tmp << qMax(1.0 * linewidth, 0.1);
- tmp << qMax(2.0 * linewidth, 0.1);
- tmp << qMax(1.0 * linewidth, 0.1);
- tmp << qMax(2.0 * linewidth, 0.1);
- }
- else if (code == 5)
- {
- tmp << qMax(4.0 * linewidth, 0.1);
- tmp << qMax(2.0 * linewidth, 0.1);
- tmp << qMax(1.0 * linewidth, 0.1);
- tmp << qMax(2.0 * linewidth, 0.1);
- tmp << qMax(1.0 * linewidth, 0.1);
- tmp << qMax(2.0 * linewidth, 0.1);
- tmp << qMax(1.0 * linewidth, 0.1);
- tmp << qMax(2.0 * linewidth, 0.1);
- }
- return tmp;
-}
-
-void XfigPlug::processArrows(int forward_arrow, QString fArrowData, int backward_arrow, QString bArrowData, int depth, PageItem *ite)
-{
- int arrow_typeAF; // (enumeration type)
- int arrow_styleAF; // (enumeration type)
- float arrow_thicknessAF; // (1/80 inch)
- float arrow_widthAF; // (Fig units)
- float arrow_heightAF; // (Fig units)
- int arrow_typeAB; // (enumeration type)
- int arrow_styleAB; // (enumeration type)
- float arrow_thicknessAB; // (1/80 inch)
- float arrow_widthAB; // (Fig units)
- float arrow_heightAB; // (Fig units)
- FPointArray arrow;
- int z = -1;
- PageItem::ItemType iteType;
- if (forward_arrow == 1)
- {
- arrow.resize(0);
- ScTextStream CodeAF(&fArrowData, QIODevice::ReadOnly);
- CodeAF >> arrow_typeAF >> arrow_styleAF >> arrow_thicknessAF >> arrow_widthAF >> arrow_heightAF;
- arrow_widthAF = fig2Pts(arrow_widthAF);
- arrow_heightAF = fig2Pts(arrow_heightAF);
- arrow_thicknessAF = arrow_thicknessAF / 80.0 * 72.0;
- FPoint End = ite->PoLine.point(ite->PoLine.size()-2);
- for (uint xx = ite->PoLine.size()-1; xx > 0; xx -= 2)
- {
- FPoint Vector = ite->PoLine.point(xx);
- if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
- {
- double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
- if (arrow_typeAF == 0)
- arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5");
- else if (arrow_typeAF == 1)
- arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5 z");
- else if (arrow_typeAF == 2)
- arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5 L -0.7 0 z");
- else if (arrow_typeAF == 3)
- arrow.parseSVG("M -0.7, -0.5 L 0, 0 L -0.7, 0.5 L -1 0 z");
- arrowTrans.translate(End.x(), End.y());
- arrowTrans.rotate(r);
- arrowTrans.scale(arrow_heightAF, arrow_widthAF);
- arrow.map(arrowTrans);
- break;
- }
- }
- QString fillC = "White";
- if (arrow_styleAF == 1)
- fillC = CurrColorStroke;
- if (arrow_typeAF == 0)
- {
- fillC = CommonStrings::None;
- iteType = PageItem::PolyLine;
- }
- else
- iteType = PageItem::Polygon;
- z = m_Doc->itemAdd(iteType, PageItem::Unspecified, ite->xPos(), ite->yPos(), 10, 10, arrow_thicknessAF, fillC, CurrColorStroke, true);
- if (z >= 0)
- {
- PageItem *item = m_Doc->Items->at(z);
- item->PoLine = arrow.copy();
- item->ClipEdited = true;
- item->FrameType = 3;
- item->setFillShade(CurrFillShade);
- item->setLineShade(CurrStrokeShade);
- FPoint wh = getMaxClipF(&item->PoLine);
- item->setWidthHeight(wh.x(),wh.y());
- item->setTextFlowMode(PageItem::TextFlowDisabled);
- m_Doc->AdjustItemSize(item);
- item->setWidthHeight(qMax(item->width(), 1.0), qMax(item->height(), 1.0));
- depthMap.insert(999 - depth, currentItemNr);
- currentItemNr++;
- }
- }
- if (backward_arrow == 1)
- {
- arrow.resize(0);
- ScTextStream CodeAB(&bArrowData, QIODevice::ReadOnly);
- CodeAB >> arrow_typeAB >> arrow_styleAB >> arrow_thicknessAB >> arrow_widthAB >> arrow_heightAB;
- arrow_widthAB = fig2Pts(arrow_widthAB);
- arrow_heightAB = fig2Pts(arrow_heightAB);
- arrow_thicknessAB = arrow_thicknessAB / 80.0 * 72.0;
- FPointArray arrow;
- FPoint Start = ite->PoLine.point(0);
- for (uint xx = 1; xx < ite->PoLine.size(); xx += 2)
- {
- FPoint Vector = ite->PoLine.point(xx);
- if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
- {
- double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
- if (arrow_typeAB == 0)
- arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5");
- else if (arrow_typeAB == 1)
- arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5 z");
- else if (arrow_typeAB == 2)
- arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5 L -0.7 0 z");
- else if (arrow_typeAB == 3)
- arrow.parseSVG("M -0.7, -0.5 L 0, 0 L -0.7, 0.5 L -1 0 z");
- arrowTrans.translate(Start.x(), Start.y());
- arrowTrans.rotate(r);
- arrowTrans.scale(arrow_heightAB, arrow_widthAB);
- arrow.map(arrowTrans);
- break;
- }
- }
- QString fillC = "White";
- if (arrow_styleAB == 1)
- fillC = CurrColorStroke;
- if (arrow_typeAB == 0)
- {
- fillC = CommonStrings::None;
- iteType = PageItem::PolyLine;
- }
- else
- iteType = PageItem::Polygon;
- z = m_Doc->itemAdd(iteType, PageItem::Unspecified, ite->xPos(), ite->yPos(), 10, 10, arrow_thicknessAB, fillC, CurrColorStroke, true);
- if (z >= 0)
- {
- PageItem *item = m_Doc->Items->at(z);
- item->PoLine = arrow.copy();
- item->ClipEdited = true;
- item->FrameType = 3;
- item->setFillShade(CurrFillShade);
- item->setLineShade(CurrStrokeShade);
- FPoint wh = getMaxClipF(&item->PoLine);
- item->setWidthHeight(wh.x(),wh.y());
- item->setTextFlowMode(PageItem::TextFlowDisabled);
- m_Doc->AdjustItemSize(item);
- item->setWidthHeight(qMax(item->width(), 1.0), qMax(item->height(), 1.0));
- depthMap.insert(999 - depth, currentItemNr);
- currentItemNr++;
- }
- }
-}
-
-void XfigPlug::processPolyline(QDataStream &ts, QString data)
-{
- QString tmp = data;
- QString fArrowData = "";
- QString bArrowData = "";
- int command;
- int subtype; // (1: polyline, 2: box, 3: polygon, 4: arc-box, 5: imported-picture bounding-box)
- int line_style; // (enumeration type)
- int thickness; // (1/80 inch)
- int pen_color; // (enumeration type, pen color)
- int fill_color; // (enumeration type, fill color)
- int depth; // (enumeration type)
- int pen_style; // (pen style, not used)
- int area_fill; // (enumeration type, -1 = no fill)
- double style_val; // (1/80 inch)
- int join_style; // (enumeration type)
- int cap_style; // (enumeration type, only used for POLYLINE)
- int radius; // (1/80 inch, radius of arc-boxes)
- int forward_arrow; // (0: off, 1: on)
- int backward_arrow; // (0: off, 1: on)
- int npoints; // (number of points in line)
- int pointsRead = 0;
- int imgFlipped;
- QString imgFile;
- double x, y;
- Coords.resize(0);
- Coords.svgInit();
- bool first = true;
- ScTextStream Code(&tmp, QIODevice::ReadOnly);
- Code >> command >> subtype >> line_style >> thickness >> pen_color >> fill_color >> depth >> pen_style;
- Code >> area_fill >> style_val >> join_style >> cap_style >> radius >> forward_arrow >> backward_arrow >> npoints;
- if (forward_arrow == 1)
- fArrowData = readLinefromDataStream(ts);
- if (backward_arrow == 1)
- bArrowData = readLinefromDataStream(ts);
- if (subtype == 5)
- {
- tmp = readLinefromDataStream(ts);
- ScTextStream imf(&tmp, QIODevice::ReadOnly);
- imf >> imgFlipped >> imgFile;
- }
- while (!ts.atEnd())
- {
- tmp = readLinefromDataStream(ts);
- ScTextStream pts(&tmp, QIODevice::ReadOnly);
- while (!pts.atEnd())
- {
- pts >> x >> y;
- x = fig2Pts(x) - docX;
- y = fig2Pts(y) - docY;
- if (first)
- {
- Coords.svgMoveTo(x, y);
- first = false;
- }
- else
- Coords.svgLineTo(x, y);
- pointsRead++;
- }
- if (pointsRead == npoints)
- {
- if (npoints == 1)
- Coords.svgLineTo(x, y);
- break;
- }
- }
- useColor(pen_color, 0, false);
- useColor(fill_color, area_fill, true);
- LineW = thickness / 80.0 * 72.0;
- int z = -1;
- PageItem *ite;
- if (subtype == 1)
- z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
- else if ((subtype == 2) || (subtype == 3) || (subtype == 4))
- {
- z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
- Coords.svgClosePath();
- }
- else if (subtype == 5)
- {
- z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
- Coords.svgClosePath();
- }
- else
- z = -1;
- if (z >= 0)
- {
- ite = m_Doc->Items->at(z);
- ite->PoLine = Coords.copy();
- ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
- ite->ClipEdited = true;
- ite->FrameType = 3;
- ite->setFillShade(CurrFillShade);
- ite->setLineShade(CurrStrokeShade);
- if (line_style > 0)
- ite->setDashes(getDashValues(LineW, line_style));
- if (subtype == 1)
- {
- if (join_style == 0)
- ite->setLineJoin(Qt::MiterJoin);
- else if (join_style == 1)
- ite->setLineJoin(Qt::RoundJoin);
- else if (join_style == 2)
- ite->setLineJoin(Qt::BevelJoin);
- if (cap_style == 0)
- ite->setLineEnd(Qt::FlatCap);
- else if (cap_style == 1)
- ite->setLineEnd(Qt::RoundCap);
- else if (cap_style == 2)
- ite->setLineEnd(Qt::SquareCap);
- }
- FPoint wh = getMaxClipF(&ite->PoLine);
- ite->setWidthHeight(wh.x(),wh.y());
- ite->setTextFlowMode(PageItem::TextFlowDisabled);
- m_Doc->AdjustItemSize(ite);
- ite->setWidthHeight(qMax(ite->width(), 1.0), qMax(ite->height(), 1.0));
- if (subtype == 4)
- {
- ite->setCornerRadius(radius / 80.0 * 72.0);
- ite->FrameType = 2;
- ite->ClipEdited = false;
- ite->updateClip();
- }
- if (subtype == 5)
- {
- ite->Pfile = baseFile + "/" + imgFile;
- m_Doc->loadPict(ite->Pfile, ite, false);
- ite->setImageXYScale(72.0 / 80.0, 72.0 / 80.0);
- ite->setImageXYOffset(0, 0);
- }
- depthMap.insert(999 - depth, currentItemNr);
- currentItemNr++;
- if ((ite->itemType() == PageItem::PolyLine) && ((forward_arrow == 1) || (backward_arrow == 1)))
- processArrows(forward_arrow, fArrowData, backward_arrow, bArrowData, depth, ite);
- }
-}
-
-void XfigPlug::processSpline(QDataStream &ts, QString data)
-{
- QString tmp = data;
- QString fArrowData = "";
- QString bArrowData = "";
- int command;
- int subtype; // 0: open approximated spline
- // 1: closed approximated spline
- // 2: open interpolated spline
- // 3: closed interpolated spline
- // 4: open x-spline
- // 5: closed x-spline
- int line_style; // (enumeration type)
- int thickness; // (1/80 inch)
- int pen_color; // (enumeration type, pen color)
- int fill_color; // (enumeration type, fill color)
- int depth; // (enumeration type)
- int pen_style; // (pen style, not used)
- int area_fill; // (enumeration type, -1 = no fill)
- double style_val; // (1/80 inch)
- int cap_style; // (enumeration type, only used for POLYLINE)
- int forward_arrow; // (0: off, 1: on)
- int backward_arrow; // (0: off, 1: on)
- int npoints; // (number of points in line)
- int pointsRead = 0;
- double x, y;
- Coords.resize(0);
- Coords.svgInit();
- bool first = true;
- ScTextStream Code(&tmp, QIODevice::ReadOnly);
- Code >> command >> subtype >> line_style >> thickness >> pen_color >> fill_color >> depth >> pen_style;
- Code >> area_fill >> style_val >> cap_style >> forward_arrow >> backward_arrow >> npoints;
- if (forward_arrow == 1)
- fArrowData = readLinefromDataStream(ts);
- if (backward_arrow == 1)
- bArrowData = readLinefromDataStream(ts);
- while (!ts.atEnd())
- {
- tmp = readLinefromDataStream(ts);
- ScTextStream pts(&tmp, QIODevice::ReadOnly);
- while (!pts.atEnd())
- {
- pts >> x >> y;
- x = fig2Pts(x) - docX;
- y = fig2Pts(y) - docY;
- if (first)
- {
- Coords.svgMoveTo(x, y);
- first = false;
- }
- else
- Coords.svgLineTo(x, y);
- pointsRead++;
- }
- if (pointsRead == npoints)
- {
- if (npoints == 1)
- Coords.svgLineTo(x, y);
- break;
- }
- }
- pointsRead = 0;
- while (!ts.atEnd())
- {
- tmp = readLinefromDataStream(ts);
- ScTextStream pts(&tmp, QIODevice::ReadOnly);
- while (!pts.atEnd())
- {
- pts >> x;
- pointsRead++;
- }
- if (pointsRead == npoints)
- break;
- }
- useColor(pen_color, 0, false);
- useColor(fill_color, area_fill, true);
- LineW = thickness / 80.0 * 72.0;
- int z = -1;
- PageItem *ite;
- if ((subtype == 0) || (subtype == 2) || (subtype == 4))
- z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
- else if ((subtype == 1) || (subtype == 3) || (subtype == 5))
- {
- z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
- Coords.svgClosePath();
- }
- if (z >= 0)
- {
- ite = m_Doc->Items->at(z);
- ite->PoLine = Coords.copy();
- ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
- ite->ClipEdited = true;
- ite->FrameType = 3;
- ite->setFillShade(CurrFillShade);
- ite->setLineShade(CurrStrokeShade);
- if (line_style > 0)
- ite->setDashes(getDashValues(LineW, line_style));
- if ((subtype == 0) || (subtype == 2) || (subtype == 4))
- {
- if (cap_style == 0)
- ite->setLineEnd(Qt::FlatCap);
- else if (cap_style == 1)
- ite->setLineEnd(Qt::RoundCap);
- else if (cap_style == 2)
- ite->setLineEnd(Qt::SquareCap);
- }
- FPoint wh = getMaxClipF(&ite->PoLine);
- ite->setWidthHeight(wh.x(),wh.y());
- ite->setTextFlowMode(PageItem::TextFlowDisabled);
- m_Doc->AdjustItemSize(ite);
- ite->setWidthHeight(qMax(ite->width(), 1.0), qMax(ite->height(), 1.0));
- depthMap.insert(999 - depth, currentItemNr);
- currentItemNr++;
- if ((ite->itemType() == PageItem::PolyLine) && ((forward_arrow == 1) || (backward_arrow == 1)))
- processArrows(forward_arrow, fArrowData, backward_arrow, bArrowData, depth, ite);
- }
-}
-
-void XfigPlug::processArc(QDataStream &ts, QString data)
-{
- QString tmp = data;
- QString fArrowData = "";
- QString bArrowData = "";
- int command;
- int subtype; // (1: open ended arc, 2: pie-wedge (closed))
- int line_style; // (enumeration type)
- int thickness; // (1/80 inch)
- int pen_color; // (enumeration type, pen color)
- int fill_color; // (enumeration type, fill color)
- int depth; // (enumeration type)
- int pen_style; // (pen style, not used)
- int area_fill; // (enumeration type, -1 = no fill)
- double style_val; // (1/80 inch)
- int cap_style; // (enumeration type, only used for POLYLINE)
- int direction; // (always 1)
- int forward_arrow; // (0: off, 1: on)
- int backward_arrow; // (0: off, 1: on)
- double center_x, center_y; // (center of the arc)
- int x1, y1; // (Fig units, the 1st point the user entered)
- int x2, y2; // (Fig units, the 2nd point)
- int x3, y3; // (Fig units, the last point)
- ScTextStream Code(&tmp, QIODevice::ReadOnly);
- Code >> command >> subtype >> line_style >> thickness >> pen_color >> fill_color >> depth >> pen_style;
- Code >> area_fill >> style_val >> cap_style >> direction >> forward_arrow >> backward_arrow;
- Code >> center_x >> center_y >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
- if (forward_arrow == 1)
- fArrowData = readLinefromDataStream(ts);
- if (backward_arrow == 1)
- bArrowData = readLinefromDataStream(ts);
- useColor(pen_color, 0, false);
- useColor(fill_color, area_fill, true);
- LineW = thickness / 80.0 * 72.0;
- int z = -1;
- PageItem *ite;
- if (subtype == 1)
- z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
- else if (subtype == 2)
- z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
- else
- z = -1;
- center_x = fig2Pts(center_x) - docX;
- center_y = fig2Pts(center_y) - docY;
- double x1R = fig2Pts(x1) - docX;
- double y1R = fig2Pts(y1) - docY;
- double x3R = fig2Pts(x3) - docX;
- double y3R = fig2Pts(y3) - docY;
- double r1 = distance(x1R - center_x, y1R - center_y);
- double x0 = center_x - r1;
- double y0 = center_y - r1;
- QRectF bBox = QRectF(x0, y0, r1 * 2.0, r1 * 2.0);
- double angle1 = -xy2Deg(x1R - center_x, y1R - center_y);
- double angle2 = -xy2Deg(x3R - center_x, y3R - center_y);
- double sweep;
- if (direction == 0)
- {
- sweep = angle1 - angle2;
- if (sweep < 0.0)
- sweep = 360.0 + sweep;
- }
- else
- {
- sweep = angle2 - angle1;
- if (sweep < 0.0)
- sweep = 360.0 + sweep;
- double an = angle1;
- angle1 = angle2;
- angle2 = an;
- }
- QPainterPath aPath;
- if (subtype == 1)
- {
- aPath.arcMoveTo(bBox, angle2);
- aPath.arcTo(bBox, angle2, sweep);
- }
- else
- {
- aPath.moveTo(center_x, center_y);
- aPath.arcTo(bBox, angle2, sweep);
- aPath.lineTo(center_x, center_y);
- }
- FPointArray points;
- points.fromQPainterPath(aPath);
-
- if (z >= 0)
- {
- ite = m_Doc->Items->at(z);
- ite->PoLine = points.copy();
- ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
- ite->ClipEdited = true;
- ite->FrameType = 3;
- ite->setFillShade(CurrFillShade);
- ite->setLineShade(CurrStrokeShade);
- if (line_style > 0)
- ite->setDashes(getDashValues(LineW, line_style));
- if (subtype == 1)
- {
- if (cap_style == 0)
- ite->setLineEnd(Qt::FlatCap);
- else if (cap_style == 1)
- ite->setLineEnd(Qt::RoundCap);
- else if (cap_style == 2)
- ite->setLineEnd(Qt::SquareCap);
- }
- FPoint wh = getMaxClipF(&ite->PoLine);
- ite->setWidthHeight(wh.x(),wh.y());
- ite->setTextFlowMode(PageItem::TextFlowDisabled);
- m_Doc->AdjustItemSize(ite);
- ite->setWidthHeight(qMax(ite->width(), 1.0), qMax(ite->height(), 1.0));
- depthMap.insert(999 - depth, currentItemNr);
- currentItemNr++;
- if ((ite->itemType() == PageItem::PolyLine) && ((forward_arrow == 1) || (backward_arrow == 1)))
- {
- if (direction == 1)
- processArrows(forward_arrow, fArrowData, backward_arrow, bArrowData, depth, ite);
- else
- processArrows(backward_arrow, bArrowData, forward_arrow, fArrowData, depth, ite);
- }
- }
-}
-
-void XfigPlug::processEllipse(QString data)
-{
- QString tmp = data;
- int command; // (always 1)
- int subtype; // (1: ellipse defined by radii
- // 2: ellipse defined by diameters
- // 3: circle defined by radius
- // 4: circle defined by diameter)
- int line_style; // (enumeration type)
- int thickness; // (1/80 inch)
- int pen_color; // (enumeration type, pen color)
- int fill_color; // (enumeration type, fill color)
- int depth; // (enumeration type)
- int pen_style; // (pen style, not used)
- int area_fill; // (enumeration type, -1 = no fill)
- double style_val; // (1/80 inch)
- int direction; // (always 1)
- double angle; // (radians, the angle of the x-axis)
- int center_x, center_y; // (Fig units)
- int radius_x, radius_y; // (Fig units)
- int start_x, start_y; // (Fig units; the 1st point entered)
- int end_x, end_y; // (Fig units; the last point entered)
- double x, y, w, h;
- ScTextStream Code(&tmp, QIODevice::ReadOnly);
- Code >> command >> subtype >> line_style >> thickness >> pen_color >> fill_color >> depth >> pen_style;
- Code >> area_fill >> style_val >> direction >> angle >> center_x >> center_y >> radius_x >> radius_y;
- Code >> start_x >> start_y >> end_x >> end_y;
- useColor(pen_color, 0, false);
- useColor(fill_color, area_fill, true);
- LineW = thickness / 80.0 * 72.0;
- w = fig2Pts(radius_x);
- h = fig2Pts(radius_y);
- x = fig2Pts(center_x) - w;
- y = fig2Pts(center_y) - h;
- w *= 2.0;
- h *= 2.0;
- x -= docX;
- x += m_Doc->currentPage()->xOffset();
- y -= docY;
- y += m_Doc->currentPage()->yOffset();
- int z = -1;
- PageItem *ite;
- z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, baseX + x, baseY + y, w, h, LineW, CurrColorFill, CurrColorStroke, true);
- if (z >= 0)
- {
- ite = m_Doc->Items->at(z);
- ite->setFillShade(CurrFillShade);
- ite->setLineShade(CurrStrokeShade);
- if (line_style > 0)
- ite->setDashes(getDashValues(LineW, line_style));
- ite->setTextFlowMode(PageItem::TextFlowDisabled);
- int rot = m_Doc->RotMode();
- m_Doc->RotMode ( 2);
- m_Doc->RotateItem(-angle * 180.0 / M_PI, ite);
- m_Doc->RotMode( rot);
- depthMap.insert(999 - depth, currentItemNr);
- currentItemNr++;
- }
-}
-
-QString XfigPlug::cleanText(QString text)
-{
- QString ret = "";
- QString tmp = "";
- bool sep = false;
- int sepcount = 0;
- for (int a = 1; a < text.count(); ++a)
- {
- QString ch = text.mid(a,1);
- if (sep)
- {
- if (ch == "\\")
- {
- ret += ch;
- sep = false;
- }
- else
- {
- tmp += ch;
- sepcount++;
- if (sepcount == 3)
- {
- sep = false;
- bool ok = false;
- if (tmp != "001")
- {
- int code = tmp.toInt(&ok, 8);
- if (ok)
- ret += QChar(code);
- }
- tmp = "";
- }
- }
- }
- else
- {
- if (ch == "\\")
- {
- sep = true;
- sepcount = 0;
- }
- else
- ret += ch;
- }
- }
- return ret;
-}
-
-void XfigPlug::processText(QString data)
-{
- QString tmp = data;
- int command; // (always 4)
- int subtype; // (0: Left justified
- // 1: Center justified
- // 2: Right justified)
- int color; // (enumeration type)
- int depth; // (enumeration type)
- int pen_style; // (enumeration , not used)
- int font; // (enumeration type)
- float font_size; // (font size in points)
- float angle; // (radians, the angle of the text)
- int font_flags; // (bit vector)
- float height; // (Fig units)
- float length; // (Fig units)
- int xT, yT; // (Fig units, coordinate of the origin
- // of the string. If sub_type = 0, it is
- // the lower left corner of the string.
- // If sub_type = 1, it is the lower
- // center. Otherwise it is the lower
- // right corner of the string.)
- QString text;
- double x, y, w, h;
- ScTextStream Code(&tmp, QIODevice::ReadOnly);
- Code >> command >> subtype >> color >> depth >> pen_style >> font >> font_size >> angle;
- Code >> font_flags >> height >> length >> xT >> yT;
- text = Code.readAll();
- text = cleanText(text);
- FPointArray textPath;
- QPainterPath painterPath;
- QString TFont = m_Doc->toolSettings.defFont;
- QFont::Weight weight = QFont::Normal;
- bool isItalic = false;
- if (font_flags & 4)
- {
- switch (font)
- {
- case 0:
- TFont = "Times Roman";
- weight = QFont::Normal;
- break;
- case 1:
- TFont = "Times Italic";
- weight = QFont::Normal;
- isItalic = true;
- break;
- case 2:
- TFont = "Times Bold";
- weight = QFont::Bold;
- break;
- case 3:
- TFont = "Times Bold Italic";
- weight = QFont::Bold;
- isItalic = true;
- break;
- case 4:
- TFont = "AvantGarde Book";
- weight = QFont::Normal;
- break;
- case 5:
- TFont = "AvantGarde Book Oblique";
- weight = QFont::Normal;
- break;
- case 6:
- TFont = "AvantGarde Demi";
- weight = QFont::DemiBold;
- break;
- case 7:
- TFont = "AvantGarde Demi Oblique";
- weight = QFont::DemiBold;
- break;
- case 8:
- TFont = "Bookman Light";
- weight = QFont::Light;
- break;
- case 9:
- TFont = "Bookman Light Italic";
- weight = QFont::Light;
- isItalic = true;
- break;
- case 10:
- TFont = "Bookman Demi";
- weight = QFont::DemiBold;
- break;
- case 11:
- TFont = "Bookman Demi Italic";
- weight = QFont::DemiBold;
- isItalic = true;
- break;
- case 12:
- TFont = "Courier";
- weight = QFont::Normal;
- break;
- case 13:
- TFont = "Courier Oblique";
- weight = QFont::Normal;
- break;
- case 14:
- TFont = "Courier Bold";
- weight = QFont::Bold;
- break;
- case 15:
- TFont = "Courier Bold Oblique";
- weight = QFont::Bold;
- break;
- case 16:
- TFont = "Helvetica";
- weight = QFont::Normal;
- break;
- case 17:
- TFont = "Helvetica Oblique";
- weight = QFont::Normal;
- break;
- case 18:
- TFont = "Helvetica Bold";
- weight = QFont::Bold;
- break;
- case 19:
- TFont = "Helvetica Bold Oblique";
- weight = QFont::Bold;
- break;
- case 20:
- TFont = "Helvetica Narrow";
- weight = QFont::Normal;
- break;
- case 21:
- TFont = "Helvetica Narrow Oblique";
- weight = QFont::Normal;
- break;
- case 22:
- TFont = "Helvetica Narrow Bold";
- weight = QFont::Bold;
- break;
- case 23:
- TFont = "Helvetica Narrow Bold Oblique";
- weight = QFont::Bold;
- break;
- case 24:
- TFont = "New Century Schoolbook Roman";
- weight = QFont::Normal;
- break;
- case 25:
- TFont = "New Century Schoolbook Italic";
- weight = QFont::Normal;
- isItalic = true;
- break;
- case 26:
- TFont = "New Century Schoolbook Bold";
- weight = QFont::Bold;
- break;
- case 27:
- TFont = "New Century Schoolbook Bold Italic";
- weight = QFont::Bold;
- isItalic = true;
- break;
- case 28:
- TFont = "Palatino Roman";
- weight = QFont::Normal;
- break;
- case 29:
- TFont = "Palatino Italic";
- weight = QFont::Normal;
- isItalic = true;
- break;
- case 30:
- TFont = "Palatino Bold";
- weight = QFont::Bold;
- break;
- case 31:
- TFont = "Palatino Bold Italic";
- weight = QFont::Bold;
- isItalic = true;
- break;
- case 32:
- TFont = "Symbol";
- weight = QFont::Normal;
- break;
- case 33:
- TFont = "Zapf Chancery Medium Italic";
- weight = QFont::Normal;
- isItalic = true;
- break;
- case 34:
- TFont = "Zapf Dingbats";
- weight = QFont::Normal;
- break;
- default:
- TFont = m_Doc->toolSettings.defFont;
- weight = QFont::Normal;
- break;
- }
- }
- else
- {
- switch (font)
- {
- case 1: // Roman
- TFont = "Times";
- weight = QFont::Normal;
- break;
- case 2: // Bold
- TFont = "Times";
- weight = QFont::Bold;
- break;
- case 3: // Italic
- TFont = "Times";
- weight = QFont::Normal;
- isItalic = true;
- break;
- case 4: // Sans Serif
- TFont = "Helvetica";
- weight = QFont::Normal;
- break;
- case 5: // Typewriter
- TFont = "Courier";
- weight = QFont::Normal;
- break;
- default:
- TFont = m_Doc->toolSettings.defFont;
- weight = QFont::Normal;
- break;
- }
- }
- w = fig2Pts(length);
- h = fig2Pts(height);
- x = fig2Pts(xT);
- y = fig2Pts(yT);
- x -= docX;
- x += m_Doc->currentPage()->xOffset();
- y -= docY;
- y += m_Doc->currentPage()->yOffset();
- QFont tf = QFont(TFont, 10, weight, isItalic);
- tf.setPointSizeF(font_size / 80.0 * 72.0);
- painterPath.addText( 0, 0, tf, text );
- QRectF br = painterPath.boundingRect();
- if ((angle == 0) && (br.width() > w))
- {
- QMatrix m;
- m.scale(w / br.width(), w / br.width());
- painterPath = m.map(painterPath);
- }
- textPath.fromQPainterPath(painterPath);
- useColor(color, 0, false);
- int z = -1;
- PageItem *ite;
- z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX + x, baseY + y, w, h, 0, CurrColorStroke, CommonStrings::None, true);
- if (z >= 0)
- {
- ite = m_Doc->Items->at(z);
- ite->setRotation(-angle * 180.0 / M_PI);
- ite->PoLine = textPath.copy();
- ite->ClipEdited = true;
- ite->FrameType = 3;
- FPoint wh = getMaxClipF(&ite->PoLine);
- ite->setWidthHeight(wh.x(),wh.y());
- ite->setTextFlowMode(PageItem::TextFlowDisabled);
- m_Doc->AdjustItemSize(ite);
- ite->setWidthHeight(qMax(ite->width(), 1.0), qMax(ite->height(), 1.0));
- if (subtype == 1)
- m_Doc->MoveRotated(ite, FPoint(-br.width() / 2.0, 0.0));
- else if (subtype == 2)
- m_Doc->MoveRotated(ite, FPoint(-br.width(), 0.0));
- depthMap.insert(999 - depth, currentItemNr);
- currentItemNr++;
- }
-}
-
-void XfigPlug::processData(QDataStream &ts, QString data)
-{
- QString tmp = data;
- int command, subtype;
- ScTextStream Code(&tmp, QIODevice::ReadOnly);
- Code >> command >> subtype;
- switch (command)
- {
- case 0:
- parseColor(data);
- break;
- case 1:
- processEllipse(data);
- break;
- case 2:
- processPolyline(ts, data);
- break;
- case 3:
- processSpline(ts, data);
- break;
- case 4:
- processText(data);
- break;
- case 5:
- processArc(ts, data);
- break;
- case 6:
-// qDebug() << "Xfig-Import:: Unsupported Compound object";
- break;
- case -6:
-// qDebug() << "Xfig-Import:: Unsupported End of Compound object";
- break;
- }
-}
-
-void XfigPlug::resortItems()
-{
- int ac = m_Doc->Items->count();
- QList<PageItem*> itemList;
- for (int as = oldDocItemCount; as < ac; ++as)
- {
- itemList.append(m_Doc->Items->takeAt(oldDocItemCount));
- }
- QList<int> keylist = depthMap.uniqueKeys();
- int keysCount = keylist.count();
- int currentLayer = 0;
- for (int it = 0; it < keysCount; ++it)
- {
- if ((importerFlags & LoadSavePlugin::lfCreateDoc) && (it > 0))
- currentLayer = m_Doc->addLayer(QString("Layer %1").arg(it), true);
- QList<int> elems = depthMap.values(keylist.at(it));
- qSort(elems);
- int itemsCount = elems.count();
- for (int i = 0; i < itemsCount; ++i)
- {
- PageItem* ite = itemList.at(elems.at(i));
- Elements.append(ite);
- m_Doc->Items->append(ite);
- ite->ItemNr = m_Doc->Items->count()-1;
- if ((importerFlags & LoadSavePlugin::lfCreateDoc) && (it > 0))
- ite->LayerID = currentLayer;
- }
- }
-}
-
-
-double XfigPlug::fig2Pts(double in)
-{
- return in / 1200.0 * 72.0;
-}
-
-bool XfigPlug::convert(QString fn)
-{
- QString tmp;
- CurrColorFill = "White";
- CurrFillShade = 100.0;
- CurrColorStroke = "Black";
- CurrStrokeShade = 100.0;
- patternMode = false;
- patternX1 = 0.0;
- patternY1 = 0.0;
- patternX2 = 0.0;
- patternY2 = 0.0;
- Coords.resize(0);
- Coords.svgInit();
- clipCoords.resize(0);
- clipCoords.svgInit();
- currentPatternName = "";
- currentPatternX = 0.0;
- currentPatternY = 0.0;
- currentPatternXScale = 1.0;
- currentPatternYScale = 1.0;
- currentPatternRotation = 0.0;
- QList<PageItem*> gElements;
- groupStack.push(gElements);
- currentItemNr = 0;
- if(progressDialog)
- {
- progressDialog->setOverallProgress(2);
- progressDialog->setLabel("GI", tr("Generating Items"));
- qApp->processEvents();
- }
- QFile f(fn);
- if (f.open(QIODevice::ReadOnly))
- {
- oldDocItemCount = m_Doc->Items->count();
- int fSize = (int) f.size();
- if (progressDialog)
- {
- progressDialog->setTotalSteps("GI", fSize);
- qApp->processEvents();
- }
- QDataStream ts(&f);
- QString version = readLinefromDataStream(ts);
- QString orientation = readLinefromDataStream(ts);
- QString justification = readLinefromDataStream(ts);
- QString units = readLinefromDataStream(ts);
- QString papersize = readLinefromDataStream(ts);
- QString magnification = readLinefromDataStream(ts);
- QString multiple = readLinefromDataStream(ts);
- QString transparent = readLinefromDataStream(ts);
- tmp = readLinefromDataStream(ts);
- if (tmp.startsWith("#"))
- tmp = readLinefromDataStream(ts);
- QString resolution = tmp;
- while (!ts.atEnd())
- {
- tmp = readLinefromDataStream(ts);
- if (tmp.startsWith("#"))
- continue;
- processData(ts, tmp);
- progressDialog->setProgress("GI", ts.device()->pos());
- qApp->processEvents();
- }
- resortItems();
- }
- if (progressDialog)
- progressDialog->close();
- return true;
-}
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#include <QByteArray>
+#include <QCursor>
+#include <QDrag>
+#include <QFile>
+#include <QList>
+#include <QMimeData>
+#include <QRegExp>
+#include <QStack>
+#include <QDebug>
+
+#include <cmath>
+#include <cstdlib>
+
+#include "commonstrings.h"
+#include "ui/customfdialog.h"
+#include "importxfig.h"
+#include "loadsaveplugin.h"
+#include "ui/missing.h"
+#include "ui/multiprogressdialog.h"
+#include "pagesize.h"
+#include "pageitem.h"
+#include "prefscontext.h"
+#include "prefsfile.h"
+#include "prefsmanager.h"
+#include "prefsmanager.h"
+#include "prefstable.h"
+#include "ui/propertiespalette.h"
+#include "rawimage.h"
+#include "scclocale.h"
+#include "sccolorengine.h"
+#include "scconfig.h"
+#include "scmimedata.h"
+#include "scpaths.h"
+#include "scpattern.h"
+#include "scpattern.h"
+#include "scribus.h"
+#include "scribusXml.h"
+#include "scribuscore.h"
+#include "sctextstream.h"
+#include "selection.h"
+#include "undomanager.h"
+#include "util.h"
+#include "util_formats.h"
+#include "util_icon.h"
+#include "util_math.h"
+
+extern SCRIBUS_API ScribusQApp * ScQApp;
+
+XfigPlug::XfigPlug(ScribusDoc* doc, int flags)
+{
+ tmpSel=new Selection(this, false);
+ m_Doc=doc;
+ interactive = (flags & LoadSavePlugin::lfInteractive);
+}
+
+bool XfigPlug::import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
+{
+ QString fName = fNameIn;
+ bool success = false;
+ interactive = (flags & LoadSavePlugin::lfInteractive);
+ importerFlags = flags;
+ cancel = false;
+ double x, y, b, h;
+ bool ret = false;
+ CustColors.clear();
+ importedColors.insert(0, "Black");
+ importedColors.insert(1, "Blue");
+ importedColors.insert(2, "Green");
+ importedColors.insert(3, "Cyan");
+ importedColors.insert(4, "Red");
+ importedColors.insert(5, "Magenta");
+ importedColors.insert(6, "Yellow");
+ importedColors.insert(7, "White");
+ importedColors.insert(8, "Blue4");
+ importedColors.insert(9, "Blue3");
+ importedColors.insert(10, "Blue2");
+ importedColors.insert(11, "LtBlue");
+ importedColors.insert(12, "Green4");
+ importedColors.insert(13, "Green3");
+ importedColors.insert(14, "Green2");
+ importedColors.insert(15, "Cyan4");
+ importedColors.insert(16, "Cyan3");
+ importedColors.insert(17, "Cyan2");
+ importedColors.insert(18, "Red4");
+ importedColors.insert(19, "Red3");
+ importedColors.insert(20, "Red2");
+ importedColors.insert(21, "Magenta4");
+ importedColors.insert(22, "Magenta3");
+ importedColors.insert(23, "Magenta2");
+ importedColors.insert(24, "Brown4");
+ importedColors.insert(25, "Brown3");
+ importedColors.insert(26, "Brown2");
+ importedColors.insert(27, "Pink4");
+ importedColors.insert(28, "Pink3");
+ importedColors.insert(29, "Pink2");
+ importedColors.insert(30, "Pink");
+ importedColors.insert(31, "Gold");
+ CustColors.insert("Blue", ScColor(255, 0, 0, 0));
+ CustColors.insert("Blue4", ScColor(0, 0, 144));
+ CustColors.insert("Blue3", ScColor(0, 0, 176));
+ CustColors.insert("Blue2", ScColor(0, 0, 208));
+ CustColors.insert("LtBlue", ScColor(135, 206, 255));
+ CustColors.insert("Cyan", ScColor(255, 0, 0, 0));
+ CustColors.insert("Cyan4", ScColor(0, 144, 144));
+ CustColors.insert("Cyan3", ScColor(0, 176, 176));
+ CustColors.insert("Cyan2", ScColor(0, 208, 208));
+ CustColors.insert("Green", ScColor(255, 0, 255, 0));
+ CustColors.insert("Green4", ScColor(0, 144, 0));
+ CustColors.insert("Green3", ScColor(0, 176, 0));
+ CustColors.insert("Green2", ScColor(0, 208, 0));
+ CustColors.insert("Red", ScColor(0, 255, 255, 0));
+ CustColors.insert("Red4", ScColor(144, 0, 0));
+ CustColors.insert("Red3", ScColor(176, 0, 0));
+ CustColors.insert("Red2", ScColor(208, 0, 0));
+ CustColors.insert("Yellow", ScColor(0, 0, 255, 0));
+ CustColors.insert("Magenta", ScColor(0, 255, 0, 0));
+ CustColors.insert("Magenta4", ScColor(144, 0, 144));
+ CustColors.insert("Magenta3", ScColor(176, 0, 176));
+ CustColors.insert("Magenta2", ScColor(208, 0, 208));
+ CustColors.insert("Brown4", ScColor(128, 48, 0));
+ CustColors.insert("Brown3", ScColor(160, 64, 0));
+ CustColors.insert("Brown2", ScColor(192, 96, 0));
+ CustColors.insert("Pink4", ScColor(255, 128, 128));
+ CustColors.insert("Pink3", ScColor(255, 160, 160));
+ CustColors.insert("Pink2", ScColor(255, 192, 192));
+ CustColors.insert("Pink", ScColor(255, 224, 224));
+ CustColors.insert("Gold", ScColor(255, 215, 0));
+ QFileInfo fi = QFileInfo(fName);
+ if ( !ScCore->usingGUI() )
+ {
+ interactive = false;
+ showProgress = false;
+ }
+ baseFile = QDir::cleanPath(QDir::toNativeSeparators(fi.absolutePath()+"/"));
+ if ( showProgress )
+ {
+ ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
+ progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw );
+ QStringList barNames, barTexts;
+ barNames << "GI";
+ barTexts << tr("Analyzing File:");
+ QList<bool> barsNumeric;
+ barsNumeric << false;
+ progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
+ progressDialog->setOverallTotalSteps(3);
+ progressDialog->setOverallProgress(0);
+ progressDialog->setProgress("GI", 0);
+ progressDialog->show();
+ connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
+ qApp->processEvents();
+ }
+ else
+ progressDialog = NULL;
+/* Set default Page to size defined in Preferences */
+ x = 0.0;
+ y = 0.0;
+ b = 0.0;
+ h = 0.0;
+ if (progressDialog)
+ {
+ progressDialog->setOverallProgress(1);
+ qApp->processEvents();
+ }
+ parseHeader(fName, x, y, b, h);
+ docX = x;
+ docY = y;
+ if (b == 0.0)
+ b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth;
+ if (h == 0.0)
+ h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight;
+ docWidth = b - x;
+ docHeight = h - y;
+ baseX = 0;
+ baseY = 0;
+ if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
+ {
+ m_Doc->setPage(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false);
+ m_Doc->addPage(0);
+ m_Doc->view()->addPage(0, true);
+ baseX = 0;
+ baseY = 0;
+ }
+ else
+ {
+ if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
+ {
+ m_Doc=ScCore->primaryMainWindow()->doFileNew(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
+ ScCore->primaryMainWindow()->HaveNewDoc();
+ ret = true;
+ baseX = 0;
+ baseY = 0;
+ }
+ }
+ if (flags & LoadSavePlugin::lfCreateDoc)
+ {
+ m_Doc->documentInfo.setAuthor(docCreator);
+ m_Doc->documentInfo.setPublisher(docOrganisation);
+ m_Doc->documentInfo.setTitle(docTitle);
+ m_Doc->documentInfo.setDate(docDate+" "+docTime);
+ }
+ if ((!ret) && (interactive))
+ {
+ baseX = m_Doc->currentPage()->xOffset();
+ baseY = m_Doc->currentPage()->yOffset();
+ }
+ if ((ret) || (!interactive))
+ {
+ if (b-x > h-y)
+ m_Doc->PageOri = 1;
+ else
+ m_Doc->PageOri = 0;
+ m_Doc->m_pageSize = "Custom";
+ }
+ Elements.clear();
+ FPoint minSize = m_Doc->minCanvasCoordinate;
+ FPoint maxSize = m_Doc->maxCanvasCoordinate;
+ FPoint cOrigin = m_Doc->view()->canvasOrigin();
+ m_Doc->setLoading(true);
+ m_Doc->DoDrawing = false;
+ m_Doc->view()->updatesOn(false);
+ m_Doc->scMW()->ScriptRunning = true;
+ qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
+ QString CurDirP = QDir::currentPath();
+ QDir::setCurrent(fi.path());
+ if (convert(fName))
+ {
+ tmpSel->clear();
+ QDir::setCurrent(CurDirP);
+ if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc)))
+ {
+ bool isGroup = true;
+ int firstElem = -1;
+ if (Elements.at(0)->Groups.count() != 0)
+ firstElem = Elements.at(0)->Groups.top();
+ for (int bx = 0; bx < Elements.count(); ++bx)
+ {
+ PageItem* bxi = Elements.at(bx);
+ if (bxi->Groups.count() != 0)
+ {
+ if (bxi->Groups.top() != firstElem)
+ isGroup = false;
+ }
+ else
+ isGroup = false;
+ }
+ if (!isGroup)
+ {
+ double minx = 99999.9;
+ double miny = 99999.9;
+ double maxx = -99999.9;
+ double maxy = -99999.9;
+ uint lowestItem = 999999;
+ uint highestItem = 0;
+ for (int a = 0; a < Elements.count(); ++a)
+ {
+ Elements.at(a)->Groups.push(m_Doc->GroupCounter);
+ PageItem* currItem = Elements.at(a);
+ lowestItem = qMin(lowestItem, currItem->ItemNr);
+ highestItem = qMax(highestItem, currItem->ItemNr);
+ double x1, x2, y1, y2;
+ currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
+ minx = qMin(minx, x1);
+ miny = qMin(miny, y1);
+ maxx = qMax(maxx, x2);
+ maxy = qMax(maxy, y2);
+ }
+ double gx = minx;
+ double gy = miny;
+ double gw = maxx - minx;
+ double gh = maxy - miny;
+ PageItem *high = m_Doc->Items->at(highestItem);
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, m_Doc->toolSettings.dBrush, m_Doc->toolSettings.dPen, true);
+ PageItem *neu = m_Doc->Items->takeAt(z);
+ m_Doc->Items->insert(lowestItem, neu);
+ neu->Groups.push(m_Doc->GroupCounter);
+ neu->setItemName( tr("Group%1").arg(neu->Groups.top()));
+ neu->AutoName = false;
+ neu->isGroupControl = true;
+ neu->groupsLastItem = high;
+ neu->setTextFlowMode(PageItem::TextFlowDisabled);
+ for (int a = 0; a < m_Doc->Items->count(); ++a)
+ {
+ m_Doc->Items->at(a)->ItemNr = a;
+ }
+ Elements.prepend(neu);
+ m_Doc->GroupCounter++;
+ }
+ }
+ m_Doc->DoDrawing = true;
+ m_Doc->scMW()->ScriptRunning = false;
+ m_Doc->setLoading(false);
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ if ((Elements.count() > 0) && (!ret) && (interactive))
+ {
+ if (flags & LoadSavePlugin::lfScripted)
+ {
+ bool loadF = m_Doc->isLoading();
+ m_Doc->setLoading(false);
+ m_Doc->changed();
+ m_Doc->setLoading(loadF);
+ m_Doc->m_Selection->delaySignalsOn();
+ for (int dre=0; dre<Elements.count(); ++dre)
+ {
+ m_Doc->m_Selection->addItem(Elements.at(dre), true);
+ }
+ m_Doc->m_Selection->delaySignalsOff();
+ m_Doc->m_Selection->setGroupRect();
+ m_Doc->view()->updatesOn(true);
+ }
+ else
+ {
+ m_Doc->DragP = true;
+ m_Doc->DraggedElem = 0;
+ m_Doc->DragElements.clear();
+ m_Doc->m_Selection->delaySignalsOn();
+ for (int dre=0; dre<Elements.count(); ++dre)
+ {
+ m_Doc->DragElements.append(Elements.at(dre)->ItemNr);
+ tmpSel->addItem(Elements.at(dre), true);
+ }
+ tmpSel->setGroupRect();
+ ScriXmlDoc *ss = new ScriXmlDoc();
+ ScElemMimeData* md = new ScElemMimeData();
+ md->setScribusElem(ss->WriteElem(m_Doc, m_Doc->view(), tmpSel));
+ delete ss;
+/*#ifndef Q_WS_MAC*/
+// see #2196
+ m_Doc->itemSelection_DeleteItem(tmpSel);
+/*#else
+ qDebug("xfigimport: leaving items on page");
+#endif*/
+ m_Doc->view()->updatesOn(true);
+ m_Doc->m_Selection->delaySignalsOff();
+ // We must copy the TransationSettings object as it is owned
+ // by handleObjectImport method afterwards
+ TransactionSettings* transacSettings = new TransactionSettings(trSettings);
+ m_Doc->view()->handleObjectImport(md, transacSettings);
+ m_Doc->DragP = false;
+ m_Doc->DraggedElem = 0;
+ m_Doc->DragElements.clear();
+ }
+ }
+ else
+ {
+ m_Doc->changed();
+ m_Doc->reformPages();
+ m_Doc->view()->updatesOn(true);
+ }
+ success = true;
+ }
+ else
+ {
+ QDir::setCurrent(CurDirP);
+ m_Doc->DoDrawing = true;
+ m_Doc->scMW()->ScriptRunning = false;
+ m_Doc->view()->updatesOn(true);
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ }
+ if (interactive)
+ m_Doc->setLoading(false);
+ //CB If we have a gui we must refresh it if we have used the progressbar
+ if ((showProgress) && (!interactive))
+ m_Doc->view()->DrawNew();
+ return success;
+}
+
+XfigPlug::~XfigPlug()
+{
+ if (progressDialog)
+ delete progressDialog;
+ delete tmpSel;
+}
+
+bool XfigPlug::parseHeader(QString fName, double &x, double &y, double &b, double &h)
+{
+ QString tmp, BBox, tmp2, FarNam;
+ ScColor cc;
+ bool found = false;
+ QFile f(fName);
+ if (f.open(QIODevice::ReadOnly))
+ {
+ QDataStream ts(&f);
+ QString version = readLinefromDataStream(ts);
+ if (!version.startsWith("#FIG 3"))
+ {
+ f.close();
+ return false;
+ }
+ QString orientation = readLinefromDataStream(ts);
+ QString justification = readLinefromDataStream(ts);
+ QString units = readLinefromDataStream(ts);
+ QString papersize = readLinefromDataStream(ts);
+ PageSize ps(papersize);
+ if (orientation.startsWith("Landscape"))
+ {
+ h = ps.width();
+ b = ps.height();
+ }
+ else
+ {
+ b = ps.width();
+ h = ps.height();
+ }
+ f.close();
+ found = true;
+ }
+ return found;
+}
+
+void XfigPlug::parseColor(QString data)
+{
+ if (data.isEmpty())
+ return;
+ int colorNum, dummy;
+ QString colorValues;
+ ScColor tmp;
+ ScTextStream Code(&data, QIODevice::ReadOnly);
+ Code >> dummy >> colorNum >> colorValues;
+ tmp.setNamedColor(colorValues);
+ tmp.setSpotColor(false);
+ tmp.setRegistrationColor(false);
+ QString namPrefix = "FromXfig%1-"+colorValues;
+ CustColors.insert(namPrefix.arg(colorNum), tmp);
+ importedColors.insert(colorNum, namPrefix.arg(colorNum));
+}
+
+void XfigPlug::useColor(int colorNum, int area_fill, bool forFill)
+{
+ QString color = CommonStrings::None;
+ int shade = 100;
+ if (forFill)
+ {
+ if (area_fill == -1)
+ color = CommonStrings::None;
+ else
+ {
+ if ((colorNum == -1) || (colorNum == 0))
+ {
+ if (area_fill == 0)
+ {
+ color = "White";
+ shade = 100;
+ }
+ else if (area_fill == 20)
+ {
+ color = "Black";
+ shade = 100;
+ }
+ else if ((area_fill > 0) && (area_fill < 20))
+ {
+ color = "Black";
+ shade = qRound(100.0 / 19.0 * area_fill);
+ }
+ }
+ else if (colorNum == 7)
+ {
+ if (area_fill == 0)
+ {
+ color = "Black";
+ shade = 100;
+ }
+ else if (area_fill == 20)
+ {
+ color = "White";
+ shade = 100;
+ }
+ else if ((area_fill > 0) && (area_fill < 20))
+ {
+ color = "Black";
+ shade = qRound(100.0 / 19.0 * (20 - area_fill));
+ }
+ }
+ else
+ {
+ if (importedColors.contains(colorNum))
+ {
+ color = importedColors[colorNum];
+ if (!m_Doc->PageColors.contains(color))
+ m_Doc->PageColors.insert(color, CustColors[color]);
+ int sat = area_fill - 20;
+ if ((sat > 0) && (sat < 20))
+ shade = qRound(100.0 / 19.0 * sat);
+ }
+ else
+ color = CommonStrings::None;
+ }
+ }
+ CurrColorFill = color;
+ CurrFillShade = shade;
+ }
+ else
+ {
+ if (area_fill == -1)
+ CurrColorStroke = CommonStrings::None;
+ else
+ {
+ if ((colorNum == -1) || (colorNum == 0))
+ CurrColorStroke = "Black";
+ else
+ {
+ if (importedColors.contains(colorNum))
+ {
+ CurrColorStroke = importedColors[colorNum];
+ if (!m_Doc->PageColors.contains(CurrColorStroke))
+ m_Doc->PageColors.insert(CurrColorStroke, CustColors[CurrColorStroke]);
+ }
+ else
+ CurrColorStroke = CommonStrings::None;
+ }
+ }
+ }
+}
+
+QVector<double> XfigPlug::getDashValues(double linewidth, int code)
+{
+ QVector<double> tmp;
+ if (code == 1)
+ {
+ tmp << qMax(4.0 * linewidth, 0.1);
+ tmp << qMax(2.0 * linewidth, 0.1);
+ }
+ else if (code == 2)
+ {
+ tmp << qMax(1.0 * linewidth, 0.1);
+ tmp << qMax(2.0 * linewidth, 0.1);
+ }
+ else if (code == 3)
+ {
+ tmp << qMax(4.0 * linewidth, 0.1);
+ tmp << qMax(2.0 * linewidth, 0.1);
+ tmp << qMax(1.0 * linewidth, 0.1);
+ tmp << qMax(2.0 * linewidth, 0.1);
+ }
+ else if (code == 4)
+ {
+ tmp << qMax(4.0 * linewidth, 0.1);
+ tmp << qMax(2.0 * linewidth, 0.1);
+ tmp << qMax(1.0 * linewidth, 0.1);
+ tmp << qMax(2.0 * linewidth, 0.1);
+ tmp << qMax(1.0 * linewidth, 0.1);
+ tmp << qMax(2.0 * linewidth, 0.1);
+ }
+ else if (code == 5)
+ {
+ tmp << qMax(4.0 * linewidth, 0.1);
+ tmp << qMax(2.0 * linewidth, 0.1);
+ tmp << qMax(1.0 * linewidth, 0.1);
+ tmp << qMax(2.0 * linewidth, 0.1);
+ tmp << qMax(1.0 * linewidth, 0.1);
+ tmp << qMax(2.0 * linewidth, 0.1);
+ tmp << qMax(1.0 * linewidth, 0.1);
+ tmp << qMax(2.0 * linewidth, 0.1);
+ }
+ return tmp;
+}
+
+void XfigPlug::processArrows(int forward_arrow, QString fArrowData, int backward_arrow, QString bArrowData, int depth, PageItem *ite)
+{
+ int arrow_typeAF; // (enumeration type)
+ int arrow_styleAF; // (enumeration type)
+ float arrow_thicknessAF; // (1/80 inch)
+ float arrow_widthAF; // (Fig units)
+ float arrow_heightAF; // (Fig units)
+ int arrow_typeAB; // (enumeration type)
+ int arrow_styleAB; // (enumeration type)
+ float arrow_thicknessAB; // (1/80 inch)
+ float arrow_widthAB; // (Fig units)
+ float arrow_heightAB; // (Fig units)
+ FPointArray arrow;
+ int z = -1;
+ PageItem::ItemType iteType;
+ if (forward_arrow == 1)
+ {
+ arrow.resize(0);
+ ScTextStream CodeAF(&fArrowData, QIODevice::ReadOnly);
+ CodeAF >> arrow_typeAF >> arrow_styleAF >> arrow_thicknessAF >> arrow_widthAF >> arrow_heightAF;
+ arrow_widthAF = fig2Pts(arrow_widthAF);
+ arrow_heightAF = fig2Pts(arrow_heightAF);
+ arrow_thicknessAF = arrow_thicknessAF / 80.0 * 72.0;
+ FPoint End = ite->PoLine.point(ite->PoLine.size()-2);
+ for (uint xx = ite->PoLine.size()-1; xx > 0; xx -= 2)
+ {
+ FPoint Vector = ite->PoLine.point(xx);
+ if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
+ {
+ double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
+ QTransform arrowTrans;
+ if (arrow_typeAF == 0)
+ arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5");
+ else if (arrow_typeAF == 1)
+ arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5 z");
+ else if (arrow_typeAF == 2)
+ arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5 L -0.7 0 z");
+ else if (arrow_typeAF == 3)
+ arrow.parseSVG("M -0.7, -0.5 L 0, 0 L -0.7, 0.5 L -1 0 z");
+ arrowTrans.translate(End.x(), End.y());
+ arrowTrans.rotate(r);
+ arrowTrans.scale(arrow_heightAF, arrow_widthAF);
+ arrow.map(arrowTrans);
+ break;
+ }
+ }
+ QString fillC = "White";
+ if (arrow_styleAF == 1)
+ fillC = CurrColorStroke;
+ if (arrow_typeAF == 0)
+ {
+ fillC = CommonStrings::None;
+ iteType = PageItem::PolyLine;
+ }
+ else
+ iteType = PageItem::Polygon;
+ z = m_Doc->itemAdd(iteType, PageItem::Unspecified, ite->xPos(), ite->yPos(), 10, 10, arrow_thicknessAF, fillC, CurrColorStroke, true);
+ if (z >= 0)
+ {
+ PageItem *item = m_Doc->Items->at(z);
+ item->PoLine = arrow.copy();
+ item->ClipEdited = true;
+ item->FrameType = 3;
+ item->setFillShade(CurrFillShade);
+ item->setLineShade(CurrStrokeShade);
+ FPoint wh = getMaxClipF(&item->PoLine);
+ item->setWidthHeight(wh.x(),wh.y());
+ item->setTextFlowMode(PageItem::TextFlowDisabled);
+ m_Doc->AdjustItemSize(item);
+ item->setWidthHeight(qMax(item->width(), 1.0), qMax(item->height(), 1.0));
+ depthMap.insert(999 - depth, currentItemNr);
+ currentItemNr++;
+ }
+ }
+ if (backward_arrow == 1)
+ {
+ arrow.resize(0);
+ ScTextStream CodeAB(&bArrowData, QIODevice::ReadOnly);
+ CodeAB >> arrow_typeAB >> arrow_styleAB >> arrow_thicknessAB >> arrow_widthAB >> arrow_heightAB;
+ arrow_widthAB = fig2Pts(arrow_widthAB);
+ arrow_heightAB = fig2Pts(arrow_heightAB);
+ arrow_thicknessAB = arrow_thicknessAB / 80.0 * 72.0;
+ FPointArray arrow;
+ FPoint Start = ite->PoLine.point(0);
+ for (uint xx = 1; xx < ite->PoLine.size(); xx += 2)
+ {
+ FPoint Vector = ite->PoLine.point(xx);
+ if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
+ {
+ double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
+ QTransform arrowTrans;
+ if (arrow_typeAB == 0)
+ arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5");
+ else if (arrow_typeAB == 1)
+ arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5 z");
+ else if (arrow_typeAB == 2)
+ arrow.parseSVG("M -1, -0.5 L 0, 0 L -1, 0.5 L -0.7 0 z");
+ else if (arrow_typeAB == 3)
+ arrow.parseSVG("M -0.7, -0.5 L 0, 0 L -0.7, 0.5 L -1 0 z");
+ arrowTrans.translate(Start.x(), Start.y());
+ arrowTrans.rotate(r);
+ arrowTrans.scale(arrow_heightAB, arrow_widthAB);
+ arrow.map(arrowTrans);
+ break;
+ }
+ }
+ QString fillC = "White";
+ if (arrow_styleAB == 1)
+ fillC = CurrColorStroke;
+ if (arrow_typeAB == 0)
+ {
+ fillC = CommonStrings::None;
+ iteType = PageItem::PolyLine;
+ }
+ else
+ iteType = PageItem::Polygon;
+ z = m_Doc->itemAdd(iteType, PageItem::Unspecified, ite->xPos(), ite->yPos(), 10, 10, arrow_thicknessAB, fillC, CurrColorStroke, true);
+ if (z >= 0)
+ {
+ PageItem *item = m_Doc->Items->at(z);
+ item->PoLine = arrow.copy();
+ item->ClipEdited = true;
+ item->FrameType = 3;
+ item->setFillShade(CurrFillShade);
+ item->setLineShade(CurrStrokeShade);
+ FPoint wh = getMaxClipF(&item->PoLine);
+ item->setWidthHeight(wh.x(),wh.y());
+ item->setTextFlowMode(PageItem::TextFlowDisabled);
+ m_Doc->AdjustItemSize(item);
+ item->setWidthHeight(qMax(item->width(), 1.0), qMax(item->height(), 1.0));
+ depthMap.insert(999 - depth, currentItemNr);
+ currentItemNr++;
+ }
+ }
+}
+
+void XfigPlug::processPolyline(QDataStream &ts, QString data)
+{
+ QString tmp = data;
+ QString fArrowData = "";
+ QString bArrowData = "";
+ int command;
+ int subtype; // (1: polyline, 2: box, 3: polygon, 4: arc-box, 5: imported-picture bounding-box)
+ int line_style; // (enumeration type)
+ int thickness; // (1/80 inch)
+ int pen_color; // (enumeration type, pen color)
+ int fill_color; // (enumeration type, fill color)
+ int depth; // (enumeration type)
+ int pen_style; // (pen style, not used)
+ int area_fill; // (enumeration type, -1 = no fill)
+ double style_val; // (1/80 inch)
+ int join_style; // (enumeration type)
+ int cap_style; // (enumeration type, only used for POLYLINE)
+ int radius; // (1/80 inch, radius of arc-boxes)
+ int forward_arrow; // (0: off, 1: on)
+ int backward_arrow; // (0: off, 1: on)
+ int npoints; // (number of points in line)
+ int pointsRead = 0;
+ int imgFlipped;
+ QString imgFile;
+ double x, y;
+ Coords.resize(0);
+ Coords.svgInit();
+ bool first = true;
+ ScTextStream Code(&tmp, QIODevice::ReadOnly);
+ Code >> command >> subtype >> line_style >> thickness >> pen_color >> fill_color >> depth >> pen_style;
+ Code >> area_fill >> style_val >> join_style >> cap_style >> radius >> forward_arrow >> backward_arrow >> npoints;
+ if (forward_arrow == 1)
+ fArrowData = readLinefromDataStream(ts);
+ if (backward_arrow == 1)
+ bArrowData = readLinefromDataStream(ts);
+ if (subtype == 5)
+ {
+ tmp = readLinefromDataStream(ts);
+ ScTextStream imf(&tmp, QIODevice::ReadOnly);
+ imf >> imgFlipped >> imgFile;
+ }
+ while (!ts.atEnd())
+ {
+ tmp = readLinefromDataStream(ts);
+ ScTextStream pts(&tmp, QIODevice::ReadOnly);
+ while (!pts.atEnd())
+ {
+ pts >> x >> y;
+ x = fig2Pts(x) - docX;
+ y = fig2Pts(y) - docY;
+ if (first)
+ {
+ Coords.svgMoveTo(x, y);
+ first = false;
+ }
+ else
+ Coords.svgLineTo(x, y);
+ pointsRead++;
+ }
+ if (pointsRead == npoints)
+ {
+ if (npoints == 1)
+ Coords.svgLineTo(x, y);
+ break;
+ }
+ }
+ useColor(pen_color, 0, false);
+ useColor(fill_color, area_fill, true);
+ LineW = thickness / 80.0 * 72.0;
+ int z = -1;
+ PageItem *ite;
+ if (subtype == 1)
+ z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ else if ((subtype == 2) || (subtype == 3) || (subtype == 4))
+ {
+ z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ Coords.svgClosePath();
+ }
+ else if (subtype == 5)
+ {
+ z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ Coords.svgClosePath();
+ }
+ else
+ z = -1;
+ if (z >= 0)
+ {
+ ite = m_Doc->Items->at(z);
+ ite->PoLine = Coords.copy();
+ ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ ite->ClipEdited = true;
+ ite->FrameType = 3;
+ ite->setFillShade(CurrFillShade);
+ ite->setLineShade(CurrStrokeShade);
+ if (line_style > 0)
+ ite->setDashes(getDashValues(LineW, line_style));
+ if (subtype == 1)
+ {
+ if (join_style == 0)
+ ite->setLineJoin(Qt::MiterJoin);
+ else if (join_style == 1)
+ ite->setLineJoin(Qt::RoundJoin);
+ else if (join_style == 2)
+ ite->setLineJoin(Qt::BevelJoin);
+ if (cap_style == 0)
+ ite->setLineEnd(Qt::FlatCap);
+ else if (cap_style == 1)
+ ite->setLineEnd(Qt::RoundCap);
+ else if (cap_style == 2)
+ ite->setLineEnd(Qt::SquareCap);
+ }
+ FPoint wh = getMaxClipF(&ite->PoLine);
+ ite->setWidthHeight(wh.x(),wh.y());
+ ite->setTextFlowMode(PageItem::TextFlowDisabled);
+ m_Doc->AdjustItemSize(ite);
+ ite->setWidthHeight(qMax(ite->width(), 1.0), qMax(ite->height(), 1.0));
+ if (subtype == 4)
+ {
+ ite->setCornerRadius(radius / 80.0 * 72.0);
+ ite->FrameType = 2;
+ ite->ClipEdited = false;
+ ite->updateClip();
+ }
+ if (subtype == 5)
+ {
+ ite->Pfile = baseFile + "/" + imgFile;
+ m_Doc->loadPict(ite->Pfile, ite, false);
+ ite->setImageXYScale(72.0 / 80.0, 72.0 / 80.0);
+ ite->setImageXYOffset(0, 0);
+ }
+ depthMap.insert(999 - depth, currentItemNr);
+ currentItemNr++;
+ if ((ite->itemType() == PageItem::PolyLine) && ((forward_arrow == 1) || (backward_arrow == 1)))
+ processArrows(forward_arrow, fArrowData, backward_arrow, bArrowData, depth, ite);
+ }
+}
+
+void XfigPlug::processSpline(QDataStream &ts, QString data)
+{
+ QString tmp = data;
+ QString fArrowData = "";
+ QString bArrowData = "";
+ int command;
+ int subtype; // 0: open approximated spline
+ // 1: closed approximated spline
+ // 2: open interpolated spline
+ // 3: closed interpolated spline
+ // 4: open x-spline
+ // 5: closed x-spline
+ int line_style; // (enumeration type)
+ int thickness; // (1/80 inch)
+ int pen_color; // (enumeration type, pen color)
+ int fill_color; // (enumeration type, fill color)
+ int depth; // (enumeration type)
+ int pen_style; // (pen style, not used)
+ int area_fill; // (enumeration type, -1 = no fill)
+ double style_val; // (1/80 inch)
+ int cap_style; // (enumeration type, only used for POLYLINE)
+ int forward_arrow; // (0: off, 1: on)
+ int backward_arrow; // (0: off, 1: on)
+ int npoints; // (number of points in line)
+ int pointsRead = 0;
+ double x, y;
+ Coords.resize(0);
+ Coords.svgInit();
+ bool first = true;
+ ScTextStream Code(&tmp, QIODevice::ReadOnly);
+ Code >> command >> subtype >> line_style >> thickness >> pen_color >> fill_color >> depth >> pen_style;
+ Code >> area_fill >> style_val >> cap_style >> forward_arrow >> backward_arrow >> npoints;
+ if (forward_arrow == 1)
+ fArrowData = readLinefromDataStream(ts);
+ if (backward_arrow == 1)
+ bArrowData = readLinefromDataStream(ts);
+ while (!ts.atEnd())
+ {
+ tmp = readLinefromDataStream(ts);
+ ScTextStream pts(&tmp, QIODevice::ReadOnly);
+ while (!pts.atEnd())
+ {
+ pts >> x >> y;
+ x = fig2Pts(x) - docX;
+ y = fig2Pts(y) - docY;
+ if (first)
+ {
+ Coords.svgMoveTo(x, y);
+ first = false;
+ }
+ else
+ Coords.svgLineTo(x, y);
+ pointsRead++;
+ }
+ if (pointsRead == npoints)
+ {
+ if (npoints == 1)
+ Coords.svgLineTo(x, y);
+ break;
+ }
+ }
+ pointsRead = 0;
+ while (!ts.atEnd())
+ {
+ tmp = readLinefromDataStream(ts);
+ ScTextStream pts(&tmp, QIODevice::ReadOnly);
+ while (!pts.atEnd())
+ {
+ pts >> x;
+ pointsRead++;
+ }
+ if (pointsRead == npoints)
+ break;
+ }
+ useColor(pen_color, 0, false);
+ useColor(fill_color, area_fill, true);
+ LineW = thickness / 80.0 * 72.0;
+ int z = -1;
+ PageItem *ite;
+ if ((subtype == 0) || (subtype == 2) || (subtype == 4))
+ z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ else if ((subtype == 1) || (subtype == 3) || (subtype == 5))
+ {
+ z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ Coords.svgClosePath();
+ }
+ if (z >= 0)
+ {
+ ite = m_Doc->Items->at(z);
+ ite->PoLine = Coords.copy();
+ ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ ite->ClipEdited = true;
+ ite->FrameType = 3;
+ ite->setFillShade(CurrFillShade);
+ ite->setLineShade(CurrStrokeShade);
+ if (line_style > 0)
+ ite->setDashes(getDashValues(LineW, line_style));
+ if ((subtype == 0) || (subtype == 2) || (subtype == 4))
+ {
+ if (cap_style == 0)
+ ite->setLineEnd(Qt::FlatCap);
+ else if (cap_style == 1)
+ ite->setLineEnd(Qt::RoundCap);
+ else if (cap_style == 2)
+ ite->setLineEnd(Qt::SquareCap);
+ }
+ FPoint wh = getMaxClipF(&ite->PoLine);
+ ite->setWidthHeight(wh.x(),wh.y());
+ ite->setTextFlowMode(PageItem::TextFlowDisabled);
+ m_Doc->AdjustItemSize(ite);
+ ite->setWidthHeight(qMax(ite->width(), 1.0), qMax(ite->height(), 1.0));
+ depthMap.insert(999 - depth, currentItemNr);
+ currentItemNr++;
+ if ((ite->itemType() == PageItem::PolyLine) && ((forward_arrow == 1) || (backward_arrow == 1)))
+ processArrows(forward_arrow, fArrowData, backward_arrow, bArrowData, depth, ite);
+ }
+}
+
+void XfigPlug::processArc(QDataStream &ts, QString data)
+{
+ QString tmp = data;
+ QString fArrowData = "";
+ QString bArrowData = "";
+ int command;
+ int subtype; // (1: open ended arc, 2: pie-wedge (closed))
+ int line_style; // (enumeration type)
+ int thickness; // (1/80 inch)
+ int pen_color; // (enumeration type, pen color)
+ int fill_color; // (enumeration type, fill color)
+ int depth; // (enumeration type)
+ int pen_style; // (pen style, not used)
+ int area_fill; // (enumeration type, -1 = no fill)
+ double style_val; // (1/80 inch)
+ int cap_style; // (enumeration type, only used for POLYLINE)
+ int direction; // (always 1)
+ int forward_arrow; // (0: off, 1: on)
+ int backward_arrow; // (0: off, 1: on)
+ double center_x, center_y; // (center of the arc)
+ int x1, y1; // (Fig units, the 1st point the user entered)
+ int x2, y2; // (Fig units, the 2nd point)
+ int x3, y3; // (Fig units, the last point)
+ ScTextStream Code(&tmp, QIODevice::ReadOnly);
+ Code >> command >> subtype >> line_style >> thickness >> pen_color >> fill_color >> depth >> pen_style;
+ Code >> area_fill >> style_val >> cap_style >> direction >> forward_arrow >> backward_arrow;
+ Code >> center_x >> center_y >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
+ if (forward_arrow == 1)
+ fArrowData = readLinefromDataStream(ts);
+ if (backward_arrow == 1)
+ bArrowData = readLinefromDataStream(ts);
+ useColor(pen_color, 0, false);
+ useColor(fill_color, area_fill, true);
+ LineW = thickness / 80.0 * 72.0;
+ int z = -1;
+ PageItem *ite;
+ if (subtype == 1)
+ z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ else if (subtype == 2)
+ z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ else
+ z = -1;
+ center_x = fig2Pts(center_x) - docX;
+ center_y = fig2Pts(center_y) - docY;
+ double x1R = fig2Pts(x1) - docX;
+ double y1R = fig2Pts(y1) - docY;
+ double x3R = fig2Pts(x3) - docX;
+ double y3R = fig2Pts(y3) - docY;
+ double r1 = distance(x1R - center_x, y1R - center_y);
+ double x0 = center_x - r1;
+ double y0 = center_y - r1;
+ QRectF bBox = QRectF(x0, y0, r1 * 2.0, r1 * 2.0);
+ double angle1 = -xy2Deg(x1R - center_x, y1R - center_y);
+ double angle2 = -xy2Deg(x3R - center_x, y3R - center_y);
+ double sweep;
+ if (direction == 0)
+ {
+ sweep = angle1 - angle2;
+ if (sweep < 0.0)
+ sweep = 360.0 + sweep;
+ }
+ else
+ {
+ sweep = angle2 - angle1;
+ if (sweep < 0.0)
+ sweep = 360.0 + sweep;
+ double an = angle1;
+ angle1 = angle2;
+ angle2 = an;
+ }
+ QPainterPath aPath;
+ if (subtype == 1)
+ {
+ aPath.arcMoveTo(bBox, angle2);
+ aPath.arcTo(bBox, angle2, sweep);
+ }
+ else
+ {
+ aPath.moveTo(center_x, center_y);
+ aPath.arcTo(bBox, angle2, sweep);
+ aPath.lineTo(center_x, center_y);
+ }
+ FPointArray points;
+ points.fromQPainterPath(aPath);
+
+ if (z >= 0)
+ {
+ ite = m_Doc->Items->at(z);
+ ite->PoLine = points.copy();
+ ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ ite->ClipEdited = true;
+ ite->FrameType = 3;
+ ite->setFillShade(CurrFillShade);
+ ite->setLineShade(CurrStrokeShade);
+ if (line_style > 0)
+ ite->setDashes(getDashValues(LineW, line_style));
+ if (subtype == 1)
+ {
+ if (cap_style == 0)
+ ite->setLineEnd(Qt::FlatCap);
+ else if (cap_style == 1)
+ ite->setLineEnd(Qt::RoundCap);
+ else if (cap_style == 2)
+ ite->setLineEnd(Qt::SquareCap);
+ }
+ FPoint wh = getMaxClipF(&ite->PoLine);
+ ite->setWidthHeight(wh.x(),wh.y());
+ ite->setTextFlowMode(PageItem::TextFlowDisabled);
+ m_Doc->AdjustItemSize(ite);
+ ite->setWidthHeight(qMax(ite->width(), 1.0), qMax(ite->height(), 1.0));
+ depthMap.insert(999 - depth, currentItemNr);
+ currentItemNr++;
+ if ((ite->itemType() == PageItem::PolyLine) && ((forward_arrow == 1) || (backward_arrow == 1)))
+ {
+ if (direction == 1)
+ processArrows(forward_arrow, fArrowData, backward_arrow, bArrowData, depth, ite);
+ else
+ processArrows(backward_arrow, bArrowData, forward_arrow, fArrowData, depth, ite);
+ }
+ }
+}
+
+void XfigPlug::processEllipse(QString data)
+{
+ QString tmp = data;
+ int command; // (always 1)
+ int subtype; // (1: ellipse defined by radii
+ // 2: ellipse defined by diameters
+ // 3: circle defined by radius
+ // 4: circle defined by diameter)
+ int line_style; // (enumeration type)
+ int thickness; // (1/80 inch)
+ int pen_color; // (enumeration type, pen color)
+ int fill_color; // (enumeration type, fill color)
+ int depth; // (enumeration type)
+ int pen_style; // (pen style, not used)
+ int area_fill; // (enumeration type, -1 = no fill)
+ double style_val; // (1/80 inch)
+ int direction; // (always 1)
+ double angle; // (radians, the angle of the x-axis)
+ int center_x, center_y; // (Fig units)
+ int radius_x, radius_y; // (Fig units)
+ int start_x, start_y; // (Fig units; the 1st point entered)
+ int end_x, end_y; // (Fig units; the last point entered)
+ double x, y, w, h;
+ ScTextStream Code(&tmp, QIODevice::ReadOnly);
+ Code >> command >> subtype >> line_style >> thickness >> pen_color >> fill_color >> depth >> pen_style;
+ Code >> area_fill >> style_val >> direction >> angle >> center_x >> center_y >> radius_x >> radius_y;
+ Code >> start_x >> start_y >> end_x >> end_y;
+ useColor(pen_color, 0, false);
+ useColor(fill_color, area_fill, true);
+ LineW = thickness / 80.0 * 72.0;
+ w = fig2Pts(radius_x);
+ h = fig2Pts(radius_y);
+ x = fig2Pts(center_x) - w;
+ y = fig2Pts(center_y) - h;
+ w *= 2.0;
+ h *= 2.0;
+ x -= docX;
+ x += m_Doc->currentPage()->xOffset();
+ y -= docY;
+ y += m_Doc->currentPage()->yOffset();
+ int z = -1;
+ PageItem *ite;
+ z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, baseX + x, baseY + y, w, h, LineW, CurrColorFill, CurrColorStroke, true);
+ if (z >= 0)
+ {
+ ite = m_Doc->Items->at(z);
+ ite->setFillShade(CurrFillShade);
+ ite->setLineShade(CurrStrokeShade);
+ if (line_style > 0)
+ ite->setDashes(getDashValues(LineW, line_style));
+ ite->setTextFlowMode(PageItem::TextFlowDisabled);
+ int rot = m_Doc->RotMode();
+ m_Doc->RotMode ( 2);
+ m_Doc->RotateItem(-angle * 180.0 / M_PI, ite);
+ m_Doc->RotMode( rot);
+ depthMap.insert(999 - depth, currentItemNr);
+ currentItemNr++;
+ }
+}
+
+QString XfigPlug::cleanText(QString text)
+{
+ QString ret = "";
+ QString tmp = "";
+ bool sep = false;
+ int sepcount = 0;
+ for (int a = 1; a < text.count(); ++a)
+ {
+ QString ch = text.mid(a,1);
+ if (sep)
+ {
+ if (ch == "\\")
+ {
+ ret += ch;
+ sep = false;
+ }
+ else
+ {
+ tmp += ch;
+ sepcount++;
+ if (sepcount == 3)
+ {
+ sep = false;
+ bool ok = false;
+ if (tmp != "001")
+ {
+ int code = tmp.toInt(&ok, 8);
+ if (ok)
+ ret += QChar(code);
+ }
+ tmp = "";
+ }
+ }
+ }
+ else
+ {
+ if (ch == "\\")
+ {
+ sep = true;
+ sepcount = 0;
+ }
+ else
+ ret += ch;
+ }
+ }
+ return ret;
+}
+
+void XfigPlug::processText(QString data)
+{
+ QString tmp = data;
+ int command; // (always 4)
+ int subtype; // (0: Left justified
+ // 1: Center justified
+ // 2: Right justified)
+ int color; // (enumeration type)
+ int depth; // (enumeration type)
+ int pen_style; // (enumeration , not used)
+ int font; // (enumeration type)
+ float font_size; // (font size in points)
+ float angle; // (radians, the angle of the text)
+ int font_flags; // (bit vector)
+ float height; // (Fig units)
+ float length; // (Fig units)
+ int xT, yT; // (Fig units, coordinate of the origin
+ // of the string. If sub_type = 0, it is
+ // the lower left corner of the string.
+ // If sub_type = 1, it is the lower
+ // center. Otherwise it is the lower
+ // right corner of the string.)
+ QString text;
+ double x, y, w, h;
+ ScTextStream Code(&tmp, QIODevice::ReadOnly);
+ Code >> command >> subtype >> color >> depth >> pen_style >> font >> font_size >> angle;
+ Code >> font_flags >> height >> length >> xT >> yT;
+ text = Code.readAll();
+ text = cleanText(text);
+ FPointArray textPath;
+ QPainterPath painterPath;
+ QString TFont = m_Doc->toolSettings.defFont;
+ QFont::Weight weight = QFont::Normal;
+ bool isItalic = false;
+ if (font_flags & 4)
+ {
+ switch (font)
+ {
+ case 0:
+ TFont = "Times Roman";
+ weight = QFont::Normal;
+ break;
+ case 1:
+ TFont = "Times Italic";
+ weight = QFont::Normal;
+ isItalic = true;
+ break;
+ case 2:
+ TFont = "Times Bold";
+ weight = QFont::Bold;
+ break;
+ case 3:
+ TFont = "Times Bold Italic";
+ weight = QFont::Bold;
+ isItalic = true;
+ break;
+ case 4:
+ TFont = "AvantGarde Book";
+ weight = QFont::Normal;
+ break;
+ case 5:
+ TFont = "AvantGarde Book Oblique";
+ weight = QFont::Normal;
+ break;
+ case 6:
+ TFont = "AvantGarde Demi";
+ weight = QFont::DemiBold;
+ break;
+ case 7:
+ TFont = "AvantGarde Demi Oblique";
+ weight = QFont::DemiBold;
+ break;
+ case 8:
+ TFont = "Bookman Light";
+ weight = QFont::Light;
+ break;
+ case 9:
+ TFont = "Bookman Light Italic";
+ weight = QFont::Light;
+ isItalic = true;
+ break;
+ case 10:
+ TFont = "Bookman Demi";
+ weight = QFont::DemiBold;
+ break;
+ case 11:
+ TFont = "Bookman Demi Italic";
+ weight = QFont::DemiBold;
+ isItalic = true;
+ break;
+ case 12:
+ TFont = "Courier";
+ weight = QFont::Normal;
+ break;
+ case 13:
+ TFont = "Courier Oblique";
+ weight = QFont::Normal;
+ break;
+ case 14:
+ TFont = "Courier Bold";
+ weight = QFont::Bold;
+ break;
+ case 15:
+ TFont = "Courier Bold Oblique";
+ weight = QFont::Bold;
+ break;
+ case 16:
+ TFont = "Helvetica";
+ weight = QFont::Normal;
+ break;
+ case 17:
+ TFont = "Helvetica Oblique";
+ weight = QFont::Normal;
+ break;
+ case 18:
+ TFont = "Helvetica Bold";
+ weight = QFont::Bold;
+ break;
+ case 19:
+ TFont = "Helvetica Bold Oblique";
+ weight = QFont::Bold;
+ break;
+ case 20:
+ TFont = "Helvetica Narrow";
+ weight = QFont::Normal;
+ break;
+ case 21:
+ TFont = "Helvetica Narrow Oblique";
+ weight = QFont::Normal;
+ break;
+ case 22:
+ TFont = "Helvetica Narrow Bold";
+ weight = QFont::Bold;
+ break;
+ case 23:
+ TFont = "Helvetica Narrow Bold Oblique";
+ weight = QFont::Bold;
+ break;
+ case 24:
+ TFont = "New Century Schoolbook Roman";
+ weight = QFont::Normal;
+ break;
+ case 25:
+ TFont = "New Century Schoolbook Italic";
+ weight = QFont::Normal;
+ isItalic = true;
+ break;
+ case 26:
+ TFont = "New Century Schoolbook Bold";
+ weight = QFont::Bold;
+ break;
+ case 27:
+ TFont = "New Century Schoolbook Bold Italic";
+ weight = QFont::Bold;
+ isItalic = true;
+ break;
+ case 28:
+ TFont = "Palatino Roman";
+ weight = QFont::Normal;
+ break;
+ case 29:
+ TFont = "Palatino Italic";
+ weight = QFont::Normal;
+ isItalic = true;
+ break;
+ case 30:
+ TFont = "Palatino Bold";
+ weight = QFont::Bold;
+ break;
+ case 31:
+ TFont = "Palatino Bold Italic";
+ weight = QFont::Bold;
+ isItalic = true;
+ break;
+ case 32:
+ TFont = "Symbol";
+ weight = QFont::Normal;
+ break;
+ case 33:
+ TFont = "Zapf Chancery Medium Italic";
+ weight = QFont::Normal;
+ isItalic = true;
+ break;
+ case 34:
+ TFont = "Zapf Dingbats";
+ weight = QFont::Normal;
+ break;
+ default:
+ TFont = m_Doc->toolSettings.defFont;
+ weight = QFont::Normal;
+ break;
+ }
+ }
+ else
+ {
+ switch (font)
+ {
+ case 1: // Roman
+ TFont = "Times";
+ weight = QFont::Normal;
+ break;
+ case 2: // Bold
+ TFont = "Times";
+ weight = QFont::Bold;
+ break;
+ case 3: // Italic
+ TFont = "Times";
+ weight = QFont::Normal;
+ isItalic = true;
+ break;
+ case 4: // Sans Serif
+ TFont = "Helvetica";
+ weight = QFont::Normal;
+ break;
+ case 5: // Typewriter
+ TFont = "Courier";
+ weight = QFont::Normal;
+ break;
+ default:
+ TFont = m_Doc->toolSettings.defFont;
+ weight = QFont::Normal;
+ break;
+ }
+ }
+ w = fig2Pts(length);
+ h = fig2Pts(height);
+ x = fig2Pts(xT);
+ y = fig2Pts(yT);
+ x -= docX;
+ x += m_Doc->currentPage()->xOffset();
+ y -= docY;
+ y += m_Doc->currentPage()->yOffset();
+ QFont tf = QFont(TFont, 10, weight, isItalic);
+ tf.setPointSizeF(font_size / 80.0 * 72.0);
+ painterPath.addText( 0, 0, tf, text );
+ QRectF br = painterPath.boundingRect();
+ if ((angle == 0) && (br.width() > w))
+ {
+ QTransform m;
+ m.scale(w / br.width(), w / br.width());
+ painterPath = m.map(painterPath);
+ }
+ textPath.fromQPainterPath(painterPath);
+ useColor(color, 0, false);
+ int z = -1;
+ PageItem *ite;
+ z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX + x, baseY + y, w, h, 0, CurrColorStroke, CommonStrings::None, true);
+ if (z >= 0)
+ {
+ ite = m_Doc->Items->at(z);
+ ite->setRotation(-angle * 180.0 / M_PI);
+ ite->PoLine = textPath.copy();
+ ite->ClipEdited = true;
+ ite->FrameType = 3;
+ FPoint wh = getMaxClipF(&ite->PoLine);
+ ite->setWidthHeight(wh.x(),wh.y());
+ ite->setTextFlowMode(PageItem::TextFlowDisabled);
+ m_Doc->AdjustItemSize(ite);
+ ite->setWidthHeight(qMax(ite->width(), 1.0), qMax(ite->height(), 1.0));
+ if (subtype == 1)
+ m_Doc->MoveRotated(ite, FPoint(-br.width() / 2.0, 0.0));
+ else if (subtype == 2)
+ m_Doc->MoveRotated(ite, FPoint(-br.width(), 0.0));
+ depthMap.insert(999 - depth, currentItemNr);
+ currentItemNr++;
+ }
+}
+
+void XfigPlug::processData(QDataStream &ts, QString data)
+{
+ QString tmp = data;
+ int command, subtype;
+ ScTextStream Code(&tmp, QIODevice::ReadOnly);
+ Code >> command >> subtype;
+ switch (command)
+ {
+ case 0:
+ parseColor(data);
+ break;
+ case 1:
+ processEllipse(data);
+ break;
+ case 2:
+ processPolyline(ts, data);
+ break;
+ case 3:
+ processSpline(ts, data);
+ break;
+ case 4:
+ processText(data);
+ break;
+ case 5:
+ processArc(ts, data);
+ break;
+ case 6:
+// qDebug() << "Xfig-Import:: Unsupported Compound object";
+ break;
+ case -6:
+// qDebug() << "Xfig-Import:: Unsupported End of Compound object";
+ break;
+ }
+}
+
+void XfigPlug::resortItems()
+{
+ int ac = m_Doc->Items->count();
+ QList<PageItem*> itemList;
+ for (int as = oldDocItemCount; as < ac; ++as)
+ {
+ itemList.append(m_Doc->Items->takeAt(oldDocItemCount));
+ }
+ QList<int> keylist = depthMap.uniqueKeys();
+ int keysCount = keylist.count();
+ int currentLayer = 0;
+ for (int it = 0; it < keysCount; ++it)
+ {
+ if ((importerFlags & LoadSavePlugin::lfCreateDoc) && (it > 0))
+ currentLayer = m_Doc->addLayer(QString("Layer %1").arg(it), true);
+ QList<int> elems = depthMap.values(keylist.at(it));
+ qSort(elems);
+ int itemsCount = elems.count();
+ for (int i = 0; i < itemsCount; ++i)
+ {
+ PageItem* ite = itemList.at(elems.at(i));
+ Elements.append(ite);
+ m_Doc->Items->append(ite);
+ ite->ItemNr = m_Doc->Items->count()-1;
+ if ((importerFlags & LoadSavePlugin::lfCreateDoc) && (it > 0))
+ ite->LayerID = currentLayer;
+ }
+ }
+}
+
+
+double XfigPlug::fig2Pts(double in)
+{
+ return in / 1200.0 * 72.0;
+}
+
+bool XfigPlug::convert(QString fn)
+{
+ QString tmp;
+ CurrColorFill = "White";
+ CurrFillShade = 100.0;
+ CurrColorStroke = "Black";
+ CurrStrokeShade = 100.0;
+ patternMode = false;
+ patternX1 = 0.0;
+ patternY1 = 0.0;
+ patternX2 = 0.0;
+ patternY2 = 0.0;
+ Coords.resize(0);
+ Coords.svgInit();
+ clipCoords.resize(0);
+ clipCoords.svgInit();
+ currentPatternName = "";
+ currentPatternX = 0.0;
+ currentPatternY = 0.0;
+ currentPatternXScale = 1.0;
+ currentPatternYScale = 1.0;
+ currentPatternRotation = 0.0;
+ QList<PageItem*> gElements;
+ groupStack.push(gElements);
+ currentItemNr = 0;
+ if(progressDialog)
+ {
+ progressDialog->setOverallProgress(2);
+ progressDialog->setLabel("GI", tr("Generating Items"));
+ qApp->processEvents();
+ }
+ QFile f(fn);
+ if (f.open(QIODevice::ReadOnly))
+ {
+ oldDocItemCount = m_Doc->Items->count();
+ int fSize = (int) f.size();
+ if (progressDialog)
+ {
+ progressDialog->setTotalSteps("GI", fSize);
+ qApp->processEvents();
+ }
+ QDataStream ts(&f);
+ QString version = readLinefromDataStream(ts);
+ QString orientation = readLinefromDataStream(ts);
+ QString justification = readLinefromDataStream(ts);
+ QString units = readLinefromDataStream(ts);
+ QString papersize = readLinefromDataStream(ts);
+ QString magnification = readLinefromDataStream(ts);
+ QString multiple = readLinefromDataStream(ts);
+ QString transparent = readLinefromDataStream(ts);
+ tmp = readLinefromDataStream(ts);
+ if (tmp.startsWith("#"))
+ tmp = readLinefromDataStream(ts);
+ QString resolution = tmp;
+ while (!ts.atEnd())
+ {
+ tmp = readLinefromDataStream(ts);
+ if (tmp.startsWith("#"))
+ continue;
+ processData(ts, tmp);
+ progressDialog->setProgress("GI", ts.device()->pos());
+ qApp->processEvents();
+ }
+ resortItems();
+ }
+ if (progressDialog)
+ progressDialog->close();
+ return true;
+}
Index: scribus/plugins/xfigimplugin/importxfig.h
===================================================================
--- scribus/plugins/xfigimplugin/importxfig.h (revision 13950)
+++ scribus/plugins/xfigimplugin/importxfig.h (revision 13951)
@@ -16,7 +16,7 @@
#include "fpointarray.h"
#include <QList>
#include <QStack>
-#include <QMatrix>
+#include <QTransform>
#include <QMultiMap>
class MultiProgressDialog;
Index: scribus/plugins/wpgimplugin/importwpg.cpp
===================================================================
--- scribus/plugins/wpgimplugin/importwpg.cpp (revision 13950)
+++ scribus/plugins/wpgimplugin/importwpg.cpp (revision 13951)
@@ -1,767 +1,767 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-
-#include <QByteArray>
-#include <QCursor>
-#include <QDrag>
-#include <QFile>
-#include <QList>
-#include <QMimeData>
-#include <QRegExp>
-#include <QStack>
-#include <QDebug>
-
-#include <cmath>
-#include <cstdlib>
-
-#include "commonstrings.h"
-#include "ui/customfdialog.h"
-#include "importwpg.h"
-#include "loadsaveplugin.h"
-#include "ui/missing.h"
-#include "ui/multiprogressdialog.h"
-#include "pagesize.h"
-#include "prefscontext.h"
-#include "prefsfile.h"
-#include "prefsmanager.h"
-#include "prefsmanager.h"
-#include "prefstable.h"
-#include "ui/propertiespalette.h"
-#include "rawimage.h"
-#include "scclocale.h"
-#include "sccolorengine.h"
-#include "scconfig.h"
-#include "scmimedata.h"
-#include "scpaths.h"
-#include "scpattern.h"
-#include "scpattern.h"
-#include "scribus.h"
-#include "scribusXml.h"
-#include "scribuscore.h"
-#include "sctextstream.h"
-#include "selection.h"
-#include "undomanager.h"
-#include "util.h"
-#include "util_formats.h"
-#include "util_icon.h"
-#include "util_math.h"
-#include <stdio.h>
-#include "wpg/WPGStreamImplementation.h"
-
-extern SCRIBUS_API ScribusQApp * ScQApp;
-
-ScrPainter::ScrPainter(): libwpg::WPGPaintInterface()
-{
-}
-
-void ScrPainter::startGraphics(double width, double height)
-{
- CurrColorFill = "Black";
- CurrFillShade = 100.0;
- CurrColorStroke = "Black";
- CurrStrokeShade = 100.0;
- CurrStrokeTrans = 0.0;
- CurrFillTrans = 0.0;
- Coords.resize(0);
- Coords.svgInit();
- LineW = 1.0;
- lineJoin = Qt::MiterJoin;
- lineEnd = Qt::FlatCap;
- fillrule = true;
- gradientAngle = 0.0;
- isGradient = false;
- fillSet = false;
- strokeSet = false;
- currentGradient = VGradient(VGradient::linear);
- currentGradient.clearStops();
- currentGradient.setRepeatMethod( VGradient::none );
- dashArray.clear();
- if (flags & LoadSavePlugin::lfCreateDoc)
- {
- m_Doc->setPage(72 * width, 72 * height, 0, 0, 0, 0, 0, 0, false, false);
- if (width > height)
- m_Doc->PageOri = 1;
- else
- m_Doc->PageOri = 0;
- m_Doc->m_pageSize = "Custom";
- m_Doc->changePageMargins(0, 0, 0, 0, 72 * height, 72 * width, 72 * height, 72 * width, m_Doc->PageOri, m_Doc->m_pageSize, m_Doc->currentPage()->pageNr(), 0);
- }
- firstLayer = true;
-}
-
-void ScrPainter::endGraphics()
-{
-}
-
-void ScrPainter::startLayer(unsigned int id)
-{
- if (flags & LoadSavePlugin::lfCreateDoc)
- {
- if (!firstLayer)
- m_Doc->addLayer(QString("Layer %1").arg(id), true);
- firstLayer = false;
- }
-}
-
-void ScrPainter::endLayer(unsigned int id)
-{
-}
-
-void ScrPainter::setPen(const libwpg::WPGPen& pen)
-{
- LineW = 72 * pen.width;
- ScColor tmp;
- ColorList::Iterator it;
- CurrColorStroke = "Black";
- CurrStrokeShade = 100.0;
- int Rc, Gc, Bc, hR, hG, hB;
- bool found = false;
- Rc = pen.foreColor.red;
- Gc = pen.foreColor.green;
- Bc = pen.foreColor.blue;
- for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
- {
- if (it.value().getColorModel() == colorModelRGB)
- {
- it.value().getRGB(&hR, &hG, &hB);
- if ((Rc == hR) && (Gc == hG) && (Bc == hB))
- {
- CurrColorStroke = it.key();
- found = true;
- break;
- }
- }
- }
- if (!found)
- {
- tmp.setColorRGB(Rc, Gc, Bc);
- tmp.setSpotColor(false);
- tmp.setRegistrationColor(false);
- QString newColorName = "FromWPG"+tmp.name();
- m_Doc->PageColors.insert(newColorName, tmp);
- importedColors.append(newColorName);
- CurrColorStroke = newColorName;
- }
- CurrStrokeTrans = pen.foreColor.alpha / 256.0;
- if(!pen.solid)
- {
- dashArray.clear();
- for(unsigned i = 0; i < pen.dashArray.count(); i++)
- {
- dashArray.append(pen.dashArray.at(i)*LineW);
- }
- }
- switch (pen.joinstyle)
- {
- case 1:
- lineJoin = Qt::BevelJoin;
- break;
- case 2:
- lineJoin = Qt::MiterJoin;
- break;
- case 3:
- lineJoin = Qt::RoundJoin;
- break;
- default:
- lineJoin = Qt::MiterJoin;
- break;
- }
- switch (pen.capstyle)
- {
- case 0:
- lineEnd = Qt::FlatCap;
- break;
- case 1:
- lineEnd = Qt::RoundCap;
- break;
- case 2:
- lineEnd = Qt::SquareCap;
- break;
- default:
- lineEnd = Qt::FlatCap;
- break;
- }
- strokeSet = true;
-}
-
-void ScrPainter::setBrush(const libwpg::WPGBrush& brush)
-{
- ScColor tmp;
- ColorList::Iterator it;
- CurrColorFill = "Black";
- CurrFillShade = 100.0;
- int Rc, Gc, Bc, hR, hG, hB;
- if(brush.style == libwpg::WPGBrush::Solid)
- {
- bool found = false;
- Rc = brush.foreColor.red;
- Gc = brush.foreColor.green;
- Bc = brush.foreColor.blue;
- for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
- {
- if (it.value().getColorModel() == colorModelRGB)
- {
- it.value().getRGB(&hR, &hG, &hB);
- if ((Rc == hR) && (Gc == hG) && (Bc == hB))
- {
- CurrColorFill = it.key();
- found = true;
- break;
- }
- }
- }
- if (!found)
- {
- tmp.setColorRGB(Rc, Gc, Bc);
- tmp.setSpotColor(false);
- tmp.setRegistrationColor(false);
- QString newColorName = "FromWPG"+tmp.name();
- m_Doc->PageColors.insert(newColorName, tmp);
- importedColors.append(newColorName);
- CurrColorFill = newColorName;
- }
- CurrFillTrans = brush.foreColor.alpha / 256.0;
- }
- else if (brush.style == libwpg::WPGBrush::Gradient)
- {
- gradientAngle = brush.gradient.angle();
- isGradient = true;
- currentGradient = VGradient(VGradient::linear);
- currentGradient.clearStops();
- for(unsigned c = 0; c < brush.gradient.count(); c++)
- {
- QString currStopColor = CommonStrings::None;
- bool found = false;
- Rc = brush.gradient.stopColor(c).red;
- Gc = brush.gradient.stopColor(c).green;
- Bc = brush.gradient.stopColor(c).blue;
- for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
- {
- if (it.value().getColorModel() == colorModelRGB)
- {
- it.value().getRGB(&hR, &hG, &hB);
- if ((Rc == hR) && (Gc == hG) && (Bc == hB))
- {
- currStopColor = it.key();
- found = true;
- break;
- }
- }
- }
- if (!found)
- {
- tmp.setColorRGB(Rc, Gc, Bc);
- tmp.setSpotColor(false);
- tmp.setRegistrationColor(false);
- QString newColorName = "FromWPG"+tmp.name();
- m_Doc->PageColors.insert(newColorName, tmp);
- importedColors.append(newColorName);
- currStopColor = newColorName;
- }
- const ScColor& gradC = m_Doc->PageColors[currStopColor];
- currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), fabs(brush.gradient.stopOffset(c)), 0.5, 1.0, currStopColor, 100 );
- }
- }
- else if (brush.style == libwpg::WPGBrush::NoBrush)
- CurrColorFill = CommonStrings::None;
- fillSet = true;
-}
-
-void ScrPainter::setFillRule(FillRule rule)
-{
- if(rule == libwpg::WPGPaintInterface::WindingFill)
- fillrule = false;
- else
- fillrule = true;
-// qDebug() << "Fill Rule " << fillrule;
-}
-
-void ScrPainter::drawRectangle(const libwpg::WPGRect& rect, double rx, double ry)
-{
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, baseX, baseY, rect.width() * 72.0, rect.height() * 72.0, LineW, CurrColorFill, CurrColorStroke, true);
- PageItem *ite = m_Doc->Items->at(z);
- if ((rx > 0) && (ry > 0))
- {
- ite->setCornerRadius(qMax(72*rx, 72*ry));
- ite->SetFrameRound();
- m_Doc->setRedrawBounding(ite);
- }
- QMatrix mm = QMatrix();
- mm.translate(72*rect.x1, 72*rect.y1);
- ite->PoLine.map(mm);
- ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
- finishItem(ite);
-// qDebug() << "draw Rect";
-}
-
-void ScrPainter::drawEllipse(const libwpg::WPGPoint& center, double rx, double ry)
-{
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, baseX, baseY, rx * 144.0, ry * 144.0, LineW, CurrColorFill, CurrColorStroke, true);
- PageItem *ite = m_Doc->Items->at(z);
- QMatrix mm = QMatrix();
- mm.translate(72*(center.x - rx), 72*(center.y - ry));
- ite->PoLine.map(mm);
- ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
- finishItem(ite);
-// qDebug() << "draw Ellipse";
-}
-
-void ScrPainter::drawPolygon(const libwpg::WPGPointArray& vertices, bool closed)
-{
- if(vertices.count() < 2)
- return;
- Coords.resize(0);
- Coords.svgInit();
- PageItem *ite;
- Coords.svgMoveTo(72 * vertices[0].x, 72 * vertices[0].y);
- for(unsigned i = 1; i < vertices.count(); i++)
- {
- Coords.svgLineTo(72 * vertices[i].x, 72 * vertices[i].y);
- }
- if (closed)
- Coords.svgClosePath();
- if (Coords.size() > 0)
- {
- int z;
- if (closed)
- z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
- else
- z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CommonStrings::None, CurrColorStroke, true);
- ite = m_Doc->Items->at(z);
- ite->PoLine = Coords.copy();
- ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
- finishItem(ite);
- }
-// qDebug() << "draw Polygon";
-}
-
-void ScrPainter::drawPath(const libwpg::WPGPath& path)
-{
- Coords.resize(0);
- Coords.svgInit();
- PageItem *ite;
- for(unsigned i = 0; i < path.count(); i++)
- {
- libwpg::WPGPathElement element = path.element(i);
- libwpg::WPGPoint point = element.point;
- switch(element.type)
- {
- case libwpg::WPGPathElement::MoveToElement:
- Coords.svgMoveTo(72 * point.x, 72 * point.y);
- break;
- case libwpg::WPGPathElement::LineToElement:
- Coords.svgLineTo(72 * point.x, 72 * point.y);
- break;
- case libwpg::WPGPathElement::CurveToElement:
- Coords.svgCurveToCubic(72*element.extra1.x, 72*element.extra1.y, 72*element.extra2.x, 72*element.extra2.y, 72 * point.x, 72 * point.y);
- break;
- default:
- break;
- }
- }
- if (Coords.size() > 0)
- {
- int z;
- if (fillSet)
- {
- if (!path.filled)
- CurrColorFill = CommonStrings::None;
- }
- if (strokeSet)
- {
- if (!path.framed)
- CurrColorStroke = CommonStrings::None;
- }
- if(path.closed)
- {
- Coords.svgClosePath();
- z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
- }
- else
- z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
- ite = m_Doc->Items->at(z);
- ite->PoLine = Coords.copy();
- ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
- finishItem(ite);
- }
-// qDebug() << "draw Path";
-}
-
-void ScrPainter::finishItem(PageItem* ite)
-{
- ite->ClipEdited = true;
- ite->Frame = false;
- ite->FrameType = 3;
- ite->setFillShade(CurrFillShade);
- ite->setFillEvenOdd(fillrule);
- ite->setLineShade(CurrStrokeShade);
- ite->setFillTransparency(CurrFillTrans);
- ite->setLineTransparency(CurrStrokeTrans);
- ite->setLineJoin(lineJoin);
- ite->setLineEnd(lineEnd);
- ite->DashValues = dashArray;
- FPoint wh = getMaxClipF(&ite->PoLine);
- ite->setWidthHeight(wh.x(),wh.y());
- ite->setTextFlowMode(PageItem::TextFlowDisabled);
- m_Doc->AdjustItemSize(ite);
- ite->OldB2 = ite->width();
- ite->OldH2 = ite->height();
- if (isGradient)
- {
- ite->fill_gradient = currentGradient;
- ite->GrType = 6;
- QMatrix m1;
- m1.rotate(-gradientAngle);
- ite->GrStartX = 0;
- ite->GrStartY = 0;
- QPointF target = m1.map(QPointF(0.0, ite->height()));
- ite->GrEndX = target.x();
- ite->GrEndY = target.y();
- }
- ite->updateClip();
- Elements.append(ite);
- Coords.resize(0);
- Coords.svgInit();
-}
-
-void ScrPainter::drawBitmap(const libwpg::WPGBitmap& bitmap, double hres, double vres)
-{
- QImage image = QImage(bitmap.width(), bitmap.height(), QImage::Format_RGB32);
- for(int x = 0; x < bitmap.width(); x++)
- {
- for(int y = 0; y < bitmap.height(); y++)
- {
- libwpg::WPGColor color = bitmap.pixel(x, y);
- image.setPixel(x, y, qRgb(color.red, color.green, color.blue));
- }
- }
- double w = (bitmap.rect.x2 - bitmap.rect.x1) * 72.0;
- double h = (bitmap.rect.y2 - bitmap.rect.y1) * 72.0;
- int z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, bitmap.rect.x1 * 72 + baseX, bitmap.rect.y1 * 72 + baseY, w, h, 1, m_Doc->toolSettings.dBrushPict, CommonStrings::None, true);
- PageItem *ite = m_Doc->Items->at(z);
- ite->tempImageFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_svg_XXXXXX.png");
- ite->tempImageFile->open();
- QString fileName = getLongPathName(ite->tempImageFile->fileName());
- ite->tempImageFile->close();
- ite->isInlineImage = true;
- image.setDotsPerMeterX ((int) (hres / 0.0254));
- image.setDotsPerMeterY ((int) (vres / 0.0254));
- image.save(fileName, "PNG");
- m_Doc->LoadPict(fileName, z);
- ite->setImageScalingMode(false, false);
- ite->moveBy(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
- finishItem(ite);
-// qDebug() << "drawBitmap";
-}
-
-void ScrPainter::drawImageObject(const libwpg::WPGBinaryData& /*binaryData*/)
-{
-// qDebug() << "drawBinaryData";
-}
-
-
-WpgPlug::WpgPlug(ScribusDoc* doc, int flags)
-{
- tmpSel=new Selection(this, false);
- m_Doc=doc;
- interactive = (flags & LoadSavePlugin::lfInteractive);
-}
-
-bool WpgPlug::import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
-{
- QString fName = fNameIn;
- bool success = false;
- interactive = (flags & LoadSavePlugin::lfInteractive);
- importerFlags = flags;
- cancel = false;
- double x, y, b, h;
- bool ret = false;
- QFileInfo fi = QFileInfo(fName);
- if ( !ScCore->usingGUI() )
- {
- interactive = false;
- showProgress = false;
- }
- if ( showProgress )
- {
- ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
- progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw );
- QStringList barNames, barTexts;
- barNames << "GI";
- barTexts << tr("Analyzing File:");
- QList<bool> barsNumeric;
- barsNumeric << false;
- progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
- progressDialog->setOverallTotalSteps(3);
- progressDialog->setOverallProgress(0);
- progressDialog->setProgress("GI", 0);
- progressDialog->show();
- connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
- qApp->processEvents();
- }
- else
- progressDialog = NULL;
-/* Set default Page to size defined in Preferences */
- x = 0.0;
- y = 0.0;
- b = 0.0;
- h = 0.0;
- if (progressDialog)
- {
- progressDialog->setOverallProgress(1);
- qApp->processEvents();
- }
- if (b == 0.0)
- b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth;
- if (h == 0.0)
- h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight;
- docWidth = b;
- docHeight = h;
- baseX = 0;
- baseY = 0;
- if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
- {
- m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false);
- m_Doc->addPage(0);
- m_Doc->view()->addPage(0, true);
- baseX = 0;
- baseY = 0;
- }
- else
- {
- if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
- {
- m_Doc=ScCore->primaryMainWindow()->doFileNew(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
- ScCore->primaryMainWindow()->HaveNewDoc();
- ret = true;
- baseX = 0;
- baseY = 0;
- baseX = m_Doc->currentPage()->xOffset();
- baseY = m_Doc->currentPage()->yOffset();
- }
- }
- if ((!ret) && (interactive))
- {
- baseX = m_Doc->currentPage()->xOffset();
- baseY = m_Doc->currentPage()->yOffset();
- }
- if ((ret) || (!interactive))
- {
- if (docWidth > docHeight)
- m_Doc->PageOri = 1;
- else
- m_Doc->PageOri = 0;
- m_Doc->m_pageSize = "Custom";
- }
- Elements.clear();
- FPoint minSize = m_Doc->minCanvasCoordinate;
- FPoint maxSize = m_Doc->maxCanvasCoordinate;
- FPoint cOrigin = m_Doc->view()->canvasOrigin();
- m_Doc->setLoading(true);
- m_Doc->DoDrawing = false;
- m_Doc->view()->updatesOn(false);
- m_Doc->scMW()->ScriptRunning = true;
- qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
- QString CurDirP = QDir::currentPath();
- QDir::setCurrent(fi.path());
- if (convert(fName))
- {
- tmpSel->clear();
- QDir::setCurrent(CurDirP);
- if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc)))
- {
- bool isGroup = true;
- int firstElem = -1;
- if (Elements.at(0)->Groups.count() != 0)
- firstElem = Elements.at(0)->Groups.top();
- for (int bx = 0; bx < Elements.count(); ++bx)
- {
- PageItem* bxi = Elements.at(bx);
- if (bxi->Groups.count() != 0)
- {
- if (bxi->Groups.top() != firstElem)
- isGroup = false;
- }
- else
- isGroup = false;
- }
- if (!isGroup)
- {
- double minx = 99999.9;
- double miny = 99999.9;
- double maxx = -99999.9;
- double maxy = -99999.9;
- uint lowestItem = 999999;
- uint highestItem = 0;
- for (int a = 0; a < Elements.count(); ++a)
- {
- Elements.at(a)->Groups.push(m_Doc->GroupCounter);
- PageItem* currItem = Elements.at(a);
- lowestItem = qMin(lowestItem, currItem->ItemNr);
- highestItem = qMax(highestItem, currItem->ItemNr);
- double x1, x2, y1, y2;
- currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
- minx = qMin(minx, x1);
- miny = qMin(miny, y1);
- maxx = qMax(maxx, x2);
- maxy = qMax(maxy, y2);
- }
- double gx = minx;
- double gy = miny;
- double gw = maxx - minx;
- double gh = maxy - miny;
- PageItem *high = m_Doc->Items->at(highestItem);
- int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, m_Doc->toolSettings.dBrush, m_Doc->toolSettings.dPen, true);
- PageItem *neu = m_Doc->Items->takeAt(z);
- m_Doc->Items->insert(lowestItem, neu);
- neu->Groups.push(m_Doc->GroupCounter);
- neu->setItemName( tr("Group%1").arg(neu->Groups.top()));
- neu->AutoName = false;
- neu->isGroupControl = true;
- neu->groupsLastItem = high;
- neu->setTextFlowMode(PageItem::TextFlowDisabled);
- for (int a = 0; a < m_Doc->Items->count(); ++a)
- {
- m_Doc->Items->at(a)->ItemNr = a;
- }
- Elements.prepend(neu);
- m_Doc->GroupCounter++;
- }
- }
- m_Doc->DoDrawing = true;
- m_Doc->scMW()->ScriptRunning = false;
- m_Doc->setLoading(false);
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- if ((Elements.count() > 0) && (!ret) && (interactive))
- {
- if (flags & LoadSavePlugin::lfScripted)
- {
- bool loadF = m_Doc->isLoading();
- m_Doc->setLoading(false);
- m_Doc->changed();
- m_Doc->setLoading(loadF);
- m_Doc->m_Selection->delaySignalsOn();
- for (int dre=0; dre<Elements.count(); ++dre)
- {
- m_Doc->m_Selection->addItem(Elements.at(dre), true);
- }
- m_Doc->m_Selection->delaySignalsOff();
- m_Doc->m_Selection->setGroupRect();
- m_Doc->view()->updatesOn(true);
- }
- else
- {
- m_Doc->DragP = true;
- m_Doc->DraggedElem = 0;
- m_Doc->DragElements.clear();
- m_Doc->m_Selection->delaySignalsOn();
- for (int dre=0; dre<Elements.count(); ++dre)
- {
- m_Doc->DragElements.append(Elements.at(dre)->ItemNr);
- tmpSel->addItem(Elements.at(dre), true);
- }
- tmpSel->setGroupRect();
- ScriXmlDoc *ss = new ScriXmlDoc();
- ScElemMimeData* md = new ScElemMimeData();
- md->setScribusElem(ss->WriteElem(m_Doc, m_Doc->view(), tmpSel));
- delete ss;
- m_Doc->itemSelection_DeleteItem(tmpSel);
- m_Doc->view()->updatesOn(true);
- m_Doc->m_Selection->delaySignalsOff();
- // We must copy the TransationSettings object as it is owned
- // by handleObjectImport method afterwards
- TransactionSettings* transacSettings = new TransactionSettings(trSettings);
- m_Doc->view()->handleObjectImport(md, transacSettings);
- m_Doc->DragP = false;
- m_Doc->DraggedElem = 0;
- m_Doc->DragElements.clear();
- }
- }
- else
- {
- m_Doc->changed();
- m_Doc->reformPages();
- m_Doc->view()->updatesOn(true);
- }
- success = true;
- }
- else
- {
- QDir::setCurrent(CurDirP);
- m_Doc->DoDrawing = true;
- m_Doc->scMW()->ScriptRunning = false;
- m_Doc->view()->updatesOn(true);
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- }
- if (interactive)
- m_Doc->setLoading(false);
- //CB If we have a gui we must refresh it if we have used the progressbar
- if ((showProgress) && (!interactive))
- m_Doc->view()->DrawNew();
- return success;
-}
-
-WpgPlug::~WpgPlug()
-{
- if (progressDialog)
- delete progressDialog;
- delete tmpSel;
-}
-
-bool WpgPlug::convert(QString fn)
-{
- QString tmp;
- importedColors.clear();
-
- QFile file(fn);
- if ( !file.exists() )
- {
- qDebug() << "File " << QFile::encodeName(fn).data() << " does not exist" << endl;
- return false;
- }
- if ( !file.open( QIODevice::ReadOnly ) )
- {
- qDebug() << "Cannot open file " << QFile::encodeName(fn).data() << endl;
- return false;
- }
- QByteArray ba = file.readAll();
- file.close();
-
- libwpg::WPGMemoryStream input(ba.constData(), ba.size());
- if (!libwpg::WPGraphics::isSupported(&input))
- {
- fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n");
- return false;
- }
- ScrPainter painter;
- painter.m_Doc = m_Doc;
- painter.baseX = baseX;
- painter.baseY = baseY;
- painter.flags = importerFlags;
- libwpg::WPGraphics::parse(&input, &painter);
- Elements = painter.Elements;
- importedColors = painter.importedColors;
- if (Elements.count() == 0)
- {
- if (importedColors.count() != 0)
- {
- for (int cd = 0; cd < importedColors.count(); cd++)
- {
- m_Doc->PageColors.remove(importedColors[cd]);
- }
- }
- }
-/* if(progressDialog)
- {
- progressDialog->setOverallProgress(2);
- progressDialog->setLabel("GI", tr("Generating Items"));
- qApp->processEvents();
- } */
- if (progressDialog)
- progressDialog->close();
- return true;
-}
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#include <QByteArray>
+#include <QCursor>
+#include <QDrag>
+#include <QFile>
+#include <QList>
+#include <QMimeData>
+#include <QRegExp>
+#include <QStack>
+#include <QDebug>
+
+#include <cmath>
+#include <cstdlib>
+
+#include "commonstrings.h"
+#include "ui/customfdialog.h"
+#include "importwpg.h"
+#include "loadsaveplugin.h"
+#include "ui/missing.h"
+#include "ui/multiprogressdialog.h"
+#include "pagesize.h"
+#include "prefscontext.h"
+#include "prefsfile.h"
+#include "prefsmanager.h"
+#include "prefsmanager.h"
+#include "prefstable.h"
+#include "ui/propertiespalette.h"
+#include "rawimage.h"
+#include "scclocale.h"
+#include "sccolorengine.h"
+#include "scconfig.h"
+#include "scmimedata.h"
+#include "scpaths.h"
+#include "scpattern.h"
+#include "scpattern.h"
+#include "scribus.h"
+#include "scribusXml.h"
+#include "scribuscore.h"
+#include "sctextstream.h"
+#include "selection.h"
+#include "undomanager.h"
+#include "util.h"
+#include "util_formats.h"
+#include "util_icon.h"
+#include "util_math.h"
+#include <stdio.h>
+#include "wpg/WPGStreamImplementation.h"
+
+extern SCRIBUS_API ScribusQApp * ScQApp;
+
+ScrPainter::ScrPainter(): libwpg::WPGPaintInterface()
+{
+}
+
+void ScrPainter::startGraphics(double width, double height)
+{
+ CurrColorFill = "Black";
+ CurrFillShade = 100.0;
+ CurrColorStroke = "Black";
+ CurrStrokeShade = 100.0;
+ CurrStrokeTrans = 0.0;
+ CurrFillTrans = 0.0;
+ Coords.resize(0);
+ Coords.svgInit();
+ LineW = 1.0;
+ lineJoin = Qt::MiterJoin;
+ lineEnd = Qt::FlatCap;
+ fillrule = true;
+ gradientAngle = 0.0;
+ isGradient = false;
+ fillSet = false;
+ strokeSet = false;
+ currentGradient = VGradient(VGradient::linear);
+ currentGradient.clearStops();
+ currentGradient.setRepeatMethod( VGradient::none );
+ dashArray.clear();
+ if (flags & LoadSavePlugin::lfCreateDoc)
+ {
+ m_Doc->setPage(72 * width, 72 * height, 0, 0, 0, 0, 0, 0, false, false);
+ if (width > height)
+ m_Doc->PageOri = 1;
+ else
+ m_Doc->PageOri = 0;
+ m_Doc->m_pageSize = "Custom";
+ m_Doc->changePageMargins(0, 0, 0, 0, 72 * height, 72 * width, 72 * height, 72 * width, m_Doc->PageOri, m_Doc->m_pageSize, m_Doc->currentPage()->pageNr(), 0);
+ }
+ firstLayer = true;
+}
+
+void ScrPainter::endGraphics()
+{
+}
+
+void ScrPainter::startLayer(unsigned int id)
+{
+ if (flags & LoadSavePlugin::lfCreateDoc)
+ {
+ if (!firstLayer)
+ m_Doc->addLayer(QString("Layer %1").arg(id), true);
+ firstLayer = false;
+ }
+}
+
+void ScrPainter::endLayer(unsigned int id)
+{
+}
+
+void ScrPainter::setPen(const libwpg::WPGPen& pen)
+{
+ LineW = 72 * pen.width;
+ ScColor tmp;
+ ColorList::Iterator it;
+ CurrColorStroke = "Black";
+ CurrStrokeShade = 100.0;
+ int Rc, Gc, Bc, hR, hG, hB;
+ bool found = false;
+ Rc = pen.foreColor.red;
+ Gc = pen.foreColor.green;
+ Bc = pen.foreColor.blue;
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelRGB)
+ {
+ it.value().getRGB(&hR, &hG, &hB);
+ if ((Rc == hR) && (Gc == hG) && (Bc == hB))
+ {
+ CurrColorStroke = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ {
+ tmp.setColorRGB(Rc, Gc, Bc);
+ tmp.setSpotColor(false);
+ tmp.setRegistrationColor(false);
+ QString newColorName = "FromWPG"+tmp.name();
+ m_Doc->PageColors.insert(newColorName, tmp);
+ importedColors.append(newColorName);
+ CurrColorStroke = newColorName;
+ }
+ CurrStrokeTrans = pen.foreColor.alpha / 256.0;
+ if(!pen.solid)
+ {
+ dashArray.clear();
+ for(unsigned i = 0; i < pen.dashArray.count(); i++)
+ {
+ dashArray.append(pen.dashArray.at(i)*LineW);
+ }
+ }
+ switch (pen.joinstyle)
+ {
+ case 1:
+ lineJoin = Qt::BevelJoin;
+ break;
+ case 2:
+ lineJoin = Qt::MiterJoin;
+ break;
+ case 3:
+ lineJoin = Qt::RoundJoin;
+ break;
+ default:
+ lineJoin = Qt::MiterJoin;
+ break;
+ }
+ switch (pen.capstyle)
+ {
+ case 0:
+ lineEnd = Qt::FlatCap;
+ break;
+ case 1:
+ lineEnd = Qt::RoundCap;
+ break;
+ case 2:
+ lineEnd = Qt::SquareCap;
+ break;
+ default:
+ lineEnd = Qt::FlatCap;
+ break;
+ }
+ strokeSet = true;
+}
+
+void ScrPainter::setBrush(const libwpg::WPGBrush& brush)
+{
+ ScColor tmp;
+ ColorList::Iterator it;
+ CurrColorFill = "Black";
+ CurrFillShade = 100.0;
+ int Rc, Gc, Bc, hR, hG, hB;
+ if(brush.style == libwpg::WPGBrush::Solid)
+ {
+ bool found = false;
+ Rc = brush.foreColor.red;
+ Gc = brush.foreColor.green;
+ Bc = brush.foreColor.blue;
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelRGB)
+ {
+ it.value().getRGB(&hR, &hG, &hB);
+ if ((Rc == hR) && (Gc == hG) && (Bc == hB))
+ {
+ CurrColorFill = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ {
+ tmp.setColorRGB(Rc, Gc, Bc);
+ tmp.setSpotColor(false);
+ tmp.setRegistrationColor(false);
+ QString newColorName = "FromWPG"+tmp.name();
+ m_Doc->PageColors.insert(newColorName, tmp);
+ importedColors.append(newColorName);
+ CurrColorFill = newColorName;
+ }
+ CurrFillTrans = brush.foreColor.alpha / 256.0;
+ }
+ else if (brush.style == libwpg::WPGBrush::Gradient)
+ {
+ gradientAngle = brush.gradient.angle();
+ isGradient = true;
+ currentGradient = VGradient(VGradient::linear);
+ currentGradient.clearStops();
+ for(unsigned c = 0; c < brush.gradient.count(); c++)
+ {
+ QString currStopColor = CommonStrings::None;
+ bool found = false;
+ Rc = brush.gradient.stopColor(c).red;
+ Gc = brush.gradient.stopColor(c).green;
+ Bc = brush.gradient.stopColor(c).blue;
+ for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
+ {
+ if (it.value().getColorModel() == colorModelRGB)
+ {
+ it.value().getRGB(&hR, &hG, &hB);
+ if ((Rc == hR) && (Gc == hG) && (Bc == hB))
+ {
+ currStopColor = it.key();
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ {
+ tmp.setColorRGB(Rc, Gc, Bc);
+ tmp.setSpotColor(false);
+ tmp.setRegistrationColor(false);
+ QString newColorName = "FromWPG"+tmp.name();
+ m_Doc->PageColors.insert(newColorName, tmp);
+ importedColors.append(newColorName);
+ currStopColor = newColorName;
+ }
+ const ScColor& gradC = m_Doc->PageColors[currStopColor];
+ currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), fabs(brush.gradient.stopOffset(c)), 0.5, 1.0, currStopColor, 100 );
+ }
+ }
+ else if (brush.style == libwpg::WPGBrush::NoBrush)
+ CurrColorFill = CommonStrings::None;
+ fillSet = true;
+}
+
+void ScrPainter::setFillRule(FillRule rule)
+{
+ if(rule == libwpg::WPGPaintInterface::WindingFill)
+ fillrule = false;
+ else
+ fillrule = true;
+// qDebug() << "Fill Rule " << fillrule;
+}
+
+void ScrPainter::drawRectangle(const libwpg::WPGRect& rect, double rx, double ry)
+{
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, baseX, baseY, rect.width() * 72.0, rect.height() * 72.0, LineW, CurrColorFill, CurrColorStroke, true);
+ PageItem *ite = m_Doc->Items->at(z);
+ if ((rx > 0) && (ry > 0))
+ {
+ ite->setCornerRadius(qMax(72*rx, 72*ry));
+ ite->SetFrameRound();
+ m_Doc->setRedrawBounding(ite);
+ }
+ QTransform mm = QTransform();
+ mm.translate(72*rect.x1, 72*rect.y1);
+ ite->PoLine.map(mm);
+ ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ finishItem(ite);
+// qDebug() << "draw Rect";
+}
+
+void ScrPainter::drawEllipse(const libwpg::WPGPoint& center, double rx, double ry)
+{
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, baseX, baseY, rx * 144.0, ry * 144.0, LineW, CurrColorFill, CurrColorStroke, true);
+ PageItem *ite = m_Doc->Items->at(z);
+ QTransform mm = QTransform();
+ mm.translate(72*(center.x - rx), 72*(center.y - ry));
+ ite->PoLine.map(mm);
+ ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ finishItem(ite);
+// qDebug() << "draw Ellipse";
+}
+
+void ScrPainter::drawPolygon(const libwpg::WPGPointArray& vertices, bool closed)
+{
+ if(vertices.count() < 2)
+ return;
+ Coords.resize(0);
+ Coords.svgInit();
+ PageItem *ite;
+ Coords.svgMoveTo(72 * vertices[0].x, 72 * vertices[0].y);
+ for(unsigned i = 1; i < vertices.count(); i++)
+ {
+ Coords.svgLineTo(72 * vertices[i].x, 72 * vertices[i].y);
+ }
+ if (closed)
+ Coords.svgClosePath();
+ if (Coords.size() > 0)
+ {
+ int z;
+ if (closed)
+ z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ else
+ z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CommonStrings::None, CurrColorStroke, true);
+ ite = m_Doc->Items->at(z);
+ ite->PoLine = Coords.copy();
+ ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ finishItem(ite);
+ }
+// qDebug() << "draw Polygon";
+}
+
+void ScrPainter::drawPath(const libwpg::WPGPath& path)
+{
+ Coords.resize(0);
+ Coords.svgInit();
+ PageItem *ite;
+ for(unsigned i = 0; i < path.count(); i++)
+ {
+ libwpg::WPGPathElement element = path.element(i);
+ libwpg::WPGPoint point = element.point;
+ switch(element.type)
+ {
+ case libwpg::WPGPathElement::MoveToElement:
+ Coords.svgMoveTo(72 * point.x, 72 * point.y);
+ break;
+ case libwpg::WPGPathElement::LineToElement:
+ Coords.svgLineTo(72 * point.x, 72 * point.y);
+ break;
+ case libwpg::WPGPathElement::CurveToElement:
+ Coords.svgCurveToCubic(72*element.extra1.x, 72*element.extra1.y, 72*element.extra2.x, 72*element.extra2.y, 72 * point.x, 72 * point.y);
+ break;
+ default:
+ break;
+ }
+ }
+ if (Coords.size() > 0)
+ {
+ int z;
+ if (fillSet)
+ {
+ if (!path.filled)
+ CurrColorFill = CommonStrings::None;
+ }
+ if (strokeSet)
+ {
+ if (!path.framed)
+ CurrColorStroke = CommonStrings::None;
+ }
+ if(path.closed)
+ {
+ Coords.svgClosePath();
+ z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ }
+ else
+ z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, LineW, CurrColorFill, CurrColorStroke, true);
+ ite = m_Doc->Items->at(z);
+ ite->PoLine = Coords.copy();
+ ite->PoLine.translate(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ finishItem(ite);
+ }
+// qDebug() << "draw Path";
+}
+
+void ScrPainter::finishItem(PageItem* ite)
+{
+ ite->ClipEdited = true;
+ ite->Frame = false;
+ ite->FrameType = 3;
+ ite->setFillShade(CurrFillShade);
+ ite->setFillEvenOdd(fillrule);
+ ite->setLineShade(CurrStrokeShade);
+ ite->setFillTransparency(CurrFillTrans);
+ ite->setLineTransparency(CurrStrokeTrans);
+ ite->setLineJoin(lineJoin);
+ ite->setLineEnd(lineEnd);
+ ite->DashValues = dashArray;
+ FPoint wh = getMaxClipF(&ite->PoLine);
+ ite->setWidthHeight(wh.x(),wh.y());
+ ite->setTextFlowMode(PageItem::TextFlowDisabled);
+ m_Doc->AdjustItemSize(ite);
+ ite->OldB2 = ite->width();
+ ite->OldH2 = ite->height();
+ if (isGradient)
+ {
+ ite->fill_gradient = currentGradient;
+ ite->GrType = 6;
+ QTransform m1;
+ m1.rotate(-gradientAngle);
+ ite->GrStartX = 0;
+ ite->GrStartY = 0;
+ QPointF target = m1.map(QPointF(0.0, ite->height()));
+ ite->GrEndX = target.x();
+ ite->GrEndY = target.y();
+ }
+ ite->updateClip();
+ Elements.append(ite);
+ Coords.resize(0);
+ Coords.svgInit();
+}
+
+void ScrPainter::drawBitmap(const libwpg::WPGBitmap& bitmap, double hres, double vres)
+{
+ QImage image = QImage(bitmap.width(), bitmap.height(), QImage::Format_RGB32);
+ for(int x = 0; x < bitmap.width(); x++)
+ {
+ for(int y = 0; y < bitmap.height(); y++)
+ {
+ libwpg::WPGColor color = bitmap.pixel(x, y);
+ image.setPixel(x, y, qRgb(color.red, color.green, color.blue));
+ }
+ }
+ double w = (bitmap.rect.x2 - bitmap.rect.x1) * 72.0;
+ double h = (bitmap.rect.y2 - bitmap.rect.y1) * 72.0;
+ int z = m_Doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, bitmap.rect.x1 * 72 + baseX, bitmap.rect.y1 * 72 + baseY, w, h, 1, m_Doc->toolSettings.dBrushPict, CommonStrings::None, true);
+ PageItem *ite = m_Doc->Items->at(z);
+ ite->tempImageFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_svg_XXXXXX.png");
+ ite->tempImageFile->open();
+ QString fileName = getLongPathName(ite->tempImageFile->fileName());
+ ite->tempImageFile->close();
+ ite->isInlineImage = true;
+ image.setDotsPerMeterX ((int) (hres / 0.0254));
+ image.setDotsPerMeterY ((int) (vres / 0.0254));
+ image.save(fileName, "PNG");
+ m_Doc->LoadPict(fileName, z);
+ ite->setImageScalingMode(false, false);
+ ite->moveBy(m_Doc->currentPage()->xOffset(), m_Doc->currentPage()->yOffset());
+ finishItem(ite);
+// qDebug() << "drawBitmap";
+}
+
+void ScrPainter::drawImageObject(const libwpg::WPGBinaryData& /*binaryData*/)
+{
+// qDebug() << "drawBinaryData";
+}
+
+
+WpgPlug::WpgPlug(ScribusDoc* doc, int flags)
+{
+ tmpSel=new Selection(this, false);
+ m_Doc=doc;
+ interactive = (flags & LoadSavePlugin::lfInteractive);
+}
+
+bool WpgPlug::import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
+{
+ QString fName = fNameIn;
+ bool success = false;
+ interactive = (flags & LoadSavePlugin::lfInteractive);
+ importerFlags = flags;
+ cancel = false;
+ double x, y, b, h;
+ bool ret = false;
+ QFileInfo fi = QFileInfo(fName);
+ if ( !ScCore->usingGUI() )
+ {
+ interactive = false;
+ showProgress = false;
+ }
+ if ( showProgress )
+ {
+ ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
+ progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw );
+ QStringList barNames, barTexts;
+ barNames << "GI";
+ barTexts << tr("Analyzing File:");
+ QList<bool> barsNumeric;
+ barsNumeric << false;
+ progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
+ progressDialog->setOverallTotalSteps(3);
+ progressDialog->setOverallProgress(0);
+ progressDialog->setProgress("GI", 0);
+ progressDialog->show();
+ connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
+ qApp->processEvents();
+ }
+ else
+ progressDialog = NULL;
+/* Set default Page to size defined in Preferences */
+ x = 0.0;
+ y = 0.0;
+ b = 0.0;
+ h = 0.0;
+ if (progressDialog)
+ {
+ progressDialog->setOverallProgress(1);
+ qApp->processEvents();
+ }
+ if (b == 0.0)
+ b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth;
+ if (h == 0.0)
+ h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight;
+ docWidth = b;
+ docHeight = h;
+ baseX = 0;
+ baseY = 0;
+ if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
+ {
+ m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false);
+ m_Doc->addPage(0);
+ m_Doc->view()->addPage(0, true);
+ baseX = 0;
+ baseY = 0;
+ }
+ else
+ {
+ if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
+ {
+ m_Doc=ScCore->primaryMainWindow()->doFileNew(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
+ ScCore->primaryMainWindow()->HaveNewDoc();
+ ret = true;
+ baseX = 0;
+ baseY = 0;
+ baseX = m_Doc->currentPage()->xOffset();
+ baseY = m_Doc->currentPage()->yOffset();
+ }
+ }
+ if ((!ret) && (interactive))
+ {
+ baseX = m_Doc->currentPage()->xOffset();
+ baseY = m_Doc->currentPage()->yOffset();
+ }
+ if ((ret) || (!interactive))
+ {
+ if (docWidth > docHeight)
+ m_Doc->PageOri = 1;
+ else
+ m_Doc->PageOri = 0;
+ m_Doc->m_pageSize = "Custom";
+ }
+ Elements.clear();
+ FPoint minSize = m_Doc->minCanvasCoordinate;
+ FPoint maxSize = m_Doc->maxCanvasCoordinate;
+ FPoint cOrigin = m_Doc->view()->canvasOrigin();
+ m_Doc->setLoading(true);
+ m_Doc->DoDrawing = false;
+ m_Doc->view()->updatesOn(false);
+ m_Doc->scMW()->ScriptRunning = true;
+ qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
+ QString CurDirP = QDir::currentPath();
+ QDir::setCurrent(fi.path());
+ if (convert(fName))
+ {
+ tmpSel->clear();
+ QDir::setCurrent(CurDirP);
+ if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc)))
+ {
+ bool isGroup = true;
+ int firstElem = -1;
+ if (Elements.at(0)->Groups.count() != 0)
+ firstElem = Elements.at(0)->Groups.top();
+ for (int bx = 0; bx < Elements.count(); ++bx)
+ {
+ PageItem* bxi = Elements.at(bx);
+ if (bxi->Groups.count() != 0)
+ {
+ if (bxi->Groups.top() != firstElem)
+ isGroup = false;
+ }
+ else
+ isGroup = false;
+ }
+ if (!isGroup)
+ {
+ double minx = 99999.9;
+ double miny = 99999.9;
+ double maxx = -99999.9;
+ double maxy = -99999.9;
+ uint lowestItem = 999999;
+ uint highestItem = 0;
+ for (int a = 0; a < Elements.count(); ++a)
+ {
+ Elements.at(a)->Groups.push(m_Doc->GroupCounter);
+ PageItem* currItem = Elements.at(a);
+ lowestItem = qMin(lowestItem, currItem->ItemNr);
+ highestItem = qMax(highestItem, currItem->ItemNr);
+ double x1, x2, y1, y2;
+ currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
+ minx = qMin(minx, x1);
+ miny = qMin(miny, y1);
+ maxx = qMax(maxx, x2);
+ maxy = qMax(maxy, y2);
+ }
+ double gx = minx;
+ double gy = miny;
+ double gw = maxx - minx;
+ double gh = maxy - miny;
+ PageItem *high = m_Doc->Items->at(highestItem);
+ int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, m_Doc->toolSettings.dBrush, m_Doc->toolSettings.dPen, true);
+ PageItem *neu = m_Doc->Items->takeAt(z);
+ m_Doc->Items->insert(lowestItem, neu);
+ neu->Groups.push(m_Doc->GroupCounter);
+ neu->setItemName( tr("Group%1").arg(neu->Groups.top()));
+ neu->AutoName = false;
+ neu->isGroupControl = true;
+ neu->groupsLastItem = high;
+ neu->setTextFlowMode(PageItem::TextFlowDisabled);
+ for (int a = 0; a < m_Doc->Items->count(); ++a)
+ {
+ m_Doc->Items->at(a)->ItemNr = a;
+ }
+ Elements.prepend(neu);
+ m_Doc->GroupCounter++;
+ }
+ }
+ m_Doc->DoDrawing = true;
+ m_Doc->scMW()->ScriptRunning = false;
+ m_Doc->setLoading(false);
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ if ((Elements.count() > 0) && (!ret) && (interactive))
+ {
+ if (flags & LoadSavePlugin::lfScripted)
+ {
+ bool loadF = m_Doc->isLoading();
+ m_Doc->setLoading(false);
+ m_Doc->changed();
+ m_Doc->setLoading(loadF);
+ m_Doc->m_Selection->delaySignalsOn();
+ for (int dre=0; dre<Elements.count(); ++dre)
+ {
+ m_Doc->m_Selection->addItem(Elements.at(dre), true);
+ }
+ m_Doc->m_Selection->delaySignalsOff();
+ m_Doc->m_Selection->setGroupRect();
+ m_Doc->view()->updatesOn(true);
+ }
+ else
+ {
+ m_Doc->DragP = true;
+ m_Doc->DraggedElem = 0;
+ m_Doc->DragElements.clear();
+ m_Doc->m_Selection->delaySignalsOn();
+ for (int dre=0; dre<Elements.count(); ++dre)
+ {
+ m_Doc->DragElements.append(Elements.at(dre)->ItemNr);
+ tmpSel->addItem(Elements.at(dre), true);
+ }
+ tmpSel->setGroupRect();
+ ScriXmlDoc *ss = new ScriXmlDoc();
+ ScElemMimeData* md = new ScElemMimeData();
+ md->setScribusElem(ss->WriteElem(m_Doc, m_Doc->view(), tmpSel));
+ delete ss;
+ m_Doc->itemSelection_DeleteItem(tmpSel);
+ m_Doc->view()->updatesOn(true);
+ m_Doc->m_Selection->delaySignalsOff();
+ // We must copy the TransationSettings object as it is owned
+ // by handleObjectImport method afterwards
+ TransactionSettings* transacSettings = new TransactionSettings(trSettings);
+ m_Doc->view()->handleObjectImport(md, transacSettings);
+ m_Doc->DragP = false;
+ m_Doc->DraggedElem = 0;
+ m_Doc->DragElements.clear();
+ }
+ }
+ else
+ {
+ m_Doc->changed();
+ m_Doc->reformPages();
+ m_Doc->view()->updatesOn(true);
+ }
+ success = true;
+ }
+ else
+ {
+ QDir::setCurrent(CurDirP);
+ m_Doc->DoDrawing = true;
+ m_Doc->scMW()->ScriptRunning = false;
+ m_Doc->view()->updatesOn(true);
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ }
+ if (interactive)
+ m_Doc->setLoading(false);
+ //CB If we have a gui we must refresh it if we have used the progressbar
+ if ((showProgress) && (!interactive))
+ m_Doc->view()->DrawNew();
+ return success;
+}
+
+WpgPlug::~WpgPlug()
+{
+ if (progressDialog)
+ delete progressDialog;
+ delete tmpSel;
+}
+
+bool WpgPlug::convert(QString fn)
+{
+ QString tmp;
+ importedColors.clear();
+
+ QFile file(fn);
+ if ( !file.exists() )
+ {
+ qDebug() << "File " << QFile::encodeName(fn).data() << " does not exist" << endl;
+ return false;
+ }
+ if ( !file.open( QIODevice::ReadOnly ) )
+ {
+ qDebug() << "Cannot open file " << QFile::encodeName(fn).data() << endl;
+ return false;
+ }
+ QByteArray ba = file.readAll();
+ file.close();
+
+ libwpg::WPGMemoryStream input(ba.constData(), ba.size());
+ if (!libwpg::WPGraphics::isSupported(&input))
+ {
+ fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n");
+ return false;
+ }
+ ScrPainter painter;
+ painter.m_Doc = m_Doc;
+ painter.baseX = baseX;
+ painter.baseY = baseY;
+ painter.flags = importerFlags;
+ libwpg::WPGraphics::parse(&input, &painter);
+ Elements = painter.Elements;
+ importedColors = painter.importedColors;
+ if (Elements.count() == 0)
+ {
+ if (importedColors.count() != 0)
+ {
+ for (int cd = 0; cd < importedColors.count(); cd++)
+ {
+ m_Doc->PageColors.remove(importedColors[cd]);
+ }
+ }
+ }
+/* if(progressDialog)
+ {
+ progressDialog->setOverallProgress(2);
+ progressDialog->setLabel("GI", tr("Generating Items"));
+ qApp->processEvents();
+ } */
+ if (progressDialog)
+ progressDialog->close();
+ return true;
+}
Index: scribus/plugins/wpgimplugin/importwpg.h
===================================================================
--- scribus/plugins/wpgimplugin/importwpg.h (revision 13950)
+++ scribus/plugins/wpgimplugin/importwpg.h (revision 13951)
@@ -17,7 +17,7 @@
#include "fpointarray.h"
#include "vgradient.h"
#include <QList>
-#include <QMatrix>
+#include <QTransform>
#include <QMultiMap>
#include <QVector>
#include "wpg/libwpg.h"
Index: scribus/plugins/colorwheel/colorwheelwidget.cpp
===================================================================
--- scribus/plugins/colorwheel/colorwheelwidget.cpp (revision 13950)
+++ scribus/plugins/colorwheel/colorwheelwidget.cpp (revision 13951)
@@ -120,10 +120,10 @@
widthH = width / 2;
for (int i = 0; i < 360; ++i)
{
- QMatrix matrix;
+ QTransform matrix;
matrix.translate(widthH, heightH);
matrix.rotate((float)i);
- p.setWorldMatrix(matrix);
+ p.setWorldTransform(matrix);
QColor c;
c.setHsv(i, 255, 255);
p.setPen(QPen(c, 7));
Index: scribus/plugins/colorwheel/colorwheelwidget.h
===================================================================
--- scribus/plugins/colorwheel/colorwheelwidget.h (revision 13950)
+++ scribus/plugins/colorwheel/colorwheelwidget.h (revision 13951)
@@ -105,7 +105,7 @@
ColorMap colorMap;
/** \brief Angle diff between colorMap and painted wheel itself.
- QMatrix wheel and colorMap have different start points.
+ QTransform wheel and colorMap have different start points.
It's taken from Qt. */
int angleShift;
Index: scribus/plugins/svgimplugin/svgplugin.cpp
===================================================================
--- scribus/plugins/svgimplugin/svgplugin.cpp (revision 13950)
+++ scribus/plugins/svgimplugin/svgplugin.cpp (revision 13951)
@@ -321,7 +321,7 @@
QStringList points = viewbox.replace( QRegExp(","), " ").simplified().split( ' ', QString::SkipEmptyParts );
if (points.size() > 3)
{
- QMatrix matrix;
+ QTransform matrix;
QSize wh2 = parseWidthHeight(docElem);
double w2 = wh2.width();
double h2 = wh2.height();
@@ -518,7 +518,7 @@
void SVGPlug::setupTransform( const QDomElement &e )
{
SvgStyle *gc = m_gc.top();
- QMatrix mat = parseTransform( e.attribute( "transform" ) );
+ QTransform mat = parseTransform( e.attribute( "transform" ) );
if (!e.attribute("transform").isEmpty())
gc->matrix = mat * gc->matrix;
}
@@ -526,7 +526,7 @@
void SVGPlug::finishNode( const QDomNode &e, PageItem* item)
{
SvgStyle *gc = m_gc.top();
- QMatrix gcm = gc->matrix;
+ QTransform gcm = gc->matrix;
double BaseX = m_Doc->currentPage()->xOffset();
double BaseY = m_Doc->currentPage()->yOffset();
double coeff1 = sqrt(gcm.m11() * gcm.m11() + gcm.m12() * gcm.m12());
@@ -537,7 +537,7 @@
{
item->ClipEdited = true;
item->FrameType = 3;
- QMatrix mm = gc->matrix;
+ QTransform mm = gc->matrix;
item->PoLine.map(mm);
item->setLineWidth(item->lineWidth() * (coeff1 + coeff2) / 2.0);
FPoint wh = getMaxClipF(&item->PoLine);
@@ -557,7 +557,7 @@
}
case PageItem::TextFrame:
{
- QMatrix mm = gc->matrix;
+ QTransform mm = gc->matrix;
item->setLineWidth(item->lineWidth() * (coeff1 + coeff2) / 2.0);
}
break;
@@ -565,11 +565,11 @@
{
item->ClipEdited = true;
item->FrameType = 3;
- QMatrix mm = gc->matrix;
+ QTransform mm = gc->matrix;
item->PoLine.map(mm);
/*if (haveViewBox)
{
- QMatrix mv;
+ QTransform mv;
mv.translate(viewTransformX, viewTransformY);
mv.scale(viewScaleX, viewScaleY);
ite->PoLine.map(mv);
@@ -615,7 +615,7 @@
{
item->GrType = gc->Gradient;
item->setPattern(importedPattTrans[gc->GCol1]);
- QMatrix mm = gc->matrixg;
+ QTransform mm = gc->matrixg;
double rot = getRotationFromMatrix(mm, 0.0) * 180 / M_PI;
mm.rotate(rot);
double patDx = (item->xPos() - BaseX) - mm.dx();
@@ -637,7 +637,7 @@
double angle2 = atan2(item->GrEndY - item->GrStartX, item->GrEndX - item->GrStartX)*(180.0/M_PI);
double dx = item->GrStartX + (item->GrEndX - item->GrStartX) / 2.0;
double dy = item->GrStartY + (item->GrEndY - item->GrStartY) / 2.0;
- QMatrix mm, mm2;
+ QTransform mm, mm2;
if ((gc->GY1 < gc->GY2) && (gc->GX1 < gc->GX2))
{
mm.rotate(-angle2);
@@ -654,7 +654,7 @@
}
else
{
- QMatrix mm = gc->matrix;
+ QTransform mm = gc->matrix;
mm = gc->matrixg * mm;
FPointArray gra;
gra.setPoints(2, gc->GX1, gc->GY1, gc->GX2, gc->GY2);
@@ -982,7 +982,7 @@
neu->setWidthHeight(gw, gh);
if (clipPath.size() != 0)
{
- QMatrix mm = gc->matrix;
+ QTransform mm = gc->matrix;
neu->PoLine = clipPath.copy();
neu->PoLine.map(mm);
neu->PoLine.translate(-gx + BaseX, -gy + BaseY);
@@ -1169,7 +1169,7 @@
SvgStyle *gc = m_gc.top();
int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, BaseX, BaseY, r * 2.0, r * 2.0, gc->LWidth, gc->FillCol, gc->StrokeCol, true);
PageItem* ite = m_Doc->Items->at(z);
- QMatrix mm = QMatrix();
+ QTransform mm = QTransform();
mm.translate(x, y);
ite->PoLine.map(mm);
FPoint wh = getMaxClipF(&ite->PoLine);
@@ -1193,7 +1193,7 @@
SvgStyle *gc = m_gc.top();
int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, BaseX, BaseY, rx * 2.0, ry * 2.0, gc->LWidth, gc->FillCol, gc->StrokeCol, true);
PageItem* ite = m_Doc->Items->at(z);
- QMatrix mm = QMatrix();
+ QTransform mm = QTransform();
mm.translate(x, y);
ite->PoLine.map(mm);
FPoint wh = getMaxClipF(&ite->PoLine);
@@ -1380,7 +1380,7 @@
ite->SetFrameRound();
m_Doc->setRedrawBounding(ite);
}
- QMatrix mm = QMatrix();
+ QTransform mm = QTransform();
mm.translate(x, y);
ite->PoLine.map(mm);
FPoint wh = getMaxClipF(&ite->PoLine);
@@ -1549,11 +1549,11 @@
setupNode(e);
if( e.hasAttribute("x") || e.hasAttribute("y") )
{
- QMatrix matrix;
+ QTransform matrix;
double xAtt = ScCLocale::toDoubleC(e.attribute("x", "0.0"));
double yAtt = ScCLocale::toDoubleC(e.attribute("y", "0.0"));
SvgStyle *gc = m_gc.top();
- gc->matrix = QMatrix(1.0, 0.0, 0.0, 1.0, xAtt, yAtt) * gc->matrix;
+ gc->matrix = QTransform(1.0, 0.0, 0.0, 1.0, xAtt, yAtt) * gc->matrix;
}
QString href = e.attribute("xlink:href").mid(1);
QMap<QString, QDomElement>::Iterator it = m_nodeMap.find(href);
@@ -1767,9 +1767,9 @@
return value;
}
-QMatrix SVGPlug::parseTransform( const QString &transform )
+QTransform SVGPlug::parseTransform( const QString &transform )
{
- QMatrix ret;
+ QTransform ret;
// Workaround for QString::split() bug when string ends with space
QString trans = transform.simplified();
// Split string for handling 1 transform statement at a time
@@ -1778,7 +1778,7 @@
QStringList::ConstIterator end = subtransforms.end();
for(; it != end; ++it)
{
- QMatrix result;
+ QTransform result;
QStringList subtransform = it->split('(', QString::SkipEmptyParts);
subtransform[0] = subtransform[0].trimmed().toLower();
subtransform[1] = subtransform[1].simplified();
@@ -1827,7 +1827,7 @@
double p2 = ScCLocale::toDoubleC(params[2]);
double p4 = ScCLocale::toDoubleC(params[4]);
double p5 = ScCLocale::toDoubleC(params[5]);
- result.setMatrix(sx, p1, p2, sy, p4, p5);
+ result = QTransform(sx, p1, p2, sy, p4, p5);
}
}
ret = result * ret;
@@ -2096,7 +2096,7 @@
unsigned int end = params.lastIndexOf(")");
QString key = params.mid(start, end - start);
obj->Gradient = 0;
- obj->matrixg = QMatrix();
+ obj->matrixg = QTransform();
bool firstMatrixValid = false;
if (m_gradients[key].matrixValid)
{
Index: scribus/plugins/svgimplugin/svgplugin.h
===================================================================
--- scribus/plugins/svgimplugin/svgplugin.h (revision 13950)
+++ scribus/plugins/svgimplugin/svgplugin.h (revision 13951)
@@ -91,7 +91,7 @@
bool cspaceValid;
VGradient gradient;
bool gradientValid;
- QMatrix matrix;
+ QTransform matrix;
bool matrixValid;
QString reference;
int Type;
@@ -166,8 +166,8 @@
double GY2;
bool InherCol;
double LWidth;
- QMatrix matrix;
- QMatrix matrixg;
+ QTransform matrix;
+ QTransform matrixg;
Qt::PenStyle PLineArt;
Qt::PenCapStyle PLineEnd;
Qt::PenJoinStyle PLineJoin;
@@ -230,7 +230,7 @@
double fromPercentage(const QString &s );
double parseFontSize(const QString& fsize);
double parseUnit(const QString &unit);
- QMatrix parseTransform(const QString &transform);
+ QTransform parseTransform(const QString &transform);
bool parseSVG( const QString &s, FPointArray *ite );
QColor parseColorN( const QString &rgbColor );
QString parseColor( const QString &s );
Index: scribus/plugins/fileloader/scribus13format/scribus13format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus13format/scribus13format.cpp (revision 13950)
+++ scribus/plugins/fileloader/scribus13format/scribus13format.cpp (revision 13951)
@@ -2075,7 +2075,7 @@
{
currItem->imageClip = currItem->pixm.imgInfo.PDSpathData[clPath].copy();
currItem->pixm.imgInfo.usedPath = clPath;
- QMatrix cl;
+ QTransform cl;
cl.translate(currItem->imageXOffset()*currItem->imageXScale(), currItem->imageYOffset()*currItem->imageYScale());
cl.scale(currItem->imageXScale(), currItem->imageYScale());
currItem->imageClip.map(cl);
Index: scribus/canvas.h
===================================================================
--- scribus/canvas.h (revision 13950)
+++ scribus/canvas.h (revision 13951)
@@ -202,7 +202,7 @@
void PaintSizeRect(QRect neu);
void PaintSizeRect(QPolygon neu);
void Transform(PageItem *currItem, QPainter *p);
- void Transform(PageItem *currItem, QMatrix& m);
+ void Transform(PageItem *currItem, QTransform& m);
void TransformM(PageItem *currItem, QPainter *p);
void getGroupRectScreen(double *x, double *y, double *w, double *h);
Index: scribus/scpainterex_gdiplus.h
===================================================================
--- scribus/scpainterex_gdiplus.h (revision 13950)
+++ scribus/scpainterex_gdiplus.h (revision 13951)
@@ -1,187 +1,187 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-/* This file is part of the KDE project
- Copyright (C) 2001, 2002, 2003 The Karbon Developers
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-/* Adapted for Scribus 22.08.2003 by Franz Schmid */
-/* Adapted for Scribus 15.01.2006 by Jean Ghali */
-
-#ifndef __SCPAINTEREX_GDIPLUS_H__
-#define __SCPAINTEREX_GDIPLUS_H__
-
-// libart wrapper
-
-#include <QColor>
-#include <QFont>
-#include <QGlobalStatic>
-#include <QList>
-#include <QMatrix>
-#include <QPixmap>
-#include <QStack>
-
-#include "scribusapi.h"
-#include "scconfig.h"
-#include "fpoint.h"
-#include "fpointarray.h"
-#include "vgradient.h"
-
-#include "scpainterexbase.h"
-
-#include <valarray>
-#include <windows.h>
-
-class QPainter;
-class ScribusDoc;
-
-namespace Gdiplus
-{
- class Graphics;
- class GraphicsPath;
-};
-
-class SCRIBUS_API ScPainterEx_GDIPlus : public ScPainterExBase
-{
-public:
-
- ScPainterEx_GDIPlus(HDC hDC, QRect& rect, ScribusDoc* doc, bool gray );
- virtual ~ScPainterEx_GDIPlus();
-
- virtual Capabilities capabilities() { return transparencies; }
-
- virtual int supportedColorModes() { return (int) rgbMode; }
- virtual ColorMode preferredColorMode() { return rgbMode; }
- virtual ImageMode imageMode() { return rgbImages; }
-
- virtual void begin();
- virtual void end();
- virtual void clear();
- virtual void clear( ScColorShade & );
-
- // matrix manipulation
- virtual void setWorldMatrix( const QMatrix & );
- virtual const QMatrix worldMatrix();
- virtual void translate( double, double );
- virtual void rotate( double );
- virtual void scale( double, double );
-
- // drawing
- virtual void moveTo( const double &, const double & );
- virtual void lineTo( const double &, const double & );
- virtual void curveTo( FPoint p1, FPoint p2, FPoint p3 );
- virtual void newPath();
- virtual void fillTextPath();
- virtual void strokeTextPath();
- virtual void fillPath();
- virtual void strokePath();
- virtual void setFillRule( bool fillRule );
- virtual bool fillRule() { return m_fillRule; }
- virtual void setFillMode( int fill );
- virtual int fillMode() { return m_fillMode; }
- virtual void setGradient( VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc = FPoint(0,0));
- virtual void setPattern ( ScPattern* pattern, QMatrix& patternTransform );
- virtual void setClipPath();
-
- virtual void drawImage( ScImage *image, ScPainterExBase::ImageMode mode );
- virtual void setupPolygon(FPointArray *points, bool closed = true);
- virtual void drawPolygon();
- virtual void drawPolyLine();
- virtual void drawLine(FPoint start, FPoint end);
- virtual void drawRect(double, double, double, double);
-
- // pen + brush
- virtual ScColorShade pen();
- virtual ScColorShade brush();
- virtual void setPen( const ScColorShade & );
- virtual void setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo );
- virtual void setPenOpacity( double op );
- virtual void setLineWidth( double w);
- virtual void setDash(const QList<double>& array, double ofs);
- virtual void setBrush( const ScColorShade & );
- virtual void setBrushOpacity( double op );
- virtual void setOpacity( double op );
- virtual void setFont( const QFont &f );
- virtual QFont font();
-
- // stack management
- virtual void save();
- virtual void restore();
-
- virtual void setRasterOp( int op );
-
-private:
-
- void drawVPath( int mode );
- void drawGradient( VGradientEx& gradient );
- void drawLinearGradient( VGradientEx& gradient, const QRect& rect );
- void drawCircularGradient( VGradientEx& gradient, const QRect& rect );
- void getClipPathDimensions( QRect& r );
- void transformPoint( const FPoint& in, FPoint& out );
- void transformPoints( const FPoint* in, FPoint* out, uint length );
-
- ScribusDoc* m_doc;
-
- unsigned int m_width;
- unsigned int m_height;
- QMatrix m_matrix;
- QFont m_font;
-/* Filling */
- ScColorShade m_fillColor;
- double m_fillTrans;
- bool m_fillRule;
- int m_fillMode; // 0 = none, 1 = solid, 2 = gradient
- int m_gradientMode; // 1 = linear, 2 = radial
-/* Stroking */
- ScColorShade m_strokeColor;
- double m_strokeTrans;
- double m_lineWidth;
-/* Grayscale conversion option */
- bool m_convertToGray;
-
-/* Line End Style */
- Qt::PenCapStyle m_lineEnd;
-/* Line Join Style */
- Qt::PenJoinStyle m_lineJoin;
-/* The Dash Array */
- QList<double> m_array;
- double m_offset;
-/* Transformation Stack */
- QStack<QMatrix> m_stack;
-
-/* Some data to describe state of drawing */
- bool m_pathIsClosed;
- bool m_drawingClosedPath;
-
-/* Device context */
- HDC m_dc;
-
-/* Color conversion function */
- QColor transformColor( ScColorShade& colorShade, double trans );
- void transformImage( QImage* image, uchar* data, int scan);
-
- QStack<int> m_gStates;
- Gdiplus::Graphics* m_graphics;
- Gdiplus::GraphicsPath* m_graphicsPath;
- double m_positionX;
- double m_positionY;
-};
-
-#endif
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+/* This file is part of the KDE project
+ Copyright (C) 2001, 2002, 2003 The Karbon Developers
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/* Adapted for Scribus 22.08.2003 by Franz Schmid */
+/* Adapted for Scribus 15.01.2006 by Jean Ghali */
+
+#ifndef __SCPAINTEREX_GDIPLUS_H__
+#define __SCPAINTEREX_GDIPLUS_H__
+
+// libart wrapper
+
+#include <QColor>
+#include <QFont>
+#include <QGlobalStatic>
+#include <QList>
+#include <QTransform>
+#include <QPixmap>
+#include <QStack>
+
+#include "scribusapi.h"
+#include "scconfig.h"
+#include "fpoint.h"
+#include "fpointarray.h"
+#include "vgradient.h"
+
+#include "scpainterexbase.h"
+
+#include <valarray>
+#include <windows.h>
+
+class QPainter;
+class ScribusDoc;
+
+namespace Gdiplus
+{
+ class Graphics;
+ class GraphicsPath;
+};
+
+class SCRIBUS_API ScPainterEx_GDIPlus : public ScPainterExBase
+{
+public:
+
+ ScPainterEx_GDIPlus(HDC hDC, QRect& rect, ScribusDoc* doc, bool gray );
+ virtual ~ScPainterEx_GDIPlus();
+
+ virtual Capabilities capabilities() { return transparencies; }
+
+ virtual int supportedColorModes() { return (int) rgbMode; }
+ virtual ColorMode preferredColorMode() { return rgbMode; }
+ virtual ImageMode imageMode() { return rgbImages; }
+
+ virtual void begin();
+ virtual void end();
+ virtual void clear();
+ virtual void clear( ScColorShade & );
+
+ // matrix manipulation
+ virtual void setWorldMatrix( const QTransform & );
+ virtual const QTransform worldMatrix();
+ virtual void translate( double, double );
+ virtual void rotate( double );
+ virtual void scale( double, double );
+
+ // drawing
+ virtual void moveTo( const double &, const double & );
+ virtual void lineTo( const double &, const double & );
+ virtual void curveTo( FPoint p1, FPoint p2, FPoint p3 );
+ virtual void newPath();
+ virtual void fillTextPath();
+ virtual void strokeTextPath();
+ virtual void fillPath();
+ virtual void strokePath();
+ virtual void setFillRule( bool fillRule );
+ virtual bool fillRule() { return m_fillRule; }
+ virtual void setFillMode( int fill );
+ virtual int fillMode() { return m_fillMode; }
+ virtual void setGradient( VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc = FPoint(0,0));
+ virtual void setPattern ( ScPattern* pattern, QTransform& patternTransform );
+ virtual void setClipPath();
+
+ virtual void drawImage( ScImage *image, ScPainterExBase::ImageMode mode );
+ virtual void setupPolygon(FPointArray *points, bool closed = true);
+ virtual void drawPolygon();
+ virtual void drawPolyLine();
+ virtual void drawLine(FPoint start, FPoint end);
+ virtual void drawRect(double, double, double, double);
+
+ // pen + brush
+ virtual ScColorShade pen();
+ virtual ScColorShade brush();
+ virtual void setPen( const ScColorShade & );
+ virtual void setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo );
+ virtual void setPenOpacity( double op );
+ virtual void setLineWidth( double w);
+ virtual void setDash(const QList<double>& array, double ofs);
+ virtual void setBrush( const ScColorShade & );
+ virtual void setBrushOpacity( double op );
+ virtual void setOpacity( double op );
+ virtual void setFont( const QFont &f );
+ virtual QFont font();
+
+ // stack management
+ virtual void save();
+ virtual void restore();
+
+ virtual void setRasterOp( int op );
+
+private:
+
+ void drawVPath( int mode );
+ void drawGradient( VGradientEx& gradient );
+ void drawLinearGradient( VGradientEx& gradient, const QRect& rect );
+ void drawCircularGradient( VGradientEx& gradient, const QRect& rect );
+ void getClipPathDimensions( QRect& r );
+ void transformPoint( const FPoint& in, FPoint& out );
+ void transformPoints( const FPoint* in, FPoint* out, uint length );
+
+ ScribusDoc* m_doc;
+
+ unsigned int m_width;
+ unsigned int m_height;
+ QTransform m_matrix;
+ QFont m_font;
+/* Filling */
+ ScColorShade m_fillColor;
+ double m_fillTrans;
+ bool m_fillRule;
+ int m_fillMode; // 0 = none, 1 = solid, 2 = gradient
+ int m_gradientMode; // 1 = linear, 2 = radial
+/* Stroking */
+ ScColorShade m_strokeColor;
+ double m_strokeTrans;
+ double m_lineWidth;
+/* Grayscale conversion option */
+ bool m_convertToGray;
+
+/* Line End Style */
+ Qt::PenCapStyle m_lineEnd;
+/* Line Join Style */
+ Qt::PenJoinStyle m_lineJoin;
+/* The Dash Array */
+ QList<double> m_array;
+ double m_offset;
+/* Transformation Stack */
+ QStack<QTransform> m_stack;
+
+/* Some data to describe state of drawing */
+ bool m_pathIsClosed;
+ bool m_drawingClosedPath;
+
+/* Device context */
+ HDC m_dc;
+
+/* Color conversion function */
+ QColor transformColor( ScColorShade& colorShade, double trans );
+ void transformImage( QImage* image, uchar* data, int scan);
+
+ QStack<int> m_gStates;
+ Gdiplus::Graphics* m_graphics;
+ Gdiplus::GraphicsPath* m_graphicsPath;
+ double m_positionX;
+ double m_positionY;
+};
+
+#endif
Index: scribus/canvasmode_edit.cpp
===================================================================
--- scribus/canvasmode_edit.cpp (revision 13950)
+++ scribus/canvasmode_edit.cpp (revision 13951)
@@ -378,7 +378,7 @@
{
if (currItem->asImageFrame())
{
- QMatrix ro;
+ QTransform ro;
ro.rotate(-currItem->rotation());
QPointF rota = ro.map(QPointF(newX-Mxp,newY-Myp));
currItem->moveImageInFrame(rota.x()/currItem->imageXScale(), rota.y()/currItem->imageYScale());
@@ -454,7 +454,7 @@
double ny = np2.y();
m_doc->ApplyGuides(&nx, &ny);
np2 = FPoint(qRound(nx*sc), qRound(ny*sc));
- QMatrix pm;
+ QTransform pm;
switch (frameResizeHandle)
{
case 1:
@@ -503,7 +503,7 @@
double nh = currItem->height();
if ((frameResizeHandle == 1) || (frameResizeHandle == 2))
{
- QMatrix mp;
+ QTransform mp;
switch (frameResizeHandle)
{
case 1:
@@ -512,7 +512,7 @@
//Shift proportional square resize
if ((m->modifiers() & Qt::ShiftModifier) && (!(m->modifiers() & Qt::ControlModifier)))
{
- QMatrix ma;
+ QTransform ma;
ma.translate(currItem->xPos(), currItem->yPos());
ma.rotate(currItem->rotation());
ma = ma.inverted();
@@ -524,7 +524,7 @@
//Control proportional resize
if ((m->modifiers() & Qt::ControlModifier) && (!(m->modifiers() & Qt::ShiftModifier)))
{
- QMatrix ma;
+ QTransform ma;
ma.translate(currItem->xPos(), currItem->yPos());
ma.rotate(currItem->rotation());
ma = ma.inverted();
@@ -560,12 +560,12 @@
erf = m_doc->SizeItem(nx, nh, currItem->ItemNr);
else
erf = m_doc->SizeItem(nx, ny, currItem->ItemNr);
- QMatrix mp;
+ QTransform mp;
mp.translate(currItem->xPos(),// - m_doc->minCanvasCoordinate.x(),
currItem->yPos());// - m_doc->minCanvasCoordinate.y());
mp.rotate(currItem->rotation());
np2 = QPoint(qRound(nx), qRound(ny));
- QMatrix pm;
+ QTransform pm;
m_canvas->Transform(currItem, pm);
m_canvas->PaintSizeRect(pm.mapToPolygon(QRect(QPoint(0, 0), np2)));
}
@@ -573,7 +573,7 @@
{
double rba = currItem->rotation();
currItem->setRotation(0.0);
- QMatrix mp;
+ QTransform mp;
m_canvas->Transform(currItem, mp);
// mp.translate(-m_doc->minCanvasCoordinate.x(), -m_doc->minCanvasCoordinate.y());
np = QPoint(m->x(), m->y()) * mp.inverted();
@@ -590,7 +590,7 @@
currItem->setRotation(rba);
np = m_doc->ApplyGrid(np);
erf = m_doc->SizeItem(sizeItemX, sizeItemY, currItem->ItemNr);
- QMatrix pm;
+ QTransform pm;
// pm.translate(-m_doc->minCanvasCoordinate.x() * m_canvas->scale(),-m_doc->minCanvasCoordinate.y() * m_canvas->scale());
m_canvas->Transform(currItem, pm);
m_canvas->newRedrawPolygon() << pm.map(QPoint(0, 0)) << pm.map(QPoint(qRound(currItem->width()), qRound(currItem->height())));
@@ -607,7 +607,7 @@
m_doc->SnapGuides = sav;
if (sav)
currItem->Sizing = true;
- QMatrix pm;
+ QTransform pm;
// pm.translate(-m_doc->minCanvasCoordinate.x() * m_canvas->scale(),-m_doc->minCanvasCoordinate.y() * m_canvas->scale());
m_canvas->Transform(currItem, pm);
m_canvas->newRedrawPolygon() << pm.map(QPoint(0, 0)) << pm.map(QPoint(qRound(currItem->width()), qRound(currItem->height())));
@@ -622,11 +622,11 @@
double nx = newP.x();
double ny = newP.y();
m_doc->ApplyGuides(&nx, &ny);
- QMatrix mp;
+ QTransform mp;
// mp.translate(currItem->xPos() - m_doc->minCanvasCoordinate.x(), currItem->yPos() - m_doc->minCanvasCoordinate.y());
mp.rotate(currItem->rotation());
np2 = QPoint(qRound(nx), qRound(ny)) * mp.inverted();
- QMatrix pm;
+ QTransform pm;
m_canvas->Transform(currItem, pm);
m_canvas->PaintSizeRect(pm.mapToPolygon(QRect(np2, QPoint(qRound(currItem->width()), qRound(currItem->height())))));
}
@@ -640,11 +640,11 @@
double nx = newP.x();
double ny = newP.y();
m_doc->ApplyGuides(&nx, &ny);
- QMatrix mp;
+ QTransform mp;
// mp.translate(currItem->xPos() - m_doc->minCanvasCoordinate.x(), currItem->yPos() - m_doc->minCanvasCoordinate.y());
mp.rotate(currItem->rotation());
np2 = QPoint(qRound(nx), qRound(ny)) * mp.inverted();
- QMatrix pm;
+ QTransform pm;
m_canvas->Transform(currItem, pm);
switch (frameResizeHandle)
{
@@ -921,7 +921,7 @@
m_canvas->PaintSizeRect(QRect());
FPoint npf, npf2;
QRect tx;
- QMatrix pm;
+ QTransform pm;
m_canvas->m_viewMode.m_MouseButtonPressed = true;
m_canvas->m_viewMode.operItemMoving = false;
m_view->HaveSelRect = false;
@@ -1225,7 +1225,7 @@
for (int a = 0; a < docItemCount; ++a)
{
PageItem* docItem = m_doc->Items->at(a);
- QMatrix p;
+ QTransform p;
m_canvas->Transform(docItem, p);
QRegion apr = QRegion(docItem->Clip * p);
QRect apr2(docItem->getRedrawBounding(1.0));
@@ -1299,7 +1299,7 @@
const unsigned SELECT_IN_GROUP = Qt::AltModifier;
const unsigned SELECT_MULTIPLE = Qt::ShiftModifier;
const unsigned SELECT_BENEATH = Qt::ControlModifier;
- QMatrix p;
+ QTransform p;
QRectF tx, mpo;
PageItem *currItem;
m_canvas->m_viewMode.m_MouseButtonPressed = true;
Index: scribus/canvasmode_drawbezier.cpp
===================================================================
--- scribus/canvasmode_drawbezier.cpp (revision 13950)
+++ scribus/canvasmode_drawbezier.cpp (revision 13951)
@@ -1,531 +1,531 @@
-/*
- For general Scribus (>=1.3.2) copyright and licensing information please refer
- to the COPYING file provided with the program. Following this notice may exist
- a copyright and/or license notice that predates the release of Scribus 1.3.2
- for which a new license (GPL+exception) is in place.
- */
-/***************************************************************************
-* *
-* This program is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-* *
-***************************************************************************/
-
-
-#include "canvasmode_drawbezier.h"
-
-#include <QApplication>
-#include <QButtonGroup>
-#include <QCheckBox>
-#include <QCursor>
-#include <QEvent>
-#include <QMessageBox>
-#include <QMouseEvent>
-#include <QPainterPath>
-#include <QPoint>
-#include <QRect>
-#include <QWidgetAction>
-
-
-#include "canvas.h"
-#include "canvasgesture_resize.h"
-#include "fpoint.h"
-#include "fpointarray.h"
-#include "hyphenator.h"
-#include "ui/insertTable.h"
-#include "ui/oneclick.h"
-#include "pageitem_textframe.h"
-#include "ui/pageselector.h"
-#include "prefscontext.h"
-#include "prefsfile.h"
-#include "prefsmanager.h"
-#include "ui/propertiespalette.h"
-#include "scraction.h"
-#include "ui/scrapbookpalette.h"
-#include "scribus.h"
-#include "scribusdoc.h"
-#include "scribusview.h"
-#include "scribusXml.h"
-#include "selection.h"
-#include "undomanager.h"
-#include "units.h"
-#include "util.h"
-#include "util_icon.h"
-#include "util_math.h"
-
-
-
-BezierMode::BezierMode(ScribusView* view) : CanvasMode(view)
-{
- GxM = GyM = -1;
- Mxp = Myp = -1;
- Dxp = Dyp = -1;
- MoveGX = MoveGY = false;
- oldCp = Cp = -1;
- frameResizeHandle = -1;
- RotMode = 0;
- inItemCreation = false;
- shiftSelItems = false;
- FirstPoly = true;
- m_createTransaction = NULL;
-}
-
-
-void BezierMode::drawControls(QPainter* p)
-{
- //
-}
-
-inline bool BezierMode::GetItem(PageItem** pi)
-{
- *pi = m_doc->m_Selection->itemAt(0);
- return (*pi) != NULL;
-}
-
-void BezierMode::finalizeItem(PageItem* currItem)
-{
- currItem->PoLine.resize(currItem->PoLine.size()-2);
- if (currItem->PoLine.size() < 4)
- {
-// emit DelObj(m_doc->currentPage->pageNr(), currItem->ItemNr);
- m_doc->Items->removeAt(currItem->ItemNr);
- m_doc->m_Selection->removeFirst();
- //emit HaveSel(-1);
- }
- else
- {
- m_doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem->ItemNr, false, false);
-// currItem->setPolyClip(qRound(qMax(currItem->lineWidth() / 2.0, 1)));
- m_doc->AdjustItemSize(currItem);
- currItem->ContourLine = currItem->PoLine.copy();
- }
- m_view->resetMousePressed();
- currItem->checkChanges();
- if (m_createTransaction)
- {
- m_view->resetMousePressed();
- currItem->checkChanges(true);
- QString targetName = Um::ScratchSpace;
- if (currItem->OwnPage > -1)
- targetName = m_doc->Pages->at(currItem->OwnPage)->getUName();
- m_createTransaction->commit(targetName, currItem->getUPixmap(),
- Um::Create + " " + currItem->getUName(), "", Um::ICreate);
- delete m_createTransaction;
- m_createTransaction = NULL;
- }
- currItem->update();
- currItem->emitAllToGUI();
-}
-
-// the following code was moved from scribusview.cpp:
-
-void BezierMode::enterEvent(QEvent *)
-{
- if (!m_MouseButtonPressed)
- {
- setModeCursor();
- }
-}
-
-
-void BezierMode::leaveEvent(QEvent *e)
-{
- if (!m_MouseButtonPressed)
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
-}
-
-
-void BezierMode::activate(bool flag)
-{
-// qDebug() << "DrawBezierMode::activate" << flag;
- GxM = GyM = -1;
- Mxp = Myp = -1;
- Dxp = Dyp = -1;
- MoveGX = MoveGY = false;
- oldCp = Cp = -1;
- frameResizeHandle = -1;
- RotMode = 0;
- inItemCreation = false;
- shiftSelItems = false;
- FirstPoly = true;
- setModeCursor();
-}
-
-void BezierMode::deactivate(bool flag)
-{
-// qDebug() << "BezierMode::deactivate" << flag;
-// m_view->stopDragTimer();
- PageItem* currItem = m_doc->m_Selection->itemAt(0);
- if (m_createTransaction && currItem)
- {
- //FIXME : we should call finalizeItem() here, currently some
- //related code is executed in ScribusMainWindow::keyPressEvent()
- m_view->resetMousePressed();
- currItem->checkChanges(true);
- QString targetName = Um::ScratchSpace;
- if (currItem->OwnPage > -1)
- targetName = m_doc->Pages->at(currItem->OwnPage)->getUName();
- m_createTransaction->commit(targetName, currItem->getUPixmap(),
- Um::Create + " " + currItem->getUName(), "", Um::ICreate);
- delete m_createTransaction;
- m_createTransaction = NULL;
- }
- else if (m_createTransaction)
- {
- m_createTransaction->cancel();
- delete m_createTransaction;
- m_createTransaction = NULL;
- }
- m_view->redrawMarker->hide();
-}
-
-void BezierMode::mouseDoubleClickEvent(QMouseEvent *m)
-{
- m->accept();
- m_MouseButtonPressed = false;
- m_canvas->resetRenderMode();
- mousePressEvent(m);
-}
-
-
-void BezierMode::mouseMoveEvent(QMouseEvent *m)
-{
- const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
-
- double newX, newY;
- PageItem *currItem;
- QPoint np, np2, mop;
- FPoint npf, npf2;
- QRect tx;
- m->accept();
- m_canvas->displayCorrectedXYHUD(m->globalPos(), mousePointDoc.x(), mousePointDoc.y());
-// qDebug() << "legacy mode move:" << m->x() << m->y() << m_canvas->globalToCanvas(m->globalPos()).x() << m_canvas->globalToCanvas(m->globalPos()).y();
-// emit MousePos(m->x()/m_canvas->scale(),// + m_doc->minCanvasCoordinate.x(),
-// m->y()/m_canvas->scale()); // + m_doc->minCanvasCoordinate.y());
-/* if (m_doc->guidesSettings.guidesShown)
- {
- if (MoveGY)
- {
- m_view->FromHRuler(m);
- return;
- }
- if (MoveGX)
- {
- m_view->FromVRuler(m);
- return;
- }
- }
-*/
-
- if (commonMouseMove(m))
- return;
-
- if (inItemCreation)
- {
- if ((GetItem(&currItem)) && (!shiftSelItems))
- {
- newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
- newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
-
- if (m_doc->DragP)
- return;
-
- if (m_doc->appMode == modeDrawBezierLine)
- {
- if ((m_doc->useRaster) && (m_doc->OnPage(currItem) != -1))
- {
- newX = qRound(newX / m_doc->guidesSettings.minorGridSpacing) * m_doc->guidesSettings.minorGridSpacing;
- newY = qRound(newY / m_doc->guidesSettings.minorGridSpacing) * m_doc->guidesSettings.minorGridSpacing;
- }
- m_canvas->newRedrawPolygon() << QPoint(qRound(newX - currItem->xPos()), qRound(newY - currItem->yPos()));
- m_view->updateCanvas();
- Mxp = newX;
- Myp = newY;
- }
-
- }
- else
- {
- if ((m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton) && (GyM == -1) && (GxM == -1))
- {
- newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
- newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
- SeRx = newX;
- SeRy = newY;
- /*
- if (m_doc->appMode == modeDrawTable)
- m_view->redrawMarker->setGeometry(QRect(Dxp, Dyp, m->globalPos().x() - Dxp, m->globalPos().y() - Dyp).normalized());
- else
- m_view->redrawMarker->setGeometry(QRect(Mxp, Myp, m->globalPos().x() - Mxp, m->globalPos().y() - Myp).normalized());
- */
- QPoint startP = m_canvas->canvasToGlobal(QPointF(Mxp, Myp));
- m_view->redrawMarker->setGeometry(QRect(startP, m->globalPos()).normalized());
- if (!m_view->redrawMarker->isVisible())
- m_view->redrawMarker->show();
- m_view->HaveSelRect = true;
- return;
- }
- }
- }
-}
-
-void BezierMode::mousePressEvent(QMouseEvent *m)
-{
- const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
-
- int z;
- double Rxp = 0;
- double Ryp = 0;
- double Rxpd = 0;
- double Rypd = 0;
- PageItem *currItem;
-// m_canvas->PaintSizeRect(QRect());
- FPoint npf, npf2;
- QRect tx;
- QMatrix pm;
- m_MouseButtonPressed = true;
- m_view->HaveSelRect = false;
- m_doc->DragP = false;
- m_doc->leaveDrag = false;
- MoveGX = MoveGY = false;
-// inItemCreation = false;
-// oldClip = 0;
- m->accept();
- m_view->registerMousePress(m->globalPos());
- Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
- Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
- QRect mpo(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
-// mpo.moveBy(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
- Rxp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).x();
- Rxpd = Mxp - Rxp;
- Mxp = qRound(Rxp);
- Ryp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).y();
- Rypd = Myp - Ryp;
- Myp = qRound(Ryp);
- SeRx = Mxp;
- SeRy = Myp;
- if (m->button() == Qt::MidButton)
- {
- m_view->MidButt = true;
- if (m->modifiers() & Qt::ControlModifier)
- m_view->DrawNew();
- return;
- }
- if (m->button() == Qt::RightButton)
- {
- m_view->stopGesture();
- return;
- }
- if (FirstPoly)
- {
- selectPage(m);
- m_createTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction());
- z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, Rxp, Ryp, 1+Rxpd, 1+Rypd, m_doc->toolSettings.dWidthLine, CommonStrings::None, m_doc->toolSettings.dPenLine, true);
- currItem = m_doc->Items->at(z);
- m_doc->m_Selection->clear();
- m_doc->m_Selection->addItem(currItem);
- qApp->changeOverrideCursor(QCursor(Qt::CrossCursor));
- m_canvas->setRenderModeFillBuffer();
- inItemCreation = true;
- }
- currItem = m_doc->m_Selection->itemAt(0);
- // pm.translate(-m_doc->minCanvasCoordinate.x()*m_canvas->scale(), -m_doc->minCanvasCoordinate.y()*m_canvas->scale());
- pm = currItem->getTransform();
- npf = m_doc->ApplyGridF(mousePointDoc).transformPoint(pm, true);
- currItem->PoLine.addPoint(npf);
- npf2 = getMinClipF(&currItem->PoLine);
- if (npf2.x() < 0)
- {
- currItem->PoLine.translate(-npf2.x(), 0);
- m_doc->MoveItem(npf2.x(), 0, currItem);
- }
- if (npf2.y() < 0)
- {
- currItem->PoLine.translate(0, -npf2.y());
- m_doc->MoveItem(0, npf2.y(), currItem);
- }
- m_doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem->ItemNr, false, false, false);
- currItem->setPolyClip(qRound(qMax(currItem->lineWidth() / 2, 1.0)));
- m_canvas->newRedrawPolygon();
-}
-
-
-
-void BezierMode::mouseReleaseEvent(QMouseEvent *m)
-{
- const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
-
-
- PageItem *currItem;
- m_MouseButtonPressed = false;
- m_canvas->resetRenderMode();
- m->accept();
-// m_view->stopDragTimer();
-
- m_canvas->setRenderModeUseBuffer(false);
- if ((m_doc->appMode == modeDrawBezierLine) && (m->button() == Qt::LeftButton))
- {
- m_canvas->setRenderModeUseBuffer(true);
- currItem = m_doc->m_Selection->itemAt(0);
- currItem->ClipEdited = true;
- currItem->FrameType = 3;
- QMatrix pm = currItem->getTransform();
- FPoint npf = m_doc->ApplyGridF(mousePointDoc).transformPoint(pm, true);
- currItem->PoLine.addPoint(npf);
- bool ssiz = currItem->Sizing;
- currItem->Sizing = true;
- if ((currItem->PoLine.size() % 4 == 0) && (currItem->PoLine.size() > 3))
- {
- FPoint lxy(currItem->PoLine.point(currItem->PoLine.size()-2));
- FPoint lk(currItem->PoLine.point(currItem->PoLine.size()-1));
- double dx = lxy.x() - lk.x();
- double dy = lxy.y() - lk.y();
- lk.setX(lk.x() + dx*2);
- lk.setY(lk.y() + dy*2);
- currItem->PoLine.addPoint(lxy);
- currItem->PoLine.addPoint(lk);
- }
- FPoint np2(getMinClipF(&currItem->PoLine));
- if (np2.x() < 0)
- {
- currItem->PoLine.translate(-np2.x(), 0);
- m_doc->MoveItem(np2.x(), 0, currItem);
- }
- if (np2.y() < 0)
- {
- currItem->PoLine.translate(0, -np2.y());
- m_doc->MoveItem(0, np2.y(), currItem);
- }
- if (FirstPoly)
- {
- FirstPoly = false;
- currItem->Sizing = ssiz;
- }
- else
- {
- m_doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem->ItemNr, false, false, false);
- m_doc->AdjustItemSize(currItem);
- currItem->Sizing = ssiz;
- currItem->ContourLine = currItem->PoLine.copy();
- m_canvas->setRenderModeUseBuffer(false);
- currItem->update();
- }
- m_canvas->setRenderModeFillBuffer();
- int newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
- int newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
- m_canvas->newRedrawPolygon() << QPoint(newX - qRound(currItem->xPos()), newY - qRound(currItem->yPos()));
- m_view->updateCanvas();
- }
- if ((m_doc->appMode == modeDrawBezierLine) && (m->button() == Qt::RightButton))
- {
- currItem = m_doc->m_Selection->itemAt(0);
- if (currItem!=0)
- {
- finalizeItem(currItem);
- }
-
- if (!PrefsManager::instance()->appPrefs.stickyTools)
- {
-// qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- m_view->requestMode(modeNormal);
-// m_view->requestMode(submodePaintingDone);
- }
- else
- m_view->requestMode(m_doc->appMode);
- m_doc->changed();
-// emit DocChanged();
- FirstPoly = true;
- inItemCreation = false;
- m_canvas->setRenderModeUseBuffer(false);
-// m_view->updateContents();
- }
- m_doc->DragP = false;
- m_doc->leaveDrag = false;
-// m_canvas->m_viewMode.operItemResizing = false;
- m_view->MidButt = false;
- shiftSelItems = false;
-// m_doc->SubMode = -1;
- if (m_view->groupTransactionStarted())
- {
- for (int i = 0; i < m_doc->m_Selection->count(); ++i)
- m_doc->m_Selection->itemAt(i)->checkChanges(true);
- m_view->endGroupTransaction();
- }
-
-//??? for (int i = 0; i < m_doc->m_Selection->count(); ++i)
-//??? m_doc->m_Selection->itemAt(i)->checkChanges(true);
-
-// //Commit drag created items to undo manager.
-// if (m_doc->m_Selection->itemAt(0)!=NULL)
-// {
-// m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0)->ItemNr);
-// }
- //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas
- m_view->zoomSpinBox->clearFocus();
- m_view->pageSelector->clearFocus();
- if (m_doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action
- {
- currItem = m_doc->m_Selection->itemAt(0);
- m_doc->nodeEdit.finishTransaction(currItem);
- }
- else
- {
- //delete oldClip;
- //oldClip = 0;
- }
-}
-
-
-
-void BezierMode::selectPage(QMouseEvent *m)
-{
- m_MouseButtonPressed = true;
- FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
- Mxp = mousePointDoc.x(); //static_cast<int>(m->x()/m_canvas->scale());
- Myp = mousePointDoc.y(); //static_cast<int>(m->y()/m_canvas->scale());
- QRect mpo(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
-// mpo.moveBy(qRound(Doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
- m_doc->nodeEdit.deselect();
- m_view->Deselect(false);
- if (!m_doc->masterPageMode())
- {
- int i = m_doc->OnPage(Mxp, Myp);
- if (i!=-1)
- {
- uint docCurrPageNo=m_doc->currentPageNumber();
- uint j=static_cast<uint>(i);
- if (docCurrPageNo != j)
- {
- m_doc->setCurrentPage(m_doc->Pages->at(j));
- m_view->setMenTxt(j);
- m_view->DrawNew();
- }
- }
-/* uint docPagesCount=m_doc->Pages->count();
- uint docCurrPageNo=m_doc->currentPageNumber();
- for (uint i = 0; i < docPagesCount; ++i)
- {
- int x = static_cast<int>(m_doc->Pages->at(i)->xOffset() * m_canvas->scale());
- int y = static_cast<int>(m_doc->Pages->at(i)->yOffset() * m_canvas->scale());
- int w = static_cast<int>(m_doc->Pages->at(i)->width() * m_canvas->scale());
- int h = static_cast<int>(m_doc->Pages->at(i)->height() * m_canvas->scale());
- if (QRect(x, y, w, h).intersects(mpo))
- {
- if (docCurrPageNo != i)
- {
- m_doc->setCurrentPage(m_doc->Pages->at(i));
- setMenTxt(i);
- DrawNew();
- }
- break;
- }
- } */
-
- //FIXME m_view->setRulerPos(m_view->contentsX(), m_view->contentsY());
- }
-}
-
-
-
+/*
+ For general Scribus (>=1.3.2) copyright and licensing information please refer
+ to the COPYING file provided with the program. Following this notice may exist
+ a copyright and/or license notice that predates the release of Scribus 1.3.2
+ for which a new license (GPL+exception) is in place.
+ */
+/***************************************************************************
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+***************************************************************************/
+
+
+#include "canvasmode_drawbezier.h"
+
+#include <QApplication>
+#include <QButtonGroup>
+#include <QCheckBox>
+#include <QCursor>
+#include <QEvent>
+#include <QMessageBox>
+#include <QMouseEvent>
+#include <QPainterPath>
+#include <QPoint>
+#include <QRect>
+#include <QWidgetAction>
+
+
+#include "canvas.h"
+#include "canvasgesture_resize.h"
+#include "fpoint.h"
+#include "fpointarray.h"
+#include "hyphenator.h"
+#include "ui/insertTable.h"
+#include "ui/oneclick.h"
+#include "pageitem_textframe.h"
+#include "ui/pageselector.h"
+#include "prefscontext.h"
+#include "prefsfile.h"
+#include "prefsmanager.h"
+#include "ui/propertiespalette.h"
+#include "scraction.h"
+#include "ui/scrapbookpalette.h"
+#include "scribus.h"
+#include "scribusdoc.h"
+#include "scribusview.h"
+#include "scribusXml.h"
+#include "selection.h"
+#include "undomanager.h"
+#include "units.h"
+#include "util.h"
+#include "util_icon.h"
+#include "util_math.h"
+
+
+
+BezierMode::BezierMode(ScribusView* view) : CanvasMode(view)
+{
+ GxM = GyM = -1;
+ Mxp = Myp = -1;
+ Dxp = Dyp = -1;
+ MoveGX = MoveGY = false;
+ oldCp = Cp = -1;
+ frameResizeHandle = -1;
+ RotMode = 0;
+ inItemCreation = false;
+ shiftSelItems = false;
+ FirstPoly = true;
+ m_createTransaction = NULL;
+}
+
+
+void BezierMode::drawControls(QPainter* p)
+{
+ //
+}
+
+inline bool BezierMode::GetItem(PageItem** pi)
+{
+ *pi = m_doc->m_Selection->itemAt(0);
+ return (*pi) != NULL;
+}
+
+void BezierMode::finalizeItem(PageItem* currItem)
+{
+ currItem->PoLine.resize(currItem->PoLine.size()-2);
+ if (currItem->PoLine.size() < 4)
+ {
+// emit DelObj(m_doc->currentPage->pageNr(), currItem->ItemNr);
+ m_doc->Items->removeAt(currItem->ItemNr);
+ m_doc->m_Selection->removeFirst();
+ //emit HaveSel(-1);
+ }
+ else
+ {
+ m_doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem->ItemNr, false, false);
+// currItem->setPolyClip(qRound(qMax(currItem->lineWidth() / 2.0, 1)));
+ m_doc->AdjustItemSize(currItem);
+ currItem->ContourLine = currItem->PoLine.copy();
+ }
+ m_view->resetMousePressed();
+ currItem->checkChanges();
+ if (m_createTransaction)
+ {
+ m_view->resetMousePressed();
+ currItem->checkChanges(true);
+ QString targetName = Um::ScratchSpace;
+ if (currItem->OwnPage > -1)
+ targetName = m_doc->Pages->at(currItem->OwnPage)->getUName();
+ m_createTransaction->commit(targetName, currItem->getUPixmap(),
+ Um::Create + " " + currItem->getUName(), "", Um::ICreate);
+ delete m_createTransaction;
+ m_createTransaction = NULL;
+ }
+ currItem->update();
+ currItem->emitAllToGUI();
+}
+
+// the following code was moved from scribusview.cpp:
+
+void BezierMode::enterEvent(QEvent *)
+{
+ if (!m_MouseButtonPressed)
+ {
+ setModeCursor();
+ }
+}
+
+
+void BezierMode::leaveEvent(QEvent *e)
+{
+ if (!m_MouseButtonPressed)
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+}
+
+
+void BezierMode::activate(bool flag)
+{
+// qDebug() << "DrawBezierMode::activate" << flag;
+ GxM = GyM = -1;
+ Mxp = Myp = -1;
+ Dxp = Dyp = -1;
+ MoveGX = MoveGY = false;
+ oldCp = Cp = -1;
+ frameResizeHandle = -1;
+ RotMode = 0;
+ inItemCreation = false;
+ shiftSelItems = false;
+ FirstPoly = true;
+ setModeCursor();
+}
+
+void BezierMode::deactivate(bool flag)
+{
+// qDebug() << "BezierMode::deactivate" << flag;
+// m_view->stopDragTimer();
+ PageItem* currItem = m_doc->m_Selection->itemAt(0);
+ if (m_createTransaction && currItem)
+ {
+ //FIXME : we should call finalizeItem() here, currently some
+ //related code is executed in ScribusMainWindow::keyPressEvent()
+ m_view->resetMousePressed();
+ currItem->checkChanges(true);
+ QString targetName = Um::ScratchSpace;
+ if (currItem->OwnPage > -1)
+ targetName = m_doc->Pages->at(currItem->OwnPage)->getUName();
+ m_createTransaction->commit(targetName, currItem->getUPixmap(),
+ Um::Create + " " + currItem->getUName(), "", Um::ICreate);
+ delete m_createTransaction;
+ m_createTransaction = NULL;
+ }
+ else if (m_createTransaction)
+ {
+ m_createTransaction->cancel();
+ delete m_createTransaction;
+ m_createTransaction = NULL;
+ }
+ m_view->redrawMarker->hide();
+}
+
+void BezierMode::mouseDoubleClickEvent(QMouseEvent *m)
+{
+ m->accept();
+ m_MouseButtonPressed = false;
+ m_canvas->resetRenderMode();
+ mousePressEvent(m);
+}
+
+
+void BezierMode::mouseMoveEvent(QMouseEvent *m)
+{
+ const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+
+ double newX, newY;
+ PageItem *currItem;
+ QPoint np, np2, mop;
+ FPoint npf, npf2;
+ QRect tx;
+ m->accept();
+ m_canvas->displayCorrectedXYHUD(m->globalPos(), mousePointDoc.x(), mousePointDoc.y());
+// qDebug() << "legacy mode move:" << m->x() << m->y() << m_canvas->globalToCanvas(m->globalPos()).x() << m_canvas->globalToCanvas(m->globalPos()).y();
+// emit MousePos(m->x()/m_canvas->scale(),// + m_doc->minCanvasCoordinate.x(),
+// m->y()/m_canvas->scale()); // + m_doc->minCanvasCoordinate.y());
+/* if (m_doc->guidesSettings.guidesShown)
+ {
+ if (MoveGY)
+ {
+ m_view->FromHRuler(m);
+ return;
+ }
+ if (MoveGX)
+ {
+ m_view->FromVRuler(m);
+ return;
+ }
+ }
+*/
+
+ if (commonMouseMove(m))
+ return;
+
+ if (inItemCreation)
+ {
+ if ((GetItem(&currItem)) && (!shiftSelItems))
+ {
+ newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
+ newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
+
+ if (m_doc->DragP)
+ return;
+
+ if (m_doc->appMode == modeDrawBezierLine)
+ {
+ if ((m_doc->useRaster) && (m_doc->OnPage(currItem) != -1))
+ {
+ newX = qRound(newX / m_doc->guidesSettings.minorGridSpacing) * m_doc->guidesSettings.minorGridSpacing;
+ newY = qRound(newY / m_doc->guidesSettings.minorGridSpacing) * m_doc->guidesSettings.minorGridSpacing;
+ }
+ m_canvas->newRedrawPolygon() << QPoint(qRound(newX - currItem->xPos()), qRound(newY - currItem->yPos()));
+ m_view->updateCanvas();
+ Mxp = newX;
+ Myp = newY;
+ }
+
+ }
+ else
+ {
+ if ((m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton) && (GyM == -1) && (GxM == -1))
+ {
+ newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
+ newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
+ SeRx = newX;
+ SeRy = newY;
+ /*
+ if (m_doc->appMode == modeDrawTable)
+ m_view->redrawMarker->setGeometry(QRect(Dxp, Dyp, m->globalPos().x() - Dxp, m->globalPos().y() - Dyp).normalized());
+ else
+ m_view->redrawMarker->setGeometry(QRect(Mxp, Myp, m->globalPos().x() - Mxp, m->globalPos().y() - Myp).normalized());
+ */
+ QPoint startP = m_canvas->canvasToGlobal(QPointF(Mxp, Myp));
+ m_view->redrawMarker->setGeometry(QRect(startP, m->globalPos()).normalized());
+ if (!m_view->redrawMarker->isVisible())
+ m_view->redrawMarker->show();
+ m_view->HaveSelRect = true;
+ return;
+ }
+ }
+ }
+}
+
+void BezierMode::mousePressEvent(QMouseEvent *m)
+{
+ const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+
+ int z;
+ double Rxp = 0;
+ double Ryp = 0;
+ double Rxpd = 0;
+ double Rypd = 0;
+ PageItem *currItem;
+// m_canvas->PaintSizeRect(QRect());
+ FPoint npf, npf2;
+ QRect tx;
+ QTransform pm;
+ m_MouseButtonPressed = true;
+ m_view->HaveSelRect = false;
+ m_doc->DragP = false;
+ m_doc->leaveDrag = false;
+ MoveGX = MoveGY = false;
+// inItemCreation = false;
+// oldClip = 0;
+ m->accept();
+ m_view->registerMousePress(m->globalPos());
+ Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
+ Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
+ QRect mpo(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
+// mpo.moveBy(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
+ Rxp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).x();
+ Rxpd = Mxp - Rxp;
+ Mxp = qRound(Rxp);
+ Ryp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).y();
+ Rypd = Myp - Ryp;
+ Myp = qRound(Ryp);
+ SeRx = Mxp;
+ SeRy = Myp;
+ if (m->button() == Qt::MidButton)
+ {
+ m_view->MidButt = true;
+ if (m->modifiers() & Qt::ControlModifier)
+ m_view->DrawNew();
+ return;
+ }
+ if (m->button() == Qt::RightButton)
+ {
+ m_view->stopGesture();
+ return;
+ }
+ if (FirstPoly)
+ {
+ selectPage(m);
+ m_createTransaction = new UndoTransaction(UndoManager::instance()->beginTransaction());
+ z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, Rxp, Ryp, 1+Rxpd, 1+Rypd, m_doc->toolSettings.dWidthLine, CommonStrings::None, m_doc->toolSettings.dPenLine, true);
+ currItem = m_doc->Items->at(z);
+ m_doc->m_Selection->clear();
+ m_doc->m_Selection->addItem(currItem);
+ qApp->changeOverrideCursor(QCursor(Qt::CrossCursor));
+ m_canvas->setRenderModeFillBuffer();
+ inItemCreation = true;
+ }
+ currItem = m_doc->m_Selection->itemAt(0);
+ // pm.translate(-m_doc->minCanvasCoordinate.x()*m_canvas->scale(), -m_doc->minCanvasCoordinate.y()*m_canvas->scale());
+ pm = currItem->getTransform();
+ npf = m_doc->ApplyGridF(mousePointDoc).transformPoint(pm, true);
+ currItem->PoLine.addPoint(npf);
+ npf2 = getMinClipF(&currItem->PoLine);
+ if (npf2.x() < 0)
+ {
+ currItem->PoLine.translate(-npf2.x(), 0);
+ m_doc->MoveItem(npf2.x(), 0, currItem);
+ }
+ if (npf2.y() < 0)
+ {
+ currItem->PoLine.translate(0, -npf2.y());
+ m_doc->MoveItem(0, npf2.y(), currItem);
+ }
+ m_doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem->ItemNr, false, false, false);
+ currItem->setPolyClip(qRound(qMax(currItem->lineWidth() / 2, 1.0)));
+ m_canvas->newRedrawPolygon();
+}
+
+
+
+void BezierMode::mouseReleaseEvent(QMouseEvent *m)
+{
+ const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+
+
+ PageItem *currItem;
+ m_MouseButtonPressed = false;
+ m_canvas->resetRenderMode();
+ m->accept();
+// m_view->stopDragTimer();
+
+ m_canvas->setRenderModeUseBuffer(false);
+ if ((m_doc->appMode == modeDrawBezierLine) && (m->button() == Qt::LeftButton))
+ {
+ m_canvas->setRenderModeUseBuffer(true);
+ currItem = m_doc->m_Selection->itemAt(0);
+ currItem->ClipEdited = true;
+ currItem->FrameType = 3;
+ QTransform pm = currItem->getTransform();
+ FPoint npf = m_doc->ApplyGridF(mousePointDoc).transformPoint(pm, true);
+ currItem->PoLine.addPoint(npf);
+ bool ssiz = currItem->Sizing;
+ currItem->Sizing = true;
+ if ((currItem->PoLine.size() % 4 == 0) && (currItem->PoLine.size() > 3))
+ {
+ FPoint lxy(currItem->PoLine.point(currItem->PoLine.size()-2));
+ FPoint lk(currItem->PoLine.point(currItem->PoLine.size()-1));
+ double dx = lxy.x() - lk.x();
+ double dy = lxy.y() - lk.y();
+ lk.setX(lk.x() + dx*2);
+ lk.setY(lk.y() + dy*2);
+ currItem->PoLine.addPoint(lxy);
+ currItem->PoLine.addPoint(lk);
+ }
+ FPoint np2(getMinClipF(&currItem->PoLine));
+ if (np2.x() < 0)
+ {
+ currItem->PoLine.translate(-np2.x(), 0);
+ m_doc->MoveItem(np2.x(), 0, currItem);
+ }
+ if (np2.y() < 0)
+ {
+ currItem->PoLine.translate(0, -np2.y());
+ m_doc->MoveItem(0, np2.y(), currItem);
+ }
+ if (FirstPoly)
+ {
+ FirstPoly = false;
+ currItem->Sizing = ssiz;
+ }
+ else
+ {
+ m_doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem->ItemNr, false, false, false);
+ m_doc->AdjustItemSize(currItem);
+ currItem->Sizing = ssiz;
+ currItem->ContourLine = currItem->PoLine.copy();
+ m_canvas->setRenderModeUseBuffer(false);
+ currItem->update();
+ }
+ m_canvas->setRenderModeFillBuffer();
+ int newX = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
+ int newY = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
+ m_canvas->newRedrawPolygon() << QPoint(newX - qRound(currItem->xPos()), newY - qRound(currItem->yPos()));
+ m_view->updateCanvas();
+ }
+ if ((m_doc->appMode == modeDrawBezierLine) && (m->button() == Qt::RightButton))
+ {
+ currItem = m_doc->m_Selection->itemAt(0);
+ if (currItem!=0)
+ {
+ finalizeItem(currItem);
+ }
+
+ if (!PrefsManager::instance()->appPrefs.stickyTools)
+ {
+// qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ m_view->requestMode(modeNormal);
+// m_view->requestMode(submodePaintingDone);
+ }
+ else
+ m_view->requestMode(m_doc->appMode);
+ m_doc->changed();
+// emit DocChanged();
+ FirstPoly = true;
+ inItemCreation = false;
+ m_canvas->setRenderModeUseBuffer(false);
+// m_view->updateContents();
+ }
+ m_doc->DragP = false;
+ m_doc->leaveDrag = false;
+// m_canvas->m_viewMode.operItemResizing = false;
+ m_view->MidButt = false;
+ shiftSelItems = false;
+// m_doc->SubMode = -1;
+ if (m_view->groupTransactionStarted())
+ {
+ for (int i = 0; i < m_doc->m_Selection->count(); ++i)
+ m_doc->m_Selection->itemAt(i)->checkChanges(true);
+ m_view->endGroupTransaction();
+ }
+
+//??? for (int i = 0; i < m_doc->m_Selection->count(); ++i)
+//??? m_doc->m_Selection->itemAt(i)->checkChanges(true);
+
+// //Commit drag created items to undo manager.
+// if (m_doc->m_Selection->itemAt(0)!=NULL)
+// {
+// m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0)->ItemNr);
+// }
+ //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas
+ m_view->zoomSpinBox->clearFocus();
+ m_view->pageSelector->clearFocus();
+ if (m_doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action
+ {
+ currItem = m_doc->m_Selection->itemAt(0);
+ m_doc->nodeEdit.finishTransaction(currItem);
+ }
+ else
+ {
+ //delete oldClip;
+ //oldClip = 0;
+ }
+}
+
+
+
+void BezierMode::selectPage(QMouseEvent *m)
+{
+ m_MouseButtonPressed = true;
+ FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+ Mxp = mousePointDoc.x(); //static_cast<int>(m->x()/m_canvas->scale());
+ Myp = mousePointDoc.y(); //static_cast<int>(m->y()/m_canvas->scale());
+ QRect mpo(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
+// mpo.moveBy(qRound(Doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
+ m_doc->nodeEdit.deselect();
+ m_view->Deselect(false);
+ if (!m_doc->masterPageMode())
+ {
+ int i = m_doc->OnPage(Mxp, Myp);
+ if (i!=-1)
+ {
+ uint docCurrPageNo=m_doc->currentPageNumber();
+ uint j=static_cast<uint>(i);
+ if (docCurrPageNo != j)
+ {
+ m_doc->setCurrentPage(m_doc->Pages->at(j));
+ m_view->setMenTxt(j);
+ m_view->DrawNew();
+ }
+ }
+/* uint docPagesCount=m_doc->Pages->count();
+ uint docCurrPageNo=m_doc->currentPageNumber();
+ for (uint i = 0; i < docPagesCount; ++i)
+ {
+ int x = static_cast<int>(m_doc->Pages->at(i)->xOffset() * m_canvas->scale());
+ int y = static_cast<int>(m_doc->Pages->at(i)->yOffset() * m_canvas->scale());
+ int w = static_cast<int>(m_doc->Pages->at(i)->width() * m_canvas->scale());
+ int h = static_cast<int>(m_doc->Pages->at(i)->height() * m_canvas->scale());
+ if (QRect(x, y, w, h).intersects(mpo))
+ {
+ if (docCurrPageNo != i)
+ {
+ m_doc->setCurrentPage(m_doc->Pages->at(i));
+ setMenTxt(i);
+ DrawNew();
+ }
+ break;
+ }
+ } */
+
+ //FIXME m_view->setRulerPos(m_view->contentsX(), m_view->contentsY());
+ }
+}
+
+
+
Index: scribus/canvas.cpp
===================================================================
--- scribus/canvas.cpp (revision 13950)
+++ scribus/canvas.cpp (revision 13951)
@@ -374,7 +374,7 @@
while (currNr >= 0)
{
currItem = m_doc->currentPage()->FromMaster.at(currNr);
- QMatrix itemPos;
+ QTransform itemPos;
if ((currItem->LayerID == m_doc->activeLayer()) && (!m_doc->layerLocked(currItem->LayerID)))
{
if (!currItem->ChangedMasterItem)
@@ -434,7 +434,7 @@
}
if ((currItem->LayerID == m_doc->activeLayer()) && (!m_doc->layerLocked(currItem->LayerID)))
{
- QMatrix itemPos = currItem->getTransform();
+ QTransform itemPos = currItem->getTransform();
QPainterPath currPath(itemPos.map(QPointF(0,0)));
currPath.lineTo(itemPos.map(QPointF(currItem->width(), 0)));
currPath.lineTo(itemPos.map(QPointF(currItem->width(), currItem->height())));
@@ -1318,7 +1318,7 @@
if ((cullingArea.intersects(currItem->getBoundingRect().adjusted(0.0, 0.0, 1.0, 1.0))) && (m_doc->guidesSettings.layerMarkersShown) && (m_doc->layerCount() > 1))
currItem->DrawObj(painter, cullingArea);
FPointArray cl = currItem->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(currItem->xPos(), currItem->yPos());
mm.rotate(currItem->rotation());
cl.map( mm );
@@ -1501,7 +1501,7 @@
{
painter->save();
FPointArray cl = currItem->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(currItem->xPos(), currItem->yPos());
mm.rotate(currItem->rotation());
cl.map( mm );
@@ -1983,7 +1983,7 @@
painter->setPen(Qt::black, 1.0 / m_viewMode.scale, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
painter->setPenOpacity(1.0);
painter->drawLine(start, end);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(end.x(), end.y());
double r = atan2(end.y()-start.y(), end.x()-start.x())*(180.0/M_PI);
arrowTrans.rotate(r);
@@ -2060,7 +2060,7 @@
p->rotate(currItem->rotation());
}
-void Canvas::Transform(PageItem *currItem, QMatrix& m)
+void Canvas::Transform(PageItem *currItem, QTransform& m)
{
m.translate(currItem->xPos()*m_viewMode.scale, currItem->yPos()*m_viewMode.scale);
m.scale(m_viewMode.scale, m_viewMode.scale);
@@ -2171,7 +2171,7 @@
gh = currItem->height();
r = currItem->rotation();
}
- QMatrix ma;
+ QTransform ma;
ma.translate(gx, gy);
ma.rotate(r);
FPoint n;
Index: scribus/pageitem_pathtext.cpp
===================================================================
--- scribus/pageitem_pathtext.cpp (revision 13950)
+++ scribus/pageitem_pathtext.cpp (revision 13951)
@@ -219,27 +219,27 @@
hl->PtransY = point.y();
hl->PRot = currAngle * M_PI / 180.0;
hl->PDx = dx;
- QMatrix trafo = QMatrix( 1, 0, 0, -1, -dx, 0 );
+ QTransform trafo = QTransform( 1, 0, 0, -1, -dx, 0 );
if (textPathFlipped)
- trafo *= QMatrix(1, 0, 0, -1, 0, 0);
+ trafo *= QTransform(1, 0, 0, -1, 0, 0);
if (textPathType == 0)
- trafo *= QMatrix( tangent.x(), tangent.y(), tangent.y(), -tangent.x(), point.x(), point.y() ); // ID's Rainbow mode
+ trafo *= QTransform( tangent.x(), tangent.y(), tangent.y(), -tangent.x(), point.x(), point.y() ); // ID's Rainbow mode
else if (textPathType == 1)
- trafo *= QMatrix( 1, 0, 0, -1, point.x(), point.y() ); // ID's Stair Step mode
+ trafo *= QTransform( 1, 0, 0, -1, point.x(), point.y() ); // ID's Stair Step mode
else if (textPathType == 2)
{
double a = 1;
if (tangent.x() < 0)
a = -1;
if (fabs(tangent.x()) > 0.1)
- trafo *= QMatrix( a, (tangent.y() / tangent.x()) * a, 0, -1, point.x(), point.y() ); // ID's Skew mode
+ trafo *= QTransform( a, (tangent.y() / tangent.x()) * a, 0, -1, point.x(), point.y() ); // ID's Skew mode
else
- trafo *= QMatrix( a, 4 * a, 0, -1, point.x(), point.y() );
+ trafo *= QTransform( a, 4 * a, 0, -1, point.x(), point.y() );
}
- QMatrix sca = p->worldMatrix();
+ QTransform sca = p->worldMatrix();
trafo *= sca;
p->save();
- QMatrix savWM = p->worldMatrix();
+ QTransform savWM = p->worldMatrix();
p->setWorldMatrix(trafo);
if (!m_Doc->RePos)
{
Index: scribus/scpageoutput.h
===================================================================
--- scribus/scpageoutput.h (revision 13950)
+++ scribus/scpageoutput.h (revision 13951)
@@ -77,7 +77,7 @@
virtual void drawItem_PolyLine( PageItem_PolyLine* item, ScPainterExBase* painte, const QRect& clip );
virtual void drawItem_TextFrame( PageItem_TextFrame* item, ScPainterExBase* painter, const QRect& clip );
- virtual void drawArrow(ScPainterExBase* painter, PageItem* item, QMatrix &arrowTrans, int arrowIndex);
+ virtual void drawArrow(ScPainterExBase* painter, PageItem* item, QTransform &arrowTrans, int arrowIndex);
virtual void drawMarks( Page* page, ScPainterExBase* painter, const MarksOptions& options );
virtual void drawBoxMarks( ScPainterExBase* painter, const QRectF& box, const QRectF& bleedBox, double offset );
virtual void drawRegistrationCross( ScPainterExBase* painter );
Index: scribus/pageitem.h
===================================================================
--- scribus/pageitem.h (revision 13950)
+++ scribus/pageitem.h (revision 13951)
@@ -295,8 +295,8 @@
void getVisualBoundingRect(double *x1, double *y1, double *x2, double *y2) const;
QRectF getBoundingRect() const;
QRectF getVisualBoundingRect() const;
- void getTransform(QMatrix& mat) const;
- QMatrix getTransform() const;
+ void getTransform(QTransform& mat) const;
+ QTransform getTransform() const;
/**
* @brief Check if a QPoint is within the items boundaries
* No coordinates transformation is performed
@@ -1026,7 +1026,7 @@
protected:
void drawLockedMarker(ScPainter *p);
- void drawArrow(ScPainter *p, QMatrix &arrowTrans, int arrowIndex);
+ void drawArrow(ScPainter *p, QTransform &arrowTrans, int arrowIndex);
/** @brief Manages undostack and is where all undo actions/states are sent. */
UndoManager * const undoManager;
Index: scribus/scpageoutput.cpp
===================================================================
--- scribus/scpageoutput.cpp (revision 13950)
+++ scribus/scpageoutput.cpp (revision 13951)
@@ -163,7 +163,7 @@
{
while (currItem == groupStack.top())
{
- QMatrix mm;
+ QTransform mm;
PageItem *tmpItem = groupClips.pop();
FPointArray cl = tmpItem->PoLine.copy();
mm.translate(tmpItem->xPos(), tmpItem->yPos());
@@ -283,7 +283,7 @@
{
while (currItem == groupStack.top())
{
- QMatrix mm;
+ QTransform mm;
PageItem *tmpItem = groupClips.pop();
FPointArray cl = tmpItem->PoLine.copy();
mm.translate(tmpItem->xPos(), tmpItem->yPos());
@@ -377,7 +377,7 @@
}
else
{
- QMatrix patternTransform;
+ QTransform patternTransform;
ScPattern& pattern = m_doc->docPatterns[item->pattern()];
double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation;
item->patternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
@@ -393,7 +393,7 @@
{
painter->setFillMode(ScPainterExBase::Gradient);
painter->m_fillGradient = VGradientEx(item->fill_gradient, *m_doc);
- QMatrix grm;
+ QTransform grm;
grm.rotate(item->rotation());
FPointArray gra;
switch (item->GrType)
@@ -507,7 +507,7 @@
//if (style.font().canRender(QChar(glyph)))
{
- QMatrix chma, chma2, chma3, chma4, chma5, chma6;
+ QTransform chma, chma2, chma3, chma4, chma5, chma6;
chma.scale(glyphs.scaleH * style.fontSize() / 100.00, glyphs.scaleV * style.fontSize() / 100.0);
FPointArray gly = style.font().glyphOutline(glyph);
// Do underlining first so you can get typographically correct
@@ -671,7 +671,7 @@
{
p->save();
FPointArray cl = embedded->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate((embedded->gXpos * (style.scaleH() / 1000.0)), ( - (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos * (style.scaleV() / 1000.0)));
if (style.baselineOffset() != 0)
mm.translate(0, -embedded->gHeight * (style.baselineOffset() / 1000.0));
@@ -780,7 +780,7 @@
// Compute pattern tansformation matrix and its inverse for converting pattern coordinates
// to pageitem coordinates
- QMatrix matrix, invMat;
+ QTransform matrix, invMat;
matrix.translate(patternOffsetX, patternOffsetY);
matrix.rotate(patternRotation);
matrix.scale(pattern.scaleX, pattern.scaleY);
@@ -974,14 +974,14 @@
}
if (startArrowIndex != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(0, 0);
arrowTrans.scale(-1,1);
drawArrow(painter, item, arrowTrans, startArrowIndex);
}
if (endArrowIndex != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(item->width(), 0);
drawArrow(painter, item, arrowTrans, endArrowIndex);
}
@@ -1117,27 +1117,27 @@
hl->PtransY = point.y();
hl->PRot = currAngle * M_PI / 180.0;
hl->PDx = dx;
- QMatrix trafo = QMatrix( 1, 0, 0, -1, -dx, 0 );
+ QTransform trafo = QTransform( 1, 0, 0, -1, -dx, 0 );
if (item->textPathFlipped)
- trafo *= QMatrix(1, 0, 0, -1, 0, 0);
+ trafo *= QTransform(1, 0, 0, -1, 0, 0);
if (item->textPathType == 0)
- trafo *= QMatrix( tangent.x(), tangent.y(), tangent.y(), -tangent.x(), point.x(), point.y() ); // ID's Rainbow mode
+ trafo *= QTransform( tangent.x(), tangent.y(), tangent.y(), -tangent.x(), point.x(), point.y() ); // ID's Rainbow mode
else if (item->textPathType == 1)
- trafo *= QMatrix( 1, 0, 0, -1, point.x(), point.y() ); // ID's Stair Step mode
+ trafo *= QTransform( 1, 0, 0, -1, point.x(), point.y() ); // ID's Stair Step mode
else if (item->textPathType == 2)
{
double a = 1;
if (tangent.x() < 0)
a = -1;
if (fabs(tangent.x()) > 0.1)
- trafo *= QMatrix( a, (tangent.y() / tangent.x()) * a, 0, -1, point.x(), point.y() ); // ID's Skew mode
+ trafo *= QTransform( a, (tangent.y() / tangent.x()) * a, 0, -1, point.x(), point.y() ); // ID's Skew mode
else
- trafo *= QMatrix( a, 4 * a, 0, -1, point.x(), point.y() );
+ trafo *= QTransform( a, 4 * a, 0, -1, point.x(), point.y() );
}
- QMatrix sca = painter->worldMatrix();
+ QTransform sca = painter->worldMatrix();
trafo *= sca;
painter->save();
- QMatrix savWM = painter->worldMatrix();
+ QTransform savWM = painter->worldMatrix();
painter->setWorldMatrix(trafo);
actFill = itemText.charStyle(a).fillColor();
@@ -1252,7 +1252,7 @@
if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
{
double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(Start.x(), Start.y());
arrowTrans.rotate(r);
drawArrow(painter, item, arrowTrans, startArrowIndex);
@@ -1269,7 +1269,7 @@
if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
{
double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(End.x(), End.y());
arrowTrans.rotate(r);
drawArrow(painter, item, arrowTrans, endArrowIndex);
@@ -1282,7 +1282,7 @@
void ScPageOutput::drawItem_TextFrame( PageItem_TextFrame* item, ScPainterExBase* painter, const QRect& clip )
{
- QMatrix wm;
+ QTransform wm;
QPoint pt1, pt2;
FPoint ColBound;
QRegion cm;
@@ -1408,7 +1408,7 @@
painter->restore();
}
-void ScPageOutput::drawArrow(ScPainterExBase* painter, PageItem* item, QMatrix &arrowTrans, int arrowIndex)
+void ScPageOutput::drawArrow(ScPainterExBase* painter, PageItem* item, QTransform &arrowTrans, int arrowIndex)
{
FPointArray arrow = m_doc->arrowStyles.at(arrowIndex-1).points.copy();
if (item->NamedLStyle.isEmpty())
Index: scribus/scpainter.cpp
===================================================================
--- scribus/scpainter.cpp (revision 13950)
+++ scribus/scpainter.cpp (revision 13951)
@@ -53,7 +53,7 @@
imageMode = true;
svgMode = false;
m_image = target;
- m_matrix = QMatrix();
+ m_matrix = QTransform();
cairo_surface_t *img = cairo_image_surface_create_for_data(m_image->bits(), CAIRO_FORMAT_ARGB32, w, h, w*4);
m_cr = cairo_create(img);
cairo_save( m_cr );
@@ -90,7 +90,7 @@
layeredMode = true;
imageMode = false;
svgMode = true;
- m_matrix = QMatrix();
+ m_matrix = QTransform();
cairo_surface_t *img = cairo_svg_surface_create(target.toLocal8Bit().constData(), w, h);
m_cr = cairo_create(img);
cairo_save( m_cr );
@@ -131,7 +131,7 @@
imageMode = true;
svgMode = false;
m_image = target;
- m_matrix = QMatrix();
+ m_matrix = QTransform();
painter.begin(m_image);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
@@ -662,27 +662,26 @@
#endif
}
-const QMatrix ScPainter::worldMatrix()
+const QTransform ScPainter::worldMatrix()
{
#ifdef HAVE_CAIRO
cairo_matrix_t matrix;
cairo_get_matrix(m_cr, &matrix);
- QMatrix mat;
- mat.setMatrix ( matrix.xx, matrix.yx, matrix.xy, matrix.yy, matrix.x0, matrix.y0 );
+ QTransform mat = QTransform( matrix.xx, matrix.yx, matrix.xy, matrix.yy, matrix.x0, matrix.y0 );
return mat;
#else
- return painter.worldMatrix();
+ return painter.worldTransform();
#endif
}
-void ScPainter::setWorldMatrix( const QMatrix &mat )
+void ScPainter::setWorldMatrix( const QTransform &mat )
{
#ifdef HAVE_CAIRO
cairo_matrix_t matrix;
cairo_matrix_init(&matrix, mat.m11(), mat.m12(), mat.m21(), mat.m22(), mat.dx(), mat.dy());
cairo_set_matrix(m_cr, &matrix);
#else
- painter.setWorldMatrix(mat);
+ painter.setWorldTransform(mat);
#endif
}
@@ -990,7 +989,7 @@
cairo_pattern_set_extend(m_pat, CAIRO_EXTEND_REPEAT);
cairo_pattern_set_filter(m_pat, CAIRO_FILTER_BEST);
cairo_matrix_t matrix;
- QMatrix qmatrix;
+ QTransform qmatrix;
// qmatrix.scale(m_zoomFactor, m_zoomFactor);
qmatrix.translate(patternOffsetX, patternOffsetY);
qmatrix.rotate(patternRotation);
@@ -1090,7 +1089,7 @@
{
painter.setRenderHint(QPainter::Antialiasing, false);
painter.setRenderHint(QPainter::SmoothPixmapTransform, false);
- QMatrix qmatrix;
+ QTransform qmatrix;
qmatrix.translate(patternOffsetX, patternOffsetY);
qmatrix.rotate(patternRotation);
qmatrix.scale(patternScaleX, patternScaleY);
Index: scribus/pageitem.cpp
===================================================================
--- scribus/pageitem.cpp (revision 13950)
+++ scribus/pageitem.cpp (revision 13951)
@@ -1056,7 +1056,7 @@
{
p->setFillMode(ScPainter::Gradient);
p->fill_gradient = fill_gradient;
- QMatrix grm;
+ QTransform grm;
grm.rotate(Rot);
FPointArray gra;
switch (GrType)
@@ -1321,7 +1321,7 @@
{
p->save();
FPointArray cl = embedded->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate((embedded->gXpos * (style.scaleH() / 1000.0)), ( - (embedded->gHeight * (style.scaleV() / 1000.0)) + embedded->gYpos * (style.scaleV() / 1000.0)));
if (style.baselineOffset() != 0)
mm.translate(0, -embedded->gHeight * (style.baselineOffset() / 1000.0));
@@ -1610,7 +1610,7 @@
{
painter->save();
FPointArray cl = embedded->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(embedded->gXpos, embedded->gYpos);
mm.rotate(embedded->rotation());
cl.map( mm );
@@ -1857,7 +1857,7 @@
glyph -= ScFace::CONTROL_GLYPHS;
else
glyph = 32;
- QMatrix chma, chma4, chma5;
+ QTransform chma, chma4, chma5;
FPointArray points;
if (glyph == SpecialChars::TAB.unicode())
{
@@ -4228,15 +4228,15 @@
-void PageItem::getTransform(QMatrix& mat) const
+void PageItem::getTransform(QTransform& mat) const
{
mat.translate(Xpos, Ypos);
mat.rotate(Rot);
}
-QMatrix PageItem::getTransform() const
+QTransform PageItem::getTransform() const
{
- QMatrix result;
+ QTransform result;
getTransform(result);
return result;
}
@@ -4291,7 +4291,7 @@
QRectF totalRect = QRectF(QPointF(*x1, *y1), QPointF(*x2, *y2));
if (m_startArrowIndex != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = m_Doc->arrowStyles.at(m_startArrowIndex-1).points.copy();
arrowTrans.translate(Xpos, Ypos);
arrowTrans.rotate(Rot);
@@ -4344,7 +4344,7 @@
}
if (m_endArrowIndex != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = m_Doc->arrowStyles.at(m_endArrowIndex-1).points.copy();
arrowTrans.translate(Xpos, Ypos);
arrowTrans.rotate(Rot);
@@ -4446,7 +4446,7 @@
QRectF totalRect = QRectF(QPointF(*x1, *y1), QPointF(*x2, *y2));
if (m_startArrowIndex != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = m_Doc->arrowStyles.at(m_startArrowIndex-1).points.copy();
arrowTrans.translate(Xpos, Ypos);
arrowTrans.rotate(Rot);
@@ -4499,7 +4499,7 @@
}
if (m_endArrowIndex != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = m_Doc->arrowStyles.at(m_endArrowIndex-1).points.copy();
arrowTrans.translate(Xpos, Ypos);
arrowTrans.rotate(Rot);
@@ -4636,7 +4636,7 @@
bool PageItem::mouseWithinItem(const int x, const int y, double scale) const
{
- QMatrix p;
+ QTransform p;
QRectF transRect;
p.translate(Xpos * scale, Ypos*scale);
p.scale(scale, scale);
@@ -4701,7 +4701,7 @@
{
imageClip = pixm.imgInfo.PDSpathData[clPath].copy();
pixm.imgInfo.usedPath = clPath;
- QMatrix cl;
+ QTransform cl;
cl.translate(LocalX*LocalScX, LocalY*LocalScY);
cl.scale(LocalScX, LocalScY);
imageClip.map(cl);
@@ -4714,7 +4714,7 @@
{
imageClip = pixm.imgInfo.PDSpathData[clPath].copy();
pixm.imgInfo.usedPath = clPath;
- QMatrix cl;
+ QTransform cl;
cl.translate(LocalX*LocalScX, LocalY*LocalScY);
cl.scale(LocalScX, LocalScY);
imageClip.map(cl);
@@ -4932,7 +4932,7 @@
p->drawLine(FPoint(bx1+scp1/2, ofy+scp1), FPoint(bx1+scp1*3.5, ofy+scp1));
}
-void PageItem::drawArrow(ScPainter *p, QMatrix &arrowTrans, int arrowIndex)
+void PageItem::drawArrow(ScPainter *p, QTransform &arrowTrans, int arrowIndex)
{
FPointArray arrow = m_Doc->arrowStyles.at(arrowIndex-1).points.copy();
if (NamedLStyle.isEmpty())
@@ -5037,7 +5037,7 @@
if (imageClip.size() != 0)
{
imageClip = pixm.imgInfo.PDSpathData[pixm.imgInfo.usedPath].copy();
- QMatrix cl;
+ QTransform cl;
cl.translate(LocalX*LocalScX, LocalY*LocalScY);
cl.scale(LocalScX, LocalScY);
imageClip.map(cl);
@@ -5178,7 +5178,7 @@
for (int a = 0; a < cl.size()-1; ++a)
{
rot = xy2Deg(cl.point(a+1).x()-cl.point(a).x(),cl.point(a+1).y()-cl.point(a).y());
- QMatrix ma;
+ QTransform ma;
ma.rotate(rot);
np = QPoint(0, -upval) * ma;
np2 = QPoint(0, -downval) * ma;
@@ -5390,7 +5390,7 @@
if (imageClip.size() != 0)
{
imageClip = pixm.imgInfo.PDSpathData[pixm.imgInfo.usedPath].copy();
- QMatrix cl;
+ QTransform cl;
cl.translate(imageXOffset()*imageXScale(), imageYOffset()*imageYScale());
cl.scale(imageXScale(), imageYScale());
imageClip.map(cl);
@@ -5465,7 +5465,7 @@
{
double scx = width() / OldB2;
double scy = height() / OldH2;
- QMatrix ma;
+ QTransform ma;
ma.scale(scx, scy);
FPointArray gr;
gr.addPoint(GrStartX, GrStartY);
@@ -5517,7 +5517,7 @@
return;
double scx = width() / OldB2;
double scy = height() / OldH2;
- QMatrix ma;
+ QTransform ma;
ma.scale(scx, scy);
FPointArray gr;
gr.addPoint(GrStartX, GrStartY);
Index: scribus/canvasmode_framelinks.cpp
===================================================================
--- scribus/canvasmode_framelinks.cpp (revision 13950)
+++ scribus/canvasmode_framelinks.cpp (revision 13951)
@@ -1,538 +1,538 @@
-/*
- For general Scribus (>=1.3.2) copyright and licensing information please refer
- to the COPYING file provided with the program. Following this notice may exist
- a copyright and/or license notice that predates the release of Scribus 1.3.2
- for which a new license (GPL+exception) is in place.
- */
-/***************************************************************************
-* *
-* This program is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-* *
-***************************************************************************/
-
-
-#include "canvasmode_framelinks.h"
-
-#include <QApplication>
-#include <QButtonGroup>
-#include <QCheckBox>
-#include <QCursor>
-#include <QEvent>
-#include <QMessageBox>
-#include <QMouseEvent>
-#include <QPainterPath>
-#include <QPoint>
-#include <QRect>
-#include <QTimer>
-#include <QWidgetAction>
-#include <QDebug>
-
-#include "canvas.h"
-#include "ui/contextmenu.h"
-#include "fpoint.h"
-#include "fpointarray.h"
-#include "pageitem_textframe.h"
-#include "ui/pageselector.h"
-#include "prefscontext.h"
-#include "prefsfile.h"
-#include "prefsmanager.h"
-#include "ui/propertiespalette.h"
-#include "scribus.h"
-#include "scribusdoc.h"
-#include "scribusview.h"
-#include "selection.h"
-#include "undomanager.h"
-#include "units.h"
-#include "util.h"
-#include "util_icon.h"
-#include "util_math.h"
-
-CanvasMode_FrameLinks::CanvasMode_FrameLinks(ScribusView* view) : CanvasMode(view), m_ScMW(view->m_ScMW)
-{
- Mxp = Myp = -1;
- Dxp = Dyp = -1;
- frameResizeHandle = -1;
-}
-
-inline bool CanvasMode_FrameLinks::GetItem(PageItem** pi)
-{
- *pi = m_doc->m_Selection->itemAt(0);
- return (*pi) != NULL;
-}
-
-void CanvasMode_FrameLinks::drawControls(QPainter* p)
-{
- commonDrawControls(p);
-}
-
-void CanvasMode_FrameLinks::enterEvent(QEvent *)
-{
- if (!m_canvas->m_viewMode.m_MouseButtonPressed)
- {
- setModeCursor();
- }
-}
-
-void CanvasMode_FrameLinks::leaveEvent(QEvent *e)
-{
- if (!m_canvas->m_viewMode.m_MouseButtonPressed)
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
-}
-
-
-void CanvasMode_FrameLinks::activate(bool fromGesture)
-{
-// qDebug() << "CanvasMode_FrameLinks::activate" << fromGesture;
- m_canvas->m_viewMode.m_MouseButtonPressed = false;
- m_canvas->resetRenderMode();
- m_doc->DragP = false;
- m_doc->leaveDrag = false;
- m_canvas->m_viewMode.operItemMoving = false;
- m_canvas->m_viewMode.operItemResizing = false;
- m_view->MidButt = false;
- Mxp = Myp = -1;
- Dxp = Dyp = -1;
- frameResizeHandle = -1;
- setModeCursor();
- if (fromGesture)
- {
- m_canvas->m_viewMode.operItemResizeInEditMode = false;
- m_view->update();
- }
-}
-
-void CanvasMode_FrameLinks::deactivate(bool forGesture)
-{
-// qDebug() << "CanvasMode_FrameLinks::deactivate" << forGesture;
- m_view->redrawMarker->hide();
-}
-
-void CanvasMode_FrameLinks::mouseDoubleClickEvent(QMouseEvent *m)
-{
- m->accept();
- m_canvas->m_viewMode.m_MouseButtonPressed = false;
- m_canvas->resetRenderMode();
-// m_view->stopDragTimer();
-}
-
-void CanvasMode_FrameLinks::mouseMoveEvent(QMouseEvent *m)
-{
- const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
-
- m->accept();
-
- if (commonMouseMove(m))
- return;
- if ((m_canvas->m_viewMode.m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton))
- {
- SeRx = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
- SeRy = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
- /*
- m_view->redrawMarker->setGeometry(QRect(Mxp, Myp, m->globalPos().x() - Mxp, m->globalPos().y() - Myp).normalized());
- */
- QPoint startP = m_canvas->canvasToGlobal(m_doc->appMode == modeDrawTable? QPointF(Dxp, Dyp) : QPointF(Mxp, Myp));
- m_view->redrawMarker->setGeometry(QRect(startP, m->globalPos()).normalized());
- if (!m_view->redrawMarker->isVisible())
- m_view->redrawMarker->show();
- m_view->HaveSelRect = true;
- return;
- }
-}
-
-void CanvasMode_FrameLinks::mousePressEvent(QMouseEvent *m)
-{
-// const double mouseX = m->globalX();
-// const double mouseY = m->globalY();
- const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
-
- double Rxp = 0;
- double Ryp = 0;
- PageItem *currItem, *bb;
- m_canvas->PaintSizeRect(QRect());
- m_canvas->m_viewMode.m_MouseButtonPressed = true;
- m_canvas->m_viewMode.operItemMoving = false;
- m_view->HaveSelRect = false;
- m_doc->DragP = false;
- m_doc->leaveDrag = false;
-// oldClip = 0;
- m->accept();
- m_view->registerMousePress(m->globalPos());
- Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
- Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
- Rxp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).x();
- Mxp = qRound(Rxp);
- Ryp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).y();
- Myp = qRound(Ryp);
- SeRx = Mxp;
- SeRy = Myp;
- if (m->button() == Qt::MidButton)
- {
- m_view->MidButt = true;
- if (m->modifiers() & Qt::ControlModifier)
- m_view->DrawNew();
- return;
- }
- switch (m_doc->appMode)
- {
- case modeLinkFrames:
- if (m->button() != Qt::LeftButton)
- break;
- currItem = m_doc->ElemToLink;
- if (currItem==NULL)
- break;
- SeleItem(m);
- if (GetItem(&bb) && (bb->asTextFrame()))
- {
- PageItem* bblast = bb;
- while (bblast->nextInChain())
- bblast = bblast->nextInChain();
-
- if (currItem->nextInChain() == 0 && bb->prevInChain() == 0 && currItem != bblast)
- {
- currItem->link(bb);
- // CB We need to do this because we draw in the order of the item list
- // Which is also item number list.. but #3488: we must also renumber the items
- if (bb->ItemNr < currItem->ItemNr)
- {
- m_doc->Items->insert(currItem->ItemNr+1, bb);
- bb = m_doc->Items->takeAt(bb->ItemNr);
- m_doc->renumberItemsInListOrder();
- }
- // m_view->updateContents();
- // link calls PageItem::update
- // emit DocChanged();
- m_doc->ElemToLink = bb;
- }
- else if (currItem == bblast)
- {
- //CB Mouse is released when this messagebox takes focus
- m_canvas->m_viewMode.m_MouseButtonPressed = false;
- QMessageBox::warning(m_view, ScribusView::tr("Linking Text Frames"),
- "<qt>" + ScribusView::tr("You are trying to link a frame to itself.") + "</qt>");
- }
- else
- {
- //CB Mouse is released when this messagebox takes focus
- m_canvas->m_viewMode.m_MouseButtonPressed = false;
- QMessageBox::warning(m_view, ScribusView::tr("Linking Text Frames"),
- "<qt>" + ScribusView::tr("You are trying to link a frame which is already linked.") + "</qt>");
- }
- }
- else
- m_doc->ElemToLink = NULL;
- break;
- case modeUnlinkFrames:
- if (m->button() != Qt::LeftButton)
- break;
- SeleItem(m);
- if (GetItem(&currItem) && (currItem->asTextFrame()))
- {
- if (currItem->prevInChain() != 0)
- {
- currItem->prevInChain()->unlink();
- }
- // unlink calls PageItem::update emit DocChanged();
- // m_view->updateContents();
- }
- break;
- }
-}
-
-void CanvasMode_FrameLinks::mouseReleaseEvent(QMouseEvent *m)
-{
-#ifdef GESTURE_FRAME_PREVIEW
- clearPixmapCache();
-#endif // GESTURE_FRAME_PREVIEW
- const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
- PageItem *currItem;
- m_canvas->m_viewMode.m_MouseButtonPressed = false;
- m_canvas->resetRenderMode();
- m->accept();
-// m_view->stopDragTimer();
- //m_canvas->update(); //ugly in a mouseReleaseEvent!!!!!!!
- if ((GetItem(&currItem)) && (m->button() == Qt::RightButton) && (!m_doc->DragP))
- {
- createContextMenu(currItem, mousePointDoc.x(), mousePointDoc.y());
- return;
- }
- if ((m_doc->appMode == modeLinkFrames) || (m_doc->appMode == modeUnlinkFrames))
- {
- m_view->updateContents();
- if (m_doc->ElemToLink != 0)
- return;
- else
- {
- m_view->requestMode(submodePaintingDone);
- return;
- }
- }
- m_canvas->setRenderModeUseBuffer(false);
- m_doc->DragP = false;
- m_doc->leaveDrag = false;
- m_canvas->m_viewMode.operItemMoving = false;
- m_canvas->m_viewMode.operItemResizing = false;
- m_view->MidButt = false;
- for (int i = 0; i < m_doc->m_Selection->count(); ++i)
- m_doc->m_Selection->itemAt(i)->checkChanges(true);
- //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas
- m_view->zoomSpinBox->clearFocus();
- m_view->pageSelector->clearFocus();
-}
-
-void CanvasMode_FrameLinks::selectPage(QMouseEvent *m)
-{
- m_canvas->m_viewMode.m_MouseButtonPressed = true;
- FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
- Mxp = mousePointDoc.x(); //static_cast<int>(m->x()/m_canvas->scale());
- Myp = mousePointDoc.y(); //static_cast<int>(m->y()/m_canvas->scale());
- m_doc->nodeEdit.deselect();
- m_view->Deselect(false);
- if (!m_doc->masterPageMode())
- {
- int i = m_doc->OnPage(Mxp, Myp);
- if (i!=-1)
- {
- uint docCurrPageNo=m_doc->currentPageNumber();
- uint j=static_cast<uint>(i);
- if (docCurrPageNo != j)
- {
- m_doc->setCurrentPage(m_doc->Pages->at(j));
- m_view->setMenTxt(j);
- m_view->DrawNew();
- }
- }
-/* uint docPagesCount=m_doc->Pages->count();
- uint docCurrPageNo=m_doc->currentPageNumber();
- for (uint i = 0; i < docPagesCount; ++i)
- {
- int x = static_cast<int>(m_doc->Pages->at(i)->xOffset() * m_canvas->scale());
- int y = static_cast<int>(m_doc->Pages->at(i)->yOffset() * m_canvas->scale());
- int w = static_cast<int>(m_doc->Pages->at(i)->width() * m_canvas->scale());
- int h = static_cast<int>(m_doc->Pages->at(i)->height() * m_canvas->scale());
- if (QRect(x, y, w, h).intersects(mpo))
- {
- if (docCurrPageNo != i)
- {
- m_doc->setCurrentPage(m_doc->Pages->at(i));
- setMenTxt(i);
- DrawNew();
- }
- break;
- }
- } */
- m_view->setRulerPos(m_view->contentsX(), m_view->contentsY());
- }
-}
-
-//CB-->Doc/Fix
-bool CanvasMode_FrameLinks::SeleItem(QMouseEvent *m)
-{
- const unsigned SELECT_IN_GROUP = Qt::AltModifier;
- const unsigned SELECT_MULTIPLE = Qt::ShiftModifier;
- const unsigned SELECT_BENEATH = Qt::ControlModifier;
- QMatrix p;
- PageItem *currItem;
- m_canvas->m_viewMode.m_MouseButtonPressed = true;
- FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
- Mxp = mousePointDoc.x(); //m->x()/m_canvas->scale());
- Myp = mousePointDoc.y(); //m->y()/m_canvas->scale());
- int MxpS = static_cast<int>(mousePointDoc.x()); //m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
- int MypS = static_cast<int>(mousePointDoc.y()); //m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
- m_doc->nodeEdit.deselect();
- if (!m_doc->masterPageMode())
- {
- int pgNum = -1;
- int docPageCount = static_cast<int>(m_doc->Pages->count() - 1);
- MarginStruct pageBleeds;
- bool drawBleed = false;
- if (m_doc->bleeds.hasNonZeroValue() && m_doc->guidesSettings.showBleed)
- drawBleed = true;
- for (int a = docPageCount; a > -1; a--)
- {
- if (drawBleed)
- m_doc->getBleeds(a, pageBleeds);
- int x = static_cast<int>(m_doc->Pages->at(a)->xOffset() - pageBleeds.Left);
- int y = static_cast<int>(m_doc->Pages->at(a)->yOffset() - pageBleeds.Top);
- int w = static_cast<int>(m_doc->Pages->at(a)->width() + pageBleeds.Left + pageBleeds.Right);
- int h = static_cast<int>(m_doc->Pages->at(a)->height() + pageBleeds.Bottom + pageBleeds.Top);
- if (QRect(x, y, w, h).contains(MxpS, MypS))
- {
- pgNum = static_cast<int>(a);
- if (drawBleed) // check again if its really on the correct page
- {
- for (int a2 = docPageCount; a2 > -1; a2--)
- {
- int xn = static_cast<int>(m_doc->Pages->at(a2)->xOffset());
- int yn = static_cast<int>(m_doc->Pages->at(a2)->yOffset());
- int wn = static_cast<int>(m_doc->Pages->at(a2)->width());
- int hn = static_cast<int>(m_doc->Pages->at(a2)->height());
- if (QRect(xn, yn, wn, hn).contains(MxpS, MypS))
- {
- pgNum = static_cast<int>(a2);
- break;
- }
- }
- }
- break;
- }
- }
- if (pgNum >= 0)
- {
- if (m_doc->currentPageNumber() != pgNum)
- {
- m_doc->setCurrentPage(m_doc->Pages->at(unsigned(pgNum)));
- m_view->setMenTxt(unsigned(pgNum));
- m_view->DrawNew();
- }
- }
- m_view->setRulerPos(m_view->contentsX(), m_view->contentsY());
- }
-
- currItem = NULL;
- if ((m->modifiers() & SELECT_BENEATH) != 0)
- {
- for (int i=0; i < m_doc->m_Selection->count(); ++i)
- {
- if (m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), m_doc->m_Selection->itemAt(i)) >= 0)
- {
- currItem = m_doc->m_Selection->itemAt(i);
-// qDebug() << "select item: found BENEATH" << currItem << "groups" << currItem->Groups.count();
- if (currItem->Groups.count() > 0)
- {
- m_doc->m_Selection->delaySignalsOn();
- for (int ga=0; ga<m_doc->Items->count(); ++ga)
- {
- PageItem* item = m_doc->Items->at(ga);
- if (item->Groups.count() != 0)
- {
- if (item->Groups.top() == currItem->Groups.top())
- {
- if (m_doc->m_Selection->findItem(item) >= 0)
- {
- m_doc->m_Selection->removeItem(item);
- }
- }
- }
- }
- m_doc->m_Selection->delaySignalsOff();
- }
- else
- {
- m_doc->m_Selection->removeItem(currItem);
- }
- break;
- }
-// else
-// qDebug() << "select item: not BENEATH" << QPointF(mousePointDoc.x(),mousePointDoc.y())
-// << m_doc->m_Selection->itemAt(i)->getTransform()
-// << m_doc->m_Selection->itemAt(i)->getBoundingRect();
- }
- }
- else if ( (m->modifiers() & SELECT_MULTIPLE) == Qt::NoModifier || (m_doc->appMode == modeLinkFrames) || (m_doc->appMode == modeUnlinkFrames) )
- {
- m_view->Deselect(false);
- }
-
-// qDebug() << "select item: beneath" << (m->modifiers() & SELECT_BENEATH) << currItem
-// << "multi" << (m->modifiers() & SELECT_MULTIPLE)
-// << "current sel" << m_doc->m_Selection->count();
- currItem = m_canvas->itemUnderCursor(m->globalPos(), currItem, (m->modifiers() & SELECT_IN_GROUP));
-// qDebug() << "item under cursor: " << currItem;
- if (currItem)
- {
- m_doc->m_Selection->delaySignalsOn();
- if (m_doc->m_Selection->containsItem(currItem))
- {
- m_doc->m_Selection->removeItem(currItem);
- }
- else
- {
- //CB: If we have a selection but the user clicks with control on another item that is not below the current
- //then clear and select the new item
- if ((m->modifiers() == SELECT_BENEATH) && m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), currItem) >= 0)
- m_doc->m_Selection->clear();
- //CB: #7186: This was prependItem, does not seem to need to be anymore with current select code
- m_doc->m_Selection->addItem(currItem);
- if ( (m->modifiers() & SELECT_IN_GROUP) && (!currItem->isGroupControl))
- {
- currItem->isSingleSel = true;
- }
- else if (currItem->Groups.count() > 0)
- {
- for (int ga=0; ga<m_doc->Items->count(); ++ga)
- {
- PageItem* item = m_doc->Items->at(ga);
- if (item->Groups.count() != 0)
- {
- if (item->Groups.top() == currItem->Groups.top())
- {
- if (item->ItemNr != currItem->ItemNr)
- {
- if (m_doc->m_Selection->findItem(item) == -1)
- {
- m_doc->m_Selection->addItem(item, true);
- }
- }
- item->isSingleSel = false;
- }
- }
- }
- }
- }
-
- currItem->update();
- m_doc->m_Selection->delaySignalsOff();
- if (m_doc->m_Selection->count() > 1)
- {
- for (int aa = 0; aa < m_doc->m_Selection->count(); ++aa)
- {
- PageItem *bb = m_doc->m_Selection->itemAt(aa);
- bb->update();
- }
- m_doc->m_Selection->setGroupRect();
- double x, y, w, h;
- m_doc->m_Selection->getGroupRect(&x, &y, &w, &h);
- // emit ItemPos(x, y);
- // emit ItemGeom(w, h);
- m_view->getGroupRectScreen(&x, &y, &w, &h);
- // m_view->updateContents(QRect(static_cast<int>(x-5), static_cast<int>(y-5), static_cast<int>(w+10), static_cast<int>(h+10)));
- // emit HaveSel(currItem->itemType());
- }
- if (m_doc->m_Selection->count() == 1)
- {
- frameResizeHandle = m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), currItem);
- if ((frameResizeHandle == Canvas::INSIDE) && (!currItem->locked()))
- qApp->changeOverrideCursor(QCursor(Qt::SizeAllCursor));
- }
- else
- {
- qApp->changeOverrideCursor(QCursor(Qt::SizeAllCursor));
- m_canvas->m_viewMode.operItemResizing = false;
- }
- return true;
- }
- //m_doc->m_Selection->setIsGUISelection(true);
- m_doc->m_Selection->connectItemToGUI();
- if ( !(m->modifiers() & SELECT_MULTIPLE) || (m_doc->appMode == modeLinkFrames) || (m_doc->appMode == modeUnlinkFrames))
- m_view->Deselect(true);
- return false;
-}
-
-void CanvasMode_FrameLinks::createContextMenu(PageItem* currItem, double mx, double my)
-{
- ContextMenu* cmen=NULL;
- qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- m_view->setObjectUndoMode();
- Mxp = mx;
- Myp = my;
- if(currItem!=NULL)
- {
- cmen = new ContextMenu(*(m_doc->m_Selection), m_ScMW, m_doc);
- cmen->exec(QCursor::pos());
- m_view->setGlobalUndoMode();
- delete cmen;
- }
-}
+/*
+ For general Scribus (>=1.3.2) copyright and licensing information please refer
+ to the COPYING file provided with the program. Following this notice may exist
+ a copyright and/or license notice that predates the release of Scribus 1.3.2
+ for which a new license (GPL+exception) is in place.
+ */
+/***************************************************************************
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+***************************************************************************/
+
+
+#include "canvasmode_framelinks.h"
+
+#include <QApplication>
+#include <QButtonGroup>
+#include <QCheckBox>
+#include <QCursor>
+#include <QEvent>
+#include <QMessageBox>
+#include <QMouseEvent>
+#include <QPainterPath>
+#include <QPoint>
+#include <QRect>
+#include <QTimer>
+#include <QWidgetAction>
+#include <QDebug>
+
+#include "canvas.h"
+#include "ui/contextmenu.h"
+#include "fpoint.h"
+#include "fpointarray.h"
+#include "pageitem_textframe.h"
+#include "ui/pageselector.h"
+#include "prefscontext.h"
+#include "prefsfile.h"
+#include "prefsmanager.h"
+#include "ui/propertiespalette.h"
+#include "scribus.h"
+#include "scribusdoc.h"
+#include "scribusview.h"
+#include "selection.h"
+#include "undomanager.h"
+#include "units.h"
+#include "util.h"
+#include "util_icon.h"
+#include "util_math.h"
+
+CanvasMode_FrameLinks::CanvasMode_FrameLinks(ScribusView* view) : CanvasMode(view), m_ScMW(view->m_ScMW)
+{
+ Mxp = Myp = -1;
+ Dxp = Dyp = -1;
+ frameResizeHandle = -1;
+}
+
+inline bool CanvasMode_FrameLinks::GetItem(PageItem** pi)
+{
+ *pi = m_doc->m_Selection->itemAt(0);
+ return (*pi) != NULL;
+}
+
+void CanvasMode_FrameLinks::drawControls(QPainter* p)
+{
+ commonDrawControls(p);
+}
+
+void CanvasMode_FrameLinks::enterEvent(QEvent *)
+{
+ if (!m_canvas->m_viewMode.m_MouseButtonPressed)
+ {
+ setModeCursor();
+ }
+}
+
+void CanvasMode_FrameLinks::leaveEvent(QEvent *e)
+{
+ if (!m_canvas->m_viewMode.m_MouseButtonPressed)
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+}
+
+
+void CanvasMode_FrameLinks::activate(bool fromGesture)
+{
+// qDebug() << "CanvasMode_FrameLinks::activate" << fromGesture;
+ m_canvas->m_viewMode.m_MouseButtonPressed = false;
+ m_canvas->resetRenderMode();
+ m_doc->DragP = false;
+ m_doc->leaveDrag = false;
+ m_canvas->m_viewMode.operItemMoving = false;
+ m_canvas->m_viewMode.operItemResizing = false;
+ m_view->MidButt = false;
+ Mxp = Myp = -1;
+ Dxp = Dyp = -1;
+ frameResizeHandle = -1;
+ setModeCursor();
+ if (fromGesture)
+ {
+ m_canvas->m_viewMode.operItemResizeInEditMode = false;
+ m_view->update();
+ }
+}
+
+void CanvasMode_FrameLinks::deactivate(bool forGesture)
+{
+// qDebug() << "CanvasMode_FrameLinks::deactivate" << forGesture;
+ m_view->redrawMarker->hide();
+}
+
+void CanvasMode_FrameLinks::mouseDoubleClickEvent(QMouseEvent *m)
+{
+ m->accept();
+ m_canvas->m_viewMode.m_MouseButtonPressed = false;
+ m_canvas->resetRenderMode();
+// m_view->stopDragTimer();
+}
+
+void CanvasMode_FrameLinks::mouseMoveEvent(QMouseEvent *m)
+{
+ const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+
+ m->accept();
+
+ if (commonMouseMove(m))
+ return;
+ if ((m_canvas->m_viewMode.m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton))
+ {
+ SeRx = qRound(mousePointDoc.x()); //m_view->translateToDoc(m->x(), m->y()).x());
+ SeRy = qRound(mousePointDoc.y()); //m_view->translateToDoc(m->x(), m->y()).y());
+ /*
+ m_view->redrawMarker->setGeometry(QRect(Mxp, Myp, m->globalPos().x() - Mxp, m->globalPos().y() - Myp).normalized());
+ */
+ QPoint startP = m_canvas->canvasToGlobal(m_doc->appMode == modeDrawTable? QPointF(Dxp, Dyp) : QPointF(Mxp, Myp));
+ m_view->redrawMarker->setGeometry(QRect(startP, m->globalPos()).normalized());
+ if (!m_view->redrawMarker->isVisible())
+ m_view->redrawMarker->show();
+ m_view->HaveSelRect = true;
+ return;
+ }
+}
+
+void CanvasMode_FrameLinks::mousePressEvent(QMouseEvent *m)
+{
+// const double mouseX = m->globalX();
+// const double mouseY = m->globalY();
+ const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+
+ double Rxp = 0;
+ double Ryp = 0;
+ PageItem *currItem, *bb;
+ m_canvas->PaintSizeRect(QRect());
+ m_canvas->m_viewMode.m_MouseButtonPressed = true;
+ m_canvas->m_viewMode.operItemMoving = false;
+ m_view->HaveSelRect = false;
+ m_doc->DragP = false;
+ m_doc->leaveDrag = false;
+// oldClip = 0;
+ m->accept();
+ m_view->registerMousePress(m->globalPos());
+ Mxp = mousePointDoc.x(); //qRound(m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
+ Myp = mousePointDoc.y(); //qRound(m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
+ Rxp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).x();
+ Mxp = qRound(Rxp);
+ Ryp = m_doc->ApplyGridF(FPoint(Mxp, Myp)).y();
+ Myp = qRound(Ryp);
+ SeRx = Mxp;
+ SeRy = Myp;
+ if (m->button() == Qt::MidButton)
+ {
+ m_view->MidButt = true;
+ if (m->modifiers() & Qt::ControlModifier)
+ m_view->DrawNew();
+ return;
+ }
+ switch (m_doc->appMode)
+ {
+ case modeLinkFrames:
+ if (m->button() != Qt::LeftButton)
+ break;
+ currItem = m_doc->ElemToLink;
+ if (currItem==NULL)
+ break;
+ SeleItem(m);
+ if (GetItem(&bb) && (bb->asTextFrame()))
+ {
+ PageItem* bblast = bb;
+ while (bblast->nextInChain())
+ bblast = bblast->nextInChain();
+
+ if (currItem->nextInChain() == 0 && bb->prevInChain() == 0 && currItem != bblast)
+ {
+ currItem->link(bb);
+ // CB We need to do this because we draw in the order of the item list
+ // Which is also item number list.. but #3488: we must also renumber the items
+ if (bb->ItemNr < currItem->ItemNr)
+ {
+ m_doc->Items->insert(currItem->ItemNr+1, bb);
+ bb = m_doc->Items->takeAt(bb->ItemNr);
+ m_doc->renumberItemsInListOrder();
+ }
+ // m_view->updateContents();
+ // link calls PageItem::update
+ // emit DocChanged();
+ m_doc->ElemToLink = bb;
+ }
+ else if (currItem == bblast)
+ {
+ //CB Mouse is released when this messagebox takes focus
+ m_canvas->m_viewMode.m_MouseButtonPressed = false;
+ QMessageBox::warning(m_view, ScribusView::tr("Linking Text Frames"),
+ "<qt>" + ScribusView::tr("You are trying to link a frame to itself.") + "</qt>");
+ }
+ else
+ {
+ //CB Mouse is released when this messagebox takes focus
+ m_canvas->m_viewMode.m_MouseButtonPressed = false;
+ QMessageBox::warning(m_view, ScribusView::tr("Linking Text Frames"),
+ "<qt>" + ScribusView::tr("You are trying to link a frame which is already linked.") + "</qt>");
+ }
+ }
+ else
+ m_doc->ElemToLink = NULL;
+ break;
+ case modeUnlinkFrames:
+ if (m->button() != Qt::LeftButton)
+ break;
+ SeleItem(m);
+ if (GetItem(&currItem) && (currItem->asTextFrame()))
+ {
+ if (currItem->prevInChain() != 0)
+ {
+ currItem->prevInChain()->unlink();
+ }
+ // unlink calls PageItem::update emit DocChanged();
+ // m_view->updateContents();
+ }
+ break;
+ }
+}
+
+void CanvasMode_FrameLinks::mouseReleaseEvent(QMouseEvent *m)
+{
+#ifdef GESTURE_FRAME_PREVIEW
+ clearPixmapCache();
+#endif // GESTURE_FRAME_PREVIEW
+ const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+ PageItem *currItem;
+ m_canvas->m_viewMode.m_MouseButtonPressed = false;
+ m_canvas->resetRenderMode();
+ m->accept();
+// m_view->stopDragTimer();
+ //m_canvas->update(); //ugly in a mouseReleaseEvent!!!!!!!
+ if ((GetItem(&currItem)) && (m->button() == Qt::RightButton) && (!m_doc->DragP))
+ {
+ createContextMenu(currItem, mousePointDoc.x(), mousePointDoc.y());
+ return;
+ }
+ if ((m_doc->appMode == modeLinkFrames) || (m_doc->appMode == modeUnlinkFrames))
+ {
+ m_view->updateContents();
+ if (m_doc->ElemToLink != 0)
+ return;
+ else
+ {
+ m_view->requestMode(submodePaintingDone);
+ return;
+ }
+ }
+ m_canvas->setRenderModeUseBuffer(false);
+ m_doc->DragP = false;
+ m_doc->leaveDrag = false;
+ m_canvas->m_viewMode.operItemMoving = false;
+ m_canvas->m_viewMode.operItemResizing = false;
+ m_view->MidButt = false;
+ for (int i = 0; i < m_doc->m_Selection->count(); ++i)
+ m_doc->m_Selection->itemAt(i)->checkChanges(true);
+ //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas
+ m_view->zoomSpinBox->clearFocus();
+ m_view->pageSelector->clearFocus();
+}
+
+void CanvasMode_FrameLinks::selectPage(QMouseEvent *m)
+{
+ m_canvas->m_viewMode.m_MouseButtonPressed = true;
+ FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+ Mxp = mousePointDoc.x(); //static_cast<int>(m->x()/m_canvas->scale());
+ Myp = mousePointDoc.y(); //static_cast<int>(m->y()/m_canvas->scale());
+ m_doc->nodeEdit.deselect();
+ m_view->Deselect(false);
+ if (!m_doc->masterPageMode())
+ {
+ int i = m_doc->OnPage(Mxp, Myp);
+ if (i!=-1)
+ {
+ uint docCurrPageNo=m_doc->currentPageNumber();
+ uint j=static_cast<uint>(i);
+ if (docCurrPageNo != j)
+ {
+ m_doc->setCurrentPage(m_doc->Pages->at(j));
+ m_view->setMenTxt(j);
+ m_view->DrawNew();
+ }
+ }
+/* uint docPagesCount=m_doc->Pages->count();
+ uint docCurrPageNo=m_doc->currentPageNumber();
+ for (uint i = 0; i < docPagesCount; ++i)
+ {
+ int x = static_cast<int>(m_doc->Pages->at(i)->xOffset() * m_canvas->scale());
+ int y = static_cast<int>(m_doc->Pages->at(i)->yOffset() * m_canvas->scale());
+ int w = static_cast<int>(m_doc->Pages->at(i)->width() * m_canvas->scale());
+ int h = static_cast<int>(m_doc->Pages->at(i)->height() * m_canvas->scale());
+ if (QRect(x, y, w, h).intersects(mpo))
+ {
+ if (docCurrPageNo != i)
+ {
+ m_doc->setCurrentPage(m_doc->Pages->at(i));
+ setMenTxt(i);
+ DrawNew();
+ }
+ break;
+ }
+ } */
+ m_view->setRulerPos(m_view->contentsX(), m_view->contentsY());
+ }
+}
+
+//CB-->Doc/Fix
+bool CanvasMode_FrameLinks::SeleItem(QMouseEvent *m)
+{
+ const unsigned SELECT_IN_GROUP = Qt::AltModifier;
+ const unsigned SELECT_MULTIPLE = Qt::ShiftModifier;
+ const unsigned SELECT_BENEATH = Qt::ControlModifier;
+ QTransform p;
+ PageItem *currItem;
+ m_canvas->m_viewMode.m_MouseButtonPressed = true;
+ FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
+ Mxp = mousePointDoc.x(); //m->x()/m_canvas->scale());
+ Myp = mousePointDoc.y(); //m->y()/m_canvas->scale());
+ int MxpS = static_cast<int>(mousePointDoc.x()); //m->x()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.x());
+ int MypS = static_cast<int>(mousePointDoc.y()); //m->y()/m_canvas->scale() + 0*m_doc->minCanvasCoordinate.y());
+ m_doc->nodeEdit.deselect();
+ if (!m_doc->masterPageMode())
+ {
+ int pgNum = -1;
+ int docPageCount = static_cast<int>(m_doc->Pages->count() - 1);
+ MarginStruct pageBleeds;
+ bool drawBleed = false;
+ if (m_doc->bleeds.hasNonZeroValue() && m_doc->guidesSettings.showBleed)
+ drawBleed = true;
+ for (int a = docPageCount; a > -1; a--)
+ {
+ if (drawBleed)
+ m_doc->getBleeds(a, pageBleeds);
+ int x = static_cast<int>(m_doc->Pages->at(a)->xOffset() - pageBleeds.Left);
+ int y = static_cast<int>(m_doc->Pages->at(a)->yOffset() - pageBleeds.Top);
+ int w = static_cast<int>(m_doc->Pages->at(a)->width() + pageBleeds.Left + pageBleeds.Right);
+ int h = static_cast<int>(m_doc->Pages->at(a)->height() + pageBleeds.Bottom + pageBleeds.Top);
+ if (QRect(x, y, w, h).contains(MxpS, MypS))
+ {
+ pgNum = static_cast<int>(a);
+ if (drawBleed) // check again if its really on the correct page
+ {
+ for (int a2 = docPageCount; a2 > -1; a2--)
+ {
+ int xn = static_cast<int>(m_doc->Pages->at(a2)->xOffset());
+ int yn = static_cast<int>(m_doc->Pages->at(a2)->yOffset());
+ int wn = static_cast<int>(m_doc->Pages->at(a2)->width());
+ int hn = static_cast<int>(m_doc->Pages->at(a2)->height());
+ if (QRect(xn, yn, wn, hn).contains(MxpS, MypS))
+ {
+ pgNum = static_cast<int>(a2);
+ break;
+ }
+ }
+ }
+ break;
+ }
+ }
+ if (pgNum >= 0)
+ {
+ if (m_doc->currentPageNumber() != pgNum)
+ {
+ m_doc->setCurrentPage(m_doc->Pages->at(unsigned(pgNum)));
+ m_view->setMenTxt(unsigned(pgNum));
+ m_view->DrawNew();
+ }
+ }
+ m_view->setRulerPos(m_view->contentsX(), m_view->contentsY());
+ }
+
+ currItem = NULL;
+ if ((m->modifiers() & SELECT_BENEATH) != 0)
+ {
+ for (int i=0; i < m_doc->m_Selection->count(); ++i)
+ {
+ if (m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), m_doc->m_Selection->itemAt(i)) >= 0)
+ {
+ currItem = m_doc->m_Selection->itemAt(i);
+// qDebug() << "select item: found BENEATH" << currItem << "groups" << currItem->Groups.count();
+ if (currItem->Groups.count() > 0)
+ {
+ m_doc->m_Selection->delaySignalsOn();
+ for (int ga=0; ga<m_doc->Items->count(); ++ga)
+ {
+ PageItem* item = m_doc->Items->at(ga);
+ if (item->Groups.count() != 0)
+ {
+ if (item->Groups.top() == currItem->Groups.top())
+ {
+ if (m_doc->m_Selection->findItem(item) >= 0)
+ {
+ m_doc->m_Selection->removeItem(item);
+ }
+ }
+ }
+ }
+ m_doc->m_Selection->delaySignalsOff();
+ }
+ else
+ {
+ m_doc->m_Selection->removeItem(currItem);
+ }
+ break;
+ }
+// else
+// qDebug() << "select item: not BENEATH" << QPointF(mousePointDoc.x(),mousePointDoc.y())
+// << m_doc->m_Selection->itemAt(i)->getTransform()
+// << m_doc->m_Selection->itemAt(i)->getBoundingRect();
+ }
+ }
+ else if ( (m->modifiers() & SELECT_MULTIPLE) == Qt::NoModifier || (m_doc->appMode == modeLinkFrames) || (m_doc->appMode == modeUnlinkFrames) )
+ {
+ m_view->Deselect(false);
+ }
+
+// qDebug() << "select item: beneath" << (m->modifiers() & SELECT_BENEATH) << currItem
+// << "multi" << (m->modifiers() & SELECT_MULTIPLE)
+// << "current sel" << m_doc->m_Selection->count();
+ currItem = m_canvas->itemUnderCursor(m->globalPos(), currItem, (m->modifiers() & SELECT_IN_GROUP));
+// qDebug() << "item under cursor: " << currItem;
+ if (currItem)
+ {
+ m_doc->m_Selection->delaySignalsOn();
+ if (m_doc->m_Selection->containsItem(currItem))
+ {
+ m_doc->m_Selection->removeItem(currItem);
+ }
+ else
+ {
+ //CB: If we have a selection but the user clicks with control on another item that is not below the current
+ //then clear and select the new item
+ if ((m->modifiers() == SELECT_BENEATH) && m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), currItem) >= 0)
+ m_doc->m_Selection->clear();
+ //CB: #7186: This was prependItem, does not seem to need to be anymore with current select code
+ m_doc->m_Selection->addItem(currItem);
+ if ( (m->modifiers() & SELECT_IN_GROUP) && (!currItem->isGroupControl))
+ {
+ currItem->isSingleSel = true;
+ }
+ else if (currItem->Groups.count() > 0)
+ {
+ for (int ga=0; ga<m_doc->Items->count(); ++ga)
+ {
+ PageItem* item = m_doc->Items->at(ga);
+ if (item->Groups.count() != 0)
+ {
+ if (item->Groups.top() == currItem->Groups.top())
+ {
+ if (item->ItemNr != currItem->ItemNr)
+ {
+ if (m_doc->m_Selection->findItem(item) == -1)
+ {
+ m_doc->m_Selection->addItem(item, true);
+ }
+ }
+ item->isSingleSel = false;
+ }
+ }
+ }
+ }
+ }
+
+ currItem->update();
+ m_doc->m_Selection->delaySignalsOff();
+ if (m_doc->m_Selection->count() > 1)
+ {
+ for (int aa = 0; aa < m_doc->m_Selection->count(); ++aa)
+ {
+ PageItem *bb = m_doc->m_Selection->itemAt(aa);
+ bb->update();
+ }
+ m_doc->m_Selection->setGroupRect();
+ double x, y, w, h;
+ m_doc->m_Selection->getGroupRect(&x, &y, &w, &h);
+ // emit ItemPos(x, y);
+ // emit ItemGeom(w, h);
+ m_view->getGroupRectScreen(&x, &y, &w, &h);
+ // m_view->updateContents(QRect(static_cast<int>(x-5), static_cast<int>(y-5), static_cast<int>(w+10), static_cast<int>(h+10)));
+ // emit HaveSel(currItem->itemType());
+ }
+ if (m_doc->m_Selection->count() == 1)
+ {
+ frameResizeHandle = m_canvas->frameHitTest(QPointF(mousePointDoc.x(),mousePointDoc.y()), currItem);
+ if ((frameResizeHandle == Canvas::INSIDE) && (!currItem->locked()))
+ qApp->changeOverrideCursor(QCursor(Qt::SizeAllCursor));
+ }
+ else
+ {
+ qApp->changeOverrideCursor(QCursor(Qt::SizeAllCursor));
+ m_canvas->m_viewMode.operItemResizing = false;
+ }
+ return true;
+ }
+ //m_doc->m_Selection->setIsGUISelection(true);
+ m_doc->m_Selection->connectItemToGUI();
+ if ( !(m->modifiers() & SELECT_MULTIPLE) || (m_doc->appMode == modeLinkFrames) || (m_doc->appMode == modeUnlinkFrames))
+ m_view->Deselect(true);
+ return false;
+}
+
+void CanvasMode_FrameLinks::createContextMenu(PageItem* currItem, double mx, double my)
+{
+ ContextMenu* cmen=NULL;
+ qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+ m_view->setObjectUndoMode();
+ Mxp = mx;
+ Myp = my;
+ if(currItem!=NULL)
+ {
+ cmen = new ContextMenu(*(m_doc->m_Selection), m_ScMW, m_doc);
+ cmen->exec(QCursor::pos());
+ m_view->setGlobalUndoMode();
+ delete cmen;
+ }
+}
Index: scribus/fpoint.cpp
===================================================================
--- scribus/fpoint.cpp (revision 13950)
+++ scribus/fpoint.cpp (revision 13951)
@@ -23,7 +23,7 @@
#include "fpoint.h"
-#include <QMatrix>
+#include <QTransform>
//Create transformed point
FPoint::FPoint(const double x, const double y, const double dx, const double dy, const double rot, const double sx, const double sy, const bool invert)
@@ -44,7 +44,7 @@
void FPoint::transform(const double dx, const double dy, const double rot, const double sx, const double sy, const bool invert)
{
- QMatrix ma;
+ QTransform ma;
ma.translate(dx, dy);
ma.scale(sx, sy);
ma.rotate(rot);
@@ -56,9 +56,9 @@
xp = newxp;
}
-FPoint FPoint::transformPoint(const QMatrix& m, const bool invert) const
+FPoint FPoint::transformPoint(const QTransform& m, const bool invert) const
{
- QMatrix ma;
+ QTransform ma;
if (invert)
ma = m.inverted();
else
@@ -71,7 +71,7 @@
FPoint FPoint::transformPoint(const double dx, const double dy, const double rot, const double sx, const double sy, const bool invert) const
{
- QMatrix ma;
+ QTransform ma;
ma.translate(dx, dy);
ma.scale(sx, sy);
ma.rotate(rot);
Index: scribus/scribusview.cpp
===================================================================
--- scribus/scribusview.cpp (revision 13950)
+++ scribus/scribusview.cpp (revision 13951)
@@ -1354,7 +1354,7 @@
void ScribusView::RefreshGradient(PageItem *currItem, double dx, double dy)
{
- QMatrix matrix;
+ QTransform matrix;
QRect rect = currItem->getRedrawBounding(m_canvas->scale());
m_canvas->Transform(currItem, matrix);
FPointArray fpNew;
@@ -1425,7 +1425,7 @@
{
PageItem *currItem = Doc->m_Selection->itemAt(0);
currItem->ClipEdited = true;
- QMatrix ma;
+ QTransform ma;
if (Doc->nodeEdit.isContourLine)
{
FPoint tp2(getMinClipF(&currItem->ContourLine));
@@ -1553,7 +1553,7 @@
currItem->PoLine.map(ma);
currItem->PoLine.translate(offsX, offsY);
Doc->AdjustItemSize(currItem);
- QMatrix ma2;
+ QTransform ma2;
ma2.translate(oldPos.x(), oldPos.y());
ma2.scale(1, 1);
ma2.translate(offsX, offsY);
@@ -1780,7 +1780,7 @@
void ScribusView::HandleCurs(PageItem *currItem, QRect mpo)
{
QPoint tx, tx2;
- QMatrix ma;
+ QTransform ma;
// ma.translate(-Doc->minCanvasCoordinate.x()*m_canvas->scale(), -Doc->minCanvasCoordinate.y()*m_canvas->scale());
m_canvas->Transform(currItem, ma);
tx = ma.map(QPoint(static_cast<int>(currItem->width()), 0));
@@ -4071,14 +4071,14 @@
// double csi = static_cast<double>(chs) / 100.0;
uint chr = chstr[0].unicode();
QPointF tangt = QPointF( cos(hl->PRot), sin(hl->PRot) );
- QMatrix chma, chma2, chma3, chma4, chma6;
- QMatrix trafo = QMatrix( 1, 0, 0, -1, -hl->PDx, 0 );
+ QTransform chma, chma2, chma3, chma4, chma6;
+ QTransform trafo = QTransform( 1, 0, 0, -1, -hl->PDx, 0 );
if (currItem->textPathFlipped)
- trafo *= QMatrix(1, 0, 0, -1, 0, 0);
+ trafo *= QTransform(1, 0, 0, -1, 0, 0);
if (currItem->textPathType == 0)
- trafo *= QMatrix( tangt.x(), tangt.y(), tangt.y(), -tangt.x(), hl->PtransX, hl->PtransY );
+ trafo *= QTransform( tangt.x(), tangt.y(), tangt.y(), -tangt.x(), hl->PtransX, hl->PtransY );
else if (currItem->textPathType == 1)
- trafo *= QMatrix(1, 0, 0, -1, hl->PtransX, hl->PtransY );
+ trafo *= QTransform(1, 0, 0, -1, hl->PtransX, hl->PtransY );
else if (currItem->textPathType == 2)
{
double a = 1;
@@ -4089,14 +4089,14 @@
b = 1;
}
if (fabs(tangt.x()) > 0.1)
- trafo *= QMatrix( a, (tangt.y() / tangt.x()) * b, 0, -1, hl->PtransX, hl->PtransY ); // ID's Skew mode
+ trafo *= QTransform( a, (tangt.y() / tangt.x()) * b, 0, -1, hl->PtransX, hl->PtransY ); // ID's Skew mode
else
- trafo *= QMatrix( a, 6 * b, 0, -1, hl->PtransX, hl->PtransY );
+ trafo *= QTransform( a, 6 * b, 0, -1, hl->PtransX, hl->PtransY );
}
- //trafo *= QMatrix( hl->PtransX, hl->PtransY, hl->PtransY, -hl->PtransX, hl->glyph.xoffset, hl->glyph.yoffset);
+ //trafo *= QTransform( hl->PtransX, hl->PtransY, hl->PtransY, -hl->PtransX, hl->glyph.xoffset, hl->glyph.yoffset);
if (currItem->rotation() != 0)
{
- QMatrix sca;
+ QTransform sca;
sca.translate(-currItem->xPos(), -currItem->yPos());
sca.rotate(currItem->rotation());
trafo *= sca;
@@ -4117,10 +4117,10 @@
if (hl->baselineOffset() != 0)
chma6.translate(0, (-charStyle.fontSize() / 10.0) * (charStyle.baselineOffset() / 1000.0));
uint gl = hl->font().char2CMap(chr);
- QMatrix finalMat = QMatrix(chma * chma2 * chma3 * chma4 * chma6 * trafo);
+ QTransform finalMat = QTransform(chma * chma2 * chma3 * chma4 * chma6 * trafo);
if (currItem->rotation() != 0)
{
- QMatrix sca;
+ QTransform sca;
sca.translate(currItem->xPos(), currItem->yPos());
pts.map(sca);
}
@@ -4128,10 +4128,10 @@
if (((charStyle.effects() & ScStyle_Underline) && !SpecialChars::isBreak(chstc))
|| ((charStyle.effects() & ScStyle_UnderlineWords) && !chstc.isSpace() && !SpecialChars::isBreak(chstc)))
{
- QMatrix stro = QMatrix(chma2 * chma3 * chma6 * trafo);
+ QTransform stro = QTransform(chma2 * chma3 * chma6 * trafo);
if (currItem->rotation() != 0)
{
- QMatrix sca;
+ QTransform sca;
sca.translate(currItem->xPos(), currItem->yPos());
stro *= sca;
}
@@ -4211,7 +4211,7 @@
bb->setItemName(currItem->itemName()+"+Sh"+ccounter.setNum(a));
bb->AutoName = false;
bb->PoLine = pts.copy();
- QMatrix shmap;
+ QTransform shmap;
shmap.translate(glxTr, glyTr);
bb->PoLine.map(finalMat * shmap);
bb->setFillColor(hl->strokeColor());
@@ -4271,10 +4271,10 @@
}
if (charStyle.effects() & ScStyle_Strikethrough)
{
- QMatrix stro = QMatrix(chma2 * chma3 * chma6 * trafo);
+ QTransform stro = QTransform(chma2 * chma3 * chma6 * trafo);
if (currItem->rotation() != 0)
{
- QMatrix sca;
+ QTransform sca;
sca.translate(currItem->xPos(), currItem->yPos());
stro *= sca;
}
@@ -4364,7 +4364,7 @@
chstr = chstr.toUpper();
double csi = static_cast<double>(chs) / 100.0;
uint chr = chstr[0].unicode();
- QMatrix chma, chma2, chma3, chma4, chma6;
+ QTransform chma, chma2, chma3, chma4, chma6;
uint gl = hl->font().char2CMap(chr);
FPoint origin = hl->font().glyphOrigin(gl);
x = origin.x() * csi;
@@ -4440,10 +4440,10 @@
pts = hl->font().glyphOutline(gl);
if (pts.size() < 4)
continue;
- chma = QMatrix();
+ chma = QTransform();
chma.scale(hl->glyph.scaleH * charStyle.fontSize() / 100.00, hl->glyph.scaleV * charStyle.fontSize() / 100.0);
pts.map(chma);
- chma = QMatrix();
+ chma = QTransform();
if (currItem->imageFlippedH() && (!currItem->reversed()))
chma.scale(-1, 1);
if (currItem->imageFlippedV())
@@ -4482,7 +4482,7 @@
x *= hl->glyph.scaleH;
y *= hl->glyph.scaleV;
}
- chma6 = QMatrix();
+ chma6 = QTransform();
if (charStyle.baselineOffset() != 0)
textY -= (charStyle.fontSize() / 10.0) * (charStyle.baselineOffset() / 1000.0);
if (a < currItem->itemText.length()-1)
@@ -4540,7 +4540,7 @@
x *= hl->glyph.scaleH;
y *= hl->glyph.scaleV;
}
- chma6 = QMatrix();
+ chma6 = QTransform();
if (charStyle.baselineOffset() != 0)
textY -= (charStyle.fontSize() / 10.0) * (charStyle.baselineOffset() / 1000.0);
if (a < currItem->itemText.length()-1)
Index: scribus/pageitem_textframe.cpp
===================================================================
--- scribus/pageitem_textframe.cpp (revision 13950)
+++ scribus/pageitem_textframe.cpp (revision 13951)
@@ -23,7 +23,7 @@
#include <QDebug>
#include <QList>
-#include <QMatrix>
+#include <QTransform>
#include <QPalette>
#include <QPoint>
#include <QPolygon>
@@ -86,7 +86,7 @@
static QRegion itemShape(PageItem* docItem, double xOffset, double yOffset)
{
QRegion res;
- QMatrix pp;
+ QTransform pp;
// pp.begin(view->viewport());
pp.translate(docItem->xPos() - xOffset, docItem->yPos() - yOffset);
pp.rotate(docItem->rotation());
@@ -470,7 +470,7 @@
}
/// find x position to start current line
- double startOfLine(const QRegion& shape, const QMatrix& pf2, double ascent, double descent, double morespace)
+ double startOfLine(const QRegion& shape, const QTransform& pf2, double ascent, double descent, double morespace)
{
QPoint pt1, pt2;
double tmpX = xPos;
@@ -491,7 +491,7 @@
}
/// find x position where this line must end
- double endOfLine(const QRegion& shape, const QMatrix& pf2, double ascent, double descent, double morespace = 0)
+ double endOfLine(const QRegion& shape, const QTransform& pf2, double ascent, double descent, double morespace = 0)
{
// Keep old code for reference
/*double EndX = floor(qMax(line.x, qMin(colRight,breakXPos) - 1));
@@ -831,7 +831,7 @@
// qDebug() << QString("textframe(%1,%2): len=%3, start relayout at %4").arg(Xpos).arg(Ypos).arg(itemText.length()).arg(firstInFrame());
// ScribusView* view = m_Doc->view();
- QMatrix pf2;
+ QTransform pf2;
QPoint pt1, pt2;
/*QRegion cm;*/
double chs, chsd = 0;
@@ -2326,7 +2326,7 @@
layout();
if (invalid)
return;
- QMatrix pf2;
+ QTransform pf2;
QPoint pt1, pt2;
double wide, lineCorr;
QChar chstr0;
Index: scribus/scpainterex_gdiplus.cpp
===================================================================
--- scribus/scpainterex_gdiplus.cpp (revision 13950)
+++ scribus/scpainterex_gdiplus.cpp (revision 13951)
@@ -1,769 +1,769 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-/* This file is part of the KDE project.
- Copyright (C) 2001, 2002, 2003 The Karbon Developers
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public License
- along with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-/* Adapted for Scribus 22.08.2003 by Franz Schmid */
-// kopainter/libart wrapper
-
-#ifdef WIN32_LEAN_AND_MEAN
-#undef WIN32_LEAN_AND_MEAN
-#endif
-
-#include <valarray>
-#include <windows.h>
-
-#include "scconfig.h"
-
-#include <gdiplus.h>
-using namespace Gdiplus;
-
-#include "scribusdoc.h"
-#include "scpainterex_gdiplus.h"
-#include "sccolorengine.h"
-#include "util.h"
-
-#include <QImage>
-#include <QList>
-#include <QPaintDevice>
-#include <QPixmap>
-
-#include <iostream>
-using namespace std;
-
-#include <math.h>
-
-ScPainterEx_GDIPlus::ScPainterEx_GDIPlus( HDC hDC, QRect& rect, ScribusDoc* doc, bool gray ) : ScPainterExBase()
-{
- m_doc = doc;
- m_width = rect.width();
- m_height = rect.height();
- m_strokeColor = ScColorShade( QColor(0,0,0), 100 );
- m_fillColor = ScColorShade( QColor(0,0,0), 100 );
- m_fillTrans = 1.0;
- m_strokeTrans = 1.0;
- m_fillRule = true;
- m_fillMode = 1;
- m_lineWidth = 1.0;
- m_offset = 0;
- m_lineEnd = Qt::SquareCap;
- m_lineJoin = Qt::RoundJoin;
- m_fillGradient = VGradientEx(VGradientEx::linear);
- m_strokeGradient = VGradientEx(VGradientEx::linear);
- // Grayscale conversion parameter
- m_convertToGray = gray;
- // Initialization of Windows GDI data
- m_dc = hDC;
- m_pathIsClosed = true;
- m_drawingClosedPath = false;
- m_positionX = m_positionY = 0;
- m_graphics = new Gdiplus::Graphics( m_dc );
- m_graphics->SetCompositingMode( CompositingModeSourceOver );
- m_graphics->SetCompositingQuality( CompositingQualityHighQuality );
- m_graphics->SetSmoothingMode( SmoothingModeHighQuality );
- m_graphics->SetPageUnit( UnitPoint );
- m_graphicsPath = NULL;
- clear();
-}
-
-ScPainterEx_GDIPlus::~ScPainterEx_GDIPlus()
-{
- if ( m_graphicsPath )
- delete m_graphicsPath;
- if ( m_graphics )
- delete m_graphics;
-}
-
-QColor ScPainterEx_GDIPlus::transformColor( ScColorShade& colorShade, double trans )
-{
- QColor c, color;
- c = ScColorEngine::getShadeColor(colorShade.color, m_doc, colorShade.shade);
- color = qRgba( qRed(c.rgb()), qGreen(c.rgb()), qBlue(c.rgb()), qAlpha(trans * 255));
- if ( m_convertToGray )
- {
- int grayLevel;
- QColor grayColor;
- grayLevel = 0.3 * color.red() + 0.59 * color.green() + 0.11 * color.blue();
- grayColor = qRgba( grayLevel, grayLevel, grayLevel, qAlpha(color.rgb()));
- color = grayColor;
- }
- return color;
-}
-
-void ScPainterEx_GDIPlus::transformImage( QImage* image, uchar* data, int scan)
-{
- int rgb, grey;
- int imageWidth = image->width();
- int imageHeight = image->height();
- QRgb* imageBits = (QRgb *) image->bits();
- QRgb* pscani;
- uchar *pscand;
-
- pscand = data;
- for ( int j = 0; j < imageHeight; j++ )
- {
- pscani = (QRgb *) image->scanLine(j);
- for (int i = 0; i < imageWidth; i++ )
- {
- rgb = pscani[i];
- grey = 0.3 * qRed(rgb) + 0.59 * qGreen(rgb) + 0.11 * qBlue(rgb);
- pscand[i] = grey;
- }
- pscand += scan;
- }
-}
-
-void ScPainterEx_GDIPlus::begin()
-{
-}
-
-void ScPainterEx_GDIPlus::end()
-{
- m_graphics->ResetTransform();
-}
-
-void ScPainterEx_GDIPlus::clear()
-{
- SolidBrush brush( Color(255,255,255) );
- m_graphics->FillRectangle(&brush, 0, 0, m_width, m_height);
-}
-
-void ScPainterEx_GDIPlus::clear( ScColorShade &c )
-{
- QColor color = transformColor( c, 1.0 );
- QRgb cs = color.rgb();
- SolidBrush brush( Color(qAlpha(cs), qRed(cs), qGreen(cs),qBlue(cs)) );
- m_graphics->FillRectangle(&brush, 0, 0, m_width, m_height);
-}
-
-const QMatrix ScPainterEx_GDIPlus::worldMatrix()
-{
- return m_matrix;
-}
-
-void ScPainterEx_GDIPlus::setWorldMatrix( const QMatrix &mat )
-{
- m_matrix = mat;
-}
-
-void ScPainterEx_GDIPlus::transformPoint( const FPoint& in, FPoint& out )
-{
- double x, y;
- x = in.x() * m_matrix.m11() + in.y() * m_matrix.m21() + m_matrix.dx();
- y = in.x() * m_matrix.m12() + in.y() * m_matrix.m22() + m_matrix.dy();
- out.setX( x );
- out.setY( y );
-}
-
-void ScPainterEx_GDIPlus::transformPoints( const FPoint* ArrayIn, FPoint* ArrayOut, uint length )
-{
- for( uint i = 0; i < length; i++ )
- {
- transformPoint( ArrayIn[i], ArrayOut[i] );
- }
-}
-
-void ScPainterEx_GDIPlus::translate( double x, double y )
-{
- m_matrix.translate(x, y);
-}
-
-void ScPainterEx_GDIPlus::rotate( double r )
-{
- m_matrix.rotate(r);
-}
-
-void ScPainterEx_GDIPlus::scale( double x, double y )
-{
- m_matrix.scale(x, y);
-}
-
-void ScPainterEx_GDIPlus::moveTo( const double &x, const double &y )
-{
- FPoint pp( x, y );
- transformPoint( pp, pp );
- m_positionX = pp.x();
- m_positionY = pp.y();
-}
-
-void ScPainterEx_GDIPlus::lineTo( const double &x, const double &y )
-{
- FPoint pp( x, y );
- transformPoint( pp, pp );
- m_graphicsPath->AddLine( (REAL) m_positionX, (REAL) m_positionY, pp.x(), pp.y() );
- m_positionX = pp.x();
- m_positionY = pp.y();
-}
-
-void ScPainterEx_GDIPlus::curveTo( FPoint p1, FPoint p2, FPoint p3 )
-{
- FPoint fpoints[3];
- fpoints[0].setXY( p1.x(), p1.y() );
- fpoints[1].setXY( p2.x(), p2.y() );
- fpoints[2].setXY( p3.x(), p3.y() );
- transformPoints( fpoints, fpoints, 3 );
- double p1x = fpoints[0].x();
- double p1y = fpoints[0].y();
- double p2x = fpoints[1].x();
- double p2y = fpoints[1].y();
- double p3x = fpoints[2].x();
- double p3y = fpoints[2].y();
- m_graphicsPath->AddBezier( (REAL) m_positionX, (REAL) m_positionY, p1x, p1y, p2x, p2y, p3x, p3y );
- m_positionX = p3x;
- m_positionY = p3y;
-}
-
-void ScPainterEx_GDIPlus::newPath()
-{
- if( m_graphicsPath )
- delete m_graphicsPath;
- m_graphicsPath = new Gdiplus::GraphicsPath();
- m_pathIsClosed = false;
- m_drawingClosedPath = false;
-}
-
-void ScPainterEx_GDIPlus::setFillRule( bool fillRule )
-{
- m_fillRule = fillRule;
-}
-
-void ScPainterEx_GDIPlus::setFillMode( int fill )
-{
- m_fillMode = fill;
-}
-
-void ScPainterEx_GDIPlus::setGradient(VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc)
-{
- m_fillGradient.setType(mode);
- m_fillGradient.setOrigin(orig);
- m_fillGradient.setVector(vec);
- m_fillGradient.setFocalPoint(foc);
-}
-
-void ScPainterEx_GDIPlus::setPattern( ScPattern* pattern, QMatrix& patternTransform )
-{
- m_pattern = pattern;
- m_patternTransform = patternTransform;
-}
-
-void ScPainterEx_GDIPlus::fillTextPath()
-{
- drawVPath( 0 );
-}
-
-void ScPainterEx_GDIPlus::strokeTextPath()
-{
- if( m_lineWidth == 0 )
- return;
- drawVPath( 1 );
-}
-
-void ScPainterEx_GDIPlus::fillPath()
-{
- m_pathIsClosed = true;
- if( m_fillMode != 0)
- drawVPath( 0 );
-}
-
-void ScPainterEx_GDIPlus::strokePath()
-{
- if( m_lineWidth == 0 )
- return;
- m_pathIsClosed = true;
- drawVPath( 1 );
-}
-
-ScColorShade ScPainterEx_GDIPlus::pen()
-{
- return m_strokeColor;
-}
-
-ScColorShade ScPainterEx_GDIPlus::brush()
-{
- return m_fillColor;
-}
-
-void ScPainterEx_GDIPlus::setPen( const ScColorShade &c )
-{
- m_strokeColor = c;
-}
-
-void ScPainterEx_GDIPlus::setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo )
-{
- m_strokeColor = c;
- m_lineWidth = w;
- m_lineEnd = ca;
- m_lineJoin = jo;
-// double Dt = qMax(1*w, 1.0);
-// double Sp = qMax(2*w, 1.0);
-// double Da = qMax(4*w, 1.0);
-// QList<double> tmp;
- m_array.clear();
- m_offset = 0;
- getDashArray(st, w, m_array);
-/* switch (st)
- {
- case Qt::SolidLine:
- break;
- case Qt::DashLine:
- m_array.append(Da);
- m_array.append(Sp);
- break;
- case Qt::DotLine:
- m_array.append(Dt);
- m_array.append(Sp);
-#ifdef SC_USE_GDIPLUS
- m_array.append(Dt);
-#endif
- break;
- case Qt::DashDotLine:
- m_array.append(Da);
- m_array.append(Sp);
- m_array.append(Dt);
- m_array.append(Sp);
- break;
- case Qt::DashDotDotLine:
- m_array.append(Da);
- m_array.append(Sp);
- m_array.append(Dt);
- m_array.append(Sp);
- m_array.append(Dt);
- m_array.append(Sp);
- break;
- default:
- break;
- } */
-}
-
-void ScPainterEx_GDIPlus::setLineWidth( double w )
-{
- m_lineWidth = w;
-}
-
-void ScPainterEx_GDIPlus::setPenOpacity( double op )
-{
- m_strokeTrans = op;
-}
-
-
-void ScPainterEx_GDIPlus::setDash(const QList<double>& array, double ofs)
-{
- m_array = array;
- m_offset = ofs;
-}
-
-void ScPainterEx_GDIPlus::setBrush( const ScColorShade &c )
-{
- m_fillColor = c;
-}
-
-void ScPainterEx_GDIPlus::setBrushOpacity( double op )
-{
- m_fillTrans = op;
-}
-
-void ScPainterEx_GDIPlus::setOpacity( double op )
-{
- m_fillTrans = op;
- m_strokeTrans = op;
-}
-
-void ScPainterEx_GDIPlus::setFont( const QFont &f)
-{
- m_font = f;
-}
-
-QFont ScPainterEx_GDIPlus::font()
-{
- return m_font;
-}
-
-void ScPainterEx_GDIPlus::save()
-{
- m_stack.push( m_matrix );
- m_gStates.push( m_graphics->Save() );
-}
-
-void ScPainterEx_GDIPlus::restore()
-{
- m_matrix = m_stack.pop();
- m_graphics->Restore( m_gStates.pop() );
-}
-
-void ScPainterEx_GDIPlus::setRasterOp( int )
-{
-}
-
-void ScPainterEx_GDIPlus::drawVPath( int mode )
-{
- save();
- if (mode == 0)
- {
- if( m_fillRule )
- m_graphicsPath->SetFillMode( FillModeAlternate);
- else
- m_graphicsPath->SetFillMode( FillModeWinding);
- if (m_fillMode == ScPainterExBase::Gradient)
- {
- drawGradient( m_fillGradient );
- }
- else
- {
- QColor fillColor = transformColor(m_fillColor, 1.0);
- SolidBrush fill_brush( Color(m_fillTrans * 255, fillColor.red(), fillColor.green(), fillColor.blue()) );
- m_graphics->FillPath( &fill_brush, m_graphicsPath );
- }
- }
- else
- {
- double m11 = m_matrix.m11();
- double m12 = m_matrix.m12();
- double m21 = m_matrix.m21();
- double m22 = m_matrix.m22();
- double norm2 = m11 * m11 + m12 * m12 + m21 * m21 + m22 * m22;
- double penScale = sqrt(norm2 / 2.0);
- double penWidth = m_lineWidth * penScale;
- QColor strokeColor = transformColor( m_strokeColor, 1.0 );
- SolidBrush stroke_brush( Color(m_strokeTrans * 255, strokeColor.red(), strokeColor.green(), strokeColor.blue()) );
- Pen stroke_pen( &stroke_brush, penWidth );
- REAL *dashes = NULL;
-
- if( m_array.count() > 0 )
- {
- dashes = new REAL[ m_array.count() ];
- for( int i = 0; i < m_array.count();++ i )
- {
- dashes[i] = (REAL) ( m_array[i] / (double) m_lineWidth );
- // The following lines are needed so that gdi+ rendering matches the libart one
- if( m_lineEnd == Qt::RoundCap || m_lineEnd == Qt::SquareCap )
- {
- if( (i % 2) == 0 )
- dashes[i] = dashes[i] + 1.0;
- else
- dashes[i] = dashes[i] - 1.0;
- }
- }
- // The following two lines are needed so that gdi+ rendering matches the libart one
- if( m_lineEnd == Qt::SquareCap && m_array.count() >= 2)
- stroke_pen.SetDashOffset( dashes[1]/2 );
- stroke_pen.SetDashPattern( dashes, m_array.count() );
- }
- if( m_lineEnd == Qt::RoundCap )
- stroke_pen.SetLineCap( LineCapRound, LineCapRound, DashCapRound );
- else if( m_lineEnd == Qt::SquareCap )
- stroke_pen.SetLineCap( LineCapSquare, LineCapSquare, DashCapFlat );
- else if( m_lineEnd == Qt::FlatCap && m_array.count() == 0 && m_drawingClosedPath )
- stroke_pen.SetLineCap( LineCapSquare, LineCapSquare, DashCapFlat );
- else if( m_lineEnd == Qt::FlatCap )
- stroke_pen.SetLineCap( LineCapFlat, LineCapFlat, DashCapFlat );
- if( m_lineJoin == Qt::RoundJoin )
- stroke_pen.SetLineJoin( LineJoinRound );
- else if( m_lineJoin == Qt::BevelJoin )
- stroke_pen.SetLineJoin( LineJoinBevel );
- else if( m_lineJoin == Qt::MiterJoin )
- stroke_pen.SetLineJoin( LineJoinMiter );
-
- m_graphics->DrawPath( &stroke_pen, m_graphicsPath );
- if( dashes )
- delete [] dashes;
- }
- restore();
-}
-
-void ScPainterEx_GDIPlus::setClipPath()
-{
- m_graphics->SetClip( m_graphicsPath, CombineModeIntersect );
-}
-
-void ScPainterEx_GDIPlus::drawImage( ScImage *image, ScPainterExBase::ImageMode mode )
-{
- FPoint ulp( 0, 0 );
- FPoint urp( image->width(), 0 );
- FPoint blp( 0, image->height() );
- transformPoint( ulp, ulp );
- transformPoint( blp, blp );
- transformPoint( urp, urp );
- Point destinationPoint[] = { Point(ulp.x(), ulp.y()), Point(urp.x(), urp.y()), Point(blp.x(), blp.y()) };
- ColorMatrix colorMatrix = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, m_fillTrans, 0.0f,
- 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
- if ( m_convertToGray )
- {
- colorMatrix.m[0][0] = colorMatrix.m[0][1] = colorMatrix.m[0][2] = (REAL) 0.3;
- colorMatrix.m[1][0] = colorMatrix.m[1][1] = colorMatrix.m[1][2] = (REAL) 0.59;
- colorMatrix.m[2][0] = colorMatrix.m[2][1] = colorMatrix.m[2][2] = (REAL) 0.11;
- }
- ImageAttributes imageAtt;
- imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);
- Bitmap bitmap( image->width(), image->height(), 4 * image->width(), PixelFormat32bppARGB, (uchar*) image->qImage().bits() );
- m_graphics->DrawImage( &bitmap, destinationPoint, 3, 0, 0, image->width(), image->height(), UnitPixel, &imageAtt );
-}
-
-void ScPainterEx_GDIPlus::setupPolygon(FPointArray *points, bool closed)
-{
- bool nPath = true, first = true;
- FPoint np, np1, np2, np3;
- if (points->size() > 3)
- {
- newPath();
- for (uint poi=0; poi<points->size()-3; poi += 4)
- {
- if (points->point(poi).x() > 900000)
- {
- nPath = true;
- continue;
- }
- if (nPath)
- {
- np = points->point(poi);
- if (!first && closed)
- m_graphicsPath->CloseFigure();
- m_graphicsPath->StartFigure();
- moveTo( np.x(), np.y() );
- nPath = first = false;
- }
- np = points->point(poi);
- np1 = points->point(poi+1);
- np2 = points->point(poi+3);
- np3 = points->point(poi+2);
- if ((np == np1) && (np2 == np3))
- lineTo( np3.x(), np3.y() );
- else
- curveTo(np1, np2, np3);
- }
- if (closed)
- {
- m_graphicsPath->CloseFigure();
- m_pathIsClosed = true;
- m_drawingClosedPath = true;
- }
- }
-}
-
-void ScPainterEx_GDIPlus::drawPolygon()
-{
- fillPath();
-}
-
-void ScPainterEx_GDIPlus::drawPolyLine()
-{
- strokePath();
-}
-
-void ScPainterEx_GDIPlus::drawLine(FPoint start, FPoint end)
-{
- newPath();
- moveTo(start.x(), start.y());
- lineTo(end.x(), end.y());
- strokePath();
-}
-
-void ScPainterEx_GDIPlus::drawRect(double x, double y, double w, double h)
-{
- newPath();
- moveTo( x, y );
- lineTo( x+w, y );
- lineTo( x+w, y+h );
- lineTo( x, y+h );
- lineTo( x, y );
- m_pathIsClosed = true;
- m_drawingClosedPath = true;
- fillPath();
- strokePath();
-}
-
-void ScPainterEx_GDIPlus::drawGradient( VGradientEx& gradient )
-{
- QRect clipPathRect;
- save();
- setClipPath();
- getClipPathDimensions( clipPathRect );
- if ( gradient.type() == VGradientEx::linear )
- drawLinearGradient( gradient, clipPathRect );
- else if ( gradient.type() == VGradientEx::radial )
- drawCircularGradient( gradient, clipPathRect );
- restore();
-}
-
-void ScPainterEx_GDIPlus::drawLinearGradient( VGradientEx& gradient, const QRect& rect )
-{
- Matrix matrix;
- int index = 0;
- int numElements;
- int r, g, b, a;
- double cosa, sina;
- double length, scale;
- double x1, y1, x2, y2, dx, dy;
- int clipBoxWidth, clipBoxHeight, maxDim;
- QList<VColorStopEx*> colorStops = gradient.colorStops();
- VColorStopEx stop( *colorStops[0] );
- FPoint p1, p1a, p2, p2a;
- QColor color;
-
- if ( gradient.Stops() < 2 )
- return;
-
- clipBoxWidth = rect.width();
- clipBoxHeight = rect.height();
- maxDim = sqrt( (double) (clipBoxWidth * clipBoxWidth + clipBoxHeight * clipBoxHeight) ) * 2;
- if ( maxDim <= 0 )
- return;
-
- x1 = m_matrix.dx() + gradient.origin().x() * m_matrix.m11();
- y1 = m_matrix.dy() + gradient.origin().y() * m_matrix.m22();
- x2 = m_matrix.dx() + gradient.vector().x() * m_matrix.m11();
- y2 = m_matrix.dy() + gradient.vector().y() * m_matrix.m22();
- p1.setXY( x1, y1 );
- p2.setXY( x2, y2 );
-
- dx = ( p2.x() - p1.x() );
- dy = ( p2.y() - p1.y() );
- length = sqrt(( dx * dx + dy * dy ));
- if ( length == 0.0 )
- scale = 1.0;
- else
- scale = 1.0 / length;
- cosa = dx * scale;
- sina = dy * scale;
-
- p1a.setXY( p1.x() - cosa * maxDim, p1.y() - sina * maxDim );
- p2a.setXY( p2.x() + cosa * maxDim, p2.y() + sina * maxDim );
-
- numElements = gradient.Stops() + 2;
- Color *colors = new Color[numElements];
- REAL *positions = new REAL[numElements];
-
- stop = *colorStops[0];
- color = transformColor( ScColorShade(stop.color, stop.shade), 1.0 );
- colors[0] = Color(stop.opacity * 255, color.red(), color.green(), color.blue());
- positions[0] = 0.0;
-
- stop = *colorStops[gradient.Stops() - 1];
- color = transformColor( ScColorShade(stop.color, stop.shade), 1.0 );
- colors[numElements - 1] = Color(stop.opacity * 255, color.red(), color.green(), color.blue());
- positions[numElements - 1] = 1.0;
-
- for( uint index = 0 ; index < gradient.Stops(); index++)
- {
- stop = *colorStops[index];
- color = transformColor( ScColorShade(stop.color, stop.shade), 1.0 );
- r = color.red();
- g = color.green();
- b = color.blue();
- a = stop.opacity * 255;
- colors[index + 1] = Color(a, r, g, b);
- positions[index + 1] = ( stop.rampPoint * length + maxDim ) / ( length + 2 * maxDim );
- }
- LinearGradientBrush gradientBrush( PointF( p1a.x(), p1a.y() ) ,
- PointF( p2a.x(), p2a.y() ),
- colors[0], colors[numElements - 1] );
- gradientBrush.SetInterpolationColors(colors, positions, numElements);
- m_graphics->FillPath( &gradientBrush, m_graphicsPath );
-
- delete[] colors;
- delete[] positions;
-}
-
-void ScPainterEx_GDIPlus::drawCircularGradient( VGradientEx& gradient, const QRect& rect )
-{
- int offset = 0;
- int numElements;
- int r, g, b, a;
- int clipBoxWidth, clipBoxHeight, maxDim;
- QList<VColorStopEx*> colorStops = gradient.colorStops();
- VColorStopEx stop( *colorStops[0] );
- QColor color;
-
- clipBoxWidth = rect.width();
- clipBoxHeight = rect.height();
- maxDim = sqrt( (double) (clipBoxWidth * clipBoxWidth + clipBoxHeight * clipBoxHeight) ) * 2;
- if ( maxDim <= 0 ) return;
-
- FPoint pc( gradient.origin().x(), gradient.origin().y() );
- FPoint pcz( gradient.origin().x(), gradient.origin().y() );
- FPoint pf( gradient.focalPoint().x(), gradient.focalPoint().y() );
- FPoint pfz( gradient.focalPoint().x(), gradient.focalPoint().y() );
- FPoint pv( gradient.vector().x(), gradient.vector().y() );
- transformPoint( pc, pc );
- transformPoint( pf, pf );
- transformPoint( pv, pv );
- transformPoint( pcz, pcz );
- transformPoint( pfz, pfz );
- double cx = pcz.x();
- double cy = pcz.y();
- double fx = pfz.x();
- double fy = pfz.y();
- double rad = sqrt( pow(pv.x() - pc.x(), 2) + pow(pv.y() - pc.y(), 2) );
-
- numElements = gradient.Stops() + 2;
- Color *colors = new Color[numElements];
- REAL *positions = new REAL[numElements];
-
- stop = *colorStops[ 0 ];
- color = transformColor( ScColorShade(stop.color, stop.shade), stop.opacity);
- colors[numElements - 1] = Color(stop.opacity * 255, color.red(), color.green(), color.blue());
- positions[numElements - 1] = 1.0;
-
- stop = *colorStops[ gradient.Stops() - 1 ];
- color = transformColor( ScColorShade(stop.color, stop.shade), stop.opacity);
- colors[0] = Color(stop.opacity * 255, color.red(), color.green(), color.blue());
- positions[0] = 0.0;
-
- for( uint index = 0 ; index < gradient.Stops() ; index++)
- {
- stop = *colorStops[index];
- color = transformColor( ScColorShade(stop.color, stop.shade), 1.0 );
- r = color.red();
- g = color.green();
- b = color.blue();
- a = stop.opacity * 255;
- colors[gradient.Stops() - index] = Color(a, r, g, b);
- positions[gradient.Stops() - index] = 1 - 2 * (stop.rampPoint * rad) / (double) maxDim;
- }
-
- GraphicsPath gradientPath;
- gradientPath.AddEllipse( cx - maxDim/2, cy - maxDim/2, maxDim, maxDim );
- PathGradientBrush gradientBrush( &gradientPath );
- gradientBrush.SetCenterPoint( PointF(cx, cy) );
- gradientBrush.SetCenterColor( colors[numElements - 1] );
- gradientBrush.SetInterpolationColors( colors, positions, numElements );
- m_graphics->FillPath( &gradientBrush, m_graphicsPath );
-
- delete[] colors;
- delete[] positions;
-}
-
-void ScPainterEx_GDIPlus::getClipPathDimensions( QRect& r )
-{
- Rect rect(0, 0, 0, 0);
- Status result = m_graphics->GetClipBounds( &rect );
- if( result == Ok )
- {
- r.setLeft( rect.GetLeft() );
- r.setRight( rect.GetRight() );
- r.setBottom( rect.GetBottom() );
- r.setTop( rect.GetTop() );
- }
-}
-
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+/* This file is part of the KDE project.
+ Copyright (C) 2001, 2002, 2003 The Karbon Developers
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/* Adapted for Scribus 22.08.2003 by Franz Schmid */
+// kopainter/libart wrapper
+
+#ifdef WIN32_LEAN_AND_MEAN
+#undef WIN32_LEAN_AND_MEAN
+#endif
+
+#include <valarray>
+#include <windows.h>
+
+#include "scconfig.h"
+
+#include <gdiplus.h>
+using namespace Gdiplus;
+
+#include "scribusdoc.h"
+#include "scpainterex_gdiplus.h"
+#include "sccolorengine.h"
+#include "util.h"
+
+#include <QImage>
+#include <QList>
+#include <QPaintDevice>
+#include <QPixmap>
+
+#include <iostream>
+using namespace std;
+
+#include <math.h>
+
+ScPainterEx_GDIPlus::ScPainterEx_GDIPlus( HDC hDC, QRect& rect, ScribusDoc* doc, bool gray ) : ScPainterExBase()
+{
+ m_doc = doc;
+ m_width = rect.width();
+ m_height = rect.height();
+ m_strokeColor = ScColorShade( QColor(0,0,0), 100 );
+ m_fillColor = ScColorShade( QColor(0,0,0), 100 );
+ m_fillTrans = 1.0;
+ m_strokeTrans = 1.0;
+ m_fillRule = true;
+ m_fillMode = 1;
+ m_lineWidth = 1.0;
+ m_offset = 0;
+ m_lineEnd = Qt::SquareCap;
+ m_lineJoin = Qt::RoundJoin;
+ m_fillGradient = VGradientEx(VGradientEx::linear);
+ m_strokeGradient = VGradientEx(VGradientEx::linear);
+ // Grayscale conversion parameter
+ m_convertToGray = gray;
+ // Initialization of Windows GDI data
+ m_dc = hDC;
+ m_pathIsClosed = true;
+ m_drawingClosedPath = false;
+ m_positionX = m_positionY = 0;
+ m_graphics = new Gdiplus::Graphics( m_dc );
+ m_graphics->SetCompositingMode( CompositingModeSourceOver );
+ m_graphics->SetCompositingQuality( CompositingQualityHighQuality );
+ m_graphics->SetSmoothingMode( SmoothingModeHighQuality );
+ m_graphics->SetPageUnit( UnitPoint );
+ m_graphicsPath = NULL;
+ clear();
+}
+
+ScPainterEx_GDIPlus::~ScPainterEx_GDIPlus()
+{
+ if ( m_graphicsPath )
+ delete m_graphicsPath;
+ if ( m_graphics )
+ delete m_graphics;
+}
+
+QColor ScPainterEx_GDIPlus::transformColor( ScColorShade& colorShade, double trans )
+{
+ QColor c, color;
+ c = ScColorEngine::getShadeColor(colorShade.color, m_doc, colorShade.shade);
+ color = qRgba( qRed(c.rgb()), qGreen(c.rgb()), qBlue(c.rgb()), qAlpha(trans * 255));
+ if ( m_convertToGray )
+ {
+ int grayLevel;
+ QColor grayColor;
+ grayLevel = 0.3 * color.red() + 0.59 * color.green() + 0.11 * color.blue();
+ grayColor = qRgba( grayLevel, grayLevel, grayLevel, qAlpha(color.rgb()));
+ color = grayColor;
+ }
+ return color;
+}
+
+void ScPainterEx_GDIPlus::transformImage( QImage* image, uchar* data, int scan)
+{
+ int rgb, grey;
+ int imageWidth = image->width();
+ int imageHeight = image->height();
+ QRgb* imageBits = (QRgb *) image->bits();
+ QRgb* pscani;
+ uchar *pscand;
+
+ pscand = data;
+ for ( int j = 0; j < imageHeight; j++ )
+ {
+ pscani = (QRgb *) image->scanLine(j);
+ for (int i = 0; i < imageWidth; i++ )
+ {
+ rgb = pscani[i];
+ grey = 0.3 * qRed(rgb) + 0.59 * qGreen(rgb) + 0.11 * qBlue(rgb);
+ pscand[i] = grey;
+ }
+ pscand += scan;
+ }
+}
+
+void ScPainterEx_GDIPlus::begin()
+{
+}
+
+void ScPainterEx_GDIPlus::end()
+{
+ m_graphics->ResetTransform();
+}
+
+void ScPainterEx_GDIPlus::clear()
+{
+ SolidBrush brush( Color(255,255,255) );
+ m_graphics->FillRectangle(&brush, 0, 0, m_width, m_height);
+}
+
+void ScPainterEx_GDIPlus::clear( ScColorShade &c )
+{
+ QColor color = transformColor( c, 1.0 );
+ QRgb cs = color.rgb();
+ SolidBrush brush( Color(qAlpha(cs), qRed(cs), qGreen(cs),qBlue(cs)) );
+ m_graphics->FillRectangle(&brush, 0, 0, m_width, m_height);
+}
+
+const QTransform ScPainterEx_GDIPlus::worldMatrix()
+{
+ return m_matrix;
+}
+
+void ScPainterEx_GDIPlus::setWorldMatrix( const QTransform &mat )
+{
+ m_matrix = mat;
+}
+
+void ScPainterEx_GDIPlus::transformPoint( const FPoint& in, FPoint& out )
+{
+ double x, y;
+ x = in.x() * m_matrix.m11() + in.y() * m_matrix.m21() + m_matrix.dx();
+ y = in.x() * m_matrix.m12() + in.y() * m_matrix.m22() + m_matrix.dy();
+ out.setX( x );
+ out.setY( y );
+}
+
+void ScPainterEx_GDIPlus::transformPoints( const FPoint* ArrayIn, FPoint* ArrayOut, uint length )
+{
+ for( uint i = 0; i < length; i++ )
+ {
+ transformPoint( ArrayIn[i], ArrayOut[i] );
+ }
+}
+
+void ScPainterEx_GDIPlus::translate( double x, double y )
+{
+ m_matrix.translate(x, y);
+}
+
+void ScPainterEx_GDIPlus::rotate( double r )
+{
+ m_matrix.rotate(r);
+}
+
+void ScPainterEx_GDIPlus::scale( double x, double y )
+{
+ m_matrix.scale(x, y);
+}
+
+void ScPainterEx_GDIPlus::moveTo( const double &x, const double &y )
+{
+ FPoint pp( x, y );
+ transformPoint( pp, pp );
+ m_positionX = pp.x();
+ m_positionY = pp.y();
+}
+
+void ScPainterEx_GDIPlus::lineTo( const double &x, const double &y )
+{
+ FPoint pp( x, y );
+ transformPoint( pp, pp );
+ m_graphicsPath->AddLine( (REAL) m_positionX, (REAL) m_positionY, pp.x(), pp.y() );
+ m_positionX = pp.x();
+ m_positionY = pp.y();
+}
+
+void ScPainterEx_GDIPlus::curveTo( FPoint p1, FPoint p2, FPoint p3 )
+{
+ FPoint fpoints[3];
+ fpoints[0].setXY( p1.x(), p1.y() );
+ fpoints[1].setXY( p2.x(), p2.y() );
+ fpoints[2].setXY( p3.x(), p3.y() );
+ transformPoints( fpoints, fpoints, 3 );
+ double p1x = fpoints[0].x();
+ double p1y = fpoints[0].y();
+ double p2x = fpoints[1].x();
+ double p2y = fpoints[1].y();
+ double p3x = fpoints[2].x();
+ double p3y = fpoints[2].y();
+ m_graphicsPath->AddBezier( (REAL) m_positionX, (REAL) m_positionY, p1x, p1y, p2x, p2y, p3x, p3y );
+ m_positionX = p3x;
+ m_positionY = p3y;
+}
+
+void ScPainterEx_GDIPlus::newPath()
+{
+ if( m_graphicsPath )
+ delete m_graphicsPath;
+ m_graphicsPath = new Gdiplus::GraphicsPath();
+ m_pathIsClosed = false;
+ m_drawingClosedPath = false;
+}
+
+void ScPainterEx_GDIPlus::setFillRule( bool fillRule )
+{
+ m_fillRule = fillRule;
+}
+
+void ScPainterEx_GDIPlus::setFillMode( int fill )
+{
+ m_fillMode = fill;
+}
+
+void ScPainterEx_GDIPlus::setGradient(VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc)
+{
+ m_fillGradient.setType(mode);
+ m_fillGradient.setOrigin(orig);
+ m_fillGradient.setVector(vec);
+ m_fillGradient.setFocalPoint(foc);
+}
+
+void ScPainterEx_GDIPlus::setPattern( ScPattern* pattern, QTransform& patternTransform )
+{
+ m_pattern = pattern;
+ m_patternTransform = patternTransform;
+}
+
+void ScPainterEx_GDIPlus::fillTextPath()
+{
+ drawVPath( 0 );
+}
+
+void ScPainterEx_GDIPlus::strokeTextPath()
+{
+ if( m_lineWidth == 0 )
+ return;
+ drawVPath( 1 );
+}
+
+void ScPainterEx_GDIPlus::fillPath()
+{
+ m_pathIsClosed = true;
+ if( m_fillMode != 0)
+ drawVPath( 0 );
+}
+
+void ScPainterEx_GDIPlus::strokePath()
+{
+ if( m_lineWidth == 0 )
+ return;
+ m_pathIsClosed = true;
+ drawVPath( 1 );
+}
+
+ScColorShade ScPainterEx_GDIPlus::pen()
+{
+ return m_strokeColor;
+}
+
+ScColorShade ScPainterEx_GDIPlus::brush()
+{
+ return m_fillColor;
+}
+
+void ScPainterEx_GDIPlus::setPen( const ScColorShade &c )
+{
+ m_strokeColor = c;
+}
+
+void ScPainterEx_GDIPlus::setPen( const ScColorShade &c, double w, Qt::PenStyle st, Qt::PenCapStyle ca, Qt::PenJoinStyle jo )
+{
+ m_strokeColor = c;
+ m_lineWidth = w;
+ m_lineEnd = ca;
+ m_lineJoin = jo;
+// double Dt = qMax(1*w, 1.0);
+// double Sp = qMax(2*w, 1.0);
+// double Da = qMax(4*w, 1.0);
+// QList<double> tmp;
+ m_array.clear();
+ m_offset = 0;
+ getDashArray(st, w, m_array);
+/* switch (st)
+ {
+ case Qt::SolidLine:
+ break;
+ case Qt::DashLine:
+ m_array.append(Da);
+ m_array.append(Sp);
+ break;
+ case Qt::DotLine:
+ m_array.append(Dt);
+ m_array.append(Sp);
+#ifdef SC_USE_GDIPLUS
+ m_array.append(Dt);
+#endif
+ break;
+ case Qt::DashDotLine:
+ m_array.append(Da);
+ m_array.append(Sp);
+ m_array.append(Dt);
+ m_array.append(Sp);
+ break;
+ case Qt::DashDotDotLine:
+ m_array.append(Da);
+ m_array.append(Sp);
+ m_array.append(Dt);
+ m_array.append(Sp);
+ m_array.append(Dt);
+ m_array.append(Sp);
+ break;
+ default:
+ break;
+ } */
+}
+
+void ScPainterEx_GDIPlus::setLineWidth( double w )
+{
+ m_lineWidth = w;
+}
+
+void ScPainterEx_GDIPlus::setPenOpacity( double op )
+{
+ m_strokeTrans = op;
+}
+
+
+void ScPainterEx_GDIPlus::setDash(const QList<double>& array, double ofs)
+{
+ m_array = array;
+ m_offset = ofs;
+}
+
+void ScPainterEx_GDIPlus::setBrush( const ScColorShade &c )
+{
+ m_fillColor = c;
+}
+
+void ScPainterEx_GDIPlus::setBrushOpacity( double op )
+{
+ m_fillTrans = op;
+}
+
+void ScPainterEx_GDIPlus::setOpacity( double op )
+{
+ m_fillTrans = op;
+ m_strokeTrans = op;
+}
+
+void ScPainterEx_GDIPlus::setFont( const QFont &f)
+{
+ m_font = f;
+}
+
+QFont ScPainterEx_GDIPlus::font()
+{
+ return m_font;
+}
+
+void ScPainterEx_GDIPlus::save()
+{
+ m_stack.push( m_matrix );
+ m_gStates.push( m_graphics->Save() );
+}
+
+void ScPainterEx_GDIPlus::restore()
+{
+ m_matrix = m_stack.pop();
+ m_graphics->Restore( m_gStates.pop() );
+}
+
+void ScPainterEx_GDIPlus::setRasterOp( int )
+{
+}
+
+void ScPainterEx_GDIPlus::drawVPath( int mode )
+{
+ save();
+ if (mode == 0)
+ {
+ if( m_fillRule )
+ m_graphicsPath->SetFillMode( FillModeAlternate);
+ else
+ m_graphicsPath->SetFillMode( FillModeWinding);
+ if (m_fillMode == ScPainterExBase::Gradient)
+ {
+ drawGradient( m_fillGradient );
+ }
+ else
+ {
+ QColor fillColor = transformColor(m_fillColor, 1.0);
+ SolidBrush fill_brush( Color(m_fillTrans * 255, fillColor.red(), fillColor.green(), fillColor.blue()) );
+ m_graphics->FillPath( &fill_brush, m_graphicsPath );
+ }
+ }
+ else
+ {
+ double m11 = m_matrix.m11();
+ double m12 = m_matrix.m12();
+ double m21 = m_matrix.m21();
+ double m22 = m_matrix.m22();
+ double norm2 = m11 * m11 + m12 * m12 + m21 * m21 + m22 * m22;
+ double penScale = sqrt(norm2 / 2.0);
+ double penWidth = m_lineWidth * penScale;
+ QColor strokeColor = transformColor( m_strokeColor, 1.0 );
+ SolidBrush stroke_brush( Color(m_strokeTrans * 255, strokeColor.red(), strokeColor.green(), strokeColor.blue()) );
+ Pen stroke_pen( &stroke_brush, penWidth );
+ REAL *dashes = NULL;
+
+ if( m_array.count() > 0 )
+ {
+ dashes = new REAL[ m_array.count() ];
+ for( int i = 0; i < m_array.count();++ i )
+ {
+ dashes[i] = (REAL) ( m_array[i] / (double) m_lineWidth );
+ // The following lines are needed so that gdi+ rendering matches the libart one
+ if( m_lineEnd == Qt::RoundCap || m_lineEnd == Qt::SquareCap )
+ {
+ if( (i % 2) == 0 )
+ dashes[i] = dashes[i] + 1.0;
+ else
+ dashes[i] = dashes[i] - 1.0;
+ }
+ }
+ // The following two lines are needed so that gdi+ rendering matches the libart one
+ if( m_lineEnd == Qt::SquareCap && m_array.count() >= 2)
+ stroke_pen.SetDashOffset( dashes[1]/2 );
+ stroke_pen.SetDashPattern( dashes, m_array.count() );
+ }
+ if( m_lineEnd == Qt::RoundCap )
+ stroke_pen.SetLineCap( LineCapRound, LineCapRound, DashCapRound );
+ else if( m_lineEnd == Qt::SquareCap )
+ stroke_pen.SetLineCap( LineCapSquare, LineCapSquare, DashCapFlat );
+ else if( m_lineEnd == Qt::FlatCap && m_array.count() == 0 && m_drawingClosedPath )
+ stroke_pen.SetLineCap( LineCapSquare, LineCapSquare, DashCapFlat );
+ else if( m_lineEnd == Qt::FlatCap )
+ stroke_pen.SetLineCap( LineCapFlat, LineCapFlat, DashCapFlat );
+ if( m_lineJoin == Qt::RoundJoin )
+ stroke_pen.SetLineJoin( LineJoinRound );
+ else if( m_lineJoin == Qt::BevelJoin )
+ stroke_pen.SetLineJoin( LineJoinBevel );
+ else if( m_lineJoin == Qt::MiterJoin )
+ stroke_pen.SetLineJoin( LineJoinMiter );
+
+ m_graphics->DrawPath( &stroke_pen, m_graphicsPath );
+ if( dashes )
+ delete [] dashes;
+ }
+ restore();
+}
+
+void ScPainterEx_GDIPlus::setClipPath()
+{
+ m_graphics->SetClip( m_graphicsPath, CombineModeIntersect );
+}
+
+void ScPainterEx_GDIPlus::drawImage( ScImage *image, ScPainterExBase::ImageMode mode )
+{
+ FPoint ulp( 0, 0 );
+ FPoint urp( image->width(), 0 );
+ FPoint blp( 0, image->height() );
+ transformPoint( ulp, ulp );
+ transformPoint( blp, blp );
+ transformPoint( urp, urp );
+ Point destinationPoint[] = { Point(ulp.x(), ulp.y()), Point(urp.x(), urp.y()), Point(blp.x(), blp.y()) };
+ ColorMatrix colorMatrix = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, m_fillTrans, 0.0f,
+ 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
+ if ( m_convertToGray )
+ {
+ colorMatrix.m[0][0] = colorMatrix.m[0][1] = colorMatrix.m[0][2] = (REAL) 0.3;
+ colorMatrix.m[1][0] = colorMatrix.m[1][1] = colorMatrix.m[1][2] = (REAL) 0.59;
+ colorMatrix.m[2][0] = colorMatrix.m[2][1] = colorMatrix.m[2][2] = (REAL) 0.11;
+ }
+ ImageAttributes imageAtt;
+ imageAtt.SetColorMatrix(&colorMatrix, ColorMatrixFlagsDefault, ColorAdjustTypeBitmap);
+ Bitmap bitmap( image->width(), image->height(), 4 * image->width(), PixelFormat32bppARGB, (uchar*) image->qImage().bits() );
+ m_graphics->DrawImage( &bitmap, destinationPoint, 3, 0, 0, image->width(), image->height(), UnitPixel, &imageAtt );
+}
+
+void ScPainterEx_GDIPlus::setupPolygon(FPointArray *points, bool closed)
+{
+ bool nPath = true, first = true;
+ FPoint np, np1, np2, np3;
+ if (points->size() > 3)
+ {
+ newPath();
+ for (uint poi=0; poi<points->size()-3; poi += 4)
+ {
+ if (points->point(poi).x() > 900000)
+ {
+ nPath = true;
+ continue;
+ }
+ if (nPath)
+ {
+ np = points->point(poi);
+ if (!first && closed)
+ m_graphicsPath->CloseFigure();
+ m_graphicsPath->StartFigure();
+ moveTo( np.x(), np.y() );
+ nPath = first = false;
+ }
+ np = points->point(poi);
+ np1 = points->point(poi+1);
+ np2 = points->point(poi+3);
+ np3 = points->point(poi+2);
+ if ((np == np1) && (np2 == np3))
+ lineTo( np3.x(), np3.y() );
+ else
+ curveTo(np1, np2, np3);
+ }
+ if (closed)
+ {
+ m_graphicsPath->CloseFigure();
+ m_pathIsClosed = true;
+ m_drawingClosedPath = true;
+ }
+ }
+}
+
+void ScPainterEx_GDIPlus::drawPolygon()
+{
+ fillPath();
+}
+
+void ScPainterEx_GDIPlus::drawPolyLine()
+{
+ strokePath();
+}
+
+void ScPainterEx_GDIPlus::drawLine(FPoint start, FPoint end)
+{
+ newPath();
+ moveTo(start.x(), start.y());
+ lineTo(end.x(), end.y());
+ strokePath();
+}
+
+void ScPainterEx_GDIPlus::drawRect(double x, double y, double w, double h)
+{
+ newPath();
+ moveTo( x, y );
+ lineTo( x+w, y );
+ lineTo( x+w, y+h );
+ lineTo( x, y+h );
+ lineTo( x, y );
+ m_pathIsClosed = true;
+ m_drawingClosedPath = true;
+ fillPath();
+ strokePath();
+}
+
+void ScPainterEx_GDIPlus::drawGradient( VGradientEx& gradient )
+{
+ QRect clipPathRect;
+ save();
+ setClipPath();
+ getClipPathDimensions( clipPathRect );
+ if ( gradient.type() == VGradientEx::linear )
+ drawLinearGradient( gradient, clipPathRect );
+ else if ( gradient.type() == VGradientEx::radial )
+ drawCircularGradient( gradient, clipPathRect );
+ restore();
+}
+
+void ScPainterEx_GDIPlus::drawLinearGradient( VGradientEx& gradient, const QRect& rect )
+{
+ Matrix matrix;
+ int index = 0;
+ int numElements;
+ int r, g, b, a;
+ double cosa, sina;
+ double length, scale;
+ double x1, y1, x2, y2, dx, dy;
+ int clipBoxWidth, clipBoxHeight, maxDim;
+ QList<VColorStopEx*> colorStops = gradient.colorStops();
+ VColorStopEx stop( *colorStops[0] );
+ FPoint p1, p1a, p2, p2a;
+ QColor color;
+
+ if ( gradient.Stops() < 2 )
+ return;
+
+ clipBoxWidth = rect.width();
+ clipBoxHeight = rect.height();
+ maxDim = sqrt( (double) (clipBoxWidth * clipBoxWidth + clipBoxHeight * clipBoxHeight) ) * 2;
+ if ( maxDim <= 0 )
+ return;
+
+ x1 = m_matrix.dx() + gradient.origin().x() * m_matrix.m11();
+ y1 = m_matrix.dy() + gradient.origin().y() * m_matrix.m22();
+ x2 = m_matrix.dx() + gradient.vector().x() * m_matrix.m11();
+ y2 = m_matrix.dy() + gradient.vector().y() * m_matrix.m22();
+ p1.setXY( x1, y1 );
+ p2.setXY( x2, y2 );
+
+ dx = ( p2.x() - p1.x() );
+ dy = ( p2.y() - p1.y() );
+ length = sqrt(( dx * dx + dy * dy ));
+ if ( length == 0.0 )
+ scale = 1.0;
+ else
+ scale = 1.0 / length;
+ cosa = dx * scale;
+ sina = dy * scale;
+
+ p1a.setXY( p1.x() - cosa * maxDim, p1.y() - sina * maxDim );
+ p2a.setXY( p2.x() + cosa * maxDim, p2.y() + sina * maxDim );
+
+ numElements = gradient.Stops() + 2;
+ Color *colors = new Color[numElements];
+ REAL *positions = new REAL[numElements];
+
+ stop = *colorStops[0];
+ color = transformColor( ScColorShade(stop.color, stop.shade), 1.0 );
+ colors[0] = Color(stop.opacity * 255, color.red(), color.green(), color.blue());
+ positions[0] = 0.0;
+
+ stop = *colorStops[gradient.Stops() - 1];
+ color = transformColor( ScColorShade(stop.color, stop.shade), 1.0 );
+ colors[numElements - 1] = Color(stop.opacity * 255, color.red(), color.green(), color.blue());
+ positions[numElements - 1] = 1.0;
+
+ for( uint index = 0 ; index < gradient.Stops(); index++)
+ {
+ stop = *colorStops[index];
+ color = transformColor( ScColorShade(stop.color, stop.shade), 1.0 );
+ r = color.red();
+ g = color.green();
+ b = color.blue();
+ a = stop.opacity * 255;
+ colors[index + 1] = Color(a, r, g, b);
+ positions[index + 1] = ( stop.rampPoint * length + maxDim ) / ( length + 2 * maxDim );
+ }
+ LinearGradientBrush gradientBrush( PointF( p1a.x(), p1a.y() ) ,
+ PointF( p2a.x(), p2a.y() ),
+ colors[0], colors[numElements - 1] );
+ gradientBrush.SetInterpolationColors(colors, positions, numElements);
+ m_graphics->FillPath( &gradientBrush, m_graphicsPath );
+
+ delete[] colors;
+ delete[] positions;
+}
+
+void ScPainterEx_GDIPlus::drawCircularGradient( VGradientEx& gradient, const QRect& rect )
+{
+ int offset = 0;
+ int numElements;
+ int r, g, b, a;
+ int clipBoxWidth, clipBoxHeight, maxDim;
+ QList<VColorStopEx*> colorStops = gradient.colorStops();
+ VColorStopEx stop( *colorStops[0] );
+ QColor color;
+
+ clipBoxWidth = rect.width();
+ clipBoxHeight = rect.height();
+ maxDim = sqrt( (double) (clipBoxWidth * clipBoxWidth + clipBoxHeight * clipBoxHeight) ) * 2;
+ if ( maxDim <= 0 ) return;
+
+ FPoint pc( gradient.origin().x(), gradient.origin().y() );
+ FPoint pcz( gradient.origin().x(), gradient.origin().y() );
+ FPoint pf( gradient.focalPoint().x(), gradient.focalPoint().y() );
+ FPoint pfz( gradient.focalPoint().x(), gradient.focalPoint().y() );
+ FPoint pv( gradient.vector().x(), gradient.vector().y() );
+ transformPoint( pc, pc );
+ transformPoint( pf, pf );
+ transformPoint( pv, pv );
+ transformPoint( pcz, pcz );
+ transformPoint( pfz, pfz );
+ double cx = pcz.x();
+ double cy = pcz.y();
+ double fx = pfz.x();
+ double fy = pfz.y();
+ double rad = sqrt( pow(pv.x() - pc.x(), 2) + pow(pv.y() - pc.y(), 2) );
+
+ numElements = gradient.Stops() + 2;
+ Color *colors = new Color[numElements];
+ REAL *positions = new REAL[numElements];
+
+ stop = *colorStops[ 0 ];
+ color = transformColor( ScColorShade(stop.color, stop.shade), stop.opacity);
+ colors[numElements - 1] = Color(stop.opacity * 255, color.red(), color.green(), color.blue());
+ positions[numElements - 1] = 1.0;
+
+ stop = *colorStops[ gradient.Stops() - 1 ];
+ color = transformColor( ScColorShade(stop.color, stop.shade), stop.opacity);
+ colors[0] = Color(stop.opacity * 255, color.red(), color.green(), color.blue());
+ positions[0] = 0.0;
+
+ for( uint index = 0 ; index < gradient.Stops() ; index++)
+ {
+ stop = *colorStops[index];
+ color = transformColor( ScColorShade(stop.color, stop.shade), 1.0 );
+ r = color.red();
+ g = color.green();
+ b = color.blue();
+ a = stop.opacity * 255;
+ colors[gradient.Stops() - index] = Color(a, r, g, b);
+ positions[gradient.Stops() - index] = 1 - 2 * (stop.rampPoint * rad) / (double) maxDim;
+ }
+
+ GraphicsPath gradientPath;
+ gradientPath.AddEllipse( cx - maxDim/2, cy - maxDim/2, maxDim, maxDim );
+ PathGradientBrush gradientBrush( &gradientPath );
+ gradientBrush.SetCenterPoint( PointF(cx, cy) );
+ gradientBrush.SetCenterColor( colors[numElements - 1] );
+ gradientBrush.SetInterpolationColors( colors, positions, numElements );
+ m_graphics->FillPath( &gradientBrush, m_graphicsPath );
+
+ delete[] colors;
+ delete[] positions;
+}
+
+void ScPainterEx_GDIPlus::getClipPathDimensions( QRect& r )
+{
+ Rect rect(0, 0, 0, 0);
+ Status result = m_graphics->GetClipBounds( &rect );
+ if( result == Ok )
+ {
+ r.setLeft( rect.GetLeft() );
+ r.setRight( rect.GetRight() );
+ r.setBottom( rect.GetBottom() );
+ r.setTop( rect.GetTop() );
+ }
+}
+
Index: scribus/vgradientex.h
===================================================================
--- scribus/vgradientex.h (revision 13950)
+++ scribus/vgradientex.h (revision 13951)
@@ -27,7 +27,7 @@
#define __VGRADIENTEX_H__
#include <QList>
-#include <QMatrix>
+#include <QTransform>
#include "fpoint.h"
#include "sccolor.h"
@@ -126,7 +126,7 @@
FPoint vector() const { return m_vector; }
void setVector( const FPoint &vector ) { m_vector = vector; }
- void transform( const QMatrix& m );
+ void transform( const QTransform& m );
protected:
QList<VColorStopEx*> m_colorStops;
Index: scribus/ui/polygonwidget.cpp
===================================================================
--- scribus/ui/polygonwidget.cpp (revision 13950)
+++ scribus/ui/polygonwidget.cpp (revision 13951)
@@ -134,20 +134,20 @@
QRectF br = pp.boundingRect();
if (br.x() < 0)
{
- QMatrix m;
+ QTransform m;
m.translate(-br.x(), 0);
pp = pp * m;
}
if (br.y() < 0)
{
- QMatrix m;
+ QTransform m;
m.translate(0, -br.y());
pp = pp * m;
}
br = pp.boundingRect();
if ((br.height() > Preview->height() - 6) || (br.width() > Preview->width() - 6))
{
- QMatrix ma;
+ QTransform ma;
double sca = static_cast<double>(qMax(Preview->height() - 6, Preview->width() - 6)) / static_cast<double>(qMax(br.width(), br.height()));
ma.scale(sca, sca);
pp = pp * ma;
Index: scribus/ui/arrowchooser.cpp
===================================================================
--- scribus/ui/arrowchooser.cpp (revision 13950)
+++ scribus/ui/arrowchooser.cpp (revision 13951)
@@ -42,8 +42,8 @@
FPoint min = getMinClipF(&Path);
Path.translate(-min.x(), -min.y());
FPoint max = Path.WidthHeight();
- QMatrix mm;
- QMatrix mm2;
+ QTransform mm;
+ QTransform mm2;
if (arrowDirection)
{
mm2.scale(-1, 1);
Index: scribus/plugins/tools/lenseffects/lensdialog.cpp
===================================================================
--- scribus/plugins/tools/lenseffects/lensdialog.cpp (revision 13950)
+++ scribus/plugins/tools/lenseffects/lensdialog.cpp (revision 13951)
@@ -280,7 +280,7 @@
else
{
PageItem* parent = groupStack3.top();
- QMatrix mm;
+ QTransform mm;
mm.rotate(-parent->rotation());
mm.translate(-parent->xPos(), -parent->yPos());
pItem->setPos(mm.map(QPointF(currItem->xPos(), currItem->yPos())));
@@ -334,13 +334,13 @@
{
double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation;
currItem->patternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
- QMatrix qmatrix;
+ QTransform qmatrix;
qmatrix.translate(patternOffsetX, patternOffsetY);
qmatrix.rotate(patternRotation);
qmatrix.scale(patternScaleX / 100.0, patternScaleY / 100.0);
QImage pat = *doc->docPatterns[currItem->pattern()].getPattern();
QBrush brush = QBrush(pat);
- brush.setMatrix(qmatrix);
+ brush.setTransform(qmatrix);
pItem->setBrush(brush);
}
}
Index: scribus/plugins/tools/pathfinder/pathfinderdialog.cpp
===================================================================
--- scribus/plugins/tools/pathfinder/pathfinderdialog.cpp (revision 13950)
+++ scribus/plugins/tools/pathfinder/pathfinderdialog.cpp (revision 13951)
@@ -31,7 +31,7 @@
#include <QPixmap>
#include <QPainter>
-#include <QMatrix>
+#include <QTransform>
PathFinderDialog::PathFinderDialog(QWidget* parent, ScribusDoc* doc, PageItem *shape1, PageItem *shape2) : QDialog( parent )
{
@@ -56,7 +56,7 @@
setCurrentComboItem(otherColorComboLine, shape1->lineColor());
setCurrentComboItem(otherColorComboFill, shape1->fillColor());
opMode = 0;
- QMatrix ms;
+ QTransform ms;
ms.rotate(shape1->rotation());
input1 = ms.map(shape1->PoLine.toQPainterPath(true));
if (shape1->fillEvenOdd())
@@ -65,7 +65,7 @@
input1.setFillRule(Qt::WindingFill);
double dx = shape2->xPos() - shape1->xPos();
double dy = shape2->yPos() - shape1->yPos();
- QMatrix mm;
+ QTransform mm;
mm.translate(dx, dy);
mm.rotate(shape2->rotation());
input2 = mm.map(shape2->PoLine.toQPainterPath(true));
Index: scribus/plugins/tools/pathconnect/pathconnect.cpp
===================================================================
--- scribus/plugins/tools/pathconnect/pathconnect.cpp (revision 13950)
+++ scribus/plugins/tools/pathconnect/pathconnect.cpp (revision 13951)
@@ -197,11 +197,11 @@
FPointArray result;
FPointArray path1 = p1.copy();
FPointArray path2 = p2.copy();
- QMatrix ma;
+ QTransform ma;
ma.translate(Item2->xPos(), Item2->yPos());
ma.rotate(Item2->rotation());
path2.map(ma);
- QMatrix ma2;
+ QTransform ma2;
ma2.translate(originalXPos, originalYPos);
ma2.rotate(Item1->rotation());
ma2 = ma2.inverted();
Index: scribus/plugins/tools/pathstroker/pathstroker.cpp
===================================================================
--- scribus/plugins/tools/pathstroker/pathstroker.cpp (revision 13950)
+++ scribus/plugins/tools/pathstroker/pathstroker.cpp (revision 13951)
@@ -147,7 +147,7 @@
if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
{
double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = currDoc->arrowStyles.at(currItem->startArrowIndex()-1).points.copy();
arrowTrans.translate(Start.x(), Start.y());
arrowTrans.rotate(r);
@@ -167,7 +167,7 @@
if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
{
double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = currDoc->arrowStyles.at(currItem->endArrowIndex()-1).points.copy();
arrowTrans.translate(End.x(), End.y());
arrowTrans.rotate(r);
@@ -265,7 +265,7 @@
if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
{
double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = currDoc->arrowStyles.at(currItem->startArrowIndex()-1).points.copy();
arrowTrans.translate(Start.x(), Start.y());
arrowTrans.rotate(r);
@@ -305,7 +305,7 @@
if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
{
double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = currDoc->arrowStyles.at(currItem->endArrowIndex()-1).points.copy();
arrowTrans.translate(End.x(), End.y());
arrowTrans.rotate(r);
Index: scribus/plugins/tools/pathcut/pathcut.cpp
===================================================================
--- scribus/plugins/tools/pathcut/pathcut.cpp (revision 13950)
+++ scribus/plugins/tools/pathcut/pathcut.cpp (revision 13951)
@@ -137,14 +137,14 @@
QPainterPathStroker stroke;
stroke.setWidth(Item1->lineWidth());
QPainterPath cutter = stroke.createStroke(path.toQPainterPath(false));
- QMatrix ms;
+ QTransform ms;
ms.translate(Item1->xPos() - Item2->xPos(), Item1->yPos() - Item2->yPos());
ms.rotate(Item1->rotation());
cutter = ms.map(cutter);
path.map(ms);
FPoint start = path.point(0);
FPoint end = path.point(path.size()-2);
- QMatrix mm;
+ QTransform mm;
mm.rotate(Item2->rotation());
QPainterPath objekt = mm.map(Item2->PoLine.toQPainterPath(true));
if ((objekt.contains(QPointF(start.x(), start.y()))) || (objekt.contains(QPointF(end.x(), end.y()))))
Index: scribus/plugins/tools/2geomtools/pathalongpath/pathalongpath.cpp
===================================================================
--- scribus/plugins/tools/2geomtools/pathalongpath/pathalongpath.cpp (revision 13950)
+++ scribus/plugins/tools/2geomtools/pathalongpath/pathalongpath.cpp (revision 13951)
@@ -197,7 +197,7 @@
else
pathItem = currDoc->m_Selection->itemAt(selCount);
effectPath = pathItem->PoLine.copy();
- QMatrix mp;
+ QTransform mp;
mp.rotate(pathItem->rotation());
effectPath.map(mp);
for (int bx = 0; bx < selCount; ++bx)
@@ -234,7 +234,7 @@
pathItem = currDoc->m_Selection->itemAt(0);
}
effectPath = pathItem->PoLine.copy();
- QMatrix mp;
+ QTransform mp;
mp.rotate(pathItem->rotation());
effectPath.map(mp);
originalPath = patternItem->PoLine.copy();
@@ -310,7 +310,7 @@
FPointArray pathP = originalPathG[bx].copy();
double deltaX = originalXPosG[bx] - originX;
double deltaY = originalYPosG[bx] - originY;
- QMatrix mm;
+ QTransform mm;
mm.rotate(originalRotG[bx]);
pathP.map(mm);
pathP.translate(deltaX, deltaY);
@@ -320,7 +320,7 @@
patternpwd2 = FPointArray2Piecewise(pathP, true);
bxi->PoLine = doEffect_pwd2(patternpwd2);
bxi->PoLine.translate(-deltaX, -deltaY);
- QMatrix mm2;
+ QTransform mm2;
mm2.rotate(-originalRotG[bx]);
bxi->PoLine.map(mm2);
bxi->Frame = false;
Index: scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp
===================================================================
--- scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp (revision 13950)
+++ scribus/plugins/tools/2geomtools/meshdistortion/meshdistortiondialog.cpp (revision 13951)
@@ -157,13 +157,13 @@
else
{
PageItem* parent = groupStack3.top();
- QMatrix mm;
+ QTransform mm;
mm.rotate(-parent->rotation());
mm.translate(-parent->xPos(), -parent->yPos());
pItem->setPos(mm.map(QPointF(currItem->xPos(), currItem->yPos())));
}
QPainterPath pathO = pp;
- QMatrix mmO;
+ QTransform mmO;
mmO.translate(-w4, -w4);
pathO = pItem->mapToScene(pathO);
pathO = mmO.map(pathO);
@@ -222,13 +222,13 @@
{
double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation;
currItem->patternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
- QMatrix qmatrix;
+ QTransform qmatrix;
qmatrix.translate(patternOffsetX, patternOffsetY);
qmatrix.rotate(patternRotation);
qmatrix.scale(patternScaleX / 100.0, patternScaleY / 100.0);
QImage pat = *doc->docPatterns[currItem->pattern()].getPattern();
QBrush brush = QBrush(pat);
- brush.setMatrix(qmatrix);
+ brush.setTransform(qmatrix);
pItem->setBrush(brush);
}
}
Index: scribus/plugins/tools/transform/transformdialog.h
===================================================================
--- scribus/plugins/tools/transform/transformdialog.h (revision 13950)
+++ scribus/plugins/tools/transform/transformdialog.h (revision 13951)
@@ -30,7 +30,7 @@
#include <QDialog>
#include <QListWidget>
#include <QListWidgetItem>
-#include <QMatrix>
+#include <QTransform>
#include <QMenu>
#include <QString>
#include "ui_transformdialogbase.h"
@@ -54,7 +54,7 @@
public:
TransformDialog(QWidget* parent, ScribusDoc *doc);
~TransformDialog() {};
- QMatrix getTransformMatrix();
+ QTransform getTransformMatrix();
int getCount();
int getBasepoint();
Index: scribus/plugins/tools/transform/transformeffect.cpp
===================================================================
--- scribus/plugins/tools/transform/transformeffect.cpp (revision 13950)
+++ scribus/plugins/tools/transform/transformeffect.cpp (revision 13951)
@@ -111,7 +111,7 @@
{
qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
int nrOfCopies = dia->getCount();
- QMatrix matrix = dia->getTransformMatrix();
+ QTransform matrix = dia->getTransformMatrix();
int baseP = dia->getBasepoint();
if (nrOfCopies == 0)
{
@@ -131,8 +131,8 @@
PageItem *currItem = currDoc->m_Selection->itemAt(a);
double deltaX = currItem->xPos() - gx;
double deltaY = currItem->yPos() - gy;
- QMatrix matrixPre = QMatrix();
- QMatrix matrixAft = QMatrix();
+ QTransform matrixPre = QTransform();
+ QTransform matrixAft = QTransform();
switch (baseP)
{
case 2:
@@ -179,7 +179,7 @@
currDoc->view()->updatesOn(false);
currDoc->m_Selection->delaySignalsOn();
currDoc->scMW()->ScriptRunning = true;
- QMatrix comulatedMatrix = matrix;
+ QTransform comulatedMatrix = matrix;
PageItem *currItem = currDoc->m_Selection->itemAt(0);
Elements.append(currItem);
int rotBack = currDoc->RotMode();
@@ -205,8 +205,8 @@
currItem = currDoc->m_Selection->itemAt(a);
double deltaX = currItem->xPos() - gx;
double deltaY = currItem->yPos() - gy;
- QMatrix matrixPre = QMatrix();
- QMatrix matrixAft = QMatrix();
+ QTransform matrixPre = QTransform();
+ QTransform matrixAft = QTransform();
switch (baseP)
{
case 2:
Index: scribus/plugins/tools/transform/transformdialog.cpp
===================================================================
--- scribus/plugins/tools/transform/transformdialog.cpp (revision 13950)
+++ scribus/plugins/tools/transform/transformdialog.cpp (revision 13951)
@@ -313,9 +313,9 @@
}
}
-QMatrix TransformDialog::getTransformMatrix()
+QTransform TransformDialog::getTransformMatrix()
{
- QMatrix ret = QMatrix();
+ QTransform ret = QTransform();
for (int a = 0; a < transformSelector->count(); a++)
{
QListWidgetItem *it = transformSelector->item(a);
Index: scribus/plugins/fileloader/scribus150format/scribus150format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus150format/scribus150format.cpp (revision 13950)
+++ scribus/plugins/fileloader/scribus150format/scribus150format.cpp (revision 13951)
@@ -1,3399 +1,3399 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-#include "scribus150format.h"
-#include "scribus150formatimpl.h"
-
-#include "../../formatidlist.h"
-#include "commonstrings.h"
-#include "ui/missing.h"
-#include "hyphenator.h"
-#include "pageitem_latexframe.h"
-#include "prefsmanager.h"
-#include "scclocale.h"
-#include "scconfig.h"
-#include "sccolorengine.h"
-#include "scpattern.h"
-#include "scribuscore.h"
-#include "scribusdoc.h"
-#include "scribusview.h"
-#include "sctextstream.h"
-#include "scxmlstreamreader.h"
-#include "undomanager.h"
-#include "units.h"
-#include "util.h"
-#include "util_math.h"
-#include "util_color.h"
-#include "scgzfile.h"
-#include "scpattern.h"
-#ifdef HAVE_OSG
- #include "pageitem_osgframe.h"
-#endif
-#include <QCursor>
-// #include <QDebug>
-#include <QFileInfo>
-#include <QList>
-#include <QByteArray>
-#include <QApplication>
-
-
-// See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods
-// do. That documentatation is not duplicated here.
-// Please don't implement the functionality of your plugin here; do that
-// in scribus150formatimpl.h and scribus150formatimpl.cpp .
-
-Scribus150Format::Scribus150Format() :
- LoadSavePlugin()
-{
- // Set action info in languageChange, so we only have to do
- // it in one place. This includes registering file formats.
- languageChange();
-}
-
-Scribus150Format::~Scribus150Format()
-{
- unregisterAll();
-};
-
-void Scribus150Format::languageChange()
-{
- //(Re)register file formats.
- unregisterAll();
- registerFormats();
-}
-
-const QString Scribus150Format::fullTrName() const
-{
- return QObject::tr("Scribus 1.3.4+ Support");
-}
-
-const ScActionPlugin::AboutData* Scribus150Format::getAboutData() const
-{
- AboutData* about = new AboutData;
- Q_CHECK_PTR(about);
- about->authors = QString::fromUtf8(
- "Franz Schmid <franz at scribus.info>, "
- "The Scribus Team");
- about->shortDescription = tr("Scribus 1.3.4+ File Format Support");
- about->description = tr("Allows Scribus to read Scribus 1.3.4 and higher formatted files.");
- // about->version
- // about->releaseDate
- // about->copyright
- about->license = "GPL";
- return about;
-}
-
-void Scribus150Format::deleteAboutData(const AboutData* about) const
-{
- Q_ASSERT(about);
- delete about;
-}
-
-void Scribus150Format::registerFormats()
-{
- FileFormat fmt(this);
- fmt.trName = tr("Scribus 1.5.0+ Document");
- fmt.formatId = FORMATID_SLA150IMPORT;
- fmt.load = true;
- fmt.save = true;
- fmt.filter = fmt.trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)";
- fmt.nameMatch = QRegExp("\\.(sla|scd)(\\.gz)?", Qt::CaseInsensitive);
- fmt.mimeTypes = QStringList();
- fmt.mimeTypes.append("application/x-scribus");
- fmt.priority = 64;
- registerFormat(fmt);
-}
-
-bool Scribus150Format::fileSupported(QIODevice* /* file */, const QString & fileName) const
-{
- QByteArray docBytes("");
- if(fileName.right(2) == "gz")
- {
- if (!ScGzFile::readFromFile(fileName, docBytes, 4096))
- {
- // FIXME: Needs better error return
- return false;
- }
- }
- else
- {
- // Not gzip encoded, just load it
- loadRawText(fileName, docBytes);
- }
-// if (docBytes.left(16) == "<SCRIBUSUTF8NEW " && docBytes.left(35).contains("Version=\"1.3.4"))
-// return true;
- int startElemPos = docBytes.left(512).indexOf("<SCRIBUSUTF8NEW ");
- return startElemPos >= 0 && ((docBytes.mid(startElemPos, 64).indexOf("Version=\"1.5.0") >= 0));
-}
-
-QString Scribus150Format::readSLA(const QString & fileName)
-{
- QByteArray docBytes("");
- if(fileName.right(2) == "gz")
- {
- if (!ScGzFile::readFromFile(fileName, docBytes))
- {
- // FIXME: Needs better error return
- return false;
- }
- }
- else
- {
- // Not gzip encoded, just load it
- loadRawText(fileName, docBytes);
- }
- QString docText("");
- int startElemPos = docBytes.left(512).indexOf("<SCRIBUSUTF8NEW ");
- if (startElemPos >= 0 && ((docBytes.mid(startElemPos, 64).indexOf("Version=\"1.5.0") >= 0)))
- docText = QString::fromUtf8(docBytes);
- else
- return QString::null;
- if (docText.endsWith(QChar(10)) || docText.endsWith(QChar(13)))
- docText.truncate(docText.length()-1);
- return docText;
-}
-
-void Scribus150Format::getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QList<ScFace> &getDummyScFaces)
-{
- getNewReplacement=false;
- getReplacedFonts.clear();
-}
-
-bool Scribus150Format::loadFile(const QString & fileName, const FileFormat & /* fmt */, int /* flags */, int /* index */)
-{
- if (m_Doc==0 || m_AvailableFonts==0)
- {
- Q_ASSERT(m_Doc==0 || m_AvailableFonts==0);
- return false;
- }
- ParagraphStyle vg;
- struct ScribusDoc::BookMa bok;
- QMap<int, ScribusDoc::BookMa> bookmarks;
-
- bool newVersion = false;
-
- QMap<int,int> TableID;
- QMap<int,int> TableIDM;
- QMap<int,int> TableIDF;
- QList<PageItem*> TableItems;
- QList<PageItem*> TableItemsM;
- QList<PageItem*> TableItemsF;
- QMap<PageItem*, int> groupID;
- QMap<PageItem*, int> groupIDM;
- QMap<PageItem*, int> groupIDF;
-
- QString f(readSLA(fileName));
- if (f.isEmpty())
- return false;
- QString fileDir = QFileInfo(fileName).absolutePath();
- int firstPage = 0;
- int layerToSetActive = 0;
- ScColor lf = ScColor();
-
- if (m_mwProgressBar!=0)
- {
- m_mwProgressBar->setMaximum(f.length());
- m_mwProgressBar->setValue(0);
- }
- // Stop autosave timer,it will be restarted only if doc has autosave feature is enabled
- if (m_Doc->autoSaveTimer->isActive())
- m_Doc->autoSaveTimer->stop();
-
- groupRemap.clear();
- itemRemap.clear();
- itemNext.clear();
- itemCount = 0;
- itemRemapM.clear();
- itemNextM.clear();
- itemCountM = 0;
- itemRemapF.clear();
- itemNextF.clear();
-
- TableItems.clear();
- TableID.clear();
- TableItemsM.clear();
- TableIDM.clear();
- TableItemsF.clear();
- TableIDF.clear();
-
- m_Doc->GroupCounter = 1;
- m_Doc->LastAuto = 0;
- m_Doc->PageColors.clear();
- m_Doc->Layers.clear();
-
- bool firstElement = true;
- bool success = true;
- bool hasPageSets = false;
- int progress = 0;
-
- ScXmlStreamReader reader(f);
- ScXmlStreamAttributes attrs;
- while(!reader.atEnd() && !reader.hasError())
- {
- QXmlStreamReader::TokenType tType = reader.readNext();
- if (tType != QXmlStreamReader::StartElement)
- continue;
- QStringRef tagName = reader.name();
- attrs = reader.scAttributes();
-
- if (m_mwProgressBar != 0)
- {
- int newProgress = qRound(reader.characterOffset() / (double) f.length() * 100);
- if (newProgress != progress)
- {
- m_mwProgressBar->setValue(reader.characterOffset());
- progress = newProgress;
- }
- }
-
- if (firstElement)
- {
- if (tagName != "SCRIBUSUTF8NEW")
- {
- success = false;
- break;
- }
- if (attrs.hasAttribute("Version"))
- newVersion = true;
- firstElement = false;
- }
- if (tagName == "DOCUMENT")
- {
- readDocAttributes(m_Doc, attrs);
- layerToSetActive = attrs.valueAsInt("ALAYER", 0);
- if (m_Doc->currentPageLayout == 0)
- firstPage = 0;
- else
- {
- if (attrs.valueAsInt("FIRSTLEFT", 0) == 1)
- firstPage = 0;
- else
- firstPage = 1;
- }
- if (attrs.hasAttribute("currentProfile"))
- {
- m_Doc->checkerProfiles.clear();
- m_Doc->curCheckProfile = attrs.valueAsString("currentProfile");
- }
- }
- if (tagName == "CheckProfile")
- {
- success = readCheckProfile(m_Doc, attrs);
- if (!success) break;
- }
- if (tagName == "PageSets")
- {
- success = readPageSets(m_Doc, reader);
- if (!success) break;
- hasPageSets = true;
- }
- // 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
- if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None)
- {
- success = readColor(m_Doc->PageColors, attrs);
- if (!success) break;
- }
- if (tagName == "STYLE")
- {
- readParagraphStyle(m_Doc, reader, vg, *m_AvailableFonts);
- StyleSet<ParagraphStyle>tmp;
- tmp.create(vg);
- m_Doc->redefineStyles(tmp, false);
- }
- if (tagName == "CHARSTYLE")
- {
- readParagraphStyle(m_Doc, reader, vg, *m_AvailableFonts);
- StyleSet<CharStyle> temp;
- temp.create(vg.charStyle());
- m_Doc->redefineCharStyles(temp, false);
- }
- if (tagName == "JAVA")
- {
- QString name = attrs.valueAsString("NAME");
- if (!name.isEmpty())
- m_Doc->JavaScripts[name] = attrs.valueAsString("SCRIPT");
- }
- if (tagName == "LAYERS")
- {
- ScLayer newLayer;
- readLayers(newLayer, attrs);
- m_Doc->Layers.append(newLayer);
- }
- if (tagName == "Arrows")
- {
- success = readArrows(m_Doc, attrs);
- if (!success) break;
- }
- if (tagName == "MultiLine")
- {
- multiLine ml;
- QString mlName = attrs.valueAsString("Name");
- success = readMultiline(ml, reader);
- if (!success) break;
- if (!mlName.isEmpty())
- {
- m_Doc->MLineStyles.insert(mlName, ml);
- }
- }
- if (tagName == "Bookmark")
- {
- int bmElem = 0;
- struct ScribusDoc::BookMa bookmark;
- success = readBookMark(bookmark, bmElem, attrs);
- if (!success) break;
- bookmarks.insert(bmElem, bookmark);
- }
- if (tagName == "PDF")
- {
- success = readPDFOptions(m_Doc, reader);
- if (!success) break;
- }
- if (tagName == "Printer")
- {
- success = readPrinterOptions(m_Doc, reader);
- if (!success) break;
- }
- if (tagName == "DocItemAttributes")
- {
- success = readDocItemAttributes(m_Doc, reader);
- if (!success) break;
- }
- if (tagName == "TablesOfContents")
- {
- success = readTableOfContents(m_Doc, reader);
- if (!success) break;
- }
- if (tagName == "Sections")
- {
- success = readSections(m_Doc, reader);
- if (!success) break;
- }
- if (tagName == "HYPHEN")
- {
- success = readHyphen(m_Doc, reader);
- if (!success) break;
- }
- if (tagName == "PAGE" || tagName == "MASTERPAGE")
- {
- success = readPage(m_Doc, reader);
- if (!success) break;
- }
- if (tagName == "PAGEOBJECT" || tagName == "MASTEROBJECT" || tagName == "FRAMEOBJECT")
- {
- ItemInfo itemInfo;
- success = readObject(m_Doc, reader, itemInfo, fileDir, false);
- if (!success) break;
-
- // first of linked chain?
- if (tagName == "PAGEOBJECT")
- {
- if (itemInfo.nextItem != -1)
- itemNext[itemInfo.item->ItemNr] = itemInfo.nextItem;
- }
- else if (tagName == "MASTEROBJECT")
- {
- if (itemInfo.nextItem != -1)
- itemNextM[itemInfo.item->ItemNr] = itemInfo.nextItem;
- }
- /* not sure if we want that...
- else if (tagName == "FRAMEOBJECT")
- {
- if (itemInfo.nextItem != -1)
- itemNextF[itemInfo.item->ItemNr] = itemInfo.nextItem;
- }*/
-
- if (itemInfo.item->isTableItem)
- {
- if (tagName == "PAGEOBJECT")
- {
- TableItems.append(itemInfo.item);
- TableID.insert(itemInfo.ownLink, itemInfo.item->ItemNr);
- }
- else if (tagName == "FRAMEOBJECT")
- {
- TableItemsF.append(itemInfo.item);
- TableIDF.insert(itemInfo.ownLink, itemInfo.item->ItemNr);
- }
- else
- {
- TableItemsM.append(itemInfo.item);
- TableIDM.insert(itemInfo.ownLink, itemInfo.item->ItemNr);
- }
- }
- if (itemInfo.item->isGroupControl)
- {
- if (tagName == "PAGEOBJECT")
- groupID.insert(itemInfo.item, itemInfo.groupLastItem + itemInfo.item->ItemNr);
- else if (tagName == "FRAMEOBJECT")
- groupIDF.insert(itemInfo.item, itemInfo.groupLastItem + itemInfo.item->ItemNr);
- else
- groupIDM.insert(itemInfo.item, itemInfo.groupLastItem + itemInfo.item->ItemNr);
- }
- }
- if (tagName == "Pattern")
- {
- success = readPattern(m_Doc, reader, fileDir);
- if (!success) break;
- }
- }
-
- if (reader.hasError())
- return false;
-
- QMap<int, ScribusDoc::BookMa>::Iterator it;
- for (it = bookmarks.begin(); it != bookmarks.end(); ++it)
- {
- int elem = it.key();
- if (elem < m_Doc->Items->count())
- {
- ScribusDoc::BookMa bookmark = it.value();
- bookmark.PageObject = m_Doc->Items->at(elem);
- m_Doc->BookMarks.append( bookmark );
- }
- }
-
- if (TableItemsF.count() != 0)
- {
- for (int ttc = 0; ttc < TableItemsF.count(); ++ttc)
- {
- PageItem* ta = TableItemsF.at(ttc);
- if (ta->TopLinkID != -1)
- ta->TopLink = m_Doc->FrameItems.at(TableIDF[ta->TopLinkID]);
- else
- ta->TopLink = 0;
- if (ta->LeftLinkID != -1)
- ta->LeftLink = m_Doc->FrameItems.at(TableIDF[ta->LeftLinkID]);
- else
- ta->LeftLink = 0;
- if (ta->RightLinkID != -1)
- ta->RightLink = m_Doc->FrameItems.at(TableIDF[ta->RightLinkID]);
- else
- ta->RightLink = 0;
- if (ta->BottomLinkID != -1)
- ta->BottomLink = m_Doc->FrameItems.at(TableIDF[ta->BottomLinkID]);
- else
- ta->BottomLink = 0;
- }
- }
- if (TableItemsM.count() != 0)
- {
- for (int ttc = 0; ttc < TableItemsM.count(); ++ttc)
- {
- PageItem* ta = TableItemsM.at(ttc);
- if (ta->TopLinkID != -1)
- ta->TopLink = m_Doc->MasterItems.at(TableIDM[ta->TopLinkID]);
- else
- ta->TopLink = 0;
- if (ta->LeftLinkID != -1)
- ta->LeftLink = m_Doc->MasterItems.at(TableIDM[ta->LeftLinkID]);
- else
- ta->LeftLink = 0;
- if (ta->RightLinkID != -1)
- ta->RightLink = m_Doc->MasterItems.at(TableIDM[ta->RightLinkID]);
- else
- ta->RightLink = 0;
- if (ta->BottomLinkID != -1)
- ta->BottomLink = m_Doc->MasterItems.at(TableIDM[ta->BottomLinkID]);
- else
- ta->BottomLink = 0;
- }
- }
- if (TableItems.count() != 0)
- {
- for (int ttc = 0; ttc < TableItems.count(); ++ttc)
- {
- PageItem* ta = TableItems.at(ttc);
- if (ta->TopLinkID != -1)
- ta->TopLink = m_Doc->Items->at(TableID[ta->TopLinkID]);
- else
- ta->TopLink = 0;
- if (ta->LeftLinkID != -1)
- ta->LeftLink = m_Doc->Items->at(TableID[ta->LeftLinkID]);
- else
- ta->LeftLink = 0;
- if (ta->RightLinkID != -1)
- ta->RightLink = m_Doc->Items->at(TableID[ta->RightLinkID]);
- else
- ta->RightLink = 0;
- if (ta->BottomLinkID != -1)
- ta->BottomLink = m_Doc->Items->at(TableID[ta->BottomLinkID]);
- else
- ta->BottomLink = 0;
- }
- }
- if (groupIDF.count() != 0)
- {
- QMap<PageItem*, int>::Iterator it;
- for (it = groupIDF.begin(); it != groupIDF.end(); ++it)
- {
- it.key()->groupsLastItem = m_Doc->FrameItems.at(it.value());
- }
- }
- if (groupID.count() != 0)
- {
- QMap<PageItem*, int>::Iterator it;
- for (it = groupID.begin(); it != groupID.end(); ++it)
- {
- it.key()->groupsLastItem = m_Doc->DocItems.at(it.value());
- }
- }
- if (groupIDM.count() != 0)
- {
- QMap<PageItem*, int>::Iterator it;
- for (it = groupIDM.begin(); it != groupIDM.end(); ++it)
- {
- it.key()->groupsLastItem = m_Doc->MasterItems.at(it.value());
- }
- }
- //CB Add this in to set this in the file in memory. Its saved, why not load it.
- //Will of course be replaced by per page settings although we still probably need a document default
- if (!hasPageSets)
- {
- m_Doc->pageSets[m_Doc->currentPageLayout].FirstPage = firstPage;
-// m_Doc->pageSets[m_Doc->currentPageLayout].GapHorizontal = dc.attribute("GapHorizontal", "0").toDouble();
-// m_Doc->pageSets[m_Doc->currentPageLayout].GapVertical = 0.0;
-// m_Doc->pageSets[m_Doc->currentPageLayout].GapBelow = dc.attribute("GapVertical", "40").toDouble();
- }
- m_Doc->setActiveLayer(layerToSetActive);
- m_Doc->setMasterPageMode(false);
- m_Doc->reformPages();
-
- if (m_Doc->Layers.count() == 0)
- m_Doc->Layers.newLayer( QObject::tr("Background") );
-
- // reestablish textframe links
- if (itemNext.count() != 0)
- {
- QMap<int,int>::Iterator lc;
- for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
- {
- if (lc.value() >= 0)
- {
- PageItem * Its = m_Doc->DocItems.at(lc.key());
- PageItem * Itn = m_Doc->DocItems.at(lc.value());
- if (Itn->prevInChain() || Its->nextInChain())
- {
- qDebug() << "scribus150format: corruption in linked textframes detected";
- continue;
- }
- Its->link(Itn);
- }
- }
- }
-
- if (itemNextM.count() != 0)
- {
- QMap<int,int>::Iterator lc;
- for (lc = itemNextM.begin(); lc != itemNextM.end(); ++lc)
- {
- if (lc.value() >= 0)
- {
- PageItem * Its = m_Doc->MasterItems.at(lc.key());
- PageItem * Itn = m_Doc->MasterItems.at(lc.value());
- if (Itn->prevInChain() || Its->nextInChain())
- {
- qDebug() << "scribus150format: corruption in linked textframes detected";
- continue;
- }
- Its->link(Itn);
- }
- }
- }
-
- // reestablish first/lastAuto
- m_Doc->FirstAuto = m_Doc->LastAuto;
- if (m_Doc->LastAuto)
- {
- while (m_Doc->LastAuto->nextInChain())
- m_Doc->LastAuto = m_Doc->LastAuto->nextInChain();
- while (m_Doc->FirstAuto->prevInChain())
- m_Doc->FirstAuto = m_Doc->FirstAuto->prevInChain();
- }
-
- // start auto save timer if needed
- if (m_Doc->AutoSave && ScCore->usingGUI())
- m_Doc->autoSaveTimer->start(m_Doc->AutoSaveTime);
-
- if (m_mwProgressBar!=0)
- m_mwProgressBar->setValue(reader.characterOffset());
- return true;
-// return false;
-}
-
-// Low level plugin API
-int scribus150format_getPluginAPIVersion()
-{
- return PLUGIN_API_VERSION;
-}
-
-ScPlugin* scribus150format_getPlugin()
-{
- Scribus150Format* plug = new Scribus150Format();
- Q_CHECK_PTR(plug);
- return plug;
-}
-
-void scribus150format_freePlugin(ScPlugin* plugin)
-{
- Scribus150Format* plug = dynamic_cast<Scribus150Format*>(plugin);
- Q_ASSERT(plug);
- delete plug;
-}
-
-
-namespace {
- const int NOVALUE = -16000;
-
- void fixLegacyCharStyle(CharStyle& cstyle)
- {
- if (! cstyle.font().usable())
- cstyle.resetFont();
- if (cstyle.fontSize() <= -16000 / 10)
- cstyle.resetFontSize();
-// if (cstyle.effects() == 65535)
-// cstyle.resetEffects();
- if (cstyle.fillColor().isEmpty())
- cstyle.resetFillColor();
- if (cstyle.fillShade() <= -16000)
- cstyle.resetFillShade();
- if (cstyle.strokeColor().isEmpty())
- cstyle.resetStrokeColor();
- if (cstyle.strokeShade() <= -16000)
- cstyle.resetStrokeShade();
- if (cstyle.shadowXOffset() <= -16000 / 10)
- cstyle.resetShadowXOffset();
- if (cstyle.shadowYOffset() <= -16000 / 10)
- cstyle.resetShadowYOffset();
- if (cstyle.outlineWidth() <= -16000 / 10)
- cstyle.resetOutlineWidth();
- if (cstyle.underlineOffset() <= -16000 / 10)
- cstyle.resetUnderlineOffset();
- if (cstyle.underlineWidth() <= -16000 / 10)
- cstyle.resetUnderlineWidth();
- if (cstyle.strikethruOffset() <= -16000 / 10)
- cstyle.resetStrikethruOffset();
- if (cstyle.strikethruWidth() <= -16000 / 10)
- cstyle.resetStrikethruWidth();
- if (cstyle.scaleH() <= -16000 / 10)
- cstyle.resetScaleH();
- if (cstyle.scaleV() <= -16000 / 10)
- cstyle.resetScaleV();
- if (cstyle.baselineOffset() <= -16000 / 10)
- cstyle.resetBaselineOffset();
- if (cstyle.tracking() <= -16000 / 10)
- cstyle.resetTracking();
- }
-
- void fixLegacyParStyle(ParagraphStyle& pstyle)
- {
- if (pstyle.lineSpacing() <= -16000)
- pstyle.resetLineSpacing();
- if (pstyle.leftMargin() <= -16000)
- pstyle.resetLeftMargin();
- if (pstyle.rightMargin() <= -16000)
- pstyle.resetRightMargin();
- if (pstyle.firstIndent() <= -16000)
- pstyle.resetFirstIndent();
- if (pstyle.alignment() < 0)
- pstyle.resetAlignment();
- if (pstyle.gapBefore() <= -16000)
- pstyle.resetGapBefore();
- if (pstyle.gapAfter() <= -16000)
- pstyle.resetGapAfter();
- if (pstyle.dropCapLines() < 0)
- pstyle.resetDropCapLines();
- if (pstyle.dropCapOffset() <= -16000)
- pstyle.resetDropCapOffset();
- fixLegacyCharStyle(pstyle.charStyle());
- }
-
-}// namespace
-
-void Scribus150Format::readDocAttributes(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
-{
- m_Doc->m_pageSize = attrs.valueAsString("PAGESIZE");
- m_Doc->PageOri = attrs.valueAsInt("ORIENTATION", 0);
- m_Doc->FirstPnum = attrs.valueAsInt("FIRSTNUM", 1);
- m_Doc->currentPageLayout = attrs.valueAsInt("BOOK", 0);
-
- m_Doc->setUsesAutomaticTextFrames( attrs.valueAsInt("AUTOTEXT") );
- m_Doc->PageSp = attrs.valueAsInt("AUTOSPALTEN");
- m_Doc->PageSpa = attrs.valueAsDouble("ABSTSPALTEN");
- m_Doc->setUnitIndex( attrs.valueAsInt("UNITS", 0) );
-
- m_Doc->Language = attrs.valueAsString("LANGUAGE", "");
- m_Doc->MinWordLen = attrs.valueAsInt("MINWORDLEN", 3);
- m_Doc->HyCount = attrs.valueAsInt("HYCOUNT", 2);
-
- if (attrs.hasAttribute("PAGEWIDTH"))
- m_Doc->pageWidth = attrs.valueAsDouble("PAGEWIDTH");
- else
- m_Doc->pageWidth = attrs.valueAsDouble("PAGEWITH");
- m_Doc->pageHeight = attrs.valueAsDouble("PAGEHEIGHT");
- m_Doc->pageMargins.Left = qMax(0.0, attrs.valueAsDouble("BORDERLEFT"));
- m_Doc->pageMargins.Right = qMax(0.0, attrs.valueAsDouble("BORDERRIGHT"));
- m_Doc->pageMargins.Top = qMax(0.0, attrs.valueAsDouble("BORDERTOP"));
- m_Doc->pageMargins.Bottom= qMax(0.0, attrs.valueAsDouble("BORDERBOTTOM"));
- m_Doc->marginPreset = attrs.valueAsInt("PRESET", 0);
- m_Doc->bleeds.Top = attrs.valueAsDouble("BleedTop", 0.0);
- m_Doc->bleeds.Left = attrs.valueAsDouble("BleedLeft", 0.0);
- m_Doc->bleeds.Right = attrs.valueAsDouble("BleedRight", 0.0);
- m_Doc->bleeds.Bottom = attrs.valueAsDouble("BleedBottom", 0.0);
- m_Doc->Automatic = attrs.valueAsBool("AUTOMATIC", true);
- m_Doc->AutoCheck = attrs.valueAsBool("AUTOCHECK", false);
- m_Doc->GuideLock = attrs.valueAsBool("GUIDELOCK", false);
-
- m_Doc->rulerXoffset = attrs.valueAsDouble("rulerXoffset", 0.0);
- m_Doc->rulerYoffset = attrs.valueAsDouble("rulerYoffset", 0.0);
- m_Doc->SnapGuides = attrs.valueAsBool("SnapToGuides", false);
- m_Doc->useRaster = attrs.valueAsBool("SnapToGrid", false);
-
- m_Doc->AutoSave = attrs.valueAsBool("AutoSave", false);
- m_Doc->AutoSaveTime = attrs.valueAsInt("AutoSaveTime", 600000);
- m_Doc->scratch.Bottom = attrs.valueAsDouble("ScratchBottom", 20.0);
- // FIXME A typo in early 1.3cvs (MAR 05) means we must support loading of
- // FIXME 'ScatchLeft' for a while too. This can be removed in a few months.
- if (attrs.hasAttribute("ScatchLeft"))
- m_Doc->scratch.Left = attrs.valueAsDouble("ScatchLeft", 100.0);
- else
- m_Doc->scratch.Left = attrs.valueAsDouble("ScratchLeft", 100.0);
- m_Doc->scratch.Right = attrs.valueAsDouble("ScratchRight", 100.0);
- m_Doc->scratch.Top = attrs.valueAsDouble("ScratchTop", 20.0);
- m_Doc->GapHorizontal = attrs.valueAsDouble("GapHorizontal", -1.0);
- m_Doc->GapVertical = attrs.valueAsDouble("GapVertical", -1.0);
-
- if (attrs.hasAttribute("PAGEC"))
- m_Doc->papColor = QColor(attrs.valueAsString("PAGEC"));
-
- m_Doc->marginColored = attrs.valueAsBool("RANDF", false);
-
- readCMSSettings(doc, attrs);
- readDocumentInfo(doc, attrs);
- readGuideSettings(doc, attrs);
- readToolSettings(doc, attrs);
- readTypographicSettings(doc, attrs);
-}
-
-void Scribus150Format::readCMSSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
-{
- doc->CMSSettings.SoftProofOn = attrs.valueAsBool("DPSo", false);
- doc->CMSSettings.SoftProofFullOn = attrs.valueAsBool("DPSFo", false);
- doc->CMSSettings.CMSinUse = attrs.valueAsBool("DPuse", false);
- doc->CMSSettings.GamutCheck = attrs.valueAsBool("DPgam", false);
- doc->CMSSettings.BlackPoint = attrs.valueAsBool("DPbla", true);
- doc->CMSSettings.DefaultMonitorProfile = attrs.valueAsString("DPMo","");
- doc->CMSSettings.DefaultPrinterProfile = attrs.valueAsString("DPPr","");
- doc->CMSSettings.DefaultImageRGBProfile = attrs.valueAsString("DPIn","");
- doc->CMSSettings.DefaultImageCMYKProfile = attrs.valueAsString("DPInCMYK","");
- doc->CMSSettings.DefaultSolidColorRGBProfile = attrs.valueAsString("DPIn2","");
- if (attrs.hasAttribute("DPIn3"))
- doc->CMSSettings.DefaultSolidColorCMYKProfile = attrs.valueAsString("DPIn3","");
- else
- doc->CMSSettings.DefaultSolidColorCMYKProfile = attrs.valueAsString("DPPr","");
- doc->CMSSettings.DefaultIntentColors = attrs.valueAsInt("DISc", 1);
- doc->CMSSettings.DefaultIntentImages = attrs.valueAsInt("DIIm", 0);
-}
-
-void Scribus150Format::readDocumentInfo(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
-{
- doc->documentInfo.setAuthor(attrs.valueAsString("AUTHOR"));
- doc->documentInfo.setComments(attrs.valueAsString("COMMENTS"));
- doc->documentInfo.setKeywords(attrs.valueAsString("KEYWORDS",""));
- doc->documentInfo.setTitle(attrs.valueAsString("TITLE"));
- doc->documentInfo.setSubject(attrs.valueAsString("SUBJECT"));
- doc->documentInfo.setPublisher(attrs.valueAsString("PUBLISHER", ""));
- doc->documentInfo.setDate(attrs.valueAsString("DOCDATE", ""));
- doc->documentInfo.setType(attrs.valueAsString("DOCTYPE", ""));
- doc->documentInfo.setFormat(attrs.valueAsString("DOCFORMAT", ""));
- doc->documentInfo.setIdent(attrs.valueAsString("DOCIDENT", ""));
- doc->documentInfo.setSource(attrs.valueAsString("DOCSOURCE", ""));
- doc->documentInfo.setLangInfo(attrs.valueAsString("DOCLANGINFO", ""));
- doc->documentInfo.setRelation(attrs.valueAsString("DOCRELATION", ""));
- doc->documentInfo.setCover(attrs.valueAsString("DOCCOVER", ""));
- doc->documentInfo.setRights(attrs.valueAsString("DOCRIGHTS", ""));
- doc->documentInfo.setContrib(attrs.valueAsString("DOCCONTRIB", ""));
-}
-
-void Scribus150Format::readGuideSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
-{
- PrefsManager* prefsManager = PrefsManager::instance();
- doc->guidesSettings.minorGridSpacing = attrs.valueAsDouble("MINGRID", prefsManager->appPrefs.guidesPrefs.minorGridSpacing);
- doc->guidesSettings.majorGridSpacing = attrs.valueAsDouble("MAJGRID", prefsManager->appPrefs.guidesPrefs.majorGridSpacing);
- doc->guidesSettings.gridShown = attrs.valueAsBool("SHOWGRID", false);
- doc->guidesSettings.guidesShown =attrs.valueAsBool("SHOWGUIDES", true);
- doc->guidesSettings.colBordersShown = attrs.valueAsBool("showcolborders", false);
- doc->guidesSettings.framesShown = attrs.valueAsBool("SHOWFRAME", true);
- doc->guidesSettings.layerMarkersShown = attrs.valueAsBool("SHOWLAYERM", false);
- doc->guidesSettings.marginsShown = attrs.valueAsBool("SHOWMARGIN", true);
- doc->guidesSettings.baselineGridShown = attrs.valueAsBool("SHOWBASE", false);
- doc->guidesSettings.showPic = attrs.valueAsBool("SHOWPICT", true);
- doc->guidesSettings.linkShown = attrs.valueAsBool("SHOWLINK", false);
- doc->guidesSettings.showControls = attrs.valueAsBool("SHOWControl", false);
- doc->guidesSettings.rulerMode = attrs.valueAsBool("rulerMode", true);
- doc->guidesSettings.rulersShown = attrs.valueAsBool("showrulers", true);
- doc->guidesSettings.showBleed = attrs.valueAsBool("showBleed", true);
- if (attrs.hasAttribute("MARGC"))
- doc->guidesSettings.marginColor = QColor(attrs.valueAsString("MARGC"));
- if (attrs.hasAttribute("MINORC"))
- doc->guidesSettings.minorGridColor = QColor(attrs.valueAsString("MINORC"));
- if (attrs.hasAttribute("MAJORC"))
- doc->guidesSettings.majorGridColor = QColor(attrs.valueAsString("MAJORC"));
- if (attrs.hasAttribute("GuideC"))
- doc->guidesSettings.guideColor = QColor(attrs.valueAsString("GuideC"));
- if (attrs.hasAttribute("BaseC"))
- doc->guidesSettings.baselineGridColor = QColor(attrs.valueAsString("BaseC"));
- doc->guidesSettings.guidePlacement = attrs.valueAsBool("BACKG", true);
- doc->guidesSettings.guideRad = attrs.valueAsDouble("GuideRad", 10.0);
- doc->guidesSettings.grabRadius = attrs.valueAsInt("GRAB", 4);
-}
-
-void Scribus150Format::readToolSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
-{
- QString defFont = attrs.valueAsString("DFONT");
- m_AvailableFonts->findFont(defFont, doc);
-
- doc->toolSettings.defFont = defFont;
- doc->toolSettings.defSize = qRound(attrs.valueAsDouble("DSIZE", 12.0) * 10);
- doc->toolSettings.dCols = attrs.valueAsInt("DCOL", 1);
- doc->toolSettings.dGap = attrs.valueAsDouble("DGAP", 0.0);
-
- doc->toolSettings.polyC = attrs.valueAsInt("POLYC", 4);
- doc->toolSettings.polyF = attrs.valueAsDouble("POLYF", 0.5);
- doc->toolSettings.polyR = attrs.valueAsDouble("POLYR", 0.0);
- doc->toolSettings.polyCurvature = attrs.valueAsDouble("POLYCUR", 0.0);
- doc->toolSettings.polyFd = attrs.valueAsInt("POLYFD", 0);
- doc->toolSettings.polyS = attrs.valueAsBool("POLYS", false);
-
- doc->toolSettings.dStartArrow = attrs.valueAsInt("StartArrow", 0);
- doc->toolSettings.dEndArrow = attrs.valueAsInt("EndArrow", 0);
- doc->toolSettings.scaleX = attrs.valueAsDouble("PICTSCX", 1.0);
- doc->toolSettings.scaleY = attrs.valueAsDouble("PICTSCY", 1.0);
- doc->toolSettings.scaleType = attrs.valueAsBool("PSCALE", true);
- doc->toolSettings.aspectRatio = attrs.valueAsBool("PASPECT", false);
- doc->toolSettings.lowResType = attrs.valueAsInt("HalfRes", 1);
- doc->toolSettings.useEmbeddedPath = attrs.valueAsBool("EmbeddedPath", false);
- if (attrs.hasAttribute("PEN"))
- doc->toolSettings.dPen = attrs.valueAsString("PEN");
- if (attrs.hasAttribute("BRUSH"))
- doc->toolSettings.dBrush = attrs.valueAsString("BRUSH");
- if (attrs.hasAttribute("PENLINE"))
- doc->toolSettings.dPenLine = attrs.valueAsString("PENLINE");
- if (attrs.hasAttribute("PENTEXT"))
- doc->toolSettings.dPenText = attrs.valueAsString("PENTEXT");
- if (attrs.hasAttribute("StrokeText"))
- doc->toolSettings.dStrokeText = attrs.valueAsString("StrokeText");
- doc->toolSettings.dTextBackGround = attrs.valueAsString("TextBackGround", CommonStrings::None);
- doc->toolSettings.dTextLineColor = attrs.valueAsString("TextLineColor", CommonStrings::None);
- doc->toolSettings.dTextBackGroundShade =attrs.valueAsInt("TextBackGroundShade", 100);
- doc->toolSettings.dTextLineShade = attrs.valueAsInt("TextLineShade", 100);
- doc->toolSettings.dTextPenShade = attrs.valueAsInt("TextPenShade", 100);
- doc->toolSettings.dTextStrokeShade = attrs.valueAsInt("TextStrokeShade", 100);
- doc->toolSettings.dLineArt = static_cast<Qt::PenStyle>(attrs.valueAsInt("STIL"));
- doc->toolSettings.dLstyleLine = static_cast<Qt::PenStyle>(attrs.valueAsInt("STILLINE"));
- doc->toolSettings.dWidth = attrs.valueAsDouble("WIDTH", 0.0);
- doc->toolSettings.dWidthLine = attrs.valueAsDouble("WIDTHLINE", 1.0);
- doc->toolSettings.dShade2 = attrs.valueAsInt("PENSHADE", 100);
- doc->toolSettings.dShadeLine = attrs.valueAsInt("LINESHADE", 100);
- doc->toolSettings.dShade = attrs.valueAsInt("BRUSHSHADE", 100);
- doc->toolSettings.magMin = attrs.valueAsInt("MAGMIN", 10);
- doc->toolSettings.magMax = attrs.valueAsInt("MAGMAX", 3200);
- doc->toolSettings.magStep = attrs.valueAsInt("MAGSTEP", 200);
- doc->toolSettings.dispX = attrs.valueAsDouble("dispX", 10.0);
- doc->toolSettings.dispY = attrs.valueAsDouble("dispY", 10.0);
- doc->toolSettings.constrain = attrs.valueAsDouble("constrain", 15.0);
- //CB Reset doc zoom step value to 200% instead of old values.
- if (doc->toolSettings.magStep < 100)
- doc->toolSettings.magStep = 200;
- doc->toolSettings.tabFillChar = attrs.valueAsString("TabFill","");
- doc->toolSettings.dTabWidth = attrs.valueAsDouble("TabWidth", 36.0);
- if (attrs.hasAttribute("CPICT"))
- doc->toolSettings.dBrushPict = attrs.valueAsString("CPICT");
- doc->toolSettings.shadePict = attrs.valueAsInt("PICTSHADE", 100);
-}
-
-void Scribus150Format::readTypographicSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
-{
- doc->typographicSettings.valueSuperScript = attrs.valueAsInt("VHOCH");
- doc->typographicSettings.scalingSuperScript = attrs.valueAsInt("VHOCHSC");
- doc->typographicSettings.valueSubScript = attrs.valueAsInt("VTIEF");
- doc->typographicSettings.scalingSubScript = attrs.valueAsInt("VTIEFSC");
- doc->typographicSettings.valueSmallCaps = attrs.valueAsInt("VKAPIT");
- doc->guidesSettings.valueBaselineGrid = attrs.valueAsDouble("BASEGRID", 12.0);
- doc->guidesSettings.offsetBaselineGrid = attrs.valueAsDouble("BASEO", 0.0);
- doc->typographicSettings.autoLineSpacing = attrs.valueAsInt("AUTOL", 20);
- doc->typographicSettings.valueUnderlinePos = attrs.valueAsInt("UnderlinePos", -1);
- doc->typographicSettings.valueUnderlineWidth = attrs.valueAsInt("UnderlineWidth", -1);
- doc->typographicSettings.valueStrikeThruPos = attrs.valueAsInt("StrikeThruPos", -1);
- doc->typographicSettings.valueStrikeThruWidth = attrs.valueAsInt("StrikeThruWidth", -1);
-}
-
-bool Scribus150Format::readPageSets(ScribusDoc* doc, ScXmlStreamReader& reader)
-{
- struct PageSet pageS;
- ScXmlStreamAttributes attrs;
-
- doc->pageSets.clear();
- while(!reader.atEnd() && !reader.hasError())
- {
- reader.readNext();
- QStringRef tagName = reader.name();
- if(reader.isStartElement())
- attrs = reader.attributes();
- if (reader.isEndElement() && tagName == "PageSets")
- break;
- if(reader.isStartElement() && tagName == "Set")
- {
- ScXmlStreamAttributes attrs = reader.scAttributes();
- pageS.Name = CommonStrings::untranslatePageSetString(attrs.valueAsString("Name"));
- pageS.FirstPage = attrs.valueAsInt("FirstPage", 0);
- pageS.Rows = attrs.valueAsInt("Rows", 1);
- pageS.Columns = attrs.valueAsInt("Columns", 1);
-// pageS.GapHorizontal = attrs.valueAsDouble("GapHorizontal", 0);
-// pageS.GapVertical = attrs.valueAsDouble("GapVertical", 0);
-// pageS.GapBelow = attrs.valueAsDouble("GapBelow", 0);
- pageS.pageNames.clear();
- }
- if(reader.isEndElement() && tagName == "Set")
- {
- doc->pageSets.append(pageS);
- if ((doc->pageSets.count()-1 == doc->currentPageLayout) && ((doc->GapHorizontal < 0) && (doc->GapVertical < 0)))
- {
- doc->GapHorizontal = attrs.valueAsDouble("GapHorizontal", 0.0);
- doc->GapVertical = attrs.valueAsDouble("GapBelow", 0.0);
- }
- }
- if (reader.isStartElement() && tagName == "PageNames")
- pageS.pageNames.append(CommonStrings::untranslatePageSetLocString(attrs.valueAsString("Name")));
- }
- return !reader.hasError();
-}
-
-bool Scribus150Format::readCheckProfile(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
-{
- struct CheckerPrefs checkerSettings;
- QString profileName = attrs.valueAsString("Name");
- if (profileName.isEmpty())
- return true;
- checkerSettings.ignoreErrors = attrs.valueAsBool("ignoreErrors", false);
- checkerSettings.autoCheck = attrs.valueAsBool("autoCheck", true);
- checkerSettings.checkGlyphs = attrs.valueAsBool("checkGlyphs", true);
- checkerSettings.checkOrphans = attrs.valueAsBool("checkOrphans", true);
- checkerSettings.checkOverflow = attrs.valueAsBool("checkOverflow", true);
- checkerSettings.checkPictures = attrs.valueAsBool("checkPictures", true);
- checkerSettings.checkResolution = attrs.valueAsBool("checkResolution", true);
- checkerSettings.checkTransparency = attrs.valueAsBool("checkTransparency", true);
- checkerSettings.minResolution = attrs.valueAsDouble("minResolution", 72.0);
- checkerSettings.maxResolution = attrs.valueAsDouble("maxResolution", 4800.0);
- checkerSettings.checkAnnotations = attrs.valueAsBool("checkAnnotations", false);
- checkerSettings.checkRasterPDF = attrs.valueAsBool("checkRasterPDF", true);
- checkerSettings.checkForGIF = attrs.valueAsBool("checkForGIF", true);
- checkerSettings.ignoreOffLayers = attrs.valueAsBool("ignoreOffLayers", false);
- doc->checkerProfiles[profileName] = checkerSettings;
- return true;
-}
-
-bool Scribus150Format::readColor(ColorList& colors, ScXmlStreamAttributes& attrs)
-{
- ScColor color;
- if (attrs.hasAttribute("CMYK"))
- color.setNamedColor(attrs.valueAsString("CMYK"));
- else
- color.fromQColor(QColor(attrs.valueAsString("RGB")));
- color.setSpotColor( attrs.valueAsBool("Spot", false) );
- color.setRegistrationColor( attrs.valueAsBool("Register", false) );
- QString name = attrs.valueAsString("NAME");
- colors.insert((name.isEmpty()) ? color.name() : name, color);
- return true;
-}
-
-void Scribus150Format::readCharacterStyleAttrs(ScribusDoc *doc, ScXmlStreamAttributes& attrs, CharStyle & newStyle)
-{
- static const QString CNAME("CNAME");
- if (attrs.hasAttribute(CNAME))
- newStyle.setName(attrs.valueAsString(CNAME));
-
- // The default style attribute must be correctly set before trying to assign a parent
- static const QString DEFAULTSTYLE("DefaultStyle");
- if (newStyle.hasName() && attrs.hasAttribute(DEFAULTSTYLE))
- newStyle.setDefaultStyle(attrs.valueAsInt(DEFAULTSTYLE));
- else if (newStyle.name() == CommonStrings::DefaultCharacterStyle || newStyle.name() == CommonStrings::trDefaultCharacterStyle)
- newStyle.setDefaultStyle(true);
- else
- newStyle.setDefaultStyle(false);
-
- static const QString CPARENT("CPARENT");
- if (attrs.hasAttribute(CPARENT))
- newStyle.setParent(attrs.valueAsString(CPARENT));
-
- static const QString FONT("FONT");
- if (attrs.hasAttribute(FONT))
- newStyle.setFont(m_AvailableFonts->findFont(attrs.valueAsString(FONT), doc));
-
- static const QString FONTSIZE("FONTSIZE");
- if (attrs.hasAttribute(FONTSIZE))
- newStyle.setFontSize(qRound(attrs.valueAsDouble(FONTSIZE) * 10));
-
- static const QString FCOLOR("FCOLOR");
- if (attrs.hasAttribute(FCOLOR))
- newStyle.setFillColor(attrs.valueAsString(FCOLOR));
-
- static const QString KERN("KERN");
- if (attrs.hasAttribute(KERN))
- newStyle.setTracking(qRound(attrs.valueAsDouble(KERN) * 10));
-
- static const QString FSHADE("FSHADE");
- if (attrs.hasAttribute(FSHADE))
- newStyle.setFillShade(attrs.valueAsInt(FSHADE));
-
- static const QString EFFECTS("EFFECTS");
- if (attrs.hasAttribute(EFFECTS))
- newStyle.setFeatures(static_cast<StyleFlag>(attrs.valueAsInt(EFFECTS)).featureList());
-
- static const QString EFFECT("EFFECT");
- if (attrs.hasAttribute(EFFECT))
- newStyle.setFeatures(static_cast<StyleFlag>(attrs.valueAsInt(EFFECT)).featureList());
-
- static const QString FEATURES("FEATURES");
- if (attrs.hasAttribute(FEATURES))
- newStyle.setFeatures(attrs.valueAsString(FEATURES).split( " ", QString::SkipEmptyParts));
-
- static const QString SCOLOR("SCOLOR");
- if (attrs.hasAttribute(SCOLOR))
- newStyle.setStrokeColor(attrs.valueAsString(SCOLOR, CommonStrings::None));
-
- static const QString SSHADE("SSHADE");
- if (attrs.hasAttribute(SSHADE))
- newStyle.setStrokeShade(attrs.valueAsInt(SSHADE));
-
- static const QString SCALEH("SCALEH");
- if (attrs.hasAttribute(SCALEH))
- newStyle.setScaleH(qRound(attrs.valueAsDouble(SCALEH) * 10));
-
- static const QString SCALEV("SCALEV");
- if (attrs.hasAttribute(SCALEV))
- newStyle.setScaleV(qRound(attrs.valueAsDouble(SCALEV) * 10));
-
- static const QString BASEO("BASEO");
- if (attrs.hasAttribute(BASEO))
- newStyle.setBaselineOffset(qRound(attrs.valueAsDouble(BASEO) * 10));
-
- static const QString TXTSHX("TXTSHX");
- if (attrs.hasAttribute(TXTSHX))
- newStyle.setShadowXOffset(qRound(attrs.valueAsDouble(TXTSHX) * 10));
-
- static const QString TXTSHY("TXTSHY");
- if (attrs.hasAttribute(TXTSHY))
- newStyle.setShadowYOffset(qRound(attrs.valueAsDouble(TXTSHY) * 10));
-
- static const QString TXTOUT("TXTOUT");
- if (attrs.hasAttribute(TXTOUT))
- newStyle.setOutlineWidth(qRound(attrs.valueAsDouble(TXTOUT) * 10));
-
- static const QString TXTULP("TXTULP");
- if (attrs.hasAttribute(TXTULP))
- newStyle.setUnderlineOffset(qRound(attrs.valueAsDouble(TXTULP) * 10));
-
- static const QString TXTULW("TXTULW");
- if (attrs.hasAttribute(TXTULW))
- newStyle.setUnderlineWidth(qRound(attrs.valueAsDouble(TXTULW) * 10));
-
- static const QString TXTSTP("TXTSTP");
- if (attrs.hasAttribute(TXTSTP))
- newStyle.setStrikethruOffset(qRound(attrs.valueAsDouble(TXTSTP) * 10));
-
- static const QString TXTSTW("TXTSTW");
- if (attrs.hasAttribute(TXTSTW))
- newStyle.setStrikethruWidth(qRound(attrs.valueAsDouble(TXTSTW) * 10));
-
- static const QString SHORTCUT("SHORTCUT");
- if (attrs.hasAttribute(SHORTCUT))
- newStyle.setShortcut(attrs.valueAsString(SHORTCUT));
-
- static const QString WORDTRACK("wordTrack");
- if (attrs.hasAttribute(WORDTRACK))
- newStyle.setWordTracking(attrs.valueAsDouble(WORDTRACK));
-}
-
-void Scribus150Format::readParagraphStyle(ScribusDoc *doc, ScXmlStreamReader& reader, ParagraphStyle& newStyle, SCFonts &fonts)
-{
- ScXmlStreamAttributes attrs = reader.scAttributes();
-
- newStyle.erase();
- newStyle.setName(attrs.valueAsString("NAME", ""));
- // The default style attribute must be correctly set before trying to assign a parent
- static const QString DEFAULTSTYLE("DefaultStyle");
- if (attrs.hasAttribute(DEFAULTSTYLE))
- newStyle.setDefaultStyle(attrs.valueAsInt(DEFAULTSTYLE));
- else if (newStyle.name() == CommonStrings::DefaultParagraphStyle || newStyle.name() == CommonStrings::trDefaultParagraphStyle)
- newStyle.setDefaultStyle(true);
- else
- newStyle.setDefaultStyle(false);
- newStyle.setParent(attrs.valueAsString("PARENT", ""));
-
- static const QString LINESPMode("LINESPMode");
- if (attrs.hasAttribute(LINESPMode))
- newStyle.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(attrs.valueAsInt(LINESPMode)));
-
- static const QString LINESP("LINESP");
- if (attrs.hasAttribute(LINESP))
- newStyle.setLineSpacing(attrs.valueAsDouble(LINESP));
-
- static const QString INDENT("INDENT");
- if (attrs.hasAttribute(INDENT))
- newStyle.setLeftMargin(attrs.valueAsDouble(INDENT));
-
- static const QString RMARGIN("RMARGIN");
- if (attrs.hasAttribute(RMARGIN))
- newStyle.setRightMargin(attrs.valueAsDouble(RMARGIN));
-
- static const QString FIRST("FIRST");
- if (attrs.hasAttribute(FIRST))
- newStyle.setFirstIndent(attrs.valueAsDouble(FIRST));
-
- static const QString ALIGN("ALIGN");
- if (attrs.hasAttribute(ALIGN))
- newStyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(attrs.valueAsInt(ALIGN)));
-
- static const QString VOR("VOR");
- if (attrs.hasAttribute(VOR))
- newStyle.setGapBefore(attrs.valueAsDouble(VOR));
-
- static const QString NACH("NACH");
- if (attrs.hasAttribute(NACH))
- newStyle.setGapAfter(attrs.valueAsDouble(NACH));
-
- static const QString DROP("DROP");
- if (attrs.hasAttribute(DROP))
- newStyle.setHasDropCap(static_cast<bool>(attrs.valueAsInt(DROP)));
-
- static const QString DROPLIN("DROPLIN");
- if (attrs.hasAttribute(DROPLIN))
- newStyle.setDropCapLines(attrs.valueAsInt(DROPLIN));
-
- static const QString DROPDIST("DROPDIST");
- if (attrs.hasAttribute(DROPDIST))
- newStyle.setDropCapOffset(attrs.valueAsDouble(DROPDIST));
-
- static const QString PSHORTCUT("PSHORTCUT");
- if (attrs.hasAttribute(PSHORTCUT))
- newStyle.setShortcut(attrs.valueAsString(PSHORTCUT));
-
- static const QString OpticalMargins("OpticalMargins");
- if (attrs.hasAttribute(OpticalMargins))
- newStyle.setOpticalMargins(attrs.valueAsInt(OpticalMargins));
-
- static const QString HyphenationMode("HyphenationMode");
- if (attrs.hasAttribute(HyphenationMode))
- newStyle.setHyphenationMode(attrs.valueAsInt(HyphenationMode));
-
- static const QString MinWordTrack("MinWordTrack");
- if (attrs.hasAttribute(MinWordTrack))
- newStyle.setMinWordTracking(attrs.valueAsDouble(MinWordTrack));
-
- static const QString NormWordTrack("NormWordTrack");
- if (attrs.hasAttribute(NormWordTrack))
- newStyle.charStyle().setWordTracking(attrs.valueAsDouble(NormWordTrack));
-
- static const QString MinGlyphShrink("MinGlyphShrink");
- if (attrs.hasAttribute(MinGlyphShrink))
- newStyle.setMinGlyphExtension(attrs.valueAsDouble(MinGlyphShrink));
-
- static const QString MaxGlyphExtend("MaxGlyphExtend");
- if (attrs.hasAttribute(MaxGlyphExtend))
- newStyle.setMaxGlyphExtension(attrs.valueAsDouble(MaxGlyphExtend));
-
- readCharacterStyleAttrs( doc, attrs, newStyle.charStyle());
-
- // newStyle.tabValues().clear();
- QList<ParagraphStyle::TabRecord> tbs;
- newStyle.resetTabValues();
- QStringRef thisTagName = reader.name();
- while (!reader.atEnd() && !reader.hasError())
- {
- reader.readNext();
- if (reader.isEndElement() && reader.name() == thisTagName)
- break;
- if (reader.isStartElement() && reader.name() == "Tabs")
- {
- ParagraphStyle::TabRecord tb;
- ScXmlStreamAttributes attrs2 = reader.scAttributes();
- tb.tabPosition = attrs2.valueAsDouble("Pos");
- tb.tabType = attrs2.valueAsInt("Type");
- QString tbCh = attrs2.valueAsString("Fill","");
- tb.tabFillChar = tbCh.isEmpty() ? QChar() : tbCh[0];
- tbs.append(tb);
- }
- }
- if (tbs.count() > 0)
- newStyle.setTabValues(tbs);
-
- fixLegacyParStyle(newStyle);
-}
-
-void Scribus150Format::readLayers(ScLayer& layer, ScXmlStreamAttributes& attrs)
-{
- int lId = attrs.valueAsInt("NUMMER");
- int level = attrs.valueAsInt("LEVEL");
- layer = ScLayer( attrs.valueAsString("NAME"), level, lId);
- layer.isViewable = attrs.valueAsInt("SICHTBAR");
- layer.isPrintable = attrs.valueAsInt("DRUCKEN");
- layer.isEditable = attrs.valueAsInt("EDIT", 1);
- layer.flowControl = attrs.valueAsInt("FLOW", 1);
- layer.transparency = attrs.valueAsDouble("TRANS", 1.0);
- layer.blendMode = attrs.valueAsInt("BLEND", 0);
- layer.outlineMode = attrs.valueAsInt("OUTL", 0);
- if (attrs.hasAttribute("LAYERC"))
- layer.markerColor = QColor(attrs.valueAsString("LAYERC","#000000"));
-}
-
-bool Scribus150Format::readArrows(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
-{
- double xa, ya;
- struct ArrowDesc arrow;
- arrow.name = attrs.valueAsString("Name");
- arrow.userArrow = true;
- QString tmp = attrs.valueAsString("Points");
- ScTextStream fp(&tmp, QIODevice::ReadOnly);
- unsigned int numPoints = attrs.valueAsUInt("NumPoints");
- for (uint cx = 0; cx < numPoints; ++cx)
- {
- fp >> xa;
- fp >> ya;
- arrow.points.addPoint(xa, ya);
- }
- doc->arrowStyles.append(arrow);
- return true;
-}
-
-bool Scribus150Format::readMultiline(multiLine& ml, ScXmlStreamReader& reader)
-{
- ml = multiLine();
- ScXmlStreamAttributes rattrs = reader.scAttributes();
- QStringRef tagName = reader.name();
- while(!reader.atEnd() && !reader.hasError())
- {
- ScXmlStreamReader::TokenType tType = reader.readNext();
- if (tType == ScXmlStreamReader::EndElement && reader.name() == tagName)
- break;
- if (tType == ScXmlStreamReader::StartElement && reader.name() == "SubLine")
- {
- struct SingleLine sl;
- ScXmlStreamAttributes attrs = reader.scAttributes();
- sl.Color = attrs.valueAsString("Color");
- sl.Dash = attrs.valueAsInt("Dash");
- sl.LineEnd = attrs.valueAsInt("LineEnd");
- sl.LineJoin = attrs.valueAsInt("LineJoin");
- sl.Shade = attrs.valueAsInt("Shade");
- sl.Width = attrs.valueAsDouble("Width");
- ml.shortcut = attrs.valueAsString("Shortcut");
- ml.push_back(sl);
- }
- }
- return !reader.hasError();
-}
-
-bool Scribus150Format::readBookMark(ScribusDoc::BookMa& bookmark, int& elem, ScXmlStreamAttributes& attrs)
-{
- elem = attrs.valueAsInt("Element");
- bookmark.PageObject = NULL;
- bookmark.Title = attrs.valueAsString("Title");
- bookmark.Text = attrs.valueAsString("Text");
- bookmark.Aktion = attrs.valueAsString("Aktion");
- bookmark.ItemNr = attrs.valueAsInt("ItemNr");
- bookmark.First = attrs.valueAsInt("First");
- bookmark.Last = attrs.valueAsInt("Last");
- bookmark.Prev = attrs.valueAsInt("Prev");
- bookmark.Next = attrs.valueAsInt("Next");
- bookmark.Parent = attrs.valueAsInt("Parent");
- return true;
-}
-
-bool Scribus150Format::readPDFOptions(ScribusDoc* doc, ScXmlStreamReader& reader)
-{
- ScXmlStreamAttributes attrs = reader.scAttributes();
-
- doc->PDF_Options.firstUse = attrs.valueAsBool("firstUse", true);
- doc->PDF_Options.Articles = attrs.valueAsBool("Articles");
- doc->PDF_Options.Thumbnails = attrs.valueAsBool("Thumbnails");
- doc->PDF_Options.Compress = attrs.valueAsBool("Compress");
- doc->PDF_Options.CompressMethod = (PDFOptions::PDFCompression)attrs.valueAsInt("CMethod", 0);
- doc->PDF_Options.Quality = attrs.valueAsInt("Quality", 0);
- doc->PDF_Options.RecalcPic = attrs.valueAsBool("RecalcPic");
- doc->PDF_Options.Bookmarks = attrs.valueAsBool("Bookmarks");
- doc->PDF_Options.MirrorH = attrs.valueAsBool("MirrorH", false);
- doc->PDF_Options.MirrorV = attrs.valueAsBool("MirrorV", false);
- doc->PDF_Options.RotateDeg = attrs.valueAsInt("RotateDeg", 0);
- doc->PDF_Options.doClip = attrs.valueAsBool("Clip", false);
- doc->PDF_Options.PresentMode = attrs.valueAsBool("PresentMode");
- doc->PDF_Options.PicRes = attrs.valueAsInt("PicRes");
- // Fixme: check input pdf version
- doc->PDF_Options.Version = (PDFOptions::PDFVersion) attrs.valueAsInt("Version");
- doc->PDF_Options.Resolution = attrs.valueAsInt("Resolution");
- doc->PDF_Options.Binding = attrs.valueAsInt("Binding");
- doc->PDF_Options.fileName = "";
- doc->PDF_Options.isGrayscale = attrs.valueAsBool("Grayscale", false);
- doc->PDF_Options.UseRGB = attrs.valueAsBool("RGBMode", false);
- doc->PDF_Options.UseProfiles = attrs.valueAsBool("UseProfiles", false);
- doc->PDF_Options.UseProfiles2 = attrs.valueAsBool("UseProfiles2", false);
- doc->PDF_Options.Intent = attrs.valueAsInt("Intent", 1);
- doc->PDF_Options.Intent2 = attrs.valueAsInt("Intent2", 1);
- doc->PDF_Options.SolidProf = attrs.valueAsString("SolidP", "");
- doc->PDF_Options.ImageProf = attrs.valueAsString("ImageP", "");
- doc->PDF_Options.PrintProf = attrs.valueAsString("PrintP", "");
- doc->PDF_Options.Info = attrs.valueAsString("InfoString", "");
- doc->PDF_Options.bleeds.Top = attrs.valueAsDouble("BTop", 0.0);
- doc->PDF_Options.bleeds.Left = attrs.valueAsDouble("BLeft", 0.0);
- doc->PDF_Options.bleeds.Right = attrs.valueAsDouble("BRight", 0.0);
- doc->PDF_Options.bleeds.Bottom = attrs.valueAsDouble("BBottom", 0.0);
- doc->PDF_Options.useDocBleeds = attrs.valueAsBool("useDocBleeds", true);
- doc->PDF_Options.cropMarks = attrs.valueAsBool("cropMarks", false);
- doc->PDF_Options.bleedMarks = attrs.valueAsBool("bleedMarks", false);
- doc->PDF_Options.registrationMarks = attrs.valueAsBool("registrationMarks", false);
- doc->PDF_Options.colorMarks = attrs.valueAsBool("colorMarks", false);
- doc->PDF_Options.docInfoMarks = attrs.valueAsBool("docInfoMarks", false);
- doc->PDF_Options.markOffset = attrs.valueAsDouble("markOffset", 0.0);
- doc->PDF_Options.EmbeddedI = attrs.valueAsBool("ImagePr", false);
- doc->PDF_Options.PassOwner = attrs.valueAsString("PassOwner", "");
- doc->PDF_Options.PassUser = attrs.valueAsString("PassUser", "");
- doc->PDF_Options.Permissions = attrs.valueAsInt("Permissions", -4);
- doc->PDF_Options.Encrypt = attrs.valueAsBool("Encrypt", false);
- doc->PDF_Options.useLayers = attrs.valueAsBool("UseLayers", false);
- doc->PDF_Options.UseLPI = attrs.valueAsBool("UseLpi", false);
- doc->PDF_Options.UseSpotColors = attrs.valueAsBool("UseSpotColors", true);
- doc->PDF_Options.doMultiFile = attrs.valueAsBool("doMultiFile", false);
- doc->PDF_Options.displayBookmarks = attrs.valueAsBool("displayBookmarks", false);
- doc->PDF_Options.displayFullscreen = attrs.valueAsBool("displayFullscreen", false);
- doc->PDF_Options.displayLayers = attrs.valueAsBool("displayLayers", false);
- doc->PDF_Options.displayThumbs = attrs.valueAsBool("displayThumbs", false);
- doc->PDF_Options.hideMenuBar = attrs.valueAsBool("hideMenuBar", false);
- doc->PDF_Options.hideToolBar = attrs.valueAsBool("hideToolBar", false);
- doc->PDF_Options.fitWindow = attrs.valueAsBool("fitWindow", false);
- doc->PDF_Options.PageLayout = attrs.valueAsInt("PageLayout", 0);
- doc->PDF_Options.openAction = attrs.valueAsString("openAction", "");
-
- QStringRef tagName = reader.name();
- while(!reader.atEnd() && !reader.hasError())
- {
- reader.readNext();
- if (reader.isEndElement() && (reader.name() == tagName))
- break;
- if (!reader.isStartElement())
- continue;
- QStringRef tName = reader.name();
- attrs = reader.scAttributes();
- if(tName == "LPI")
- {
- struct LPIData lpo;
- lpo.Angle = attrs.valueAsInt("Angle");
- lpo.Frequency = attrs.valueAsInt("Frequency");
- lpo.SpotFunc = attrs.valueAsInt("SpotFunction");
- doc->PDF_Options.LPISettings[attrs.valueAsString("Color")] = lpo;
- }
- if(tName == "Fonts")
- {
- QString fname = attrs.valueAsString("Name");
- if (!doc->PDF_Options.EmbedList.contains(fname))
- doc->PDF_Options.EmbedList.append(fname);
- }
- if(tName == "Subset")
- {
- QString sname = attrs.valueAsString("Name");
- if (!doc->PDF_Options.SubsetList.contains(sname))
- doc->PDF_Options.SubsetList.append(sname);
- }
- if(tName == "Effekte")
- {
- struct PDFPresentationData ef;
- ef.pageEffectDuration = attrs.valueAsInt("pageEffectDuration");
- ef.pageViewDuration = attrs.valueAsInt("pageViewDuration");
- ef.effectType = attrs.valueAsInt("effectType");
- ef.Dm = attrs.valueAsInt("Dm");
- ef.M = attrs.valueAsInt("M");
- ef.Di = attrs.valueAsInt("Di");
- doc->PDF_Options.PresentVals.append(ef);
- }
- }
- return !reader.hasError();
-}
-
-bool Scribus150Format::readPrinterOptions(ScribusDoc* doc, ScXmlStreamReader& reader)
-{
- ScXmlStreamAttributes attrs = reader.scAttributes();
- doc->Print_Options.firstUse = attrs.valueAsBool("firstUse");
- doc->Print_Options.toFile = attrs.valueAsBool("toFile");
- doc->Print_Options.useAltPrintCommand = attrs.valueAsBool("useAltPrintCommand");
- doc->Print_Options.outputSeparations = attrs.valueAsBool("outputSeparations");
- doc->Print_Options.useSpotColors = attrs.valueAsBool("useSpotColors");
- doc->Print_Options.useColor = attrs.valueAsBool("useColor");
- doc->Print_Options.mirrorH = attrs.valueAsBool("mirrorH");
- doc->Print_Options.mirrorV = attrs.valueAsBool("mirrorV");
- doc->Print_Options.useICC = attrs.valueAsBool("useICC");
- doc->Print_Options.doGCR = attrs.valueAsBool("doGCR");
- doc->Print_Options.doClip = attrs.valueAsBool("doClip");
- doc->Print_Options.setDevParam = attrs.valueAsBool("setDevParam");
- doc->Print_Options.useDocBleeds = attrs.valueAsBool("useDocBleeds");
- doc->Print_Options.cropMarks = attrs.valueAsBool("cropMarks");
- doc->Print_Options.bleedMarks = attrs.valueAsBool("bleedMarks");
- doc->Print_Options.registrationMarks = attrs.valueAsBool("registrationMarks");
- doc->Print_Options.colorMarks = attrs.valueAsBool("colorMarks");
- doc->Print_Options.includePDFMarks = attrs.valueAsBool("includePDFMarks", "1");
- if (attrs.hasAttribute("PrintEngine"))
- doc->Print_Options.prnEngine = (PrintEngine) attrs.valueAsInt("PrintEngine", 3);
- else
- doc->Print_Options.prnEngine = (PrintEngine) attrs.valueAsInt("PSLevel", 3);
- doc->Print_Options.markOffset = attrs.valueAsDouble("markOffset");
- doc->Print_Options.bleeds.Top = attrs.valueAsDouble("BleedTop");
- doc->Print_Options.bleeds.Left = attrs.valueAsDouble("BleedLeft");
- doc->Print_Options.bleeds.Right = attrs.valueAsDouble("BleedRight");
- doc->Print_Options.bleeds.Bottom = attrs.valueAsDouble("BleedBottom");
- doc->Print_Options.printer = attrs.valueAsString("printer");
- doc->Print_Options.filename = attrs.valueAsString("filename");
- doc->Print_Options.separationName = attrs.valueAsString("separationName");
- doc->Print_Options.printerCommand = attrs.valueAsString("printerCommand");
- doc->Print_Options.copies = 1;
-
- QStringRef tagName = reader.name();
- while(!reader.atEnd() && !reader.hasError())
- {
- ScXmlStreamReader::TokenType tType = reader.readNext();
- QStringRef tName = reader.name();
- if (tType == ScXmlStreamReader::StartElement && tName == "Separation")
- doc->Print_Options.allSeparations.append(reader.attributes().value("Name").toString());
- if (tType == ScXmlStreamReader::EndElement && tName == tagName)
- break;
- }
- return !reader.hasError();
-}
-
-bool Scribus150Format::readDocItemAttributes(ScribusDoc *doc, ScXmlStreamReader& reader)
-{
- QStringRef tagName = reader.name();
- doc->docItemAttributes.clear();
- while(!reader.atEnd() && !reader.hasError())
- {
- reader.readNext();
- if (reader.isEndElement() && reader.name() == tagName)
- break;
- if(reader.isStartElement() && reader.name() == "ItemAttribute")
- {
- ScXmlStreamAttributes attrs = reader.scAttributes();
- ObjectAttribute objattr;
- objattr.name = attrs.valueAsString("Name");
- objattr.type = attrs.valueAsString("Type");
- objattr.value = attrs.valueAsString("Value");
- objattr.parameter = attrs.valueAsString("Parameter");
- objattr.relationship = attrs.valueAsString("Relationship");
- objattr.relationshipto = attrs.valueAsString("RelationshipTo");
- objattr.autoaddto = attrs.valueAsString("AutoAddTo");
- doc->docItemAttributes.append(objattr);
- }
- }
- return !reader.hasError();
-}
-
-bool Scribus150Format::readTableOfContents(ScribusDoc* doc, ScXmlStreamReader& reader)
-{
- QStringRef tagName = reader.name();
- m_Doc->docToCSetups.clear();
- while(!reader.atEnd() && !reader.hasError())
- {
- reader.readNext();
- if (reader.isEndElement() && reader.name() == tagName)
- break;
- if(reader.isStartElement() && reader.name() == "TableOfContents")
- {
- ScXmlStreamAttributes attrs = reader.scAttributes();
- ToCSetup tocsetup;
- tocsetup.name = attrs.valueAsString("Name");
- tocsetup.itemAttrName = attrs.valueAsString("ItemAttributeName");
- tocsetup.frameName = attrs.valueAsString("FrameName");
- tocsetup.textStyle = attrs.valueAsString("Style");
- tocsetup.listNonPrintingFrames = QVariant(attrs.valueAsString("ListNonPrinting")).toBool();
- QString numberPlacement = attrs.valueAsString("NumberPlacement");
- if (numberPlacement == "Beginning")
- tocsetup.pageLocation = Beginning;
- if (numberPlacement == "End")
- tocsetup.pageLocation = End;
- if (numberPlacement == "NotShown")
- tocsetup.pageLocation = NotShown;
- doc->docToCSetups.append(tocsetup);
- }
- }
- return !reader.hasError();
-}
-
-bool Scribus150Format::readSections(ScribusDoc* doc, ScXmlStreamReader& reader)
-{
- QStringRef tagName = reader.name();
- while(!reader.atEnd() && !reader.hasError())
- {
- reader.readNext();
- if (reader.isEndElement() && reader.name() == tagName)
- break;
- if (reader.isStartElement() && reader.name() == "Section")
- {
- ScXmlStreamAttributes attrs = reader.scAttributes();
- struct DocumentSection newSection;
- newSection.number = attrs.valueAsInt("Number");
- newSection.name = attrs.valueAsString("Name");
- newSection.fromindex = attrs.valueAsInt("From");
- newSection.toindex = attrs.valueAsInt("To");
- QString type = attrs.valueAsString("Type");
- if (type == "Type_1_2_3")
- newSection.type=Type_1_2_3;
- if (type == "Type_i_ii_iii")
- newSection.type=Type_i_ii_iii;
- if (type == "Type_I_II_III")
- newSection.type=Type_I_II_III;
- if (type == "Type_a_b_c")
- newSection.type=Type_a_b_c;
- if (type == "Type_A_B_C")
- newSection.type=Type_A_B_C;
- if (type == "Type_None")
- newSection.type=Type_None;
- newSection.sectionstartindex = attrs.valueAsInt("Start");
- newSection.reversed = attrs.valueAsBool("Reversed");
- newSection.active = attrs.valueAsBool("Active");
- doc->sections.insert(newSection.number, newSection);
- }
- }
- return !reader.hasError();
-}
-
-bool Scribus150Format::readHyphen(ScribusDoc *doc, ScXmlStreamReader& reader)
-{
- QStringRef tagName = reader.name();
- while(!reader.atEnd() && !reader.hasError())
- {
- reader.readNext();
- if (reader.isEndElement() && reader.name() == tagName)
- break;
- if (reader.isStartElement() && reader.name() == "EXCEPTION")
- {
- ScXmlStreamAttributes attrs = reader.scAttributes();
- QString word = attrs.valueAsString("WORD");
- QString hyph = attrs.valueAsString("HYPHENATED");
- doc->docHyphenator->specialWords.insert(word, hyph);
- }
- else if (reader.isStartElement() && reader.name() == "IGNORE")
- {
- ScXmlStreamAttributes attrs = reader.scAttributes();
- QString word = attrs.valueAsString("WORD");
- doc->docHyphenator->ignoredWords.insert(word);
- }
- }
- return !reader.hasError();
-}
-
-bool Scribus150Format::readPage(ScribusDoc* doc, ScXmlStreamReader& reader)
-{
- QStringRef tagName = reader.name();
-
- ScXmlStreamAttributes attrs = reader.scAttributes();
- int pageNum = attrs.valueAsInt("NUM");
- QString pageName = attrs.valueAsString("NAM", "");
- if (tagName == "MASTERPAGE" && pageName.isEmpty())
- {
- qDebug() << "scribus150format: corrupted masterpage with empty name detected";
- return true;
- }
- m_Doc->setMasterPageMode(!pageName.isEmpty());
- Page* newPage = pageName.isEmpty() ? doc->addPage(pageNum) : doc->addMasterPage(pageNum, pageName);
-
- newPage->LeftPg = attrs.valueAsInt("LEFT", 0);
- QString mpName = attrs.valueAsString("MNAM", "Normal");
- newPage->MPageNam = m_Doc->masterPageMode() ? QString("") : mpName;
- if (attrs.hasAttribute("Size"))
- newPage->m_pageSize = attrs.valueAsString("Size");
- if (attrs.hasAttribute("Orientation"))
- newPage->setOrientation(attrs.valueAsInt("Orientation"));
- newPage->setXOffset(attrs.valueAsDouble("PAGEXPOS"));
- newPage->setYOffset(attrs.valueAsDouble("PAGEYPOS"));
- if (attrs.hasAttribute("PAGEWIDTH"))
- newPage->setWidth(attrs.valueAsDouble("PAGEWIDTH"));
- else
- newPage->setWidth(attrs.valueAsDouble("PAGEWITH"));
- newPage->setHeight(attrs.valueAsDouble("PAGEHEIGHT"));
- newPage->setInitialHeight(newPage->height());
- newPage->setInitialWidth(newPage->width());
- newPage->initialMargins.Top = qMax(0.0, attrs.valueAsDouble("BORDERTOP"));
- newPage->initialMargins.Bottom = qMax(0.0, attrs.valueAsDouble("BORDERBOTTOM"));
- newPage->initialMargins.Left = qMax(0.0, attrs.valueAsDouble("BORDERLEFT"));
- newPage->initialMargins.Right = qMax(0.0, attrs.valueAsDouble("BORDERRIGHT"));
- newPage->marginPreset = attrs.valueAsInt("PRESET", 0);
- newPage->Margins.Top = newPage->initialMargins.Top;
- newPage->Margins.Bottom = newPage->initialMargins.Bottom;
- m_Doc->setMasterPageMode(false);
- //m_Doc->Pages=&m_Doc->DocPages;
- // guides reading
- newPage->guides.setHorizontalAutoGap( attrs.valueAsDouble("AGhorizontalAutoGap", 0.0));
- newPage->guides.setVerticalAutoGap ( attrs.valueAsDouble("AGverticalAutoGap", 0.0));
- newPage->guides.setHorizontalAutoCount( attrs.valueAsInt("AGhorizontalAutoCount", 0) );
- newPage->guides.setVerticalAutoCount ( attrs.valueAsInt("AGverticalAutoCount", 0) );
- newPage->guides.setHorizontalAutoRefer( attrs.valueAsInt("AGhorizontalAutoRefer", 0) );
- newPage->guides.setVerticalAutoRefer ( attrs.valueAsInt("AGverticalAutoRefer", 0) );
- GuideManagerIO::readVerticalGuides(attrs.valueAsString("VerticalGuides"),
- newPage,
- GuideManagerCore::Standard,
- attrs.hasAttribute("NumVGuides"));
- GuideManagerIO::readHorizontalGuides(attrs.valueAsString("HorizontalGuides"),
- newPage,
- GuideManagerCore::Standard,
- attrs.hasAttribute("NumHGuides"));
- GuideManagerIO::readSelection(attrs.valueAsString("AGSelection"), newPage);
- return true;
-}
-
-bool Scribus150Format::readObject(ScribusDoc* doc, ScXmlStreamReader& reader, ItemInfo& info, const QString& baseDir, bool loadPage)
-{
- QStringRef tagName = reader.name();
- ScXmlStreamAttributes attrs = reader.scAttributes();
-
- if (!loadPage)
- {
- if (tagName == "PAGEOBJECT" || tagName == "FRAMEOBJECT" || tagName == "PatternItem")
- doc->setMasterPageMode(false);
- else
- doc->setMasterPageMode(true);
- }
- int pagenr = -1;
- if ((!attrs.value("OnMasterPage").isEmpty()) && (tagName == "MASTEROBJECT"))
- {
- doc->setCurrentPage(doc->MasterPages.at(doc->MasterNames[attrs.valueAsString("OnMasterPage")]));
- pagenr = -2;
- }
-
- PageItem* newItem = pasteItem(doc, attrs, baseDir, pagenr);
- newItem->setRedrawBounding();
- if (tagName == "MASTEROBJECT")
- newItem->OwnPage = doc->OnPage(newItem);
- else
- newItem->OwnPage = attrs.valueAsInt("OwnPage");
- if (tagName == "PAGEOBJECT")
- newItem->OnMasterPage = "";
- QString tmpf = attrs.valueAsString("IFONT", doc->toolSettings.defFont);
- m_AvailableFonts->findFont(tmpf, doc);
-
-// newItem->Language = ScMW->GetLang(pg.attribute("LANGUAGE", doc->Language));
- newItem->isAutoText = attrs.valueAsBool("AUTOTEXT", false);
- newItem->isEmbedded = attrs.valueAsBool("isInline", false);
- newItem->gXpos = attrs.valueAsDouble("gXpos", 0.0);
- newItem->gYpos = attrs.valueAsDouble("gYpos", 0.0);
- newItem->gWidth = attrs.valueAsDouble("gWidth", newItem->width());
- newItem->gHeight = attrs.valueAsDouble("gHeight", newItem->height());
- if (newItem->isAutoText)
- doc->LastAuto = newItem;
-
- if (tagName == "FRAMEOBJECT")
- {
- doc->FrameItems.append(doc->Items->takeAt(newItem->ItemNr));
- newItem->ItemNr = doc->FrameItems.count()-1;
- }
-
- info.item = newItem;
- info.nextItem = attrs.valueAsInt("NEXTITEM", -1);
- info.ownLink = newItem->isTableItem ? attrs.valueAsInt("OwnLINK", 0) : 0;
- info.groupLastItem = 0;
-
- newItem->isGroupControl = attrs.valueAsBool("isGroupControl", 0);
- if (newItem->isGroupControl)
- {
- int groupLastItem = attrs.valueAsInt("groupsLastItem", 0);
- // Sanity check for some broken files created using buggy development versions.
- if ((newItem->Groups.count() == 0) || (groupLastItem <= 0))
- {
- newItem->isGroupControl = false;
- newItem->setFillColor("None");
- }
- info.groupLastItem = groupLastItem;
- }
-
- bool layerFound = true;
- struct ImageLoadRequest loadingInfo;
-#ifdef HAVE_OSG
- struct PageItem_OSGFrame::viewDefinition currentView;
-#endif
- QList<ParagraphStyle::TabRecord> tabValues;
-
- LastStyles * lastStyle = new LastStyles();
- while(!reader.atEnd() && !reader.hasError())
- {
- ScXmlStreamReader::TokenType tType = reader.readNext();
- if (reader.isEndElement() && tagName == reader.name())
- break;
- if (tType != ScXmlStreamReader::StartElement)
- continue;
- QStringRef tName = reader.name();
- ScXmlStreamAttributes tAtt = reader.scAttributes();
- if (tName == "CSTOP")
- {
- QString name = tAtt.valueAsString("NAME");
- double ramp = tAtt.valueAsDouble("RAMP", 0.0);
- int shade = tAtt.valueAsInt("SHADE", 100);
- double opa = tAtt.valueAsDouble("TRANS", 1.0);
- newItem->fill_gradient.addStop(SetColor(doc, name, shade), ramp, 0.5, opa, name, shade);
- }
-
- if (tName == "ITEXT")
- readItemText(newItem, tAtt, lastStyle);
- else if (tName == "para")
- {
- newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::PARSEP);
- ParagraphStyle newStyle;
- PrefsManager* prefsManager = PrefsManager::instance();
- readParagraphStyle(doc, reader, newStyle, prefsManager->appPrefs.AvailFonts);
- newItem->itemText.setStyle(newItem->itemText.length()-1, newStyle);
- newItem->itemText.setCharStyle(newItem->itemText.length()-1, 1, lastStyle->Style);
- }
- else if (tName == "trail")
- {
- ParagraphStyle newStyle;
- PrefsManager* prefsManager = PrefsManager::instance();
- readParagraphStyle(doc, reader, newStyle, prefsManager->appPrefs.AvailFonts);
- newItem->itemText.setStyle(newItem->itemText.length(), newStyle);
- }
- else if (tName == "tab")
- newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::TAB);
- else if (tName == "breakline")
- newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::LINEBREAK);
- else if (tName == "breakcol")
- newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::COLBREAK);
- else if (tName == "breakframe")
- newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::FRAMEBREAK);
- else if (tName == "nbhyphen")
- newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::NBHYPHEN);
- else if (tName == "nbspace")
- newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::NBSPACE);
- else if (tName == "zwnbspace")
- newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::ZWNBSPACE);
- else if (tName == "zwspace")
- newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::ZWSPACE);
- else if (tName == "var")
- {
- CharStyle newStyle;
- if (tAtt.value("name") == "pgno")
- newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::PAGENUMBER);
- else
- newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::PAGECOUNT);
- readCharacterStyleAttrs(doc, tAtt, newStyle);
- newItem->itemText.setCharStyle(newItem->itemText.length()-1, 1, newStyle);
- lastStyle->StyleStart = newItem->itemText.length()-1;
- lastStyle->Style = newStyle;
- }
- if (tName == "PageItemAttributes")
- {
- readPageItemAttributes(newItem, reader);
- }
- if (tName == "PSDLayer")
- {
- layerFound = true;
- loadingInfo.blend = tAtt.valueAsString("Blend");
- loadingInfo.opacity = tAtt.valueAsInt("Opacity");
- loadingInfo.visible = tAtt.valueAsBool("Visible");
- loadingInfo.useMask = tAtt.valueAsBool("useMask", true);
- newItem->pixm.imgInfo.RequestProps.insert(tAtt.valueAsInt("Layer"), loadingInfo);
- }
-#ifdef HAVE_OSG
- if (tName == "OSGViews")
- {
- currentView.angleFOV = tAtt.valueAsDouble("angleFOV");
- QString tmp = "";
- tmp = tAtt.valueAsString("trackM");
- ScTextStream fp(&tmp, QIODevice::ReadOnly);
- double m1, m2, m3, m4;
- double m5, m6, m7, m8;
- double m9, m10, m11, m12;
- double m13, m14, m15, m16;
- fp >> m1 >> m2 >> m3 >> m4;
- fp >> m5 >> m6 >> m7 >> m8;
- fp >> m9 >> m10 >> m11 >> m12;
- fp >> m13 >> m14 >> m15 >> m16;
- currentView.trackerMatrix.set(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16);
- tmp = "";
- tmp = tAtt.valueAsString("trackC");
- ScTextStream fp2(&tmp, QIODevice::ReadOnly);
- double v1, v2, v3;
- fp2 >> v1 >> v2 >> v3;
- currentView.trackerCenter.set(v1, v2, v3);
- tmp = "";
- tmp = tAtt.valueAsString("cameraP");
- ScTextStream fp3(&tmp, QIODevice::ReadOnly);
- fp3 >> v1 >> v2 >> v3;
- currentView.cameraPosition.set(v1, v2, v3);
- tmp = "";
- tmp = tAtt.valueAsString("cameraU");
- ScTextStream fp4(&tmp, QIODevice::ReadOnly);
- fp4 >> v1 >> v2 >> v3;
- currentView.cameraUp.set(v1, v2, v3);
- currentView.trackerDist = tAtt.valueAsDouble("trackerDist");
- currentView.trackerSize = tAtt.valueAsDouble("trackerSize");
- currentView.illumination = static_cast<PageItem_OSGFrame::LightType>(tAtt.valueAsInt("illumination"));
- currentView.rendermode = static_cast<PageItem_OSGFrame::RenderType>(tAtt.valueAsInt("rendermode"));
- currentView.addedTransparency = tAtt.valueAsDouble("trans");
- currentView.colorAC = QColor(tAtt.valueAsString("colorAC"));
- currentView.colorFC = QColor(tAtt.valueAsString("colorFC"));
- if (newItem->asOSGFrame())
- newItem->asOSGFrame()->viewMap.insert(tAtt.valueAsString("viewName"), currentView);
- }
-#endif
- if (tName == "ImageEffect")
- {
- struct ImageEffect ef;
- ef.effectParameters = tAtt.valueAsString("Param");
- ef.effectCode = tAtt.valueAsInt("Code");
- newItem->effectsInUse.append(ef);
- }
- if (tName == "Tabs")
- {
- ParagraphStyle::TabRecord tb;
- tb.tabPosition = tAtt.valueAsDouble("Pos");
- tb.tabType = tAtt.valueAsInt("Type");
- QString tbCh = tAtt.valueAsString("Fill", "");
- tb.tabFillChar = tbCh.isEmpty() ? QChar() : tbCh[0];
- tabValues.append(tb);
- }
- if (tName == "LATEX")
- {
- if (newItem->asLatexFrame())
- {
- readLatexInfo(newItem->asLatexFrame(), reader);
- }
- else
- {
- while (!reader.atEnd() && !reader.hasError())
- {
- reader.readNext();
- if (reader.isEndElement() && reader.name() == tName)
- break;
- }
- }
- }
- }
- delete lastStyle;
-
- if (tabValues.count() > 0)
- {
- ParagraphStyle newDefault(newItem->itemText.defaultStyle());
- newDefault.setTabValues(tabValues);
- newItem->itemText.setDefaultStyle(newDefault);
- }
-
- if (newItem->fill_gradient.Stops() == 0)
- {
- const ScColor& col1 = doc->PageColors[doc->toolSettings.dBrush];
- const ScColor& col2 = doc->PageColors[doc->toolSettings.dPen];
- newItem->fill_gradient.addStop(ScColorEngine::getRGBColor(col1, doc), 0.0, 0.5, 1.0, doc->toolSettings.dBrush, 100);
- newItem->fill_gradient.addStop(ScColorEngine::getRGBColor(col2, doc), 1.0, 0.5, 1.0, doc->toolSettings.dPen, 100);
- }
-
- if (newItem->asPathText())
- {
- newItem->updatePolyClip();
- newItem->Frame = true;
- }
-#ifdef HAVE_OSG
- if (newItem->asImageFrame() || newItem->asLatexFrame() || newItem->asOSGFrame())
-#else
- if (newItem->asImageFrame() || newItem->asLatexFrame())
-#endif
- {
- if (!newItem->Pfile.isEmpty())
- {
- doc->loadPict(newItem->Pfile, newItem, false);
- if (layerFound)
- {
- newItem->pixm.imgInfo.isRequest = true;
- doc->loadPict(newItem->Pfile, newItem, true);
- }
- newItem->AdjustPictScale();
- }
- }
-
- if (!loadPage)
- doc->setMasterPageMode(false);
- return !reader.hasError();
-}
-
-bool Scribus150Format::readPattern(ScribusDoc* doc, ScXmlStreamReader& reader, const QString& baseDir)
-{
- ScPattern pat;
- ScXmlStreamAttributes attrs = reader.scAttributes();
- QString patternName = attrs.valueAsString("Name");
- bool success = true;
-
- if (patternName.isEmpty())
- {
- reader.readToElementEnd();
- return true;
- }
-
- QMap<PageItem*, int> groupID2;
- QMap<int,int> TableID2;
- QList<PageItem*> TableItems2;
-
- pat.setDoc(doc);
- pat.width = attrs.valueAsDouble("width", 0.0);
- pat.height = attrs.valueAsDouble("height", 0.0);
- pat.scaleX = attrs.valueAsDouble("scaleX", 0.0);
- pat.scaleY = attrs.valueAsDouble("scaleY", 0.0);
- pat.xoffset = attrs.valueAsDouble("xoffset", 0.0);
- pat.yoffset = attrs.valueAsDouble("yoffset", 0.0);
-
- uint itemCount1 = m_Doc->Items->count();
- bool savedAlignGrid = m_Doc->useRaster;
- bool savedAlignGuides = m_Doc->SnapGuides;
- m_Doc->useRaster = false;
- m_Doc->SnapGuides = false;
-
- QStringRef tagName = reader.name();
- while(!reader.atEnd() && !reader.hasError())
- {
- reader.readNext();
- if (reader.isEndElement() && reader.name() == tagName)
- break;
- if (!reader.isStartElement() || reader.name() != "PatternItem")
- continue;
-
- QStringRef tName = reader.name();
- ScXmlStreamAttributes tAtt = reader.attributes();
-
- ItemInfo itemInfo;
- m_Doc->setMasterPageMode(false);
-
- int ownPage = tAtt.valueAsInt("OwnPage");
- success = readObject(doc, reader, itemInfo, baseDir, false);
- if (!success) break;
-
- itemInfo.item->OwnPage = ownPage;
- itemInfo.item->OnMasterPage = "";
-
- if (itemInfo.item->isTableItem)
- {
- TableItems2.append(itemInfo.item);
- TableID2.insert(itemInfo.ownLink, itemInfo.item->ItemNr);
- }
- if (itemInfo.item->isGroupControl)
- {
- groupID2.insert(itemInfo.item, itemInfo.groupLastItem + itemInfo.item->ItemNr);
- }
- }
-
- doc->useRaster = savedAlignGrid;
- doc->SnapGuides = savedAlignGuides;
- if (!success)
- {
- return false;
- }
-
- if (groupID2.count() != 0)
- {
- QMap<PageItem*, int>::Iterator it;
- for (it = groupID2.begin(); it != groupID2.end(); ++it)
- {
- it.key()->groupsLastItem = m_Doc->Items->at(it.value());
- }
- }
- if (TableItems2.count() != 0)
- {
- for (int ttc = 0; ttc < TableItems2.count(); ++ttc)
- {
- PageItem* ta = TableItems2.at(ttc);
- if (ta->TopLinkID != -1)
- ta->TopLink = m_Doc->Items->at(TableID2[ta->TopLinkID]);
- else
- ta->TopLink = 0;
- if (ta->LeftLinkID != -1)
- ta->LeftLink = m_Doc->Items->at(TableID2[ta->LeftLinkID]);
- else
- ta->LeftLink = 0;
- if (ta->RightLinkID != -1)
- ta->RightLink = m_Doc->Items->at(TableID2[ta->RightLinkID]);
- else
- ta->RightLink = 0;
- if (ta->BottomLinkID != -1)
- ta->BottomLink = m_Doc->Items->at(TableID2[ta->BottomLinkID]);
- else
- ta->BottomLink = 0;
- }
- }
-
- uint itemCount2 = m_Doc->Items->count();
- if (itemCount2 > itemCount1)
- {
- PageItem* currItem = doc->Items->at(itemCount1), *newItem;
- pat.pattern = currItem->DrawObj_toImage();
- pat.pattern = pat.pattern.copy(-pat.xoffset, -pat.yoffset, pat.width, pat.height);
- for (uint as = itemCount1; as < itemCount2; ++as)
- {
- newItem = doc->Items->takeAt(itemCount1);
- newItem->moveBy(pat.xoffset, pat.yoffset, true);
- newItem->gXpos += pat.xoffset;
- newItem->gYpos += pat.yoffset;
- newItem->ItemNr = pat.items.count();
- pat.items.append(newItem);
- }
- }
- doc->docPatterns.insert(patternName, pat);
-
- return success;
-}
-
-bool Scribus150Format::readItemText(PageItem *obj, ScXmlStreamAttributes& attrs, LastStyles* last)
-{
- QString tmp2;
- CharStyle newStyle;
- ScribusDoc* doc = obj->doc();
-
- readCharacterStyleAttrs(doc, attrs, newStyle);
-
- if (attrs.hasAttribute(QLatin1String("Unicode")))
- {
- tmp2 = QChar(attrs.valueAsInt("Unicode"));
- }
- else
- {
- tmp2 = attrs.valueAsString("CH");
-
- // legacy stuff:
- tmp2.replace(QRegExp("\r"), QChar(13));
- tmp2.replace(QRegExp("\n"), QChar(13));
- tmp2.replace(QRegExp("\t"), QChar(9));
- }
-
- // more legacy stuff:
- QString pstylename = attrs.valueAsString("PSTYLE", "");
-
- fixLegacyCharStyle(newStyle);
- last->ParaStyle = pstylename;
- // end of legacy stuff
-
- int iobj = attrs.valueAsInt("COBJ", -1);
-
- for (int cxx=0; cxx<tmp2.length(); ++cxx)
- {
- QChar ch = tmp2.at(cxx);
- { // Legacy mode
- if (ch == QChar(5))
- ch = SpecialChars::PARSEP;
- if (ch == QChar(4))
- ch = SpecialChars::TAB;
- }
-
- int pos = obj->itemText.length();
- if (ch == SpecialChars::OBJECT) {
- if (iobj != -1) {
- obj->itemText.insertObject(pos, doc->FrameItems.at(iobj));
- }
- }
- else if (ch == SpecialChars::SHYPHEN && pos > 0)
- {
-// qDebug() << QString("scribus150format: SHYPHEN at %1").arg(pos);
- ScText* lastItem = obj->itemText.item(pos-1);
- // double SHY means user provided SHY, single SHY is automatic one
- if (lastItem->effects() & ScStyle_HyphenationPossible)
- {
- lastItem->setEffects(lastItem->effects() & ~ScStyle_HyphenationPossible);
- obj->itemText.insertChars(pos, QString(ch));
- }
- else
- {
- lastItem->setEffects(lastItem->effects() | ScStyle_HyphenationPossible);
- }
- }
- else {
- obj->itemText.insertChars(pos, QString(ch));
- }
-// qDebug() << QString("style at %1: %2 ^ %3 = %4 (%5)").arg(pos).arg((uint)newStyle.effects()).arg((uint)last->Style.effects()).arg((uint)(newStyle.effects() ^ last->Style.effects())).arg(newStyle != last->Style);
- if (newStyle != last->Style) // || (newStyle.effects() ^ last->Style.effects()) == ScStyle_HyphenationPossible)
- { // FIXME StyleFlag operator== ignores hyphen flag
-// qDebug() << QString("new style at %1: %2 -> %3").arg(pos).arg(last->Style.asString()).arg(newStyle.asString());
- obj->itemText.setCharStyle(last->StyleStart, pos-last->StyleStart, last->Style);
- last->Style = newStyle;
- last->StyleStart = pos;
- }
- if (ch == SpecialChars::PARSEP) {
- ParagraphStyle pstyle;
- // Qt4 if (last->ParaStyle >= 0) {
- if (!last->ParaStyle.isEmpty()) {
- pstyle.setParent( last->ParaStyle );
- }
- obj->itemText.applyStyle(pos, pstyle);
- }
- }
-
- obj->itemText.setCharStyle(last->StyleStart, obj->itemText.length()-last->StyleStart, last->Style);
- last->StyleStart = obj->itemText.length();
-/*
- QString dbg("");
- for (int i=0; i < obj->itemText.length(); ++i)
- {
- dbg += obj->itemText.text(i,1);
- if (obj->itemText.item(i)->effects() & ScStyle_HyphenationPossible)
- dbg += "~";
- }
- qDebug("scribus150format: read itemtext %d '%s'", obj->itemText.length(), dbg.latin1());
- */
- ParagraphStyle pstyle;
-
- if (!last->ParaStyle.isEmpty()) { // Qt4 >= 0) {
- pstyle.setParent( last->ParaStyle );
- obj->itemText.applyStyle(obj->itemText.length()-1, pstyle);
- }
-
- return true;
-}
-
-bool Scribus150Format::readPageItemAttributes(PageItem* item, ScXmlStreamReader& reader)
-{
- QStringRef tagName = reader.name();
- ObjAttrVector pageItemAttributes;
- while(!reader.atEnd() && !reader.hasError())
- {
- reader.readNext();
- if (reader.isEndElement() && reader.name() == tagName)
- break;
- if (reader.isStartElement() && reader.name() == "ItemAttribute")
- {
- ScXmlStreamAttributes tAtt = reader.scAttributes();
- ObjectAttribute objattr;
- objattr.name = tAtt.valueAsString("Name");
- objattr.type = tAtt.valueAsString("Type");
- objattr.value = tAtt.valueAsString("Value");
- objattr.parameter = tAtt.valueAsString("Parameter");
- objattr.relationship = tAtt.valueAsString("Relationship");
- objattr.relationshipto = tAtt.valueAsString("RelationshipTo");
- objattr.autoaddto = tAtt.valueAsString("AutoAddTo");
- pageItemAttributes.append(objattr);
- }
- }
- item->setObjectAttributes(&pageItemAttributes);
- return !reader.hasError();
-}
-
-PageItem* Scribus150Format::pasteItem(ScribusDoc *doc, ScXmlStreamAttributes& attrs, const QString& baseDir, int pagenr)
-{
- int z = 0;
- struct ImageLoadRequest loadingInfo;
- PageItem::ItemType pt = static_cast<PageItem::ItemType>(attrs.valueAsInt("PTYPE"));
- double xf, yf;
- double x = attrs.valueAsDouble("XPOS");
- double y = attrs.valueAsDouble("YPOS");
- double w = attrs.valueAsDouble("WIDTH");
- double h = attrs.valueAsDouble("HEIGHT");
- double pw = attrs.valueAsDouble("PWIDTH");
- double scx = attrs.valueAsDouble("LOCALSCX");
- double scy = attrs.valueAsDouble("LOCALSCY");
- QString Pcolor = attrs.valueAsString("PCOLOR");
- if (Pcolor.isEmpty())
- Pcolor = CommonStrings::None;
- QString Pcolor2 = attrs.valueAsString("PCOLOR2");
- if (Pcolor2.isEmpty())
- Pcolor2 = CommonStrings::None;
- QColor tmpc;
- PageItem *currItem=NULL;
- QString tmp, clPath;
- int xi;
-
- switch (pt)
- {
- // OBSOLETE CR 2005-02-06
- case PageItem::ItemType1:
- z = doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, x, y, w, h, pw, Pcolor, Pcolor2, true);
- currItem = doc->Items->at(z);
- if (pagenr > -2)
- currItem->OwnPage = pagenr;
- break;
- //
- case PageItem::ImageFrame:
- case PageItem::OSGFrame:
- case PageItem::LatexFrame: /*Everything that is valid for image frames is also valid for latex frames*/
- z = doc->itemAdd(pt, PageItem::Unspecified, x, y, w, h, 1, doc->toolSettings.dBrushPict, CommonStrings::None, true);
- currItem = doc->Items->at(z);
- if (pagenr > -2)
- currItem->OwnPage = pagenr;
- UndoManager::instance()->setUndoEnabled(false);
- currItem->setImageXYScale(scx, scy);
- currItem->setImageXYOffset(attrs.valueAsDouble("LOCALX"), attrs.valueAsDouble("LOCALY"));
-// if (!currItem->asLatexFrame())
-#ifdef HAVE_OSG
- if ((currItem->asImageFrame() || currItem->asOSGFrame()) && (!currItem->asLatexFrame()))
-#else
- if ((currItem->asImageFrame()) && (!currItem->asLatexFrame()))
-#endif
- {
- bool inlineF = attrs.valueAsBool("isInlineImage", false);
- QString dat = attrs.valueAsString("ImageData", "");
- QByteArray inlineImageData;
- inlineImageData.append(dat);
- QString inlineImageExt = attrs.valueAsString("inlineImageExt", "");
- if (inlineF)
- {
- if (inlineImageData.size() > 0)
- {
- currItem->tempImageFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_XXXXXX." + inlineImageExt);
- currItem->tempImageFile->open();
- QString fileName = getLongPathName(currItem->tempImageFile->fileName());
- currItem->tempImageFile->close();
- inlineImageData = qUncompress(QByteArray::fromBase64(inlineImageData));
- QFile outFil(fileName);
- if (outFil.open(QIODevice::WriteOnly))
- {
- outFil.write(inlineImageData);
- outFil.close();
- currItem->isInlineImage = true;
- currItem->Pfile = fileName;
- }
- }
- }
- else
- currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE"), baseDir);
-#ifdef HAVE_OSG
- if (currItem->asOSGFrame())
- {
- PageItem_OSGFrame *osgframe = currItem->asOSGFrame();
- osgframe->modelFile = Relative2Path(attrs.valueAsString("modelFile"), baseDir);
- osgframe->currentView = attrs.valueAsString("currentViewName", "");
- osgframe->loadModel();
- }
-#endif
- }
- currItem->IProfile = attrs.valueAsString("PRFILE", "");
- currItem->EmProfile = attrs.valueAsString("EPROF" , "");
- currItem->IRender = attrs.valueAsInt("IRENDER", 1);
- currItem->UseEmbedded = attrs.valueAsInt("EMBEDDED", 1);
- currItem->pixm.imgInfo.lowResType = attrs.valueAsInt("ImageRes", 1);
- currItem->pixm.imgInfo.actualPageNumber = attrs.valueAsInt("Pagenumber", 0);
- currItem->IProfile = attrs.valueAsString("PRFILE","");
- currItem->EmProfile = attrs.valueAsString("EPROF","");
- currItem->IRender = attrs.valueAsInt("IRENDER", 1);
- currItem->UseEmbedded = attrs.valueAsInt("EMBEDDED", 1);
- if (currItem->asLatexFrame())
- {
- currItem->setImageXYOffset(attrs.valueAsDouble("LOCALX") * scx, attrs.valueAsDouble("LOCALY") * scy);
- // currItem->setImageXYScale(1.0, 1.0);
- }
- else
- currItem->setImageXYScale(scx, scy);
- clPath = attrs.valueAsString("ImageClip", "");
- if (currItem->pixm.imgInfo.PDSpathData.contains(clPath))
- {
- currItem->imageClip = currItem->pixm.imgInfo.PDSpathData[clPath].copy();
- currItem->pixm.imgInfo.usedPath = clPath;
- QMatrix cl;
- cl.translate(currItem->imageXOffset()*currItem->imageXScale(), currItem->imageYOffset()*currItem->imageYScale());
- cl.scale(currItem->imageXScale(), currItem->imageYScale());
- currItem->imageClip.map(cl);
- }
- currItem->setImageShown( attrs.valueAsInt("PICART"));
-/* currItem->BBoxX = ScCLocale::toDoubleC( obj->attribute("BBOXX"));
- currItem->BBoxH = ScCLocale::toDoubleC( obj->attribute("BBOXH")); */
- currItem->ScaleType = attrs.valueAsInt("SCALETYPE", 1);
- currItem->AspectRatio = attrs.valueAsInt("RATIO", 0);
- currItem->setLineWidth(pw);
- UndoManager::instance()->setUndoEnabled(true);
- break;
- // OBSOLETE CR 2005-02-06
- case PageItem::ItemType3:
- z = doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, x, y, w, h, pw, Pcolor, Pcolor2, true);
- currItem = doc->Items->at(z);
- if (pagenr > -2)
- currItem->OwnPage = pagenr;
- break;
- //
- case PageItem::PathText:
- z = doc->itemAdd(PageItem::PathText, PageItem::Unspecified, x, y, w, h, pw, CommonStrings::None, Pcolor, true);
- currItem = doc->Items->at(z);
- if (pagenr > -2)
- currItem->OwnPage = pagenr;
- UndoManager::instance()->setUndoEnabled(false);
- if (attrs.valueAsInt("ANNOTATION", 0) && attrs.valueAsBool("ANICON", false))
- {
- currItem->setImageXYScale(scx, scy);
- currItem->setImageXYOffset(attrs.valueAsDouble("LOCALX"), attrs.valueAsDouble("LOCALY"));
- currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE" , "") , baseDir);
- currItem->Pfile2 = Relative2Path(attrs.valueAsString("PFILE2", ""), baseDir);
- currItem->Pfile3 = Relative2Path(attrs.valueAsString("PFILE3", ""), baseDir);
- currItem->IProfile = attrs.valueAsString("PRFILE", "");
- currItem->EmProfile = attrs.valueAsString("EPROF", "");
- currItem->IRender = attrs.valueAsInt("IRENDER", 1);
- currItem->UseEmbedded = attrs.valueAsInt("EMBEDDED", 1);
- doc->LoadPict(currItem->Pfile, z);
- currItem->setImageXYScale(scx, scy);
- currItem->setImageShown(attrs.valueAsInt("PICART"));
-/* currItem->BBoxX = ScCLocale::toDoubleC( obj->attribute("BBOXX"));
- currItem->BBoxH = ScCLocale::toDoubleC( obj->attribute("BBOXH")); */
- currItem->ScaleType = attrs.valueAsInt("SCALETYPE", 1);
- currItem->AspectRatio = attrs.valueAsInt("RATIO", 0);
- }
- //currItem->convertTo(pt);
- UndoManager::instance()->setUndoEnabled(true);
- break;
- case PageItem::TextFrame:
- z = doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, x, y, w, h, pw, CommonStrings::None, Pcolor, true);
- currItem = doc->Items->at(z);
- if (pagenr > -2)
- currItem->OwnPage = pagenr;
- UndoManager::instance()->setUndoEnabled(false);
- if ((attrs.valueAsInt("ANNOTATION", 0)) && (attrs.valueAsBool("ANICON", false)))
- {
- currItem->setImageXYScale(scx, scy);
- currItem->setImageXYOffset(attrs.valueAsDouble("LOCALX"), attrs.valueAsDouble("LOCALY"));
- currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE" , ""), baseDir);
- currItem->Pfile2 = Relative2Path(attrs.valueAsString("PFILE2", ""), baseDir);
- currItem->Pfile3 = Relative2Path(attrs.valueAsString("PFILE3", ""), baseDir);
- currItem->IProfile = attrs.valueAsString("PRFILE", "");
- currItem->EmProfile = attrs.valueAsString("EPROF", "");
- currItem->IRender = attrs.valueAsInt("IRENDER" , 1);
- currItem->UseEmbedded = attrs.valueAsInt("EMBEDDED", 1);
- doc->LoadPict(currItem->Pfile, z);
- currItem->setImageXYScale(scx, scy);
- currItem->setImageShown( attrs.valueAsInt("PICART"));
-/* currItem->BBoxX = ScCLocale::toDoubleC( obj->attribute("BBOXX"));
- currItem->BBoxH = ScCLocale::toDoubleC( obj->attribute("BBOXH")); */
- currItem->ScaleType = attrs.valueAsInt("SCALETYPE", 1);
- currItem->AspectRatio = attrs.valueAsInt("RATIO", 0);
- }
- //currItem->convertTo(pt);
- UndoManager::instance()->setUndoEnabled(true);
- break;
- case PageItem::Line:
- z = doc->itemAdd(PageItem::Line, PageItem::Unspecified, x, y, w, h, pw, CommonStrings::None, Pcolor2, true);
- currItem = doc->Items->at(z);
- if (pagenr > -2)
- currItem->OwnPage = pagenr;
- break;
- case PageItem::Polygon:
- z = doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, x, y, w, h, pw, Pcolor, Pcolor2, true);
- currItem = doc->Items->at(z);
- if (pagenr > -2)
- currItem->OwnPage = pagenr;
- break;
- case PageItem::PolyLine:
- z = doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, w, h, pw, Pcolor, Pcolor2, true);
- currItem = doc->Items->at(z);
- if (pagenr > -2)
- currItem->OwnPage = pagenr;
- break;
- case PageItem::Multiple:
- Q_ASSERT(false);
- break;
- }
-
- UndoManager::instance()->setUndoEnabled(false);
- currItem->FrameType = attrs.valueAsInt("FRTYPE", 0);
- int startArrowIndex = attrs.valueAsInt("startArrowIndex", 0);
- if ((startArrowIndex < 0) || (startArrowIndex > static_cast<int>(doc->arrowStyles.size())))
- {
- qDebug() << QString("scribus150format: invalid arrow index: %").arg(startArrowIndex);
- startArrowIndex = 0;
- }
- currItem->setStartArrowIndex(startArrowIndex);
- int endArrowIndex = attrs.valueAsInt("endArrowIndex", 0);
- if ((endArrowIndex < 0) || (endArrowIndex > static_cast<int>(doc->arrowStyles.size())))
- {
- qDebug() << QString("scribus150format: invalid arrow index: %").arg(endArrowIndex);
- endArrowIndex = 0;
- }
- currItem->setEndArrowIndex(endArrowIndex);
- currItem->NamedLStyle = attrs.valueAsString("NAMEDLST", "");
- currItem->isBookmark = attrs.valueAsInt("BOOKMARK");
- if ((currItem->isBookmark) && (doc->BookMarks.count() == 0))
- doc->OldBM = true;
- currItem->setImageFlippedH( attrs.valueAsInt("FLIPPEDH"));
- currItem->setImageFlippedV( attrs.valueAsInt("FLIPPEDV"));
- currItem->setCornerRadius( attrs.valueAsDouble("RADRECT", 0.0));
- currItem->ClipEdited = attrs.valueAsInt("CLIPEDIT", 0);
- currItem->setFillColor(Pcolor);
- currItem->setLineColor(Pcolor2);
- currItem->setFillShade(attrs.valueAsInt("SHADE"));
- currItem->setLineShade(attrs.valueAsInt("SHADE2"));
-
- ParagraphStyle pstyle;
- if (attrs.hasAttribute("LINESP"))
- pstyle.setLineSpacing(attrs.valueAsDouble("LINESP"));
- if (attrs.hasAttribute("LINESPMode"))
- pstyle.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(attrs.valueAsInt("LINESPMode", 0)));
- if (attrs.hasAttribute("ALIGN"))
- pstyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(attrs.valueAsInt("ALIGN", 0)));
- if (attrs.hasAttribute("IFONT"))
- pstyle.charStyle().setFont(m_AvailableFonts->findFont(attrs.valueAsString("IFONT"), doc));
- if (attrs.hasAttribute("ISIZE"))
- pstyle.charStyle().setFontSize(qRound(attrs.valueAsDouble("ISIZE") * 10));
- if (attrs.hasAttribute("TXTSTROKE"))
- pstyle.charStyle().setStrokeColor(attrs.valueAsString("TXTSTROKE"));
- if (attrs.hasAttribute("TXTFILL"))
- pstyle.charStyle().setFillColor(attrs.valueAsString("TXTFILL"));
- if (attrs.hasAttribute("TXTSTRSH"))
- pstyle.charStyle().setStrokeShade(attrs.valueAsInt("TXTSTRSH"));
- if (attrs.hasAttribute("TXTFILLSH"))
- pstyle.charStyle().setFillShade(attrs.valueAsInt("TXTFILLSH"));
- if (attrs.hasAttribute("TXTSCALE"))
- pstyle.charStyle().setScaleH(qRound(attrs.valueAsDouble("TXTSCALE") * 10));
- if (attrs.hasAttribute("TXTSCALEV"))
- pstyle.charStyle().setScaleV(qRound(attrs.valueAsDouble("TXTSCALEV") * 10));
- if (attrs.hasAttribute("TXTBASE"))
- pstyle.charStyle().setBaselineOffset(qRound(attrs.valueAsDouble("TXTBASE") * 10));
- if (attrs.hasAttribute("TXTSHX"))
- pstyle.charStyle().setShadowXOffset(qRound(attrs.valueAsDouble("TXTSHX") * 10));
- if (attrs.hasAttribute("TXTSHY"))
- pstyle.charStyle().setShadowYOffset(qRound(attrs.valueAsDouble("TXTSHY") * 10));
- if (attrs.hasAttribute("TXTOUT"))
- pstyle.charStyle().setOutlineWidth(qRound(attrs.valueAsDouble("TXTOUT") * 10));
- if (attrs.hasAttribute("TXTULP"))
- pstyle.charStyle().setUnderlineOffset(qRound(attrs.valueAsDouble("TXTULP") * 10));
- if (attrs.hasAttribute("TXTULW"))
- pstyle.charStyle().setUnderlineWidth(qRound(attrs.valueAsDouble("TXTULW") * 10));
- if (attrs.hasAttribute("TXTSTP"))
- pstyle.charStyle().setStrikethruOffset(qRound(attrs.valueAsDouble("TXTSTP") * 10));
- if (attrs.hasAttribute("TXTSTW"))
- pstyle.charStyle().setStrikethruWidth(qRound(attrs.valueAsDouble("TXTSTW") * 10));
- if (attrs.hasAttribute("TXTSTYLE"))
- pstyle.charStyle().setFeatures(static_cast<StyleFlag>(attrs.valueAsInt("TXTSTYLE")).featureList());
- if (attrs.hasAttribute("TXTKERN"))
- pstyle.charStyle().setTracking(qRound(attrs.valueAsDouble("TXTKERN", 0.0) * 10));
- if (attrs.hasAttribute("wordTrack"))
- pstyle.charStyle().setWordTracking(attrs.valueAsDouble("wordTrack"));
- if (attrs.hasAttribute("MinWordTrack"))
- pstyle.setMinWordTracking(attrs.valueAsDouble("MinWordTrack"));
- if (attrs.hasAttribute("MinGlyphShrink"))
- pstyle.setMinGlyphExtension(attrs.valueAsDouble("MinGlyphShrink"));
- if (attrs.hasAttribute("MaxGlyphExtend"))
- pstyle.setMaxGlyphExtension(attrs.valueAsDouble("MaxGlyphExtend"));
- if (attrs.hasAttribute("OpticalMargins"))
- pstyle.setOpticalMargins(attrs.valueAsInt("OpticalMargins"));
- if (attrs.hasAttribute("HyphenationMode"))
- pstyle.setHyphenationMode(attrs.valueAsInt("HyphenationMode"));
- if (attrs.hasAttribute("leftMargin"))
- pstyle.setLeftMargin(attrs.valueAsDouble("leftMargin"));
- if (attrs.hasAttribute("rightMargin"))
- pstyle.setRightMargin(attrs.valueAsDouble("rightMargin"));
- if (attrs.hasAttribute("firstIndent"))
- pstyle.setFirstIndent(attrs.valueAsDouble("firstIndent"));
- currItem->itemText.setDefaultStyle(pstyle);
-
- if (attrs.hasAttribute("PSTYLE"))
- {
- QString pstyleName = attrs.valueAsString("PSTYLE");
- if (!pstyleName.isEmpty())
- {
- ParagraphStyle defStyle(currItem->itemText.defaultStyle());
- defStyle.setParent(pstyleName);
- currItem->itemText.setDefaultStyle(defStyle);
- }
- }
-
- currItem->setRotation( attrs.valueAsDouble("ROT") );
- currItem->setTextToFrameDist(attrs.valueAsDouble("EXTRA"),
- attrs.valueAsDouble("REXTRA", 1.0),
- attrs.valueAsDouble("TEXTRA", 1.0),
- attrs.valueAsDouble("BEXTRA", 1.0));
- currItem->setFirstLineOffset(static_cast<FirstLineOffsetPolicy>(attrs.valueAsInt("FLOP")));
-
- currItem->PLineArt = Qt::PenStyle(attrs.valueAsInt("PLINEART"));
- currItem->PLineEnd = Qt::PenCapStyle(attrs.valueAsInt("PLINEEND", 0));
- currItem->PLineJoin = Qt::PenJoinStyle(attrs.valueAsInt("PLINEJOIN", 0));
- currItem->setPrintEnabled( attrs.valueAsInt("PRINTABLE"));
- currItem->setIsAnnotation( attrs.valueAsInt("ANNOTATION", 0));
- currItem->annotation().setType( attrs.valueAsInt("ANTYPE", 0));
- QString AnName = attrs.valueAsString("ANNAME","");
- if (!AnName.isEmpty())
- {
- if (currItem->itemName() == AnName)
- currItem->AutoName = true;
- else
- {
- currItem->setItemName(AnName);
- currItem->AutoName = false;
- }
- }
- currItem->annotation().setAction( attrs.valueAsString("ANACTION","") );
- currItem->annotation().setE_act ( attrs.valueAsString("ANEACT","") );
- currItem->annotation().setX_act ( attrs.valueAsString("ANXACT","") );
- currItem->annotation().setD_act ( attrs.valueAsString("ANDACT","") );
- currItem->annotation().setFo_act( attrs.valueAsString("ANFOACT","") );
- currItem->annotation().setBl_act( attrs.valueAsString("ANBLACT","") );
- currItem->annotation().setK_act ( attrs.valueAsString("ANKACT","") );
- currItem->annotation().setF_act ( attrs.valueAsString("ANFACT","") );
- currItem->annotation().setV_act ( attrs.valueAsString("ANVACT","") );
- currItem->annotation().setC_act ( attrs.valueAsString("ANCACT","") );
- currItem->annotation().setActionType(attrs.valueAsInt("ANACTYP", 0));
- currItem->annotation().setExtern( attrs.valueAsString("ANEXTERN",""));
- if ((!currItem->annotation().Extern().isEmpty()) && (currItem->annotation().ActionType() != 8))
- currItem->annotation().setExtern(Relative2Path(attrs.valueAsString("ANEXTERN", "") , baseDir));
- currItem->annotation().setZiel( attrs.valueAsInt("ANZIEL", 0));
- currItem->annotation().setToolTip ( attrs.valueAsString("ANTOOLTIP",""));
- currItem->annotation().setRollOver( attrs.valueAsString("ANROLL",""));
- currItem->annotation().setDown( attrs.valueAsString("ANDOWN",""));
- currItem->annotation().setBwid( attrs.valueAsInt("ANBWID", 1));
- currItem->annotation().setBsty( attrs.valueAsInt("ANBSTY", 0));
- currItem->annotation().setFeed( attrs.valueAsInt("ANFEED", 1));
- currItem->annotation().setFlag( attrs.valueAsInt("ANFLAG", 0));
- currItem->annotation().setFont( attrs.valueAsInt("ANFONT", 4));
- currItem->annotation().setFormat( attrs.valueAsInt("ANFORMAT", 0));
- currItem->annotation().setVis( attrs.valueAsInt("ANVIS", 0));
- currItem->annotation().setIsChk( attrs.valueAsBool("ANCHK", false) );
- currItem->annotation().setAAact( attrs.valueAsBool("ANAA", false) );
- currItem->annotation().setHTML ( attrs.valueAsInt("ANHTML", 0));
- currItem->annotation().setUseIcons( attrs.valueAsBool("ANICON", false));
- currItem->annotation().setChkStil ( attrs.valueAsInt("ANCHKS", 0));
- currItem->annotation().setMaxChar ( attrs.valueAsInt("ANMC", -1));
- currItem->annotation().setBorderColor( attrs.valueAsString("ANBCOL", CommonStrings::None));
- currItem->annotation().setIPlace(attrs.valueAsInt("ANPLACE", 1));
- currItem->annotation().setScaleW(attrs.valueAsInt("ANSCALE", 0));
- currItem->TopLine = attrs.valueAsBool("TopLine", false);
- currItem->LeftLine = attrs.valueAsBool("LeftLine", false);
- currItem->RightLine = attrs.valueAsBool("RightLine", false);
- currItem->BottomLine = attrs.valueAsBool("BottomLine", false);
- currItem->isTableItem = attrs.valueAsBool("isTableItem", false);
- currItem->TopLinkID = attrs.valueAsInt("TopLINK", -1);
- currItem->LeftLinkID = attrs.valueAsInt("LeftLINK", -1);
- currItem->RightLinkID = attrs.valueAsInt("RightLINK", -1);
- currItem->BottomLinkID = attrs.valueAsInt("BottomLINK", -1);
- currItem->PoShow = attrs.valueAsInt("PLTSHOW", 0);
- currItem->BaseOffs = attrs.valueAsDouble("BASEOF", 0.0);
- currItem->textPathType = attrs.valueAsInt("textPathType", 0);
- currItem->textPathFlipped = attrs.valueAsBool("textPathFlipped", false);
- if ( attrs.hasAttribute("TEXTFLOWMODE") )
- currItem->setTextFlowMode((PageItem::TextFlowMode) attrs.valueAsInt("TEXTFLOWMODE", 0));
- else if ( attrs.valueAsInt("TEXTFLOW") )
- {
- if (attrs.valueAsInt("TEXTFLOW2", 0))
- currItem->setTextFlowMode(PageItem::TextFlowUsesBoundingBox);
- else if (attrs.valueAsInt("TEXTFLOW3", 0))
- currItem->setTextFlowMode(PageItem::TextFlowUsesContourLine);
- else
- currItem->setTextFlowMode(PageItem::TextFlowUsesFrameShape);
- }
- else
- currItem->setTextFlowMode(PageItem::TextFlowDisabled);
- currItem->DashOffset = attrs.valueAsDouble("DASHOFF", 0.0);
- currItem->setReversed(attrs.valueAsBool("REVERS", false));
- currItem->setLocked (attrs.valueAsBool("LOCK", false));
- currItem->setSizeLocked(attrs.valueAsBool("LOCKR", false));
- currItem->setFillTransparency(attrs.valueAsDouble("TransValue", 0.0));
- currItem->fillRule = attrs.valueAsBool("fillRule", true);
- currItem->doOverprint = attrs.valueAsBool("doOverprint", false);
- if (attrs.hasAttribute("TransValueS"))
- currItem->setLineTransparency(attrs.valueAsDouble("TransValueS", 0.0));
- else
- currItem->setLineTransparency(attrs.valueAsDouble("TransValue", 0.0));
- currItem->setFillBlendmode(attrs.valueAsInt("TransBlend", 0));
- currItem->setLineBlendmode(attrs.valueAsInt("TransBlendS", 0));
- if (attrs.valueAsInt("TRANSPARENT", 0) == 1)
- currItem->setFillColor(CommonStrings::None);
- currItem->Cols = attrs.valueAsInt("COLUMNS", 1);
- currItem->ColGap = attrs.valueAsDouble("COLGAP", 0.0);
- if (attrs.valueAsInt("LAYER", 0) != -1)
- currItem->LayerID = attrs.valueAsInt("LAYER", 0);
- tmp = "";
-
- if (attrs.hasAttribute("GROUPS") && (attrs.valueAsInt("NUMGROUP", 0) != 0))
- {
- int groupMax = doc->GroupCounter;
- QMap<int, int>::ConstIterator gIt;
- tmp = attrs.valueAsString("GROUPS");
- ScTextStream fg(&tmp, QIODevice::ReadOnly);
- currItem->Groups.clear();
- int numGroup = attrs.valueAsInt("NUMGROUP", 0);
- for (int cx = 0; cx < numGroup; ++cx)
- {
- fg >> xi;
- gIt = groupRemap.find(xi);
- if (gIt != groupRemap.end())
- currItem->Groups.push(gIt.value());
- else
- {
- currItem->Groups.push(groupMax);
- groupRemap.insert(xi, groupMax);
- ++groupMax;
- }
- }
- doc->GroupCounter = groupMax;
- tmp = "";
- }
- else
- currItem->Groups.clear();
-
- tmp = "";
- if ((attrs.hasAttribute("NUMDASH")) && (attrs.valueAsInt("NUMDASH", 0) != 0))
- {
- tmp = attrs.valueAsString("DASHS");
- ScTextStream dgv(&tmp, QIODevice::ReadOnly);
- currItem->DashValues.clear();
- int numDash = attrs.valueAsInt("NUMDASH", 0);
- for (int cxv = 0; cxv < numDash; ++cxv)
- {
- dgv >> xf;
- currItem->DashValues.append(xf);
- }
- tmp = "";
- }
- else
- currItem->DashValues.clear();
-
- tmp = "";
- if (attrs.hasAttribute("NUMPO"))
- {
- currItem->PoLine.resize(attrs.valueAsUInt("NUMPO"));
- tmp = attrs.valueAsString("POCOOR");
- ScTextStream fp(&tmp, QIODevice::ReadOnly);
- uint numPo = attrs.valueAsUInt("NUMPO");
- for (uint cx=0; cx < numPo; ++cx)
- {
- fp >> xf;
- fp >> yf;
- currItem->PoLine.setPoint(cx, xf, yf);
- }
- }
- else
- currItem->PoLine.resize(0);
-
- tmp = "";
- if (attrs.hasAttribute("NUMCO"))
- {
- currItem->ContourLine.resize(attrs.valueAsUInt("NUMCO"));
- tmp = attrs.valueAsString("COCOOR");
- ScTextStream fp(&tmp, QIODevice::ReadOnly);
- uint numCo = attrs.valueAsUInt("NUMCO");
- for (uint cx=0; cx < numCo; ++cx)
- {
- fp >> xf;
- fp >> yf;
- currItem->ContourLine.setPoint(cx, xf, yf);
- }
- }
- else
- currItem->ContourLine = currItem->PoLine.copy();
-
- if (!currItem->asLine())
- currItem->Clip = FlattenPath(currItem->PoLine, currItem->Segments);
- else
- {
- int ph = static_cast<int>(qMax(1.0, currItem->lineWidth() / 2.0));
- currItem->Segments.clear();
- currItem->PoLine.resize(0);
- currItem->Clip.setPoints(4, -ph,-ph, static_cast<int>(currItem->width()+ph),-ph,
- static_cast<int>(currItem->width()+ph),static_cast<int>(currItem->height()+ph),
- -ph,static_cast<int>(currItem->height()+ph));
- currItem->setHeight(1.0);
- }
-
- if (currItem->asPathText())
- {
- currItem->updatePolyClip();
- currItem->Frame = true;
- }
- currItem->GrType = attrs.valueAsInt("GRTYP", 0);
- QString GrColor;
- QString GrColor2;
- int GrShade = 0;
- int GrShade2 = 0;
- if (currItem->GrType != 0)
- {
- if (currItem->GrType == 8)
- {
- currItem->setPattern( attrs.valueAsString("pattern", "") );
- double patternScaleX = attrs.valueAsDouble("pScaleX", 100.0);
- double patternScaleY = attrs.valueAsDouble("pScaleY", 100.0);
- double patternOffsetX = attrs.valueAsDouble("pOffsetX", 0.0);
- double patternOffsetY = attrs.valueAsDouble("pOffsetY", 0.0);
- double patternRotation = attrs.valueAsDouble("pRotation", 0.0);
- currItem->setPatternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
- }
- else
- {
- currItem->GrStartX = attrs.valueAsDouble("GRSTARTX", 0.0);
- currItem->GrStartY = attrs.valueAsDouble("GRSTARTY", 0.0);
- currItem->GrEndX = attrs.valueAsDouble("GRENDX", 0.0);
- currItem->GrEndY = attrs.valueAsDouble("GRENDY", 0.0);
- GrColor = attrs.valueAsString("GRCOLOR","");
- if (!GrColor.isEmpty())
- {
- GrColor2 = attrs.valueAsString("GRCOLOR2","");
- GrShade = attrs.valueAsInt("GRSHADE", 100);
- GrShade2 = attrs.valueAsInt("GRSHADE2", 100);
- }
- }
- }
- if ((currItem->GrType != 0) && (currItem->GrType != 8))
- {
- currItem->fill_gradient.clearStops();
- if ((!GrColor.isEmpty()) && (!GrColor2.isEmpty()))
- {
- if (currItem->GrType == 5)
- {
- if ((GrColor != CommonStrings::None) && (!GrColor.isEmpty()))
- currItem->SetQColor(&tmpc, GrColor, GrShade);
- currItem->fill_gradient.addStop(tmpc, 0.0, 0.5, 1.0, GrColor, GrShade);
- if ((GrColor2 != CommonStrings::None) && (!GrColor2.isEmpty()))
- currItem->SetQColor(&tmpc, GrColor2, GrShade2);
- currItem->fill_gradient.addStop(tmpc, 1.0, 0.5, 1.0, GrColor2, GrShade2);
- }
- else
- {
- if ((GrColor2 != CommonStrings::None) && (!GrColor2.isEmpty()))
- currItem->SetQColor(&tmpc, GrColor2, GrShade2);
- currItem->fill_gradient.addStop(tmpc, 0.0, 0.5, 1.0, GrColor2, GrShade2);
- if ((GrColor != CommonStrings::None) && (!GrColor.isEmpty()))
- currItem->SetQColor(&tmpc, GrColor, GrShade);
- currItem->fill_gradient.addStop(tmpc, 1.0, 0.5, 1.0, GrColor, GrShade);
- }
- }
-// currItem->updateGradientVectors();
- }
- //currItem->setRedrawBounding();
- //currItem->OwnPage = view->OnPage(currItem);
- UndoManager::instance()->setUndoEnabled(true);
- return currItem;
-}
-
-bool Scribus150Format::readLatexInfo(PageItem_LatexFrame* latexitem, ScXmlStreamReader& reader)
-{
- ScXmlStreamAttributes attrs = reader.scAttributes();
- QStringRef tagName = reader.name();
-
- latexitem->setConfigFile(attrs.valueAsString("ConfigFile"), true);
- latexitem->setDpi(attrs.valueAsInt("DPI"));
- latexitem->setUsePreamble(attrs.valueAsBool("USE_PREAMBLE"));
-
- QString formula;
- while (!reader.atEnd() && !reader.hasError())
- {
- reader.readNext();
- if (reader.isEndElement() && reader.name() == tagName)
- break;
- if (reader.isCharacters())
- formula += reader.text().toString();
- if (reader.isStartDocument() && reader.name() == "PROPERTY")
- {
- ScXmlStreamAttributes tAtt = reader.scAttributes();
- QString name = tAtt.valueAsString("name");
- QString value = tAtt.valueAsString("value");
- if (name.isEmpty()) continue;
- latexitem->editorProperties[name] = value;
- }
- }
- formula = formula.trimmed();
- latexitem->setFormula(formula, false);
-
- return !reader.hasError();
-}
-
-bool Scribus150Format::loadPage(const QString & fileName, int pageNumber, bool Mpage, QString renamedPageName)
-{
-// qDebug() << QString("loading page %2 from file '%1' from 1.3.x plugin").arg(fileName).arg(pageNumber);
- if (m_Doc==0 || m_AvailableFonts==0)
- {
- Q_ASSERT(m_Doc==0 || m_AvailableFonts==0);
- return false;
- }
- ParagraphStyle vg;
- struct ScribusDoc::BookMa bok;
- QMap<int, ScribusDoc::BookMa> bookmarks;
-
- Page* newPage = NULL;
-
- QString tmp;
- QMap<int,int> TableID;
- QList<PageItem*> TableItems;
- QMap<PageItem*, int> groupID;
- double pageX = 0, pageY = 0;
- bool newVersion = false;
- QMap<int,int> layerTrans;
- int maxLayer = 0, maxLevel = 0, a = 0;
-
- layerTrans.clear();
- uint layerCount=m_Doc->layerCount();
- for (uint la2 = 0; la2 < layerCount; ++la2)
- {
- maxLayer = qMax(m_Doc->Layers[la2].ID, maxLayer);
- maxLevel = qMax(m_Doc->Layers[la2].Level, maxLevel);
- }
-
- groupRemap.clear();
- itemRemap.clear();
- itemNext.clear();
- itemCount = 0;
- itemRemapM.clear();
- itemNextM.clear();
- itemCountM = 0;
- itemRemapF.clear();
- itemNextF.clear();
-
- QString f(readSLA(fileName));
- if (f.isEmpty())
- return false;
-
- QString fileDir = QFileInfo(fileName).absolutePath();
-
- bool firstElement = true;
- bool success = true;
-
- ScXmlStreamReader reader(f);
- ScXmlStreamAttributes attrs;
- while(!reader.atEnd() && !reader.hasError())
- {
- QXmlStreamReader::TokenType tType = reader.readNext();
- if (tType != QXmlStreamReader::StartElement)
- continue;
- QStringRef tagName = reader.name();
- attrs = reader.scAttributes();
-
- if (firstElement)
- {
- if (tagName != "SCRIBUSUTF8NEW")
- {
- success = false;
- break;
- }
- if (attrs.hasAttribute("Version"))
- newVersion = true;
- firstElement = false;
- }
-
- if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None)
- {
- success = readColor(m_Doc->PageColors, attrs);
- if (!success) break;
- }
- if (tagName == "JAVA")
- {
- QString name = attrs.valueAsString("NAME");
- if (!name.isEmpty())
- m_Doc->JavaScripts[name] = attrs.valueAsString("SCRIPT");
- }
- if (tagName == "LAYERS")
- {
- ScLayer newLayer;
- readLayers(newLayer, attrs);
- const ScLayer* la2 = m_Doc->Layers.layerByName(newLayer.Name);
- if (la2)
- layerTrans.insert(newLayer.ID, la2->ID);
- else
- {
- maxLayer++;
- maxLevel++;
- layerTrans.insert(newLayer.ID, maxLayer);
- newLayer.ID = maxLayer;
- newLayer.Level = maxLevel;
- m_Doc->Layers.append(newLayer);
- }
- }
- if (tagName == "Arrows")
- {
- success = readArrows(m_Doc, attrs);
- if (!success) break;
- }
- if(tagName == "MultiLine")
- {
- multiLine ml;
- QString mlName = attrs.valueAsString("Name");
- QString mlName2 = mlName;
- readMultiline(ml, reader);
- int copyC = 1;
- QMap<QString,multiLine>::ConstIterator mlit = m_Doc->MLineStyles.find(mlName2);
- if (mlit != m_Doc->MLineStyles.end() && ml != mlit.value())
- {
- while (m_Doc->MLineStyles.contains(mlName2))
- {
- mlName2 = QObject::tr("Copy #%1 of ").arg(copyC)+mlName;
- copyC++;
- }
- }
- m_Doc->MLineStyles.insert(mlName2, ml);
- }
- if (tagName == "Pattern")
- {
- success = readPattern(m_Doc, reader, fileDir);
- if (!success) break;
- }
- if (tagName == "Bookmark")
- {
- int bmElem = 0;
- struct ScribusDoc::BookMa bookmark;
- success = readBookMark(bookmark, bmElem, attrs);
- if (!success) break;
- bookmarks.insert(bmElem, bookmark);
- }
- if(tagName == "STYLE")
- {
- getStyle(vg, reader, NULL, m_Doc, true);
- }
- if (((tagName == "PAGE") || (tagName == "MASTERPAGE")) && (attrs.valueAsInt("NUM") == pageNumber))
- {
- if (Mpage && (tagName != "MASTERPAGE"))
- continue;
- a = m_Doc->currentPage()->pageNr();
- newPage = m_Doc->Pages->at(a);
- if (Mpage)
- {
- newPage->LeftPg = attrs.valueAsInt("LEFT", 0);
-
- if (!renamedPageName.isEmpty())
- newPage->setPageName(renamedPageName);
- else
- newPage->setPageName(attrs.valueAsString("NAM",""));
- }
- if (attrs.hasAttribute("Size"))
- newPage->m_pageSize = attrs.valueAsString("Size");
- if (attrs.hasAttribute("Orientation"))
- newPage->setOrientation(attrs.valueAsInt("Orientation"));
- if (attrs.hasAttribute("PAGEWIDTH"))
- newPage->setWidth( attrs.valueAsDouble("PAGEWIDTH") );
- else
- newPage->setWidth( attrs.valueAsDouble("PAGEWITH") );
- newPage->setHeight( attrs.valueAsDouble("PAGEHEIGHT") );
- newPage->setInitialHeight(newPage->height());
- newPage->setInitialWidth(newPage->width());
- newPage->initialMargins.Top = qMax(0.0, attrs.valueAsDouble("BORDERTOP"));
- newPage->initialMargins.Bottom = qMax(0.0, attrs.valueAsDouble("BORDERBOTTOM"));
- newPage->initialMargins.Left = qMax(0.0, attrs.valueAsDouble("BORDERLEFT"));
- newPage->initialMargins.Right = qMax(0.0, attrs.valueAsDouble("BORDERRIGHT"));
- newPage->marginPreset = attrs.valueAsInt("PRESET", 0);
- newPage->Margins.Top = newPage->initialMargins.Top;
- newPage->Margins.Bottom = newPage->initialMargins.Bottom;
- pageX = attrs.valueAsDouble( attrs.valueAsString("PAGEXPOS"));
- pageY = attrs.valueAsDouble( attrs.valueAsString("PAGEYPOS"));
- // guides reading
- tmp = "";
- newPage->guides.setHorizontalAutoGap(attrs.valueAsDouble("AGhorizontalAutoGap", 0.0));
- newPage->guides.setVerticalAutoGap(attrs.valueAsDouble("AGverticalAutoGap", 0.0));
- newPage->guides.setHorizontalAutoCount(attrs.valueAsInt("AGhorizontalAutoCount", 0));
- newPage->guides.setVerticalAutoCount(attrs.valueAsInt("AGverticalAutoCount", 0));
- newPage->guides.setHorizontalAutoRefer(attrs.valueAsInt("AGhorizontalAutoRefer", 0));
- newPage->guides.setVerticalAutoRefer(attrs.valueAsInt("AGverticalAutoRefer", 0));
- GuideManagerIO::readVerticalGuides(attrs.valueAsString("VerticalGuides"),
- newPage,
- GuideManagerCore::Standard,
- attrs.hasAttribute("NumVGuides"));
- GuideManagerIO::readHorizontalGuides(attrs.valueAsString("HorizontalGuides"),
- newPage,
- GuideManagerCore::Standard,
- attrs.hasAttribute("NumHGuides"));
- GuideManagerIO::readSelection(attrs.valueAsString("AGSelection"), newPage);
- }
- if ((tagName == "PAGEOBJECT") || (tagName == "MASTEROBJECT") || (tagName == "FRAMEOBJECT"))
- {
- if ((Mpage && tagName != "MASTEROBJECT") || (!Mpage && tagName == "MASTEROBJECT"))
- {
- // Go to end of node
- reader.readToElementEnd();
- continue;
- }
- if (attrs.valueAsInt("OwnPage") != pageNumber)
- {
- if (tagName == "PAGEOBJECT")
- itemRemap[itemCount++] = -1;
- else if (tagName == "MASTEROBJECT")
- itemRemapM[itemCountM++] = -1;
- reader.readToElementEnd();
- }
- else
- {
- // first of linked chain?
- if (tagName == "PAGEOBJECT")
- {
- itemRemap[itemCount++] = m_Doc->DocItems.count();
- if (attrs.valueAsInt("NEXTITEM") != -1)
- itemNext[m_Doc->DocItems.count()] = attrs.valueAsInt("NEXTITEM");
- }
- else if (tagName == "MASTEROBJECT")
- {
- itemRemapM[itemCountM++] = m_Doc->MasterItems.count();
- if (attrs.valueAsInt("NEXTITEM") != -1)
- itemNextM[m_Doc->MasterItems.count()] = attrs.valueAsInt("NEXTITEM");
- }
-
- ItemInfo itemInfo;
- success = readObject(m_Doc, reader, itemInfo, fileDir, true);
- if (!success) break;
-
- PageItem* newItem = itemInfo.item;
- newItem->moveBy(-pageX + newPage->xOffset(), - pageY + newPage->yOffset());
- newItem->OwnPage = m_Doc->currentPageNumber();
- if (tagName == "PAGEOBJECT")
- newItem->OnMasterPage = "";
-
- if (newItem->isTableItem)
- {
- TableItems.append(newItem);
- TableID.insert(itemInfo.ownLink, newItem->ItemNr);
- }
- if (newItem->isGroupControl)
- {
- groupID.insert(newItem, itemInfo.groupLastItem + newItem->ItemNr);
- }
- if (tagName == "FRAMEOBJECT")
- {
- m_Doc->FrameItems.append(m_Doc->Items->takeAt(newItem->ItemNr));
- newItem->ItemNr = m_Doc->FrameItems.count()-1;
- }
- }
- }
- }
-
- if (reader.hasError())
- return false;
-
- QMap<int, ScribusDoc::BookMa>::Iterator it;
- for (it = bookmarks.begin(); it != bookmarks.end(); ++it)
- {
- int elem = it.key();
- if (elem < m_Doc->Items->count())
- {
- ScribusDoc::BookMa bookmark = it.value();
- bookmark.PageObject = m_Doc->Items->at(elem);
- m_Doc->BookMarks.append( bookmark );
- }
- }
-
- if (TableItems.count() != 0)
- {
- for (int ttc = 0; ttc < TableItems.count(); ++ttc)
- {
- PageItem* ta = TableItems.at(ttc);
- if (ta->TopLinkID != -1)
- ta->TopLink = m_Doc->Items->at(TableID[ta->TopLinkID]);
- else
- ta->TopLink = 0;
- if (ta->LeftLinkID != -1)
- ta->LeftLink = m_Doc->Items->at(TableID[ta->LeftLinkID]);
- else
- ta->LeftLink = 0;
- if (ta->RightLinkID != -1)
- ta->RightLink = m_Doc->Items->at(TableID[ta->RightLinkID]);
- else
- ta->RightLink = 0;
- if (ta->BottomLinkID != -1)
- ta->BottomLink = m_Doc->Items->at(TableID[ta->BottomLinkID]);
- else
- ta->BottomLink = 0;
- }
- }
-
- if (groupID.count() != 0)
- {
- QMap<PageItem*, int>::Iterator it;
- for (it = groupID.begin(); it != groupID.end(); ++it)
- {
- it.key()->groupsLastItem = m_Doc->Items->at(it.value());
- }
- }
-
- // reestablish textframe links
- if (itemNext.count() != 0 && !Mpage)
- {
- QMap<int,int>::Iterator lc;
- for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
- {
- if (itemRemap[lc.value()] >= 0)
- {
- if ((lc.key() < m_Doc->Items->count()) && (itemRemap[lc.value()] < m_Doc->Items->count()))
- {
- PageItem * Its = m_Doc->DocItems.at(lc.key());
- PageItem * Itn = m_Doc->DocItems.at(itemRemap[lc.value()]);
- if (Itn->prevInChain() || Its->nextInChain())
- {
- qDebug() << "scribus150format: corruption in linked textframes detected";
- continue;
- }
- Its->link(Itn);
- }
- }
- }
- }
- else if (itemNextM.count() != 0 && Mpage)
- {
- QMap<int,int>::Iterator lc;
- for (lc = itemNextM.begin(); lc != itemNextM.end(); ++lc)
- {
- if (itemRemapM[lc.value()] >= 0)
- {
- if ((lc.key() < m_Doc->MasterItems.count()) && (itemRemapM[lc.value()] < m_Doc->MasterItems.count()))
- {
- PageItem * Its = m_Doc->MasterItems.at(lc.key());
- PageItem * Itn = m_Doc->MasterItems.at(itemRemapM[lc.value()]);
- if (Itn->prevInChain() || Its->nextInChain())
- {
- qDebug() << "scribus150format: corruption in linked textframes detected";
- continue;
- }
- Its->link(Itn);
- }
- }
- }
- }
-
- // reestablish first/lastAuto
- m_Doc->FirstAuto = m_Doc->LastAuto;
- if (m_Doc->LastAuto)
- {
- while (m_Doc->LastAuto->nextInChain())
- m_Doc->LastAuto = m_Doc->LastAuto->nextInChain();
- while (m_Doc->FirstAuto->prevInChain())
- m_Doc->FirstAuto = m_Doc->FirstAuto->prevInChain();
- }
-
- return true;
-}
-
-void Scribus150Format::getStyle(ParagraphStyle& style, ScXmlStreamReader& reader, StyleSet<ParagraphStyle> *tempStyles, ScribusDoc* doc, bool fl)
-{
- bool fou(false);
- QString tmpf, tmV;
- const StyleSet<ParagraphStyle> * docParagraphStyles = tempStyles? tempStyles : & doc->paragraphStyles();
- PrefsManager* prefsManager = PrefsManager::instance();
- readParagraphStyle(doc, reader, style, prefsManager->appPrefs.AvailFonts);
- for (int xx=0; xx<docParagraphStyles->count(); ++xx)
- {
- if (style.name() == (*docParagraphStyles)[xx].name())
- {
- if (style.equiv((*docParagraphStyles)[xx]))
- {
- fou = true;
- }
- else
- {
- style.setName("Copy of "+(*docParagraphStyles)[xx].name());
- fou = false;
- }
- break;
- }
- }
- if (!fou && fl)
- {
- for (int xx=0; xx< docParagraphStyles->count(); ++xx)
- {
- if (style.equiv((*docParagraphStyles)[xx]))
- {
- style.setName((*docParagraphStyles)[xx].name());
- fou = true;
- break;
- }
- }
- }
- if (!fou)
- {
- if (tempStyles)
- tempStyles->create(style);
- else
- {
- StyleSet<ParagraphStyle> tmp;
- tmp.create(style);
- doc->redefineStyles(tmp, false);
- }
- }
-}
-
-bool Scribus150Format::readStyles(const QString& fileName, ScribusDoc* doc, StyleSet<ParagraphStyle> &docParagraphStyles)
-{
- ParagraphStyle vg;
- QString tmpf;
- QString f (readSLA(fileName));
- if (f.isEmpty())
- return false;
-
- bool firstElement = true;
- bool success = true;
-
- ScXmlStreamReader reader(f);
- ScXmlStreamAttributes attrs;
- while(!reader.atEnd() && !reader.hasError())
- {
- QXmlStreamReader::TokenType tType = reader.readNext();
- if (tType != QXmlStreamReader::StartElement)
- continue;
- QStringRef tagName = reader.name();
- if (firstElement)
- {
- if (tagName != "SCRIBUSUTF8NEW")
- {
- success = false;
- break;
- }
- firstElement = false;
- continue;
- }
- if (tagName == "STYLE")
- {
- getStyle(vg, reader, &docParagraphStyles, doc, false);
- }
- }
- return success;
-}
-
-bool Scribus150Format::readCharStyles(const QString& fileName, ScribusDoc* doc, StyleSet<CharStyle> &docCharStyles)
-{
- CharStyle cstyle;
- QString f(readSLA(fileName));
- if (f.isEmpty())
- return false;
- bool firstElement = true;
- bool success = true;
-
- ScXmlStreamReader reader(f);
- ScXmlStreamAttributes attrs;
- while(!reader.atEnd() && !reader.hasError())
- {
- QXmlStreamReader::TokenType tType = reader.readNext();
- if (tType != QXmlStreamReader::StartElement)
- continue;
- QStringRef tagName = reader.name();
- if (firstElement)
- {
- if (tagName != "SCRIBUSUTF8NEW")
- {
- success = false;
- break;
- }
- firstElement = false;
- continue;
- }
- if (tagName == "CHARSTYLE")
- {
- readCharacterStyleAttrs(doc, attrs, cstyle);
- docCharStyles.create(cstyle);
- }
- }
- return true;
-}
-
-bool Scribus150Format::readLineStyles(const QString& fileName, QMap<QString,multiLine> *styles)
-{
- QString f(readSLA(fileName));
- if (f.isEmpty())
- return false;
- bool firstElement = true;
- bool success = true;
-
- ScXmlStreamReader reader(f);
- ScXmlStreamAttributes attrs;
- while(!reader.atEnd() && !reader.hasError())
- {
- QXmlStreamReader::TokenType tType = reader.readNext();
- if (tType != QXmlStreamReader::StartElement)
- continue;
- QStringRef tagName = reader.name();
- if (firstElement)
- {
- if (tagName != "SCRIBUSUTF8NEW")
- {
- success = false;
- break;
- }
- firstElement = false;
- continue;
- }
- if (tagName == "MultiLine")
- {
- multiLine ml;
- attrs = reader.scAttributes();
- QString mlName = attrs.valueAsString("Name");
- QString mlName2 = mlName;
- readMultiline(ml, reader);
- int copyC = 1;
- QMap<QString,multiLine>::ConstIterator mlit = styles->find(mlName2);
- if (mlit != styles->end() && ml != mlit.value())
- {
- while (styles->contains(mlName2))
- {
- mlName2 = tr("Copy #%1 of ").arg(copyC)+mlName;
- copyC++;
- }
- }
- styles->insert(mlName2, ml);
- }
- }
- return true;
-}
-
-bool Scribus150Format::readColors(const QString& fileName, ColorList & colors)
-{
- QString f(readSLA(fileName));
- if (f.isEmpty())
- return false;
- bool firstElement = true;
- bool success = true;
-
- ScXmlStreamReader reader(f);
- ScXmlStreamAttributes attrs;
- while(!reader.atEnd() && !reader.hasError())
- {
- QXmlStreamReader::TokenType tType = reader.readNext();
- if (tType != QXmlStreamReader::StartElement)
- continue;
- QStringRef tagName = reader.name();
- if (firstElement)
- {
- if (tagName != "SCRIBUSUTF8NEW")
- {
- success = false;
- break;
- }
- firstElement = false;
- continue;
- }
- if(tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None)
- {
- attrs = reader.scAttributes();
- if (attrs.valueAsString("NAME") != CommonStrings::None)
- {
- readColor(colors, attrs);
- }
- }
- }
- return true;
-}
-
-bool Scribus150Format::readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames)
-{
- QString pageName;
- int counter = 0;
- int counter2 = 0;
- QString f(readSLA(fileName));
- if (f.isEmpty())
- return false;
- bool firstElement = true;
- bool success = true;
-
- ScXmlStreamReader reader(f);
- ScXmlStreamAttributes attrs;
- while(!reader.atEnd() && !reader.hasError())
- {
- QXmlStreamReader::TokenType tType = reader.readNext();
- if (tType != QXmlStreamReader::StartElement)
- continue;
- QStringRef tagName = reader.name();
- if (firstElement)
- {
- if (tagName != "SCRIBUSUTF8NEW")
- {
- success = false;
- break;
- }
- firstElement = false;
- continue;
- }
- if(tagName == "PAGE")
- counter++;
- if(tagName == "MASTERPAGE")
- {
- pageName = reader.scAttributes().valueAsString("NAM");
- if (!pageName.isEmpty())
- {
- counter2++;
- masterPageNames.append(pageName);
- }
- }
- }
- *num1 = counter;
- *num2 = counter2;
- return success;
-}
-
-
-
-
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+#include "scribus150format.h"
+#include "scribus150formatimpl.h"
+
+#include "../../formatidlist.h"
+#include "commonstrings.h"
+#include "ui/missing.h"
+#include "hyphenator.h"
+#include "pageitem_latexframe.h"
+#include "prefsmanager.h"
+#include "scclocale.h"
+#include "scconfig.h"
+#include "sccolorengine.h"
+#include "scpattern.h"
+#include "scribuscore.h"
+#include "scribusdoc.h"
+#include "scribusview.h"
+#include "sctextstream.h"
+#include "scxmlstreamreader.h"
+#include "undomanager.h"
+#include "units.h"
+#include "util.h"
+#include "util_math.h"
+#include "util_color.h"
+#include "scgzfile.h"
+#include "scpattern.h"
+#ifdef HAVE_OSG
+ #include "pageitem_osgframe.h"
+#endif
+#include <QCursor>
+// #include <QDebug>
+#include <QFileInfo>
+#include <QList>
+#include <QByteArray>
+#include <QApplication>
+
+
+// See scplugin.h and pluginmanager.{cpp,h} for detail on what these methods
+// do. That documentatation is not duplicated here.
+// Please don't implement the functionality of your plugin here; do that
+// in scribus150formatimpl.h and scribus150formatimpl.cpp .
+
+Scribus150Format::Scribus150Format() :
+ LoadSavePlugin()
+{
+ // Set action info in languageChange, so we only have to do
+ // it in one place. This includes registering file formats.
+ languageChange();
+}
+
+Scribus150Format::~Scribus150Format()
+{
+ unregisterAll();
+};
+
+void Scribus150Format::languageChange()
+{
+ //(Re)register file formats.
+ unregisterAll();
+ registerFormats();
+}
+
+const QString Scribus150Format::fullTrName() const
+{
+ return QObject::tr("Scribus 1.3.4+ Support");
+}
+
+const ScActionPlugin::AboutData* Scribus150Format::getAboutData() const
+{
+ AboutData* about = new AboutData;
+ Q_CHECK_PTR(about);
+ about->authors = QString::fromUtf8(
+ "Franz Schmid <franz at scribus.info>, "
+ "The Scribus Team");
+ about->shortDescription = tr("Scribus 1.3.4+ File Format Support");
+ about->description = tr("Allows Scribus to read Scribus 1.3.4 and higher formatted files.");
+ // about->version
+ // about->releaseDate
+ // about->copyright
+ about->license = "GPL";
+ return about;
+}
+
+void Scribus150Format::deleteAboutData(const AboutData* about) const
+{
+ Q_ASSERT(about);
+ delete about;
+}
+
+void Scribus150Format::registerFormats()
+{
+ FileFormat fmt(this);
+ fmt.trName = tr("Scribus 1.5.0+ Document");
+ fmt.formatId = FORMATID_SLA150IMPORT;
+ fmt.load = true;
+ fmt.save = true;
+ fmt.filter = fmt.trName + " (*.sla *.SLA *.sla.gz *.SLA.GZ *.scd *.SCD *.scd.gz *.SCD.GZ)";
+ fmt.nameMatch = QRegExp("\\.(sla|scd)(\\.gz)?", Qt::CaseInsensitive);
+ fmt.mimeTypes = QStringList();
+ fmt.mimeTypes.append("application/x-scribus");
+ fmt.priority = 64;
+ registerFormat(fmt);
+}
+
+bool Scribus150Format::fileSupported(QIODevice* /* file */, const QString & fileName) const
+{
+ QByteArray docBytes("");
+ if(fileName.right(2) == "gz")
+ {
+ if (!ScGzFile::readFromFile(fileName, docBytes, 4096))
+ {
+ // FIXME: Needs better error return
+ return false;
+ }
+ }
+ else
+ {
+ // Not gzip encoded, just load it
+ loadRawText(fileName, docBytes);
+ }
+// if (docBytes.left(16) == "<SCRIBUSUTF8NEW " && docBytes.left(35).contains("Version=\"1.3.4"))
+// return true;
+ int startElemPos = docBytes.left(512).indexOf("<SCRIBUSUTF8NEW ");
+ return startElemPos >= 0 && ((docBytes.mid(startElemPos, 64).indexOf("Version=\"1.5.0") >= 0));
+}
+
+QString Scribus150Format::readSLA(const QString & fileName)
+{
+ QByteArray docBytes("");
+ if(fileName.right(2) == "gz")
+ {
+ if (!ScGzFile::readFromFile(fileName, docBytes))
+ {
+ // FIXME: Needs better error return
+ return false;
+ }
+ }
+ else
+ {
+ // Not gzip encoded, just load it
+ loadRawText(fileName, docBytes);
+ }
+ QString docText("");
+ int startElemPos = docBytes.left(512).indexOf("<SCRIBUSUTF8NEW ");
+ if (startElemPos >= 0 && ((docBytes.mid(startElemPos, 64).indexOf("Version=\"1.5.0") >= 0)))
+ docText = QString::fromUtf8(docBytes);
+ else
+ return QString::null;
+ if (docText.endsWith(QChar(10)) || docText.endsWith(QChar(13)))
+ docText.truncate(docText.length()-1);
+ return docText;
+}
+
+void Scribus150Format::getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QList<ScFace> &getDummyScFaces)
+{
+ getNewReplacement=false;
+ getReplacedFonts.clear();
+}
+
+bool Scribus150Format::loadFile(const QString & fileName, const FileFormat & /* fmt */, int /* flags */, int /* index */)
+{
+ if (m_Doc==0 || m_AvailableFonts==0)
+ {
+ Q_ASSERT(m_Doc==0 || m_AvailableFonts==0);
+ return false;
+ }
+ ParagraphStyle vg;
+ struct ScribusDoc::BookMa bok;
+ QMap<int, ScribusDoc::BookMa> bookmarks;
+
+ bool newVersion = false;
+
+ QMap<int,int> TableID;
+ QMap<int,int> TableIDM;
+ QMap<int,int> TableIDF;
+ QList<PageItem*> TableItems;
+ QList<PageItem*> TableItemsM;
+ QList<PageItem*> TableItemsF;
+ QMap<PageItem*, int> groupID;
+ QMap<PageItem*, int> groupIDM;
+ QMap<PageItem*, int> groupIDF;
+
+ QString f(readSLA(fileName));
+ if (f.isEmpty())
+ return false;
+ QString fileDir = QFileInfo(fileName).absolutePath();
+ int firstPage = 0;
+ int layerToSetActive = 0;
+ ScColor lf = ScColor();
+
+ if (m_mwProgressBar!=0)
+ {
+ m_mwProgressBar->setMaximum(f.length());
+ m_mwProgressBar->setValue(0);
+ }
+ // Stop autosave timer,it will be restarted only if doc has autosave feature is enabled
+ if (m_Doc->autoSaveTimer->isActive())
+ m_Doc->autoSaveTimer->stop();
+
+ groupRemap.clear();
+ itemRemap.clear();
+ itemNext.clear();
+ itemCount = 0;
+ itemRemapM.clear();
+ itemNextM.clear();
+ itemCountM = 0;
+ itemRemapF.clear();
+ itemNextF.clear();
+
+ TableItems.clear();
+ TableID.clear();
+ TableItemsM.clear();
+ TableIDM.clear();
+ TableItemsF.clear();
+ TableIDF.clear();
+
+ m_Doc->GroupCounter = 1;
+ m_Doc->LastAuto = 0;
+ m_Doc->PageColors.clear();
+ m_Doc->Layers.clear();
+
+ bool firstElement = true;
+ bool success = true;
+ bool hasPageSets = false;
+ int progress = 0;
+
+ ScXmlStreamReader reader(f);
+ ScXmlStreamAttributes attrs;
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ QXmlStreamReader::TokenType tType = reader.readNext();
+ if (tType != QXmlStreamReader::StartElement)
+ continue;
+ QStringRef tagName = reader.name();
+ attrs = reader.scAttributes();
+
+ if (m_mwProgressBar != 0)
+ {
+ int newProgress = qRound(reader.characterOffset() / (double) f.length() * 100);
+ if (newProgress != progress)
+ {
+ m_mwProgressBar->setValue(reader.characterOffset());
+ progress = newProgress;
+ }
+ }
+
+ if (firstElement)
+ {
+ if (tagName != "SCRIBUSUTF8NEW")
+ {
+ success = false;
+ break;
+ }
+ if (attrs.hasAttribute("Version"))
+ newVersion = true;
+ firstElement = false;
+ }
+ if (tagName == "DOCUMENT")
+ {
+ readDocAttributes(m_Doc, attrs);
+ layerToSetActive = attrs.valueAsInt("ALAYER", 0);
+ if (m_Doc->currentPageLayout == 0)
+ firstPage = 0;
+ else
+ {
+ if (attrs.valueAsInt("FIRSTLEFT", 0) == 1)
+ firstPage = 0;
+ else
+ firstPage = 1;
+ }
+ if (attrs.hasAttribute("currentProfile"))
+ {
+ m_Doc->checkerProfiles.clear();
+ m_Doc->curCheckProfile = attrs.valueAsString("currentProfile");
+ }
+ }
+ if (tagName == "CheckProfile")
+ {
+ success = readCheckProfile(m_Doc, attrs);
+ if (!success) break;
+ }
+ if (tagName == "PageSets")
+ {
+ success = readPageSets(m_Doc, reader);
+ if (!success) break;
+ hasPageSets = true;
+ }
+ // 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
+ if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None)
+ {
+ success = readColor(m_Doc->PageColors, attrs);
+ if (!success) break;
+ }
+ if (tagName == "STYLE")
+ {
+ readParagraphStyle(m_Doc, reader, vg, *m_AvailableFonts);
+ StyleSet<ParagraphStyle>tmp;
+ tmp.create(vg);
+ m_Doc->redefineStyles(tmp, false);
+ }
+ if (tagName == "CHARSTYLE")
+ {
+ readParagraphStyle(m_Doc, reader, vg, *m_AvailableFonts);
+ StyleSet<CharStyle> temp;
+ temp.create(vg.charStyle());
+ m_Doc->redefineCharStyles(temp, false);
+ }
+ if (tagName == "JAVA")
+ {
+ QString name = attrs.valueAsString("NAME");
+ if (!name.isEmpty())
+ m_Doc->JavaScripts[name] = attrs.valueAsString("SCRIPT");
+ }
+ if (tagName == "LAYERS")
+ {
+ ScLayer newLayer;
+ readLayers(newLayer, attrs);
+ m_Doc->Layers.append(newLayer);
+ }
+ if (tagName == "Arrows")
+ {
+ success = readArrows(m_Doc, attrs);
+ if (!success) break;
+ }
+ if (tagName == "MultiLine")
+ {
+ multiLine ml;
+ QString mlName = attrs.valueAsString("Name");
+ success = readMultiline(ml, reader);
+ if (!success) break;
+ if (!mlName.isEmpty())
+ {
+ m_Doc->MLineStyles.insert(mlName, ml);
+ }
+ }
+ if (tagName == "Bookmark")
+ {
+ int bmElem = 0;
+ struct ScribusDoc::BookMa bookmark;
+ success = readBookMark(bookmark, bmElem, attrs);
+ if (!success) break;
+ bookmarks.insert(bmElem, bookmark);
+ }
+ if (tagName == "PDF")
+ {
+ success = readPDFOptions(m_Doc, reader);
+ if (!success) break;
+ }
+ if (tagName == "Printer")
+ {
+ success = readPrinterOptions(m_Doc, reader);
+ if (!success) break;
+ }
+ if (tagName == "DocItemAttributes")
+ {
+ success = readDocItemAttributes(m_Doc, reader);
+ if (!success) break;
+ }
+ if (tagName == "TablesOfContents")
+ {
+ success = readTableOfContents(m_Doc, reader);
+ if (!success) break;
+ }
+ if (tagName == "Sections")
+ {
+ success = readSections(m_Doc, reader);
+ if (!success) break;
+ }
+ if (tagName == "HYPHEN")
+ {
+ success = readHyphen(m_Doc, reader);
+ if (!success) break;
+ }
+ if (tagName == "PAGE" || tagName == "MASTERPAGE")
+ {
+ success = readPage(m_Doc, reader);
+ if (!success) break;
+ }
+ if (tagName == "PAGEOBJECT" || tagName == "MASTEROBJECT" || tagName == "FRAMEOBJECT")
+ {
+ ItemInfo itemInfo;
+ success = readObject(m_Doc, reader, itemInfo, fileDir, false);
+ if (!success) break;
+
+ // first of linked chain?
+ if (tagName == "PAGEOBJECT")
+ {
+ if (itemInfo.nextItem != -1)
+ itemNext[itemInfo.item->ItemNr] = itemInfo.nextItem;
+ }
+ else if (tagName == "MASTEROBJECT")
+ {
+ if (itemInfo.nextItem != -1)
+ itemNextM[itemInfo.item->ItemNr] = itemInfo.nextItem;
+ }
+ /* not sure if we want that...
+ else if (tagName == "FRAMEOBJECT")
+ {
+ if (itemInfo.nextItem != -1)
+ itemNextF[itemInfo.item->ItemNr] = itemInfo.nextItem;
+ }*/
+
+ if (itemInfo.item->isTableItem)
+ {
+ if (tagName == "PAGEOBJECT")
+ {
+ TableItems.append(itemInfo.item);
+ TableID.insert(itemInfo.ownLink, itemInfo.item->ItemNr);
+ }
+ else if (tagName == "FRAMEOBJECT")
+ {
+ TableItemsF.append(itemInfo.item);
+ TableIDF.insert(itemInfo.ownLink, itemInfo.item->ItemNr);
+ }
+ else
+ {
+ TableItemsM.append(itemInfo.item);
+ TableIDM.insert(itemInfo.ownLink, itemInfo.item->ItemNr);
+ }
+ }
+ if (itemInfo.item->isGroupControl)
+ {
+ if (tagName == "PAGEOBJECT")
+ groupID.insert(itemInfo.item, itemInfo.groupLastItem + itemInfo.item->ItemNr);
+ else if (tagName == "FRAMEOBJECT")
+ groupIDF.insert(itemInfo.item, itemInfo.groupLastItem + itemInfo.item->ItemNr);
+ else
+ groupIDM.insert(itemInfo.item, itemInfo.groupLastItem + itemInfo.item->ItemNr);
+ }
+ }
+ if (tagName == "Pattern")
+ {
+ success = readPattern(m_Doc, reader, fileDir);
+ if (!success) break;
+ }
+ }
+
+ if (reader.hasError())
+ return false;
+
+ QMap<int, ScribusDoc::BookMa>::Iterator it;
+ for (it = bookmarks.begin(); it != bookmarks.end(); ++it)
+ {
+ int elem = it.key();
+ if (elem < m_Doc->Items->count())
+ {
+ ScribusDoc::BookMa bookmark = it.value();
+ bookmark.PageObject = m_Doc->Items->at(elem);
+ m_Doc->BookMarks.append( bookmark );
+ }
+ }
+
+ if (TableItemsF.count() != 0)
+ {
+ for (int ttc = 0; ttc < TableItemsF.count(); ++ttc)
+ {
+ PageItem* ta = TableItemsF.at(ttc);
+ if (ta->TopLinkID != -1)
+ ta->TopLink = m_Doc->FrameItems.at(TableIDF[ta->TopLinkID]);
+ else
+ ta->TopLink = 0;
+ if (ta->LeftLinkID != -1)
+ ta->LeftLink = m_Doc->FrameItems.at(TableIDF[ta->LeftLinkID]);
+ else
+ ta->LeftLink = 0;
+ if (ta->RightLinkID != -1)
+ ta->RightLink = m_Doc->FrameItems.at(TableIDF[ta->RightLinkID]);
+ else
+ ta->RightLink = 0;
+ if (ta->BottomLinkID != -1)
+ ta->BottomLink = m_Doc->FrameItems.at(TableIDF[ta->BottomLinkID]);
+ else
+ ta->BottomLink = 0;
+ }
+ }
+ if (TableItemsM.count() != 0)
+ {
+ for (int ttc = 0; ttc < TableItemsM.count(); ++ttc)
+ {
+ PageItem* ta = TableItemsM.at(ttc);
+ if (ta->TopLinkID != -1)
+ ta->TopLink = m_Doc->MasterItems.at(TableIDM[ta->TopLinkID]);
+ else
+ ta->TopLink = 0;
+ if (ta->LeftLinkID != -1)
+ ta->LeftLink = m_Doc->MasterItems.at(TableIDM[ta->LeftLinkID]);
+ else
+ ta->LeftLink = 0;
+ if (ta->RightLinkID != -1)
+ ta->RightLink = m_Doc->MasterItems.at(TableIDM[ta->RightLinkID]);
+ else
+ ta->RightLink = 0;
+ if (ta->BottomLinkID != -1)
+ ta->BottomLink = m_Doc->MasterItems.at(TableIDM[ta->BottomLinkID]);
+ else
+ ta->BottomLink = 0;
+ }
+ }
+ if (TableItems.count() != 0)
+ {
+ for (int ttc = 0; ttc < TableItems.count(); ++ttc)
+ {
+ PageItem* ta = TableItems.at(ttc);
+ if (ta->TopLinkID != -1)
+ ta->TopLink = m_Doc->Items->at(TableID[ta->TopLinkID]);
+ else
+ ta->TopLink = 0;
+ if (ta->LeftLinkID != -1)
+ ta->LeftLink = m_Doc->Items->at(TableID[ta->LeftLinkID]);
+ else
+ ta->LeftLink = 0;
+ if (ta->RightLinkID != -1)
+ ta->RightLink = m_Doc->Items->at(TableID[ta->RightLinkID]);
+ else
+ ta->RightLink = 0;
+ if (ta->BottomLinkID != -1)
+ ta->BottomLink = m_Doc->Items->at(TableID[ta->BottomLinkID]);
+ else
+ ta->BottomLink = 0;
+ }
+ }
+ if (groupIDF.count() != 0)
+ {
+ QMap<PageItem*, int>::Iterator it;
+ for (it = groupIDF.begin(); it != groupIDF.end(); ++it)
+ {
+ it.key()->groupsLastItem = m_Doc->FrameItems.at(it.value());
+ }
+ }
+ if (groupID.count() != 0)
+ {
+ QMap<PageItem*, int>::Iterator it;
+ for (it = groupID.begin(); it != groupID.end(); ++it)
+ {
+ it.key()->groupsLastItem = m_Doc->DocItems.at(it.value());
+ }
+ }
+ if (groupIDM.count() != 0)
+ {
+ QMap<PageItem*, int>::Iterator it;
+ for (it = groupIDM.begin(); it != groupIDM.end(); ++it)
+ {
+ it.key()->groupsLastItem = m_Doc->MasterItems.at(it.value());
+ }
+ }
+ //CB Add this in to set this in the file in memory. Its saved, why not load it.
+ //Will of course be replaced by per page settings although we still probably need a document default
+ if (!hasPageSets)
+ {
+ m_Doc->pageSets[m_Doc->currentPageLayout].FirstPage = firstPage;
+// m_Doc->pageSets[m_Doc->currentPageLayout].GapHorizontal = dc.attribute("GapHorizontal", "0").toDouble();
+// m_Doc->pageSets[m_Doc->currentPageLayout].GapVertical = 0.0;
+// m_Doc->pageSets[m_Doc->currentPageLayout].GapBelow = dc.attribute("GapVertical", "40").toDouble();
+ }
+ m_Doc->setActiveLayer(layerToSetActive);
+ m_Doc->setMasterPageMode(false);
+ m_Doc->reformPages();
+
+ if (m_Doc->Layers.count() == 0)
+ m_Doc->Layers.newLayer( QObject::tr("Background") );
+
+ // reestablish textframe links
+ if (itemNext.count() != 0)
+ {
+ QMap<int,int>::Iterator lc;
+ for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
+ {
+ if (lc.value() >= 0)
+ {
+ PageItem * Its = m_Doc->DocItems.at(lc.key());
+ PageItem * Itn = m_Doc->DocItems.at(lc.value());
+ if (Itn->prevInChain() || Its->nextInChain())
+ {
+ qDebug() << "scribus150format: corruption in linked textframes detected";
+ continue;
+ }
+ Its->link(Itn);
+ }
+ }
+ }
+
+ if (itemNextM.count() != 0)
+ {
+ QMap<int,int>::Iterator lc;
+ for (lc = itemNextM.begin(); lc != itemNextM.end(); ++lc)
+ {
+ if (lc.value() >= 0)
+ {
+ PageItem * Its = m_Doc->MasterItems.at(lc.key());
+ PageItem * Itn = m_Doc->MasterItems.at(lc.value());
+ if (Itn->prevInChain() || Its->nextInChain())
+ {
+ qDebug() << "scribus150format: corruption in linked textframes detected";
+ continue;
+ }
+ Its->link(Itn);
+ }
+ }
+ }
+
+ // reestablish first/lastAuto
+ m_Doc->FirstAuto = m_Doc->LastAuto;
+ if (m_Doc->LastAuto)
+ {
+ while (m_Doc->LastAuto->nextInChain())
+ m_Doc->LastAuto = m_Doc->LastAuto->nextInChain();
+ while (m_Doc->FirstAuto->prevInChain())
+ m_Doc->FirstAuto = m_Doc->FirstAuto->prevInChain();
+ }
+
+ // start auto save timer if needed
+ if (m_Doc->AutoSave && ScCore->usingGUI())
+ m_Doc->autoSaveTimer->start(m_Doc->AutoSaveTime);
+
+ if (m_mwProgressBar!=0)
+ m_mwProgressBar->setValue(reader.characterOffset());
+ return true;
+// return false;
+}
+
+// Low level plugin API
+int scribus150format_getPluginAPIVersion()
+{
+ return PLUGIN_API_VERSION;
+}
+
+ScPlugin* scribus150format_getPlugin()
+{
+ Scribus150Format* plug = new Scribus150Format();
+ Q_CHECK_PTR(plug);
+ return plug;
+}
+
+void scribus150format_freePlugin(ScPlugin* plugin)
+{
+ Scribus150Format* plug = dynamic_cast<Scribus150Format*>(plugin);
+ Q_ASSERT(plug);
+ delete plug;
+}
+
+
+namespace {
+ const int NOVALUE = -16000;
+
+ void fixLegacyCharStyle(CharStyle& cstyle)
+ {
+ if (! cstyle.font().usable())
+ cstyle.resetFont();
+ if (cstyle.fontSize() <= -16000 / 10)
+ cstyle.resetFontSize();
+// if (cstyle.effects() == 65535)
+// cstyle.resetEffects();
+ if (cstyle.fillColor().isEmpty())
+ cstyle.resetFillColor();
+ if (cstyle.fillShade() <= -16000)
+ cstyle.resetFillShade();
+ if (cstyle.strokeColor().isEmpty())
+ cstyle.resetStrokeColor();
+ if (cstyle.strokeShade() <= -16000)
+ cstyle.resetStrokeShade();
+ if (cstyle.shadowXOffset() <= -16000 / 10)
+ cstyle.resetShadowXOffset();
+ if (cstyle.shadowYOffset() <= -16000 / 10)
+ cstyle.resetShadowYOffset();
+ if (cstyle.outlineWidth() <= -16000 / 10)
+ cstyle.resetOutlineWidth();
+ if (cstyle.underlineOffset() <= -16000 / 10)
+ cstyle.resetUnderlineOffset();
+ if (cstyle.underlineWidth() <= -16000 / 10)
+ cstyle.resetUnderlineWidth();
+ if (cstyle.strikethruOffset() <= -16000 / 10)
+ cstyle.resetStrikethruOffset();
+ if (cstyle.strikethruWidth() <= -16000 / 10)
+ cstyle.resetStrikethruWidth();
+ if (cstyle.scaleH() <= -16000 / 10)
+ cstyle.resetScaleH();
+ if (cstyle.scaleV() <= -16000 / 10)
+ cstyle.resetScaleV();
+ if (cstyle.baselineOffset() <= -16000 / 10)
+ cstyle.resetBaselineOffset();
+ if (cstyle.tracking() <= -16000 / 10)
+ cstyle.resetTracking();
+ }
+
+ void fixLegacyParStyle(ParagraphStyle& pstyle)
+ {
+ if (pstyle.lineSpacing() <= -16000)
+ pstyle.resetLineSpacing();
+ if (pstyle.leftMargin() <= -16000)
+ pstyle.resetLeftMargin();
+ if (pstyle.rightMargin() <= -16000)
+ pstyle.resetRightMargin();
+ if (pstyle.firstIndent() <= -16000)
+ pstyle.resetFirstIndent();
+ if (pstyle.alignment() < 0)
+ pstyle.resetAlignment();
+ if (pstyle.gapBefore() <= -16000)
+ pstyle.resetGapBefore();
+ if (pstyle.gapAfter() <= -16000)
+ pstyle.resetGapAfter();
+ if (pstyle.dropCapLines() < 0)
+ pstyle.resetDropCapLines();
+ if (pstyle.dropCapOffset() <= -16000)
+ pstyle.resetDropCapOffset();
+ fixLegacyCharStyle(pstyle.charStyle());
+ }
+
+}// namespace
+
+void Scribus150Format::readDocAttributes(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
+{
+ m_Doc->m_pageSize = attrs.valueAsString("PAGESIZE");
+ m_Doc->PageOri = attrs.valueAsInt("ORIENTATION", 0);
+ m_Doc->FirstPnum = attrs.valueAsInt("FIRSTNUM", 1);
+ m_Doc->currentPageLayout = attrs.valueAsInt("BOOK", 0);
+
+ m_Doc->setUsesAutomaticTextFrames( attrs.valueAsInt("AUTOTEXT") );
+ m_Doc->PageSp = attrs.valueAsInt("AUTOSPALTEN");
+ m_Doc->PageSpa = attrs.valueAsDouble("ABSTSPALTEN");
+ m_Doc->setUnitIndex( attrs.valueAsInt("UNITS", 0) );
+
+ m_Doc->Language = attrs.valueAsString("LANGUAGE", "");
+ m_Doc->MinWordLen = attrs.valueAsInt("MINWORDLEN", 3);
+ m_Doc->HyCount = attrs.valueAsInt("HYCOUNT", 2);
+
+ if (attrs.hasAttribute("PAGEWIDTH"))
+ m_Doc->pageWidth = attrs.valueAsDouble("PAGEWIDTH");
+ else
+ m_Doc->pageWidth = attrs.valueAsDouble("PAGEWITH");
+ m_Doc->pageHeight = attrs.valueAsDouble("PAGEHEIGHT");
+ m_Doc->pageMargins.Left = qMax(0.0, attrs.valueAsDouble("BORDERLEFT"));
+ m_Doc->pageMargins.Right = qMax(0.0, attrs.valueAsDouble("BORDERRIGHT"));
+ m_Doc->pageMargins.Top = qMax(0.0, attrs.valueAsDouble("BORDERTOP"));
+ m_Doc->pageMargins.Bottom= qMax(0.0, attrs.valueAsDouble("BORDERBOTTOM"));
+ m_Doc->marginPreset = attrs.valueAsInt("PRESET", 0);
+ m_Doc->bleeds.Top = attrs.valueAsDouble("BleedTop", 0.0);
+ m_Doc->bleeds.Left = attrs.valueAsDouble("BleedLeft", 0.0);
+ m_Doc->bleeds.Right = attrs.valueAsDouble("BleedRight", 0.0);
+ m_Doc->bleeds.Bottom = attrs.valueAsDouble("BleedBottom", 0.0);
+ m_Doc->Automatic = attrs.valueAsBool("AUTOMATIC", true);
+ m_Doc->AutoCheck = attrs.valueAsBool("AUTOCHECK", false);
+ m_Doc->GuideLock = attrs.valueAsBool("GUIDELOCK", false);
+
+ m_Doc->rulerXoffset = attrs.valueAsDouble("rulerXoffset", 0.0);
+ m_Doc->rulerYoffset = attrs.valueAsDouble("rulerYoffset", 0.0);
+ m_Doc->SnapGuides = attrs.valueAsBool("SnapToGuides", false);
+ m_Doc->useRaster = attrs.valueAsBool("SnapToGrid", false);
+
+ m_Doc->AutoSave = attrs.valueAsBool("AutoSave", false);
+ m_Doc->AutoSaveTime = attrs.valueAsInt("AutoSaveTime", 600000);
+ m_Doc->scratch.Bottom = attrs.valueAsDouble("ScratchBottom", 20.0);
+ // FIXME A typo in early 1.3cvs (MAR 05) means we must support loading of
+ // FIXME 'ScatchLeft' for a while too. This can be removed in a few months.
+ if (attrs.hasAttribute("ScatchLeft"))
+ m_Doc->scratch.Left = attrs.valueAsDouble("ScatchLeft", 100.0);
+ else
+ m_Doc->scratch.Left = attrs.valueAsDouble("ScratchLeft", 100.0);
+ m_Doc->scratch.Right = attrs.valueAsDouble("ScratchRight", 100.0);
+ m_Doc->scratch.Top = attrs.valueAsDouble("ScratchTop", 20.0);
+ m_Doc->GapHorizontal = attrs.valueAsDouble("GapHorizontal", -1.0);
+ m_Doc->GapVertical = attrs.valueAsDouble("GapVertical", -1.0);
+
+ if (attrs.hasAttribute("PAGEC"))
+ m_Doc->papColor = QColor(attrs.valueAsString("PAGEC"));
+
+ m_Doc->marginColored = attrs.valueAsBool("RANDF", false);
+
+ readCMSSettings(doc, attrs);
+ readDocumentInfo(doc, attrs);
+ readGuideSettings(doc, attrs);
+ readToolSettings(doc, attrs);
+ readTypographicSettings(doc, attrs);
+}
+
+void Scribus150Format::readCMSSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
+{
+ doc->CMSSettings.SoftProofOn = attrs.valueAsBool("DPSo", false);
+ doc->CMSSettings.SoftProofFullOn = attrs.valueAsBool("DPSFo", false);
+ doc->CMSSettings.CMSinUse = attrs.valueAsBool("DPuse", false);
+ doc->CMSSettings.GamutCheck = attrs.valueAsBool("DPgam", false);
+ doc->CMSSettings.BlackPoint = attrs.valueAsBool("DPbla", true);
+ doc->CMSSettings.DefaultMonitorProfile = attrs.valueAsString("DPMo","");
+ doc->CMSSettings.DefaultPrinterProfile = attrs.valueAsString("DPPr","");
+ doc->CMSSettings.DefaultImageRGBProfile = attrs.valueAsString("DPIn","");
+ doc->CMSSettings.DefaultImageCMYKProfile = attrs.valueAsString("DPInCMYK","");
+ doc->CMSSettings.DefaultSolidColorRGBProfile = attrs.valueAsString("DPIn2","");
+ if (attrs.hasAttribute("DPIn3"))
+ doc->CMSSettings.DefaultSolidColorCMYKProfile = attrs.valueAsString("DPIn3","");
+ else
+ doc->CMSSettings.DefaultSolidColorCMYKProfile = attrs.valueAsString("DPPr","");
+ doc->CMSSettings.DefaultIntentColors = attrs.valueAsInt("DISc", 1);
+ doc->CMSSettings.DefaultIntentImages = attrs.valueAsInt("DIIm", 0);
+}
+
+void Scribus150Format::readDocumentInfo(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
+{
+ doc->documentInfo.setAuthor(attrs.valueAsString("AUTHOR"));
+ doc->documentInfo.setComments(attrs.valueAsString("COMMENTS"));
+ doc->documentInfo.setKeywords(attrs.valueAsString("KEYWORDS",""));
+ doc->documentInfo.setTitle(attrs.valueAsString("TITLE"));
+ doc->documentInfo.setSubject(attrs.valueAsString("SUBJECT"));
+ doc->documentInfo.setPublisher(attrs.valueAsString("PUBLISHER", ""));
+ doc->documentInfo.setDate(attrs.valueAsString("DOCDATE", ""));
+ doc->documentInfo.setType(attrs.valueAsString("DOCTYPE", ""));
+ doc->documentInfo.setFormat(attrs.valueAsString("DOCFORMAT", ""));
+ doc->documentInfo.setIdent(attrs.valueAsString("DOCIDENT", ""));
+ doc->documentInfo.setSource(attrs.valueAsString("DOCSOURCE", ""));
+ doc->documentInfo.setLangInfo(attrs.valueAsString("DOCLANGINFO", ""));
+ doc->documentInfo.setRelation(attrs.valueAsString("DOCRELATION", ""));
+ doc->documentInfo.setCover(attrs.valueAsString("DOCCOVER", ""));
+ doc->documentInfo.setRights(attrs.valueAsString("DOCRIGHTS", ""));
+ doc->documentInfo.setContrib(attrs.valueAsString("DOCCONTRIB", ""));
+}
+
+void Scribus150Format::readGuideSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
+{
+ PrefsManager* prefsManager = PrefsManager::instance();
+ doc->guidesSettings.minorGridSpacing = attrs.valueAsDouble("MINGRID", prefsManager->appPrefs.guidesPrefs.minorGridSpacing);
+ doc->guidesSettings.majorGridSpacing = attrs.valueAsDouble("MAJGRID", prefsManager->appPrefs.guidesPrefs.majorGridSpacing);
+ doc->guidesSettings.gridShown = attrs.valueAsBool("SHOWGRID", false);
+ doc->guidesSettings.guidesShown =attrs.valueAsBool("SHOWGUIDES", true);
+ doc->guidesSettings.colBordersShown = attrs.valueAsBool("showcolborders", false);
+ doc->guidesSettings.framesShown = attrs.valueAsBool("SHOWFRAME", true);
+ doc->guidesSettings.layerMarkersShown = attrs.valueAsBool("SHOWLAYERM", false);
+ doc->guidesSettings.marginsShown = attrs.valueAsBool("SHOWMARGIN", true);
+ doc->guidesSettings.baselineGridShown = attrs.valueAsBool("SHOWBASE", false);
+ doc->guidesSettings.showPic = attrs.valueAsBool("SHOWPICT", true);
+ doc->guidesSettings.linkShown = attrs.valueAsBool("SHOWLINK", false);
+ doc->guidesSettings.showControls = attrs.valueAsBool("SHOWControl", false);
+ doc->guidesSettings.rulerMode = attrs.valueAsBool("rulerMode", true);
+ doc->guidesSettings.rulersShown = attrs.valueAsBool("showrulers", true);
+ doc->guidesSettings.showBleed = attrs.valueAsBool("showBleed", true);
+ if (attrs.hasAttribute("MARGC"))
+ doc->guidesSettings.marginColor = QColor(attrs.valueAsString("MARGC"));
+ if (attrs.hasAttribute("MINORC"))
+ doc->guidesSettings.minorGridColor = QColor(attrs.valueAsString("MINORC"));
+ if (attrs.hasAttribute("MAJORC"))
+ doc->guidesSettings.majorGridColor = QColor(attrs.valueAsString("MAJORC"));
+ if (attrs.hasAttribute("GuideC"))
+ doc->guidesSettings.guideColor = QColor(attrs.valueAsString("GuideC"));
+ if (attrs.hasAttribute("BaseC"))
+ doc->guidesSettings.baselineGridColor = QColor(attrs.valueAsString("BaseC"));
+ doc->guidesSettings.guidePlacement = attrs.valueAsBool("BACKG", true);
+ doc->guidesSettings.guideRad = attrs.valueAsDouble("GuideRad", 10.0);
+ doc->guidesSettings.grabRadius = attrs.valueAsInt("GRAB", 4);
+}
+
+void Scribus150Format::readToolSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
+{
+ QString defFont = attrs.valueAsString("DFONT");
+ m_AvailableFonts->findFont(defFont, doc);
+
+ doc->toolSettings.defFont = defFont;
+ doc->toolSettings.defSize = qRound(attrs.valueAsDouble("DSIZE", 12.0) * 10);
+ doc->toolSettings.dCols = attrs.valueAsInt("DCOL", 1);
+ doc->toolSettings.dGap = attrs.valueAsDouble("DGAP", 0.0);
+
+ doc->toolSettings.polyC = attrs.valueAsInt("POLYC", 4);
+ doc->toolSettings.polyF = attrs.valueAsDouble("POLYF", 0.5);
+ doc->toolSettings.polyR = attrs.valueAsDouble("POLYR", 0.0);
+ doc->toolSettings.polyCurvature = attrs.valueAsDouble("POLYCUR", 0.0);
+ doc->toolSettings.polyFd = attrs.valueAsInt("POLYFD", 0);
+ doc->toolSettings.polyS = attrs.valueAsBool("POLYS", false);
+
+ doc->toolSettings.dStartArrow = attrs.valueAsInt("StartArrow", 0);
+ doc->toolSettings.dEndArrow = attrs.valueAsInt("EndArrow", 0);
+ doc->toolSettings.scaleX = attrs.valueAsDouble("PICTSCX", 1.0);
+ doc->toolSettings.scaleY = attrs.valueAsDouble("PICTSCY", 1.0);
+ doc->toolSettings.scaleType = attrs.valueAsBool("PSCALE", true);
+ doc->toolSettings.aspectRatio = attrs.valueAsBool("PASPECT", false);
+ doc->toolSettings.lowResType = attrs.valueAsInt("HalfRes", 1);
+ doc->toolSettings.useEmbeddedPath = attrs.valueAsBool("EmbeddedPath", false);
+ if (attrs.hasAttribute("PEN"))
+ doc->toolSettings.dPen = attrs.valueAsString("PEN");
+ if (attrs.hasAttribute("BRUSH"))
+ doc->toolSettings.dBrush = attrs.valueAsString("BRUSH");
+ if (attrs.hasAttribute("PENLINE"))
+ doc->toolSettings.dPenLine = attrs.valueAsString("PENLINE");
+ if (attrs.hasAttribute("PENTEXT"))
+ doc->toolSettings.dPenText = attrs.valueAsString("PENTEXT");
+ if (attrs.hasAttribute("StrokeText"))
+ doc->toolSettings.dStrokeText = attrs.valueAsString("StrokeText");
+ doc->toolSettings.dTextBackGround = attrs.valueAsString("TextBackGround", CommonStrings::None);
+ doc->toolSettings.dTextLineColor = attrs.valueAsString("TextLineColor", CommonStrings::None);
+ doc->toolSettings.dTextBackGroundShade =attrs.valueAsInt("TextBackGroundShade", 100);
+ doc->toolSettings.dTextLineShade = attrs.valueAsInt("TextLineShade", 100);
+ doc->toolSettings.dTextPenShade = attrs.valueAsInt("TextPenShade", 100);
+ doc->toolSettings.dTextStrokeShade = attrs.valueAsInt("TextStrokeShade", 100);
+ doc->toolSettings.dLineArt = static_cast<Qt::PenStyle>(attrs.valueAsInt("STIL"));
+ doc->toolSettings.dLstyleLine = static_cast<Qt::PenStyle>(attrs.valueAsInt("STILLINE"));
+ doc->toolSettings.dWidth = attrs.valueAsDouble("WIDTH", 0.0);
+ doc->toolSettings.dWidthLine = attrs.valueAsDouble("WIDTHLINE", 1.0);
+ doc->toolSettings.dShade2 = attrs.valueAsInt("PENSHADE", 100);
+ doc->toolSettings.dShadeLine = attrs.valueAsInt("LINESHADE", 100);
+ doc->toolSettings.dShade = attrs.valueAsInt("BRUSHSHADE", 100);
+ doc->toolSettings.magMin = attrs.valueAsInt("MAGMIN", 10);
+ doc->toolSettings.magMax = attrs.valueAsInt("MAGMAX", 3200);
+ doc->toolSettings.magStep = attrs.valueAsInt("MAGSTEP", 200);
+ doc->toolSettings.dispX = attrs.valueAsDouble("dispX", 10.0);
+ doc->toolSettings.dispY = attrs.valueAsDouble("dispY", 10.0);
+ doc->toolSettings.constrain = attrs.valueAsDouble("constrain", 15.0);
+ //CB Reset doc zoom step value to 200% instead of old values.
+ if (doc->toolSettings.magStep < 100)
+ doc->toolSettings.magStep = 200;
+ doc->toolSettings.tabFillChar = attrs.valueAsString("TabFill","");
+ doc->toolSettings.dTabWidth = attrs.valueAsDouble("TabWidth", 36.0);
+ if (attrs.hasAttribute("CPICT"))
+ doc->toolSettings.dBrushPict = attrs.valueAsString("CPICT");
+ doc->toolSettings.shadePict = attrs.valueAsInt("PICTSHADE", 100);
+}
+
+void Scribus150Format::readTypographicSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
+{
+ doc->typographicSettings.valueSuperScript = attrs.valueAsInt("VHOCH");
+ doc->typographicSettings.scalingSuperScript = attrs.valueAsInt("VHOCHSC");
+ doc->typographicSettings.valueSubScript = attrs.valueAsInt("VTIEF");
+ doc->typographicSettings.scalingSubScript = attrs.valueAsInt("VTIEFSC");
+ doc->typographicSettings.valueSmallCaps = attrs.valueAsInt("VKAPIT");
+ doc->guidesSettings.valueBaselineGrid = attrs.valueAsDouble("BASEGRID", 12.0);
+ doc->guidesSettings.offsetBaselineGrid = attrs.valueAsDouble("BASEO", 0.0);
+ doc->typographicSettings.autoLineSpacing = attrs.valueAsInt("AUTOL", 20);
+ doc->typographicSettings.valueUnderlinePos = attrs.valueAsInt("UnderlinePos", -1);
+ doc->typographicSettings.valueUnderlineWidth = attrs.valueAsInt("UnderlineWidth", -1);
+ doc->typographicSettings.valueStrikeThruPos = attrs.valueAsInt("StrikeThruPos", -1);
+ doc->typographicSettings.valueStrikeThruWidth = attrs.valueAsInt("StrikeThruWidth", -1);
+}
+
+bool Scribus150Format::readPageSets(ScribusDoc* doc, ScXmlStreamReader& reader)
+{
+ struct PageSet pageS;
+ ScXmlStreamAttributes attrs;
+
+ doc->pageSets.clear();
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ reader.readNext();
+ QStringRef tagName = reader.name();
+ if(reader.isStartElement())
+ attrs = reader.attributes();
+ if (reader.isEndElement() && tagName == "PageSets")
+ break;
+ if(reader.isStartElement() && tagName == "Set")
+ {
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ pageS.Name = CommonStrings::untranslatePageSetString(attrs.valueAsString("Name"));
+ pageS.FirstPage = attrs.valueAsInt("FirstPage", 0);
+ pageS.Rows = attrs.valueAsInt("Rows", 1);
+ pageS.Columns = attrs.valueAsInt("Columns", 1);
+// pageS.GapHorizontal = attrs.valueAsDouble("GapHorizontal", 0);
+// pageS.GapVertical = attrs.valueAsDouble("GapVertical", 0);
+// pageS.GapBelow = attrs.valueAsDouble("GapBelow", 0);
+ pageS.pageNames.clear();
+ }
+ if(reader.isEndElement() && tagName == "Set")
+ {
+ doc->pageSets.append(pageS);
+ if ((doc->pageSets.count()-1 == doc->currentPageLayout) && ((doc->GapHorizontal < 0) && (doc->GapVertical < 0)))
+ {
+ doc->GapHorizontal = attrs.valueAsDouble("GapHorizontal", 0.0);
+ doc->GapVertical = attrs.valueAsDouble("GapBelow", 0.0);
+ }
+ }
+ if (reader.isStartElement() && tagName == "PageNames")
+ pageS.pageNames.append(CommonStrings::untranslatePageSetLocString(attrs.valueAsString("Name")));
+ }
+ return !reader.hasError();
+}
+
+bool Scribus150Format::readCheckProfile(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
+{
+ struct CheckerPrefs checkerSettings;
+ QString profileName = attrs.valueAsString("Name");
+ if (profileName.isEmpty())
+ return true;
+ checkerSettings.ignoreErrors = attrs.valueAsBool("ignoreErrors", false);
+ checkerSettings.autoCheck = attrs.valueAsBool("autoCheck", true);
+ checkerSettings.checkGlyphs = attrs.valueAsBool("checkGlyphs", true);
+ checkerSettings.checkOrphans = attrs.valueAsBool("checkOrphans", true);
+ checkerSettings.checkOverflow = attrs.valueAsBool("checkOverflow", true);
+ checkerSettings.checkPictures = attrs.valueAsBool("checkPictures", true);
+ checkerSettings.checkResolution = attrs.valueAsBool("checkResolution", true);
+ checkerSettings.checkTransparency = attrs.valueAsBool("checkTransparency", true);
+ checkerSettings.minResolution = attrs.valueAsDouble("minResolution", 72.0);
+ checkerSettings.maxResolution = attrs.valueAsDouble("maxResolution", 4800.0);
+ checkerSettings.checkAnnotations = attrs.valueAsBool("checkAnnotations", false);
+ checkerSettings.checkRasterPDF = attrs.valueAsBool("checkRasterPDF", true);
+ checkerSettings.checkForGIF = attrs.valueAsBool("checkForGIF", true);
+ checkerSettings.ignoreOffLayers = attrs.valueAsBool("ignoreOffLayers", false);
+ doc->checkerProfiles[profileName] = checkerSettings;
+ return true;
+}
+
+bool Scribus150Format::readColor(ColorList& colors, ScXmlStreamAttributes& attrs)
+{
+ ScColor color;
+ if (attrs.hasAttribute("CMYK"))
+ color.setNamedColor(attrs.valueAsString("CMYK"));
+ else
+ color.fromQColor(QColor(attrs.valueAsString("RGB")));
+ color.setSpotColor( attrs.valueAsBool("Spot", false) );
+ color.setRegistrationColor( attrs.valueAsBool("Register", false) );
+ QString name = attrs.valueAsString("NAME");
+ colors.insert((name.isEmpty()) ? color.name() : name, color);
+ return true;
+}
+
+void Scribus150Format::readCharacterStyleAttrs(ScribusDoc *doc, ScXmlStreamAttributes& attrs, CharStyle & newStyle)
+{
+ static const QString CNAME("CNAME");
+ if (attrs.hasAttribute(CNAME))
+ newStyle.setName(attrs.valueAsString(CNAME));
+
+ // The default style attribute must be correctly set before trying to assign a parent
+ static const QString DEFAULTSTYLE("DefaultStyle");
+ if (newStyle.hasName() && attrs.hasAttribute(DEFAULTSTYLE))
+ newStyle.setDefaultStyle(attrs.valueAsInt(DEFAULTSTYLE));
+ else if (newStyle.name() == CommonStrings::DefaultCharacterStyle || newStyle.name() == CommonStrings::trDefaultCharacterStyle)
+ newStyle.setDefaultStyle(true);
+ else
+ newStyle.setDefaultStyle(false);
+
+ static const QString CPARENT("CPARENT");
+ if (attrs.hasAttribute(CPARENT))
+ newStyle.setParent(attrs.valueAsString(CPARENT));
+
+ static const QString FONT("FONT");
+ if (attrs.hasAttribute(FONT))
+ newStyle.setFont(m_AvailableFonts->findFont(attrs.valueAsString(FONT), doc));
+
+ static const QString FONTSIZE("FONTSIZE");
+ if (attrs.hasAttribute(FONTSIZE))
+ newStyle.setFontSize(qRound(attrs.valueAsDouble(FONTSIZE) * 10));
+
+ static const QString FCOLOR("FCOLOR");
+ if (attrs.hasAttribute(FCOLOR))
+ newStyle.setFillColor(attrs.valueAsString(FCOLOR));
+
+ static const QString KERN("KERN");
+ if (attrs.hasAttribute(KERN))
+ newStyle.setTracking(qRound(attrs.valueAsDouble(KERN) * 10));
+
+ static const QString FSHADE("FSHADE");
+ if (attrs.hasAttribute(FSHADE))
+ newStyle.setFillShade(attrs.valueAsInt(FSHADE));
+
+ static const QString EFFECTS("EFFECTS");
+ if (attrs.hasAttribute(EFFECTS))
+ newStyle.setFeatures(static_cast<StyleFlag>(attrs.valueAsInt(EFFECTS)).featureList());
+
+ static const QString EFFECT("EFFECT");
+ if (attrs.hasAttribute(EFFECT))
+ newStyle.setFeatures(static_cast<StyleFlag>(attrs.valueAsInt(EFFECT)).featureList());
+
+ static const QString FEATURES("FEATURES");
+ if (attrs.hasAttribute(FEATURES))
+ newStyle.setFeatures(attrs.valueAsString(FEATURES).split( " ", QString::SkipEmptyParts));
+
+ static const QString SCOLOR("SCOLOR");
+ if (attrs.hasAttribute(SCOLOR))
+ newStyle.setStrokeColor(attrs.valueAsString(SCOLOR, CommonStrings::None));
+
+ static const QString SSHADE("SSHADE");
+ if (attrs.hasAttribute(SSHADE))
+ newStyle.setStrokeShade(attrs.valueAsInt(SSHADE));
+
+ static const QString SCALEH("SCALEH");
+ if (attrs.hasAttribute(SCALEH))
+ newStyle.setScaleH(qRound(attrs.valueAsDouble(SCALEH) * 10));
+
+ static const QString SCALEV("SCALEV");
+ if (attrs.hasAttribute(SCALEV))
+ newStyle.setScaleV(qRound(attrs.valueAsDouble(SCALEV) * 10));
+
+ static const QString BASEO("BASEO");
+ if (attrs.hasAttribute(BASEO))
+ newStyle.setBaselineOffset(qRound(attrs.valueAsDouble(BASEO) * 10));
+
+ static const QString TXTSHX("TXTSHX");
+ if (attrs.hasAttribute(TXTSHX))
+ newStyle.setShadowXOffset(qRound(attrs.valueAsDouble(TXTSHX) * 10));
+
+ static const QString TXTSHY("TXTSHY");
+ if (attrs.hasAttribute(TXTSHY))
+ newStyle.setShadowYOffset(qRound(attrs.valueAsDouble(TXTSHY) * 10));
+
+ static const QString TXTOUT("TXTOUT");
+ if (attrs.hasAttribute(TXTOUT))
+ newStyle.setOutlineWidth(qRound(attrs.valueAsDouble(TXTOUT) * 10));
+
+ static const QString TXTULP("TXTULP");
+ if (attrs.hasAttribute(TXTULP))
+ newStyle.setUnderlineOffset(qRound(attrs.valueAsDouble(TXTULP) * 10));
+
+ static const QString TXTULW("TXTULW");
+ if (attrs.hasAttribute(TXTULW))
+ newStyle.setUnderlineWidth(qRound(attrs.valueAsDouble(TXTULW) * 10));
+
+ static const QString TXTSTP("TXTSTP");
+ if (attrs.hasAttribute(TXTSTP))
+ newStyle.setStrikethruOffset(qRound(attrs.valueAsDouble(TXTSTP) * 10));
+
+ static const QString TXTSTW("TXTSTW");
+ if (attrs.hasAttribute(TXTSTW))
+ newStyle.setStrikethruWidth(qRound(attrs.valueAsDouble(TXTSTW) * 10));
+
+ static const QString SHORTCUT("SHORTCUT");
+ if (attrs.hasAttribute(SHORTCUT))
+ newStyle.setShortcut(attrs.valueAsString(SHORTCUT));
+
+ static const QString WORDTRACK("wordTrack");
+ if (attrs.hasAttribute(WORDTRACK))
+ newStyle.setWordTracking(attrs.valueAsDouble(WORDTRACK));
+}
+
+void Scribus150Format::readParagraphStyle(ScribusDoc *doc, ScXmlStreamReader& reader, ParagraphStyle& newStyle, SCFonts &fonts)
+{
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+
+ newStyle.erase();
+ newStyle.setName(attrs.valueAsString("NAME", ""));
+ // The default style attribute must be correctly set before trying to assign a parent
+ static const QString DEFAULTSTYLE("DefaultStyle");
+ if (attrs.hasAttribute(DEFAULTSTYLE))
+ newStyle.setDefaultStyle(attrs.valueAsInt(DEFAULTSTYLE));
+ else if (newStyle.name() == CommonStrings::DefaultParagraphStyle || newStyle.name() == CommonStrings::trDefaultParagraphStyle)
+ newStyle.setDefaultStyle(true);
+ else
+ newStyle.setDefaultStyle(false);
+ newStyle.setParent(attrs.valueAsString("PARENT", ""));
+
+ static const QString LINESPMode("LINESPMode");
+ if (attrs.hasAttribute(LINESPMode))
+ newStyle.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(attrs.valueAsInt(LINESPMode)));
+
+ static const QString LINESP("LINESP");
+ if (attrs.hasAttribute(LINESP))
+ newStyle.setLineSpacing(attrs.valueAsDouble(LINESP));
+
+ static const QString INDENT("INDENT");
+ if (attrs.hasAttribute(INDENT))
+ newStyle.setLeftMargin(attrs.valueAsDouble(INDENT));
+
+ static const QString RMARGIN("RMARGIN");
+ if (attrs.hasAttribute(RMARGIN))
+ newStyle.setRightMargin(attrs.valueAsDouble(RMARGIN));
+
+ static const QString FIRST("FIRST");
+ if (attrs.hasAttribute(FIRST))
+ newStyle.setFirstIndent(attrs.valueAsDouble(FIRST));
+
+ static const QString ALIGN("ALIGN");
+ if (attrs.hasAttribute(ALIGN))
+ newStyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(attrs.valueAsInt(ALIGN)));
+
+ static const QString VOR("VOR");
+ if (attrs.hasAttribute(VOR))
+ newStyle.setGapBefore(attrs.valueAsDouble(VOR));
+
+ static const QString NACH("NACH");
+ if (attrs.hasAttribute(NACH))
+ newStyle.setGapAfter(attrs.valueAsDouble(NACH));
+
+ static const QString DROP("DROP");
+ if (attrs.hasAttribute(DROP))
+ newStyle.setHasDropCap(static_cast<bool>(attrs.valueAsInt(DROP)));
+
+ static const QString DROPLIN("DROPLIN");
+ if (attrs.hasAttribute(DROPLIN))
+ newStyle.setDropCapLines(attrs.valueAsInt(DROPLIN));
+
+ static const QString DROPDIST("DROPDIST");
+ if (attrs.hasAttribute(DROPDIST))
+ newStyle.setDropCapOffset(attrs.valueAsDouble(DROPDIST));
+
+ static const QString PSHORTCUT("PSHORTCUT");
+ if (attrs.hasAttribute(PSHORTCUT))
+ newStyle.setShortcut(attrs.valueAsString(PSHORTCUT));
+
+ static const QString OpticalMargins("OpticalMargins");
+ if (attrs.hasAttribute(OpticalMargins))
+ newStyle.setOpticalMargins(attrs.valueAsInt(OpticalMargins));
+
+ static const QString HyphenationMode("HyphenationMode");
+ if (attrs.hasAttribute(HyphenationMode))
+ newStyle.setHyphenationMode(attrs.valueAsInt(HyphenationMode));
+
+ static const QString MinWordTrack("MinWordTrack");
+ if (attrs.hasAttribute(MinWordTrack))
+ newStyle.setMinWordTracking(attrs.valueAsDouble(MinWordTrack));
+
+ static const QString NormWordTrack("NormWordTrack");
+ if (attrs.hasAttribute(NormWordTrack))
+ newStyle.charStyle().setWordTracking(attrs.valueAsDouble(NormWordTrack));
+
+ static const QString MinGlyphShrink("MinGlyphShrink");
+ if (attrs.hasAttribute(MinGlyphShrink))
+ newStyle.setMinGlyphExtension(attrs.valueAsDouble(MinGlyphShrink));
+
+ static const QString MaxGlyphExtend("MaxGlyphExtend");
+ if (attrs.hasAttribute(MaxGlyphExtend))
+ newStyle.setMaxGlyphExtension(attrs.valueAsDouble(MaxGlyphExtend));
+
+ readCharacterStyleAttrs( doc, attrs, newStyle.charStyle());
+
+ // newStyle.tabValues().clear();
+ QList<ParagraphStyle::TabRecord> tbs;
+ newStyle.resetTabValues();
+ QStringRef thisTagName = reader.name();
+ while (!reader.atEnd() && !reader.hasError())
+ {
+ reader.readNext();
+ if (reader.isEndElement() && reader.name() == thisTagName)
+ break;
+ if (reader.isStartElement() && reader.name() == "Tabs")
+ {
+ ParagraphStyle::TabRecord tb;
+ ScXmlStreamAttributes attrs2 = reader.scAttributes();
+ tb.tabPosition = attrs2.valueAsDouble("Pos");
+ tb.tabType = attrs2.valueAsInt("Type");
+ QString tbCh = attrs2.valueAsString("Fill","");
+ tb.tabFillChar = tbCh.isEmpty() ? QChar() : tbCh[0];
+ tbs.append(tb);
+ }
+ }
+ if (tbs.count() > 0)
+ newStyle.setTabValues(tbs);
+
+ fixLegacyParStyle(newStyle);
+}
+
+void Scribus150Format::readLayers(ScLayer& layer, ScXmlStreamAttributes& attrs)
+{
+ int lId = attrs.valueAsInt("NUMMER");
+ int level = attrs.valueAsInt("LEVEL");
+ layer = ScLayer( attrs.valueAsString("NAME"), level, lId);
+ layer.isViewable = attrs.valueAsInt("SICHTBAR");
+ layer.isPrintable = attrs.valueAsInt("DRUCKEN");
+ layer.isEditable = attrs.valueAsInt("EDIT", 1);
+ layer.flowControl = attrs.valueAsInt("FLOW", 1);
+ layer.transparency = attrs.valueAsDouble("TRANS", 1.0);
+ layer.blendMode = attrs.valueAsInt("BLEND", 0);
+ layer.outlineMode = attrs.valueAsInt("OUTL", 0);
+ if (attrs.hasAttribute("LAYERC"))
+ layer.markerColor = QColor(attrs.valueAsString("LAYERC","#000000"));
+}
+
+bool Scribus150Format::readArrows(ScribusDoc* doc, ScXmlStreamAttributes& attrs)
+{
+ double xa, ya;
+ struct ArrowDesc arrow;
+ arrow.name = attrs.valueAsString("Name");
+ arrow.userArrow = true;
+ QString tmp = attrs.valueAsString("Points");
+ ScTextStream fp(&tmp, QIODevice::ReadOnly);
+ unsigned int numPoints = attrs.valueAsUInt("NumPoints");
+ for (uint cx = 0; cx < numPoints; ++cx)
+ {
+ fp >> xa;
+ fp >> ya;
+ arrow.points.addPoint(xa, ya);
+ }
+ doc->arrowStyles.append(arrow);
+ return true;
+}
+
+bool Scribus150Format::readMultiline(multiLine& ml, ScXmlStreamReader& reader)
+{
+ ml = multiLine();
+ ScXmlStreamAttributes rattrs = reader.scAttributes();
+ QStringRef tagName = reader.name();
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ ScXmlStreamReader::TokenType tType = reader.readNext();
+ if (tType == ScXmlStreamReader::EndElement && reader.name() == tagName)
+ break;
+ if (tType == ScXmlStreamReader::StartElement && reader.name() == "SubLine")
+ {
+ struct SingleLine sl;
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ sl.Color = attrs.valueAsString("Color");
+ sl.Dash = attrs.valueAsInt("Dash");
+ sl.LineEnd = attrs.valueAsInt("LineEnd");
+ sl.LineJoin = attrs.valueAsInt("LineJoin");
+ sl.Shade = attrs.valueAsInt("Shade");
+ sl.Width = attrs.valueAsDouble("Width");
+ ml.shortcut = attrs.valueAsString("Shortcut");
+ ml.push_back(sl);
+ }
+ }
+ return !reader.hasError();
+}
+
+bool Scribus150Format::readBookMark(ScribusDoc::BookMa& bookmark, int& elem, ScXmlStreamAttributes& attrs)
+{
+ elem = attrs.valueAsInt("Element");
+ bookmark.PageObject = NULL;
+ bookmark.Title = attrs.valueAsString("Title");
+ bookmark.Text = attrs.valueAsString("Text");
+ bookmark.Aktion = attrs.valueAsString("Aktion");
+ bookmark.ItemNr = attrs.valueAsInt("ItemNr");
+ bookmark.First = attrs.valueAsInt("First");
+ bookmark.Last = attrs.valueAsInt("Last");
+ bookmark.Prev = attrs.valueAsInt("Prev");
+ bookmark.Next = attrs.valueAsInt("Next");
+ bookmark.Parent = attrs.valueAsInt("Parent");
+ return true;
+}
+
+bool Scribus150Format::readPDFOptions(ScribusDoc* doc, ScXmlStreamReader& reader)
+{
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+
+ doc->PDF_Options.firstUse = attrs.valueAsBool("firstUse", true);
+ doc->PDF_Options.Articles = attrs.valueAsBool("Articles");
+ doc->PDF_Options.Thumbnails = attrs.valueAsBool("Thumbnails");
+ doc->PDF_Options.Compress = attrs.valueAsBool("Compress");
+ doc->PDF_Options.CompressMethod = (PDFOptions::PDFCompression)attrs.valueAsInt("CMethod", 0);
+ doc->PDF_Options.Quality = attrs.valueAsInt("Quality", 0);
+ doc->PDF_Options.RecalcPic = attrs.valueAsBool("RecalcPic");
+ doc->PDF_Options.Bookmarks = attrs.valueAsBool("Bookmarks");
+ doc->PDF_Options.MirrorH = attrs.valueAsBool("MirrorH", false);
+ doc->PDF_Options.MirrorV = attrs.valueAsBool("MirrorV", false);
+ doc->PDF_Options.RotateDeg = attrs.valueAsInt("RotateDeg", 0);
+ doc->PDF_Options.doClip = attrs.valueAsBool("Clip", false);
+ doc->PDF_Options.PresentMode = attrs.valueAsBool("PresentMode");
+ doc->PDF_Options.PicRes = attrs.valueAsInt("PicRes");
+ // Fixme: check input pdf version
+ doc->PDF_Options.Version = (PDFOptions::PDFVersion) attrs.valueAsInt("Version");
+ doc->PDF_Options.Resolution = attrs.valueAsInt("Resolution");
+ doc->PDF_Options.Binding = attrs.valueAsInt("Binding");
+ doc->PDF_Options.fileName = "";
+ doc->PDF_Options.isGrayscale = attrs.valueAsBool("Grayscale", false);
+ doc->PDF_Options.UseRGB = attrs.valueAsBool("RGBMode", false);
+ doc->PDF_Options.UseProfiles = attrs.valueAsBool("UseProfiles", false);
+ doc->PDF_Options.UseProfiles2 = attrs.valueAsBool("UseProfiles2", false);
+ doc->PDF_Options.Intent = attrs.valueAsInt("Intent", 1);
+ doc->PDF_Options.Intent2 = attrs.valueAsInt("Intent2", 1);
+ doc->PDF_Options.SolidProf = attrs.valueAsString("SolidP", "");
+ doc->PDF_Options.ImageProf = attrs.valueAsString("ImageP", "");
+ doc->PDF_Options.PrintProf = attrs.valueAsString("PrintP", "");
+ doc->PDF_Options.Info = attrs.valueAsString("InfoString", "");
+ doc->PDF_Options.bleeds.Top = attrs.valueAsDouble("BTop", 0.0);
+ doc->PDF_Options.bleeds.Left = attrs.valueAsDouble("BLeft", 0.0);
+ doc->PDF_Options.bleeds.Right = attrs.valueAsDouble("BRight", 0.0);
+ doc->PDF_Options.bleeds.Bottom = attrs.valueAsDouble("BBottom", 0.0);
+ doc->PDF_Options.useDocBleeds = attrs.valueAsBool("useDocBleeds", true);
+ doc->PDF_Options.cropMarks = attrs.valueAsBool("cropMarks", false);
+ doc->PDF_Options.bleedMarks = attrs.valueAsBool("bleedMarks", false);
+ doc->PDF_Options.registrationMarks = attrs.valueAsBool("registrationMarks", false);
+ doc->PDF_Options.colorMarks = attrs.valueAsBool("colorMarks", false);
+ doc->PDF_Options.docInfoMarks = attrs.valueAsBool("docInfoMarks", false);
+ doc->PDF_Options.markOffset = attrs.valueAsDouble("markOffset", 0.0);
+ doc->PDF_Options.EmbeddedI = attrs.valueAsBool("ImagePr", false);
+ doc->PDF_Options.PassOwner = attrs.valueAsString("PassOwner", "");
+ doc->PDF_Options.PassUser = attrs.valueAsString("PassUser", "");
+ doc->PDF_Options.Permissions = attrs.valueAsInt("Permissions", -4);
+ doc->PDF_Options.Encrypt = attrs.valueAsBool("Encrypt", false);
+ doc->PDF_Options.useLayers = attrs.valueAsBool("UseLayers", false);
+ doc->PDF_Options.UseLPI = attrs.valueAsBool("UseLpi", false);
+ doc->PDF_Options.UseSpotColors = attrs.valueAsBool("UseSpotColors", true);
+ doc->PDF_Options.doMultiFile = attrs.valueAsBool("doMultiFile", false);
+ doc->PDF_Options.displayBookmarks = attrs.valueAsBool("displayBookmarks", false);
+ doc->PDF_Options.displayFullscreen = attrs.valueAsBool("displayFullscreen", false);
+ doc->PDF_Options.displayLayers = attrs.valueAsBool("displayLayers", false);
+ doc->PDF_Options.displayThumbs = attrs.valueAsBool("displayThumbs", false);
+ doc->PDF_Options.hideMenuBar = attrs.valueAsBool("hideMenuBar", false);
+ doc->PDF_Options.hideToolBar = attrs.valueAsBool("hideToolBar", false);
+ doc->PDF_Options.fitWindow = attrs.valueAsBool("fitWindow", false);
+ doc->PDF_Options.PageLayout = attrs.valueAsInt("PageLayout", 0);
+ doc->PDF_Options.openAction = attrs.valueAsString("openAction", "");
+
+ QStringRef tagName = reader.name();
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ reader.readNext();
+ if (reader.isEndElement() && (reader.name() == tagName))
+ break;
+ if (!reader.isStartElement())
+ continue;
+ QStringRef tName = reader.name();
+ attrs = reader.scAttributes();
+ if(tName == "LPI")
+ {
+ struct LPIData lpo;
+ lpo.Angle = attrs.valueAsInt("Angle");
+ lpo.Frequency = attrs.valueAsInt("Frequency");
+ lpo.SpotFunc = attrs.valueAsInt("SpotFunction");
+ doc->PDF_Options.LPISettings[attrs.valueAsString("Color")] = lpo;
+ }
+ if(tName == "Fonts")
+ {
+ QString fname = attrs.valueAsString("Name");
+ if (!doc->PDF_Options.EmbedList.contains(fname))
+ doc->PDF_Options.EmbedList.append(fname);
+ }
+ if(tName == "Subset")
+ {
+ QString sname = attrs.valueAsString("Name");
+ if (!doc->PDF_Options.SubsetList.contains(sname))
+ doc->PDF_Options.SubsetList.append(sname);
+ }
+ if(tName == "Effekte")
+ {
+ struct PDFPresentationData ef;
+ ef.pageEffectDuration = attrs.valueAsInt("pageEffectDuration");
+ ef.pageViewDuration = attrs.valueAsInt("pageViewDuration");
+ ef.effectType = attrs.valueAsInt("effectType");
+ ef.Dm = attrs.valueAsInt("Dm");
+ ef.M = attrs.valueAsInt("M");
+ ef.Di = attrs.valueAsInt("Di");
+ doc->PDF_Options.PresentVals.append(ef);
+ }
+ }
+ return !reader.hasError();
+}
+
+bool Scribus150Format::readPrinterOptions(ScribusDoc* doc, ScXmlStreamReader& reader)
+{
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ doc->Print_Options.firstUse = attrs.valueAsBool("firstUse");
+ doc->Print_Options.toFile = attrs.valueAsBool("toFile");
+ doc->Print_Options.useAltPrintCommand = attrs.valueAsBool("useAltPrintCommand");
+ doc->Print_Options.outputSeparations = attrs.valueAsBool("outputSeparations");
+ doc->Print_Options.useSpotColors = attrs.valueAsBool("useSpotColors");
+ doc->Print_Options.useColor = attrs.valueAsBool("useColor");
+ doc->Print_Options.mirrorH = attrs.valueAsBool("mirrorH");
+ doc->Print_Options.mirrorV = attrs.valueAsBool("mirrorV");
+ doc->Print_Options.useICC = attrs.valueAsBool("useICC");
+ doc->Print_Options.doGCR = attrs.valueAsBool("doGCR");
+ doc->Print_Options.doClip = attrs.valueAsBool("doClip");
+ doc->Print_Options.setDevParam = attrs.valueAsBool("setDevParam");
+ doc->Print_Options.useDocBleeds = attrs.valueAsBool("useDocBleeds");
+ doc->Print_Options.cropMarks = attrs.valueAsBool("cropMarks");
+ doc->Print_Options.bleedMarks = attrs.valueAsBool("bleedMarks");
+ doc->Print_Options.registrationMarks = attrs.valueAsBool("registrationMarks");
+ doc->Print_Options.colorMarks = attrs.valueAsBool("colorMarks");
+ doc->Print_Options.includePDFMarks = attrs.valueAsBool("includePDFMarks", "1");
+ if (attrs.hasAttribute("PrintEngine"))
+ doc->Print_Options.prnEngine = (PrintEngine) attrs.valueAsInt("PrintEngine", 3);
+ else
+ doc->Print_Options.prnEngine = (PrintEngine) attrs.valueAsInt("PSLevel", 3);
+ doc->Print_Options.markOffset = attrs.valueAsDouble("markOffset");
+ doc->Print_Options.bleeds.Top = attrs.valueAsDouble("BleedTop");
+ doc->Print_Options.bleeds.Left = attrs.valueAsDouble("BleedLeft");
+ doc->Print_Options.bleeds.Right = attrs.valueAsDouble("BleedRight");
+ doc->Print_Options.bleeds.Bottom = attrs.valueAsDouble("BleedBottom");
+ doc->Print_Options.printer = attrs.valueAsString("printer");
+ doc->Print_Options.filename = attrs.valueAsString("filename");
+ doc->Print_Options.separationName = attrs.valueAsString("separationName");
+ doc->Print_Options.printerCommand = attrs.valueAsString("printerCommand");
+ doc->Print_Options.copies = 1;
+
+ QStringRef tagName = reader.name();
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ ScXmlStreamReader::TokenType tType = reader.readNext();
+ QStringRef tName = reader.name();
+ if (tType == ScXmlStreamReader::StartElement && tName == "Separation")
+ doc->Print_Options.allSeparations.append(reader.attributes().value("Name").toString());
+ if (tType == ScXmlStreamReader::EndElement && tName == tagName)
+ break;
+ }
+ return !reader.hasError();
+}
+
+bool Scribus150Format::readDocItemAttributes(ScribusDoc *doc, ScXmlStreamReader& reader)
+{
+ QStringRef tagName = reader.name();
+ doc->docItemAttributes.clear();
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ reader.readNext();
+ if (reader.isEndElement() && reader.name() == tagName)
+ break;
+ if(reader.isStartElement() && reader.name() == "ItemAttribute")
+ {
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ ObjectAttribute objattr;
+ objattr.name = attrs.valueAsString("Name");
+ objattr.type = attrs.valueAsString("Type");
+ objattr.value = attrs.valueAsString("Value");
+ objattr.parameter = attrs.valueAsString("Parameter");
+ objattr.relationship = attrs.valueAsString("Relationship");
+ objattr.relationshipto = attrs.valueAsString("RelationshipTo");
+ objattr.autoaddto = attrs.valueAsString("AutoAddTo");
+ doc->docItemAttributes.append(objattr);
+ }
+ }
+ return !reader.hasError();
+}
+
+bool Scribus150Format::readTableOfContents(ScribusDoc* doc, ScXmlStreamReader& reader)
+{
+ QStringRef tagName = reader.name();
+ m_Doc->docToCSetups.clear();
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ reader.readNext();
+ if (reader.isEndElement() && reader.name() == tagName)
+ break;
+ if(reader.isStartElement() && reader.name() == "TableOfContents")
+ {
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ ToCSetup tocsetup;
+ tocsetup.name = attrs.valueAsString("Name");
+ tocsetup.itemAttrName = attrs.valueAsString("ItemAttributeName");
+ tocsetup.frameName = attrs.valueAsString("FrameName");
+ tocsetup.textStyle = attrs.valueAsString("Style");
+ tocsetup.listNonPrintingFrames = QVariant(attrs.valueAsString("ListNonPrinting")).toBool();
+ QString numberPlacement = attrs.valueAsString("NumberPlacement");
+ if (numberPlacement == "Beginning")
+ tocsetup.pageLocation = Beginning;
+ if (numberPlacement == "End")
+ tocsetup.pageLocation = End;
+ if (numberPlacement == "NotShown")
+ tocsetup.pageLocation = NotShown;
+ doc->docToCSetups.append(tocsetup);
+ }
+ }
+ return !reader.hasError();
+}
+
+bool Scribus150Format::readSections(ScribusDoc* doc, ScXmlStreamReader& reader)
+{
+ QStringRef tagName = reader.name();
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ reader.readNext();
+ if (reader.isEndElement() && reader.name() == tagName)
+ break;
+ if (reader.isStartElement() && reader.name() == "Section")
+ {
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ struct DocumentSection newSection;
+ newSection.number = attrs.valueAsInt("Number");
+ newSection.name = attrs.valueAsString("Name");
+ newSection.fromindex = attrs.valueAsInt("From");
+ newSection.toindex = attrs.valueAsInt("To");
+ QString type = attrs.valueAsString("Type");
+ if (type == "Type_1_2_3")
+ newSection.type=Type_1_2_3;
+ if (type == "Type_i_ii_iii")
+ newSection.type=Type_i_ii_iii;
+ if (type == "Type_I_II_III")
+ newSection.type=Type_I_II_III;
+ if (type == "Type_a_b_c")
+ newSection.type=Type_a_b_c;
+ if (type == "Type_A_B_C")
+ newSection.type=Type_A_B_C;
+ if (type == "Type_None")
+ newSection.type=Type_None;
+ newSection.sectionstartindex = attrs.valueAsInt("Start");
+ newSection.reversed = attrs.valueAsBool("Reversed");
+ newSection.active = attrs.valueAsBool("Active");
+ doc->sections.insert(newSection.number, newSection);
+ }
+ }
+ return !reader.hasError();
+}
+
+bool Scribus150Format::readHyphen(ScribusDoc *doc, ScXmlStreamReader& reader)
+{
+ QStringRef tagName = reader.name();
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ reader.readNext();
+ if (reader.isEndElement() && reader.name() == tagName)
+ break;
+ if (reader.isStartElement() && reader.name() == "EXCEPTION")
+ {
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ QString word = attrs.valueAsString("WORD");
+ QString hyph = attrs.valueAsString("HYPHENATED");
+ doc->docHyphenator->specialWords.insert(word, hyph);
+ }
+ else if (reader.isStartElement() && reader.name() == "IGNORE")
+ {
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ QString word = attrs.valueAsString("WORD");
+ doc->docHyphenator->ignoredWords.insert(word);
+ }
+ }
+ return !reader.hasError();
+}
+
+bool Scribus150Format::readPage(ScribusDoc* doc, ScXmlStreamReader& reader)
+{
+ QStringRef tagName = reader.name();
+
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ int pageNum = attrs.valueAsInt("NUM");
+ QString pageName = attrs.valueAsString("NAM", "");
+ if (tagName == "MASTERPAGE" && pageName.isEmpty())
+ {
+ qDebug() << "scribus150format: corrupted masterpage with empty name detected";
+ return true;
+ }
+ m_Doc->setMasterPageMode(!pageName.isEmpty());
+ Page* newPage = pageName.isEmpty() ? doc->addPage(pageNum) : doc->addMasterPage(pageNum, pageName);
+
+ newPage->LeftPg = attrs.valueAsInt("LEFT", 0);
+ QString mpName = attrs.valueAsString("MNAM", "Normal");
+ newPage->MPageNam = m_Doc->masterPageMode() ? QString("") : mpName;
+ if (attrs.hasAttribute("Size"))
+ newPage->m_pageSize = attrs.valueAsString("Size");
+ if (attrs.hasAttribute("Orientation"))
+ newPage->setOrientation(attrs.valueAsInt("Orientation"));
+ newPage->setXOffset(attrs.valueAsDouble("PAGEXPOS"));
+ newPage->setYOffset(attrs.valueAsDouble("PAGEYPOS"));
+ if (attrs.hasAttribute("PAGEWIDTH"))
+ newPage->setWidth(attrs.valueAsDouble("PAGEWIDTH"));
+ else
+ newPage->setWidth(attrs.valueAsDouble("PAGEWITH"));
+ newPage->setHeight(attrs.valueAsDouble("PAGEHEIGHT"));
+ newPage->setInitialHeight(newPage->height());
+ newPage->setInitialWidth(newPage->width());
+ newPage->initialMargins.Top = qMax(0.0, attrs.valueAsDouble("BORDERTOP"));
+ newPage->initialMargins.Bottom = qMax(0.0, attrs.valueAsDouble("BORDERBOTTOM"));
+ newPage->initialMargins.Left = qMax(0.0, attrs.valueAsDouble("BORDERLEFT"));
+ newPage->initialMargins.Right = qMax(0.0, attrs.valueAsDouble("BORDERRIGHT"));
+ newPage->marginPreset = attrs.valueAsInt("PRESET", 0);
+ newPage->Margins.Top = newPage->initialMargins.Top;
+ newPage->Margins.Bottom = newPage->initialMargins.Bottom;
+ m_Doc->setMasterPageMode(false);
+ //m_Doc->Pages=&m_Doc->DocPages;
+ // guides reading
+ newPage->guides.setHorizontalAutoGap( attrs.valueAsDouble("AGhorizontalAutoGap", 0.0));
+ newPage->guides.setVerticalAutoGap ( attrs.valueAsDouble("AGverticalAutoGap", 0.0));
+ newPage->guides.setHorizontalAutoCount( attrs.valueAsInt("AGhorizontalAutoCount", 0) );
+ newPage->guides.setVerticalAutoCount ( attrs.valueAsInt("AGverticalAutoCount", 0) );
+ newPage->guides.setHorizontalAutoRefer( attrs.valueAsInt("AGhorizontalAutoRefer", 0) );
+ newPage->guides.setVerticalAutoRefer ( attrs.valueAsInt("AGverticalAutoRefer", 0) );
+ GuideManagerIO::readVerticalGuides(attrs.valueAsString("VerticalGuides"),
+ newPage,
+ GuideManagerCore::Standard,
+ attrs.hasAttribute("NumVGuides"));
+ GuideManagerIO::readHorizontalGuides(attrs.valueAsString("HorizontalGuides"),
+ newPage,
+ GuideManagerCore::Standard,
+ attrs.hasAttribute("NumHGuides"));
+ GuideManagerIO::readSelection(attrs.valueAsString("AGSelection"), newPage);
+ return true;
+}
+
+bool Scribus150Format::readObject(ScribusDoc* doc, ScXmlStreamReader& reader, ItemInfo& info, const QString& baseDir, bool loadPage)
+{
+ QStringRef tagName = reader.name();
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+
+ if (!loadPage)
+ {
+ if (tagName == "PAGEOBJECT" || tagName == "FRAMEOBJECT" || tagName == "PatternItem")
+ doc->setMasterPageMode(false);
+ else
+ doc->setMasterPageMode(true);
+ }
+ int pagenr = -1;
+ if ((!attrs.value("OnMasterPage").isEmpty()) && (tagName == "MASTEROBJECT"))
+ {
+ doc->setCurrentPage(doc->MasterPages.at(doc->MasterNames[attrs.valueAsString("OnMasterPage")]));
+ pagenr = -2;
+ }
+
+ PageItem* newItem = pasteItem(doc, attrs, baseDir, pagenr);
+ newItem->setRedrawBounding();
+ if (tagName == "MASTEROBJECT")
+ newItem->OwnPage = doc->OnPage(newItem);
+ else
+ newItem->OwnPage = attrs.valueAsInt("OwnPage");
+ if (tagName == "PAGEOBJECT")
+ newItem->OnMasterPage = "";
+ QString tmpf = attrs.valueAsString("IFONT", doc->toolSettings.defFont);
+ m_AvailableFonts->findFont(tmpf, doc);
+
+// newItem->Language = ScMW->GetLang(pg.attribute("LANGUAGE", doc->Language));
+ newItem->isAutoText = attrs.valueAsBool("AUTOTEXT", false);
+ newItem->isEmbedded = attrs.valueAsBool("isInline", false);
+ newItem->gXpos = attrs.valueAsDouble("gXpos", 0.0);
+ newItem->gYpos = attrs.valueAsDouble("gYpos", 0.0);
+ newItem->gWidth = attrs.valueAsDouble("gWidth", newItem->width());
+ newItem->gHeight = attrs.valueAsDouble("gHeight", newItem->height());
+ if (newItem->isAutoText)
+ doc->LastAuto = newItem;
+
+ if (tagName == "FRAMEOBJECT")
+ {
+ doc->FrameItems.append(doc->Items->takeAt(newItem->ItemNr));
+ newItem->ItemNr = doc->FrameItems.count()-1;
+ }
+
+ info.item = newItem;
+ info.nextItem = attrs.valueAsInt("NEXTITEM", -1);
+ info.ownLink = newItem->isTableItem ? attrs.valueAsInt("OwnLINK", 0) : 0;
+ info.groupLastItem = 0;
+
+ newItem->isGroupControl = attrs.valueAsBool("isGroupControl", 0);
+ if (newItem->isGroupControl)
+ {
+ int groupLastItem = attrs.valueAsInt("groupsLastItem", 0);
+ // Sanity check for some broken files created using buggy development versions.
+ if ((newItem->Groups.count() == 0) || (groupLastItem <= 0))
+ {
+ newItem->isGroupControl = false;
+ newItem->setFillColor("None");
+ }
+ info.groupLastItem = groupLastItem;
+ }
+
+ bool layerFound = true;
+ struct ImageLoadRequest loadingInfo;
+#ifdef HAVE_OSG
+ struct PageItem_OSGFrame::viewDefinition currentView;
+#endif
+ QList<ParagraphStyle::TabRecord> tabValues;
+
+ LastStyles * lastStyle = new LastStyles();
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ ScXmlStreamReader::TokenType tType = reader.readNext();
+ if (reader.isEndElement() && tagName == reader.name())
+ break;
+ if (tType != ScXmlStreamReader::StartElement)
+ continue;
+ QStringRef tName = reader.name();
+ ScXmlStreamAttributes tAtt = reader.scAttributes();
+ if (tName == "CSTOP")
+ {
+ QString name = tAtt.valueAsString("NAME");
+ double ramp = tAtt.valueAsDouble("RAMP", 0.0);
+ int shade = tAtt.valueAsInt("SHADE", 100);
+ double opa = tAtt.valueAsDouble("TRANS", 1.0);
+ newItem->fill_gradient.addStop(SetColor(doc, name, shade), ramp, 0.5, opa, name, shade);
+ }
+
+ if (tName == "ITEXT")
+ readItemText(newItem, tAtt, lastStyle);
+ else if (tName == "para")
+ {
+ newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::PARSEP);
+ ParagraphStyle newStyle;
+ PrefsManager* prefsManager = PrefsManager::instance();
+ readParagraphStyle(doc, reader, newStyle, prefsManager->appPrefs.AvailFonts);
+ newItem->itemText.setStyle(newItem->itemText.length()-1, newStyle);
+ newItem->itemText.setCharStyle(newItem->itemText.length()-1, 1, lastStyle->Style);
+ }
+ else if (tName == "trail")
+ {
+ ParagraphStyle newStyle;
+ PrefsManager* prefsManager = PrefsManager::instance();
+ readParagraphStyle(doc, reader, newStyle, prefsManager->appPrefs.AvailFonts);
+ newItem->itemText.setStyle(newItem->itemText.length(), newStyle);
+ }
+ else if (tName == "tab")
+ newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::TAB);
+ else if (tName == "breakline")
+ newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::LINEBREAK);
+ else if (tName == "breakcol")
+ newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::COLBREAK);
+ else if (tName == "breakframe")
+ newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::FRAMEBREAK);
+ else if (tName == "nbhyphen")
+ newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::NBHYPHEN);
+ else if (tName == "nbspace")
+ newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::NBSPACE);
+ else if (tName == "zwnbspace")
+ newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::ZWNBSPACE);
+ else if (tName == "zwspace")
+ newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::ZWSPACE);
+ else if (tName == "var")
+ {
+ CharStyle newStyle;
+ if (tAtt.value("name") == "pgno")
+ newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::PAGENUMBER);
+ else
+ newItem->itemText.insertChars(newItem->itemText.length(), SpecialChars::PAGECOUNT);
+ readCharacterStyleAttrs(doc, tAtt, newStyle);
+ newItem->itemText.setCharStyle(newItem->itemText.length()-1, 1, newStyle);
+ lastStyle->StyleStart = newItem->itemText.length()-1;
+ lastStyle->Style = newStyle;
+ }
+ if (tName == "PageItemAttributes")
+ {
+ readPageItemAttributes(newItem, reader);
+ }
+ if (tName == "PSDLayer")
+ {
+ layerFound = true;
+ loadingInfo.blend = tAtt.valueAsString("Blend");
+ loadingInfo.opacity = tAtt.valueAsInt("Opacity");
+ loadingInfo.visible = tAtt.valueAsBool("Visible");
+ loadingInfo.useMask = tAtt.valueAsBool("useMask", true);
+ newItem->pixm.imgInfo.RequestProps.insert(tAtt.valueAsInt("Layer"), loadingInfo);
+ }
+#ifdef HAVE_OSG
+ if (tName == "OSGViews")
+ {
+ currentView.angleFOV = tAtt.valueAsDouble("angleFOV");
+ QString tmp = "";
+ tmp = tAtt.valueAsString("trackM");
+ ScTextStream fp(&tmp, QIODevice::ReadOnly);
+ double m1, m2, m3, m4;
+ double m5, m6, m7, m8;
+ double m9, m10, m11, m12;
+ double m13, m14, m15, m16;
+ fp >> m1 >> m2 >> m3 >> m4;
+ fp >> m5 >> m6 >> m7 >> m8;
+ fp >> m9 >> m10 >> m11 >> m12;
+ fp >> m13 >> m14 >> m15 >> m16;
+ currentView.trackerMatrix.set(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16);
+ tmp = "";
+ tmp = tAtt.valueAsString("trackC");
+ ScTextStream fp2(&tmp, QIODevice::ReadOnly);
+ double v1, v2, v3;
+ fp2 >> v1 >> v2 >> v3;
+ currentView.trackerCenter.set(v1, v2, v3);
+ tmp = "";
+ tmp = tAtt.valueAsString("cameraP");
+ ScTextStream fp3(&tmp, QIODevice::ReadOnly);
+ fp3 >> v1 >> v2 >> v3;
+ currentView.cameraPosition.set(v1, v2, v3);
+ tmp = "";
+ tmp = tAtt.valueAsString("cameraU");
+ ScTextStream fp4(&tmp, QIODevice::ReadOnly);
+ fp4 >> v1 >> v2 >> v3;
+ currentView.cameraUp.set(v1, v2, v3);
+ currentView.trackerDist = tAtt.valueAsDouble("trackerDist");
+ currentView.trackerSize = tAtt.valueAsDouble("trackerSize");
+ currentView.illumination = static_cast<PageItem_OSGFrame::LightType>(tAtt.valueAsInt("illumination"));
+ currentView.rendermode = static_cast<PageItem_OSGFrame::RenderType>(tAtt.valueAsInt("rendermode"));
+ currentView.addedTransparency = tAtt.valueAsDouble("trans");
+ currentView.colorAC = QColor(tAtt.valueAsString("colorAC"));
+ currentView.colorFC = QColor(tAtt.valueAsString("colorFC"));
+ if (newItem->asOSGFrame())
+ newItem->asOSGFrame()->viewMap.insert(tAtt.valueAsString("viewName"), currentView);
+ }
+#endif
+ if (tName == "ImageEffect")
+ {
+ struct ImageEffect ef;
+ ef.effectParameters = tAtt.valueAsString("Param");
+ ef.effectCode = tAtt.valueAsInt("Code");
+ newItem->effectsInUse.append(ef);
+ }
+ if (tName == "Tabs")
+ {
+ ParagraphStyle::TabRecord tb;
+ tb.tabPosition = tAtt.valueAsDouble("Pos");
+ tb.tabType = tAtt.valueAsInt("Type");
+ QString tbCh = tAtt.valueAsString("Fill", "");
+ tb.tabFillChar = tbCh.isEmpty() ? QChar() : tbCh[0];
+ tabValues.append(tb);
+ }
+ if (tName == "LATEX")
+ {
+ if (newItem->asLatexFrame())
+ {
+ readLatexInfo(newItem->asLatexFrame(), reader);
+ }
+ else
+ {
+ while (!reader.atEnd() && !reader.hasError())
+ {
+ reader.readNext();
+ if (reader.isEndElement() && reader.name() == tName)
+ break;
+ }
+ }
+ }
+ }
+ delete lastStyle;
+
+ if (tabValues.count() > 0)
+ {
+ ParagraphStyle newDefault(newItem->itemText.defaultStyle());
+ newDefault.setTabValues(tabValues);
+ newItem->itemText.setDefaultStyle(newDefault);
+ }
+
+ if (newItem->fill_gradient.Stops() == 0)
+ {
+ const ScColor& col1 = doc->PageColors[doc->toolSettings.dBrush];
+ const ScColor& col2 = doc->PageColors[doc->toolSettings.dPen];
+ newItem->fill_gradient.addStop(ScColorEngine::getRGBColor(col1, doc), 0.0, 0.5, 1.0, doc->toolSettings.dBrush, 100);
+ newItem->fill_gradient.addStop(ScColorEngine::getRGBColor(col2, doc), 1.0, 0.5, 1.0, doc->toolSettings.dPen, 100);
+ }
+
+ if (newItem->asPathText())
+ {
+ newItem->updatePolyClip();
+ newItem->Frame = true;
+ }
+#ifdef HAVE_OSG
+ if (newItem->asImageFrame() || newItem->asLatexFrame() || newItem->asOSGFrame())
+#else
+ if (newItem->asImageFrame() || newItem->asLatexFrame())
+#endif
+ {
+ if (!newItem->Pfile.isEmpty())
+ {
+ doc->loadPict(newItem->Pfile, newItem, false);
+ if (layerFound)
+ {
+ newItem->pixm.imgInfo.isRequest = true;
+ doc->loadPict(newItem->Pfile, newItem, true);
+ }
+ newItem->AdjustPictScale();
+ }
+ }
+
+ if (!loadPage)
+ doc->setMasterPageMode(false);
+ return !reader.hasError();
+}
+
+bool Scribus150Format::readPattern(ScribusDoc* doc, ScXmlStreamReader& reader, const QString& baseDir)
+{
+ ScPattern pat;
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ QString patternName = attrs.valueAsString("Name");
+ bool success = true;
+
+ if (patternName.isEmpty())
+ {
+ reader.readToElementEnd();
+ return true;
+ }
+
+ QMap<PageItem*, int> groupID2;
+ QMap<int,int> TableID2;
+ QList<PageItem*> TableItems2;
+
+ pat.setDoc(doc);
+ pat.width = attrs.valueAsDouble("width", 0.0);
+ pat.height = attrs.valueAsDouble("height", 0.0);
+ pat.scaleX = attrs.valueAsDouble("scaleX", 0.0);
+ pat.scaleY = attrs.valueAsDouble("scaleY", 0.0);
+ pat.xoffset = attrs.valueAsDouble("xoffset", 0.0);
+ pat.yoffset = attrs.valueAsDouble("yoffset", 0.0);
+
+ uint itemCount1 = m_Doc->Items->count();
+ bool savedAlignGrid = m_Doc->useRaster;
+ bool savedAlignGuides = m_Doc->SnapGuides;
+ m_Doc->useRaster = false;
+ m_Doc->SnapGuides = false;
+
+ QStringRef tagName = reader.name();
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ reader.readNext();
+ if (reader.isEndElement() && reader.name() == tagName)
+ break;
+ if (!reader.isStartElement() || reader.name() != "PatternItem")
+ continue;
+
+ QStringRef tName = reader.name();
+ ScXmlStreamAttributes tAtt = reader.attributes();
+
+ ItemInfo itemInfo;
+ m_Doc->setMasterPageMode(false);
+
+ int ownPage = tAtt.valueAsInt("OwnPage");
+ success = readObject(doc, reader, itemInfo, baseDir, false);
+ if (!success) break;
+
+ itemInfo.item->OwnPage = ownPage;
+ itemInfo.item->OnMasterPage = "";
+
+ if (itemInfo.item->isTableItem)
+ {
+ TableItems2.append(itemInfo.item);
+ TableID2.insert(itemInfo.ownLink, itemInfo.item->ItemNr);
+ }
+ if (itemInfo.item->isGroupControl)
+ {
+ groupID2.insert(itemInfo.item, itemInfo.groupLastItem + itemInfo.item->ItemNr);
+ }
+ }
+
+ doc->useRaster = savedAlignGrid;
+ doc->SnapGuides = savedAlignGuides;
+ if (!success)
+ {
+ return false;
+ }
+
+ if (groupID2.count() != 0)
+ {
+ QMap<PageItem*, int>::Iterator it;
+ for (it = groupID2.begin(); it != groupID2.end(); ++it)
+ {
+ it.key()->groupsLastItem = m_Doc->Items->at(it.value());
+ }
+ }
+ if (TableItems2.count() != 0)
+ {
+ for (int ttc = 0; ttc < TableItems2.count(); ++ttc)
+ {
+ PageItem* ta = TableItems2.at(ttc);
+ if (ta->TopLinkID != -1)
+ ta->TopLink = m_Doc->Items->at(TableID2[ta->TopLinkID]);
+ else
+ ta->TopLink = 0;
+ if (ta->LeftLinkID != -1)
+ ta->LeftLink = m_Doc->Items->at(TableID2[ta->LeftLinkID]);
+ else
+ ta->LeftLink = 0;
+ if (ta->RightLinkID != -1)
+ ta->RightLink = m_Doc->Items->at(TableID2[ta->RightLinkID]);
+ else
+ ta->RightLink = 0;
+ if (ta->BottomLinkID != -1)
+ ta->BottomLink = m_Doc->Items->at(TableID2[ta->BottomLinkID]);
+ else
+ ta->BottomLink = 0;
+ }
+ }
+
+ uint itemCount2 = m_Doc->Items->count();
+ if (itemCount2 > itemCount1)
+ {
+ PageItem* currItem = doc->Items->at(itemCount1), *newItem;
+ pat.pattern = currItem->DrawObj_toImage();
+ pat.pattern = pat.pattern.copy(-pat.xoffset, -pat.yoffset, pat.width, pat.height);
+ for (uint as = itemCount1; as < itemCount2; ++as)
+ {
+ newItem = doc->Items->takeAt(itemCount1);
+ newItem->moveBy(pat.xoffset, pat.yoffset, true);
+ newItem->gXpos += pat.xoffset;
+ newItem->gYpos += pat.yoffset;
+ newItem->ItemNr = pat.items.count();
+ pat.items.append(newItem);
+ }
+ }
+ doc->docPatterns.insert(patternName, pat);
+
+ return success;
+}
+
+bool Scribus150Format::readItemText(PageItem *obj, ScXmlStreamAttributes& attrs, LastStyles* last)
+{
+ QString tmp2;
+ CharStyle newStyle;
+ ScribusDoc* doc = obj->doc();
+
+ readCharacterStyleAttrs(doc, attrs, newStyle);
+
+ if (attrs.hasAttribute(QLatin1String("Unicode")))
+ {
+ tmp2 = QChar(attrs.valueAsInt("Unicode"));
+ }
+ else
+ {
+ tmp2 = attrs.valueAsString("CH");
+
+ // legacy stuff:
+ tmp2.replace(QRegExp("\r"), QChar(13));
+ tmp2.replace(QRegExp("\n"), QChar(13));
+ tmp2.replace(QRegExp("\t"), QChar(9));
+ }
+
+ // more legacy stuff:
+ QString pstylename = attrs.valueAsString("PSTYLE", "");
+
+ fixLegacyCharStyle(newStyle);
+ last->ParaStyle = pstylename;
+ // end of legacy stuff
+
+ int iobj = attrs.valueAsInt("COBJ", -1);
+
+ for (int cxx=0; cxx<tmp2.length(); ++cxx)
+ {
+ QChar ch = tmp2.at(cxx);
+ { // Legacy mode
+ if (ch == QChar(5))
+ ch = SpecialChars::PARSEP;
+ if (ch == QChar(4))
+ ch = SpecialChars::TAB;
+ }
+
+ int pos = obj->itemText.length();
+ if (ch == SpecialChars::OBJECT) {
+ if (iobj != -1) {
+ obj->itemText.insertObject(pos, doc->FrameItems.at(iobj));
+ }
+ }
+ else if (ch == SpecialChars::SHYPHEN && pos > 0)
+ {
+// qDebug() << QString("scribus150format: SHYPHEN at %1").arg(pos);
+ ScText* lastItem = obj->itemText.item(pos-1);
+ // double SHY means user provided SHY, single SHY is automatic one
+ if (lastItem->effects() & ScStyle_HyphenationPossible)
+ {
+ lastItem->setEffects(lastItem->effects() & ~ScStyle_HyphenationPossible);
+ obj->itemText.insertChars(pos, QString(ch));
+ }
+ else
+ {
+ lastItem->setEffects(lastItem->effects() | ScStyle_HyphenationPossible);
+ }
+ }
+ else {
+ obj->itemText.insertChars(pos, QString(ch));
+ }
+// qDebug() << QString("style at %1: %2 ^ %3 = %4 (%5)").arg(pos).arg((uint)newStyle.effects()).arg((uint)last->Style.effects()).arg((uint)(newStyle.effects() ^ last->Style.effects())).arg(newStyle != last->Style);
+ if (newStyle != last->Style) // || (newStyle.effects() ^ last->Style.effects()) == ScStyle_HyphenationPossible)
+ { // FIXME StyleFlag operator== ignores hyphen flag
+// qDebug() << QString("new style at %1: %2 -> %3").arg(pos).arg(last->Style.asString()).arg(newStyle.asString());
+ obj->itemText.setCharStyle(last->StyleStart, pos-last->StyleStart, last->Style);
+ last->Style = newStyle;
+ last->StyleStart = pos;
+ }
+ if (ch == SpecialChars::PARSEP) {
+ ParagraphStyle pstyle;
+ // Qt4 if (last->ParaStyle >= 0) {
+ if (!last->ParaStyle.isEmpty()) {
+ pstyle.setParent( last->ParaStyle );
+ }
+ obj->itemText.applyStyle(pos, pstyle);
+ }
+ }
+
+ obj->itemText.setCharStyle(last->StyleStart, obj->itemText.length()-last->StyleStart, last->Style);
+ last->StyleStart = obj->itemText.length();
+/*
+ QString dbg("");
+ for (int i=0; i < obj->itemText.length(); ++i)
+ {
+ dbg += obj->itemText.text(i,1);
+ if (obj->itemText.item(i)->effects() & ScStyle_HyphenationPossible)
+ dbg += "~";
+ }
+ qDebug("scribus150format: read itemtext %d '%s'", obj->itemText.length(), dbg.latin1());
+ */
+ ParagraphStyle pstyle;
+
+ if (!last->ParaStyle.isEmpty()) { // Qt4 >= 0) {
+ pstyle.setParent( last->ParaStyle );
+ obj->itemText.applyStyle(obj->itemText.length()-1, pstyle);
+ }
+
+ return true;
+}
+
+bool Scribus150Format::readPageItemAttributes(PageItem* item, ScXmlStreamReader& reader)
+{
+ QStringRef tagName = reader.name();
+ ObjAttrVector pageItemAttributes;
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ reader.readNext();
+ if (reader.isEndElement() && reader.name() == tagName)
+ break;
+ if (reader.isStartElement() && reader.name() == "ItemAttribute")
+ {
+ ScXmlStreamAttributes tAtt = reader.scAttributes();
+ ObjectAttribute objattr;
+ objattr.name = tAtt.valueAsString("Name");
+ objattr.type = tAtt.valueAsString("Type");
+ objattr.value = tAtt.valueAsString("Value");
+ objattr.parameter = tAtt.valueAsString("Parameter");
+ objattr.relationship = tAtt.valueAsString("Relationship");
+ objattr.relationshipto = tAtt.valueAsString("RelationshipTo");
+ objattr.autoaddto = tAtt.valueAsString("AutoAddTo");
+ pageItemAttributes.append(objattr);
+ }
+ }
+ item->setObjectAttributes(&pageItemAttributes);
+ return !reader.hasError();
+}
+
+PageItem* Scribus150Format::pasteItem(ScribusDoc *doc, ScXmlStreamAttributes& attrs, const QString& baseDir, int pagenr)
+{
+ int z = 0;
+ struct ImageLoadRequest loadingInfo;
+ PageItem::ItemType pt = static_cast<PageItem::ItemType>(attrs.valueAsInt("PTYPE"));
+ double xf, yf;
+ double x = attrs.valueAsDouble("XPOS");
+ double y = attrs.valueAsDouble("YPOS");
+ double w = attrs.valueAsDouble("WIDTH");
+ double h = attrs.valueAsDouble("HEIGHT");
+ double pw = attrs.valueAsDouble("PWIDTH");
+ double scx = attrs.valueAsDouble("LOCALSCX");
+ double scy = attrs.valueAsDouble("LOCALSCY");
+ QString Pcolor = attrs.valueAsString("PCOLOR");
+ if (Pcolor.isEmpty())
+ Pcolor = CommonStrings::None;
+ QString Pcolor2 = attrs.valueAsString("PCOLOR2");
+ if (Pcolor2.isEmpty())
+ Pcolor2 = CommonStrings::None;
+ QColor tmpc;
+ PageItem *currItem=NULL;
+ QString tmp, clPath;
+ int xi;
+
+ switch (pt)
+ {
+ // OBSOLETE CR 2005-02-06
+ case PageItem::ItemType1:
+ z = doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, x, y, w, h, pw, Pcolor, Pcolor2, true);
+ currItem = doc->Items->at(z);
+ if (pagenr > -2)
+ currItem->OwnPage = pagenr;
+ break;
+ //
+ case PageItem::ImageFrame:
+ case PageItem::OSGFrame:
+ case PageItem::LatexFrame: /*Everything that is valid for image frames is also valid for latex frames*/
+ z = doc->itemAdd(pt, PageItem::Unspecified, x, y, w, h, 1, doc->toolSettings.dBrushPict, CommonStrings::None, true);
+ currItem = doc->Items->at(z);
+ if (pagenr > -2)
+ currItem->OwnPage = pagenr;
+ UndoManager::instance()->setUndoEnabled(false);
+ currItem->setImageXYScale(scx, scy);
+ currItem->setImageXYOffset(attrs.valueAsDouble("LOCALX"), attrs.valueAsDouble("LOCALY"));
+// if (!currItem->asLatexFrame())
+#ifdef HAVE_OSG
+ if ((currItem->asImageFrame() || currItem->asOSGFrame()) && (!currItem->asLatexFrame()))
+#else
+ if ((currItem->asImageFrame()) && (!currItem->asLatexFrame()))
+#endif
+ {
+ bool inlineF = attrs.valueAsBool("isInlineImage", false);
+ QString dat = attrs.valueAsString("ImageData", "");
+ QByteArray inlineImageData;
+ inlineImageData.append(dat);
+ QString inlineImageExt = attrs.valueAsString("inlineImageExt", "");
+ if (inlineF)
+ {
+ if (inlineImageData.size() > 0)
+ {
+ currItem->tempImageFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_XXXXXX." + inlineImageExt);
+ currItem->tempImageFile->open();
+ QString fileName = getLongPathName(currItem->tempImageFile->fileName());
+ currItem->tempImageFile->close();
+ inlineImageData = qUncompress(QByteArray::fromBase64(inlineImageData));
+ QFile outFil(fileName);
+ if (outFil.open(QIODevice::WriteOnly))
+ {
+ outFil.write(inlineImageData);
+ outFil.close();
+ currItem->isInlineImage = true;
+ currItem->Pfile = fileName;
+ }
+ }
+ }
+ else
+ currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE"), baseDir);
+#ifdef HAVE_OSG
+ if (currItem->asOSGFrame())
+ {
+ PageItem_OSGFrame *osgframe = currItem->asOSGFrame();
+ osgframe->modelFile = Relative2Path(attrs.valueAsString("modelFile"), baseDir);
+ osgframe->currentView = attrs.valueAsString("currentViewName", "");
+ osgframe->loadModel();
+ }
+#endif
+ }
+ currItem->IProfile = attrs.valueAsString("PRFILE", "");
+ currItem->EmProfile = attrs.valueAsString("EPROF" , "");
+ currItem->IRender = attrs.valueAsInt("IRENDER", 1);
+ currItem->UseEmbedded = attrs.valueAsInt("EMBEDDED", 1);
+ currItem->pixm.imgInfo.lowResType = attrs.valueAsInt("ImageRes", 1);
+ currItem->pixm.imgInfo.actualPageNumber = attrs.valueAsInt("Pagenumber", 0);
+ currItem->IProfile = attrs.valueAsString("PRFILE","");
+ currItem->EmProfile = attrs.valueAsString("EPROF","");
+ currItem->IRender = attrs.valueAsInt("IRENDER", 1);
+ currItem->UseEmbedded = attrs.valueAsInt("EMBEDDED", 1);
+ if (currItem->asLatexFrame())
+ {
+ currItem->setImageXYOffset(attrs.valueAsDouble("LOCALX") * scx, attrs.valueAsDouble("LOCALY") * scy);
+ // currItem->setImageXYScale(1.0, 1.0);
+ }
+ else
+ currItem->setImageXYScale(scx, scy);
+ clPath = attrs.valueAsString("ImageClip", "");
+ if (currItem->pixm.imgInfo.PDSpathData.contains(clPath))
+ {
+ currItem->imageClip = currItem->pixm.imgInfo.PDSpathData[clPath].copy();
+ currItem->pixm.imgInfo.usedPath = clPath;
+ QTransform cl;
+ cl.translate(currItem->imageXOffset()*currItem->imageXScale(), currItem->imageYOffset()*currItem->imageYScale());
+ cl.scale(currItem->imageXScale(), currItem->imageYScale());
+ currItem->imageClip.map(cl);
+ }
+ currItem->setImageShown( attrs.valueAsInt("PICART"));
+/* currItem->BBoxX = ScCLocale::toDoubleC( obj->attribute("BBOXX"));
+ currItem->BBoxH = ScCLocale::toDoubleC( obj->attribute("BBOXH")); */
+ currItem->ScaleType = attrs.valueAsInt("SCALETYPE", 1);
+ currItem->AspectRatio = attrs.valueAsInt("RATIO", 0);
+ currItem->setLineWidth(pw);
+ UndoManager::instance()->setUndoEnabled(true);
+ break;
+ // OBSOLETE CR 2005-02-06
+ case PageItem::ItemType3:
+ z = doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, x, y, w, h, pw, Pcolor, Pcolor2, true);
+ currItem = doc->Items->at(z);
+ if (pagenr > -2)
+ currItem->OwnPage = pagenr;
+ break;
+ //
+ case PageItem::PathText:
+ z = doc->itemAdd(PageItem::PathText, PageItem::Unspecified, x, y, w, h, pw, CommonStrings::None, Pcolor, true);
+ currItem = doc->Items->at(z);
+ if (pagenr > -2)
+ currItem->OwnPage = pagenr;
+ UndoManager::instance()->setUndoEnabled(false);
+ if (attrs.valueAsInt("ANNOTATION", 0) && attrs.valueAsBool("ANICON", false))
+ {
+ currItem->setImageXYScale(scx, scy);
+ currItem->setImageXYOffset(attrs.valueAsDouble("LOCALX"), attrs.valueAsDouble("LOCALY"));
+ currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE" , "") , baseDir);
+ currItem->Pfile2 = Relative2Path(attrs.valueAsString("PFILE2", ""), baseDir);
+ currItem->Pfile3 = Relative2Path(attrs.valueAsString("PFILE3", ""), baseDir);
+ currItem->IProfile = attrs.valueAsString("PRFILE", "");
+ currItem->EmProfile = attrs.valueAsString("EPROF", "");
+ currItem->IRender = attrs.valueAsInt("IRENDER", 1);
+ currItem->UseEmbedded = attrs.valueAsInt("EMBEDDED", 1);
+ doc->LoadPict(currItem->Pfile, z);
+ currItem->setImageXYScale(scx, scy);
+ currItem->setImageShown(attrs.valueAsInt("PICART"));
+/* currItem->BBoxX = ScCLocale::toDoubleC( obj->attribute("BBOXX"));
+ currItem->BBoxH = ScCLocale::toDoubleC( obj->attribute("BBOXH")); */
+ currItem->ScaleType = attrs.valueAsInt("SCALETYPE", 1);
+ currItem->AspectRatio = attrs.valueAsInt("RATIO", 0);
+ }
+ //currItem->convertTo(pt);
+ UndoManager::instance()->setUndoEnabled(true);
+ break;
+ case PageItem::TextFrame:
+ z = doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified, x, y, w, h, pw, CommonStrings::None, Pcolor, true);
+ currItem = doc->Items->at(z);
+ if (pagenr > -2)
+ currItem->OwnPage = pagenr;
+ UndoManager::instance()->setUndoEnabled(false);
+ if ((attrs.valueAsInt("ANNOTATION", 0)) && (attrs.valueAsBool("ANICON", false)))
+ {
+ currItem->setImageXYScale(scx, scy);
+ currItem->setImageXYOffset(attrs.valueAsDouble("LOCALX"), attrs.valueAsDouble("LOCALY"));
+ currItem->Pfile = Relative2Path(attrs.valueAsString("PFILE" , ""), baseDir);
+ currItem->Pfile2 = Relative2Path(attrs.valueAsString("PFILE2", ""), baseDir);
+ currItem->Pfile3 = Relative2Path(attrs.valueAsString("PFILE3", ""), baseDir);
+ currItem->IProfile = attrs.valueAsString("PRFILE", "");
+ currItem->EmProfile = attrs.valueAsString("EPROF", "");
+ currItem->IRender = attrs.valueAsInt("IRENDER" , 1);
+ currItem->UseEmbedded = attrs.valueAsInt("EMBEDDED", 1);
+ doc->LoadPict(currItem->Pfile, z);
+ currItem->setImageXYScale(scx, scy);
+ currItem->setImageShown( attrs.valueAsInt("PICART"));
+/* currItem->BBoxX = ScCLocale::toDoubleC( obj->attribute("BBOXX"));
+ currItem->BBoxH = ScCLocale::toDoubleC( obj->attribute("BBOXH")); */
+ currItem->ScaleType = attrs.valueAsInt("SCALETYPE", 1);
+ currItem->AspectRatio = attrs.valueAsInt("RATIO", 0);
+ }
+ //currItem->convertTo(pt);
+ UndoManager::instance()->setUndoEnabled(true);
+ break;
+ case PageItem::Line:
+ z = doc->itemAdd(PageItem::Line, PageItem::Unspecified, x, y, w, h, pw, CommonStrings::None, Pcolor2, true);
+ currItem = doc->Items->at(z);
+ if (pagenr > -2)
+ currItem->OwnPage = pagenr;
+ break;
+ case PageItem::Polygon:
+ z = doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, x, y, w, h, pw, Pcolor, Pcolor2, true);
+ currItem = doc->Items->at(z);
+ if (pagenr > -2)
+ currItem->OwnPage = pagenr;
+ break;
+ case PageItem::PolyLine:
+ z = doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, w, h, pw, Pcolor, Pcolor2, true);
+ currItem = doc->Items->at(z);
+ if (pagenr > -2)
+ currItem->OwnPage = pagenr;
+ break;
+ case PageItem::Multiple:
+ Q_ASSERT(false);
+ break;
+ }
+
+ UndoManager::instance()->setUndoEnabled(false);
+ currItem->FrameType = attrs.valueAsInt("FRTYPE", 0);
+ int startArrowIndex = attrs.valueAsInt("startArrowIndex", 0);
+ if ((startArrowIndex < 0) || (startArrowIndex > static_cast<int>(doc->arrowStyles.size())))
+ {
+ qDebug() << QString("scribus150format: invalid arrow index: %").arg(startArrowIndex);
+ startArrowIndex = 0;
+ }
+ currItem->setStartArrowIndex(startArrowIndex);
+ int endArrowIndex = attrs.valueAsInt("endArrowIndex", 0);
+ if ((endArrowIndex < 0) || (endArrowIndex > static_cast<int>(doc->arrowStyles.size())))
+ {
+ qDebug() << QString("scribus150format: invalid arrow index: %").arg(endArrowIndex);
+ endArrowIndex = 0;
+ }
+ currItem->setEndArrowIndex(endArrowIndex);
+ currItem->NamedLStyle = attrs.valueAsString("NAMEDLST", "");
+ currItem->isBookmark = attrs.valueAsInt("BOOKMARK");
+ if ((currItem->isBookmark) && (doc->BookMarks.count() == 0))
+ doc->OldBM = true;
+ currItem->setImageFlippedH( attrs.valueAsInt("FLIPPEDH"));
+ currItem->setImageFlippedV( attrs.valueAsInt("FLIPPEDV"));
+ currItem->setCornerRadius( attrs.valueAsDouble("RADRECT", 0.0));
+ currItem->ClipEdited = attrs.valueAsInt("CLIPEDIT", 0);
+ currItem->setFillColor(Pcolor);
+ currItem->setLineColor(Pcolor2);
+ currItem->setFillShade(attrs.valueAsInt("SHADE"));
+ currItem->setLineShade(attrs.valueAsInt("SHADE2"));
+
+ ParagraphStyle pstyle;
+ if (attrs.hasAttribute("LINESP"))
+ pstyle.setLineSpacing(attrs.valueAsDouble("LINESP"));
+ if (attrs.hasAttribute("LINESPMode"))
+ pstyle.setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(attrs.valueAsInt("LINESPMode", 0)));
+ if (attrs.hasAttribute("ALIGN"))
+ pstyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(attrs.valueAsInt("ALIGN", 0)));
+ if (attrs.hasAttribute("IFONT"))
+ pstyle.charStyle().setFont(m_AvailableFonts->findFont(attrs.valueAsString("IFONT"), doc));
+ if (attrs.hasAttribute("ISIZE"))
+ pstyle.charStyle().setFontSize(qRound(attrs.valueAsDouble("ISIZE") * 10));
+ if (attrs.hasAttribute("TXTSTROKE"))
+ pstyle.charStyle().setStrokeColor(attrs.valueAsString("TXTSTROKE"));
+ if (attrs.hasAttribute("TXTFILL"))
+ pstyle.charStyle().setFillColor(attrs.valueAsString("TXTFILL"));
+ if (attrs.hasAttribute("TXTSTRSH"))
+ pstyle.charStyle().setStrokeShade(attrs.valueAsInt("TXTSTRSH"));
+ if (attrs.hasAttribute("TXTFILLSH"))
+ pstyle.charStyle().setFillShade(attrs.valueAsInt("TXTFILLSH"));
+ if (attrs.hasAttribute("TXTSCALE"))
+ pstyle.charStyle().setScaleH(qRound(attrs.valueAsDouble("TXTSCALE") * 10));
+ if (attrs.hasAttribute("TXTSCALEV"))
+ pstyle.charStyle().setScaleV(qRound(attrs.valueAsDouble("TXTSCALEV") * 10));
+ if (attrs.hasAttribute("TXTBASE"))
+ pstyle.charStyle().setBaselineOffset(qRound(attrs.valueAsDouble("TXTBASE") * 10));
+ if (attrs.hasAttribute("TXTSHX"))
+ pstyle.charStyle().setShadowXOffset(qRound(attrs.valueAsDouble("TXTSHX") * 10));
+ if (attrs.hasAttribute("TXTSHY"))
+ pstyle.charStyle().setShadowYOffset(qRound(attrs.valueAsDouble("TXTSHY") * 10));
+ if (attrs.hasAttribute("TXTOUT"))
+ pstyle.charStyle().setOutlineWidth(qRound(attrs.valueAsDouble("TXTOUT") * 10));
+ if (attrs.hasAttribute("TXTULP"))
+ pstyle.charStyle().setUnderlineOffset(qRound(attrs.valueAsDouble("TXTULP") * 10));
+ if (attrs.hasAttribute("TXTULW"))
+ pstyle.charStyle().setUnderlineWidth(qRound(attrs.valueAsDouble("TXTULW") * 10));
+ if (attrs.hasAttribute("TXTSTP"))
+ pstyle.charStyle().setStrikethruOffset(qRound(attrs.valueAsDouble("TXTSTP") * 10));
+ if (attrs.hasAttribute("TXTSTW"))
+ pstyle.charStyle().setStrikethruWidth(qRound(attrs.valueAsDouble("TXTSTW") * 10));
+ if (attrs.hasAttribute("TXTSTYLE"))
+ pstyle.charStyle().setFeatures(static_cast<StyleFlag>(attrs.valueAsInt("TXTSTYLE")).featureList());
+ if (attrs.hasAttribute("TXTKERN"))
+ pstyle.charStyle().setTracking(qRound(attrs.valueAsDouble("TXTKERN", 0.0) * 10));
+ if (attrs.hasAttribute("wordTrack"))
+ pstyle.charStyle().setWordTracking(attrs.valueAsDouble("wordTrack"));
+ if (attrs.hasAttribute("MinWordTrack"))
+ pstyle.setMinWordTracking(attrs.valueAsDouble("MinWordTrack"));
+ if (attrs.hasAttribute("MinGlyphShrink"))
+ pstyle.setMinGlyphExtension(attrs.valueAsDouble("MinGlyphShrink"));
+ if (attrs.hasAttribute("MaxGlyphExtend"))
+ pstyle.setMaxGlyphExtension(attrs.valueAsDouble("MaxGlyphExtend"));
+ if (attrs.hasAttribute("OpticalMargins"))
+ pstyle.setOpticalMargins(attrs.valueAsInt("OpticalMargins"));
+ if (attrs.hasAttribute("HyphenationMode"))
+ pstyle.setHyphenationMode(attrs.valueAsInt("HyphenationMode"));
+ if (attrs.hasAttribute("leftMargin"))
+ pstyle.setLeftMargin(attrs.valueAsDouble("leftMargin"));
+ if (attrs.hasAttribute("rightMargin"))
+ pstyle.setRightMargin(attrs.valueAsDouble("rightMargin"));
+ if (attrs.hasAttribute("firstIndent"))
+ pstyle.setFirstIndent(attrs.valueAsDouble("firstIndent"));
+ currItem->itemText.setDefaultStyle(pstyle);
+
+ if (attrs.hasAttribute("PSTYLE"))
+ {
+ QString pstyleName = attrs.valueAsString("PSTYLE");
+ if (!pstyleName.isEmpty())
+ {
+ ParagraphStyle defStyle(currItem->itemText.defaultStyle());
+ defStyle.setParent(pstyleName);
+ currItem->itemText.setDefaultStyle(defStyle);
+ }
+ }
+
+ currItem->setRotation( attrs.valueAsDouble("ROT") );
+ currItem->setTextToFrameDist(attrs.valueAsDouble("EXTRA"),
+ attrs.valueAsDouble("REXTRA", 1.0),
+ attrs.valueAsDouble("TEXTRA", 1.0),
+ attrs.valueAsDouble("BEXTRA", 1.0));
+ currItem->setFirstLineOffset(static_cast<FirstLineOffsetPolicy>(attrs.valueAsInt("FLOP")));
+
+ currItem->PLineArt = Qt::PenStyle(attrs.valueAsInt("PLINEART"));
+ currItem->PLineEnd = Qt::PenCapStyle(attrs.valueAsInt("PLINEEND", 0));
+ currItem->PLineJoin = Qt::PenJoinStyle(attrs.valueAsInt("PLINEJOIN", 0));
+ currItem->setPrintEnabled( attrs.valueAsInt("PRINTABLE"));
+ currItem->setIsAnnotation( attrs.valueAsInt("ANNOTATION", 0));
+ currItem->annotation().setType( attrs.valueAsInt("ANTYPE", 0));
+ QString AnName = attrs.valueAsString("ANNAME","");
+ if (!AnName.isEmpty())
+ {
+ if (currItem->itemName() == AnName)
+ currItem->AutoName = true;
+ else
+ {
+ currItem->setItemName(AnName);
+ currItem->AutoName = false;
+ }
+ }
+ currItem->annotation().setAction( attrs.valueAsString("ANACTION","") );
+ currItem->annotation().setE_act ( attrs.valueAsString("ANEACT","") );
+ currItem->annotation().setX_act ( attrs.valueAsString("ANXACT","") );
+ currItem->annotation().setD_act ( attrs.valueAsString("ANDACT","") );
+ currItem->annotation().setFo_act( attrs.valueAsString("ANFOACT","") );
+ currItem->annotation().setBl_act( attrs.valueAsString("ANBLACT","") );
+ currItem->annotation().setK_act ( attrs.valueAsString("ANKACT","") );
+ currItem->annotation().setF_act ( attrs.valueAsString("ANFACT","") );
+ currItem->annotation().setV_act ( attrs.valueAsString("ANVACT","") );
+ currItem->annotation().setC_act ( attrs.valueAsString("ANCACT","") );
+ currItem->annotation().setActionType(attrs.valueAsInt("ANACTYP", 0));
+ currItem->annotation().setExtern( attrs.valueAsString("ANEXTERN",""));
+ if ((!currItem->annotation().Extern().isEmpty()) && (currItem->annotation().ActionType() != 8))
+ currItem->annotation().setExtern(Relative2Path(attrs.valueAsString("ANEXTERN", "") , baseDir));
+ currItem->annotation().setZiel( attrs.valueAsInt("ANZIEL", 0));
+ currItem->annotation().setToolTip ( attrs.valueAsString("ANTOOLTIP",""));
+ currItem->annotation().setRollOver( attrs.valueAsString("ANROLL",""));
+ currItem->annotation().setDown( attrs.valueAsString("ANDOWN",""));
+ currItem->annotation().setBwid( attrs.valueAsInt("ANBWID", 1));
+ currItem->annotation().setBsty( attrs.valueAsInt("ANBSTY", 0));
+ currItem->annotation().setFeed( attrs.valueAsInt("ANFEED", 1));
+ currItem->annotation().setFlag( attrs.valueAsInt("ANFLAG", 0));
+ currItem->annotation().setFont( attrs.valueAsInt("ANFONT", 4));
+ currItem->annotation().setFormat( attrs.valueAsInt("ANFORMAT", 0));
+ currItem->annotation().setVis( attrs.valueAsInt("ANVIS", 0));
+ currItem->annotation().setIsChk( attrs.valueAsBool("ANCHK", false) );
+ currItem->annotation().setAAact( attrs.valueAsBool("ANAA", false) );
+ currItem->annotation().setHTML ( attrs.valueAsInt("ANHTML", 0));
+ currItem->annotation().setUseIcons( attrs.valueAsBool("ANICON", false));
+ currItem->annotation().setChkStil ( attrs.valueAsInt("ANCHKS", 0));
+ currItem->annotation().setMaxChar ( attrs.valueAsInt("ANMC", -1));
+ currItem->annotation().setBorderColor( attrs.valueAsString("ANBCOL", CommonStrings::None));
+ currItem->annotation().setIPlace(attrs.valueAsInt("ANPLACE", 1));
+ currItem->annotation().setScaleW(attrs.valueAsInt("ANSCALE", 0));
+ currItem->TopLine = attrs.valueAsBool("TopLine", false);
+ currItem->LeftLine = attrs.valueAsBool("LeftLine", false);
+ currItem->RightLine = attrs.valueAsBool("RightLine", false);
+ currItem->BottomLine = attrs.valueAsBool("BottomLine", false);
+ currItem->isTableItem = attrs.valueAsBool("isTableItem", false);
+ currItem->TopLinkID = attrs.valueAsInt("TopLINK", -1);
+ currItem->LeftLinkID = attrs.valueAsInt("LeftLINK", -1);
+ currItem->RightLinkID = attrs.valueAsInt("RightLINK", -1);
+ currItem->BottomLinkID = attrs.valueAsInt("BottomLINK", -1);
+ currItem->PoShow = attrs.valueAsInt("PLTSHOW", 0);
+ currItem->BaseOffs = attrs.valueAsDouble("BASEOF", 0.0);
+ currItem->textPathType = attrs.valueAsInt("textPathType", 0);
+ currItem->textPathFlipped = attrs.valueAsBool("textPathFlipped", false);
+ if ( attrs.hasAttribute("TEXTFLOWMODE") )
+ currItem->setTextFlowMode((PageItem::TextFlowMode) attrs.valueAsInt("TEXTFLOWMODE", 0));
+ else if ( attrs.valueAsInt("TEXTFLOW") )
+ {
+ if (attrs.valueAsInt("TEXTFLOW2", 0))
+ currItem->setTextFlowMode(PageItem::TextFlowUsesBoundingBox);
+ else if (attrs.valueAsInt("TEXTFLOW3", 0))
+ currItem->setTextFlowMode(PageItem::TextFlowUsesContourLine);
+ else
+ currItem->setTextFlowMode(PageItem::TextFlowUsesFrameShape);
+ }
+ else
+ currItem->setTextFlowMode(PageItem::TextFlowDisabled);
+ currItem->DashOffset = attrs.valueAsDouble("DASHOFF", 0.0);
+ currItem->setReversed(attrs.valueAsBool("REVERS", false));
+ currItem->setLocked (attrs.valueAsBool("LOCK", false));
+ currItem->setSizeLocked(attrs.valueAsBool("LOCKR", false));
+ currItem->setFillTransparency(attrs.valueAsDouble("TransValue", 0.0));
+ currItem->fillRule = attrs.valueAsBool("fillRule", true);
+ currItem->doOverprint = attrs.valueAsBool("doOverprint", false);
+ if (attrs.hasAttribute("TransValueS"))
+ currItem->setLineTransparency(attrs.valueAsDouble("TransValueS", 0.0));
+ else
+ currItem->setLineTransparency(attrs.valueAsDouble("TransValue", 0.0));
+ currItem->setFillBlendmode(attrs.valueAsInt("TransBlend", 0));
+ currItem->setLineBlendmode(attrs.valueAsInt("TransBlendS", 0));
+ if (attrs.valueAsInt("TRANSPARENT", 0) == 1)
+ currItem->setFillColor(CommonStrings::None);
+ currItem->Cols = attrs.valueAsInt("COLUMNS", 1);
+ currItem->ColGap = attrs.valueAsDouble("COLGAP", 0.0);
+ if (attrs.valueAsInt("LAYER", 0) != -1)
+ currItem->LayerID = attrs.valueAsInt("LAYER", 0);
+ tmp = "";
+
+ if (attrs.hasAttribute("GROUPS") && (attrs.valueAsInt("NUMGROUP", 0) != 0))
+ {
+ int groupMax = doc->GroupCounter;
+ QMap<int, int>::ConstIterator gIt;
+ tmp = attrs.valueAsString("GROUPS");
+ ScTextStream fg(&tmp, QIODevice::ReadOnly);
+ currItem->Groups.clear();
+ int numGroup = attrs.valueAsInt("NUMGROUP", 0);
+ for (int cx = 0; cx < numGroup; ++cx)
+ {
+ fg >> xi;
+ gIt = groupRemap.find(xi);
+ if (gIt != groupRemap.end())
+ currItem->Groups.push(gIt.value());
+ else
+ {
+ currItem->Groups.push(groupMax);
+ groupRemap.insert(xi, groupMax);
+ ++groupMax;
+ }
+ }
+ doc->GroupCounter = groupMax;
+ tmp = "";
+ }
+ else
+ currItem->Groups.clear();
+
+ tmp = "";
+ if ((attrs.hasAttribute("NUMDASH")) && (attrs.valueAsInt("NUMDASH", 0) != 0))
+ {
+ tmp = attrs.valueAsString("DASHS");
+ ScTextStream dgv(&tmp, QIODevice::ReadOnly);
+ currItem->DashValues.clear();
+ int numDash = attrs.valueAsInt("NUMDASH", 0);
+ for (int cxv = 0; cxv < numDash; ++cxv)
+ {
+ dgv >> xf;
+ currItem->DashValues.append(xf);
+ }
+ tmp = "";
+ }
+ else
+ currItem->DashValues.clear();
+
+ tmp = "";
+ if (attrs.hasAttribute("NUMPO"))
+ {
+ currItem->PoLine.resize(attrs.valueAsUInt("NUMPO"));
+ tmp = attrs.valueAsString("POCOOR");
+ ScTextStream fp(&tmp, QIODevice::ReadOnly);
+ uint numPo = attrs.valueAsUInt("NUMPO");
+ for (uint cx=0; cx < numPo; ++cx)
+ {
+ fp >> xf;
+ fp >> yf;
+ currItem->PoLine.setPoint(cx, xf, yf);
+ }
+ }
+ else
+ currItem->PoLine.resize(0);
+
+ tmp = "";
+ if (attrs.hasAttribute("NUMCO"))
+ {
+ currItem->ContourLine.resize(attrs.valueAsUInt("NUMCO"));
+ tmp = attrs.valueAsString("COCOOR");
+ ScTextStream fp(&tmp, QIODevice::ReadOnly);
+ uint numCo = attrs.valueAsUInt("NUMCO");
+ for (uint cx=0; cx < numCo; ++cx)
+ {
+ fp >> xf;
+ fp >> yf;
+ currItem->ContourLine.setPoint(cx, xf, yf);
+ }
+ }
+ else
+ currItem->ContourLine = currItem->PoLine.copy();
+
+ if (!currItem->asLine())
+ currItem->Clip = FlattenPath(currItem->PoLine, currItem->Segments);
+ else
+ {
+ int ph = static_cast<int>(qMax(1.0, currItem->lineWidth() / 2.0));
+ currItem->Segments.clear();
+ currItem->PoLine.resize(0);
+ currItem->Clip.setPoints(4, -ph,-ph, static_cast<int>(currItem->width()+ph),-ph,
+ static_cast<int>(currItem->width()+ph),static_cast<int>(currItem->height()+ph),
+ -ph,static_cast<int>(currItem->height()+ph));
+ currItem->setHeight(1.0);
+ }
+
+ if (currItem->asPathText())
+ {
+ currItem->updatePolyClip();
+ currItem->Frame = true;
+ }
+ currItem->GrType = attrs.valueAsInt("GRTYP", 0);
+ QString GrColor;
+ QString GrColor2;
+ int GrShade = 0;
+ int GrShade2 = 0;
+ if (currItem->GrType != 0)
+ {
+ if (currItem->GrType == 8)
+ {
+ currItem->setPattern( attrs.valueAsString("pattern", "") );
+ double patternScaleX = attrs.valueAsDouble("pScaleX", 100.0);
+ double patternScaleY = attrs.valueAsDouble("pScaleY", 100.0);
+ double patternOffsetX = attrs.valueAsDouble("pOffsetX", 0.0);
+ double patternOffsetY = attrs.valueAsDouble("pOffsetY", 0.0);
+ double patternRotation = attrs.valueAsDouble("pRotation", 0.0);
+ currItem->setPatternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
+ }
+ else
+ {
+ currItem->GrStartX = attrs.valueAsDouble("GRSTARTX", 0.0);
+ currItem->GrStartY = attrs.valueAsDouble("GRSTARTY", 0.0);
+ currItem->GrEndX = attrs.valueAsDouble("GRENDX", 0.0);
+ currItem->GrEndY = attrs.valueAsDouble("GRENDY", 0.0);
+ GrColor = attrs.valueAsString("GRCOLOR","");
+ if (!GrColor.isEmpty())
+ {
+ GrColor2 = attrs.valueAsString("GRCOLOR2","");
+ GrShade = attrs.valueAsInt("GRSHADE", 100);
+ GrShade2 = attrs.valueAsInt("GRSHADE2", 100);
+ }
+ }
+ }
+ if ((currItem->GrType != 0) && (currItem->GrType != 8))
+ {
+ currItem->fill_gradient.clearStops();
+ if ((!GrColor.isEmpty()) && (!GrColor2.isEmpty()))
+ {
+ if (currItem->GrType == 5)
+ {
+ if ((GrColor != CommonStrings::None) && (!GrColor.isEmpty()))
+ currItem->SetQColor(&tmpc, GrColor, GrShade);
+ currItem->fill_gradient.addStop(tmpc, 0.0, 0.5, 1.0, GrColor, GrShade);
+ if ((GrColor2 != CommonStrings::None) && (!GrColor2.isEmpty()))
+ currItem->SetQColor(&tmpc, GrColor2, GrShade2);
+ currItem->fill_gradient.addStop(tmpc, 1.0, 0.5, 1.0, GrColor2, GrShade2);
+ }
+ else
+ {
+ if ((GrColor2 != CommonStrings::None) && (!GrColor2.isEmpty()))
+ currItem->SetQColor(&tmpc, GrColor2, GrShade2);
+ currItem->fill_gradient.addStop(tmpc, 0.0, 0.5, 1.0, GrColor2, GrShade2);
+ if ((GrColor != CommonStrings::None) && (!GrColor.isEmpty()))
+ currItem->SetQColor(&tmpc, GrColor, GrShade);
+ currItem->fill_gradient.addStop(tmpc, 1.0, 0.5, 1.0, GrColor, GrShade);
+ }
+ }
+// currItem->updateGradientVectors();
+ }
+ //currItem->setRedrawBounding();
+ //currItem->OwnPage = view->OnPage(currItem);
+ UndoManager::instance()->setUndoEnabled(true);
+ return currItem;
+}
+
+bool Scribus150Format::readLatexInfo(PageItem_LatexFrame* latexitem, ScXmlStreamReader& reader)
+{
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ QStringRef tagName = reader.name();
+
+ latexitem->setConfigFile(attrs.valueAsString("ConfigFile"), true);
+ latexitem->setDpi(attrs.valueAsInt("DPI"));
+ latexitem->setUsePreamble(attrs.valueAsBool("USE_PREAMBLE"));
+
+ QString formula;
+ while (!reader.atEnd() && !reader.hasError())
+ {
+ reader.readNext();
+ if (reader.isEndElement() && reader.name() == tagName)
+ break;
+ if (reader.isCharacters())
+ formula += reader.text().toString();
+ if (reader.isStartDocument() && reader.name() == "PROPERTY")
+ {
+ ScXmlStreamAttributes tAtt = reader.scAttributes();
+ QString name = tAtt.valueAsString("name");
+ QString value = tAtt.valueAsString("value");
+ if (name.isEmpty()) continue;
+ latexitem->editorProperties[name] = value;
+ }
+ }
+ formula = formula.trimmed();
+ latexitem->setFormula(formula, false);
+
+ return !reader.hasError();
+}
+
+bool Scribus150Format::loadPage(const QString & fileName, int pageNumber, bool Mpage, QString renamedPageName)
+{
+// qDebug() << QString("loading page %2 from file '%1' from 1.3.x plugin").arg(fileName).arg(pageNumber);
+ if (m_Doc==0 || m_AvailableFonts==0)
+ {
+ Q_ASSERT(m_Doc==0 || m_AvailableFonts==0);
+ return false;
+ }
+ ParagraphStyle vg;
+ struct ScribusDoc::BookMa bok;
+ QMap<int, ScribusDoc::BookMa> bookmarks;
+
+ Page* newPage = NULL;
+
+ QString tmp;
+ QMap<int,int> TableID;
+ QList<PageItem*> TableItems;
+ QMap<PageItem*, int> groupID;
+ double pageX = 0, pageY = 0;
+ bool newVersion = false;
+ QMap<int,int> layerTrans;
+ int maxLayer = 0, maxLevel = 0, a = 0;
+
+ layerTrans.clear();
+ uint layerCount=m_Doc->layerCount();
+ for (uint la2 = 0; la2 < layerCount; ++la2)
+ {
+ maxLayer = qMax(m_Doc->Layers[la2].ID, maxLayer);
+ maxLevel = qMax(m_Doc->Layers[la2].Level, maxLevel);
+ }
+
+ groupRemap.clear();
+ itemRemap.clear();
+ itemNext.clear();
+ itemCount = 0;
+ itemRemapM.clear();
+ itemNextM.clear();
+ itemCountM = 0;
+ itemRemapF.clear();
+ itemNextF.clear();
+
+ QString f(readSLA(fileName));
+ if (f.isEmpty())
+ return false;
+
+ QString fileDir = QFileInfo(fileName).absolutePath();
+
+ bool firstElement = true;
+ bool success = true;
+
+ ScXmlStreamReader reader(f);
+ ScXmlStreamAttributes attrs;
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ QXmlStreamReader::TokenType tType = reader.readNext();
+ if (tType != QXmlStreamReader::StartElement)
+ continue;
+ QStringRef tagName = reader.name();
+ attrs = reader.scAttributes();
+
+ if (firstElement)
+ {
+ if (tagName != "SCRIBUSUTF8NEW")
+ {
+ success = false;
+ break;
+ }
+ if (attrs.hasAttribute("Version"))
+ newVersion = true;
+ firstElement = false;
+ }
+
+ if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None)
+ {
+ success = readColor(m_Doc->PageColors, attrs);
+ if (!success) break;
+ }
+ if (tagName == "JAVA")
+ {
+ QString name = attrs.valueAsString("NAME");
+ if (!name.isEmpty())
+ m_Doc->JavaScripts[name] = attrs.valueAsString("SCRIPT");
+ }
+ if (tagName == "LAYERS")
+ {
+ ScLayer newLayer;
+ readLayers(newLayer, attrs);
+ const ScLayer* la2 = m_Doc->Layers.layerByName(newLayer.Name);
+ if (la2)
+ layerTrans.insert(newLayer.ID, la2->ID);
+ else
+ {
+ maxLayer++;
+ maxLevel++;
+ layerTrans.insert(newLayer.ID, maxLayer);
+ newLayer.ID = maxLayer;
+ newLayer.Level = maxLevel;
+ m_Doc->Layers.append(newLayer);
+ }
+ }
+ if (tagName == "Arrows")
+ {
+ success = readArrows(m_Doc, attrs);
+ if (!success) break;
+ }
+ if(tagName == "MultiLine")
+ {
+ multiLine ml;
+ QString mlName = attrs.valueAsString("Name");
+ QString mlName2 = mlName;
+ readMultiline(ml, reader);
+ int copyC = 1;
+ QMap<QString,multiLine>::ConstIterator mlit = m_Doc->MLineStyles.find(mlName2);
+ if (mlit != m_Doc->MLineStyles.end() && ml != mlit.value())
+ {
+ while (m_Doc->MLineStyles.contains(mlName2))
+ {
+ mlName2 = QObject::tr("Copy #%1 of ").arg(copyC)+mlName;
+ copyC++;
+ }
+ }
+ m_Doc->MLineStyles.insert(mlName2, ml);
+ }
+ if (tagName == "Pattern")
+ {
+ success = readPattern(m_Doc, reader, fileDir);
+ if (!success) break;
+ }
+ if (tagName == "Bookmark")
+ {
+ int bmElem = 0;
+ struct ScribusDoc::BookMa bookmark;
+ success = readBookMark(bookmark, bmElem, attrs);
+ if (!success) break;
+ bookmarks.insert(bmElem, bookmark);
+ }
+ if(tagName == "STYLE")
+ {
+ getStyle(vg, reader, NULL, m_Doc, true);
+ }
+ if (((tagName == "PAGE") || (tagName == "MASTERPAGE")) && (attrs.valueAsInt("NUM") == pageNumber))
+ {
+ if (Mpage && (tagName != "MASTERPAGE"))
+ continue;
+ a = m_Doc->currentPage()->pageNr();
+ newPage = m_Doc->Pages->at(a);
+ if (Mpage)
+ {
+ newPage->LeftPg = attrs.valueAsInt("LEFT", 0);
+
+ if (!renamedPageName.isEmpty())
+ newPage->setPageName(renamedPageName);
+ else
+ newPage->setPageName(attrs.valueAsString("NAM",""));
+ }
+ if (attrs.hasAttribute("Size"))
+ newPage->m_pageSize = attrs.valueAsString("Size");
+ if (attrs.hasAttribute("Orientation"))
+ newPage->setOrientation(attrs.valueAsInt("Orientation"));
+ if (attrs.hasAttribute("PAGEWIDTH"))
+ newPage->setWidth( attrs.valueAsDouble("PAGEWIDTH") );
+ else
+ newPage->setWidth( attrs.valueAsDouble("PAGEWITH") );
+ newPage->setHeight( attrs.valueAsDouble("PAGEHEIGHT") );
+ newPage->setInitialHeight(newPage->height());
+ newPage->setInitialWidth(newPage->width());
+ newPage->initialMargins.Top = qMax(0.0, attrs.valueAsDouble("BORDERTOP"));
+ newPage->initialMargins.Bottom = qMax(0.0, attrs.valueAsDouble("BORDERBOTTOM"));
+ newPage->initialMargins.Left = qMax(0.0, attrs.valueAsDouble("BORDERLEFT"));
+ newPage->initialMargins.Right = qMax(0.0, attrs.valueAsDouble("BORDERRIGHT"));
+ newPage->marginPreset = attrs.valueAsInt("PRESET", 0);
+ newPage->Margins.Top = newPage->initialMargins.Top;
+ newPage->Margins.Bottom = newPage->initialMargins.Bottom;
+ pageX = attrs.valueAsDouble( attrs.valueAsString("PAGEXPOS"));
+ pageY = attrs.valueAsDouble( attrs.valueAsString("PAGEYPOS"));
+ // guides reading
+ tmp = "";
+ newPage->guides.setHorizontalAutoGap(attrs.valueAsDouble("AGhorizontalAutoGap", 0.0));
+ newPage->guides.setVerticalAutoGap(attrs.valueAsDouble("AGverticalAutoGap", 0.0));
+ newPage->guides.setHorizontalAutoCount(attrs.valueAsInt("AGhorizontalAutoCount", 0));
+ newPage->guides.setVerticalAutoCount(attrs.valueAsInt("AGverticalAutoCount", 0));
+ newPage->guides.setHorizontalAutoRefer(attrs.valueAsInt("AGhorizontalAutoRefer", 0));
+ newPage->guides.setVerticalAutoRefer(attrs.valueAsInt("AGverticalAutoRefer", 0));
+ GuideManagerIO::readVerticalGuides(attrs.valueAsString("VerticalGuides"),
+ newPage,
+ GuideManagerCore::Standard,
+ attrs.hasAttribute("NumVGuides"));
+ GuideManagerIO::readHorizontalGuides(attrs.valueAsString("HorizontalGuides"),
+ newPage,
+ GuideManagerCore::Standard,
+ attrs.hasAttribute("NumHGuides"));
+ GuideManagerIO::readSelection(attrs.valueAsString("AGSelection"), newPage);
+ }
+ if ((tagName == "PAGEOBJECT") || (tagName == "MASTEROBJECT") || (tagName == "FRAMEOBJECT"))
+ {
+ if ((Mpage && tagName != "MASTEROBJECT") || (!Mpage && tagName == "MASTEROBJECT"))
+ {
+ // Go to end of node
+ reader.readToElementEnd();
+ continue;
+ }
+ if (attrs.valueAsInt("OwnPage") != pageNumber)
+ {
+ if (tagName == "PAGEOBJECT")
+ itemRemap[itemCount++] = -1;
+ else if (tagName == "MASTEROBJECT")
+ itemRemapM[itemCountM++] = -1;
+ reader.readToElementEnd();
+ }
+ else
+ {
+ // first of linked chain?
+ if (tagName == "PAGEOBJECT")
+ {
+ itemRemap[itemCount++] = m_Doc->DocItems.count();
+ if (attrs.valueAsInt("NEXTITEM") != -1)
+ itemNext[m_Doc->DocItems.count()] = attrs.valueAsInt("NEXTITEM");
+ }
+ else if (tagName == "MASTEROBJECT")
+ {
+ itemRemapM[itemCountM++] = m_Doc->MasterItems.count();
+ if (attrs.valueAsInt("NEXTITEM") != -1)
+ itemNextM[m_Doc->MasterItems.count()] = attrs.valueAsInt("NEXTITEM");
+ }
+
+ ItemInfo itemInfo;
+ success = readObject(m_Doc, reader, itemInfo, fileDir, true);
+ if (!success) break;
+
+ PageItem* newItem = itemInfo.item;
+ newItem->moveBy(-pageX + newPage->xOffset(), - pageY + newPage->yOffset());
+ newItem->OwnPage = m_Doc->currentPageNumber();
+ if (tagName == "PAGEOBJECT")
+ newItem->OnMasterPage = "";
+
+ if (newItem->isTableItem)
+ {
+ TableItems.append(newItem);
+ TableID.insert(itemInfo.ownLink, newItem->ItemNr);
+ }
+ if (newItem->isGroupControl)
+ {
+ groupID.insert(newItem, itemInfo.groupLastItem + newItem->ItemNr);
+ }
+ if (tagName == "FRAMEOBJECT")
+ {
+ m_Doc->FrameItems.append(m_Doc->Items->takeAt(newItem->ItemNr));
+ newItem->ItemNr = m_Doc->FrameItems.count()-1;
+ }
+ }
+ }
+ }
+
+ if (reader.hasError())
+ return false;
+
+ QMap<int, ScribusDoc::BookMa>::Iterator it;
+ for (it = bookmarks.begin(); it != bookmarks.end(); ++it)
+ {
+ int elem = it.key();
+ if (elem < m_Doc->Items->count())
+ {
+ ScribusDoc::BookMa bookmark = it.value();
+ bookmark.PageObject = m_Doc->Items->at(elem);
+ m_Doc->BookMarks.append( bookmark );
+ }
+ }
+
+ if (TableItems.count() != 0)
+ {
+ for (int ttc = 0; ttc < TableItems.count(); ++ttc)
+ {
+ PageItem* ta = TableItems.at(ttc);
+ if (ta->TopLinkID != -1)
+ ta->TopLink = m_Doc->Items->at(TableID[ta->TopLinkID]);
+ else
+ ta->TopLink = 0;
+ if (ta->LeftLinkID != -1)
+ ta->LeftLink = m_Doc->Items->at(TableID[ta->LeftLinkID]);
+ else
+ ta->LeftLink = 0;
+ if (ta->RightLinkID != -1)
+ ta->RightLink = m_Doc->Items->at(TableID[ta->RightLinkID]);
+ else
+ ta->RightLink = 0;
+ if (ta->BottomLinkID != -1)
+ ta->BottomLink = m_Doc->Items->at(TableID[ta->BottomLinkID]);
+ else
+ ta->BottomLink = 0;
+ }
+ }
+
+ if (groupID.count() != 0)
+ {
+ QMap<PageItem*, int>::Iterator it;
+ for (it = groupID.begin(); it != groupID.end(); ++it)
+ {
+ it.key()->groupsLastItem = m_Doc->Items->at(it.value());
+ }
+ }
+
+ // reestablish textframe links
+ if (itemNext.count() != 0 && !Mpage)
+ {
+ QMap<int,int>::Iterator lc;
+ for (lc = itemNext.begin(); lc != itemNext.end(); ++lc)
+ {
+ if (itemRemap[lc.value()] >= 0)
+ {
+ if ((lc.key() < m_Doc->Items->count()) && (itemRemap[lc.value()] < m_Doc->Items->count()))
+ {
+ PageItem * Its = m_Doc->DocItems.at(lc.key());
+ PageItem * Itn = m_Doc->DocItems.at(itemRemap[lc.value()]);
+ if (Itn->prevInChain() || Its->nextInChain())
+ {
+ qDebug() << "scribus150format: corruption in linked textframes detected";
+ continue;
+ }
+ Its->link(Itn);
+ }
+ }
+ }
+ }
+ else if (itemNextM.count() != 0 && Mpage)
+ {
+ QMap<int,int>::Iterator lc;
+ for (lc = itemNextM.begin(); lc != itemNextM.end(); ++lc)
+ {
+ if (itemRemapM[lc.value()] >= 0)
+ {
+ if ((lc.key() < m_Doc->MasterItems.count()) && (itemRemapM[lc.value()] < m_Doc->MasterItems.count()))
+ {
+ PageItem * Its = m_Doc->MasterItems.at(lc.key());
+ PageItem * Itn = m_Doc->MasterItems.at(itemRemapM[lc.value()]);
+ if (Itn->prevInChain() || Its->nextInChain())
+ {
+ qDebug() << "scribus150format: corruption in linked textframes detected";
+ continue;
+ }
+ Its->link(Itn);
+ }
+ }
+ }
+ }
+
+ // reestablish first/lastAuto
+ m_Doc->FirstAuto = m_Doc->LastAuto;
+ if (m_Doc->LastAuto)
+ {
+ while (m_Doc->LastAuto->nextInChain())
+ m_Doc->LastAuto = m_Doc->LastAuto->nextInChain();
+ while (m_Doc->FirstAuto->prevInChain())
+ m_Doc->FirstAuto = m_Doc->FirstAuto->prevInChain();
+ }
+
+ return true;
+}
+
+void Scribus150Format::getStyle(ParagraphStyle& style, ScXmlStreamReader& reader, StyleSet<ParagraphStyle> *tempStyles, ScribusDoc* doc, bool fl)
+{
+ bool fou(false);
+ QString tmpf, tmV;
+ const StyleSet<ParagraphStyle> * docParagraphStyles = tempStyles? tempStyles : & doc->paragraphStyles();
+ PrefsManager* prefsManager = PrefsManager::instance();
+ readParagraphStyle(doc, reader, style, prefsManager->appPrefs.AvailFonts);
+ for (int xx=0; xx<docParagraphStyles->count(); ++xx)
+ {
+ if (style.name() == (*docParagraphStyles)[xx].name())
+ {
+ if (style.equiv((*docParagraphStyles)[xx]))
+ {
+ fou = true;
+ }
+ else
+ {
+ style.setName("Copy of "+(*docParagraphStyles)[xx].name());
+ fou = false;
+ }
+ break;
+ }
+ }
+ if (!fou && fl)
+ {
+ for (int xx=0; xx< docParagraphStyles->count(); ++xx)
+ {
+ if (style.equiv((*docParagraphStyles)[xx]))
+ {
+ style.setName((*docParagraphStyles)[xx].name());
+ fou = true;
+ break;
+ }
+ }
+ }
+ if (!fou)
+ {
+ if (tempStyles)
+ tempStyles->create(style);
+ else
+ {
+ StyleSet<ParagraphStyle> tmp;
+ tmp.create(style);
+ doc->redefineStyles(tmp, false);
+ }
+ }
+}
+
+bool Scribus150Format::readStyles(const QString& fileName, ScribusDoc* doc, StyleSet<ParagraphStyle> &docParagraphStyles)
+{
+ ParagraphStyle vg;
+ QString tmpf;
+ QString f (readSLA(fileName));
+ if (f.isEmpty())
+ return false;
+
+ bool firstElement = true;
+ bool success = true;
+
+ ScXmlStreamReader reader(f);
+ ScXmlStreamAttributes attrs;
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ QXmlStreamReader::TokenType tType = reader.readNext();
+ if (tType != QXmlStreamReader::StartElement)
+ continue;
+ QStringRef tagName = reader.name();
+ if (firstElement)
+ {
+ if (tagName != "SCRIBUSUTF8NEW")
+ {
+ success = false;
+ break;
+ }
+ firstElement = false;
+ continue;
+ }
+ if (tagName == "STYLE")
+ {
+ getStyle(vg, reader, &docParagraphStyles, doc, false);
+ }
+ }
+ return success;
+}
+
+bool Scribus150Format::readCharStyles(const QString& fileName, ScribusDoc* doc, StyleSet<CharStyle> &docCharStyles)
+{
+ CharStyle cstyle;
+ QString f(readSLA(fileName));
+ if (f.isEmpty())
+ return false;
+ bool firstElement = true;
+ bool success = true;
+
+ ScXmlStreamReader reader(f);
+ ScXmlStreamAttributes attrs;
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ QXmlStreamReader::TokenType tType = reader.readNext();
+ if (tType != QXmlStreamReader::StartElement)
+ continue;
+ QStringRef tagName = reader.name();
+ if (firstElement)
+ {
+ if (tagName != "SCRIBUSUTF8NEW")
+ {
+ success = false;
+ break;
+ }
+ firstElement = false;
+ continue;
+ }
+ if (tagName == "CHARSTYLE")
+ {
+ readCharacterStyleAttrs(doc, attrs, cstyle);
+ docCharStyles.create(cstyle);
+ }
+ }
+ return true;
+}
+
+bool Scribus150Format::readLineStyles(const QString& fileName, QMap<QString,multiLine> *styles)
+{
+ QString f(readSLA(fileName));
+ if (f.isEmpty())
+ return false;
+ bool firstElement = true;
+ bool success = true;
+
+ ScXmlStreamReader reader(f);
+ ScXmlStreamAttributes attrs;
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ QXmlStreamReader::TokenType tType = reader.readNext();
+ if (tType != QXmlStreamReader::StartElement)
+ continue;
+ QStringRef tagName = reader.name();
+ if (firstElement)
+ {
+ if (tagName != "SCRIBUSUTF8NEW")
+ {
+ success = false;
+ break;
+ }
+ firstElement = false;
+ continue;
+ }
+ if (tagName == "MultiLine")
+ {
+ multiLine ml;
+ attrs = reader.scAttributes();
+ QString mlName = attrs.valueAsString("Name");
+ QString mlName2 = mlName;
+ readMultiline(ml, reader);
+ int copyC = 1;
+ QMap<QString,multiLine>::ConstIterator mlit = styles->find(mlName2);
+ if (mlit != styles->end() && ml != mlit.value())
+ {
+ while (styles->contains(mlName2))
+ {
+ mlName2 = tr("Copy #%1 of ").arg(copyC)+mlName;
+ copyC++;
+ }
+ }
+ styles->insert(mlName2, ml);
+ }
+ }
+ return true;
+}
+
+bool Scribus150Format::readColors(const QString& fileName, ColorList & colors)
+{
+ QString f(readSLA(fileName));
+ if (f.isEmpty())
+ return false;
+ bool firstElement = true;
+ bool success = true;
+
+ ScXmlStreamReader reader(f);
+ ScXmlStreamAttributes attrs;
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ QXmlStreamReader::TokenType tType = reader.readNext();
+ if (tType != QXmlStreamReader::StartElement)
+ continue;
+ QStringRef tagName = reader.name();
+ if (firstElement)
+ {
+ if (tagName != "SCRIBUSUTF8NEW")
+ {
+ success = false;
+ break;
+ }
+ firstElement = false;
+ continue;
+ }
+ if(tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None)
+ {
+ attrs = reader.scAttributes();
+ if (attrs.valueAsString("NAME") != CommonStrings::None)
+ {
+ readColor(colors, attrs);
+ }
+ }
+ }
+ return true;
+}
+
+bool Scribus150Format::readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames)
+{
+ QString pageName;
+ int counter = 0;
+ int counter2 = 0;
+ QString f(readSLA(fileName));
+ if (f.isEmpty())
+ return false;
+ bool firstElement = true;
+ bool success = true;
+
+ ScXmlStreamReader reader(f);
+ ScXmlStreamAttributes attrs;
+ while(!reader.atEnd() && !reader.hasError())
+ {
+ QXmlStreamReader::TokenType tType = reader.readNext();
+ if (tType != QXmlStreamReader::StartElement)
+ continue;
+ QStringRef tagName = reader.name();
+ if (firstElement)
+ {
+ if (tagName != "SCRIBUSUTF8NEW")
+ {
+ success = false;
+ break;
+ }
+ firstElement = false;
+ continue;
+ }
+ if(tagName == "PAGE")
+ counter++;
+ if(tagName == "MASTERPAGE")
+ {
+ pageName = reader.scAttributes().valueAsString("NAM");
+ if (!pageName.isEmpty())
+ {
+ counter2++;
+ masterPageNames.append(pageName);
+ }
+ }
+ }
+ *num1 = counter;
+ *num2 = counter2;
+ return success;
+}
+
+
+
+
Index: scribus/plugins/fileloader/oodraw/oodrawimp.cpp
===================================================================
--- scribus/plugins/fileloader/oodraw/oodrawimp.cpp (revision 13950)
+++ scribus/plugins/fileloader/oodraw/oodrawimp.cpp (revision 13951)
@@ -819,7 +819,7 @@
}
else
{
- QMatrix mat;
+ QTransform mat;
double x = parseUnit(e.attribute("svg:x"));
double y = parseUnit(e.attribute("svg:y")) ;
double w = parseUnit(e.attribute("svg:width"));
@@ -1426,7 +1426,7 @@
void OODPlug::parseTransform(FPointArray *composite, const QString &transform)
{
double dx, dy;
- QMatrix result;
+ QTransform result;
QStringList subtransforms = transform.split(')', QString::SkipEmptyParts);
QStringList::ConstIterator it = subtransforms.begin();
QStringList::ConstIterator end = subtransforms.end();
@@ -1441,7 +1441,7 @@
subtransform[0] = subtransform[0].right(subtransform[0].length() - 1);
if(subtransform[0] == "rotate")
{
- result = QMatrix();
+ result = QTransform();
result.rotate(-parseUnit(params[0]) * 180 / M_PI);
composite->map(result);
}
@@ -1457,19 +1457,19 @@
dx = parseUnit(params[0]);
dy =0.0;
}
- result = QMatrix();
+ result = QTransform();
result.translate(dx, dy);
composite->map(result);
}
else if(subtransform[0] == "skewx")
{
- result = QMatrix();
+ result = QTransform();
result.shear(-tan(ScCLocale::toDoubleC(params[0])), 0.0);
composite->map(result);
}
else if(subtransform[0] == "skewy")
{
- result = QMatrix();
+ result = QTransform();
result.shear(0.0, -tan(ScCLocale::toDoubleC(params[0])));
composite->map(result);
}
@@ -1528,7 +1528,7 @@
composite->addPoint(firstP);
composite->addPoint(firstP);
}
- QMatrix mat;
+ QTransform mat;
mat.translate(x, y);
mat.scale(sx, sy);
composite->map(mat);
Index: scribus/plugins/fileloader/scribus134format/scribus134format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus134format/scribus134format.cpp (revision 13950)
+++ scribus/plugins/fileloader/scribus134format/scribus134format.cpp (revision 13951)
@@ -2339,7 +2339,7 @@
{
currItem->imageClip = currItem->pixm.imgInfo.PDSpathData[clPath].copy();
currItem->pixm.imgInfo.usedPath = clPath;
- QMatrix cl;
+ QTransform cl;
cl.translate(currItem->imageXOffset()*currItem->imageXScale(), currItem->imageYOffset()*currItem->imageYScale());
cl.scale(currItem->imageXScale(), currItem->imageYScale());
currItem->imageClip.map(cl);
Index: scribus/plugins/svgexplugin/svgexplugin.h
===================================================================
--- scribus/plugins/svgexplugin/svgexplugin.h (revision 13950)
+++ scribus/plugins/svgexplugin/svgexplugin.h (revision 13951)
@@ -85,7 +85,7 @@
QDomElement processImageItem(PageItem *Item, QString trans, QString fill, QString stroke);
QDomElement processTextItem(PageItem *Item, QString trans, QString fill, QString stroke);
QDomElement processPathTextItem(PageItem *Item, QString trans, QString stroke);
- QDomElement processInlineItem(double xpos, double ypos, QMatrix &finalMat, ScText *hl, bool pathT, QString trans);
+ QDomElement processInlineItem(double xpos, double ypos, QTransform &finalMat, ScText *hl, bool pathT, QString trans);
QString handleGlyph(uint chr, ScText *hl);
QDomElement processArrows(PageItem *Item, QDomElement line, QString trans);
QString getFillStyle(PageItem *Item);
@@ -117,7 +117,7 @@
\param plug ScribusMainWindow *
\retval QString Colour settings
*/
- QString MatrixToStr(QMatrix &mat);
+ QString MatrixToStr(QTransform &mat);
QString SetColor(QString farbe, int shad);
/*!
\author Franz Schmid
Index: scribus/plugins/svgexplugin/svgexplugin.cpp
===================================================================
--- scribus/plugins/svgexplugin/svgexplugin.cpp (revision 13950)
+++ scribus/plugins/svgexplugin/svgexplugin.cpp (revision 13951)
@@ -560,7 +560,7 @@
ob3.setAttribute("y", FToStr(Item->imageYOffset() * Item->imageYScale()));
ob3.setAttribute("width", FToStr(img.width() * Item->imageXScale()));
ob3.setAttribute("height", FToStr(img.height() * Item->imageYScale()));
- QMatrix mpa;
+ QTransform mpa;
if (Item->imageFlippedH())
{
mpa.translate(Item->width(), 0);
@@ -651,11 +651,11 @@
else if (hl->effects() & ScStyle_AllCaps)
chstr = chstr.toUpper();
uint chr = chstr[0].unicode();
- QMatrix chma, chma2, chma3, chma4, chma6;
- QMatrix trafo = QMatrix( 1, 0, 0, 1, CurX, ls.y );
+ QTransform chma, chma2, chma3, chma4, chma6;
+ QTransform trafo = QTransform( 1, 0, 0, 1, CurX, ls.y );
if (Item->rotation() != 0)
{
- QMatrix sca;
+ QTransform sca;
sca.translate(-Item->xPos(), -Item->yPos());
trafo *= sca;
}
@@ -674,10 +674,10 @@
chma6.translate(0, hl->glyph.yoffset);
if (hl->baselineOffset() != 0)
chma6.translate(0, (-charStyle.fontSize() / 10.0) * (charStyle.baselineOffset() / 1000.0));
- QMatrix finalMat = QMatrix(chma * chma2 * chma3 * chma4 * chma6 * trafo);
+ QTransform finalMat = chma * chma2 * chma3 * chma4 * chma6 * trafo;
if (Item->rotation() != 0)
{
- QMatrix sca;
+ QTransform sca;
sca.translate(Item->xPos(), Item->yPos());
finalMat *= sca;
}
@@ -694,8 +694,8 @@
glName = handleGlyph(chr, hl);
if ((charStyle.effects() & ScStyle_Shadowed) && (charStyle.strokeColor() != CommonStrings::None) && (chstr > QChar(32)))
{
- QMatrix sha = finalMat;
- QMatrix shad;
+ QTransform sha = finalMat;
+ QTransform shad;
shad.translate(charStyle.fontSize() * charStyle.shadowXOffset() / 10000.0, -charStyle.fontSize() * charStyle.shadowYOffset() / 10000.0);
sha *= shad;
QDomElement ob2 = docu.createElement("use");
@@ -889,14 +889,14 @@
chstr = chstr.toUpper();
uint chr = chstr[0].unicode();
QPointF tangt = QPointF( cos(hl->PRot), sin(hl->PRot) );
- QMatrix chma, chma2, chma3, chma4, chma6;
- QMatrix trafo = QMatrix( 1, 0, 0, -1, -hl->PDx, 0 );
+ QTransform chma, chma2, chma3, chma4, chma6;
+ QTransform trafo = QTransform( 1, 0, 0, -1, -hl->PDx, 0 );
if (Item->textPathFlipped)
- trafo *= QMatrix(1, 0, 0, -1, 0, 0);
+ trafo *= QTransform(1, 0, 0, -1, 0, 0);
if (Item->textPathType == 0)
- trafo *= QMatrix( tangt.x(), tangt.y(), tangt.y(), -tangt.x(), hl->PtransX, hl->PtransY );
+ trafo *= QTransform( tangt.x(), tangt.y(), tangt.y(), -tangt.x(), hl->PtransX, hl->PtransY );
else if (Item->textPathType == 1)
- trafo *= QMatrix(1, 0, 0, -1, hl->PtransX, hl->PtransY );
+ trafo *= QTransform(1, 0, 0, -1, hl->PtransX, hl->PtransY );
else if (Item->textPathType == 2)
{
double a = 1;
@@ -907,20 +907,20 @@
b = 1;
}
if (fabs(tangt.x()) > 0.1)
- trafo *= QMatrix( a, (tangt.y() / tangt.x()) * b, 0, -1, hl->PtransX, hl->PtransY ); // ID's Skew mode
+ trafo *= QTransform( a, (tangt.y() / tangt.x()) * b, 0, -1, hl->PtransX, hl->PtransY ); // ID's Skew mode
else
- trafo *= QMatrix( a, 6 * b, 0, -1, hl->PtransX, hl->PtransY );
+ trafo *= QTransform( a, 6 * b, 0, -1, hl->PtransX, hl->PtransY );
}
if ((hl->ch == SpecialChars::OBJECT) && (hl->embedded.hasItem()))
{
- QMatrix finalMat = QMatrix(chma * chma2 * chma3 * chma4 * chma6 * trafo);
+ QTransform finalMat = chma * chma2 * chma3 * chma4 * chma6 * trafo;
ob.appendChild(processInlineItem(0, 0, finalMat, hl, true, trans));
}
else
{
if (Item->rotation() != 0)
{
- QMatrix sca;
+ QTransform sca;
sca.translate(-Item->xPos(), -Item->yPos());
trafo *= sca;
}
@@ -939,10 +939,10 @@
chma6.translate(0, hl->glyph.yoffset);
if (hl->baselineOffset() != 0)
chma6.translate(0, (-charStyle.fontSize() / 10.0) * (charStyle.baselineOffset() / 1000.0));
- QMatrix finalMat = QMatrix(chma * chma2 * chma3 * chma4 * chma6 * trafo);
+ QTransform finalMat = chma * chma2 * chma3 * chma4 * chma6 * trafo;
if (Item->rotation() != 0)
{
- QMatrix sca;
+ QTransform sca;
sca.translate(Item->xPos(), Item->yPos());
finalMat *= sca;
}
@@ -950,10 +950,10 @@
if (((charStyle.effects() & ScStyle_Underline) && !SpecialChars::isBreak(chstc))
|| ((charStyle.effects() & ScStyle_UnderlineWords) && !chstc.isSpace() && !SpecialChars::isBreak(chstc)))
{
- QMatrix stro = QMatrix(chma2 * chma3 * chma6 * trafo);
+ QTransform stro = chma2 * chma3 * chma6 * trafo;
if (Item->rotation() != 0)
{
- QMatrix sca;
+ QTransform sca;
sca.translate(Item->xPos(), Item->yPos());
stro *= sca;
}
@@ -1001,8 +1001,8 @@
QString glName = handleGlyph(chr, hl);
if ((charStyle.effects() & ScStyle_Shadowed) && (charStyle.strokeColor() != CommonStrings::None))
{
- QMatrix sha = finalMat;
- QMatrix shad;
+ QTransform sha = finalMat;
+ QTransform shad;
shad.translate(charStyle.fontSize() * charStyle.shadowXOffset() / 10000.0, -charStyle.fontSize() * charStyle.shadowYOffset() / 10000.0);
sha *= shad;
QDomElement ob2 = docu.createElement("use");
@@ -1026,10 +1026,10 @@
}
if (charStyle.effects() & ScStyle_Strikethrough)
{
- QMatrix stro = QMatrix(chma2 * chma3 * chma6 * trafo);
+ QTransform stro = chma2 * chma3 * chma6 * trafo;
if (Item->rotation() != 0)
{
- QMatrix sca;
+ QTransform sca;
sca.translate(Item->xPos(), Item->yPos());
stro *= sca;
}
@@ -1074,7 +1074,7 @@
return ob;
}
-QDomElement SVGExPlug::processInlineItem(double xpos, double ypos, QMatrix &finalMat, ScText *hl, bool pathT, QString trans)
+QDomElement SVGExPlug::processInlineItem(double xpos, double ypos, QTransform &finalMat, ScText *hl, bool pathT, QString trans)
{
const CharStyle & charStyle(*hl);
QList<PageItem*> emG = hl->embedded.getGroupedItems();
@@ -1097,7 +1097,7 @@
ob.setAttribute("id", "Clip"+IToStr(ClipCount));
QDomElement cl = docu.createElement("path");
cl.setAttribute("d", SetClipPath(&embedded->PoLine, true));
- QMatrix mm;
+ QTransform mm;
mm.translate(xpos + embedded->gXpos * (charStyle.scaleH() / 1000.0), (ypos - (embedded->gHeight * (charStyle.scaleV() / 1000.0)) + embedded->gYpos * (charStyle.scaleV() / 1000.0)));
if (charStyle.baselineOffset() != 0)
mm.translate(0, embedded->gHeight * (charStyle.baselineOffset() / 1000.0));
@@ -1144,7 +1144,7 @@
default:
break;
}
- QMatrix mm;
+ QTransform mm;
mm.translate(xpos + embedded->gXpos * (charStyle.scaleH() / 1000.0), (ypos - (embedded->gHeight * (charStyle.scaleV() / 1000.0)) + embedded->gYpos * (charStyle.scaleV() / 1000.0)));
if (charStyle.baselineOffset() != 0)
mm.translate(0, embedded->gHeight * (charStyle.baselineOffset() / 1000.0));
@@ -1176,7 +1176,7 @@
continue;
if ((embedded->TopLine) || (embedded->RightLine) || (embedded->BottomLine) || (embedded->LeftLine))
{
- QMatrix mm;
+ QTransform mm;
mm.translate(xpos + embedded->gXpos * (charStyle.scaleH() / 1000.0), (ypos - (embedded->gHeight * (charStyle.scaleV() / 1000.0)) + embedded->gYpos * (charStyle.scaleV() / 1000.0)));
if (charStyle.baselineOffset() != 0)
mm.translate(0, embedded->gHeight * (charStyle.baselineOffset() / 1000.0));
@@ -1229,7 +1229,7 @@
gr.appendChild(line);
if (Item->startArrowIndex() != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = m_Doc->arrowStyles.at(Item->startArrowIndex()-1).points.copy();
if (Item->itemType() == PageItem::Line)
{
@@ -1317,7 +1317,7 @@
}
if (Item->endArrowIndex() != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = m_Doc->arrowStyles.at(Item->endArrowIndex()-1).points.copy();
if (Item->itemType() == PageItem::Line)
{
@@ -1430,7 +1430,7 @@
patt.setAttribute("patternUnits", "userSpaceOnUse");
double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation;
Item->patternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
- QMatrix mpa;
+ QTransform mpa;
mpa.translate(patternOffsetX, patternOffsetY);
mpa.rotate(patternRotation);
mpa.scale(pa.scaleX, pa.scaleY);
@@ -1703,7 +1703,7 @@
return cc.setNum(c);
}
-QString SVGExPlug::MatrixToStr(QMatrix &mat)
+QString SVGExPlug::MatrixToStr(QTransform &mat)
{
QString cc("matrix(%1 %2 %3 %4 %5 %6)");
return cc.arg(mat.m11()).arg(mat.m12()).arg(mat.m21()).arg(mat.m22()).arg(mat.dx()).arg(mat.dy());
Index: scribus/scpainterexbase.h
===================================================================
--- scribus/scpainterexbase.h (revision 13950)
+++ scribus/scpainterexbase.h (revision 13951)
@@ -32,7 +32,7 @@
#include <QFont>
#include <QGlobalStatic>
#include <QList>
-#include <QMatrix>
+#include <QTransform>
#include <QPixmap>
#include <QStack>
@@ -72,8 +72,8 @@
virtual void clear( ScColorShade& ) = 0;
// matrix manipulation
- virtual void setWorldMatrix( const QMatrix & ) = 0;
- virtual const QMatrix worldMatrix() = 0;
+ virtual void setWorldMatrix( const QTransform & ) = 0;
+ virtual const QTransform worldMatrix() = 0;
virtual void translate( double, double ) = 0;
virtual void rotate( double ) = 0;
virtual void scale( double, double ) = 0;
@@ -92,7 +92,7 @@
virtual void setFillMode( int fill ) = 0;
virtual int fillMode() = 0;
virtual void setGradient( VGradientEx::Type mode, FPoint orig, FPoint vec, FPoint foc = FPoint(0,0) ) = 0;
- virtual void setPattern ( ScPattern* pattern, QMatrix& patternTransform ) = 0;
+ virtual void setPattern ( ScPattern* pattern, QTransform& patternTransform ) = 0;
virtual void setClipPath() = 0;
virtual void drawImage( ScImage *image, ScPainterExBase::ImageMode mode ) = 0;
@@ -125,7 +125,7 @@
VGradientEx m_fillGradient;
VGradientEx m_strokeGradient;
ScPattern* m_pattern;
- QMatrix m_patternTransform;
+ QTransform m_patternTransform;
};
#endif
Index: scribus/vgradient.h
===================================================================
--- scribus/vgradient.h (revision 13950)
+++ scribus/vgradient.h (revision 13951)
@@ -28,7 +28,7 @@
#include <QColor>
#include <QList>
-#include <QMatrix>
+#include <QTransform>
#include "fpoint.h"
#include "scribusapi.h"
@@ -128,7 +128,7 @@
FPoint vector() const { return m_vector; }
void setVector( const FPoint &vector ) { m_vector = vector; }
- void transform( const QMatrix& m );
+ void transform( const QTransform& m );
protected:
QList<VColorStop*> m_colorStops;
Index: scribus/canvasgesture_resize.cpp
===================================================================
--- scribus/canvasgesture_resize.cpp (revision 13950)
+++ scribus/canvasgesture_resize.cpp (revision 13951)
@@ -1,543 +1,543 @@
-/*
- For general Scribus (>=1.3.2) copyright and licensing information please refer
- to the COPYING file provided with the program. Following this notice may exist
- a copyright and/or license notice that predates the release of Scribus 1.3.2
- for which a new license (GPL+exception) is in place.
- */
-/***************************************************************************
-* *
-* This program is free software; you can redistribute it and/or modify *
-* it under the terms of the GNU General Public License as published by *
-* the Free Software Foundation; either version 2 of the License, or *
-* (at your option) any later version. *
-* *
-***************************************************************************/
-
-#include "canvasgesture_resize.h"
-
-#include <QMouseEvent>
-#include <QPainter>
-#include <QPen>
-#include <QRubberBand>
-
-#include "scribusdoc.h"
-#include "scribusview.h"
-#include "selection.h"
-#include "undomanager.h"
-
-ResizeGesture::ResizeGesture (CanvasMode* parent) : CanvasGesture(parent)
-{
- m_transactionStarted = NULL;
-}
-
-void ResizeGesture::prepare(Canvas::FrameHandle framehandle)
-{
- if (framehandle > 0)
- m_handle = framehandle;
-
- if (m_doc->m_Selection->count() == 0)
- {
- m_handle = Canvas::OUTSIDE;
- return;
- }
- else if (m_doc->m_Selection->isMultipleSelection())
- {
- double ex, ey, eh, ew;
- m_doc->m_Selection->getGroupRect(&ex, &ey, &ew, &eh);
- double gx, gy, gh, gw;
- m_doc->m_Selection->getVisualGroupRect(&gx, &gy, &gw, &gh);
- m_bounds = QRectF(QPointF(gx,gy), QSizeF(gw, gh));
- m_rotation = 0.0;
- m_extraX = ex - gx;
- m_extraY = ey - gy;
- m_extraWidth = gw - ew;
- m_extraHeight = gh - eh;
- }
- else // we keep m_bounds non-rotated
- {
- PageItem* currItem = m_doc->m_Selection->itemAt(0);
- m_bounds = QRectF(currItem->visualXPos(), currItem->visualYPos(), currItem->visualWidth(), currItem->visualHeight());
- m_rotation = currItem->rotation();
-// currItem->OldB2 = currItem->visualWidth();
-// currItem->OldH2 = currItem->visualHeight();
- currItem->OldB2 = currItem->width();
- currItem->OldH2 = currItem->height();
- m_extraWidth = currItem->visualWidth() - currItem->width();
- m_extraHeight = currItem->visualHeight() - currItem->height();
- m_extraX = m_extraY = m_extraWidth / 2.0;
- }
- m_origRatio = m_bounds.width() / m_bounds.height();
- m_origBounds = m_bounds;
-// qDebug()<<"P"<<m_bounds<< "E"<< m_extraX<< m_extraY<<m_extraWidth<<m_extraHeight;
-}
-
-
-void ResizeGesture::clear()
-{
- m_handle = Canvas::OUTSIDE;
- if (m_transactionStarted)
- {
-// qDebug() << "ResizeGesture::clear: cancel transaction" << m_transactionStarted;
- m_transactionStarted->cancel();
- delete m_transactionStarted;
- m_transactionStarted = NULL;
- }
-}
-
-void ResizeGesture::activate(bool flag)
-{
-// qDebug() << "ResizeGesture::activate" << flag;
-}
-
-
-
-void ResizeGesture::deactivate(bool forgesture)
-{
-// qDebug() << "ResizeGesture::deactivate" << forgesture;
- if (!forgesture)
- clear();
-}
-
-
-
-void ResizeGesture::drawControls(QPainter* p)
-{
- QColor drawColor = qApp->palette().color(QPalette::Active, QPalette::Highlight);
- QRect localRect = m_canvas->canvasToLocal(m_bounds);
- p->save();
- // p->setPen(QPen(Qt::black, 1, Qt::DashLine, Qt::FlatCap, Qt::MiterJoin));
- // p->drawRect(localRect);
- if (m_rotation != 0)
- {
- p->setRenderHint(QPainter::Antialiasing);
- p->translate(localRect.x(), localRect.y());
- p->rotate(m_rotation);
- p->translate(-localRect.x(), -localRect.y());
- }
- p->setPen(QPen(drawColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
- drawColor.setAlpha(64);
- p->setBrush(drawColor);
- p->drawRect(localRect);
- // p->setPen(Qt::darkMagenta);
- // p->drawLine(localRect.topLeft(), localRect.bottomRight());
- p->restore();
-
- if (m_origBounds != m_bounds)
- {
- p->save();
-// p->translate(m_bounds.topLeft() - m_origBounds.topLeft());
- drawOutline(p, qAbs(m_bounds.width()) / qMax(qAbs(m_origBounds.width()), static_cast<qreal>(1.0)),
- qAbs(m_bounds.height()) / qMax(qAbs(m_origBounds.height()), static_cast<qreal>(1.0)),
- m_bounds.left() - m_origBounds.left(),
- m_bounds.top() - m_origBounds.top());
- p->restore();
- }
-}
-
-
-
-void ResizeGesture::mouseReleaseEvent(QMouseEvent *m)
-{
- adjustBounds(m);
- if (m_doc->m_Selection->count() != 0)
- {
- PageItem* currItem = m_doc->m_Selection->itemAt(0);
-// qDebug() << "ResizeGesture::release: new bounds" << m_bounds;
- doResize(m->modifiers() & Qt::AltModifier);
- m_doc->setRedrawBounding(currItem);
- if (currItem->asImageFrame())
- currItem->AdjustPictScale();
- m_view->resetMousePressed();
- // necessary since mousebutton is still recorded pressed, and otherwise checkchanges() will do nothing
- // we must check changes on whole selection otherwise resize operation won't undo correctly on groups
- for (int i = 0; i < m_doc->m_Selection->count(); ++i)
- m_doc->m_Selection->itemAt(i)->checkChanges();
- currItem->invalidateLayout();
- currItem->update();
- }
-// qDebug() << "ResizeGesture::release: transaction" << m_transactionStarted;
- if (m_transactionStarted)
- {
- m_transactionStarted->commit();
- delete m_transactionStarted;
- m_transactionStarted = NULL;
- }
- m->accept();
- m_canvas->update();
- m_view->stopGesture();
-}
-
-
-void ResizeGesture::doResize(bool scaleContent)
-{
- PageItem* currItem = m_doc->m_Selection->itemAt(0);
- QString targetName = Um::SelectionGroup;
- QPixmap* targetIcon = Um::IGroup;
- if (!m_doc->m_Selection->isMultipleSelection())
- {
- targetName = currItem->getUName();
- targetIcon = currItem->getUPixmap();
- }
- if (!m_transactionStarted)
- {
- m_transactionStarted = new UndoTransaction(Um::instance()->beginTransaction(targetName, targetIcon,
- Um::Resize, "", Um::IResize));
-// qDebug() << "ResizeGesture::doResize: begin transaction" << m_transactionStarted;
- }
- QRectF newBounds = m_bounds.normalized();
- if (m_doc->m_Selection->isMultipleSelection())
- {
- int RotModeBack = m_doc->RotMode();
- m_doc->RotMode ( 0 );
- double gx, gy, gh, gw;
- m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
- QRectF oldBounds(gx, gy, gw, gh);
- double scx = oldBounds.width() == 0? 1.0 : (newBounds.width() - m_extraWidth) / oldBounds.width();
- double scy = oldBounds.height() == 0? 1.0 : (newBounds.height() - m_extraHeight) / oldBounds.height();
- //CB #3012 only scale text in a group if alt is pressed
- if ((currItem->itemType() == PageItem::TextFrame) && scaleContent)
- m_doc->scaleGroup(scx, scy, true);
- else
- m_doc->scaleGroup(scx, scy, false);
- double dx = newBounds.x() - oldBounds.x();
- double dy = newBounds.y() - oldBounds.y();
- if (dx != 0 || dy != 0)
- m_doc->moveGroup(dx + m_extraX, dy + m_extraY);
- m_doc->RotMode ( RotModeBack );
- }
- else
- {
- if (currItem->itemType() == PageItem::ImageFrame && scaleContent)
- {
- double divX = (currItem->width() != 0) ? currItem->width() : 1.0;
- double divY = (currItem->height() != 0) ? currItem->height() : 1.0;
- double imgScX = (newBounds.width() - m_extraWidth) / divX * currItem->imageXScale();
- double imgScY = (newBounds.height() - m_extraHeight) / divY * currItem->imageYScale();
- // The aspect ratio has been fixed, so make the modification in the direction of the larger movement.
- if (currItem->keepAspectRatio() && currItem->fitImageToFrame())
- {
- if (qAbs((newBounds.width() - m_extraWidth) - currItem->width()) > qAbs((newBounds.height() - m_extraHeight) - currItem->height()))
- imgScY = imgScX;
- else
- imgScX = imgScY;
- }
- currItem->setImageXYScale(imgScX, imgScY);
- }
- else if (currItem->itemType() == PageItem::ImageFrame && currItem->PictureIsAvailable)
- {
- double dx = ((newBounds.x() + m_extraX) - currItem->xPos());
- double dy = ((newBounds.y() + m_extraY) - currItem->yPos());
- double cosa = cos(currItem->rotation() * M_PI / 180.0);
- double sina = sin(currItem->rotation() * M_PI / 180.0);
- double xoff = -(cosa*dx + sina*dy);
- if (currItem->imageFlippedH())
- xoff += (currItem->width() - (newBounds.width() - m_extraWidth));
- double yoff = -(cosa*dy - sina*dx);
- if (currItem->imageFlippedV())
- yoff += (currItem->height() - (newBounds.height() - m_extraHeight));
- if (xoff != 0.0 || yoff != 0.0)
- {
- currItem->moveImageInFrame(xoff / currItem->imageXScale(), yoff / currItem->imageYScale());
- }
- }
- // We do not want to scale the text of a linked frame
- // as it would alter text in other frames of the string
- else if((currItem->itemType() == PageItem::TextFrame)
- && (currItem->nextInChain() == 0)
- && (currItem->prevInChain() == 0)
- && scaleContent)
- {
- double divX = (currItem->width() != 0) ? currItem->width() : 1.0;
- double divY = (currItem->height() != 0) ? currItem->height() : 1.0;
- double txtScX = (newBounds.width() - m_extraWidth) / divX;
- double txtScY = (newBounds.height() - m_extraHeight) / divY;
- if (currItem->itemText.length() != 0)
- {
- for (int aa = 0; aa < currItem->itemText.length(); ++aa)
- {
-#if 0 // hard to decide if itâs batter to scale or to change font size
- currItem->itemText.item(aa)->setScaleV(
- qMax(qMin(qRound(currItem->itemText.item(aa)->scaleV()*txtScY), 4000), 100));
- currItem->itemText.item(aa)->setScaleH(
- qMax(qMin(qRound(currItem->itemText.item(aa)->scaleH() * txtScX), 4000), 100));
-#else
- currItem->itemText.item(aa)->setFontSize(
- qMax(qMin(currItem->itemText.item(aa)->fontSize() * txtScY, 4000.0), 1.0));
- currItem->itemText.item(aa)->setScaleH(
- qMax(qMin(qRound(currItem->itemText.item(aa)->scaleH() * txtScX / txtScY), 4000), 100));
-#endif
-
- // We need to scale the linespacing _only once_ per paragraph.
- if((aa == 0)
- || ( SpecialChars::isBreak(currItem->itemText.itemText(aa - 1).at(0))))
- {
- ParagraphStyle ps(currItem->itemText.paragraphStyle(aa));
- double oldLS(currItem->itemText.paragraphStyle(aa).lineSpacing());
- ps.setLineSpacing(qMax(qRound(oldLS * txtScY), 1));
- currItem->itemText.setStyle(aa,ps);
- }
- }
- }
- }
- currItem->setXYPos(newBounds.x() + m_extraX, newBounds.y() + m_extraY);
- currItem->setWidth(newBounds.width() - m_extraWidth);
- currItem->setHeight(newBounds.height() - m_extraHeight);
- // rotation does not change
- }
- m_origBounds = m_bounds;
- currItem->updateClip();
-}
-
-
-void ResizeGesture::mouseMoveEvent(QMouseEvent *m)
-{
- adjustBounds(m);
- FPoint where = m_canvas->globalToCanvas(m->globalPos());
- if (// directly after a create the shape of an item isnt really usable, so we fix here
- m_origBounds.width() < 20 || m_origBounds.height() < 20 ||
- // and if we resize outside of the current canvas dimensions, we need to enlarge it
- where.x() < m_doc->minCanvasCoordinate.x() || where.y() < m_doc->minCanvasCoordinate.y() ||
- where.x() > m_doc->maxCanvasCoordinate.x() || where.y() > m_doc->maxCanvasCoordinate.y())
- {
- doResize(m->modifiers() & Qt::AltModifier);
- }
- m->accept();
- QPoint point = m->globalPos() - (m_canvas->mapToParent(QPoint(0, 0)) + m_canvas->parentWidget()->mapToGlobal(QPoint(0, 0)));
- m_view->ensureVisible(point.x(), point.y(), 20, 20);
- m_canvas->repaint();
- QRectF newBounds = m_bounds.normalized();
- m_canvas->displaySizeHUD(m->globalPos(), newBounds.width() - m_extraWidth, newBounds.height() - m_extraHeight);
-}
-
-
-
-void ResizeGesture::adjustBounds(QMouseEvent *m)
-{
- QMatrix rotation;
- FPoint docPoint = m_canvas->globalToCanvas(m->globalPos());
- QPointF oldXY = m_bounds.topLeft();
- // proportional resize
- bool constrainRatio = ((m->modifiers() & Qt::ControlModifier) != Qt::NoModifier);
-
-
- // snap to grid + snap to guides
- bool isCorner = m_handle == Canvas::NORTHWEST || m_handle == Canvas::NORTHEAST
- || m_handle == Canvas::SOUTHWEST || m_handle == Canvas::SOUTHEAST;
- if (m_rotation == 0 || isCorner)
- {
- FPoint snappedPoint = m_doc->ApplyGridF(docPoint);
- double x = snappedPoint.x(), y = snappedPoint.y();
- m_doc->ApplyGuides(&x, &y);
-// if (m_doc->ApplyGuides(&x, &y))
-// qDebug() << "guides applied:" << snappedPoint.x() << snappedPoint.y() << "to" << x << y;
- if (m_handle == Canvas::NORTH || m_handle == Canvas::SOUTH)
- // only snap on y-axis
- docPoint = FPoint(docPoint.x(), y);
- else if (m_handle == Canvas::EAST || m_handle == Canvas::WEST)
- // only snap on x-axis
- docPoint = FPoint(x, docPoint.y());
- else
- docPoint = FPoint(x,y);
-// qDebug() << "resize snap grid/guides:" << m->globalPos() << "-->" << m_canvas->canvasToGlobal(docPoint);
- }
-
- // un-rotate point
- if (m_rotation != 0)
- {
- // rotate point around item position
- rotation.translate(m_bounds.x(), m_bounds.y());
- rotation.rotate(m_rotation);
- rotation.translate(-m_bounds.x(), -m_bounds.y());
-// qDebug() << "resize rotated" << m_rotation << "°" << m_bounds << rotation << ":" << point-globalBounds.topLeft() << "-->" << rotation.map(point)-globalBounds.topLeft();
- QPointF qp = QPointF(docPoint.x(), docPoint.y());
- qp = rotation.inverted().map(qp);
- docPoint = FPoint(qp.x(), qp.y());
- }
-
- // adjust bounds vertically
- switch (m_handle)
- {
- case Canvas::NORTHWEST:
- case Canvas::NORTH:
- case Canvas::NORTHEAST:
-// qDebug() << "ResizeGesture: top to" << point.y();
- m_bounds.setTop(docPoint.y());
- break;
- case Canvas::SOUTHWEST:
- case Canvas::SOUTH:
- case Canvas::SOUTHEAST:
-// qDebug() << "ResizeGesture: bottom to" << point.y();
- m_bounds.setBottom(docPoint.y());
- break;
- default:
- break;
- }
- // adjust bounds horizontally
- switch (m_handle)
- {
- case Canvas::NORTHWEST:
- case Canvas::WEST:
- case Canvas::SOUTHWEST:
-// qDebug() << "ResizeGesture: left to" << point.x();
- m_bounds.setLeft(docPoint.x());
- break;
- case Canvas::NORTHEAST:
- case Canvas::EAST:
- case Canvas::SOUTHEAST:
-// qDebug() << "ResizeGesture: right to" << point.x();
- m_bounds.setRight(docPoint.x());
- break;
- default:
- break;
- }
-
- // constrain ratio
- double newRatio = double(m_bounds.width()) / double(m_bounds.height());
- if (constrainRatio && m_origRatio != newRatio)
- {
-// qDebug() << "constrain ratio:" << m_bounds << newRatio << "to" << m_origRatio;
- int newWidth = qRound(m_bounds.height() * m_origRatio);
- int newHeight = qRound(m_bounds.width() / m_origRatio);
- switch (m_handle)
- {
- case Canvas::NORTHWEST:
- // axis: topleft + t*[origRatio, 1] t:= y-top
- // [x',y] = [left, top] + [(y-top)*origRatio, y-top]
- // = [left + (y-top)*origRatio, y]
- // x < x' => mouse is WEST, x > x' => mouse is NORTH
- // x < left + (y-top)*origratio <=> x - left < (y - top) * origratio
-
-// qDebug() << "NORTHWEST" << point << m_origBounds.topLeft() << m_origRatio
-// << (point.x() - m_origBounds.left() < (point.y()-m_origBounds.top()) * m_origRatio);
-
- if (docPoint.x() - m_origBounds.left() < (docPoint.y()-m_origBounds.top()) * m_origRatio)
- m_bounds.setTop(m_bounds.top() - newHeight + m_bounds.height());
- else
- m_bounds.setLeft(m_bounds.left() - newWidth + m_bounds.width());
- break;
- case Canvas::SOUTHWEST:
- // axis: bottomleft + t*[origRatio, -1] t:= bottom-y
- // (x',y) = [left, bottom] + [(bottom-y)*origRatio, -bottom+y]
- // = [left + (bottom-y)*origRatio, y]
- // x < x' => mouse is WEST, x > x' => mouse is SOUTH
- // x < left + (bottom-y)*origratio <=> x - left < (bottom-y) * origratio
-
-// qDebug() << "SOUTHWEST" << point << m_origBounds.bottomLeft() << m_origRatio
-// << (point.x() - m_origBounds.left() < (m_origBounds.bottom() - point.y()) * m_origRatio);
-
- if (docPoint.x() - m_origBounds.left() < (m_origBounds.bottom() - docPoint.y()) * m_origRatio)
- m_bounds.setHeight(newHeight);
- else
- m_bounds.setLeft(m_bounds.left() - newWidth + m_bounds.width());
- break;
- case Canvas::NORTHEAST:
- // cf. SOUTHWEST
- if (docPoint.x() - m_origBounds.left() > (m_origBounds.bottom() - docPoint.y()) * m_origRatio)
- m_bounds.setTop(m_bounds.top() - newHeight + m_bounds.height());
- else
- m_bounds.setWidth(newWidth);
- break;
- case Canvas::SOUTHEAST:
- // cf. NORTHWEST
- if (docPoint.x() - m_origBounds.left() > (docPoint.y()-m_origBounds.top()) * m_origRatio)
- m_bounds.setHeight(newHeight);
- else
- m_bounds.setWidth(newWidth);
- break;
- case Canvas::WEST:
- case Canvas::EAST:
- // (origBounds.top + origBounds.bottom) / 2 is the horizontal axis
- // keep that fixed
- m_bounds.setTop(((m_origBounds.top() + m_origBounds.bottom()) / 2) - newHeight / 2);
- m_bounds.setHeight(newHeight);
- break;
- case Canvas::NORTH:
- case Canvas::SOUTH:
- // (origBounds.left + origBounds.right) / 2 is the vertical axis
- // keep that fixed
- m_bounds.setLeft(((m_origBounds.left() + m_origBounds.right()) / 2) - newWidth / 2);
- m_bounds.setWidth(newWidth);
- break;
- default:
- break;
- }
-// qDebug() << "constrained:" << m_bounds << double(m_bounds.width()) / m_bounds.height();
- }
-
- // re-rotate: if top left has changed, then it needs rotation
- if (m_rotation != 0 && oldXY != m_bounds.topLeft())
- {
- m_bounds.moveTo(rotation.map(m_bounds.topLeft()));
- // fix opposite corner to avoid aggregating rounding errors
- QPointF origFixPoint, newFixPoint;
- switch (m_handle)
- {
- case Canvas::NORTHWEST:
- origFixPoint = m_origBounds.bottomRight();
- newFixPoint = m_bounds.bottomRight();
- break;
- case Canvas::WEST:
- origFixPoint = m_origBounds.topRight() + QPointF(0, m_origBounds.height()/2);
- newFixPoint = m_bounds.topRight() + QPointF(0, m_bounds.height()/2);
- break;
- case Canvas::SOUTHWEST:
- origFixPoint = m_origBounds.topRight();
- newFixPoint = m_bounds.topRight();
- break;
- case Canvas::SOUTH:
- origFixPoint = m_origBounds.topLeft() + QPointF(m_origBounds.width()/2, 0);
- newFixPoint = m_bounds.topLeft() + QPointF(m_bounds.width()/2, 0);
- break;
- case Canvas::SOUTHEAST:
- origFixPoint = m_origBounds.topLeft();
- newFixPoint = m_bounds.topLeft();
- break;
- case Canvas::EAST:
- origFixPoint = m_origBounds.topLeft() + QPointF(0, m_origBounds.height()/2);
- newFixPoint = m_bounds.topLeft() + QPointF(0, m_bounds.height()/2);
- break;
- case Canvas::NORTHEAST:
- origFixPoint = m_origBounds.bottomLeft();
- newFixPoint = m_bounds.bottomLeft();
- break;
- case Canvas::NORTH:
- origFixPoint = m_origBounds.bottomLeft() + QPointF(m_origBounds.width()/2, 0);
- newFixPoint = m_bounds.bottomLeft() + QPointF(m_bounds.width()/2, 0);
- break;
- default:
- origFixPoint = m_origBounds.topLeft();
- newFixPoint = m_bounds.topLeft();
- break;
- }
- origFixPoint = m_origBounds.topLeft() + rotation.map(origFixPoint - m_origBounds.topLeft());
- newFixPoint = m_bounds.topLeft() + rotation.map(newFixPoint - m_bounds.topLeft());
- if (origFixPoint != newFixPoint)
- m_bounds.translate(origFixPoint - newFixPoint);
- }
-}
-
-
-
-void ResizeGesture::mousePressEvent(QMouseEvent *m)
-{
- FPoint point = m_canvas->globalToCanvas(m->globalPos());
- if (m_doc->m_Selection->count() == 0)
- {
- m_handle = Canvas::OUTSIDE;
- }
- else if (m_doc->m_Selection->isMultipleSelection())
- {
- double gx, gy, gh, gw;
- m_doc->m_Selection->getVisualGroupRect(&gx, &gy, &gw, &gh);
- m_handle = m_canvas->frameHitTest(QPointF(point.x(), point.y()), QRectF(gx,gy,gw,gh));
- }
- else
- {
- m_handle = m_canvas->frameHitTest(QPointF(point.x(), point.y()), m_doc->m_Selection->itemAt(0));
- }
- if (m_handle > 0)
- {
- prepare(m_handle);
- m->accept();
- }
-}
+/*
+ For general Scribus (>=1.3.2) copyright and licensing information please refer
+ to the COPYING file provided with the program. Following this notice may exist
+ a copyright and/or license notice that predates the release of Scribus 1.3.2
+ for which a new license (GPL+exception) is in place.
+ */
+/***************************************************************************
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+***************************************************************************/
+
+#include "canvasgesture_resize.h"
+
+#include <QMouseEvent>
+#include <QPainter>
+#include <QPen>
+#include <QRubberBand>
+
+#include "scribusdoc.h"
+#include "scribusview.h"
+#include "selection.h"
+#include "undomanager.h"
+
+ResizeGesture::ResizeGesture (CanvasMode* parent) : CanvasGesture(parent)
+{
+ m_transactionStarted = NULL;
+}
+
+void ResizeGesture::prepare(Canvas::FrameHandle framehandle)
+{
+ if (framehandle > 0)
+ m_handle = framehandle;
+
+ if (m_doc->m_Selection->count() == 0)
+ {
+ m_handle = Canvas::OUTSIDE;
+ return;
+ }
+ else if (m_doc->m_Selection->isMultipleSelection())
+ {
+ double ex, ey, eh, ew;
+ m_doc->m_Selection->getGroupRect(&ex, &ey, &ew, &eh);
+ double gx, gy, gh, gw;
+ m_doc->m_Selection->getVisualGroupRect(&gx, &gy, &gw, &gh);
+ m_bounds = QRectF(QPointF(gx,gy), QSizeF(gw, gh));
+ m_rotation = 0.0;
+ m_extraX = ex - gx;
+ m_extraY = ey - gy;
+ m_extraWidth = gw - ew;
+ m_extraHeight = gh - eh;
+ }
+ else // we keep m_bounds non-rotated
+ {
+ PageItem* currItem = m_doc->m_Selection->itemAt(0);
+ m_bounds = QRectF(currItem->visualXPos(), currItem->visualYPos(), currItem->visualWidth(), currItem->visualHeight());
+ m_rotation = currItem->rotation();
+// currItem->OldB2 = currItem->visualWidth();
+// currItem->OldH2 = currItem->visualHeight();
+ currItem->OldB2 = currItem->width();
+ currItem->OldH2 = currItem->height();
+ m_extraWidth = currItem->visualWidth() - currItem->width();
+ m_extraHeight = currItem->visualHeight() - currItem->height();
+ m_extraX = m_extraY = m_extraWidth / 2.0;
+ }
+ m_origRatio = m_bounds.width() / m_bounds.height();
+ m_origBounds = m_bounds;
+// qDebug()<<"P"<<m_bounds<< "E"<< m_extraX<< m_extraY<<m_extraWidth<<m_extraHeight;
+}
+
+
+void ResizeGesture::clear()
+{
+ m_handle = Canvas::OUTSIDE;
+ if (m_transactionStarted)
+ {
+// qDebug() << "ResizeGesture::clear: cancel transaction" << m_transactionStarted;
+ m_transactionStarted->cancel();
+ delete m_transactionStarted;
+ m_transactionStarted = NULL;
+ }
+}
+
+void ResizeGesture::activate(bool flag)
+{
+// qDebug() << "ResizeGesture::activate" << flag;
+}
+
+
+
+void ResizeGesture::deactivate(bool forgesture)
+{
+// qDebug() << "ResizeGesture::deactivate" << forgesture;
+ if (!forgesture)
+ clear();
+}
+
+
+
+void ResizeGesture::drawControls(QPainter* p)
+{
+ QColor drawColor = qApp->palette().color(QPalette::Active, QPalette::Highlight);
+ QRect localRect = m_canvas->canvasToLocal(m_bounds);
+ p->save();
+ // p->setPen(QPen(Qt::black, 1, Qt::DashLine, Qt::FlatCap, Qt::MiterJoin));
+ // p->drawRect(localRect);
+ if (m_rotation != 0)
+ {
+ p->setRenderHint(QPainter::Antialiasing);
+ p->translate(localRect.x(), localRect.y());
+ p->rotate(m_rotation);
+ p->translate(-localRect.x(), -localRect.y());
+ }
+ p->setPen(QPen(drawColor, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
+ drawColor.setAlpha(64);
+ p->setBrush(drawColor);
+ p->drawRect(localRect);
+ // p->setPen(Qt::darkMagenta);
+ // p->drawLine(localRect.topLeft(), localRect.bottomRight());
+ p->restore();
+
+ if (m_origBounds != m_bounds)
+ {
+ p->save();
+// p->translate(m_bounds.topLeft() - m_origBounds.topLeft());
+ drawOutline(p, qAbs(m_bounds.width()) / qMax(qAbs(m_origBounds.width()), static_cast<qreal>(1.0)),
+ qAbs(m_bounds.height()) / qMax(qAbs(m_origBounds.height()), static_cast<qreal>(1.0)),
+ m_bounds.left() - m_origBounds.left(),
+ m_bounds.top() - m_origBounds.top());
+ p->restore();
+ }
+}
+
+
+
+void ResizeGesture::mouseReleaseEvent(QMouseEvent *m)
+{
+ adjustBounds(m);
+ if (m_doc->m_Selection->count() != 0)
+ {
+ PageItem* currItem = m_doc->m_Selection->itemAt(0);
+// qDebug() << "ResizeGesture::release: new bounds" << m_bounds;
+ doResize(m->modifiers() & Qt::AltModifier);
+ m_doc->setRedrawBounding(currItem);
+ if (currItem->asImageFrame())
+ currItem->AdjustPictScale();
+ m_view->resetMousePressed();
+ // necessary since mousebutton is still recorded pressed, and otherwise checkchanges() will do nothing
+ // we must check changes on whole selection otherwise resize operation won't undo correctly on groups
+ for (int i = 0; i < m_doc->m_Selection->count(); ++i)
+ m_doc->m_Selection->itemAt(i)->checkChanges();
+ currItem->invalidateLayout();
+ currItem->update();
+ }
+// qDebug() << "ResizeGesture::release: transaction" << m_transactionStarted;
+ if (m_transactionStarted)
+ {
+ m_transactionStarted->commit();
+ delete m_transactionStarted;
+ m_transactionStarted = NULL;
+ }
+ m->accept();
+ m_canvas->update();
+ m_view->stopGesture();
+}
+
+
+void ResizeGesture::doResize(bool scaleContent)
+{
+ PageItem* currItem = m_doc->m_Selection->itemAt(0);
+ QString targetName = Um::SelectionGroup;
+ QPixmap* targetIcon = Um::IGroup;
+ if (!m_doc->m_Selection->isMultipleSelection())
+ {
+ targetName = currItem->getUName();
+ targetIcon = currItem->getUPixmap();
+ }
+ if (!m_transactionStarted)
+ {
+ m_transactionStarted = new UndoTransaction(Um::instance()->beginTransaction(targetName, targetIcon,
+ Um::Resize, "", Um::IResize));
+// qDebug() << "ResizeGesture::doResize: begin transaction" << m_transactionStarted;
+ }
+ QRectF newBounds = m_bounds.normalized();
+ if (m_doc->m_Selection->isMultipleSelection())
+ {
+ int RotModeBack = m_doc->RotMode();
+ m_doc->RotMode ( 0 );
+ double gx, gy, gh, gw;
+ m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
+ QRectF oldBounds(gx, gy, gw, gh);
+ double scx = oldBounds.width() == 0? 1.0 : (newBounds.width() - m_extraWidth) / oldBounds.width();
+ double scy = oldBounds.height() == 0? 1.0 : (newBounds.height() - m_extraHeight) / oldBounds.height();
+ //CB #3012 only scale text in a group if alt is pressed
+ if ((currItem->itemType() == PageItem::TextFrame) && scaleContent)
+ m_doc->scaleGroup(scx, scy, true);
+ else
+ m_doc->scaleGroup(scx, scy, false);
+ double dx = newBounds.x() - oldBounds.x();
+ double dy = newBounds.y() - oldBounds.y();
+ if (dx != 0 || dy != 0)
+ m_doc->moveGroup(dx + m_extraX, dy + m_extraY);
+ m_doc->RotMode ( RotModeBack );
+ }
+ else
+ {
+ if (currItem->itemType() == PageItem::ImageFrame && scaleContent)
+ {
+ double divX = (currItem->width() != 0) ? currItem->width() : 1.0;
+ double divY = (currItem->height() != 0) ? currItem->height() : 1.0;
+ double imgScX = (newBounds.width() - m_extraWidth) / divX * currItem->imageXScale();
+ double imgScY = (newBounds.height() - m_extraHeight) / divY * currItem->imageYScale();
+ // The aspect ratio has been fixed, so make the modification in the direction of the larger movement.
+ if (currItem->keepAspectRatio() && currItem->fitImageToFrame())
+ {
+ if (qAbs((newBounds.width() - m_extraWidth) - currItem->width()) > qAbs((newBounds.height() - m_extraHeight) - currItem->height()))
+ imgScY = imgScX;
+ else
+ imgScX = imgScY;
+ }
+ currItem->setImageXYScale(imgScX, imgScY);
+ }
+ else if (currItem->itemType() == PageItem::ImageFrame && currItem->PictureIsAvailable)
+ {
+ double dx = ((newBounds.x() + m_extraX) - currItem->xPos());
+ double dy = ((newBounds.y() + m_extraY) - currItem->yPos());
+ double cosa = cos(currItem->rotation() * M_PI / 180.0);
+ double sina = sin(currItem->rotation() * M_PI / 180.0);
+ double xoff = -(cosa*dx + sina*dy);
+ if (currItem->imageFlippedH())
+ xoff += (currItem->width() - (newBounds.width() - m_extraWidth));
+ double yoff = -(cosa*dy - sina*dx);
+ if (currItem->imageFlippedV())
+ yoff += (currItem->height() - (newBounds.height() - m_extraHeight));
+ if (xoff != 0.0 || yoff != 0.0)
+ {
+ currItem->moveImageInFrame(xoff / currItem->imageXScale(), yoff / currItem->imageYScale());
+ }
+ }
+ // We do not want to scale the text of a linked frame
+ // as it would alter text in other frames of the string
+ else if((currItem->itemType() == PageItem::TextFrame)
+ && (currItem->nextInChain() == 0)
+ && (currItem->prevInChain() == 0)
+ && scaleContent)
+ {
+ double divX = (currItem->width() != 0) ? currItem->width() : 1.0;
+ double divY = (currItem->height() != 0) ? currItem->height() : 1.0;
+ double txtScX = (newBounds.width() - m_extraWidth) / divX;
+ double txtScY = (newBounds.height() - m_extraHeight) / divY;
+ if (currItem->itemText.length() != 0)
+ {
+ for (int aa = 0; aa < currItem->itemText.length(); ++aa)
+ {
+#if 0 // hard to decide if itâs batter to scale or to change font size
+ currItem->itemText.item(aa)->setScaleV(
+ qMax(qMin(qRound(currItem->itemText.item(aa)->scaleV()*txtScY), 4000), 100));
+ currItem->itemText.item(aa)->setScaleH(
+ qMax(qMin(qRound(currItem->itemText.item(aa)->scaleH() * txtScX), 4000), 100));
+#else
+ currItem->itemText.item(aa)->setFontSize(
+ qMax(qMin(currItem->itemText.item(aa)->fontSize() * txtScY, 4000.0), 1.0));
+ currItem->itemText.item(aa)->setScaleH(
+ qMax(qMin(qRound(currItem->itemText.item(aa)->scaleH() * txtScX / txtScY), 4000), 100));
+#endif
+
+ // We need to scale the linespacing _only once_ per paragraph.
+ if((aa == 0)
+ || ( SpecialChars::isBreak(currItem->itemText.itemText(aa - 1).at(0))))
+ {
+ ParagraphStyle ps(currItem->itemText.paragraphStyle(aa));
+ double oldLS(currItem->itemText.paragraphStyle(aa).lineSpacing());
+ ps.setLineSpacing(qMax(qRound(oldLS * txtScY), 1));
+ currItem->itemText.setStyle(aa,ps);
+ }
+ }
+ }
+ }
+ currItem->setXYPos(newBounds.x() + m_extraX, newBounds.y() + m_extraY);
+ currItem->setWidth(newBounds.width() - m_extraWidth);
+ currItem->setHeight(newBounds.height() - m_extraHeight);
+ // rotation does not change
+ }
+ m_origBounds = m_bounds;
+ currItem->updateClip();
+}
+
+
+void ResizeGesture::mouseMoveEvent(QMouseEvent *m)
+{
+ adjustBounds(m);
+ FPoint where = m_canvas->globalToCanvas(m->globalPos());
+ if (// directly after a create the shape of an item isnt really usable, so we fix here
+ m_origBounds.width() < 20 || m_origBounds.height() < 20 ||
+ // and if we resize outside of the current canvas dimensions, we need to enlarge it
+ where.x() < m_doc->minCanvasCoordinate.x() || where.y() < m_doc->minCanvasCoordinate.y() ||
+ where.x() > m_doc->maxCanvasCoordinate.x() || where.y() > m_doc->maxCanvasCoordinate.y())
+ {
+ doResize(m->modifiers() & Qt::AltModifier);
+ }
+ m->accept();
+ QPoint point = m->globalPos() - (m_canvas->mapToParent(QPoint(0, 0)) + m_canvas->parentWidget()->mapToGlobal(QPoint(0, 0)));
+ m_view->ensureVisible(point.x(), point.y(), 20, 20);
+ m_canvas->repaint();
+ QRectF newBounds = m_bounds.normalized();
+ m_canvas->displaySizeHUD(m->globalPos(), newBounds.width() - m_extraWidth, newBounds.height() - m_extraHeight);
+}
+
+
+
+void ResizeGesture::adjustBounds(QMouseEvent *m)
+{
+ QTransform rotation;
+ FPoint docPoint = m_canvas->globalToCanvas(m->globalPos());
+ QPointF oldXY = m_bounds.topLeft();
+ // proportional resize
+ bool constrainRatio = ((m->modifiers() & Qt::ControlModifier) != Qt::NoModifier);
+
+
+ // snap to grid + snap to guides
+ bool isCorner = m_handle == Canvas::NORTHWEST || m_handle == Canvas::NORTHEAST
+ || m_handle == Canvas::SOUTHWEST || m_handle == Canvas::SOUTHEAST;
+ if (m_rotation == 0 || isCorner)
+ {
+ FPoint snappedPoint = m_doc->ApplyGridF(docPoint);
+ double x = snappedPoint.x(), y = snappedPoint.y();
+ m_doc->ApplyGuides(&x, &y);
+// if (m_doc->ApplyGuides(&x, &y))
+// qDebug() << "guides applied:" << snappedPoint.x() << snappedPoint.y() << "to" << x << y;
+ if (m_handle == Canvas::NORTH || m_handle == Canvas::SOUTH)
+ // only snap on y-axis
+ docPoint = FPoint(docPoint.x(), y);
+ else if (m_handle == Canvas::EAST || m_handle == Canvas::WEST)
+ // only snap on x-axis
+ docPoint = FPoint(x, docPoint.y());
+ else
+ docPoint = FPoint(x,y);
+// qDebug() << "resize snap grid/guides:" << m->globalPos() << "-->" << m_canvas->canvasToGlobal(docPoint);
+ }
+
+ // un-rotate point
+ if (m_rotation != 0)
+ {
+ // rotate point around item position
+ rotation.translate(m_bounds.x(), m_bounds.y());
+ rotation.rotate(m_rotation);
+ rotation.translate(-m_bounds.x(), -m_bounds.y());
+// qDebug() << "resize rotated" << m_rotation << "°" << m_bounds << rotation << ":" << point-globalBounds.topLeft() << "-->" << rotation.map(point)-globalBounds.topLeft();
+ QPointF qp = QPointF(docPoint.x(), docPoint.y());
+ qp = rotation.inverted().map(qp);
+ docPoint = FPoint(qp.x(), qp.y());
+ }
+
+ // adjust bounds vertically
+ switch (m_handle)
+ {
+ case Canvas::NORTHWEST:
+ case Canvas::NORTH:
+ case Canvas::NORTHEAST:
+// qDebug() << "ResizeGesture: top to" << point.y();
+ m_bounds.setTop(docPoint.y());
+ break;
+ case Canvas::SOUTHWEST:
+ case Canvas::SOUTH:
+ case Canvas::SOUTHEAST:
+// qDebug() << "ResizeGesture: bottom to" << point.y();
+ m_bounds.setBottom(docPoint.y());
+ break;
+ default:
+ break;
+ }
+ // adjust bounds horizontally
+ switch (m_handle)
+ {
+ case Canvas::NORTHWEST:
+ case Canvas::WEST:
+ case Canvas::SOUTHWEST:
+// qDebug() << "ResizeGesture: left to" << point.x();
+ m_bounds.setLeft(docPoint.x());
+ break;
+ case Canvas::NORTHEAST:
+ case Canvas::EAST:
+ case Canvas::SOUTHEAST:
+// qDebug() << "ResizeGesture: right to" << point.x();
+ m_bounds.setRight(docPoint.x());
+ break;
+ default:
+ break;
+ }
+
+ // constrain ratio
+ double newRatio = double(m_bounds.width()) / double(m_bounds.height());
+ if (constrainRatio && m_origRatio != newRatio)
+ {
+// qDebug() << "constrain ratio:" << m_bounds << newRatio << "to" << m_origRatio;
+ int newWidth = qRound(m_bounds.height() * m_origRatio);
+ int newHeight = qRound(m_bounds.width() / m_origRatio);
+ switch (m_handle)
+ {
+ case Canvas::NORTHWEST:
+ // axis: topleft + t*[origRatio, 1] t:= y-top
+ // [x',y] = [left, top] + [(y-top)*origRatio, y-top]
+ // = [left + (y-top)*origRatio, y]
+ // x < x' => mouse is WEST, x > x' => mouse is NORTH
+ // x < left + (y-top)*origratio <=> x - left < (y - top) * origratio
+
+// qDebug() << "NORTHWEST" << point << m_origBounds.topLeft() << m_origRatio
+// << (point.x() - m_origBounds.left() < (point.y()-m_origBounds.top()) * m_origRatio);
+
+ if (docPoint.x() - m_origBounds.left() < (docPoint.y()-m_origBounds.top()) * m_origRatio)
+ m_bounds.setTop(m_bounds.top() - newHeight + m_bounds.height());
+ else
+ m_bounds.setLeft(m_bounds.left() - newWidth + m_bounds.width());
+ break;
+ case Canvas::SOUTHWEST:
+ // axis: bottomleft + t*[origRatio, -1] t:= bottom-y
+ // (x',y) = [left, bottom] + [(bottom-y)*origRatio, -bottom+y]
+ // = [left + (bottom-y)*origRatio, y]
+ // x < x' => mouse is WEST, x > x' => mouse is SOUTH
+ // x < left + (bottom-y)*origratio <=> x - left < (bottom-y) * origratio
+
+// qDebug() << "SOUTHWEST" << point << m_origBounds.bottomLeft() << m_origRatio
+// << (point.x() - m_origBounds.left() < (m_origBounds.bottom() - point.y()) * m_origRatio);
+
+ if (docPoint.x() - m_origBounds.left() < (m_origBounds.bottom() - docPoint.y()) * m_origRatio)
+ m_bounds.setHeight(newHeight);
+ else
+ m_bounds.setLeft(m_bounds.left() - newWidth + m_bounds.width());
+ break;
+ case Canvas::NORTHEAST:
+ // cf. SOUTHWEST
+ if (docPoint.x() - m_origBounds.left() > (m_origBounds.bottom() - docPoint.y()) * m_origRatio)
+ m_bounds.setTop(m_bounds.top() - newHeight + m_bounds.height());
+ else
+ m_bounds.setWidth(newWidth);
+ break;
+ case Canvas::SOUTHEAST:
+ // cf. NORTHWEST
+ if (docPoint.x() - m_origBounds.left() > (docPoint.y()-m_origBounds.top()) * m_origRatio)
+ m_bounds.setHeight(newHeight);
+ else
+ m_bounds.setWidth(newWidth);
+ break;
+ case Canvas::WEST:
+ case Canvas::EAST:
+ // (origBounds.top + origBounds.bottom) / 2 is the horizontal axis
+ // keep that fixed
+ m_bounds.setTop(((m_origBounds.top() + m_origBounds.bottom()) / 2) - newHeight / 2);
+ m_bounds.setHeight(newHeight);
+ break;
+ case Canvas::NORTH:
+ case Canvas::SOUTH:
+ // (origBounds.left + origBounds.right) / 2 is the vertical axis
+ // keep that fixed
+ m_bounds.setLeft(((m_origBounds.left() + m_origBounds.right()) / 2) - newWidth / 2);
+ m_bounds.setWidth(newWidth);
+ break;
+ default:
+ break;
+ }
+// qDebug() << "constrained:" << m_bounds << double(m_bounds.width()) / m_bounds.height();
+ }
+
+ // re-rotate: if top left has changed, then it needs rotation
+ if (m_rotation != 0 && oldXY != m_bounds.topLeft())
+ {
+ m_bounds.moveTo(rotation.map(m_bounds.topLeft()));
+ // fix opposite corner to avoid aggregating rounding errors
+ QPointF origFixPoint, newFixPoint;
+ switch (m_handle)
+ {
+ case Canvas::NORTHWEST:
+ origFixPoint = m_origBounds.bottomRight();
+ newFixPoint = m_bounds.bottomRight();
+ break;
+ case Canvas::WEST:
+ origFixPoint = m_origBounds.topRight() + QPointF(0, m_origBounds.height()/2);
+ newFixPoint = m_bounds.topRight() + QPointF(0, m_bounds.height()/2);
+ break;
+ case Canvas::SOUTHWEST:
+ origFixPoint = m_origBounds.topRight();
+ newFixPoint = m_bounds.topRight();
+ break;
+ case Canvas::SOUTH:
+ origFixPoint = m_origBounds.topLeft() + QPointF(m_origBounds.width()/2, 0);
+ newFixPoint = m_bounds.topLeft() + QPointF(m_bounds.width()/2, 0);
+ break;
+ case Canvas::SOUTHEAST:
+ origFixPoint = m_origBounds.topLeft();
+ newFixPoint = m_bounds.topLeft();
+ break;
+ case Canvas::EAST:
+ origFixPoint = m_origBounds.topLeft() + QPointF(0, m_origBounds.height()/2);
+ newFixPoint = m_bounds.topLeft() + QPointF(0, m_bounds.height()/2);
+ break;
+ case Canvas::NORTHEAST:
+ origFixPoint = m_origBounds.bottomLeft();
+ newFixPoint = m_bounds.bottomLeft();
+ break;
+ case Canvas::NORTH:
+ origFixPoint = m_origBounds.bottomLeft() + QPointF(m_origBounds.width()/2, 0);
+ newFixPoint = m_bounds.bottomLeft() + QPointF(m_bounds.width()/2, 0);
+ break;
+ default:
+ origFixPoint = m_origBounds.topLeft();
+ newFixPoint = m_bounds.topLeft();
+ break;
+ }
+ origFixPoint = m_origBounds.topLeft() + rotation.map(origFixPoint - m_origBounds.topLeft());
+ newFixPoint = m_bounds.topLeft() + rotation.map(newFixPoint - m_bounds.topLeft());
+ if (origFixPoint != newFixPoint)
+ m_bounds.translate(origFixPoint - newFixPoint);
+ }
+}
+
+
+
+void ResizeGesture::mousePressEvent(QMouseEvent *m)
+{
+ FPoint point = m_canvas->globalToCanvas(m->globalPos());
+ if (m_doc->m_Selection->count() == 0)
+ {
+ m_handle = Canvas::OUTSIDE;
+ }
+ else if (m_doc->m_Selection->isMultipleSelection())
+ {
+ double gx, gy, gh, gw;
+ m_doc->m_Selection->getVisualGroupRect(&gx, &gy, &gw, &gh);
+ m_handle = m_canvas->frameHitTest(QPointF(point.x(), point.y()), QRectF(gx,gy,gw,gh));
+ }
+ else
+ {
+ m_handle = m_canvas->frameHitTest(QPointF(point.x(), point.y()), m_doc->m_Selection->itemAt(0));
+ }
+ if (m_handle > 0)
+ {
+ prepare(m_handle);
+ m->accept();
+ }
+}
Index: scribus/util_math.h
===================================================================
--- scribus/util_math.h (revision 13950)
+++ scribus/util_math.h (revision 13951)
@@ -1,92 +1,92 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-#ifndef _UTIL_MATH_H
-#define _UTIL_MATH_H
-
-#if defined(_MSC_VER)
-#define _USE_MATH_DEFINES
-#endif
-#include <cmath>
-#include <vector>
-
-#include <QString>
-#include <QPolygon>
-#include <QList>
-#include <QPainterPath>
-
-#include "scribusapi.h"
-
-class FPoint;
-class FPointArray;
-
-
-/*! \brief Compare double values by pre-multiplying by 10000 and converting to long if possible.
-If premultiplication does not allow to store result in a long value, perform a standard comparison.
-*/
-bool SCRIBUS_API compareDouble(double a, double b);
-FPoint SCRIBUS_API getMaxClipF(FPointArray* Clip);
-FPoint SCRIBUS_API getMinClipF(FPointArray* Clip);
-inline double SCRIBUS_API xy2Deg(double x, double y);
-FPoint SCRIBUS_API projectPointOnLine(FPoint p, QPointF lineStart, QPointF lineEnd);
-QPolygon SCRIBUS_API FlattenPath(const FPointArray& ina, QList<uint> &Segs);
-QList<QPainterPath> SCRIBUS_API decomposePath(QPainterPath &path);
-QPainterPath SCRIBUS_API RegularPolygon(double w, double h, uint c, bool star, double factor, double rota, double factor2 = 0.0);
-uint SCRIBUS_API getDouble(QString in, bool raw);
-inline double SCRIBUS_API sind(double);
-inline double SCRIBUS_API cosd(double);
-inline double SCRIBUS_API square(double);
-inline double SCRIBUS_API distance(double, double);
-/*! \brief Constrains an angle of rotation to 45 degree intervals
- Will make code simpler and reduce interval or provide as a parameter
- \param angle angle Angle in degrees
- \param constrain contrain value in degrees
- \retval double Constrained angle
- */
-double SCRIBUS_API constrainAngle(double angle, double constrain);
-/*! \brief Get the rotation angle (in radian) from a transformation matrix
- Will make code simpler and reduce interval or provide as a parameter
- \param matrix the transformation matrix
- \param def the value that should be return if matrix is not a rotation matrix
- \retval double the rotation angle
- */
-double SCRIBUS_API getRotationFromMatrix(QMatrix& matrix, double def);
-
-
-// IMPLEMENTATION
-
-inline double square(double x)
-{
- return x*x;
-}
-
-inline double distance(double x, double y)
-{
- return sqrt(x*x + y*y);
-}
-
-inline double xy2Deg(double x, double y)
-{
- return atan2(y,x) * (180.0/M_PI);
-}
-
-inline double sind(double alpha)
-{
- return sin(alpha / (180.0/M_PI));
-}
-
-inline double cosd(double alpha)
-{
- return cos(alpha / (180.0/M_PI));
-}
-
-template <typename T>
-inline bool isequiv(const T& v1, const T& v2) { return v1 == v2; }
-
-template <>
-inline bool isequiv<double>(const double& v1, const double& v2) { return compareDouble(v1, v2); }
-
-#endif
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+#ifndef _UTIL_MATH_H
+#define _UTIL_MATH_H
+
+#if defined(_MSC_VER)
+#define _USE_MATH_DEFINES
+#endif
+#include <cmath>
+#include <vector>
+
+#include <QString>
+#include <QPolygon>
+#include <QList>
+#include <QPainterPath>
+
+#include "scribusapi.h"
+
+class FPoint;
+class FPointArray;
+
+
+/*! \brief Compare double values by pre-multiplying by 10000 and converting to long if possible.
+If premultiplication does not allow to store result in a long value, perform a standard comparison.
+*/
+bool SCRIBUS_API compareDouble(double a, double b);
+FPoint SCRIBUS_API getMaxClipF(FPointArray* Clip);
+FPoint SCRIBUS_API getMinClipF(FPointArray* Clip);
+inline double SCRIBUS_API xy2Deg(double x, double y);
+FPoint SCRIBUS_API projectPointOnLine(FPoint p, QPointF lineStart, QPointF lineEnd);
+QPolygon SCRIBUS_API FlattenPath(const FPointArray& ina, QList<uint> &Segs);
+QList<QPainterPath> SCRIBUS_API decomposePath(QPainterPath &path);
+QPainterPath SCRIBUS_API RegularPolygon(double w, double h, uint c, bool star, double factor, double rota, double factor2 = 0.0);
+uint SCRIBUS_API getDouble(QString in, bool raw);
+inline double SCRIBUS_API sind(double);
+inline double SCRIBUS_API cosd(double);
+inline double SCRIBUS_API square(double);
+inline double SCRIBUS_API distance(double, double);
+/*! \brief Constrains an angle of rotation to 45 degree intervals
+ Will make code simpler and reduce interval or provide as a parameter
+ \param angle angle Angle in degrees
+ \param constrain contrain value in degrees
+ \retval double Constrained angle
+ */
+double SCRIBUS_API constrainAngle(double angle, double constrain);
+/*! \brief Get the rotation angle (in radian) from a transformation matrix
+ Will make code simpler and reduce interval or provide as a parameter
+ \param matrix the transformation matrix
+ \param def the value that should be return if matrix is not a rotation matrix
+ \retval double the rotation angle
+ */
+double SCRIBUS_API getRotationFromMatrix(QTransform& matrix, double def);
+
+
+// IMPLEMENTATION
+
+inline double square(double x)
+{
+ return x*x;
+}
+
+inline double distance(double x, double y)
+{
+ return sqrt(x*x + y*y);
+}
+
+inline double xy2Deg(double x, double y)
+{
+ return atan2(y,x) * (180.0/M_PI);
+}
+
+inline double sind(double alpha)
+{
+ return sin(alpha / (180.0/M_PI));
+}
+
+inline double cosd(double alpha)
+{
+ return cos(alpha / (180.0/M_PI));
+}
+
+template <typename T>
+inline bool isequiv(const T& v1, const T& v2) { return v1 == v2; }
+
+template <>
+inline bool isequiv<double>(const double& v1, const double& v2) { return compareDouble(v1, v2); }
+
+#endif
Index: scribus/scpreview.cpp
===================================================================
--- scribus/scpreview.cpp (revision 13950)
+++ scribus/scpreview.cpp (revision 13951)
@@ -475,7 +475,7 @@
{
pS->save();
FPointArray cl = OB.PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(OB.Xpos, OB.Ypos);
mm.rotate(static_cast<double>(OB.Rot));
cl.map( mm );
@@ -526,7 +526,7 @@
}
else
pS->fill_gradient = OB.fill_gradient;
- QMatrix grm;
+ QTransform grm;
grm.rotate(OB.Rot);
FPointArray gra;
switch (OB.GrType)
@@ -748,7 +748,7 @@
}
if (OB.startArrowIndex != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = arrowStyles.at(OB.startArrowIndex-1).points.copy();
arrowTrans.translate(0, 0);
arrowTrans.scale(OB.Pwidth, OB.Pwidth);
@@ -762,7 +762,7 @@
}
if (OB.endArrowIndex != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = arrowStyles.at(OB.endArrowIndex-1).points.copy();
arrowTrans.translate(OB.Width, 0);
arrowTrans.scale(OB.Pwidth, OB.Pwidth);
@@ -851,7 +851,7 @@
if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
{
double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = arrowStyles.at(OB.startArrowIndex-1).points.copy();
arrowTrans.translate(Start.x(), Start.y());
arrowTrans.rotate(r);
@@ -875,7 +875,7 @@
if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
{
double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
FPointArray arrow = arrowStyles.at(OB.endArrowIndex-1).points.copy();
arrowTrans.translate(End.x(), End.y());
arrowTrans.rotate(r);
@@ -1066,21 +1066,21 @@
if (prefsManager->appPrefs.AvailFonts[ZFo].canRender(ccx[0]))
{
wide = prefsManager->appPrefs.AvailFonts[ZFo].charWidth(ccx[0])*(Siz / 10.0);
- QMatrix chma;
+ QTransform chma;
chma.scale(csi, csi);
uint gl = prefsManager->appPrefs.AvailFonts[ZFo].char2CMap(ccx[0]);
FPointArray gly = prefsManager->appPrefs.AvailFonts[ZFo].glyphOutline(gl);
if (gly.size() < 4)
return;
gly.map(chma);
- chma = QMatrix();
+ chma = QTransform();
p->setFillMode(1);
if (Reverse)
{
chma.scale(-1, 1);
chma.translate(-wide, 0);
gly.map(chma);
- chma = QMatrix();
+ chma = QTransform();
chma.translate(xco, yco-(Siz / 10.0));
}
else
Index: scribus/pslib.cpp
===================================================================
--- scribus/pslib.cpp (revision 13950)
+++ scribus/pslib.cpp (revision 13951)
@@ -489,7 +489,7 @@
{
PS_save();
FPointArray cl = item->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(item->gXpos, item->gYpos - pa.height);
mm.rotate(item->rotation());
cl.map( mm );
@@ -2267,13 +2267,13 @@
}
if (c->startArrowIndex() != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.scale(-1,1);
drawArrow(c, arrowTrans, c->startArrowIndex(), gcr);
}
if (c->endArrowIndex() != 0)
{
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(c->width(), 0);
drawArrow(c, arrowTrans, c->endArrowIndex(), gcr);
}
@@ -2374,7 +2374,7 @@
if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
{
double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(Start.x(), Start.y());
arrowTrans.rotate(r);
drawArrow(c, arrowTrans, c->startArrowIndex(), gcr);
@@ -2391,7 +2391,7 @@
if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
{
double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
- QMatrix arrowTrans;
+ QTransform arrowTrans;
arrowTrans.translate(End.x(), End.y());
arrowTrans.rotate(r);
drawArrow(c, arrowTrans, c->endArrowIndex(), gcr);
@@ -2512,7 +2512,7 @@
{
PS_save();
FPointArray cl = embedded->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(embedded->gXpos * (style.scaleH() / 1000.0), ((embedded->gHeight * (style.scaleV() / 1000.0)) - embedded->gYpos * (style.scaleV() / 1000.0)) * -1);
if (style.baselineOffset() != 0)
mm.translate(0, embedded->gHeight * (style.baselineOffset() / 1000.0));
@@ -2837,7 +2837,7 @@
{
uint gl = style.font().char2CMap(chstr);
FPointArray gly = style.font().glyphOutline(gl);
- QMatrix chma;
+ QTransform chma;
chma.scale(tsz / 100.0, tsz / 100.0);
gly.map(chma);
PS_save();
@@ -2958,7 +2958,7 @@
{
PS_save();
FPointArray cl = c->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(c->xPos() - a->xOffset(), (c->yPos() - a->yOffset()) - a->height());
mm.rotate(c->rotation());
cl.map( mm );
@@ -3084,7 +3084,7 @@
{
PS_save();
FPointArray cl = ite->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(ite->xPos() - mPage->xOffset(), (ite->yPos() - mPage->yOffset()) - page->height());
mm.rotate(ite->rotation());
cl.map( mm );
@@ -3289,7 +3289,7 @@
{
PS_save();
FPointArray cl = item->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(item->xPos() - page->xOffset(), (item->yPos() - page->yOffset()) - page->height());
mm.rotate(item->rotation());
cl.map( mm );
@@ -3401,7 +3401,7 @@
double EndX = 0;
double EndY =0;
ScPattern *pat;
- QMatrix patternMatrix;
+ QTransform patternMatrix;
double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation;
QList<VColorStop*> cstops = c->fill_gradient.colorStops();
switch (c->GrType)
@@ -3533,7 +3533,7 @@
}
}
-void PSLib::drawArrow(PageItem *ite, QMatrix &arrowTrans, int arrowIndex, bool gcr)
+void PSLib::drawArrow(PageItem *ite, QTransform &arrowTrans, int arrowIndex, bool gcr)
{
int h, s, v, k;
QVector<double> dum;
@@ -3964,7 +3964,7 @@
{
uint gl = hl->font().char2CMap(chstr);
FPointArray gly = hl->font().glyphOutline(gl);
- QMatrix chma, chma2, chma3;
+ QTransform chma, chma2, chma3;
chma.scale(tsz / 100.0, tsz / 100.0);
chma2.scale(hl->scaleH() / 1000.0, hl->scaleV() / 1000.0);
if (hl->baselineOffset() != 0)
@@ -3972,7 +3972,7 @@
gly.map(chma * chma2 * chma3);
if (ite->reversed())
{
- chma = QMatrix();
+ chma = QTransform();
chma.scale(-1, 1);
chma.translate(wideR, 0);
gly.map(chma);
@@ -4083,10 +4083,10 @@
{
uint gl = hl->font().char2CMap(chstr);
FPointArray gly = hl->font().glyphOutline(gl);
- QMatrix chma;
+ QTransform chma;
chma.scale(tsz / 100.0, tsz / 100.0);
gly.map(chma);
- chma = QMatrix();
+ chma = QTransform();
chma.scale(hl->scaleH() / 1000.0, hl->scaleV() / 1000.0);
gly.map(chma);
if (hl->fillColor() != CommonStrings::None)
@@ -4146,7 +4146,7 @@
{
PS_save();
FPointArray cl = embedded->PoLine.copy();
- QMatrix mm;
+ QTransform mm;
mm.translate(x + hl->glyph.xoffset + embedded->gXpos * (cstyle.scaleH() / 1000.0), (y + hl->glyph.yoffset - (embedded->gHeight * (cstyle.scaleV() / 1000.0)) + embedded->gYpos * (cstyle.scaleV() / 1000.0)));
if (cstyle.baselineOffset() != 0)
mm.translate(0, embedded->gHeight * (cstyle.baselineOffset() / 1000.0));
@@ -4367,7 +4367,7 @@
// if (cstyle.font().canRender(chstr))
{
FPointArray gly = cstyle.font().glyphOutline(glyph);
- QMatrix chma, chma2, chma3;
+ QTransform chma, chma2, chma3;
chma.scale(tsz / 100.0, tsz / 100.0);
chma2.scale(glyphs.scaleH, glyphs.scaleV);
if (cstyle.baselineOffset() != 0)
@@ -4375,7 +4375,7 @@
gly.map(chma * chma2 * chma3);
if (ite->reversed())
{
- chma = QMatrix();
+ chma = QTransform();
chma.scale(-1, 1);
chma.translate(wideR, 0);
gly.map(chma);
@@ -4453,10 +4453,10 @@
// if (cstyle.font().canRender(chstr))
{
FPointArray gly = cstyle.font().glyphOutline(glyph);
- QMatrix chma;
+ QTransform chma;
chma.scale(tsz / 100.0, tsz / 100.0);
gly.map(chma);
- chma = QMatrix();
+ chma = QTransform();
chma.scale(glyphs.scaleH, glyphs.scaleV);
gly.map(chma);
if (cstyle.fillColor() != CommonStrings::None)
Index: scribus/vgradient.cpp
===================================================================
--- scribus/vgradient.cpp (revision 13950)
+++ scribus/vgradient.cpp (revision 13951)
@@ -199,7 +199,7 @@
}
}
-void VGradient::transform( const QMatrix &m )
+void VGradient::transform( const QTransform &m )
{
double mx, my;
mx = m.m11() * m_origin.x() + m.m21() * m_origin.y() + m.dx();
Index: scribus/canvasmode_normal.cpp
===================================================================
--- scribus/canvasmode_normal.cpp (revision 13950)
+++ scribus/canvasmode_normal.cpp (revision 13951)
@@ -539,7 +539,7 @@
currItem = m_doc->m_Selection->itemAt(a);
if (currItem->locked())
break;
- QMatrix p;
+ QTransform p;
m_canvas->Transform(currItem, p);
QRect mpo = QRect(m->x()-m_doc->guidesSettings.grabRadius, m->y()-m_doc->guidesSettings.grabRadius, m_doc->guidesSettings.grabRadius*2, m_doc->guidesSettings.grabRadius*2);
// mpo.moveBy(qRound(m_doc->minCanvasCoordinate.x() * m_canvas->scale()), qRound(m_doc->minCanvasCoordinate.y() * m_canvas->scale()));
@@ -929,7 +929,7 @@
PageItem* docItem = m_doc->Items->at(a);
if ((m_doc->masterPageMode()) && (docItem->OnMasterPage != m_doc->currentPage()->pageName()))
continue;
- QMatrix p;
+ QTransform p;
m_canvas->Transform(docItem, p);
// QRegion apr = QRegion(docItem->Clip * p);
QRect apr2(docItem->getRedrawBounding(m_canvas->scale()));
@@ -1019,7 +1019,7 @@
const unsigned SELECT_IN_GROUP = Qt::AltModifier;
const unsigned SELECT_MULTIPLE = Qt::ShiftModifier;
const unsigned SELECT_BENEATH = Qt::ControlModifier;
- QMatrix p;
+ QTransform p;
PageItem *currItem;
m_canvas->m_viewMode.m_MouseButtonPressed = true;
FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
Index: scribus/scpainter.h
===================================================================
--- scribus/scpainter.h (revision 13950)
+++ scribus/scpainter.h (revision 13951)
@@ -13,7 +13,7 @@
#include <QVector>
#include <QStack>
#include <QColor>
-#include <QMatrix>
+#include <QTransform>
#include <QFont>
#include <QImage>
#include "scribusapi.h"
@@ -47,8 +47,8 @@
virtual void clear( const QColor & );
// matrix manipulation
- virtual void setWorldMatrix( const QMatrix & );
- virtual const QMatrix worldMatrix();
+ virtual void setWorldMatrix( const QTransform & );
+ virtual const QTransform worldMatrix();
virtual void setZoomFactor( double );
virtual double zoomFactor() { return m_zoomFactor; }
virtual void translate( double, double );
@@ -136,7 +136,7 @@
int m_blendMode;
unsigned int m_width;
unsigned int m_height;
- QMatrix m_matrix;
+ QTransform m_matrix;
QFont m_font;
bool mf_underline;
bool mf_strikeout;
More information about the scribus-commit
mailing list