sw/source/ui/uiview/srcview.cxx | 46 +++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 21 deletions(-)
New commits: commit a59504bfb06d57ddb0e1f4cfc02222022fa68da1 Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Wed Oct 2 08:42:21 2013 +0200 Fix typo in comment Change-Id: I78b3e37d261d5c82795c40c9eb3de2731b8edd83 diff --git a/sw/source/ui/uiview/srcview.cxx b/sw/source/ui/uiview/srcview.cxx index f44fc64..cefbd34 100644 --- a/sw/source/ui/uiview/srcview.cxx +++ b/sw/source/ui/uiview/srcview.cxx @@ -694,7 +694,7 @@ sal_Int32 SwSrcView::PrintSource( if (!pOutDev || nPage <= 0) return 0; - //! This logarithm for printing the n-th page is very poor since it + //! This algorithm for printing the n-th page is very poor since it //! needs to go over the text of all previous pages to get to the correct one. //! But since HTML source code is expected to be just a small number of pages //! even this poor algorithm should be enough... commit 31eb55e55103e83025bffacafa7832e4c2575e9a Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Wed Oct 2 08:41:33 2013 +0200 Do print empty lines or beyond end of text Change-Id: I706faba95ca6b3034b2293f3dcc15b9f124014be diff --git a/sw/source/ui/uiview/srcview.cxx b/sw/source/ui/uiview/srcview.cxx index f93cb1b..f44fc64 100644 --- a/sw/source/ui/uiview/srcview.cxx +++ b/sw/source/ui/uiview/srcview.cxx @@ -721,7 +721,8 @@ sal_Int32 SwSrcView::PrintSource( // nLinepPage is not true, if lines have to be wrapped... sal_uInt16 nLinespPage = (sal_uInt16) (aPaperSz.Height() / nLineHeight); - sal_uInt16 nCharspLine = (sal_uInt16) (aPaperSz.Width() / pOutDev->GetTextWidth(OUString('X'))); + const sal_Int32 nCharspLine = + static_cast<sal_Int32>(aPaperSz.Width() / pOutDev->GetTextWidth("X")); sal_uInt16 nParas = static_cast< sal_uInt16 >( pTextEngine->GetParagraphCount() ); sal_uInt16 nPages = (sal_uInt16) (nParas / nLinespPage + 1 ); @@ -735,7 +736,8 @@ sal_Int32 SwSrcView::PrintSource( for ( sal_uInt16 nPara = 0; nPara < nParas; ++nPara ) { const OUString aLine( lcl_ConvertTabsToSpaces(pTextEngine->GetText( nPara )) ); - sal_Int32 nLines = aLine.getLength() / nCharspLine + 1; + const sal_Int32 nLineLen = aLine.getLength(); + const sal_Int32 nLines = (nLineLen+nCharspLine-1) / nCharspLine; for ( sal_Int32 nLine = 0; nLine < nLines; ++nLine ) { aPos.Y() += nLineHeight; @@ -747,7 +749,11 @@ sal_Int32 SwSrcView::PrintSource( aPos = aStartPos; } if (!bCalcNumPagesOnly && nPage == nCurPage) - pOutDev->DrawText( aPos, aLine.copy(nLine * nCharspLine, nCharspLine) ); + { + const sal_Int32 nStart = nLine * nCharspLine; + const sal_Int32 nLen = std::min(nLineLen-nStart, nCharspLine); + pOutDev->DrawText( aPos, aLine.copy(nStart, nLen) ); + } } aPos.Y() += nParaSpace; } commit 06941b060bab0b5941b619441ecf767c6a0ab23d Author: Matteo Casalin <matteo.casa...@yahoo.com> Date: Wed Oct 2 02:09:36 2013 +0200 String to OUString Change-Id: I03949be73025d8b58ee35648d95e76b3ac1df2b8 diff --git a/sw/source/ui/uiview/srcview.cxx b/sw/source/ui/uiview/srcview.cxx index 02762d5..f93cb1b 100644 --- a/sw/source/ui/uiview/srcview.cxx +++ b/sw/source/ui/uiview/srcview.cxx @@ -192,26 +192,26 @@ static rtl_TextEncoding lcl_GetStreamCharSet(rtl_TextEncoding eLoadEncoding) return eRet; } -static void lcl_ConvertTabsToSpaces( String& rLine ) +static OUString lcl_ConvertTabsToSpaces( OUString sLine ) { - if ( rLine.Len() ) + if (!sLine.isEmpty()) { - sal_uInt16 nPos = 0; - sal_uInt16 nMax = rLine.Len(); - while ( nPos < nMax ) + const sal_Unicode aPadSpaces[4] = {' ', ' ', ' ', ' '}; + sal_Int32 nPos = 0; + for (;;) { - if ( rLine.GetChar(nPos) == '\t' ) + nPos = sLine.indexOf('\t', nPos); + if (nPos<0) { - // Not 4 blanks, but on 4th TabPos: - OUStringBuffer aBlanker; - comphelper::string::padToLength(aBlanker, ( 4 - ( nPos % 4 ) ), ' '); - rLine.Erase( nPos, 1 ); - rLine.Insert(aBlanker.makeStringAndClear(), nPos); - nMax = rLine.Len(); + break; } - nPos++; // Not optimally, if tab, but not wrong... + // Not 4 blanks, but on 4th TabPos: + const sal_Int32 nPadLen = 4 - (nPos % 4); + sLine.replaceAt(nPos, 1, OUString(aPadSpaces, nPadLen)); + nPos += nPadLen; } } + return sLine; } SwSrcView::SwSrcView(SfxViewFrame* pViewFrame, SfxViewShell*) : @@ -734,12 +734,10 @@ sal_Int32 SwSrcView::PrintSource( Point aPos( aStartPos ); for ( sal_uInt16 nPara = 0; nPara < nParas; ++nPara ) { - String aLine( pTextEngine->GetText( nPara ) ); - lcl_ConvertTabsToSpaces( aLine ); - sal_uInt16 nLines = aLine.Len() / nCharspLine + 1; - for ( sal_uInt16 nLine = 0; nLine < nLines; ++nLine ) + const OUString aLine( lcl_ConvertTabsToSpaces(pTextEngine->GetText( nPara )) ); + sal_Int32 nLines = aLine.getLength() / nCharspLine + 1; + for ( sal_Int32 nLine = 0; nLine < nLines; ++nLine ) { - String aTmpLine( aLine, nLine * nCharspLine, nCharspLine ); aPos.Y() += nLineHeight; if ( aPos.Y() > ( aPaperSz.Height() + TMARGPRN - nLineHeight/2 ) ) { @@ -749,7 +747,7 @@ sal_Int32 SwSrcView::PrintSource( aPos = aStartPos; } if (!bCalcNumPagesOnly && nPage == nCurPage) - pOutDev->DrawText( aPos, aTmpLine ); + pOutDev->DrawText( aPos, aLine.copy(nLine * nCharspLine, nCharspLine) ); } aPos.Y() += nParaSpace; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits