summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-05-04 19:54:37 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-05-04 20:18:40 +0200
commita9f46b72df15c3540044a4441b926a1de9df5d2f (patch)
treedd8b43432e114779535227c2a5b7bf19c420ac4a /editeng
parentf5f5d7476885fe6107cb9f39504078e833bfb27d (diff)
Unify some code managing coordinated depending on text direction
Change-Id: I12163e83a6a4d4e7cb85eed690b787c47ee2e7e5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115107 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/editeng/impedit.hxx11
-rw-r--r--editeng/source/editeng/impedit3.cxx319
2 files changed, 128 insertions, 202 deletions
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx
index 21de40ed4f54..473856281e3c 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -761,6 +761,17 @@ private:
void SetValidPaperSize( const Size& rSz );
+ tools::Long getXDirectionAware(const Point& pt) const;
+ tools::Long getYDirectionAware(const Point& pt) const;
+ tools::Long getWidthDirectionAware(const Size& sz) const;
+ tools::Long getHeightDirectionAware(const Size& sz) const;
+ void adjustXDirectionAware(Point& pt, tools::Long x) const;
+ void adjustYDirectionAware(Point& pt, tools::Long y) const;
+ void setXDirectionAware(Point& pt, tools::Long x) const;
+ void setYDirectionAware(Point& pt, tools::Long y) const;
+ bool isYOverflowDirectionAware(const Point& pt, const tools::Rectangle& rectMax) const;
+ bool isXOverflowDirectionAware(const Point& pt, const tools::Rectangle& rectMax) const;
+
css::uno::Reference < css::i18n::XBreakIterator > const & ImplGetBreakIterator() const;
css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > const & ImplGetInputSequenceChecker() const;
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
index b5a1fe828cf3..6c3933c0ca54 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -414,7 +414,7 @@ void ImpEditEngine::FormatDoc()
if ( aInvalidRect.IsEmpty() )
{
// For Paperwidth 0 (AutoPageSize) it would otherwise be Empty()...
- tools::Long nWidth = std::max( tools::Long(1), ( !IsVertical() ? aPaperSize.Width() : aPaperSize.Height() ) );
+ tools::Long nWidth = std::max(tools::Long(1), getWidthDirectionAware(aPaperSize));
Range aInvRange( GetInvalidYOffsets( &rParaPortion ) );
aInvalidRect = tools::Rectangle( Point( 0, nY+aInvRange.Min() ),
Size( nWidth, aInvRange.Len() ) );
@@ -447,7 +447,7 @@ void ImpEditEngine::FormatDoc()
aInvalidRect.SetTop( 0 );
// Left and Right are not evaluated, are however set due to IsEmpty.
aInvalidRect.SetLeft( 0 );
- aInvalidRect.SetRight( !IsVertical() ? aPaperSize.Width() : aPaperSize.Height() );
+ aInvalidRect.SetRight(getWidthDirectionAware(aPaperSize));
}
}
@@ -797,7 +797,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
// If PaperSize == long_max, one cannot take away any negative
// first line indent. (Overflow)
if ( ( nMaxLineWidth < 0 ) && ( nStartX < 0 ) )
- nMaxLineWidth = ( !IsVertical() ? aPaperSize.Width() : aPaperSize.Height() ) - GetXValue( rLRItem.GetRight() );
+ nMaxLineWidth = getWidthDirectionAware(aPaperSize) - GetXValue(rLRItem.GetRight());
// If still less than 0, it may be just the right edge.
if ( nMaxLineWidth <= 0 )
@@ -885,7 +885,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
nTextExtraYOffset += std::max( static_cast<tools::Long>(nTextLineHeight / 10), tools::Long(1) );
if ( ( nTextY + nTextExtraYOffset ) > GetTextRanger()->GetBoundRect().Bottom() )
{
- nXWidth = !IsVertical() ? GetPaperSize().Width() : GetPaperSize().Height();
+ nXWidth = getWidthDirectionAware(GetPaperSize());
if ( !nXWidth ) // AutoPaperSize
nXWidth = 0x7FFFFFFF;
}
@@ -1468,7 +1468,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY )
// has to be used for the Alignment. If it does not fit or if it
// will change the paper width, it will be formatted again for
// Justification! = LEFT anyway.
- tools::Long nMaxLineWidthFix = ( !IsVertical() ? aPaperSize.Width() : aPaperSize.Height() )
+ tools::Long nMaxLineWidthFix = getWidthDirectionAware(aPaperSize)
- GetXValue( rLRItem.GetRight() ) - nStartX;
if ( aTextSize.Width() < nMaxLineWidthFix )
nMaxLineWidth = nMaxLineWidthFix;
@@ -1725,7 +1725,7 @@ void ImpEditEngine::CreateAndInsertEmptyLine( ParaPortion* pParaPortion )
{
sal_Int32 nPara = GetParaPortions().GetPos( pParaPortion );
SvxAdjust eJustification = GetJustification( nPara );
- tools::Long nMaxLineWidth = !IsVertical() ? aPaperSize.Width() : aPaperSize.Height();
+ tools::Long nMaxLineWidth = getWidthDirectionAware(aPaperSize);
nMaxLineWidth -= GetXValue( rLRItem.GetRight() );
if ( nMaxLineWidth < 0 )
nMaxLineWidth = 1;
@@ -2948,6 +2948,86 @@ void ImpEditEngine::RecalcFormatterFontMetrics( FormatterFontMetric& rCurMetrics
}
}
+tools::Long ImpEditEngine::getXDirectionAware(const Point& pt) const
+{
+ if (!IsVertical())
+ return pt.X();
+ else
+ return pt.Y();
+}
+
+tools::Long ImpEditEngine::getYDirectionAware(const Point& pt) const
+{
+ if (!IsVertical())
+ return pt.Y();
+ else
+ return pt.X();
+}
+
+tools::Long ImpEditEngine::getWidthDirectionAware(const Size& sz) const
+{
+ return !IsVertical() ? sz.Width() : sz.Height();
+}
+
+tools::Long ImpEditEngine::getHeightDirectionAware(const Size& sz) const
+{
+ return !IsVertical() ? sz.Height() : sz.Width();
+}
+
+void ImpEditEngine::adjustXDirectionAware(Point& pt, tools::Long x) const
+{
+ if (!IsVertical())
+ pt.AdjustX(x);
+ else
+ pt.AdjustY(IsTopToBottom() ? x : -x);
+}
+
+void ImpEditEngine::adjustYDirectionAware(Point& pt, tools::Long y) const
+{
+ if (!IsVertical())
+ pt.AdjustY(y);
+ else
+ pt.AdjustX(IsTopToBottom() ? -y : y);
+}
+
+void ImpEditEngine::setXDirectionAware(Point& pt, tools::Long x) const
+{
+ if (!IsVertical())
+ pt.setX(x);
+ else
+ pt.setY(x);
+}
+
+void ImpEditEngine::setYDirectionAware(Point& pt, tools::Long y) const
+{
+ if (!IsVertical())
+ pt.setY(y);
+ else
+ pt.setX(y);
+}
+
+bool ImpEditEngine::isYOverflowDirectionAware(const Point& pt, const tools::Rectangle& rectMax) const
+{
+ if (!IsVertical())
+ return pt.Y() >= rectMax.Bottom();
+
+ if (IsTopToBottom())
+ return pt.X() <= rectMax.Left();
+ else
+ return pt.X() >= rectMax.Right();
+}
+
+bool ImpEditEngine::isXOverflowDirectionAware(const Point& pt, const tools::Rectangle& rectMax) const
+{
+ if (!IsVertical())
+ return pt.X() > rectMax.Right();
+
+ if (IsTopToBottom())
+ return pt.Y() > rectMax.Bottom();
+ else
+ return pt.Y() < rectMax.Top();
+}
+
void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Point aStartPos, bool bStripOnly, Degree10 nOrientation )
{
if ( !GetUpdateMode() && !bStripOnly )
@@ -3013,15 +3093,7 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
bool bEndOfParagraphWritten(false);
- if ( !IsVertical() )
- aStartPos.AdjustY(rPortion.GetFirstLineOffset() );
- else
- {
- if( IsTopToBottom() )
- aStartPos.AdjustX( -(rPortion.GetFirstLineOffset()) );
- else
- aStartPos.AdjustX(rPortion.GetFirstLineOffset() );
- }
+ adjustYDirectionAware(aStartPos, rPortion.GetFirstLineOffset());
const Point aParaStart( aStartPos );
@@ -3036,33 +3108,11 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
assert( pLine && "NULL-Pointer in the line iterator in UpdateViews" );
sal_Int32 nIndex = pLine->GetStart();
aTmpPos = aStartPos;
- if ( !IsVertical() )
- {
- aTmpPos.AdjustX(pLine->GetStartPosX() );
- aTmpPos.AdjustY(pLine->GetMaxAscent() );
- aStartPos.AdjustY(pLine->GetHeight() );
- if (nLine != nLastLine)
- aStartPos.AdjustY(nVertLineSpacing );
- }
- else
- {
- if ( IsTopToBottom() )
- {
- aTmpPos.AdjustY(pLine->GetStartPosX() );
- aTmpPos.AdjustX( -(pLine->GetMaxAscent()) );
- aStartPos.AdjustX( -(pLine->GetHeight()) );
- if (nLine != nLastLine)
- aStartPos.AdjustX( -nVertLineSpacing );
- }
- else
- {
- aTmpPos.AdjustY( -(pLine->GetStartPosX()) );
- aTmpPos.AdjustX(pLine->GetMaxAscent() );
- aStartPos.AdjustX(pLine->GetHeight() );
- if (nLine != nLastLine)
- aStartPos.AdjustX(nVertLineSpacing );
- }
- }
+ adjustXDirectionAware(aTmpPos, pLine->GetStartPosX());
+ adjustYDirectionAware(aTmpPos, pLine->GetMaxAscent());
+ adjustYDirectionAware(aStartPos, pLine->GetHeight());
+ if (nLine != nLastLine)
+ adjustYDirectionAware(aStartPos, nVertLineSpacing);
if ( ( !IsVertical() && ( aStartPos.Y() > aClipRect.Top() ) )
|| ( IsVertical() && IsTopToBottom() && aStartPos.X() < aClipRect.Right() )
@@ -3095,27 +3145,10 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
const TextPortion& rTextPortion = rPortion.GetTextPortions()[nPortion];
const tools::Long nPortionXOffset = GetPortionXOffset( &rPortion, pLine, nPortion );
- if ( !IsVertical() )
- {
- aTmpPos.setX( aStartPos.X() + nPortionXOffset );
- if ( aTmpPos.X() > aClipRect.Right() )
- break; // No further output in line necessary
- }
- else
- {
- if( IsTopToBottom() )
- {
- aTmpPos.setY( aStartPos.Y() + nPortionXOffset );
- if ( aTmpPos.Y() > aClipRect.Bottom() )
- break; // No further output in line necessary
- }
- else
- {
- aTmpPos.setY( aStartPos.Y() - nPortionXOffset );
- if (aTmpPos.Y() < aClipRect.Top())
- break; // No further output in line necessary
- }
- }
+ setXDirectionAware(aTmpPos, getXDirectionAware(aParaStart));
+ adjustXDirectionAware(aTmpPos, nPortionXOffset);
+ if (isXOverflowDirectionAware(aTmpPos, aClipRect))
+ break; // No further output in line necessary
switch ( rTextPortion.GetKind() )
{
@@ -3203,44 +3236,12 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
const tools::Long nAdvanceY = -pLine->GetMaxAscent();
Point aTopLeftRectPos( aTmpPos );
- if ( !IsVertical() )
- {
- aTopLeftRectPos.AdjustX(nAdvanceX );
- aTopLeftRectPos.AdjustY(nAdvanceY );
- }
- else
- {
- if( IsTopToBottom() )
- {
- aTopLeftRectPos.AdjustY( -nAdvanceX );
- aTopLeftRectPos.AdjustX(nAdvanceY );
- }
- else
- {
- aTopLeftRectPos.AdjustY(nAdvanceX );
- aTopLeftRectPos.AdjustX( -nAdvanceY );
- }
- }
+ adjustXDirectionAware(aTopLeftRectPos, nAdvanceX);
+ adjustYDirectionAware(aTopLeftRectPos, nAdvanceY);
Point aBottomRightRectPos( aTopLeftRectPos );
- if ( !IsVertical() )
- {
- aBottomRightRectPos.AdjustX(2 * nHalfBlankWidth );
- aBottomRightRectPos.AdjustY(pLine->GetHeight() );
- }
- else
- {
- if (IsTopToBottom())
- {
- aBottomRightRectPos.AdjustX(pLine->GetHeight() );
- aBottomRightRectPos.AdjustY( -(2 * nHalfBlankWidth) );
- }
- else
- {
- aBottomRightRectPos.AdjustX( -(pLine->GetHeight()) );
- aBottomRightRectPos.AdjustY(2 * nHalfBlankWidth );
- }
- }
+ adjustXDirectionAware(aBottomRightRectPos, 2 * nHalfBlankWidth);
+ adjustYDirectionAware(aBottomRightRectPos, pLine->GetHeight());
pOutDev->Push( PushFlags::FILLCOLOR );
pOutDev->Push( PushFlags::LINECOLOR );
@@ -3266,17 +3267,8 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
const Size aSlashSize = aTmpFont.QuickGetTextSize( pOutDev, aSlash, 0, 1 );
Point aSlashPos( aTmpPos );
const tools::Long nAddX = nHalfBlankWidth - aSlashSize.Width() / 2;
- if ( !IsVertical() )
- {
- aSlashPos.setX( aTopLeftRectPos.X() + nAddX );
- }
- else
- {
- if (IsTopToBottom())
- aSlashPos.setY( aTopLeftRectPos.Y() + nAddX );
- else
- aSlashPos.setY( aTopLeftRectPos.Y() - nAddX );
- }
+ setXDirectionAware(aSlashPos, getXDirectionAware(aTopLeftRectPos));
+ adjustXDirectionAware(aSlashPos, nAddX);
aTmpFont.QuickDrawText( pOutDev, aSlashPos, aSlash, 0, 1 );
@@ -3320,24 +3312,8 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
// what will lead to a compressed look with multiple lines
const sal_uInt16 nMaxAscent(pLine->GetMaxAscent());
- if ( !IsVertical() )
- {
- aStartPos.AdjustY(nMaxAscent );
- aTmpPos.AdjustY(nMaxAscent );
- }
- else
- {
- if (IsTopToBottom())
- {
- aTmpPos.AdjustX( -nMaxAscent );
- aStartPos.AdjustX( -nMaxAscent );
- }
- else
- {
- aTmpPos.AdjustX(nMaxAscent );
- aStartPos.AdjustX(nMaxAscent );
- }
- }
+ adjustYDirectionAware(aStartPos, nMaxAscent);
+ adjustYDirectionAware(aTmpPos, nMaxAscent);
}
std::vector< sal_Int32 >::iterator curIt = itSubLines;
++itSubLines;
@@ -3504,15 +3480,7 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
if ( aTmpFont.GetEscapement() )
{
tools::Long nDiff = aTmpFont.GetFontSize().Height() * aTmpFont.GetEscapement() / 100L;
- if ( !IsVertical() )
- aOutPos.AdjustY( -nDiff );
- else
- {
- if (IsTopToBottom())
- aOutPos.AdjustX(nDiff );
- else
- aOutPos.AdjustX( -nDiff );
- }
+ adjustYDirectionAware(aOutPos, -nDiff);
aRedLineTmpPos = aOutPos;
aTmpFont.SetEscapement( 0 );
}
@@ -3639,13 +3607,7 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
if( _nEsc )
{
tools::Long nShift = (_nEsc * aTmpFont.GetFontSize().Height()) / 100L;
- if( !IsVertical() )
- aRedLineTmpPos.AdjustY( -nShift );
- else
- if (IsTopToBottom())
- aRedLineTmpPos.AdjustX(nShift );
- else
- aRedLineTmpPos.AdjustX( -nShift );
+ adjustYDirectionAware(aRedLineTmpPos, -nShift);
}
}
Color aOldColor( pOutDev->GetLineColor() );
@@ -3759,23 +3721,11 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
if ( ( nLine != nLastLine ) && !aStatus.IsOutliner() )
{
- if ( !IsVertical() )
- aStartPos.AdjustY(nSBL );
- else
- {
- if( IsTopToBottom() )
- aStartPos.AdjustX( -nSBL );
- else
- aStartPos.AdjustX(nSBL );
- }
+ adjustYDirectionAware(aStartPos, nSBL);
}
// no more visible actions?
- if ( !IsVertical() && ( aStartPos.Y() >= aClipRect.Bottom() ) )
- break;
- else if ( IsVertical() && IsTopToBottom() && ( aStartPos.X() <= aClipRect.Left() ) )
- break;
- else if (IsVertical() && !IsTopToBottom() && (aStartPos.X() >= aClipRect.Right()))
+ if (isYOverflowDirectionAware(aStartPos, aClipRect))
break;
}
@@ -3783,15 +3733,7 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
{
const SvxULSpaceItem& rULItem = rPortion.GetNode()->GetContentAttribs().GetItem( EE_PARA_ULSPACE );
tools::Long nUL = GetYValue( rULItem.GetLower() );
- if ( !IsVertical() )
- aStartPos.AdjustY(nUL );
- else
- {
- if (IsTopToBottom())
- aStartPos.AdjustX( -nUL );
- else
- aStartPos.AdjustX(nUL );
- }
+ adjustYDirectionAware(aStartPos, nUL);
}
// #108052# Safer way for #i108052# and #i118881#: If for the current ParaPortion
@@ -3817,26 +3759,14 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
}
else
{
- if ( !IsVertical() )
- aStartPos.AdjustY(nParaHeight );
- else
- {
- if (IsTopToBottom())
- aStartPos.AdjustX( -nParaHeight );
- else
- aStartPos.AdjustX(nParaHeight );
- }
+ adjustYDirectionAware(aStartPos, nParaHeight);
}
if ( pPDFExtOutDevData )
pPDFExtOutDevData->EndStructureElement();
// no more visible actions?
- if ( !IsVertical() && ( aStartPos.Y() > aClipRect.Bottom() ) )
- break;
- if ( IsVertical() && IsTopToBottom() && ( aStartPos.X() < aClipRect.Left() ) )
- break;
- if (IsVertical() && !IsTopToBottom() && ( aStartPos.X() > aClipRect.Right() ) )
+ if (isYOverflowDirectionAware(aStartPos, aClipRect))
break;
}
}
@@ -3856,26 +3786,16 @@ void ImpEditEngine::Paint( ImpEditView* pView, const tools::Rectangle& rRect, Ou
Point aStartPos;
if ( !IsVertical() )
- {
aStartPos = pView->GetOutputArea().TopLeft();
- aStartPos.AdjustX( -(pView->GetVisDocLeft()) );
- aStartPos.AdjustY( -(pView->GetVisDocTop()) );
- }
else
{
if( IsTopToBottom() )
- {
aStartPos = pView->GetOutputArea().TopRight();
- aStartPos.AdjustX(pView->GetVisDocTop() );
- aStartPos.AdjustY( -(pView->GetVisDocLeft()) );
- }
else
- {
aStartPos = pView->GetOutputArea().BottomLeft();
- aStartPos.AdjustX( -(pView->GetVisDocTop()) );
- aStartPos.AdjustY(pView->GetVisDocLeft() );
- }
}
+ adjustXDirectionAware(aStartPos, -(pView->GetVisDocLeft()));
+ adjustYDirectionAware(aStartPos, -(pView->GetVisDocTop()));
// If Doc-width < Output Area,Width and not wrapped fields,
// the fields usually protrude if > line.
@@ -4151,19 +4071,14 @@ tools::Long ImpEditEngine::CalcVertLineSpacing(Point& rStartPos) const
}
}
- tools::Long nTotalSpace = IsVertical() ? aPaperSize.Width() : aPaperSize.Height();
+ tools::Long nTotalSpace = getHeightDirectionAware(aPaperSize);
nTotalSpace -= nTotalOccupiedHeight;
if (nTotalSpace <= 0 || nTotalLineCount <= 1)
return 0;
+ // Shift the text to the right for the asian layout mode.
if (IsVertical())
- {
- if( IsTopToBottom() )
- // Shift the text to the right for the asian layout mode.
- rStartPos.AdjustX(nTotalSpace );
- else
- rStartPos.AdjustX( -nTotalSpace );
- }
+ adjustYDirectionAware(rStartPos, -nTotalSpace);
return nTotalSpace / (nTotalLineCount-1);
}
@@ -4240,7 +4155,7 @@ void ImpEditEngine::SetFlatMode( bool bFlat )
void ImpEditEngine::SetCharStretching( sal_uInt16 nX, sal_uInt16 nY )
{
- bool bChanged(false);
+ bool bChanged;
if ( !IsVertical() )
{
bChanged = nStretchX!=nX || nStretchY!=nY;