tdf#135843 tdf#146731 Fix the missing border handling

Reverts fa5ab8aa5d88e7128015127af75980a65f945cbb inside. And fix the
missing border problem with better way. Reason of the problem is using
ORIGCELL cell style for bottom and right of merged ranges is wrong.

Eg: We have Row X Col 3X3 table. (0,1) and (0,2) merged. The right side
of right border style should be same with (0,2). But ORIGCELL points (0,1)
instead. In case we should use LASTCELL. Same reason is valid for bottom case.

Change-Id: I5282083541f0bd02f3765943da4f34cabe05ef13
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128493
Reviewed-by: Gülşah Köse <gulsah.kose@collabora.com>
Tested-by: Gülşah Köse <gulsah.kose@collabora.com>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128498
Tested-by: Jenkins
diff --git a/svx/source/dialog/framelinkarray.cxx b/svx/source/dialog/framelinkarray.cxx
index 16f6c09..62967b6 100644
--- a/svx/source/dialog/framelinkarray.cxx
+++ b/svx/source/dialog/framelinkarray.cxx
@@ -260,6 +260,7 @@ struct ArrayImpl
    size_t              GetMergedLastRow( size_t nCol, size_t nRow ) const;

    const Cell&         GetMergedOriginCell( size_t nCol, size_t nRow ) const;
    const Cell&         GetMergedLastCell( size_t nCol, size_t nRow ) const;

    bool                IsMergedOverlappedLeft( size_t nCol, size_t nRow ) const;
    bool                IsMergedOverlappedRight( size_t nCol, size_t nRow ) const;
@@ -343,6 +344,11 @@ const Cell& ArrayImpl::GetMergedOriginCell( size_t nCol, size_t nRow ) const
    return GetCell( GetMergedFirstCol( nCol, nRow ), GetMergedFirstRow( nCol, nRow ) );
}

const Cell& ArrayImpl::GetMergedLastCell( size_t nCol, size_t nRow ) const
{
    return GetCell( GetMergedLastCol( nCol, nRow ), GetMergedLastRow( nCol, nRow ) );
}

bool ArrayImpl::IsMergedOverlappedLeft( size_t nCol, size_t nRow ) const
{
    const Cell& rCell = GetCell( nCol, nRow );
@@ -486,6 +492,7 @@ MergedCellIterator& MergedCellIterator::operator++()
#define CELL( col, row )        mxImpl->GetCell( col, row )
#define CELLACC( col, row )     mxImpl->GetCellAcc( col, row )
#define ORIGCELL( col, row )    mxImpl->GetMergedOriginCell( col, row )
#define LASTCELL( col, row )    mxImpl->GetMergedLastCell( col, row )


Array::Array()
@@ -653,7 +660,7 @@ const Style& Array::GetCellStyleRight( size_t nCol, size_t nRow ) const
        return ORIGCELL( nCol + 1, nRow ).GetStyleLeft();
    // right clipping border: always own right style
    if( nCol == mxImpl->mnLastClipCol )
        return ORIGCELL( nCol, nRow ).GetStyleRight();
        return LASTCELL( nCol, nRow ).GetStyleRight();
    // outside clipping columns: invisible
    if( !mxImpl->IsColInClipRange( nCol ) )
        return OBJ_STYLE_NONE;
@@ -689,7 +696,7 @@ const Style& Array::GetCellStyleBottom( size_t nCol, size_t nRow ) const
        return ORIGCELL( nCol, nRow + 1 ).GetStyleTop();
    // bottom clipping border: always own bottom style
    if( nRow == mxImpl->mnLastClipRow )
        return ORIGCELL( nCol, nRow ).GetStyleBottom();
        return LASTCELL( nCol, nRow ).GetStyleBottom();
    // outside clipping rows: invisible
    if( !mxImpl->IsRowInClipRange( nRow ) )
        return OBJ_STYLE_NONE;
@@ -1519,6 +1526,7 @@ drawinglayer::primitive2d::Primitive2DContainer Array::CreateB2DPrimitiveArray()
}

#undef ORIGCELL
#undef LASTCELL
#undef CELLACC
#undef CELL
#undef DBG_FRAME_CHECK_ROW_1
diff --git a/svx/source/table/viewcontactoftableobj.cxx b/svx/source/table/viewcontactoftableobj.cxx
index cb23985..a79882e 100644
--- a/svx/source/table/viewcontactoftableobj.cxx
+++ b/svx/source/table/viewcontactoftableobj.cxx
@@ -259,9 +259,9 @@ namespace sdr::contact
                            {
                                // copy styles for current cell to CellBorderArray for primitive creation
                                aArray.SetCellStyleLeft(aCellPos.mnCol, aCellPos.mnRow, impGetLineStyle(rTableLayouter, aCellPos.mnCol, aCellPos.mnRow, false, nColCount, nRowCount, bIsRTL));
                                aArray.SetCellStyleRight(aCellPos.mnCol, aCellPos.mnRow, impGetLineStyle(rTableLayouter, aCellPos.mnCol, aCellPos.mnRow, false, nColCount, nRowCount, bIsRTL));
                                aArray.SetCellStyleRight(aCellPos.mnCol, aCellPos.mnRow, impGetLineStyle(rTableLayouter, aCellPos.mnCol + 1, aCellPos.mnRow, false, nColCount, nRowCount, bIsRTL));
                                aArray.SetCellStyleTop(aCellPos.mnCol, aCellPos.mnRow, impGetLineStyle(rTableLayouter, aCellPos.mnCol, aCellPos.mnRow, true, nColCount, nRowCount, bIsRTL));
                                aArray.SetCellStyleBottom(aCellPos.mnCol, aCellPos.mnRow, impGetLineStyle(rTableLayouter, aCellPos.mnCol, aCellPos.mnRow, true, nColCount, nRowCount, bIsRTL));
                                aArray.SetCellStyleBottom(aCellPos.mnCol, aCellPos.mnRow, impGetLineStyle(rTableLayouter, aCellPos.mnCol, aCellPos.mnRow + 1, true, nColCount, nRowCount, bIsRTL));

                                // ignore merged cells (all except the top-left of a merged cell)
                                if(!xCurrentCell->isMerged())