Skip to content

Commit b432aa5

Browse files
author
yu
committed
better to resize content in proportion to source when Paper size is not same as source
1 parent 30f24db commit b432aa5

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

qt/src/hocr/HOCRPdfExporter.cc

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,16 @@ class HOCRPdfExporter::QPainterPDFPainter : public HOCRPdfExporter::PDFPainter {
7575
m_curFont.setItalic(italic);
7676
m_painter->setFont(m_curFont);
7777
}
78-
void setFontSize(double pointSize) override {
79-
if(pointSize != m_curFont.pointSize()) {
80-
m_curFont.setPointSize(pointSize);
81-
m_painter->setFont(m_curFont);
78+
void setFontSize(double pointSize, bool defaultFont = false) override {
79+
if(defaultFont) {
80+
if(pointSize != m_defaultFont.pointSize()) {
81+
m_defaultFont.setPointSize(pointSize);
82+
}
83+
} else {
84+
if(pointSize != m_curFont.pointSize()) {
85+
m_curFont.setPointSize(pointSize);
86+
m_painter->setFont(m_curFont);
87+
}
8288
}
8389
}
8490
void drawText(double x, double y, const QString& text) override {
@@ -232,8 +238,12 @@ class HOCRPdfExporter::PoDoFoPDFPainter : public HOCRPdfExporter::PDFPainter {
232238
m_painter.SetFont(getFont(family, bold, italic));
233239
m_painter.GetFont()->SetFontSize(curSize);
234240
}
235-
void setFontSize(double pointSize) override {
236-
m_painter.GetFont()->SetFontSize(pointSize);
241+
void setFontSize(double pointSize, bool defaultFont = false) override {
242+
if(defaultFont) {
243+
m_defaultFontSize = pointSize;
244+
} else {
245+
m_painter.GetFont()->SetFontSize(pointSize);
246+
}
237247
}
238248
void drawText(double x, double y, const QString& text) override {
239249
PoDoFo::PdfString pdfString(reinterpret_cast<const PoDoFo::pdf_utf8*>(text.toUtf8().data()));
@@ -512,7 +522,6 @@ bool HOCRPdfExporter::run(QString& filebasename) {
512522
}
513523
break;
514524
}
515-
516525
MAIN->getDisplayer()->scene()->removeItem(m_preview);
517526
delete m_preview;
518527
m_preview = nullptr;
@@ -560,7 +569,15 @@ bool HOCRPdfExporter::run(QString& filebasename) {
560569
// [pt] = 72 * [in]
561570
// [in] = 1 / dpi * [px]
562571
// => [pt] = 72 / dpi * [px]
563-
double px2pt = (72.0 / sourceDpi);
572+
double sourceSizeToOutSize;
573+
if( paperSize == "source") {
574+
sourceSizeToOutSize = 1;
575+
} else {
576+
sourceSizeToOutSize = pageWidth / (72.0 / sourceDpi * bbox.width());
577+
}
578+
painter->setFontSize(ui.spinBoxFontSize->value() * sourceSizeToOutSize, true);
579+
double px2pt = (72.0 / sourceDpi) * sourceSizeToOutSize;
580+
pdfSettings.detectedFontScaling *= sourceSizeToOutSize;
564581
double imgScale = double(outputDpi) / sourceDpi;
565582
if(paperSize == "source") {
566583
pageWidth = bbox.width() * px2pt;

qt/src/hocr/HOCRPdfExporter.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private:
6161
public:
6262
virtual ~PDFPainter() {}
6363
virtual void setFontFamily(const QString& family, bool bold, bool italic) = 0;
64-
virtual void setFontSize(double pointSize) = 0;
64+
virtual void setFontSize(double pointSize, bool defaultFont = false) = 0;
6565
virtual void drawText(double x, double y, const QString& text) = 0;
6666
virtual void drawImage(const QRect& bbox, const QImage& image, const PDFSettings& settings) = 0;
6767
virtual double getAverageCharWidth() const = 0;

0 commit comments

Comments
 (0)