summaryrefslogtreecommitdiff
path: root/vcl/unx/generic/gdi
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2015-01-19 16:04:24 +1100
committerChris Sherlock <chris.sherlock79@gmail.com>2015-01-24 14:27:37 +1100
commit35131df0ff833423809ea38621002322cf2d75b2 (patch)
tree246ccff6329b4cfd48412092b44398fddb622cea /vcl/unx/generic/gdi
parente3c0025461bdf55e62a308a76c3aa0a35109f076 (diff)
vcl: Reduce OpenGLX11CairoTextRender surface area to size of text bounds
With this patch I get the text boundary and use it to reduce the size of the surface to this area. However, this is mainly needed for OpenGLX11CairoTextRender, which creates a surface image and uses this for OpenGL rendering. Change-Id: Icffc19bed89aaa2ff84ae845d274258a6fca27da
Diffstat (limited to 'vcl/unx/generic/gdi')
-rw-r--r--vcl/unx/generic/gdi/cairotextrender.cxx2
-rw-r--r--vcl/unx/generic/gdi/openglx11cairotextrender.cxx53
-rw-r--r--vcl/unx/generic/gdi/openglx11cairotextrender.hxx2
-rw-r--r--vcl/unx/generic/gdi/x11cairotextrender.cxx3
-rw-r--r--vcl/unx/generic/gdi/x11cairotextrender.hxx3
5 files changed, 53 insertions, 10 deletions
diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx
index 7b0438ea49bf..1ad59365e0af 100644
--- a/vcl/unx/generic/gdi/cairotextrender.cxx
+++ b/vcl/unx/generic/gdi/cairotextrender.cxx
@@ -204,7 +204,7 @@ void CairoTextRender::DrawServerFontLayout( const ServerFontLayout& rLayout )
if (cairo_glyphs.empty())
return;
- cairo_surface_t *surface = getCairoSurface();
+ cairo_surface_t *surface = getCairoSurface( rLayout );
DBG_ASSERT( surface!=NULL, "no cairo surface for text" );
if( !surface )
diff --git a/vcl/unx/generic/gdi/openglx11cairotextrender.cxx b/vcl/unx/generic/gdi/openglx11cairotextrender.cxx
index 64bf196ef54c..67024bf0f561 100644
--- a/vcl/unx/generic/gdi/openglx11cairotextrender.cxx
+++ b/vcl/unx/generic/gdi/openglx11cairotextrender.cxx
@@ -20,23 +20,64 @@ OpenGLX11CairoTextRender::OpenGLX11CairoTextRender(bool bPrinter, X11SalGraphics
{
}
-cairo_surface_t* OpenGLX11CairoTextRender::getCairoSurface()
+cairo_surface_t* OpenGLX11CairoTextRender::getCairoSurface( const ServerFontLayout& rLayout )
{
// static size_t id = 0;
// OString aFileName = OString("/tmp/libo_logs/text_rendering") + OString::number(id++) + OString(".svg");
// cairo_surface_t* surface = cairo_svg_surface_create(aFileName.getStr(), GetWidth(), GetHeight());
cairo_surface_t* surface = NULL;
+ Rectangle aTextBoundRect;
OpenGLSalGraphicsImpl *pImpl = dynamic_cast< OpenGLSalGraphicsImpl* >(mrParent.GetImpl());
- if( pImpl )
+
+ if (pImpl)
{
Rectangle aClipRect = pImpl->getClipRegion().GetBoundRect();
- if( aClipRect.GetWidth() == 0 || aClipRect.GetHeight() == 0 )
+
+ // no clipping area, we need to take the whole area
+ if ( aClipRect.IsEmpty() )
+ {
+ aClipRect.setWidth(GetWidth());
+ aClipRect.setHeight(GetHeight());
+ }
+
+ if (!rLayout.GetOrientation() )
+ {
+ // GetBoundRect can fail!
+ if ( rLayout.GetBoundRect(mrParent, aTextBoundRect) )
+ {
+ // we need to take into account SalLayout's drawing offset
+ int nOffsetX = rLayout.DrawOffset().X() - rLayout.DrawBase().X();
+ int nOffsetY = rLayout.DrawOffset().Y() - rLayout.DrawBase().Y();
+
+ aTextBoundRect.Left() += nOffsetX;
+ aTextBoundRect.Top() += nOffsetY;
+
+ aTextBoundRect = aTextBoundRect.Intersection(aClipRect);
+ }
+ else
+ {
+ SAL_WARN("vcl.layout", "GetBoundRect() failed");
+ }
+ }
+ else
{
- aClipRect.setWidth( GetWidth() );
- aClipRect.setHeight( GetHeight() );
+ aTextBoundRect = aClipRect;
}
- surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, aClipRect.GetWidth(), aClipRect.GetHeight() );
}
+ else
+ {
+ SAL_WARN("vcl.opengl", "No OpenGLSalGraphicsImpl!");
+ return NULL;
+ }
+
+
+ double nDX=0, nDY=0;
+ getSurfaceOffset(nDX, nDY);
+
+ // add cairo surface offsets to work out surface width and height
+ surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, aTextBoundRect.GetWidth() + nDX,
+ aTextBoundRect.GetHeight() + nDY );
+
return surface;
}
diff --git a/vcl/unx/generic/gdi/openglx11cairotextrender.hxx b/vcl/unx/generic/gdi/openglx11cairotextrender.hxx
index 171949651635..4f8a0558a3eb 100644
--- a/vcl/unx/generic/gdi/openglx11cairotextrender.hxx
+++ b/vcl/unx/generic/gdi/openglx11cairotextrender.hxx
@@ -17,7 +17,7 @@ class OpenGLX11CairoTextRender : public X11CairoTextRender
public:
OpenGLX11CairoTextRender(bool bPrinter, X11SalGraphics& rParent);
- virtual cairo_surface_t* getCairoSurface() SAL_OVERRIDE;
+ virtual cairo_surface_t* getCairoSurface( const ServerFontLayout& rLayout ) SAL_OVERRIDE;
virtual void getSurfaceOffset(double& nDX, double& nDY) SAL_OVERRIDE;
virtual void drawSurface(cairo_t* cr) SAL_OVERRIDE;
};
diff --git a/vcl/unx/generic/gdi/x11cairotextrender.cxx b/vcl/unx/generic/gdi/x11cairotextrender.cxx
index f3aa47d07800..2519816298a0 100644
--- a/vcl/unx/generic/gdi/x11cairotextrender.cxx
+++ b/vcl/unx/generic/gdi/x11cairotextrender.cxx
@@ -53,7 +53,8 @@ GlyphCache& X11CairoTextRender::getPlatformGlyphCache()
return X11GlyphCache::GetInstance();
}
-cairo_surface_t* X11CairoTextRender::getCairoSurface()
+
+cairo_surface_t* X11CairoTextRender::getCairoSurface( const ServerFontLayout& )
{
// find a XRenderPictFormat compatible with the Drawable
XRenderPictFormat* pVisualFormat = mrParent.GetXRenderFormat();
diff --git a/vcl/unx/generic/gdi/x11cairotextrender.hxx b/vcl/unx/generic/gdi/x11cairotextrender.hxx
index 1449b3aa0dc5..57c85696e0a6 100644
--- a/vcl/unx/generic/gdi/x11cairotextrender.hxx
+++ b/vcl/unx/generic/gdi/x11cairotextrender.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_VCL_UNX_GENERIC_GDI_X11CAIROTEXTRENDER_HXX value
#include "cairotextrender.hxx"
+#include "generic/glyphcache.hxx"
#include "unx/saldata.hxx"
#include "unx/saldisp.hxx"
@@ -40,7 +41,7 @@ public:
X11CairoTextRender(bool bPrinter, X11SalGraphics& rParent);
virtual GlyphCache& getPlatformGlyphCache() SAL_OVERRIDE;
- virtual cairo_surface_t* getCairoSurface() SAL_OVERRIDE;
+ virtual cairo_surface_t* getCairoSurface( const ServerFontLayout &rLayout ) SAL_OVERRIDE;
virtual void getSurfaceOffset(double& nDX, double& nDY) SAL_OVERRIDE;
virtual void clipRegion(cairo_t* cr) SAL_OVERRIDE;
virtual void drawSurface(cairo_t* cr) SAL_OVERRIDE;