Fix Svg export page & text size in HiRez

This commit is contained in:
WandererFan
2017-01-02 13:02:48 -05:00
parent 9822e30224
commit 34a044b969
7 changed files with 58 additions and 31 deletions

View File

@@ -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);