summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2019-11-01 15:40:43 +0000
committerMichael Meeks <michael.meeks@collabora.com>2019-11-06 01:19:28 +0100
commit05b72d7dc26080b2e97cbe76d08478926b20947e (patch)
tree37190571d5b1e3067654cf48da63a0c231561e77
parent56b11c503cbc4a42b604821a8701408d59a7f744 (diff)
sc lok: cope with non 100% zoom better.
Do the tile rendering and alignment ourselves. More work required to get cleaner conversion between view and document twips (view twips being rounded to produce nice round pixel sizes when re-converted). Change-Id: I51edb186cfd2dc434005cc074f4ed8de19c85cb3 Reviewed-on: https://gerrit.libreoffice.org/82092 Tested-by: Jenkins Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r--sc/source/ui/inc/viewdata.hxx4
-rw-r--r--sc/source/ui/view/gridwin4.cxx3
-rw-r--r--sc/source/ui/view/tabview.cxx39
-rw-r--r--sc/source/ui/view/viewdata.cxx24
4 files changed, 36 insertions, 34 deletions
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 52da7fba5c5b..24dd5e69a275 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -161,13 +161,15 @@ class ScBoundsProvider
const bool bColumnHeader;
const index_type MAX_INDEX;
+ double mfPPTX;
+ double mfPPTY;
index_type nFirstIndex;
index_type nSecondIndex;
long nFirstPositionPx;
long nSecondPositionPx;
public:
- ScBoundsProvider(ScDocument* pD, SCTAB nT, bool bColumnHeader);
+ ScBoundsProvider(const ScViewData &rView, SCTAB nT, bool bColumnHeader);
void GetStartIndexAndPosition(SCCOL& nIndex, long& nPosition) const;
void GetEndIndexAndPosition(SCCOL& nIndex, long& nPosition) const;
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 9f924931b09b..acaa81842a97 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1086,7 +1086,6 @@ namespace
const bool bColumnHeader = std::is_same<IndexType, SCCOL>::value;
SCTAB nTab = pViewData->GetTabNo();
- ScDocument* pDoc = pViewData->GetDocument();
IndexType nStartIndex = -1;
IndexType nEndIndex = -1;
@@ -1098,7 +1097,7 @@ namespace
const auto& rStartNearest = rPositionHelper.getNearestByPosition(nTileStartPosPx);
const auto& rEndNearest = rPositionHelper.getNearestByPosition(nTileEndPosPx);
- ScBoundsProvider aBoundsProvider(pDoc, nTab, bColumnHeader);
+ ScBoundsProvider aBoundsProvider(*pViewData, nTab, bColumnHeader);
aBoundsProvider.Compute(rStartNearest, rEndNearest, nTileStartPosPx, nTileEndPosPx);
aBoundsProvider.GetStartIndexAndPosition(nStartIndex, nStartPosPx); ++nStartIndex;
aBoundsProvider.GetEndIndexAndPosition(nEndIndex, nEndPosPx);
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index 807dc27d4993..ff0dc196d82f 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -2310,16 +2310,16 @@ void ScTabView::SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const std::vector<ed
namespace
{
-long lcl_GetRowHeightPx(const ScDocument* pDoc, SCROW nRow, SCTAB nTab)
+long lcl_GetRowHeightPx(const ScViewData &rViewData, SCROW nRow, SCTAB nTab)
{
- const sal_uInt16 nSize = pDoc->GetRowHeight(nRow, nTab);
- return ScViewData::ToPixel(nSize, 1.0 / TWIPS_PER_PIXEL);
+ const sal_uInt16 nSize = rViewData.GetDocument()->GetRowHeight(nRow, nTab);
+ return ScViewData::ToPixel(nSize, rViewData.GetPPTY());
}
-long lcl_GetColWidthPx(const ScDocument* pDoc, SCCOL nCol, SCTAB nTab)
+long lcl_GetColWidthPx(const ScViewData &rViewData, SCCOL nCol, SCTAB nTab)
{
- const sal_uInt16 nSize = pDoc->GetColWidth(nCol, nTab);
- return ScViewData::ToPixel(nSize, 1.0 / TWIPS_PER_PIXEL);
+ const sal_uInt16 nSize = rViewData.GetDocument()->GetColWidth(nCol, nTab);
+ return ScViewData::ToPixel(nSize, rViewData.GetPPTX());
}
void lcl_getGroupIndexes(const ScOutlineArray& rArray, SCCOLROW nStart, SCCOLROW nEnd, std::vector<size_t>& rGroupIndexes)
@@ -2495,13 +2495,13 @@ OUString ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle)
{
SAL_INFO("sc.lok.header", "Row Header: compute start/end rows.");
long nEndHeightPx = 0;
- long nRectTopPx = rRectangle.Top() / TWIPS_PER_PIXEL;
- long nRectBottomPx = rRectangle.Bottom() / TWIPS_PER_PIXEL;
+ long nRectTopPx = rRectangle.Top() * aViewData.GetPPTX();
+ long nRectBottomPx = rRectangle.Bottom() * aViewData.GetPPTY();
const auto& rTopNearest = aViewData.GetLOKHeightHelper().getNearestByPosition(nRectTopPx);
const auto& rBottomNearest = aViewData.GetLOKHeightHelper().getNearestByPosition(nRectBottomPx);
- ScBoundsProvider aBoundingRowsProvider(pDoc, nTab, /*bColumnHeader: */ false);
+ ScBoundsProvider aBoundingRowsProvider(aViewData, nTab, /*bColumnHeader: */ false);
aBoundingRowsProvider.Compute(rTopNearest, rBottomNearest, nRectTopPx, nRectBottomPx);
aBoundingRowsProvider.EnlargeBy(2);
aBoundingRowsProvider.GetStartIndexAndPosition(nStartRow, nStartHeightPx);
@@ -2591,7 +2591,7 @@ OUString ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle)
{
OUString aText = OUString::number(nStartRow + 1);
aBuffer.append("{ \"text\": \"").append(aText).append("\", ");
- aBuffer.append("\"size\": \"").append(OUString::number(nTotalPixels * TWIPS_PER_PIXEL)).append("\", ");
+ aBuffer.append("\"size\": \"").append(OUString::number(nTotalPixels / aViewData.GetPPTX())).append("\", ");
aBuffer.append("\"groupLevels\": \"").append(OUString::number(nRowGroupDepth)).append("\" }");
}
@@ -2601,14 +2601,15 @@ OUString ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle)
for (SCROW nRow = nStartRow + 1; nRow <= nEndRow; ++nRow)
{
// nSize will be 0 for hidden rows.
- const long nSizePx = lcl_GetRowHeightPx(pDoc, nRow, nTab);
+ const long nSizePx = lcl_GetRowHeightPx(aViewData, nRow, nTab);
nTotalPixels += nSizePx;
- const long nTotalTwips = nTotalPixels * TWIPS_PER_PIXEL;
+ const long nTotalTwips = nTotalPixels / aViewData.GetPPTY();
if (bRangeHeaderSupport && nRowGroupDepth > 0)
{
lcl_createGroupsData(nRow, nEndRow, nSizePx, nTotalTwips,
- *pRowArray, aRowGroupIndexes, aRowGroupStartPositions, aRowGroupsBuffer);
+ *pRowArray, aRowGroupIndexes, aRowGroupStartPositions,
+ aRowGroupsBuffer);
}
if (bRangeHeaderSupport && nRow < nEndRow && nSizePx == nPrevSizePx)
@@ -2638,13 +2639,13 @@ OUString ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle)
{
SAL_INFO("sc.lok.header", "Column Header: compute start/end columns.");
long nEndWidthPx = 0;
- long nRectLeftPx = rRectangle.Left() / TWIPS_PER_PIXEL;
- long nRectRightPx = rRectangle.Right() / TWIPS_PER_PIXEL;
+ long nRectLeftPx = rRectangle.Left() * aViewData.GetPPTX();
+ long nRectRightPx = rRectangle.Right() * aViewData.GetPPTY();
const auto& rLeftNearest = aViewData.GetLOKWidthHelper().getNearestByPosition(nRectLeftPx);
const auto& rRightNearest = aViewData.GetLOKWidthHelper().getNearestByPosition(nRectRightPx);
- ScBoundsProvider aBoundingColsProvider(pDoc, nTab, /*bColumnHeader: */ true);
+ ScBoundsProvider aBoundingColsProvider(aViewData, nTab, /*bColumnHeader: */ true);
aBoundingColsProvider.Compute(rLeftNearest, rRightNearest, nRectLeftPx, nRectRightPx);
aBoundingColsProvider.EnlargeBy(2);
aBoundingColsProvider.GetStartIndexAndPosition(nStartCol, nStartWidthPx);
@@ -2734,7 +2735,7 @@ OUString ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle)
{
OUString aText = OUString::number(nStartCol + 1);
aBuffer.append("{ \"text\": \"").append(aText).append("\", ");
- aBuffer.append("\"size\": \"").append(OUString::number(nTotalPixels * TWIPS_PER_PIXEL)).append("\", ");
+ aBuffer.append("\"size\": \"").append(OUString::number(nTotalPixels / aViewData.GetPPTY())).append("\", ");
aBuffer.append("\"groupLevels\": \"").append(OUString::number(nColGroupDepth)).append("\" }");
}
@@ -2744,9 +2745,9 @@ OUString ScTabView::getRowColumnHeaders(const tools::Rectangle& rRectangle)
for (SCCOL nCol = nStartCol + 1; nCol <= nEndCol; ++nCol)
{
// nSize will be 0 for hidden columns.
- const long nSizePx = lcl_GetColWidthPx(pDoc, nCol, nTab);
+ const long nSizePx = lcl_GetColWidthPx(aViewData, nCol, nTab);
nTotalPixels += nSizePx;
- const long nTotalTwips = nTotalPixels * TWIPS_PER_PIXEL;
+ const long nTotalTwips = nTotalPixels / aViewData.GetPPTY();
if (bRangeHeaderSupport && nColGroupDepth > 0)
{
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 0eb317ff1eca..97dbaacfac2a 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -280,11 +280,13 @@ long ScPositionHelper::computePosition(index_type nIndex, const std::function<lo
return nTotalPixels;
}
-ScBoundsProvider::ScBoundsProvider(ScDocument* pD, SCTAB nT, bool bColHeader)
- : pDoc(pD)
+ScBoundsProvider::ScBoundsProvider(const ScViewData &rView, SCTAB nT, bool bColHeader)
+ : pDoc(rView.GetDocument())
, nTab(nT)
, bColumnHeader(bColHeader)
- , MAX_INDEX(bColHeader ? pD->MaxCol() : MAXTILEDROW)
+ , MAX_INDEX(bColHeader ? pDoc->MaxCol() : MAXTILEDROW)
+ , mfPPTX(rView.GetPPTX())
+ , mfPPTY(rView.GetPPTY())
, nFirstIndex(-1)
, nSecondIndex(-1)
, nFirstPositionPx(-1)
@@ -322,7 +324,7 @@ void ScBoundsProvider::GetEndIndexAndPosition(SCROW& nIndex, long& nPosition) co
long ScBoundsProvider::GetSize(index_type nIndex) const
{
const sal_uInt16 nSize = bColumnHeader ? pDoc->GetColWidth(nIndex, nTab) : pDoc->GetRowHeight(nIndex, nTab);
- return ScViewData::ToPixel(nSize, 1.0 / TWIPS_PER_PIXEL);
+ return ScViewData::ToPixel(nSize, bColumnHeader ? mfPPTX : mfPPTY);
}
void ScBoundsProvider::GetIndexAndPos(index_type nNearestIndex, long nNearestPosition,
@@ -1372,10 +1374,9 @@ void ScViewData::SetMaxTiledCol( SCCOL nNewMaxCol )
nNewMaxCol = pDoc->MaxCol();
const SCTAB nTab = GetTabNo();
- ScDocument* pThisDoc = pDoc;
- auto GetColWidthPx = [pThisDoc, nTab](SCCOL nCol) {
- const sal_uInt16 nSize = pThisDoc->GetColWidth(nCol, nTab);
- const long nSizePx = ScViewData::ToPixel(nSize, 1.0 / TWIPS_PER_PIXEL);
+ auto GetColWidthPx = [this, nTab](SCCOL nCol) {
+ const sal_uInt16 nSize = this->pDoc->GetColWidth(nCol, nTab);
+ const long nSizePx = ScViewData::ToPixel(nSize, nPPTX);
return nSizePx;
};
@@ -1398,10 +1399,9 @@ void ScViewData::SetMaxTiledRow( SCROW nNewMaxRow )
nNewMaxRow = MAXTILEDROW;
const SCTAB nTab = GetTabNo();
- ScDocument* pThisDoc = pDoc;
- auto GetRowHeightPx = [pThisDoc, nTab](SCROW nRow) {
- const sal_uInt16 nSize = pThisDoc->GetRowHeight(nRow, nTab);
- const long nSizePx = ScViewData::ToPixel(nSize, 1.0 / TWIPS_PER_PIXEL);
+ auto GetRowHeightPx = [this, nTab](SCROW nRow) {
+ const sal_uInt16 nSize = this->pDoc->GetRowHeight(nRow, nTab);
+ const long nSizePx = ScViewData::ToPixel(nSize, nPPTY);
return nSizePx;
};