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 <vcl/outdev.hxx>
37 #include <svtools/lingucfg.hxx>
38 #include <com/sun/star/uno/Any.hxx>
39 #include <com/sun/star/uno/Sequence.hxx>
40 #include <swtypes.hxx>
46 using namespace com::sun::star::uno
;
48 /* -----------------07.10.2002 12:15-----------------
50 * --------------------------------------------------*/
51 inline LanguageType
lcl_LanguageOfType(sal_Int16 nType
, sal_Int16 eWestern
, sal_Int16 eCJK
, sal_Int16 eCTL
)
54 nType
< FONT_STANDARD_CJK
? eWestern
:
55 nType
>= FONT_STANDARD_CTL
? eCTL
: eCJK
);
57 /* -----------------------------08.09.00 15:52--------------------------------
59 ---------------------------------------------------------------------------*/
60 Sequence
<OUString
> SwStdFontConfig::GetPropertyNames()
62 Sequence
<OUString
> aNames
;
63 if(!aNames
.getLength())
65 static const char* aPropNames
[] =
67 "DefaultFont/Standard", // 0
68 "DefaultFont/Heading", // 1
69 "DefaultFont/List", // 2
70 "DefaultFont/Caption", // 3
71 "DefaultFont/Index", // 4
72 "DefaultFontCJK/Standard", // 5
73 "DefaultFontCJK/Heading", // 6
74 "DefaultFontCJK/List", // 7
75 "DefaultFontCJK/Caption", // 8
76 "DefaultFontCJK/Index", // 9
77 "DefaultFontCTL/Standard", // 10
78 "DefaultFontCTL/Heading", // 11
79 "DefaultFontCTL/List", // 12
80 "DefaultFontCTL/Caption", // 13
81 "DefaultFontCTL/Index", // 14
82 "DefaultFont/StandardHeight", // 15
83 "DefaultFont/HeadingHeight", // 16
84 "DefaultFont/ListHeight", // 17
85 "DefaultFont/CaptionHeight", // 18
86 "DefaultFont/IndexHeight", // 19
87 "DefaultFontCJK/StandardHeight", // 20
88 "DefaultFontCJK/HeadingHeight", // 21
89 "DefaultFontCJK/ListHeight", // 22
90 "DefaultFontCJK/CaptionHeight", // 23
91 "DefaultFontCJK/IndexHeight", // 24
92 "DefaultFontCTL/StandardHeight", // 25
93 "DefaultFontCTL/HeadingHeight", // 26
94 "DefaultFontCTL/ListHeight", // 27
95 "DefaultFontCTL/CaptionHeight", // 28
96 "DefaultFontCTL/IndexHeight" // 29
98 const int nCount
= sizeof(aPropNames
)/sizeof(const char*);
99 aNames
.realloc(nCount
);
100 OUString
* pNames
= aNames
.getArray();
101 for(int i
= 0; i
< nCount
; i
++)
103 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
108 /*-----------------03.09.96 15.00-------------------
110 --------------------------------------------------*/
112 SwStdFontConfig::SwStdFontConfig() :
113 utl::ConfigItem(C2U("Office.Writer"))
115 SvtLinguOptions aLinguOpt
;
117 SvtLinguConfig().GetOptions( aLinguOpt
);
119 sal_Int16 eWestern
= aLinguOpt
.nDefaultLanguage
,
120 eCJK
= aLinguOpt
.nDefaultLanguage_CJK
,
121 eCTL
= aLinguOpt
.nDefaultLanguage_CTL
;
122 for(sal_Int16 i
= 0; i
< DEF_FONT_COUNT
; i
++)
124 sDefaultFonts
[i
] = GetDefaultFor(i
,
125 lcl_LanguageOfType(i
, eWestern
, eCJK
, eCTL
));
126 nDefaultFontHeight
[i
] = -1;
129 Sequence
<OUString
> aNames
= GetPropertyNames();
130 Sequence
<Any
> aValues
= GetProperties(aNames
);
131 const Any
* pValues
= aValues
.getConstArray();
132 DBG_ASSERT(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
133 if(aValues
.getLength() == aNames
.getLength())
135 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
137 if(pValues
[nProp
].hasValue())
139 if( nProp
< DEF_FONT_COUNT
)
142 pValues
[nProp
] >>= sVal
;
143 sDefaultFonts
[nProp
] = sVal
;
147 pValues
[nProp
] >>= nDefaultFontHeight
[nProp
- DEF_FONT_COUNT
];
148 nDefaultFontHeight
[nProp
- DEF_FONT_COUNT
] = MM100_TO_TWIP(nDefaultFontHeight
[nProp
- DEF_FONT_COUNT
]);
154 /* -----------------------------08.09.00 15:58--------------------------------
156 ---------------------------------------------------------------------------*/
157 void SwStdFontConfig::Commit()
159 Sequence
<OUString
> aNames
= GetPropertyNames();
160 Sequence
<Any
> aValues(aNames
.getLength());
161 Any
* pValues
= aValues
.getArray();
162 SvtLinguOptions aLinguOpt
;
164 SvtLinguConfig().GetOptions( aLinguOpt
);
166 sal_Int16 eWestern
= aLinguOpt
.nDefaultLanguage
,
167 eCJK
= aLinguOpt
.nDefaultLanguage_CJK
,
168 eCTL
= aLinguOpt
.nDefaultLanguage_CTL
;
169 for(sal_uInt16 nProp
= 0;
170 nProp
< sal::static_int_cast
< sal_uInt16
, sal_Int32
>( aNames
.getLength() );
173 if( nProp
< DEF_FONT_COUNT
)
175 if(GetDefaultFor(nProp
, lcl_LanguageOfType(nProp
, eWestern
, eCJK
, eCTL
)) != sDefaultFonts
[nProp
])
176 pValues
[nProp
] <<= OUString(sDefaultFonts
[nProp
]);
180 if(nDefaultFontHeight
[nProp
- DEF_FONT_COUNT
] > 0)
181 pValues
[nProp
] <<= static_cast<sal_Int32
>(TWIP_TO_MM100(nDefaultFontHeight
[nProp
- DEF_FONT_COUNT
]));
184 PutProperties(aNames
, aValues
);
186 /* -----------------------------08.09.00 15:56--------------------------------
188 ---------------------------------------------------------------------------*/
189 SwStdFontConfig::~SwStdFontConfig()
191 /*-----------------18.01.97 10.05-------------------
193 --------------------------------------------------*/
194 BOOL
SwStdFontConfig::IsFontDefault(USHORT nFontType
) const
196 BOOL bSame
= sal_False
;
197 SvtLinguOptions aLinguOpt
;
199 SvtLinguConfig().GetOptions( aLinguOpt
);
201 sal_Int16 eWestern
= aLinguOpt
.nDefaultLanguage
,
202 eCJK
= aLinguOpt
.nDefaultLanguage_CJK
,
203 eCTL
= aLinguOpt
.nDefaultLanguage_CTL
;
204 String
sDefFont(GetDefaultFor(FONT_STANDARD
, eWestern
));
205 String
sDefFontCJK(GetDefaultFor(FONT_STANDARD_CJK
, eCJK
));
206 String
sDefFontCTL(GetDefaultFor(FONT_STANDARD_CTL
, eCTL
));
207 LanguageType eLang
= lcl_LanguageOfType(nFontType
, eWestern
, eCJK
, eCTL
);
211 bSame
= sDefaultFonts
[nFontType
] == sDefFont
;
213 case FONT_STANDARD_CJK
:
214 bSame
= sDefaultFonts
[nFontType
] == sDefFontCJK
;
216 case FONT_STANDARD_CTL
:
217 bSame
= sDefaultFonts
[nFontType
] == sDefFontCTL
;
220 case FONT_OUTLINE_CJK
:
221 case FONT_OUTLINE_CTL
:
222 bSame
= sDefaultFonts
[nFontType
] ==
223 GetDefaultFor(nFontType
, eLang
);
228 bSame
= sDefaultFonts
[nFontType
] == sDefFont
&&
229 sDefaultFonts
[FONT_STANDARD
] == sDefFont
;
232 case FONT_CAPTION_CJK
:
233 case FONT_INDEX_CJK
:
235 BOOL b1
= sDefaultFonts
[FONT_STANDARD_CJK
] == sDefFontCJK
;
236 bSame
= b1
&& sDefaultFonts
[nFontType
] == sDefFontCJK
;
240 case FONT_CAPTION_CTL
:
241 case FONT_INDEX_CTL
:
243 BOOL b1
= sDefaultFonts
[FONT_STANDARD_CJK
] == sDefFontCTL
;
244 bSame
= b1
&& sDefaultFonts
[nFontType
] == sDefFontCTL
;
251 /* -----------------11.01.99 13:16-------------------
253 * --------------------------------------------------*/
254 String
SwStdFontConfig::GetDefaultFor(USHORT nFontType
, LanguageType eLang
)
261 nFontId
= DEFAULTFONT_LATIN_HEADING
;
263 case FONT_OUTLINE_CJK
:
264 nFontId
= DEFAULTFONT_CJK_HEADING
;
266 case FONT_OUTLINE_CTL
:
267 nFontId
= DEFAULTFONT_CTL_HEADING
;
269 case FONT_STANDARD_CJK
:
271 case FONT_CAPTION_CJK
:
272 case FONT_INDEX_CJK
:
273 nFontId
= DEFAULTFONT_CJK_TEXT
;
275 case FONT_STANDARD_CTL
:
277 case FONT_CAPTION_CTL
:
278 case FONT_INDEX_CTL
:
279 nFontId
= DEFAULTFONT_CTL_TEXT
;
281 // case FONT_STANDARD:
283 // case FONT_CAPTION :
286 nFontId
= DEFAULTFONT_LATIN_TEXT
;
288 Font aFont
= OutputDevice::GetDefaultFont(nFontId
, eLang
, DEFAULTFONT_FLAGS_ONLYONE
);
289 return aFont
.GetName();
292 /*-- 11.10.2005 10:43:43---------------------------------------------------
294 -----------------------------------------------------------------------*/
295 sal_Int32
SwStdFontConfig::GetDefaultHeightFor(USHORT nFontType
, LanguageType eLang
)
297 sal_Int32 nRet
= FONTSIZE_DEFAULT
;
301 case FONT_OUTLINE_CJK
:
302 case FONT_OUTLINE_CTL
:
303 nRet
= FONTSIZE_OUTLINE
;
305 case FONT_STANDARD_CJK
:
306 nRet
= FONTSIZE_CJK_DEFAULT
;
309 if( eLang
== LANGUAGE_THAI
&& nFontType
>= FONT_STANDARD_CTL
)
316 /*-- 11.10.2005 10:50:06---------------------------------------------------
318 -----------------------------------------------------------------------*/
319 void SwStdFontConfig::ChangeInt( USHORT nFontType
, sal_Int32 nHeight
)
321 DBG_ASSERT( nFontType
< DEF_FONT_COUNT
, "invalid index in SwStdFontConfig::ChangInt()");
322 if( nFontType
< DEF_FONT_COUNT
&& nDefaultFontHeight
[nFontType
] != nHeight
)
324 SvtLinguOptions aLinguOpt
;
325 SvtLinguConfig().GetOptions( aLinguOpt
);
326 sal_Int16 eWestern
= aLinguOpt
.nDefaultLanguage
,
327 eCJK
= aLinguOpt
.nDefaultLanguage_CJK
,
328 eCTL
= aLinguOpt
.nDefaultLanguage_CTL
;
329 // #i92090# default height value sets back to -1
330 const sal_Int32 nDefaultHeight
= GetDefaultHeightFor(nFontType
, lcl_LanguageOfType(nFontType
, eWestern
, eCJK
, eCTL
));
331 const bool bIsDefaultHeight
= nHeight
== nDefaultHeight
;
332 if( bIsDefaultHeight
&& nDefaultFontHeight
[nFontType
] > 0 )
335 nDefaultFontHeight
[nFontType
] = -1;
337 else if( !bIsDefaultHeight
&& nHeight
!= nDefaultFontHeight
[nFontType
] )
340 nDefaultFontHeight
[nFontType
] = nHeight
;
345 /*-- 08.11.2005 14:18:26---------------------------------------------------
347 -----------------------------------------------------------------------*/
348 sal_Int32
SwStdFontConfig::GetFontHeight( sal_uInt8 nFont
, sal_uInt8 nScriptType
, LanguageType eLang
)
350 DBG_ASSERT(nFont
+ FONT_PER_GROUP
* nScriptType
< DEF_FONT_COUNT
, "wrong index in SwStdFontConfig::GetFontHeight()");
351 sal_Int32 nRet
= nDefaultFontHeight
[nFont
+ FONT_PER_GROUP
* nScriptType
];
353 return GetDefaultHeightFor(nFont
+ FONT_PER_GROUP
* nScriptType
, eLang
);