1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_starmath.hxx"
32 #include <vcl/svapp.hxx>
34 #include "cfgitem.hxx"
36 #include "starmath.hrc"
41 using namespace com::sun::star
;
42 using namespace com::sun::star::uno
;
43 using namespace com::sun::star::beans
;
46 static const char* aRootName
= "Office.Math";
48 #define SYMBOL_LIST "SymbolList"
49 #define FONT_FORMAT_LIST "FontFormatList"
51 SV_IMPL_OBJARR( SmFntFmtListEntryArr
, SmFntFmtListEntry
);
53 /////////////////////////////////////////////////////////////////
56 static Sequence
< OUString
> lcl_GetFontPropertyNames()
58 static const char * aPropNames
[] =
69 const char** ppPropName
= aPropNames
;
71 Sequence
< OUString
> aNames( 6 );
72 OUString
*pNames
= aNames
.getArray();
73 for( INT32 i
= 0; *ppPropName
; ++i
, ++ppPropName
)
75 pNames
[i
] = A2OU( *ppPropName
);
77 //aNames.realloc( i );
81 /////////////////////////////////////////////////////////////////
84 static Sequence
< OUString
> lcl_GetSymbolPropertyNames()
86 static const char * aPropNames
[] =
95 const char** ppPropName
= aPropNames
;
97 Sequence
< OUString
> aNames( 4 );
98 OUString
*pNames
= aNames
.getArray();
99 for( INT32 i
= 0; *ppPropName
; ++i
, ++ppPropName
)
101 pNames
[i
] = A2OU( *ppPropName
);
103 //aNames.realloc( i );
107 /////////////////////////////////////////////////////////////////
109 static const char * aMathPropNames
[] =
116 //"Misc/NoSymbolsWarning",
117 "Misc/IgnoreSpacesRight",
118 "View/ToolboxVisible",
124 //! Beware of order according to *_BEGIN *_END defines in format.hxx !
125 //! see respective load/save routines here
126 static const char * aFormatPropNames
[] =
128 "StandardFormat/Textmode",
129 "StandardFormat/GreekCharStyle",
130 "StandardFormat/ScaleNormalBracket",
131 "StandardFormat/HorizontalAlignment",
132 "StandardFormat/BaseSize",
133 "StandardFormat/TextSize",
134 "StandardFormat/IndexSize",
135 "StandardFormat/FunctionSize",
136 "StandardFormat/OperatorSize",
137 "StandardFormat/LimitsSize",
138 "StandardFormat/Distance/Horizontal",
139 "StandardFormat/Distance/Vertical",
140 "StandardFormat/Distance/Root",
141 "StandardFormat/Distance/SuperScript",
142 "StandardFormat/Distance/SubScript",
143 "StandardFormat/Distance/Numerator",
144 "StandardFormat/Distance/Denominator",
145 "StandardFormat/Distance/Fraction",
146 "StandardFormat/Distance/StrokeWidth",
147 "StandardFormat/Distance/UpperLimit",
148 "StandardFormat/Distance/LowerLimit",
149 "StandardFormat/Distance/BracketSize",
150 "StandardFormat/Distance/BracketSpace",
151 "StandardFormat/Distance/MatrixRow",
152 "StandardFormat/Distance/MatrixColumn",
153 "StandardFormat/Distance/OrnamentSize",
154 "StandardFormat/Distance/OrnamentSpace",
155 "StandardFormat/Distance/OperatorSize",
156 "StandardFormat/Distance/OperatorSpace",
157 "StandardFormat/Distance/LeftSpace",
158 "StandardFormat/Distance/RightSpace",
159 "StandardFormat/Distance/TopSpace",
160 "StandardFormat/Distance/BottomSpace",
161 "StandardFormat/Distance/NormalBracketSize",
162 "StandardFormat/VariableFont",
163 "StandardFormat/FunctionFont",
164 "StandardFormat/NumberFont",
165 "StandardFormat/TextFont",
166 "StandardFormat/SerifFont",
167 "StandardFormat/SansFont",
168 "StandardFormat/FixedFont"
172 static Sequence
< OUString
> lcl_GetPropertyNames(
173 const char * aPropNames
[], USHORT nCount
)
176 const char** ppPropName
= aPropNames
;
178 Sequence
< OUString
> aNames( nCount
);
179 OUString
*pNames
= aNames
.getArray();
180 for (INT32 i
= 0; i
< nCount
; ++i
, ++ppPropName
)
182 pNames
[i
] = A2OU( *ppPropName
);
184 //aNames.realloc( i );
189 static Sequence
< OUString
> GetFormatPropertyNames()
191 USHORT nCnt
= sizeof(aFormatPropNames
) / sizeof(aFormatPropNames
[0]);
192 return lcl_GetPropertyNames( aFormatPropNames
, nCnt
);
196 static Sequence
< OUString
> GetOtherPropertyNames()
198 USHORT nCnt
= sizeof(aMathPropNames
) / sizeof(aMathPropNames
[0]);
199 return lcl_GetPropertyNames( aMathPropNames
, nCnt
);
202 /////////////////////////////////////////////////////////////////
206 SmPrintSize ePrintSize
;
207 USHORT nPrintZoomFactor
;
209 BOOL bPrintFormulaText
;
211 BOOL bIgnoreSpacesRight
;
212 BOOL bToolboxVisible
;
215 //BOOL bNoSymbolsWarning;
221 SmCfgOther::SmCfgOther()
223 ePrintSize
= PRINT_SIZE_NORMAL
;
224 nPrintZoomFactor
= 100;
225 bPrintTitle
= bPrintFormulaText
=
226 bPrintFrame
= bIgnoreSpacesRight
=
227 bToolboxVisible
= bAutoRedraw
=
228 bFormulaCursor
= /*bNoSymbolsWarning =*/ TRUE
;
231 /////////////////////////////////////////////////////////////////
234 SmFontFormat::SmFontFormat()
236 aName
.AssignAscii( FONTNAME_MATH
);
237 nCharSet
= RTL_TEXTENCODING_UNICODE
;
238 nFamily
= FAMILY_DONTKNOW
;
239 nPitch
= PITCH_DONTKNOW
;
240 nWeight
= WEIGHT_DONTKNOW
;
241 nItalic
= ITALIC_NONE
;
245 SmFontFormat::SmFontFormat( const Font
&rFont
)
247 aName
= rFont
.GetName();
248 nCharSet
= (INT16
) rFont
.GetCharSet();
249 nFamily
= (INT16
) rFont
.GetFamily();
250 nPitch
= (INT16
) rFont
.GetPitch();
251 nWeight
= (INT16
) rFont
.GetWeight();
252 nItalic
= (INT16
) rFont
.GetItalic();
256 const Font
SmFontFormat::GetFont() const
259 aRes
.SetName( aName
);
260 aRes
.SetCharSet( (rtl_TextEncoding
) nCharSet
);
261 aRes
.SetFamily( (FontFamily
) nFamily
);
262 aRes
.SetPitch( (FontPitch
) nPitch
);
263 aRes
.SetWeight( (FontWeight
) nWeight
);
264 aRes
.SetItalic( (FontItalic
) nItalic
);
269 BOOL
SmFontFormat::operator == ( const SmFontFormat
&rFntFmt
) const
271 return aName
== rFntFmt
.aName
&&
272 nCharSet
== rFntFmt
.nCharSet
&&
273 nFamily
== rFntFmt
.nFamily
&&
274 nPitch
== rFntFmt
.nPitch
&&
275 nWeight
== rFntFmt
.nWeight
&&
276 nItalic
== rFntFmt
.nItalic
;
280 /////////////////////////////////////////////////////////////////
282 SmFntFmtListEntry::SmFntFmtListEntry( const String
&rId
, const SmFontFormat
&rFntFmt
) :
289 SmFontFormatList::SmFontFormatList()
295 void SmFontFormatList::Clear()
297 USHORT nCnt
= aEntries
.Count();
300 aEntries
.Remove( 0, nCnt
);
306 void SmFontFormatList::AddFontFormat( const String
&rFntFmtId
,
307 const SmFontFormat
&rFntFmt
)
309 const SmFontFormat
*pFntFmt
= GetFontFormat( rFntFmtId
);
310 DBG_ASSERT( !pFntFmt
, "FontFormatId already exists" );
313 SmFntFmtListEntry
aEntry( rFntFmtId
, rFntFmt
);
314 aEntries
.Insert( aEntry
, aEntries
.Count() );
320 void SmFontFormatList::RemoveFontFormat( const String
&rFntFmtId
)
322 USHORT nPos
= 0xFFFF;
325 USHORT nCnt
= aEntries
.Count();
326 for (USHORT i
= 0; i
< nCnt
&& nPos
== 0xFFFF; ++i
)
328 if (aEntries
[i
].aId
== rFntFmtId
)
332 // remove entry if found
335 aEntries
.Remove( nPos
);
341 const SmFontFormat
* SmFontFormatList::GetFontFormat( const String
&rFntFmtId
) const
343 SmFontFormat
*pRes
= 0;
345 USHORT nCnt
= aEntries
.Count();
347 for (i
= 0; i
< nCnt
&& !pRes
; ++i
)
349 if (aEntries
[i
].aId
== rFntFmtId
)
350 pRes
= &aEntries
[i
].aFntFmt
;
358 const SmFontFormat
* SmFontFormatList::GetFontFormat( USHORT nPos
) const
360 SmFontFormat
*pRes
= 0;
361 if (nPos
< aEntries
.Count())
362 pRes
= &aEntries
[ nPos
].aFntFmt
;
367 const String
SmFontFormatList::GetFontFormatId( const SmFontFormat
&rFntFmt
) const
371 USHORT nCnt
= aEntries
.Count();
373 for (i
= 0; i
< nCnt
&& 0 == aRes
.Len(); ++i
)
375 if (aEntries
[i
].aFntFmt
== rFntFmt
)
376 aRes
= aEntries
[i
].aId
;
383 const String
SmFontFormatList::GetFontFormatId( const SmFontFormat
&rFntFmt
, BOOL bAdd
)
385 String
aRes( GetFontFormatId( rFntFmt
) );
386 if (0 == aRes
.Len() && bAdd
)
388 aRes
= GetNewFontFormatId();
389 AddFontFormat( aRes
, rFntFmt
);
395 const String
SmFontFormatList::GetFontFormatId( USHORT nPos
) const
398 if (nPos
< aEntries
.Count())
399 aRes
= aEntries
[nPos
].aId
;
404 const String
SmFontFormatList::GetNewFontFormatId() const
406 // returns first unused FormatId
410 String
aPrefix( RTL_CONSTASCII_STRINGPARAM( "Id" ) );
411 INT32 nCnt
= GetCount();
412 for (INT32 i
= 1; i
<= nCnt
+ 1 && 0 == aRes
.Len(); ++i
)
414 String
aTmpId( aPrefix
);
415 aTmpId
+= String::CreateFromInt32( i
);
416 if (!GetFontFormat( aTmpId
))
419 DBG_ASSERT( 0 != aRes
.Len(), "failed to create new FontFormatId" );
424 /////////////////////////////////////////////////////////////////
426 SmMathConfig::SmMathConfig() :
427 ConfigItem( String::CreateFromAscii( aRootName
))
434 bIsOtherModified
= bIsFormatModified
= FALSE
;
438 SmMathConfig::~SmMathConfig()
443 delete pFontFormatList
;
448 void SmMathConfig::SetOtherModified( BOOL bVal
)
450 bIsOtherModified
= bVal
;
454 void SmMathConfig::SetFormatModified( BOOL bVal
)
456 bIsFormatModified
= bVal
;
460 void SmMathConfig::SetFontFormatListModified( BOOL bVal
)
463 pFontFormatList
->SetModified( bVal
);
467 void SmMathConfig::ReadSymbol( SmSym
&rSymbol
,
468 const rtl::OUString
&rSymbolName
,
469 const rtl::OUString
&rBaseNode
) const
471 Sequence
< OUString
> aNames
= lcl_GetSymbolPropertyNames();
472 INT32 nProps
= aNames
.getLength();
474 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
475 OUString
*pName
= aNames
.getArray();
476 for (INT32 i
= 0; i
< nProps
; ++i
)
478 OUString
&rName
= pName
[i
];
479 OUString
aTmp( rName
);
482 rName
+= rSymbolName
;
487 const Sequence
< Any
> aValues
= ((SmMathConfig
*) this)->GetProperties( aNames
);
489 if (nProps
&& aValues
.getLength() == nProps
)
491 const Any
* pValue
= aValues
.getConstArray();
493 sal_Unicode cChar
= '\0';
495 BOOL bPredefined
= FALSE
;
502 if (pValue
->hasValue() && (*pValue
>>= nTmp32
))
503 cChar
= (sal_Unicode
) nTmp32
;
507 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
512 if (pValue
->hasValue() && (*pValue
>>= bTmp
))
517 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
519 const SmFontFormat
*pFntFmt
= GetFontFormatList().GetFontFormat( aTmpStr
);
520 DBG_ASSERT( pFntFmt
, "unknown FontFormat" );
522 aFont
= pFntFmt
->GetFont();
530 String
aUiName( rSymbolName
);
531 String
aUiSetName( aSet
);
535 aTmp
= GetUiSymbolName( rSymbolName
);
536 DBG_ASSERT( aTmp
.Len(), "localized symbol-name not found" );
539 aTmp
= GetUiSymbolSetName( aSet
);
540 DBG_ASSERT( aTmp
.Len(), "localized symbolset-name not found" );
545 rSymbol
= SmSym( aUiName
, aFont
, cChar
, aUiSetName
, bPredefined
);
546 if (aUiName
!= String(rSymbolName
))
547 rSymbol
.SetExportName( rSymbolName
);
551 DBG_ERROR( "symbol read error" );
557 SmSymbolManager
& SmMathConfig::GetSymbolManager()
561 pSymbolMgr
= new SmSymbolManager
;
568 void SmMathConfig::Commit()
574 void SmMathConfig::Save()
578 SaveFontFormatList();
582 void SmMathConfig::GetSymbols( std::vector
< SmSym
> &rSymbols
) const
584 Sequence
< OUString
> aNodes( ((SmMathConfig
*) this)->GetNodeNames( A2OU( SYMBOL_LIST
) ) );
585 const OUString
*pNode
= aNodes
.getConstArray();
586 INT32 nNodes
= aNodes
.getLength();
588 rSymbols
.resize( nNodes
);
589 std::vector
< SmSym
>::iterator
aIt( rSymbols
.begin() );
590 std::vector
< SmSym
>::iterator
aEnd( rSymbols
.end() );
593 ReadSymbol( *aIt
++, *pNode
++, A2OU( SYMBOL_LIST
) );
598 void SmMathConfig::SetSymbols( const std::vector
< SmSym
> &rNewSymbols
)
600 sal_uIntPtr nCount
= rNewSymbols
.size();
602 Sequence
< OUString
> aNames
= lcl_GetSymbolPropertyNames();
603 const OUString
*pNames
= aNames
.getConstArray();
604 sal_uIntPtr nSymbolProps
= sal::static_int_cast
< UINT32
>(aNames
.getLength());
606 Sequence
< PropertyValue
> aValues( nCount
* nSymbolProps
);
607 PropertyValue
*pValues
= aValues
.getArray();
609 PropertyValue
*pVal
= pValues
;
610 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
611 std::vector
< SmSym
>::const_iterator
aIt( rNewSymbols
.begin() );
612 std::vector
< SmSym
>::const_iterator
aEnd( rNewSymbols
.end() );
615 const SmSym
&rSymbol
= *aIt
++;
616 //const Font &rFont = rSymbol.GetFace();
617 OUString
aNodeNameDelim( A2OU( SYMBOL_LIST
) );
618 aNodeNameDelim
+= aDelim
;
619 aNodeNameDelim
+= rSymbol
.GetExportName();
620 aNodeNameDelim
+= aDelim
;
622 const OUString
*pName
= pNames
;
625 pVal
->Name
= aNodeNameDelim
;
626 pVal
->Name
+= *pName
++;
627 pVal
->Value
<<= (INT32
) rSymbol
.GetCharacter();
630 pVal
->Name
= aNodeNameDelim
;
631 pVal
->Name
+= *pName
++;
632 OUString
aTmp( rSymbol
.GetSymbolSetName() );
633 if (rSymbol
.IsPredefined())
634 aTmp
= GetExportSymbolSetName( aTmp
);
635 pVal
->Value
<<= aTmp
;
638 pVal
->Name
= aNodeNameDelim
;
639 pVal
->Name
+= *pName
++;
640 pVal
->Value
<<= (BOOL
) rSymbol
.IsPredefined();
643 SmFontFormat
aFntFmt( rSymbol
.GetFace() );
644 String
aFntFmtId( GetFontFormatList().GetFontFormatId( aFntFmt
, TRUE
) );
645 DBG_ASSERT( aFntFmtId
.Len(), "FontFormatId not found" );
646 pVal
->Name
= aNodeNameDelim
;
647 pVal
->Name
+= *pName
++;
648 pVal
->Value
<<= OUString( aFntFmtId
);
651 DBG_ASSERT( pVal
- pValues
== sal::static_int_cast
< ptrdiff_t >(nCount
* nSymbolProps
), "properties missing" );
652 ReplaceSetProperties( A2OU( SYMBOL_LIST
) , aValues
);
654 StripFontFormatList( rNewSymbols
);
655 SaveFontFormatList();
659 SmFontFormatList
& SmMathConfig::GetFontFormatList()
661 if (!pFontFormatList
)
663 LoadFontFormatList();
665 return *pFontFormatList
;
669 void SmMathConfig::LoadFontFormatList()
671 if (!pFontFormatList
)
672 pFontFormatList
= new SmFontFormatList
;
674 pFontFormatList
->Clear();
676 Sequence
< OUString
> aNodes( GetNodeNames( A2OU( FONT_FORMAT_LIST
) ) );
677 const OUString
*pNode
= aNodes
.getConstArray();
678 INT32 nNodes
= aNodes
.getLength();
680 for (INT32 i
= 0; i
< nNodes
; ++i
)
682 SmFontFormat aFntFmt
;
683 ReadFontFormat( aFntFmt
, pNode
[i
], A2OU( FONT_FORMAT_LIST
) );
684 if (!pFontFormatList
->GetFontFormat( pNode
[i
] ))
686 DBG_ASSERT( 0 == pFontFormatList
->GetFontFormat( pNode
[i
] ),
687 "FontFormat ID already exists" );
688 pFontFormatList
->AddFontFormat( pNode
[i
], aFntFmt
);
691 pFontFormatList
->SetModified( FALSE
);
695 void SmMathConfig::ReadFontFormat( SmFontFormat
&rFontFormat
,
696 const OUString
&rSymbolName
, const OUString
&rBaseNode
) const
698 Sequence
< OUString
> aNames
= lcl_GetFontPropertyNames();
699 INT32 nProps
= aNames
.getLength();
701 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
702 OUString
*pName
= aNames
.getArray();
703 for (INT32 i
= 0; i
< nProps
; ++i
)
705 OUString
&rName
= pName
[i
];
706 OUString
aTmp( rName
);
709 rName
+= rSymbolName
;
714 const Sequence
< Any
> aValues
= ((SmMathConfig
*) this)->GetProperties( aNames
);
716 if (nProps
&& aValues
.getLength() == nProps
)
718 const Any
* pValue
= aValues
.getConstArray();
724 if (pValue
->hasValue() && (*pValue
>>= aTmpStr
))
725 rFontFormat
.aName
= aTmpStr
;
729 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
730 rFontFormat
.nCharSet
= nTmp16
; // 6.0 file-format GetSOLoadTextEncoding not needed
734 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
735 rFontFormat
.nFamily
= nTmp16
;
739 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
740 rFontFormat
.nPitch
= nTmp16
;
744 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
745 rFontFormat
.nWeight
= nTmp16
;
749 if (pValue
->hasValue() && (*pValue
>>= nTmp16
))
750 rFontFormat
.nItalic
= nTmp16
;
755 DBG_ASSERT( bOK
, "read FontFormat failed" );
760 void SmMathConfig::SaveFontFormatList()
762 SmFontFormatList
&rFntFmtList
= GetFontFormatList();
764 if (!rFntFmtList
.IsModified())
767 Sequence
< OUString
> aNames
= lcl_GetFontPropertyNames();
768 INT32 nSymbolProps
= aNames
.getLength();
770 USHORT nCount
= rFntFmtList
.GetCount();
772 Sequence
< PropertyValue
> aValues( nCount
* nSymbolProps
);
773 PropertyValue
*pValues
= aValues
.getArray();
775 PropertyValue
*pVal
= pValues
;
776 OUString
aDelim( OUString::valueOf( (sal_Unicode
) '/' ) );
777 for (USHORT i
= 0; i
< nCount
; ++i
)
779 String
aFntFmtId( rFntFmtList
.GetFontFormatId( i
) );
780 const SmFontFormat
aFntFmt( *rFntFmtList
.GetFontFormat( aFntFmtId
) );
782 OUString
aNodeNameDelim( A2OU( FONT_FORMAT_LIST
) );
783 aNodeNameDelim
+= aDelim
;
784 aNodeNameDelim
+= aFntFmtId
;
785 aNodeNameDelim
+= aDelim
;
787 const OUString
*pName
= aNames
.getConstArray();;
790 pVal
->Name
= aNodeNameDelim
;
791 pVal
->Name
+= *pName
++;
792 pVal
->Value
<<= OUString( aFntFmt
.aName
);
795 pVal
->Name
= aNodeNameDelim
;
796 pVal
->Name
+= *pName
++;
797 pVal
->Value
<<= (INT16
) aFntFmt
.nCharSet
; // 6.0 file-format GetSOStoreTextEncoding not needed
800 pVal
->Name
= aNodeNameDelim
;
801 pVal
->Name
+= *pName
++;
802 pVal
->Value
<<= (INT16
) aFntFmt
.nFamily
;
805 pVal
->Name
= aNodeNameDelim
;
806 pVal
->Name
+= *pName
++;
807 pVal
->Value
<<= (INT16
) aFntFmt
.nPitch
;
810 pVal
->Name
= aNodeNameDelim
;
811 pVal
->Name
+= *pName
++;
812 pVal
->Value
<<= (INT16
) aFntFmt
.nWeight
;
815 pVal
->Name
= aNodeNameDelim
;
816 pVal
->Name
+= *pName
++;
817 pVal
->Value
<<= (INT16
) aFntFmt
.nItalic
;
820 DBG_ASSERT( pVal
- pValues
== nCount
* nSymbolProps
, "properties missing" );
821 ReplaceSetProperties( A2OU( FONT_FORMAT_LIST
) , aValues
);
823 rFntFmtList
.SetModified( FALSE
);
827 void SmMathConfig::StripFontFormatList( const std::vector
< SmSym
> &rSymbols
)
829 size_t nCount
= rSymbols
.size();
832 // build list of used font-formats only
833 //!! font-format IDs may be different !!
834 SmFontFormatList aUsedList
;
835 for (i
= 0; i
< nCount
; ++i
)
837 DBG_ASSERT( rSymbols
[i
].GetName().Len() > 0, "non named symbol" );
838 aUsedList
.GetFontFormatId( SmFontFormat( rSymbols
[i
].GetFace() ) , TRUE
);
840 const SmFormat
& rStdFmt
= GetStandardFormat();
841 for (i
= FNT_BEGIN
; i
<= FNT_END
; ++i
)
843 aUsedList
.GetFontFormatId( SmFontFormat( rStdFmt
.GetFont( i
) ) , TRUE
);
846 // remove unused font-formats from list
847 SmFontFormatList
&rFntFmtList
= GetFontFormatList();
848 USHORT nCnt
= rFntFmtList
.GetCount();
849 SmFontFormat
*pTmpFormat
= new SmFontFormat
[ nCnt
];
850 String
*pId
= new String
[ nCnt
];
852 for (k
= 0; k
< nCnt
; ++k
)
854 pTmpFormat
[k
] = *rFntFmtList
.GetFontFormat( (USHORT
) k
);
855 pId
[k
] = rFntFmtList
.GetFontFormatId( (USHORT
) k
);
857 for (k
= 0; k
< nCnt
; ++k
)
859 if (0 == aUsedList
.GetFontFormatId( pTmpFormat
[k
] ).Len())
861 rFntFmtList
.RemoveFontFormat( pId
[k
] );
865 delete [] pTmpFormat
;
869 void SmMathConfig::LoadOther()
872 pOther
= new SmCfgOther
;
874 Sequence
< OUString
> aNames( GetOtherPropertyNames() );
875 INT32 nProps
= aNames
.getLength();
877 Sequence
< Any
> aValues( GetProperties( aNames
) );
878 if (nProps
&& aValues
.getLength() == nProps
)
880 const Any
*pValues
= aValues
.getConstArray();
881 const Any
*pVal
= pValues
;
887 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
888 pOther
->bPrintTitle
= bTmp
;
891 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
892 pOther
->bPrintFormulaText
= bTmp
;
895 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
896 pOther
->bPrintFrame
= bTmp
;
899 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
900 pOther
->ePrintSize
= (SmPrintSize
) nTmp16
;
903 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
904 pOther
->nPrintZoomFactor
= nTmp16
;
906 // Misc/NoSymbolsWarning
907 if (pVal->hasValue() && (*pVal >>= bTmp))
908 pOther->bNoSymbolsWarning = bTmp;
911 // Misc/IgnoreSpacesRight
912 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
913 pOther
->bIgnoreSpacesRight
= bTmp
;
915 // View/ToolboxVisible
916 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
917 pOther
->bToolboxVisible
= bTmp
;
920 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
921 pOther
->bAutoRedraw
= bTmp
;
923 // View/FormulaCursor
924 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
925 pOther
->bFormulaCursor
= bTmp
;
928 DBG_ASSERT( pVal
- pValues
== nProps
, "property mismatch" );
929 SetOtherModified( FALSE
);
934 void SmMathConfig::SaveOther()
936 if (!pOther
|| !IsOtherModified())
939 const Sequence
< OUString
> aNames( GetOtherPropertyNames() );
940 INT32 nProps
= aNames
.getLength();
942 Sequence
< Any
> aValues( nProps
);
943 Any
*pValues
= aValues
.getArray();
944 Any
*pValue
= pValues
;
947 *pValue
++ <<= (BOOL
) pOther
->bPrintTitle
;
949 *pValue
++ <<= (BOOL
) pOther
->bPrintFormulaText
;
951 *pValue
++ <<= (BOOL
) pOther
->bPrintFrame
;
953 *pValue
++ <<= (INT16
) pOther
->ePrintSize
;
955 *pValue
++ <<= (INT16
) pOther
->nPrintZoomFactor
;
956 /* // Misc/NoSymbolsWarning
957 *pValue++ <<= (BOOL) pOther->bNoSymbolsWarning;
959 // Misc/IgnoreSpacesRight
960 *pValue
++ <<= (BOOL
) pOther
->bIgnoreSpacesRight
;
961 // View/ToolboxVisible
962 *pValue
++ <<= (BOOL
) pOther
->bToolboxVisible
;
964 *pValue
++ <<= (BOOL
) pOther
->bAutoRedraw
;
965 // View/FormulaCursor
966 *pValue
++ <<= (BOOL
) pOther
->bFormulaCursor
;
968 DBG_ASSERT( pValue
- pValues
== nProps
, "property mismatch" );
969 PutProperties( aNames
, aValues
);
971 SetOtherModified( FALSE
);
974 void SmMathConfig::LoadFormat()
977 pFormat
= new SmFormat
;
980 Sequence
< OUString
> aNames( GetFormatPropertyNames() );
981 INT32 nProps
= aNames
.getLength();
983 Sequence
< Any
> aValues( GetProperties( aNames
) );
984 if (nProps
&& aValues
.getLength() == nProps
)
986 const Any
*pValues
= aValues
.getConstArray();
987 const Any
*pVal
= pValues
;
993 // StandardFormat/Textmode
994 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
995 pFormat
->SetTextmode( bTmp
);
997 // StandardFormat/GreekCharStyle
998 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
999 pFormat
->SetGreekCharStyle( nTmp16
);
1001 // StandardFormat/ScaleNormalBracket
1002 if (pVal
->hasValue() && (*pVal
>>= bTmp
))
1003 pFormat
->SetScaleNormalBrackets( bTmp
);
1005 // StandardFormat/HorizontalAlignment
1006 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1007 pFormat
->SetHorAlign( (SmHorAlign
) nTmp16
);
1009 // StandardFormat/BaseSize
1010 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1011 pFormat
->SetBaseSize( Size(0, SmPtsTo100th_mm( nTmp16
)) );
1015 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; ++i
)
1017 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1018 pFormat
->SetRelSize( i
, nTmp16
);
1022 for (i
= DIS_BEGIN
; i
<= DIS_END
; ++i
)
1024 if (pVal
->hasValue() && (*pVal
>>= nTmp16
))
1025 pFormat
->SetDistance( i
, nTmp16
);
1029 LanguageType nLang
= Application::GetSettings().GetUILanguage();
1030 for (i
= FNT_BEGIN
; i
< FNT_END
; ++i
)
1033 BOOL bUseDefaultFont
= TRUE
;
1034 if (pVal
->hasValue() && (*pVal
>>= aTmpStr
))
1036 bUseDefaultFont
= 0 == aTmpStr
.getLength();
1037 if (bUseDefaultFont
)
1039 aFnt
= pFormat
->GetFont( i
);
1040 aFnt
.SetName( GetDefaultFontName( nLang
, i
) );
1044 const SmFontFormat
*pFntFmt
= GetFontFormatList().GetFontFormat( aTmpStr
);
1045 DBG_ASSERT( pFntFmt
, "unknown FontFormat" );
1047 aFnt
= pFntFmt
->GetFont();
1052 aFnt
.SetSize( pFormat
->GetBaseSize() );
1053 pFormat
->SetFont( i
, aFnt
, bUseDefaultFont
);
1056 DBG_ASSERT( pVal
- pValues
== nProps
, "property mismatch" );
1057 SetFormatModified( FALSE
);
1062 void SmMathConfig::SaveFormat()
1064 if (!pFormat
|| !IsFormatModified())
1067 const Sequence
< OUString
> aNames( GetFormatPropertyNames() );
1068 INT32 nProps
= aNames
.getLength();
1070 Sequence
< Any
> aValues( nProps
);
1071 Any
*pValues
= aValues
.getArray();
1072 Any
*pValue
= pValues
;
1074 // StandardFormat/Textmode
1075 *pValue
++ <<= (BOOL
) pFormat
->IsTextmode();
1076 // StandardFormat/GreekCharStyle
1077 *pValue
++ <<= (INT16
) pFormat
->GetGreekCharStyle();
1078 // StandardFormat/ScaleNormalBracket
1079 *pValue
++ <<= (BOOL
) pFormat
->IsScaleNormalBrackets();
1080 // StandardFormat/HorizontalAlignment
1081 *pValue
++ <<= (INT16
) pFormat
->GetHorAlign();
1082 // StandardFormat/BaseSize
1083 *pValue
++ <<= (INT16
) SmRoundFraction( Sm100th_mmToPts(
1084 pFormat
->GetBaseSize().Height() ) );
1087 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; ++i
)
1088 *pValue
++ <<= (INT16
) pFormat
->GetRelSize( i
);
1090 for (i
= DIS_BEGIN
; i
<= DIS_END
; ++i
)
1091 *pValue
++ <<= (INT16
) pFormat
->GetDistance( i
);
1093 for (i
= FNT_BEGIN
; i
< FNT_END
; ++i
)
1097 if (!pFormat
->IsDefaultFont( i
))
1099 SmFontFormat
aFntFmt( pFormat
->GetFont( i
) );
1100 aFntFmtId
= GetFontFormatList().GetFontFormatId( aFntFmt
, TRUE
);
1101 DBG_ASSERT( aFntFmtId
.getLength(), "FontFormatId not found" );
1104 *pValue
++ <<= aFntFmtId
;
1107 DBG_ASSERT( pValue
- pValues
== nProps
, "property mismatch" );
1108 PutProperties( aNames
, aValues
);
1110 SetFormatModified( FALSE
);
1114 const SmFormat
& SmMathConfig::GetStandardFormat() const
1117 ((SmMathConfig
*) this)->LoadFormat();
1122 void SmMathConfig::SetStandardFormat( const SmFormat
&rFormat
, BOOL bSaveFontFormatList
)
1126 if (rFormat
!= *pFormat
)
1129 SetFormatModified( TRUE
);
1132 if (bSaveFontFormatList
)
1134 // needed for SmFontTypeDialog's DefaultButtonClickHdl
1135 SetFontFormatListModified( TRUE
);
1136 SaveFontFormatList();
1142 SmPrintSize
SmMathConfig::GetPrintSize() const
1145 ((SmMathConfig
*) this)->LoadOther();
1146 return pOther
->ePrintSize
;
1150 void SmMathConfig::SetPrintSize( SmPrintSize eSize
)
1154 if (eSize
!= pOther
->ePrintSize
)
1156 pOther
->ePrintSize
= eSize
;
1157 SetOtherModified( TRUE
);
1162 USHORT
SmMathConfig::GetPrintZoomFactor() const
1165 ((SmMathConfig
*) this)->LoadOther();
1166 return pOther
->nPrintZoomFactor
;
1170 void SmMathConfig::SetPrintZoomFactor( USHORT nVal
)
1174 if (nVal
!= pOther
->nPrintZoomFactor
)
1176 pOther
->nPrintZoomFactor
= nVal
;
1177 SetOtherModified( TRUE
);
1182 void SmMathConfig::SetOtherIfNotEqual( BOOL
&rbItem
, BOOL bNewVal
)
1184 if (bNewVal
!= rbItem
)
1187 SetOtherModified( TRUE
);
1192 BOOL
SmMathConfig::IsPrintTitle() const
1195 ((SmMathConfig
*) this)->LoadOther();
1196 return pOther
->bPrintTitle
;
1200 void SmMathConfig::SetPrintTitle( BOOL bVal
)
1204 SetOtherIfNotEqual( pOther
->bPrintTitle
, bVal
);
1208 BOOL
SmMathConfig::IsPrintFormulaText() const
1211 ((SmMathConfig
*) this)->LoadOther();
1212 return pOther
->bPrintFormulaText
;
1216 void SmMathConfig::SetPrintFormulaText( BOOL bVal
)
1220 SetOtherIfNotEqual( pOther
->bPrintFormulaText
, bVal
);
1224 BOOL
SmMathConfig::IsPrintFrame() const
1227 ((SmMathConfig
*) this)->LoadOther();
1228 return pOther
->bPrintFrame
;
1232 void SmMathConfig::SetPrintFrame( BOOL bVal
)
1236 SetOtherIfNotEqual( pOther
->bPrintFrame
, bVal
);
1240 BOOL
SmMathConfig::IsIgnoreSpacesRight() const
1243 ((SmMathConfig
*) this)->LoadOther();
1244 return pOther
->bIgnoreSpacesRight
;
1248 void SmMathConfig::SetIgnoreSpacesRight( BOOL bVal
)
1252 SetOtherIfNotEqual( pOther
->bIgnoreSpacesRight
, bVal
);
1256 BOOL
SmMathConfig::IsAutoRedraw() const
1259 ((SmMathConfig
*) this)->LoadOther();
1260 return pOther
->bAutoRedraw
;
1264 void SmMathConfig::SetAutoRedraw( BOOL bVal
)
1268 SetOtherIfNotEqual( pOther
->bAutoRedraw
, bVal
);
1272 BOOL
SmMathConfig::IsShowFormulaCursor() const
1275 ((SmMathConfig
*) this)->LoadOther();
1276 return pOther
->bFormulaCursor
;
1280 void SmMathConfig::SetShowFormulaCursor( BOOL bVal
)
1284 SetOtherIfNotEqual( pOther
->bFormulaCursor
, bVal
);
1287 void SmMathConfig::Notify( const com::sun::star::uno::Sequence
< rtl::OUString
>& )
1290 /////////////////////////////////////////////////////////////////