21#include <officecfg/Setup.hxx>
22#include <officecfg/System.hxx>
25#include <rtl/ustring.hxx>
26#include <rtl/string.hxx>
32#include <com/sun/star/lang/Locale.hpp>
37#if defined(LC_PAPER) && defined(_GNU_SOURCE)
48 const char *m_pPSName;
49 const char *m_pAltPSName;
54#define PT2MM100( v ) \
55 tools::Long(((v) * 35.27777778) + 0.5)
57#define IN2MM100( v ) \
58 (tools::Long(((v) * 2540) + 0.5))
60#define MM2MM100( v ) \
61 (tools::Long((v) * 100))
84 { 0, 0,
nullptr,
nullptr },
172#define MAXSLOPPY PT2MM100(1.25)
174void PaperInfo::doSloppyFit(
bool bAlsoTryRotated)
188 m_nPaperWidth =
aDinTab[
i].m_nWidth;
189 m_nPaperHeight =
aDinTab[
i].m_nHeight;
190 m_eType =
static_cast<Paper>(
i);
197 std::swap(m_nPaperWidth, m_nPaperHeight);
199 std::swap(m_nPaperWidth, m_nPaperHeight);
203bool PaperInfo::sloppyEqual(
const PaperInfo &rOther)
const
207 (std::abs(m_nPaperWidth - rOther.m_nPaperWidth) <
MAXSLOPPY) &&
208 (std::abs(m_nPaperHeight - rOther.m_nPaperHeight) <
MAXSLOPPY)
219 lDiff = std::abs(
aDinTab[i].m_nWidth - nDimension);
223 lDiff = std::abs(
aDinTab[i].m_nHeight - nDimension);
230PaperInfo PaperInfo::getSystemDefaultPaper()
235 OUString aLocaleStr = officecfg::Setup::L10N::ooSetupSystemLocale::get();
239 if (aLocaleStr.isEmpty())
241 static bool bInitialized =
false;
247#if ! defined(MACOSX) && ! defined(EMSCRIPTEN)
250 FILE* pPipe = popen(
"paperconf 2>/dev/null",
"r" );
257 char *pBuffer = fgets( aBuffer,
sizeof(aBuffer), pPipe );
258 bool bOk = pclose(pPipe) == 0;
260 if (bOk && pBuffer && *pBuffer != 0)
262 OString aPaper(pBuffer);
263 aPaper = aPaper.trim();
264 static const struct {
const char *
pName;
Paper ePaper; } aCustoms [] =
285 for (
size_t i = 0;
i < nExtraTabSize; ++
i)
287 if (rtl_str_compareIgnoreAsciiCase(aCustoms[i].pName, aPaper.getStr()) == 0)
289 ePaper = aCustoms[
i].ePaper;
296 bHalve = aPaper.startsWith(
"half", &aPaper);
297 ePaper = PaperInfo::fromPSName(aPaper);
304 aInstance =
PaperInfo(aInstance.getHeight()/2, aInstance.getWidth());
313#if defined(LC_PAPER) && defined(_GNU_SOURCE) && !defined(ANDROID)
315 locale_t loc = newlocale(LC_PAPER_MASK,
"",
static_cast<locale_t
>(0));
316 if (loc !=
static_cast<locale_t
>(0))
318 union paperword {
char *string;
int word; };
320 w.string = nl_langinfo_l(_NL_PAPER_WIDTH, loc);
321 h.string = nl_langinfo_l(_NL_PAPER_HEIGHT, loc);
339 if (width ==
w.word/100 && height ==
h.word/100)
356 if (aLocaleStr.isEmpty())
357 aLocaleStr = officecfg::System::L10N::Locale::get();
359 static constexpr OUStringLiteral EN_US =
u"en-US";
360 if (aLocaleStr.isEmpty())
364 css::lang::Locale aSysLocale;
365 sal_Int32 nDashPos = aLocaleStr.indexOf(
'-' );
366 if( nDashPos < 0 ) nDashPos = aLocaleStr.getLength();
367 aSysLocale.Language = aLocaleStr.copy( 0, nDashPos );
368 if( nDashPos + 1 < aLocaleStr.getLength() )
369 aSysLocale.Country = aLocaleStr.copy( nDashPos + 1 );
371 return PaperInfo::getDefaultPaperForLocale(aSysLocale);
377 "mismatch between array entries and enum values" );
385 m_nPaperWidth(nPaperWidth),
386 m_nPaperHeight(nPaperHeight)
391 (nPaperWidth ==
aDinTab[i].m_nWidth) &&
392 (nPaperHeight ==
aDinTab[i].m_nHeight)
401OString PaperInfo::toPSName(
Paper ePaper)
403 return static_cast<size_t>(ePaper) <
nTabSize ?
404 OString(
aDinTab[ePaper].m_pPSName) : OString();
407Paper PaperInfo::fromPSName(
const OString &rName)
415 !rtl_str_compareIgnoreAsciiCase(
aDinTab[i].m_pPSName, rName.getStr()))
417 return static_cast<Paper>(
i);
419 else if (
aDinTab[i].m_pAltPSName &&
420 !rtl_str_compareIgnoreAsciiCase(
aDinTab[i].m_pAltPSName, rName.getStr()))
422 return static_cast<Paper>(
i);
434PaperInfo PaperInfo::getDefaultPaperForLocale(
const css::lang::Locale & rLocale )
440 rLocale.Country ==
"US" ||
444 rLocale.Country ==
"PR" ||
447 rLocale.Country ==
"CA" ||
451 rLocale.Country ==
"VE" ||
455 rLocale.Country ==
"CL" ||
459 rLocale.Country ==
"MX" ||
463 rLocale.Country ==
"CO" ||
468 rLocale.Country ==
"PH" ||
472 rLocale.Country ==
"BZ" ||
476 rLocale.Country ==
"CR" ||
480 rLocale.Country ==
"GT" ||
483 rLocale.Country ==
"NI" ||
487 rLocale.Country ==
"PA" ||
491 rLocale.Country ==
"SV"
const EnumerationType m_eType
#define SAL_N_ELEMENTS(arr)
const PageDesc aDinTab[]
! The order of these entries must correspond to enum Paper in <i18nutil/paper.hxx>
Paper
! The values of the following enumerators must correspond to the array position ! of the respective p...
#define NUM_PAPER_ENTRIES
std::unique_ptr< char[]> aBuffer