Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include "openglx11cairotextrender.hxx"
11 :
12 : #include "openglgdiimpl.hxx"
13 : #include "salbmp.hxx"
14 : #include <vcl/salbtype.hxx>
15 :
16 : #include <cairo-svg.h>
17 :
18 0 : OpenGLX11CairoTextRender::OpenGLX11CairoTextRender(X11SalGraphics& rParent)
19 0 : : X11CairoTextRender(rParent)
20 : {
21 0 : }
22 :
23 0 : cairo_t* OpenGLX11CairoTextRender::getCairoContext()
24 : {
25 : // static size_t id = 0;
26 : // OString aFileName = OString("/tmp/libo_logs/text_rendering") + OString::number(id++) + OString(".svg");
27 : // cairo_surface_t* surface = cairo_svg_surface_create(aFileName.getStr(), GetWidth(), GetHeight());
28 0 : cairo_surface_t* surface = NULL;
29 0 : OpenGLSalGraphicsImpl *pImpl = dynamic_cast< OpenGLSalGraphicsImpl* >(mrParent.GetImpl());
30 0 : if( pImpl )
31 : {
32 0 : Rectangle aClipRect = pImpl->getClipRegion().GetBoundRect();
33 0 : if( aClipRect.GetWidth() == 0 || aClipRect.GetHeight() == 0 )
34 : {
35 0 : aClipRect.setWidth( GetWidth() );
36 0 : aClipRect.setHeight( GetHeight() );
37 : }
38 0 : surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, aClipRect.GetWidth(), aClipRect.GetHeight() );
39 : }
40 0 : if (!surface)
41 0 : return NULL;
42 0 : cairo_t *cr = cairo_create(surface);
43 0 : cairo_surface_destroy(surface);
44 0 : return cr;
45 : }
46 :
47 0 : void OpenGLX11CairoTextRender::getSurfaceOffset( double& nDX, double& nDY )
48 : {
49 0 : OpenGLSalGraphicsImpl *pImpl = dynamic_cast< OpenGLSalGraphicsImpl* >(mrParent.GetImpl());
50 0 : if( pImpl )
51 : {
52 0 : Rectangle aClipRect = pImpl->getClipRegion().GetBoundRect();
53 0 : nDX = -aClipRect.Left();
54 0 : nDY = -aClipRect.Top();
55 : }
56 0 : }
57 :
58 0 : void OpenGLX11CairoTextRender::drawSurface(cairo_t* cr)
59 : {
60 : // XXX: lfrb: GLES 2.0 doesn't support GL_UNSIGNED_INT_8_8_8_8_REV
61 0 : OpenGLSalGraphicsImpl *pImpl = dynamic_cast< OpenGLSalGraphicsImpl* >(mrParent.GetImpl());
62 0 : if(!pImpl)
63 0 : return;
64 :
65 0 : cairo_surface_t* pSurface = cairo_get_target(cr);
66 0 : int nWidth = cairo_image_surface_get_width( pSurface );
67 0 : int nHeight = cairo_image_surface_get_height( pSurface );
68 0 : unsigned char *pSrc = cairo_image_surface_get_data( pSurface );
69 :
70 : // XXX: lfrb: GLES 2.0 doesn't support GL_UNSIGNED_INT_8_8_8_8_REV
71 0 : Rectangle aClipRect = pImpl->getClipRegion().GetBoundRect();
72 :
73 : SalTwoRect aRect(0, 0, nWidth, nHeight,
74 0 : aClipRect.Left(), aClipRect.Top(), nWidth, nHeight);
75 :
76 : // Cairo surface data is ARGB with premultiplied alpha and is Y-inverted
77 0 : OpenGLTexture aTexture( nWidth, nHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pSrc );
78 0 : pImpl->PreDraw();
79 0 : pImpl->DrawAlphaTexture( aTexture, aRect, true, true );
80 0 : pImpl->PostDraw();
81 9 : }
82 :
83 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|