Kaydet (Commit) 26d5fe1b authored tarafından Markus Mohrhard's avatar Markus Mohrhard

extract cairo rendering and abstract platform bits

The text rendering is now abstracted into the TextRender abstract class.
Additionally we have now an abstracted cairo rendering class
CairoTextRender which is a subclass of the TextRender class. The
CairoTextRender class is still platform independent and needs to be
subclassed to implement the few platform dependent methods.

You can reuse the cairo based text rendering now by subclassing
CairoTextRender for the platform that you need.

Conflicts:
	vcl/unx/generic/gdi/salgdi.cxx

Change-Id: I8b07e3fe646a81563d308971d30e14a00fd921ad
üst 1c1af964
...@@ -88,6 +88,8 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_gen,\ ...@@ -88,6 +88,8 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_gen,\
vcl/unx/generic/dtrans/X11_selection \ vcl/unx/generic/dtrans/X11_selection \
vcl/unx/generic/dtrans/X11_service \ vcl/unx/generic/dtrans/X11_service \
vcl/unx/generic/dtrans/X11_transferable \ vcl/unx/generic/dtrans/X11_transferable \
vcl/unx/generic/gdi/cairotextrender \
vcl/unx/generic/gdi/x11cairotextrender \
vcl/unx/generic/gdi/gcach_xpeer \ vcl/unx/generic/gdi/gcach_xpeer \
vcl/unx/generic/gdi/gdiimpl \ vcl/unx/generic/gdi/gdiimpl \
vcl/unx/generic/gdi/salbmp \ vcl/unx/generic/gdi/salbmp \
......
...@@ -205,6 +205,7 @@ private: ...@@ -205,6 +205,7 @@ private:
friend class ServerFontLayout; friend class ServerFontLayout;
friend class ImplServerFontEntry; friend class ImplServerFontEntry;
friend class X11SalGraphics; friend class X11SalGraphics;
friend class CairoTextRender;
void AddRef() const { ++mnRefCount; } void AddRef() const { ++mnRefCount; }
long GetRefCount() const { return mnRefCount; } long GetRefCount() const { return mnRefCount; }
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#ifndef _MSC_VER #ifndef _MSC_VER
#include <graphite_layout.hxx> #include <graphite_layout.hxx>
#include "generic/glyphcache.hxx"
class PhysicalFontFace; class PhysicalFontFace;
// Modules // Modules
......
/* -*- 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_VCL_INC_UNX_CAIROFONTIMPL_HXX
#define INCLUDED_VCL_INC_UNX_CAIROFONTIMPL_HXX
#include <tools/rational.hxx>
#include <vcl/salgtype.hxx>
#include <vcl/vclenum.hxx>
#include <vcl/metric.hxx>
#include "salgdi.hxx"
#include "salglyphid.hxx"
#include "fontsubset.hxx"
class PspSalPrinter;
class PspSalInfoPrinter;
class ServerFont;
class ImplLayoutArgs;
class ServerFontLayout;
class PhysicalFontCollection;
class PhysicalFontFace;
class TextRenderImpl
{
public:
virtual ~TextRenderImpl() {}
virtual void SetTextColor( SalColor nSalColor ) = 0;
virtual sal_uInt16 SetFont( FontSelectPattern*, int nFallbackLevel ) = 0;
virtual void GetFontMetric( ImplFontMetricData*, int nFallbackLevel ) = 0;
virtual const FontCharMapPtr GetFontCharMap() const = 0;
virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const = 0;
virtual void GetDevFontList( PhysicalFontCollection* ) = 0;
virtual void ClearDevFontCache() = 0;
virtual bool AddTempDevFont( PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) = 0;
virtual bool CreateFontSubset( const OUString& rToFile,
const PhysicalFontFace*,
sal_GlyphId* pGlyphIDs,
sal_uInt8* pEncoding,
sal_Int32* pWidths,
int nGlyphs,
FontSubsetInfo& rInfo
) = 0;
virtual const Ucs2SIntMap* GetFontEncodingVector( const PhysicalFontFace*, const Ucs2OStrMap** ppNonEncoded ) = 0;
virtual const void* GetEmbedFontData( const PhysicalFontFace*,
const sal_Ucs* pUnicodes,
sal_Int32* pWidths,
FontSubsetInfo& rInfo,
long* pDataLen ) = 0;
virtual void FreeEmbedFontData( const void* pData, long nDataLen ) = 0;
virtual void GetGlyphWidths( const PhysicalFontFace*,
bool bVertical,
Int32Vector& rWidths,
Ucs2UIntMap& rUnicodeEnc ) = 0;
virtual bool GetGlyphBoundRect( sal_GlyphId nIndex, Rectangle& ) = 0;
virtual bool GetGlyphOutline( sal_GlyphId nIndex, ::basegfx::B2DPolyPolygon& ) = 0;
virtual SalLayout* GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) = 0;
virtual void DrawServerFontLayout( const ServerFontLayout& ) = 0;
virtual SystemFontData GetSysFontData( int nFallbackLevel ) const = 0;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_VCL_INC_UNX_CAIROTEXTRENDER_HXX
#define INCLUDED_VCL_INC_UNX_CAIROTEXTRENDER_HXX
#include "textrender.hxx"
#include <vcl/region.hxx>
#include <deque>
typedef struct FT_FaceRec_* FT_Face;
class PspSalPrinter;
class PspSalInfoPrinter;
class ServerFont;
class GlyphCache;
class ImplLayoutArgs;
class ServerFontLayout;
class PhysicalFontCollection;
class PhysicalFontFace;
struct _cairo_surface_t;
typedef struct _cairo_surface cairo_surface_t;
typedef struct _cairo cairo_t;
class CairoFontsCache
{
public:
struct CacheId
{
FT_Face maFace;
const void *mpOptions;
bool mbEmbolden;
bool mbVerticalMetrics;
bool operator ==(const CacheId& rOther) const
{
return maFace == rOther.maFace &&
mpOptions == rOther.mpOptions &&
mbEmbolden == rOther.mbEmbolden &&
mbVerticalMetrics == rOther.mbVerticalMetrics;
}
};
private:
static int mnRefCount;
typedef std::deque< std::pair<void *, CacheId> > LRUFonts;
static LRUFonts maLRUFonts;
public:
CairoFontsCache();
static void CacheFont(void *pFont, const CacheId &rId);
static void* FindCachedFont(const CacheId &rId);
~CairoFontsCache();
};
class CairoTextRender : public TextRenderImpl
{
bool mbPrinter;
ServerFont* mpServerFont[ MAX_FALLBACK ];
SalColor nTextColor_;
CairoFontsCache m_aCairoFontsCache;
protected:
virtual GlyphCache& getPlatformGlyphCache() = 0;
virtual cairo_surface_t* getCairoSurface() = 0;
bool setFont( const FontSelectPattern *pEntry, int nFallbackLevel );
virtual void clipRegion(cairo_t* cr) = 0;
public:
CairoTextRender(bool bPrinter);
virtual void SetTextColor( SalColor nSalColor ) SAL_OVERRIDE;
virtual sal_uInt16 SetFont( FontSelectPattern*, int nFallbackLevel ) SAL_OVERRIDE;
virtual void GetFontMetric( ImplFontMetricData*, int nFallbackLevel ) SAL_OVERRIDE;
virtual const FontCharMapPtr GetFontCharMap() const SAL_OVERRIDE;
virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const SAL_OVERRIDE;
virtual void GetDevFontList( PhysicalFontCollection* ) SAL_OVERRIDE;
virtual void ClearDevFontCache() SAL_OVERRIDE;
virtual bool AddTempDevFont( PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) SAL_OVERRIDE;
virtual bool CreateFontSubset( const OUString& rToFile,
const PhysicalFontFace*,
sal_GlyphId* pGlyphIDs,
sal_uInt8* pEncoding,
sal_Int32* pWidths,
int nGlyphs,
FontSubsetInfo& rInfo
) SAL_OVERRIDE;
virtual const Ucs2SIntMap* GetFontEncodingVector( const PhysicalFontFace*, const Ucs2OStrMap** ppNonEncoded ) SAL_OVERRIDE;
virtual const void* GetEmbedFontData( const PhysicalFontFace*,
const sal_Ucs* pUnicodes,
sal_Int32* pWidths,
FontSubsetInfo& rInfo,
long* pDataLen ) SAL_OVERRIDE;
virtual void FreeEmbedFontData( const void* pData, long nDataLen ) SAL_OVERRIDE;
virtual void GetGlyphWidths( const PhysicalFontFace*,
bool bVertical,
Int32Vector& rWidths,
Ucs2UIntMap& rUnicodeEnc ) SAL_OVERRIDE;
virtual bool GetGlyphBoundRect( sal_GlyphId nIndex, Rectangle& ) SAL_OVERRIDE;
virtual bool GetGlyphOutline( sal_GlyphId nIndex, ::basegfx::B2DPolyPolygon& ) SAL_OVERRIDE;
virtual SalLayout* GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) SAL_OVERRIDE;
virtual void DrawServerFontLayout( const ServerFontLayout& ) SAL_OVERRIDE;
virtual SystemFontData GetSysFontData( int nFallbackLevel ) const SAL_OVERRIDE;
private:
bool bDisableGraphite_;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -52,48 +52,21 @@ class ServerFontLayout; ...@@ -52,48 +52,21 @@ class ServerFontLayout;
class PhysicalFontCollection; class PhysicalFontCollection;
class PhysicalFontFace; class PhysicalFontFace;
class SalGraphicsImpl; class SalGraphicsImpl;
class TextRenderImpl;
namespace basegfx { namespace basegfx {
class B2DTrapezoid; class B2DTrapezoid;
} }
typedef struct FT_FaceRec_* FT_Face;
class CairoFontsCache
{
public:
struct CacheId
{
FT_Face maFace;
const void *mpOptions;
bool mbEmbolden;
bool mbVerticalMetrics;
bool operator ==(const CacheId& rOther) const
{
return maFace == rOther.maFace &&
mpOptions == rOther.mpOptions &&
mbEmbolden == rOther.mbEmbolden &&
mbVerticalMetrics == rOther.mbVerticalMetrics;
}
};
private:
static int mnRefCount;
typedef std::deque< std::pair<void *, CacheId> > LRUFonts;
static LRUFonts maLRUFonts;
public:
CairoFontsCache();
static void CacheFont(void *pFont, const CacheId &rId);
static void* FindCachedFont(const CacheId &rId);
~CairoFontsCache();
};
class VCLPLUG_GEN_PUBLIC X11SalGraphics : public SalGraphics class VCLPLUG_GEN_PUBLIC X11SalGraphics : public SalGraphics
{ {
friend class ServerFontLayout; friend class ServerFontLayout;
friend class X11SalGraphicsImpl; friend class X11SalGraphicsImpl;
friend class X11CairoTextRender;
private: private:
boost::scoped_ptr<SalGraphicsImpl> mpImpl; boost::scoped_ptr<SalGraphicsImpl> mpImpl;
boost::scoped_ptr<TextRenderImpl> mpTextRenderImpl;
protected: protected:
SalFrame* m_pFrame; // the SalFrame which created this Graphics or NULL SalFrame* m_pFrame; // the SalFrame which created this Graphics or NULL
...@@ -105,18 +78,12 @@ protected: ...@@ -105,18 +78,12 @@ protected:
SalX11Screen m_nXScreen; SalX11Screen m_nXScreen;
mutable XRenderPictFormat* m_pXRenderFormat; mutable XRenderPictFormat* m_pXRenderFormat;
XID m_aXRenderPicture; XID m_aXRenderPicture;
CairoFontsCache m_aCairoFontsCache;
Region pPaintRegion_; Region pPaintRegion_;
Region mpClipRegion; Region mpClipRegion;
GC pFontGC_; // Font attributes GC pFontGC_; // Font attributes
ServerFont* mpServerFont[ MAX_FALLBACK ]; Pixel nTextPixel_;
SalColor nTextColor_;
Pixel nTextPixel_;
bool bDisableGraphite_;
Pixmap hBrush_; // Dither Pixmap hBrush_; // Dither
...@@ -140,7 +107,6 @@ protected: ...@@ -140,7 +107,6 @@ protected:
SalColor nTransparentColor ); SalColor nTransparentColor );
GC GetFontGC(); GC GetFontGC();
bool setFont( const FontSelectPattern* pEntry, int nFallbackLevel );
protected: protected:
void DrawPrinterString( const SalLayout& ); void DrawPrinterString( const SalLayout& );
...@@ -293,7 +259,7 @@ public: ...@@ -293,7 +259,7 @@ public:
long nHeight, sal_uInt8 nTransparency ) SAL_OVERRIDE; long nHeight, sal_uInt8 nTransparency ) SAL_OVERRIDE;
virtual SystemGraphicsData GetGraphicsData() const SAL_OVERRIDE; virtual SystemGraphicsData GetGraphicsData() const SAL_OVERRIDE;
virtual SystemFontData GetSysFontData( int nFallbacklevel ) const SAL_OVERRIDE; virtual SystemFontData GetSysFontData( int nFallbackLevel ) const SAL_OVERRIDE;
virtual bool SwapBuffers() SAL_OVERRIDE; virtual bool SwapBuffers() SAL_OVERRIDE;
......
This diff is collapsed.
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "salgdiimpl.hxx" #include "salgdiimpl.hxx"
#include "unx/x11windowprovider.hxx" #include "unx/x11windowprovider.hxx"
#include "textrender.hxx"
#include "gdiimpl.hxx" #include "gdiimpl.hxx"
#include "openglgdiimpl.hxx" #include "openglgdiimpl.hxx"
...@@ -74,7 +75,6 @@ X11SalGraphics::X11SalGraphics(): ...@@ -74,7 +75,6 @@ X11SalGraphics::X11SalGraphics():
pPaintRegion_(NULL), pPaintRegion_(NULL),
mpClipRegion(NULL), mpClipRegion(NULL),
pFontGC_(NULL), pFontGC_(NULL),
nTextColor_(MAKE_SALCOLOR(0x00, 0x00, 0x00)), //black
nTextPixel_(0), nTextPixel_(0),
hBrush_(None), hBrush_(None),
bWindow_(false), bWindow_(false),
...@@ -87,15 +87,6 @@ X11SalGraphics::X11SalGraphics(): ...@@ -87,15 +87,6 @@ X11SalGraphics::X11SalGraphics():
mpImpl.reset(new OpenGLSalGraphicsImpl()); mpImpl.reset(new OpenGLSalGraphicsImpl());
else else
mpImpl.reset(new X11SalGraphicsImpl(*this)); mpImpl.reset(new X11SalGraphicsImpl(*this));
for( int i = 0; i < MAX_FALLBACK; ++i )
mpServerFont[i] = NULL;
#if ENABLE_GRAPHITE
// check if graphite fonts have been disabled
static const char* pDisableGraphiteStr = getenv( "SAL_DISABLE_GRAPHITE" );
bDisableGraphite_ = pDisableGraphiteStr && (pDisableGraphiteStr[0]!='0');
#endif
} }
X11SalGraphics::~X11SalGraphics() X11SalGraphics::~X11SalGraphics()
...@@ -157,7 +148,7 @@ void X11SalGraphics::SetDrawable( Drawable aDrawable, SalX11Screen nXScreen ) ...@@ -157,7 +148,7 @@ void X11SalGraphics::SetDrawable( Drawable aDrawable, SalX11Screen nXScreen )
} }
mpImpl->Init( m_pFrame ); mpImpl->Init( m_pFrame );
nTextPixel_ = GetPixel( nTextColor_ ); // TODO: moggi: FIXME nTextPixel_ = GetPixel( nTextColor_ );
} }
} }
......
This diff is collapsed.
/* -*- 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "x11cairotextrender.hxx"
#include "unx/saldata.hxx"
#include "unx/saldisp.hxx"
#include "gcach_xpeer.hxx"
#include <cairo.h>
#include <cairo-ft.h>
#include <cairo-xlib.h>
#include <cairo-xlib-xrender.h>
struct BOX
{
short x1, x2, y1, y2;
};
struct _XRegion
{
long size;
long numRects;
BOX *rects;
BOX extents;
};
X11CairoTextRender::X11CairoTextRender(bool bPrinter, X11SalGraphics& rParent):
CairoTextRender(bPrinter),
mrParent(rParent)
{
}
GlyphCache& X11CairoTextRender::getPlatformGlyphCache()
{
return X11GlyphCache::GetInstance();
}
cairo_surface_t* X11CairoTextRender::getCairoSurface()
{
// find a XRenderPictFormat compatible with the Drawable
XRenderPictFormat* pVisualFormat = mrParent.GetXRenderFormat();
Display* pDisplay = mrParent.GetXDisplay();
cairo_surface_t* surface = NULL;
if (pVisualFormat)
{
surface = cairo_xlib_surface_create_with_xrender_format (
pDisplay, mrParent.hDrawable_,
ScreenOfDisplay(pDisplay, mrParent.m_nXScreen.getXScreen()),
pVisualFormat, SAL_MAX_INT16, SAL_MAX_INT16);
}
else
{
surface = cairo_xlib_surface_create(pDisplay, mrParent.hDrawable_,
mrParent.GetVisual().visual, SAL_MAX_INT16, SAL_MAX_INT16);
}
return surface;
}
void X11CairoTextRender::clipRegion(cairo_t* cr)
{
Region pClipRegion = mrParent.mpClipRegion;
if( pClipRegion && !XEmptyRegion( pClipRegion ) )
{
for (long i = 0; i < pClipRegion->numRects; ++i)
{
cairo_rectangle(cr,
pClipRegion->rects[i].x1,
pClipRegion->rects[i].y1,
pClipRegion->rects[i].x2 - pClipRegion->rects[i].x1,
pClipRegion->rects[i].y2 - pClipRegion->rects[i].y1);
}
cairo_clip(cr);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "unx/cairotextrender.hxx"
#include "unx/saldata.hxx"
#include "unx/saldisp.hxx"
#include "unx/salgdi.h"
class X11CairoTextRender : public CairoTextRender
{
private:
X11SalGraphics& mrParent;
public:
X11CairoTextRender(bool bPrinter, X11SalGraphics& rParent);
virtual GlyphCache& getPlatformGlyphCache() SAL_OVERRIDE;
virtual cairo_surface_t* getCairoSurface() SAL_OVERRIDE;
virtual void clipRegion(cairo_t* cr) SAL_OVERRIDE;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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