From: <ai...@us...> - 2009-03-24 22:02:56
|
Revision: 9771 http://plplot.svn.sourceforge.net/plplot/?rev=9771&view=rev Author: airwin Date: 2009-03-24 22:02:46 +0000 (Tue, 24 Mar 2009) Log Message: ----------- Improve self-documentation. Distinguish between setting number of points per inch (always 72) for "points" device drivers (epsqt, pdfqt, and svgqt), and setting pixels per inch (or dots per inch) for raster devices. Raster version of setResolution changed so it has dots per inch argument similar to points per inch argument for the epsqt, pdfqt, and svgqt versions. Comment out downscale=1.; statement in QtPLDriver which must have been ignored in any case, but which confuses the casual reader of the code. Allow user to control dpi via -dpi command-line option or by using plspage. Modified Paths: -------------- trunk/drivers/qt.cpp trunk/drivers/qt.h Modified: trunk/drivers/qt.cpp =================================================================== --- trunk/drivers/qt.cpp 2009-03-24 08:20:09 UTC (rev 9770) +++ trunk/drivers/qt.cpp 2009-03-24 22:02:46 UTC (rev 9771) @@ -6,6 +6,7 @@ Imperial College, London Copyright (C) 2009 Imperial College, London + Copyright (C) 2009 Alan W. Irwin This is free software; you can redistribute it and/or modify it under the terms of the GNU General Lesser Public License as published @@ -201,7 +202,7 @@ { m_dWidth=i_iWidth; m_dHeight=i_iHeight; - downscale=1.; +// downscale=1.; // fontScalingFactor=1.; } @@ -318,7 +319,11 @@ yOffset=0.; xOffset=0.; - currentFontSize=chrht*72./25.4*1.6; + // Scaling factor of 1.6 determined empirically to make all qt results + // have the same character size as cairo results (taking into account + // the slightly different actual glyph sizes for the different + // default fonts found by cairo and qt). + currentFontSize=chrht*POINTS_PER_INCH/25.4*1.6; currentFontScale=1.; underlined=false; overlined=false; @@ -662,9 +667,6 @@ b.setStyle(Qt::SolidPattern); m_painterP->setBrush(b); m_painterP->setRenderHint(QPainter::Antialiasing, true); -// int res=DPI/25.4/downscale*1000.; -// setDotsPerMeterX(res); -// setDotsPerMeterY(res); // Let's fill the background m_painterP->fillRect(0, 0, width(), height(), QBrush(Qt::black)); @@ -701,6 +703,7 @@ void plD_init_rasterqt(PLStream * pls) { + double dpi; /* Stream setup */ pls->color = 1; pls->plbuf_write=0; @@ -716,6 +719,13 @@ initQtApp(false); + if (pls->xdpi <=0.) + dpi = DEFAULT_DPI; + else + dpi = pls->xdpi; + // For raster debug + // std::cout << dpi << std::endl; + // Shamelessly copied on the Cairo stuff :) if (pls->xlength <= 0 || pls->ylength <= 0) { @@ -735,9 +745,9 @@ plP_setphy((PLINT) 0, (PLINT) (pls->xlength / ((QtRasterDevice*)(pls->dev))->downscale), (PLINT) 0, (PLINT) (pls->ylength / ((QtRasterDevice*)(pls->dev))->downscale)); - plP_setpxl(DPI/25.4/((QtRasterDevice*)(pls->dev))->downscale, DPI/25.4/((QtRasterDevice*)(pls->dev))->downscale); + plP_setpxl(dpi/25.4/((QtRasterDevice*)(pls->dev))->downscale, dpi/25.4/((QtRasterDevice*)(pls->dev))->downscale); - ((QtRasterDevice*)(pls->dev))->setResolution(pls->xpmm); + ((QtRasterDevice*)(pls->dev))->setResolution(dpi); /* Initialize family file info */ plFamInit(pls); @@ -926,7 +936,7 @@ void QtSVGDevice::definePlotName(const char* fileName) { setFileName(QString(fileName)); - setResolution(DPI); + setResolution(POINTS_PER_INCH); setSize(QSize(m_dWidth, m_dHeight)); m_painterP=new QPainter(this); @@ -991,7 +1001,7 @@ plP_setphy((PLINT) 0, (PLINT) (pls->xlength / ((QtSVGDevice*)(pls->dev))->downscale), (PLINT) 0, (PLINT) (pls->ylength / ((QtSVGDevice*)(pls->dev))->downscale)); - plP_setpxl(DPI/25.4/((QtSVGDevice*)(pls->dev))->downscale, DPI/25.4/((QtSVGDevice*)(pls->dev))->downscale); + plP_setpxl(POINTS_PER_INCH/25.4/((QtSVGDevice*)(pls->dev))->downscale, POINTS_PER_INCH/25.4/((QtSVGDevice*)(pls->dev))->downscale); /* Initialize family file info */ plFamInit(pls); @@ -1037,7 +1047,7 @@ setFullPage(true); setPaperSize(QSizeF(i_iHeight, i_iWidth), QPrinter::Point); #endif - setResolution(DPI); + setResolution(POINTS_PER_INCH); setColorMode(QPrinter::Color); setOrientation(QPrinter::Landscape); setPrintProgram(QString("lpr")); @@ -1159,7 +1169,7 @@ plP_setphy((PLINT) 0, (PLINT) (pls->xlength / ((QtEPSDevice*)(pls->dev))->downscale), (PLINT) 0, (PLINT) (pls->ylength / ((QtEPSDevice*)(pls->dev))->downscale)); - plP_setpxl(DPI/25.4/((QtEPSDevice*)(pls->dev))->downscale, DPI/25.4/((QtEPSDevice*)(pls->dev))->downscale); + plP_setpxl(POINTS_PER_INCH/25.4/((QtEPSDevice*)(pls->dev))->downscale, POINTS_PER_INCH/25.4/((QtEPSDevice*)(pls->dev))->downscale); /* Initialize family file info */ plFamInit(pls); Modified: trunk/drivers/qt.h =================================================================== --- trunk/drivers/qt.h 2009-03-24 08:20:09 UTC (rev 9770) +++ trunk/drivers/qt.h 2009-03-24 22:02:46 UTC (rev 9771) @@ -6,6 +6,7 @@ Imperial College, London Copyright (C) 2009 Imperial College, London + Copyright (C) 2009 Alan W. Irwin This is free software; you can redistribute it and/or modify it under the terms of the GNU General Lesser Public License as published @@ -30,13 +31,25 @@ */ /* -Interpretation of the -geometry factor for the various devices: -- bmpqt, jpgqt, pngqt, ppmqt, tiffqt: - The geometry parameter defines the size in pixels +Interpretation of the -geometry XSIZExYSIZE option (or the third and fourth + parameters of plspage if those are specified by the user instead) for + the various devices: +- the raster devices (bmpqt, jpgqt, pngqt, ppmqt, tiffqt): + XSIZE and YSIZE define the x and y size in pixels +- qtwidget: + XSIZE and YSIZE define the default x and y size of the widget in + pixels, as well as its aspect ratio, which is kept when the widget is + resized. - svgqt, epsqt, pdfqt: - The geometry parameter defines the size in points (1/72 of inches). EPS and PDF files will be drawn in A4 pages for Qt versions before 4.4 -- qtwidget: - The geometry factor defines the default size of the widget, as well as its aspect ratio, which is kept when the widget is resized. + XSIZE and YSIZE define the x and y size in points (1/72 of inches). + EPS and PDF files will be drawn in A4 pages for Qt versions before 4.4 + +Interpretation of the -dpi DPI option (or the first parameter of + plspage if that is specified by the user instead). + DPI is ignored for all but the raster devices. For those devices + DPI should be set to the DPI value of the monitor being used to view + the results if exact character sizes are desired. Otherwise, DEFAULT_DPI + (set to an average value for modern monitors) is used instead. */ #ifndef QT_H @@ -58,7 +71,20 @@ #include "plplotP.h" #include "drivers.h" -#define DPI 72 +// Used for devices (epsqt, pdfqt, svgqt) with known physical size in points. +#define POINTS_PER_INCH 72 + +// Average value of dots per inch assumed for modern monitors if the user +// does not specify a value appropriate to their monitor with plspage or +// the -dpi option. Used only for devices with size specified in pixels +// but not qtwidget since it has independent access to information (e.g., +// delivered by X) about the DPI of the monitor. So this value is only +// used for the raster devices (bmpqt, jpgqt, pngqt, ppmqt, tiffqt). +#define DEFAULT_DPI 80 + +// These values are in units of pixels (the raster devices and qtwidget) +// or points (epsqt, pdfqt, svgqt). In the points case, this corresponds +// to the A4 paper size. #define QT_DEFAULT_X 842 #define QT_DEFAULT_Y 595 @@ -132,10 +158,10 @@ void savePlot(); - virtual void setResolution(double dotsPerMM) + virtual void setResolution(double dotsPerInch) { - setDotsPerMeterX(dotsPerMM*1000.*downscale); - setDotsPerMeterY(dotsPerMM*1000.*downscale); + setDotsPerMeterX((dotsPerInch/25.4)*1000.); + setDotsPerMeterY((dotsPerInch/25.4)*1000.); } protected: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |