Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / dialog / fntctrl.cxx
blob6e9ca6e176fe74575c9724509b9eec583ab71aab
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sfx2/dialoghelper.hxx>
21 #include <sfx2/viewsh.hxx>
22 #include <sfx2/printer.hxx>
23 #include <vcl/builder.hxx>
24 #include <vcl/metric.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/settings.hxx>
27 #include <unicode/uchar.h>
28 #include <com/sun/star/uno/Reference.h>
29 #include <com/sun/star/i18n/BreakIterator.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <comphelper/processfactory.hxx>
33 #include <com/sun/star/i18n/ScriptType.hpp>
35 #include <vector>
36 #include <deque>
37 #include <svtools/colorcfg.hxx>
38 #include <svtools/sampletext.hxx>
40 #include <svx/fntctrl.hxx>
41 #include <svx/dialogs.hrc>
42 #include <svx/sdasitm.hxx>
44 // Item set includes
45 #include <svl/itemset.hxx>
46 #include <svl/itempool.hxx>
47 #include <svl/stritem.hxx>
48 #include <svl/languageoptions.hxx>
50 #include <editeng/colritem.hxx>
51 #include <editeng/fontitem.hxx>
52 #include <editeng/editids.hrc>
53 #include <editeng/postitem.hxx>
54 #include <editeng/udlnitem.hxx>
55 #include <editeng/crossedoutitem.hxx>
56 #include <editeng/contouritem.hxx>
57 #include <editeng/wghtitem.hxx>
58 #include <editeng/fhgtitem.hxx>
59 #include <editeng/shdditem.hxx>
60 #include <editeng/escapementitem.hxx>
61 #include <editeng/wrlmitem.hxx>
62 #include <editeng/cmapitem.hxx>
63 #include <editeng/kernitem.hxx>
64 #include <editeng/brushitem.hxx>
65 #include <editeng/emphasismarkitem.hxx>
66 #include <editeng/charreliefitem.hxx>
67 #include <editeng/twolinesitem.hxx>
68 #include <editeng/charscaleitem.hxx>
69 #include <editeng/langitem.hxx>
71 // define ----------------------------------------------------------------
73 //TODO: remove this and calculate off the actual size of text, not
74 //an arbitrary number of characters
75 #define TEXT_WIDTH 80
76 #define ISITEMSET rSet.GetItemState(nWhich)>=SFX_ITEM_DEFAULT
78 using namespace ::com::sun::star::uno;
79 using namespace ::com::sun::star::lang;
80 using ::com::sun::star::i18n::XBreakIterator;
81 using ::com::sun::star::i18n::BreakIterator;
84 // small helper functions to set fonts
86 namespace
88 void scaleFontWidth(Font& _rFont,const OutputDevice& rOutDev,long& _n100PercentFont)
90 _rFont.SetWidth( 0 );
91 _n100PercentFont = rOutDev.GetFontMetric( _rFont ).GetWidth();
94 void initFont(Font& _rFont)
96 _rFont.SetTransparent(true);
97 _rFont.SetAlign(ALIGN_BASELINE);
100 void setFontSize(Font& _rFont)
102 Size aSize( _rFont.GetSize() );
103 aSize.Height() = ( aSize.Height() * 3 ) / 5;
104 aSize.Width() = ( aSize.Width() * 3 ) / 5;
105 _rFont.SetSize( aSize );
108 void calcFontHeightAnyAscent(OutputDevice* _pWin,const Font& _rFont,long& _nHeight,long& _nAscent)
110 if ( !_nHeight )
112 _pWin->SetFont( _rFont );
113 FontMetric aMetric( _pWin->GetFontMetric() );
114 _nHeight = aMetric.GetLineHeight();
115 _nAscent = aMetric.GetAscent();
119 void setFont( const SvxFont& rNewFont, SvxFont& rImplFont )
121 rImplFont = rNewFont;
122 rImplFont.SetTransparent( true );
123 rImplFont.SetAlign( ALIGN_BASELINE );
130 // class FontPrevWin_Impl -----------------------------------------------
132 class FontPrevWin_Impl
134 friend class SvxFontPrevWindow;
136 SvxFont aFont;
137 Printer* pPrinter;
138 bool bDelPrinter;
140 Reference < XBreakIterator > xBreak;
141 std::vector<sal_uIntPtr> aTextWidth;
142 std::deque<sal_Int32> aScriptChg;
143 std::vector<sal_uInt16> aScriptType;
144 SvxFont aCJKFont;
145 SvxFont aCTLFont;
146 OUString aText;
147 OUString aScriptText;
148 Color* pColor;
149 Color* pBackColor;
150 long nAscent;
151 sal_Unicode cStartBracket;
152 sal_Unicode cEndBracket;
154 long n100PercentFontWidth; // initial -1 -> not set yet
155 long n100PercentFontWidthCJK;
156 long n100PercentFontWidthCTL;
157 sal_uInt16 nFontWidthScale;
159 bool bSelection : 1,
160 bGetSelection : 1,
161 bUseResText : 1,
162 bPreviewBackgroundToCharacter : 1,
163 bTwoLines : 1,
164 bUseFontNameAsText : 1,
165 bTextInited : 1;
167 bool m_bCJKEnabled;
168 bool m_bCTLEnabled;
171 public:
172 inline FontPrevWin_Impl() :
173 pPrinter( NULL ), bDelPrinter( false ),
174 pColor( NULL ), pBackColor( 0 ), nAscent( 0 ),
175 cStartBracket( 0 ), cEndBracket( 0 ), nFontWidthScale( 100 ),
176 bSelection( false ), bGetSelection( false ), bUseResText( false ),
177 bPreviewBackgroundToCharacter( false ), bTwoLines( false ),
178 bUseFontNameAsText( false ), bTextInited( false )
180 SvtLanguageOptions aLanguageOptions;
181 m_bCJKEnabled = aLanguageOptions.IsAnyEnabled();
182 m_bCTLEnabled = aLanguageOptions.IsCTLFontEnabled();
184 Invalidate100PercentFontWidth();
187 inline ~FontPrevWin_Impl()
189 delete pColor;
190 delete pBackColor;
191 if( bDelPrinter )
192 delete pPrinter;
195 void CheckScript();
196 Size CalcTextSize( OutputDevice* pWin, OutputDevice* pPrt, const SvxFont &rFont );
197 void DrawPrev( OutputDevice* pWin, Printer* pPrt, Point &rPt, const SvxFont &rFont );
199 bool SetFontWidthScale( sal_uInt16 nScaleInPercent );
200 inline void Invalidate100PercentFontWidth();
201 inline bool Is100PercentFontWidthValid() const;
202 void ScaleFontWidth( const OutputDevice& rOutDev );
203 // scales rNonCJKFont and aCJKFont depending on nFontWidthScale and
204 // sets the 100%-Font-Widths
207 inline void FontPrevWin_Impl::Invalidate100PercentFontWidth()
209 n100PercentFontWidth = n100PercentFontWidthCJK = n100PercentFontWidthCTL = -1;
212 inline bool FontPrevWin_Impl::Is100PercentFontWidthValid() const
214 DBG_ASSERT( ( n100PercentFontWidth == -1 && n100PercentFontWidthCJK == -1 ) ||
215 ( n100PercentFontWidth != -1 && n100PercentFontWidthCJK != -1 ) ||
216 ( n100PercentFontWidth == -1 && n100PercentFontWidthCTL == -1 ) ||
217 ( n100PercentFontWidth != -1 && n100PercentFontWidthCTL != -1 ),
218 "*FontPrevWin_Impl::Is100PercentFontWidthValid(): 100PercentFontWidth's not synchronous" );
219 return n100PercentFontWidth != -1;
222 // class FontPrevWin_Impl -----------------------------------------------
225 * evalutates the scripttypes of the actual string.
226 * Afterwards the positions of script change are notified in aScriptChg,
227 * the scripttypes in aScriptType.
228 * The aTextWidth array will be filled with zero.
230 void FontPrevWin_Impl::CheckScript()
232 assert(!aText.isEmpty()); // must have a preview text here!
233 if (aText == aScriptText)
235 return; // already initialized
238 aScriptText = aText;
240 aScriptChg.clear();
241 aScriptType.clear();
242 aTextWidth.clear();
244 if( !xBreak.is() )
246 Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
247 xBreak = BreakIterator::create(xContext);
249 sal_uInt16 nScript = xBreak->getScriptType( aText, 0 );
250 sal_Int32 nChg = 0;
251 if( com::sun::star::i18n::ScriptType::WEAK == nScript )
253 nChg = xBreak->endOfScript( aText, nChg, nScript );
254 if (nChg < aText.getLength() && nChg >= 0)
255 nScript = xBreak->getScriptType( aText, nChg );
256 else
257 nScript = com::sun::star::i18n::ScriptType::LATIN;
262 nChg = xBreak->endOfScript( aText, nChg, nScript );
263 if (nChg < aText.getLength() && nChg > 0 &&
264 (com::sun::star::i18n::ScriptType::WEAK ==
265 xBreak->getScriptType(aText, nChg - 1)))
267 int8_t nType = u_charType(aText[nChg] );
268 if (nType == U_NON_SPACING_MARK || nType == U_ENCLOSING_MARK ||
269 nType == U_COMBINING_SPACING_MARK )
271 aScriptChg.push_back( nChg - 1 );
273 else
275 aScriptChg.push_back( nChg );
278 else
280 aScriptChg.push_back( nChg );
282 aScriptType.push_back( nScript );
283 aTextWidth.push_back( 0 );
285 if( nChg < aText.getLength() )
286 nScript = xBreak->getScriptType( aText, nChg );
287 else
288 break;
289 } while( true );
293 * Size FontPrevWin_Impl::CalcTextSize(..)
294 * fills the aTextWidth array with the text width of every part
295 * of the actual string without a script change inside.
296 * For Latin parts the given rFont will be used,
297 * for Asian parts the aCJKFont.
298 * The returned size contains the whole string.
299 * The member nAscent is calculated to the maximal ascent of all used fonts.
302 Size FontPrevWin_Impl::CalcTextSize( OutputDevice* pWin, OutputDevice* _pPrinter,
303 const SvxFont &rFont )
305 sal_uInt16 nScript;
306 sal_uInt16 nIdx = 0;
307 sal_Int32 nStart = 0;
308 sal_Int32 nEnd;
309 size_t nCnt = aScriptChg.size();
310 if( nCnt )
312 nEnd = aScriptChg[ nIdx ];
313 nScript = aScriptType[ nIdx ];
315 else
317 nEnd = aText.getLength();
318 nScript = com::sun::star::i18n::ScriptType::LATIN;
320 long nTxtWidth = 0;
321 long nCJKHeight = 0;
322 long nCTLHeight = 0;
323 long nHeight = 0;
324 nAscent = 0;
325 long nCJKAscent = 0;
326 long nCTLAscent = 0;
330 const SvxFont& rFnt = (nScript==com::sun::star::i18n::ScriptType::ASIAN) ? aCJKFont : ((nScript==com::sun::star::i18n::ScriptType::COMPLEX) ? aCTLFont : rFont);
331 sal_uIntPtr nWidth = rFnt.GetTxtSize( _pPrinter, aText, nStart, nEnd-nStart ).
332 Width();
333 if (nIdx >= aTextWidth.size())
334 break;
335 aTextWidth[ nIdx++ ] = nWidth;
336 nTxtWidth += nWidth;
337 switch(nScript)
339 case com::sun::star::i18n::ScriptType::ASIAN:
340 calcFontHeightAnyAscent(pWin,aCJKFont,nCJKHeight,nCJKAscent);
341 break;
342 case com::sun::star::i18n::ScriptType::COMPLEX:
343 calcFontHeightAnyAscent(pWin,aCTLFont,nCTLHeight,nCTLAscent);
344 break;
345 default:
346 calcFontHeightAnyAscent(pWin,rFont,nHeight,nAscent);
349 if( nEnd < aText.getLength() && nIdx < nCnt )
351 nStart = nEnd;
352 nEnd = aScriptChg[ nIdx ];
353 nScript = aScriptType[ nIdx ];
355 else
356 break;
358 while( true );
359 nHeight -= nAscent;
360 nCJKHeight -= nCJKAscent;
361 nCTLHeight -= nCTLAscent;
362 if( nHeight < nCJKHeight )
363 nHeight = nCJKHeight;
364 if( nAscent < nCJKAscent )
365 nAscent = nCJKAscent;
366 if( nHeight < nCTLHeight )
367 nHeight = nCTLHeight;
368 if( nAscent < nCTLAscent )
369 nAscent = nCTLAscent;
370 nHeight += nAscent;
372 Size aTxtSize( nTxtWidth, nHeight );
373 return aTxtSize;
377 * void FontPrevWin_Impl::DrawPrev(..)
378 * calls SvxFont::DrawPrev(..) for every part of the string without a script
379 * change inside, for Asian parts the aCJKFont will be used, otherwise the
380 * given rFont.
383 void FontPrevWin_Impl::DrawPrev( OutputDevice* pWin, Printer* _pPrinter,
384 Point &rPt, const SvxFont &rFont )
386 Font aOldFont = _pPrinter->GetFont();
387 sal_uInt16 nScript;
388 sal_uInt16 nIdx = 0;
389 sal_Int32 nStart = 0;
390 sal_Int32 nEnd;
391 size_t nCnt = aScriptChg.size();
392 if( nCnt )
394 nEnd = aScriptChg[ nIdx ];
395 nScript = aScriptType[ nIdx ];
397 else
399 nEnd = aText.getLength();
400 nScript = com::sun::star::i18n::ScriptType::LATIN;
404 const SvxFont& rFnt = (nScript==com::sun::star::i18n::ScriptType::ASIAN) ? aCJKFont : ((nScript==com::sun::star::i18n::ScriptType::COMPLEX) ? aCTLFont : rFont);
405 _pPrinter->SetFont( rFnt );
407 rFnt.DrawPrev( pWin, _pPrinter, rPt, aText, nStart, nEnd - nStart );
409 rPt.X() += aTextWidth[ nIdx++ ];
410 if( nEnd < aText.getLength() && nIdx < nCnt )
412 nStart = nEnd;
413 nEnd = aScriptChg[ nIdx ];
414 nScript = aScriptType[ nIdx ];
416 else
417 break;
419 while( true );
420 _pPrinter->SetFont( aOldFont );
425 bool FontPrevWin_Impl::SetFontWidthScale( sal_uInt16 nScale )
427 if( nFontWidthScale != nScale )
429 nFontWidthScale = nScale;
430 return true;
433 return false;
439 void FontPrevWin_Impl::ScaleFontWidth( const OutputDevice& rOutDev )
441 if( !Is100PercentFontWidthValid() )
443 scaleFontWidth(aFont,rOutDev,n100PercentFontWidth);
444 scaleFontWidth(aCJKFont,rOutDev,n100PercentFontWidthCJK);
445 scaleFontWidth(aCTLFont,rOutDev,n100PercentFontWidthCTL);
448 aFont.SetWidth( n100PercentFontWidth * nFontWidthScale / 100 );
449 aCJKFont.SetWidth( n100PercentFontWidthCJK * nFontWidthScale / 100 );
450 aCTLFont.SetWidth( n100PercentFontWidthCTL * nFontWidthScale / 100 );
453 // class SvxFontPrevWindow -----------------------------------------------
455 void SvxFontPrevWindow::InitSettings( bool bForeground, bool bBackground )
457 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
459 if ( bForeground )
461 svtools::ColorConfig aColorConfig;
462 Color aTextColor( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
464 if ( IsControlForeground() )
465 aTextColor = GetControlForeground();
466 SetTextColor( aTextColor );
469 if ( bBackground )
471 if ( IsControlBackground() )
472 SetBackground( GetControlBackground() );
473 else
474 SetBackground( rStyleSettings.GetWindowColor() );
476 Invalidate();
481 void SvxFontPrevWindow::Init()
483 pImpl = new FontPrevWin_Impl;
484 SfxViewShell* pSh = SfxViewShell::Current();
486 if ( pSh )
487 pImpl->pPrinter = pSh->GetPrinter();
489 if ( !pImpl->pPrinter )
491 pImpl->pPrinter = new Printer;
492 pImpl->bDelPrinter = true;
494 SetMapMode( MapMode( MAP_TWIP ) );
495 initFont(pImpl->aFont);
496 initFont(pImpl->aCJKFont);
497 initFont(pImpl->aCTLFont);
498 InitSettings( true, true );
499 SetBorderStyle( WINDOW_BORDER_MONO );
502 SvxFontPrevWindow::SvxFontPrevWindow( Window* pParent, const ResId& rId ) :
503 Window( pParent, rId )
505 Init();
508 SvxFontPrevWindow::SvxFontPrevWindow(Window* pParent, WinBits nStyle)
509 : Window(pParent, nStyle)
511 Init();
514 extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSvxFontPrevWindow(Window *pParent, VclBuilder::stringmap &rMap)
516 WinBits nWinStyle = 0;
517 OString sBorder = VclBuilder::extractCustomProperty(rMap);
518 if (!sBorder.isEmpty())
519 nWinStyle |= WB_BORDER;
520 SvxFontPrevWindow *pWindow = new SvxFontPrevWindow(pParent, nWinStyle);
521 return pWindow;
524 SvxFontPrevWindow::~SvxFontPrevWindow()
526 delete pImpl;
530 SvxFont& SvxFontPrevWindow::GetCTLFont()
532 return pImpl->aCTLFont;
537 SvxFont& SvxFontPrevWindow::GetCJKFont()
539 return pImpl->aCJKFont;
544 void SvxFontPrevWindow::StateChanged( StateChangedType nType )
546 if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
547 InitSettings( true, false );
548 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
549 InitSettings( false, true );
551 Window::StateChanged( nType );
552 Invalidate();
557 void SvxFontPrevWindow::DataChanged( const DataChangedEvent& rDCEvt )
559 if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
560 InitSettings( true, true );
561 else
562 Window::DataChanged( rDCEvt );
565 SvxFont& SvxFontPrevWindow::GetFont()
567 pImpl->Invalidate100PercentFontWidth(); // because the user might change the size
568 return pImpl->aFont;
571 const SvxFont& SvxFontPrevWindow::GetFont() const
573 return pImpl->aFont;
578 void SvxFontPrevWindow::SetPreviewText( const OUString& rString )
580 pImpl->aText = rString;
581 pImpl->bTextInited = true;
586 void SvxFontPrevWindow::SetFontNameAsPreviewText()
588 pImpl->bUseFontNameAsText = true;
593 void SvxFontPrevWindow::SetFont( const SvxFont& rNormalOutFont, const SvxFont& rCJKOutFont, const SvxFont& rCTLFont )
595 setFont( rNormalOutFont, pImpl->aFont );
596 setFont( rCJKOutFont, pImpl->aCJKFont );
597 setFont( rCTLFont, pImpl->aCTLFont );
600 pImpl->Invalidate100PercentFontWidth();
601 Invalidate();
606 void SvxFontPrevWindow::SetColor(const Color &rColor)
608 delete pImpl->pColor;
609 pImpl->pColor = new Color( rColor );
610 Invalidate();
614 void SvxFontPrevWindow::ResetColor()
616 delete pImpl->pColor;
617 pImpl->pColor = 0;
618 Invalidate();
623 void SvxFontPrevWindow::SetBackColor(const Color &rColor)
625 delete pImpl->pBackColor;
626 pImpl->pBackColor = new Color( rColor );
627 Invalidate();
632 void SvxFontPrevWindow::UseResourceText( bool bUse )
634 pImpl->bUseResText = bUse;
639 void SvxFontPrevWindow::Paint( const Rectangle& )
641 Printer* pPrinter = pImpl->pPrinter;
642 const SvxFont& rFont = pImpl->aFont;
643 const SvxFont& rCJKFont = pImpl->aCJKFont;
644 const SvxFont& rCTLFont = pImpl->aCTLFont;
646 if ( !IsEnabled() )
648 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
649 const Size aLogSize( GetOutputSize() );
651 Rectangle aRect( Point( 0, 0 ), aLogSize );
652 SetLineColor();
653 SetFillColor( rStyleSettings.GetWindowColor() );
654 DrawRect( aRect );
656 else
658 if ( pImpl->bUseResText )
659 pImpl->aText = GetText();
660 else if ( !pImpl->bSelection && !pImpl->bTextInited )
662 using namespace com::sun::star::i18n::ScriptType;
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.isEmpty();
674 if ( !pImpl->bSelection || pImpl->bUseFontNameAsText )
676 //If we're showing multiple sample texts, then they're all
677 //sample texts. If only showing Latin, continue to use
678 //the fontname as the preview
679 if ((pImpl->m_bCJKEnabled) || (pImpl->m_bCTLEnabled))
680 pImpl->aText = makeRepresentativeTextForFont(LATIN, rFont);
681 else
682 pImpl->aText = rFont.GetName();
684 if (pImpl->m_bCJKEnabled)
686 if (!pImpl->aText.isEmpty())
687 pImpl->aText += " ";
688 pImpl->aText += makeRepresentativeTextForFont(ASIAN, rCJKFont);
691 if (pImpl->m_bCTLEnabled)
693 if (!pImpl->aText.isEmpty())
694 pImpl->aText += " ";
695 pImpl->aText += makeRepresentativeTextForFont(COMPLEX, rCTLFont);
699 if ( pImpl->aText.isEmpty() )
700 pImpl->aText = GetText();
702 if (pImpl->aText.isEmpty())
703 { // fdo#58427: still no text? let's try that one...
704 pImpl->aText = makeRepresentativeTextForFont(LATIN, rFont);
707 // remove line feeds and carriage returns from string
708 bool bNotEmpty = false;
709 for ( sal_Int32 i = 0; i < pImpl->aText.getLength(); ++i )
711 if ( 0xa == pImpl->aText[i] || 0xd == pImpl->aText[i] )
712 pImpl->aText = pImpl->aText.replaceAt( i, 1, " " );
713 else
714 bNotEmpty = true;
716 if ( !bNotEmpty )
717 pImpl->aText = GetText();
719 if ( pImpl->aText.getLength() > (TEXT_WIDTH-1) )
721 sal_Int32 nSpaceIdx = pImpl->aText.indexOf(" ", TEXT_WIDTH);
722 if (nSpaceIdx != -1)
723 pImpl->aText = pImpl->aText.copy(0, nSpaceIdx);
727 // calculate text width scaling
728 pImpl->ScaleFontWidth( *this/*, rFont*/ );
730 pImpl->CheckScript();
731 Size aTxtSize = pImpl->CalcTextSize( this, pPrinter, rFont );
733 const Size aLogSize( GetOutputSize() );
735 long nX = aLogSize.Width() / 2 - aTxtSize.Width() / 2;
736 long nY = aLogSize.Height() / 2 - aTxtSize.Height() / 2;
738 if ( nY + pImpl->nAscent > aLogSize.Height() )
739 nY = aLogSize.Height() - pImpl->nAscent;
741 if ( pImpl->pBackColor )
743 Rectangle aRect( Point( 0, 0 ), aLogSize );
744 Color aLineCol = GetLineColor();
745 Color aFillCol = GetFillColor();
746 SetLineColor();
747 SetFillColor( *pImpl->pBackColor );
748 DrawRect( aRect );
749 SetLineColor( aLineCol );
750 SetFillColor( aFillCol );
752 if ( pImpl->pColor )
754 Rectangle aRect( Point( nX, nY ), aTxtSize );
755 Color aLineCol = GetLineColor();
756 Color aFillCol = GetFillColor();
757 SetLineColor();
758 SetFillColor( *pImpl->pColor );
759 DrawRect( aRect );
760 SetLineColor( aLineCol );
761 SetFillColor( aFillCol );
764 long nStdAscent = pImpl->nAscent;
765 nY += nStdAscent;
767 if (IsTwoLines())
769 SvxFont aSmallFont( rFont );
770 Size aOldSize = pImpl->aCJKFont.GetSize();
771 setFontSize(aSmallFont);
772 setFontSize(pImpl->aCJKFont);
774 long nStartBracketWidth = 0;
775 long nEndBracketWidth = 0;
776 long nTextWidth = 0;
777 if(pImpl->cStartBracket)
779 OUString sBracket(pImpl->cStartBracket);
780 nStartBracketWidth = rFont.GetTxtSize( pPrinter, sBracket ).Width();
782 if(pImpl->cEndBracket)
784 OUString sBracket(pImpl->cEndBracket);
785 nEndBracketWidth = rFont.GetTxtSize( pPrinter, sBracket ).Width();
787 nTextWidth = pImpl->CalcTextSize( this, pPrinter, aSmallFont ).Width();
788 long nResultWidth = nStartBracketWidth;
789 nResultWidth += nEndBracketWidth;
790 nResultWidth += nTextWidth;
792 long _nX = (aLogSize.Width() - nResultWidth) / 2;
793 DrawLine( Point( 0, nY ), Point( _nX, nY ) );
794 DrawLine( Point( _nX + nResultWidth, nY ), Point( aLogSize.Width(), nY ) );
796 long nSmallAscent = pImpl->nAscent;
797 long nOffset = (nStdAscent - nSmallAscent ) / 2;
799 if(pImpl->cStartBracket)
801 OUString sBracket(pImpl->cStartBracket);
802 rFont.DrawPrev( this, pPrinter, Point( _nX, nY - nOffset - 4), sBracket );
803 _nX += nStartBracketWidth;
806 Point aTmpPoint1( _nX, nY - nSmallAscent - 2 );
807 Point aTmpPoint2( _nX, nY );
808 pImpl->DrawPrev( this, pPrinter, aTmpPoint1, aSmallFont );
809 pImpl->DrawPrev( this, pPrinter, aTmpPoint2, aSmallFont );
811 _nX += nTextWidth;
812 if(pImpl->cEndBracket)
814 Point aTmpPoint( _nX + 1, nY - nOffset - 4);
815 OUString sBracket(pImpl->cEndBracket);
816 rFont.DrawPrev( this, pPrinter, aTmpPoint, sBracket );
818 pImpl->aCJKFont.SetSize( aOldSize );
820 else
823 Color aLineCol = GetLineColor();
825 SetLineColor( rFont.GetColor() );
826 DrawLine( Point( 0, nY ), Point( nX, nY ) );
827 DrawLine( Point( nX + aTxtSize.Width(), nY ), Point( aLogSize.Width(), nY ) );
828 SetLineColor( aLineCol );
830 Point aTmpPoint( nX, nY );
831 pImpl->DrawPrev( this, pPrinter, aTmpPoint, rFont );
836 bool SvxFontPrevWindow::IsTwoLines() const
838 return pImpl->bTwoLines;
841 void SvxFontPrevWindow::SetTwoLines(bool bSet)
843 pImpl->bTwoLines = bSet;
846 void SvxFontPrevWindow::SetBrackets(sal_Unicode cStart, sal_Unicode cEnd)
848 pImpl->cStartBracket = cStart;
849 pImpl->cEndBracket = cEnd;
854 void SvxFontPrevWindow::SetFontWidthScale( sal_uInt16 n )
856 if( pImpl->SetFontWidthScale( n ) )
857 Invalidate();
862 void SvxFontPrevWindow::AutoCorrectFontColor( void )
864 Color aFontColor( GetTextColor() );
866 if( COL_AUTO == pImpl->aFont.GetColor().GetColor() )
867 pImpl->aFont.SetColor( aFontColor );
869 if( COL_AUTO == pImpl->aCJKFont.GetColor().GetColor() )
870 pImpl->aCJKFont.SetColor( aFontColor );
872 if( COL_AUTO == pImpl->aCTLFont.GetColor().GetColor() )
873 pImpl->aCTLFont.SetColor( aFontColor );
878 static bool GetWhich (const SfxItemSet &rSet, sal_uInt16 nSlot, sal_uInt16 &rWhich)
880 rWhich = rSet.GetPool()->GetWhich( nSlot, true );
881 return rSet.GetItemState(rWhich) >= SFX_ITEM_DEFAULT;
884 static void SetPrevFont( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont )
886 sal_uInt16 nWhich;
887 if (GetWhich ( rSet, nSlot, nWhich ) )
889 const SvxFontItem& rFontItem = ( SvxFontItem& ) rSet.Get( nWhich );
890 rFont.SetFamily( rFontItem.GetFamily() );
891 rFont.SetName( rFontItem.GetFamilyName() );
892 rFont.SetPitch( rFontItem.GetPitch() );
893 rFont.SetCharSet( rFontItem.GetCharSet() );
894 rFont.SetStyleName( rFontItem.GetStyleName() );
898 static void SetPrevFontStyle( const SfxItemSet& rSet, sal_uInt16 nPosture, sal_uInt16 nWeight, SvxFont& rFont )
900 sal_uInt16 nWhich;
901 if( GetWhich( rSet, nPosture, nWhich ) )
903 const SvxPostureItem& rItem = ( const SvxPostureItem& ) rSet.Get( nWhich );
904 rFont.SetItalic( ( FontItalic ) rItem.GetValue() != ITALIC_NONE ? ITALIC_NORMAL : ITALIC_NONE );
907 if( GetWhich( rSet, nWeight, nWhich ) )
909 const SvxWeightItem& rItem = ( const SvxWeightItem& ) rSet.Get( nWhich );
910 rFont.SetWeight( ( FontWeight ) rItem.GetValue() != WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL );
914 void SvxFontPrevWindow::SetFontSize( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont )
916 sal_uInt16 nWhich;
917 long nH;
918 if( GetWhich( rSet, nSlot, nWhich ) )
920 nH = LogicToLogic( ( ( SvxFontHeightItem& ) rSet.Get( nWhich ) ).GetHeight(),
921 ( MapUnit ) rSet.GetPool()->GetMetric( nWhich ),
922 MAP_TWIP );
924 else
925 nH = 240; // as default 12pt
927 rFont.SetSize( Size( 0, nH ) );
930 void SvxFontPrevWindow::SetFontLang(const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont)
932 sal_uInt16 nWhich;
933 LanguageType nLang;
934 if( GetWhich( rSet, nSlot, nWhich ) )
935 nLang = static_cast<const SvxLanguageItem&>(rSet.Get(nWhich)).GetLanguage();
936 else
937 nLang = LANGUAGE_NONE;
938 rFont.SetLanguage(nLang);
941 static void SetPrevFontEscapement(SvxFont& _rFont, sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc )
943 _rFont.SetPropr( nProp );
944 _rFont.SetProprRel( nEscProp );
945 _rFont.SetEscapement( nEsc );
948 void SvxFontPrevWindow::SetFromItemSet( const SfxItemSet &rSet,
949 bool bPreviewBackgroundToCharacter )
951 sal_uInt16 nWhich;
952 SvxFont& rFont = GetFont();
953 SvxFont& rCJKFont = GetCJKFont();
954 SvxFont& rCTLFont = GetCTLFont();
956 // Preview string
957 if( GetWhich( rSet, SID_CHAR_DLG_PREVIEW_STRING, nWhich ) )
959 const SfxStringItem& rItem = ( SfxStringItem& ) rSet.Get( nWhich );
960 OUString aString = rItem.GetValue();
961 if( !aString.isEmpty() )
962 SetPreviewText( aString );
963 else
964 SetFontNameAsPreviewText();
967 // Underline
968 FontUnderline eUnderline;
969 if( GetWhich( rSet, SID_ATTR_CHAR_UNDERLINE, nWhich ) )
971 const SvxUnderlineItem& rItem = ( SvxUnderlineItem& ) rSet.Get( nWhich );
972 eUnderline = ( FontUnderline ) rItem.GetValue();
973 SetTextLineColor( rItem.GetColor() );
975 else
976 eUnderline = UNDERLINE_NONE;
978 rFont.SetUnderline( eUnderline );
979 rCJKFont.SetUnderline( eUnderline );
980 rCTLFont.SetUnderline( eUnderline );
982 // Overline
983 FontUnderline eOverline;
984 if( GetWhich( rSet, SID_ATTR_CHAR_OVERLINE, nWhich ) )
986 const SvxOverlineItem& rItem = ( SvxOverlineItem& ) rSet.Get( nWhich );
987 eOverline = ( FontUnderline ) rItem.GetValue();
988 SetOverlineColor( rItem.GetColor() );
990 else
991 eOverline = UNDERLINE_NONE;
993 rFont.SetOverline( eOverline );
994 rCJKFont.SetOverline( eOverline );
995 rCTLFont.SetOverline( eOverline );
997 // Strikeout
998 FontStrikeout eStrikeout;
999 if( GetWhich( rSet, SID_ATTR_CHAR_STRIKEOUT, nWhich ) )
1001 const SvxCrossedOutItem& rItem = ( SvxCrossedOutItem& ) rSet.Get( nWhich );
1002 eStrikeout = ( FontStrikeout ) rItem.GetValue();
1004 else
1005 eStrikeout = STRIKEOUT_NONE;
1007 rFont.SetStrikeout( eStrikeout );
1008 rCJKFont.SetStrikeout( eStrikeout );
1009 rCTLFont.SetStrikeout( eStrikeout );
1011 // WordLineMode
1012 if( GetWhich( rSet, SID_ATTR_CHAR_WORDLINEMODE, nWhich ) )
1014 const SvxWordLineModeItem& rItem = ( SvxWordLineModeItem& ) rSet.Get( nWhich );
1015 rFont.SetWordLineMode( rItem.GetValue() );
1016 rCJKFont.SetWordLineMode( rItem.GetValue() );
1017 rCTLFont.SetWordLineMode( rItem.GetValue() );
1020 // Emphasis
1021 if( GetWhich( rSet, SID_ATTR_CHAR_EMPHASISMARK, nWhich ) )
1023 const SvxEmphasisMarkItem& rItem = ( SvxEmphasisMarkItem& ) rSet.Get( nWhich );
1024 FontEmphasisMark eMark = rItem.GetEmphasisMark();
1025 rFont.SetEmphasisMark( eMark );
1026 rCJKFont.SetEmphasisMark( eMark );
1027 rCTLFont.SetEmphasisMark( eMark );
1030 // Relief
1031 if( GetWhich( rSet, SID_ATTR_CHAR_RELIEF, nWhich ) )
1033 const SvxCharReliefItem& rItem = ( SvxCharReliefItem& ) rSet.Get( nWhich );
1034 FontRelief eFontRelief = ( FontRelief ) rItem.GetValue();
1035 rFont.SetRelief( eFontRelief );
1036 rCJKFont.SetRelief( eFontRelief );
1037 rCTLFont.SetRelief( eFontRelief );
1040 // Effects
1041 if( GetWhich( rSet, SID_ATTR_CHAR_CASEMAP, nWhich ) )
1043 const SvxCaseMapItem& rItem = ( SvxCaseMapItem& ) rSet.Get( nWhich );
1044 SvxCaseMap eCaseMap = ( SvxCaseMap ) rItem.GetValue();
1045 rFont.SetCaseMap( eCaseMap );
1046 rCJKFont.SetCaseMap( eCaseMap );
1047 // #i78474# small caps do not exist in CTL fonts
1048 rCTLFont.SetCaseMap( eCaseMap == SVX_CASEMAP_KAPITAELCHEN ? SVX_CASEMAP_NOT_MAPPED : eCaseMap );
1051 // Outline
1052 if( GetWhich( rSet, SID_ATTR_CHAR_CONTOUR, nWhich ) )
1054 const SvxContourItem& rItem = ( SvxContourItem& ) rSet.Get( nWhich );
1055 bool bOutline = rItem.GetValue();
1056 rFont.SetOutline( bOutline );
1057 rCJKFont.SetOutline( bOutline );
1058 rCTLFont.SetOutline( bOutline );
1061 // Shadow
1062 if( GetWhich( rSet, SID_ATTR_CHAR_SHADOWED, nWhich ) )
1064 const SvxShadowedItem& rItem = ( SvxShadowedItem& ) rSet.Get( nWhich );
1065 bool bShadow = rItem.GetValue();
1066 rFont.SetShadow( bShadow );
1067 rCJKFont.SetShadow( bShadow );
1068 rCTLFont.SetShadow( bShadow );
1071 // Background
1072 bool bTransparent;
1073 if( GetWhich( rSet, bPreviewBackgroundToCharacter ? SID_ATTR_BRUSH : SID_ATTR_BRUSH_CHAR, nWhich ) )
1075 const SvxBrushItem& rBrush = ( SvxBrushItem& ) rSet.Get( nWhich );
1076 const Color& rColor = rBrush.GetColor();
1077 bTransparent = rColor.GetTransparency() > 0;
1078 rFont.SetFillColor( rColor );
1079 rCJKFont.SetFillColor( rColor );
1080 rCTLFont.SetFillColor( rColor );
1082 else
1083 bTransparent = TRUE;
1085 rFont.SetTransparent( bTransparent );
1086 rCJKFont.SetTransparent( bTransparent );
1087 rCTLFont.SetTransparent( bTransparent );
1089 Color aBackCol( COL_TRANSPARENT );
1090 if( !bPreviewBackgroundToCharacter )
1092 if( GetWhich( rSet, SID_ATTR_BRUSH, nWhich ) )
1094 const SvxBrushItem& rBrush = ( SvxBrushItem& ) rSet.Get( nWhich );
1095 if( GPOS_NONE == rBrush.GetGraphicPos() )
1096 aBackCol = rBrush.GetColor();
1099 SetBackColor( aBackCol );
1101 // Font
1102 SetPrevFont( rSet, SID_ATTR_CHAR_FONT, rFont );
1103 SetPrevFont( rSet, SID_ATTR_CHAR_CJK_FONT, rCJKFont );
1104 SetPrevFont( rSet, SID_ATTR_CHAR_CTL_FONT, rCTLFont );
1106 // Style
1107 SetPrevFontStyle( rSet, SID_ATTR_CHAR_POSTURE, SID_ATTR_CHAR_WEIGHT, rFont );
1108 SetPrevFontStyle( rSet, SID_ATTR_CHAR_CJK_POSTURE, SID_ATTR_CHAR_CJK_WEIGHT, rCJKFont );
1109 SetPrevFontStyle( rSet, SID_ATTR_CHAR_CTL_POSTURE, SID_ATTR_CHAR_CTL_WEIGHT, rCTLFont );
1111 // Size
1112 SetFontSize( rSet, SID_ATTR_CHAR_FONTHEIGHT, rFont );
1113 SetFontSize( rSet, SID_ATTR_CHAR_CJK_FONTHEIGHT, rCJKFont );
1114 SetFontSize( rSet, SID_ATTR_CHAR_CTL_FONTHEIGHT, rCTLFont );
1116 // Language
1117 SetFontLang( rSet, SID_ATTR_CHAR_LANGUAGE, rFont );
1118 SetFontLang( rSet, SID_ATTR_CHAR_CJK_LANGUAGE, rCJKFont );
1119 SetFontLang( rSet, SID_ATTR_CHAR_CTL_LANGUAGE, rCTLFont );
1121 // Color
1122 if( GetWhich( rSet, SID_ATTR_CHAR_COLOR, nWhich ) )
1124 const SvxColorItem& rItem = ( SvxColorItem& ) rSet.Get( nWhich );
1125 Color aCol( rItem.GetValue() );
1126 rFont.SetColor( aCol );
1128 rCJKFont.SetColor( aCol );
1129 rCTLFont.SetColor( aCol );
1131 AutoCorrectFontColor(); // handle color COL_AUTO
1134 // Kerning
1135 if( GetWhich( rSet, SID_ATTR_CHAR_KERNING, nWhich ) )
1137 const SvxKerningItem& rItem = ( SvxKerningItem& ) rSet.Get( nWhich );
1138 short nKern = ( short )
1139 LogicToLogic( rItem.GetValue(), ( MapUnit ) rSet.GetPool()->GetMetric( nWhich ), MAP_TWIP );
1140 rFont.SetFixKerning( nKern );
1141 rCJKFont.SetFixKerning( nKern );
1142 rCTLFont.SetFixKerning( nKern );
1145 // Escapement
1146 const sal_uInt8 nProp = 100;
1147 short nEsc;
1148 sal_uInt8 nEscProp;
1149 if( GetWhich( rSet, SID_ATTR_CHAR_ESCAPEMENT, nWhich ) )
1151 const SvxEscapementItem& rItem = ( SvxEscapementItem& ) rSet.Get( nWhich );
1152 nEsc = rItem.GetEsc();
1153 nEscProp = rItem.GetProp();
1155 if( nEsc == DFLT_ESC_AUTO_SUPER )
1156 nEsc = DFLT_ESC_SUPER;
1157 else if( nEsc == DFLT_ESC_AUTO_SUB )
1158 nEsc = DFLT_ESC_SUB;
1160 else
1162 nEsc = 0;
1163 nEscProp = 100;
1165 SetPrevFontEscapement( rFont, nProp, nEscProp, nEsc );
1166 SetPrevFontEscapement( rCJKFont, nProp, nEscProp, nEsc );
1167 SetPrevFontEscapement( rCTLFont, nProp, nEscProp, nEsc );
1169 // Font width scale
1170 if( GetWhich( rSet, SID_ATTR_CHAR_SCALEWIDTH, nWhich ) )
1172 const SvxCharScaleWidthItem&rItem = ( SvxCharScaleWidthItem& ) rSet.Get( nWhich );
1173 SetFontWidthScale( rItem.GetValue() );
1176 Invalidate();
1181 void SvxFontPrevWindow::Init( const SfxItemSet& rSet )
1183 SvxFont& rFont = GetFont();
1184 SvxFont& rCJKFont = GetCJKFont();
1185 SvxFont& rCTLFont = GetCTLFont();
1187 initFont(rFont);
1188 initFont(rCJKFont);
1189 initFont(rCTLFont);
1190 InitSettings( true, true );
1192 sal_uInt16 nWhich;
1193 nWhich = rSet.GetPool()->GetWhich( SID_CHAR_DLG_PREVIEW_STRING );
1194 if( ISITEMSET )
1196 const SfxStringItem& rItem = ( SfxStringItem& ) rSet.Get( nWhich );
1197 OUString aString = rItem.GetValue();
1198 if( !aString.isEmpty() )
1199 SetPreviewText( aString );
1200 else
1201 SetFontNameAsPreviewText();
1204 // Underline
1205 FontUnderline eUnderline;
1206 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_UNDERLINE );
1207 if( ISITEMSET )
1209 const SvxUnderlineItem& rItem = ( SvxUnderlineItem& ) rSet.Get( nWhich );
1210 eUnderline = ( FontUnderline ) rItem.GetValue();
1211 SetTextLineColor( rItem.GetColor() );
1213 else
1214 eUnderline = UNDERLINE_NONE;
1216 rFont.SetUnderline( eUnderline );
1217 rCJKFont.SetUnderline( eUnderline );
1218 rCTLFont.SetUnderline( eUnderline );
1220 // Overline
1221 FontUnderline eOverline;
1222 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_OVERLINE );
1223 if( ISITEMSET )
1225 const SvxOverlineItem& rItem = ( SvxOverlineItem& ) rSet.Get( nWhich );
1226 eOverline = ( FontUnderline ) rItem.GetValue();
1227 SetOverlineColor( rItem.GetColor() );
1229 else
1230 eOverline = UNDERLINE_NONE;
1232 rFont.SetOverline( eOverline );
1233 rCJKFont.SetOverline( eOverline );
1234 rCTLFont.SetOverline( eOverline );
1236 // Strikeout
1237 FontStrikeout eStrikeout;
1238 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_STRIKEOUT );
1239 if( ISITEMSET )
1241 const SvxCrossedOutItem& rItem = ( SvxCrossedOutItem& ) rSet.Get( nWhich );
1242 eStrikeout = ( FontStrikeout ) rItem.GetValue();
1244 else
1245 eStrikeout = STRIKEOUT_NONE;
1247 rFont.SetStrikeout( eStrikeout );
1248 rCJKFont.SetStrikeout( eStrikeout );
1249 rCTLFont.SetStrikeout( eStrikeout );
1251 // WordLineMode
1252 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_WORDLINEMODE );
1253 if( ISITEMSET )
1255 const SvxWordLineModeItem& rItem = ( SvxWordLineModeItem& ) rSet.Get( nWhich );
1256 rFont.SetWordLineMode( rItem.GetValue() );
1257 rCJKFont.SetWordLineMode( rItem.GetValue() );
1258 rCTLFont.SetWordLineMode( rItem.GetValue() );
1261 // Emphasis
1262 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_EMPHASISMARK );
1263 if( ISITEMSET )
1265 const SvxEmphasisMarkItem& rItem = ( SvxEmphasisMarkItem& ) rSet.Get( nWhich );
1266 FontEmphasisMark eMark = rItem.GetEmphasisMark();
1267 rFont.SetEmphasisMark( eMark );
1268 rCJKFont.SetEmphasisMark( eMark );
1269 rCTLFont.SetEmphasisMark( eMark );
1272 // Relief
1273 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_RELIEF );
1274 if( ISITEMSET )
1276 const SvxCharReliefItem& rItem = ( SvxCharReliefItem& ) rSet.Get( nWhich );
1277 FontRelief eFontRelief = ( FontRelief ) rItem.GetValue();
1278 rFont.SetRelief( eFontRelief );
1279 rCJKFont.SetRelief( eFontRelief );
1280 rCTLFont.SetRelief( eFontRelief );
1283 // Effects
1284 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_CASEMAP );
1285 if( ISITEMSET )
1287 const SvxCaseMapItem& rItem = ( SvxCaseMapItem& ) rSet.Get( nWhich );
1288 SvxCaseMap eCaseMap = ( SvxCaseMap ) rItem.GetValue();
1289 rFont.SetCaseMap( eCaseMap );
1290 rCJKFont.SetCaseMap( eCaseMap );
1291 // #i78474# small caps do not exist in CTL fonts
1292 rCTLFont.SetCaseMap( eCaseMap == SVX_CASEMAP_KAPITAELCHEN ? SVX_CASEMAP_NOT_MAPPED : eCaseMap );
1295 // Outline
1296 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_CONTOUR );
1297 if( ISITEMSET )
1299 const SvxContourItem& rItem = ( SvxContourItem& ) rSet.Get( nWhich );
1300 bool bOutline = rItem.GetValue();
1301 rFont.SetOutline( bOutline );
1302 rCJKFont.SetOutline( bOutline );
1303 rCTLFont.SetOutline( bOutline );
1306 // Shadow
1307 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_SHADOWED );
1308 if( ISITEMSET )
1310 const SvxShadowedItem& rItem = ( SvxShadowedItem& ) rSet.Get( nWhich );
1311 bool bShadow = rItem.GetValue();
1312 rFont.SetShadow( bShadow );
1313 rCJKFont.SetShadow( bShadow );
1314 rCTLFont.SetShadow( bShadow );
1317 // Background
1318 bool bTransparent;
1319 nWhich = rSet.GetPool()->GetWhich( pImpl->bPreviewBackgroundToCharacter ? SID_ATTR_BRUSH : SID_ATTR_BRUSH_CHAR );
1320 if( ISITEMSET )
1322 const SvxBrushItem& rBrush = ( SvxBrushItem& ) rSet.Get( nWhich );
1323 const Color& rColor = rBrush.GetColor();
1324 bTransparent = rColor.GetTransparency() > 0;
1325 rFont.SetFillColor( rColor );
1326 rCJKFont.SetFillColor( rColor );
1327 rCTLFont.SetFillColor( rColor );
1329 else
1330 bTransparent = true;
1332 rFont.SetTransparent( bTransparent );
1333 rCJKFont.SetTransparent( bTransparent );
1334 rCTLFont.SetTransparent( bTransparent );
1336 Color aBackCol( COL_TRANSPARENT );
1337 if( !pImpl->bPreviewBackgroundToCharacter )
1339 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_BRUSH );
1340 if( ISITEMSET )
1342 const SvxBrushItem& rBrush = ( SvxBrushItem& ) rSet.Get( nWhich );
1343 if( GPOS_NONE == rBrush.GetGraphicPos() )
1344 aBackCol = rBrush.GetColor();
1347 SetBackColor( aBackCol );
1349 // Font
1350 SetFont( rSet, SID_ATTR_CHAR_FONT, rFont );
1351 SetFont( rSet, SID_ATTR_CHAR_CJK_FONT, rCJKFont );
1352 SetFont( rSet, SID_ATTR_CHAR_CTL_FONT, rCTLFont );
1354 // Style
1355 SetFontStyle( rSet, SID_ATTR_CHAR_POSTURE, SID_ATTR_CHAR_WEIGHT, rFont );
1356 SetFontStyle( rSet, SID_ATTR_CHAR_CJK_POSTURE, SID_ATTR_CHAR_CJK_WEIGHT, rCJKFont );
1357 SetFontStyle( rSet, SID_ATTR_CHAR_CTL_POSTURE, SID_ATTR_CHAR_CTL_WEIGHT, rCTLFont );
1359 // Size
1360 SetFontSize( rSet, SID_ATTR_CHAR_FONTHEIGHT, rFont );
1361 SetFontSize( rSet, SID_ATTR_CHAR_CJK_FONTHEIGHT, rCJKFont );
1362 SetFontSize( rSet, SID_ATTR_CHAR_CTL_FONTHEIGHT, rCTLFont );
1364 // Language
1365 SetFontLang( rSet, SID_ATTR_CHAR_LANGUAGE, rFont );
1366 SetFontLang( rSet, SID_ATTR_CHAR_CJK_LANGUAGE, rCJKFont );
1367 SetFontLang( rSet, SID_ATTR_CHAR_CTL_LANGUAGE, rCTLFont );
1369 // Color
1370 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_COLOR );
1371 if( ISITEMSET )
1373 const SvxColorItem& rItem = ( SvxColorItem& ) rSet.Get( nWhich );
1374 Color aCol( rItem.GetValue() );
1375 rFont.SetColor( aCol );
1376 rCJKFont.SetColor( aCol );
1377 rCTLFont.SetColor( aCol );
1379 AutoCorrectFontColor(); // handle color COL_AUTO
1382 // Kerning
1383 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_KERNING );
1384 if( ISITEMSET )
1386 const SvxKerningItem& rItem = ( SvxKerningItem& ) rSet.Get( nWhich );
1387 short nKern = ( short )
1388 LogicToLogic( rItem.GetValue(), ( MapUnit ) rSet.GetPool()->GetMetric( nWhich ), MAP_TWIP );
1389 rFont.SetFixKerning( nKern );
1390 rCJKFont.SetFixKerning( nKern );
1391 rCTLFont.SetFixKerning( nKern );
1394 // Escapement
1395 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_ESCAPEMENT );
1396 const sal_uInt8 nProp = 100;
1397 short nEsc;
1398 sal_uInt8 nEscProp;
1399 if( ISITEMSET )
1401 const SvxEscapementItem& rItem = ( SvxEscapementItem& ) rSet.Get( nWhich );
1402 nEsc = rItem.GetEsc();
1403 nEscProp = rItem.GetProp();
1405 if( nEsc == DFLT_ESC_AUTO_SUPER )
1406 nEsc = DFLT_ESC_SUPER;
1407 else if( nEsc == DFLT_ESC_AUTO_SUB )
1408 nEsc = DFLT_ESC_SUB;
1410 else
1412 nEsc = 0;
1413 nEscProp = 100;
1416 SetFontEscapement( nProp, nEscProp, nEsc );
1418 // Font width scale
1419 SetFontWidthScale( rSet );
1421 Invalidate();
1429 void SvxFontPrevWindow::SetFont( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont )
1431 sal_uInt16 nWhich = rSet.GetPool()->GetWhich( nSlot );
1432 if( ISITEMSET )
1434 const SvxFontItem& rFontItem = (const SvxFontItem&)rSet.Get(nWhich);
1435 rFont.SetFamily( rFontItem.GetFamily() );
1436 rFont.SetName( rFontItem.GetFamilyName() );
1437 rFont.SetPitch( rFontItem.GetPitch() );
1438 rFont.SetCharSet( rFontItem.GetCharSet() );
1439 rFont.SetStyleName( rFontItem.GetStyleName() );
1445 void SvxFontPrevWindow::SetFontStyle( const SfxItemSet& rSet, sal_uInt16 nPosture, sal_uInt16 nWeight, SvxFont& rFont )
1447 sal_uInt16 nWhich = rSet.GetPool()->GetWhich( nPosture );
1448 if( ISITEMSET )
1450 const SvxPostureItem& rItem = ( SvxPostureItem& ) rSet.Get( nWhich );
1451 rFont.SetItalic( ( FontItalic ) rItem.GetValue() != ITALIC_NONE ? ITALIC_NORMAL : ITALIC_NONE );
1454 nWhich = rSet.GetPool()->GetWhich( nWeight );
1455 if( ISITEMSET )
1457 SvxWeightItem& rItem = ( SvxWeightItem& ) rSet.Get( nWhich );
1458 rFont.SetWeight( ( FontWeight ) rItem.GetValue() != WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL );
1464 void SvxFontPrevWindow::SetFontWidthScale( const SfxItemSet& rSet )
1466 sal_uInt16 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_SCALEWIDTH );
1467 if( ISITEMSET )
1469 const SvxCharScaleWidthItem& rItem = ( SvxCharScaleWidthItem& ) rSet.Get( nWhich );
1471 SetFontWidthScale( rItem.GetValue() );
1476 namespace
1479 void setFontEscapement(SvxFont& _rFont,sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc )
1481 _rFont.SetPropr( nProp );
1482 _rFont.SetProprRel( nEscProp );
1483 _rFont.SetEscapement( nEsc );
1490 void SvxFontPrevWindow::SetFontEscapement( sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc )
1492 setFontEscapement(GetFont(),nProp,nEscProp,nEsc);
1493 setFontEscapement(GetCJKFont(),nProp,nEscProp,nEsc);
1494 setFontEscapement(GetCTLFont(),nProp,nEscProp,nEsc);
1495 Invalidate();
1498 Size SvxFontPrevWindow::GetOptimalSize() const
1500 return getPreviewStripSize(this);
1503 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */