Margins in the printer properties
Goffioul Michael
goffioul at imec.be
Wed Sep 28 15:26:53 CEST 2005
> Ok. See below:
> Appologies if I'm quoting wrong versions of the sources:
> From:
> http://developer.kde.org/documentation/library/3.4-api/kdeprin
> t/html/kpmarginpage_8cpp-source.html
>
> 00060 void KPMarginPage::initPageSize(const QString& ps, bool
> landscape)
> 00061 {
> 00062 // first retrieve the Qt values for page size and margins
> 00063 QPrinter prt(QPrinter::PrinterResolution);
> 00064 prt.setFullPage(true);
> 00065 prt.setPageSize((QPrinter::PageSize)(ps.isEmpty() ?
> KGlobal::locale()->pageSize() : ps.toInt()));
> 00066 QPaintDeviceMetrics metrics(&prt);
> 00067 float w = metrics.width();
> 00068 float h = metrics.height();
> 00069 unsigned int it, il, ib, ir;
> 00070 prt.margins( &it, &il, &ib, &ir );
> 00071 float mt = it;
> 00072 float ml = il;
> 00073 float mb = ib;
> 00074 float mr = ir;
> 00075
> 00076 if (driver() && m_usedriver )
> 00077 {
> 00078 QString pageSize(ps);
> 00079
> 00080 if (pageSize.isEmpty())
> 00081 {
> 00082 DrListOption *o =
> (DrListOption*)driver()->findOption("PageSize");
> 00083 if (o)
> 00084 pageSize = o->get("default");
> 00085 }
> 00086 if (!pageSize.isEmpty())
> 00087 {
> 00088 DrPageSize *dps = driver()->findPageSize(pageSize);
> 00089 if (dps)
> 00090 {
> 00091 w = dps->pageWidth();
> 00092 h = dps->pageHeight();
> 00093 mt = QMAX( mt, dps->topMargin() );
> 00094 ml = QMAX( ml, dps->leftMargin() );
> 00095 mb = QMAX( mb, dps->bottomMargin() );
> 00096 mr = QMAX( mr, dps->rightMargin() );
> 00097 }
> 00098 }
> 00099 }
> 00100 m_margin->setPageSize(w, h);
> 00101 m_margin->setOrientation(landscape ? KPrinter::Landscape :
> KPrinter::Portrait);
> 00102 m_margin->setDefaultMargins( mt, mb, ml, mr );
> 00103 m_margin->setCustomEnabled(false);
> 00104 }
>
> The interesting part starts at line 00093 there if I
> understand it correctly
> it will take the maximum of the settings from the ppd and the
> setting that
> come from QPrinter.
>
> However in qt-x11-free-3.3.5/src/kernel/qprinter_unix.cpp:
>
>
> /*!
> \overload
>
> Sets \a top, \a left, \a bottom and \a right to the margins of the
> printer. On Unix, this is a best-effort guess, not based on
> perfect knowledge.
>
> If you have called setFullPage( TRUE ), the four values specify
> the smallest sane margins you can use.
>
> If you have called setFullPage( FALSE ) (this is the default),
> the margins are automatically subtracted from the pageSize() by
> QPrinter.
>
> \sa setFullPage() QPaintDeviceMetrics PageSize
> */
> void QPrinter::margins( uint *top, uint *left, uint *bottom,
> uint *right )
> const
> {
> if ( !D->marginsSpecified ) {
> int x = orient == Portrait ? res/2 : res/3;
> int y = orient == Portrait ? res/3 : res/2;
> *top = *bottom = y;
> *left = *right = x;
> } else {
> *top = D->topMargin;
> *left = D->leftMargin;
> *bottom = D->bottomMargin;
> *right = D->rightMargin;
> }
> }
>
> Afaik the problem is, as D->marginsSpecified gets initialized
> to false in the
> QPrinter constructor, the guessing algorithm gets used. In my
> case the
> guessed values are larger than the ones from the ppd and in
> the end it will
> use the guessed values. Making it impossible for me to
> exactly position a
> cdlabel or whatever.
>
> The question is how to fix. Maybe simply removing the QMAXs
> would help.
> What do you think?
It's actually a *feature*. You can read the extended reasoning in that
thread: http://lists.kde.org/?t=110607853400003&r=1&w=2
The point is that an application that do not want to print on the whole
page (setFullPage(false)), expects to print with some reasonable margins
by default, even if the PPD files says it can print on the whole page.
However, you should be able to go beyond these reasonable margins by using
an application capable of printing on the whole page (setFullPage(true)),
I think KWord is one.
Michael.
More information about the kde-print
mailing list