diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2018-11-21 12:28:03 +0100 |
---|---|---|
committer | Michael Stahl <Michael.Stahl@cib.de> | 2018-12-07 10:32:29 +0100 |
commit | 570037ddd5f46b0ef6cc8b100dda0aefbb50fbb6 (patch) | |
tree | 3f8b41a87d6b31c18c22805c3f060bd6e5d6c337 | |
parent | sw_redlinehide_4a: fix the number handling in SwEditShell::GetScriptType() (diff) | |
download | core-570037ddd5f46b0ef6cc8b100dda0aefbb50fbb6.tar.gz core-570037ddd5f46b0ef6cc8b100dda0aefbb50fbb6.zip |
sw_redlinehide_4a: convert SwEditShell::GetScalingOfSelectedText()
Move SwTextNode::GetScalingOfSelectedText() to SwTextFrame & simplify.
Change-Id: I9e9f0059665fb128de6be12a15ca2b4a95ebc5ff
(cherry picked from commit 782506335e2b5a1c6d4c0222520165900a91aeb8)
-rw-r--r-- | sw/inc/ndtxt.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/edit/edattr.cxx | 17 | ||||
-rw-r--r-- | sw/source/core/inc/txtfrm.hxx | 1 | ||||
-rw-r--r-- | sw/source/core/text/itratr.cxx | 96 |
4 files changed, 46 insertions, 70 deletions
diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx index 64eef11f9221..4c0e6468fb9b 100644 --- a/sw/inc/ndtxt.hxx +++ b/sw/inc/ndtxt.hxx @@ -775,8 +775,6 @@ public: bool IsFirstOfNumRule(SwRootFrame const& rLayout) const; - sal_uInt16 GetScalingOfSelectedText( sal_Int32 nStt, sal_Int32 nEnd ) const; - SAL_DLLPRIVATE css::uno::WeakReference<css::text::XTextContent> const& GetXParagraph() const { return m_wXParagraph; } SAL_DLLPRIVATE void SetXParagraph(css::uno::Reference<css::text::XTextContent> const& xParagraph) diff --git a/sw/source/core/edit/edattr.cxx b/sw/source/core/edit/edattr.cxx index 678363ccad81..5b61dbe0ed86 100644 --- a/sw/source/core/edit/edattr.cxx +++ b/sw/source/core/edit/edattr.cxx @@ -840,14 +840,15 @@ sal_uInt16 SwEditShell::GetScalingOfSelectedText() const sal_uInt16 nScaleWidth; if( pTNd ) { - const SwPosition* pEnd = pStt == pCursor->GetPoint() - ? pCursor->GetMark() - : pCursor->GetPoint(); - const sal_Int32 nStt = pStt->nContent.GetIndex(); - const sal_Int32 nEnd = pStt->nNode == pEnd->nNode - ? pEnd->nContent.GetIndex() - : pTNd->GetText().getLength(); - nScaleWidth = pTNd->GetScalingOfSelectedText( nStt, nEnd ); + SwTextFrame *const pFrame(static_cast<SwTextFrame *>( + pTNd->getLayoutFrame(GetLayout(), pStt))); + assert(pFrame); // shell cursor must be positioned in node with frame + TextFrameIndex const nStart(pFrame->MapModelToViewPos(*pStt)); + TextFrameIndex const nEnd( + sw::FrameContainsNode(*pFrame, pCursor->End()->nNode.GetIndex()) + ? pFrame->MapModelToViewPos(*pCursor->End()) + : TextFrameIndex(pFrame->GetText().getLength())); + nScaleWidth = pFrame->GetScalingOfSelectedText(nStart, nEnd); } else nScaleWidth = 100; // default are no scaling -> 100% diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx index f0adb57b5bbb..ea7f3d2c82fc 100644 --- a/sw/source/core/inc/txtfrm.hxx +++ b/sw/source/core/inc/txtfrm.hxx @@ -756,6 +756,7 @@ public: bool IsSymbolAt(TextFrameIndex) const; OUString GetCurWord(SwPosition const&) const; + sal_uInt16 GetScalingOfSelectedText(TextFrameIndex nStt, TextFrameIndex nEnd); virtual void dumpAsXmlAttributes(xmlTextWriterPtr writer) const override; }; diff --git a/sw/source/core/text/itratr.cxx b/sw/source/core/text/itratr.cxx index 1ae7e8e23469..4879f4c2cecb 100644 --- a/sw/source/core/text/itratr.cxx +++ b/sw/source/core/text/itratr.cxx @@ -1199,60 +1199,50 @@ void SwTextNode::GetMinMaxSize( sal_uLong nIndex, sal_uLong& rMin, sal_uLong &rM } /** - * Calculates the width of the text part specified by nStt and nEnd, - * the height of the line containing nStt is divided by this width, + * Calculates the width of the text part specified by nStart and nEnd, + * the height of the line containing nStart is divided by this width, * indicating the scaling factor, if the text part is rotated. * Having CH_BREAKs in the text part, this method returns the scaling * factor for the longest of the text parts separated by the CH_BREAK * * Changing this method very likely requires changing of "GetMinMaxSize" */ -sal_uInt16 SwTextNode::GetScalingOfSelectedText( sal_Int32 nStt, sal_Int32 nEnd ) - const +sal_uInt16 SwTextFrame::GetScalingOfSelectedText( + TextFrameIndex nStart, TextFrameIndex nEnd) { - SwViewShell const * pSh = GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell(); - OutputDevice* pOut = nullptr; - - if ( pSh ) - pOut = &pSh->GetRefDev(); - else - { - // Access via StarONE, there's no need for an existing or active shell - if ( getIDocumentSettingAccess()->get(DocumentSettingId::HTML_MODE) ) - pOut = Application::GetDefaultDevice(); - else - pOut = getIDocumentDeviceAccess().getReferenceDevice( true ); - } - - OSL_ENSURE( pOut, "GetScalingOfSelectedText without outdev" ); + assert(GetOfst() <= nStart && (!GetFollow() || nStart < GetFollow()->GetOfst())); + SwViewShell const*const pSh = getRootFrame()->GetCurrShell(); + assert(pSh); + OutputDevice *const pOut = &pSh->GetRefDev(); + assert(pOut); MapMode aOldMap( pOut->GetMapMode() ); pOut->SetMapMode( MapMode( MapUnit::MapTwip ) ); - if ( nStt == nEnd ) + if (nStart == nEnd) { assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is()); SwScriptInfo aScriptInfo; - SwAttrIter aIter( *const_cast<SwTextNode*>(this), aScriptInfo ); - aIter.SeekAndChgAttrIter( nStt, pOut ); + SwAttrIter aIter(*GetTextNodeFirst(), aScriptInfo, this); + aIter.SeekAndChgAttrIter( nStart, pOut ); - Boundary aBound = - g_pBreakIt->GetBreakIter()->getWordBoundary( GetText(), nStt, + Boundary aBound = g_pBreakIt->GetBreakIter()->getWordBoundary( + GetText(), sal_Int32(nStart), g_pBreakIt->GetLocale( aIter.GetFnt()->GetLanguage() ), WordType::DICTIONARY_WORD, true ); - if ( nStt == aBound.startPos ) + if (sal_Int32(nStart) == aBound.startPos) { // cursor is at left or right border of word pOut->SetMapMode( aOldMap ); return 100; } - nStt = aBound.startPos; - nEnd = aBound.endPos; + nStart = TextFrameIndex(aBound.startPos); + nEnd = TextFrameIndex(aBound.endPos); - if ( nStt == nEnd ) + if (nStart == nEnd) { pOut->SetMapMode( aOldMap ); return 100; @@ -1260,18 +1250,18 @@ sal_uInt16 SwTextNode::GetScalingOfSelectedText( sal_Int32 nStt, sal_Int32 nEnd } SwScriptInfo aScriptInfo; - SwAttrIter aIter( *const_cast<SwTextNode*>(this), aScriptInfo ); + SwAttrIter aIter(*GetTextNodeFirst(), aScriptInfo, this); // We do not want scaling attributes to be considered during this // calculation. For this, we push a temporary scaling attribute with // scaling value 100 and priority flag on top of the scaling stack SwAttrHandler& rAH = aIter.GetAttrHandler(); SvxCharScaleWidthItem aItem(100, RES_CHRATR_SCALEW); - SwTextAttrEnd aAttr( aItem, nStt, nEnd ); + SwTextAttrEnd aAttr( aItem, 0, COMPLETE_STRING ); aAttr.SetPriorityAttr( true ); rAH.PushAndChg( aAttr, *(aIter.GetFnt()) ); - sal_Int32 nIdx = nStt; + TextFrameIndex nIdx = nStart; sal_uLong nWidth = 0; sal_uLong nProWidth = 0; @@ -1281,16 +1271,16 @@ sal_uInt16 SwTextNode::GetScalingOfSelectedText( sal_Int32 nStt, sal_Int32 nEnd aIter.SeekAndChgAttrIter( nIdx, pOut ); // scan for end of portion - const sal_Int32 nNextChg = std::min(aIter.GetNextAttr(), aScriptInfo.NextScriptChg(nIdx)); + TextFrameIndex const nNextChg = std::min(aIter.GetNextAttr(), aScriptInfo.NextScriptChg(nIdx)); - sal_Int32 nStop = nIdx; + TextFrameIndex nStop = nIdx; sal_Unicode cChar = CH_BLANK; SwTextAttr* pHint = nullptr; // stop at special characters in [ nIdx, nNextChg ] while( nStop < nEnd && nStop < nNextChg ) { - cChar = m_Text[nStop]; + cChar = GetText()[sal_Int32(nStop)]; if ( CH_TAB == cChar || CH_BREAK == cChar || @@ -1312,7 +1302,7 @@ sal_uInt16 SwTextNode::GetScalingOfSelectedText( sal_Int32 nStt, sal_Int32 nEnd // calculate text widths up to cChar if ( nStop > nIdx ) { - SwDrawTextInfo aDrawInf(pSh, *pOut, GetText(), nIdx, nStop - nIdx); + SwDrawTextInfo aDrawInf(pSh, *pOut, GetText(), sal_Int32(nIdx), sal_Int32(nStop - nIdx)); nProWidth += aIter.GetFnt()->GetTextSize_( aDrawInf ).Width(); } @@ -1329,7 +1319,7 @@ sal_uInt16 SwTextNode::GetScalingOfSelectedText( sal_Int32 nStt, sal_Int32 nEnd { // tab receives width of one space OUString sTmp( CH_BLANK ); - SwDrawTextInfo aDrawInf( pSh, *pOut, sTmp, 0, 1 ); + SwDrawTextInfo aDrawInf(pSh, *pOut, sTmp, 0, 1); nProWidth += aIter.GetFnt()->GetTextSize_( aDrawInf ).Width(); nIdx++; } @@ -1338,7 +1328,7 @@ sal_uInt16 SwTextNode::GetScalingOfSelectedText( sal_Int32 nStt, sal_Int32 nEnd else if ( cChar == CHAR_HARDBLANK || cChar == CHAR_HARDHYPHEN ) { OUString sTmp( cChar ); - SwDrawTextInfo aDrawInf( pSh, *pOut, sTmp, 0, 1 ); + SwDrawTextInfo aDrawInf(pSh, *pOut, sTmp, 0, 1); nProWidth += aIter.GetFnt()->GetTextSize_( aDrawInf ).Width(); nIdx++; } @@ -1359,7 +1349,7 @@ sal_uInt16 SwTextNode::GetScalingOfSelectedText( sal_Int32 nStt, sal_Int32 nEnd case RES_TXTATR_ANNOTATION : { SwField *pField = const_cast<SwField*>(pHint->GetFormatField().GetField()); - OUString const aText = pField->ExpandField(true, pSh->GetLayout()); + OUString const aText = pField->ExpandField(true, getRootFrame()); SwDrawTextInfo aDrawInf(pSh, *pOut, aText, 0, aText.getLength()); nProWidth += aIter.GetFnt()->GetTextSize_( aDrawInf ).Width(); @@ -1377,37 +1367,23 @@ sal_uInt16 SwTextNode::GetScalingOfSelectedText( sal_Int32 nStt, sal_Int32 nEnd nWidth = std::max( nWidth, nProWidth ); - // search for a text frame this node belongs to - SwIterator<SwTextFrame, SwTextNode, sw::IteratorMode::UnwrapMulti> aFrameIter(*this); - SwTextFrame* pFrame = nullptr; - for( SwTextFrame* pTmpFrame = aFrameIter.First(); pTmpFrame; pTmpFrame = aFrameIter.Next() ) - { - if ( pTmpFrame->GetOfst() <= nStt && - ( !pTmpFrame->GetFollow() || - pTmpFrame->GetFollow()->GetOfst() > nStt ) ) - { - pFrame = pTmpFrame; - break; - } - } - - // search for the line containing nStt - if ( pFrame && pFrame->HasPara() ) + // search for the line containing nStart + if (HasPara()) { - SwTextInfo aInf( pFrame ); - SwTextIter aLine( pFrame, &aInf ); - aLine.CharToLine( nStt ); + SwTextInfo aInf(this); + SwTextIter aLine(this, &aInf); + aLine.CharToLine( nStart ); pOut->SetMapMode( aOldMap ); return static_cast<sal_uInt16>( nWidth ? ( ( 100 * aLine.GetCurr()->Height() ) / nWidth ) : 0 ); } // no frame or no paragraph, we take the height of the character - // at nStt as line height + // at nStart as line height - aIter.SeekAndChgAttrIter( nStt, pOut ); + aIter.SeekAndChgAttrIter( nStart, pOut ); pOut->SetMapMode( aOldMap ); - SwDrawTextInfo aDrawInf( pSh, *pOut, GetText(), nStt, 1 ); + SwDrawTextInfo aDrawInf(pSh, *pOut, GetText(), sal_Int32(nStart), 1); return static_cast<sal_uInt16>( nWidth ? ((100 * aIter.GetFnt()->GetTextSize_( aDrawInf ).Height()) / nWidth ) : 0 ); } |