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 .
20 #include <svl/itemset.hxx>
21 #include <svl/intitem.hxx>
22 #include <svl/eitem.hxx>
23 #include <svl/languageoptions.hxx>
24 #include <unotools/configmgr.hxx>
26 #include <vcl/outdev.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/settings.hxx>
29 #include <sal/log.hxx>
30 #include <osl/diagnose.h>
31 #include <i18nlangtag/languagetag.hxx>
33 #include <com/sun/star/beans/PropertyValue.hpp>
35 #include <cfgitem.hxx>
37 #include <starmath.hrc>
42 using namespace com::sun::star::uno
;
43 using namespace com::sun::star::beans
;
45 constexpr OUStringLiteral SYMBOL_LIST
= u
"SymbolList";
46 constexpr OUStringLiteral FONT_FORMAT_LIST
= u
"FontFormatList";
48 static Sequence
< OUString
> lcl_GetFontPropertyNames()
50 return Sequence
< OUString
> {
60 static Sequence
< OUString
> lcl_GetSymbolPropertyNames()
62 return Sequence
< OUString
> {
70 static Sequence
<OUString
> lcl_GetOtherPropertyNames()
72 return Sequence
<OUString
>{ "LoadSave/IsSaveOnlyUsedSymbols",
73 "Misc/AutoCloseBrackets",
74 "Misc/DefaultSmSyntaxVersion",
75 "Misc/IgnoreSpacesRight",
76 "Misc/SmEditWindowZoomFactor",
84 "View/ToolboxVisible" };
87 static Sequence
< OUString
> lcl_GetFormatPropertyNames()
89 //! Beware of order according to *_BEGIN *_END defines in format.hxx !
90 //! see respective load/save routines here
91 return Sequence
< OUString
> {
92 "StandardFormat/Textmode",
93 "StandardFormat/GreekCharStyle",
94 "StandardFormat/ScaleNormalBracket",
95 "StandardFormat/HorizontalAlignment",
96 "StandardFormat/BaseSize",
97 "StandardFormat/TextSize",
98 "StandardFormat/IndexSize",
99 "StandardFormat/FunctionSize",
100 "StandardFormat/OperatorSize",
101 "StandardFormat/LimitsSize",
102 "StandardFormat/Distance/Horizontal",
103 "StandardFormat/Distance/Vertical",
104 "StandardFormat/Distance/Root",
105 "StandardFormat/Distance/SuperScript",
106 "StandardFormat/Distance/SubScript",
107 "StandardFormat/Distance/Numerator",
108 "StandardFormat/Distance/Denominator",
109 "StandardFormat/Distance/Fraction",
110 "StandardFormat/Distance/StrokeWidth",
111 "StandardFormat/Distance/UpperLimit",
112 "StandardFormat/Distance/LowerLimit",
113 "StandardFormat/Distance/BracketSize",
114 "StandardFormat/Distance/BracketSpace",
115 "StandardFormat/Distance/MatrixRow",
116 "StandardFormat/Distance/MatrixColumn",
117 "StandardFormat/Distance/OrnamentSize",
118 "StandardFormat/Distance/OrnamentSpace",
119 "StandardFormat/Distance/OperatorSize",
120 "StandardFormat/Distance/OperatorSpace",
121 "StandardFormat/Distance/LeftSpace",
122 "StandardFormat/Distance/RightSpace",
123 "StandardFormat/Distance/TopSpace",
124 "StandardFormat/Distance/BottomSpace",
125 "StandardFormat/Distance/NormalBracketSize",
126 "StandardFormat/VariableFont",
127 "StandardFormat/FunctionFont",
128 "StandardFormat/NumberFont",
129 "StandardFormat/TextFont",
130 "StandardFormat/SerifFont",
131 "StandardFormat/SansFont",
132 "StandardFormat/FixedFont"
138 SmPrintSize ePrintSize
;
139 sal_uInt16 nPrintZoomFactor
;
140 sal_uInt16 nSmEditWindowZoomFactor
;
141 sal_uInt16 nSmSyntaxVersion
;
143 bool bPrintFormulaText
;
145 bool bIsSaveOnlyUsedSymbols
;
146 bool bIsAutoCloseBrackets
;
147 bool bIgnoreSpacesRight
;
148 bool bToolboxVisible
;
155 constexpr sal_uInt16
nDefaultSmSyntaxVersion(5);
157 SmCfgOther::SmCfgOther()
158 : ePrintSize(PRINT_SIZE_NORMAL
)
159 , nPrintZoomFactor(100)
160 , nSmEditWindowZoomFactor(100)
161 // Defaulted as 5 so I have time to code the parser 6
162 , nSmSyntaxVersion(nDefaultSmSyntaxVersion
)
164 , bPrintFormulaText(true)
166 , bIsSaveOnlyUsedSymbols(true)
167 , bIsAutoCloseBrackets(true)
168 , bIgnoreSpacesRight(true)
169 , bToolboxVisible(true)
171 , bFormulaCursor(true)
176 SmFontFormat::SmFontFormat()
177 : aName(FONTNAME_MATH
)
178 , nCharSet(RTL_TEXTENCODING_UNICODE
)
179 , nFamily(FAMILY_DONTKNOW
)
180 , nPitch(PITCH_DONTKNOW
)
181 , nWeight(WEIGHT_DONTKNOW
)
182 , nItalic(ITALIC_NONE
)
187 SmFontFormat::SmFontFormat( const vcl::Font
&rFont
)
188 : aName(rFont
.GetFamilyName())
189 , nCharSet(static_cast<sal_Int16
>(rFont
.GetCharSet()))
190 , nFamily(static_cast<sal_Int16
>(rFont
.GetFamilyType()))
191 , nPitch(static_cast<sal_Int16
>(rFont
.GetPitch()))
192 , nWeight(static_cast<sal_Int16
>(rFont
.GetWeight()))
193 , nItalic(static_cast<sal_Int16
>(rFont
.GetItalic()))
198 vcl::Font
SmFontFormat::GetFont() const
201 aRes
.SetFamilyName( aName
);
202 aRes
.SetCharSet( static_cast<rtl_TextEncoding
>(nCharSet
) );
203 aRes
.SetFamily( static_cast<FontFamily
>(nFamily
) );
204 aRes
.SetPitch( static_cast<FontPitch
>(nPitch
) );
205 aRes
.SetWeight( static_cast<FontWeight
>(nWeight
) );
206 aRes
.SetItalic( static_cast<FontItalic
>(nItalic
) );
211 bool SmFontFormat::operator == ( const SmFontFormat
&rFntFmt
) const
213 return aName
== rFntFmt
.aName
&&
214 nCharSet
== rFntFmt
.nCharSet
&&
215 nFamily
== rFntFmt
.nFamily
&&
216 nPitch
== rFntFmt
.nPitch
&&
217 nWeight
== rFntFmt
.nWeight
&&
218 nItalic
== rFntFmt
.nItalic
;
222 SmFntFmtListEntry::SmFntFmtListEntry( OUString _aId
, SmFontFormat _aFntFmt
) :
223 aId (std::move(_aId
)),
224 aFntFmt (std::move(_aFntFmt
))
229 SmFontFormatList::SmFontFormatList()
235 void SmFontFormatList::Clear()
237 if (!aEntries
.empty())
245 void SmFontFormatList::AddFontFormat( const OUString
&rFntFmtId
,
246 const SmFontFormat
&rFntFmt
)
248 const SmFontFormat
*pFntFmt
= GetFontFormat( rFntFmtId
);
249 OSL_ENSURE( !pFntFmt
, "FontFormatId already exists" );
252 SmFntFmtListEntry
aEntry( rFntFmtId
, rFntFmt
);
253 aEntries
.push_back( aEntry
);
259 void SmFontFormatList::RemoveFontFormat( std::u16string_view rFntFmtId
)
263 for (size_t i
= 0; i
< aEntries
.size(); ++i
)
265 if (aEntries
[i
].aId
== rFntFmtId
)
267 // remove entry if found
268 aEntries
.erase( aEntries
.begin() + i
);
276 const SmFontFormat
* SmFontFormatList::GetFontFormat( std::u16string_view rFntFmtId
) const
278 const SmFontFormat
*pRes
= nullptr;
280 for (const auto & rEntry
: aEntries
)
282 if (rEntry
.aId
== rFntFmtId
)
284 pRes
= &rEntry
.aFntFmt
;
293 const SmFontFormat
* SmFontFormatList::GetFontFormat( size_t nPos
) const
295 const SmFontFormat
*pRes
= nullptr;
296 if (nPos
< aEntries
.size())
297 pRes
= &aEntries
[nPos
].aFntFmt
;
302 OUString
SmFontFormatList::GetFontFormatId( const SmFontFormat
&rFntFmt
) const
306 for (const auto & rEntry
: aEntries
)
308 if (rEntry
.aFntFmt
== rFntFmt
)
319 OUString
SmFontFormatList::GetFontFormatId( const SmFontFormat
&rFntFmt
, bool bAdd
)
321 OUString
aRes( GetFontFormatId( rFntFmt
) );
322 if (aRes
.isEmpty() && bAdd
)
324 aRes
= GetNewFontFormatId();
325 AddFontFormat( aRes
, rFntFmt
);
331 OUString
SmFontFormatList::GetFontFormatId( size_t nPos
) const
334 if (nPos
< aEntries
.size())
335 aRes
= aEntries
[nPos
].aId
;
340 OUString
SmFontFormatList::GetNewFontFormatId() const
342 // returns first unused FormatId
344 sal_Int32 nCnt
= GetCount();
345 for (sal_Int32 i
= 1; i
<= nCnt
+ 1; ++i
)
347 OUString aTmpId
= "Id" + OUString::number(i
);
348 if (!GetFontFormat(aTmpId
))
351 OSL_ENSURE( false, "failed to create new FontFormatId" );
357 SmMathConfig::SmMathConfig() :
358 ConfigItem("Office.Math")
359 , bIsOtherModified(false)
360 , bIsFormatModified(false)
362 EnableNotification({ {} }); // Listen to everything under the node
366 SmMathConfig::~SmMathConfig()
372 void SmMathConfig::SetOtherModified( bool bVal
)
374 bIsOtherModified
= bVal
;
378 void SmMathConfig::SetFormatModified( bool bVal
)
380 bIsFormatModified
= bVal
;
384 void SmMathConfig::ReadSymbol( SmSym
&rSymbol
,
385 const OUString
&rSymbolName
,
386 std::u16string_view rBaseNode
) const
388 Sequence
< OUString
> aNames
= lcl_GetSymbolPropertyNames();
389 sal_Int32 nProps
= aNames
.getLength();
391 OUString
aDelim( "/" );
392 for (auto& rName
: asNonConstRange(aNames
))
393 rName
= rBaseNode
+ aDelim
+ rSymbolName
+ aDelim
+ rName
;
395 const Sequence
< Any
> aValues
= const_cast<SmMathConfig
*>(this)->GetProperties(aNames
);
397 if (!(nProps
&& aValues
.getLength() == nProps
))
400 const Any
* pValue
= aValues
.getConstArray();
402 sal_UCS4 cChar
= '\0';
404 bool bPredefined
= false;
407 sal_Int32 nTmp32
= 0;
411 if (pValue
->hasValue() && (*pValue
>>= nTmp32
))
412 cChar
= static_cast< sal_UCS4
>( nTmp32
);
416 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
421 if (pValue
->hasValue() && (*pValue
>>= bTmp
))
426 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
428 const SmFontFormat
*pFntFmt
= GetFontFormatList().GetFontFormat( aTmpStr
);
429 OSL_ENSURE( pFntFmt
, "unknown FontFormat" );
431 aFont
= pFntFmt
->GetFont();
439 OUString
aUiName( rSymbolName
);
440 OUString
aUiSetName( aSet
);
444 aTmp
= SmLocalizedSymbolData::GetUiSymbolName( rSymbolName
);
445 OSL_ENSURE( !aTmp
.isEmpty(), "localized symbol-name not found" );
448 aTmp
= SmLocalizedSymbolData::GetUiSymbolSetName( aSet
);
449 OSL_ENSURE( !aTmp
.isEmpty(), "localized symbolset-name not found" );
454 rSymbol
= SmSym( aUiName
, aFont
, cChar
, aUiSetName
, bPredefined
);
455 if (aUiName
!= rSymbolName
)
456 rSymbol
.SetExportName( rSymbolName
);
460 SAL_WARN("starmath", "symbol read error");
465 SmSymbolManager
& SmMathConfig::GetSymbolManager()
469 pSymbolMgr
.reset(new SmSymbolManager
);
476 void SmMathConfig::ImplCommit()
482 void SmMathConfig::Save()
486 SaveFontFormatList();
490 void SmMathConfig::UnlockCommit()
492 if (--m_nCommitLock
== 0)
497 void SmMathConfig::Clear()
499 // Re-read data on next request
502 pFontFormatList
.reset();
506 void SmMathConfig::GetSymbols( std::vector
< SmSym
> &rSymbols
) const
508 Sequence
< OUString
> aNodes(const_cast<SmMathConfig
*>(this)->GetNodeNames(SYMBOL_LIST
));
509 const OUString
*pNode
= aNodes
.getConstArray();
510 sal_Int32 nNodes
= aNodes
.getLength();
512 rSymbols
.resize( nNodes
);
513 for (auto& rSymbol
: rSymbols
)
515 ReadSymbol( rSymbol
, *pNode
++, SYMBOL_LIST
);
520 void SmMathConfig::SetSymbols( const std::vector
< SmSym
> &rNewSymbols
)
522 CommitLocker
aLock(*this);
523 auto nCount
= sal::static_int_cast
<sal_Int32
>(rNewSymbols
.size());
525 Sequence
< OUString
> aNames
= lcl_GetSymbolPropertyNames();
526 const OUString
*pNames
= aNames
.getConstArray();
527 sal_Int32 nSymbolProps
= aNames
.getLength();
529 Sequence
< PropertyValue
> aValues( nCount
* nSymbolProps
);
530 PropertyValue
*pValues
= aValues
.getArray();
532 PropertyValue
*pVal
= pValues
;
533 OUString
aDelim( "/" );
534 for (const SmSym
& rSymbol
: rNewSymbols
)
536 OUString aNodeNameDelim
= SYMBOL_LIST
+
538 rSymbol
.GetExportName() +
541 const OUString
*pName
= pNames
;
544 pVal
->Name
= aNodeNameDelim
;
545 pVal
->Name
+= *pName
++;
546 pVal
->Value
<<= rSymbol
.GetCharacter();
549 pVal
->Name
= aNodeNameDelim
;
550 pVal
->Name
+= *pName
++;
551 OUString
aTmp( rSymbol
.GetSymbolSetName() );
552 if (rSymbol
.IsPredefined())
553 aTmp
= SmLocalizedSymbolData::GetExportSymbolSetName( aTmp
);
554 pVal
->Value
<<= aTmp
;
557 pVal
->Name
= aNodeNameDelim
;
558 pVal
->Name
+= *pName
++;
559 pVal
->Value
<<= rSymbol
.IsPredefined();
562 SmFontFormat
aFntFmt( rSymbol
.GetFace() );
563 OUString
aFntFmtId( GetFontFormatList().GetFontFormatId( aFntFmt
, true ) );
564 OSL_ENSURE( !aFntFmtId
.isEmpty(), "FontFormatId not found" );
565 pVal
->Name
= aNodeNameDelim
;
566 pVal
->Name
+= *pName
++;
567 pVal
->Value
<<= aFntFmtId
;
570 OSL_ENSURE( pVal
- pValues
== sal::static_int_cast
< ptrdiff_t >(nCount
* nSymbolProps
), "properties missing" );
571 ReplaceSetProperties( SYMBOL_LIST
, aValues
);
573 StripFontFormatList( rNewSymbols
);
577 SmFontFormatList
& SmMathConfig::GetFontFormatList()
579 if (!pFontFormatList
)
581 LoadFontFormatList();
583 return *pFontFormatList
;
587 void SmMathConfig::LoadFontFormatList()
589 if (!pFontFormatList
)
590 pFontFormatList
.reset(new SmFontFormatList
);
592 pFontFormatList
->Clear();
594 const Sequence
< OUString
> aNodes( GetNodeNames( FONT_FORMAT_LIST
) );
596 for (const OUString
& rNode
: aNodes
)
598 SmFontFormat aFntFmt
;
599 ReadFontFormat( aFntFmt
, rNode
, FONT_FORMAT_LIST
);
600 if (!pFontFormatList
->GetFontFormat( rNode
))
601 pFontFormatList
->AddFontFormat( rNode
, aFntFmt
);
603 pFontFormatList
->SetModified( false );
607 void SmMathConfig::ReadFontFormat( SmFontFormat
&rFontFormat
,
608 std::u16string_view rSymbolName
, std::u16string_view rBaseNode
) const
610 Sequence
< OUString
> aNames
= lcl_GetFontPropertyNames();
611 sal_Int32 nProps
= aNames
.getLength();
613 OUString
aDelim( "/" );
614 for (auto& rName
: asNonConstRange(aNames
))
615 rName
= rBaseNode
+ aDelim
+ rSymbolName
+ aDelim
+ rName
;
617 const Sequence
< Any
> aValues
= const_cast<SmMathConfig
*>(this)->GetProperties(aNames
);
619 if (!(nProps
&& aValues
.getLength() == nProps
))
622 const Any
* pValue
= aValues
.getConstArray();
625 sal_Int16 nTmp16
= 0;
628 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
629 rFontFormat
.aName
= aTmpStr
;
633 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
634 rFontFormat
.nCharSet
= nTmp16
; // 6.0 file-format GetSOLoadTextEncoding not needed
638 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
639 rFontFormat
.nFamily
= nTmp16
;
643 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
644 rFontFormat
.nPitch
= nTmp16
;
648 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
649 rFontFormat
.nWeight
= nTmp16
;
653 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
654 rFontFormat
.nItalic
= nTmp16
;
659 OSL_ENSURE( bOK
, "read FontFormat failed" );
663 void SmMathConfig::SaveFontFormatList()
665 SmFontFormatList
&rFntFmtList
= GetFontFormatList();
667 if (!rFntFmtList
.IsModified())
670 Sequence
< OUString
> aNames
= lcl_GetFontPropertyNames();
671 sal_Int32 nSymbolProps
= aNames
.getLength();
673 size_t nCount
= rFntFmtList
.GetCount();
675 Sequence
< PropertyValue
> aValues( nCount
* nSymbolProps
);
676 PropertyValue
*pValues
= aValues
.getArray();
678 PropertyValue
*pVal
= pValues
;
679 OUString
aDelim( "/" );
680 for (size_t i
= 0; i
< nCount
; ++i
)
682 OUString
aFntFmtId(rFntFmtList
.GetFontFormatId(i
));
683 const SmFontFormat
*pFntFmt
= rFntFmtList
.GetFontFormat(i
);
685 const SmFontFormat
aFntFmt(*pFntFmt
);
687 OUString aNodeNameDelim
= FONT_FORMAT_LIST
+
692 const OUString
*pName
= aNames
.getConstArray();
695 pVal
->Name
= aNodeNameDelim
;
696 pVal
->Name
+= *pName
++;
697 pVal
->Value
<<= aFntFmt
.aName
;
700 pVal
->Name
= aNodeNameDelim
;
701 pVal
->Name
+= *pName
++;
702 pVal
->Value
<<= aFntFmt
.nCharSet
; // 6.0 file-format GetSOStoreTextEncoding not needed
705 pVal
->Name
= aNodeNameDelim
;
706 pVal
->Name
+= *pName
++;
707 pVal
->Value
<<= aFntFmt
.nFamily
;
710 pVal
->Name
= aNodeNameDelim
;
711 pVal
->Name
+= *pName
++;
712 pVal
->Value
<<= aFntFmt
.nPitch
;
715 pVal
->Name
= aNodeNameDelim
;
716 pVal
->Name
+= *pName
++;
717 pVal
->Value
<<= aFntFmt
.nWeight
;
720 pVal
->Name
= aNodeNameDelim
;
721 pVal
->Name
+= *pName
++;
722 pVal
->Value
<<= aFntFmt
.nItalic
;
725 OSL_ENSURE( sal::static_int_cast
<size_t>(pVal
- pValues
) == nCount
* nSymbolProps
, "properties missing" );
726 ReplaceSetProperties( FONT_FORMAT_LIST
, aValues
);
728 rFntFmtList
.SetModified( false );
732 void SmMathConfig::StripFontFormatList( const std::vector
< SmSym
> &rSymbols
)
736 // build list of used font-formats only
737 //!! font-format IDs may be different !!
738 SmFontFormatList aUsedList
;
739 for (i
= 0; i
< rSymbols
.size(); ++i
)
741 OSL_ENSURE( rSymbols
[i
].GetName().getLength() > 0, "non named symbol" );
742 aUsedList
.GetFontFormatId( SmFontFormat( rSymbols
[i
].GetFace() ) , true );
744 const SmFormat
& rStdFmt
= GetStandardFormat();
745 for (i
= FNT_BEGIN
; i
<= FNT_END
; ++i
)
747 aUsedList
.GetFontFormatId( SmFontFormat( rStdFmt
.GetFont( i
) ) , true );
750 // remove unused font-formats from list
751 SmFontFormatList
&rFntFmtList
= GetFontFormatList();
752 size_t nCnt
= rFntFmtList
.GetCount();
753 std::unique_ptr
<SmFontFormat
[]> pTmpFormat(new SmFontFormat
[ nCnt
]);
754 std::unique_ptr
<OUString
[]> pId(new OUString
[ nCnt
]);
756 for (k
= 0; k
< nCnt
; ++k
)
758 pTmpFormat
[k
] = *rFntFmtList
.GetFontFormat( k
);
759 pId
[k
] = rFntFmtList
.GetFontFormatId( k
);
761 for (k
= 0; k
< nCnt
; ++k
)
763 if (aUsedList
.GetFontFormatId( pTmpFormat
[k
] ).isEmpty())
765 rFntFmtList
.RemoveFontFormat( pId
[k
] );
771 void SmMathConfig::LoadOther()
774 pOther
.reset(new SmCfgOther
);
776 const Sequence
<OUString
> aNames(lcl_GetOtherPropertyNames());
777 const Sequence
<Any
> aValues(GetProperties(aNames
));
778 if (aNames
.getLength() != aValues
.getLength())
781 const Any
* pValues
= aValues
.getConstArray();
782 const Any
* pVal
= pValues
;
784 // LoadSave/IsSaveOnlyUsedSymbols
785 if (bool bTmp
; pVal
->hasValue() && (*pVal
>>= bTmp
))
786 pOther
->bIsSaveOnlyUsedSymbols
= bTmp
;
788 // Misc/AutoCloseBrackets
789 if (bool bTmp
; pVal
->hasValue() && (*pVal
>>= bTmp
))
790 pOther
->bIsAutoCloseBrackets
= bTmp
;
792 // Misc/DefaultSmSyntaxVersion
793 if (sal_Int16 nTmp
; pVal
->hasValue() && (*pVal
>>= nTmp
))
794 pOther
->nSmSyntaxVersion
= nTmp
;
796 // Misc/IgnoreSpacesRight
797 if (bool bTmp
; pVal
->hasValue() && (*pVal
>>= bTmp
))
798 pOther
->bIgnoreSpacesRight
= bTmp
;
800 // Misc/SmEditWindowZoomFactor
801 if (sal_Int16 nTmp
; pVal
->hasValue() && (*pVal
>>= nTmp
))
802 pOther
->nSmEditWindowZoomFactor
= nTmp
;
805 if (bool bTmp
; pVal
->hasValue() && (*pVal
>>= bTmp
))
806 pOther
->bPrintFormulaText
= bTmp
;
809 if (bool bTmp
; pVal
->hasValue() && (*pVal
>>= bTmp
))
810 pOther
->bPrintFrame
= bTmp
;
813 if (sal_Int16 nTmp
; pVal
->hasValue() && (*pVal
>>= nTmp
))
814 pOther
->ePrintSize
= static_cast<SmPrintSize
>(nTmp
);
817 if (bool bTmp
; pVal
->hasValue() && (*pVal
>>= bTmp
))
818 pOther
->bPrintTitle
= bTmp
;
821 if (sal_Int16 nTmp
; pVal
->hasValue() && (*pVal
>>= nTmp
))
822 pOther
->nPrintZoomFactor
= nTmp
;
825 if (bool bTmp
; pVal
->hasValue() && (*pVal
>>= bTmp
))
826 pOther
->bAutoRedraw
= bTmp
;
828 // View/FormulaCursor
829 if (bool bTmp
; pVal
->hasValue() && (*pVal
>>= bTmp
))
830 pOther
->bFormulaCursor
= bTmp
;
832 // View/ToolboxVisible
833 if (bool bTmp
; pVal
->hasValue() && (*pVal
>>= bTmp
))
834 pOther
->bToolboxVisible
= bTmp
;
837 OSL_ENSURE(pVal
- pValues
== aNames
.getLength(), "property mismatch");
838 SetOtherModified( false );
842 void SmMathConfig::SaveOther()
844 if (!pOther
|| !IsOtherModified())
847 const Sequence
<OUString
> aNames(lcl_GetOtherPropertyNames());
848 Sequence
<Any
> aValues(aNames
.getLength());
850 Any
* pValues
= aValues
.getArray();
853 // LoadSave/IsSaveOnlyUsedSymbols
854 *pVal
++ <<= pOther
->bIsSaveOnlyUsedSymbols
;
855 // Misc/AutoCloseBrackets
856 *pVal
++ <<= pOther
->bIsAutoCloseBrackets
;
857 // Misc/DefaultSmSyntaxVersion
858 *pVal
++ <<= pOther
->nSmSyntaxVersion
;
859 // Misc/IgnoreSpacesRight
860 *pVal
++ <<= pOther
->bIgnoreSpacesRight
;
861 // Misc/SmEditWindowZoomFactor
862 *pVal
++ <<= pOther
->nSmEditWindowZoomFactor
;
864 *pVal
++ <<= pOther
->bPrintFormulaText
;
866 *pVal
++ <<= pOther
->bPrintFrame
;
868 *pVal
++ <<= static_cast<sal_Int16
>(pOther
->ePrintSize
);
870 *pVal
++ <<= pOther
->bPrintTitle
;
872 *pVal
++ <<= pOther
->nPrintZoomFactor
;
874 *pVal
++ <<= pOther
->bAutoRedraw
;
875 // View/FormulaCursor
876 *pVal
++ <<= pOther
->bFormulaCursor
;
877 // View/ToolboxVisible
878 *pVal
++ <<= pOther
->bToolboxVisible
;
880 OSL_ENSURE(pVal
- pValues
== aNames
.getLength(), "property mismatch");
881 PutProperties(aNames
, aValues
);
883 SetOtherModified( false );
888 // Latin default-fonts
889 const DefaultFontType aLatinDefFnts
[FNT_END
] =
891 DefaultFontType::SERIF
, // FNT_VARIABLE
892 DefaultFontType::SERIF
, // FNT_FUNCTION
893 DefaultFontType::SERIF
, // FNT_NUMBER
894 DefaultFontType::SERIF
, // FNT_TEXT
895 DefaultFontType::SERIF
, // FNT_SERIF
896 DefaultFontType::SANS
, // FNT_SANS
897 DefaultFontType::FIXED
// FNT_FIXED
898 //OpenSymbol, // FNT_MATH
902 //! we use non-asian fonts for variables, functions and numbers since they
903 //! look better and even in asia only latin letters will be used for those.
904 //! At least that's what I was told...
905 const DefaultFontType aCJKDefFnts
[FNT_END
] =
907 DefaultFontType::SERIF
, // FNT_VARIABLE
908 DefaultFontType::SERIF
, // FNT_FUNCTION
909 DefaultFontType::SERIF
, // FNT_NUMBER
910 DefaultFontType::CJK_TEXT
, // FNT_TEXT
911 DefaultFontType::CJK_TEXT
, // FNT_SERIF
912 DefaultFontType::CJK_DISPLAY
, // FNT_SANS
913 DefaultFontType::CJK_TEXT
// FNT_FIXED
914 //OpenSymbol, // FNT_MATH
918 const DefaultFontType aCTLDefFnts
[FNT_END
] =
920 DefaultFontType::CTL_TEXT
, // FNT_VARIABLE
921 DefaultFontType::CTL_TEXT
, // FNT_FUNCTION
922 DefaultFontType::CTL_TEXT
, // FNT_NUMBER
923 DefaultFontType::CTL_TEXT
, // FNT_TEXT
924 DefaultFontType::CTL_TEXT
, // FNT_SERIF
925 DefaultFontType::CTL_TEXT
, // FNT_SANS
926 DefaultFontType::CTL_TEXT
// FNT_FIXED
927 //OpenSymbol, // FNT_MATH
931 OUString
lcl_GetDefaultFontName( LanguageType nLang
, sal_uInt16 nIdent
)
933 assert(nIdent
< FNT_END
);
934 const DefaultFontType
*pTable
;
935 switch ( SvtLanguageOptions::GetScriptTypeOfLanguage( nLang
) )
937 case SvtScriptType::LATIN
: pTable
= aLatinDefFnts
; break;
938 case SvtScriptType::ASIAN
: pTable
= aCJKDefFnts
; break;
939 case SvtScriptType::COMPLEX
: pTable
= aCTLDefFnts
; break;
941 pTable
= aLatinDefFnts
;
942 SAL_WARN("starmath", "unknown script-type");
945 return OutputDevice::GetDefaultFont(pTable
[ nIdent
], nLang
,
946 GetDefaultFontFlags::OnlyOne
).GetFamilyName();
952 void SmMathConfig::LoadFormat()
955 pFormat
.reset(new SmFormat
);
958 Sequence
< OUString
> aNames
= lcl_GetFormatPropertyNames();
960 sal_Int32 nProps
= aNames
.getLength();
962 Sequence
< Any
> aValues( GetProperties( aNames
) );
963 if (!(nProps
&& aValues
.getLength() == nProps
))
966 const Any
*pValues
= aValues
.getConstArray();
967 const Any
*pVal
= pValues
;
970 sal_Int16 nTmp16
= 0;
973 // StandardFormat/Textmode
974 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
975 pFormat
->SetTextmode( bTmp
);
977 // StandardFormat/GreekCharStyle
978 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
979 pFormat
->SetGreekCharStyle( nTmp16
);
981 // StandardFormat/ScaleNormalBracket
982 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
983 pFormat
->SetScaleNormalBrackets( bTmp
);
985 // StandardFormat/HorizontalAlignment
986 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
987 pFormat
->SetHorAlign( static_cast<SmHorAlign
>(nTmp16
) );
989 // StandardFormat/BaseSize
990 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
991 pFormat
->SetBaseSize(Size(0, o3tl::convert(nTmp16
, o3tl::Length::pt
, SmO3tlLengthUnit())));
995 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; ++i
)
997 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
998 pFormat
->SetRelSize( i
, nTmp16
);
1002 for (i
= DIS_BEGIN
; i
<= DIS_END
; ++i
)
1004 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1005 pFormat
->SetDistance( i
, nTmp16
);
1009 LanguageType nLang
= Application::GetSettings().GetUILanguageTag().getLanguageType();
1010 for (i
= FNT_BEGIN
; i
< FNT_END
; ++i
)
1013 bool bUseDefaultFont
= true;
1014 if (pVal
->hasValue() && (*pVal
>>= aTmpStr
))
1016 bUseDefaultFont
= aTmpStr
.isEmpty();
1017 if (bUseDefaultFont
)
1019 aFnt
= pFormat
->GetFont( i
);
1020 aFnt
.SetFamilyName( lcl_GetDefaultFontName( nLang
, i
) );
1024 const SmFontFormat
*pFntFmt
= GetFontFormatList().GetFontFormat( aTmpStr
);
1025 OSL_ENSURE( pFntFmt
, "unknown FontFormat" );
1027 aFnt
= pFntFmt
->GetFont();
1032 aFnt
.SetFontSize( pFormat
->GetBaseSize() );
1033 pFormat
->SetFont( i
, aFnt
, bUseDefaultFont
);
1036 OSL_ENSURE( pVal
- pValues
== nProps
, "property mismatch" );
1037 SetFormatModified( false );
1041 void SmMathConfig::SaveFormat()
1043 if (!pFormat
|| !IsFormatModified())
1046 const Sequence
< OUString
> aNames
= lcl_GetFormatPropertyNames();
1047 sal_Int32 nProps
= aNames
.getLength();
1049 Sequence
< Any
> aValues( nProps
);
1050 Any
*pValues
= aValues
.getArray();
1051 Any
*pValue
= pValues
;
1053 // StandardFormat/Textmode
1054 *pValue
++ <<= pFormat
->IsTextmode();
1055 // StandardFormat/GreekCharStyle
1056 *pValue
++ <<= pFormat
->GetGreekCharStyle();
1057 // StandardFormat/ScaleNormalBracket
1058 *pValue
++ <<= pFormat
->IsScaleNormalBrackets();
1059 // StandardFormat/HorizontalAlignment
1060 *pValue
++ <<= static_cast<sal_Int16
>(pFormat
->GetHorAlign());
1061 // StandardFormat/BaseSize
1062 *pValue
++ <<= static_cast<sal_Int16
>(
1063 o3tl::convert(pFormat
->GetBaseSize().Height(), SmO3tlLengthUnit(), o3tl::Length::pt
));
1066 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; ++i
)
1067 *pValue
++ <<= static_cast<sal_Int16
>(pFormat
->GetRelSize( i
));
1069 for (i
= DIS_BEGIN
; i
<= DIS_END
; ++i
)
1070 *pValue
++ <<= static_cast<sal_Int16
>(pFormat
->GetDistance( i
));
1072 for (i
= FNT_BEGIN
; i
< FNT_END
; ++i
)
1076 if (!pFormat
->IsDefaultFont( i
))
1078 SmFontFormat
aFntFmt( pFormat
->GetFont( i
) );
1079 aFntFmtId
= GetFontFormatList().GetFontFormatId( aFntFmt
, true );
1080 OSL_ENSURE( !aFntFmtId
.isEmpty(), "FontFormatId not found" );
1083 *pValue
++ <<= aFntFmtId
;
1086 OSL_ENSURE( pValue
- pValues
== nProps
, "property mismatch" );
1087 PutProperties( aNames
, aValues
);
1089 SetFormatModified( false );
1093 const SmFormat
& SmMathConfig::GetStandardFormat() const
1096 const_cast<SmMathConfig
*>(this)->LoadFormat();
1101 void SmMathConfig::SetStandardFormat( const SmFormat
&rFormat
, bool bSaveFontFormatList
)
1105 if (rFormat
== *pFormat
)
1108 CommitLocker
aLock(*this);
1110 SetFormatModified( true );
1112 if (bSaveFontFormatList
)
1114 // needed for SmFontTypeDialog's DefaultButtonClickHdl
1115 if (pFontFormatList
)
1116 pFontFormatList
->SetModified( true );
1121 SmPrintSize
SmMathConfig::GetPrintSize() const
1124 const_cast<SmMathConfig
*>(this)->LoadOther();
1125 return pOther
->ePrintSize
;
1129 void SmMathConfig::SetPrintSize( SmPrintSize eSize
)
1133 if (eSize
!= pOther
->ePrintSize
)
1135 CommitLocker
aLock(*this);
1136 pOther
->ePrintSize
= eSize
;
1137 SetOtherModified( true );
1142 sal_uInt16
SmMathConfig::GetPrintZoomFactor() const
1145 const_cast<SmMathConfig
*>(this)->LoadOther();
1146 return pOther
->nPrintZoomFactor
;
1150 void SmMathConfig::SetPrintZoomFactor( sal_uInt16 nVal
)
1154 if (nVal
!= pOther
->nPrintZoomFactor
)
1156 CommitLocker
aLock(*this);
1157 pOther
->nPrintZoomFactor
= nVal
;
1158 SetOtherModified( true );
1163 sal_uInt16
SmMathConfig::GetSmEditWindowZoomFactor() const
1165 sal_uInt16 smzoomfactor
;
1167 const_cast<SmMathConfig
*>(this)->LoadOther();
1168 smzoomfactor
= pOther
->nSmEditWindowZoomFactor
;
1169 return smzoomfactor
< 10 || smzoomfactor
> 1000 ? 100 : smzoomfactor
;
1173 void SmMathConfig::SetSmEditWindowZoomFactor( sal_uInt16 nVal
)
1177 if (nVal
!= pOther
->nSmEditWindowZoomFactor
)
1179 CommitLocker
aLock(*this);
1180 pOther
->nSmEditWindowZoomFactor
= nVal
;
1181 SetOtherModified( true );
1186 bool SmMathConfig::SetOtherIfNotEqual( bool &rbItem
, bool bNewVal
)
1188 if (bNewVal
!= rbItem
)
1190 CommitLocker
aLock(*this);
1192 SetOtherModified( true );
1199 bool SmMathConfig::IsPrintTitle() const
1202 const_cast<SmMathConfig
*>(this)->LoadOther();
1203 return pOther
->bPrintTitle
;
1207 void SmMathConfig::SetPrintTitle( bool bVal
)
1211 SetOtherIfNotEqual( pOther
->bPrintTitle
, bVal
);
1215 bool SmMathConfig::IsPrintFormulaText() const
1218 const_cast<SmMathConfig
*>(this)->LoadOther();
1219 return pOther
->bPrintFormulaText
;
1223 void SmMathConfig::SetPrintFormulaText( bool bVal
)
1227 SetOtherIfNotEqual( pOther
->bPrintFormulaText
, bVal
);
1230 bool SmMathConfig::IsSaveOnlyUsedSymbols() const
1233 const_cast<SmMathConfig
*>(this)->LoadOther();
1234 return pOther
->bIsSaveOnlyUsedSymbols
;
1237 bool SmMathConfig::IsAutoCloseBrackets() const
1240 const_cast<SmMathConfig
*>(this)->LoadOther();
1241 return pOther
->bIsAutoCloseBrackets
;
1244 sal_uInt16
SmMathConfig::GetDefaultSmSyntaxVersion() const
1246 if (utl::ConfigManager::IsFuzzing())
1247 return nDefaultSmSyntaxVersion
;
1249 const_cast<SmMathConfig
*>(this)->LoadOther();
1250 return pOther
->nSmSyntaxVersion
;
1253 bool SmMathConfig::IsPrintFrame() const
1256 const_cast<SmMathConfig
*>(this)->LoadOther();
1257 return pOther
->bPrintFrame
;
1261 void SmMathConfig::SetPrintFrame( bool bVal
)
1265 SetOtherIfNotEqual( pOther
->bPrintFrame
, bVal
);
1269 void SmMathConfig::SetSaveOnlyUsedSymbols( bool bVal
)
1273 SetOtherIfNotEqual( pOther
->bIsSaveOnlyUsedSymbols
, bVal
);
1277 void SmMathConfig::SetAutoCloseBrackets( bool bVal
)
1281 SetOtherIfNotEqual( pOther
->bIsAutoCloseBrackets
, bVal
);
1284 void SmMathConfig::SetDefaultSmSyntaxVersion( sal_uInt16 nVal
)
1288 if (nVal
!= pOther
->nSmSyntaxVersion
)
1290 CommitLocker
aLock(*this);
1291 pOther
->nSmSyntaxVersion
= nVal
;
1292 SetOtherModified( true );
1296 bool SmMathConfig::IsIgnoreSpacesRight() const
1298 if (utl::ConfigManager::IsFuzzing())
1301 const_cast<SmMathConfig
*>(this)->LoadOther();
1302 return pOther
->bIgnoreSpacesRight
;
1306 void SmMathConfig::SetIgnoreSpacesRight( bool bVal
)
1310 if (SetOtherIfNotEqual( pOther
->bIgnoreSpacesRight
, bVal
))
1312 // reformat (displayed) formulas accordingly
1313 Broadcast(SfxHint(SfxHintId::MathFormatChanged
));
1319 bool SmMathConfig::IsAutoRedraw() const
1322 const_cast<SmMathConfig
*>(this)->LoadOther();
1323 return pOther
->bAutoRedraw
;
1327 void SmMathConfig::SetAutoRedraw( bool bVal
)
1331 SetOtherIfNotEqual( pOther
->bAutoRedraw
, bVal
);
1335 bool SmMathConfig::IsShowFormulaCursor() const
1338 const_cast<SmMathConfig
*>(this)->LoadOther();
1339 return pOther
->bFormulaCursor
;
1343 void SmMathConfig::SetShowFormulaCursor( bool bVal
)
1347 SetOtherIfNotEqual( pOther
->bFormulaCursor
, bVal
);
1350 void SmMathConfig::Notify( const css::uno::Sequence
< OUString
>& rNames
)
1353 if (std::find(rNames
.begin(), rNames
.end(), "Misc/IgnoreSpacesRight") != rNames
.end())
1354 Broadcast(SfxHint(SfxHintId::MathFormatChanged
));
1358 void SmMathConfig::ItemSetToConfig(const SfxItemSet
&rSet
)
1360 CommitLocker
aLock(*this);
1364 if (const SfxUInt16Item
* pPrintSizeItem
= rSet
.GetItemIfSet(SID_PRINTSIZE
))
1365 { nU16
= pPrintSizeItem
->GetValue();
1366 SetPrintSize( static_cast<SmPrintSize
>(nU16
) );
1368 if (const SfxUInt16Item
* pPrintZoomItem
= rSet
.GetItemIfSet(SID_PRINTZOOM
))
1369 { nU16
= pPrintZoomItem
->GetValue();
1370 SetPrintZoomFactor( nU16
);
1372 if (const SfxUInt16Item
* pPrintZoomItem
= rSet
.GetItemIfSet(SID_SMEDITWINDOWZOOM
))
1373 { nU16
= pPrintZoomItem
->GetValue();
1374 SetSmEditWindowZoomFactor( nU16
);
1376 if (const SfxBoolItem
* pPrintTitleItem
= rSet
.GetItemIfSet(SID_PRINTTITLE
))
1377 { bVal
= pPrintTitleItem
->GetValue();
1378 SetPrintTitle( bVal
);
1380 if (const SfxBoolItem
* pPrintTextItem
= rSet
.GetItemIfSet(SID_PRINTTEXT
))
1381 { bVal
= pPrintTextItem
->GetValue();
1382 SetPrintFormulaText( bVal
);
1384 if (const SfxBoolItem
* pPrintZoomItem
= rSet
.GetItemIfSet(SID_PRINTFRAME
))
1385 { bVal
= pPrintZoomItem
->GetValue();
1386 SetPrintFrame( bVal
);
1388 if (const SfxBoolItem
* pRedrawItem
= rSet
.GetItemIfSet(SID_AUTOREDRAW
))
1389 { bVal
= pRedrawItem
->GetValue();
1390 SetAutoRedraw( bVal
);
1392 if (const SfxBoolItem
* pSpacesItem
= rSet
.GetItemIfSet(SID_NO_RIGHT_SPACES
))
1393 { bVal
= pSpacesItem
->GetValue();
1394 SetIgnoreSpacesRight( bVal
);
1396 if (const SfxBoolItem
* pSymbolsItem
= rSet
.GetItemIfSet(SID_SAVE_ONLY_USED_SYMBOLS
))
1397 { bVal
= pSymbolsItem
->GetValue();
1398 SetSaveOnlyUsedSymbols( bVal
);
1401 if (const SfxBoolItem
* pBracketsItem
= rSet
.GetItemIfSet(SID_AUTO_CLOSE_BRACKETS
))
1403 bVal
= pBracketsItem
->GetValue();
1404 SetAutoCloseBrackets( bVal
);
1407 if (const SfxUInt16Item
* pSyntaxItem
= rSet
.GetItemIfSet(SID_DEFAULT_SM_SYNTAX_VERSION
))
1409 nU16
= pSyntaxItem
->GetValue();
1410 SetDefaultSmSyntaxVersion( nU16
);
1415 void SmMathConfig::ConfigToItemSet(SfxItemSet
&rSet
) const
1417 rSet
.Put(SfxUInt16Item(SID_PRINTSIZE
,
1418 sal::static_int_cast
<sal_uInt16
>(GetPrintSize())));
1419 rSet
.Put(SfxUInt16Item(SID_PRINTZOOM
,
1420 GetPrintZoomFactor()));
1421 rSet
.Put(SfxUInt16Item(SID_SMEDITWINDOWZOOM
,
1422 GetSmEditWindowZoomFactor()));
1424 rSet
.Put(SfxBoolItem(SID_PRINTTITLE
, IsPrintTitle()));
1425 rSet
.Put(SfxBoolItem(SID_PRINTTEXT
, IsPrintFormulaText()));
1426 rSet
.Put(SfxBoolItem(SID_PRINTFRAME
, IsPrintFrame()));
1427 rSet
.Put(SfxBoolItem(SID_AUTOREDRAW
, IsAutoRedraw()));
1428 rSet
.Put(SfxBoolItem(SID_NO_RIGHT_SPACES
, IsIgnoreSpacesRight()));
1429 rSet
.Put(SfxBoolItem(SID_SAVE_ONLY_USED_SYMBOLS
, IsSaveOnlyUsedSymbols()));
1430 rSet
.Put(SfxBoolItem(SID_AUTO_CLOSE_BRACKETS
, IsAutoCloseBrackets()));
1431 rSet
.Put(SfxBoolItem(SID_DEFAULT_SM_SYNTAX_VERSION
, GetDefaultSmSyntaxVersion()));
1434 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */