Kaydet (Commit) 3ace447b 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
üst c9b0766a
......@@ -38,7 +38,7 @@ static bool g_bLocalRendering(false);
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);
void setActive(bool bActive)
......
......@@ -2134,15 +2134,16 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
#if defined(UNX) && !defined(MACOSX) && !defined(ENABLE_HEADLESS)
// Painting of zoomed or hi-dpi spreadsheets is special, we actually draw
// everything at 100%, and only set cairo's scale factor accordingly, so
// that everything is painted bigger or smaller. This is different to
// what Calc's internal scaling would do - because that one is trying to
// fit the lines between cells to integer multiples of pixels.
// Painting of zoomed or hi-dpi spreadsheets is special, we actually draw everything at 100%,
// and only set cairo's (or CoreGraphic's, in the iOS case) scale factor accordingly, so that
// everything is painted bigger or smaller. This is different to what Calc's internal scaling
// 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;
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);
comphelper::LibreOfficeKit::setDPIScale(fDPIScaleX);
}
......@@ -2151,7 +2152,7 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
CGContextRef cgc = CGBitmapContextCreate(pBuffer, nCanvasWidth, nCanvasHeight, 8, nCanvasWidth*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGImageByteOrder32Little);
CGContextTranslateCTM(cgc, 0, nCanvasHeight);
CGContextScaleCTM(cgc, 1, -1);
CGContextScaleCTM(cgc, fDPIScaleX, -fDPIScaleX);
doc_paintTileToCGContext(pThis, (void*) cgc, nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
......@@ -3618,8 +3619,8 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKW
return;
}
// Setup cairo to draw with the changed DPI scale (and return back to 1.0
// when the painting finishes)
// Setup cairo (or CoreGraphics, in the iOS case) 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);
......@@ -3628,7 +3629,7 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKW
CGContextRef cgc = CGBitmapContextCreate(pBuffer, nWidth, nHeight, 8, nWidth*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGImageByteOrder32Little);
CGContextTranslateCTM(cgc, 0, nHeight);
CGContextScaleCTM(cgc, 1, -1);
CGContextScaleCTM(cgc, fDPIScale, -fDPIScale);
SystemGraphicsData aData;
aData.rCGContext = cgc;
......@@ -3639,7 +3640,7 @@ static void doc_paintWindowDPI(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKW
pDevice->SetOutputSizePixel(Size(nWidth, nHeight));
MapMode aMapMode(pDevice->GetMapMode());
aMapMode.SetOrigin(Point(-nX, -nY));
aMapMode.SetOrigin(Point(-(nX / fDPIScale), -(nY / fDPIScale)));
pDevice->SetMapMode(aMapMode);
comphelper::LibreOfficeKit::setDialogPainting(true);
......
......@@ -1112,10 +1112,10 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
// not care about any zoom settings.
//
// But until that happens, we actually draw everything at 100%, and only
// set cairo's scale factor accordingly, so that everything is painted
// bigger or smaller. This is different to what Calc's internal scaling
// would do - because that one is trying to fit the lines between cells to
// integer multiples of pixels.
// set cairo's or CoreGraphic's scale factor accordingly, so that everything
// is painted bigger or smaller. This is different to what Calc's internal
// scaling would do - because that one is trying to fit the lines between
// cells to integer multiples of pixels.
//
// See also desktop/source/lib/init.cxx for details, where we have to set
// the stuff accordingly for the VirtualDevice creation.
......@@ -1126,8 +1126,8 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
Fraction aFracY(long(256 * TWIPS_PER_PIXEL), 3840);
pViewData->SetZoom(aFracX, aFracY, true);
// Cairo scales for us, we have to compensate for that, otherwise we are
// painting too far away
// Cairo or CoreGraphics scales for us, we have to compensate for that,
// otherwise we are painting too far away
const double fDPIScale = comphelper::LibreOfficeKit::getDPIScale();
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