update credits
[LibreOffice.git] / svx / source / dialog / fntctrl.cxx
blob5cd5abe4d114c607a2b28ff0b9eb2425e31c4eb4
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/viewsh.hxx> // SfxViewShell
21 #include <sfx2/printer.hxx> // Printer
22 #include <vcl/builder.hxx>
23 #include <vcl/metric.hxx>
24 #include <vcl/svapp.hxx>
25 #include <unicode/uchar.h>
26 #include <com/sun/star/uno/Reference.h>
27 #include <com/sun/star/i18n/BreakIterator.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <comphelper/processfactory.hxx>
31 #include <com/sun/star/i18n/ScriptType.hpp>
33 #include <vector>
34 #include <deque>
35 #include <svtools/colorcfg.hxx>
36 #include <svtools/sampletext.hxx>
38 #include <svx/fntctrl.hxx>
39 #include <svx/dialogs.hrc>
40 #include <svx/sdasitm.hxx>
42 // Item set includes
43 #include <svl/itemset.hxx>
44 #include <svl/itempool.hxx>
45 #include <svl/stritem.hxx> // SfxStringItem
46 #include <svl/languageoptions.hxx>
48 #include <editeng/colritem.hxx>
49 #include <editeng/fontitem.hxx>
50 #include <editeng/editids.hrc> // #define SID_ATTR_*
51 #include <editeng/fontitem.hxx> // SvxFontItem
52 #include <editeng/postitem.hxx> // SvxPostureItem
53 #include <editeng/udlnitem.hxx> // SvxUnderlineItem
54 #include <editeng/crossedoutitem.hxx> // SvxCrossedOutItem
55 #include <editeng/contouritem.hxx> // SvxContourItem
56 #include <editeng/wghtitem.hxx> // SvxWeightItem
57 #include <editeng/fhgtitem.hxx> // SvxFontHeightItem
58 #include <editeng/shdditem.hxx> // SvxShadowedItem
59 #include <editeng/escapementitem.hxx> // SvxEscapementItem
60 #include <editeng/wrlmitem.hxx> // SvxWordLineModeItem
61 #include <editeng/cmapitem.hxx> // SvxWordLineModeItem
62 #include <editeng/kernitem.hxx> // SvxKerningItem
63 #include <editeng/brushitem.hxx> // SvxBrushItem
64 #include <editeng/colritem.hxx> // SvxColorItem
65 #include <editeng/emphasismarkitem.hxx> // SvxEmphasisMarkItem
66 #include <editeng/charreliefitem.hxx> // SvxCharReliefItem
67 #include <editeng/twolinesitem.hxx> // SvxTwoLinesItem
68 #include <editeng/charscaleitem.hxx> // SvxCharScaleWidthItem
69 #include <editeng/langitem.hxx> // SvxLanguageItem
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;
83 // -----------------------------------------------------------------------
84 // small helper functions to set fonts
85 // -----------------------------------------------------------------------
86 namespace
88 void scaleFontWidth(Font& _rFont,const OutputDevice& rOutDev,long& _n100PercentFont)
90 _rFont.SetWidth( 0 );
91 _n100PercentFont = rOutDev.GetFontMetric( _rFont ).GetWidth();
93 // -----------------------------------------------------------------------
94 void initFont(Font& _rFont)
96 _rFont.SetTransparent(sal_True);
97 _rFont.SetAlign(ALIGN_BASELINE);
99 // -----------------------------------------------------------------------
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 );
107 // -----------------------------------------------------------------------
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();
118 // -----------------------------------------------------------------------
119 void setFont( const SvxFont& rNewFont, SvxFont& rImplFont )
121 rImplFont = rNewFont;
122 rImplFont.SetTransparent( sal_True );
123 rImplFont.SetAlign( ALIGN_BASELINE );
127 // -----------------------------------------------------------------------
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<xub_StrLen> aScriptChg;
143 std::vector<sal_uInt16> aScriptType;
144 SvxFont aCJKFont;
145 SvxFont aCTLFont;
146 String aText;
147 String 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.Len()); // 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_uInt16 nChg = 0;
251 if( com::sun::star::i18n::ScriptType::WEAK == nScript )
253 nChg = (xub_StrLen)xBreak->endOfScript( aText, nChg, nScript );
254 if( nChg < aText.Len() )
255 nScript = xBreak->getScriptType( aText, nChg );
256 else
257 nScript = com::sun::star::i18n::ScriptType::LATIN;
262 nChg = (xub_StrLen)xBreak->endOfScript( aText, nChg, nScript );
263 if (nChg < aText.Len() && nChg > 0 &&
264 (com::sun::star::i18n::ScriptType::WEAK ==
265 xBreak->getScriptType(aText, nChg - 1)))
267 int8_t nType = u_charType(aText.GetChar(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.Len() )
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 xub_StrLen nStart = 0;
308 xub_StrLen nEnd;
309 size_t nCnt = aScriptChg.size();
310 if( nCnt )
312 nEnd = aScriptChg[ nIdx ];
313 nScript = aScriptType[ nIdx ];
315 else
317 nEnd = aText.Len();
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.Len() && 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 xub_StrLen nStart = 0;
390 xub_StrLen nEnd;
391 size_t nCnt = aScriptChg.size();
392 if( nCnt )
394 nEnd = aScriptChg[ nIdx ];
395 nScript = aScriptType[ nIdx ];
397 else
399 nEnd = aText.Len();
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.Len() && nIdx < nCnt )
412 nStart = nEnd;
413 nEnd = aScriptChg[ nIdx ];
414 nScript = aScriptType[ nIdx ];
416 else
417 break;
419 while( true );
420 _pPrinter->SetFont( aOldFont );
423 // -----------------------------------------------------------------------
425 bool FontPrevWin_Impl::SetFontWidthScale( sal_uInt16 nScale )
427 if( nFontWidthScale != nScale )
429 nFontWidthScale = nScale;
430 return true;
433 return false;
437 // -----------------------------------------------------------------------
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( sal_Bool bForeground, sal_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();
479 // -----------------------------------------------------------------------
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( sal_True, sal_True );
499 SetBorderStyle( WINDOW_BORDER_MONO );
502 SvxFontPrevWindow::SvxFontPrevWindow( Window* pParent, const ResId& rId ) :
503 Window( pParent, rId )
505 m_aInitialSize = GetSizePixel();
506 Init();
509 SvxFontPrevWindow::SvxFontPrevWindow(Window* pParent, WinBits nStyle)
510 : Window(pParent, nStyle)
512 Init();
515 extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSvxFontPrevWindow(Window *pParent, VclBuilder::stringmap &rMap)
517 WinBits nWinStyle = 0;
518 OString sBorder = VclBuilder::extractCustomProperty(rMap);
519 if (!sBorder.isEmpty())
520 nWinStyle |= WB_BORDER;
521 SvxFontPrevWindow *pWindow = new SvxFontPrevWindow(pParent, nWinStyle);
522 return pWindow;
525 SvxFontPrevWindow::~SvxFontPrevWindow()
527 delete pImpl;
530 // -----------------------------------------------------------------------
531 SvxFont& SvxFontPrevWindow::GetCTLFont()
533 return pImpl->aCTLFont;
536 // -----------------------------------------------------------------------
538 SvxFont& SvxFontPrevWindow::GetCJKFont()
540 return pImpl->aCJKFont;
543 // -----------------------------------------------------------------------
545 void SvxFontPrevWindow::StateChanged( StateChangedType nType )
547 if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
548 InitSettings( sal_True, sal_False );
549 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
550 InitSettings( sal_False, sal_True );
552 Window::StateChanged( nType );
553 Invalidate();
556 // -----------------------------------------------------------------------
558 void SvxFontPrevWindow::DataChanged( const DataChangedEvent& rDCEvt )
560 if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
561 InitSettings( sal_True, sal_True );
562 else
563 Window::DataChanged( rDCEvt );
566 SvxFont& SvxFontPrevWindow::GetFont()
568 pImpl->Invalidate100PercentFontWidth(); // because the user might change the size
569 return pImpl->aFont;
572 const SvxFont& SvxFontPrevWindow::GetFont() const
574 return pImpl->aFont;
577 // -----------------------------------------------------------------------
579 void SvxFontPrevWindow::SetPreviewText( const OUString& rString )
581 pImpl->aText = rString;
582 pImpl->bTextInited = true;
585 // -----------------------------------------------------------------------
587 void SvxFontPrevWindow::SetFontNameAsPreviewText()
589 pImpl->bUseFontNameAsText = sal_True;
592 // -----------------------------------------------------------------------
594 void SvxFontPrevWindow::SetFont( const SvxFont& rNormalOutFont, const SvxFont& rCJKOutFont, const SvxFont& rCTLFont )
596 setFont( rNormalOutFont, pImpl->aFont );
597 setFont( rCJKOutFont, pImpl->aCJKFont );
598 setFont( rCTLFont, pImpl->aCTLFont );
601 pImpl->Invalidate100PercentFontWidth();
602 Invalidate();
605 // -----------------------------------------------------------------------
607 void SvxFontPrevWindow::SetColor(const Color &rColor)
609 delete pImpl->pColor;
610 pImpl->pColor = new Color( rColor );
611 Invalidate();
613 // -----------------------------------------------------------------------
615 void SvxFontPrevWindow::ResetColor()
617 delete pImpl->pColor;
618 pImpl->pColor = 0;
619 Invalidate();
622 // -----------------------------------------------------------------------
624 void SvxFontPrevWindow::SetBackColor(const Color &rColor)
626 delete pImpl->pBackColor;
627 pImpl->pBackColor = new Color( rColor );
628 Invalidate();
631 // -----------------------------------------------------------------------
633 void SvxFontPrevWindow::UseResourceText( bool bUse )
635 pImpl->bUseResText = bUse;
638 // -----------------------------------------------------------------------
640 void SvxFontPrevWindow::Paint( const Rectangle& )
642 Printer* pPrinter = pImpl->pPrinter;
643 const SvxFont& rFont = pImpl->aFont;
644 const SvxFont& rCJKFont = pImpl->aCJKFont;
645 const SvxFont& rCTLFont = pImpl->aCTLFont;
647 if ( !IsEnabled() )
649 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
650 const Size aLogSize( GetOutputSize() );
652 Rectangle aRect( Point( 0, 0 ), aLogSize );
653 SetLineColor();
654 SetFillColor( rStyleSettings.GetWindowColor() );
655 DrawRect( aRect );
657 else
659 if ( pImpl->bUseResText )
660 pImpl->aText = GetText();
661 else if ( !pImpl->bSelection && !pImpl->bTextInited )
663 using namespace com::sun::star::i18n::ScriptType;
665 SfxViewShell* pSh = SfxViewShell::Current();
667 if ( pSh && !pImpl->bGetSelection && !pImpl->bUseFontNameAsText )
669 pImpl->aText = pSh->GetSelectionText();
670 pImpl->bGetSelection = true;
671 pImpl->bSelection = pImpl->aText.Len() != 0;
675 if ( !pImpl->bSelection || pImpl->bUseFontNameAsText )
677 //If we're showing multiple sample texts, then they're all
678 //sample texts. If only showing Latin, continue to use
679 //the fontname as the preview
680 if ((pImpl->m_bCJKEnabled) || (pImpl->m_bCTLEnabled))
681 pImpl->aText = makeRepresentativeTextForFont(LATIN, rFont);
682 else
683 pImpl->aText = rFont.GetName();
685 if (pImpl->m_bCJKEnabled)
687 if (pImpl->aText.Len())
688 pImpl->aText.AppendAscii(" ");
689 pImpl->aText += makeRepresentativeTextForFont(ASIAN, rCJKFont);
692 if (pImpl->m_bCTLEnabled)
694 if (pImpl->aText.Len())
695 pImpl->aText.AppendAscii(" ");
696 pImpl->aText += makeRepresentativeTextForFont(COMPLEX, rCTLFont);
700 if ( !pImpl->aText.Len() )
701 pImpl->aText = GetText();
703 if (!pImpl->aText.Len())
704 { // fdo#58427: still no text? let's try that one...
705 pImpl->aText = makeRepresentativeTextForFont(LATIN, rFont);
708 // remove line feeds and carriage returns from string
709 bool bNotEmpty = false;
710 for ( xub_StrLen i = 0; i < pImpl->aText.Len(); ++i )
712 if ( 0xa == pImpl->aText.GetChar( i ) ||
713 0xd == pImpl->aText.GetChar( i ) )
714 pImpl->aText.SetChar( i, ' ' );
715 else
716 bNotEmpty = true;
718 if ( !bNotEmpty )
719 pImpl->aText = GetText();
721 if ( pImpl->aText.Len() > (TEXT_WIDTH-1) )
722 pImpl->aText.Erase( pImpl->aText.Search( sal_Unicode( ' ' ), TEXT_WIDTH ) );
725 // calculate text width scaling
726 pImpl->ScaleFontWidth( *this/*, rFont*/ );
728 pImpl->CheckScript();
729 Size aTxtSize = pImpl->CalcTextSize( this, pPrinter, rFont );
731 const Size aLogSize( GetOutputSize() );
733 long nX = aLogSize.Width() / 2 - aTxtSize.Width() / 2;
734 long nY = aLogSize.Height() / 2 - aTxtSize.Height() / 2;
736 if ( nY + pImpl->nAscent > aLogSize.Height() )
737 nY = aLogSize.Height() - pImpl->nAscent;
739 if ( pImpl->pBackColor )
741 Rectangle aRect( Point( 0, 0 ), aLogSize );
742 Color aLineCol = GetLineColor();
743 Color aFillCol = GetFillColor();
744 SetLineColor();
745 SetFillColor( *pImpl->pBackColor );
746 DrawRect( aRect );
747 SetLineColor( aLineCol );
748 SetFillColor( aFillCol );
750 if ( pImpl->pColor )
752 Rectangle aRect( Point( nX, nY ), aTxtSize );
753 Color aLineCol = GetLineColor();
754 Color aFillCol = GetFillColor();
755 SetLineColor();
756 SetFillColor( *pImpl->pColor );
757 DrawRect( aRect );
758 SetLineColor( aLineCol );
759 SetFillColor( aFillCol );
762 long nStdAscent = pImpl->nAscent;
763 nY += nStdAscent;
765 if (IsTwoLines())
767 SvxFont aSmallFont( rFont );
768 Size aOldSize = pImpl->aCJKFont.GetSize();
769 setFontSize(aSmallFont);
770 setFontSize(pImpl->aCJKFont);
772 long nStartBracketWidth = 0;
773 long nEndBracketWidth = 0;
774 long nTextWidth = 0;
775 if(pImpl->cStartBracket)
777 OUString sBracket(pImpl->cStartBracket);
778 nStartBracketWidth = rFont.GetTxtSize( pPrinter, sBracket ).Width();
780 if(pImpl->cEndBracket)
782 OUString sBracket(pImpl->cEndBracket);
783 nEndBracketWidth = rFont.GetTxtSize( pPrinter, sBracket ).Width();
785 nTextWidth = pImpl->CalcTextSize( this, pPrinter, aSmallFont ).Width();
786 long nResultWidth = nStartBracketWidth;
787 nResultWidth += nEndBracketWidth;
788 nResultWidth += nTextWidth;
790 long _nX = (aLogSize.Width() - nResultWidth) / 2;
791 DrawLine( Point( 0, nY ), Point( _nX, nY ) );
792 DrawLine( Point( _nX + nResultWidth, nY ), Point( aLogSize.Width(), nY ) );
794 long nSmallAscent = pImpl->nAscent;
795 long nOffset = (nStdAscent - nSmallAscent ) / 2;
797 if(pImpl->cStartBracket)
799 OUString sBracket(pImpl->cStartBracket);
800 rFont.DrawPrev( this, pPrinter, Point( _nX, nY - nOffset - 4), sBracket );
801 _nX += nStartBracketWidth;
804 Point aTmpPoint1( _nX, nY - nSmallAscent - 2 );
805 Point aTmpPoint2( _nX, nY );
806 pImpl->DrawPrev( this, pPrinter, aTmpPoint1, aSmallFont );
807 pImpl->DrawPrev( this, pPrinter, aTmpPoint2, aSmallFont );
809 _nX += nTextWidth;
810 if(pImpl->cEndBracket)
812 Point aTmpPoint( _nX + 1, nY - nOffset - 4);
813 OUString sBracket(pImpl->cEndBracket);
814 rFont.DrawPrev( this, pPrinter, aTmpPoint, sBracket );
816 pImpl->aCJKFont.SetSize( aOldSize );
818 else
821 Color aLineCol = GetLineColor();
823 SetLineColor( rFont.GetColor() );
824 DrawLine( Point( 0, nY ), Point( nX, nY ) );
825 DrawLine( Point( nX + aTxtSize.Width(), nY ), Point( aLogSize.Width(), nY ) );
826 SetLineColor( aLineCol );
828 Point aTmpPoint( nX, nY );
829 pImpl->DrawPrev( this, pPrinter, aTmpPoint, rFont );
834 bool SvxFontPrevWindow::IsTwoLines() const
836 return pImpl->bTwoLines;
839 void SvxFontPrevWindow::SetTwoLines(bool bSet)
841 pImpl->bTwoLines = bSet;
844 void SvxFontPrevWindow::SetBrackets(sal_Unicode cStart, sal_Unicode cEnd)
846 pImpl->cStartBracket = cStart;
847 pImpl->cEndBracket = cEnd;
850 // -----------------------------------------------------------------------
852 void SvxFontPrevWindow::SetFontWidthScale( sal_uInt16 n )
854 if( pImpl->SetFontWidthScale( n ) )
855 Invalidate();
858 // -----------------------------------------------------------------------
860 void SvxFontPrevWindow::AutoCorrectFontColor( void )
862 Color aFontColor( GetTextColor() );
864 if( COL_AUTO == pImpl->aFont.GetColor().GetColor() )
865 pImpl->aFont.SetColor( aFontColor );
867 if( COL_AUTO == pImpl->aCJKFont.GetColor().GetColor() )
868 pImpl->aCJKFont.SetColor( aFontColor );
870 if( COL_AUTO == pImpl->aCTLFont.GetColor().GetColor() )
871 pImpl->aCTLFont.SetColor( aFontColor );
874 // -----------------------------------------------------------------------
876 static bool GetWhich (const SfxItemSet &rSet, sal_uInt16 nSlot, sal_uInt16 &rWhich)
878 rWhich = rSet.GetPool()->GetWhich( nSlot, sal_True );
879 return rSet.GetItemState(rWhich) >= SFX_ITEM_DEFAULT;
882 static void SetPrevFont( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont )
884 sal_uInt16 nWhich;
885 if (GetWhich ( rSet, nSlot, nWhich ) )
887 const SvxFontItem& rFontItem = ( SvxFontItem& ) rSet.Get( nWhich );
888 rFont.SetFamily( rFontItem.GetFamily() );
889 rFont.SetName( rFontItem.GetFamilyName() );
890 rFont.SetPitch( rFontItem.GetPitch() );
891 rFont.SetCharSet( rFontItem.GetCharSet() );
892 rFont.SetStyleName( rFontItem.GetStyleName() );
896 static void SetPrevFontStyle( const SfxItemSet& rSet, sal_uInt16 nPosture, sal_uInt16 nWeight, SvxFont& rFont )
898 sal_uInt16 nWhich;
899 if( GetWhich( rSet, nPosture, nWhich ) )
901 const SvxPostureItem& rItem = ( const SvxPostureItem& ) rSet.Get( nWhich );
902 rFont.SetItalic( ( FontItalic ) rItem.GetValue() != ITALIC_NONE ? ITALIC_NORMAL : ITALIC_NONE );
905 if( GetWhich( rSet, nWeight, nWhich ) )
907 const SvxWeightItem& rItem = ( const SvxWeightItem& ) rSet.Get( nWhich );
908 rFont.SetWeight( ( FontWeight ) rItem.GetValue() != WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL );
912 void SvxFontPrevWindow::SetFontSize( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont )
914 sal_uInt16 nWhich;
915 long nH;
916 if( GetWhich( rSet, nSlot, nWhich ) )
918 nH = LogicToLogic( ( ( SvxFontHeightItem& ) rSet.Get( nWhich ) ).GetHeight(),
919 ( MapUnit ) rSet.GetPool()->GetMetric( nWhich ),
920 MAP_TWIP );
922 else
923 nH = 240; // as default 12pt
925 rFont.SetSize( Size( 0, nH ) );
928 void SvxFontPrevWindow::SetFontLang(const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont)
930 sal_uInt16 nWhich;
931 LanguageType nLang;
932 if( GetWhich( rSet, nSlot, nWhich ) )
933 nLang = static_cast<const SvxLanguageItem&>(rSet.Get(nWhich)).GetLanguage();
934 else
935 nLang = LANGUAGE_NONE;
936 rFont.SetLanguage(nLang);
939 static void SetPrevFontEscapement(SvxFont& _rFont, sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc )
941 _rFont.SetPropr( nProp );
942 _rFont.SetProprRel( nEscProp );
943 _rFont.SetEscapement( nEsc );
946 void SvxFontPrevWindow::SetFromItemSet( const SfxItemSet &rSet,
947 bool bPreviewBackgroundToCharacter )
949 sal_uInt16 nWhich;
950 SvxFont& rFont = GetFont();
951 SvxFont& rCJKFont = GetCJKFont();
952 SvxFont& rCTLFont = GetCTLFont();
954 // Preview string
955 if( GetWhich( rSet, SID_CHAR_DLG_PREVIEW_STRING, nWhich ) )
957 const SfxStringItem& rItem = ( SfxStringItem& ) rSet.Get( nWhich );
958 OUString aString = rItem.GetValue();
959 if( !aString.isEmpty() )
960 SetPreviewText( aString );
961 else
962 SetFontNameAsPreviewText();
965 // Underline
966 FontUnderline eUnderline;
967 if( GetWhich( rSet, SID_ATTR_CHAR_UNDERLINE, nWhich ) )
969 const SvxUnderlineItem& rItem = ( SvxUnderlineItem& ) rSet.Get( nWhich );
970 eUnderline = ( FontUnderline ) rItem.GetValue();
971 SetTextLineColor( rItem.GetColor() );
973 else
974 eUnderline = UNDERLINE_NONE;
976 rFont.SetUnderline( eUnderline );
977 rCJKFont.SetUnderline( eUnderline );
978 rCTLFont.SetUnderline( eUnderline );
980 // Overline
981 FontUnderline eOverline;
982 if( GetWhich( rSet, SID_ATTR_CHAR_OVERLINE, nWhich ) )
984 const SvxOverlineItem& rItem = ( SvxOverlineItem& ) rSet.Get( nWhich );
985 eOverline = ( FontUnderline ) rItem.GetValue();
986 SetOverlineColor( rItem.GetColor() );
988 else
989 eOverline = UNDERLINE_NONE;
991 rFont.SetOverline( eOverline );
992 rCJKFont.SetOverline( eOverline );
993 rCTLFont.SetOverline( eOverline );
995 // Strikeout
996 FontStrikeout eStrikeout;
997 if( GetWhich( rSet, SID_ATTR_CHAR_STRIKEOUT, nWhich ) )
999 const SvxCrossedOutItem& rItem = ( SvxCrossedOutItem& ) rSet.Get( nWhich );
1000 eStrikeout = ( FontStrikeout ) rItem.GetValue();
1002 else
1003 eStrikeout = STRIKEOUT_NONE;
1005 rFont.SetStrikeout( eStrikeout );
1006 rCJKFont.SetStrikeout( eStrikeout );
1007 rCTLFont.SetStrikeout( eStrikeout );
1009 // WordLineMode
1010 if( GetWhich( rSet, SID_ATTR_CHAR_WORDLINEMODE, nWhich ) )
1012 const SvxWordLineModeItem& rItem = ( SvxWordLineModeItem& ) rSet.Get( nWhich );
1013 rFont.SetWordLineMode( rItem.GetValue() );
1014 rCJKFont.SetWordLineMode( rItem.GetValue() );
1015 rCTLFont.SetWordLineMode( rItem.GetValue() );
1018 // Emphasis
1019 if( GetWhich( rSet, SID_ATTR_CHAR_EMPHASISMARK, nWhich ) )
1021 const SvxEmphasisMarkItem& rItem = ( SvxEmphasisMarkItem& ) rSet.Get( nWhich );
1022 FontEmphasisMark eMark = rItem.GetEmphasisMark();
1023 rFont.SetEmphasisMark( eMark );
1024 rCJKFont.SetEmphasisMark( eMark );
1025 rCTLFont.SetEmphasisMark( eMark );
1028 // Relief
1029 if( GetWhich( rSet, SID_ATTR_CHAR_RELIEF, nWhich ) )
1031 const SvxCharReliefItem& rItem = ( SvxCharReliefItem& ) rSet.Get( nWhich );
1032 FontRelief eFontRelief = ( FontRelief ) rItem.GetValue();
1033 rFont.SetRelief( eFontRelief );
1034 rCJKFont.SetRelief( eFontRelief );
1035 rCTLFont.SetRelief( eFontRelief );
1038 // Effects
1039 if( GetWhich( rSet, SID_ATTR_CHAR_CASEMAP, nWhich ) )
1041 const SvxCaseMapItem& rItem = ( SvxCaseMapItem& ) rSet.Get( nWhich );
1042 SvxCaseMap eCaseMap = ( SvxCaseMap ) rItem.GetValue();
1043 rFont.SetCaseMap( eCaseMap );
1044 rCJKFont.SetCaseMap( eCaseMap );
1045 // #i78474# small caps do not exist in CTL fonts
1046 rCTLFont.SetCaseMap( eCaseMap == SVX_CASEMAP_KAPITAELCHEN ? SVX_CASEMAP_NOT_MAPPED : eCaseMap );
1049 // Outline
1050 if( GetWhich( rSet, SID_ATTR_CHAR_CONTOUR, nWhich ) )
1052 const SvxContourItem& rItem = ( SvxContourItem& ) rSet.Get( nWhich );
1053 sal_Bool bOutline = rItem.GetValue();
1054 rFont.SetOutline( bOutline );
1055 rCJKFont.SetOutline( bOutline );
1056 rCTLFont.SetOutline( bOutline );
1059 // Shadow
1060 if( GetWhich( rSet, SID_ATTR_CHAR_SHADOWED, nWhich ) )
1062 const SvxShadowedItem& rItem = ( SvxShadowedItem& ) rSet.Get( nWhich );
1063 sal_Bool bShadow = rItem.GetValue();
1064 rFont.SetShadow( bShadow );
1065 rCJKFont.SetShadow( bShadow );
1066 rCTLFont.SetShadow( bShadow );
1069 // Background
1070 sal_Bool bTransparent;
1071 if( GetWhich( rSet, bPreviewBackgroundToCharacter ? SID_ATTR_BRUSH : SID_ATTR_BRUSH_CHAR, nWhich ) )
1073 const SvxBrushItem& rBrush = ( SvxBrushItem& ) rSet.Get( nWhich );
1074 const Color& rColor = rBrush.GetColor();
1075 bTransparent = rColor.GetTransparency() > 0;
1076 rFont.SetFillColor( rColor );
1077 rCJKFont.SetFillColor( rColor );
1078 rCTLFont.SetFillColor( rColor );
1080 else
1081 bTransparent = TRUE;
1083 rFont.SetTransparent( bTransparent );
1084 rCJKFont.SetTransparent( bTransparent );
1085 rCTLFont.SetTransparent( bTransparent );
1087 Color aBackCol( COL_TRANSPARENT );
1088 if( !bPreviewBackgroundToCharacter )
1090 if( GetWhich( rSet, SID_ATTR_BRUSH, nWhich ) )
1092 const SvxBrushItem& rBrush = ( SvxBrushItem& ) rSet.Get( nWhich );
1093 if( GPOS_NONE == rBrush.GetGraphicPos() )
1094 aBackCol = rBrush.GetColor();
1097 SetBackColor( aBackCol );
1099 // Font
1100 SetPrevFont( rSet, SID_ATTR_CHAR_FONT, rFont );
1101 SetPrevFont( rSet, SID_ATTR_CHAR_CJK_FONT, rCJKFont );
1102 SetPrevFont( rSet, SID_ATTR_CHAR_CTL_FONT, rCTLFont );
1104 // Style
1105 SetPrevFontStyle( rSet, SID_ATTR_CHAR_POSTURE, SID_ATTR_CHAR_WEIGHT, rFont );
1106 SetPrevFontStyle( rSet, SID_ATTR_CHAR_CJK_POSTURE, SID_ATTR_CHAR_CJK_WEIGHT, rCJKFont );
1107 SetPrevFontStyle( rSet, SID_ATTR_CHAR_CTL_POSTURE, SID_ATTR_CHAR_CTL_WEIGHT, rCTLFont );
1109 // Size
1110 SetFontSize( rSet, SID_ATTR_CHAR_FONTHEIGHT, rFont );
1111 SetFontSize( rSet, SID_ATTR_CHAR_CJK_FONTHEIGHT, rCJKFont );
1112 SetFontSize( rSet, SID_ATTR_CHAR_CTL_FONTHEIGHT, rCTLFont );
1114 // Language
1115 SetFontLang( rSet, SID_ATTR_CHAR_LANGUAGE, rFont );
1116 SetFontLang( rSet, SID_ATTR_CHAR_CJK_LANGUAGE, rCJKFont );
1117 SetFontLang( rSet, SID_ATTR_CHAR_CTL_LANGUAGE, rCTLFont );
1119 // Color
1120 if( GetWhich( rSet, SID_ATTR_CHAR_COLOR, nWhich ) )
1122 const SvxColorItem& rItem = ( SvxColorItem& ) rSet.Get( nWhich );
1123 Color aCol( rItem.GetValue() );
1124 rFont.SetColor( aCol );
1126 rCJKFont.SetColor( aCol );
1127 rCTLFont.SetColor( aCol );
1129 AutoCorrectFontColor(); // handle color COL_AUTO
1132 // Kerning
1133 if( GetWhich( rSet, SID_ATTR_CHAR_KERNING, nWhich ) )
1135 const SvxKerningItem& rItem = ( SvxKerningItem& ) rSet.Get( nWhich );
1136 short nKern = ( short )
1137 LogicToLogic( rItem.GetValue(), ( MapUnit ) rSet.GetPool()->GetMetric( nWhich ), MAP_TWIP );
1138 rFont.SetFixKerning( nKern );
1139 rCJKFont.SetFixKerning( nKern );
1140 rCTLFont.SetFixKerning( nKern );
1143 // Escapement
1144 const sal_uInt8 nProp = 100;
1145 short nEsc;
1146 sal_uInt8 nEscProp;
1147 if( GetWhich( rSet, SID_ATTR_CHAR_ESCAPEMENT, nWhich ) )
1149 const SvxEscapementItem& rItem = ( SvxEscapementItem& ) rSet.Get( nWhich );
1150 nEsc = rItem.GetEsc();
1151 nEscProp = rItem.GetProp();
1153 if( nEsc == DFLT_ESC_AUTO_SUPER )
1154 nEsc = DFLT_ESC_SUPER;
1155 else if( nEsc == DFLT_ESC_AUTO_SUB )
1156 nEsc = DFLT_ESC_SUB;
1158 else
1160 nEsc = 0;
1161 nEscProp = 100;
1163 SetPrevFontEscapement( rFont, nProp, nEscProp, nEsc );
1164 SetPrevFontEscapement( rCJKFont, nProp, nEscProp, nEsc );
1165 SetPrevFontEscapement( rCTLFont, nProp, nEscProp, nEsc );
1167 // Font width scale
1168 if( GetWhich( rSet, SID_ATTR_CHAR_SCALEWIDTH, nWhich ) )
1170 const SvxCharScaleWidthItem&rItem = ( SvxCharScaleWidthItem& ) rSet.Get( nWhich );
1171 SetFontWidthScale( rItem.GetValue() );
1174 Invalidate();
1177 // -----------------------------------------------------------------------
1179 void SvxFontPrevWindow::Init( const SfxItemSet& rSet )
1181 SvxFont& rFont = GetFont();
1182 SvxFont& rCJKFont = GetCJKFont();
1183 SvxFont& rCTLFont = GetCTLFont();
1185 initFont(rFont);
1186 initFont(rCJKFont);
1187 initFont(rCTLFont);
1188 InitSettings( sal_True, sal_True );
1190 sal_uInt16 nWhich;
1191 nWhich = rSet.GetPool()->GetWhich( SID_CHAR_DLG_PREVIEW_STRING );
1192 if( ISITEMSET )
1194 const SfxStringItem& rItem = ( SfxStringItem& ) rSet.Get( nWhich );
1195 OUString aString = rItem.GetValue();
1196 if( !aString.isEmpty() )
1197 SetPreviewText( aString );
1198 else
1199 SetFontNameAsPreviewText();
1202 // Underline
1203 FontUnderline eUnderline;
1204 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_UNDERLINE );
1205 if( ISITEMSET )
1207 const SvxUnderlineItem& rItem = ( SvxUnderlineItem& ) rSet.Get( nWhich );
1208 eUnderline = ( FontUnderline ) rItem.GetValue();
1209 SetTextLineColor( rItem.GetColor() );
1211 else
1212 eUnderline = UNDERLINE_NONE;
1214 rFont.SetUnderline( eUnderline );
1215 rCJKFont.SetUnderline( eUnderline );
1216 rCTLFont.SetUnderline( eUnderline );
1218 // Overline
1219 FontUnderline eOverline;
1220 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_OVERLINE );
1221 if( ISITEMSET )
1223 const SvxOverlineItem& rItem = ( SvxOverlineItem& ) rSet.Get( nWhich );
1224 eOverline = ( FontUnderline ) rItem.GetValue();
1225 SetOverlineColor( rItem.GetColor() );
1227 else
1228 eOverline = UNDERLINE_NONE;
1230 rFont.SetOverline( eOverline );
1231 rCJKFont.SetOverline( eOverline );
1232 rCTLFont.SetOverline( eOverline );
1234 // Strikeout
1235 FontStrikeout eStrikeout;
1236 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_STRIKEOUT );
1237 if( ISITEMSET )
1239 const SvxCrossedOutItem& rItem = ( SvxCrossedOutItem& ) rSet.Get( nWhich );
1240 eStrikeout = ( FontStrikeout ) rItem.GetValue();
1242 else
1243 eStrikeout = STRIKEOUT_NONE;
1245 rFont.SetStrikeout( eStrikeout );
1246 rCJKFont.SetStrikeout( eStrikeout );
1247 rCTLFont.SetStrikeout( eStrikeout );
1249 // WordLineMode
1250 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_WORDLINEMODE );
1251 if( ISITEMSET )
1253 const SvxWordLineModeItem& rItem = ( SvxWordLineModeItem& ) rSet.Get( nWhich );
1254 rFont.SetWordLineMode( rItem.GetValue() );
1255 rCJKFont.SetWordLineMode( rItem.GetValue() );
1256 rCTLFont.SetWordLineMode( rItem.GetValue() );
1259 // Emphasis
1260 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_EMPHASISMARK );
1261 if( ISITEMSET )
1263 const SvxEmphasisMarkItem& rItem = ( SvxEmphasisMarkItem& ) rSet.Get( nWhich );
1264 FontEmphasisMark eMark = rItem.GetEmphasisMark();
1265 rFont.SetEmphasisMark( eMark );
1266 rCJKFont.SetEmphasisMark( eMark );
1267 rCTLFont.SetEmphasisMark( eMark );
1270 // Relief
1271 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_RELIEF );
1272 if( ISITEMSET )
1274 const SvxCharReliefItem& rItem = ( SvxCharReliefItem& ) rSet.Get( nWhich );
1275 FontRelief eFontRelief = ( FontRelief ) rItem.GetValue();
1276 rFont.SetRelief( eFontRelief );
1277 rCJKFont.SetRelief( eFontRelief );
1278 rCTLFont.SetRelief( eFontRelief );
1281 // Effects
1282 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_CASEMAP );
1283 if( ISITEMSET )
1285 const SvxCaseMapItem& rItem = ( SvxCaseMapItem& ) rSet.Get( nWhich );
1286 SvxCaseMap eCaseMap = ( SvxCaseMap ) rItem.GetValue();
1287 rFont.SetCaseMap( eCaseMap );
1288 rCJKFont.SetCaseMap( eCaseMap );
1289 // #i78474# small caps do not exist in CTL fonts
1290 rCTLFont.SetCaseMap( eCaseMap == SVX_CASEMAP_KAPITAELCHEN ? SVX_CASEMAP_NOT_MAPPED : eCaseMap );
1293 // Outline
1294 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_CONTOUR );
1295 if( ISITEMSET )
1297 const SvxContourItem& rItem = ( SvxContourItem& ) rSet.Get( nWhich );
1298 sal_Bool bOutline = rItem.GetValue();
1299 rFont.SetOutline( bOutline );
1300 rCJKFont.SetOutline( bOutline );
1301 rCTLFont.SetOutline( bOutline );
1304 // Shadow
1305 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_SHADOWED );
1306 if( ISITEMSET )
1308 const SvxShadowedItem& rItem = ( SvxShadowedItem& ) rSet.Get( nWhich );
1309 sal_Bool bShadow = rItem.GetValue();
1310 rFont.SetShadow( bShadow );
1311 rCJKFont.SetShadow( bShadow );
1312 rCTLFont.SetShadow( bShadow );
1315 // Background
1316 sal_Bool bTransparent;
1317 nWhich = rSet.GetPool()->GetWhich( pImpl->bPreviewBackgroundToCharacter ? SID_ATTR_BRUSH : SID_ATTR_BRUSH_CHAR );
1318 if( ISITEMSET )
1320 const SvxBrushItem& rBrush = ( SvxBrushItem& ) rSet.Get( nWhich );
1321 const Color& rColor = rBrush.GetColor();
1322 bTransparent = rColor.GetTransparency() > 0;
1323 rFont.SetFillColor( rColor );
1324 rCJKFont.SetFillColor( rColor );
1325 rCTLFont.SetFillColor( rColor );
1327 else
1328 bTransparent = sal_True;
1330 rFont.SetTransparent( bTransparent );
1331 rCJKFont.SetTransparent( bTransparent );
1332 rCTLFont.SetTransparent( bTransparent );
1334 Color aBackCol( COL_TRANSPARENT );
1335 if( !pImpl->bPreviewBackgroundToCharacter )
1337 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_BRUSH );
1338 if( ISITEMSET )
1340 const SvxBrushItem& rBrush = ( SvxBrushItem& ) rSet.Get( nWhich );
1341 if( GPOS_NONE == rBrush.GetGraphicPos() )
1342 aBackCol = rBrush.GetColor();
1345 SetBackColor( aBackCol );
1347 // Font
1348 SetFont( rSet, SID_ATTR_CHAR_FONT, rFont );
1349 SetFont( rSet, SID_ATTR_CHAR_CJK_FONT, rCJKFont );
1350 SetFont( rSet, SID_ATTR_CHAR_CTL_FONT, rCTLFont );
1352 // Style
1353 SetFontStyle( rSet, SID_ATTR_CHAR_POSTURE, SID_ATTR_CHAR_WEIGHT, rFont );
1354 SetFontStyle( rSet, SID_ATTR_CHAR_CJK_POSTURE, SID_ATTR_CHAR_CJK_WEIGHT, rCJKFont );
1355 SetFontStyle( rSet, SID_ATTR_CHAR_CTL_POSTURE, SID_ATTR_CHAR_CTL_WEIGHT, rCTLFont );
1357 // Size
1358 SetFontSize( rSet, SID_ATTR_CHAR_FONTHEIGHT, rFont );
1359 SetFontSize( rSet, SID_ATTR_CHAR_CJK_FONTHEIGHT, rCJKFont );
1360 SetFontSize( rSet, SID_ATTR_CHAR_CTL_FONTHEIGHT, rCTLFont );
1362 // Language
1363 SetFontLang( rSet, SID_ATTR_CHAR_LANGUAGE, rFont );
1364 SetFontLang( rSet, SID_ATTR_CHAR_CJK_LANGUAGE, rCJKFont );
1365 SetFontLang( rSet, SID_ATTR_CHAR_CTL_LANGUAGE, rCTLFont );
1367 // Color
1368 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_COLOR );
1369 if( ISITEMSET )
1371 const SvxColorItem& rItem = ( SvxColorItem& ) rSet.Get( nWhich );
1372 Color aCol( rItem.GetValue() );
1373 rFont.SetColor( aCol );
1374 rCJKFont.SetColor( aCol );
1375 rCTLFont.SetColor( aCol );
1377 AutoCorrectFontColor(); // handle color COL_AUTO
1380 // Kerning
1381 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_KERNING );
1382 if( ISITEMSET )
1384 const SvxKerningItem& rItem = ( SvxKerningItem& ) rSet.Get( nWhich );
1385 short nKern = ( short )
1386 LogicToLogic( rItem.GetValue(), ( MapUnit ) rSet.GetPool()->GetMetric( nWhich ), MAP_TWIP );
1387 rFont.SetFixKerning( nKern );
1388 rCJKFont.SetFixKerning( nKern );
1389 rCTLFont.SetFixKerning( nKern );
1392 // Escapement
1393 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_ESCAPEMENT );
1394 const sal_uInt8 nProp = 100;
1395 short nEsc;
1396 sal_uInt8 nEscProp;
1397 if( ISITEMSET )
1399 const SvxEscapementItem& rItem = ( SvxEscapementItem& ) rSet.Get( nWhich );
1400 nEsc = rItem.GetEsc();
1401 nEscProp = rItem.GetProp();
1403 if( nEsc == DFLT_ESC_AUTO_SUPER )
1404 nEsc = DFLT_ESC_SUPER;
1405 else if( nEsc == DFLT_ESC_AUTO_SUB )
1406 nEsc = DFLT_ESC_SUB;
1408 else
1410 nEsc = 0;
1411 nEscProp = 100;
1414 SetFontEscapement( nProp, nEscProp, nEsc );
1416 // Font width scale
1417 SetFontWidthScale( rSet );
1419 Invalidate();
1422 // -----------------------------------------------------------------------
1425 // -----------------------------------------------------------------------
1427 void SvxFontPrevWindow::SetFont( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont )
1429 sal_uInt16 nWhich = rSet.GetPool()->GetWhich( nSlot );
1430 if( ISITEMSET )
1432 const SvxFontItem& rFontItem = (const SvxFontItem&)rSet.Get(nWhich);
1433 rFont.SetFamily( rFontItem.GetFamily() );
1434 rFont.SetName( rFontItem.GetFamilyName() );
1435 rFont.SetPitch( rFontItem.GetPitch() );
1436 rFont.SetCharSet( rFontItem.GetCharSet() );
1437 rFont.SetStyleName( rFontItem.GetStyleName() );
1441 // -----------------------------------------------------------------------
1443 void SvxFontPrevWindow::SetFontStyle( const SfxItemSet& rSet, sal_uInt16 nPosture, sal_uInt16 nWeight, SvxFont& rFont )
1445 sal_uInt16 nWhich = rSet.GetPool()->GetWhich( nPosture );
1446 if( ISITEMSET )
1448 const SvxPostureItem& rItem = ( SvxPostureItem& ) rSet.Get( nWhich );
1449 rFont.SetItalic( ( FontItalic ) rItem.GetValue() != ITALIC_NONE ? ITALIC_NORMAL : ITALIC_NONE );
1452 nWhich = rSet.GetPool()->GetWhich( nWeight );
1453 if( ISITEMSET )
1455 SvxWeightItem& rItem = ( SvxWeightItem& ) rSet.Get( nWhich );
1456 rFont.SetWeight( ( FontWeight ) rItem.GetValue() != WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL );
1460 // -----------------------------------------------------------------------
1462 void SvxFontPrevWindow::SetFontWidthScale( const SfxItemSet& rSet )
1464 sal_uInt16 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_SCALEWIDTH );
1465 if( ISITEMSET )
1467 const SvxCharScaleWidthItem& rItem = ( SvxCharScaleWidthItem& ) rSet.Get( nWhich );
1469 SetFontWidthScale( rItem.GetValue() );
1473 // -----------------------------------------------------------------------
1474 namespace
1476 // -----------------------------------------------------------------------
1477 void setFontEscapement(SvxFont& _rFont,sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc )
1479 _rFont.SetPropr( nProp );
1480 _rFont.SetProprRel( nEscProp );
1481 _rFont.SetEscapement( nEsc );
1483 // -----------------------------------------------------------------------
1484 // -----------------------------------------------------------------------
1486 // -----------------------------------------------------------------------
1488 void SvxFontPrevWindow::SetFontEscapement( sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc )
1490 setFontEscapement(GetFont(),nProp,nEscProp,nEsc);
1491 setFontEscapement(GetCJKFont(),nProp,nEscProp,nEsc);
1492 setFontEscapement(GetCTLFont(),nProp,nEscProp,nEsc);
1493 Invalidate();
1496 Size SvxFontPrevWindow::GetOptimalSize() const
1498 return m_aInitialSize;
1501 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */