7#include "pdfvectorpicture_p.h"
15constexpr inline const auto RenderDPI = 150.0;
22 std::vector<PdfVectorPicture::PathStroke> strokes;
29PdfVectorPicture::PdfVectorPicture()
30 : d(new PdfVectorPicturePrivate)
34PdfVectorPicture::PdfVectorPicture(
const PdfVectorPicture&) =
default;
35PdfVectorPicture::~PdfVectorPicture() =
default;
36PdfVectorPicture& PdfVectorPicture::operator=(
const PdfVectorPicture&) =
default;
38bool PdfVectorPicture::isNull()
const
40 return d->strokes.empty();
43void PdfVectorPicture::setStrokes(std::vector<PdfVectorPicture::PathStroke> &&strokes)
46 d->strokes = std::move(strokes);
48 d->boundingRect =
QRectF();
56void PdfVectorPicture::setTransform(
const QTransform &t)
62QRectF PdfVectorPicture::boundingRect()
const
64 if (d->strokes.empty()) {
68 if (d->boundingRect.isEmpty()) {
69 double maxPenWidth = 0.0;
70 for (
const auto &stroke : d->strokes) {
71 d->boundingRect = d->boundingRect.united(stroke.path.boundingRect());
72 maxPenWidth = std::max(maxPenWidth, stroke.pen.widthF());
75 d->boundingRect.adjust(-maxPenWidth, -maxPenWidth, maxPenWidth, maxPenWidth);
78 return d->boundingRect;
81int PdfVectorPicture::pathElementsCount()
const
84 for (
const auto &stroke : d->strokes) {
85 c += stroke.path.elementCount();
90static double scaleFromTransform(
QTransform t,
bool *shouldFlip =
nullptr)
95 qDebug() <<
"non-90° rotation, likely not a barcode";
100 if (std::abs(std::abs(t.
m11()) - std::abs(t.
m22())) < 0.1) {
101 if (shouldFlip && t.
m22() < 0) {
104 return std::max(std::abs(t.
m11()), std::abs(t.
m22()));
106 qDebug() <<
"asymmetric scale not supported yet" << t;
110QImage PdfVectorPicture::renderToImage()
const
112 if (d->image.isNull()) {
113 bool shouldFlip =
false;
114 const double scale = (RenderDPI / 72.0) * scaleFromTransform(d->transform, &shouldFlip);
115 const int width = std::ceil(boundingRect().width() * scale);
116 const int height = std::ceil(boundingRect().height() * scale);
121 p.translate(0.0, height);
122 p.scale(scale, -scale);
124 p.scale(scale, scale);
126 for (
const auto &stroke : d->strokes) {
128 p.strokePath(stroke.path.translated(-boundingRect().x(), -boundingRect().y()), stroke.pen);
130 p.fillPath(stroke.path.translated(-boundingRect().x(), -boundingRect().y()), stroke.brush);
138int PdfVectorPicture::sourceWidth()
const
141 return boundingRect().
width() * (RenderDPI / 72.0);
144int PdfVectorPicture::sourceHeight()
const
147 return boundingRect().height() * (RenderDPI / 72.0);
150int PdfVectorPicture::width()
const
152 return boundingRect().width() * scaleFromTransform(d->transform);
155int PdfVectorPicture::height()
const
157 return boundingRect().height() * scaleFromTransform(d->transform);
Classes for reservation/travel data models, data extraction and data augmentation.