[Kde-print-devel] PageSize versus kde-pagesize

Albert Astals Cid aacid at kde.org
Wed May 9 23:20:13 CEST 2007


A Dimarts 08 Maig 2007, Cristian Tibirna va escriure:
> On 7 May 2007 14:56, Albert Astals Cid wrote:
> > Hi, in kpdf we need to know the paper size because we create our own PS
> > and need to know the size so we can write it to the file.
> >
> > Currently i'm using this code
> >
> > QString ps = printer.option("PageSize");
> >
> > if (ps.find(QRegExp("w\\d+h\\d+")) == 0)
> > {
> >     // size not supported by Qt, KPrinter gives us the size as
> > wWIDTHhHEIGHT // remove the w
> >     ps = ps.mid(1);
> >     int hPos = ps.find("h");
> >     paperWidth = ps.left(hPos).toInt();
> >     paperHeight = ps.mid(hPos+1).toInt();
> > }
> > else
> > {
> >     // size is supported by Qt, we get either the pageSize name or
> > nothing because the default pageSize is used
> >     QPrinter dummy(QPrinter::PrinterResolution);
> >     dummy.setFullPage(true);
> >     dummy.setPageSize((QPrinter::PageSize)(ps.isEmpty() ?
> > KGlobal::locale()->pageSize() : pageNameToPageSize(ps)));
> >
> >     QPaintDeviceMetrics metrics(&dummy);
> >     paperWidth = metrics.width();
> >     paperHeight = metrics.height();
> > }
> >
> > This has been always working for me when printing to a printer, but when,
> > for example printing to a PS file i never get the "PageSize" but
> > a "kde-pagesize".
> >
> > Now a user is also getting "kde-pagesize" when printing to a printer
> > resulting in wrong printouts.
> >
> > So can someone give some light on how PageSize and kde-pagesize work and
> > if i should be using any other way to get the paper size?
>
> I'm afraid I don't have the original knowledge behind the design of this
> issue inside KDEPrint.
>
> From what the code shows, you can also use KPrinter::pageSize() to fetch
> the current size.
>
> "kde-pagesize" is a printer property that is artificially created by
> KDEPrint when the printer's PPD driver doesn't report a "PageSize" option
> of its own.
>
> The "PageSize" option should be checked first, then, if it doesn't
> exist, "kde-pagesize" is checked. Using KPrinter::pageSize somehow
> implements this logic for you, if you need.
>
> I don't know about the "w[0-9]*h[0-9]*" format in the PageSize option, that
> you check for.
>
> I would need 1-2h of code reading in order to become more helpful than
> this, and I unfortunately don't have this time right now (leaving for work
> in 10 minutes).
>
> Hope this helps at least a bit.

Thanks using KPrinter::pageSize worked :-)

Albert


More information about the Kde-print-devel mailing list