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