1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
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
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
88 void scaleFontWidth(Font
& _rFont
,const OutputDevice
& rOutDev
,long& _n100PercentFont
)
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
)
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
;
140 Reference
< XBreakIterator
> xBreak
;
141 std::vector
<sal_uIntPtr
> aTextWidth
;
142 std::deque
<sal_Int32
> aScriptChg
;
143 std::vector
<sal_uInt16
> aScriptType
;
147 OUString aScriptText
;
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
;
162 bPreviewBackgroundToCharacter
: 1,
164 bUseFontNameAsText
: 1,
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()
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
246 Reference
< XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
247 xBreak
= BreakIterator::create(xContext
);
249 sal_uInt16 nScript
= xBreak
->getScriptType( aText
, 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
);
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 );
275 aScriptChg
.push_back( nChg
);
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
);
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
)
307 sal_Int32 nStart
= 0;
309 size_t nCnt
= aScriptChg
.size();
312 nEnd
= aScriptChg
[ nIdx
];
313 nScript
= aScriptType
[ nIdx
];
317 nEnd
= aText
.getLength();
318 nScript
= com::sun::star::i18n::ScriptType::LATIN
;
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
).
333 if (nIdx
>= aTextWidth
.size())
335 aTextWidth
[ nIdx
++ ] = nWidth
;
339 case com::sun::star::i18n::ScriptType::ASIAN
:
340 calcFontHeightAnyAscent(pWin
,aCJKFont
,nCJKHeight
,nCJKAscent
);
342 case com::sun::star::i18n::ScriptType::COMPLEX
:
343 calcFontHeightAnyAscent(pWin
,aCTLFont
,nCTLHeight
,nCTLAscent
);
346 calcFontHeightAnyAscent(pWin
,rFont
,nHeight
,nAscent
);
349 if( nEnd
< aText
.getLength() && nIdx
< nCnt
)
352 nEnd
= aScriptChg
[ nIdx
];
353 nScript
= aScriptType
[ nIdx
];
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
;
372 Size
aTxtSize( nTxtWidth
, nHeight
);
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
383 void FontPrevWin_Impl::DrawPrev( OutputDevice
* pWin
, Printer
* _pPrinter
,
384 Point
&rPt
, const SvxFont
&rFont
)
386 Font aOldFont
= _pPrinter
->GetFont();
389 sal_Int32 nStart
= 0;
391 size_t nCnt
= aScriptChg
.size();
394 nEnd
= aScriptChg
[ nIdx
];
395 nScript
= aScriptType
[ nIdx
];
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
)
413 nEnd
= aScriptChg
[ nIdx
];
414 nScript
= aScriptType
[ nIdx
];
420 _pPrinter
->SetFont( aOldFont
);
425 bool FontPrevWin_Impl::SetFontWidthScale( sal_uInt16 nScale
)
427 if( nFontWidthScale
!= nScale
)
429 nFontWidthScale
= nScale
;
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();
461 svtools::ColorConfig aColorConfig
;
462 Color
aTextColor( aColorConfig
.GetColorValue( svtools::FONTCOLOR
).nColor
);
464 if ( IsControlForeground() )
465 aTextColor
= GetControlForeground();
466 SetTextColor( aTextColor
);
471 if ( IsControlBackground() )
472 SetBackground( GetControlBackground() );
474 SetBackground( rStyleSettings
.GetWindowColor() );
481 void SvxFontPrevWindow::Init()
483 pImpl
= new FontPrevWin_Impl
;
484 SfxViewShell
* pSh
= SfxViewShell::Current();
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
)
508 SvxFontPrevWindow::SvxFontPrevWindow(Window
* pParent
, WinBits nStyle
)
509 : Window(pParent
, nStyle
)
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
);
524 SvxFontPrevWindow::~SvxFontPrevWindow()
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
);
557 void SvxFontPrevWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
559 if ( ( rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && ( rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
560 InitSettings( true, true );
562 Window::DataChanged( rDCEvt
);
565 SvxFont
& SvxFontPrevWindow::GetFont()
567 pImpl
->Invalidate100PercentFontWidth(); // because the user might change the size
571 const SvxFont
& SvxFontPrevWindow::GetFont() const
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();
606 void SvxFontPrevWindow::SetColor(const Color
&rColor
)
608 delete pImpl
->pColor
;
609 pImpl
->pColor
= new Color( rColor
);
614 void SvxFontPrevWindow::ResetColor()
616 delete pImpl
->pColor
;
623 void SvxFontPrevWindow::SetBackColor(const Color
&rColor
)
625 delete pImpl
->pBackColor
;
626 pImpl
->pBackColor
= new Color( rColor
);
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
;
648 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
649 const Size
aLogSize( GetOutputSize() );
651 Rectangle
aRect( Point( 0, 0 ), aLogSize
);
653 SetFillColor( rStyleSettings
.GetWindowColor() );
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
);
682 pImpl
->aText
= rFont
.GetName();
684 if (pImpl
->m_bCJKEnabled
)
686 if (!pImpl
->aText
.isEmpty())
688 pImpl
->aText
+= makeRepresentativeTextForFont(ASIAN
, rCJKFont
);
691 if (pImpl
->m_bCTLEnabled
)
693 if (!pImpl
->aText
.isEmpty())
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, " " );
717 pImpl
->aText
= GetText();
719 if ( pImpl
->aText
.getLength() > (TEXT_WIDTH
-1) )
721 sal_Int32 nSpaceIdx
= pImpl
->aText
.indexOf(" ", TEXT_WIDTH
);
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();
747 SetFillColor( *pImpl
->pBackColor
);
749 SetLineColor( aLineCol
);
750 SetFillColor( aFillCol
);
754 Rectangle
aRect( Point( nX
, nY
), aTxtSize
);
755 Color aLineCol
= GetLineColor();
756 Color aFillCol
= GetFillColor();
758 SetFillColor( *pImpl
->pColor
);
760 SetLineColor( aLineCol
);
761 SetFillColor( aFillCol
);
764 long nStdAscent
= pImpl
->nAscent
;
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;
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
);
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
);
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
) )
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
)
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
)
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
)
918 if( GetWhich( rSet
, nSlot
, nWhich
) )
920 nH
= LogicToLogic( ( ( SvxFontHeightItem
& ) rSet
.Get( nWhich
) ).GetHeight(),
921 ( MapUnit
) rSet
.GetPool()->GetMetric( nWhich
),
925 nH
= 240; // as default 12pt
927 rFont
.SetSize( Size( 0, nH
) );
930 void SvxFontPrevWindow::SetFontLang(const SfxItemSet
& rSet
, sal_uInt16 nSlot
, SvxFont
& rFont
)
934 if( GetWhich( rSet
, nSlot
, nWhich
) )
935 nLang
= static_cast<const SvxLanguageItem
&>(rSet
.Get(nWhich
)).GetLanguage();
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
)
952 SvxFont
& rFont
= GetFont();
953 SvxFont
& rCJKFont
= GetCJKFont();
954 SvxFont
& rCTLFont
= GetCTLFont();
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
);
964 SetFontNameAsPreviewText();
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() );
976 eUnderline
= UNDERLINE_NONE
;
978 rFont
.SetUnderline( eUnderline
);
979 rCJKFont
.SetUnderline( eUnderline
);
980 rCTLFont
.SetUnderline( eUnderline
);
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() );
991 eOverline
= UNDERLINE_NONE
;
993 rFont
.SetOverline( eOverline
);
994 rCJKFont
.SetOverline( eOverline
);
995 rCTLFont
.SetOverline( eOverline
);
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();
1005 eStrikeout
= STRIKEOUT_NONE
;
1007 rFont
.SetStrikeout( eStrikeout
);
1008 rCJKFont
.SetStrikeout( eStrikeout
);
1009 rCTLFont
.SetStrikeout( eStrikeout
);
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() );
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
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
);
1146 const sal_uInt8 nProp
= 100;
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
;
1165 SetPrevFontEscapement( rFont
, nProp
, nEscProp
, nEsc
);
1166 SetPrevFontEscapement( rCJKFont
, nProp
, nEscProp
, nEsc
);
1167 SetPrevFontEscapement( rCTLFont
, nProp
, nEscProp
, nEsc
);
1170 if( GetWhich( rSet
, SID_ATTR_CHAR_SCALEWIDTH
, nWhich
) )
1172 const SvxCharScaleWidthItem
&rItem
= ( SvxCharScaleWidthItem
& ) rSet
.Get( nWhich
);
1173 SetFontWidthScale( rItem
.GetValue() );
1181 void SvxFontPrevWindow::Init( const SfxItemSet
& rSet
)
1183 SvxFont
& rFont
= GetFont();
1184 SvxFont
& rCJKFont
= GetCJKFont();
1185 SvxFont
& rCTLFont
= GetCTLFont();
1190 InitSettings( true, true );
1193 nWhich
= rSet
.GetPool()->GetWhich( SID_CHAR_DLG_PREVIEW_STRING
);
1196 const SfxStringItem
& rItem
= ( SfxStringItem
& ) rSet
.Get( nWhich
);
1197 OUString aString
= rItem
.GetValue();
1198 if( !aString
.isEmpty() )
1199 SetPreviewText( aString
);
1201 SetFontNameAsPreviewText();
1205 FontUnderline eUnderline
;
1206 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_CHAR_UNDERLINE
);
1209 const SvxUnderlineItem
& rItem
= ( SvxUnderlineItem
& ) rSet
.Get( nWhich
);
1210 eUnderline
= ( FontUnderline
) rItem
.GetValue();
1211 SetTextLineColor( rItem
.GetColor() );
1214 eUnderline
= UNDERLINE_NONE
;
1216 rFont
.SetUnderline( eUnderline
);
1217 rCJKFont
.SetUnderline( eUnderline
);
1218 rCTLFont
.SetUnderline( eUnderline
);
1221 FontUnderline eOverline
;
1222 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_CHAR_OVERLINE
);
1225 const SvxOverlineItem
& rItem
= ( SvxOverlineItem
& ) rSet
.Get( nWhich
);
1226 eOverline
= ( FontUnderline
) rItem
.GetValue();
1227 SetOverlineColor( rItem
.GetColor() );
1230 eOverline
= UNDERLINE_NONE
;
1232 rFont
.SetOverline( eOverline
);
1233 rCJKFont
.SetOverline( eOverline
);
1234 rCTLFont
.SetOverline( eOverline
);
1237 FontStrikeout eStrikeout
;
1238 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_CHAR_STRIKEOUT
);
1241 const SvxCrossedOutItem
& rItem
= ( SvxCrossedOutItem
& ) rSet
.Get( nWhich
);
1242 eStrikeout
= ( FontStrikeout
) rItem
.GetValue();
1245 eStrikeout
= STRIKEOUT_NONE
;
1247 rFont
.SetStrikeout( eStrikeout
);
1248 rCJKFont
.SetStrikeout( eStrikeout
);
1249 rCTLFont
.SetStrikeout( eStrikeout
);
1252 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_CHAR_WORDLINEMODE
);
1255 const SvxWordLineModeItem
& rItem
= ( SvxWordLineModeItem
& ) rSet
.Get( nWhich
);
1256 rFont
.SetWordLineMode( rItem
.GetValue() );
1257 rCJKFont
.SetWordLineMode( rItem
.GetValue() );
1258 rCTLFont
.SetWordLineMode( rItem
.GetValue() );
1262 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_CHAR_EMPHASISMARK
);
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
);
1273 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_CHAR_RELIEF
);
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
);
1284 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_CHAR_CASEMAP
);
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
);
1296 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_CHAR_CONTOUR
);
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
);
1307 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_CHAR_SHADOWED
);
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
);
1319 nWhich
= rSet
.GetPool()->GetWhich( pImpl
->bPreviewBackgroundToCharacter
? SID_ATTR_BRUSH
: SID_ATTR_BRUSH_CHAR
);
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
);
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
);
1342 const SvxBrushItem
& rBrush
= ( SvxBrushItem
& ) rSet
.Get( nWhich
);
1343 if( GPOS_NONE
== rBrush
.GetGraphicPos() )
1344 aBackCol
= rBrush
.GetColor();
1347 SetBackColor( aBackCol
);
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
);
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
);
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
);
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
);
1370 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_CHAR_COLOR
);
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
1383 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_CHAR_KERNING
);
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
);
1395 nWhich
= rSet
.GetPool()->GetWhich( SID_ATTR_CHAR_ESCAPEMENT
);
1396 const sal_uInt8 nProp
= 100;
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
;
1416 SetFontEscapement( nProp
, nEscProp
, nEsc
);
1419 SetFontWidthScale( rSet
);
1429 void SvxFontPrevWindow::SetFont( const SfxItemSet
& rSet
, sal_uInt16 nSlot
, SvxFont
& rFont
)
1431 sal_uInt16 nWhich
= rSet
.GetPool()->GetWhich( nSlot
);
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
);
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
);
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
);
1469 const SvxCharScaleWidthItem
& rItem
= ( SvxCharScaleWidthItem
& ) rSet
.Get( nWhich
);
1471 SetFontWidthScale( rItem
.GetValue() );
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
);
1498 Size
SvxFontPrevWindow::GetOptimalSize() const
1500 return getPreviewStripSize(this);
1503 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */