sw/qa/extras/unowriter/unowriter.cxx | 14 ++++++++++ sw/source/core/unocore/unoportenum.cxx | 44 +++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 7 deletions(-)
New commits: commit bf4b40f720146e7f76dab4deb72e85ea158e2d17 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Jun 21 13:53:24 2019 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Jun 21 18:01:24 2019 +0200 sw comments on frames: fix annotation start order in UNO portion enum The problem was similar to commit 76a4305d1e90b6617054dd33036e64f005dbcf04 (sw: fix inconsistent bookmark behavior around at-char/as-char anchored frames, 2017-12-21), except here we have an (annotation) mark which does have a range, but still around at-char anchored frames, similar to the bookmark situation in that commit. Fix the problem similarly, by first adding comment-start portions to the enumeration, then frames, and finally the rest of the comment portions (as before). With this, an ODF <office:annotation/><draw:frame text:anchor-type="char"/><office:annotation-end/> sequence (commented at-char image) is roundtripped correctly. Change-Id: I8790d9efae625de48c689ca4180fe75f15b4833c Reviewed-on: https://gerrit.libreoffice.org/74503 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx index 2969b5447675..38c55cfb74dd 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -547,6 +547,20 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testImageCommentAtChar) // is also the anchor position of the image). IDocumentMarkAccess* pMarks = pDoc->getIDocumentMarkAccess(); CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), pMarks->getAnnotationMarksCount()); + + uno::Reference<text::XTextRange> xPara = getParagraph(1); + CPPUNIT_ASSERT_EQUAL(OUString("Text"), + getProperty<OUString>(getRun(xPara, 1), "TextPortionType")); + // Without the accompanying fix in place, this test would have failed with 'Expected: + // Annotation; Actual: Frame', i.e. the comment-start portion was after the commented image. + CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), + getProperty<OUString>(getRun(xPara, 2), "TextPortionType")); + CPPUNIT_ASSERT_EQUAL(OUString("Frame"), + getProperty<OUString>(getRun(xPara, 3), "TextPortionType")); + CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), + getProperty<OUString>(getRun(xPara, 4), "TextPortionType")); + CPPUNIT_ASSERT_EQUAL(OUString("Text"), + getProperty<OUString>(getRun(xPara, 5), "TextPortionType")); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx index 30cf25ade0bd..9660d3187754 100644 --- a/sw/source/core/unocore/unoportenum.cxx +++ b/sw/source/core/unocore/unoportenum.cxx @@ -1161,12 +1161,25 @@ static void lcl_ExportBkmAndRedline( lcl_ExportSoftPageBreak(rPortions, xParent, pUnoCursor, rBreakArr, nIndex); } +/** + * Exports all start annotation marks from rAnnotationStartArr into rPortions that have the same + * start position as nIndex. + * + * @param rAnnotationStartArr the array of annotation marks. Consumed entries are removed. + * + * @param rFramePositions the list of positions where there is an at-char anchored frame. + * + * @param bOnlyFrame If true: export only the start of annotation marks which cover an at-char + * anchored frame. If false: export everything else. + */ static void lcl_ExportAnnotationStarts( TextRangeList_t & rPortions, Reference<XText> const & xParent, const SwUnoCursor * const pUnoCursor, SwAnnotationStartPortion_ImplList& rAnnotationStartArr, - const sal_Int32 nIndex) + const sal_Int32 nIndex, + const std::set<sal_Int32>& rFramePositions, + bool bOnlyFrame) { for ( SwAnnotationStartPortion_ImplList::iterator aIter = rAnnotationStartArr.begin(), aEnd = rAnnotationStartArr.end(); aIter != aEnd; ) @@ -1182,12 +1195,18 @@ static void lcl_ExportAnnotationStarts( break; } - SwXTextPortion* pPortion = - new SwXTextPortion( pUnoCursor, xParent, PORTION_ANNOTATION ); - pPortion->SetTextField( pPtr->mxAnnotationField ); - rPortions.emplace_back(pPortion); + bool bFrameStart = rFramePositions.find(nIndex) != rFramePositions.end(); + if (bFrameStart || !bOnlyFrame) + { + SwXTextPortion* pPortion = + new SwXTextPortion( pUnoCursor, xParent, PORTION_ANNOTATION ); + pPortion->SetTextField( pPtr->mxAnnotationField ); + rPortions.emplace_back(pPortion); - aIter = rAnnotationStartArr.erase(aIter); + aIter = rAnnotationStartArr.erase(aIter); + } + else + ++aIter; } } @@ -1356,6 +1375,15 @@ static void lcl_CreatePortions( lcl_ExportBkmAndRedline( *PortionStack.top().first, i_xParentText, pUnoCursor, Bookmarks, Redlines, SoftPageBreaks, nCurrentIndex, aFramePositions, /*bOnlyFrameBookmarkStarts=*/true ); + lcl_ExportAnnotationStarts( + *PortionStack.top().first, + i_xParentText, + pUnoCursor, + AnnotationStarts, + nCurrentIndex, + aFramePositions, + /*bOnlyFrame=*/true ); + const sal_Int32 nFirstFrameIndex = lcl_ExportFrames( *PortionStack.top().first, i_xParentText, pUnoCursor, i_rFrames, nCurrentIndex); @@ -1370,7 +1398,9 @@ static void lcl_CreatePortions( i_xParentText, pUnoCursor, AnnotationStarts, - nCurrentIndex ); + nCurrentIndex, + aFramePositions, + /*bOnlyFrame=*/false ); bool bCursorMoved( false ); sal_Int32 nNextAttrIndex = -1; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits