xref: /AOO41X/main/svx/source/dialog/fntctrl.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // include ---------------------------------------------------------------
32*cdf0e10cSrcweir #include <sfx2/viewsh.hxx>		// SfxViewShell
33*cdf0e10cSrcweir #include <sfx2/printer.hxx>		// Printer
34*cdf0e10cSrcweir #include <vcl/metric.hxx>
35*cdf0e10cSrcweir #include <vcl/svapp.hxx>
36*cdf0e10cSrcweir #include <unicode/uchar.h>
37*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
38*cdf0e10cSrcweir #include <com/sun/star/i18n/XBreakIterator.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_I18N_SCRIPTTYPE_HDL_
43*cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hdl>
44*cdf0e10cSrcweir #endif
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #ifndef _SVSTDARR_HXX
47*cdf0e10cSrcweir #define _SVSTDARR_USHORTS
48*cdf0e10cSrcweir #define _SVSTDARR_ULONGS
49*cdf0e10cSrcweir #define _SVSTDARR_XUB_STRLEN
50*cdf0e10cSrcweir #include <svl/svstdarr.hxx>
51*cdf0e10cSrcweir #endif
52*cdf0e10cSrcweir #include <svtools/colorcfg.hxx>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #include <svx/fntctrl.hxx>
55*cdf0e10cSrcweir #include <svx/dialogs.hrc>
56*cdf0e10cSrcweir #define TEXT_WIDTH	20
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
59*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
60*cdf0e10cSrcweir using ::com::sun::star::i18n::XBreakIterator;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir // -----------------------------------------------------------------------
63*cdf0e10cSrcweir // small helper functions to set fonts
64*cdf0e10cSrcweir // -----------------------------------------------------------------------
65*cdf0e10cSrcweir namespace
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir 	void scaleFontWidth(Font& _rFont,const OutputDevice& rOutDev,long& _n100PercentFont)
68*cdf0e10cSrcweir 	{
69*cdf0e10cSrcweir 		_rFont.SetWidth( 0 );
70*cdf0e10cSrcweir 		_n100PercentFont = rOutDev.GetFontMetric( _rFont ).GetWidth();
71*cdf0e10cSrcweir 	}
72*cdf0e10cSrcweir 	// -----------------------------------------------------------------------
73*cdf0e10cSrcweir 	void initFont(Font& _rFont)
74*cdf0e10cSrcweir 	{
75*cdf0e10cSrcweir 		_rFont.SetTransparent(sal_True);
76*cdf0e10cSrcweir 		_rFont.SetAlign(ALIGN_BASELINE);
77*cdf0e10cSrcweir 	}
78*cdf0e10cSrcweir 	// -----------------------------------------------------------------------
79*cdf0e10cSrcweir 	void setFontSize(Font& _rFont)
80*cdf0e10cSrcweir 	{
81*cdf0e10cSrcweir 		Size aSize( _rFont.GetSize() );
82*cdf0e10cSrcweir         aSize.Height() = ( aSize.Height() * 3 ) / 5;
83*cdf0e10cSrcweir         aSize.Width() = ( aSize.Width() * 3 ) / 5;
84*cdf0e10cSrcweir         _rFont.SetSize( aSize );
85*cdf0e10cSrcweir 	}
86*cdf0e10cSrcweir 	// -----------------------------------------------------------------------
87*cdf0e10cSrcweir 	void calcFontHeightAnyAscent(OutputDevice* _pWin,Font& _rFont,long& _nHeight,long& _nAscent)
88*cdf0e10cSrcweir 	{
89*cdf0e10cSrcweir         if ( !_nHeight )
90*cdf0e10cSrcweir         {
91*cdf0e10cSrcweir             _pWin->SetFont( _rFont );
92*cdf0e10cSrcweir             FontMetric aMetric( _pWin->GetFontMetric() );
93*cdf0e10cSrcweir             _nHeight = aMetric.GetLineHeight();
94*cdf0e10cSrcweir             _nAscent = aMetric.GetAscent();
95*cdf0e10cSrcweir         }
96*cdf0e10cSrcweir 	}
97*cdf0e10cSrcweir 	// -----------------------------------------------------------------------
98*cdf0e10cSrcweir 	void setFont( const SvxFont& rNewFont, SvxFont& rImplFont )
99*cdf0e10cSrcweir 	{
100*cdf0e10cSrcweir 		rImplFont = rNewFont;
101*cdf0e10cSrcweir 		rImplFont.SetTransparent( sal_True );
102*cdf0e10cSrcweir 		rImplFont.SetAlign( ALIGN_BASELINE );
103*cdf0e10cSrcweir 	}
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir }
106*cdf0e10cSrcweir // -----------------------------------------------------------------------
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir // class FontPrevWin_Impl -----------------------------------------------
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir class FontPrevWin_Impl
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir 	friend class SvxFontPrevWindow;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	SvxFont         				aFont;
116*cdf0e10cSrcweir 	Printer*        				pPrinter;
117*cdf0e10cSrcweir 	sal_Bool            				bDelPrinter;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	Reference < XBreakIterator >	xBreak;
120*cdf0e10cSrcweir 	SvULongs						aTextWidth;
121*cdf0e10cSrcweir 	SvXub_StrLens					aScriptChg;
122*cdf0e10cSrcweir 	SvUShorts						aScriptType;
123*cdf0e10cSrcweir 	SvxFont							aCJKFont;
124*cdf0e10cSrcweir 	SvxFont							aCTLFont;
125*cdf0e10cSrcweir 	String							aText;
126*cdf0e10cSrcweir 	String							aScriptText;
127*cdf0e10cSrcweir 	Color*							pColor;
128*cdf0e10cSrcweir 	Color*							pBackColor;
129*cdf0e10cSrcweir 	long							nAscent;
130*cdf0e10cSrcweir 	sal_Unicode						cStartBracket;
131*cdf0e10cSrcweir 	sal_Unicode						cEndBracket;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	long							n100PercentFontWidth;		// initial -1 -> not set yet
134*cdf0e10cSrcweir 	long							n100PercentFontWidthCJK;
135*cdf0e10cSrcweir 	long							n100PercentFontWidthCTL;
136*cdf0e10cSrcweir 	sal_uInt16							nFontWidthScale;
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	sal_Bool							bSelection		: 1,
139*cdf0e10cSrcweir 									bGetSelection   : 1,
140*cdf0e10cSrcweir 									bUseResText     : 1,
141*cdf0e10cSrcweir 									bTwoLines       : 1,
142*cdf0e10cSrcweir 									bIsCJKUI        : 1,
143*cdf0e10cSrcweir                                     bIsCTLUI        : 1,
144*cdf0e10cSrcweir                                     bUseFontNameAsText : 1,
145*cdf0e10cSrcweir                                     bTextInited     : 1;
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 	void				_CheckScript();
148*cdf0e10cSrcweir public:
149*cdf0e10cSrcweir 	inline FontPrevWin_Impl() :
150*cdf0e10cSrcweir 		pPrinter( NULL ), bDelPrinter( sal_False ),
151*cdf0e10cSrcweir         pColor( NULL ), pBackColor( 0 ),
152*cdf0e10cSrcweir         cStartBracket( 0 ), cEndBracket( 0 ), nFontWidthScale( 100 ),
153*cdf0e10cSrcweir         bSelection( sal_False ), bGetSelection( sal_False ), bUseResText( sal_False ),
154*cdf0e10cSrcweir         bTwoLines( sal_False ),
155*cdf0e10cSrcweir         bIsCJKUI( sal_False ), bIsCTLUI( sal_False ),
156*cdf0e10cSrcweir         bUseFontNameAsText( sal_False ), bTextInited( sal_False )
157*cdf0e10cSrcweir 		{
158*cdf0e10cSrcweir 			Invalidate100PercentFontWidth();
159*cdf0e10cSrcweir 		}
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	inline ~FontPrevWin_Impl()
162*cdf0e10cSrcweir 	{
163*cdf0e10cSrcweir         delete pColor;
164*cdf0e10cSrcweir         delete pBackColor;
165*cdf0e10cSrcweir         if( bDelPrinter )
166*cdf0e10cSrcweir 			delete pPrinter;
167*cdf0e10cSrcweir 	}
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	void				CheckScript();
170*cdf0e10cSrcweir     Size				CalcTextSize( OutputDevice* pWin, OutputDevice* pPrt, SvxFont &rFont );
171*cdf0e10cSrcweir     void				DrawPrev( OutputDevice* pWin, Printer* pPrt, Point &rPt, SvxFont &rFont );
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	sal_Bool				SetFontWidthScale( sal_uInt16 nScaleInPercent );
174*cdf0e10cSrcweir 	inline void			Invalidate100PercentFontWidth();
175*cdf0e10cSrcweir 	inline sal_Bool			Is100PercentFontWidthValid() const;
176*cdf0e10cSrcweir 	void				ScaleFontWidth( const OutputDevice& rOutDev );
177*cdf0e10cSrcweir 							// scales rNonCJKFont and aCJKFont depending on nFontWidthScale and
178*cdf0e10cSrcweir 							//  sets the 100%-Font-Widths
179*cdf0e10cSrcweir };
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir void FontPrevWin_Impl::CheckScript()
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir 	if( aText != aScriptText )
184*cdf0e10cSrcweir 		_CheckScript();
185*cdf0e10cSrcweir }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir inline void FontPrevWin_Impl::Invalidate100PercentFontWidth()
188*cdf0e10cSrcweir {
189*cdf0e10cSrcweir 	n100PercentFontWidth = n100PercentFontWidthCJK = n100PercentFontWidthCTL = -1;
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir inline sal_Bool FontPrevWin_Impl::Is100PercentFontWidthValid() const
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir 	DBG_ASSERT(	( n100PercentFontWidth == -1 && n100PercentFontWidthCJK == -1 ) ||
195*cdf0e10cSrcweir 				( n100PercentFontWidth != -1 && n100PercentFontWidthCJK != -1 ) ||
196*cdf0e10cSrcweir 				( n100PercentFontWidth == -1 && n100PercentFontWidthCTL == -1 ) ||
197*cdf0e10cSrcweir 				( n100PercentFontWidth != -1 && n100PercentFontWidthCTL != -1 ),
198*cdf0e10cSrcweir 				"*FontPrevWin_Impl::Is100PercentFontWidthValid(): 100PercentFontWidth's not synchronous" );
199*cdf0e10cSrcweir 	return n100PercentFontWidth != -1;
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir // class FontPrevWin_Impl -----------------------------------------------
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir /*-----------------19.7.2001 08:44------------------
205*cdf0e10cSrcweir  * void FontPrevWin_Impl::_CheckScript()
206*cdf0e10cSrcweir  * evalutates the scripttypes of the actual string.
207*cdf0e10cSrcweir  * Afterwards the positions of script change are notified in aScriptChg,
208*cdf0e10cSrcweir  * the scripttypes in aScriptType.
209*cdf0e10cSrcweir  * The aTextWidth array will be filled with zero.
210*cdf0e10cSrcweir  * --------------------------------------------------*/
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir void FontPrevWin_Impl::_CheckScript()
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir     aScriptText = aText;
215*cdf0e10cSrcweir     size_t nCnt = aScriptChg.size();
216*cdf0e10cSrcweir     if( nCnt )
217*cdf0e10cSrcweir     {
218*cdf0e10cSrcweir         aScriptChg.clear();
219*cdf0e10cSrcweir         aScriptType.Remove( 0, nCnt );
220*cdf0e10cSrcweir         aTextWidth.Remove( 0, nCnt );
221*cdf0e10cSrcweir         nCnt = 0;
222*cdf0e10cSrcweir     }
223*cdf0e10cSrcweir     if( !xBreak.is() )
224*cdf0e10cSrcweir     {
225*cdf0e10cSrcweir         Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
226*cdf0e10cSrcweir         xBreak = Reference< XBreakIterator >(xMSF->createInstance(
227*cdf0e10cSrcweir 				::rtl::OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) ),UNO_QUERY);
228*cdf0e10cSrcweir     }
229*cdf0e10cSrcweir     if( xBreak.is() )
230*cdf0e10cSrcweir     {
231*cdf0e10cSrcweir         sal_uInt16 nScript = xBreak->getScriptType( aText, 0 );
232*cdf0e10cSrcweir         sal_uInt16 nChg = 0;
233*cdf0e10cSrcweir         if( com::sun::star::i18n::ScriptType::WEAK == nScript )
234*cdf0e10cSrcweir         {
235*cdf0e10cSrcweir             nChg = (xub_StrLen)xBreak->endOfScript( aText, nChg, nScript );
236*cdf0e10cSrcweir             if( nChg < aText.Len() )
237*cdf0e10cSrcweir                 nScript = xBreak->getScriptType( aText, nChg );
238*cdf0e10cSrcweir             else
239*cdf0e10cSrcweir                 nScript = com::sun::star::i18n::ScriptType::LATIN;
240*cdf0e10cSrcweir         }
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir         do
243*cdf0e10cSrcweir         {
244*cdf0e10cSrcweir             nChg = (xub_StrLen)xBreak->endOfScript( aText, nChg, nScript );
245*cdf0e10cSrcweir             if (nChg < aText.Len() && nChg > 0 &&
246*cdf0e10cSrcweir                 (com::sun::star::i18n::ScriptType::WEAK ==
247*cdf0e10cSrcweir                  xBreak->getScriptType(aText, nChg - 1)))
248*cdf0e10cSrcweir             {
249*cdf0e10cSrcweir                 int8_t nType = u_charType(aText.GetChar(nChg) );
250*cdf0e10cSrcweir                 if (nType == U_NON_SPACING_MARK || nType == U_ENCLOSING_MARK ||
251*cdf0e10cSrcweir                     nType == U_COMBINING_SPACING_MARK )
252*cdf0e10cSrcweir                 {
253*cdf0e10cSrcweir                     aScriptChg.push_back( nChg - 1 );
254*cdf0e10cSrcweir                 }
255*cdf0e10cSrcweir                 else
256*cdf0e10cSrcweir                 {
257*cdf0e10cSrcweir                     aScriptChg.push_back( nChg );
258*cdf0e10cSrcweir                 }
259*cdf0e10cSrcweir             }
260*cdf0e10cSrcweir             else
261*cdf0e10cSrcweir             {
262*cdf0e10cSrcweir                 aScriptChg.push_back( nChg );
263*cdf0e10cSrcweir             }
264*cdf0e10cSrcweir             aScriptType.Insert( nScript, nCnt );
265*cdf0e10cSrcweir             aTextWidth.Insert( sal_uIntPtr(0), nCnt++ );
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir             if( nChg < aText.Len() )
268*cdf0e10cSrcweir                 nScript = xBreak->getScriptType( aText, nChg );
269*cdf0e10cSrcweir             else
270*cdf0e10cSrcweir                 break;
271*cdf0e10cSrcweir         } while( sal_True );
272*cdf0e10cSrcweir     }
273*cdf0e10cSrcweir }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir /*-----------------19.7.2001 08:48------------------
276*cdf0e10cSrcweir  * Size FontPrevWin_Impl::CalcTextSize(..)
277*cdf0e10cSrcweir  * fills the aTextWidth array with the text width of every part
278*cdf0e10cSrcweir  * of the actual string without a script change inside.
279*cdf0e10cSrcweir  * For Latin parts the given rFont will be used,
280*cdf0e10cSrcweir  * for Asian parts the aCJKFont.
281*cdf0e10cSrcweir  * The returned size contains the whole string.
282*cdf0e10cSrcweir  * The member nAscent is calculated to the maximal ascent of all used fonts.
283*cdf0e10cSrcweir  * --------------------------------------------------*/
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir Size FontPrevWin_Impl::CalcTextSize( OutputDevice* pWin, OutputDevice* _pPrinter,
286*cdf0e10cSrcweir     SvxFont &rFont )
287*cdf0e10cSrcweir {
288*cdf0e10cSrcweir     sal_uInt16 nScript;
289*cdf0e10cSrcweir     sal_uInt16 nIdx = 0;
290*cdf0e10cSrcweir     xub_StrLen nStart = 0;
291*cdf0e10cSrcweir     xub_StrLen nEnd;
292*cdf0e10cSrcweir     size_t nCnt = aScriptChg.size();
293*cdf0e10cSrcweir     if( nCnt )
294*cdf0e10cSrcweir     {
295*cdf0e10cSrcweir         nEnd = aScriptChg[ nIdx ];
296*cdf0e10cSrcweir         nScript = aScriptType[ nIdx ];
297*cdf0e10cSrcweir     }
298*cdf0e10cSrcweir     else
299*cdf0e10cSrcweir     {
300*cdf0e10cSrcweir         nEnd = aText.Len();
301*cdf0e10cSrcweir         nScript = com::sun::star::i18n::ScriptType::LATIN;
302*cdf0e10cSrcweir     }
303*cdf0e10cSrcweir     long nTxtWidth = 0;
304*cdf0e10cSrcweir     long nCJKHeight = 0;
305*cdf0e10cSrcweir 	long nCTLHeight = 0;
306*cdf0e10cSrcweir     long nHeight = 0;
307*cdf0e10cSrcweir     nAscent = 0;
308*cdf0e10cSrcweir     long nCJKAscent = 0;
309*cdf0e10cSrcweir 	long nCTLAscent = 0;
310*cdf0e10cSrcweir     do
311*cdf0e10cSrcweir     {
312*cdf0e10cSrcweir         SvxFont& rFnt = (nScript==com::sun::star::i18n::ScriptType::ASIAN) ? aCJKFont : ((nScript==com::sun::star::i18n::ScriptType::COMPLEX) ? aCTLFont : rFont);
313*cdf0e10cSrcweir         sal_uIntPtr nWidth = rFnt.GetTxtSize( _pPrinter, aText, nStart, nEnd-nStart ).
314*cdf0e10cSrcweir                        Width();
315*cdf0e10cSrcweir         aTextWidth[ nIdx++ ] = nWidth;
316*cdf0e10cSrcweir         nTxtWidth += nWidth;
317*cdf0e10cSrcweir 		switch(nScript)
318*cdf0e10cSrcweir 		{
319*cdf0e10cSrcweir 			case com::sun::star::i18n::ScriptType::ASIAN:
320*cdf0e10cSrcweir 				calcFontHeightAnyAscent(pWin,aCJKFont,nCJKHeight,nCJKAscent);
321*cdf0e10cSrcweir 				break;
322*cdf0e10cSrcweir 			case com::sun::star::i18n::ScriptType::COMPLEX:
323*cdf0e10cSrcweir 				calcFontHeightAnyAscent(pWin,aCTLFont,nCTLHeight,nCTLAscent);
324*cdf0e10cSrcweir 				break;
325*cdf0e10cSrcweir 			default:
326*cdf0e10cSrcweir 				calcFontHeightAnyAscent(pWin,rFont,nHeight,nAscent);
327*cdf0e10cSrcweir 		}
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir         if( nEnd < aText.Len() && nIdx < nCnt )
330*cdf0e10cSrcweir         {
331*cdf0e10cSrcweir             nStart = nEnd;
332*cdf0e10cSrcweir             nEnd = aScriptChg[ nIdx ];
333*cdf0e10cSrcweir             nScript = aScriptType[ nIdx ];
334*cdf0e10cSrcweir         }
335*cdf0e10cSrcweir         else
336*cdf0e10cSrcweir             break;
337*cdf0e10cSrcweir     }
338*cdf0e10cSrcweir     while( sal_True );
339*cdf0e10cSrcweir     nHeight -= nAscent;
340*cdf0e10cSrcweir     nCJKHeight -= nCJKAscent;
341*cdf0e10cSrcweir 	nCTLHeight -= nCTLAscent;
342*cdf0e10cSrcweir     if( nHeight < nCJKHeight )
343*cdf0e10cSrcweir         nHeight = nCJKHeight;
344*cdf0e10cSrcweir     if( nAscent < nCJKAscent )
345*cdf0e10cSrcweir         nAscent = nCJKAscent;
346*cdf0e10cSrcweir 	if( nHeight < nCTLHeight )
347*cdf0e10cSrcweir         nHeight = nCTLHeight;
348*cdf0e10cSrcweir     if( nAscent < nCTLAscent )
349*cdf0e10cSrcweir         nAscent = nCTLAscent;
350*cdf0e10cSrcweir     nHeight += nAscent;
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir     Size aTxtSize( nTxtWidth, nHeight );
353*cdf0e10cSrcweir     return aTxtSize;
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir /*-----------------19.7.2001 08:54------------------
357*cdf0e10cSrcweir  * void FontPrevWin_Impl::DrawPrev(..)
358*cdf0e10cSrcweir  * calls SvxFont::DrawPrev(..) for every part of the string without a script
359*cdf0e10cSrcweir  * change inside, for Asian parts the aCJKFont will be used, otherwise the
360*cdf0e10cSrcweir  * given rFont.
361*cdf0e10cSrcweir  * --------------------------------------------------*/
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir void FontPrevWin_Impl::DrawPrev( OutputDevice* pWin, Printer* _pPrinter,
364*cdf0e10cSrcweir     Point &rPt, SvxFont &rFont )
365*cdf0e10cSrcweir {
366*cdf0e10cSrcweir     Font aOldFont = _pPrinter->GetFont();
367*cdf0e10cSrcweir     sal_uInt16 nScript;
368*cdf0e10cSrcweir     sal_uInt16 nIdx = 0;
369*cdf0e10cSrcweir     xub_StrLen nStart = 0;
370*cdf0e10cSrcweir     xub_StrLen nEnd;
371*cdf0e10cSrcweir     size_t nCnt = aScriptChg.size();
372*cdf0e10cSrcweir     if( nCnt )
373*cdf0e10cSrcweir     {
374*cdf0e10cSrcweir         nEnd = aScriptChg[ nIdx ];
375*cdf0e10cSrcweir         nScript = aScriptType[ nIdx ];
376*cdf0e10cSrcweir     }
377*cdf0e10cSrcweir     else
378*cdf0e10cSrcweir     {
379*cdf0e10cSrcweir         nEnd = aText.Len();
380*cdf0e10cSrcweir         nScript = com::sun::star::i18n::ScriptType::LATIN;
381*cdf0e10cSrcweir     }
382*cdf0e10cSrcweir     do
383*cdf0e10cSrcweir     {
384*cdf0e10cSrcweir         SvxFont& rFnt = (nScript==com::sun::star::i18n::ScriptType::ASIAN) ? aCJKFont : ((nScript==com::sun::star::i18n::ScriptType::COMPLEX) ? aCTLFont : rFont);
385*cdf0e10cSrcweir         _pPrinter->SetFont( rFnt );
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir         rFnt.DrawPrev( pWin, _pPrinter, rPt, aText, nStart, nEnd - nStart );
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir         rPt.X() += aTextWidth[ nIdx++ ];
390*cdf0e10cSrcweir         if( nEnd < aText.Len() && nIdx < nCnt )
391*cdf0e10cSrcweir         {
392*cdf0e10cSrcweir             nStart = nEnd;
393*cdf0e10cSrcweir             nEnd = aScriptChg[ nIdx ];
394*cdf0e10cSrcweir             nScript = aScriptType[ nIdx ];
395*cdf0e10cSrcweir         }
396*cdf0e10cSrcweir         else
397*cdf0e10cSrcweir             break;
398*cdf0e10cSrcweir     }
399*cdf0e10cSrcweir     while( sal_True );
400*cdf0e10cSrcweir     _pPrinter->SetFont( aOldFont );
401*cdf0e10cSrcweir }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir // -----------------------------------------------------------------------
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir sal_Bool FontPrevWin_Impl::SetFontWidthScale( sal_uInt16 nScale )
406*cdf0e10cSrcweir {
407*cdf0e10cSrcweir 	if( nFontWidthScale != nScale )
408*cdf0e10cSrcweir 	{
409*cdf0e10cSrcweir 		nFontWidthScale = nScale;
410*cdf0e10cSrcweir 		return sal_True;
411*cdf0e10cSrcweir 	}
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 	return sal_False;
414*cdf0e10cSrcweir }
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir // -----------------------------------------------------------------------
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir void FontPrevWin_Impl::ScaleFontWidth( const OutputDevice& rOutDev )
420*cdf0e10cSrcweir {
421*cdf0e10cSrcweir 	if( !Is100PercentFontWidthValid() )
422*cdf0e10cSrcweir 	{
423*cdf0e10cSrcweir 		scaleFontWidth(aFont,rOutDev,n100PercentFontWidth);
424*cdf0e10cSrcweir 		scaleFontWidth(aCJKFont,rOutDev,n100PercentFontWidthCJK);
425*cdf0e10cSrcweir 		scaleFontWidth(aCTLFont,rOutDev,n100PercentFontWidthCTL);
426*cdf0e10cSrcweir 	}
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir 	aFont.SetWidth( n100PercentFontWidth * nFontWidthScale / 100 );
429*cdf0e10cSrcweir 	aCJKFont.SetWidth( n100PercentFontWidthCJK * nFontWidthScale / 100 );
430*cdf0e10cSrcweir 	aCTLFont.SetWidth( n100PercentFontWidthCTL * nFontWidthScale / 100 );
431*cdf0e10cSrcweir }
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir // class SvxFontPrevWindow -----------------------------------------------
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir void SvxFontPrevWindow::InitSettings( sal_Bool bForeground, sal_Bool bBackground )
436*cdf0e10cSrcweir {
437*cdf0e10cSrcweir 	const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 	if ( bForeground )
440*cdf0e10cSrcweir 	{
441*cdf0e10cSrcweir 		svtools::ColorConfig aColorConfig;
442*cdf0e10cSrcweir 		Color aTextColor( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir 		if ( IsControlForeground() )
445*cdf0e10cSrcweir 			aTextColor = GetControlForeground();
446*cdf0e10cSrcweir 		SetTextColor( aTextColor );
447*cdf0e10cSrcweir 	}
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir 	if ( bBackground )
450*cdf0e10cSrcweir 	{
451*cdf0e10cSrcweir 		if ( IsControlBackground() )
452*cdf0e10cSrcweir 			SetBackground( GetControlBackground() );
453*cdf0e10cSrcweir 		else
454*cdf0e10cSrcweir 			SetBackground( rStyleSettings.GetWindowColor() );
455*cdf0e10cSrcweir 	}
456*cdf0e10cSrcweir 	Invalidate();
457*cdf0e10cSrcweir }
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir // -----------------------------------------------------------------------
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir SvxFontPrevWindow::SvxFontPrevWindow( Window* pParent, const ResId& rId ) :
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 	Window     ( pParent, rId )
464*cdf0e10cSrcweir {
465*cdf0e10cSrcweir 	pImpl = new FontPrevWin_Impl;
466*cdf0e10cSrcweir 	SfxViewShell* pSh = SfxViewShell::Current();
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir 	if ( pSh )
469*cdf0e10cSrcweir 		pImpl->pPrinter = pSh->GetPrinter();
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 	if ( !pImpl->pPrinter )
472*cdf0e10cSrcweir 	{
473*cdf0e10cSrcweir 		pImpl->pPrinter = new Printer;
474*cdf0e10cSrcweir 		pImpl->bDelPrinter = sal_True;
475*cdf0e10cSrcweir 	}
476*cdf0e10cSrcweir 	SetMapMode( MapMode( MAP_TWIP ) );
477*cdf0e10cSrcweir 	initFont(pImpl->aFont);
478*cdf0e10cSrcweir 	initFont(pImpl->aCJKFont);
479*cdf0e10cSrcweir 	initFont(pImpl->aCTLFont);
480*cdf0e10cSrcweir 	InitSettings( sal_True, sal_True );
481*cdf0e10cSrcweir     SetBorderStyle( WINDOW_BORDER_MONO );
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir     LanguageType eLanguage = Application::GetSettings().GetUILanguage();
484*cdf0e10cSrcweir     switch( eLanguage )
485*cdf0e10cSrcweir     {
486*cdf0e10cSrcweir         case LANGUAGE_CHINESE:
487*cdf0e10cSrcweir         case LANGUAGE_JAPANESE:
488*cdf0e10cSrcweir         case LANGUAGE_KOREAN:
489*cdf0e10cSrcweir         case LANGUAGE_KOREAN_JOHAB:
490*cdf0e10cSrcweir         case LANGUAGE_CHINESE_SIMPLIFIED:
491*cdf0e10cSrcweir         case LANGUAGE_CHINESE_HONGKONG:
492*cdf0e10cSrcweir         case LANGUAGE_CHINESE_SINGAPORE:
493*cdf0e10cSrcweir         case LANGUAGE_CHINESE_MACAU:
494*cdf0e10cSrcweir         case LANGUAGE_CHINESE_TRADITIONAL:
495*cdf0e10cSrcweir             pImpl->bIsCJKUI = sal_True;
496*cdf0e10cSrcweir             break;
497*cdf0e10cSrcweir         // TODO: CTL Locale
498*cdf0e10cSrcweir         //  pImpl->bIsCTLUI = sal_True;
499*cdf0e10cSrcweir         //  break;
500*cdf0e10cSrcweir         default:
501*cdf0e10cSrcweir             pImpl->bIsCJKUI = pImpl->bIsCTLUI = sal_False;
502*cdf0e10cSrcweir             break;
503*cdf0e10cSrcweir     }
504*cdf0e10cSrcweir }
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir // -----------------------------------------------------------------------
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir SvxFontPrevWindow::~SvxFontPrevWindow()
509*cdf0e10cSrcweir {
510*cdf0e10cSrcweir     delete pImpl;
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir // -----------------------------------------------------------------------
514*cdf0e10cSrcweir SvxFont& SvxFontPrevWindow::GetCTLFont()
515*cdf0e10cSrcweir {
516*cdf0e10cSrcweir     return pImpl->aCTLFont;
517*cdf0e10cSrcweir }
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir // -----------------------------------------------------------------------
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir SvxFont& SvxFontPrevWindow::GetCJKFont()
522*cdf0e10cSrcweir {
523*cdf0e10cSrcweir     return pImpl->aCJKFont;
524*cdf0e10cSrcweir }
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir // -----------------------------------------------------------------------
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir void SvxFontPrevWindow::StateChanged( StateChangedType nType )
529*cdf0e10cSrcweir {
530*cdf0e10cSrcweir 	if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
531*cdf0e10cSrcweir 		InitSettings( sal_True, sal_False );
532*cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
533*cdf0e10cSrcweir 		InitSettings( sal_False, sal_True );
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 	Window::StateChanged( nType );
536*cdf0e10cSrcweir }
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir // -----------------------------------------------------------------------
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir void SvxFontPrevWindow::DataChanged( const DataChangedEvent& rDCEvt )
541*cdf0e10cSrcweir {
542*cdf0e10cSrcweir 	if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
543*cdf0e10cSrcweir 		InitSettings( sal_True, sal_True );
544*cdf0e10cSrcweir 	else
545*cdf0e10cSrcweir 		Window::DataChanged( rDCEvt );
546*cdf0e10cSrcweir }
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir SvxFont& SvxFontPrevWindow::GetFont()
549*cdf0e10cSrcweir {
550*cdf0e10cSrcweir 	pImpl->Invalidate100PercentFontWidth();		// because the user might change the size
551*cdf0e10cSrcweir 	return pImpl->aFont;
552*cdf0e10cSrcweir }
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir const SvxFont& SvxFontPrevWindow::GetFont() const
555*cdf0e10cSrcweir {
556*cdf0e10cSrcweir 	return pImpl->aFont;
557*cdf0e10cSrcweir }
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir // -----------------------------------------------------------------------
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir void SvxFontPrevWindow::SetPreviewText( const ::rtl::OUString& rString )
562*cdf0e10cSrcweir {
563*cdf0e10cSrcweir     pImpl->aText = rString;
564*cdf0e10cSrcweir     pImpl->bTextInited = sal_True;
565*cdf0e10cSrcweir }
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir // -----------------------------------------------------------------------
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir void SvxFontPrevWindow::SetFontNameAsPreviewText()
570*cdf0e10cSrcweir {
571*cdf0e10cSrcweir     pImpl->bUseFontNameAsText = sal_True;
572*cdf0e10cSrcweir }
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir // -----------------------------------------------------------------------
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir void SvxFontPrevWindow::SetFont( const SvxFont& rOutFont )
577*cdf0e10cSrcweir {
578*cdf0e10cSrcweir 	setFont( rOutFont, pImpl->aFont );
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 	pImpl->Invalidate100PercentFontWidth();
581*cdf0e10cSrcweir 	Invalidate();
582*cdf0e10cSrcweir }
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir // -----------------------------------------------------------------------
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir void SvxFontPrevWindow::SetFont( const SvxFont& rNormalOutFont, const SvxFont& rCJKOutFont, const SvxFont& rCTLFont )
587*cdf0e10cSrcweir {
588*cdf0e10cSrcweir 	setFont( rNormalOutFont, pImpl->aFont );
589*cdf0e10cSrcweir 	setFont( rCJKOutFont, pImpl->aCJKFont );
590*cdf0e10cSrcweir 	setFont( rCTLFont, pImpl->aCTLFont );
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir 	pImpl->Invalidate100PercentFontWidth();
594*cdf0e10cSrcweir 	Invalidate();
595*cdf0e10cSrcweir }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir // -----------------------------------------------------------------------
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir void SvxFontPrevWindow::SetCJKFont( const SvxFont &rCJKOutFont )
600*cdf0e10cSrcweir {
601*cdf0e10cSrcweir 	setFont( rCJKOutFont, pImpl->aCJKFont );
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir 	pImpl->Invalidate100PercentFontWidth();
604*cdf0e10cSrcweir 	Invalidate();
605*cdf0e10cSrcweir }
606*cdf0e10cSrcweir // -----------------------------------------------------------------------------
607*cdf0e10cSrcweir void SvxFontPrevWindow::SetCTLFont( const SvxFont &rCTLOutFont )
608*cdf0e10cSrcweir {
609*cdf0e10cSrcweir 	setFont( rCTLOutFont, pImpl->aCTLFont );
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 	pImpl->Invalidate100PercentFontWidth();
612*cdf0e10cSrcweir 	Invalidate();
613*cdf0e10cSrcweir }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir // -----------------------------------------------------------------------
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir void SvxFontPrevWindow::SetColor(const Color &rColor)
618*cdf0e10cSrcweir {
619*cdf0e10cSrcweir 	delete pImpl->pColor;
620*cdf0e10cSrcweir 	pImpl->pColor = new Color( rColor );
621*cdf0e10cSrcweir 	Invalidate();
622*cdf0e10cSrcweir }
623*cdf0e10cSrcweir // -----------------------------------------------------------------------
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir void SvxFontPrevWindow::ResetColor()
626*cdf0e10cSrcweir {
627*cdf0e10cSrcweir     delete pImpl->pColor;
628*cdf0e10cSrcweir     pImpl->pColor = 0;
629*cdf0e10cSrcweir     Invalidate();
630*cdf0e10cSrcweir }
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir // -----------------------------------------------------------------------
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir void SvxFontPrevWindow::SetBackColor(const Color &rColor)
635*cdf0e10cSrcweir {
636*cdf0e10cSrcweir     delete pImpl->pBackColor;
637*cdf0e10cSrcweir     pImpl->pBackColor = new Color( rColor );
638*cdf0e10cSrcweir 	Invalidate();
639*cdf0e10cSrcweir }
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir // -----------------------------------------------------------------------
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir void SvxFontPrevWindow::UseResourceText( sal_Bool bUse )
644*cdf0e10cSrcweir {
645*cdf0e10cSrcweir 	pImpl->bUseResText = bUse;
646*cdf0e10cSrcweir }
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir // -----------------------------------------------------------------------
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir void SvxFontPrevWindow::Paint( const Rectangle& )
651*cdf0e10cSrcweir {
652*cdf0e10cSrcweir 	Printer* pPrinter = pImpl->pPrinter;
653*cdf0e10cSrcweir 	SvxFont& rFont = pImpl->aFont;
654*cdf0e10cSrcweir 	SvxFont& rCJKFont = pImpl->aCJKFont;
655*cdf0e10cSrcweir 	// TODO: SvxFont& rCTLFont = pImpl->aCTLFont;
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir     if ( pImpl->bUseResText )
658*cdf0e10cSrcweir 		pImpl->aText = GetText();
659*cdf0e10cSrcweir 	else if ( !pImpl->bSelection && !pImpl->bTextInited )
660*cdf0e10cSrcweir 	{
661*cdf0e10cSrcweir 		SfxViewShell* pSh = SfxViewShell::Current();
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir 		if ( pSh && !pImpl->bGetSelection && !pImpl->bUseFontNameAsText )
664*cdf0e10cSrcweir 		{
665*cdf0e10cSrcweir 			pImpl->aText = pSh->GetSelectionText();
666*cdf0e10cSrcweir 			pImpl->bGetSelection = sal_True;
667*cdf0e10cSrcweir 			pImpl->bSelection = pImpl->aText.Len() != 0;
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir 		}
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir 		if ( !pImpl->bSelection || pImpl->bUseFontNameAsText )
672*cdf0e10cSrcweir         {
673*cdf0e10cSrcweir 			pImpl->aText = rFont.GetName();
674*cdf0e10cSrcweir             if( pImpl->bIsCJKUI )
675*cdf0e10cSrcweir                 pImpl->aText += rCJKFont.GetName();
676*cdf0e10cSrcweir             //TODO bIsCTLUI
677*cdf0e10cSrcweir         }
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir 		if ( !pImpl->aText.Len() )
680*cdf0e10cSrcweir 			pImpl->aText = GetText();
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir         // remove line feeds and carriage returns from string
683*cdf0e10cSrcweir         bool bNotEmpty = false;
684*cdf0e10cSrcweir         for ( xub_StrLen i = 0; i < pImpl->aText.Len(); ++i )
685*cdf0e10cSrcweir         {
686*cdf0e10cSrcweir             if ( 0xa == pImpl->aText.GetChar( i ) ||
687*cdf0e10cSrcweir                  0xd == pImpl->aText.GetChar( i ) )
688*cdf0e10cSrcweir                  pImpl->aText.SetChar( i, ' ' );
689*cdf0e10cSrcweir             else
690*cdf0e10cSrcweir                 bNotEmpty = true;
691*cdf0e10cSrcweir         }
692*cdf0e10cSrcweir         if ( !bNotEmpty )
693*cdf0e10cSrcweir 			pImpl->aText = GetText();
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir 		if ( pImpl->aText.Len() > (TEXT_WIDTH-1) )
696*cdf0e10cSrcweir 			pImpl->aText.Erase( pImpl->aText.Search( sal_Unicode( ' ' ), TEXT_WIDTH ) );
697*cdf0e10cSrcweir 	}
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir 	// calculate text width scaling
700*cdf0e10cSrcweir 	pImpl->ScaleFontWidth( *this/*, rFont*/ );
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir     pImpl->CheckScript();
703*cdf0e10cSrcweir     Size aTxtSize = pImpl->CalcTextSize( this, pPrinter, rFont );
704*cdf0e10cSrcweir 
705*cdf0e10cSrcweir 	const Size aLogSize( GetOutputSize() );
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 	long nX = aLogSize.Width()  / 2 - aTxtSize.Width() / 2;
708*cdf0e10cSrcweir 	long nY = aLogSize.Height() / 2 - aTxtSize.Height() / 2;
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir     if ( nY + pImpl->nAscent > aLogSize.Height() )
711*cdf0e10cSrcweir         nY = aLogSize.Height() - pImpl->nAscent;
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir     if ( pImpl->pBackColor )
714*cdf0e10cSrcweir 	{
715*cdf0e10cSrcweir         Rectangle aRect( Point( 0, 0 ), aLogSize );
716*cdf0e10cSrcweir 		Color aLineCol = GetLineColor();
717*cdf0e10cSrcweir 		Color aFillCol = GetFillColor();
718*cdf0e10cSrcweir 		SetLineColor();
719*cdf0e10cSrcweir         SetFillColor( *pImpl->pBackColor );
720*cdf0e10cSrcweir 		DrawRect( aRect );
721*cdf0e10cSrcweir 		SetLineColor( aLineCol );
722*cdf0e10cSrcweir 		SetFillColor( aFillCol );
723*cdf0e10cSrcweir 	}
724*cdf0e10cSrcweir     if ( pImpl->pColor )
725*cdf0e10cSrcweir 	{
726*cdf0e10cSrcweir 		Rectangle aRect( Point( nX, nY ), aTxtSize );
727*cdf0e10cSrcweir 		Color aLineCol = GetLineColor();
728*cdf0e10cSrcweir 		Color aFillCol = GetFillColor();
729*cdf0e10cSrcweir 		SetLineColor();
730*cdf0e10cSrcweir 		SetFillColor( *pImpl->pColor );
731*cdf0e10cSrcweir 		DrawRect( aRect );
732*cdf0e10cSrcweir 		SetLineColor( aLineCol );
733*cdf0e10cSrcweir 		SetFillColor( aFillCol );
734*cdf0e10cSrcweir 	}
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir     long nStdAscent = pImpl->nAscent;
737*cdf0e10cSrcweir 	nY += nStdAscent;
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir 	if(pImpl->bTwoLines)
740*cdf0e10cSrcweir 	{
741*cdf0e10cSrcweir 		SvxFont aSmallFont( rFont );
742*cdf0e10cSrcweir 		Size aOldSize = pImpl->aCJKFont.GetSize();
743*cdf0e10cSrcweir 		setFontSize(aSmallFont);
744*cdf0e10cSrcweir 		setFontSize(pImpl->aCJKFont);
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir 		long nStartBracketWidth = 0;
747*cdf0e10cSrcweir 		long nEndBracketWidth = 0;
748*cdf0e10cSrcweir 		long nTextWidth = 0;
749*cdf0e10cSrcweir 		if(pImpl->cStartBracket)
750*cdf0e10cSrcweir 		{
751*cdf0e10cSrcweir 			String sBracket(pImpl->cStartBracket);
752*cdf0e10cSrcweir 			nStartBracketWidth = rFont.GetTxtSize( pPrinter, sBracket ).Width();
753*cdf0e10cSrcweir 		}
754*cdf0e10cSrcweir 		if(pImpl->cEndBracket)
755*cdf0e10cSrcweir 		{
756*cdf0e10cSrcweir 			String sBracket(pImpl->cEndBracket);
757*cdf0e10cSrcweir 			nEndBracketWidth = rFont.GetTxtSize( pPrinter, sBracket ).Width();
758*cdf0e10cSrcweir 		}
759*cdf0e10cSrcweir         nTextWidth = pImpl->CalcTextSize( this, pPrinter, aSmallFont ).Width();
760*cdf0e10cSrcweir 		long nResultWidth = nStartBracketWidth;
761*cdf0e10cSrcweir 		nResultWidth += nEndBracketWidth;
762*cdf0e10cSrcweir 		nResultWidth += nTextWidth;
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir         long _nX = (aLogSize.Width() - nResultWidth) / 2;
765*cdf0e10cSrcweir         DrawLine( Point( 0,  nY ), Point( _nX, nY ) );
766*cdf0e10cSrcweir         DrawLine( Point( _nX + nResultWidth, nY ), Point( aLogSize.Width(), nY ) );
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir         long nSmallAscent = pImpl->nAscent;
769*cdf0e10cSrcweir 		long nOffset = (nStdAscent - nSmallAscent ) / 2;
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir 		if(pImpl->cStartBracket)
772*cdf0e10cSrcweir 		{
773*cdf0e10cSrcweir 			String sBracket(pImpl->cStartBracket);
774*cdf0e10cSrcweir             rFont.DrawPrev( this, pPrinter, Point( _nX, nY - nOffset - 4), sBracket );
775*cdf0e10cSrcweir             _nX += nStartBracketWidth;
776*cdf0e10cSrcweir 		}
777*cdf0e10cSrcweir 
778*cdf0e10cSrcweir         Point aTmpPoint1( _nX, nY - nSmallAscent - 2 );
779*cdf0e10cSrcweir         Point aTmpPoint2( _nX, nY );
780*cdf0e10cSrcweir         pImpl->DrawPrev( this, pPrinter, aTmpPoint1, aSmallFont );
781*cdf0e10cSrcweir         pImpl->DrawPrev( this, pPrinter, aTmpPoint2, aSmallFont );
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir         _nX += nTextWidth;
784*cdf0e10cSrcweir 		if(pImpl->cEndBracket)
785*cdf0e10cSrcweir 		{
786*cdf0e10cSrcweir             Point aTmpPoint( _nX + 1, nY - nOffset - 4);
787*cdf0e10cSrcweir 			String sBracket(pImpl->cEndBracket);
788*cdf0e10cSrcweir 			rFont.DrawPrev( this, pPrinter, aTmpPoint, sBracket );
789*cdf0e10cSrcweir 		}
790*cdf0e10cSrcweir         pImpl->aCJKFont.SetSize( aOldSize );
791*cdf0e10cSrcweir 	}
792*cdf0e10cSrcweir 	else
793*cdf0e10cSrcweir 	{
794*cdf0e10cSrcweir 		Color aLineCol = GetLineColor();
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir 		SetLineColor( rFont.GetColor() );
797*cdf0e10cSrcweir         DrawLine( Point( 0,  nY ), Point( nX, nY ) );
798*cdf0e10cSrcweir         DrawLine( Point( nX + aTxtSize.Width(), nY ), Point( aLogSize.Width(), nY ) );
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir 		SetLineColor( aLineCol );
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir         Point aTmpPoint( nX, nY );
803*cdf0e10cSrcweir         pImpl->DrawPrev( this, pPrinter, aTmpPoint, rFont );
804*cdf0e10cSrcweir 	}
805*cdf0e10cSrcweir }
806*cdf0e10cSrcweir /* -----------------------------04.12.00 16:26--------------------------------
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
809*cdf0e10cSrcweir sal_Bool SvxFontPrevWindow::IsTwoLines() const
810*cdf0e10cSrcweir {
811*cdf0e10cSrcweir 	return pImpl->bTwoLines;
812*cdf0e10cSrcweir }
813*cdf0e10cSrcweir /* -----------------------------04.12.00 16:26--------------------------------
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
816*cdf0e10cSrcweir void SvxFontPrevWindow::SetTwoLines(sal_Bool bSet)
817*cdf0e10cSrcweir {
818*cdf0e10cSrcweir 	pImpl->bTwoLines = bSet;}
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir /* -----------------------------04.12.00 16:26--------------------------------
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
823*cdf0e10cSrcweir void SvxFontPrevWindow::SetBrackets(sal_Unicode cStart, sal_Unicode cEnd)
824*cdf0e10cSrcweir {
825*cdf0e10cSrcweir 	pImpl->cStartBracket = cStart;
826*cdf0e10cSrcweir 	pImpl->cEndBracket = cEnd;
827*cdf0e10cSrcweir }
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir // -----------------------------------------------------------------------
830*cdf0e10cSrcweir 
831*cdf0e10cSrcweir void SvxFontPrevWindow::SetFontWidthScale( sal_uInt16 n )
832*cdf0e10cSrcweir {
833*cdf0e10cSrcweir 	if( pImpl->SetFontWidthScale( n ) )
834*cdf0e10cSrcweir 		Invalidate();
835*cdf0e10cSrcweir }
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir // -----------------------------------------------------------------------
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir void SvxFontPrevWindow::AutoCorrectFontColor( void )
840*cdf0e10cSrcweir {
841*cdf0e10cSrcweir 	Color	aFontColor( GetTextColor() );
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir 	if( COL_AUTO == pImpl->aFont.GetColor().GetColor() )
844*cdf0e10cSrcweir 		pImpl->aFont.SetColor( aFontColor );
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir 	if( COL_AUTO == pImpl->aCJKFont.GetColor().GetColor() )
847*cdf0e10cSrcweir 		pImpl->aCJKFont.SetColor( aFontColor );
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir 	if( COL_AUTO == pImpl->aCTLFont.GetColor().GetColor() )
850*cdf0e10cSrcweir 		pImpl->aCTLFont.SetColor( aFontColor );
851*cdf0e10cSrcweir }
852