[Libreoffice-commits] core.git: emfio/source filter/source include/unotools unotools/Library_utl.mk unotools/source writerfilter/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Mon Apr 27 07:39:01 UTC 2020
emfio/source/reader/mtftools.cxx | 19 +-------------
filter/source/graphicfilter/idxf/dxfreprd.cxx | 24 +++---------------
include/unotools/defaultencoding.hxx | 31 ++++++++++++++++++++++++
unotools/Library_utl.mk | 1
unotools/source/misc/defaultencoding.cxx | 27 ++++++++++++++++++++
writerfilter/source/rtftok/rtfdispatchvalue.cxx | 19 +++-----------
6 files changed, 70 insertions(+), 51 deletions(-)
New commits:
commit e6df5847379a97ad2de95a3c01cb11380c56e0f7
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Mon Apr 27 08:02:53 2020 +0300
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Mon Apr 27 09:38:27 2020 +0200
Extract getting default locale for filters into separate unotools function
Change-Id: Ic97b1a4507d5629963f360147ecc20eb10f5d391
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92957
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index 01c091be598c..06b0f813588d 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -34,9 +34,8 @@
#include <osl/diagnose.h>
#include <vcl/virdev.hxx>
#include <o3tl/safeint.hxx>
-#include <officecfg/Setup.hxx>
-#include <officecfg/Office/Linguistic.hxx>
#include <unotools/configmgr.hxx>
+#include <unotools/defaultencoding.hxx>
#include <unotools/wincodepage.hxx>
#if OSL_DEBUG_LEVEL > 1
@@ -164,20 +163,6 @@ namespace emfio
bClosed = true;
}
- namespace {
-
- OUString getLODefaultLanguage()
- {
- if (utl::ConfigManager::IsFuzzing())
- return "en-US";
- OUString result(officecfg::Office::Linguistic::General::DefaultLocale::get());
- if (result.isEmpty())
- result = officecfg::Setup::L10N::ooSetupSystemLocale::get();
- return result;
- }
-
- }
-
WinMtfFontStyle::WinMtfFontStyle( LOGFONTW const & rFont )
{
rtl_TextEncoding eCharSet;
@@ -185,7 +170,7 @@ namespace emfio
|| (rFont.alfFaceName == "MT Extra"))
eCharSet = RTL_TEXTENCODING_SYMBOL;
else if ((rFont.lfCharSet == DEFAULT_CHARSET) || (rFont.lfCharSet == OEM_CHARSET))
- eCharSet = utl_getWinTextEncodingFromLangStr(getLODefaultLanguage(),
+ eCharSet = utl_getWinTextEncodingFromLangStr(utl_getLocaleForGlobalDefaultEncoding(),
rFont.lfCharSet == OEM_CHARSET);
else
eCharSet = rtl_getTextEncodingFromWindowsCharset( rFont.lfCharSet );
diff --git a/filter/source/graphicfilter/idxf/dxfreprd.cxx b/filter/source/graphicfilter/idxf/dxfreprd.cxx
index 8e4c9bc73560..e20e407cc013 100644
--- a/filter/source/graphicfilter/idxf/dxfreprd.cxx
+++ b/filter/source/graphicfilter/idxf/dxfreprd.cxx
@@ -20,8 +20,7 @@
#include "dxfreprd.hxx"
#include <osl/nlsupport.h>
-#include <officecfg/Setup.hxx>
-#include <officecfg/Office/Linguistic.hxx>
+#include <unotools/defaultencoding.hxx>
#include <unotools/wincodepage.hxx>
#include <unotools/configmgr.hxx>
@@ -134,21 +133,6 @@ DXFRepresentation::~DXFRepresentation()
{
}
-namespace {
-
-OUString getLODefaultLanguage()
-{
- if (utl::ConfigManager::IsFuzzing())
- return "en-US";
-
- OUString result(officecfg::Office::Linguistic::General::DefaultLocale::get());
- if (result.isEmpty())
- result = officecfg::Setup::L10N::ooSetupSystemLocale::get();
- return result;
-}
-
-}
-
rtl_TextEncoding DXFRepresentation::getTextEncoding() const
{
return (isTextEncodingSet()) ?
@@ -229,7 +213,8 @@ void DXFRepresentation::ReadHeader(DXFGroupReader & rDGR)
// only if the encoding is not set yet
// e.g. by previous $DWGCODEPAGE
if (!isTextEncodingSet())
- setTextEncoding(utl_getWinTextEncodingFromLangStr(getLODefaultLanguage(), true));
+ setTextEncoding(utl_getWinTextEncodingFromLangStr(
+ utl_getLocaleForGlobalDefaultEncoding(), true));
}
else if (rDGR.GetS() >= "AC1021")
setTextEncoding(RTL_TEXTENCODING_UTF8);
@@ -239,7 +224,8 @@ void DXFRepresentation::ReadHeader(DXFGroupReader & rDGR)
// only if the encoding is not set yet
// e.g. by previous $DWGCODEPAGE
if (!isTextEncodingSet())
- setTextEncoding(utl_getWinTextEncodingFromLangStr(getLODefaultLanguage()));
+ setTextEncoding(utl_getWinTextEncodingFromLangStr(
+ utl_getLocaleForGlobalDefaultEncoding()));
}
}
else if (rDGR.GetS() == "$DWGCODEPAGE")
diff --git a/include/unotools/defaultencoding.hxx b/include/unotools/defaultencoding.hxx
new file mode 100644
index 000000000000..8cde4bccbe04
--- /dev/null
+++ b/include/unotools/defaultencoding.hxx
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_UNOTOOLS_DEFAULTENCODING_HXX
+#define INCLUDED_UNOTOOLS_DEFAULTENCODING_HXX
+
+#include <sal/config.h>
+
+#include <unotools/unotoolsdllapi.h>
+#include <rtl/ustring.hxx>
+
+/** Determines which locale should be used by default in filters when importing non-unicode strings.
+This value should be used when the file does not explicitly define encoding of 8-bit strings. It is
+defined by officecfg::Office::Linguistic::General::DefaultLocale, or when it's not set,
+officecfg::Setup::L10N::ooSetupSystemLocale, and is typically mapped to a corresponding Windows
+codepage by filters.
+
+ at return
+A BCP-47 language tag string.
+*/
+UNOTOOLS_DLLPUBLIC OUString utl_getLocaleForGlobalDefaultEncoding();
+
+#endif // INCLUDED_UNOTOOLS_DEFAULTENCODING_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotools/Library_utl.mk b/unotools/Library_utl.mk
index e36d291db0f0..b7c06cbf4a7f 100644
--- a/unotools/Library_utl.mk
+++ b/unotools/Library_utl.mk
@@ -100,6 +100,7 @@ $(eval $(call gb_Library_add_exception_objects,utl,\
unotools/source/i18n/transliterationwrapper \
unotools/source/misc/closeveto \
unotools/source/misc/datetime \
+ unotools/source/misc/defaultencoding \
unotools/source/misc/desktopterminationobserver \
unotools/source/misc/eventlisteneradapter \
unotools/source/misc/fontcvt \
diff --git a/unotools/source/misc/defaultencoding.cxx b/unotools/source/misc/defaultencoding.cxx
new file mode 100644
index 000000000000..b0e473d099bd
--- /dev/null
+++ b/unotools/source/misc/defaultencoding.cxx
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include <unotools/configmgr.hxx>
+#include <unotools/defaultencoding.hxx>
+#include <officecfg/Office/Linguistic.hxx>
+#include <officecfg/Setup.hxx>
+
+OUString utl_getLocaleForGlobalDefaultEncoding()
+{
+ if (utl::ConfigManager::IsFuzzing())
+ return "en-US";
+ OUString result(officecfg::Office::Linguistic::General::DefaultLocale::get());
+ if (result.isEmpty())
+ result = officecfg::Setup::L10N::ooSetupSystemLocale::get();
+ return result;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
index e847e58f0797..227fba3c24fa 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -26,23 +26,11 @@
#include "rtfreferenceproperties.hxx"
#include "rtfskipdestination.hxx"
-#include <officecfg/Setup.hxx>
-#include <officecfg/Office/Linguistic.hxx>
+#include <unotools/defaultencoding.hxx>
#include <unotools/wincodepage.hxx>
using namespace com::sun::star;
-namespace
-{
-OUString getLODefaultLanguage()
-{
- OUString result(::officecfg::Office::Linguistic::General::DefaultLocale::get());
- if (result.isEmpty())
- result = ::officecfg::Setup::L10N::ooSetupSystemLocale::get();
- return result;
-}
-}
-
namespace writerfilter
{
static int getNumberFormat(int nParam)
@@ -841,8 +829,9 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
case RTF_CPG:
{
rtl_TextEncoding nEncoding
- = (nParam == 0) ? utl_getWinTextEncodingFromLangStr(getLODefaultLanguage())
- : rtl_getTextEncodingFromWindowsCodePage(nParam);
+ = (nParam == 0)
+ ? utl_getWinTextEncodingFromLangStr(utl_getLocaleForGlobalDefaultEncoding())
+ : rtl_getTextEncodingFromWindowsCodePage(nParam);
if (nKeyword == RTF_ANSICPG)
m_aDefaultState.setCurrentEncoding(nEncoding);
else
More information about the Libreoffice-commits
mailing list