Hi,
I was trying to implement the wrapping feature for fields (specifically
the hyperlinks) in impress. Currently, the text box containing
hyperlinks can overflow the width of the box. This can be a problem when
the content is on the border of the slide (or otherwise).
What this patch does/does not:
a) Wraps the field text during display (i.e. not during editing)
b) But, the subsequent text would start from the next line.
c) The link (in case of hyperlinks) is clickable only in the
first segment
I have attached the patch for review. Is my approach correct?
Thank you so much!
Muthu Subramanian
diff --git a/editeng/source/editeng/editdoc.hxx b/editeng/source/editeng/editdoc.hxx
--- a/editeng/source/editeng/editdoc.hxx
+++ b/editeng/source/editeng/editdoc.hxx
@@ -361,6 +361,7 @@ struct ExtraPortionInfo
sal_Bool bCompressed;
sal_Int32* pOrgDXArray;
+ ::std::vector< sal_Int32 > lineBreaksList;
ExtraPortionInfo();
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -1007,7 +1014,31 @@ sal_Bool ImpEditEngine::CreateLines( sal_uInt16 nPara, sal_uInt32 nStartPosY )
pPortion->GetSize() = aTmpFont.QuickGetTextSize( GetRefDevice(), aFieldValue, 0, aFieldValue.Len(), 0 );
// So no scrolling for oversized fields
if ( pPortion->GetSize().Width() > nXWidth )
+ {
+ sal_Int32 nWidthOrg = pPortion->GetSize().Width();
+ sal_Int32 nChars = aFieldValue.Len();
+ sal_Int32 nApproxWC = nXWidth / ( nWidthOrg / nChars );
+ ExtraPortionInfo *pExtraInfo= pPortion->GetExtraInfos();
+ if( !nApproxWC ) nApproxWC++;
+ if( pExtraInfo == NULL )
+ {
+ pExtraInfo = new ExtraPortionInfo();
+ pExtraInfo->nOrgWidth = nXWidth;
+ pPortion->SetExtraInfos( pExtraInfo );
+ }
+ else
+ {
+ pExtraInfo->lineBreaksList.clear();
+ }
+
pPortion->GetSize().Width() = nXWidth;
+
+ while( nChars > 0 )
+ {
+ pExtraInfo->lineBreaksList.push_back( aFieldValue.Len() - nChars );
+ nChars -= nApproxWC;
+ }
+ }
}
nTmpWidth += pPortion->GetSize().Width();
pLine->GetCharPosArray().Insert( pPortion->GetSize().Width(), nTmpPos-pLine->GetStart() );
@@ -2909,6 +2942,8 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRec, Point aSta
// Over the Portions of the line ...
// --------------------------------------------------
sal_uInt16 nIndex = pLine->GetStart();
+ bool bParsingFields = false;
+ ::std::vector< sal_Int32 >::iterator itSubLines;
for ( sal_uInt16 y = pLine->GetStartPortion(); y <= pLine->GetEndPortion(); y++ )
{
DBG_ASSERT( pPortion->GetTextPortions().Count(), "Line without Textportion in Paint!" );
@@ -3084,12 +3122,48 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRec, Point aSta
aText = ((EditCharAttribField*)pAttr)->GetFieldValue();
nTextStart = 0;
nTextLen = aText.Len();
+ ExtraPortionInfo *pExtraInfo = pTextPortion->GetExtraInfos();
+ // Do not split the Fields into different lines while editing
+ if( bStripOnly && !bParsingFields && pExtraInfo && pExtraInfo->lineBreaksList.size() )
+ {
+ bParsingFields = true;
+ itSubLines = pExtraInfo->lineBreaksList.begin();
+ }
+ if( bParsingFields )
+ {
+ if( itSubLines != pExtraInfo->lineBreaksList.begin() )
+ {
+ if ( !IsVertical() )
+ {
+ aStartPos.Y() += pLine->GetMaxAscent();
+ aTmpPos.Y() += pLine->GetHeight();
+ }
+ else
+ {
+ aTmpPos.X() -= pLine->GetMaxAscent();
+ aStartPos.X() -= pLine->GetHeight();
+ }
+ }
+ ::std::vector< sal_Int32 >::iterator curIt = itSubLines;
+ itSubLines++;
+ if( itSubLines != pExtraInfo->lineBreaksList.end() )
+ {
+ nTextStart = *curIt;
+ nTextLen = *itSubLines - nTextStart;
+ }
+ else
+ {
+ nTextStart = *curIt;
+ nTextLen = nTextLen - nTextStart;
+ bParsingFields = false;
+ }
+ }
pTmpDXArray = new sal_Int32[ aText.Len() ];
pDXArray = pTmpDXArray;
Font _aOldFont( GetRefDevice()->GetFont() );
aTmpFont.SetPhysFont( GetRefDevice() );
- aTmpFont.QuickGetTextSize( GetRefDevice(), aText, 0, aText.Len(), pTmpDXArray );
+ aTmpFont.QuickGetTextSize( GetRefDevice(), aText, nTextStart, nTextLen, pTmpDXArray );
if ( aStatus.DoRestoreFont() )
GetRefDevice()->SetFont( _aOldFont );
@@ -3471,7 +3548,11 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRec, Point aSta
}
break;
}
- nIndex = nIndex + pTextPortion->GetLen();
+ if( bParsingFields )
+ y--;
+ else
+ nIndex = nIndex + pTextPortion->GetLen();
+
}
}
_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice