LibreOffice Module svl (master) 1
asiancfg.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 <sal/config.h>
21
22#include <cassert>
23
24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/container/ElementExistException.hpp>
26#include <com/sun/star/container/NoSuchElementException.hpp>
27#include <com/sun/star/container/XNameAccess.hpp>
28#include <com/sun/star/container/XNameContainer.hpp>
29#include <com/sun/star/lang/Locale.hpp>
30#include <com/sun/star/lang/XSingleServiceFactory.hpp>
31#include <com/sun/star/uno/Any.hxx>
32#include <com/sun/star/uno/Reference.hxx>
33#include <com/sun/star/uno/Sequence.hxx>
36#include <officecfg/Office/Common.hxx>
37#include <rtl/ustring.hxx>
38#include <sal/log.hxx>
39#include <sal/types.h>
41#include <svl/asiancfg.hxx>
42
43namespace {
44
45OUString toString(css::lang::Locale const & locale) {
46 SAL_WARN_IF( locale.Language.indexOf('-') != -1, "svl",
47 "Locale language \"" << locale.Language << "\" contains \"-\"");
48 SAL_WARN_IF( locale.Country.indexOf('-') != -1, "svl",
49 "Locale country \"" << locale.Country << "\" contains \"-\"");
50 return LanguageTag::convertToBcp47( locale, false);
51}
52
53}
54
57 batch(comphelper::ConfigurationChanges::create())
58 {}
59
60 Impl(const Impl&) = delete;
61 Impl& operator=(const Impl&) = delete;
62
63 std::shared_ptr< comphelper::ConfigurationChanges > batch;
64};
65
67
69
71 impl_->batch->commit();
72}
73
75 return
76 officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::get();
77}
78
80 officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::set(
81 value, impl_->batch);
82}
83
85 return static_cast<CharCompressType>(officecfg::Office::Common::AsianLayout::CompressCharacterDistance::get());
86}
87
89 officecfg::Office::Common::AsianLayout::CompressCharacterDistance::set(
90 static_cast<sal_uInt16>(value), impl_->batch);
91}
92
93css::uno::Sequence< css::lang::Locale > SvxAsianConfig::GetStartEndCharLocales()
94 const
95{
96 const css::uno::Sequence< OUString > ns(
97 officecfg::Office::Common::AsianLayout::StartEndCharacters::get()->
98 getElementNames());
99 css::uno::Sequence< css::lang::Locale > ls(ns.getLength());
100 std::transform(ns.begin(), ns.end(), ls.getArray(),
101 [](const OUString& rName) -> css::lang::Locale {
102 return LanguageTag::convertToLocale( rName, false); });
103 return ls;
104}
105
107 css::lang::Locale const & locale, OUString & startChars,
108 OUString & endChars) const
109{
110 css::uno::Reference< css::container::XNameAccess > set(
111 officecfg::Office::Common::AsianLayout::StartEndCharacters::get());
112 css::uno::Any v;
113 try {
114 v = set->getByName(toString(locale));
115 } catch (css::container::NoSuchElementException &) {
116 return false;
117 }
118 css::uno::Reference< css::beans::XPropertySet > el(
119 v.get< css::uno::Reference< css::beans::XPropertySet > >(),
120 css::uno::UNO_SET_THROW);
121 startChars = el->getPropertyValue("StartCharacters").get< OUString >();
122 endChars = el->getPropertyValue("EndCharacters").get< OUString >();
123 return true;
124}
125
127 css::lang::Locale const & locale, OUString const * startChars,
128 OUString const * endChars)
129{
130 assert((startChars == nullptr) == (endChars == nullptr));
131 css::uno::Reference< css::container::XNameContainer > set(
132 officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
133 impl_->batch));
134 OUString name(toString(locale));
135 if (startChars == nullptr) {
136 try {
137 set->removeByName(name);
138 } catch (css::container::NoSuchElementException &) {}
139 } else {
140 bool found;
141 css::uno::Any v;
142 try {
143 v = set->getByName(name);
144 found = true;
145 } catch (css::container::NoSuchElementException &) {
146 found = false;
147 }
148 if (found) {
149 css::uno::Reference< css::beans::XPropertySet > el(
150 v.get< css::uno::Reference< css::beans::XPropertySet > >(),
151 css::uno::UNO_SET_THROW);
152 el->setPropertyValue("StartCharacters", css::uno::Any(*startChars));
153 el->setPropertyValue("EndCharacters", css::uno::Any(*endChars));
154 } else {
155 css::uno::Reference< css::beans::XPropertySet > el(
156 (css::uno::Reference< css::lang::XSingleServiceFactory >(
157 set, css::uno::UNO_QUERY_THROW)->
159 css::uno::UNO_QUERY_THROW);
160 el->setPropertyValue("StartCharacters", css::uno::Any(*startChars));
161 el->setPropertyValue("EndCharacters", css::uno::Any(*endChars));
162 css::uno::Any v2(el);
163 try {
164 set->insertByName(name, v2);
165 } catch (css::container::ElementExistException &) {
166 SAL_INFO("svl", "Concurrent update race for \"" << name << '"');
167 }
168 }
169 }
170}
171
172/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
CharCompressType
These constants define character compression in Asian text.
Definition: asiancfg.hxx:36
static OUString convertToBcp47(LanguageType nLangID)
void Commit()
Definition: asiancfg.cxx:70
CharCompressType GetCharDistanceCompression() const
Definition: asiancfg.cxx:84
bool GetStartEndChars(css::lang::Locale const &locale, OUString &startChars, OUString &endChars) const
Definition: asiancfg.cxx:106
void SetKerningWesternTextOnly(bool value)
Definition: asiancfg.cxx:79
css::uno::Sequence< css::lang::Locale > GetStartEndCharLocales() const
Definition: asiancfg.cxx:93
void SetStartEndChars(css::lang::Locale const &locale, OUString const *startChars, OUString const *endChars)
Definition: asiancfg.cxx:126
bool IsKerningWesternTextOnly() const
Definition: asiancfg.cxx:74
void SetCharDistanceCompression(CharCompressType value)
Definition: asiancfg.cxx:88
std::unique_ptr< Impl > impl_
Definition: asiancfg.hxx:71
Any value
float v
const char * name
#define SAL_WARN_IF(condition, area, stream)
#define SAL_INFO(area, stream)
void set(css::uno::UnoInterfaceReference const &value)
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
ns
OUString toString(OptionInfo const *info)
Impl & operator=(const Impl &)=delete
Impl(const Impl &)=delete
std::shared_ptr< comphelper::ConfigurationChanges > batch
Definition: asiancfg.cxx:63