diff options
Diffstat (limited to 'i18nutil')
-rw-r--r-- | i18nutil/source/utility/paper.cxx | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/i18nutil/source/utility/paper.cxx b/i18nutil/source/utility/paper.cxx index 09440f46be6d..3a6e98a28d4f 100644 --- a/i18nutil/source/utility/paper.cxx +++ b/i18nutil/source/utility/paper.cxx @@ -290,39 +290,43 @@ PaperInfo PaperInfo::getSystemDefaultPaper() } #if defined(LC_PAPER) && defined(_GNU_SOURCE) - - union paperword { char *string; int word; }; - // try LC_PAPER - paperword w, h; - w.string = nl_langinfo(_NL_PAPER_WIDTH); - h.string = nl_langinfo(_NL_PAPER_HEIGHT); - - //glibc stores sizes as integer mm units - w.word *= 100; - h.word *= 100; - - for ( size_t i = 0; i < nTabSize; ++i ) + locale_t loc = newlocale(LC_PAPER_MASK, "", static_cast<locale_t>(0)); + if (loc != static_cast<locale_t>(0)) { - if (i == PAPER_USER) continue; + union paperword { char *string; int word; }; + paperword w, h; + w.string = nl_langinfo_l(_NL_PAPER_WIDTH, loc); + h.string = nl_langinfo_l(_NL_PAPER_HEIGHT, loc); + + freelocale(loc); - //glibc stores sizes as integer mm units, and so is inaccurate. To - //find a standard paper size we calculate the standard paper sizes - //into equally inaccurate mm and compare - long width = (aDinTab[i].m_nWidth + 50) / 100; - long height = (aDinTab[i].m_nHeight + 50) / 100; + //glibc stores sizes as integer mm units + w.word *= 100; + h.word *= 100; - if (width == w.word/100 && height == h.word/100) + for ( size_t i = 0; i < nTabSize; ++i ) { - w.word = aDinTab[i].m_nWidth; - h.word = aDinTab[i].m_nHeight; - break; + if (i == PAPER_USER) continue; + + //glibc stores sizes as integer mm units, and so is inaccurate. + //To find a standard paper size we calculate the standard paper + //sizes into equally inaccurate mm and compare + long width = (aDinTab[i].m_nWidth + 50) / 100; + long height = (aDinTab[i].m_nHeight + 50) / 100; + + if (width == w.word/100 && height == h.word/100) + { + w.word = aDinTab[i].m_nWidth; + h.word = aDinTab[i].m_nHeight; + break; + } } - } - aInstance = PaperInfo(w.word, h.word); - bInitialized = true; - return aInstance; + aInstance = PaperInfo(w.word, h.word); + bInitialized = true; + return aInstance; + } #endif } #endif |