sc/inc/fillinfo.hxx                |    4 
 sc/inc/tablestyle.hxx              |  120 ---------
 sc/source/core/data/fillinfo.cxx   |   20 -
 sc/source/core/data/tablestyle.cxx |  482 +++++++++++++++++++++++++++++++++++++
 4 files changed, 506 insertions(+), 120 deletions(-)

New commits:
commit b1a0db9e06c43ef247583b6a3563d696c8ec2f98
Author:     Balazs Varga <[email protected]>
AuthorDate: Thu Oct 9 10:39:52 2025 +0200
Commit:     Andras Timar <[email protected]>
CommitDate: Mon Nov 17 19:01:34 2025 +0100

    Improve border style handling for table styles
    
    Recreate BoxItems for individual cells in the Table
    style so FillInfo can handle that if we have Table border,
    Row/Column border Header/Total row etc. style for one cells.
    Handle vertical and horizontal border definitions.
    
    Change-Id: I9388f1d95b1b3bd3a92c7640186e381fa3be63f8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192471
    Tested-by: Balazs Varga <[email protected]>
    Reviewed-by: Balazs Varga <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193675
    Reviewed-by: Andras Timar <[email protected]>
    Tested-by: Andras Timar <[email protected]>

diff --git a/sc/inc/fillinfo.hxx b/sc/inc/fillinfo.hxx
index f42d1dd7f92e..b4a4d544c4d2 100644
--- a/sc/inc/fillinfo.hxx
+++ b/sc/inc/fillinfo.hxx
@@ -121,7 +121,7 @@ struct ScCellInfo
         , pDataBar(nullptr)
         , pIconSet(nullptr)
         , maBackground()
-        , pLinesAttr(nullptr)
+        , maLinesAttr()
         , mpTLBRLine(nullptr)
         , mpBLTRLine(nullptr)
         , pShadowAttr(nullptr)
@@ -159,8 +159,8 @@ struct ScCellInfo
     const ScIconSetInfo*        pIconSet;
 
     SfxPoolItemHolder           maBackground;
+    SfxPoolItemHolder           maLinesAttr;
 
-    const SvxBoxItem*           pLinesAttr;         /// original item from 
document.
     const SvxLineItem*          mpTLBRLine;         /// original item from 
document.
     const SvxLineItem*          mpBLTRLine;         /// original item from 
document.
 
diff --git a/sc/inc/tablestyle.hxx b/sc/inc/tablestyle.hxx
index e14bbb486aaf..04b9c36d56e4 100644
--- a/sc/inc/tablestyle.hxx
+++ b/sc/inc/tablestyle.hxx
@@ -11,6 +11,8 @@
 
 #include <memory>
 
+#include <editeng/boxitem.hxx>
+#include <editeng/brushitem.hxx>
 #include "document.hxx"
 #include "scdllapi.h"
 #include "dbdata.hxx"
@@ -40,6 +42,11 @@ template <class T> const T* 
GetItemFromPattern(ScPatternAttr* pPattern, TypedWhi
 class SC_DLLPUBLIC ScTableStyle
 {
 private:
+    ScTableStyle(ScTableStyle const&) = delete;
+    ScTableStyle(ScTableStyle&&) = delete;
+    void operator=(ScTableStyle const&) = delete;
+    void operator=(ScTableStyle&&) = delete;
+
     std::unique_ptr<ScPatternAttr> mpTablePattern;
     std::unique_ptr<ScPatternAttr> mpFirstColumnStripePattern;
     std::unique_ptr<ScPatternAttr> mpSecondColumnStripePattern;
@@ -64,117 +71,12 @@ private:
 public:
     ScTableStyle(const OUString& rName, const std::optional<OUString>& 
rUIName);
 
-    template <class T>
-    const T* GetItem(const ScDBData& rDBData, SCCOL nCol, SCROW nRow, SCROW 
nRowIndex,
-                     TypedWhichId<T> nWhich) const
-    {
-        const ScTableStyleParam* pParam = rDBData.GetTableStyleInfo();
-        ScRange aRange;
-        rDBData.GetArea(aRange);
-
-        bool bHasHeader = rDBData.HasHeader();
-        bool bHasTotal = rDBData.HasTotals();
-        if (bHasHeader && mpLastHeaderCellPattern && nRow == 
aRange.aStart.Row()
-            && nCol == aRange.aEnd.Col())
-        {
-            const T* pPoolItem = 
GetItemFromPattern(mpLastHeaderCellPattern.get(), nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        if (bHasHeader && mpFirstHeaderCellPattern && nRow == 
aRange.aStart.Row()
-            && nCol == aRange.aStart.Col())
-        {
-            const T* pPoolItem = 
GetItemFromPattern(mpFirstHeaderCellPattern.get(), nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        if (bHasTotal && mpTotalRowPattern && nRow == aRange.aEnd.Row())
-        {
-            const T* pPoolItem = GetItemFromPattern(mpTotalRowPattern.get(), 
nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        if (bHasHeader && mpHeaderRowPattern && nRow == aRange.aStart.Row())
-        {
-            const T* pPoolItem = GetItemFromPattern(mpHeaderRowPattern.get(), 
nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        if (pParam->mbFirstColumn && mpFirstColumnPattern && nCol == 
aRange.aStart.Col())
-        {
-            const T* pPoolItem = 
GetItemFromPattern(mpFirstColumnPattern.get(), nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        if (pParam->mbLastColumn && mpLastColumnPattern && nCol == 
aRange.aEnd.Col())
-        {
-            const T* pPoolItem = GetItemFromPattern(mpLastColumnPattern.get(), 
nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        if (!bHasTotal || aRange.aEnd.Row() != nRow)
-        {
-            if (pParam->mbRowStripes && nRowIndex >= 0)
-            {
-                sal_Int32 nTotalRowStripPattern = mnFirstRowStripeSize + 
mnSecondRowStripeSize;
-                bool bFirstRowStripe = (nRowIndex % nTotalRowStripPattern) < 
mnFirstRowStripeSize;
-                if (mpSecondRowStripePattern && !bFirstRowStripe)
-                {
-                    const T* pPoolItem = 
GetItemFromPattern(mpSecondRowStripePattern.get(), nWhich);
-                    if (pPoolItem)
-                        return pPoolItem;
-                }
-
-                if (mpFirstRowStripePattern && bFirstRowStripe)
-                {
-                    const T* pPoolItem = 
GetItemFromPattern(mpFirstRowStripePattern.get(), nWhich);
-                    if (pPoolItem)
-                        return pPoolItem;
-                }
-            }
-
-            if (pParam->mbColumnStripes)
-            {
-                SCCOL nRelativeCol = nCol - aRange.aStart.Col();
-                sal_Int32 nTotalColStripePattern = mnFirstColStripeSize + 
mnSecondColStripeSize;
-                bool bFirstColStripe
-                    = (nRelativeCol % nTotalColStripePattern) < 
mnFirstColStripeSize;
-                if (mpSecondColumnStripePattern && !bFirstColStripe)
-                {
-                    const T* pPoolItem
-                        = 
GetItemFromPattern(mpSecondColumnStripePattern.get(), nWhich);
-                    if (pPoolItem)
-                        return pPoolItem;
-                }
-
-                if (mpFirstColumnStripePattern && bFirstColStripe)
-                {
-                    const T* pPoolItem
-                        = GetItemFromPattern(mpFirstColumnStripePattern.get(), 
nWhich);
-                    if (pPoolItem)
-                        return pPoolItem;
-                }
-            }
-        }
-
-        if (mpTablePattern)
-        {
-            const T* pPoolItem = GetItemFromPattern(mpTablePattern.get(), 
nWhich);
-            if (pPoolItem)
-                return pPoolItem;
-        }
-
-        return nullptr;
-    }
-
     const SfxItemSet* GetTableCellItemSet(const ScDBData& rDBData, SCCOL nCol, 
SCROW nRow,
                                           SCROW nRowIndex) const;
+    const SvxBrushItem* GetFillItem(const ScDBData& rDBData, SCCOL nCol, SCROW 
nRow,
+                                    SCROW nRowIndex) const;
+    std::unique_ptr<SvxBoxItem> GetBoxItem(const ScDBData& rDBData, SCCOL 
nCol, SCROW nRow,
+                                           SCROW nRowIndex) const;
 
     void SetRowStripeSize(sal_Int32 nFirstRowStripeSize, sal_Int32 
nSecondRowStripeSize);
     void SetColStripeSize(sal_Int32 nFirstColStripeSize, sal_Int32 
nSecondColStripeSize);
diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx
index 17dca4a5544c..9ff8c501e0f2 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -445,18 +445,17 @@ void ScDocument::FillInfo(
 
                 ScCellInfo* pInfo = &pThisRowInfo->cellInfo(nCol);
 
-                const SvxBrushItem* pBackground = 
pTableStyle->GetItem(*pDBData, nCol, nRow, nRowIndex, ATTR_BACKGROUND);
-
+                const SvxBrushItem* pBackground = 
pTableStyle->GetFillItem(*pDBData, nCol, nRow, nRowIndex);
                 if (pBackground)
                 {
                     pInfo->maBackground = SfxPoolItemHolder(*pPool, 
pBackground);
                     pThisRowInfo->bEmptyBack = false;
                 }
 
-                const SvxBoxItem* pLinesAttr = pTableStyle->GetItem(*pDBData, 
nCol, nRow, nRowIndex, ATTR_BORDER);
+                std::unique_ptr<SvxBoxItem> pLinesAttr = 
pTableStyle->GetBoxItem(*pDBData, nCol, nRow, nRowIndex);
                 if (pLinesAttr)
                 {
-                    pInfo->pLinesAttr = pLinesAttr;
+                    pInfo->maLinesAttr = SfxPoolItemHolder(*pPool, 
pLinesAttr.get());
                 }
 
                 const SfxItemSet* pPoolItem = 
pTableStyle->GetTableCellItemSet(*pDBData, nCol, nRow, nRowIndex);
@@ -623,16 +622,16 @@ void ScDocument::FillInfo(
                                 pInfo->bPivotExpandButton = bPivotExpandButton;
                                 pInfo->bPivotPopupButtonMulti = 
bPivotPopupButtonMulti;
                                 pInfo->bFilterActive = bFilterActive;
-                                if (pInfo->pLinesAttr)
+                                if (pInfo->maLinesAttr)
                                 {
                                     if (pExplicitBackground)
                                     {
-                                        pInfo->pLinesAttr = pExplicitLinesAttr;
+                                        pInfo->maLinesAttr = 
SfxPoolItemHolder(*pPool, pExplicitLinesAttr);
                                     }
                                 }
                                 else
                                 {
-                                    pInfo->pLinesAttr = pLinesAttr;
+                                    pInfo->maLinesAttr = 
SfxPoolItemHolder(*pPool, pLinesAttr);
                                 }
                                 pInfo->mpTLBRLine   = pTLBRLine;
                                 pInfo->mpBLTRLine   = pBLTRLine;
@@ -756,7 +755,10 @@ void ScDocument::FillInfo(
 
                             // Border
                     if ( const SvxBoxItem* pItem = pCondSet->GetItemIfSet( 
ATTR_BORDER ) )
-                        pInfo->pLinesAttr = pItem;
+                    {
+                        pInfo->maLinesAttr = SfxPoolItemHolder(*pPool, pItem);
+                        pRowInfo[nArrRow].bEmptyBack = false;
+                    }
 
                     if ( const SvxLineItem* pItem = pCondSet->GetItemIfSet( 
ATTR_BORDER_TLBR ) )
                         pInfo->mpTLBRLine = pItem;
@@ -1013,7 +1015,7 @@ void ScDocument::FillInfo(
         for( SCCOL nCol = nCol1 - 1; nCol <= nCol2 + 1; ++nCol ) // 1 more 
left and right
         {
             const ScCellInfo& rInfo = rThisRowInfo.cellInfo( nCol );
-            const SvxBoxItem* pBox = rInfo.pLinesAttr;
+            const SvxBoxItem* pBox = static_cast<const 
SvxBoxItem*>(rInfo.maLinesAttr.getItem());
             const SvxLineItem* pTLBR = rInfo.mpTLBRLine;
             const SvxLineItem* pBLTR = rInfo.mpBLTRLine;
 
diff --git a/sc/source/core/data/tablestyle.cxx 
b/sc/source/core/data/tablestyle.cxx
index 5ee0229c9704..d7d3ff02a330 100644
--- a/sc/source/core/data/tablestyle.cxx
+++ b/sc/source/core/data/tablestyle.cxx
@@ -103,6 +103,488 @@ const SfxItemSet* ScTableStyle::GetTableCellItemSet(const 
ScDBData& rDBData, SCC
     return nullptr;
 }
 
+const SvxBrushItem* ScTableStyle::GetFillItem(const ScDBData& rDBData, SCCOL 
nCol, SCROW nRow,
+                                              SCROW nRowIndex) const
+{
+    const ScTableStyleParam* pParam = rDBData.GetTableStyleInfo();
+    ScRange aRange;
+    rDBData.GetArea(aRange);
+
+    bool bHasHeader = rDBData.HasHeader();
+    bool bHasTotal = rDBData.HasTotals();
+    if (bHasHeader && mpLastHeaderCellPattern && nRow == aRange.aStart.Row()
+        && nCol == aRange.aEnd.Col())
+    {
+        const SvxBrushItem* pPoolItem
+            = GetItemFromPattern(mpLastHeaderCellPattern.get(), 
ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    if (bHasHeader && mpFirstHeaderCellPattern && nRow == aRange.aStart.Row()
+        && nCol == aRange.aStart.Col())
+    {
+        const SvxBrushItem* pPoolItem
+            = GetItemFromPattern(mpFirstHeaderCellPattern.get(), 
ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    if (bHasHeader && mpHeaderRowPattern && nRow == aRange.aStart.Row())
+    {
+        const SvxBrushItem* pPoolItem
+            = GetItemFromPattern(mpHeaderRowPattern.get(), ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    if (bHasTotal && mpTotalRowPattern && nRow == aRange.aEnd.Row())
+    {
+        const SvxBrushItem* pPoolItem
+            = GetItemFromPattern(mpTotalRowPattern.get(), ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    if (pParam->mbFirstColumn && mpFirstColumnPattern && nCol == 
aRange.aStart.Col())
+    {
+        const SvxBrushItem* pPoolItem
+            = GetItemFromPattern(mpFirstColumnPattern.get(), ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    if (pParam->mbLastColumn && mpLastColumnPattern && nCol == 
aRange.aEnd.Col())
+    {
+        const SvxBrushItem* pPoolItem
+            = GetItemFromPattern(mpLastColumnPattern.get(), ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    if (!bHasTotal || aRange.aEnd.Row() != nRow)
+    {
+        if (pParam->mbRowStripes && nRowIndex >= 0)
+        {
+            sal_Int32 nTotalRowStripPattern = mnFirstRowStripeSize + 
mnSecondRowStripeSize;
+            bool bFirstRowStripe = (nRowIndex % nTotalRowStripPattern) < 
mnFirstRowStripeSize;
+            if (mpSecondRowStripePattern && !bFirstRowStripe)
+            {
+                const SvxBrushItem* pPoolItem
+                    = GetItemFromPattern(mpSecondRowStripePattern.get(), 
ATTR_BACKGROUND);
+                if (pPoolItem)
+                    return pPoolItem;
+            }
+
+            if (mpFirstRowStripePattern && bFirstRowStripe)
+            {
+                const SvxBrushItem* pPoolItem
+                    = GetItemFromPattern(mpFirstRowStripePattern.get(), 
ATTR_BACKGROUND);
+                if (pPoolItem)
+                    return pPoolItem;
+            }
+        }
+
+        if (pParam->mbColumnStripes)
+        {
+            SCCOL nRelativeCol = nCol - aRange.aStart.Col();
+            sal_Int32 nTotalColStripePattern = mnFirstColStripeSize + 
mnSecondColStripeSize;
+            bool bFirstColStripe = (nRelativeCol % nTotalColStripePattern) < 
mnFirstColStripeSize;
+            if (mpSecondColumnStripePattern && !bFirstColStripe)
+            {
+                const SvxBrushItem* pPoolItem
+                    = GetItemFromPattern(mpSecondColumnStripePattern.get(), 
ATTR_BACKGROUND);
+                if (pPoolItem)
+                    return pPoolItem;
+            }
+
+            if (mpFirstColumnStripePattern && bFirstColStripe)
+            {
+                const SvxBrushItem* pPoolItem
+                    = GetItemFromPattern(mpFirstColumnStripePattern.get(), 
ATTR_BACKGROUND);
+                if (pPoolItem)
+                    return pPoolItem;
+            }
+        }
+    }
+
+    if (mpTablePattern)
+    {
+        const SvxBrushItem* pPoolItem = 
GetItemFromPattern(mpTablePattern.get(), ATTR_BACKGROUND);
+        if (pPoolItem)
+            return pPoolItem;
+    }
+
+    return nullptr;
+}
+
+std::unique_ptr<SvxBoxItem> ScTableStyle::GetBoxItem(const ScDBData& rDBData, 
SCCOL nCol,
+                                                     SCROW nRow, SCROW 
nRowIndex) const
+{
+    const ScTableStyleParam* pParam = rDBData.GetTableStyleInfo();
+    ScRange aRange;
+    rDBData.GetArea(aRange);
+
+    bool bHasHeader = rDBData.HasHeader();
+    bool bHasTotal = rDBData.HasTotals();
+    if (bHasHeader && mpLastHeaderCellPattern && nRow == aRange.aStart.Row()
+        && nCol == aRange.aEnd.Col())
+    {
+        const SvxBoxItem* pPoolItem
+            = GetItemFromPattern(mpLastHeaderCellPattern.get(), ATTR_BORDER);
+        if (mpTablePattern)
+        {
+            if (const SvxBoxItem* pBoxItem
+                = GetItemFromPattern(mpTotalRowPattern.get(), ATTR_BORDER))
+            {
+                const ::editeng::SvxBorderLine* pTLine = 
pBoxItem->GetLine(SvxBoxItemLine::TOP);
+                const ::editeng::SvxBorderLine* pRLine = 
pBoxItem->GetLine(SvxBoxItemLine::RIGHT);
+                if (pTLine || pRLine)
+                {
+                    std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                      : 
nullptr);
+                    if (!pNewBoxItem)
+                        pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                    if (pTLine)
+                        pNewBoxItem->SetLine(pTLine, SvxBoxItemLine::TOP);
+                    if (pRLine)
+                        pNewBoxItem->SetLine(pRLine, SvxBoxItemLine::RIGHT);
+
+                    return pNewBoxItem;
+                }
+            }
+        }
+
+        if (pPoolItem)
+            return std::make_unique<SvxBoxItem>(*pPoolItem);
+    }
+
+    if (bHasHeader && mpFirstHeaderCellPattern && nRow == aRange.aStart.Row()
+        && nCol == aRange.aStart.Col())
+    {
+        const SvxBoxItem* pPoolItem
+            = GetItemFromPattern(mpFirstHeaderCellPattern.get(), ATTR_BORDER);
+        if (mpTablePattern)
+        {
+            if (const SvxBoxItem* pBoxItem
+                = GetItemFromPattern(mpTotalRowPattern.get(), ATTR_BORDER))
+            {
+                const ::editeng::SvxBorderLine* pTLine = 
pBoxItem->GetLine(SvxBoxItemLine::TOP);
+                const ::editeng::SvxBorderLine* pLLine = 
pBoxItem->GetLine(SvxBoxItemLine::LEFT);
+                if (pTLine || pLLine)
+                {
+                    std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                      : 
nullptr);
+                    if (!pNewBoxItem)
+                        pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                    if (pTLine)
+                        pNewBoxItem->SetLine(pTLine, SvxBoxItemLine::TOP);
+                    if (pLLine)
+                        pNewBoxItem->SetLine(pLLine, SvxBoxItemLine::LEFT);
+
+                    return pNewBoxItem;
+                }
+            }
+        }
+
+        if (pPoolItem)
+            return std::make_unique<SvxBoxItem>(*pPoolItem);
+    }
+
+    if (bHasHeader && mpHeaderRowPattern && nRow == aRange.aStart.Row())
+    {
+        const SvxBoxItem* pPoolItem = 
GetItemFromPattern(mpHeaderRowPattern.get(), ATTR_BORDER);
+        if (mpTablePattern)
+        {
+            const SvxBoxItem* pBoxItem = 
GetItemFromPattern(mpTablePattern.get(), ATTR_BORDER);
+            const SvxBoxInfoItem* pBoxInfoItem
+                = GetItemFromPattern(mpTablePattern.get(), ATTR_BORDER_INNER);
+            if (pBoxItem || pBoxInfoItem)
+            {
+                if (pBoxItem && nCol == aRange.aStart.Col())
+                {
+                    const ::editeng::SvxBorderLine* pTLine = 
pBoxItem->GetLine(SvxBoxItemLine::TOP);
+                    const ::editeng::SvxBorderLine* pLLine
+                        = pBoxItem->GetLine(SvxBoxItemLine::LEFT);
+                    if (pTLine || pLLine)
+                    {
+                        std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                          : 
nullptr);
+                        if (!pNewBoxItem)
+                            pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                        if (pTLine)
+                            pNewBoxItem->SetLine(pTLine, SvxBoxItemLine::TOP);
+                        if (pLLine)
+                            pNewBoxItem->SetLine(pLLine, SvxBoxItemLine::LEFT);
+
+                        return pNewBoxItem;
+                    }
+                }
+                else if (pBoxItem && nCol == aRange.aEnd.Col())
+                {
+                    const ::editeng::SvxBorderLine* pTLine = 
pBoxItem->GetLine(SvxBoxItemLine::TOP);
+                    const ::editeng::SvxBorderLine* pRLine
+                        = pBoxItem->GetLine(SvxBoxItemLine::RIGHT);
+                    if (pTLine || pRLine)
+                    {
+                        std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                          : 
nullptr);
+                        if (!pNewBoxItem)
+                            pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                        if (pTLine)
+                            pNewBoxItem->SetLine(pTLine, SvxBoxItemLine::TOP);
+                        if (pRLine)
+                            pNewBoxItem->SetLine(pRLine, 
SvxBoxItemLine::RIGHT);
+
+                        return pNewBoxItem;
+                    }
+                }
+                else
+                {
+                    const ::editeng::SvxBorderLine* pTLine = nullptr;
+                    if (pBoxItem)
+                        pTLine = pBoxItem->GetLine(SvxBoxItemLine::TOP);
+
+                    const ::editeng::SvxBorderLine* pVLine = nullptr;
+                    if (pBoxInfoItem)
+                        pVLine = pBoxInfoItem->GetVert();
+
+                    if (pTLine || pVLine)
+                    {
+                        std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                          : 
nullptr);
+                        if (!pNewBoxItem)
+                            pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                        if (pTLine)
+                            pNewBoxItem->SetLine(pTLine, SvxBoxItemLine::TOP);
+                        if (pVLine)
+                        {
+                            pNewBoxItem->SetLine(pVLine, SvxBoxItemLine::LEFT);
+                            pNewBoxItem->SetLine(pVLine, 
SvxBoxItemLine::RIGHT);
+                        }
+
+                        return pNewBoxItem;
+                    }
+                }
+            }
+        }
+
+        if (pPoolItem)
+            return std::make_unique<SvxBoxItem>(*pPoolItem);
+    }
+
+    if (bHasTotal && mpTotalRowPattern && nRow == aRange.aEnd.Row())
+    {
+        const SvxBoxItem* pPoolItem = 
GetItemFromPattern(mpTotalRowPattern.get(), ATTR_BORDER);
+        if (mpTablePattern)
+        {
+            const SvxBoxItem* pBoxItem = 
GetItemFromPattern(mpTablePattern.get(), ATTR_BORDER);
+            const SvxBoxInfoItem* pBoxInfoItem
+                = GetItemFromPattern(mpTablePattern.get(), ATTR_BORDER_INNER);
+            if (pBoxItem || pBoxInfoItem)
+            {
+                if (pBoxItem && nCol == aRange.aStart.Col())
+                {
+                    const ::editeng::SvxBorderLine* pBLine
+                        = pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+                    const ::editeng::SvxBorderLine* pLLine
+                        = pBoxItem->GetLine(SvxBoxItemLine::LEFT);
+                    if (pBLine || pLLine)
+                    {
+                        std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                          : 
nullptr);
+                        if (!pNewBoxItem)
+                            pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                        if (pBLine)
+                            pNewBoxItem->SetLine(pBLine, 
SvxBoxItemLine::BOTTOM);
+                        if (pLLine)
+                            pNewBoxItem->SetLine(pLLine, SvxBoxItemLine::LEFT);
+
+                        return pNewBoxItem;
+                    }
+                }
+                else if (pBoxItem && nCol == aRange.aEnd.Col())
+                {
+                    const ::editeng::SvxBorderLine* pBLine
+                        = pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+                    const ::editeng::SvxBorderLine* pRLine
+                        = pBoxItem->GetLine(SvxBoxItemLine::RIGHT);
+                    if (pBLine || pRLine)
+                    {
+                        std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                          : 
nullptr);
+                        if (!pNewBoxItem)
+                            pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                        if (pBLine)
+                            pNewBoxItem->SetLine(pBLine, 
SvxBoxItemLine::BOTTOM);
+                        if (pRLine)
+                            pNewBoxItem->SetLine(pRLine, 
SvxBoxItemLine::RIGHT);
+
+                        return pNewBoxItem;
+                    }
+                }
+                else
+                {
+                    const ::editeng::SvxBorderLine* pBLine = nullptr;
+                    if (pBoxItem)
+                        pBLine = pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+
+                    const ::editeng::SvxBorderLine* pVLine = nullptr;
+                    if (pBoxInfoItem)
+                        pVLine = pBoxInfoItem->GetVert();
+
+                    if (pBLine || pVLine)
+                    {
+                        std::unique_ptr<SvxBoxItem> pNewBoxItem(pPoolItem ? 
pPoolItem->Clone()
+                                                                          : 
nullptr);
+                        if (!pNewBoxItem)
+                            pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+                        if (pBLine)
+                            pNewBoxItem->SetLine(pBLine, 
SvxBoxItemLine::BOTTOM);
+                        if (pVLine)
+                        {
+                            pNewBoxItem->SetLine(pVLine, SvxBoxItemLine::LEFT);
+                            pNewBoxItem->SetLine(pVLine, 
SvxBoxItemLine::RIGHT);
+                        }
+
+                        return pNewBoxItem;
+                    }
+                }
+            }
+        }
+
+        if (pPoolItem)
+            return std::make_unique<SvxBoxItem>(*pPoolItem);
+    }
+
+    if (pParam->mbFirstColumn && mpFirstColumnPattern && nCol == 
aRange.aStart.Col())
+    {
+        const SvxBoxItem* pPoolItem = 
GetItemFromPattern(mpFirstColumnPattern.get(), ATTR_BORDER);
+        if (pPoolItem)
+            return std::make_unique<SvxBoxItem>(*pPoolItem);
+    }
+
+    if (pParam->mbLastColumn && mpLastColumnPattern && nCol == 
aRange.aEnd.Col())
+    {
+        const SvxBoxItem* pPoolItem = 
GetItemFromPattern(mpLastColumnPattern.get(), ATTR_BORDER);
+        if (pPoolItem)
+            return std::make_unique<SvxBoxItem>(*pPoolItem);
+    }
+
+    if (!bHasTotal || aRange.aEnd.Row() != nRow)
+    {
+        if (pParam->mbRowStripes && nRowIndex >= 0)
+        {
+            sal_Int32 nTotalRowStripPattern = mnFirstRowStripeSize + 
mnSecondRowStripeSize;
+            bool bFirstRowStripe = (nRowIndex % nTotalRowStripPattern) < 
mnFirstRowStripeSize;
+            if (mpSecondRowStripePattern && !bFirstRowStripe)
+            {
+                const SvxBoxItem* pPoolItem
+                    = GetItemFromPattern(mpSecondRowStripePattern.get(), 
ATTR_BORDER);
+                if (pPoolItem)
+                    return std::make_unique<SvxBoxItem>(*pPoolItem);
+            }
+
+            if (mpFirstRowStripePattern && bFirstRowStripe)
+            {
+                const SvxBoxItem* pPoolItem
+                    = GetItemFromPattern(mpFirstRowStripePattern.get(), 
ATTR_BORDER);
+                if (pPoolItem)
+                    return std::make_unique<SvxBoxItem>(*pPoolItem);
+            }
+        }
+
+        if (pParam->mbColumnStripes)
+        {
+            SCCOL nRelativeCol = nCol - aRange.aStart.Col();
+            sal_Int32 nTotalColStripePattern = mnFirstColStripeSize + 
mnSecondColStripeSize;
+            bool bFirstColStripe = (nRelativeCol % nTotalColStripePattern) < 
mnFirstColStripeSize;
+            if (mpSecondColumnStripePattern && !bFirstColStripe)
+            {
+                const SvxBoxItem* pPoolItem
+                    = GetItemFromPattern(mpSecondColumnStripePattern.get(), 
ATTR_BORDER);
+                if (pPoolItem)
+                    return std::make_unique<SvxBoxItem>(*pPoolItem);
+            }
+
+            if (mpFirstColumnStripePattern && bFirstColStripe)
+            {
+                const SvxBoxItem* pPoolItem
+                    = GetItemFromPattern(mpFirstColumnStripePattern.get(), 
ATTR_BORDER);
+                if (pPoolItem)
+                    return std::make_unique<SvxBoxItem>(*pPoolItem);
+            }
+        }
+    }
+
+    if (mpTablePattern)
+    {
+        const SvxBoxItem* pBoxItem = GetItemFromPattern(mpTablePattern.get(), 
ATTR_BORDER);
+        const SvxBoxInfoItem* pBoxInfoItem
+            = GetItemFromPattern(mpTablePattern.get(), ATTR_BORDER_INNER);
+
+        if (pBoxItem || pBoxInfoItem)
+        {
+            std::unique_ptr<SvxBoxItem> pNewBoxItem = 
std::make_unique<SvxBoxItem>(ATTR_BORDER);
+            // Start/End col borders
+            if (pBoxItem && nCol == aRange.aStart.Col())
+            {
+                const ::editeng::SvxBorderLine* pLLine = 
pBoxItem->GetLine(SvxBoxItemLine::LEFT);
+                if (pLLine)
+                {
+                    pNewBoxItem->SetLine(pLLine, SvxBoxItemLine::LEFT);
+                }
+            }
+            else if (pBoxItem && nCol == aRange.aEnd.Col())
+            {
+                const ::editeng::SvxBorderLine* pRLine = 
pBoxItem->GetLine(SvxBoxItemLine::RIGHT);
+                if (pRLine)
+                {
+                    pNewBoxItem->SetLine(pRLine, SvxBoxItemLine::RIGHT);
+                }
+            }
+            // Start/End row borders
+            if (pBoxItem && nRow == aRange.aStart.Row())
+            {
+                const ::editeng::SvxBorderLine* pTLine = 
pBoxItem->GetLine(SvxBoxItemLine::TOP);
+                if (pTLine)
+                {
+                    pNewBoxItem->SetLine(pTLine, SvxBoxItemLine::TOP);
+                }
+            }
+            else if (pBoxItem && nRow == aRange.aEnd.Row())
+            {
+                const ::editeng::SvxBorderLine* pBLine = 
pBoxItem->GetLine(SvxBoxItemLine::BOTTOM);
+                if (pBLine)
+                {
+                    pNewBoxItem->SetLine(pBLine, SvxBoxItemLine::BOTTOM);
+                }
+            }
+            // Inner borders
+            if (pBoxInfoItem)
+            {
+                const ::editeng::SvxBorderLine* pHLine = 
pBoxInfoItem->GetHori();
+                if (pHLine)
+                {
+                    pNewBoxItem->SetLine(pHLine, SvxBoxItemLine::TOP);
+                    pNewBoxItem->SetLine(pHLine, SvxBoxItemLine::BOTTOM);
+                }
+
+                const ::editeng::SvxBorderLine* pVLine = 
pBoxInfoItem->GetVert();
+                if (pVLine)
+                {
+                    pNewBoxItem->SetLine(pVLine, SvxBoxItemLine::LEFT);
+                    pNewBoxItem->SetLine(pVLine, SvxBoxItemLine::RIGHT);
+                }
+            }
+
+            return pNewBoxItem;
+        }
+    }
+
+    return nullptr;
+}
+
 void ScTableStyle::SetRowStripeSize(sal_Int32 nFirstRowStripeSize, sal_Int32 
nSecondRowStripeSize)
 {
     if (nFirstRowStripeSize >= 1)

Reply via email to