Files
libreoffice/vcl/qt5/Qt5SvpSurface.cxx
Caolán McNamara 6e2a7571e8 tdf#127529 vertical text not drawn in slideshow canvas
because the canvas text drawing impl falls back to using an OutputDevice view
of the canvas to use the vcl text drawing apis to achieve vertical text

To get an OutputDevice view of the canvas there is a specific VirtualDevice
ctor available to create a VirtualDevice that, unlike the normal case, doesn't
have its own specific backing buffer, but instead draws to the underlying target
provided via the SystemGraphicsData arg

The svp/gtk impl missed that understanding and provided an ordinary
VirtualDevice with its own backing buffer, not a VirtualDevice that would draw
to the expected target surface of the canvas. So the vertical text was drawn to
a different surface than the intended one, and was just discarded.

The cairo use in the canvas long precedes the use of cairo in vcl itself.

Seeing as text is now rendered with cairo in all cases where the canvas uses
cairo its probably now pointless for canvas to have its own text rendering
path.

Change-Id: Ie3b0a43ca2b746cbfe25e2d0415315b3d5403cd2
Reviewed-on: https://gerrit.libreoffice.org/80162
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
2019-10-04 20:51:56 +02:00

92 lines
2.5 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <utility>
#include <Qt5SvpSurface.hxx>
#include <Qt5SvpGraphics.hxx>
#include <vcl/sysdata.hxx>
#include <vcl/bitmap.hxx>
#include <vcl/virdev.hxx>
#include <vcl/window.hxx>
#include <basegfx/vector/b2isize.hxx>
namespace
{
Size get_surface_size(cairo_surface_t* surface)
{
cairo_t* cr = cairo_create(surface);
double x1, x2, y1, y2;
cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
cairo_destroy(cr);
return Size(x2 - x1, y2 - y1);
}
}
namespace cairo
{
Qt5SvpSurface::Qt5SvpSurface(const CairoSurfaceSharedPtr& pSurface)
: m_pGraphics(nullptr)
, m_pCairoContext(nullptr)
, m_pSurface(pSurface)
{
}
Qt5SvpSurface::Qt5SvpSurface(const Qt5SvpGraphics* pGraphics, int x, int y, int width, int height)
: m_pGraphics(pGraphics)
, m_pCairoContext(pGraphics->getCairoContext(false))
{
cairo_surface_t* surface = cairo_get_target(m_pCairoContext);
m_pSurface.reset(cairo_surface_create_for_rectangle(surface, x, y, width, height),
&cairo_surface_destroy);
}
Qt5SvpSurface::~Qt5SvpSurface()
{
if (m_pCairoContext)
cairo_destroy(m_pCairoContext);
}
CairoSharedPtr Qt5SvpSurface::getCairo() const
{
return CairoSharedPtr(cairo_create(m_pSurface.get()), &cairo_destroy);
}
SurfaceSharedPtr Qt5SvpSurface::getSimilar(int cairo_content_type, int width, int height) const
{
return SurfaceSharedPtr(new Qt5SvpSurface(CairoSurfaceSharedPtr(
cairo_surface_create_similar(
m_pSurface.get(), static_cast<cairo_content_t>(cairo_content_type), width, height),
&cairo_surface_destroy)));
}
void Qt5SvpSurface::flush() const
{
cairo_surface_flush(m_pSurface.get());
if (m_pGraphics)
m_pGraphics->updateQWidget();
}
VclPtr<VirtualDevice> Qt5SvpSurface::createVirtualDevice() const
{
SystemGraphicsData aSystemGraphicsData;
aSystemGraphicsData.nSize = sizeof(SystemGraphicsData);
aSystemGraphicsData.pSurface = m_pSurface.get();
return VclPtr<VirtualDevice>::Create(aSystemGraphicsData, get_surface_size(m_pSurface.get()),
DeviceFormat::DEFAULT);
}
} // namespace cairo
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */