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 <vcl/svapp.hxx>
21 #include <sal/macros.h>
22 #include "cfgitem.hxx"
24 #include "starmath.hrc"
28 using namespace com::sun::star
;
29 using namespace com::sun::star::uno
;
30 using namespace com::sun::star::beans
;
34 static const char aRootName
[] = "Office.Math";
36 #define SYMBOL_LIST "SymbolList"
37 #define FONT_FORMAT_LIST "FontFormatList"
39 /////////////////////////////////////////////////////////////////
42 static Sequence
< OUString
> lcl_GetFontPropertyNames()
44 static const char * aPropNames
[] =
55 const char** ppPropName
= aPropNames
;
57 Sequence
< OUString
> aNames( 6 );
58 OUString
*pNames
= aNames
.getArray();
59 for( sal_Int32 i
= 0; *ppPropName
; ++i
, ++ppPropName
)
61 pNames
[i
] = OUString::createFromAscii( *ppPropName
);
66 /////////////////////////////////////////////////////////////////
69 static Sequence
< OUString
> lcl_GetSymbolPropertyNames()
71 static const char * aPropNames
[] =
80 const char** ppPropName
= aPropNames
;
82 Sequence
< OUString
> aNames( 4 );
83 OUString
*pNames
= aNames
.getArray();
84 for( sal_Int32 i
= 0; *ppPropName
; ++i
, ++ppPropName
)
86 pNames
[i
] = OUString::createFromAscii( *ppPropName
);
91 /////////////////////////////////////////////////////////////////
93 static const char * aMathPropNames
[] =
100 "LoadSave/IsSaveOnlyUsedSymbols",
101 "Misc/IgnoreSpacesRight",
102 "View/ToolboxVisible",
108 //! Beware of order according to *_BEGIN *_END defines in format.hxx !
109 //! see respective load/save routines here
110 static const char * aFormatPropNames
[] =
112 "StandardFormat/Textmode",
113 "StandardFormat/GreekCharStyle",
114 "StandardFormat/ScaleNormalBracket",
115 "StandardFormat/HorizontalAlignment",
116 "StandardFormat/BaseSize",
117 "StandardFormat/TextSize",
118 "StandardFormat/IndexSize",
119 "StandardFormat/FunctionSize",
120 "StandardFormat/OperatorSize",
121 "StandardFormat/LimitsSize",
122 "StandardFormat/Distance/Horizontal",
123 "StandardFormat/Distance/Vertical",
124 "StandardFormat/Distance/Root",
125 "StandardFormat/Distance/SuperScript",
126 "StandardFormat/Distance/SubScript",
127 "StandardFormat/Distance/Numerator",
128 "StandardFormat/Distance/Denominator",
129 "StandardFormat/Distance/Fraction",
130 "StandardFormat/Distance/StrokeWidth",
131 "StandardFormat/Distance/UpperLimit",
132 "StandardFormat/Distance/LowerLimit",
133 "StandardFormat/Distance/BracketSize",
134 "StandardFormat/Distance/BracketSpace",
135 "StandardFormat/Distance/MatrixRow",
136 "StandardFormat/Distance/MatrixColumn",
137 "StandardFormat/Distance/OrnamentSize",
138 "StandardFormat/Distance/OrnamentSpace",
139 "StandardFormat/Distance/OperatorSize",
140 "StandardFormat/Distance/OperatorSpace",
141 "StandardFormat/Distance/LeftSpace",
142 "StandardFormat/Distance/RightSpace",
143 "StandardFormat/Distance/TopSpace",
144 "StandardFormat/Distance/BottomSpace",
145 "StandardFormat/Distance/NormalBracketSize",
146 "StandardFormat/VariableFont",
147 "StandardFormat/FunctionFont",
148 "StandardFormat/NumberFont",
149 "StandardFormat/TextFont",
150 "StandardFormat/SerifFont",
151 "StandardFormat/SansFont",
152 "StandardFormat/FixedFont"
156 static Sequence
< OUString
> lcl_GetPropertyNames(
157 const char * aPropNames
[], sal_uInt16 nCount
)
160 const char** ppPropName
= aPropNames
;
162 Sequence
< OUString
> aNames( nCount
);
163 OUString
*pNames
= aNames
.getArray();
164 for (sal_Int32 i
= 0; i
< nCount
; ++i
, ++ppPropName
)
166 pNames
[i
] = OUString::createFromAscii( *ppPropName
);
171 static Sequence
< OUString
> GetFormatPropertyNames()
173 return lcl_GetPropertyNames( aFormatPropNames
, SAL_N_ELEMENTS( aFormatPropNames
) );
176 static Sequence
< OUString
> GetOtherPropertyNames()
178 return lcl_GetPropertyNames( aMathPropNames
, SAL_N_ELEMENTS( aMathPropNames
) );
181 /////////////////////////////////////////////////////////////////
185 SmPrintSize ePrintSize
;
186 sal_uInt16 nPrintZoomFactor
;
188 bool bPrintFormulaText
;
190 bool bIsSaveOnlyUsedSymbols
;
191 bool bIgnoreSpacesRight
;
192 bool bToolboxVisible
;
200 SmCfgOther::SmCfgOther()
202 ePrintSize
= PRINT_SIZE_NORMAL
;
203 nPrintZoomFactor
= 100;
204 bPrintTitle
= bPrintFormulaText
=
205 bPrintFrame
= bIgnoreSpacesRight
=
206 bToolboxVisible
= bAutoRedraw
=
207 bFormulaCursor
= bIsSaveOnlyUsedSymbols
= true;
210 /////////////////////////////////////////////////////////////////
213 SmFontFormat::SmFontFormat()
215 aName
.AssignAscii( FONTNAME_MATH
);
216 nCharSet
= RTL_TEXTENCODING_UNICODE
;
217 nFamily
= FAMILY_DONTKNOW
;
218 nPitch
= PITCH_DONTKNOW
;
219 nWeight
= WEIGHT_DONTKNOW
;
220 nItalic
= ITALIC_NONE
;
224 SmFontFormat::SmFontFormat( const Font
&rFont
)
226 aName
= rFont
.GetName();
227 nCharSet
= (sal_Int16
) rFont
.GetCharSet();
228 nFamily
= (sal_Int16
) rFont
.GetFamily();
229 nPitch
= (sal_Int16
) rFont
.GetPitch();
230 nWeight
= (sal_Int16
) rFont
.GetWeight();
231 nItalic
= (sal_Int16
) rFont
.GetItalic();
235 const Font
SmFontFormat::GetFont() const
238 aRes
.SetName( aName
);
239 aRes
.SetCharSet( (rtl_TextEncoding
) nCharSet
);
240 aRes
.SetFamily( (FontFamily
) nFamily
);
241 aRes
.SetPitch( (FontPitch
) nPitch
);
242 aRes
.SetWeight( (FontWeight
) nWeight
);
243 aRes
.SetItalic( (FontItalic
) nItalic
);
248 bool SmFontFormat::operator == ( const SmFontFormat
&rFntFmt
) const
250 return aName
== rFntFmt
.aName
&&
251 nCharSet
== rFntFmt
.nCharSet
&&
252 nFamily
== rFntFmt
.nFamily
&&
253 nPitch
== rFntFmt
.nPitch
&&
254 nWeight
== rFntFmt
.nWeight
&&
255 nItalic
== rFntFmt
.nItalic
;
259 /////////////////////////////////////////////////////////////////
261 SmFntFmtListEntry::SmFntFmtListEntry( const String
&rId
, const SmFontFormat
&rFntFmt
) :
268 SmFontFormatList::SmFontFormatList()
274 void SmFontFormatList::Clear()
276 if (!aEntries
.empty())
284 void SmFontFormatList::AddFontFormat( const String
&rFntFmtId
,
285 const SmFontFormat
&rFntFmt
)
287 const SmFontFormat
*pFntFmt
= GetFontFormat( rFntFmtId
);
288 OSL_ENSURE( !pFntFmt
, "FontFormatId already exists" );
291 SmFntFmtListEntry
aEntry( rFntFmtId
, rFntFmt
);
292 aEntries
.push_back( aEntry
);
298 void SmFontFormatList::RemoveFontFormat( const String
&rFntFmtId
)
302 for (size_t i
= 0; i
< aEntries
.size(); ++i
)
304 if (aEntries
[i
].aId
== rFntFmtId
)
306 // remove entry if found
307 aEntries
.erase( aEntries
.begin() + i
);
315 const SmFontFormat
* SmFontFormatList::GetFontFormat( const String
&rFntFmtId
) const
317 const SmFontFormat
*pRes
= 0;
319 for (size_t i
= 0; i
< aEntries
.size(); ++i
)
321 if (aEntries
[i
].aId
== rFntFmtId
)
323 pRes
= &aEntries
[i
].aFntFmt
;
333 const SmFontFormat
* SmFontFormatList::GetFontFormat( size_t nPos
) const
335 const SmFontFormat
*pRes
= 0;
336 if (nPos
< aEntries
.size())
337 pRes
= &aEntries
[nPos
].aFntFmt
;
342 const String
SmFontFormatList::GetFontFormatId( const SmFontFormat
&rFntFmt
) const
346 for (size_t i
= 0; i
< aEntries
.size(); ++i
)
348 if (aEntries
[i
].aFntFmt
== rFntFmt
)
350 aRes
= aEntries
[i
].aId
;
359 const String
SmFontFormatList::GetFontFormatId( const SmFontFormat
&rFntFmt
, bool bAdd
)
361 String
aRes( GetFontFormatId( rFntFmt
) );
362 if (0 == aRes
.Len() && bAdd
)
364 aRes
= GetNewFontFormatId();
365 AddFontFormat( aRes
, rFntFmt
);
371 const String
SmFontFormatList::GetFontFormatId( size_t nPos
) const
374 if (nPos
< aEntries
.size())
375 aRes
= aEntries
[nPos
].aId
;
380 const OUString
SmFontFormatList::GetNewFontFormatId() const
382 // returns first unused FormatId
384 OUString
aPrefix("Id");
385 sal_Int32 nCnt
= GetCount();
386 for (sal_Int32 i
= 1; i
<= nCnt
+ 1; ++i
)
388 OUString aTmpId
= aPrefix
+ OUString::valueOf(i
);
389 if (!GetFontFormat(aTmpId
))
392 OSL_ENSURE( !this, "failed to create new FontFormatId" );
397 /////////////////////////////////////////////////////////////////
399 SmMathConfig::SmMathConfig() :
400 ConfigItem(OUString(aRootName
))
407 bIsOtherModified
= bIsFormatModified
= false;
411 SmMathConfig::~SmMathConfig()
416 delete pFontFormatList
;
421 void SmMathConfig::SetOtherModified( bool bVal
)
423 bIsOtherModified
= bVal
;
427 void SmMathConfig::SetFormatModified( bool bVal
)
429 bIsFormatModified
= bVal
;
433 void SmMathConfig::SetFontFormatListModified( bool bVal
)
436 pFontFormatList
->SetModified( bVal
);
440 void SmMathConfig::ReadSymbol( SmSym
&rSymbol
,
441 const OUString
&rSymbolName
,
442 const OUString
&rBaseNode
) const
444 Sequence
< OUString
> aNames
= lcl_GetSymbolPropertyNames();
445 sal_Int32 nProps
= aNames
.getLength();
447 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
448 OUString
*pName
= aNames
.getArray();
449 for (sal_Int32 i
= 0; i
< nProps
; ++i
)
451 OUString
&rName
= pName
[i
];
452 OUString
aTmp( rName
);
455 rName
+= rSymbolName
;
460 const Sequence
< Any
> aValues
= ((SmMathConfig
*) this)->GetProperties( aNames
);
462 if (nProps
&& aValues
.getLength() == nProps
)
464 const Any
* pValue
= aValues
.getConstArray();
466 sal_UCS4 cChar
= '\0';
468 bool bPredefined
= false;
471 sal_Int32 nTmp32
= 0;
475 if (pValue
->hasValue() && (*pValue
>>= nTmp32
))
476 cChar
= static_cast< sal_UCS4
>( nTmp32
);
480 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
485 if (pValue
->hasValue() && (*pValue
>>= bTmp
))
490 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
492 const SmFontFormat
*pFntFmt
= GetFontFormatList().GetFontFormat( aTmpStr
);
493 OSL_ENSURE( pFntFmt
, "unknown FontFormat" );
495 aFont
= pFntFmt
->GetFont();
503 String
aUiName( rSymbolName
);
504 String
aUiSetName( aSet
);
508 aTmp
= GetUiSymbolName( rSymbolName
);
509 OSL_ENSURE( aTmp
.Len(), "localized symbol-name not found" );
512 aTmp
= GetUiSymbolSetName( aSet
);
513 OSL_ENSURE( aTmp
.Len(), "localized symbolset-name not found" );
518 rSymbol
= SmSym( aUiName
, aFont
, cChar
, aUiSetName
, bPredefined
);
519 if (aUiName
!= String(rSymbolName
))
520 rSymbol
.SetExportName( rSymbolName
);
524 OSL_FAIL( "symbol read error" );
530 SmSymbolManager
& SmMathConfig::GetSymbolManager()
534 pSymbolMgr
= new SmSymbolManager
;
541 void SmMathConfig::Commit()
547 void SmMathConfig::Save()
551 SaveFontFormatList();
555 void SmMathConfig::GetSymbols( std::vector
< SmSym
> &rSymbols
) const
557 Sequence
< OUString
> aNodes( ((SmMathConfig
*) this)->GetNodeNames( SYMBOL_LIST
) );
558 const OUString
*pNode
= aNodes
.getConstArray();
559 sal_Int32 nNodes
= aNodes
.getLength();
561 rSymbols
.resize( nNodes
);
562 std::vector
< SmSym
>::iterator
aIt( rSymbols
.begin() );
563 std::vector
< SmSym
>::iterator
aEnd( rSymbols
.end() );
566 ReadSymbol( *aIt
++, *pNode
++, SYMBOL_LIST
);
571 void SmMathConfig::SetSymbols( const std::vector
< SmSym
> &rNewSymbols
)
573 sal_uIntPtr nCount
= rNewSymbols
.size();
575 Sequence
< OUString
> aNames
= lcl_GetSymbolPropertyNames();
576 const OUString
*pNames
= aNames
.getConstArray();
577 sal_uIntPtr nSymbolProps
= sal::static_int_cast
< sal_uInt32
>(aNames
.getLength());
579 Sequence
< PropertyValue
> aValues( nCount
* nSymbolProps
);
580 PropertyValue
*pValues
= aValues
.getArray();
582 PropertyValue
*pVal
= pValues
;
583 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
584 std::vector
< SmSym
>::const_iterator
aIt( rNewSymbols
.begin() );
585 std::vector
< SmSym
>::const_iterator
aEnd( rNewSymbols
.end() );
588 const SmSym
&rSymbol
= *aIt
++;
589 OUString
aNodeNameDelim( SYMBOL_LIST
);
590 aNodeNameDelim
+= aDelim
;
591 aNodeNameDelim
+= rSymbol
.GetExportName();
592 aNodeNameDelim
+= aDelim
;
594 const OUString
*pName
= pNames
;
597 pVal
->Name
= aNodeNameDelim
;
598 pVal
->Name
+= *pName
++;
599 pVal
->Value
<<= static_cast< sal_UCS4
>( rSymbol
.GetCharacter() );
602 pVal
->Name
= aNodeNameDelim
;
603 pVal
->Name
+= *pName
++;
604 OUString
aTmp( rSymbol
.GetSymbolSetName() );
605 if (rSymbol
.IsPredefined())
606 aTmp
= GetExportSymbolSetName( aTmp
);
607 pVal
->Value
<<= aTmp
;
610 pVal
->Name
= aNodeNameDelim
;
611 pVal
->Name
+= *pName
++;
612 pVal
->Value
<<= (sal_Bool
) rSymbol
.IsPredefined();
615 SmFontFormat
aFntFmt( rSymbol
.GetFace() );
616 String
aFntFmtId( GetFontFormatList().GetFontFormatId( aFntFmt
, true ) );
617 OSL_ENSURE( aFntFmtId
.Len(), "FontFormatId not found" );
618 pVal
->Name
= aNodeNameDelim
;
619 pVal
->Name
+= *pName
++;
620 pVal
->Value
<<= OUString( aFntFmtId
);
623 OSL_ENSURE( pVal
- pValues
== sal::static_int_cast
< ptrdiff_t >(nCount
* nSymbolProps
), "properties missing" );
624 ReplaceSetProperties( SYMBOL_LIST
, aValues
);
626 StripFontFormatList( rNewSymbols
);
627 SaveFontFormatList();
631 SmFontFormatList
& SmMathConfig::GetFontFormatList()
633 if (!pFontFormatList
)
635 LoadFontFormatList();
637 return *pFontFormatList
;
641 void SmMathConfig::LoadFontFormatList()
643 if (!pFontFormatList
)
644 pFontFormatList
= new SmFontFormatList
;
646 pFontFormatList
->Clear();
648 Sequence
< OUString
> aNodes( GetNodeNames( FONT_FORMAT_LIST
) );
649 const OUString
*pNode
= aNodes
.getConstArray();
650 sal_Int32 nNodes
= aNodes
.getLength();
652 for (sal_Int32 i
= 0; i
< nNodes
; ++i
)
654 SmFontFormat aFntFmt
;
655 ReadFontFormat( aFntFmt
, pNode
[i
], FONT_FORMAT_LIST
);
656 if (!pFontFormatList
->GetFontFormat( pNode
[i
] ))
658 OSL_ENSURE( 0 == pFontFormatList
->GetFontFormat( pNode
[i
] ),
659 "FontFormat ID already exists" );
660 pFontFormatList
->AddFontFormat( pNode
[i
], aFntFmt
);
663 pFontFormatList
->SetModified( false );
667 void SmMathConfig::ReadFontFormat( SmFontFormat
&rFontFormat
,
668 const OUString
&rSymbolName
, const OUString
&rBaseNode
) const
670 Sequence
< OUString
> aNames
= lcl_GetFontPropertyNames();
671 sal_Int32 nProps
= aNames
.getLength();
673 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
674 OUString
*pName
= aNames
.getArray();
675 for (sal_Int32 i
= 0; i
< nProps
; ++i
)
677 OUString
&rName
= pName
[i
];
678 OUString
aTmp( rName
);
681 rName
+= rSymbolName
;
686 const Sequence
< Any
> aValues
= ((SmMathConfig
*) this)->GetProperties( aNames
);
688 if (nProps
&& aValues
.getLength() == nProps
)
690 const Any
* pValue
= aValues
.getConstArray();
693 sal_Int16 nTmp16
= 0;
696 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
697 rFontFormat
.aName
= aTmpStr
;
701 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
702 rFontFormat
.nCharSet
= nTmp16
; // 6.0 file-format GetSOLoadTextEncoding not needed
706 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
707 rFontFormat
.nFamily
= nTmp16
;
711 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
712 rFontFormat
.nPitch
= nTmp16
;
716 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
717 rFontFormat
.nWeight
= nTmp16
;
721 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
722 rFontFormat
.nItalic
= nTmp16
;
727 OSL_ENSURE( bOK
, "read FontFormat failed" );
733 void SmMathConfig::SaveFontFormatList()
735 SmFontFormatList
&rFntFmtList
= GetFontFormatList();
737 if (!rFntFmtList
.IsModified())
740 Sequence
< OUString
> aNames
= lcl_GetFontPropertyNames();
741 sal_Int32 nSymbolProps
= aNames
.getLength();
743 size_t nCount
= rFntFmtList
.GetCount();
745 Sequence
< PropertyValue
> aValues( nCount
* nSymbolProps
);
746 PropertyValue
*pValues
= aValues
.getArray();
748 PropertyValue
*pVal
= pValues
;
749 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
750 for (size_t i
= 0; i
< nCount
; ++i
)
752 String
aFntFmtId( rFntFmtList
.GetFontFormatId( i
) );
753 const SmFontFormat
aFntFmt( *rFntFmtList
.GetFontFormat( aFntFmtId
) );
755 OUString
aNodeNameDelim( FONT_FORMAT_LIST
);
756 aNodeNameDelim
+= aDelim
;
757 aNodeNameDelim
+= aFntFmtId
;
758 aNodeNameDelim
+= aDelim
;
760 const OUString
*pName
= aNames
.getConstArray();
763 pVal
->Name
= aNodeNameDelim
;
764 pVal
->Name
+= *pName
++;
765 pVal
->Value
<<= OUString( aFntFmt
.aName
);
768 pVal
->Name
= aNodeNameDelim
;
769 pVal
->Name
+= *pName
++;
770 pVal
->Value
<<= (sal_Int16
) aFntFmt
.nCharSet
; // 6.0 file-format GetSOStoreTextEncoding not needed
773 pVal
->Name
= aNodeNameDelim
;
774 pVal
->Name
+= *pName
++;
775 pVal
->Value
<<= (sal_Int16
) aFntFmt
.nFamily
;
778 pVal
->Name
= aNodeNameDelim
;
779 pVal
->Name
+= *pName
++;
780 pVal
->Value
<<= (sal_Int16
) aFntFmt
.nPitch
;
783 pVal
->Name
= aNodeNameDelim
;
784 pVal
->Name
+= *pName
++;
785 pVal
->Value
<<= (sal_Int16
) aFntFmt
.nWeight
;
788 pVal
->Name
= aNodeNameDelim
;
789 pVal
->Name
+= *pName
++;
790 pVal
->Value
<<= (sal_Int16
) aFntFmt
.nItalic
;
793 OSL_ENSURE( sal::static_int_cast
<size_t>(pVal
- pValues
) == nCount
* nSymbolProps
, "properties missing" );
794 ReplaceSetProperties( FONT_FORMAT_LIST
, aValues
);
796 rFntFmtList
.SetModified( false );
800 void SmMathConfig::StripFontFormatList( const std::vector
< SmSym
> &rSymbols
)
804 // build list of used font-formats only
805 //!! font-format IDs may be different !!
806 SmFontFormatList aUsedList
;
807 for (i
= 0; i
< rSymbols
.size(); ++i
)
809 OSL_ENSURE( rSymbols
[i
].GetName().getLength() > 0, "non named symbol" );
810 aUsedList
.GetFontFormatId( SmFontFormat( rSymbols
[i
].GetFace() ) , true );
812 const SmFormat
& rStdFmt
= GetStandardFormat();
813 for (i
= FNT_BEGIN
; i
<= FNT_END
; ++i
)
815 aUsedList
.GetFontFormatId( SmFontFormat( rStdFmt
.GetFont( i
) ) , true );
818 // remove unused font-formats from list
819 SmFontFormatList
&rFntFmtList
= GetFontFormatList();
820 size_t nCnt
= rFntFmtList
.GetCount();
821 SmFontFormat
*pTmpFormat
= new SmFontFormat
[ nCnt
];
822 String
*pId
= new String
[ nCnt
];
824 for (k
= 0; k
< nCnt
; ++k
)
826 pTmpFormat
[k
] = *rFntFmtList
.GetFontFormat( k
);
827 pId
[k
] = rFntFmtList
.GetFontFormatId( k
);
829 for (k
= 0; k
< nCnt
; ++k
)
831 if (0 == aUsedList
.GetFontFormatId( pTmpFormat
[k
] ).Len())
833 rFntFmtList
.RemoveFontFormat( pId
[k
] );
837 delete [] pTmpFormat
;
841 void SmMathConfig::LoadOther()
844 pOther
= new SmCfgOther
;
846 Sequence
< OUString
> aNames( GetOtherPropertyNames() );
847 sal_Int32 nProps
= aNames
.getLength();
849 Sequence
< Any
> aValues( GetProperties( aNames
) );
850 if (nProps
&& aValues
.getLength() == nProps
)
852 const Any
*pValues
= aValues
.getConstArray();
853 const Any
*pVal
= pValues
;
855 sal_Int16 nTmp16
= 0;
859 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
860 pOther
->bPrintTitle
= bTmp
;
863 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
864 pOther
->bPrintFormulaText
= bTmp
;
867 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
868 pOther
->bPrintFrame
= bTmp
;
871 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
872 pOther
->ePrintSize
= (SmPrintSize
) nTmp16
;
875 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
876 pOther
->nPrintZoomFactor
= nTmp16
;
878 // LoadSave/IsSaveOnlyUsedSymbols
879 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
880 pOther
->bIsSaveOnlyUsedSymbols
= bTmp
;
882 // Misc/IgnoreSpacesRight
883 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
884 pOther
->bIgnoreSpacesRight
= bTmp
;
886 // View/ToolboxVisible
887 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
888 pOther
->bToolboxVisible
= bTmp
;
891 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
892 pOther
->bAutoRedraw
= bTmp
;
894 // View/FormulaCursor
895 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
896 pOther
->bFormulaCursor
= bTmp
;
899 OSL_ENSURE( pVal
- pValues
== nProps
, "property mismatch" );
900 SetOtherModified( false );
905 void SmMathConfig::SaveOther()
907 if (!pOther
|| !IsOtherModified())
910 const Sequence
< OUString
> aNames( GetOtherPropertyNames() );
911 sal_Int32 nProps
= aNames
.getLength();
913 Sequence
< Any
> aValues( nProps
);
914 Any
*pValues
= aValues
.getArray();
915 Any
*pValue
= pValues
;
918 *pValue
++ <<= (sal_Bool
) pOther
->bPrintTitle
;
920 *pValue
++ <<= (sal_Bool
) pOther
->bPrintFormulaText
;
922 *pValue
++ <<= (sal_Bool
) pOther
->bPrintFrame
;
924 *pValue
++ <<= (sal_Int16
) pOther
->ePrintSize
;
926 *pValue
++ <<= (sal_Int16
) pOther
->nPrintZoomFactor
;
927 // LoadSave/IsSaveOnlyUsedSymbols
928 *pValue
++ <<= (sal_Bool
) pOther
->bIsSaveOnlyUsedSymbols
;
929 // Misc/IgnoreSpacesRight
930 *pValue
++ <<= (sal_Bool
) pOther
->bIgnoreSpacesRight
;
931 // View/ToolboxVisible
932 *pValue
++ <<= (sal_Bool
) pOther
->bToolboxVisible
;
934 *pValue
++ <<= (sal_Bool
) pOther
->bAutoRedraw
;
935 // View/FormulaCursor
936 *pValue
++ <<= (sal_Bool
) pOther
->bFormulaCursor
;
938 OSL_ENSURE( pValue
- pValues
== nProps
, "property mismatch" );
939 PutProperties( aNames
, aValues
);
941 SetOtherModified( false );
944 void SmMathConfig::LoadFormat()
947 pFormat
= new SmFormat
;
950 Sequence
< OUString
> aNames( GetFormatPropertyNames() );
951 sal_Int32 nProps
= aNames
.getLength();
953 Sequence
< Any
> aValues( GetProperties( aNames
) );
954 if (nProps
&& aValues
.getLength() == nProps
)
956 const Any
*pValues
= aValues
.getConstArray();
957 const Any
*pVal
= pValues
;
960 sal_Int16 nTmp16
= 0;
963 // StandardFormat/Textmode
964 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
965 pFormat
->SetTextmode( bTmp
);
967 // StandardFormat/GreekCharStyle
968 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
969 pFormat
->SetGreekCharStyle( nTmp16
);
971 // StandardFormat/ScaleNormalBracket
972 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
973 pFormat
->SetScaleNormalBrackets( bTmp
);
975 // StandardFormat/HorizontalAlignment
976 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
977 pFormat
->SetHorAlign( (SmHorAlign
) nTmp16
);
979 // StandardFormat/BaseSize
980 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
981 pFormat
->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16
)) );
985 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; ++i
)
987 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
988 pFormat
->SetRelSize( i
, nTmp16
);
992 for (i
= DIS_BEGIN
; i
<= DIS_END
; ++i
)
994 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
995 pFormat
->SetDistance( i
, nTmp16
);
999 LanguageType nLang
= Application::GetSettings().GetUILanguageTag().getLanguageType();
1000 for (i
= FNT_BEGIN
; i
< FNT_END
; ++i
)
1003 bool bUseDefaultFont
= true;
1004 if (pVal
->hasValue() && (*pVal
>>= aTmpStr
))
1006 bUseDefaultFont
= aTmpStr
.isEmpty();
1007 if (bUseDefaultFont
)
1009 aFnt
= pFormat
->GetFont( i
);
1010 aFnt
.SetName( GetDefaultFontName( nLang
, i
) );
1014 const SmFontFormat
*pFntFmt
= GetFontFormatList().GetFontFormat( aTmpStr
);
1015 OSL_ENSURE( pFntFmt
, "unknown FontFormat" );
1017 aFnt
= pFntFmt
->GetFont();
1022 aFnt
.SetSize( pFormat
->GetBaseSize() );
1023 pFormat
->SetFont( i
, aFnt
, bUseDefaultFont
);
1026 OSL_ENSURE( pVal
- pValues
== nProps
, "property mismatch" );
1027 SetFormatModified( false );
1032 void SmMathConfig::SaveFormat()
1034 if (!pFormat
|| !IsFormatModified())
1037 const Sequence
< OUString
> aNames( GetFormatPropertyNames() );
1038 sal_Int32 nProps
= aNames
.getLength();
1040 Sequence
< Any
> aValues( nProps
);
1041 Any
*pValues
= aValues
.getArray();
1042 Any
*pValue
= pValues
;
1044 // StandardFormat/Textmode
1045 *pValue
++ <<= (sal_Bool
) pFormat
->IsTextmode();
1046 // StandardFormat/GreekCharStyle
1047 *pValue
++ <<= (sal_Int16
) pFormat
->GetGreekCharStyle();
1048 // StandardFormat/ScaleNormalBracket
1049 *pValue
++ <<= (sal_Bool
) pFormat
->IsScaleNormalBrackets();
1050 // StandardFormat/HorizontalAlignment
1051 *pValue
++ <<= (sal_Int16
) pFormat
->GetHorAlign();
1052 // StandardFormat/BaseSize
1053 *pValue
++ <<= (sal_Int16
) SmRoundFraction( Sm100th_mmToPts(
1054 pFormat
->GetBaseSize().Height() ) );
1057 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; ++i
)
1058 *pValue
++ <<= (sal_Int16
) pFormat
->GetRelSize( i
);
1060 for (i
= DIS_BEGIN
; i
<= DIS_END
; ++i
)
1061 *pValue
++ <<= (sal_Int16
) pFormat
->GetDistance( i
);
1063 for (i
= FNT_BEGIN
; i
< FNT_END
; ++i
)
1067 if (!pFormat
->IsDefaultFont( i
))
1069 SmFontFormat
aFntFmt( pFormat
->GetFont( i
) );
1070 aFntFmtId
= GetFontFormatList().GetFontFormatId( aFntFmt
, true );
1071 OSL_ENSURE( !aFntFmtId
.isEmpty(), "FontFormatId not found" );
1074 *pValue
++ <<= aFntFmtId
;
1077 OSL_ENSURE( pValue
- pValues
== nProps
, "property mismatch" );
1078 PutProperties( aNames
, aValues
);
1080 SetFormatModified( false );
1084 const SmFormat
& SmMathConfig::GetStandardFormat() const
1087 ((SmMathConfig
*) this)->LoadFormat();
1092 void SmMathConfig::SetStandardFormat( const SmFormat
&rFormat
, bool bSaveFontFormatList
)
1096 if (rFormat
!= *pFormat
)
1099 SetFormatModified( true );
1102 if (bSaveFontFormatList
)
1104 // needed for SmFontTypeDialog's DefaultButtonClickHdl
1105 SetFontFormatListModified( true );
1106 SaveFontFormatList();
1112 SmPrintSize
SmMathConfig::GetPrintSize() const
1115 ((SmMathConfig
*) this)->LoadOther();
1116 return pOther
->ePrintSize
;
1120 void SmMathConfig::SetPrintSize( SmPrintSize eSize
)
1124 if (eSize
!= pOther
->ePrintSize
)
1126 pOther
->ePrintSize
= eSize
;
1127 SetOtherModified( true );
1132 sal_uInt16
SmMathConfig::GetPrintZoomFactor() const
1135 ((SmMathConfig
*) this)->LoadOther();
1136 return pOther
->nPrintZoomFactor
;
1140 void SmMathConfig::SetPrintZoomFactor( sal_uInt16 nVal
)
1144 if (nVal
!= pOther
->nPrintZoomFactor
)
1146 pOther
->nPrintZoomFactor
= nVal
;
1147 SetOtherModified( true );
1152 void SmMathConfig::SetOtherIfNotEqual( bool &rbItem
, bool bNewVal
)
1154 if (bNewVal
!= rbItem
)
1157 SetOtherModified( true );
1162 bool SmMathConfig::IsPrintTitle() const
1165 ((SmMathConfig
*) this)->LoadOther();
1166 return pOther
->bPrintTitle
;
1170 void SmMathConfig::SetPrintTitle( bool bVal
)
1174 SetOtherIfNotEqual( pOther
->bPrintTitle
, bVal
);
1178 bool SmMathConfig::IsPrintFormulaText() const
1181 ((SmMathConfig
*) this)->LoadOther();
1182 return pOther
->bPrintFormulaText
;
1186 void SmMathConfig::SetPrintFormulaText( bool bVal
)
1190 SetOtherIfNotEqual( pOther
->bPrintFormulaText
, bVal
);
1193 bool SmMathConfig::IsSaveOnlyUsedSymbols() const
1196 ((SmMathConfig
*) this)->LoadOther();
1197 return pOther
->bIsSaveOnlyUsedSymbols
;
1200 bool SmMathConfig::IsPrintFrame() const
1203 ((SmMathConfig
*) this)->LoadOther();
1204 return pOther
->bPrintFrame
;
1208 void SmMathConfig::SetPrintFrame( bool bVal
)
1212 SetOtherIfNotEqual( pOther
->bPrintFrame
, bVal
);
1216 void SmMathConfig::SetSaveOnlyUsedSymbols( bool bVal
)
1220 SetOtherIfNotEqual( pOther
->bIsSaveOnlyUsedSymbols
, bVal
);
1224 bool SmMathConfig::IsIgnoreSpacesRight() const
1227 ((SmMathConfig
*) this)->LoadOther();
1228 return pOther
->bIgnoreSpacesRight
;
1232 void SmMathConfig::SetIgnoreSpacesRight( bool bVal
)
1236 SetOtherIfNotEqual( pOther
->bIgnoreSpacesRight
, bVal
);
1240 bool SmMathConfig::IsAutoRedraw() const
1243 ((SmMathConfig
*) this)->LoadOther();
1244 return pOther
->bAutoRedraw
;
1248 void SmMathConfig::SetAutoRedraw( bool bVal
)
1252 SetOtherIfNotEqual( pOther
->bAutoRedraw
, bVal
);
1256 bool SmMathConfig::IsShowFormulaCursor() const
1259 ((SmMathConfig
*) this)->LoadOther();
1260 return pOther
->bFormulaCursor
;
1264 void SmMathConfig::SetShowFormulaCursor( bool bVal
)
1268 SetOtherIfNotEqual( pOther
->bFormulaCursor
, bVal
);
1271 void SmMathConfig::Notify( const com::sun::star::uno::Sequence
< OUString
>& )
1274 /////////////////////////////////////////////////////////////////
1276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */