diff options
author | tagezi <lera.goncharuk@gmail.com> | 2017-11-24 19:55:15 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-12-04 20:40:48 +0100 |
commit | eafc42a2b46e70a0840a870b8c8cce85b32980c1 (patch) | |
tree | b67750a874a3445ca0cfeee63687c2214065554d /sc | |
parent | 0616a5e13e6656a97071b1407912e1043a903407 (diff) |
tdf#39593 deduplicate code in ScOutputData
Change-Id: I98fedf943e2e832d3171a3f2c88acb49acccaa2a
Reviewed-on: https://gerrit.libreoffice.org/45255
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/inc/output.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/view/output2.cxx | 115 |
2 files changed, 41 insertions, 76 deletions
diff --git a/sc/source/ui/inc/output.hxx b/sc/source/ui/inc/output.hxx index e68c92e9c379..a59b3937264b 100644 --- a/sc/source/ui/inc/output.hxx +++ b/sc/source/ui/inc/output.hxx @@ -252,6 +252,8 @@ private: long nEngineHeight, bool bWrapFields ); bool AdjustAreaParamClipRect(OutputAreaParam& rAreaParam); + long SetEngineTextAndGetWidth( DrawEditParam& rParam, const OUString& rSetString, + long& rNeededPixel, long nAddWidthPixels ); public: /** diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx index 3bb430f9883a..8195ad00fab6 100644 --- a/sc/source/ui/view/output2.cxx +++ b/sc/source/ui/view/output2.cxx @@ -2801,6 +2801,22 @@ private: bool mbMetaFile; }; +// Returns needed width in current units; sets rNeededPixel to needed width in pixels +long ScOutputData::SetEngineTextAndGetWidth( DrawEditParam& rParam, const OUString& rSetString, + long& rNeededPixel, long nAddWidthPixels ) +{ + rParam.mpEngine->SetText( rSetString ); + long nEngineWidth = static_cast<long>( rParam.mpEngine->CalcTextWidth() ); + if ( rParam.mbPixelToLogic ) + rNeededPixel = mpRefDevice->LogicToPixel( Size( nEngineWidth, 0 ) ).Width(); + else + rNeededPixel = nEngineWidth; + + rNeededPixel += nAddWidthPixels; + + return nEngineWidth; +} + void ScOutputData::DrawEditStandard(DrawEditParam& rParam) { OSL_ASSERT(rParam.meOrient == SvxCellOrientation::Standard); @@ -2808,7 +2824,6 @@ void ScOutputData::DrawEditStandard(DrawEditParam& rParam) Size aRefOne = mpRefDevice->PixelToLogic(Size(1,1)); - bool bHidden = false; bool bRepeat = (rParam.meHorJustAttr == SvxCellHorJustify::Repeat && !rParam.mbBreak); bool bShrink = !rParam.mbBreak && !bRepeat && lcl_GetBoolValue(*rParam.mpPattern, ATTR_SHRINKTOFIT, rParam.mpCondSet); long nAttrRotate = lcl_GetValue<SfxInt32Item, long>(*rParam.mpPattern, ATTR_ROTATE_VALUE, rParam.mpCondSet); @@ -2831,12 +2846,9 @@ void ScOutputData::DrawEditStandard(DrawEditParam& rParam) { //! set flag to find the cell in DrawRotated again ? //! (or flag already set during DrawBackground, then no query here) - bHidden = true; // rotated is outputted separately + return; // rotated is outputted separately } - if (bHidden) - return; - SvxCellHorJustify eOutHorJust = rParam.meHorJustContext; //! mirror margin values for RTL? @@ -2951,11 +2963,9 @@ void ScOutputData::DrawEditStandard(DrawEditParam& rParam) { // "repeat" is handled with unformatted text (for performance reasons) OUString aCellStr = rParam.mpEngine->GetText(); - rParam.mpEngine->SetText( aCellStr ); - long nRepeatSize = (long) rParam.mpEngine->CalcTextWidth(); - if (rParam.mbPixelToLogic) - nRepeatSize = mpRefDevice->LogicToPixel(Size(nRepeatSize,0)).Width(); + long nRepeatSize = 0; + SetEngineTextAndGetWidth( rParam, aCellStr, nRepeatSize, 0 ); if ( pFmtDevice != mpRefDevice ) ++nRepeatSize; if ( nRepeatSize > 0 ) @@ -2966,29 +2976,20 @@ void ScOutputData::DrawEditStandard(DrawEditParam& rParam) OUString aRepeated = aCellStr; for ( long nRepeat = 1; nRepeat < nRepeatCount; nRepeat++ ) aRepeated += aCellStr; - rParam.mpEngine->SetText( aRepeated ); + + nEngineWidth = SetEngineTextAndGetWidth( rParam, aRepeated, + nNeededPixel, (nLeftM + nRightM ) ); nEngineHeight = rParam.mpEngine->GetTextHeight(); - nEngineWidth = (long) rParam.mpEngine->CalcTextWidth(); - if (rParam.mbPixelToLogic) - nNeededPixel = mpRefDevice->LogicToPixel(Size(nEngineWidth,0)).Width(); - else - nNeededPixel = nEngineWidth; - nNeededPixel += nLeftM + nRightM; } } } } + if ( rParam.mbCellIsValue && ( aAreaParam.mbLeftClip || aAreaParam.mbRightClip ) ) { - rParam.mpEngine->SetText(OUString("###")); - nEngineWidth = (long) rParam.mpEngine->CalcTextWidth(); - if (rParam.mbPixelToLogic) - nNeededPixel = mpRefDevice->LogicToPixel(Size(nEngineWidth,0)).Width(); - else - nNeededPixel = nEngineWidth; - nNeededPixel += nLeftM + nRightM; + nEngineWidth = SetEngineTextAndGetWidth( rParam, "###", nNeededPixel, ( nLeftM + nRightM ) ); // No clip marks if "###" doesn't fit (same as in DrawStrings) } @@ -3334,11 +3335,9 @@ void ScOutputData::DrawEditBottomTop(DrawEditParam& rParam) { // "repeat" is handled with unformatted text (for performance reasons) OUString aCellStr = rParam.mpEngine->GetText(); - rParam.mpEngine->SetText( aCellStr ); - long nRepeatSize = static_cast<long>( rParam.mpEngine->CalcTextWidth() ); - if (rParam.mbPixelToLogic) - nRepeatSize = mpRefDevice->LogicToPixel(Size(nRepeatSize,0)).Width(); + long nRepeatSize = 0; + SetEngineTextAndGetWidth( rParam, aCellStr, nRepeatSize, 0 ); if ( pFmtDevice != mpRefDevice ) ++nRepeatSize; if ( nRepeatSize > 0 ) @@ -3349,29 +3348,18 @@ void ScOutputData::DrawEditBottomTop(DrawEditParam& rParam) OUString aRepeated = aCellStr; for ( long nRepeat = 1; nRepeat < nRepeatCount; nRepeat++ ) aRepeated += aCellStr; - rParam.mpEngine->SetText( aRepeated ); + + nEngineWidth = SetEngineTextAndGetWidth( rParam, aRepeated, + nNeededPixel, (nLeftM + nRightM ) ); nEngineHeight = rParam.mpEngine->GetTextHeight(); - nEngineWidth = static_cast<long>( rParam.mpEngine->CalcTextWidth() ); - if (rParam.mbPixelToLogic) - nNeededPixel = mpRefDevice->LogicToPixel(Size(nEngineWidth,0)).Width(); - else - nNeededPixel = nEngineWidth; - nNeededPixel += nLeftM + nRightM; } } } } - if ( rParam.mbCellIsValue && ( aAreaParam.mbLeftClip || aAreaParam.mbRightClip ) ) { - rParam.mpEngine->SetText(OUString("###")); - nEngineWidth = (long) rParam.mpEngine->CalcTextWidth(); - if (rParam.mbPixelToLogic) - nNeededPixel = mpRefDevice->LogicToPixel(Size(nEngineWidth,0)).Width(); - else - nNeededPixel = nEngineWidth; - nNeededPixel += nLeftM + nRightM; + nEngineWidth = SetEngineTextAndGetWidth( rParam, "###", nNeededPixel, ( nLeftM + nRightM ) ); // No clip marks if "###" doesn't fit (same as in DrawStrings) } @@ -3591,11 +3579,10 @@ void ScOutputData::DrawEditTopBottom(DrawEditParam& rParam) { // "repeat" is handled with unformatted text (for performance reasons) OUString aCellStr = rParam.mpEngine->GetText(); - rParam.mpEngine->SetText( aCellStr ); - long nRepeatSize = static_cast<long>( rParam.mpEngine->CalcTextWidth() ); - if (rParam.mbPixelToLogic) - nRepeatSize = mpRefDevice->LogicToPixel(Size(nRepeatSize,0)).Width(); + long nRepeatSize = 0; + SetEngineTextAndGetWidth( rParam, aCellStr, nRepeatSize, 0 ); + if ( pFmtDevice != mpRefDevice ) ++nRepeatSize; if ( nRepeatSize > 0 ) @@ -3606,29 +3593,18 @@ void ScOutputData::DrawEditTopBottom(DrawEditParam& rParam) OUString aRepeated = aCellStr; for ( long nRepeat = 1; nRepeat < nRepeatCount; nRepeat++ ) aRepeated += aCellStr; - rParam.mpEngine->SetText( aRepeated ); + + nEngineWidth = SetEngineTextAndGetWidth( rParam, aRepeated, + nNeededPixel, (nLeftM + nRightM ) ); nEngineHeight = rParam.mpEngine->GetTextHeight(); - nEngineWidth = static_cast<long>( rParam.mpEngine->CalcTextWidth() ); - if (rParam.mbPixelToLogic) - nNeededPixel = mpRefDevice->LogicToPixel(Size(nEngineWidth,0)).Width(); - else - nNeededPixel = nEngineWidth; - nNeededPixel += nLeftM + nRightM; } } } } - if ( rParam.mbCellIsValue && ( aAreaParam.mbLeftClip || aAreaParam.mbRightClip ) ) { - rParam.mpEngine->SetText(OUString("###")); - nEngineWidth = static_cast<long>( rParam.mpEngine->CalcTextWidth() ); - if (rParam.mbPixelToLogic) - nNeededPixel = mpRefDevice->LogicToPixel(Size(nEngineWidth,0)).Width(); - else - nNeededPixel = nEngineWidth; - nNeededPixel += nLeftM + nRightM; + nEngineWidth = SetEngineTextAndGetWidth( rParam, "###", nNeededPixel, ( nLeftM + nRightM ) ); // No clip marks if "###" doesn't fit (same as in DrawStrings) } @@ -3851,13 +3827,7 @@ void ScOutputData::DrawEditStacked(DrawEditParam& rParam) if ( rParam.mbCellIsValue && ( aAreaParam.mbLeftClip || aAreaParam.mbRightClip ) ) { - rParam.mpEngine->SetText(OUString("###")); - nEngineWidth = (long) rParam.mpEngine->CalcTextWidth(); - if (rParam.mbPixelToLogic) - nNeededPixel = mpRefDevice->LogicToPixel(Size(nEngineWidth,0)).Width(); - else - nNeededPixel = nEngineWidth; - nNeededPixel += nLeftM + nRightM; + nEngineWidth = SetEngineTextAndGetWidth( rParam, "###", nNeededPixel, ( nLeftM + nRightM ) ); // No clip marks if "###" doesn't fit (same as in DrawStrings) } @@ -4156,16 +4126,9 @@ void ScOutputData::DrawEditAsianVertical(DrawEditParam& rParam) nEngineWidth, nEngineHeight, nNeededPixel, aAreaParam.mbLeftClip, aAreaParam.mbRightClip ); } - if ( rParam.mbCellIsValue && ( aAreaParam.mbLeftClip || aAreaParam.mbRightClip ) ) { - rParam.mpEngine->SetText(OUString("###")); - nEngineWidth = (long) rParam.mpEngine->CalcTextWidth(); - if (rParam.mbPixelToLogic) - nNeededPixel = mpRefDevice->LogicToPixel(Size(nEngineWidth,0)).Width(); - else - nNeededPixel = nEngineWidth; - nNeededPixel += nLeftM + nRightM; + nEngineWidth = SetEngineTextAndGetWidth( rParam, "###", nNeededPixel, ( nLeftM + nRightM ) ); // No clip marks if "###" doesn't fit (same as in DrawStrings) } |