From 3a9c974fd5fc9335d9e063e1a76ec0e2cec9d1be Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 16 Feb 2012 17:31:31 +0000 Subject: [PATCH] Handy function for setting the size of the drawing in mm and correct management of label printing --- wrap/qt/PolyToQImage.cpp | 11 +++++++---- wrap/qt/PolyToQImage.h | 31 ++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/wrap/qt/PolyToQImage.cpp b/wrap/qt/PolyToQImage.cpp index 7ecd377d..1deee27c 100644 --- a/wrap/qt/PolyToQImage.cpp +++ b/wrap/qt/PolyToQImage.cpp @@ -285,7 +285,7 @@ void PolyDumper::dumpPolySetPNG(const char * imageName, painter.resetTransform(); 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(); img.save(imageName); @@ -302,8 +302,11 @@ void PolyDumper::dumpPolySetSVG(const char * imageName, { assert(polyVecVec.size() == trVec.size()); + ///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); QSvgGenerator svg; svg.setFileName(imageName); @@ -311,7 +314,7 @@ void PolyDumper::dumpPolySetSVG(const char * imageName, ///SET THE DRAWING SIZE svg.setSize(QSize(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 QPainter painter; @@ -364,7 +367,7 @@ void PolyDumper::dumpPolySetSVG(const char * imageName, painter.setFont(qf); painter.resetTransform(); 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(); } diff --git a/wrap/qt/PolyToQImage.h b/wrap/qt/PolyToQImage.h index ba00b23c..69eb2657 100644 --- a/wrap/qt/PolyToQImage.h +++ b/wrap/qt/PolyToQImage.h @@ -13,28 +13,41 @@ class PolyDumperParam { public: - ///the backgrround color + /// the backgrround color vcg::Color4b backgroundColor; - ///true if the polygons must be filled with color + /// true if the polygons must be filled with color bool fill; - ///true if the filling color is random + /// true if the filling color is random 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; - - ///dimension of the image (in PNG are pixels, while in SV is the workspace in points) + /// The size of the font. If zero (default) it is automatically chosen. + int fontSize; + /// dimension of the image (in PNG are pixels, while in SVG is the workspace in points) int width; int height; - ///DPi resolution, used only for SVG + + /// DPI resolution, used only for SVG 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() { backgroundColor = vcg::Color4b::Gray; width=1024; height=1024; dpi=72; + fontSize=0; fill=false; randomColor=true; FillColor=vcg::Color4b(0,0,0,255);