Fix Svg export page & text size in HiRez
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
|
||||
#include <qmath.h>
|
||||
#include <QRectF>
|
||||
#include "Rez.h"
|
||||
#include "QGCustomLabel.h"
|
||||
|
||||
using namespace TechDrawGui;
|
||||
@@ -75,5 +76,24 @@ void QGCustomLabel::centerAt(double cX, double cY)
|
||||
void QGCustomLabel::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
|
||||
QStyleOptionGraphicsItem myOption(*option);
|
||||
myOption.state &= ~QStyle::State_Selected;
|
||||
|
||||
//see QGCustomText for explanation of this code
|
||||
double dppt = 3.53;
|
||||
double svgMagicX = Rez::guiX(8.0);
|
||||
double svgMagicY = Rez::guiX(12.0);
|
||||
double svgMagicYoffset = Rez::guiX(3.0);
|
||||
double fontSize = Rez::appX(font().pointSizeF());
|
||||
double ty = svgMagicY + (svgMagicYoffset*fontSize)/dppt;
|
||||
QPointF svgMove(-svgMagicX/dppt,ty);
|
||||
|
||||
QPaintDevice* hw = painter->device();
|
||||
QSvgGenerator* svg = dynamic_cast<QSvgGenerator*>(hw);
|
||||
if (svg) {
|
||||
painter->scale(Rez::appX(dppt),Rez::appX(dppt));
|
||||
painter->translate(svgMove);
|
||||
} else {
|
||||
painter->scale(1.0,1.0);
|
||||
}
|
||||
|
||||
QGraphicsTextItem::paint (painter, &myOption, widget);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,6 @@ private:
|
||||
|
||||
};
|
||||
|
||||
} // namespace MDIViewPageGui
|
||||
}
|
||||
|
||||
#endif // DRAWINGGUI_QGCUSTOMLABEL_H
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
|
||||
#include <qmath.h>
|
||||
#include <QRectF>
|
||||
#include "Rez.h"
|
||||
#include "QGIView.h"
|
||||
#include "QGCustomText.h"
|
||||
|
||||
@@ -124,28 +125,27 @@ void QGCustomText::paint ( QPainter * painter, const QStyleOptionGraphicsItem *
|
||||
QStyleOptionGraphicsItem myOption(*option);
|
||||
myOption.state &= ~QStyle::State_Selected;
|
||||
|
||||
//svg text is much larger than screen text. scene units(mm) vs points.
|
||||
//svg text is much larger than screen text. scene units(mm or 0.1mm in hirez) vs points.
|
||||
//need to scale text if going to svg.
|
||||
//TODO: magic translation happens? approx: right ~8mm down: 12mm + (3mm per mm of text height)
|
||||
//TODO: magic translation happens. why? approx: right ~8mm down: 12mm + (3mm per mm of text height)
|
||||
//SVG transform matrix translation values are different for same font size + different fonts (Sans vs Ubuntu vs Arial)???
|
||||
// scale values are same for same font size + different fonts.
|
||||
//double svgScale = 2.835; //72dpi/(25.4mm/in)
|
||||
//double svgScale = 3.84; //96dpi/(25mm/in)
|
||||
//double svgScale = 3.6; //90dpi/(25mm/in) more/less CSS standard?
|
||||
double svgScale = 2.88; //72dpi/(25mm/in) Qt logicalDpiY() is int
|
||||
double svgMagicX = 8.0;
|
||||
//double svgMagicY = 7.5; //idk
|
||||
double fontSize = font().pointSizeF();
|
||||
//double ty = (12.0/svgScale + 3.0*fontSize/svgScale) + (svgMagicY/svgScale);
|
||||
double ty = (12.0/svgScale + 3.0*fontSize/svgScale);
|
||||
QPointF svgMove(-svgMagicX/svgScale,-ty);
|
||||
//calculate dots/mm
|
||||
//in hirez - say factor = 10, we have 10 dpmm in scene space.
|
||||
// so 254dpi / 72pts/in => 3.53 dppt
|
||||
double dpmm = 3.53; //dots/pt
|
||||
double svgMagicX = Rez::guiX(8.0); //8mm -> 80 gui dots
|
||||
double svgMagicY = Rez::guiX(12.0);
|
||||
double svgMagicYoffset = Rez::guiX(3.0); // 3mm per mm of font size => 30gunits / mm of font size
|
||||
double fontSize = Rez::appX(font().pointSizeF()); //gui pts 4mm text * 10 scunits/mm = size 40 text but still only 4mm
|
||||
double ty = svgMagicY + (svgMagicYoffset*fontSize)/dpmm;
|
||||
// 12mm (in gunits) + [3mm (in gunits) * (# of mm)]/ [dots per mm] works out to dots?
|
||||
QPointF svgMove(-svgMagicX/dpmm,ty);
|
||||
|
||||
QPaintDevice* hw = painter->device();
|
||||
//QPaintDeviceMetrics hwm(hw);
|
||||
//QPrinter* pr = dynamic_cast<QPrinter*>(hw); //printer does not rescale vs screen?
|
||||
QSvgGenerator* svg = dynamic_cast<QSvgGenerator*>(hw);
|
||||
if (svg) {
|
||||
painter->scale(svgScale,svgScale);
|
||||
painter->scale(Rez::appX(dpmm),Rez::appX(dpmm));
|
||||
painter->translate(svgMove);
|
||||
} else {
|
||||
painter->scale(1.0,1.0);
|
||||
|
||||
@@ -116,6 +116,8 @@ void QGIViewAnnotation::draw()
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: text is position slightly high (and left??) on page save to SVG file
|
||||
|
||||
void QGIViewAnnotation::drawAnnotation()
|
||||
{
|
||||
auto viewAnno( dynamic_cast<TechDraw::DrawViewAnnotation *>(getViewObject()) );
|
||||
|
||||
@@ -506,22 +506,19 @@ void QGVPage::saveSvg(QString filename)
|
||||
docName;
|
||||
|
||||
//Base::Console().Message("TRACE - saveSVG - page width: %d height: %d\n",width,height); //A4 297x210
|
||||
|
||||
//with Rez set to 10 we make a dot 10 times/mm => 254dpi?
|
||||
// 12 => 304.8 dpi? approx printer dpi 300dpi
|
||||
|
||||
QSvgGenerator svgGen;
|
||||
svgGen.setFileName(filename);
|
||||
svgGen.setSize(QSize((int) page->getPageWidth(), (int)page->getPageHeight()));
|
||||
svgGen.setViewBox(QRect(0, 0, page->getPageWidth(), page->getPageHeight()));
|
||||
//TODO: Exported Svg file is not quite right. <svg width="301.752mm" height="213.36mm" viewBox="0 0 297 210"... A4: 297x210
|
||||
// Page too small (A4 vs Letter? margins?)
|
||||
//TODO: text in Qt is in mm (actually scene units). text in SVG is points(?). fontsize in export file is too small by 1/2.835.
|
||||
// resize all textItem before export?
|
||||
// postprocess generated file to mult all font-size attrib by 2.835 to get pts?
|
||||
// duplicate all textItems and only show the appropriate one for screen/print vs export?
|
||||
svgGen.setSize(QSize((int) Rez::guiX(page->getPageWidth()), (int) Rez::guiX(page->getPageHeight()))); //expects pixels, gets mm
|
||||
//"By default this property is set to QSize(-1, -1), which indicates that the generator should not output
|
||||
// the width and height attributes of the <svg> element." >> but Inkscape won't read it without size info??
|
||||
svgGen.setViewBox(QRect(0, 0, Rez::guiX(page->getPageWidth()), Rez::guiX(page->getPageHeight())));
|
||||
|
||||
svgGen.setResolution(Rez::guiX(25.4)); // docs say this is DPI. 1dot/mm so 25.4dpi
|
||||
|
||||
// TODO: Was svgGen.setResolution(25.4000508); // mm/inch?? docs say this is DPI //really "user space units/inch"?
|
||||
svgGen.setResolution(25); // mm/inch?? docs say this is DPI
|
||||
|
||||
//svgGen.setResolution(600); // resulting page is ~12.5x9mm
|
||||
//svgGen.setResolution(96); // page is ~78x55mm
|
||||
svgGen.setTitle(QObject::tr("FreeCAD SVG Export"));
|
||||
svgGen.setDescription(svgDescription);
|
||||
|
||||
|
||||
@@ -80,6 +80,12 @@ QPointF Rez::guiPt(QPointF p)
|
||||
return result;
|
||||
}
|
||||
|
||||
QPointF Rez::appPt(QPointF p)
|
||||
{
|
||||
QPointF result(appX(p.x()),appX(p.y()));
|
||||
return result;
|
||||
}
|
||||
|
||||
QRectF Rez::guiRect(QRectF r)
|
||||
{
|
||||
QRectF result(guiX(r.left()),
|
||||
@@ -105,7 +111,7 @@ double Rez::getParameter()
|
||||
{
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Rez");
|
||||
double rezFactor = hGrp->GetFloat("Resolution", 12.0);
|
||||
double rezFactor = hGrp->GetFloat("Resolution", 1.0);
|
||||
return rezFactor;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,10 +43,12 @@ public:
|
||||
static double guiX(double x);
|
||||
static Base::Vector2d guiX(Base::Vector2d v);
|
||||
static Base::Vector3d guiX(Base::Vector3d v);
|
||||
|
||||
//turn Gui side value to App side value
|
||||
static double appX(double x);
|
||||
|
||||
static QPointF guiPt(QPointF p);
|
||||
static QPointF appPt(QPointF p);
|
||||
|
||||
static QRectF guiRect(QRectF r);
|
||||
static QSize guiSize(QSize s);
|
||||
static QSize appSize(QSize s);
|
||||
|
||||
Reference in New Issue
Block a user