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 <cassert>
21 #include <memory>
22 #include <vector>
23 
24 #include <svl/itemset.hxx>
25 #include <svl/intitem.hxx>
26 #include <svl/itempool.hxx>
27 #include <svl/eitem.hxx>
28 #include <svl/languageoptions.hxx>
29 #include <vcl/outdev.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/settings.hxx>
32 #include <sal/log.hxx>
33 #include <osl/diagnose.h>
34 #include <i18nlangtag/languagetag.hxx>
35 
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 
38 #include <officecfg/Office/Math.hxx>
39 #include "cfgitem.hxx"
40 
41 #include <starmath.hrc>
42 #include <smmod.hxx>
43 #include <symbol.hxx>
44 #include <format.hxx>
45 
46 using namespace com::sun::star::uno;
47 using namespace com::sun::star::beans;
48 
49 #define SYMBOL_LIST         "SymbolList"
50 #define FONT_FORMAT_LIST    "FontFormatList"
51 
lcl_GetFontPropertyNames()52 static Sequence< OUString > lcl_GetFontPropertyNames()
53 {
54     return Sequence< OUString > {
55                         "Name",
56                         "CharSet",
57                         "Family",
58                         "Pitch",
59                         "Weight",
60                         "Italic"
61                     };
62 }
63 
lcl_GetSymbolPropertyNames()64 static Sequence< OUString > lcl_GetSymbolPropertyNames()
65 {
66     return Sequence< OUString > {
67                         "Char",
68                         "Set",
69                         "Predefined",
70                         "FontFormatId"
71                     };
72 }
73 
lcl_GetFormatPropertyNames()74 static Sequence< OUString > lcl_GetFormatPropertyNames()
75 {
76     //! Beware of order according to *_BEGIN *_END defines in format.hxx !
77     //! see respective load/save routines here
78     return Sequence< OUString > {
79                         "StandardFormat/Textmode",
80                         "StandardFormat/GreekCharStyle",
81                         "StandardFormat/ScaleNormalBracket",
82                         "StandardFormat/HorizontalAlignment",
83                         "StandardFormat/BaseSize",
84                         "StandardFormat/TextSize",
85                         "StandardFormat/IndexSize",
86                         "StandardFormat/FunctionSize",
87                         "StandardFormat/OperatorSize",
88                         "StandardFormat/LimitsSize",
89                         "StandardFormat/Distance/Horizontal",
90                         "StandardFormat/Distance/Vertical",
91                         "StandardFormat/Distance/Root",
92                         "StandardFormat/Distance/SuperScript",
93                         "StandardFormat/Distance/SubScript",
94                         "StandardFormat/Distance/Numerator",
95                         "StandardFormat/Distance/Denominator",
96                         "StandardFormat/Distance/Fraction",
97                         "StandardFormat/Distance/StrokeWidth",
98                         "StandardFormat/Distance/UpperLimit",
99                         "StandardFormat/Distance/LowerLimit",
100                         "StandardFormat/Distance/BracketSize",
101                         "StandardFormat/Distance/BracketSpace",
102                         "StandardFormat/Distance/MatrixRow",
103                         "StandardFormat/Distance/MatrixColumn",
104                         "StandardFormat/Distance/OrnamentSize",
105                         "StandardFormat/Distance/OrnamentSpace",
106                         "StandardFormat/Distance/OperatorSize",
107                         "StandardFormat/Distance/OperatorSpace",
108                         "StandardFormat/Distance/LeftSpace",
109                         "StandardFormat/Distance/RightSpace",
110                         "StandardFormat/Distance/TopSpace",
111                         "StandardFormat/Distance/BottomSpace",
112                         "StandardFormat/Distance/NormalBracketSize",
113                         "StandardFormat/VariableFont",
114                         "StandardFormat/FunctionFont",
115                         "StandardFormat/NumberFont",
116                         "StandardFormat/TextFont",
117                         "StandardFormat/SerifFont",
118                         "StandardFormat/SansFont",
119                         "StandardFormat/FixedFont"
120                     };
121 }
122 
123 struct SmCfgOther
124 {
125     SmPrintSize     ePrintSize;
126     sal_uInt16      nPrintZoomFactor;
127     bool            bPrintTitle;
128     bool            bPrintFormulaText;
129     bool            bPrintFrame;
130     bool            bIsSaveOnlyUsedSymbols;
131     bool            bIsAutoCloseBrackets;
132     bool            bIgnoreSpacesRight;
133     bool            bToolboxVisible;
134     bool            bAutoRedraw;
135     bool            bFormulaCursor;
136 
137     SmCfgOther();
138 };
139 
140 
SmCfgOther()141 SmCfgOther::SmCfgOther()
142     : ePrintSize(PRINT_SIZE_NORMAL)
143     , nPrintZoomFactor(100)
144     , bPrintTitle(true)
145     , bPrintFormulaText(true)
146     , bPrintFrame(true)
147     , bIsSaveOnlyUsedSymbols(true)
148     , bIsAutoCloseBrackets(true)
149     , bIgnoreSpacesRight(true)
150     , bToolboxVisible(true)
151     , bAutoRedraw(true)
152     , bFormulaCursor(true)
153 {
154 }
155 
156 
SmFontFormat()157 SmFontFormat::SmFontFormat()
158     : aName(FONTNAME_MATH)
159     , nCharSet(RTL_TEXTENCODING_UNICODE)
160     , nFamily(FAMILY_DONTKNOW)
161     , nPitch(PITCH_DONTKNOW)
162     , nWeight(WEIGHT_DONTKNOW)
163     , nItalic(ITALIC_NONE)
164 {
165 }
166 
167 
SmFontFormat(const vcl::Font & rFont)168 SmFontFormat::SmFontFormat( const vcl::Font &rFont )
169     : aName(rFont.GetFamilyName())
170     , nCharSet(static_cast<sal_Int16>(rFont.GetCharSet()))
171     , nFamily(static_cast<sal_Int16>(rFont.GetFamilyType()))
172     , nPitch(static_cast<sal_Int16>(rFont.GetPitch()))
173     , nWeight(static_cast<sal_Int16>(rFont.GetWeight()))
174     , nItalic(static_cast<sal_Int16>(rFont.GetItalic()))
175 {
176 }
177 
178 
GetFont() const179 vcl::Font SmFontFormat::GetFont() const
180 {
181     vcl::Font aRes;
182     aRes.SetFamilyName( aName );
183     aRes.SetCharSet( static_cast<rtl_TextEncoding>(nCharSet) );
184     aRes.SetFamily( static_cast<FontFamily>(nFamily) );
185     aRes.SetPitch( static_cast<FontPitch>(nPitch) );
186     aRes.SetWeight( static_cast<FontWeight>(nWeight) );
187     aRes.SetItalic( static_cast<FontItalic>(nItalic) );
188     return aRes;
189 }
190 
191 
operator ==(const SmFontFormat & rFntFmt) const192 bool SmFontFormat::operator == ( const SmFontFormat &rFntFmt ) const
193 {
194     return  aName    == rFntFmt.aName       &&
195             nCharSet == rFntFmt.nCharSet    &&
196             nFamily  == rFntFmt.nFamily     &&
197             nPitch   == rFntFmt.nPitch      &&
198             nWeight  == rFntFmt.nWeight     &&
199             nItalic  == rFntFmt.nItalic;
200 }
201 
202 
SmFntFmtListEntry(const OUString & rId,const SmFontFormat & rFntFmt)203 SmFntFmtListEntry::SmFntFmtListEntry( const OUString &rId, const SmFontFormat &rFntFmt ) :
204     aId     (rId),
205     aFntFmt (rFntFmt)
206 {
207 }
208 
209 
SmFontFormatList()210 SmFontFormatList::SmFontFormatList()
211     : bModified(false)
212 {
213 }
214 
215 
Clear()216 void SmFontFormatList::Clear()
217 {
218     if (!aEntries.empty())
219     {
220         aEntries.clear();
221         SetModified( true );
222     }
223 }
224 
225 
AddFontFormat(const OUString & rFntFmtId,const SmFontFormat & rFntFmt)226 void SmFontFormatList::AddFontFormat( const OUString &rFntFmtId,
227         const SmFontFormat &rFntFmt )
228 {
229     const SmFontFormat *pFntFmt = GetFontFormat( rFntFmtId );
230     OSL_ENSURE( !pFntFmt, "FontFormatId already exists" );
231     if (!pFntFmt)
232     {
233         SmFntFmtListEntry aEntry( rFntFmtId, rFntFmt );
234         aEntries.push_back( aEntry );
235         SetModified( true );
236     }
237 }
238 
239 
RemoveFontFormat(const OUString & rFntFmtId)240 void SmFontFormatList::RemoveFontFormat( const OUString &rFntFmtId )
241 {
242 
243     // search for entry
244     for (size_t i = 0;  i < aEntries.size();  ++i)
245     {
246         if (aEntries[i].aId == rFntFmtId)
247         {
248             // remove entry if found
249             aEntries.erase( aEntries.begin() + i );
250             SetModified( true );
251             break;
252         }
253     }
254 }
255 
256 
GetFontFormat(const OUString & rFntFmtId) const257 const SmFontFormat * SmFontFormatList::GetFontFormat( const OUString &rFntFmtId ) const
258 {
259     const SmFontFormat *pRes = nullptr;
260 
261     for (const auto & rEntry : aEntries)
262     {
263         if (rEntry.aId == rFntFmtId)
264         {
265             pRes = &rEntry.aFntFmt;
266             break;
267         }
268     }
269 
270     return pRes;
271 }
272 
273 
GetFontFormat(size_t nPos) const274 const SmFontFormat * SmFontFormatList::GetFontFormat( size_t nPos ) const
275 {
276     const SmFontFormat *pRes = nullptr;
277     if (nPos < aEntries.size())
278         pRes = &aEntries[nPos].aFntFmt;
279     return pRes;
280 }
281 
282 
GetFontFormatId(const SmFontFormat & rFntFmt) const283 OUString SmFontFormatList::GetFontFormatId( const SmFontFormat &rFntFmt ) const
284 {
285     OUString aRes;
286 
287     for (const auto & rEntry : aEntries)
288     {
289         if (rEntry.aFntFmt == rFntFmt)
290         {
291             aRes = rEntry.aId;
292             break;
293         }
294     }
295 
296     return aRes;
297 }
298 
299 
GetFontFormatId(const SmFontFormat & rFntFmt,bool bAdd)300 OUString SmFontFormatList::GetFontFormatId( const SmFontFormat &rFntFmt, bool bAdd )
301 {
302     OUString aRes( GetFontFormatId( rFntFmt) );
303     if (aRes.isEmpty()  &&  bAdd)
304     {
305         aRes = GetNewFontFormatId();
306         AddFontFormat( aRes, rFntFmt );
307     }
308     return aRes;
309 }
310 
311 
GetFontFormatId(size_t nPos) const312 OUString SmFontFormatList::GetFontFormatId( size_t nPos ) const
313 {
314     OUString aRes;
315     if (nPos < aEntries.size())
316         aRes = aEntries[nPos].aId;
317     return aRes;
318 }
319 
320 
GetNewFontFormatId() const321 OUString SmFontFormatList::GetNewFontFormatId() const
322 {
323     // returns first unused FormatId
324 
325     sal_Int32 nCnt = GetCount();
326     for (sal_Int32 i = 1;  i <= nCnt + 1;  ++i)
327     {
328         OUString aTmpId = "Id" + OUString::number(i);
329         if (!GetFontFormat(aTmpId))
330             return aTmpId;
331     }
332     OSL_ENSURE( false, "failed to create new FontFormatId" );
333 
334     return OUString();
335 }
336 
337 
SmMathConfig()338 SmMathConfig::SmMathConfig() :
339     ConfigItem("Office.Math")
340     , pFormat()
341     , pOther()
342     , pFontFormatList()
343     , pSymbolMgr()
344     , bIsOtherModified(false)
345     , bIsFormatModified(false)
346 {
347 }
348 
349 
~SmMathConfig()350 SmMathConfig::~SmMathConfig()
351 {
352     Save();
353 }
354 
355 
SetOtherModified(bool bVal)356 void SmMathConfig::SetOtherModified( bool bVal )
357 {
358     bIsOtherModified = bVal;
359 }
360 
361 
SetFormatModified(bool bVal)362 void SmMathConfig::SetFormatModified( bool bVal )
363 {
364     bIsFormatModified = bVal;
365 }
366 
367 
ReadSymbol(SmSym & rSymbol,const OUString & rSymbolName,const OUString & rBaseNode) const368 void SmMathConfig::ReadSymbol( SmSym &rSymbol,
369                         const OUString &rSymbolName,
370                         const OUString &rBaseNode ) const
371 {
372     Sequence< OUString > aNames = lcl_GetSymbolPropertyNames();
373     sal_Int32 nProps = aNames.getLength();
374 
375     OUString aDelim( "/" );
376     for (auto& rName : aNames)
377         rName = rBaseNode + aDelim + rSymbolName + aDelim + rName;
378 
379     const Sequence< Any > aValues = const_cast<SmMathConfig*>(this)->GetProperties(aNames);
380 
381     if (!(nProps  &&  aValues.getLength() == nProps))
382         return;
383 
384     const Any * pValue = aValues.getConstArray();
385     vcl::Font   aFont;
386     sal_UCS4    cChar = '\0';
387     OUString    aSet;
388     bool        bPredefined = false;
389 
390     OUString    aTmpStr;
391     sal_Int32       nTmp32 = 0;
392     bool        bTmp = false;
393 
394     bool bOK = true;
395     if (pValue->hasValue()  &&  (*pValue >>= nTmp32))
396         cChar = static_cast< sal_UCS4 >( nTmp32 );
397     else
398         bOK = false;
399     ++pValue;
400     if (pValue->hasValue()  &&  (*pValue >>= aTmpStr))
401         aSet = aTmpStr;
402     else
403         bOK = false;
404     ++pValue;
405     if (pValue->hasValue()  &&  (*pValue >>= bTmp))
406         bPredefined = bTmp;
407     else
408         bOK = false;
409     ++pValue;
410     if (pValue->hasValue()  &&  (*pValue >>= aTmpStr))
411     {
412         const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
413         OSL_ENSURE( pFntFmt, "unknown FontFormat" );
414         if (pFntFmt)
415             aFont = pFntFmt->GetFont();
416     }
417     else
418         bOK = false;
419     ++pValue;
420 
421     if (bOK)
422     {
423         OUString aUiName( rSymbolName );
424         OUString aUiSetName( aSet );
425         if (bPredefined)
426         {
427             OUString aTmp;
428             aTmp = SmLocalizedSymbolData::GetUiSymbolName( rSymbolName );
429             OSL_ENSURE( !aTmp.isEmpty(), "localized symbol-name not found" );
430             if (!aTmp.isEmpty())
431                 aUiName = aTmp;
432             aTmp = SmLocalizedSymbolData::GetUiSymbolSetName( aSet );
433             OSL_ENSURE( !aTmp.isEmpty(), "localized symbolset-name not found" );
434             if (!aTmp.isEmpty())
435                 aUiSetName = aTmp;
436         }
437 
438         rSymbol = SmSym( aUiName, aFont, cChar, aUiSetName, bPredefined );
439         if (aUiName != rSymbolName)
440             rSymbol.SetExportName( rSymbolName );
441     }
442     else
443     {
444         SAL_WARN("starmath", "symbol read error");
445     }
446 }
447 
448 
GetSymbolManager()449 SmSymbolManager & SmMathConfig::GetSymbolManager()
450 {
451     if (!pSymbolMgr)
452     {
453         pSymbolMgr.reset(new SmSymbolManager);
454         pSymbolMgr->Load();
455     }
456     return *pSymbolMgr;
457 }
458 
459 
ImplCommit()460 void SmMathConfig::ImplCommit()
461 {
462     Save();
463 }
464 
465 
Save()466 void SmMathConfig::Save()
467 {
468     SaveOther();
469     SaveFormat();
470     SaveFontFormatList();
471 }
472 
473 
GetSymbols(std::vector<SmSym> & rSymbols) const474 void SmMathConfig::GetSymbols( std::vector< SmSym > &rSymbols ) const
475 {
476     Sequence< OUString > aNodes(const_cast<SmMathConfig*>(this)->GetNodeNames(SYMBOL_LIST));
477     const OUString *pNode = aNodes.getConstArray();
478     sal_Int32 nNodes = aNodes.getLength();
479 
480     rSymbols.resize( nNodes );
481     for (auto& rSymbol : rSymbols)
482     {
483         ReadSymbol( rSymbol, *pNode++, SYMBOL_LIST );
484     }
485 }
486 
487 
SetSymbols(const std::vector<SmSym> & rNewSymbols)488 void SmMathConfig::SetSymbols( const std::vector< SmSym > &rNewSymbols )
489 {
490     auto nCount = sal::static_int_cast<sal_Int32>(rNewSymbols.size());
491 
492     Sequence< OUString > aNames = lcl_GetSymbolPropertyNames();
493     const OUString *pNames = aNames.getConstArray();
494     sal_Int32 nSymbolProps = aNames.getLength();
495 
496     Sequence< PropertyValue > aValues( nCount * nSymbolProps );
497     PropertyValue *pValues = aValues.getArray();
498 
499     PropertyValue *pVal = pValues;
500     OUString aDelim( "/" );
501     for (const SmSym& rSymbol : rNewSymbols)
502     {
503         OUString  aNodeNameDelim = SYMBOL_LIST +
504             aDelim +
505             rSymbol.GetExportName() +
506             aDelim;
507 
508         const OUString *pName = pNames;
509 
510         // Char
511         pVal->Name  = aNodeNameDelim;
512         pVal->Name += *pName++;
513         pVal->Value <<= rSymbol.GetCharacter();
514         pVal++;
515         // Set
516         pVal->Name  = aNodeNameDelim;
517         pVal->Name += *pName++;
518         OUString aTmp( rSymbol.GetSymbolSetName() );
519         if (rSymbol.IsPredefined())
520             aTmp = SmLocalizedSymbolData::GetExportSymbolSetName( aTmp );
521         pVal->Value <<= aTmp;
522         pVal++;
523         // Predefined
524         pVal->Name  = aNodeNameDelim;
525         pVal->Name += *pName++;
526         pVal->Value <<= rSymbol.IsPredefined();
527         pVal++;
528         // FontFormatId
529         SmFontFormat aFntFmt( rSymbol.GetFace() );
530         OUString aFntFmtId( GetFontFormatList().GetFontFormatId( aFntFmt, true ) );
531         OSL_ENSURE( !aFntFmtId.isEmpty(), "FontFormatId not found" );
532         pVal->Name  = aNodeNameDelim;
533         pVal->Name += *pName++;
534         pVal->Value <<= aFntFmtId;
535         pVal++;
536     }
537     OSL_ENSURE( pVal - pValues == sal::static_int_cast< ptrdiff_t >(nCount * nSymbolProps), "properties missing" );
538     ReplaceSetProperties( SYMBOL_LIST, aValues );
539 
540     StripFontFormatList( rNewSymbols );
541     SaveFontFormatList();
542 }
543 
544 
GetFontFormatList()545 SmFontFormatList & SmMathConfig::GetFontFormatList()
546 {
547     if (!pFontFormatList)
548     {
549         LoadFontFormatList();
550     }
551     return *pFontFormatList;
552 }
553 
554 
LoadFontFormatList()555 void SmMathConfig::LoadFontFormatList()
556 {
557     if (!pFontFormatList)
558         pFontFormatList.reset(new SmFontFormatList);
559     else
560         pFontFormatList->Clear();
561 
562     const Sequence< OUString > aNodes( GetNodeNames( FONT_FORMAT_LIST ) );
563 
564     for (const OUString& rNode : aNodes)
565     {
566         SmFontFormat aFntFmt;
567         ReadFontFormat( aFntFmt, rNode, FONT_FORMAT_LIST );
568         if (!pFontFormatList->GetFontFormat( rNode ))
569             pFontFormatList->AddFontFormat( rNode, aFntFmt );
570     }
571     pFontFormatList->SetModified( false );
572 }
573 
574 
ReadFontFormat(SmFontFormat & rFontFormat,const OUString & rSymbolName,const OUString & rBaseNode) const575 void SmMathConfig::ReadFontFormat( SmFontFormat &rFontFormat,
576         const OUString &rSymbolName, const OUString &rBaseNode ) const
577 {
578     Sequence< OUString > aNames = lcl_GetFontPropertyNames();
579     sal_Int32 nProps = aNames.getLength();
580 
581     OUString aDelim( "/" );
582     for (auto& rName : aNames)
583         rName = rBaseNode + aDelim + rSymbolName + aDelim + rName;
584 
585     const Sequence< Any > aValues = const_cast<SmMathConfig*>(this)->GetProperties(aNames);
586 
587     if (!(nProps  &&  aValues.getLength() == nProps))
588         return;
589 
590     const Any * pValue = aValues.getConstArray();
591 
592     OUString    aTmpStr;
593     sal_Int16       nTmp16 = 0;
594 
595     bool bOK = true;
596     if (pValue->hasValue()  &&  (*pValue >>= aTmpStr))
597         rFontFormat.aName = aTmpStr;
598     else
599         bOK = false;
600     ++pValue;
601     if (pValue->hasValue()  &&  (*pValue >>= nTmp16))
602         rFontFormat.nCharSet = nTmp16; // 6.0 file-format GetSOLoadTextEncoding not needed
603     else
604         bOK = false;
605     ++pValue;
606     if (pValue->hasValue()  &&  (*pValue >>= nTmp16))
607         rFontFormat.nFamily = nTmp16;
608     else
609         bOK = false;
610     ++pValue;
611     if (pValue->hasValue()  &&  (*pValue >>= nTmp16))
612         rFontFormat.nPitch = nTmp16;
613     else
614         bOK = false;
615     ++pValue;
616     if (pValue->hasValue()  &&  (*pValue >>= nTmp16))
617         rFontFormat.nWeight = nTmp16;
618     else
619         bOK = false;
620     ++pValue;
621     if (pValue->hasValue()  &&  (*pValue >>= nTmp16))
622         rFontFormat.nItalic = nTmp16;
623     else
624         bOK = false;
625     ++pValue;
626 
627     OSL_ENSURE( bOK, "read FontFormat failed" );
628 }
629 
630 
SaveFontFormatList()631 void SmMathConfig::SaveFontFormatList()
632 {
633     SmFontFormatList &rFntFmtList = GetFontFormatList();
634 
635     if (!rFntFmtList.IsModified())
636         return;
637 
638     Sequence< OUString > aNames = lcl_GetFontPropertyNames();
639     sal_Int32 nSymbolProps = aNames.getLength();
640 
641     size_t nCount = rFntFmtList.GetCount();
642 
643     Sequence< PropertyValue > aValues( nCount * nSymbolProps );
644     PropertyValue *pValues = aValues.getArray();
645 
646     PropertyValue *pVal = pValues;
647     OUString aDelim( "/" );
648     for (size_t i = 0;  i < nCount;  ++i)
649     {
650         OUString aFntFmtId(rFntFmtList.GetFontFormatId(i));
651         const SmFontFormat *pFntFmt = rFntFmtList.GetFontFormat(i);
652         assert(pFntFmt);
653         const SmFontFormat aFntFmt(*pFntFmt);
654 
655         OUString  aNodeNameDelim = FONT_FORMAT_LIST +
656             aDelim +
657             aFntFmtId +
658             aDelim;
659 
660         const OUString *pName = aNames.getConstArray();
661 
662         // Name
663         pVal->Name  = aNodeNameDelim;
664         pVal->Name += *pName++;
665         pVal->Value <<= aFntFmt.aName;
666         pVal++;
667         // CharSet
668         pVal->Name  = aNodeNameDelim;
669         pVal->Name += *pName++;
670         pVal->Value <<= aFntFmt.nCharSet; // 6.0 file-format GetSOStoreTextEncoding not needed
671         pVal++;
672         // Family
673         pVal->Name  = aNodeNameDelim;
674         pVal->Name += *pName++;
675         pVal->Value <<= aFntFmt.nFamily;
676         pVal++;
677         // Pitch
678         pVal->Name  = aNodeNameDelim;
679         pVal->Name += *pName++;
680         pVal->Value <<= aFntFmt.nPitch;
681         pVal++;
682         // Weight
683         pVal->Name  = aNodeNameDelim;
684         pVal->Name += *pName++;
685         pVal->Value <<= aFntFmt.nWeight;
686         pVal++;
687         // Italic
688         pVal->Name  = aNodeNameDelim;
689         pVal->Name += *pName++;
690         pVal->Value <<= aFntFmt.nItalic;
691         pVal++;
692     }
693     OSL_ENSURE( sal::static_int_cast<size_t>(pVal - pValues) == nCount * nSymbolProps, "properties missing" );
694     ReplaceSetProperties( FONT_FORMAT_LIST, aValues );
695 
696     rFntFmtList.SetModified( false );
697 }
698 
699 
StripFontFormatList(const std::vector<SmSym> & rSymbols)700 void SmMathConfig::StripFontFormatList( const std::vector< SmSym > &rSymbols )
701 {
702     size_t i;
703 
704     // build list of used font-formats only
705     //!! font-format IDs may be different !!
706     SmFontFormatList aUsedList;
707     for (i = 0;  i < rSymbols.size();  ++i)
708     {
709         OSL_ENSURE( rSymbols[i].GetName().getLength() > 0, "non named symbol" );
710         aUsedList.GetFontFormatId( SmFontFormat( rSymbols[i].GetFace() ) , true );
711     }
712     const SmFormat & rStdFmt = GetStandardFormat();
713     for (i = FNT_BEGIN;  i <= FNT_END;  ++i)
714     {
715         aUsedList.GetFontFormatId( SmFontFormat( rStdFmt.GetFont( i ) ) , true );
716     }
717 
718     // remove unused font-formats from list
719     SmFontFormatList &rFntFmtList = GetFontFormatList();
720     size_t nCnt = rFntFmtList.GetCount();
721     std::unique_ptr<SmFontFormat[]> pTmpFormat(new SmFontFormat[ nCnt ]);
722     std::unique_ptr<OUString[]> pId(new OUString[ nCnt ]);
723     size_t k;
724     for (k = 0;  k < nCnt;  ++k)
725     {
726         pTmpFormat[k] = *rFntFmtList.GetFontFormat( k );
727         pId[k]     = rFntFmtList.GetFontFormatId( k );
728     }
729     for (k = 0;  k < nCnt;  ++k)
730     {
731         if (aUsedList.GetFontFormatId( pTmpFormat[k] ).isEmpty())
732         {
733             rFntFmtList.RemoveFontFormat( pId[k] );
734         }
735     }
736 }
737 
738 
LoadOther()739 void SmMathConfig::LoadOther()
740 {
741     if (!pOther)
742         pOther.reset(new SmCfgOther);
743 
744     pOther->bPrintTitle = officecfg::Office::Math::Print::Title::get();
745     pOther->bPrintFormulaText = officecfg::Office::Math::Print::FormulaText::get();
746     pOther->bPrintFrame = officecfg::Office::Math::Print::Frame::get();
747     pOther->ePrintSize = static_cast<SmPrintSize>(officecfg::Office::Math::Print::Size::get());
748     pOther->nPrintZoomFactor = officecfg::Office::Math::Print::ZoomFactor::get();
749     pOther->bIsSaveOnlyUsedSymbols = officecfg::Office::Math::LoadSave::IsSaveOnlyUsedSymbols::get();
750     pOther->bIsAutoCloseBrackets = officecfg::Office::Math::Misc::AutoCloseBrackets::get();
751     pOther->bIgnoreSpacesRight = officecfg::Office::Math::Misc::IgnoreSpacesRight::get();
752     pOther->bToolboxVisible = officecfg::Office::Math::View::ToolboxVisible::get();
753     pOther->bAutoRedraw = officecfg::Office::Math::View::AutoRedraw::get();
754     pOther->bFormulaCursor = officecfg::Office::Math::View::FormulaCursor::get();
755     SetOtherModified( false );
756 }
757 
758 
SaveOther()759 void SmMathConfig::SaveOther()
760 {
761     if (!pOther || !IsOtherModified())
762         return;
763 
764     std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
765 
766     officecfg::Office::Math::Print::Title::set(pOther->bPrintTitle, batch);
767     officecfg::Office::Math::Print::FormulaText::set(pOther->bPrintFormulaText, batch);
768     officecfg::Office::Math::Print::Frame::set(pOther->bPrintFrame, batch);
769     officecfg::Office::Math::Print::Size::set(pOther->ePrintSize, batch);
770     officecfg::Office::Math::Print::ZoomFactor::set(pOther->nPrintZoomFactor, batch);
771     officecfg::Office::Math::LoadSave::IsSaveOnlyUsedSymbols::set(pOther->bIsSaveOnlyUsedSymbols, batch);
772     officecfg::Office::Math::Misc::AutoCloseBrackets::set(pOther->bIsAutoCloseBrackets, batch);
773     officecfg::Office::Math::Misc::IgnoreSpacesRight::set(pOther->bIgnoreSpacesRight, batch);
774     officecfg::Office::Math::View::ToolboxVisible::set(pOther->bToolboxVisible, batch);
775     officecfg::Office::Math::View::AutoRedraw::set(pOther->bAutoRedraw, batch);
776     officecfg::Office::Math::View::FormulaCursor::set(pOther->bFormulaCursor, batch);
777 
778     batch->commit();
779     SetOtherModified( false );
780 }
781 
782 namespace {
783 
784 // Latin default-fonts
785 const DefaultFontType aLatinDefFnts[FNT_END] =
786 {
787     DefaultFontType::SERIF,  // FNT_VARIABLE
788     DefaultFontType::SERIF,  // FNT_FUNCTION
789     DefaultFontType::SERIF,  // FNT_NUMBER
790     DefaultFontType::SERIF,  // FNT_TEXT
791     DefaultFontType::SERIF,  // FNT_SERIF
792     DefaultFontType::SANS,   // FNT_SANS
793     DefaultFontType::FIXED   // FNT_FIXED
794     //OpenSymbol,    // FNT_MATH
795 };
796 
797 // CJK default-fonts
798 //! we use non-asian fonts for variables, functions and numbers since they
799 //! look better and even in asia only latin letters will be used for those.
800 //! At least that's what I was told...
801 const DefaultFontType aCJKDefFnts[FNT_END] =
802 {
803     DefaultFontType::SERIF,          // FNT_VARIABLE
804     DefaultFontType::SERIF,          // FNT_FUNCTION
805     DefaultFontType::SERIF,          // FNT_NUMBER
806     DefaultFontType::CJK_TEXT,       // FNT_TEXT
807     DefaultFontType::CJK_TEXT,       // FNT_SERIF
808     DefaultFontType::CJK_DISPLAY,    // FNT_SANS
809     DefaultFontType::CJK_TEXT        // FNT_FIXED
810     //OpenSymbol,    // FNT_MATH
811 };
812 
813 // CTL default-fonts
814 const DefaultFontType aCTLDefFnts[FNT_END] =
815 {
816     DefaultFontType::CTL_TEXT,    // FNT_VARIABLE
817     DefaultFontType::CTL_TEXT,    // FNT_FUNCTION
818     DefaultFontType::CTL_TEXT,    // FNT_NUMBER
819     DefaultFontType::CTL_TEXT,    // FNT_TEXT
820     DefaultFontType::CTL_TEXT,    // FNT_SERIF
821     DefaultFontType::CTL_TEXT,    // FNT_SANS
822     DefaultFontType::CTL_TEXT     // FNT_FIXED
823     //OpenSymbol,    // FNT_MATH
824 };
825 
826 
lcl_GetDefaultFontName(LanguageType nLang,sal_uInt16 nIdent)827 OUString lcl_GetDefaultFontName( LanguageType nLang, sal_uInt16 nIdent )
828 {
829     assert(nIdent < FNT_END);
830     const DefaultFontType *pTable;
831     switch ( SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ) )
832     {
833         case SvtScriptType::LATIN :     pTable = aLatinDefFnts; break;
834         case SvtScriptType::ASIAN :     pTable = aCJKDefFnts; break;
835         case SvtScriptType::COMPLEX :   pTable = aCTLDefFnts; break;
836         default :
837             pTable = aLatinDefFnts;
838             SAL_WARN("starmath", "unknown script-type");
839     }
840 
841     return OutputDevice::GetDefaultFont(pTable[ nIdent ], nLang,
842                                         GetDefaultFontFlags::OnlyOne ).GetFamilyName();
843 }
844 
845 }
846 
847 
LoadFormat()848 void SmMathConfig::LoadFormat()
849 {
850     if (!pFormat)
851         pFormat.reset(new SmFormat);
852 
853 
854     Sequence< OUString > aNames = lcl_GetFormatPropertyNames();
855 
856     sal_Int32 nProps = aNames.getLength();
857 
858     Sequence< Any > aValues( GetProperties( aNames ) );
859     if (!(nProps  &&  aValues.getLength() == nProps))
860         return;
861 
862     const Any *pValues = aValues.getConstArray();
863     const Any *pVal = pValues;
864 
865     OUString    aTmpStr;
866     sal_Int16       nTmp16 = 0;
867     bool        bTmp = false;
868 
869     // StandardFormat/Textmode
870     if (pVal->hasValue()  &&  (*pVal >>= bTmp))
871         pFormat->SetTextmode( bTmp );
872     ++pVal;
873     // StandardFormat/GreekCharStyle
874     if (pVal->hasValue()  &&  (*pVal >>= nTmp16))
875         pFormat->SetGreekCharStyle( nTmp16 );
876     ++pVal;
877     // StandardFormat/ScaleNormalBracket
878     if (pVal->hasValue()  &&  (*pVal >>= bTmp))
879         pFormat->SetScaleNormalBrackets( bTmp );
880     ++pVal;
881     // StandardFormat/HorizontalAlignment
882     if (pVal->hasValue()  &&  (*pVal >>= nTmp16))
883         pFormat->SetHorAlign( static_cast<SmHorAlign>(nTmp16) );
884     ++pVal;
885     // StandardFormat/BaseSize
886     if (pVal->hasValue()  &&  (*pVal >>= nTmp16))
887         pFormat->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16 )) );
888     ++pVal;
889 
890     sal_uInt16 i;
891     for (i = SIZ_BEGIN;  i <= SIZ_END;  ++i)
892     {
893         if (pVal->hasValue()  &&  (*pVal >>= nTmp16))
894             pFormat->SetRelSize( i, nTmp16 );
895         ++pVal;
896     }
897 
898     for (i = DIS_BEGIN;  i <= DIS_END;  ++i)
899     {
900         if (pVal->hasValue()  &&  (*pVal >>= nTmp16))
901             pFormat->SetDistance( i, nTmp16 );
902         ++pVal;
903     }
904 
905     LanguageType nLang = Application::GetSettings().GetUILanguageTag().getLanguageType();
906     for (i = FNT_BEGIN;  i < FNT_END;  ++i)
907     {
908         vcl::Font aFnt;
909         bool bUseDefaultFont = true;
910         if (pVal->hasValue()  &&  (*pVal >>= aTmpStr))
911         {
912             bUseDefaultFont = aTmpStr.isEmpty();
913             if (bUseDefaultFont)
914             {
915                 aFnt = pFormat->GetFont( i );
916                 aFnt.SetFamilyName( lcl_GetDefaultFontName( nLang, i ) );
917             }
918             else
919             {
920                 const SmFontFormat *pFntFmt = GetFontFormatList().GetFontFormat( aTmpStr );
921                 OSL_ENSURE( pFntFmt, "unknown FontFormat" );
922                 if (pFntFmt)
923                     aFnt = pFntFmt->GetFont();
924             }
925         }
926         ++pVal;
927 
928         aFnt.SetFontSize( pFormat->GetBaseSize() );
929         pFormat->SetFont( i, aFnt, bUseDefaultFont );
930     }
931 
932     OSL_ENSURE( pVal - pValues == nProps, "property mismatch" );
933     SetFormatModified( false );
934 }
935 
936 
SaveFormat()937 void SmMathConfig::SaveFormat()
938 {
939     if (!pFormat || !IsFormatModified())
940         return;
941 
942     const Sequence< OUString > aNames = lcl_GetFormatPropertyNames();
943     sal_Int32 nProps = aNames.getLength();
944 
945     Sequence< Any > aValues( nProps );
946     Any *pValues = aValues.getArray();
947     Any *pValue  = pValues;
948 
949     // StandardFormat/Textmode
950     *pValue++ <<= pFormat->IsTextmode();
951     // StandardFormat/GreekCharStyle
952     *pValue++ <<= pFormat->GetGreekCharStyle();
953     // StandardFormat/ScaleNormalBracket
954     *pValue++ <<= pFormat->IsScaleNormalBrackets();
955     // StandardFormat/HorizontalAlignment
956     *pValue++ <<= static_cast<sal_Int16>(pFormat->GetHorAlign());
957     // StandardFormat/BaseSize
958     *pValue++ <<= static_cast<sal_Int16>(SmRoundFraction( Sm100th_mmToPts(
959                                     pFormat->GetBaseSize().Height() ) ));
960 
961     sal_uInt16 i;
962     for (i = SIZ_BEGIN;  i <= SIZ_END;  ++i)
963         *pValue++ <<= static_cast<sal_Int16>(pFormat->GetRelSize( i ));
964 
965     for (i = DIS_BEGIN;  i <= DIS_END;  ++i)
966         *pValue++ <<= static_cast<sal_Int16>(pFormat->GetDistance( i ));
967 
968     for (i = FNT_BEGIN;  i < FNT_END;  ++i)
969     {
970         OUString aFntFmtId;
971 
972         if (!pFormat->IsDefaultFont( i ))
973         {
974             SmFontFormat aFntFmt( pFormat->GetFont( i ) );
975             aFntFmtId = GetFontFormatList().GetFontFormatId( aFntFmt, true );
976             OSL_ENSURE( !aFntFmtId.isEmpty(), "FontFormatId not found" );
977         }
978 
979         *pValue++ <<= aFntFmtId;
980     }
981 
982     OSL_ENSURE( pValue - pValues == nProps, "property mismatch" );
983     PutProperties( aNames , aValues );
984 
985     SetFormatModified( false );
986 }
987 
988 
GetStandardFormat() const989 const SmFormat & SmMathConfig::GetStandardFormat() const
990 {
991     if (!pFormat)
992         const_cast<SmMathConfig*>(this)->LoadFormat();
993     return *pFormat;
994 }
995 
996 
SetStandardFormat(const SmFormat & rFormat,bool bSaveFontFormatList)997 void SmMathConfig::SetStandardFormat( const SmFormat &rFormat, bool bSaveFontFormatList )
998 {
999     if (!pFormat)
1000         LoadFormat();
1001     if (rFormat == *pFormat)
1002         return;
1003 
1004     *pFormat = rFormat;
1005     SetFormatModified( true );
1006     SaveFormat();
1007 
1008     if (bSaveFontFormatList)
1009     {
1010         // needed for SmFontTypeDialog's DefaultButtonClickHdl
1011         if (pFontFormatList)
1012             pFontFormatList->SetModified( true );
1013         SaveFontFormatList();
1014     }
1015 }
1016 
1017 
GetPrintSize() const1018 SmPrintSize SmMathConfig::GetPrintSize() const
1019 {
1020     if (!pOther)
1021         const_cast<SmMathConfig*>(this)->LoadOther();
1022     return pOther->ePrintSize;
1023 }
1024 
1025 
SetPrintSize(SmPrintSize eSize)1026 void SmMathConfig::SetPrintSize( SmPrintSize eSize )
1027 {
1028     if (!pOther)
1029         LoadOther();
1030     if (eSize != pOther->ePrintSize)
1031     {
1032         pOther->ePrintSize = eSize;
1033         SetOtherModified( true );
1034     }
1035 }
1036 
1037 
GetPrintZoomFactor() const1038 sal_uInt16 SmMathConfig::GetPrintZoomFactor() const
1039 {
1040     if (!pOther)
1041         const_cast<SmMathConfig*>(this)->LoadOther();
1042     return pOther->nPrintZoomFactor;
1043 }
1044 
1045 
SetPrintZoomFactor(sal_uInt16 nVal)1046 void SmMathConfig::SetPrintZoomFactor( sal_uInt16 nVal )
1047 {
1048     if (!pOther)
1049         LoadOther();
1050     if (nVal != pOther->nPrintZoomFactor)
1051     {
1052         pOther->nPrintZoomFactor = nVal;
1053         SetOtherModified( true );
1054     }
1055 }
1056 
1057 
SetOtherIfNotEqual(bool & rbItem,bool bNewVal)1058 void SmMathConfig::SetOtherIfNotEqual( bool &rbItem, bool bNewVal )
1059 {
1060     if (bNewVal != rbItem)
1061     {
1062         rbItem = bNewVal;
1063         SetOtherModified( true );
1064     }
1065 }
1066 
1067 
IsPrintTitle() const1068 bool SmMathConfig::IsPrintTitle() const
1069 {
1070     if (!pOther)
1071         const_cast<SmMathConfig*>(this)->LoadOther();
1072     return pOther->bPrintTitle;
1073 }
1074 
1075 
SetPrintTitle(bool bVal)1076 void SmMathConfig::SetPrintTitle( bool bVal )
1077 {
1078     if (!pOther)
1079         LoadOther();
1080     SetOtherIfNotEqual( pOther->bPrintTitle, bVal );
1081 }
1082 
1083 
IsPrintFormulaText() const1084 bool SmMathConfig::IsPrintFormulaText() const
1085 {
1086     if (!pOther)
1087         const_cast<SmMathConfig*>(this)->LoadOther();
1088     return pOther->bPrintFormulaText;
1089 }
1090 
1091 
SetPrintFormulaText(bool bVal)1092 void SmMathConfig::SetPrintFormulaText( bool bVal )
1093 {
1094     if (!pOther)
1095         LoadOther();
1096     SetOtherIfNotEqual( pOther->bPrintFormulaText, bVal );
1097 }
1098 
IsSaveOnlyUsedSymbols() const1099 bool SmMathConfig::IsSaveOnlyUsedSymbols() const
1100 {
1101     if (!pOther)
1102         const_cast<SmMathConfig*>(this)->LoadOther();
1103     return pOther->bIsSaveOnlyUsedSymbols;
1104 }
1105 
IsAutoCloseBrackets() const1106 bool SmMathConfig::IsAutoCloseBrackets() const
1107 {
1108     if (!pOther)
1109         const_cast<SmMathConfig*>(this)->LoadOther();
1110     return pOther->bIsAutoCloseBrackets;
1111 }
1112 
IsPrintFrame() const1113 bool SmMathConfig::IsPrintFrame() const
1114 {
1115     if (!pOther)
1116         const_cast<SmMathConfig*>(this)->LoadOther();
1117     return pOther->bPrintFrame;
1118 }
1119 
1120 
SetPrintFrame(bool bVal)1121 void SmMathConfig::SetPrintFrame( bool bVal )
1122 {
1123     if (!pOther)
1124         LoadOther();
1125     SetOtherIfNotEqual( pOther->bPrintFrame, bVal );
1126 }
1127 
1128 
SetSaveOnlyUsedSymbols(bool bVal)1129 void SmMathConfig::SetSaveOnlyUsedSymbols( bool bVal )
1130 {
1131     if (!pOther)
1132         LoadOther();
1133     SetOtherIfNotEqual( pOther->bIsSaveOnlyUsedSymbols, bVal );
1134 }
1135 
1136 
SetAutoCloseBrackets(bool bVal)1137 void SmMathConfig::SetAutoCloseBrackets( bool bVal )
1138 {
1139     if (!pOther)
1140         LoadOther();
1141     SetOtherIfNotEqual( pOther->bIsAutoCloseBrackets, bVal );
1142 }
1143 
1144 
IsIgnoreSpacesRight() const1145 bool SmMathConfig::IsIgnoreSpacesRight() const
1146 {
1147     if (!pOther)
1148         const_cast<SmMathConfig*>(this)->LoadOther();
1149     return pOther->bIgnoreSpacesRight;
1150 }
1151 
1152 
SetIgnoreSpacesRight(bool bVal)1153 void SmMathConfig::SetIgnoreSpacesRight( bool bVal )
1154 {
1155     if (!pOther)
1156         LoadOther();
1157     SetOtherIfNotEqual( pOther->bIgnoreSpacesRight, bVal );
1158 }
1159 
1160 
IsAutoRedraw() const1161 bool SmMathConfig::IsAutoRedraw() const
1162 {
1163     if (!pOther)
1164         const_cast<SmMathConfig*>(this)->LoadOther();
1165     return pOther->bAutoRedraw;
1166 }
1167 
1168 
SetAutoRedraw(bool bVal)1169 void SmMathConfig::SetAutoRedraw( bool bVal )
1170 {
1171     if (!pOther)
1172         LoadOther();
1173     SetOtherIfNotEqual( pOther->bAutoRedraw, bVal );
1174 }
1175 
1176 
IsShowFormulaCursor() const1177 bool SmMathConfig::IsShowFormulaCursor() const
1178 {
1179     if (!pOther)
1180         const_cast<SmMathConfig*>(this)->LoadOther();
1181     return pOther->bFormulaCursor;
1182 }
1183 
1184 
SetShowFormulaCursor(bool bVal)1185 void SmMathConfig::SetShowFormulaCursor( bool bVal )
1186 {
1187     if (!pOther)
1188         LoadOther();
1189     SetOtherIfNotEqual( pOther->bFormulaCursor, bVal );
1190 }
1191 
Notify(const css::uno::Sequence<OUString> &)1192 void SmMathConfig::Notify( const css::uno::Sequence< OUString >& )
1193 {}
1194 
1195 
ItemSetToConfig(const SfxItemSet & rSet)1196 void SmMathConfig::ItemSetToConfig(const SfxItemSet &rSet)
1197 {
1198     const SfxPoolItem *pItem     = nullptr;
1199 
1200     sal_uInt16 nU16;
1201     bool bVal;
1202     if (rSet.GetItemState(SID_PRINTSIZE, true, &pItem) == SfxItemState::SET)
1203     {   nU16 = static_cast<const SfxUInt16Item *>(pItem)->GetValue();
1204         SetPrintSize( static_cast<SmPrintSize>(nU16) );
1205     }
1206     if (rSet.GetItemState(SID_PRINTZOOM, true, &pItem) == SfxItemState::SET)
1207     {   nU16 = static_cast<const SfxUInt16Item *>(pItem)->GetValue();
1208         SetPrintZoomFactor( nU16 );
1209     }
1210     if (rSet.GetItemState(SID_PRINTTITLE, true, &pItem) == SfxItemState::SET)
1211     {   bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1212         SetPrintTitle( bVal );
1213     }
1214     if (rSet.GetItemState(SID_PRINTTEXT, true, &pItem) == SfxItemState::SET)
1215     {   bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1216         SetPrintFormulaText( bVal );
1217     }
1218     if (rSet.GetItemState(SID_PRINTFRAME, true, &pItem) == SfxItemState::SET)
1219     {   bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1220         SetPrintFrame( bVal );
1221     }
1222     if (rSet.GetItemState(SID_AUTOREDRAW, true, &pItem) == SfxItemState::SET)
1223     {   bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1224         SetAutoRedraw( bVal );
1225     }
1226     if (rSet.GetItemState(SID_NO_RIGHT_SPACES, true, &pItem) == SfxItemState::SET)
1227     {   bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1228         if (IsIgnoreSpacesRight() != bVal)
1229         {
1230             SetIgnoreSpacesRight( bVal );
1231 
1232             // reformat (displayed) formulas accordingly
1233             Broadcast(SfxHint(SfxHintId::MathFormatChanged));
1234         }
1235     }
1236     if (rSet.GetItemState(SID_SAVE_ONLY_USED_SYMBOLS, true, &pItem) == SfxItemState::SET)
1237     {   bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1238         SetSaveOnlyUsedSymbols( bVal );
1239     }
1240 
1241     if (rSet.GetItemState(SID_AUTO_CLOSE_BRACKETS, true, &pItem) == SfxItemState::SET)
1242     {
1243         bVal = static_cast<const SfxBoolItem *>(pItem)->GetValue();
1244         SetAutoCloseBrackets( bVal );
1245     }
1246 
1247     SaveOther();
1248 }
1249 
1250 
ConfigToItemSet(SfxItemSet & rSet) const1251 void SmMathConfig::ConfigToItemSet(SfxItemSet &rSet) const
1252 {
1253     const SfxItemPool *pPool = rSet.GetPool();
1254 
1255     rSet.Put(SfxUInt16Item(pPool->GetWhich(SID_PRINTSIZE),
1256                            sal::static_int_cast<sal_uInt16>(GetPrintSize())));
1257     rSet.Put(SfxUInt16Item(pPool->GetWhich(SID_PRINTZOOM),
1258                            GetPrintZoomFactor()));
1259 
1260     rSet.Put(SfxBoolItem(pPool->GetWhich(SID_PRINTTITLE), IsPrintTitle()));
1261     rSet.Put(SfxBoolItem(pPool->GetWhich(SID_PRINTTEXT),  IsPrintFormulaText()));
1262     rSet.Put(SfxBoolItem(pPool->GetWhich(SID_PRINTFRAME), IsPrintFrame()));
1263     rSet.Put(SfxBoolItem(pPool->GetWhich(SID_AUTOREDRAW), IsAutoRedraw()));
1264     rSet.Put(SfxBoolItem(pPool->GetWhich(SID_NO_RIGHT_SPACES), IsIgnoreSpacesRight()));
1265     rSet.Put(SfxBoolItem(pPool->GetWhich(SID_SAVE_ONLY_USED_SYMBOLS), IsSaveOnlyUsedSymbols()));
1266     rSet.Put(SfxBoolItem(pPool->GetWhich(SID_AUTO_CLOSE_BRACKETS), IsAutoCloseBrackets()));
1267 }
1268 
1269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1270