fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / config / fontsubstconfig.cxx
blobb3ccb4fb725f7231220c229b205713e90fb058ca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svtools/fontsubstconfig.hxx>
21 #include <com/sun/star/beans/PropertyValue.hpp>
22 #include <com/sun/star/uno/Any.hxx>
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <tools/debug.hxx>
25 #include <vcl/outdev.hxx>
26 #include <rtl/logfile.hxx>
28 #include <boost/ptr_container/ptr_vector.hpp>
30 using namespace utl;
31 using namespace com::sun::star;
32 using namespace com::sun::star::uno;
33 using namespace com::sun::star::beans;
36 const sal_Char cReplacement[] = "Replacement";
37 const sal_Char cFontPairs[] = "FontPairs";
39 const sal_Char cReplaceFont[] = "ReplaceFont";
40 const sal_Char cSubstituteFont[]= "SubstituteFont";
41 const sal_Char cOnScreenOnly[] = "OnScreenOnly";
42 const sal_Char cAlways[] = "Always";
44 typedef boost::ptr_vector<SubstitutionStruct> SubstitutionStructArr;
46 struct SvtFontSubstConfig_Impl
48 SubstitutionStructArr aSubstArr;
51 SvtFontSubstConfig::SvtFontSubstConfig() :
52 ConfigItem(OUString("Office.Common/Font/Substitution")),
53 bIsEnabled(sal_False),
54 pImpl(new SvtFontSubstConfig_Impl)
56 RTL_LOGFILE_CONTEXT(aLog, "svtools SvtFontSubstConfig::SvtFontSubstConfig()");
58 Sequence<OUString> aNames(1);
59 aNames.getArray()[0] = cReplacement;
60 Sequence<Any> aValues = GetProperties(aNames);
61 DBG_ASSERT(aValues.getConstArray()[0].hasValue(), "no value available");
62 if(aValues.getConstArray()[0].hasValue())
63 bIsEnabled = *(sal_Bool*)aValues.getConstArray()[0].getValue();
65 OUString sPropPrefix(cFontPairs);
66 Sequence<OUString> aNodeNames = GetNodeNames(sPropPrefix, CONFIG_NAME_LOCAL_PATH);
67 const OUString* pNodeNames = aNodeNames.getConstArray();
68 Sequence<OUString> aPropNames(aNodeNames.getLength() * 4);
69 OUString* pNames = aPropNames.getArray();
70 sal_Int32 nName = 0;
71 sPropPrefix += OUString("/");
72 sal_Int32 nNode;
73 for(nNode = 0; nNode < aNodeNames.getLength(); nNode++)
75 OUString sStart(sPropPrefix);
76 sStart += pNodeNames[nNode];
77 sStart += OUString("/");
78 pNames[nName] = sStart; pNames[nName++] += cReplaceFont;
79 pNames[nName] = sStart; pNames[nName++] += cSubstituteFont;
80 pNames[nName] = sStart; pNames[nName++] += cAlways;
81 pNames[nName] = sStart; pNames[nName++] += cOnScreenOnly;
83 Sequence<Any> aNodeValues = GetProperties(aPropNames);
84 const Any* pNodeValues = aNodeValues.getConstArray();
85 nName = 0;
86 for(nNode = 0; nNode < aNodeNames.getLength(); nNode++)
88 SubstitutionStruct* pInsert = new SubstitutionStruct;
89 pNodeValues[nName++] >>= pInsert->sFont;
90 pNodeValues[nName++] >>= pInsert->sReplaceBy;
91 pInsert->bReplaceAlways = *(sal_Bool*)pNodeValues[nName++].getValue();
92 pInsert->bReplaceOnScreenOnly = *(sal_Bool*)pNodeValues[nName++].getValue();
93 pImpl->aSubstArr.push_back(pInsert);
97 SvtFontSubstConfig::~SvtFontSubstConfig()
99 delete pImpl;
102 void SvtFontSubstConfig::Notify( const com::sun::star::uno::Sequence< OUString >& )
106 void SvtFontSubstConfig::Commit()
108 Sequence<OUString> aNames(1);
109 aNames.getArray()[0] = cReplacement;
110 Sequence<Any> aValues(1);
111 aValues.getArray()[0].setValue(&bIsEnabled, ::getBooleanCppuType());
112 PutProperties(aNames, aValues);
114 OUString sNode(cFontPairs);
115 if(pImpl->aSubstArr.empty())
116 ClearNodeSet(sNode);
117 else
119 Sequence<PropertyValue> aSetValues(4 * pImpl->aSubstArr.size());
120 PropertyValue* pSetValues = aSetValues.getArray();
121 sal_Int32 nSetValue = 0;
123 const OUString sReplaceFont(cReplaceFont);
124 const OUString sSubstituteFont(cSubstituteFont);
125 const OUString sAlways(cAlways);
126 const OUString sOnScreenOnly(cOnScreenOnly);
128 const uno::Type& rBoolType = ::getBooleanCppuType();
129 for(size_t i = 0; i < pImpl->aSubstArr.size(); i++)
131 OUString sPrefix(sNode);
132 sPrefix += "/_";
133 sPrefix += OUString::valueOf((sal_Int32)i);
134 sPrefix += "/";
136 SubstitutionStruct& pSubst = pImpl->aSubstArr[i];
137 pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sReplaceFont;
138 pSetValues[nSetValue++].Value <<= pSubst.sFont;
139 pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sSubstituteFont;
140 pSetValues[nSetValue++].Value <<= pSubst.sReplaceBy;
141 pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sAlways;
142 pSetValues[nSetValue++].Value.setValue(&pSubst.bReplaceAlways, rBoolType);
143 pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sOnScreenOnly;
144 pSetValues[nSetValue++].Value.setValue(&pSubst.bReplaceOnScreenOnly, rBoolType);
146 ReplaceSetProperties(sNode, aSetValues);
150 sal_Int32 SvtFontSubstConfig::SubstitutionCount() const
152 return pImpl->aSubstArr.size();
155 void SvtFontSubstConfig::ClearSubstitutions()
157 pImpl->aSubstArr.clear();
160 const SubstitutionStruct* SvtFontSubstConfig::GetSubstitution(sal_Int32 nPos)
162 sal_Int32 nCount = static_cast<sal_Int32>(pImpl->aSubstArr.size());
163 DBG_ASSERT(nPos >= 0 && nPos < nCount, "illegal array index");
164 if(nPos >= 0 && nPos < nCount)
165 return &pImpl->aSubstArr[nPos];
166 return NULL;
169 void SvtFontSubstConfig::AddSubstitution(const SubstitutionStruct& rToAdd)
171 pImpl->aSubstArr.push_back(new SubstitutionStruct(rToAdd));
174 void SvtFontSubstConfig::Apply()
176 OutputDevice::BeginFontSubstitution();
178 // remove old substitions
179 sal_uInt16 nOldCount = OutputDevice::GetFontSubstituteCount();
181 while (nOldCount)
182 OutputDevice::RemoveFontSubstitute(--nOldCount);
184 // read new substitutions
185 sal_Int32 nCount = IsEnabled() ? SubstitutionCount() : 0;
187 for (sal_Int32 i = 0; i < nCount; i++)
189 sal_uInt16 nFlags = 0;
190 const SubstitutionStruct* pSubs = GetSubstitution(i);
191 if(pSubs->bReplaceAlways)
192 nFlags |= FONT_SUBSTITUTE_ALWAYS;
193 if(pSubs->bReplaceOnScreenOnly)
194 nFlags |= FONT_SUBSTITUTE_SCREENONLY;
195 OutputDevice::AddFontSubstitute( String(pSubs->sFont), String(pSubs->sReplaceBy), nFlags );
198 OutputDevice::EndFontSubstitution();
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */