summaryrefslogtreecommitdiffstats
path: root/i18nutil/source/utility/paper.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'i18nutil/source/utility/paper.cxx')
-rw-r--r--i18nutil/source/utility/paper.cxx31
1 files changed, 14 insertions, 17 deletions
diff --git a/i18nutil/source/utility/paper.cxx b/i18nutil/source/utility/paper.cxx
index 97dbb2938c25..c5870d04d72b 100644
--- a/i18nutil/source/utility/paper.cxx
+++ b/i18nutil/source/utility/paper.cxx
@@ -17,10 +17,11 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+#include <o3tl/unit_conversion.hxx>
#include <officecfg/Setup.hxx>
#include <officecfg/System.hxx>
-#include <sal/config.h>
#include <sal/macros.h>
#include <rtl/ustring.hxx>
#include <rtl/string.hxx>
@@ -28,7 +29,6 @@
#include <i18nutil/paper.hxx>
-#include <cstdlib>
#include <unotools/configmgr.hxx>
#include <com/sun/star/lang/Locale.hpp>
@@ -50,17 +50,11 @@ struct PageDesc
const char *m_pAltPSName;
};
+constexpr tools::Long PT2MM100(double v) { return o3tl::convert(v, o3tl::Length::pt, o3tl::Length::mm100) + 0.5; }
+constexpr tools::Long IN2MM100(double v) { return o3tl::convert(v, o3tl::Length::in, o3tl::Length::mm100) + 0.5; }
+constexpr tools::Long MM2MM100(double v) { return o3tl::convert(v, o3tl::Length::mm, o3tl::Length::mm100) + 0.5; }
}
-#define PT2MM100( v ) \
- tools::Long(((v) * 35.27777778) + 0.5)
-
-#define IN2MM100( v ) \
- (tools::Long(((v) * 2540) + 0.5))
-
-#define MM2MM100( v ) \
- (tools::Long((v) * 100))
-
//PostScript Printer Description File Format Specification
//http://partners.adobe.com/public/developer/en/ps/5003.PPD_Spec_v4.3.pdf
//https://web.archive.org/web/20040912070512/http://www.y-adagio.com/public/committees/docsii/doc_00-49/symp_ulaan/china_ppr.pdf (Kai)
@@ -69,7 +63,7 @@ struct PageDesc
//!! The order of these entries must correspond to enum Paper in <i18nutil/paper.hxx>
// see XclPaperSize pPaperSizeTable in calc and ApiPaperSize in filter
-const PageDesc aDinTab[] =
+constexpr PageDesc aDinTab[] =
{
{ MM2MM100( 841 ), MM2MM100( 1189 ), "A0", nullptr },
{ MM2MM100( 594 ), MM2MM100( 841 ), "A1", nullptr },
@@ -166,7 +160,11 @@ const PageDesc aDinTab[] =
const size_t nTabSize = SAL_N_ELEMENTS(aDinTab);
-#define MAXSLOPPY 21
+// tdf#151107 make this not just large enough for rounding errors on our side
+// but also large enough to match where the ppd side rounded up to the next
+// point. Seen with C5/C6/C65 envelopes which can be found over 1 point away
+// from the values in aDinTab
+#define MAXSLOPPY PT2MM100(1.25)
void PaperInfo::doSloppyFit(bool bAlsoTryRotated)
{
@@ -226,7 +224,7 @@ tools::Long PaperInfo::sloppyFitPageDimension(tools::Long nDimension)
PaperInfo PaperInfo::getSystemDefaultPaper()
{
- if (utl::ConfigManager::IsFuzzing())
+ if (comphelper::IsFuzzing())
return PaperInfo(PAPER_A4);
OUString aLocaleStr = officecfg::Setup::L10N::ooSetupSystemLocale::get();
@@ -353,7 +351,7 @@ PaperInfo PaperInfo::getSystemDefaultPaper()
if (aLocaleStr.isEmpty())
aLocaleStr = officecfg::System::L10N::Locale::get();
- static const OUStringLiteral EN_US = u"en-US";
+ static constexpr OUStringLiteral EN_US = u"en-US";
if (aLocaleStr.isEmpty())
aLocaleStr = EN_US;
@@ -397,8 +395,7 @@ PaperInfo::PaperInfo(tools::Long nPaperWidth, tools::Long nPaperHeight)
OString PaperInfo::toPSName(Paper ePaper)
{
- return static_cast<size_t>(ePaper) < nTabSize ?
- OString(aDinTab[ePaper].m_pPSName) : OString();
+ return static_cast<size_t>(ePaper) < nTabSize && aDinTab[ePaper].m_pPSName ? OString(aDinTab[ePaper].m_pPSName) : OString();
}
Paper PaperInfo::fromPSName(const OString &rName)