Skip to content

Commit

Permalink
better to resize content in proportion to source when Paper size is n…
Browse files Browse the repository at this point in the history
…ot same as source
  • Loading branch information
yu committed Jun 25, 2018
1 parent 30f24db commit b432aa5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
33 changes: 25 additions & 8 deletions qt/src/hocr/HOCRPdfExporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ class HOCRPdfExporter::QPainterPDFPainter : public HOCRPdfExporter::PDFPainter {
m_curFont.setItalic(italic);
m_painter->setFont(m_curFont);
}
void setFontSize(double pointSize) override {
if(pointSize != m_curFont.pointSize()) {
m_curFont.setPointSize(pointSize);
m_painter->setFont(m_curFont);
void setFontSize(double pointSize, bool defaultFont = false) override {
if(defaultFont) {
if(pointSize != m_defaultFont.pointSize()) {
m_defaultFont.setPointSize(pointSize);
}
} else {
if(pointSize != m_curFont.pointSize()) {
m_curFont.setPointSize(pointSize);
m_painter->setFont(m_curFont);
}
}
}
void drawText(double x, double y, const QString& text) override {
Expand Down Expand Up @@ -232,8 +238,12 @@ class HOCRPdfExporter::PoDoFoPDFPainter : public HOCRPdfExporter::PDFPainter {
m_painter.SetFont(getFont(family, bold, italic));
m_painter.GetFont()->SetFontSize(curSize);
}
void setFontSize(double pointSize) override {
m_painter.GetFont()->SetFontSize(pointSize);
void setFontSize(double pointSize, bool defaultFont = false) override {
if(defaultFont) {
m_defaultFontSize = pointSize;
} else {
m_painter.GetFont()->SetFontSize(pointSize);
}
}
void drawText(double x, double y, const QString& text) override {
PoDoFo::PdfString pdfString(reinterpret_cast<const PoDoFo::pdf_utf8*>(text.toUtf8().data()));
Expand Down Expand Up @@ -512,7 +522,6 @@ bool HOCRPdfExporter::run(QString& filebasename) {
}
break;
}

MAIN->getDisplayer()->scene()->removeItem(m_preview);
delete m_preview;
m_preview = nullptr;
Expand Down Expand Up @@ -560,7 +569,15 @@ bool HOCRPdfExporter::run(QString& filebasename) {
// [pt] = 72 * [in]
// [in] = 1 / dpi * [px]
// => [pt] = 72 / dpi * [px]
double px2pt = (72.0 / sourceDpi);
double sourceSizeToOutSize;
if( paperSize == "source") {
sourceSizeToOutSize = 1;
} else {
sourceSizeToOutSize = pageWidth / (72.0 / sourceDpi * bbox.width());
}
painter->setFontSize(ui.spinBoxFontSize->value() * sourceSizeToOutSize, true);
double px2pt = (72.0 / sourceDpi) * sourceSizeToOutSize;
pdfSettings.detectedFontScaling *= sourceSizeToOutSize;
double imgScale = double(outputDpi) / sourceDpi;
if(paperSize == "source") {
pageWidth = bbox.width() * px2pt;
Expand Down
2 changes: 1 addition & 1 deletion qt/src/hocr/HOCRPdfExporter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private:
public:
virtual ~PDFPainter() {}
virtual void setFontFamily(const QString& family, bool bold, bool italic) = 0;
virtual void setFontSize(double pointSize) = 0;
virtual void setFontSize(double pointSize, bool defaultFont = false) = 0;
virtual void drawText(double x, double y, const QString& text) = 0;
virtual void drawImage(const QRect& bbox, const QImage& image, const PDFSettings& settings) = 0;
virtual double getAverageCharWidth() const = 0;
Expand Down

0 comments on commit b432aa5

Please sign in to comment.