1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <svl/itemset.hxx>
23 #include <svl/stritem.hxx>
24 #include <svl/intitem.hxx>
25 #include <svl/itempool.hxx>
26 #include <svl/eitem.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/settings.hxx>
30 #include <sal/macros.h>
31 #include <officecfg/Office/Math.hxx>
32 #include "cfgitem.hxx"
34 #include "starmath.hrc"
39 using namespace com::sun::star::uno
;
40 using namespace com::sun::star::beans
;
42 #define SYMBOL_LIST "SymbolList"
43 #define FONT_FORMAT_LIST "FontFormatList"
45 static Sequence
< OUString
> lcl_GetFontPropertyNames()
47 return Sequence
< OUString
> {
57 static Sequence
< OUString
> lcl_GetSymbolPropertyNames()
59 return Sequence
< OUString
> {
67 static Sequence
< OUString
> lcl_GetFormatPropertyNames()
69 //! Beware of order according to *_BEGIN *_END defines in format.hxx !
70 //! see respective load/save routines here
71 return Sequence
< OUString
> {
72 "StandardFormat/Textmode",
73 "StandardFormat/GreekCharStyle",
74 "StandardFormat/ScaleNormalBracket",
75 "StandardFormat/HorizontalAlignment",
76 "StandardFormat/BaseSize",
77 "StandardFormat/TextSize",
78 "StandardFormat/IndexSize",
79 "StandardFormat/FunctionSize",
80 "StandardFormat/OperatorSize",
81 "StandardFormat/LimitsSize",
82 "StandardFormat/Distance/Horizontal",
83 "StandardFormat/Distance/Vertical",
84 "StandardFormat/Distance/Root",
85 "StandardFormat/Distance/SuperScript",
86 "StandardFormat/Distance/SubScript",
87 "StandardFormat/Distance/Numerator",
88 "StandardFormat/Distance/Denominator",
89 "StandardFormat/Distance/Fraction",
90 "StandardFormat/Distance/StrokeWidth",
91 "StandardFormat/Distance/UpperLimit",
92 "StandardFormat/Distance/LowerLimit",
93 "StandardFormat/Distance/BracketSize",
94 "StandardFormat/Distance/BracketSpace",
95 "StandardFormat/Distance/MatrixRow",
96 "StandardFormat/Distance/MatrixColumn",
97 "StandardFormat/Distance/OrnamentSize",
98 "StandardFormat/Distance/OrnamentSpace",
99 "StandardFormat/Distance/OperatorSize",
100 "StandardFormat/Distance/OperatorSpace",
101 "StandardFormat/Distance/LeftSpace",
102 "StandardFormat/Distance/RightSpace",
103 "StandardFormat/Distance/TopSpace",
104 "StandardFormat/Distance/BottomSpace",
105 "StandardFormat/Distance/NormalBracketSize",
106 "StandardFormat/VariableFont",
107 "StandardFormat/FunctionFont",
108 "StandardFormat/NumberFont",
109 "StandardFormat/TextFont",
110 "StandardFormat/SerifFont",
111 "StandardFormat/SansFont",
112 "StandardFormat/FixedFont"
118 SmPrintSize ePrintSize
;
119 sal_uInt16 nPrintZoomFactor
;
121 bool bPrintFormulaText
;
123 bool bIsSaveOnlyUsedSymbols
;
124 bool bIsAutoCloseBrackets
;
125 bool bIgnoreSpacesRight
;
126 bool bToolboxVisible
;
134 SmCfgOther::SmCfgOther()
135 : ePrintSize(PRINT_SIZE_NORMAL
)
136 , nPrintZoomFactor(100)
138 , bPrintFormulaText(true)
140 , bIsSaveOnlyUsedSymbols(true)
141 , bIsAutoCloseBrackets(true)
142 , bIgnoreSpacesRight(true)
143 , bToolboxVisible(true)
145 , bFormulaCursor(true)
150 SmFontFormat::SmFontFormat()
151 : aName(FONTNAME_MATH
)
152 , nCharSet(RTL_TEXTENCODING_UNICODE
)
153 , nFamily(FAMILY_DONTKNOW
)
154 , nPitch(PITCH_DONTKNOW
)
155 , nWeight(WEIGHT_DONTKNOW
)
156 , nItalic(ITALIC_NONE
)
161 SmFontFormat::SmFontFormat( const vcl::Font
&rFont
)
162 : aName(rFont
.GetFamilyName())
163 , nCharSet(static_cast<sal_Int16
>(rFont
.GetCharSet()))
164 , nFamily(static_cast<sal_Int16
>(rFont
.GetFamilyType()))
165 , nPitch(static_cast<sal_Int16
>(rFont
.GetPitch()))
166 , nWeight(static_cast<sal_Int16
>(rFont
.GetWeight()))
167 , nItalic(static_cast<sal_Int16
>(rFont
.GetItalic()))
172 const vcl::Font
SmFontFormat::GetFont() const
175 aRes
.SetFamilyName( aName
);
176 aRes
.SetCharSet( static_cast<rtl_TextEncoding
>(nCharSet
) );
177 aRes
.SetFamily( static_cast<FontFamily
>(nFamily
) );
178 aRes
.SetPitch( static_cast<FontPitch
>(nPitch
) );
179 aRes
.SetWeight( static_cast<FontWeight
>(nWeight
) );
180 aRes
.SetItalic( static_cast<FontItalic
>(nItalic
) );
185 bool SmFontFormat::operator == ( const SmFontFormat
&rFntFmt
) const
187 return aName
== rFntFmt
.aName
&&
188 nCharSet
== rFntFmt
.nCharSet
&&
189 nFamily
== rFntFmt
.nFamily
&&
190 nPitch
== rFntFmt
.nPitch
&&
191 nWeight
== rFntFmt
.nWeight
&&
192 nItalic
== rFntFmt
.nItalic
;
196 SmFntFmtListEntry::SmFntFmtListEntry( const OUString
&rId
, const SmFontFormat
&rFntFmt
) :
203 SmFontFormatList::SmFontFormatList()
209 void SmFontFormatList::Clear()
211 if (!aEntries
.empty())
219 void SmFontFormatList::AddFontFormat( const OUString
&rFntFmtId
,
220 const SmFontFormat
&rFntFmt
)
222 const SmFontFormat
*pFntFmt
= GetFontFormat( rFntFmtId
);
223 OSL_ENSURE( !pFntFmt
, "FontFormatId already exists" );
226 SmFntFmtListEntry
aEntry( rFntFmtId
, rFntFmt
);
227 aEntries
.push_back( aEntry
);
233 void SmFontFormatList::RemoveFontFormat( const OUString
&rFntFmtId
)
237 for (size_t i
= 0; i
< aEntries
.size(); ++i
)
239 if (aEntries
[i
].aId
== rFntFmtId
)
241 // remove entry if found
242 aEntries
.erase( aEntries
.begin() + i
);
250 const SmFontFormat
* SmFontFormatList::GetFontFormat( const OUString
&rFntFmtId
) const
252 const SmFontFormat
*pRes
= nullptr;
254 for (const auto & rEntry
: aEntries
)
256 if (rEntry
.aId
== rFntFmtId
)
258 pRes
= &rEntry
.aFntFmt
;
267 const SmFontFormat
* SmFontFormatList::GetFontFormat( size_t nPos
) const
269 const SmFontFormat
*pRes
= nullptr;
270 if (nPos
< aEntries
.size())
271 pRes
= &aEntries
[nPos
].aFntFmt
;
276 const OUString
SmFontFormatList::GetFontFormatId( const SmFontFormat
&rFntFmt
) const
280 for (const auto & rEntry
: aEntries
)
282 if (rEntry
.aFntFmt
== rFntFmt
)
293 const OUString
SmFontFormatList::GetFontFormatId( const SmFontFormat
&rFntFmt
, bool bAdd
)
295 OUString
aRes( GetFontFormatId( rFntFmt
) );
296 if (aRes
.isEmpty() && bAdd
)
298 aRes
= GetNewFontFormatId();
299 AddFontFormat( aRes
, rFntFmt
);
305 const OUString
SmFontFormatList::GetFontFormatId( size_t nPos
) const
308 if (nPos
< aEntries
.size())
309 aRes
= aEntries
[nPos
].aId
;
314 const OUString
SmFontFormatList::GetNewFontFormatId() const
316 // returns first unused FormatId
318 OUString
aPrefix("Id");
319 sal_Int32 nCnt
= GetCount();
320 for (sal_Int32 i
= 1; i
<= nCnt
+ 1; ++i
)
322 OUString aTmpId
= aPrefix
+ OUString::number(i
);
323 if (!GetFontFormat(aTmpId
))
326 OSL_ENSURE( false, "failed to create new FontFormatId" );
332 SmMathConfig::SmMathConfig() :
333 ConfigItem(OUString("Office.Math"))
338 , bIsOtherModified(false)
339 , bIsFormatModified(false)
344 SmMathConfig::~SmMathConfig()
350 void SmMathConfig::SetOtherModified( bool bVal
)
352 bIsOtherModified
= bVal
;
356 void SmMathConfig::SetFormatModified( bool bVal
)
358 bIsFormatModified
= bVal
;
362 void SmMathConfig::ReadSymbol( SmSym
&rSymbol
,
363 const OUString
&rSymbolName
,
364 const OUString
&rBaseNode
) const
366 Sequence
< OUString
> aNames
= lcl_GetSymbolPropertyNames();
367 sal_Int32 nProps
= aNames
.getLength();
369 OUString
aDelim( "/" );
370 OUString
*pName
= aNames
.getArray();
371 for (sal_Int32 i
= 0; i
< nProps
; ++i
)
373 OUString
&rName
= pName
[i
];
374 OUString
aTmp( rName
);
377 rName
+= rSymbolName
;
382 const Sequence
< Any
> aValues
= const_cast<SmMathConfig
*>(this)->GetProperties(aNames
);
384 if (nProps
&& aValues
.getLength() == nProps
)
386 const Any
* pValue
= aValues
.getConstArray();
388 sal_UCS4 cChar
= '\0';
390 bool bPredefined
= false;
393 sal_Int32 nTmp32
= 0;
397 if (pValue
->hasValue() && (*pValue
>>= nTmp32
))
398 cChar
= static_cast< sal_UCS4
>( nTmp32
);
402 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
407 if (pValue
->hasValue() && (*pValue
>>= bTmp
))
412 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
414 const SmFontFormat
*pFntFmt
= GetFontFormatList().GetFontFormat( aTmpStr
);
415 OSL_ENSURE( pFntFmt
, "unknown FontFormat" );
417 aFont
= pFntFmt
->GetFont();
425 OUString
aUiName( rSymbolName
);
426 OUString
aUiSetName( aSet
);
430 aTmp
= SmLocalizedSymbolData::GetUiSymbolName( rSymbolName
);
431 OSL_ENSURE( !aTmp
.isEmpty(), "localized symbol-name not found" );
434 aTmp
= SmLocalizedSymbolData::GetUiSymbolSetName( aSet
);
435 OSL_ENSURE( !aTmp
.isEmpty(), "localized symbolset-name not found" );
440 rSymbol
= SmSym( aUiName
, aFont
, cChar
, aUiSetName
, bPredefined
);
441 if (aUiName
!= rSymbolName
)
442 rSymbol
.SetExportName( rSymbolName
);
446 SAL_WARN("starmath", "symbol read error");
452 SmSymbolManager
& SmMathConfig::GetSymbolManager()
456 pSymbolMgr
.reset(new SmSymbolManager
);
463 void SmMathConfig::ImplCommit()
469 void SmMathConfig::Save()
473 SaveFontFormatList();
477 void SmMathConfig::GetSymbols( std::vector
< SmSym
> &rSymbols
) const
479 Sequence
< OUString
> aNodes(const_cast<SmMathConfig
*>(this)->GetNodeNames(SYMBOL_LIST
));
480 const OUString
*pNode
= aNodes
.getConstArray();
481 sal_Int32 nNodes
= aNodes
.getLength();
483 rSymbols
.resize( nNodes
);
484 std::vector
< SmSym
>::iterator
aIt( rSymbols
.begin() );
485 std::vector
< SmSym
>::iterator
aEnd( rSymbols
.end() );
488 ReadSymbol( *aIt
++, *pNode
++, SYMBOL_LIST
);
493 void SmMathConfig::SetSymbols( const std::vector
< SmSym
> &rNewSymbols
)
495 sal_uIntPtr nCount
= rNewSymbols
.size();
497 Sequence
< OUString
> aNames
= lcl_GetSymbolPropertyNames();
498 const OUString
*pNames
= aNames
.getConstArray();
499 sal_uIntPtr nSymbolProps
= sal::static_int_cast
< sal_uInt32
>(aNames
.getLength());
501 Sequence
< PropertyValue
> aValues( nCount
* nSymbolProps
);
502 PropertyValue
*pValues
= aValues
.getArray();
504 PropertyValue
*pVal
= pValues
;
505 OUString
aDelim( "/" );
506 std::vector
< SmSym
>::const_iterator
aIt( rNewSymbols
.begin() );
507 std::vector
< SmSym
>::const_iterator
aEnd( rNewSymbols
.end() );
510 const SmSym
&rSymbol
= *aIt
++;
511 OUString
aNodeNameDelim( SYMBOL_LIST
);
512 aNodeNameDelim
+= aDelim
;
513 aNodeNameDelim
+= rSymbol
.GetExportName();
514 aNodeNameDelim
+= aDelim
;
516 const OUString
*pName
= pNames
;
519 pVal
->Name
= aNodeNameDelim
;
520 pVal
->Name
+= *pName
++;
521 pVal
->Value
<<= static_cast< sal_UCS4
>( rSymbol
.GetCharacter() );
524 pVal
->Name
= aNodeNameDelim
;
525 pVal
->Name
+= *pName
++;
526 OUString
aTmp( rSymbol
.GetSymbolSetName() );
527 if (rSymbol
.IsPredefined())
528 aTmp
= SmLocalizedSymbolData::GetExportSymbolSetName( aTmp
);
529 pVal
->Value
<<= aTmp
;
532 pVal
->Name
= aNodeNameDelim
;
533 pVal
->Name
+= *pName
++;
534 pVal
->Value
<<= rSymbol
.IsPredefined();
537 SmFontFormat
aFntFmt( rSymbol
.GetFace() );
538 OUString
aFntFmtId( GetFontFormatList().GetFontFormatId( aFntFmt
, true ) );
539 OSL_ENSURE( !aFntFmtId
.isEmpty(), "FontFormatId not found" );
540 pVal
->Name
= aNodeNameDelim
;
541 pVal
->Name
+= *pName
++;
542 pVal
->Value
<<= aFntFmtId
;
545 OSL_ENSURE( pVal
- pValues
== sal::static_int_cast
< ptrdiff_t >(nCount
* nSymbolProps
), "properties missing" );
546 ReplaceSetProperties( SYMBOL_LIST
, aValues
);
548 StripFontFormatList( rNewSymbols
);
549 SaveFontFormatList();
553 SmFontFormatList
& SmMathConfig::GetFontFormatList()
555 if (!pFontFormatList
)
557 LoadFontFormatList();
559 return *pFontFormatList
;
563 void SmMathConfig::LoadFontFormatList()
565 if (!pFontFormatList
)
566 pFontFormatList
.reset(new SmFontFormatList
);
568 pFontFormatList
->Clear();
570 Sequence
< OUString
> aNodes( GetNodeNames( FONT_FORMAT_LIST
) );
571 const OUString
*pNode
= aNodes
.getConstArray();
572 sal_Int32 nNodes
= aNodes
.getLength();
574 for (sal_Int32 i
= 0; i
< nNodes
; ++i
)
576 SmFontFormat aFntFmt
;
577 ReadFontFormat( aFntFmt
, pNode
[i
], FONT_FORMAT_LIST
);
578 if (!pFontFormatList
->GetFontFormat( pNode
[i
] ))
580 OSL_ENSURE( nullptr == pFontFormatList
->GetFontFormat( pNode
[i
] ),
581 "FontFormat ID already exists" );
582 pFontFormatList
->AddFontFormat( pNode
[i
], aFntFmt
);
585 pFontFormatList
->SetModified( false );
589 void SmMathConfig::ReadFontFormat( SmFontFormat
&rFontFormat
,
590 const OUString
&rSymbolName
, const OUString
&rBaseNode
) const
592 Sequence
< OUString
> aNames
= lcl_GetFontPropertyNames();
593 sal_Int32 nProps
= aNames
.getLength();
595 OUString
aDelim( "/" );
596 OUString
*pName
= aNames
.getArray();
597 for (sal_Int32 i
= 0; i
< nProps
; ++i
)
599 OUString
&rName
= pName
[i
];
600 OUString
aTmp( rName
);
603 rName
+= rSymbolName
;
608 const Sequence
< Any
> aValues
= const_cast<SmMathConfig
*>(this)->GetProperties(aNames
);
610 if (nProps
&& aValues
.getLength() == nProps
)
612 const Any
* pValue
= aValues
.getConstArray();
615 sal_Int16 nTmp16
= 0;
618 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
619 rFontFormat
.aName
= aTmpStr
;
623 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
624 rFontFormat
.nCharSet
= nTmp16
; // 6.0 file-format GetSOLoadTextEncoding not needed
628 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
629 rFontFormat
.nFamily
= nTmp16
;
633 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
634 rFontFormat
.nPitch
= nTmp16
;
638 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
639 rFontFormat
.nWeight
= nTmp16
;
643 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
644 rFontFormat
.nItalic
= nTmp16
;
649 OSL_ENSURE( bOK
, "read FontFormat failed" );
655 void SmMathConfig::SaveFontFormatList()
657 SmFontFormatList
&rFntFmtList
= GetFontFormatList();
659 if (!rFntFmtList
.IsModified())
662 Sequence
< OUString
> aNames
= lcl_GetFontPropertyNames();
663 sal_Int32 nSymbolProps
= aNames
.getLength();
665 size_t nCount
= rFntFmtList
.GetCount();
667 Sequence
< PropertyValue
> aValues( nCount
* nSymbolProps
);
668 PropertyValue
*pValues
= aValues
.getArray();
670 PropertyValue
*pVal
= pValues
;
671 OUString
aDelim( "/" );
672 for (size_t i
= 0; i
< nCount
; ++i
)
674 OUString
aFntFmtId(rFntFmtList
.GetFontFormatId(i
));
675 const SmFontFormat
*pFntFmt
= rFntFmtList
.GetFontFormat(i
);
677 const SmFontFormat
aFntFmt(*pFntFmt
);
679 OUString
aNodeNameDelim( FONT_FORMAT_LIST
);
680 aNodeNameDelim
+= aDelim
;
681 aNodeNameDelim
+= aFntFmtId
;
682 aNodeNameDelim
+= aDelim
;
684 const OUString
*pName
= aNames
.getConstArray();
687 pVal
->Name
= aNodeNameDelim
;
688 pVal
->Name
+= *pName
++;
689 pVal
->Value
<<= OUString( aFntFmt
.aName
);
692 pVal
->Name
= aNodeNameDelim
;
693 pVal
->Name
+= *pName
++;
694 pVal
->Value
<<= static_cast<sal_Int16
>(aFntFmt
.nCharSet
); // 6.0 file-format GetSOStoreTextEncoding not needed
697 pVal
->Name
= aNodeNameDelim
;
698 pVal
->Name
+= *pName
++;
699 pVal
->Value
<<= static_cast<sal_Int16
>(aFntFmt
.nFamily
);
702 pVal
->Name
= aNodeNameDelim
;
703 pVal
->Name
+= *pName
++;
704 pVal
->Value
<<= static_cast<sal_Int16
>(aFntFmt
.nPitch
);
707 pVal
->Name
= aNodeNameDelim
;
708 pVal
->Name
+= *pName
++;
709 pVal
->Value
<<= static_cast<sal_Int16
>(aFntFmt
.nWeight
);
712 pVal
->Name
= aNodeNameDelim
;
713 pVal
->Name
+= *pName
++;
714 pVal
->Value
<<= static_cast<sal_Int16
>(aFntFmt
.nItalic
);
717 OSL_ENSURE( sal::static_int_cast
<size_t>(pVal
- pValues
) == nCount
* nSymbolProps
, "properties missing" );
718 ReplaceSetProperties( FONT_FORMAT_LIST
, aValues
);
720 rFntFmtList
.SetModified( false );
724 void SmMathConfig::StripFontFormatList( const std::vector
< SmSym
> &rSymbols
)
728 // build list of used font-formats only
729 //!! font-format IDs may be different !!
730 SmFontFormatList aUsedList
;
731 for (i
= 0; i
< rSymbols
.size(); ++i
)
733 OSL_ENSURE( rSymbols
[i
].GetName().getLength() > 0, "non named symbol" );
734 aUsedList
.GetFontFormatId( SmFontFormat( rSymbols
[i
].GetFace() ) , true );
736 const SmFormat
& rStdFmt
= GetStandardFormat();
737 for (i
= FNT_BEGIN
; i
<= FNT_END
; ++i
)
739 aUsedList
.GetFontFormatId( SmFontFormat( rStdFmt
.GetFont( i
) ) , true );
742 // remove unused font-formats from list
743 SmFontFormatList
&rFntFmtList
= GetFontFormatList();
744 size_t nCnt
= rFntFmtList
.GetCount();
745 std::unique_ptr
<SmFontFormat
[]> pTmpFormat(new SmFontFormat
[ nCnt
]);
746 std::unique_ptr
<OUString
[]> pId(new OUString
[ nCnt
]);
748 for (k
= 0; k
< nCnt
; ++k
)
750 pTmpFormat
[k
] = *rFntFmtList
.GetFontFormat( k
);
751 pId
[k
] = rFntFmtList
.GetFontFormatId( k
);
753 for (k
= 0; k
< nCnt
; ++k
)
755 if (aUsedList
.GetFontFormatId( pTmpFormat
[k
] ).isEmpty())
757 rFntFmtList
.RemoveFontFormat( pId
[k
] );
763 void SmMathConfig::LoadOther()
766 pOther
.reset(new SmCfgOther
);
768 pOther
->bPrintTitle
= officecfg::Office::Math::Print::Title::get();
769 pOther
->bPrintFormulaText
= officecfg::Office::Math::Print::FormulaText::get();
770 pOther
->bPrintFrame
= officecfg::Office::Math::Print::Frame::get();
771 pOther
->ePrintSize
= static_cast<SmPrintSize
>(officecfg::Office::Math::Print::Size::get());
772 pOther
->nPrintZoomFactor
= officecfg::Office::Math::Print::ZoomFactor::get();
773 pOther
->bIsSaveOnlyUsedSymbols
= officecfg::Office::Math::LoadSave::IsSaveOnlyUsedSymbols::get();
774 pOther
->bIsAutoCloseBrackets
= officecfg::Office::Math::Misc::AutoCloseBrackets::get();
775 pOther
->bIgnoreSpacesRight
= officecfg::Office::Math::Misc::IgnoreSpacesRight::get();
776 pOther
->bToolboxVisible
= officecfg::Office::Math::View::ToolboxVisible::get();
777 pOther
->bAutoRedraw
= officecfg::Office::Math::View::AutoRedraw::get();
778 pOther
->bFormulaCursor
= officecfg::Office::Math::View::FormulaCursor::get();
779 SetOtherModified( false );
783 void SmMathConfig::SaveOther()
785 if (!pOther
|| !IsOtherModified())
788 std::shared_ptr
<comphelper::ConfigurationChanges
> batch(comphelper::ConfigurationChanges::create());
790 officecfg::Office::Math::Print::Title::set(pOther
->bPrintTitle
, batch
);
791 officecfg::Office::Math::Print::FormulaText::set(pOther
->bPrintFormulaText
, batch
);
792 officecfg::Office::Math::Print::Frame::set(pOther
->bPrintFrame
, batch
);
793 officecfg::Office::Math::Print::Size::set(pOther
->ePrintSize
, batch
);
794 officecfg::Office::Math::Print::ZoomFactor::set(pOther
->nPrintZoomFactor
, batch
);
795 officecfg::Office::Math::LoadSave::IsSaveOnlyUsedSymbols::set(pOther
->bIsSaveOnlyUsedSymbols
, batch
);
796 officecfg::Office::Math::Misc::AutoCloseBrackets::set(pOther
->bIsAutoCloseBrackets
, batch
);
797 officecfg::Office::Math::Misc::IgnoreSpacesRight::set(pOther
->bIgnoreSpacesRight
, batch
);
798 officecfg::Office::Math::View::ToolboxVisible::set(pOther
->bToolboxVisible
, batch
);
799 officecfg::Office::Math::View::AutoRedraw::set(pOther
->bAutoRedraw
, batch
);
800 officecfg::Office::Math::View::FormulaCursor::set(pOther
->bFormulaCursor
, batch
);
803 SetOtherModified( false );
806 void SmMathConfig::LoadFormat()
809 pFormat
.reset(new SmFormat
);
812 Sequence
< OUString
> aNames
= lcl_GetFormatPropertyNames();
814 sal_Int32 nProps
= aNames
.getLength();
816 Sequence
< Any
> aValues( GetProperties( aNames
) );
817 if (nProps
&& aValues
.getLength() == nProps
)
819 const Any
*pValues
= aValues
.getConstArray();
820 const Any
*pVal
= pValues
;
823 sal_Int16 nTmp16
= 0;
826 // StandardFormat/Textmode
827 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
828 pFormat
->SetTextmode( bTmp
);
830 // StandardFormat/GreekCharStyle
831 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
832 pFormat
->SetGreekCharStyle( nTmp16
);
834 // StandardFormat/ScaleNormalBracket
835 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
836 pFormat
->SetScaleNormalBrackets( bTmp
);
838 // StandardFormat/HorizontalAlignment
839 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
840 pFormat
->SetHorAlign( static_cast<SmHorAlign
>(nTmp16
) );
842 // StandardFormat/BaseSize
843 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
844 pFormat
->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16
)) );
848 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; ++i
)
850 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
851 pFormat
->SetRelSize( i
, nTmp16
);
855 for (i
= DIS_BEGIN
; i
<= DIS_END
; ++i
)
857 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
858 pFormat
->SetDistance( i
, nTmp16
);
862 LanguageType nLang
= Application::GetSettings().GetUILanguageTag().getLanguageType();
863 for (i
= FNT_BEGIN
; i
< FNT_END
; ++i
)
866 bool bUseDefaultFont
= true;
867 if (pVal
->hasValue() && (*pVal
>>= aTmpStr
))
869 bUseDefaultFont
= aTmpStr
.isEmpty();
872 aFnt
= pFormat
->GetFont( i
);
873 aFnt
.SetFamilyName( GetDefaultFontName( nLang
, i
) );
877 const SmFontFormat
*pFntFmt
= GetFontFormatList().GetFontFormat( aTmpStr
);
878 OSL_ENSURE( pFntFmt
, "unknown FontFormat" );
880 aFnt
= pFntFmt
->GetFont();
885 aFnt
.SetFontSize( pFormat
->GetBaseSize() );
886 pFormat
->SetFont( i
, aFnt
, bUseDefaultFont
);
889 OSL_ENSURE( pVal
- pValues
== nProps
, "property mismatch" );
890 SetFormatModified( false );
895 void SmMathConfig::SaveFormat()
897 if (!pFormat
|| !IsFormatModified())
900 const Sequence
< OUString
> aNames
= lcl_GetFormatPropertyNames();
901 sal_Int32 nProps
= aNames
.getLength();
903 Sequence
< Any
> aValues( nProps
);
904 Any
*pValues
= aValues
.getArray();
905 Any
*pValue
= pValues
;
907 // StandardFormat/Textmode
908 *pValue
++ <<= pFormat
->IsTextmode();
909 // StandardFormat/GreekCharStyle
910 *pValue
++ <<= static_cast<sal_Int16
>(pFormat
->GetGreekCharStyle());
911 // StandardFormat/ScaleNormalBracket
912 *pValue
++ <<= pFormat
->IsScaleNormalBrackets();
913 // StandardFormat/HorizontalAlignment
914 *pValue
++ <<= static_cast<sal_Int16
>(pFormat
->GetHorAlign());
915 // StandardFormat/BaseSize
916 *pValue
++ <<= static_cast<sal_Int16
>(SmRoundFraction( Sm100th_mmToPts(
917 pFormat
->GetBaseSize().Height() ) ));
920 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; ++i
)
921 *pValue
++ <<= static_cast<sal_Int16
>(pFormat
->GetRelSize( i
));
923 for (i
= DIS_BEGIN
; i
<= DIS_END
; ++i
)
924 *pValue
++ <<= static_cast<sal_Int16
>(pFormat
->GetDistance( i
));
926 for (i
= FNT_BEGIN
; i
< FNT_END
; ++i
)
930 if (!pFormat
->IsDefaultFont( i
))
932 SmFontFormat
aFntFmt( pFormat
->GetFont( i
) );
933 aFntFmtId
= GetFontFormatList().GetFontFormatId( aFntFmt
, true );
934 OSL_ENSURE( !aFntFmtId
.isEmpty(), "FontFormatId not found" );
937 *pValue
++ <<= aFntFmtId
;
940 OSL_ENSURE( pValue
- pValues
== nProps
, "property mismatch" );
941 PutProperties( aNames
, aValues
);
943 SetFormatModified( false );
947 const SmFormat
& SmMathConfig::GetStandardFormat() const
950 const_cast<SmMathConfig
*>(this)->LoadFormat();
955 void SmMathConfig::SetStandardFormat( const SmFormat
&rFormat
, bool bSaveFontFormatList
)
959 if (rFormat
!= *pFormat
)
962 SetFormatModified( true );
965 if (bSaveFontFormatList
)
967 // needed for SmFontTypeDialog's DefaultButtonClickHdl
969 pFontFormatList
->SetModified( true );
970 SaveFontFormatList();
976 SmPrintSize
SmMathConfig::GetPrintSize() const
979 const_cast<SmMathConfig
*>(this)->LoadOther();
980 return pOther
->ePrintSize
;
984 void SmMathConfig::SetPrintSize( SmPrintSize eSize
)
988 if (eSize
!= pOther
->ePrintSize
)
990 pOther
->ePrintSize
= eSize
;
991 SetOtherModified( true );
996 sal_uInt16
SmMathConfig::GetPrintZoomFactor() const
999 const_cast<SmMathConfig
*>(this)->LoadOther();
1000 return pOther
->nPrintZoomFactor
;
1004 void SmMathConfig::SetPrintZoomFactor( sal_uInt16 nVal
)
1008 if (nVal
!= pOther
->nPrintZoomFactor
)
1010 pOther
->nPrintZoomFactor
= nVal
;
1011 SetOtherModified( true );
1016 void SmMathConfig::SetOtherIfNotEqual( bool &rbItem
, bool bNewVal
)
1018 if (bNewVal
!= rbItem
)
1021 SetOtherModified( true );
1026 bool SmMathConfig::IsPrintTitle() const
1029 const_cast<SmMathConfig
*>(this)->LoadOther();
1030 return pOther
->bPrintTitle
;
1034 void SmMathConfig::SetPrintTitle( bool bVal
)
1038 SetOtherIfNotEqual( pOther
->bPrintTitle
, bVal
);
1042 bool SmMathConfig::IsPrintFormulaText() const
1045 const_cast<SmMathConfig
*>(this)->LoadOther();
1046 return pOther
->bPrintFormulaText
;
1050 void SmMathConfig::SetPrintFormulaText( bool bVal
)
1054 SetOtherIfNotEqual( pOther
->bPrintFormulaText
, bVal
);
1057 bool SmMathConfig::IsSaveOnlyUsedSymbols() const
1060 const_cast<SmMathConfig
*>(this)->LoadOther();
1061 return pOther
->bIsSaveOnlyUsedSymbols
;
1064 bool SmMathConfig::IsAutoCloseBrackets() const
1067 const_cast<SmMathConfig
*>(this)->LoadOther();
1068 return pOther
->bIsAutoCloseBrackets
;
1071 bool SmMathConfig::IsPrintFrame() const
1074 const_cast<SmMathConfig
*>(this)->LoadOther();
1075 return pOther
->bPrintFrame
;
1079 void SmMathConfig::SetPrintFrame( bool bVal
)
1083 SetOtherIfNotEqual( pOther
->bPrintFrame
, bVal
);
1087 void SmMathConfig::SetSaveOnlyUsedSymbols( bool bVal
)
1091 SetOtherIfNotEqual( pOther
->bIsSaveOnlyUsedSymbols
, bVal
);
1095 void SmMathConfig::SetAutoCloseBrackets( bool bVal
)
1099 SetOtherIfNotEqual( pOther
->bIsAutoCloseBrackets
, bVal
);
1103 bool SmMathConfig::IsIgnoreSpacesRight() const
1106 const_cast<SmMathConfig
*>(this)->LoadOther();
1107 return pOther
->bIgnoreSpacesRight
;
1111 void SmMathConfig::SetIgnoreSpacesRight( bool bVal
)
1115 SetOtherIfNotEqual( pOther
->bIgnoreSpacesRight
, bVal
);
1119 bool SmMathConfig::IsAutoRedraw() const
1122 const_cast<SmMathConfig
*>(this)->LoadOther();
1123 return pOther
->bAutoRedraw
;
1127 void SmMathConfig::SetAutoRedraw( bool bVal
)
1131 SetOtherIfNotEqual( pOther
->bAutoRedraw
, bVal
);
1135 bool SmMathConfig::IsShowFormulaCursor() const
1138 const_cast<SmMathConfig
*>(this)->LoadOther();
1139 return pOther
->bFormulaCursor
;
1143 void SmMathConfig::SetShowFormulaCursor( bool bVal
)
1147 SetOtherIfNotEqual( pOther
->bFormulaCursor
, bVal
);
1150 void SmMathConfig::Notify( const css::uno::Sequence
< OUString
>& )
1154 void SmMathConfig::ItemSetToConfig(const SfxItemSet
&rSet
)
1156 const SfxPoolItem
*pItem
= nullptr;
1160 if (rSet
.GetItemState(SID_PRINTSIZE
, true, &pItem
) == SfxItemState::SET
)
1161 { nU16
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
1162 SetPrintSize( static_cast<SmPrintSize
>(nU16
) );
1164 if (rSet
.GetItemState(SID_PRINTZOOM
, true, &pItem
) == SfxItemState::SET
)
1165 { nU16
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
1166 SetPrintZoomFactor( nU16
);
1168 if (rSet
.GetItemState(SID_PRINTTITLE
, true, &pItem
) == SfxItemState::SET
)
1169 { bVal
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
1170 SetPrintTitle( bVal
);
1172 if (rSet
.GetItemState(SID_PRINTTEXT
, true, &pItem
) == SfxItemState::SET
)
1173 { bVal
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
1174 SetPrintFormulaText( bVal
);
1176 if (rSet
.GetItemState(SID_PRINTFRAME
, true, &pItem
) == SfxItemState::SET
)
1177 { bVal
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
1178 SetPrintFrame( bVal
);
1180 if (rSet
.GetItemState(SID_AUTOREDRAW
, true, &pItem
) == SfxItemState::SET
)
1181 { bVal
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
1182 SetAutoRedraw( bVal
);
1184 if (rSet
.GetItemState(SID_NO_RIGHT_SPACES
, true, &pItem
) == SfxItemState::SET
)
1185 { bVal
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
1186 if (IsIgnoreSpacesRight() != bVal
)
1188 SetIgnoreSpacesRight( bVal
);
1190 // reformat (displayed) formulas accordingly
1191 Broadcast(SfxHint(HINT_FORMATCHANGED
));
1194 if (rSet
.GetItemState(SID_SAVE_ONLY_USED_SYMBOLS
, true, &pItem
) == SfxItemState::SET
)
1195 { bVal
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
1196 SetSaveOnlyUsedSymbols( bVal
);
1199 if (rSet
.GetItemState(SID_AUTO_CLOSE_BRACKETS
, true, &pItem
) == SfxItemState::SET
)
1201 bVal
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
1202 SetAutoCloseBrackets( bVal
);
1209 void SmMathConfig::ConfigToItemSet(SfxItemSet
&rSet
) const
1211 const SfxItemPool
*pPool
= rSet
.GetPool();
1213 rSet
.Put(SfxUInt16Item(pPool
->GetWhich(SID_PRINTSIZE
),
1214 sal::static_int_cast
<sal_uInt16
>(GetPrintSize())));
1215 rSet
.Put(SfxUInt16Item(pPool
->GetWhich(SID_PRINTZOOM
),
1216 GetPrintZoomFactor()));
1218 rSet
.Put(SfxBoolItem(pPool
->GetWhich(SID_PRINTTITLE
), IsPrintTitle()));
1219 rSet
.Put(SfxBoolItem(pPool
->GetWhich(SID_PRINTTEXT
), IsPrintFormulaText()));
1220 rSet
.Put(SfxBoolItem(pPool
->GetWhich(SID_PRINTFRAME
), IsPrintFrame()));
1221 rSet
.Put(SfxBoolItem(pPool
->GetWhich(SID_AUTOREDRAW
), IsAutoRedraw()));
1222 rSet
.Put(SfxBoolItem(pPool
->GetWhich(SID_NO_RIGHT_SPACES
), IsIgnoreSpacesRight()));
1223 rSet
.Put(SfxBoolItem(pPool
->GetWhich(SID_SAVE_ONLY_USED_SYMBOLS
), IsSaveOnlyUsedSymbols()));
1224 rSet
.Put(SfxBoolItem(pPool
->GetWhich(SID_AUTO_CLOSE_BRACKETS
), IsAutoCloseBrackets()));
1227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */