Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/i18nutil/source/utility/paper.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <sal/config.h>
21
22
#include <iterator>
23
24
#include <o3tl/unit_conversion.hxx>
25
#include <o3tl/string_view.hxx>
26
#include <officecfg/Setup.hxx>
27
#include <officecfg/System.hxx>
28
#include <rtl/ustring.hxx>
29
#include <rtl/string.hxx>
30
#include <tools/long.hxx>
31
32
#include <i18nutil/paper.hxx>
33
34
#include <unotools/configmgr.hxx>
35
#include <com/sun/star/lang/Locale.hpp>
36
37
#ifdef UNX
38
#include <stdio.h>
39
#include <locale.h>
40
#if defined(LC_PAPER) && defined(_GNU_SOURCE)
41
#include <langinfo.h>
42
#endif
43
#endif
44
45
namespace {
46
47
struct PageDesc
48
{
49
    tools::Long m_nWidth;
50
    tools::Long m_nHeight;
51
    const char *m_pPSName;
52
    const char *m_pAltPSName;
53
};
54
55
0
constexpr tools::Long PT2MM100(double v) { return o3tl::convert(v, o3tl::Length::pt, o3tl::Length::mm100) + 0.5; }
56
0
constexpr tools::Long IN2MM100(double v) { return o3tl::convert(v, o3tl::Length::in, o3tl::Length::mm100) + 0.5; }
57
0
constexpr tools::Long MM2MM100(double v) { return o3tl::convert(v, o3tl::Length::mm, o3tl::Length::mm100) + 0.5; }
58
}
59
60
//PostScript Printer Description File Format Specification
61
//http://partners.adobe.com/public/developer/en/ps/5003.PPD_Spec_v4.3.pdf
62
//https://web.archive.org/web/20040912070512/http://www.y-adagio.com/public/committees/docsii/doc_00-49/symp_ulaan/china_ppr.pdf (Kai)
63
//http://www.sls.psi.ch/controls/help/howto/Howto_Print_a_A0_Poster_at_WSLA_012_2.pdf (Dia)
64
65
//!! The order of these entries must correspond to enum Paper in <i18nutil/paper.hxx>
66
67
// see XclPaperSize pPaperSizeTable in calc and ApiPaperSize in filter
68
constexpr PageDesc aDinTab[] =
69
{
70
    { MM2MM100( 841 ),   MM2MM100( 1189 ),   "A0",  nullptr },
71
    { MM2MM100( 594 ),   MM2MM100( 841 ),    "A1",  nullptr },
72
    { MM2MM100( 420 ),   MM2MM100( 594 ),    "A2",  nullptr },
73
    { MM2MM100( 297 ),   MM2MM100( 420 ),    "A3",  nullptr },
74
    { MM2MM100( 210 ),   MM2MM100( 297 ),    "A4",  nullptr },
75
    { MM2MM100( 148 ),   MM2MM100( 210 ),    "A5",  nullptr },
76
    { MM2MM100( 250 ),   MM2MM100( 353 ),    "ISOB4",  nullptr },
77
    { MM2MM100( 176 ),   MM2MM100( 250 ),    "ISOB5",  nullptr },
78
    { IN2MM100( 8.5 ),   IN2MM100( 11 ),     "Letter",  "Note" },
79
    { IN2MM100( 8.5 ),   IN2MM100( 14 ),     "Legal",  nullptr },
80
    { IN2MM100( 11 ),    IN2MM100( 17 ),     "Tabloid",  "11x17" },
81
    { 0,                 0,                  nullptr, nullptr }, //User
82
    { MM2MM100( 125 ),   MM2MM100( 176 ),    "ISOB6",  nullptr },
83
    { MM2MM100( 229 ),   MM2MM100( 324 ),    "EnvC4",  "C4" },
84
    { MM2MM100( 162 ),   MM2MM100( 229 ),    "EnvC5",  "C5" },
85
    { MM2MM100( 114 ),   MM2MM100( 162 ),    "EnvC6",  "C6" },
86
    { MM2MM100( 114 ),   MM2MM100( 229 ),    "EnvC65", nullptr },
87
    { MM2MM100( 110 ),   MM2MM100( 220 ),    "EnvDL",  "DL" },
88
    { MM2MM100( 180),    MM2MM100( 270 ),    nullptr,  nullptr }, //Dia
89
    { MM2MM100( 210),    MM2MM100( 280 ),    nullptr,  nullptr }, //Screen 4:3
90
    { IN2MM100( 17 ),    IN2MM100( 22 ),     "AnsiC",  "CSheet" },
91
    { IN2MM100( 22 ),    IN2MM100( 34 ),     "AnsiD",  "DSheet" },
92
    { IN2MM100( 34 ),    IN2MM100( 44 ),     "AnsiE",  "ESheet" },
93
    { IN2MM100( 7.25 ),  IN2MM100( 10.5 ),   "Executive",  nullptr },
94
    //"Folio" is a different size in the PPD documentation than 8.5x11
95
    //This "FanFoldGermanLegal" is known in the Philippines as
96
    //"Legal" paper or "Long Bond Paper".  The "Legal" name causing untold
97
    //misery, given the differently sized US "Legal" paper
98
    { IN2MM100( 8.5 ),   IN2MM100( 13 ),     "FanFoldGermanLegal",  nullptr },
99
    { IN2MM100( 3.875 ), IN2MM100( 7.5 ),    "EnvMonarch", "Monarch" },
100
    { IN2MM100( 3.625 ), IN2MM100( 6.5 ),    "EnvPersonal",  "Personal" },
101
    { IN2MM100( 3.875 ), IN2MM100( 8.875 ),  "Env9",  nullptr },
102
    { IN2MM100( 4.125 ), IN2MM100( 9.5 ),    "Env10",  "Comm10" },
103
    { IN2MM100( 4.5 ),   IN2MM100( 10.375 ), "Env11",  nullptr },
104
    { IN2MM100( 4.75 ),  IN2MM100( 11 ),     "Env12",  nullptr },
105
    { MM2MM100( 184 ),   MM2MM100( 260 ),    nullptr,  nullptr }, //Kai16 / 16k
106
    { MM2MM100( 130 ),   MM2MM100( 184 ),    nullptr,  nullptr }, //Kai32
107
    { MM2MM100( 140 ),   MM2MM100( 203 ),    nullptr,  nullptr }, //BigKai32
108
    { MM2MM100( 257 ),   MM2MM100( 364 ),    "B4",  nullptr }, //JIS
109
    { MM2MM100( 182 ),   MM2MM100( 257 ),    "B5",  nullptr }, //JIS
110
    { MM2MM100( 128 ),   MM2MM100( 182 ),    "B6",  nullptr }, //JIS
111
    { IN2MM100( 17 ),    IN2MM100( 11 ),     "Ledger",  nullptr },
112
    { IN2MM100( 5.5 ),   IN2MM100( 8.5 ),    "Statement",  nullptr },
113
    { PT2MM100( 610 ),   PT2MM100( 780 ),    "Quarto",  nullptr },
114
    { IN2MM100( 10 ),    IN2MM100( 14 ),     "10x14",  nullptr },
115
    { IN2MM100( 5.5 ),   IN2MM100( 11.5 ),   "Env14",  nullptr },
116
    { MM2MM100( 324 ),   MM2MM100( 458 ),    "EnvC3",  "C3" },
117
    { MM2MM100( 110 ),   MM2MM100( 230 ),    "EnvItalian",  nullptr },
118
    { IN2MM100( 14.875 ),IN2MM100( 11 ),     "FanFoldUS",  nullptr },
119
    { IN2MM100( 8.5 ),   IN2MM100( 13 ),     "FanFoldGerman",  nullptr },
120
    { MM2MM100( 100 ),   MM2MM100( 148 ),    "Postcard",  nullptr },
121
    { IN2MM100( 9 ),     IN2MM100( 11 ),     "9x11",  nullptr },
122
    { IN2MM100( 10 ),    IN2MM100( 11 ),     "10x11",  nullptr },
123
    { IN2MM100( 15 ),    IN2MM100( 11 ),     "15x11",  nullptr },
124
    { MM2MM100( 220 ),   MM2MM100( 220 ),    "EnvInvite",  nullptr },
125
    { MM2MM100( 227 ),   MM2MM100( 356 ),    "SuperA",  nullptr },
126
    { MM2MM100( 305 ),   MM2MM100( 487 ),    "SuperB",  nullptr },
127
    { IN2MM100( 8.5 ),   IN2MM100( 12.69 ),  "LetterPlus",  nullptr },
128
    { MM2MM100( 210 ),   MM2MM100( 330 ),    "A4Plus",  nullptr },
129
    { MM2MM100( 200 ),   MM2MM100( 148 ),    "DoublePostcard",  nullptr },
130
    { MM2MM100( 105 ),   MM2MM100( 148 ),    "A6",  nullptr },
131
    { IN2MM100( 12 ),    IN2MM100( 11 ),     "12x11",  nullptr },
132
    { MM2MM100( 74 ),    MM2MM100( 105 ),    "A7",  nullptr },
133
    { MM2MM100( 52 ),    MM2MM100( 74 ),     "A8",  nullptr },
134
    { MM2MM100( 37 ),    MM2MM100( 52 ),     "A9",  nullptr },
135
    { MM2MM100( 26 ),    MM2MM100( 37 ),     "A10",  nullptr },
136
    { MM2MM100( 1000 ),  MM2MM100( 1414 ),   "ISOB0",  nullptr },
137
    { MM2MM100( 707 ),   MM2MM100( 1000 ),   "ISOB1",  nullptr },
138
    { MM2MM100( 500 ),   MM2MM100( 707 ),    "ISOB2",  nullptr },
139
    { MM2MM100( 353 ),   MM2MM100( 500 ),    "ISOB3",  nullptr },
140
    { MM2MM100( 88 ),    MM2MM100( 125 ),    "ISOB7",  nullptr },
141
    { MM2MM100( 62 ),    MM2MM100( 88 ),     "ISOB8",  nullptr },
142
    { MM2MM100( 44 ),    MM2MM100( 62 ),     "ISOB9",  nullptr },
143
    { MM2MM100( 31 ),    MM2MM100( 44 ),     "ISOB10", nullptr },
144
    { MM2MM100( 458 ),   MM2MM100( 648 ),    "EnvC2",  "C2" },
145
    { MM2MM100( 81 ),    MM2MM100( 114 ),    "EnvC7",  "C7" },
146
    { MM2MM100( 57 ),    MM2MM100( 81 ),     "EnvC8",  "C8" },
147
    { IN2MM100( 9 ),     IN2MM100( 12 ),     "ARCHA",  nullptr },
148
    { IN2MM100( 12 ),    IN2MM100( 18 ),     "ARCHB",  nullptr },
149
    { IN2MM100( 18 ),    IN2MM100( 24 ),     "ARCHC",  nullptr },
150
    { IN2MM100( 24 ),    IN2MM100( 36 ),     "ARCHD",  nullptr },
151
    { IN2MM100( 36 ),    IN2MM100( 48 ),     "ARCHE",  nullptr },
152
    { MM2MM100( 157.5),  MM2MM100( 280 ),    nullptr,  nullptr }, //Screen 16:9
153
    { MM2MM100( 175 ),   MM2MM100( 280 ),    nullptr,  nullptr }, //Screen 16:10
154
    { MM2MM100( 195 ),   MM2MM100( 270 ),    nullptr,  nullptr }, // 16k
155
    { MM2MM100( 197 ),   MM2MM100( 273 ),    nullptr,  nullptr }, // 16k
156
    { IN2MM100( 7.5 ),   IN2MM100( 13.333 ), nullptr,  nullptr }, //PowerPoint Widescreen
157
    { IN2MM100( 7.5 ),   IN2MM100( 10 ),     nullptr,  nullptr }, //PowerPoint On-screen Show (4:3)
158
    { IN2MM100( 5.625 ), IN2MM100( 10 ),     nullptr,  nullptr }, //PowerPoint On-screen Show (16:9)
159
    { IN2MM100( 6.25 ),  IN2MM100( 10 ),     nullptr,  nullptr }  //PowerPoint On-screen Show (16:10)
160
161
};
162
163
const size_t nTabSize = std::size(aDinTab);
164
165
// tdf#151107 make this not just large enough for rounding errors on our side
166
// but also large enough to match where the ppd side rounded up to the next
167
// point. Seen with C5/C6/C65 envelopes which can be found over 1 point away
168
// from the values in aDinTab
169
constexpr auto MAXSLOPPY = PT2MM100(1.25);
170
171
void PaperInfo::doSloppyFit(bool bAlsoTryRotated)
172
0
{
173
0
    if (m_eType != PAPER_USER)
174
0
        return;
175
176
0
    for ( size_t i = 0; i < nTabSize; ++i )
177
0
    {
178
0
        if (i == PAPER_USER) continue;
179
180
0
        tools::Long lDiffW = std::abs(aDinTab[i].m_nWidth - m_nPaperWidth);
181
0
        tools::Long lDiffH = std::abs(aDinTab[i].m_nHeight - m_nPaperHeight);
182
183
0
        if (lDiffW < MAXSLOPPY && lDiffH < MAXSLOPPY)
184
0
        {
185
0
            m_nPaperWidth = aDinTab[i].m_nWidth;
186
0
            m_nPaperHeight = aDinTab[i].m_nHeight;
187
0
            m_eType = static_cast<Paper>(i);
188
0
            return;
189
0
        }
190
0
    }
191
192
0
    if (bAlsoTryRotated)
193
0
    {
194
0
        std::swap(m_nPaperWidth, m_nPaperHeight);
195
0
        doSloppyFit();
196
0
        std::swap(m_nPaperWidth, m_nPaperHeight);
197
0
    }
198
0
}
199
200
bool PaperInfo::sloppyEqual(const PaperInfo &rOther) const
201
0
{
202
0
    return
203
0
    (
204
0
      (std::abs(m_nPaperWidth - rOther.m_nPaperWidth) < MAXSLOPPY) &&
205
0
      (std::abs(m_nPaperHeight - rOther.m_nPaperHeight) < MAXSLOPPY)
206
0
    );
207
0
}
208
209
tools::Long PaperInfo::sloppyFitPageDimension(tools::Long nDimension)
210
85.6k
{
211
2.00M
    for ( size_t i = 0; i < nTabSize; ++i )
212
1.98M
    {
213
1.98M
        if (i == PAPER_USER) continue;
214
1.96M
        tools::Long lDiff;
215
216
1.96M
        lDiff = std::abs(aDinTab[i].m_nWidth - nDimension);
217
1.96M
        if ( lDiff < MAXSLOPPY )
218
45.2k
            return aDinTab[i].m_nWidth;
219
220
1.92M
        lDiff = std::abs(aDinTab[i].m_nHeight - nDimension);
221
1.92M
        if ( lDiff < MAXSLOPPY )
222
23.9k
            return aDinTab[i].m_nHeight;
223
1.92M
    }
224
16.4k
    return nDimension;
225
85.6k
}
226
227
PaperInfo PaperInfo::getSystemDefaultPaper()
228
197k
{
229
197k
    if (comphelper::IsFuzzing())
230
197k
        return PaperInfo(PAPER_A4);
231
232
0
    OUString aLocaleStr = officecfg::Setup::L10N::ooSetupSystemLocale::get();
233
234
0
#ifdef UNX
235
    // if set to "use system", get papersize from system
236
0
    if (aLocaleStr.isEmpty())
237
0
    {
238
0
        static bool bInitialized = false;
239
0
        static PaperInfo aInstance(PAPER_A4);
240
241
0
        if (bInitialized)
242
0
            return aInstance;
243
244
0
#if ! defined(MACOSX) && ! defined(__EMSCRIPTEN__)
245
        // try libpaper
246
        // #i78617# workaround missing paperconf command
247
0
        FILE* pPipe = popen( "paperconf 2>/dev/null", "r" );
248
0
        if( pPipe )
249
0
        {
250
0
            Paper ePaper = PAPER_USER;
251
252
0
            char aBuffer[ 1024 ];
253
0
            aBuffer[0] = 0;
254
0
            char *pBuffer = fgets( aBuffer, sizeof(aBuffer), pPipe );
255
0
            bool bOk = pclose(pPipe) == 0;
256
257
0
            if (bOk && pBuffer && *pBuffer != 0)
258
0
            {
259
0
                std::string_view aPaper(pBuffer);
260
0
                aPaper = o3tl::trim(aPaper);
261
0
                static constexpr struct { std::string_view aName; Paper ePaper; } aCustoms [] =
262
0
                {
263
0
                    { "B0",   PAPER_B0_ISO },
264
0
                    { "B1",   PAPER_B1_ISO },
265
0
                    { "B2",   PAPER_B2_ISO },
266
0
                    { "B3",   PAPER_B3_ISO },
267
0
                    { "B4",   PAPER_B4_ISO },
268
0
                    { "B5",   PAPER_B5_ISO },
269
0
                    { "B6",   PAPER_B6_ISO },
270
0
                    { "B7",   PAPER_B7_ISO },
271
0
                    { "B8",   PAPER_B8_ISO },
272
0
                    { "B9",   PAPER_B9_ISO },
273
0
                    { "B10",  PAPER_B10_ISO },
274
0
                    { "folio", PAPER_FANFOLD_LEGAL_DE },
275
0
                    { "flsa",  PAPER_FANFOLD_LEGAL_DE },
276
0
                    { "flse",  PAPER_FANFOLD_LEGAL_DE }
277
0
                };
278
279
0
                bool bHalve = false;
280
281
0
                size_t const nExtraTabSize = std::size(aCustoms);
282
0
                for (size_t i = 0; i < nExtraTabSize; ++i)
283
0
                {
284
0
                    if (o3tl::equalsIgnoreAsciiCase(aCustoms[i].aName, aPaper))
285
0
                    {
286
0
                        ePaper = aCustoms[i].ePaper;
287
0
                        break;
288
0
                    }
289
0
                }
290
291
0
                if (ePaper == PAPER_USER)
292
0
                {
293
0
                    bHalve = o3tl::starts_with(aPaper, "half", &aPaper);
294
0
                    ePaper = PaperInfo::fromPSName(aPaper);
295
0
                }
296
297
0
                if (ePaper != PAPER_USER)
298
0
                {
299
0
                    aInstance = PaperInfo(ePaper);
300
0
                    if (bHalve)
301
0
                        aInstance = PaperInfo(aInstance.getHeight()/2, aInstance.getWidth());
302
0
                    bInitialized = true;
303
0
                    return aInstance;
304
0
                }
305
0
            }
306
0
        }
307
0
#endif
308
309
// _NL_PAPER_WIDTH / HEIGHT not available with android unified headers
310
0
#if defined(LC_PAPER) && defined(_GNU_SOURCE) && !defined(ANDROID)
311
        // try LC_PAPER
312
0
        locale_t loc = newlocale(LC_PAPER_MASK, "", static_cast<locale_t>(0));
313
0
        if (loc != static_cast<locale_t>(0))
314
0
        {
315
0
            union paperword { char *string; int word; };
316
0
            paperword w, h;
317
0
            w.string = nl_langinfo_l(_NL_PAPER_WIDTH, loc);
318
0
            h.string = nl_langinfo_l(_NL_PAPER_HEIGHT, loc);
319
320
0
            freelocale(loc);
321
322
            //glibc stores sizes as integer mm units
323
0
            tools::Long nPaperWidth = w.word * 100;
324
0
            tools::Long nPaperHeight = h.word * 100;
325
326
0
            for ( size_t i = 0; i < nTabSize; ++i )
327
0
            {
328
0
                if (i == PAPER_USER) continue;
329
330
                //glibc stores sizes as integer mm units, and so is inaccurate.
331
                //To find a standard paper size we calculate the standard paper
332
                //sizes into equally inaccurate mm and compare
333
0
                tools::Long width = o3tl::convert(aDinTab[i].m_nWidth, o3tl::Length::mm100, o3tl::Length::mm);
334
0
                tools::Long height = o3tl::convert(aDinTab[i].m_nHeight, o3tl::Length::mm100, o3tl::Length::mm);
335
336
0
                if (width == w.word && height == h.word)
337
0
                {
338
0
                    nPaperWidth = aDinTab[i].m_nWidth;
339
0
                    nPaperHeight = aDinTab[i].m_nHeight;
340
0
                    break;
341
0
                }
342
0
            }
343
344
0
            aInstance = PaperInfo(nPaperWidth, nPaperHeight);
345
0
            bInitialized = true;
346
0
            return aInstance;
347
0
        }
348
0
#endif
349
0
    }
350
0
#endif
351
352
    // if set to "use system", try to get locale from system
353
0
    if (aLocaleStr.isEmpty())
354
0
        aLocaleStr = officecfg::System::L10N::Locale::get();
355
356
0
    static constexpr OUStringLiteral EN_US = u"en-US";
357
0
    if (aLocaleStr.isEmpty())
358
0
        aLocaleStr = EN_US;
359
360
    // convert locale string to locale struct
361
0
    css::lang::Locale aSysLocale;
362
0
    sal_Int32 nDashPos = aLocaleStr.indexOf( '-' );
363
0
    if( nDashPos < 0 ) nDashPos = aLocaleStr.getLength();
364
0
    aSysLocale.Language = aLocaleStr.copy( 0, nDashPos );
365
0
    if( nDashPos + 1 < aLocaleStr.getLength() )
366
0
        aSysLocale.Country = aLocaleStr.copy( nDashPos + 1 );
367
368
0
    return PaperInfo::getDefaultPaperForLocale(aSysLocale);
369
0
}
370
371
319k
PaperInfo::PaperInfo(Paper eType) : m_eType(eType)
372
319k
{
373
319k
    static_assert( std::size(aDinTab) == NUM_PAPER_ENTRIES,
374
319k
            "mismatch between array entries and enum values" );
375
376
319k
    m_nPaperWidth = aDinTab[m_eType].m_nWidth;
377
319k
    m_nPaperHeight = aDinTab[m_eType].m_nHeight;
378
319k
}
379
380
PaperInfo::PaperInfo(tools::Long nPaperWidth, tools::Long nPaperHeight, bool bAlsoTryRotated)
381
0
    : m_eType(PAPER_USER),
382
0
      m_nPaperWidth(nPaperWidth),
383
0
      m_nPaperHeight(nPaperHeight)
384
0
{
385
0
    for ( size_t i = 0; i < nTabSize; ++i )
386
0
    {
387
0
        if (nPaperWidth == aDinTab[i].m_nWidth && nPaperHeight == aDinTab[i].m_nHeight)
388
0
        {
389
0
            m_eType = static_cast<Paper>(i);
390
0
            return;
391
0
        }
392
0
    }
393
0
    if (!bAlsoTryRotated)
394
0
        return;
395
    // Only check rotated dimensions after completing the normal pass, because there are pairs like
396
    // Tabloid (11x17) / Ledger (17x11) in aDinTab
397
0
    for ( size_t i = 0; i < nTabSize; ++i )
398
0
    {
399
0
        if (nPaperHeight == aDinTab[i].m_nWidth && nPaperWidth == aDinTab[i].m_nHeight)
400
0
        {
401
0
            m_eType = static_cast<Paper>(i);
402
0
            return;
403
0
        }
404
0
    }
405
0
}
406
407
OString PaperInfo::toPSName(Paper ePaper)
408
0
{
409
0
    return static_cast<size_t>(ePaper) < nTabSize && aDinTab[ePaper].m_pPSName ?  OString(aDinTab[ePaper].m_pPSName) : OString();
410
0
}
411
412
Paper PaperInfo::fromPSName(std::string_view rName)
413
0
{
414
0
    if (rName.empty())
415
0
        return PAPER_USER;
416
417
0
    for ( size_t i = 0; i < nTabSize; ++i )
418
0
    {
419
0
        if (aDinTab[i].m_pPSName &&
420
0
          o3tl::equalsIgnoreAsciiCase(aDinTab[i].m_pPSName, rName))
421
0
        {
422
0
            return static_cast<Paper>(i);
423
0
        }
424
0
        else if (aDinTab[i].m_pAltPSName &&
425
0
          o3tl::equalsIgnoreAsciiCase(aDinTab[i].m_pAltPSName, rName))
426
0
        {
427
0
            return static_cast<Paper>(i);
428
0
        }
429
0
    }
430
431
0
    return PAPER_USER;
432
0
}
433
434
//http://wiki.openoffice.org/wiki/DefaultPaperSize
435
//http://www.unicode.org/cldr/data/charts/supplemental/territory_language_information.html
436
//http://sourceware.org/git/?p=glibc.git;a=tree;f=localedata/locales
437
//http://en.wikipedia.org/wiki/Paper_size
438
//http://msdn.microsoft.com/en-us/library/cc195164.aspx
439
PaperInfo PaperInfo::getDefaultPaperForLocale( const css::lang::Locale & rLocale )
440
0
{
441
0
    Paper eType = PAPER_A4;
442
443
0
    if (
444
        //United States, Letter
445
0
        rLocale.Country == "US" ||
446
        //Puerto Rico:
447
        //    http://unicode.org/cldr/trac/ticket/1710
448
        //    http://sources.redhat.com/ml/libc-hacker/2001-07/msg00046.html
449
0
        rLocale.Country == "PR" ||
450
        //Canada:
451
        //    http://sources.redhat.com/ml/libc-hacker/2001-07/msg00053.html
452
0
        rLocale.Country == "CA" ||
453
        //Venuzuela:
454
        //    http://unicode.org/cldr/trac/ticket/1710
455
        //    https://www.redhat.com/archives/fedora-devel-list/2008-August/msg00019.html
456
0
        rLocale.Country == "VE" ||
457
        //Chile:
458
        //    http://unicode.org/cldr/trac/ticket/1710
459
        //    https://www.redhat.com/archives/fedora-devel-list/2008-August/msg00240.html
460
0
        rLocale.Country == "CL" ||
461
        //Mexico:
462
        //    http://unicode.org/cldr/trac/ticket/1710
463
        //    http://qa.openoffice.org/issues/show_bug.cgi?id=49739
464
0
        rLocale.Country == "MX" ||
465
        //Colombia:
466
        //    http://unicode.org/cldr/trac/ticket/1710
467
        //    http://qa.openoffice.org/issues/show_bug.cgi?id=69703
468
0
        rLocale.Country == "CO" ||
469
        //Philippines:
470
        //    http://unicode.org/cldr/trac/ticket/1710
471
        //    http://ubuntuliving.blogspot.com/2008/07/default-paper-size-in-evince.html
472
        //    http://www.gov.ph/faqs/driverslicense.asp
473
0
        rLocale.Country == "PH" ||
474
        //Belize:
475
        //    http://unicode.org/cldr/trac/ticket/2585
476
        //    http://www.belize.gov.bz/ct.asp?xItem=1666&ctNode=486&mp=27
477
0
        rLocale.Country == "BZ" ||
478
        //Costa Rica:
479
        //    http://unicode.org/cldr/trac/ticket/2585
480
        //    http://sources.redhat.com/bugzilla/show_bug.cgi?id=11258
481
0
        rLocale.Country == "CR" ||
482
        //Guatemala:
483
        //    http://unicode.org/cldr/trac/ticket/2585
484
        //    http://sources.redhat.com/bugzilla/show_bug.cgi?id=10936
485
0
        rLocale.Country == "GT" ||
486
        //Nicaragua:
487
        //    http://unicode.org/cldr/trac/ticket/2585
488
0
        rLocale.Country == "NI" ||
489
        //Panama:
490
        //    http://unicode.org/cldr/trac/ticket/2585
491
        //    http://www.minsa.gob.pa/minsa/tl_files/documents/baner_informativo/INSTRUMENTO%20DE%20INVESTIGACION%20DE%20RAAV%202009.pdf
492
0
        rLocale.Country == "PA" ||
493
        //El Salvador:
494
        //    http://unicode.org/cldr/trac/ticket/2585
495
        //    http://www.tse.gob.sv
496
0
        rLocale.Country == "SV"
497
0
       )
498
0
    {
499
0
        eType = PAPER_LETTER;
500
0
    }
501
502
0
    return eType;
503
0
}
504
505
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */