diff options
-rw-r--r-- | desktop/source/lib/init.cxx | 24 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 9 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.hxx | 13 |
3 files changed, 41 insertions, 5 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 5b5381c002fa..a8d5e87eed08 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -678,6 +678,11 @@ static void doc_paintWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId const int nX, const int nY, const int nWidth, const int nHeight); +static void doc_paintWindowDPI(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, unsigned char* pBuffer, + const int nX, const int nY, + const int nWidth, const int nHeight, + const double fDPIScale); + static void doc_postWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, int nAction); static char* doc_getPartInfo(LibreOfficeKitDocument* pThis, int nPart); @@ -733,6 +738,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone m_pDocumentClass->getPartHash = doc_getPartHash; m_pDocumentClass->paintWindow = doc_paintWindow; + m_pDocumentClass->paintWindowDPI = doc_paintWindowDPI; m_pDocumentClass->postWindow = doc_postWindow; m_pDocumentClass->setViewLanguage = doc_setViewLanguage; @@ -3566,11 +3572,20 @@ unsigned char* doc_renderFont(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pTh return nullptr; } -static void doc_paintWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindowId, +static void doc_paintWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, unsigned char* pBuffer, const int nX, const int nY, const int nWidth, const int nHeight) { + doc_paintWindowDPI(pThis, nLOKWindowId, pBuffer, nX, nY, nWidth, nHeight, 1.0); +} + +static void doc_paintWindowDPI(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindowId, + unsigned char* pBuffer, + const int nX, const int nY, + const int nWidth, const int nHeight, + const double fDPIScale) +{ SolarMutexGuard aGuard; if (gImpl) gImpl->maLastExceptionMsg.clear(); @@ -3582,6 +3597,11 @@ static void doc_paintWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWind return; } + // Setup cairo to draw with the changed DPI scale (and return back to 1.0 + // when the painting finishes) + comphelper::ScopeGuard dpiScaleGuard([]() { comphelper::LibreOfficeKit::setDPIScale(1.0); }); + comphelper::LibreOfficeKit::setDPIScale(fDPIScale); + #if defined(IOS) CGContextRef cgc = CGBitmapContextCreate(pBuffer, nWidth, nHeight, 8, nWidth*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGImageByteOrder32Little); @@ -3615,7 +3635,7 @@ static void doc_paintWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWind pDevice->SetOutputSizePixelScaleOffsetAndBuffer(Size(nWidth, nHeight), Fraction(1.0), Point(), pBuffer); MapMode aMapMode(pDevice->GetMapMode()); - aMapMode.SetOrigin(Point(-nX, -nY)); + aMapMode.SetOrigin(Point(-(nX / fDPIScale), -(nY / fDPIScale))); pDevice->SetMapMode(aMapMode); comphelper::LibreOfficeKit::setDialogPainting(true); diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 0799584d3097..f8021065af1e 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -309,6 +309,15 @@ struct _LibreOfficeKitDocumentClass /// @see lok::Document::getPartInfo(). char* (*getPartInfo) (LibreOfficeKitDocument* pThis, int nPart); + /// Paints window with given id to the buffer with the give DPI scale + /// (every pixel is dpiscale-times larger). + /// @see lok::Document::paintWindow(). + void (*paintWindowDPI) (LibreOfficeKitDocument* pThis, unsigned nWindowId, + unsigned char* pBuffer, + const int x, const int y, + const int width, const int height, + const double dpiscale); + #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY }; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 232eada69821..51d072331762 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -164,16 +164,23 @@ public: * @param y y-coordinate from where the dialog should start painting * @param width The width of the dialog image to be painted * @param height The height of the dialog image to be painted + * @param dpiscale The dpi scale value used by the client. Please note + * that the x, y, width, height are supposed to be the + * values with dpiscale applied (ie. dialog covering + * 100x100 "normal" pixels with dpiscale '2' will have + * 200x200 width x height), so that it is easy to compute + * the buffer sizes etc. */ void paintWindow(unsigned nWindowId, unsigned char* pBuffer, const int x, const int y, const int width, - const int height) + const int height, + const double dpiscale = 1.0) { - return mpDoc->pClass->paintWindow(mpDoc, nWindowId, pBuffer, - x, y, width, height); + return mpDoc->pClass->paintWindowDPI(mpDoc, nWindowId, pBuffer, + x, y, width, height, dpiscale); } /** |