summaryrefslogtreecommitdiffstats
path: root/scribus/scpageoutput_ps2.cpp
blob: 9b69f255c84c9148d02aacd6e3f8426cf10f19fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
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 "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";
}