Handy function for setting the size of the drawing in mm and correct management of label printing

This commit is contained in:
Paolo Cignoni 2012-02-16 17:31:31 +00:00
parent 01453b8b0e
commit 3a9c974fd5
2 changed files with 29 additions and 13 deletions

View File

@ -285,7 +285,7 @@ void PolyDumper::dumpPolySetPNG(const char * imageName,
painter.resetTransform(); painter.resetTransform();
painter.translate(trVec[i].tra[0],trVec[i].tra[1]); painter.translate(trVec[i].tra[0],trVec[i].tra[1]);
painter.drawText(bc[0]-radius,bc[1]-radius,radius*2,radius*2,Qt::AlignHCenter|Qt::AlignCenter,QString("ii")); painter.drawText(bc[0]-radius,bc[1]-radius,radius*2,radius*2,Qt::AlignHCenter|Qt::AlignCenter,QString(labelVec[i].c_str()));
} }
painter.end(); painter.end();
img.save(imageName); img.save(imageName);
@ -302,8 +302,11 @@ void PolyDumper::dumpPolySetSVG(const char * imageName,
{ {
assert(polyVecVec.size() == trVec.size()); assert(polyVecVec.size() == trVec.size());
///SET THE FONT ///SET THE FONT
int fontSize=ceil(std::max(pp.width,pp.height)/100.0); int fontSize;
if(pp.fontSize==0) fontSize=ceil(std::max(pp.width,pp.height)/100.0);
else fontSize=pp.fontSize;
QFont qf("courier",fontSize); QFont qf("courier",fontSize);
QSvgGenerator svg; QSvgGenerator svg;
svg.setFileName(imageName); svg.setFileName(imageName);
@ -311,7 +314,7 @@ void PolyDumper::dumpPolySetSVG(const char * imageName,
///SET THE DRAWING SIZE ///SET THE DRAWING SIZE
svg.setSize(QSize(pp.width,pp.height)); svg.setSize(QSize(pp.width,pp.height));
svg.setViewBox(QRect(0, 0, pp.width,pp.height)); svg.setViewBox(QRect(0, 0, pp.width,pp.height));
svg.setResolution(pp.dpi);// svg.setResolution(int(pp.dpi));//
///SETUP OF DRAWING PROCEDURE ///SETUP OF DRAWING PROCEDURE
QPainter painter; QPainter painter;
@ -364,7 +367,7 @@ void PolyDumper::dumpPolySetSVG(const char * imageName,
painter.setFont(qf); painter.setFont(qf);
painter.resetTransform(); painter.resetTransform();
painter.translate(trVec[i].tra[0],trVec[i].tra[1]); painter.translate(trVec[i].tra[0],trVec[i].tra[1]);
painter.drawText(bc[0]-radius,bc[1]-radius,radius*2,radius*2,Qt::AlignHCenter|Qt::AlignCenter,QString("ii")); painter.drawText(bc[0]-radius,bc[1]-radius,radius*2,radius*2,Qt::AlignHCenter|Qt::AlignCenter,QString(labelVec[i].c_str()));
} }
painter.end(); painter.end();
} }

View File

@ -13,28 +13,41 @@
class PolyDumperParam class PolyDumperParam
{ {
public: public:
///the backgrround color /// the backgrround color
vcg::Color4b backgroundColor; vcg::Color4b backgroundColor;
///true if the polygons must be filled with color /// true if the polygons must be filled with color
bool fill; bool fill;
///true if the filling color is random /// true if the filling color is random
bool randomColor; bool randomColor;
///the filling color of polygons, used only if randomColor==false /// the filling color of polygons, used only if randomColor==false
vcg::Color4b FillColor; vcg::Color4b FillColor;
/// The size of the font. If zero (default) it is automatically chosen.
///dimension of the image (in PNG are pixels, while in SV is the workspace in points) int fontSize;
/// dimension of the image (in PNG are pixels, while in SVG is the workspace in points)
int width; int width;
int height; int height;
///DPi resolution, used only for SVG
/// DPI resolution, used only for SVG
int dpi; int dpi;
///default contructor ///Handy function for setting the size of the drawing
void SetSVGDimInMm(float widthMM,float heightMM,float _dpi=72)
{
dpi=_dpi;
float widthInch = float(widthMM / 25.4f);
float heightInch = float(heightMM / 25.4f);
width = widthInch * _dpi;
height = heightInch * _dpi;
}
///default constructor
PolyDumperParam() PolyDumperParam()
{ {
backgroundColor = vcg::Color4b::Gray; backgroundColor = vcg::Color4b::Gray;
width=1024; width=1024;
height=1024; height=1024;
dpi=72; dpi=72;
fontSize=0;
fill=false; fill=false;
randomColor=true; randomColor=true;
FillColor=vcg::Color4b(0,0,0,255); FillColor=vcg::Color4b(0,0,0,255);