From 5e7a0dc80bbdfc9c513c15985a66569938020038 Mon Sep 17 00:00:00 2001 From: Robert DARGAUD Date: Mon, 4 Apr 2011 23:04:56 +0200 Subject: [PATCH 1/2] Conditional formatting with an unlimited rules number --- svx/inc/svx/fntctrl.hxx | 14 +- svx/source/dialog/fntctrl.cxx | 649 +++++++++++++++++++++++++++++++++-------- 2 files changed, 536 insertions(+), 127 deletions(-) mode change 100755 => 100644 svx/inc/svx/fntctrl.hxx mode change 100755 => 100644 svx/source/dialog/fntctrl.cxx diff --git a/svx/inc/svx/fntctrl.hxx b/svx/inc/svx/fntctrl.hxx old mode 100755 new mode 100644 index c9a4c34..bdac4cc --- a/svx/inc/svx/fntctrl.hxx +++ b/svx/inc/svx/fntctrl.hxx @@ -33,6 +33,8 @@ #include #include #include "svx/svxdllapi.h" +#include +#include #include @@ -57,6 +59,8 @@ public: virtual void StateChanged( StateChangedType nStateChange ); virtual void DataChanged( const DataChangedEvent& rDCEvt ); + void Init( const SfxItemSet& rSet ); + // for reasons of efficiency not const SvxFont& GetFont(); const SvxFont& GetFont() const; @@ -70,9 +74,11 @@ public: void ResetColor(); void SetBackColor( const Color& rColor ); void UseResourceText( sal_Bool bUse = sal_True ); + void SetDrawBaseLine( sal_Bool bSet = sal_True ); + void SetPreviewBackgroundToCharacter( sal_Bool bSet = sal_True ); void Paint( const Rectangle& ); - sal_Bool IsTwoLines() const; + sal_Bool IsTwoLines() const; void SetTwoLines(sal_Bool bSet); void SetBrackets(sal_Unicode cStart, sal_Unicode cEnd); @@ -83,6 +89,12 @@ public: void SetPreviewText( const ::rtl::OUString& rString ); void SetFontNameAsPreviewText(); + + void SetFontSize( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont ); + void SetFont( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont ); + void SetFontStyle( const SfxItemSet& rSet, sal_uInt16 nSlotPosture, sal_uInt16 nSlotWeight, SvxFont& rFont ); // posture/weight + void SetFontWidthScale( const SfxItemSet& rSet ); + void SetFontEscapement( sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc ); }; #endif // #ifndef _SVX_FNTCTRL_HXX diff --git a/svx/source/dialog/fntctrl.cxx b/svx/source/dialog/fntctrl.cxx old mode 100755 new mode 100644 index a34cae1..1fc210d --- a/svx/source/dialog/fntctrl.cxx +++ b/svx/source/dialog/fntctrl.cxx @@ -54,6 +54,39 @@ #include #define TEXT_WIDTH 20 +// RMQ voir si tous ces include sont indispensables +#include +#include "editeng/fontitem.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "editeng/flstitem.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// define ---------------------------------------------------------------- + +#define ISITEMSET rSet.GetItemState(nWhich)>=SFX_ITEM_DEFAULT + using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using ::com::sun::star::i18n::XBreakIterator; @@ -113,7 +146,7 @@ class FontPrevWin_Impl SvxFont aFont; Printer* pPrinter; - sal_Bool bDelPrinter; + sal_Bool bDelPrinter; Reference < XBreakIterator > xBreak; SvULongs aTextWidth; @@ -132,11 +165,13 @@ class FontPrevWin_Impl long n100PercentFontWidth; // initial -1 -> not set yet long n100PercentFontWidthCJK; long n100PercentFontWidthCTL; - sal_uInt16 nFontWidthScale; + sal_uInt16 nFontWidthScale; - sal_Bool bSelection : 1, + sal_Bool bSelection : 1, bGetSelection : 1, bUseResText : 1, + bDrawBaseLine : 1, + bPreviewBackgroundToCharacter : 1, bTwoLines : 1, bIsCJKUI : 1, bIsCTLUI : 1, @@ -150,7 +185,7 @@ public: pColor( NULL ), pBackColor( 0 ), nAscent( 0 ), cStartBracket( 0 ), cEndBracket( 0 ), nFontWidthScale( 100 ), bSelection( sal_False ), bGetSelection( sal_False ), bUseResText( sal_False ), - bTwoLines( sal_False ), + bDrawBaseLine( sal_True ), bPreviewBackgroundToCharacter( sal_False ), bTwoLines( sal_False ), bIsCJKUI( sal_False ), bIsCTLUI( sal_False ), bUseFontNameAsText( sal_False ), bTextInited( sal_False ) { @@ -169,9 +204,9 @@ public: Size CalcTextSize( OutputDevice* pWin, OutputDevice* pPrt, SvxFont &rFont ); void DrawPrev( OutputDevice* pWin, Printer* pPrt, Point &rPt, SvxFont &rFont ); - sal_Bool SetFontWidthScale( sal_uInt16 nScaleInPercent ); + sal_Bool SetFontWidthScale( sal_uInt16 nScaleInPercent ); inline void Invalidate100PercentFontWidth(); - inline sal_Bool Is100PercentFontWidthValid() const; + inline sal_Bool Is100PercentFontWidthValid() const; void ScaleFontWidth( const OutputDevice& rOutDev ); // scales rNonCJKFont and aCJKFont depending on nFontWidthScale and // sets the 100%-Font-Widths @@ -532,6 +567,7 @@ void SvxFontPrevWindow::StateChanged( StateChangedType nType ) InitSettings( sal_False, sal_True ); Window::StateChanged( nType ); + Invalidate(); } // ----------------------------------------------------------------------- @@ -646,6 +682,20 @@ void SvxFontPrevWindow::UseResourceText( sal_Bool bUse ) // ----------------------------------------------------------------------- +void SvxFontPrevWindow::SetDrawBaseLine( sal_Bool bSet ) +{ + pImpl->bDrawBaseLine = bSet; +} + +// ----------------------------------------------------------------------- + +void SvxFontPrevWindow::SetPreviewBackgroundToCharacter(sal_Bool bSet) +{ + pImpl->bPreviewBackgroundToCharacter = bSet; +} + +// ----------------------------------------------------------------------- + void SvxFontPrevWindow::Paint( const Rectangle& ) { Printer* pPrinter = pImpl->pPrinter; @@ -653,153 +703,171 @@ void SvxFontPrevWindow::Paint( const Rectangle& ) SvxFont& rCJKFont = pImpl->aCJKFont; // TODO: SvxFont& rCTLFont = pImpl->aCTLFont; - if ( pImpl->bUseResText ) - pImpl->aText = GetText(); - else if ( !pImpl->bSelection && !pImpl->bTextInited ) + if ( !IsEnabled() ) { - SfxViewShell* pSh = SfxViewShell::Current(); + const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); + const Size aLogSize( GetOutputSize() ); - if ( pSh && !pImpl->bGetSelection && !pImpl->bUseFontNameAsText ) - { - pImpl->aText = pSh->GetSelectionText(); - pImpl->bGetSelection = sal_True; - pImpl->bSelection = pImpl->aText.Len() != 0; - - } - - if ( !pImpl->bSelection || pImpl->bUseFontNameAsText ) + Rectangle aRect( Point( 0, 0 ), aLogSize ); + SetLineColor(); + SetFillColor( rStyleSettings.GetWindowColor() ); + DrawRect( aRect ); + } + else + { + if ( pImpl->bUseResText ) + pImpl->aText = GetText(); + else if ( !pImpl->bSelection && !pImpl->bTextInited ) { - pImpl->aText = rFont.GetName(); - if( pImpl->bIsCJKUI ) - pImpl->aText += rCJKFont.GetName(); - //TODO bIsCTLUI - } + SfxViewShell* pSh = SfxViewShell::Current(); - if ( !pImpl->aText.Len() ) - pImpl->aText = GetText(); + if ( pSh && !pImpl->bGetSelection && !pImpl->bUseFontNameAsText ) + { + pImpl->aText = pSh->GetSelectionText(); + pImpl->bGetSelection = sal_True; + pImpl->bSelection = pImpl->aText.Len() != 0; - // remove line feeds and carriage returns from string - bool bNotEmpty = false; - for ( xub_StrLen i = 0; i < pImpl->aText.Len(); ++i ) - { - if ( 0xa == pImpl->aText.GetChar( i ) || - 0xd == pImpl->aText.GetChar( i ) ) - pImpl->aText.SetChar( i, ' ' ); - else - bNotEmpty = true; - } - if ( !bNotEmpty ) - pImpl->aText = GetText(); + } - if ( pImpl->aText.Len() > (TEXT_WIDTH-1) ) - pImpl->aText.Erase( pImpl->aText.Search( sal_Unicode( ' ' ), TEXT_WIDTH ) ); - } + if ( !pImpl->bSelection || pImpl->bUseFontNameAsText ) + { + pImpl->aText = rFont.GetName(); + if( pImpl->bIsCJKUI ) + pImpl->aText += rCJKFont.GetName(); + //TODO bIsCTLUI + } - // calculate text width scaling - pImpl->ScaleFontWidth( *this/*, rFont*/ ); + if ( !pImpl->aText.Len() ) + pImpl->aText = GetText(); - pImpl->CheckScript(); - Size aTxtSize = pImpl->CalcTextSize( this, pPrinter, rFont ); + // remove line feeds and carriage returns from string + bool bNotEmpty = false; + for ( xub_StrLen i = 0; i < pImpl->aText.Len(); ++i ) + { + if ( 0xa == pImpl->aText.GetChar( i ) || + 0xd == pImpl->aText.GetChar( i ) ) + pImpl->aText.SetChar( i, ' ' ); + else + bNotEmpty = true; + } + if ( !bNotEmpty ) + pImpl->aText = GetText(); - const Size aLogSize( GetOutputSize() ); + if ( pImpl->aText.Len() > (TEXT_WIDTH-1) ) + pImpl->aText.Erase( pImpl->aText.Search( sal_Unicode( ' ' ), TEXT_WIDTH ) ); + } - long nX = aLogSize.Width() / 2 - aTxtSize.Width() / 2; - long nY = aLogSize.Height() / 2 - aTxtSize.Height() / 2; + // calculate text width scaling + pImpl->ScaleFontWidth( *this/*, rFont*/ ); - if ( nY + pImpl->nAscent > aLogSize.Height() ) - nY = aLogSize.Height() - pImpl->nAscent; + pImpl->CheckScript(); + Size aTxtSize = pImpl->CalcTextSize( this, pPrinter, rFont ); - if ( pImpl->pBackColor ) - { - Rectangle aRect( Point( 0, 0 ), aLogSize ); - Color aLineCol = GetLineColor(); - Color aFillCol = GetFillColor(); - SetLineColor(); - SetFillColor( *pImpl->pBackColor ); - DrawRect( aRect ); - SetLineColor( aLineCol ); - SetFillColor( aFillCol ); - } - if ( pImpl->pColor ) - { - Rectangle aRect( Point( nX, nY ), aTxtSize ); - Color aLineCol = GetLineColor(); - Color aFillCol = GetFillColor(); - SetLineColor(); - SetFillColor( *pImpl->pColor ); - DrawRect( aRect ); - SetLineColor( aLineCol ); - SetFillColor( aFillCol ); - } + const Size aLogSize( GetOutputSize() ); - long nStdAscent = pImpl->nAscent; - nY += nStdAscent; + long nX = aLogSize.Width() / 2 - aTxtSize.Width() / 2; + long nY = aLogSize.Height() / 2 - aTxtSize.Height() / 2; - if(pImpl->bTwoLines) - { - SvxFont aSmallFont( rFont ); - Size aOldSize = pImpl->aCJKFont.GetSize(); - setFontSize(aSmallFont); - setFontSize(pImpl->aCJKFont); + if ( nY + pImpl->nAscent > aLogSize.Height() ) + nY = aLogSize.Height() - pImpl->nAscent; - long nStartBracketWidth = 0; - long nEndBracketWidth = 0; - long nTextWidth = 0; - if(pImpl->cStartBracket) + if ( pImpl->pBackColor ) { - String sBracket(pImpl->cStartBracket); - nStartBracketWidth = rFont.GetTxtSize( pPrinter, sBracket ).Width(); + Rectangle aRect( Point( 0, 0 ), aLogSize ); + Color aLineCol = GetLineColor(); + Color aFillCol = GetFillColor(); + SetLineColor(); + SetFillColor( *pImpl->pBackColor ); + DrawRect( aRect ); + SetLineColor( aLineCol ); + SetFillColor( aFillCol ); } - if(pImpl->cEndBracket) + if ( pImpl->pColor ) { - String sBracket(pImpl->cEndBracket); - nEndBracketWidth = rFont.GetTxtSize( pPrinter, sBracket ).Width(); + Rectangle aRect( Point( nX, nY ), aTxtSize ); + Color aLineCol = GetLineColor(); + Color aFillCol = GetFillColor(); + SetLineColor(); + SetFillColor( *pImpl->pColor ); + DrawRect( aRect ); + SetLineColor( aLineCol ); + SetFillColor( aFillCol ); } - nTextWidth = pImpl->CalcTextSize( this, pPrinter, aSmallFont ).Width(); - long nResultWidth = nStartBracketWidth; - nResultWidth += nEndBracketWidth; - nResultWidth += nTextWidth; - long _nX = (aLogSize.Width() - nResultWidth) / 2; - DrawLine( Point( 0, nY ), Point( _nX, nY ) ); - DrawLine( Point( _nX + nResultWidth, nY ), Point( aLogSize.Width(), nY ) ); + long nStdAscent = pImpl->nAscent; + nY += nStdAscent; - long nSmallAscent = pImpl->nAscent; - long nOffset = (nStdAscent - nSmallAscent ) / 2; - - if(pImpl->cStartBracket) + if(pImpl->bTwoLines) { - String sBracket(pImpl->cStartBracket); - rFont.DrawPrev( this, pPrinter, Point( _nX, nY - nOffset - 4), sBracket ); - _nX += nStartBracketWidth; - } + SvxFont aSmallFont( rFont ); + Size aOldSize = pImpl->aCJKFont.GetSize(); + setFontSize(aSmallFont); + setFontSize(pImpl->aCJKFont); + + long nStartBracketWidth = 0; + long nEndBracketWidth = 0; + long nTextWidth = 0; + if(pImpl->cStartBracket) + { + String sBracket(pImpl->cStartBracket); + nStartBracketWidth = rFont.GetTxtSize( pPrinter, sBracket ).Width(); + } + if(pImpl->cEndBracket) + { + String sBracket(pImpl->cEndBracket); + nEndBracketWidth = rFont.GetTxtSize( pPrinter, sBracket ).Width(); + } + nTextWidth = pImpl->CalcTextSize( this, pPrinter, aSmallFont ).Width(); + long nResultWidth = nStartBracketWidth; + nResultWidth += nEndBracketWidth; + nResultWidth += nTextWidth; - Point aTmpPoint1( _nX, nY - nSmallAscent - 2 ); - Point aTmpPoint2( _nX, nY ); - pImpl->DrawPrev( this, pPrinter, aTmpPoint1, aSmallFont ); - pImpl->DrawPrev( this, pPrinter, aTmpPoint2, aSmallFont ); + long _nX = (aLogSize.Width() - nResultWidth) / 2; + if ( pImpl->bDrawBaseLine ) + { + DrawLine( Point( 0, nY ), Point( _nX, nY ) ); + DrawLine( Point( _nX + nResultWidth, nY ), Point( aLogSize.Width(), nY ) ); + } - _nX += nTextWidth; - if(pImpl->cEndBracket) - { - Point aTmpPoint( _nX + 1, nY - nOffset - 4); - String sBracket(pImpl->cEndBracket); - rFont.DrawPrev( this, pPrinter, aTmpPoint, sBracket ); - } - pImpl->aCJKFont.SetSize( aOldSize ); - } - else - { - Color aLineCol = GetLineColor(); + long nSmallAscent = pImpl->nAscent; + long nOffset = (nStdAscent - nSmallAscent ) / 2; + + if(pImpl->cStartBracket) + { + String sBracket(pImpl->cStartBracket); + rFont.DrawPrev( this, pPrinter, Point( _nX, nY - nOffset - 4), sBracket ); + _nX += nStartBracketWidth; + } + + Point aTmpPoint1( _nX, nY - nSmallAscent - 2 ); + Point aTmpPoint2( _nX, nY ); + pImpl->DrawPrev( this, pPrinter, aTmpPoint1, aSmallFont ); + pImpl->DrawPrev( this, pPrinter, aTmpPoint2, aSmallFont ); - SetLineColor( rFont.GetColor() ); - DrawLine( Point( 0, nY ), Point( nX, nY ) ); - DrawLine( Point( nX + aTxtSize.Width(), nY ), Point( aLogSize.Width(), nY ) ); + _nX += nTextWidth; + if(pImpl->cEndBracket) + { + Point aTmpPoint( _nX + 1, nY - nOffset - 4); + String sBracket(pImpl->cEndBracket); + rFont.DrawPrev( this, pPrinter, aTmpPoint, sBracket ); + } + pImpl->aCJKFont.SetSize( aOldSize ); + } + else + { + Color aLineCol = GetLineColor(); - SetLineColor( aLineCol ); + SetLineColor( rFont.GetColor() ); + if ( pImpl->bDrawBaseLine ) + { + DrawLine( Point( 0, nY ), Point( nX, nY ) ); + DrawLine( Point( nX + aTxtSize.Width(), nY ), Point( aLogSize.Width(), nY ) ); + } + SetLineColor( aLineCol ); - Point aTmpPoint( nX, nY ); - pImpl->DrawPrev( this, pPrinter, aTmpPoint, rFont ); + Point aTmpPoint( nX, nY ); + pImpl->DrawPrev( this, pPrinter, aTmpPoint, rFont ); + } } } @@ -843,4 +911,333 @@ void SvxFontPrevWindow::AutoCorrectFontColor( void ) pImpl->aCTLFont.SetColor( aFontColor ); } +// ----------------------------------------------------------------------- + +void SvxFontPrevWindow::Init( const SfxItemSet& rSet ) +{ + SvxFont& rFont = GetFont(); + SvxFont& rCJKFont = GetCJKFont(); + SvxFont& rCTLFont = GetCTLFont(); + + initFont(rFont); + initFont(rCJKFont); + initFont(rCTLFont); + InitSettings( sal_True, sal_True ); + + sal_uInt16 nWhich; + nWhich = rSet.GetPool()->GetWhich( SID_CHAR_DLG_PREVIEW_STRING ); + if( ISITEMSET ) + { + const SfxStringItem& rItem = ( SfxStringItem& ) rSet.Get( nWhich ); + ::rtl::OUString aString = rItem.GetValue(); + if( aString.getLength() != 0 ) + SetPreviewText( aString ); + else + SetFontNameAsPreviewText(); + } + + // Underline + FontUnderline eUnderline; + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_UNDERLINE ); + if( ISITEMSET ) + { + const SvxUnderlineItem& rItem = ( SvxUnderlineItem& ) rSet.Get( nWhich ); + eUnderline = ( FontUnderline ) rItem.GetValue(); + SetTextLineColor( rItem.GetColor() ); + } + else + eUnderline = UNDERLINE_NONE; + + rFont.SetUnderline( eUnderline ); + rCJKFont.SetUnderline( eUnderline ); + rCTLFont.SetUnderline( eUnderline ); + + // Overline + FontUnderline eOverline; + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_OVERLINE ); + if( ISITEMSET ) + { + const SvxOverlineItem& rItem = ( SvxOverlineItem& ) rSet.Get( nWhich ); + eOverline = ( FontUnderline ) rItem.GetValue(); + SetOverlineColor( rItem.GetColor() ); + } + else + eOverline = UNDERLINE_NONE; + + rFont.SetOverline( eOverline ); + rCJKFont.SetOverline( eOverline ); + rCTLFont.SetOverline( eOverline ); + + // Strikeout + FontStrikeout eStrikeout; + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_STRIKEOUT ); + if( ISITEMSET ) + { + const SvxCrossedOutItem& rItem = ( SvxCrossedOutItem& ) rSet.Get( nWhich ); + eStrikeout = ( FontStrikeout ) rItem.GetValue(); + } + else + eStrikeout = STRIKEOUT_NONE; + + rFont.SetStrikeout( eStrikeout ); + rCJKFont.SetStrikeout( eStrikeout ); + rCTLFont.SetStrikeout( eStrikeout ); + + // WordLineMode + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_WORDLINEMODE ); + if( ISITEMSET ) + { + const SvxWordLineModeItem& rItem = ( SvxWordLineModeItem& ) rSet.Get( nWhich ); + rFont.SetWordLineMode( rItem.GetValue() ); + rCJKFont.SetWordLineMode( rItem.GetValue() ); + rCTLFont.SetWordLineMode( rItem.GetValue() ); + } + + // Emphasis + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_EMPHASISMARK ); + if( ISITEMSET ) + { + const SvxEmphasisMarkItem& rItem = ( SvxEmphasisMarkItem& ) rSet.Get( nWhich ); + FontEmphasisMark eMark = rItem.GetEmphasisMark(); + rFont.SetEmphasisMark( eMark ); + rCJKFont.SetEmphasisMark( eMark ); + rCTLFont.SetEmphasisMark( eMark ); + } + + // Relief + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_RELIEF ); + if( ISITEMSET ) + { + const SvxCharReliefItem& rItem = ( SvxCharReliefItem& ) rSet.Get( nWhich ); + FontRelief eFontRelief = ( FontRelief ) rItem.GetValue(); + rFont.SetRelief( eFontRelief ); + rCJKFont.SetRelief( eFontRelief ); + rCTLFont.SetRelief( eFontRelief ); + } + + // Effects + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_CASEMAP ); + if( ISITEMSET ) + { + const SvxCaseMapItem& rItem = ( SvxCaseMapItem& ) rSet.Get( nWhich ); + SvxCaseMap eCaseMap = ( SvxCaseMap ) rItem.GetValue(); + rFont.SetCaseMap( eCaseMap ); + rCJKFont.SetCaseMap( eCaseMap ); + // #i78474# small caps do not exist in CTL fonts + rCTLFont.SetCaseMap( eCaseMap == SVX_CASEMAP_KAPITAELCHEN ? SVX_CASEMAP_NOT_MAPPED : eCaseMap ); + } + + // Outline + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_CONTOUR ); + if( ISITEMSET ) + { + const SvxContourItem& rItem = ( SvxContourItem& ) rSet.Get( nWhich ); + sal_Bool bOutline = rItem.GetValue(); + rFont.SetOutline( bOutline ); + rCJKFont.SetOutline( bOutline ); + rCTLFont.SetOutline( bOutline ); + } + + // Shadow + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_SHADOWED ); + if( ISITEMSET ) + { + const SvxShadowedItem& rItem = ( SvxShadowedItem& ) rSet.Get( nWhich ); + sal_Bool bShadow = rItem.GetValue(); + rFont.SetShadow( bShadow ); + rCJKFont.SetShadow( bShadow ); + rCTLFont.SetShadow( bShadow ); + } + + // Background + sal_Bool bTransparent; + nWhich = rSet.GetPool()->GetWhich( pImpl->bPreviewBackgroundToCharacter ? SID_ATTR_BRUSH : SID_ATTR_BRUSH_CHAR ); + if( ISITEMSET ) + { + const SvxBrushItem& rBrush = ( SvxBrushItem& ) rSet.Get( nWhich ); + const Color& rColor = rBrush.GetColor(); + bTransparent = rColor.GetTransparency() > 0; + rFont.SetFillColor( rColor ); + rCJKFont.SetFillColor( rColor ); + rCTLFont.SetFillColor( rColor ); + } + else + bTransparent = sal_True; + + rFont.SetTransparent( bTransparent ); + rCJKFont.SetTransparent( bTransparent ); + rCTLFont.SetTransparent( bTransparent ); + + Color aBackCol( COL_TRANSPARENT ); + if( !pImpl->bPreviewBackgroundToCharacter ) + { + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_BRUSH ); + if( ISITEMSET ) + { + const SvxBrushItem& rBrush = ( SvxBrushItem& ) rSet.Get( nWhich ); + if( GPOS_NONE == rBrush.GetGraphicPos() ) + aBackCol = rBrush.GetColor(); + } + } + SetBackColor( aBackCol ); + + // Font + SetFont( rSet, SID_ATTR_CHAR_FONT, rFont ); + SetFont( rSet, SID_ATTR_CHAR_CJK_FONT, rCJKFont ); + SetFont( rSet, SID_ATTR_CHAR_CTL_FONT, rCTLFont ); + + // Style + SetFontStyle( rSet, SID_ATTR_CHAR_POSTURE, SID_ATTR_CHAR_WEIGHT, rFont ); + SetFontStyle( rSet, SID_ATTR_CHAR_CJK_POSTURE, SID_ATTR_CHAR_CJK_WEIGHT, rCJKFont ); + SetFontStyle( rSet, SID_ATTR_CHAR_CTL_POSTURE, SID_ATTR_CHAR_CTL_WEIGHT, rCTLFont ); + + // Size + SetFontSize( rSet, SID_ATTR_CHAR_FONTHEIGHT, rFont ); + SetFontSize( rSet, SID_ATTR_CHAR_CJK_FONTHEIGHT, rCJKFont ); + SetFontSize( rSet, SID_ATTR_CHAR_CTL_FONTHEIGHT, rCTLFont ); + + // Color + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_COLOR ); + if( ISITEMSET ) + { + const SvxColorItem& rItem = ( SvxColorItem& ) rSet.Get( nWhich ); + Color aCol( rItem.GetValue() ); + rFont.SetColor( aCol ); + rCJKFont.SetColor( aCol ); + rCTLFont.SetColor( aCol ); + + AutoCorrectFontColor(); // handle color COL_AUTO + } + + // Kerning + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_KERNING ); + if( ISITEMSET ) + { + const SvxKerningItem& rItem = ( SvxKerningItem& ) rSet.Get( nWhich ); + short nKern = ( short ) + LogicToLogic( rItem.GetValue(), ( MapUnit ) rSet.GetPool()->GetMetric( nWhich ), MAP_TWIP ); + rFont.SetFixKerning( nKern ); + rCJKFont.SetFixKerning( nKern ); + rCTLFont.SetFixKerning( nKern ); + } + + // Escapement + nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_ESCAPEMENT ); + const sal_uInt8 nProp = 100; + short nEsc; + sal_uInt8 nEscProp; + if( ISITEMSET ) + { + const SvxEscapementItem& rItem = ( SvxEscapementItem& ) rSet.Get( nWhich ); + nEsc = rItem.GetEsc(); + nEscProp = rItem.GetProp(); + + if( nEsc == DFLT_ESC_AUTO_SUPER ) + nEsc = DFLT_ESC_SUPER; + else if( nEsc == DFLT_ESC_AUTO_SUB ) + nEsc = DFLT_ESC_SUB; + } + else + { + nEsc = 0; + nEscProp = 100; + } + + SetFontEscapement( nProp, nEscProp, nEsc ); + + // Font width scale + SetFontWidthScale( rSet ); + + Invalidate(); +} + +// ----------------------------------------------------------------------- + +void SvxFontPrevWindow::SetFontSize( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont ) +{ + sal_uInt16 nWhich = rSet.GetPool()->GetWhich( nSlot ); + long nH; + if( rSet.GetItemState( nWhich ) >= SFX_ITEM_SET ) + { + nH = LogicToLogic( ( ( SvxFontHeightItem& ) rSet.Get( nWhich ) ).GetHeight(), + ( MapUnit ) rSet.GetPool()->GetMetric( nWhich ), + MAP_TWIP ); + } + else + nH = 240; // as default 12pt + + rFont.SetSize( Size( 0, nH ) ); +} + +// ----------------------------------------------------------------------- + +void SvxFontPrevWindow::SetFont( const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont ) +{ + sal_uInt16 nWhich = rSet.GetPool()->GetWhich( nSlot ); + if( ISITEMSET ) + { + const SvxFontItem& rFontItem = ( SvxFontItem& ) rSet.Get( nWhich ); + rFont.SetFamily( rFontItem.GetFamily() ); + rFont.SetName( rFontItem.GetFamilyName() ); + rFont.SetPitch( rFontItem.GetPitch() ); + rFont.SetCharSet( rFontItem.GetCharSet() ); + rFont.SetStyleName( rFontItem.GetStyleName() ); + } +} + +// ----------------------------------------------------------------------- + +void SvxFontPrevWindow::SetFontStyle( const SfxItemSet& rSet, sal_uInt16 nPosture, sal_uInt16 nWeight, SvxFont& rFont ) +{ + sal_uInt16 nWhich = rSet.GetPool()->GetWhich( nPosture ); + if( ISITEMSET ) + { + const SvxPostureItem& rItem = ( SvxPostureItem& ) rSet.Get( nWhich ); + rFont.SetItalic( ( FontItalic ) rItem.GetValue() != ITALIC_NONE ? ITALIC_NORMAL : ITALIC_NONE ); + } + + nWhich = rSet.GetPool()->GetWhich( nWeight ); + if( ISITEMSET ) + { + SvxWeightItem& rItem = ( SvxWeightItem& ) rSet.Get( nWhich ); + rFont.SetWeight( ( FontWeight ) rItem.GetValue() != WEIGHT_NORMAL ? WEIGHT_BOLD : WEIGHT_NORMAL ); + } +} + +// ----------------------------------------------------------------------- + +void SvxFontPrevWindow::SetFontWidthScale( const SfxItemSet& rSet ) +{ + sal_uInt16 nWhich = rSet.GetPool()->GetWhich( SID_ATTR_CHAR_SCALEWIDTH ); + if( ISITEMSET ) + { + const SvxCharScaleWidthItem& rItem = ( SvxCharScaleWidthItem& ) rSet.Get( nWhich ); + + SetFontWidthScale( rItem.GetValue() ); + } +} + +// ----------------------------------------------------------------------- +namespace +{ + // ----------------------------------------------------------------------- + void setFontEscapement(SvxFont& _rFont,sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc ) + { + _rFont.SetPropr( nProp ); + _rFont.SetProprRel( nEscProp ); + _rFont.SetEscapement( nEsc ); + } + // ----------------------------------------------------------------------- + // ----------------------------------------------------------------------- +} +// ----------------------------------------------------------------------- + +void SvxFontPrevWindow::SetFontEscapement( sal_uInt8 nProp, sal_uInt8 nEscProp, short nEsc ) +{ + setFontEscapement(GetFont(),nProp,nEscProp,nEsc); + setFontEscapement(GetCJKFont(),nProp,nEscProp,nEsc); + setFontEscapement(GetCTLFont(),nProp,nEscProp,nEsc); + Invalidate(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- 1.7.1