updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / pdfedit-addscript-csv / displayparams.h
blobf14726dee57095ee58013a09621c6f00c94c4465
1 /*
2 * PDFedit - free program for PDF document manipulation.
3 * Copyright (C) 2006-2009 PDFedit team: Michal Hocko,
4 * Jozef Misutka,
5 * Martin Petricek
6 * Former team members: Miroslav Jahoda
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program (in doc/LICENSE.GPL); if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
22 * Project is hosted on http://sourceforge.net/projects/pdfedit
24 // vim:tabstop=4:shiftwidth=4:noexpandtab:textwidth=80
26 #ifndef _DISPLAYPARAMS_H_
27 #define _DISPLAYPARAMS_H_
29 // all basic includes
30 #include "kernel/static.h"
33 //=====================================================================================
34 namespace pdfobjects {
35 //=====================================================================================
38 //=====================================================================================
39 // Display parameters (loose xpdf parameters put into a simple structure)
40 // -- default values are in cpage.cc because we do not want to have global variables.
41 //=====================================================================================
43 /**
44 * Graphical state parameters.
46 * These parameters are used by xpdf when updating bounding boxex of content stream operators,
47 * displaying page etc.
49 typedef struct DisplayParams
51 /** Paramaters */
52 double hDpi; /**< Horizontal DPI. */
53 double vDpi; /**< Vertical DPI. */
54 libs::Rectangle pageRect;/**< Page rectangle. */
55 int rotate; /**< Page rotation. */
56 GBool useMediaBox;/**< Use page media box. */
57 GBool crop; /**< Crop the page. */
58 GBool upsideDown; /**< Upside down. */
60 /** Constructor. Default values are set. */
61 DisplayParams () :
62 hDpi (DEFAULT_HDPI), vDpi (DEFAULT_VDPI),
63 pageRect (libs::Rectangle (DEFAULT_PAGE_LX, DEFAULT_PAGE_LY, DEFAULT_PAGE_RX, DEFAULT_PAGE_RY)),
64 rotate (DEFAULT_ROTATE), useMediaBox (gTrue), crop (gFalse), upsideDown (gTrue)
69 /** Equality operator. */
70 bool operator== (const DisplayParams& dp) const
72 return (hDpi == dp.hDpi && vDpi == dp.vDpi &&
73 pageRect == dp.pageRect && rotate == dp.rotate &&
74 useMediaBox == dp.useMediaBox && crop == dp.crop &&
75 upsideDown == dp.upsideDown);
78 /** Converting position from pixmap of viewed page to pdf position.
79 * @param fromX X position on viewed page.
80 * @param fromY Y position on viewed page.
82 * @param toX return X position in pdf page.
83 * @param toY return Y position in pdf page.
85 * @see convertPdfPosToPixmapPos
87 void convertPixmapPosToPdfPos( double fromX, double fromY, double & toX, double & toY ) const {
88 const double * ctm /*[6]*/;
89 double h;
90 PDFRectangle pdfRect ( pageRect.xleft, pageRect.yleft, pageRect.xright, pageRect.yright );
91 GfxState state (hDpi, vDpi, &pdfRect, rotate, upsideDown );
92 ctm = state.getCTM();
94 h = (ctm[0]*ctm[3] - ctm[1]*ctm[2]);
96 assert( h != 0 );
98 toX = (fromX*ctm[3] - ctm[2]*fromY + ctm[2]*ctm[5] - ctm[4]*ctm[3]) / h;
99 toY = (ctm[0]*fromY + ctm[1]*ctm[4] - ctm[0]*ctm[5] - ctm[1]*fromX) / h;
102 /** Converting pdf position to position on pixmap of viewed page.
103 * @param fromX X position in pdf page.
104 * @param fromY Y position in pdf page.
106 * @param toX return X position on viewed page.
107 * @param toY return Y position on viewed page.
109 * @see convertPixmapPosToPdfPos
111 void convertPdfPosToPixmapPos( double fromX, double fromY, double & toX, double & toY ) const {
112 PDFRectangle pdfRect ( pageRect.xleft, pageRect.yleft, pageRect.xright, pageRect.yright );
113 GfxState state (hDpi, vDpi, &pdfRect, rotate, upsideDown );
115 state.transform( fromX, fromY, &toX, &toY );
119 // Default values
120 // -- small hack to declare them as ints, to be able to init
121 // them here (if double, we could not init them here because of the non
122 // integral type compilator error))
124 static const int DEFAULT_HDPI = 72; /**< Default horizontal dpi. */
125 static const int DEFAULT_VDPI = 72; /**< Default vertical dpi. */
126 static const int DEFAULT_ROTATE = 0; /**< No rotatation. */
128 static const int DEFAULT_PAGE_LX = 0; /**< Default x position of left upper corner. */
129 static const int DEFAULT_PAGE_LY = 0; /**< Default y position of right upper corner. */
130 static const int DEFAULT_PAGE_RX = 1584; /**< Default A4 width on a device with 72 horizontal dpi. */
131 static const int DEFAULT_PAGE_RY = 1584; /**< Default A4 height on a device with 72 vertical dpi. */
133 } DisplayParams;
136 //=====================================================================================
137 } // namespace pdfobjects
138 //=====================================================================================
141 #endif // _DISPLAYPARAMS_H_