1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fontsubstconfig.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #ifdef SVL_DLLIMPLEMENTATION
35 #undef SVL_DLLIMPLEMENTATION
37 #define SVT_DLLIMPLEMENTATION
39 #include "fontsubstconfig.hxx"
40 #include <svtools/svarray.hxx>
41 #include <com/sun/star/beans/PropertyValue.hpp>
42 #include <com/sun/star/uno/Any.hxx>
43 #include <com/sun/star/uno/Sequence.hxx>
44 #include <tools/debug.hxx>
46 #include <vcl/outdev.hxx>
47 #include <rtl/logfile.hxx>
51 using namespace com::sun::star
;
52 using namespace com::sun::star::uno
;
53 using namespace com::sun::star::beans
;
55 #define C2U(cChar) OUString::createFromAscii(cChar)
57 const sal_Char cReplacement
[] = "Replacement";
58 const sal_Char cFontPairs
[] = "FontPairs";
60 const sal_Char cReplaceFont
[] = "ReplaceFont";
61 const sal_Char cSubstituteFont
[]= "SubstituteFont";
62 const sal_Char cOnScreenOnly
[] = "OnScreenOnly";
63 const sal_Char cAlways
[] = "Always";
65 //-----------------------------------------------------------------------------
66 typedef SubstitutionStruct
* SubstitutionStructPtr
;
67 SV_DECL_PTRARR_DEL(SubstitutionStructArr
, SubstitutionStructPtr
, 2, 2)
68 SV_IMPL_PTRARR(SubstitutionStructArr
, SubstitutionStructPtr
);
69 //-----------------------------------------------------------------------------
70 struct SvtFontSubstConfig_Impl
72 SubstitutionStructArr aSubstArr
;
74 /* -----------------------------18.01.01 12:04--------------------------------
76 ---------------------------------------------------------------------------*/
77 SvtFontSubstConfig::SvtFontSubstConfig() :
78 ConfigItem(C2U("Office.Common/Font/Substitution")),
79 bIsEnabled(sal_False
),
80 pImpl(new SvtFontSubstConfig_Impl
)
82 RTL_LOGFILE_CONTEXT(aLog
, "svtools SvtFontSubstConfig::SvtFontSubstConfig()");
84 Sequence
<OUString
> aNames(1);
85 aNames
.getArray()[0] = C2U(cReplacement
);
86 Sequence
<Any
> aValues
= GetProperties(aNames
);
87 DBG_ASSERT(aValues
.getConstArray()[0].hasValue(), "no value available");
88 if(aValues
.getConstArray()[0].hasValue())
89 bIsEnabled
= *(sal_Bool
*)aValues
.getConstArray()[0].getValue();
91 OUString
sPropPrefix(C2U(cFontPairs
));
92 Sequence
<OUString
> aNodeNames
= GetNodeNames(sPropPrefix
, CONFIG_NAME_LOCAL_PATH
);
93 const OUString
* pNodeNames
= aNodeNames
.getConstArray();
94 Sequence
<OUString
> aPropNames(aNodeNames
.getLength() * 4);
95 OUString
* pNames
= aPropNames
.getArray();
97 sPropPrefix
+= C2U("/");
99 for(nNode
= 0; nNode
< aNodeNames
.getLength(); nNode
++)
101 OUString
sStart(sPropPrefix
);
102 sStart
+= pNodeNames
[nNode
];
104 pNames
[nName
] = sStart
; pNames
[nName
++] += C2U(cReplaceFont
);
105 pNames
[nName
] = sStart
; pNames
[nName
++] += C2U(cSubstituteFont
);
106 pNames
[nName
] = sStart
; pNames
[nName
++] += C2U(cAlways
);
107 pNames
[nName
] = sStart
; pNames
[nName
++] += C2U(cOnScreenOnly
);
109 Sequence
<Any
> aNodeValues
= GetProperties(aPropNames
);
110 const Any
* pNodeValues
= aNodeValues
.getConstArray();
112 for(nNode
= 0; nNode
< aNodeNames
.getLength(); nNode
++)
114 SubstitutionStructPtr pInsert
= new SubstitutionStruct
;
115 pNodeValues
[nName
++] >>= pInsert
->sFont
;
116 pNodeValues
[nName
++] >>= pInsert
->sReplaceBy
;
117 pInsert
->bReplaceAlways
= *(sal_Bool
*)pNodeValues
[nName
++].getValue();
118 pInsert
->bReplaceOnScreenOnly
= *(sal_Bool
*)pNodeValues
[nName
++].getValue();
119 pImpl
->aSubstArr
.Insert(pInsert
, pImpl
->aSubstArr
.Count());
122 /* -----------------------------18.01.01 12:06--------------------------------
124 ---------------------------------------------------------------------------*/
125 SvtFontSubstConfig::~SvtFontSubstConfig()
129 /*-- 18.01.01 12:08:00---------------------------------------------------
131 -----------------------------------------------------------------------*/
132 void SvtFontSubstConfig::Commit()
134 Sequence
<OUString
> aNames(1);
135 aNames
.getArray()[0] = C2U(cReplacement
);
136 Sequence
<Any
> aValues(1);
137 aValues
.getArray()[0].setValue(&bIsEnabled
, ::getBooleanCppuType());
138 PutProperties(aNames
, aValues
);
140 OUString
sNode(C2U(cFontPairs
));
141 if(!pImpl
->aSubstArr
.Count())
145 Sequence
<PropertyValue
> aSetValues(4 * pImpl
->aSubstArr
.Count());
146 PropertyValue
* pSetValues
= aSetValues
.getArray();
147 sal_Int32 nSetValue
= 0;
149 const OUString
sReplaceFont(C2U(cReplaceFont
));
150 const OUString
sSubstituteFont(C2U(cSubstituteFont
));
151 const OUString
sAlways(C2U(cAlways
));
152 const OUString
sOnScreenOnly(C2U(cOnScreenOnly
));
154 const uno::Type
& rBoolType
= ::getBooleanCppuType();
155 for(sal_uInt16 i
= 0; i
< pImpl
->aSubstArr
.Count(); i
++)
157 OUString
sPrefix(sNode
);
158 sPrefix
+= C2U("/_");
159 sPrefix
+= OUString::valueOf((sal_Int32
)i
);
162 SubstitutionStructPtr pSubst
= pImpl
->aSubstArr
[i
];
163 pSetValues
[nSetValue
].Name
= sPrefix
; pSetValues
[nSetValue
].Name
+= sReplaceFont
;
164 pSetValues
[nSetValue
++].Value
<<= pSubst
->sFont
;
165 pSetValues
[nSetValue
].Name
= sPrefix
; pSetValues
[nSetValue
].Name
+= sSubstituteFont
;
166 pSetValues
[nSetValue
++].Value
<<= pSubst
->sReplaceBy
;
167 pSetValues
[nSetValue
].Name
= sPrefix
; pSetValues
[nSetValue
].Name
+= sAlways
;
168 pSetValues
[nSetValue
++].Value
.setValue(&pSubst
->bReplaceAlways
, rBoolType
);
169 pSetValues
[nSetValue
].Name
= sPrefix
; pSetValues
[nSetValue
].Name
+= sOnScreenOnly
;
170 pSetValues
[nSetValue
++].Value
.setValue(&pSubst
->bReplaceOnScreenOnly
, rBoolType
);
172 ReplaceSetProperties(sNode
, aSetValues
);
175 /*-- 18.01.01 12:08:00---------------------------------------------------
177 -----------------------------------------------------------------------*/
178 sal_Int32
SvtFontSubstConfig::SubstitutionCount() const
180 return pImpl
->aSubstArr
.Count();
182 /*-- 18.01.01 12:08:00---------------------------------------------------
184 -----------------------------------------------------------------------*/
185 void SvtFontSubstConfig::ClearSubstitutions()
187 pImpl
->aSubstArr
.DeleteAndDestroy(0, pImpl
->aSubstArr
.Count());
189 /*-- 18.01.01 12:08:00---------------------------------------------------
191 -----------------------------------------------------------------------*/
192 const SubstitutionStruct
* SvtFontSubstConfig::GetSubstitution(sal_Int32 nPos
)
194 DBG_ASSERT(nPos
>= 0 && nPos
< pImpl
->aSubstArr
.Count(), "illegal array index");
195 if(nPos
>= 0 && nPos
< pImpl
->aSubstArr
.Count())
196 return pImpl
->aSubstArr
[(sal_uInt16
)nPos
];
199 /*-- 18.01.01 12:08:01---------------------------------------------------
201 -----------------------------------------------------------------------*/
202 void SvtFontSubstConfig::AddSubstitution(const SubstitutionStruct
& rToAdd
)
204 SubstitutionStructPtr pInsert
= new SubstitutionStruct(rToAdd
);
205 pImpl
->aSubstArr
.Insert(pInsert
, pImpl
->aSubstArr
.Count());
208 void SvtFontSubstConfig::Apply()
210 OutputDevice::BeginFontSubstitution();
212 // Alte Substitution entfernen
213 sal_uInt16 nOldCount
= OutputDevice::GetFontSubstituteCount();
216 OutputDevice::RemoveFontSubstitute(--nOldCount
);
218 // Neue Substitution einlesen
219 sal_Int32 nCount
= IsEnabled() ? SubstitutionCount() : 0;
221 for (sal_Int32 i
= 0; i
< nCount
; i
++)
223 sal_uInt16 nFlags
= 0;
224 const SubstitutionStruct
* pSubs
= GetSubstitution(i
);
225 if(pSubs
->bReplaceAlways
)
226 nFlags
|= FONT_SUBSTITUTE_ALWAYS
;
227 if(pSubs
->bReplaceOnScreenOnly
)
228 nFlags
|= FONT_SUBSTITUTE_SCREENONLY
;
229 OutputDevice::AddFontSubstitute( String(pSubs
->sFont
), String(pSubs
->sReplaceBy
), nFlags
);
232 OutputDevice::EndFontSubstitution();