Rebased ref, commits from common ancestor: commit a1971e6d0e962b1553afc02ff61ffb7319fc222e Author: Michael Meeks <michael.me...@collabora.com> AuthorDate: Fri Nov 1 15:40:43 2019 +0000 Commit: Michael Meeks <michael.me...@collabora.com> CommitDate: Tue Nov 5 17:46:07 2019 +0000
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 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..3a54172c8760 100644 --- a/sc/source/ui/view/gridwin4.cxx +++ b/sc/source/ui/view/gridwin4.cxx @@ -1098,7 +1098,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..64b3daed8b39 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 = this->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 = this->ToPixel(nSize, nPPTY); return nSizePx; }; commit 2d3bc84146bca1c5923ff48869d8e5903773d3cd Author: Michael Meeks <michael.me...@collabora.com> AuthorDate: Mon Nov 4 15:44:04 2019 +0000 Commit: Michael Meeks <michael.me...@collabora.com> CommitDate: Tue Nov 5 17:46:04 2019 +0000 lok: share conversion of OUString to C strings. Change-Id: I0178f673dc1e59d9fba8f3daae532f19b46e4d36 diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index e46d11dee080..5b5b301cdee9 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -260,6 +260,20 @@ static OUString getUString(const char* pString) return OStringToOUString(sString, RTL_TEXTENCODING_UTF8); } +// Tolerate embedded \0s etc. +static char *convertOString(const OString &rStr) +{ + char* pMemory = static_cast<char*>(malloc(rStr.getLength() + 1)); + assert(pMemory); // don't tolerate failed allocations. + memcpy(pMemory, rStr.getStr(), rStr.getLength() + 1); + return pMemory; +} + +static char *convertOUString(const OUString &aStr) +{ + return convertOString(OUStringToOString(aStr, RTL_TEXTENCODING_UTF8)); +} + /// Try to convert a relative URL to an absolute one, unless it already looks like a URL. static OUString getAbsoluteURL(const char* pURL) { @@ -2544,13 +2558,7 @@ static char* doc_getPartInfo(LibreOfficeKitDocument* pThis, int nPart) return nullptr; } - OUString aPartInfo = pDoc->getPartInfo( nPart ); - OString aString = OUStringToOString(aPartInfo, RTL_TEXTENCODING_UTF8); - - char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1)); - assert(pMemory); // Don't handle OOM conditions - strcpy(pMemory, aString.getStr()); - return pMemory; + return convertOUString(pDoc->getPartInfo(nPart)); } static void doc_selectPart(LibreOfficeKitDocument* pThis, int nPart, int nSelect) @@ -2599,13 +2607,7 @@ static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis) return nullptr; } - OUString sRectangles = pDoc->getPartPageRectangles(); - OString aString = OUStringToOString(sRectangles, RTL_TEXTENCODING_UTF8); - char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1)); - assert(pMemory); // Don't handle OOM conditions - strcpy(pMemory, aString.getStr()); - return pMemory; - + return convertOUString(pDoc->getPartPageRectangles()); } static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart) @@ -2622,13 +2624,7 @@ static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart) return nullptr; } - OUString sName = pDoc->getPartName( nPart ); - OString aString = OUStringToOString(sName, RTL_TEXTENCODING_UTF8); - char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1)); - assert(pMemory); // Don't handle OOM conditions - strcpy(pMemory, aString.getStr()); - return pMemory; - + return convertOUString(pDoc->getPartName(nPart)); } static char* doc_getPartHash(LibreOfficeKitDocument* pThis, int nPart) @@ -2645,13 +2641,7 @@ static char* doc_getPartHash(LibreOfficeKitDocument* pThis, int nPart) return nullptr; } - OUString sHash = pDoc->getPartHash(nPart); - OString aString = OUStringToOString(sHash, RTL_TEXTENCODING_UTF8); - char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1)); - assert(pMemory); // Don't handle OOM conditions - strcpy(pMemory, aString.getStr()); - return pMemory; - + return convertOUString(pDoc->getPartHash(nPart)); } static void doc_setPartMode(LibreOfficeKitDocument* pThis, @@ -3746,14 +3736,6 @@ static bool getFromTransferrable( return true; } -// Tolerate embedded \0s etc. -static char *convertOString(const OString &rStr) -{ - char* pMemory = static_cast<char*>(malloc(rStr.getLength() + 1)); - memcpy(pMemory, rStr.getStr(), rStr.getLength() + 1); - return pMemory; -} - static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMimeType, char** pUsedMimeType) { comphelper::ProfileZone aZone("doc_getTextSelection"); @@ -3908,7 +3890,7 @@ static int doc_getClipboard(LibreOfficeKitDocument* pThis, else { (*pOutSizes)[i] = aRet.getLength(); - (*pOutStreams)[i] = convertOString(aRet); + (*pOutStreams)[i] = convertOString(aRet); } } @@ -4484,13 +4466,8 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo OUString aHeaders = pDoc->getRowColumnHeaders(aRectangle); if (aHeaders.isEmpty()) return nullptr; - - OString aString = OUStringToOString(aHeaders, RTL_TEXTENCODING_UTF8); - - char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1)); - assert(pMemory); // Don't handle OOM conditions - strcpy(pMemory, aString.getStr()); - return pMemory; + else + return convertOUString(aHeaders); } else if (aCommand.startsWith(aCellCursor)) { @@ -4537,12 +4514,7 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo while (nParamIndex >= 0); } - OString aString = pDoc->getCellCursor(nOutputWidth, nOutputHeight, nTileWidth, nTileHeight); - - char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1)); - assert(pMemory); // Don't handle OOM conditions - strcpy(pMemory, aString.getStr()); - return pMemory; + return convertOString(pDoc->getCellCursor(nOutputWidth, nOutputHeight, nTileWidth, nTileHeight)); } else if (aCommand.startsWith(aFontSubset)) { @@ -5104,11 +5076,7 @@ static char* lo_getError (LibreOfficeKit *pThis) SolarMutexGuard aGuard; LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis); - OString aString = OUStringToOString(pLib->maLastExceptionMsg, RTL_TEXTENCODING_UTF8); - char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1)); - assert(pMemory); // Don't handle OOM conditions - strcpy(pMemory, aString.getStr()); - return pMemory; + return convertOUString(pLib->maLastExceptionMsg); } static void lo_freeError(char* pFree) @@ -5200,12 +5168,7 @@ static char* lo_getVersionInfo(SAL_UNUSED_PARAMETER LibreOfficeKit* /*pThis*/) "\"BuildId\": \"%BUILDID\" " "}" ); - const OString sVersionStr = OUStringToOString(ReplaceStringHookProc(sVersionStrTemplate), RTL_TEXTENCODING_UTF8); - - char* pVersion = static_cast<char*>(malloc(sVersionStr.getLength() + 1)); - assert(pVersion); // Don't handle OOM conditions - strcpy(pVersion, sVersionStr.getStr()); - return pVersion; + return convertOUString(ReplaceStringHookProc(sVersionStrTemplate)); } static void force_c_locale() commit 655ad3399315397a5fdb0929e26167c59a34126a Author: Michael Meeks <michael.me...@collabora.com> AuthorDate: Mon Nov 4 15:42:07 2019 +0000 Commit: Michael Meeks <michael.me...@collabora.com> CommitDate: Tue Nov 5 17:46:03 2019 +0000 lok: avoid ILibreOfficeKitNotifier null ptr de-reference on shutdown. Change-Id: I79c8fa3ebf7ed457b7bebb4da536eb83f5cac567 diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index b3df086f64be..0072ec49f1b8 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -3227,7 +3227,7 @@ ILibreOfficeKitNotifier::~ILibreOfficeKitNotifier() for (auto it = GetLOKWindowsMap().begin(); it != GetLOKWindowsMap().end();) { WindowImpl* pWindowImpl = it->second->ImplGetWindowImpl(); - if (pWindowImpl->mpLOKNotifier == this) + if (pWindowImpl && pWindowImpl->mpLOKNotifier == this) { pWindowImpl->mpLOKNotifier = nullptr; pWindowImpl->mnLOKWindowId = 0; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits