Kaydet (Commit) da0c3f39 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Use the correct DPI scaling factor in LibreOfficeKit for iOS, too

Fixes the rendering of spreadsheets in the iOS app. (The cell area was
rendered at half the scale of the row and column headers.)

Actual code change only in desktop/source/lib/init.cxx, but update
related comments elsewhere to mention CoreGraphics, too, and not just
cairo.

Change-Id: Ife99c6a2d58e592cfea3b4ed1ab09c19fba77e72
(cherry picked from commit 3ace447b)
Reviewed-on: https://gerrit.libreoffice.org/63919
Tested-by: Jenkins
Reviewed-by: 's avatarTor Lillqvist <tml@collabora.com>
üst 8f575690
...@@ -38,7 +38,7 @@ static bool g_bLocalRendering(false); ...@@ -38,7 +38,7 @@ static bool g_bLocalRendering(false);
static LanguageTag g_aLanguageTag("en-US", true); static LanguageTag g_aLanguageTag("en-US", true);
/// Scaling of the cairo canvas painting for hi-dpi or zooming in Calc. /// Scaling of the cairo or CoreGraphics canvas painting for hi-dpi or zooming in Calc.
static double g_fDPIScale(1.0); static double g_fDPIScale(1.0);
void setActive(bool bActive) void setActive(bool bActive)
......
...@@ -2134,15 +2134,16 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis, ...@@ -2134,15 +2134,16 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
#if defined(UNX) && !defined(MACOSX) && !defined(ENABLE_HEADLESS) #if defined(UNX) && !defined(MACOSX) && !defined(ENABLE_HEADLESS)
// Painting of zoomed or hi-dpi spreadsheets is special, we actually draw // Painting of zoomed or hi-dpi spreadsheets is special, we actually draw everything at 100%,
// everything at 100%, and only set cairo's scale factor accordingly, so // and only set cairo's (or CoreGraphic's, in the iOS case) scale factor accordingly, so that
// that everything is painted bigger or smaller. This is different to // everything is painted bigger or smaller. This is different to what Calc's internal scaling
// what Calc's internal scaling would do - because that one is trying to // would do - because that one is trying to fit the lines between cells to integer multiples of
// fit the lines between cells to integer multiples of pixels. // pixels.
comphelper::ScopeGuard dpiScaleGuard([]() { comphelper::LibreOfficeKit::setDPIScale(1.0); }); comphelper::ScopeGuard dpiScaleGuard([]() { comphelper::LibreOfficeKit::setDPIScale(1.0); });
double fDPIScaleX = 1;
if (doc_getDocumentType(pThis) == LOK_DOCTYPE_SPREADSHEET) if (doc_getDocumentType(pThis) == LOK_DOCTYPE_SPREADSHEET)
{ {
double fDPIScaleX = (nCanvasWidth * 3840.0) / (256.0 * nTileWidth); fDPIScaleX = (nCanvasWidth * 3840.0) / (256.0 * nTileWidth);
assert(fabs(fDPIScaleX - ((nCanvasHeight * 3840.0) / (256.0 * nTileHeight))) < 0.0001); assert(fabs(fDPIScaleX - ((nCanvasHeight * 3840.0) / (256.0 * nTileHeight))) < 0.0001);
comphelper::LibreOfficeKit::setDPIScale(fDPIScaleX); comphelper::LibreOfficeKit::setDPIScale(fDPIScaleX);
} }
...@@ -2151,7 +2152,7 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis, ...@@ -2151,7 +2152,7 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
CGContextRef cgc = CGBitmapContextCreate(pBuffer, nCanvasWidth, nCanvasHeight, 8, nCanvasWidth*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGImageByteOrder32Little); CGContextRef cgc = CGBitmapContextCreate(pBuffer, nCanvasWidth, nCanvasHeight, 8, nCanvasWidth*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGImageByteOrder32Little);
CGContextTranslateCTM(cgc, 0, nCanvasHeight); CGContextTranslateCTM(cgc, 0, nCanvasHeight);
CGContextScaleCTM(cgc, 1, -1); CGContextScaleCTM(cgc, fDPIScaleX, -fDPIScaleX);
doc_paintTileToCGContext(pThis, (void*) cgc, nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight); doc_paintTileToCGContext(pThis, (void*) cgc, nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
...@@ -3618,8 +3619,8 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKW ...@@ -3618,8 +3619,8 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKW
return; return;
} }
// Setup cairo to draw with the changed DPI scale (and return back to 1.0 // Setup cairo (or CoreGraphics, in the iOS case) to draw with the changed DPI scale (and return
// when the painting finishes) // back to 1.0 when the painting finishes)
comphelper::ScopeGuard dpiScaleGuard([]() { comphelper::LibreOfficeKit::setDPIScale(1.0); }); comphelper::ScopeGuard dpiScaleGuard([]() { comphelper::LibreOfficeKit::setDPIScale(1.0); });
comphelper::LibreOfficeKit::setDPIScale(fDPIScale); comphelper::LibreOfficeKit::setDPIScale(fDPIScale);
...@@ -3628,7 +3629,7 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKW ...@@ -3628,7 +3629,7 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKW
CGContextRef cgc = CGBitmapContextCreate(pBuffer, nWidth, nHeight, 8, nWidth*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGImageByteOrder32Little); CGContextRef cgc = CGBitmapContextCreate(pBuffer, nWidth, nHeight, 8, nWidth*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGImageByteOrder32Little);
CGContextTranslateCTM(cgc, 0, nHeight); CGContextTranslateCTM(cgc, 0, nHeight);
CGContextScaleCTM(cgc, 1, -1); CGContextScaleCTM(cgc, fDPIScale, -fDPIScale);
SystemGraphicsData aData; SystemGraphicsData aData;
aData.rCGContext = cgc; aData.rCGContext = cgc;
...@@ -3639,7 +3640,7 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKW ...@@ -3639,7 +3640,7 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKW
pDevice->SetOutputSizePixel(Size(nWidth, nHeight)); pDevice->SetOutputSizePixel(Size(nWidth, nHeight));
MapMode aMapMode(pDevice->GetMapMode()); MapMode aMapMode(pDevice->GetMapMode());
aMapMode.SetOrigin(Point(-nX, -nY)); aMapMode.SetOrigin(Point(-(nX / fDPIScale), -(nY / fDPIScale)));
pDevice->SetMapMode(aMapMode); pDevice->SetMapMode(aMapMode);
comphelper::LibreOfficeKit::setDialogPainting(true); comphelper::LibreOfficeKit::setDialogPainting(true);
......
...@@ -1112,10 +1112,10 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice, ...@@ -1112,10 +1112,10 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
// not care about any zoom settings. // not care about any zoom settings.
// //
// But until that happens, we actually draw everything at 100%, and only // But until that happens, we actually draw everything at 100%, and only
// set cairo's scale factor accordingly, so that everything is painted // set cairo's or CoreGraphic's scale factor accordingly, so that everything
// bigger or smaller. This is different to what Calc's internal scaling // is painted bigger or smaller. This is different to what Calc's internal
// would do - because that one is trying to fit the lines between cells to // scaling would do - because that one is trying to fit the lines between
// integer multiples of pixels. // cells to integer multiples of pixels.
// //
// See also desktop/source/lib/init.cxx for details, where we have to set // See also desktop/source/lib/init.cxx for details, where we have to set
// the stuff accordingly for the VirtualDevice creation. // the stuff accordingly for the VirtualDevice creation.
...@@ -1126,8 +1126,8 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice, ...@@ -1126,8 +1126,8 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
Fraction aFracY(long(256 * TWIPS_PER_PIXEL), 3840); Fraction aFracY(long(256 * TWIPS_PER_PIXEL), 3840);
pViewData->SetZoom(aFracX, aFracY, true); pViewData->SetZoom(aFracX, aFracY, true);
// Cairo scales for us, we have to compensate for that, otherwise we are // Cairo or CoreGraphics scales for us, we have to compensate for that,
// painting too far away // otherwise we are painting too far away
const double fDPIScale = comphelper::LibreOfficeKit::getDPIScale(); const double fDPIScale = comphelper::LibreOfficeKit::getDPIScale();
const double fTilePosXPixel = static_cast<double>(nTilePosX) * nOutputWidth / (nTileWidth * fDPIScale); const double fTilePosXPixel = static_cast<double>(nTilePosX) * nOutputWidth / (nTileWidth * fDPIScale);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment