diff --git a/Pdf4QtLib/sources/pdfannotation.cpp b/Pdf4QtLib/sources/pdfannotation.cpp index 1ffcc43..6dd96ca 100644 --- a/Pdf4QtLib/sources/pdfannotation.cpp +++ b/Pdf4QtLib/sources/pdfannotation.cpp @@ -1057,7 +1057,7 @@ QPen PDFAnnotation::getPen() const { PDFLineDashPattern lineDashPattern(border.getDashPattern(), 0.0); pen.setStyle(Qt::CustomDashLine); - pen.setDashPattern(QVector(lineDashPattern.getDashArray().begin(), lineDashPattern.getDashArray().end())); + pen.setDashPattern(lineDashPattern.createForQPen(pen.widthF())); pen.setDashOffset(lineDashPattern.getDashOffset()); } diff --git a/Pdf4QtLib/sources/pdfpagecontentprocessor.cpp b/Pdf4QtLib/sources/pdfpagecontentprocessor.cpp index 1ff3c97..fd96bac 100644 --- a/Pdf4QtLib/sources/pdfpagecontentprocessor.cpp +++ b/Pdf4QtLib/sources/pdfpagecontentprocessor.cpp @@ -911,8 +911,7 @@ void PDFPageContentProcessor::processPathPainting(const QPainterPath& path, bool const PDFLineDashPattern& lineDashPattern = m_graphicState.getLineDashPattern(); if (!lineDashPattern.isSolid()) { - const auto& dashArray = lineDashPattern.getDashArray(); - stroker.setDashPattern(QVector(dashArray.begin(), dashArray.end())); + stroker.setDashPattern(lineDashPattern.createForQPen(m_graphicState.getLineWidth())); stroker.setDashOffset(lineDashPattern.getDashOffset()); } QPainterPath strokedPath = stroker.createStroke(path); @@ -959,8 +958,7 @@ void PDFPageContentProcessor::processPathPainting(const QPainterPath& path, bool const PDFLineDashPattern& lineDashPattern = m_graphicState.getLineDashPattern(); if (!lineDashPattern.isSolid()) { - const auto& dashArray = lineDashPattern.getDashArray(); - stroker.setDashPattern(QVector(dashArray.begin(), dashArray.end())); + stroker.setDashPattern(lineDashPattern.createForQPen(m_graphicState.getLineWidth())); stroker.setDashOffset(lineDashPattern.getDashOffset()); } QPainterPath strokedPath = stroker.createStroke(path); @@ -3978,6 +3976,18 @@ void PDFLineDashPattern::fix() } } +QVector PDFLineDashPattern::createForQPen(qreal penWidthF) const +{ + QVector lineDashPattern(m_dashArray.begin(), m_dashArray.end()); + + for (qreal& value : lineDashPattern) + { + value /= penWidthF; + } + + return lineDashPattern; +} + PDFPageContentProcessor::PDFSoftMaskDefinition PDFPageContentProcessor::PDFSoftMaskDefinition::parse(const PDFDictionary* softMask, PDFPageContentProcessor* processor) { PDFSoftMaskDefinition result; diff --git a/Pdf4QtLib/sources/pdfpagecontentprocessor.h b/Pdf4QtLib/sources/pdfpagecontentprocessor.h index 25ef2fd..d27aaf8 100644 --- a/Pdf4QtLib/sources/pdfpagecontentprocessor.h +++ b/Pdf4QtLib/sources/pdfpagecontentprocessor.h @@ -28,6 +28,7 @@ #include "pdftextlayout.h" #include "pdfoperationcontrol.h" +#include #include #include #include @@ -68,6 +69,11 @@ public: /// Fix line dash pattern according to the specification void fix(); + /// Create dash pattern for QPen. + /// \param penWidthF Width of the pen. + /// \note Dash pattern in QPen is in pen width units + QVector createForQPen(qreal penWidthF) const; + private: std::vector m_dashArray; PDFReal m_dashOffset = 0.0; diff --git a/Pdf4QtLib/sources/pdfpainter.cpp b/Pdf4QtLib/sources/pdfpainter.cpp index 0df75c9..dfafc48 100644 --- a/Pdf4QtLib/sources/pdfpainter.cpp +++ b/Pdf4QtLib/sources/pdfpainter.cpp @@ -136,9 +136,7 @@ QPen PDFPainterBase::getCurrentPenImpl() const else { pen.setStyle(Qt::CustomDashLine); - - const auto& dashArray = lineDashPattern.getDashArray(); - pen.setDashPattern(QVector(dashArray.begin(), dashArray.end())); + pen.setDashPattern(lineDashPattern.createForQPen(pen.widthF())); pen.setDashOffset(lineDashPattern.getDashOffset()); } diff --git a/Pdf4QtLib/sources/pdftransparencyrenderer.cpp b/Pdf4QtLib/sources/pdftransparencyrenderer.cpp index fa6ba3b..b1075c4 100644 --- a/Pdf4QtLib/sources/pdftransparencyrenderer.cpp +++ b/Pdf4QtLib/sources/pdftransparencyrenderer.cpp @@ -2187,8 +2187,7 @@ void PDFTransparencyRenderer::performPathPainting(const QPainterPath& path, bool const PDFLineDashPattern& lineDashPattern = getGraphicState()->getLineDashPattern(); if (!lineDashPattern.isSolid()) { - const auto& dashArray = lineDashPattern.getDashArray(); - stroker.setDashPattern(QVector(dashArray.begin(), dashArray.end())); + stroker.setDashPattern(lineDashPattern.createForQPen(getGraphicState()->getLineWidth())); stroker.setDashOffset(lineDashPattern.getDashOffset()); } QPainterPath strokedPath = stroker.createStroke(path);