update dev300-m58
[ooovba.git] / svx / source / dialog / fntctrl.cxx
blobd76dd9a4a267b199b34165b05ec0c45b2150ba33
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fntctrl.cxx,v $
10 * $Revision: 1.24 $
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_svx.hxx"
34 // include ---------------------------------------------------------------
35 #include <sfx2/viewsh.hxx> // SfxViewShell
36 #include <sfx2/printer.hxx> // SfxPrinter
37 #include <vcl/metric.hxx>
38 #include <vcl/svapp.hxx>
39 #include <unicode/uchar.h>
40 #include <com/sun/star/uno/Reference.h>
41 #include <com/sun/star/i18n/XBreakIterator.hpp>
42 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 #include <comphelper/processfactory.hxx>
45 #ifndef _COM_SUN_STAR_I18N_SCRIPTTYPE_HDL_
46 #include <com/sun/star/i18n/ScriptType.hdl>
47 #endif
49 #ifndef _SVSTDARR_HXX
50 #define _SVSTDARR_USHORTS
51 #define _SVSTDARR_ULONGS
52 #define _SVSTDARR_XUB_STRLEN
53 #include <svtools/svstdarr.hxx>
54 #endif
55 #include <svtools/colorcfg.hxx>
57 #include <svx/fntctrl.hxx>
58 #include <svx/dialogs.hrc>
59 #define TEXT_WIDTH 20
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::lang;
63 using ::com::sun::star::i18n::XBreakIterator;
65 // -----------------------------------------------------------------------
66 // small helper functions to set fonts
67 // -----------------------------------------------------------------------
68 namespace
70 void scaleFontWidth(Font& _rFont,const OutputDevice& rOutDev,long& _n100PercentFont)
72 _rFont.SetWidth( 0 );
73 _n100PercentFont = rOutDev.GetFontMetric( _rFont ).GetWidth();
75 // -----------------------------------------------------------------------
76 void initFont(Font& _rFont)
78 _rFont.SetTransparent(TRUE);
79 _rFont.SetAlign(ALIGN_BASELINE);
81 // -----------------------------------------------------------------------
82 void setFontSize(Font& _rFont)
84 Size aSize( _rFont.GetSize() );
85 aSize.Height() = ( aSize.Height() * 3 ) / 5;
86 aSize.Width() = ( aSize.Width() * 3 ) / 5;
87 _rFont.SetSize( aSize );
89 // -----------------------------------------------------------------------
90 void calcFontHeightAnyAscent(OutputDevice* _pWin,Font& _rFont,long& _nHeight,long& _nAscent)
92 if ( !_nHeight )
94 _pWin->SetFont( _rFont );
95 FontMetric aMetric( _pWin->GetFontMetric() );
96 _nHeight = aMetric.GetLineHeight();
97 _nAscent = aMetric.GetAscent();
100 // -----------------------------------------------------------------------
101 void setFont( const SvxFont& rNewFont, SvxFont& rImplFont )
103 rImplFont = rNewFont;
104 rImplFont.SetTransparent( TRUE );
105 rImplFont.SetAlign( ALIGN_BASELINE );
109 // -----------------------------------------------------------------------
112 // class FontPrevWin_Impl -----------------------------------------------
114 class FontPrevWin_Impl
116 friend class SvxFontPrevWindow;
118 SvxFont aFont;
119 Printer* pPrinter;
120 BOOL bDelPrinter;
122 Reference < XBreakIterator > xBreak;
123 SvULongs aTextWidth;
124 SvXub_StrLens aScriptChg;
125 SvUShorts aScriptType;
126 SvxFont aCJKFont;
127 SvxFont aCTLFont;
128 String aText;
129 String aScriptText;
130 Color* pColor;
131 Color* pBackColor;
132 long nAscent;
133 sal_Unicode cStartBracket;
134 sal_Unicode cEndBracket;
136 long n100PercentFontWidth; // initial -1 -> not set yet
137 long n100PercentFontWidthCJK;
138 long n100PercentFontWidthCTL;
139 UINT16 nFontWidthScale;
141 BOOL bSelection : 1,
142 bGetSelection : 1,
143 bUseResText : 1,
144 bTwoLines : 1,
145 bIsCJKUI : 1,
146 bIsCTLUI : 1,
147 bUseFontNameAsText : 1,
148 bTextInited : 1;
150 void _CheckScript();
151 public:
152 inline FontPrevWin_Impl() :
153 pPrinter( NULL ), bDelPrinter( FALSE ),
154 pColor( NULL ), pBackColor( 0 ),
155 cStartBracket( 0 ), cEndBracket( 0 ), nFontWidthScale( 100 ),
156 bSelection( FALSE ), bGetSelection( FALSE ), bUseResText( FALSE ),
157 bTwoLines( FALSE ),
158 bIsCJKUI( FALSE ), bIsCTLUI( FALSE ),
159 bUseFontNameAsText( FALSE ), bTextInited( FALSE )
161 Invalidate100PercentFontWidth();
164 inline ~FontPrevWin_Impl()
166 delete pColor;
167 delete pBackColor;
168 if( bDelPrinter )
169 delete pPrinter;
172 void CheckScript();
173 Size CalcTextSize( OutputDevice* pWin, OutputDevice* pPrt, SvxFont &rFont );
174 void DrawPrev( OutputDevice* pWin, Printer* pPrt, Point &rPt, SvxFont &rFont );
176 BOOL SetFontWidthScale( UINT16 nScaleInPercent );
177 inline void Invalidate100PercentFontWidth();
178 inline BOOL Is100PercentFontWidthValid() const;
179 void ScaleFontWidth( const OutputDevice& rOutDev );
180 // scales rNonCJKFont and aCJKFont depending on nFontWidthScale and
181 // sets the 100%-Font-Widths
184 void FontPrevWin_Impl::CheckScript()
186 if( aText != aScriptText )
187 _CheckScript();
190 inline void FontPrevWin_Impl::Invalidate100PercentFontWidth()
192 n100PercentFontWidth = n100PercentFontWidthCJK = n100PercentFontWidthCTL = -1;
195 inline BOOL FontPrevWin_Impl::Is100PercentFontWidthValid() const
197 DBG_ASSERT( ( n100PercentFontWidth == -1 && n100PercentFontWidthCJK == -1 ) ||
198 ( n100PercentFontWidth != -1 && n100PercentFontWidthCJK != -1 ) ||
199 ( n100PercentFontWidth == -1 && n100PercentFontWidthCTL == -1 ) ||
200 ( n100PercentFontWidth != -1 && n100PercentFontWidthCTL != -1 ),
201 "*FontPrevWin_Impl::Is100PercentFontWidthValid(): 100PercentFontWidth's not synchronous" );
202 return n100PercentFontWidth != -1;
205 // class FontPrevWin_Impl -----------------------------------------------
207 /*-----------------19.7.2001 08:44------------------
208 * void FontPrevWin_Impl::_CheckScript()
209 * evalutates the scripttypes of the actual string.
210 * Afterwards the positions of script change are notified in aScriptChg,
211 * the scripttypes in aScriptType.
212 * The aTextWidth array will be filled with zero.
213 * --------------------------------------------------*/
215 void FontPrevWin_Impl::_CheckScript()
217 aScriptText = aText;
218 USHORT nCnt = aScriptChg.Count();
219 if( nCnt )
221 aScriptChg.Remove( 0, nCnt );
222 aScriptType.Remove( 0, nCnt );
223 aTextWidth.Remove( 0, nCnt );
224 nCnt = 0;
226 if( !xBreak.is() )
228 Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
229 xBreak = Reference< XBreakIterator >(xMSF->createInstance(
230 ::rtl::OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) ),UNO_QUERY);
232 if( xBreak.is() )
234 USHORT nScript = xBreak->getScriptType( aText, 0 );
235 USHORT nChg = 0;
236 if( com::sun::star::i18n::ScriptType::WEAK == nScript )
238 nChg = (xub_StrLen)xBreak->endOfScript( aText, nChg, nScript );
239 if( nChg < aText.Len() )
240 nScript = xBreak->getScriptType( aText, nChg );
241 else
242 nScript = com::sun::star::i18n::ScriptType::LATIN;
247 nChg = (xub_StrLen)xBreak->endOfScript( aText, nChg, nScript );
248 if (nChg < aText.Len() && nChg > 0 &&
249 (com::sun::star::i18n::ScriptType::WEAK ==
250 xBreak->getScriptType(aText, nChg - 1)))
252 int8_t nType = u_charType(aText.GetChar(nChg) );
253 if (nType == U_NON_SPACING_MARK || nType == U_ENCLOSING_MARK ||
254 nType == U_COMBINING_SPACING_MARK )
256 aScriptChg.Insert( nChg - 1, nCnt );
258 else
260 aScriptChg.Insert( nChg, nCnt );
263 else
265 aScriptChg.Insert( nChg, nCnt );
267 aScriptType.Insert( nScript, nCnt );
268 aTextWidth.Insert( ULONG(0), nCnt++ );
270 if( nChg < aText.Len() )
271 nScript = xBreak->getScriptType( aText, nChg );
272 else
273 break;
274 } while( TRUE );
278 /*-----------------19.7.2001 08:48------------------
279 * Size FontPrevWin_Impl::CalcTextSize(..)
280 * fills the aTextWidth array with the text width of every part
281 * of the actual string without a script change inside.
282 * For Latin parts the given rFont will be used,
283 * for Asian parts the aCJKFont.
284 * The returned size contains the whole string.
285 * The member nAscent is calculated to the maximal ascent of all used fonts.
286 * --------------------------------------------------*/
288 Size FontPrevWin_Impl::CalcTextSize( OutputDevice* pWin, OutputDevice* _pPrinter,
289 SvxFont &rFont )
291 USHORT nScript;
292 USHORT nIdx = 0;
293 xub_StrLen nStart = 0;
294 xub_StrLen nEnd;
295 USHORT nCnt = aScriptChg.Count();
296 if( nCnt )
298 nEnd = aScriptChg[ nIdx ];
299 nScript = aScriptType[ nIdx ];
301 else
303 nEnd = aText.Len();
304 nScript = com::sun::star::i18n::ScriptType::LATIN;
306 long nTxtWidth = 0;
307 long nCJKHeight = 0;
308 long nCTLHeight = 0;
309 long nHeight = 0;
310 nAscent = 0;
311 long nCJKAscent = 0;
312 long nCTLAscent = 0;
315 SvxFont& rFnt = (nScript==com::sun::star::i18n::ScriptType::ASIAN) ? aCJKFont : ((nScript==com::sun::star::i18n::ScriptType::COMPLEX) ? aCTLFont : rFont);
316 ULONG nWidth = rFnt.GetTxtSize( _pPrinter, aText, nStart, nEnd-nStart ).
317 Width();
318 aTextWidth[ nIdx++ ] = nWidth;
319 nTxtWidth += nWidth;
320 switch(nScript)
322 case com::sun::star::i18n::ScriptType::ASIAN:
323 calcFontHeightAnyAscent(pWin,aCJKFont,nCJKHeight,nCJKAscent);
324 break;
325 case com::sun::star::i18n::ScriptType::COMPLEX:
326 calcFontHeightAnyAscent(pWin,aCTLFont,nCTLHeight,nCTLAscent);
327 break;
328 default:
329 calcFontHeightAnyAscent(pWin,rFont,nHeight,nAscent);
332 if( nEnd < aText.Len() && nIdx < nCnt )
334 nStart = nEnd;
335 nEnd = aScriptChg[ nIdx ];
336 nScript = aScriptType[ nIdx ];
338 else
339 break;
341 while( TRUE );
342 nHeight -= nAscent;
343 nCJKHeight -= nCJKAscent;
344 nCTLHeight -= nCTLAscent;
345 if( nHeight < nCJKHeight )
346 nHeight = nCJKHeight;
347 if( nAscent < nCJKAscent )
348 nAscent = nCJKAscent;
349 if( nHeight < nCTLHeight )
350 nHeight = nCTLHeight;
351 if( nAscent < nCTLAscent )
352 nAscent = nCTLAscent;
353 nHeight += nAscent;
355 Size aTxtSize( nTxtWidth, nHeight );
356 return aTxtSize;
359 /*-----------------19.7.2001 08:54------------------
360 * void FontPrevWin_Impl::DrawPrev(..)
361 * calls SvxFont::DrawPrev(..) for every part of the string without a script
362 * change inside, for Asian parts the aCJKFont will be used, otherwise the
363 * given rFont.
364 * --------------------------------------------------*/
366 void FontPrevWin_Impl::DrawPrev( OutputDevice* pWin, Printer* _pPrinter,
367 Point &rPt, SvxFont &rFont )
369 Font aOldFont = _pPrinter->GetFont();
370 USHORT nScript;
371 USHORT nIdx = 0;
372 xub_StrLen nStart = 0;
373 xub_StrLen nEnd;
374 USHORT nCnt = aScriptChg.Count();
375 if( nCnt )
377 nEnd = aScriptChg[ nIdx ];
378 nScript = aScriptType[ nIdx ];
380 else
382 nEnd = aText.Len();
383 nScript = com::sun::star::i18n::ScriptType::LATIN;
387 SvxFont& rFnt = (nScript==com::sun::star::i18n::ScriptType::ASIAN) ? aCJKFont : ((nScript==com::sun::star::i18n::ScriptType::COMPLEX) ? aCTLFont : rFont);
388 _pPrinter->SetFont( rFnt );
390 rFnt.DrawPrev( pWin, _pPrinter, rPt, aText, nStart, nEnd - nStart );
392 rPt.X() += aTextWidth[ nIdx++ ];
393 if( nEnd < aText.Len() && nIdx < nCnt )
395 nStart = nEnd;
396 nEnd = aScriptChg[ nIdx ];
397 nScript = aScriptType[ nIdx ];
399 else
400 break;
402 while( TRUE );
403 _pPrinter->SetFont( aOldFont );
406 // -----------------------------------------------------------------------
408 BOOL FontPrevWin_Impl::SetFontWidthScale( UINT16 nScale )
410 if( nFontWidthScale != nScale )
412 nFontWidthScale = nScale;
413 return TRUE;
416 return FALSE;
420 // -----------------------------------------------------------------------
422 void FontPrevWin_Impl::ScaleFontWidth( const OutputDevice& rOutDev )
424 if( !Is100PercentFontWidthValid() )
426 scaleFontWidth(aFont,rOutDev,n100PercentFontWidth);
427 scaleFontWidth(aCJKFont,rOutDev,n100PercentFontWidthCJK);
428 scaleFontWidth(aCTLFont,rOutDev,n100PercentFontWidthCTL);
431 aFont.SetWidth( n100PercentFontWidth * nFontWidthScale / 100 );
432 aCJKFont.SetWidth( n100PercentFontWidthCJK * nFontWidthScale / 100 );
433 aCTLFont.SetWidth( n100PercentFontWidthCTL * nFontWidthScale / 100 );
436 // class SvxFontPrevWindow -----------------------------------------------
438 void SvxFontPrevWindow::InitSettings( BOOL bForeground, BOOL bBackground )
440 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
442 if ( bForeground )
444 svtools::ColorConfig aColorConfig;
445 Color aTextColor( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
447 if ( IsControlForeground() )
448 aTextColor = GetControlForeground();
449 SetTextColor( aTextColor );
452 if ( bBackground )
454 if ( IsControlBackground() )
455 SetBackground( GetControlBackground() );
456 else
457 SetBackground( rStyleSettings.GetWindowColor() );
459 Invalidate();
462 // -----------------------------------------------------------------------
464 SvxFontPrevWindow::SvxFontPrevWindow( Window* pParent, const ResId& rId ) :
466 Window ( pParent, rId )
468 pImpl = new FontPrevWin_Impl;
469 SfxViewShell* pSh = SfxViewShell::Current();
471 if ( pSh )
472 pImpl->pPrinter = pSh->GetPrinter();
474 if ( !pImpl->pPrinter )
476 pImpl->pPrinter = new Printer;
477 pImpl->bDelPrinter = TRUE;
479 SetMapMode( MapMode( MAP_TWIP ) );
480 initFont(pImpl->aFont);
481 initFont(pImpl->aCJKFont);
482 initFont(pImpl->aCTLFont);
483 InitSettings( TRUE, TRUE );
484 SetBorderStyle( WINDOW_BORDER_MONO );
486 LanguageType eLanguage = Application::GetSettings().GetUILanguage();
487 switch( eLanguage )
489 case LANGUAGE_CHINESE:
490 case LANGUAGE_JAPANESE:
491 case LANGUAGE_KOREAN:
492 case LANGUAGE_KOREAN_JOHAB:
493 case LANGUAGE_CHINESE_SIMPLIFIED:
494 case LANGUAGE_CHINESE_HONGKONG:
495 case LANGUAGE_CHINESE_SINGAPORE:
496 case LANGUAGE_CHINESE_MACAU:
497 case LANGUAGE_CHINESE_TRADITIONAL:
498 pImpl->bIsCJKUI = sal_True;
499 break;
500 // TODO: CTL Locale
501 // pImpl->bIsCTLUI = sal_True;
502 // break;
503 default:
504 pImpl->bIsCJKUI = pImpl->bIsCTLUI = sal_False;
505 break;
509 // -----------------------------------------------------------------------
511 SvxFontPrevWindow::~SvxFontPrevWindow()
513 delete pImpl;
516 // -----------------------------------------------------------------------
517 SvxFont& SvxFontPrevWindow::GetCTLFont()
519 return pImpl->aCTLFont;
522 // -----------------------------------------------------------------------
524 SvxFont& SvxFontPrevWindow::GetCJKFont()
526 return pImpl->aCJKFont;
529 // -----------------------------------------------------------------------
531 void SvxFontPrevWindow::StateChanged( StateChangedType nType )
533 if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
534 InitSettings( TRUE, FALSE );
535 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
536 InitSettings( FALSE, TRUE );
538 Window::StateChanged( nType );
541 // -----------------------------------------------------------------------
543 void SvxFontPrevWindow::DataChanged( const DataChangedEvent& rDCEvt )
545 if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
546 InitSettings( TRUE, TRUE );
547 else
548 Window::DataChanged( rDCEvt );
551 SvxFont& SvxFontPrevWindow::GetFont()
553 pImpl->Invalidate100PercentFontWidth(); // because the user might change the size
554 return pImpl->aFont;
557 const SvxFont& SvxFontPrevWindow::GetFont() const
559 return pImpl->aFont;
562 // -----------------------------------------------------------------------
564 void SvxFontPrevWindow::SetPreviewText( const ::rtl::OUString& rString )
566 pImpl->aText = rString;
567 pImpl->bTextInited = TRUE;
570 // -----------------------------------------------------------------------
572 void SvxFontPrevWindow::SetFontNameAsPreviewText()
574 pImpl->bUseFontNameAsText = TRUE;
577 // -----------------------------------------------------------------------
579 void SvxFontPrevWindow::SetFont( const SvxFont& rOutFont )
581 setFont( rOutFont, pImpl->aFont );
583 pImpl->Invalidate100PercentFontWidth();
584 Invalidate();
587 // -----------------------------------------------------------------------
589 void SvxFontPrevWindow::SetFont( const SvxFont& rNormalOutFont, const SvxFont& rCJKOutFont, const SvxFont& rCTLFont )
591 setFont( rNormalOutFont, pImpl->aFont );
592 setFont( rCJKOutFont, pImpl->aCJKFont );
593 setFont( rCTLFont, pImpl->aCTLFont );
596 pImpl->Invalidate100PercentFontWidth();
597 Invalidate();
600 // -----------------------------------------------------------------------
602 void SvxFontPrevWindow::SetCJKFont( const SvxFont &rCJKOutFont )
604 setFont( rCJKOutFont, pImpl->aCJKFont );
606 pImpl->Invalidate100PercentFontWidth();
607 Invalidate();
609 // -----------------------------------------------------------------------------
610 void SvxFontPrevWindow::SetCTLFont( const SvxFont &rCTLOutFont )
612 setFont( rCTLOutFont, pImpl->aCTLFont );
614 pImpl->Invalidate100PercentFontWidth();
615 Invalidate();
618 // -----------------------------------------------------------------------
620 void SvxFontPrevWindow::SetColor(const Color &rColor)
622 delete pImpl->pColor;
623 pImpl->pColor = new Color( rColor );
624 Invalidate();
626 // -----------------------------------------------------------------------
628 void SvxFontPrevWindow::ResetColor()
630 delete pImpl->pColor;
631 pImpl->pColor = 0;
632 Invalidate();
635 // -----------------------------------------------------------------------
637 void SvxFontPrevWindow::SetBackColor(const Color &rColor)
639 delete pImpl->pBackColor;
640 pImpl->pBackColor = new Color( rColor );
641 Invalidate();
644 // -----------------------------------------------------------------------
646 void SvxFontPrevWindow::UseResourceText( BOOL bUse )
648 pImpl->bUseResText = bUse;
651 // -----------------------------------------------------------------------
653 void SvxFontPrevWindow::Paint( const Rectangle& )
655 Printer* pPrinter = pImpl->pPrinter;
656 SvxFont& rFont = pImpl->aFont;
657 SvxFont& rCJKFont = pImpl->aCJKFont;
658 // TODO: SvxFont& rCTLFont = pImpl->aCTLFont;
660 if ( pImpl->bUseResText )
661 pImpl->aText = GetText();
662 else if ( !pImpl->bSelection && !pImpl->bTextInited )
664 SfxViewShell* pSh = SfxViewShell::Current();
666 if ( pSh && !pImpl->bGetSelection && !pImpl->bUseFontNameAsText )
668 pImpl->aText = pSh->GetSelectionText();
669 pImpl->bGetSelection = TRUE;
670 pImpl->bSelection = pImpl->aText.Len() != 0;
674 if ( !pImpl->bSelection || pImpl->bUseFontNameAsText )
676 pImpl->aText = rFont.GetName();
677 if( pImpl->bIsCJKUI )
678 pImpl->aText += rCJKFont.GetName();
679 //TODO bIsCTLUI
682 if ( !pImpl->aText.Len() )
683 pImpl->aText = GetText();
685 // remove line feeds and carriage returns from string
686 bool bNotEmpty = false;
687 for ( xub_StrLen i = 0; i < pImpl->aText.Len(); ++i )
689 if ( 0xa == pImpl->aText.GetChar( i ) ||
690 0xd == pImpl->aText.GetChar( i ) )
691 pImpl->aText.SetChar( i, ' ' );
692 else
693 bNotEmpty = true;
695 if ( !bNotEmpty )
696 pImpl->aText = GetText();
698 if ( pImpl->aText.Len() > (TEXT_WIDTH-1) )
699 pImpl->aText.Erase( pImpl->aText.Search( sal_Unicode( ' ' ), TEXT_WIDTH ) );
702 // calculate text width scaling
703 pImpl->ScaleFontWidth( *this/*, rFont*/ );
705 pImpl->CheckScript();
706 Size aTxtSize = pImpl->CalcTextSize( this, pPrinter, rFont );
708 const Size aLogSize( GetOutputSize() );
710 long nX = aLogSize.Width() / 2 - aTxtSize.Width() / 2;
711 long nY = aLogSize.Height() / 2 - aTxtSize.Height() / 2;
713 if ( nY + pImpl->nAscent > aLogSize.Height() )
714 nY = aLogSize.Height() - pImpl->nAscent;
716 if ( pImpl->pBackColor )
718 Rectangle aRect( Point( 0, 0 ), aLogSize );
719 Color aLineCol = GetLineColor();
720 Color aFillCol = GetFillColor();
721 SetLineColor();
722 SetFillColor( *pImpl->pBackColor );
723 DrawRect( aRect );
724 SetLineColor( aLineCol );
725 SetFillColor( aFillCol );
727 if ( pImpl->pColor )
729 Rectangle aRect( Point( nX, nY ), aTxtSize );
730 Color aLineCol = GetLineColor();
731 Color aFillCol = GetFillColor();
732 SetLineColor();
733 SetFillColor( *pImpl->pColor );
734 DrawRect( aRect );
735 SetLineColor( aLineCol );
736 SetFillColor( aFillCol );
739 long nStdAscent = pImpl->nAscent;
740 nY += nStdAscent;
742 if(pImpl->bTwoLines)
744 SvxFont aSmallFont( rFont );
745 Size aOldSize = pImpl->aCJKFont.GetSize();
746 setFontSize(aSmallFont);
747 setFontSize(pImpl->aCJKFont);
749 long nStartBracketWidth = 0;
750 long nEndBracketWidth = 0;
751 long nTextWidth = 0;
752 if(pImpl->cStartBracket)
754 String sBracket(pImpl->cStartBracket);
755 nStartBracketWidth = rFont.GetTxtSize( pPrinter, sBracket ).Width();
757 if(pImpl->cEndBracket)
759 String sBracket(pImpl->cEndBracket);
760 nEndBracketWidth = rFont.GetTxtSize( pPrinter, sBracket ).Width();
762 nTextWidth = pImpl->CalcTextSize( this, pPrinter, aSmallFont ).Width();
763 long nResultWidth = nStartBracketWidth;
764 nResultWidth += nEndBracketWidth;
765 nResultWidth += nTextWidth;
767 long _nX = (aLogSize.Width() - nResultWidth) / 2;
768 DrawLine( Point( 0, nY ), Point( _nX, nY ) );
769 DrawLine( Point( _nX + nResultWidth, nY ), Point( aLogSize.Width(), nY ) );
771 long nSmallAscent = pImpl->nAscent;
772 long nOffset = (nStdAscent - nSmallAscent ) / 2;
774 if(pImpl->cStartBracket)
776 String sBracket(pImpl->cStartBracket);
777 rFont.DrawPrev( this, pPrinter, Point( _nX, nY - nOffset - 4), sBracket );
778 _nX += nStartBracketWidth;
781 Point aTmpPoint1( _nX, nY - nSmallAscent - 2 );
782 Point aTmpPoint2( _nX, nY );
783 pImpl->DrawPrev( this, pPrinter, aTmpPoint1, aSmallFont );
784 pImpl->DrawPrev( this, pPrinter, aTmpPoint2, aSmallFont );
786 _nX += nTextWidth;
787 if(pImpl->cEndBracket)
789 Point aTmpPoint( _nX + 1, nY - nOffset - 4);
790 String sBracket(pImpl->cEndBracket);
791 rFont.DrawPrev( this, pPrinter, aTmpPoint, sBracket );
793 pImpl->aCJKFont.SetSize( aOldSize );
795 else
797 Color aLineCol = GetLineColor();
799 SetLineColor( rFont.GetColor() );
800 DrawLine( Point( 0, nY ), Point( nX, nY ) );
801 DrawLine( Point( nX + aTxtSize.Width(), nY ), Point( aLogSize.Width(), nY ) );
803 SetLineColor( aLineCol );
805 Point aTmpPoint( nX, nY );
806 pImpl->DrawPrev( this, pPrinter, aTmpPoint, rFont );
809 /* -----------------------------04.12.00 16:26--------------------------------
811 ---------------------------------------------------------------------------*/
812 BOOL SvxFontPrevWindow::IsTwoLines() const
814 return pImpl->bTwoLines;
816 /* -----------------------------04.12.00 16:26--------------------------------
818 ---------------------------------------------------------------------------*/
819 void SvxFontPrevWindow::SetTwoLines(BOOL bSet)
821 pImpl->bTwoLines = bSet;}
823 /* -----------------------------04.12.00 16:26--------------------------------
825 ---------------------------------------------------------------------------*/
826 void SvxFontPrevWindow::SetBrackets(sal_Unicode cStart, sal_Unicode cEnd)
828 pImpl->cStartBracket = cStart;
829 pImpl->cEndBracket = cEnd;
832 // -----------------------------------------------------------------------
834 void SvxFontPrevWindow::SetFontWidthScale( UINT16 n )
836 if( pImpl->SetFontWidthScale( n ) )
837 Invalidate();
840 // -----------------------------------------------------------------------
842 void SvxFontPrevWindow::AutoCorrectFontColor( void )
844 Color aFontColor( GetTextColor() );
846 if( COL_AUTO == pImpl->aFont.GetColor().GetColor() )
847 pImpl->aFont.SetColor( aFontColor );
849 if( COL_AUTO == pImpl->aCJKFont.GetColor().GetColor() )
850 pImpl->aCJKFont.SetColor( aFontColor );
852 if( COL_AUTO == pImpl->aCTLFont.GetColor().GetColor() )
853 pImpl->aCTLFont.SetColor( aFontColor );