21#include "KoPageLayout.h"
32#define PG_A3_WIDTH 297.0
33#define PG_A3_HEIGHT 420.0
34#define PG_A4_WIDTH 210.0
35#define PG_A4_HEIGHT 297.0
36#define PG_A5_WIDTH 148.0
37#define PG_A5_HEIGHT 210.0
38#define PG_B5_WIDTH 182.0
39#define PG_B5_HEIGHT 257.0
40#define PG_US_LETTER_WIDTH 216.0
41#define PG_US_LETTER_HEIGHT 279.0
42#define PG_US_LEGAL_WIDTH 216.0
43#define PG_US_LEGAL_HEIGHT 356.0
44#define PG_US_EXECUTIVE_WIDTH 191.0
45#define PG_US_EXECUTIVE_HEIGHT 254.0
49 KoGenStyle style(KoGenStyle::STYLE_PAGELAYOUT);
50 style.addPropertyPt( "fo:page-width", ptWidth);
51 style.addPropertyPt( "fo:page-height", ptHeight);
52 style.addPropertyPt( "fo:margin-left", ptLeft);
53 style.addPropertyPt( "fo:margin-right", ptRight);
54 style.addPropertyPt( "fo:margin-top", ptTop);
55 style.addPropertyPt( "fo:margin-bottom", ptBottom);
56 style.addProperty( "style:print-orientation", ( orientation == PG_LANDSCAPE ? "landscape" : "portrait"));
62 TQDomElement properties( KoDom::namedItemNS( style, KoXmlNS::style, "page-layout-properties" ) );
63 if ( !properties.isNull() )
67 if (properties.attributeNS( KoXmlNS::style, "print-orientation", TQString())== "portrait")
86 layout. format = KoPageFormat::defaultFormat();
90 layout. ptLeft = MM_TO_POINT( 20.0 );
91 layout. ptRight = MM_TO_POINT( 20.0 );
92 layout. ptTop = MM_TO_POINT( 20.0 );
93 layout. ptBottom = MM_TO_POINT( 20.0 );
94 layout.ptPageEdge = -1;
95 layout.ptBindingSide = -1;
102 KPrinter::PageSize kprinter;
103 const char* shortName;
104 const char* descriptiveName;
114const PageFormatInfo pageFormatInfo[]=
116 { PG_DIN_A3, KPrinter::A3, "A3", I18N_NOOP( "ISO A3"), 297.0, 420.0 },
117 { PG_DIN_A4, KPrinter::A4, "A4", I18N_NOOP( "ISO A4"), 210.0, 297.0 },
118 { PG_DIN_A5, KPrinter::A5, "A5", I18N_NOOP( "ISO A5"), 148.0, 210.0 },
119 { PG_US_LETTER, KPrinter::Letter, "Letter", I18N_NOOP( "US Letter"), 215.9, 279.4 },
120 { PG_US_LEGAL, KPrinter::Legal, "Legal", I18N_NOOP( "US Legal"), 215.9, 355.6 },
121 { PG_SCREEN, KPrinter::A4, "Screen", I18N_NOOP( "Screen"), PG_A4_HEIGHT, PG_A4_WIDTH },
122 { PG_CUSTOM, KPrinter::A4, "Custom", I18N_NOOP2( "Custom size", "Custom"), PG_A4_WIDTH, PG_A4_HEIGHT },
123 { PG_DIN_B5, KPrinter::B5, "B5", I18N_NOOP( "ISO B5"), 182.0, 257.0 },
125 { PG_US_EXECUTIVE, KPrinter::Executive, "Executive", I18N_NOOP( "US Executive"), 191.0, 254.0 },
126 { PG_DIN_A0, KPrinter::A0, "A0", I18N_NOOP( "ISO A0"), 841.0, 1189.0 },
127 { PG_DIN_A1, KPrinter::A1, "A1", I18N_NOOP( "ISO A1"), 594.0, 841.0 },
128 { PG_DIN_A2, KPrinter::A2, "A2", I18N_NOOP( "ISO A2"), 420.0, 594.0 },
129 { PG_DIN_A6, KPrinter::A6, "A6", I18N_NOOP( "ISO A6"), 105.0, 148.0 },
130 { PG_DIN_A7, KPrinter::A7, "A7", I18N_NOOP( "ISO A7"), 74.0, 105.0 },
131 { PG_DIN_A8, KPrinter::A8, "A8", I18N_NOOP( "ISO A8"), 52.0, 74.0 },
132 { PG_DIN_A9, KPrinter::A9, "A9", I18N_NOOP( "ISO A9"), 37.0, 52.0 },
133 { PG_DIN_B0, KPrinter::B0, "B0", I18N_NOOP( "ISO B0"), 1030.0, 1456.0 },
134 { PG_DIN_B1, KPrinter::B1, "B1", I18N_NOOP( "ISO B1"), 728.0, 1030.0 },
135 { PG_DIN_B10, KPrinter::B10, "B10", I18N_NOOP( "ISO B10"), 32.0, 45.0 },
136 { PG_DIN_B2, KPrinter::B2, "B2", I18N_NOOP( "ISO B2"), 515.0, 728.0 },
137 { PG_DIN_B3, KPrinter::B3, "B3", I18N_NOOP( "ISO B3"), 364.0, 515.0 },
138 { PG_DIN_B4, KPrinter::B4, "B4", I18N_NOOP( "ISO B4"), 257.0, 364.0 },
139 { PG_DIN_B6, KPrinter::B6, "B6", I18N_NOOP( "ISO B6"), 128.0, 182.0 },
140 { PG_ISO_C5, KPrinter::C5E, "C5", I18N_NOOP( "ISO C5"), 163.0, 229.0 },
141 { PG_US_COMM10, KPrinter::Comm10E, "Comm10", I18N_NOOP( "US Common 10"), 105.0, 241.0 },
142 { PG_ISO_DL, KPrinter::DLE, "DL", I18N_NOOP( "ISO DL"), 110.0, 220.0 },
143 { PG_US_FOLIO, KPrinter::Folio, "Folio", I18N_NOOP( "US Folio"), 210.0, 330.0 },
144 { PG_US_LEDGER, KPrinter::Ledger, "Ledger", I18N_NOOP( "US Ledger"), 432.0, 279.0 },
145 { PG_US_TABLOID, KPrinter::Tabloid, "Tabloid", I18N_NOOP( "US Tabloid"), 279.0, 432.0 }
148int KoPageFormat::printerPageSize( KoFormat format )
150 if ( format == PG_SCREEN )
152 kdWarning() << "You use the page layout SCREEN. Printing in DIN A4 LANDSCAPE." << endl;
155 else if ( format == PG_CUSTOM )
157 kdWarning() << "The used page layout (CUSTOM) is not supported by KPrinter. Printing in A4." << endl;
160 else if ( format <= PG_LAST_FORMAT )
161 return pageFormatInfo[ format ].kprinter;
166double KoPageFormat::width( KoFormat format, KoOrientation orientation )
168 if ( orientation == PG_LANDSCAPE )
169 return height( format, PG_PORTRAIT );
170 if ( format <= PG_LAST_FORMAT )
171 return pageFormatInfo[ format ].width;
175double KoPageFormat::height( KoFormat format, KoOrientation orientation )
177 if ( orientation == PG_LANDSCAPE )
178 return width( format, PG_PORTRAIT );
179 if ( format <= PG_LAST_FORMAT )
180 return pageFormatInfo[ format ].height;
184KoFormat KoPageFormat::guessFormat( double width, double height )
186 for ( int i = 0 ; i <= PG_LAST_FORMAT ; ++i )
191 && kAbs( width - pageFormatInfo[i].width ) < 1.0
192 && kAbs( height - pageFormatInfo[i].height ) < 1.0 )
193 return static_cast<KoFormat >(i);
198TQString KoPageFormat::formatString( KoFormat format )
200 if ( format <= PG_LAST_FORMAT )
201 return TQString::fromLatin1( pageFormatInfo[ format ].shortName );
202 return TQString::fromLatin1( "A4" );
205KoFormat KoPageFormat::formatFromString( const TQString & string )
207 for ( int i = 0 ; i <= PG_LAST_FORMAT ; ++i )
209 if ( string == TQString::fromLatin1( pageFormatInfo[ i ].shortName ))
210 return pageFormatInfo[ i ].format;
216KoFormat KoPageFormat::defaultFormat()
218 int kprinter = TDEGlobal::locale()->pageSize();
219 for ( int i = 0 ; i <= PG_LAST_FORMAT ; ++i )
221 if ( pageFormatInfo[ i ].kprinter == kprinter )
222 return static_cast<KoFormat >(i);
227TQString KoPageFormat::name( KoFormat format )
229 if ( format <= PG_LAST_FORMAT )
230 return i18n( pageFormatInfo[ format ].descriptiveName );
231 return i18n( pageFormatInfo[ PG_DIN_A4 ].descriptiveName );
234TQStringList KoPageFormat::allFormats()
237 for ( int i = 0 ; i <= PG_LAST_FORMAT ; ++i )
239 lst << i18n( pageFormatInfo[ i ].descriptiveName );
static double parseValue(TQString value, double defaultVal=0.0) parse common KOffice and OO values, like "10cm", "5mm" to pt
KOFFICECORE_EXPORT TQDomElement namedItemNS(const TQDomNode &node, const char *nsURI, const char *localName) A namespace-aware version of TQDomNode::namedItem(), which also takes care of casting to a TQDomEleme...
This structure defines the page layout, including its size in pt, its format (e.g.
KoFormat format Page format.
double ptRight Right margin in pt.
double ptHeight Page height in pt.
KOFFICECORE_EXPORT void loadOasis(const TQDomElement &style) Load this page layout from OASIS.
KoOrientation orientation Page orientation.
double ptLeft Left margin in pt.
double ptBottom Bottom margin in pt.
double ptWidth Page width in pt.
static KOFFICECORE_EXPORT KoPageLayout standardLayout()
KOFFICECORE_EXPORT KoGenStyle saveOasis() const Save this page layout to OASIS.
double ptTop Top margin in pt.
|