1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fontcfg.cxx,v $
10 * $Revision: 1.24.224.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <fontcfg.hxx>
36 #include <i18npool/mslangid.hxx>
37 #include <vcl/outdev.hxx>
38 #include <svtools/lingucfg.hxx>
39 #include <com/sun/star/uno/Any.hxx>
40 #include <com/sun/star/uno/Sequence.hxx>
41 #include <com/sun/star/i18n/ScriptType.hpp>
42 #include <swtypes.hxx>
48 using namespace com::sun::star::uno
;
50 /* -----------------07.10.2002 12:15-----------------
52 * --------------------------------------------------*/
53 inline LanguageType
lcl_LanguageOfType(sal_Int16 nType
, sal_Int16 eWestern
, sal_Int16 eCJK
, sal_Int16 eCTL
)
56 nType
< FONT_STANDARD_CJK
? eWestern
:
57 nType
>= FONT_STANDARD_CTL
? eCTL
: eCJK
);
59 /* -----------------------------08.09.00 15:52--------------------------------
61 ---------------------------------------------------------------------------*/
62 Sequence
<OUString
> SwStdFontConfig::GetPropertyNames()
64 Sequence
<OUString
> aNames
;
65 if(!aNames
.getLength())
67 static const char* aPropNames
[] =
69 "DefaultFont/Standard", // 0
70 "DefaultFont/Heading", // 1
71 "DefaultFont/List", // 2
72 "DefaultFont/Caption", // 3
73 "DefaultFont/Index", // 4
74 "DefaultFontCJK/Standard", // 5
75 "DefaultFontCJK/Heading", // 6
76 "DefaultFontCJK/List", // 7
77 "DefaultFontCJK/Caption", // 8
78 "DefaultFontCJK/Index", // 9
79 "DefaultFontCTL/Standard", // 10
80 "DefaultFontCTL/Heading", // 11
81 "DefaultFontCTL/List", // 12
82 "DefaultFontCTL/Caption", // 13
83 "DefaultFontCTL/Index", // 14
84 "DefaultFont/StandardHeight", // 15
85 "DefaultFont/HeadingHeight", // 16
86 "DefaultFont/ListHeight", // 17
87 "DefaultFont/CaptionHeight", // 18
88 "DefaultFont/IndexHeight", // 19
89 "DefaultFontCJK/StandardHeight", // 20
90 "DefaultFontCJK/HeadingHeight", // 21
91 "DefaultFontCJK/ListHeight", // 22
92 "DefaultFontCJK/CaptionHeight", // 23
93 "DefaultFontCJK/IndexHeight", // 24
94 "DefaultFontCTL/StandardHeight", // 25
95 "DefaultFontCTL/HeadingHeight", // 26
96 "DefaultFontCTL/ListHeight", // 27
97 "DefaultFontCTL/CaptionHeight", // 28
98 "DefaultFontCTL/IndexHeight" // 29
100 const int nCount
= sizeof(aPropNames
)/sizeof(const char*);
101 aNames
.realloc(nCount
);
102 OUString
* pNames
= aNames
.getArray();
103 for(int i
= 0; i
< nCount
; i
++)
105 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
110 /*-----------------03.09.96 15.00-------------------
112 --------------------------------------------------*/
114 SwStdFontConfig::SwStdFontConfig() :
115 utl::ConfigItem(C2U("Office.Writer"))
117 SvtLinguOptions aLinguOpt
;
119 SvtLinguConfig().GetOptions( aLinguOpt
);
121 sal_Int16 eWestern
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage
, ::com::sun::star::i18n::ScriptType::LATIN
),
122 eCJK
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage_CJK
, ::com::sun::star::i18n::ScriptType::ASIAN
),
123 eCTL
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage_CTL
, ::com::sun::star::i18n::ScriptType::COMPLEX
);
125 for(sal_Int16 i
= 0; i
< DEF_FONT_COUNT
; i
++)
127 sDefaultFonts
[i
] = GetDefaultFor(i
,
128 lcl_LanguageOfType(i
, eWestern
, eCJK
, eCTL
));
129 nDefaultFontHeight
[i
] = -1;
132 Sequence
<OUString
> aNames
= GetPropertyNames();
133 Sequence
<Any
> aValues
= GetProperties(aNames
);
134 const Any
* pValues
= aValues
.getConstArray();
135 DBG_ASSERT(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
136 if(aValues
.getLength() == aNames
.getLength())
138 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
140 if(pValues
[nProp
].hasValue())
142 if( nProp
< DEF_FONT_COUNT
)
145 pValues
[nProp
] >>= sVal
;
146 sDefaultFonts
[nProp
] = sVal
;
150 pValues
[nProp
] >>= nDefaultFontHeight
[nProp
- DEF_FONT_COUNT
];
151 nDefaultFontHeight
[nProp
- DEF_FONT_COUNT
] = MM100_TO_TWIP(nDefaultFontHeight
[nProp
- DEF_FONT_COUNT
]);
157 /* -----------------------------08.09.00 15:58--------------------------------
159 ---------------------------------------------------------------------------*/
160 void SwStdFontConfig::Commit()
162 Sequence
<OUString
> aNames
= GetPropertyNames();
163 Sequence
<Any
> aValues(aNames
.getLength());
164 Any
* pValues
= aValues
.getArray();
165 SvtLinguOptions aLinguOpt
;
167 SvtLinguConfig().GetOptions( aLinguOpt
);
169 sal_Int16 eWestern
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage
, ::com::sun::star::i18n::ScriptType::LATIN
),
170 eCJK
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage_CJK
, ::com::sun::star::i18n::ScriptType::ASIAN
),
171 eCTL
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage_CTL
, ::com::sun::star::i18n::ScriptType::COMPLEX
);
173 for(sal_uInt16 nProp
= 0;
174 nProp
< sal::static_int_cast
< sal_uInt16
, sal_Int32
>( aNames
.getLength() );
177 if( nProp
< DEF_FONT_COUNT
)
179 if(GetDefaultFor(nProp
, lcl_LanguageOfType(nProp
, eWestern
, eCJK
, eCTL
)) != sDefaultFonts
[nProp
])
180 pValues
[nProp
] <<= OUString(sDefaultFonts
[nProp
]);
184 if(nDefaultFontHeight
[nProp
- DEF_FONT_COUNT
] > 0)
185 pValues
[nProp
] <<= static_cast<sal_Int32
>(TWIP_TO_MM100(nDefaultFontHeight
[nProp
- DEF_FONT_COUNT
]));
188 PutProperties(aNames
, aValues
);
190 /* -----------------------------08.09.00 15:56--------------------------------
192 ---------------------------------------------------------------------------*/
193 SwStdFontConfig::~SwStdFontConfig()
195 /*-----------------18.01.97 10.05-------------------
197 --------------------------------------------------*/
198 BOOL
SwStdFontConfig::IsFontDefault(USHORT nFontType
) const
200 BOOL bSame
= sal_False
;
201 SvtLinguOptions aLinguOpt
;
203 SvtLinguConfig().GetOptions( aLinguOpt
);
205 sal_Int16 eWestern
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage
, ::com::sun::star::i18n::ScriptType::LATIN
),
206 eCJK
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage_CJK
, ::com::sun::star::i18n::ScriptType::ASIAN
),
207 eCTL
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage_CTL
, ::com::sun::star::i18n::ScriptType::COMPLEX
);
209 String
sDefFont(GetDefaultFor(FONT_STANDARD
, eWestern
));
210 String
sDefFontCJK(GetDefaultFor(FONT_STANDARD_CJK
, eCJK
));
211 String
sDefFontCTL(GetDefaultFor(FONT_STANDARD_CTL
, eCTL
));
212 LanguageType eLang
= lcl_LanguageOfType(nFontType
, eWestern
, eCJK
, eCTL
);
216 bSame
= sDefaultFonts
[nFontType
] == sDefFont
;
218 case FONT_STANDARD_CJK
:
219 bSame
= sDefaultFonts
[nFontType
] == sDefFontCJK
;
221 case FONT_STANDARD_CTL
:
222 bSame
= sDefaultFonts
[nFontType
] == sDefFontCTL
;
225 case FONT_OUTLINE_CJK
:
226 case FONT_OUTLINE_CTL
:
227 bSame
= sDefaultFonts
[nFontType
] ==
228 GetDefaultFor(nFontType
, eLang
);
233 bSame
= sDefaultFonts
[nFontType
] == sDefFont
&&
234 sDefaultFonts
[FONT_STANDARD
] == sDefFont
;
237 case FONT_CAPTION_CJK
:
238 case FONT_INDEX_CJK
:
240 BOOL b1
= sDefaultFonts
[FONT_STANDARD_CJK
] == sDefFontCJK
;
241 bSame
= b1
&& sDefaultFonts
[nFontType
] == sDefFontCJK
;
245 case FONT_CAPTION_CTL
:
246 case FONT_INDEX_CTL
:
248 BOOL b1
= sDefaultFonts
[FONT_STANDARD_CJK
] == sDefFontCTL
;
249 bSame
= b1
&& sDefaultFonts
[nFontType
] == sDefFontCTL
;
256 /* -----------------11.01.99 13:16-------------------
258 * --------------------------------------------------*/
259 String
SwStdFontConfig::GetDefaultFor(USHORT nFontType
, LanguageType eLang
)
266 nFontId
= DEFAULTFONT_LATIN_HEADING
;
268 case FONT_OUTLINE_CJK
:
269 nFontId
= DEFAULTFONT_CJK_HEADING
;
271 case FONT_OUTLINE_CTL
:
272 nFontId
= DEFAULTFONT_CTL_HEADING
;
274 case FONT_STANDARD_CJK
:
276 case FONT_CAPTION_CJK
:
277 case FONT_INDEX_CJK
:
278 nFontId
= DEFAULTFONT_CJK_TEXT
;
280 case FONT_STANDARD_CTL
:
282 case FONT_CAPTION_CTL
:
283 case FONT_INDEX_CTL
:
284 nFontId
= DEFAULTFONT_CTL_TEXT
;
286 // case FONT_STANDARD:
288 // case FONT_CAPTION :
291 nFontId
= DEFAULTFONT_LATIN_TEXT
;
293 Font aFont
= OutputDevice::GetDefaultFont(nFontId
, eLang
, DEFAULTFONT_FLAGS_ONLYONE
);
294 return aFont
.GetName();
297 /*-- 11.10.2005 10:43:43---------------------------------------------------
299 -----------------------------------------------------------------------*/
300 sal_Int32
SwStdFontConfig::GetDefaultHeightFor(USHORT nFontType
, LanguageType eLang
)
302 sal_Int32 nRet
= FONTSIZE_DEFAULT
;
306 case FONT_OUTLINE_CJK
:
307 case FONT_OUTLINE_CTL
:
308 nRet
= FONTSIZE_OUTLINE
;
310 case FONT_STANDARD_CJK
:
311 nRet
= FONTSIZE_CJK_DEFAULT
;
314 if( eLang
== LANGUAGE_THAI
&& nFontType
>= FONT_STANDARD_CTL
)
321 /*-- 11.10.2005 10:50:06---------------------------------------------------
323 -----------------------------------------------------------------------*/
324 void SwStdFontConfig::ChangeInt( USHORT nFontType
, sal_Int32 nHeight
)
326 DBG_ASSERT( nFontType
< DEF_FONT_COUNT
, "invalid index in SwStdFontConfig::ChangInt()");
327 if( nFontType
< DEF_FONT_COUNT
&& nDefaultFontHeight
[nFontType
] != nHeight
)
329 SvtLinguOptions aLinguOpt
;
330 SvtLinguConfig().GetOptions( aLinguOpt
);
332 sal_Int16 eWestern
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage
, ::com::sun::star::i18n::ScriptType::LATIN
),
333 eCJK
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage_CJK
, ::com::sun::star::i18n::ScriptType::ASIAN
),
334 eCTL
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage_CTL
, ::com::sun::star::i18n::ScriptType::COMPLEX
);
336 // #i92090# default height value sets back to -1
337 const sal_Int32 nDefaultHeight
= GetDefaultHeightFor(nFontType
, lcl_LanguageOfType(nFontType
, eWestern
, eCJK
, eCTL
));
338 const bool bIsDefaultHeight
= nHeight
== nDefaultHeight
;
339 if( bIsDefaultHeight
&& nDefaultFontHeight
[nFontType
] > 0 )
342 nDefaultFontHeight
[nFontType
] = -1;
344 else if( !bIsDefaultHeight
&& nHeight
!= nDefaultFontHeight
[nFontType
] )
347 nDefaultFontHeight
[nFontType
] = nHeight
;
352 /*-- 08.11.2005 14:18:26---------------------------------------------------
354 -----------------------------------------------------------------------*/
355 sal_Int32
SwStdFontConfig::GetFontHeight( sal_uInt8 nFont
, sal_uInt8 nScriptType
, LanguageType eLang
)
357 DBG_ASSERT(nFont
+ FONT_PER_GROUP
* nScriptType
< DEF_FONT_COUNT
, "wrong index in SwStdFontConfig::GetFontHeight()");
358 sal_Int32 nRet
= nDefaultFontHeight
[nFont
+ FONT_PER_GROUP
* nScriptType
];
360 return GetDefaultHeightFor(nFont
+ FONT_PER_GROUP
* nScriptType
, eLang
);