Skip to content

Commit

Permalink
Fix PDF orientation for ANSI B Landscape
Browse files Browse the repository at this point in the history
- PDF exports in landscape orientation on ANSI B (Ledger) paper
  were formatted as landscape, but on portrait paper orientation.
  • Loading branch information
WandererFan authored and yorikvanhavre committed Feb 19, 2019
1 parent 7642214 commit dca9120
Show file tree
Hide file tree
Showing 2 changed files with 463 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Mod/TechDraw/Gui/MDIViewPage.cpp
Expand Up @@ -571,7 +571,12 @@ void MDIViewPage::printPdf(std::string file)
printer.setFullPage(true);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(filename);
printer.setOrientation(m_orientation);
// printer.setOrientation(m_orientation);
if (m_paperSize == QPrinter::Ledger) {
printer.setOrientation((QPrinter::Orientation) (1 - m_orientation)); //reverse 0/1
} else {
printer.setOrientation(m_orientation);
}
printer.setPaperSize(m_paperSize);
print(&printer);
}
Expand Down Expand Up @@ -728,8 +733,8 @@ QPrinter::PaperSize MDIViewPage::getPaperSize(int w, int h) const
{105, 241}, // US Common
{110, 220}, // DLE
{210, 330}, // Folio
{431.8f, 279.4f}, // Ledger
{279.4f, 431.8f} // Tabloid
{431.8f, 279.4f}, // Ledger (28) note, two names for same size paper (ANSI B)
{279.4f, 431.8f} // Tabloid (29) causes trouble with orientation on PDF export
};

QPrinter::PaperSize ps = QPrinter::Custom;
Expand All @@ -739,13 +744,19 @@ QPrinter::PaperSize MDIViewPage::getPaperSize(int w, int h) const
ps = static_cast<QPrinter::PaperSize>(i);
break;
}
else
else //handle landscape & portrait w/h
if (std::abs(paperSizes[i][0]-h) <= 1 &&
std::abs(paperSizes[i][1]-w) <= 1) {
ps = static_cast<QPrinter::PaperSize>(i);
break;
}
}
if (ps == QPrinter::Ledger) { //check if really Tabloid
if (w < 431) {
ps = QPrinter::Tabloid;
}
}

return ps;
}

Expand Down

0 comments on commit dca9120

Please sign in to comment.