PDA

View Full Version : Font cutted in pdf print



giusepped
9th November 2010, 15:47
To export in pdf I use the following code


void MyPlot::exportPDF()
{
QString fileName;
fileName = QFileDialog::getSaveFileName(this, tr("blabla"), recentExportPath,"Acrobat ( *pdf)");
QFileInfo fileInfo(fileName);
recentExportPath = fileInfo.absoluteDir().absolutePath();
if ( !fileName.isEmpty() ) {
fileName = MyMath::checkFormat(fileName,"pdf");
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
printer.setCreator("Test");
printer.setOrientation(QPrinter::Landscape);
print(printer);
QDesktopServices::openUrl(fileName);

}
}

but the pdf has the font on the axes cutted, as shown in the figure.5441
The same result if I print on Adobe PDF printer.
Any suggestion?

wysota
9th November 2010, 15:50
What is "MyPlot"? How do you paint the labels on the scale?

giusepped
9th November 2010, 15:59
MyPlot::MyPlot( QWidget* par ) : QwtPlot(par )
setAxisScale(QwtPlot::xBottom,-180*1.2,180*1.2);

Thanks

wysota
9th November 2010, 21:12
What if you don't put the printer into high resolution mode?

giusepped
9th November 2010, 21:35
Yes, it works,but why?
I would have not never thouht to such a thing.
Regards

wysota
9th November 2010, 21:38
Yes, it works,but why?
Probably some sizes are calculated in points and other in pixels so when the resolution changes, one size changes and the other doesn't.

giusepped
9th November 2010, 21:55
which calculation are you referring to? in my code or qt code?

wysota
9th November 2010, 22:19
In Qwt code, most likely.

giusepped
9th November 2010, 22:24
So, it sounds like to be a bug, isnt'it?
G

wysota
9th November 2010, 22:41
So, it sounds like to be a bug, isnt'it?
I don't know. I'm against suggestions that if something acts differently than what I want to achieve then it's a bug. I have not seen your code nor analyzed Qwt code so I will not make any judgements. There could be a proper call available in Qwt that would give a correct result instead of an improper call you might have used.

giusepped
9th November 2010, 23:03
Thank you for the replies.
And let me bother you a little bit more.
As engineer I always stress myself in finding the meaning of things, especially whenever I do not understand them.
In this case, I use a very classical coding, as suggested in many examples in the Qwt branch and also here in the forum.
The plot I see on screen is perfect. So I guess that the calls to Qwt's plot functions are good. The export to pdf function is very simple: just prepare a printer, a painter and call the print function of Qwtplot. That's all.
Regards

wysota
9th November 2010, 23:29
The plot I see on screen is perfect.
This is the essence here. You would like to see the plot as it is displayed on screen. That's why you should use ScreenResolution instead of HighResolution. If you use HighResolution, you get a situation different than what you see on screen. So based on what you see you can't say whether Qwt code is correct for HighResolution or not.

Uwe
10th November 2010, 07:10
This is the essence here. You would like to see the plot as it is displayed on screen. That's why you should use ScreenResolution instead of HighResolution. If you use HighResolution, you get a situation different than what you see on screen. So based on what you see you can't say whether Qwt code is correct for HighResolution or not.

Well in case of a plot widget a higher resolution is often important, when you want to identify points, that are close. And Qwt supports printing/exporting in non screen resolution since decades.

Qwt draws the tick labels using QPainter::drawText(const QRect, ...). From your posted image it looks like the calculated bounding rectangle is not correct and someone ( Qwt isn't doing it ) clips against this rectangle. The calculation of the rectangle is done using the font system of Qt - maybe there is a mismatch with the font system used by the backend of your printer paint engine.

First thing I woud try is to print to a pdf File instead of printing to the Adobe PDF printer. Then you can be sure that layout and render code use the same font system. If this doesn't help you should try a different font. Qwt 5.2 scales the fonts manually - maybe this results to something invalid and the best match algorithm of Qt ends up with a larger font.

You could also try to use Qwt 6.x. It has a floating point based render engine, and because of this all manual scaling is replaced by using QPainter scaling.

Uwe

giusepped
10th November 2010, 08:43
Thank you for the replies.
Sincerely, I do not know who and if there is something in my code doing a clipping.
The only line I can see is the simple QwtPainter::setDeviceClipping(false);
Beside x and y settings, in my code there is no other line that modifies QwtPlot's properties.
This morning, I tried also to switch off any font setting. For example, I had Times Roman for xlabel and ylabel. I turn on back HighResolution and the printing to a pdf file gave me the same font effect.
Where is Qwt 6?
G

wysota
10th November 2010, 10:22
Well in case of a plot widget a higher resolution is often important, when you want to identify points, that are close. And Qwt supports printing/exporting in non screen resolution since decades.
I didn't say you shouldn't use high resolution with plots or that Qwt didn't support it. I only say that if someone states "I want it to look exactly like on the screen" then it means ScreenResolution. And I also said that if you print in high resolution then you can't say whether the code is correct or not if you look at the results of screen resolution rendering.