Margins in the printer properties
Sascha Sommer
saschasommer at freenet.de
Wed Sep 28 15:02:16 CEST 2005
Thanks for the prompt reply.
On Wednesday 28 September 2005 13:28, Goffioul Michael wrote:
> > Hi,
> > what are the differences between the margin settings in the
> > text property page
> > and the margins that can be specified in the margin property page?
> > Gwenview for example will always use the later, however
> > unlike the ones from
> > the text property page, they do not seem to come from the
> > ppd. I think this
> > will be problematic when the printer requires different margins.
> > Is this the intended behaviour?
>
> The text margins are used in CUPS when plain text is sent for printing.
> In that case, CUPS converts it to PS, using the margins specified. The
> margin values are just sent as-is without processing in KDE, and the
> corresponding tab only appear in kprinter, not in the print dialog from
> a KDE application. Those margins are in no way linked to the PPD.
>
Ok.
> The other margins are the margins used within a KDE application when
> generating PS data to sent to CUPS. This means that a KDE app will get
> as printable area the selected page size reduced by those margins. The
> default values of these margins are taken from the PPD file (when
> possible).
Ok. See below:
Appologies if I'm quoting wrong versions of the sources:
From:
http://developer.kde.org/documentation/library/3.4-api/kdeprint/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?
Regards
Sascha
More information about the kde-print
mailing list