Fix export tiled pdf on Mac OS.

This commit is contained in:
Roman Telezhynskyi 2022-08-18 17:10:42 +03:00
parent 94a2bcb005
commit 7d276461ed
6 changed files with 37 additions and 9 deletions

View File

@ -18,6 +18,7 @@
- Support for options Force Flipping and Forbid Flipping in Puzzle.
- Remember selected dimension values.
- Fix segmenting a simple curve.
- Fix export tiled pdf on Mac OS.
# Valentina 0.7.51 April 18, 2022
- Z value change for a layout piece.

View File

@ -2778,8 +2778,9 @@ auto VPMainWindow::DrawTilesScheme(QPrinter *printer, QPainter *painter, const V
target = QRectF(0, 0, width, height);
}
sheet->SceneData()->Scene()->render(painter, VPrintLayout::SceneTargetRect(printer, target), source,
Qt::KeepAspectRatio);
target = VPrintLayout::SceneTargetRect(printer, target);
sheet->SceneData()->Scene()->render(painter, target, source, Qt::KeepAspectRatio);
VWatermarkData watermarkData = m_layout->TileFactory()->WatermarkData();
if (watermarkData.opacity > 0)

View File

@ -174,6 +174,11 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
// add the tiles decorations (cutting and gluing lines, scissors, infos etc.)
painter->setPen(PenTileInfos());
painter->save();
const QPair<qreal, qreal> scale = VPrintLayout::PrinterScaleDiff(printer);
painter->scale(scale.first, scale.second);
if(row > 0)
{
// add top triangle
@ -217,7 +222,7 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
DrawSolidBottomLine(painter, col, nbCol);
}
DrawRuler(painter);
DrawRuler(painter, scale.first);
DrawWatermark(painter);
if(col < nbCol-1)
@ -235,6 +240,8 @@ void VPTileFactory::drawTile(QPainter *painter, QPrinter *printer, const VPSheet
// prepare the painting for the text information
DrawTextInformation(painter, row, col, nbRow, nbCol, sheet->GetName());
painter->restore();
}
//---------------------------------------------------------------------------------------------------------------------
@ -294,7 +301,7 @@ auto VPTileFactory::WatermarkData() const -> const VWatermarkData &
}
//---------------------------------------------------------------------------------------------------------------------
void VPTileFactory::DrawRuler(QPainter *painter) const
void VPTileFactory::DrawRuler(QPainter *painter, qreal scale) const
{
VPLayoutPtr layout = m_layout.toStrongRef();
if(layout.isNull())
@ -330,15 +337,21 @@ void VPTileFactory::DrawRuler(QPainter *painter) const
}
else
{
QString units = rulerUnits != Unit::Inch ? tr("cm", "unit") : tr("in", "unit");
painter->save();
QFont fnt = painter->font();
fnt.setPointSize(10);
const int size = qRound(10/scale);
size > 0 ? fnt.setPointSize(size) : fnt.setPointSize(10);
painter->setFont(fnt);
qreal unitsWidth = 0;
QFontMetrics fm(fnt);
QString units = rulerUnits != Unit::Inch ? tr("cm", "unit") : tr("in", "unit");
unitsWidth = TextWidth(fm, units);
painter->drawText(QPointF(step*0.5-unitsWidth*0.6,
m_drawingAreaHeight - tileStripeWidth + notchHeight+shortNotchHeight), units);
painter->restore();
}
++i;
}

View File

@ -123,7 +123,7 @@ private:
VWatermarkData m_watermarkData{};
void DrawRuler(QPainter *painter) const;
void DrawRuler(QPainter *painter, qreal scale) const;
void DrawWatermark(QPainter *painter) const;
auto PenTileInfos() const -> QPen;

View File

@ -750,7 +750,7 @@ auto VPrintLayout::ContinueIfLayoutStale(QWidget *parent) -> int
}
//---------------------------------------------------------------------------------------------------------------------
QRectF VPrintLayout::SceneTargetRect(QPrinter *printer, const QRectF &source)
auto VPrintLayout::SceneTargetRect(QPrinter *printer, const QRectF &source) -> QRectF
{
SCASSERT(printer != nullptr)
@ -769,6 +769,18 @@ QRectF VPrintLayout::SceneTargetRect(QPrinter *printer, const QRectF &source)
x = 0; y = 0;
}
QPair<qreal, qreal> scaleDiff = PrinterScaleDiff(printer);
const double xscale = scaleDiff.first;
const double yscale = scaleDiff.second;
return {x * xscale, y * yscale, source.width() * xscale, source.height() * yscale};
}
//---------------------------------------------------------------------------------------------------------------------
auto VPrintLayout::PrinterScaleDiff(QPrinter *printer) -> QPair<qreal, qreal>
{
SCASSERT(printer != nullptr)
// Here we try understand difference between printer's dpi and our.
// Get printer rect according to our dpi.
const QRectF printerPageRect(0, 0, ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm),
@ -777,5 +789,5 @@ QRectF VPrintLayout::SceneTargetRect(QPrinter *printer, const QRectF &source)
const double xscale = pageRect.width() / printerPageRect.width();
const double yscale = pageRect.height() / printerPageRect.height();
return QRectF(x * xscale, y * yscale, source.width() * xscale, source.height() * yscale);
return qMakePair(xscale, yscale);
}

View File

@ -122,6 +122,7 @@ public:
static auto ContinueIfLayoutStale(QWidget *parent) -> int;
static auto SceneTargetRect(QPrinter *printer, const QRectF &source) -> QRectF;
static auto PrinterScaleDiff(QPrinter *printer) -> QPair<qreal, qreal>;
private slots:
void PrintPages (QPrinter *printer);