summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-06-03 12:50:47 +0900
committerTomaž Vajngerl <quikee@gmail.com>2019-06-03 10:32:02 +0200
commit80c5c68fede7af89e7a3732408e97364498fbbcd (patch)
treee765a5ca1c0c97dee7d0268df7c9bcd33f52b938 /desktop
parent8b8c3a95e42965c997f3bfd2e7459e83034d33da (diff)
LOK: Factor out iOS painting code
Change-Id: Ica706842003fe60ba864e013614eb535580446bb Reviewed-on: https://gerrit.libreoffice.org/73363 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/lib/init.cxx72
1 files changed, 44 insertions, 28 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index aea40f41a2cb..2a19ef820c1a 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1598,6 +1598,45 @@ ITiledRenderable* getTiledRenderable(LibreOfficeKitDocument* pThis)
return dynamic_cast<ITiledRenderable*>(pDocument->mxComponent.get());
}
+#ifdef IOS
+void paintTileToCGContext(ITiledRenderable* pDocument,
+ void* rCGContext, const Size nCanvasSize,
+ const int nTilePosX, const int nTilePosY,
+ const int nTileWidth, const int nTileHeight)
+{
+ SystemGraphicsData aData;
+ aData.rCGContext = reinterpret_cast<CGContextRef>(rCGContext);
+
+ ScopedVclPtrInstance<VirtualDevice> pDevice(&aData, Size(1, 1), DeviceFormat::DEFAULT);
+ pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+ pDevice->SetOutputSizePixel(nCanvasSize);
+ pDocument->paintTile(*pDevice, nCanvasSize.Width(), nCanvasSize.Height(),
+ nTilePosX, nTilePosY, nTileWidth, nTileHeight);
+}
+
+void paintTileIOS(LibreOfficeKitDocument* pThis,
+ unsigned char* pBuffer,
+ const int nCanvasWidth, const int nCanvasHeight, const double fDPIScale,
+ const int nTilePosX, const int nTilePosY,
+ const int nTileWidth, const int nTileHeight)
+{
+ CGContextRef pCGContext = CGBitmapContextCreate(pBuffer, nCanvasWidth, nCanvasHeight, 8,
+ nCanvasWidth * 4, CGColorSpaceCreateDeviceRGB(),
+ kCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little);
+
+ // Use the vcl.cg tag even if this code is not in vcl, to match all other SAL_INFO logging about Core Graphics, in vcl.
+ SAL_INFO("vcl.cg", "CGBitmapContextCreate(" << nCanvasWidth << "x" << nCanvasHeight << "x32) = " << pCGContext);
+
+ CGContextTranslateCTM(pCGContext, 0, nCanvasHeight);
+ CGContextScaleCTM(pCGContext, fDPIScale, -fDPIScale);
+
+ doc_paintTileToCGContext(pThis, (void*) pCGContext, nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
+
+ SAL_INFO("vcl.cg", "CGContextRelease(" << pCGContext << ")");
+ CGContextRelease(pCGContext);
+}
+#endif
+
} // anonymous namespace
// Wonder global state ...
@@ -2446,7 +2485,7 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
// would do - because that one is trying to fit the lines between cells to integer multiples of
// pixels.
comphelper::ScopeGuard dpiScaleGuard([]() { comphelper::LibreOfficeKit::setDPIScale(1.0); });
- double fDPIScaleX = 1;
+ double fDPIScaleX = 1.0;
if (doc_getDocumentType(pThis) == LOK_DOCTYPE_SPREADSHEET)
{
fDPIScaleX = (nCanvasWidth * 3840.0) / (256.0 * nTileWidth);
@@ -2455,19 +2494,7 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
}
#if defined(IOS)
- CGContextRef cgc = CGBitmapContextCreate(pBuffer, nCanvasWidth, nCanvasHeight, 8, nCanvasWidth*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little);
-
- // Use the vcl.cg tag even if this code is not in vcl, to match all other SAL_INFO logging about Core Graphics, in vcl.
- SAL_INFO( "vcl.cg", "CGBitmapContextCreate(" << nCanvasWidth << "x" << nCanvasHeight << "x32) = " << cgc );
-
- CGContextTranslateCTM(cgc, 0, nCanvasHeight);
- CGContextScaleCTM(cgc, fDPIScaleX, -fDPIScaleX);
-
- doc_paintTileToCGContext(pThis, (void*) cgc, nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
-
- SAL_INFO( "vcl.cg", "CGContextRelease(" << cgc << ")" );
- CGContextRelease(cgc);
-
+ paintTileIOS(pThis, pBuffer, nCanvasWidth, nCanvasHeight, fDPIScaleX, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
#else
ScopedVclPtrInstance< VirtualDevice > pDevice(nullptr, Size(1, 1), DeviceFormat::DEFAULT) ;
@@ -2510,8 +2537,7 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
#ifdef IOS
// This function is separate only to be used by LibreOfficeLight. If that app can be retired, this
-// function's code can be inlined into the iOS part of doc_paintTile().
-
+// function's code can be inlined.
static void doc_paintTileToCGContext(LibreOfficeKitDocument* pThis,
void* rCGContext,
const int nCanvasWidth, const int nCanvasHeight,
@@ -2532,18 +2558,8 @@ static void doc_paintTileToCGContext(LibreOfficeKitDocument* pThis,
return;
}
- SystemGraphicsData aData;
- aData.rCGContext = reinterpret_cast<CGContextRef>(rCGContext);
- // the Size argument is irrelevant, I hope
- ScopedVclPtrInstance<VirtualDevice> pDevice(&aData, Size(1, 1), DeviceFormat::DEFAULT);
-
- pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
-
- pDevice->SetOutputSizePixel(Size(nCanvasWidth, nCanvasHeight));
-
- pDoc->paintTile(*pDevice, nCanvasWidth, nCanvasHeight,
- nTilePosX, nTilePosY, nTileWidth, nTileHeight);
-
+ Size aCanvasSize(nCanvasWidth, nCanvasHeight);
+ paintTileToCGContext(pDoc, rCGContext, aCanvasSize, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
}
#endif