LibreOffice Module sc (master) 1
numformat.cxx
Go to the documentation of this file.
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 <numformat.hxx>
21#include <patattr.hxx>
22#include <document.hxx>
23
25#include <svl/numformat.hxx>
26#include <svl/zformat.hxx>
28#include <optional>
29
30namespace sc {
31
33{
34 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
35 sal_uInt32 nKey = rPat.GetNumberFormat(pFormatter);
36 return isLatinScript(nKey, rDoc);
37}
38
40{
41 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
42 const SvNumberformat* pFormat = pFormatter->GetEntry(nFormat);
43 if (!pFormat || !pFormat->IsStandard())
44 return false;
45
46 // The standard format is all-latin if the decimal separator doesn't
47 // have a different script type
48
49 OUString aDecSep;
50 LanguageType nFormatLang = pFormat->GetLanguage();
51 if (nFormatLang == LANGUAGE_SYSTEM)
53 else
54 {
55 // LocaleDataWrapper can be expensive to construct, so cache the result for
56 // repeated calls
57 static std::optional<LocaleDataWrapper> localeCache;
58 if (!localeCache || localeCache->getLanguageTag().getLanguageType() != nFormatLang)
59 localeCache.emplace(
61 aDecSep = localeCache->getNumDecimalSep();
62 }
63
64 SvtScriptType nScript = rDoc.GetStringScriptType(aDecSep);
65 return (nScript == SvtScriptType::NONE || nScript == SvtScriptType::LATIN);
66}
67
68}
69
70/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & getNumDecimalSep() const
SC_DLLPUBLIC SvtScriptType GetStringScriptType(const OUString &rString)
Definition: documen6.cxx:76
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:467
static SC_DLLPUBLIC const LocaleDataWrapper & getLocaleData()
Definition: global.cxx:1055
sal_uInt32 GetNumberFormat(SvNumberFormatter *) const
Definition: patattr.cxx:1398
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
LanguageType GetLanguage() const
bool IsStandard() const
static bool isLatinScript(const ScPatternAttr &rPat, ScDocument &rDoc)
Check if the attribute pattern has a number format that only produces latin script output.
Definition: numformat.cxx:32
#define LANGUAGE_SYSTEM
SvtScriptType
Reference< XComponentContext > getProcessComponentContext()
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
sal_uIntPtr sal_uLong