Add freetype text rendering engine.
git-svn-id: svn://10.0.0.236/branches/SVG_20020806_BRANCH@147036 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -180,6 +180,10 @@ NS_NewXULTreeBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
||||
#include "nsSVGTypeCIDs.h"
|
||||
#include "nsISVGRenderer.h"
|
||||
#include "nsSVGRect.h"
|
||||
#ifdef MOZ_SVG_RENDERER_LIBART
|
||||
void NS_InitSVGRendererLibartGlobals();
|
||||
void NS_FreeSVGRendererLibartGlobals();
|
||||
#endif
|
||||
#ifdef MOZ_SVG_RENDERER_GDIPLUS
|
||||
void NS_InitSVGRendererGDIPlusGlobals();
|
||||
void NS_FreeSVGRendererGDIPlusGlobals();
|
||||
@@ -251,6 +255,9 @@ Initialize(nsIModule* aSelf)
|
||||
|
||||
#ifdef MOZ_SVG
|
||||
nsSVGAtoms::AddRefAtoms();
|
||||
#ifdef MOZ_SVG_RENDERER_LIBART
|
||||
NS_InitSVGRendererLibartGlobals();
|
||||
#endif
|
||||
#ifdef MOZ_SVG_RENDERER_GDIPLUS
|
||||
NS_InitSVGRendererGDIPlusGlobals();
|
||||
#endif
|
||||
@@ -320,6 +327,9 @@ Shutdown(nsIModule* aSelf)
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_SVG
|
||||
#ifdef MOZ_SVG_RENDERER_LIBART
|
||||
NS_FreeSVGRendererLibartGlobals();
|
||||
#endif
|
||||
#ifdef MOZ_SVG_RENDERER_GDIPLUS
|
||||
NS_FreeSVGRendererGDIPlusGlobals();
|
||||
#endif
|
||||
|
||||
@@ -55,6 +55,8 @@ REQUIRES = \
|
||||
necko \
|
||||
libart_lgpl \
|
||||
util \
|
||||
uconv \
|
||||
windowwatcher \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
@@ -66,8 +68,8 @@ CPPSRCS = \
|
||||
nsSVGRenderItem.cpp \
|
||||
nsSVGFill.cpp \
|
||||
nsSVGStroke.cpp \
|
||||
nsSVGLibartGlyphGeometry.cpp \
|
||||
nsSVGLibartGlyphMetrics.cpp \
|
||||
nsSVGLibartGlyphGeometryDefault.cpp \
|
||||
nsSVGLibartGlyphMetricsDefault.cpp \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
@@ -75,6 +77,7 @@ include $(topsrcdir)/config/config.mk
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
FORCE_STATIC_LIB = 1
|
||||
|
||||
# **********************************************************************
|
||||
# choose a toolkit specific implementation of nsISVGLibartBitmap:
|
||||
|
||||
# gtk2:
|
||||
@@ -99,6 +102,26 @@ ifeq (,$(filter gtk2 mac cocoa,$(MOZ_GFX_TOOLKIT)))
|
||||
CPPSRCS += nsSVGLibartBitmapDefault.cpp
|
||||
endif
|
||||
|
||||
# **********************************************************************
|
||||
# choose a text renderer besides the default one:
|
||||
|
||||
ifdef MOZ_ENABLE_FREETYPE2
|
||||
CPPSRCS += \
|
||||
nsSVGLibartFreetype.cpp \
|
||||
nsSVGLibartGlyphGeometryFT.cpp \
|
||||
nsSVGLibartGlyphMetricsFT.cpp \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES += \
|
||||
$(FT2_CFLAGS) \
|
||||
-I$(topsrcdir)/gfx \
|
||||
-I$(topsrcdir)/gfx/src/freetype \
|
||||
$(NULL)
|
||||
|
||||
DEFINES += -DMOZ_ENABLE_FREETYPE2
|
||||
endif
|
||||
|
||||
# **********************************************************************
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#include "art_vpath_dash.h"
|
||||
#include "art_pathcode.h"
|
||||
#include "art_render.h"
|
||||
#include "art_render_mask.h"
|
||||
#include "art_render_gradient.h"
|
||||
#include "art_render_svp.h"
|
||||
#include "art_rgb.h"
|
||||
|
||||
@@ -46,19 +46,25 @@ class nsIPresContext;
|
||||
struct nsRect;
|
||||
typedef PRUint32 nscolor;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsISVGLibartBitmap
|
||||
// Abstraction of a libart-compatible bitmap hiding
|
||||
// platform-specific implementation details
|
||||
|
||||
// {18E4F62F-60A4-42D1-BCE2-43445656096E}
|
||||
#define NS_ISVGLIBARTBITMAP_IID \
|
||||
{ 0x18e4f62f, 0x60a4, 0x42d1, { 0xbc, 0xe2, 0x43, 0x44, 0x56, 0x56, 0x09, 0x6e } }
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* 'Private' rendering engine interface
|
||||
*
|
||||
* Abstraction of a libart-compatible bitmap
|
||||
* hiding platform-specific implementation details.
|
||||
*/
|
||||
class nsISVGLibartBitmap : public nsISupports
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_ISVGLIBARTBITMAP_IID; return iid; }
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISVGLIBARTBITMAP_IID)
|
||||
|
||||
enum PixelFormat {
|
||||
PIXEL_FORMAT_24_RGB = 1, // linux
|
||||
@@ -68,19 +74,39 @@ public:
|
||||
|
||||
NS_IMETHOD_(PRUint8 *) GetBits()=0;
|
||||
NS_IMETHOD_(PixelFormat) GetPixelFormat()=0;
|
||||
|
||||
/**
|
||||
* Linestride in bytes.
|
||||
*/
|
||||
NS_IMETHOD_(int) GetLineStride()=0;
|
||||
|
||||
/**
|
||||
* Width in pixels.
|
||||
*/
|
||||
NS_IMETHOD_(int) GetWidth()=0;
|
||||
|
||||
/**
|
||||
* Height in pixels.
|
||||
*/
|
||||
NS_IMETHOD_(int) GetHeight()=0;
|
||||
|
||||
// Obtain a rendering context for part of the bitmap. In general
|
||||
// this will be different to the RC passed at initialization time
|
||||
/**
|
||||
* Obtain a rendering context for part of the bitmap. In general
|
||||
* this will be different to the RC passed at initialization time.
|
||||
*/
|
||||
NS_IMETHOD_(void) LockRenderingContext(const nsRect& rect, nsIRenderingContext**ctx)=0;
|
||||
|
||||
NS_IMETHOD_(void) UnlockRenderingContext()=0;
|
||||
|
||||
// flush changes to the rendering context passed at initialization time
|
||||
/**
|
||||
* Flush changes to the rendering context passed at initialization time.
|
||||
*/
|
||||
NS_IMETHOD_(void) Flush()=0;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
// The libart backend expects to find a statically linked class
|
||||
// implementing the above interface and instantiable with the
|
||||
// following method:
|
||||
|
||||
@@ -48,15 +48,44 @@ typedef ArtPixMaxDepth ArtColor[3];
|
||||
#define NS_ISVGLIBARTCANVAS_IID \
|
||||
{ 0x6f963b6f, 0x8d8e, 0x4c8d, { 0xb4, 0xa1, 0xfa, 0x87, 0xfb, 0x82, 0x59, 0x73 } }
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* 'Private' rendering engine interface
|
||||
*/
|
||||
class nsISVGLibartCanvas : public nsISVGRendererCanvas
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_ISVGLIBARTCANVAS_IID; return iid; }
|
||||
|
||||
/**
|
||||
* Deprecated. Use NewRender(int x0, int y0, int x1, int y1).
|
||||
*/
|
||||
NS_IMETHOD_(ArtRender*) NewRender()=0;
|
||||
|
||||
/**
|
||||
* Construct a new render object for the given rect.
|
||||
*
|
||||
* @return New render object or 0 if the requested rect doesn't
|
||||
* overlap the dirty rect or if there is an error.
|
||||
*/
|
||||
NS_IMETHOD_(ArtRender*) NewRender(int x0, int y0, int x1, int y1)=0;
|
||||
|
||||
/**
|
||||
* Invoke the render object previously constructed with a call to
|
||||
* NewRender().
|
||||
*/
|
||||
NS_IMETHOD_(void) InvokeRender(ArtRender* render)=0;
|
||||
|
||||
/**
|
||||
* Convert an rgb value into a libart color value.
|
||||
*/
|
||||
NS_IMETHOD_(void) GetArtColor(nscolor rgb, ArtColor& artColor)=0;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif //__NS_ISVGLIBART_CANVAS_H__
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla SVG project.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* .
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Leon Sha <leon.sha@sun.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ----- END LICENSE BLOCK ----- */
|
||||
|
||||
#ifndef __NS_ISVGLIBART_GLYPHMETRICS_FT_H__
|
||||
#define __NS_ISVGLIBART_GLYPHMETRICS_FT_H__
|
||||
|
||||
#include "nsISVGRendererGlyphMetrics.h"
|
||||
#include "nsFreeType.h"
|
||||
|
||||
// {b74698f5-b016-4423-a742-d2a14e5d8c45}
|
||||
#define NS_ISVGLIBARTGLYPHMETRICSFT_IID \
|
||||
{ 0xb74698f5, 0xb016, 0x4423, { 0xa7, 0x42, 0xd2, 0xa1, 0x4e, 0x5d, 0x8c, 0x45 } }
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* 'Private' rendering engine interface
|
||||
*/
|
||||
class nsISVGLibartGlyphMetricsFT : public nsISVGRendererGlyphMetrics
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISVGLIBARTGLYPHMETRICSFT_IID)
|
||||
NS_IMETHOD_(FT_Face) GetFTFace() = 0;
|
||||
NS_IMETHOD_(float) GetPixelScale() = 0;
|
||||
NS_IMETHOD_(float) GetTwipsToPixels() = 0;
|
||||
NS_IMETHOD_(const FT_BBox*) GetBoundingBox() = 0;
|
||||
NS_IMETHOD_(PRUint32) GetGlyphCount() = 0;
|
||||
NS_IMETHOD_(FT_Glyph) GetGlyphAt(PRUint32 pos) = 0;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif // __NS_ISVGLIBART_GLYPHMETRICS_FT_H__
|
||||
@@ -46,13 +46,26 @@
|
||||
#define NS_ISVGLIBARTREGION_IID \
|
||||
{ 0xfb7271c1, 0x54ed, 0x418d, { 0x8f, 0xff, 0xef, 0x0f, 0x64, 0xdf, 0x01, 0x5f } }
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* 'Private' rendering engine interface
|
||||
*/
|
||||
class nsISVGLibartRegion : public nsISVGRendererRegion
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISVGLIBARTREGION_IID)
|
||||
|
||||
|
||||
/**
|
||||
* Get region as a libart microtile array.
|
||||
*/
|
||||
NS_IMETHOD_(ArtUta*) GetUta()=0;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#endif //__NS_ISVGLIBART_REGION_H__
|
||||
|
||||
@@ -44,10 +44,17 @@
|
||||
|
||||
class nsISVGPathGeometrySource;
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
|
||||
class nsSVGFill : public nsSVGRenderItem
|
||||
{
|
||||
public:
|
||||
void Build(ArtVpath* path, nsISVGPathGeometrySource* source);
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif // __NS_SVGFILL_H__
|
||||
|
||||
@@ -42,9 +42,14 @@
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsSVGLibartBPathBuilder class
|
||||
|
||||
/**
|
||||
* Libart path builder implementation
|
||||
*/
|
||||
class nsSVGLibartBPathBuilder : public nsISVGRendererPathBuilder
|
||||
{
|
||||
protected:
|
||||
@@ -71,6 +76,8 @@ private:
|
||||
PRUint32 mBPathEnd; // one-past-the-end
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// implementation:
|
||||
|
||||
@@ -107,7 +114,7 @@ NS_INTERFACE_MAP_END
|
||||
//----------------------------------------------------------------------
|
||||
// nsISVGRendererPathBuilder methods:
|
||||
|
||||
/* void moveto (in float x, in float y); */
|
||||
/** Implements void moveto(in float x, in float y); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartBPathBuilder::Moveto(float x, float y)
|
||||
{
|
||||
@@ -122,7 +129,7 @@ nsSVGLibartBPathBuilder::Moveto(float x, float y)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void lineto (in float x, in float y); */
|
||||
/** Implements void lineto(in float x, in float y); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartBPathBuilder::Lineto(float x, float y)
|
||||
{
|
||||
@@ -137,7 +144,7 @@ nsSVGLibartBPathBuilder::Lineto(float x, float y)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void curveto (in float x, in float y, in float x1, in float y1, in float x2, in float y2); */
|
||||
/** Implements void curveto(in float x, in float y, in float x1, in float y1, in float x2, in float y2); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartBPathBuilder::Curveto(float x, float y, float x1, float y1, float x2, float y2)
|
||||
{
|
||||
@@ -167,7 +174,7 @@ static inline double CalcVectorAngle(double ux, double uy, double vx, double vy)
|
||||
}
|
||||
|
||||
|
||||
/* void arcto (in float x, in float y, in float r1, in float r2, in float angle, in boolean largeArcFlag, in boolean sweepFlag); */
|
||||
/** Implements void arcto(in float x, in float y, in float r1, in float r2, in float angle, in boolean largeArcFlag, in boolean sweepFlag); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartBPathBuilder::Arcto(float x2, float y2, float rx, float ry, float angle, PRBool largeArcFlag, PRBool sweepFlag)
|
||||
{
|
||||
@@ -280,7 +287,7 @@ nsSVGLibartBPathBuilder::Arcto(float x2, float y2, float rx, float ry, float ang
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void closePath (out float newX, out float newY); */
|
||||
/** Implements void closePath(out float newX, out float newY); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartBPathBuilder::ClosePath(float *newX, float *newY)
|
||||
{
|
||||
@@ -302,7 +309,7 @@ nsSVGLibartBPathBuilder::ClosePath(float *newX, float *newY)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void endPath (); */
|
||||
/** Implements void endPath(); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartBPathBuilder::EndPath()
|
||||
{
|
||||
|
||||
@@ -50,11 +50,17 @@
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsSVGLibartBitmapDefault: an implementation based on gfxIImageFrame
|
||||
// that should work on all platforms but doesn't support obtaining
|
||||
// RenderingContexts with Lock/UnlockRenderingContext
|
||||
|
||||
/**
|
||||
* A libart-bitmap implementation based on gfxIImageFrame that should
|
||||
* work on all platforms but doesn't support obtaining
|
||||
* RenderingContexts with Lock/UnlockRenderingContext and is generally
|
||||
* a bit of a hack.
|
||||
*/
|
||||
class nsSVGLibartBitmapDefault : public nsISVGLibartBitmap
|
||||
{
|
||||
public:
|
||||
@@ -89,6 +95,8 @@ private:
|
||||
nsRect mRect;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// implementation:
|
||||
|
||||
|
||||
@@ -47,9 +47,14 @@
|
||||
#include "nsDrawingSurfaceGTK.h"
|
||||
#include "nsRenderingContextGTK.h"
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsSVGLibartBitmapGdk
|
||||
|
||||
/**
|
||||
* A libart-bitmap implementation for gtk 2.0.
|
||||
*/
|
||||
class nsSVGLibartBitmapGdk : public nsISVGLibartBitmap
|
||||
{
|
||||
public:
|
||||
@@ -80,6 +85,8 @@ private:
|
||||
nsDrawingSurface mTempSurface;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// implementation:
|
||||
|
||||
|
||||
@@ -50,11 +50,16 @@
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsSVGLibartBitmapMac: an implementation based on gfxIImageFrame
|
||||
// that should work for Mac but doesn't support obtaining
|
||||
// RenderingContexts with Lock/UnlockRenderingContext
|
||||
|
||||
/**
|
||||
* A libart bitmap implementation based on gfxIImageFrame that should
|
||||
* work for Mac but doesn't support obtaining RenderingContexts with
|
||||
* Lock/UnlockRenderingContext
|
||||
*/
|
||||
class nsSVGLibartBitmapMac : public nsISVGLibartBitmap
|
||||
{
|
||||
public:
|
||||
@@ -89,6 +94,8 @@ private:
|
||||
nsRect mRect;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// implementation:
|
||||
|
||||
|
||||
@@ -48,9 +48,14 @@
|
||||
#include "nsRect.h"
|
||||
#include "libart-incs.h"
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsSVGLibartCanvas class
|
||||
|
||||
/**
|
||||
* Libart canvas implementation
|
||||
*/
|
||||
class nsSVGLibartCanvas : public nsISVGLibartCanvas
|
||||
{
|
||||
public:
|
||||
@@ -67,6 +72,7 @@ public:
|
||||
|
||||
// nsISVGLibartCanvas interface:
|
||||
NS_IMETHOD_(ArtRender*) NewRender();
|
||||
NS_IMETHOD_(ArtRender*) NewRender(int x0, int y0, int x1, int y1);
|
||||
NS_IMETHOD_(void) InvokeRender(ArtRender* render);
|
||||
NS_IMETHOD_(void) GetArtColor(nscolor rgb, ArtColor& artColor);
|
||||
|
||||
@@ -78,6 +84,8 @@ private:
|
||||
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// implementation:
|
||||
|
||||
@@ -148,7 +156,7 @@ NS_INTERFACE_MAP_END
|
||||
//----------------------------------------------------------------------
|
||||
// nsISVGRendererCanvas methods:
|
||||
|
||||
/* [noscript] nsIRenderingContext lockRenderingContext ([const] in nsRectRef rect); */
|
||||
/** Implements [noscript] nsIRenderingContext lockRenderingContext(const in nsRectRef rect); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartCanvas::LockRenderingContext(const nsRect & rect,
|
||||
nsIRenderingContext **_retval)
|
||||
@@ -159,7 +167,7 @@ nsSVGLibartCanvas::LockRenderingContext(const nsRect & rect,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void unlockRenderingContext (); */
|
||||
/** Implements void unlockRenderingContext(); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartCanvas::UnlockRenderingContext()
|
||||
{
|
||||
@@ -167,7 +175,7 @@ nsSVGLibartCanvas::UnlockRenderingContext()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsIPresContext getPresContext (); */
|
||||
/** Implements nsIPresContext getPresContext(); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartCanvas::GetPresContext(nsIPresContext **_retval)
|
||||
{
|
||||
@@ -176,7 +184,7 @@ nsSVGLibartCanvas::GetPresContext(nsIPresContext **_retval)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void clear (in nscolor color); */
|
||||
/** void clear(in nscolor color); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartCanvas::Clear(nscolor color)
|
||||
{
|
||||
@@ -225,7 +233,7 @@ nsSVGLibartCanvas::Clear(nscolor color)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void flush (); */
|
||||
/** void flush(); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartCanvas::Flush()
|
||||
{
|
||||
@@ -250,6 +258,34 @@ nsSVGLibartCanvas::NewRender()
|
||||
);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(ArtRender*)
|
||||
nsSVGLibartCanvas::NewRender(int x0, int y0, int x1, int y1)
|
||||
{
|
||||
NS_ASSERTION(x0<x1 && y0<y1, "empty rect passed to NewRender()");
|
||||
if (x0>=x1 || y0>=y1) return;
|
||||
|
||||
// only construct a render object if there is overlap with the dirty rect:
|
||||
if (x1<mDirtyRect.x || x0>mDirtyRect.x+mDirtyRect.width ||
|
||||
y1<mDirtyRect.y || y0>mDirtyRect.y+mDirtyRect.height)
|
||||
return nsnull;
|
||||
|
||||
int rx0 = (x0>mDirtyRect.x ? x0 : mDirtyRect.x);
|
||||
int rx1 = (x1<mDirtyRect.x+mDirtyRect.width ? x1 : mDirtyRect.x+mDirtyRect.width);
|
||||
int ry0 = (y0>mDirtyRect.y ? y0 : mDirtyRect.y);
|
||||
int ry1 = (y1<mDirtyRect.y+mDirtyRect.height ? y1 : mDirtyRect.y+mDirtyRect.height);
|
||||
|
||||
int offset = 3*(rx0-mDirtyRect.x) + mBitmap->GetLineStride()*(ry0-mDirtyRect.y);
|
||||
|
||||
return art_render_new(rx0, ry0, rx1, ry1,
|
||||
mBitmap->GetBits()+offset, // pixels
|
||||
mBitmap->GetLineStride(), // rowstride
|
||||
3, // n_chan
|
||||
8, // depth
|
||||
mBitmap->GetPixelFormat()==nsISVGLibartBitmap::PIXEL_FORMAT_32_ABGR ? ART_ALPHA_SEPARATE : ART_ALPHA_NONE, // alpha_type
|
||||
NULL //alphagamma
|
||||
);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
nsSVGLibartCanvas::InvokeRender(ArtRender* render)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla SVG project.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Crocodile Clips Ltd..
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ----- END LICENSE BLOCK ----- */
|
||||
|
||||
#include "nsSVGLibartFreetype.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsArray.h"
|
||||
|
||||
nsCOMPtr<nsIFreeType2> nsSVGLibartFreetype::ft2;
|
||||
nsCOMPtr<nsIFontCatalogService> nsSVGLibartFreetype::fontCatalog;
|
||||
|
||||
PRBool nsSVGLibartFreetype::Init()
|
||||
{
|
||||
NS_ASSERTION(!ft2, "ft2 already initialized");
|
||||
ft2 = do_GetService(NS_FREETYPE2_CONTRACTID);
|
||||
if (!ft2) return PR_FALSE;
|
||||
|
||||
fontCatalog = do_GetService("@mozilla.org/gfx/xfontcatalogservice;1");
|
||||
if (!fontCatalog) {
|
||||
NS_ERROR("Font catalog initialization failure");
|
||||
ft2 = nsnull;
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void nsSVGLibartFreetype::Shutdown()
|
||||
{
|
||||
NS_ASSERTION(ft2, "ft2 never initialized");
|
||||
ft2 = nsnull;
|
||||
fontCatalog = nsnull;
|
||||
}
|
||||
|
||||
PRBool nsSVGLibartFreetype::HasSuitableFonts()
|
||||
{
|
||||
NS_ASSERTION(fontCatalog, "freetype not initialized");
|
||||
|
||||
nsCOMPtr<nsIArray> arr;
|
||||
nsCAutoString empty;
|
||||
fontCatalog->GetFontCatalogEntries(empty, empty,
|
||||
nsIFontCatalogService::kFCWeightAny,
|
||||
nsIFontCatalogService::kFCWidthAny,
|
||||
nsIFontCatalogService::kFCSlantAny,
|
||||
nsIFontCatalogService::kFCSpacingAny,
|
||||
getter_AddRefs(arr));
|
||||
PRUint32 count;
|
||||
arr->GetLength(&count);
|
||||
#ifdef DEBUG
|
||||
{
|
||||
printf("Freetype Families available:\n");
|
||||
for (PRUint32 i=0;i<count;++i) {
|
||||
nsCOMPtr<nsITrueTypeFontCatalogEntry> font = do_QueryElementAt(arr, i);
|
||||
nsCAutoString family, style, vendor;
|
||||
font->GetFamilyName(family);
|
||||
font->GetStyleName(style);
|
||||
font->GetVendorID(vendor);
|
||||
printf("* %s, %s, %s\n", family.get(), style.get(), vendor.get());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return (count!=0);
|
||||
}
|
||||
73
mozilla/layout/svg/renderer/src/libart/nsSVGLibartFreetype.h
Normal file
73
mozilla/layout/svg/renderer/src/libart/nsSVGLibartFreetype.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla SVG project.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Crocodile Clips Ltd..
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ----- END LICENSE BLOCK ----- */
|
||||
|
||||
#ifndef __NS_SVGLIBART_FREETYPE_H__
|
||||
#define __NS_SVGLIBART_FREETYPE_H__
|
||||
|
||||
#include "nsFreeType.h"
|
||||
|
||||
namespace nsSVGLibartFreetype {
|
||||
/**
|
||||
* Initializes global ft2 and fontcatalog instances.
|
||||
*
|
||||
* @return PR_TRUE if the initialization succeeded, PR_FALSE otherwise.
|
||||
*/
|
||||
PRBool Init();
|
||||
|
||||
/**
|
||||
* Releases global ft2 and fontcatalog instances.
|
||||
*/
|
||||
void Shutdown();
|
||||
|
||||
/**
|
||||
* @return PR_TRUE if there are suitable fonts on the system, PR_FALSE otherwise
|
||||
*/
|
||||
PRBool HasSuitableFonts();
|
||||
|
||||
/**
|
||||
* Global freetype2 instance.
|
||||
*/
|
||||
extern nsCOMPtr<nsIFreeType2> ft2;
|
||||
|
||||
/**
|
||||
* Global fontcatalog instance.
|
||||
*/
|
||||
extern nsCOMPtr<nsIFontCatalogService> fontCatalog;
|
||||
}
|
||||
|
||||
#endif // __NS_SVGLIBART_FREETYPE_H__
|
||||
@@ -38,7 +38,6 @@
|
||||
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsSVGLibartGlyphGeometry.h"
|
||||
#include "nsISVGRendererGlyphGeometry.h"
|
||||
#include "nsIDOMSVGMatrix.h"
|
||||
#include "nsISVGGlyphGeometrySource.h"
|
||||
@@ -46,15 +45,19 @@
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsMemory.h"
|
||||
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsSVGLibartGlyphGeometry class
|
||||
|
||||
/**
|
||||
* Libart glyph geometry implementation
|
||||
*/
|
||||
class nsSVGLibartGlyphGeometry : public nsISVGRendererGlyphGeometry
|
||||
{
|
||||
protected:
|
||||
friend nsresult NS_NewSVGLibartGlyphGeometry(nsISVGRendererGlyphGeometry **result,
|
||||
nsISVGGlyphGeometrySource *src);
|
||||
friend nsresult NS_NewSVGLibartGlyphGeometryDefault(nsISVGRendererGlyphGeometry **result,
|
||||
nsISVGGlyphGeometrySource *src);
|
||||
|
||||
nsSVGLibartGlyphGeometry();
|
||||
~nsSVGLibartGlyphGeometry();
|
||||
@@ -69,6 +72,8 @@ public:
|
||||
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// implementation:
|
||||
|
||||
@@ -88,8 +93,8 @@ nsSVGLibartGlyphGeometry::Init(nsISVGGlyphGeometrySource* src)
|
||||
|
||||
|
||||
nsresult
|
||||
NS_NewSVGLibartGlyphGeometry(nsISVGRendererGlyphGeometry **result,
|
||||
nsISVGGlyphGeometrySource *src)
|
||||
NS_NewSVGLibartGlyphGeometryDefault(nsISVGRendererGlyphGeometry **result,
|
||||
nsISVGGlyphGeometrySource *src)
|
||||
{
|
||||
*result = nsnull;
|
||||
|
||||
@@ -124,14 +129,14 @@ NS_INTERFACE_MAP_END
|
||||
//----------------------------------------------------------------------
|
||||
// nsISVGRendererGlyphGeometry methods:
|
||||
|
||||
/* void render (in nsISVGRendererCanvas canvas); */
|
||||
/** Implements void render(in nsISVGRendererCanvas canvas); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphGeometry::Render(nsISVGRendererCanvas *canvas)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsISVGRendererRegion update (in unsigned long updatemask); */
|
||||
/** Implements nsISVGRendererRegion update(in unsigned long updatemask); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphGeometry::Update(PRUint32 updatemask, nsISVGRendererRegion **_retval)
|
||||
{
|
||||
@@ -139,7 +144,7 @@ nsSVGLibartGlyphGeometry::Update(PRUint32 updatemask, nsISVGRendererRegion **_re
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsISVGRendererRegion getCoveredRegion (); */
|
||||
/** Implements nsISVGRendererRegion getCoveredRegion(); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphGeometry::GetCoveredRegion(nsISVGRendererRegion **_retval)
|
||||
{
|
||||
@@ -147,7 +152,7 @@ nsSVGLibartGlyphGeometry::GetCoveredRegion(nsISVGRendererRegion **_retval)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* boolean containsPoint (in float x, in float y); */
|
||||
/** Implements boolean containsPoint(in float x, in float y); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphGeometry::ContainsPoint(float x, float y, PRBool *_retval)
|
||||
{
|
||||
@@ -0,0 +1,49 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla SVG project.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Crocodile Clips Ltd..
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ----- END LICENSE BLOCK ----- */
|
||||
|
||||
#ifndef __NS_SVGLIBART_GLYPHGEOMETRYDEFAULT_H__
|
||||
#define __NS_SVGLIBART_GLYPHGEOMETRYDEFAULT_H__
|
||||
|
||||
class nsISVGRendererGlyphGeometry;
|
||||
class nsISVGGlyphGeometrySource;
|
||||
|
||||
nsresult
|
||||
NS_NewSVGLibartGlyphGeometryDefault(nsISVGRendererGlyphGeometry **result,
|
||||
nsISVGGlyphGeometrySource *src);
|
||||
|
||||
#endif // __NS_SVGLIBART_GLYPHGEOMETRYDEFAULT_H__
|
||||
@@ -0,0 +1,294 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla SVG project.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* .
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Leon Sha <leon.sha@sun.com>
|
||||
* Alex Fritze <alex@croczilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ----- END LICENSE BLOCK ----- */
|
||||
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsISVGRendererGlyphGeometry.h"
|
||||
#include "nsIDOMSVGMatrix.h"
|
||||
#include "nsISVGGlyphGeometrySource.h"
|
||||
#include "nsPromiseFlatString.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsMemory.h"
|
||||
|
||||
#include "nsSVGLibartFreetype.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsISVGLibartGlyphMetricsFT.h"
|
||||
#include "libart-incs.h"
|
||||
#include "nsISVGLibartCanvas.h"
|
||||
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Libart freetype-based glyph geometry implementation
|
||||
*/
|
||||
class nsSVGLibartGlyphGeometryFT : public nsISVGRendererGlyphGeometry
|
||||
{
|
||||
protected:
|
||||
friend nsresult NS_NewSVGLibartGlyphGeometryFT(nsISVGRendererGlyphGeometry **result,
|
||||
nsISVGGlyphGeometrySource *src);
|
||||
|
||||
nsSVGLibartGlyphGeometryFT();
|
||||
~nsSVGLibartGlyphGeometryFT();
|
||||
nsresult Init(nsISVGGlyphGeometrySource* src);
|
||||
|
||||
public:
|
||||
// nsISupports interface:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISVGRendererGlyphGeometry interface:
|
||||
NS_DECL_NSISVGRENDERERGLYPHGEOMETRY
|
||||
|
||||
protected:
|
||||
void PaintFill(nsISVGLibartCanvas* canvas, nsISVGLibartGlyphMetricsFT* metrics);
|
||||
nsCOMPtr<nsISVGGlyphGeometrySource> mSource;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// implementation:
|
||||
|
||||
nsSVGLibartGlyphGeometryFT::nsSVGLibartGlyphGeometryFT()
|
||||
{
|
||||
}
|
||||
|
||||
nsSVGLibartGlyphGeometryFT::~nsSVGLibartGlyphGeometryFT()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSVGLibartGlyphGeometryFT::Init(nsISVGGlyphGeometrySource* src)
|
||||
{
|
||||
mSource = src;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewSVGLibartGlyphGeometryFT(nsISVGRendererGlyphGeometry **result,
|
||||
nsISVGGlyphGeometrySource *src)
|
||||
{
|
||||
*result = nsnull;
|
||||
|
||||
nsSVGLibartGlyphGeometryFT* gg = new nsSVGLibartGlyphGeometryFT();
|
||||
if (!gg) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(gg);
|
||||
|
||||
nsresult rv = gg->Init(src);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(gg);
|
||||
return rv;
|
||||
}
|
||||
|
||||
*result = gg;
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsISupports methods:
|
||||
|
||||
NS_IMPL_ADDREF(nsSVGLibartGlyphGeometryFT)
|
||||
NS_IMPL_RELEASE(nsSVGLibartGlyphGeometryFT)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsSVGLibartGlyphGeometryFT)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISVGRendererGlyphGeometry)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsISVGRendererGlyphGeometry methods:
|
||||
|
||||
/** Implements void render(in nsISVGRendererCanvas canvas); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphGeometryFT::Render(nsISVGRendererCanvas *canvas)
|
||||
{
|
||||
nsCOMPtr<nsISVGLibartCanvas> libartCanvas = do_QueryInterface(canvas);
|
||||
NS_ASSERTION(libartCanvas, "wrong svg render context for geometry!");
|
||||
if (!libartCanvas) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsISVGLibartGlyphMetricsFT> metrics;
|
||||
{
|
||||
nsCOMPtr<nsISVGRendererGlyphMetrics> xpmetrics;
|
||||
mSource->GetMetrics(getter_AddRefs(xpmetrics));
|
||||
metrics = do_QueryInterface(xpmetrics);
|
||||
NS_ASSERTION(metrics, "wrong metrics object!");
|
||||
if (!metrics) return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
PRBool hasFill = PR_FALSE;
|
||||
{
|
||||
PRUint16 filltype;
|
||||
mSource->GetFillPaintType(&filltype);
|
||||
if (filltype == nsISVGGeometrySource::PAINT_TYPE_SOLID_COLOR)
|
||||
hasFill = PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool hasStroke = PR_FALSE;
|
||||
{
|
||||
PRUint16 stroketype;
|
||||
mSource->GetStrokePaintType(&stroketype);
|
||||
if (stroketype == nsISVGGeometrySource::PAINT_TYPE_SOLID_COLOR)
|
||||
hasStroke = PR_TRUE;
|
||||
}
|
||||
|
||||
if (hasFill)
|
||||
PaintFill(libartCanvas, metrics);
|
||||
|
||||
// XXX
|
||||
// if (hasStroke)
|
||||
// PaintStroke(libartCanvas, metrics);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Implements nsISVGRendererRegion update(in unsigned long updatemask); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphGeometryFT::Update(PRUint32 updatemask, nsISVGRendererRegion **_retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** Implements nsISVGRendererRegion getCoveredRegion(); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphGeometryFT::GetCoveredRegion(nsISVGRendererRegion **_retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** Implements boolean containsPoint(in float x, in float y); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphGeometryFT::ContainsPoint(float x, float y, PRBool *_retval)
|
||||
{
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsSVGLibartGlyphGeometryFT::PaintFill(nsISVGLibartCanvas* canvas,
|
||||
nsISVGLibartGlyphMetricsFT* metrics)
|
||||
{
|
||||
FT_Matrix xform;
|
||||
FT_Vector delta;
|
||||
{
|
||||
float x,y;
|
||||
mSource->GetX(&x);
|
||||
mSource->GetY(&y);
|
||||
|
||||
nsCOMPtr<nsIDOMSVGMatrix> ctm;
|
||||
mSource->GetCTM(getter_AddRefs(ctm));
|
||||
NS_ASSERTION(ctm, "graphic source didn't specify a ctm");
|
||||
|
||||
// negations of B,C,F are to transform matrix from y-down to y-up
|
||||
|
||||
float a,b,c,d,e,f;
|
||||
ctm->GetA(&a);
|
||||
xform.xx = (FT_Fixed)(a*0x10000L); // convert to 16.16 fixed
|
||||
ctm->GetB(&b);
|
||||
xform.yx = (FT_Fixed)(-b*0x10000L);
|
||||
ctm->GetC(&c);
|
||||
xform.xy = (FT_Fixed)(-c*0x10000L);
|
||||
ctm->GetD(&d);
|
||||
xform.yy = (FT_Fixed)(d*0x10000L);
|
||||
ctm->GetE(&e);
|
||||
delta.x = (FT_Pos)((a*x+c*y+e)*64); // convert to 26.6 fixed
|
||||
ctm->GetF(&f);
|
||||
delta.y = (FT_Pos)(-(b*x+d*y+f)*64);
|
||||
}
|
||||
|
||||
float opacity;
|
||||
mSource->GetFillOpacity(&opacity);
|
||||
|
||||
ArtColor fill_color;
|
||||
{
|
||||
nscolor rgb;
|
||||
mSource->GetFillPaint(&rgb);
|
||||
canvas->GetArtColor(rgb, fill_color);
|
||||
}
|
||||
|
||||
PRUint32 glyph_count = metrics->GetGlyphCount();
|
||||
|
||||
for (PRUint32 i=0; i<glyph_count; ++i) {
|
||||
FT_Glyph glyph;
|
||||
nsSVGLibartFreetype::ft2->GlyphCopy(metrics->GetGlyphAt(i), &glyph);
|
||||
|
||||
nsSVGLibartFreetype::ft2->GlyphTransform(glyph, &xform, &delta);
|
||||
|
||||
if (NS_SUCCEEDED(nsSVGLibartFreetype::ft2->GlyphToBitmap(&glyph,
|
||||
FT_RENDER_MODE_NORMAL,
|
||||
nsnull, // translation
|
||||
1 // destroy glyph copy
|
||||
))) {
|
||||
FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph;
|
||||
|
||||
ArtRender* render = canvas->NewRender(bitmap->left,
|
||||
-bitmap->top,
|
||||
bitmap->left+bitmap->bitmap.width,
|
||||
-bitmap->top+bitmap->bitmap.rows);
|
||||
if (render) {
|
||||
art_render_image_solid(render, fill_color);
|
||||
art_render_mask_solid(render, (int)(0x10000*opacity));
|
||||
|
||||
art_render_mask(render,
|
||||
bitmap->left,
|
||||
-bitmap->top,
|
||||
bitmap->left+bitmap->bitmap.width,
|
||||
-bitmap->top+bitmap->bitmap.rows,
|
||||
bitmap->bitmap.buffer,
|
||||
bitmap->bitmap.pitch);
|
||||
canvas->InvokeRender(render);
|
||||
}
|
||||
}
|
||||
nsSVGLibartFreetype::ft2->DoneGlyph(glyph);
|
||||
}
|
||||
}
|
||||
@@ -36,14 +36,14 @@
|
||||
*
|
||||
* ----- END LICENSE BLOCK ----- */
|
||||
|
||||
#ifndef __NS_SVGLIBART_GLYPHGEOMETRY_H__
|
||||
#define __NS_SVGLIBART_GLYPHGEOMETRY_H__
|
||||
#ifndef __NS_SVGLIBART_GLYPHGEOMETRYFT_H__
|
||||
#define __NS_SVGLIBART_GLYPHGEOMETRYFT_H__
|
||||
|
||||
class nsISVGRendererGlyphGeometry;
|
||||
class nsISVGGlyphGeometrySource;
|
||||
|
||||
nsresult
|
||||
NS_NewSVGLibartGlyphGeometry(nsISVGRendererGlyphGeometry **result,
|
||||
nsISVGGlyphGeometrySource *src);
|
||||
NS_NewSVGLibartGlyphGeometryFT(nsISVGRendererGlyphGeometry **result,
|
||||
nsISVGGlyphGeometrySource *src);
|
||||
|
||||
#endif // __NS_SVGLIBART_GLYPHGEOMETRY_H__
|
||||
#endif // __NS_SVGLIBART_GLYPHGEOMETRYFT_H__
|
||||
@@ -43,22 +43,26 @@
|
||||
#include "nsFont.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsSVGLibartGlyphMetrics.h"
|
||||
#include "float.h"
|
||||
#include "nsIDOMSVGMatrix.h"
|
||||
#include "nsIDOMSVGRect.h"
|
||||
#include "nsSVGTypeCIDs.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsSVGLibartGlyphMetrics class
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Default Libart glyph metrics implementation.
|
||||
*/
|
||||
class nsSVGLibartGlyphMetrics : public nsISVGRendererGlyphMetrics
|
||||
{
|
||||
protected:
|
||||
friend nsresult NS_NewSVGLibartGlyphMetrics(nsISVGRendererGlyphMetrics **result,
|
||||
nsISVGGlyphMetricsSource *src);
|
||||
friend nsresult NS_NewSVGLibartGlyphMetricsDefault(nsISVGRendererGlyphMetrics **result,
|
||||
nsISVGGlyphMetricsSource *src);
|
||||
|
||||
nsSVGLibartGlyphMetrics(nsISVGGlyphMetricsSource *src);
|
||||
~nsSVGLibartGlyphMetrics();
|
||||
public:
|
||||
@@ -72,6 +76,8 @@ private:
|
||||
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// implementation:
|
||||
|
||||
@@ -84,8 +90,8 @@ nsSVGLibartGlyphMetrics::~nsSVGLibartGlyphMetrics()
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewSVGLibartGlyphMetrics(nsISVGRendererGlyphMetrics **result,
|
||||
nsISVGGlyphMetricsSource *src)
|
||||
NS_NewSVGLibartGlyphMetricsDefault(nsISVGRendererGlyphMetrics **result,
|
||||
nsISVGGlyphMetricsSource *src)
|
||||
{
|
||||
*result = new nsSVGLibartGlyphMetrics(src);
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
@@ -108,7 +114,7 @@ NS_INTERFACE_MAP_END
|
||||
//----------------------------------------------------------------------
|
||||
// nsISVGRendererGlyphMetrics methods:
|
||||
|
||||
/* float getBaselineOffset (in unsigned short baselineIdentifier); */
|
||||
/** Implements float getBaselineOffset(in unsigned short baselineIdentifier); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphMetrics::GetBaselineOffset(PRUint16 baselineIdentifier, float *_retval)
|
||||
{
|
||||
@@ -131,7 +137,7 @@ nsSVGLibartGlyphMetrics::GetBaselineOffset(PRUint16 baselineIdentifier, float *_
|
||||
}
|
||||
|
||||
|
||||
/* readonly attribute float advance; */
|
||||
/** Implements readonly attribute float #advance; */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphMetrics::GetAdvance(float *aAdvance)
|
||||
{
|
||||
@@ -139,7 +145,7 @@ nsSVGLibartGlyphMetrics::GetAdvance(float *aAdvance)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMSVGRect boundingBox; */
|
||||
/** Implements readonly attribute nsIDOMSVGRect #boundingBox; */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphMetrics::GetBoundingBox(nsIDOMSVGRect * *aBoundingBox)
|
||||
{
|
||||
@@ -161,7 +167,7 @@ nsSVGLibartGlyphMetrics::GetBoundingBox(nsIDOMSVGRect * *aBoundingBox)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* [noscript] nsIDOMSVGRect getExtentOfChar (in unsigned long charnum); */
|
||||
/** Implements [noscript] nsIDOMSVGRect getExtentOfChar(in unsigned long charnum); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphMetrics::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)
|
||||
{
|
||||
@@ -183,7 +189,7 @@ nsSVGLibartGlyphMetrics::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retv
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* boolean update (in unsigned long updatemask); */
|
||||
/** Implements boolean update(in unsigned long updatemask); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphMetrics::Update(PRUint32 updatemask, PRBool *_retval)
|
||||
{
|
||||
@@ -36,13 +36,13 @@
|
||||
*
|
||||
* ----- END LICENSE BLOCK ----- */
|
||||
|
||||
#ifndef __NS_SVGLIBART_GLYPHMETRICS_H__
|
||||
#define __NS_SVGLIBART_GLYPHMETRICS_H__
|
||||
#ifndef __NS_SVGLIBART_GLYPHMETRICSDEFAULT_H__
|
||||
#define __NS_SVGLIBART_GLYPHMETRICSDEFAULT_H__
|
||||
|
||||
class nsISVGRendererGlyphMetrics;
|
||||
class nsISVGGlyphMetricsSource;
|
||||
|
||||
nsresult NS_NewSVGLibartGlyphMetrics(nsISVGRendererGlyphMetrics **result,
|
||||
nsISVGGlyphMetricsSource *src);
|
||||
nsresult NS_NewSVGLibartGlyphMetricsDefault(nsISVGRendererGlyphMetrics **result,
|
||||
nsISVGGlyphMetricsSource *src);
|
||||
|
||||
#endif // __NS_SVGLIBART_GLYPHMETRICS_H__
|
||||
#endif // __NS_SVGLIBART_GLYPHMETRICSDEFAULT_H__
|
||||
@@ -0,0 +1,547 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla SVG project.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* .
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Leon Sha <leon.sha@sun.com>
|
||||
* Alex Fritze <alex@croczilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ----- END LICENSE BLOCK ----- */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsISVGGlyphMetricsSource.h"
|
||||
#include "nsISVGRendererGlyphMetrics.h"
|
||||
#include "nsPromiseFlatString.h"
|
||||
#include "nsFont.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "float.h"
|
||||
#include "nsIDOMSVGMatrix.h"
|
||||
#include "nsIDOMSVGRect.h"
|
||||
#include "nsSVGTypeCIDs.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsISVGLibartGlyphMetricsFT.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsSVGLibartFreetype.h"
|
||||
#include "libart-incs.h"
|
||||
#include "nsArray.h"
|
||||
#include "nsDataHashtable.h"
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Libart freetype-based glyph metrics implementation.
|
||||
* Conditionally compiled in for freetype-enabled builds only.
|
||||
*/
|
||||
class nsSVGLibartGlyphMetricsFT : public nsISVGLibartGlyphMetricsFT
|
||||
{
|
||||
protected:
|
||||
friend nsresult NS_NewSVGLibartGlyphMetricsFT(nsISVGRendererGlyphMetrics **result,
|
||||
nsISVGGlyphMetricsSource *src);
|
||||
friend void NS_InitSVGLibartGlyphMetricsFTGlobals();
|
||||
friend void NS_FreeSVGLibartGlyphMetricsFTGlobals();
|
||||
|
||||
nsSVGLibartGlyphMetricsFT(nsISVGGlyphMetricsSource *src);
|
||||
~nsSVGLibartGlyphMetricsFT();
|
||||
|
||||
// nsISupports interface:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISVGRendererGlyphMetrics interface:
|
||||
NS_DECL_NSISVGRENDERERGLYPHMETRICS
|
||||
|
||||
// nsISVGLibartGlyphMetrics interface:
|
||||
NS_IMETHOD_(FT_Face) GetFTFace();
|
||||
NS_IMETHOD_(float) GetPixelScale();
|
||||
NS_IMETHOD_(float) GetTwipsToPixels();
|
||||
NS_IMETHOD_(const FT_BBox*) GetBoundingBox();
|
||||
NS_IMETHOD_(PRUint32) GetGlyphCount();
|
||||
NS_IMETHOD_(FT_Glyph) GetGlyphAt(PRUint32 pos);
|
||||
|
||||
// helpers :
|
||||
void InitializeFace();
|
||||
void ClearFace() { mFace = nsnull; }
|
||||
void InitializeGlyphArray();
|
||||
void ClearGlyphArray();
|
||||
private:
|
||||
FT_Face mFace;
|
||||
|
||||
struct GlyphDescriptor {
|
||||
GlyphDescriptor() : index(0), image(nsnull) {};
|
||||
~GlyphDescriptor() { if (image) nsSVGLibartFreetype::ft2->DoneGlyph(image); }
|
||||
FT_UInt index; // glyph index
|
||||
FT_Glyph image; // glyph image translated to correct position within string
|
||||
};
|
||||
|
||||
GlyphDescriptor *mGlyphArray;
|
||||
PRUint32 mGlyphArrayLength;
|
||||
FT_BBox mBBox;
|
||||
|
||||
nsCOMPtr<nsISVGGlyphMetricsSource> mSource;
|
||||
|
||||
public:
|
||||
static nsDataHashtable<nsStringHashKey,nsDependentString*> sFontAliases;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsSVGLibartGlyphMetricsFT implementation:
|
||||
|
||||
nsDataHashtable<nsStringHashKey,nsDependentString*>
|
||||
nsSVGLibartGlyphMetricsFT::sFontAliases;
|
||||
|
||||
|
||||
nsSVGLibartGlyphMetricsFT::nsSVGLibartGlyphMetricsFT(nsISVGGlyphMetricsSource *src)
|
||||
: mSource(src), mFace(nsnull), mGlyphArray(nsnull), mGlyphArrayLength(0)
|
||||
{
|
||||
}
|
||||
|
||||
nsSVGLibartGlyphMetricsFT::~nsSVGLibartGlyphMetricsFT()
|
||||
{
|
||||
ClearGlyphArray();
|
||||
ClearFace();
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewSVGLibartGlyphMetricsFT(nsISVGRendererGlyphMetrics **result,
|
||||
nsISVGGlyphMetricsSource *src)
|
||||
{
|
||||
*result = new nsSVGLibartGlyphMetricsFT(src);
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void NS_InitSVGLibartGlyphMetricsFTGlobals()
|
||||
{
|
||||
|
||||
NS_ASSERTION(!nsSVGLibartGlyphMetricsFT::sFontAliases.IsInitialized(),
|
||||
"font aliases already initialized");
|
||||
nsSVGLibartGlyphMetricsFT::sFontAliases.Init(3);
|
||||
|
||||
static NS_NAMED_LITERAL_STRING(arial, "arial");
|
||||
nsSVGLibartGlyphMetricsFT::sFontAliases.Put(NS_LITERAL_STRING("helvetica"),
|
||||
&arial);
|
||||
|
||||
static NS_NAMED_LITERAL_STRING(courier, "courier new");
|
||||
nsSVGLibartGlyphMetricsFT::sFontAliases.Put(NS_LITERAL_STRING("courier"),
|
||||
&courier);
|
||||
|
||||
static NS_NAMED_LITERAL_STRING(times, "times new roman");
|
||||
nsSVGLibartGlyphMetricsFT::sFontAliases.Put(NS_LITERAL_STRING("times"),
|
||||
×);
|
||||
}
|
||||
|
||||
void NS_FreeSVGLibartGlyphMetricsFTGlobals()
|
||||
{
|
||||
NS_ASSERTION(nsSVGLibartGlyphMetricsFT::sFontAliases.IsInitialized(),
|
||||
"font aliases never initialized");
|
||||
nsSVGLibartGlyphMetricsFT::sFontAliases.Clear();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsISupports methods:
|
||||
|
||||
NS_IMPL_ADDREF(nsSVGLibartGlyphMetricsFT)
|
||||
NS_IMPL_RELEASE(nsSVGLibartGlyphMetricsFT)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsSVGLibartGlyphMetricsFT)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISVGRendererGlyphMetrics)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISVGLibartGlyphMetricsFT)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsISVGRendererGlyphMetrics methods:
|
||||
|
||||
/** Implements float getBaselineOffset(in unsigned short baselineIdentifier); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphMetricsFT::GetBaselineOffset(PRUint16 baselineIdentifier, float *_retval)
|
||||
{
|
||||
*_retval = 0.0f;
|
||||
|
||||
switch (baselineIdentifier) {
|
||||
case BASELINE_TEXT_BEFORE_EDGE:
|
||||
break;
|
||||
case BASELINE_TEXT_AFTER_EDGE:
|
||||
break;
|
||||
case BASELINE_CENTRAL:
|
||||
case BASELINE_MIDDLE:
|
||||
break;
|
||||
case BASELINE_ALPHABETIC:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/** Implements readonly attribute float #advance; */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphMetricsFT::GetAdvance(float *aAdvance)
|
||||
{
|
||||
InitializeGlyphArray();
|
||||
*aAdvance = mBBox.xMax-mBBox.yMin;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** Implements readonly attribute nsIDOMSVGRect #boundingBox; */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphMetricsFT::GetBoundingBox(nsIDOMSVGRect * *aBoundingBox)
|
||||
{
|
||||
InitializeGlyphArray();
|
||||
|
||||
*aBoundingBox = nsnull;
|
||||
|
||||
nsCOMPtr<nsIDOMSVGRect> rect = do_CreateInstance(NS_SVGRECT_CONTRACTID);
|
||||
|
||||
NS_ASSERTION(rect, "could not create rect");
|
||||
if (!rect) return NS_ERROR_FAILURE;
|
||||
|
||||
rect->SetX(mBBox.xMin);
|
||||
rect->SetY(mBBox.yMin);
|
||||
rect->SetWidth(mBBox.xMax-mBBox.xMin);
|
||||
rect->SetHeight(mBBox.yMax-mBBox.yMin);
|
||||
|
||||
*aBoundingBox = rect;
|
||||
NS_ADDREF(*aBoundingBox);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** Implements [noscript] nsIDOMSVGRect getExtentOfChar(in unsigned long charnum); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphMetricsFT::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
|
||||
nsCOMPtr<nsIDOMSVGRect> rect = do_CreateInstance(NS_SVGRECT_CONTRACTID);
|
||||
|
||||
NS_ASSERTION(rect, "could not create rect");
|
||||
if (!rect) return NS_ERROR_FAILURE;
|
||||
|
||||
rect->SetX(0);
|
||||
rect->SetY(0);
|
||||
rect->SetWidth(0);
|
||||
rect->SetHeight(0);
|
||||
|
||||
*_retval = rect;
|
||||
NS_ADDREF(*_retval);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** Implements boolean update(in unsigned long updatemask); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartGlyphMetricsFT::Update(PRUint32 updatemask, PRBool *_retval)
|
||||
{
|
||||
*_retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsISVGLibartGlyphMetrics methods:
|
||||
|
||||
NS_IMETHODIMP_(FT_Face)
|
||||
nsSVGLibartGlyphMetricsFT::GetFTFace()
|
||||
{
|
||||
InitializeFace();
|
||||
return mFace;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(float)
|
||||
nsSVGLibartGlyphMetricsFT::GetPixelScale()
|
||||
{
|
||||
nsCOMPtr<nsIPresContext> presContext;
|
||||
mSource->GetPresContext(getter_AddRefs(presContext));
|
||||
if (!presContext) {
|
||||
NS_ERROR("null prescontext");
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDeviceContext> devicecontext;
|
||||
presContext->GetDeviceContext(getter_AddRefs(devicecontext));
|
||||
|
||||
float scale;
|
||||
devicecontext->GetCanonicalPixelScale(scale);
|
||||
return scale;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(float)
|
||||
nsSVGLibartGlyphMetricsFT::GetTwipsToPixels()
|
||||
{
|
||||
nsCOMPtr<nsIPresContext> presContext;
|
||||
mSource->GetPresContext(getter_AddRefs(presContext));
|
||||
if (!presContext) {
|
||||
NS_ERROR("null prescontext");
|
||||
return 1.0f;
|
||||
}
|
||||
float twipstopixel;
|
||||
presContext->GetTwipsToPixels(&twipstopixel);
|
||||
return twipstopixel;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(const FT_BBox*)
|
||||
nsSVGLibartGlyphMetricsFT::GetBoundingBox()
|
||||
{
|
||||
InitializeGlyphArray();
|
||||
return &mBBox;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRUint32)
|
||||
nsSVGLibartGlyphMetricsFT::GetGlyphCount()
|
||||
{
|
||||
InitializeGlyphArray();
|
||||
return mGlyphArrayLength;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(FT_Glyph)
|
||||
nsSVGLibartGlyphMetricsFT::GetGlyphAt(PRUint32 pos)
|
||||
{
|
||||
NS_ASSERTION(pos<mGlyphArrayLength, "out of range");
|
||||
return mGlyphArray[pos].image;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Implementation helpers:
|
||||
|
||||
|
||||
struct FindFontStruct {
|
||||
nsCOMPtr<nsITrueTypeFontCatalogEntry> font_entry;
|
||||
nsFont font;
|
||||
};
|
||||
|
||||
static PRBool
|
||||
FindFont(const nsString& aFamily, PRBool aGeneric, void *aData)
|
||||
{
|
||||
PRBool retval = PR_TRUE;
|
||||
|
||||
FindFontStruct* &font_data = (FindFontStruct*) aData;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("trying to instantiate font %s, generic=%d\n", NS_ConvertUCS2toUTF8(aFamily).get(),
|
||||
aGeneric);
|
||||
#endif
|
||||
|
||||
nsCAutoString family_name;
|
||||
|
||||
if (aGeneric) {
|
||||
PRUint8 id;
|
||||
nsFont::GetGenericID(aFamily, &id);
|
||||
switch (id) {
|
||||
case kGenericFont_serif:
|
||||
family_name = NS_LITERAL_CSTRING("times new roman");
|
||||
break;
|
||||
case kGenericFont_monospace:
|
||||
family_name = NS_LITERAL_CSTRING("courier new");
|
||||
break;
|
||||
case kGenericFont_sans_serif:
|
||||
default:
|
||||
family_name = NS_LITERAL_CSTRING("arial");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
family_name = NS_ConvertUCS2toUTF8(aFamily);
|
||||
ToLowerCase(family_name);
|
||||
}
|
||||
|
||||
nsCAutoString language;
|
||||
PRUint16 slant = nsIFontCatalogService::kFCSlantRoman;
|
||||
if (font_data->font.style && NS_FONT_STYLE_ITALIC)
|
||||
slant = nsIFontCatalogService::kFCSlantItalic;
|
||||
|
||||
nsCOMPtr<nsIArray> arr;
|
||||
nsSVGLibartFreetype::fontCatalog->GetFontCatalogEntries(family_name,
|
||||
language,
|
||||
font_data->font.weight,
|
||||
nsIFontCatalogService::kFCWeightAny,
|
||||
slant,
|
||||
nsIFontCatalogService::kFCSpacingAny,
|
||||
getter_AddRefs(arr));
|
||||
PRUint32 count;
|
||||
arr->GetLength(&count);
|
||||
#ifdef DEBUG
|
||||
printf("FindFont(%s): number of fonts found: %d\n", family_name.get(), count);
|
||||
#endif
|
||||
if (count>0) {
|
||||
retval = PR_FALSE; // break
|
||||
// just take the first one for now:
|
||||
arr->QueryElementAt(0, NS_GET_IID(nsITrueTypeFontCatalogEntry),
|
||||
getter_AddRefs(font_data->font_entry));
|
||||
}
|
||||
else {
|
||||
// try alias if there is one:
|
||||
nsDependentString *alias = nsnull;
|
||||
nsSVGLibartGlyphMetricsFT::sFontAliases.Get(NS_ConvertUTF8toUCS2(family_name),
|
||||
&alias);
|
||||
if (alias) {
|
||||
// XXX this might cause a stack-overflow if there are cyclic
|
||||
// aliases in sFontAliases
|
||||
retval = FindFont(nsString(*alias), PR_FALSE, aData);
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
nsSVGLibartGlyphMetricsFT::InitializeFace()
|
||||
{
|
||||
if (mFace) return; // already initialized
|
||||
|
||||
FindFontStruct font_data;
|
||||
mSource->GetFont(&font_data.font);
|
||||
|
||||
font_data.font.EnumerateFamilies(FindFont, (void*)&font_data);
|
||||
|
||||
if (!font_data.font_entry) {
|
||||
// try to find *any* font
|
||||
nsAutoString empty;
|
||||
FindFont(empty, PR_FALSE, (void*)&font_data);
|
||||
}
|
||||
|
||||
if (!font_data.font_entry) {
|
||||
NS_ERROR("svg libart renderer can't find a font (let alone a suitable one)");
|
||||
return;
|
||||
}
|
||||
|
||||
FTC_Image_Desc imageDesc;
|
||||
imageDesc.font.face_id=(void*)font_data.font_entry.get(); // XXX do we need to addref?
|
||||
float twipstopixel = GetTwipsToPixels();
|
||||
float scale = GetPixelScale();
|
||||
imageDesc.font.pix_width = (int)((float)(font_data.font.size)*twipstopixel/scale);
|
||||
imageDesc.font.pix_height = (int)((float)(font_data.font.size)*twipstopixel/scale);
|
||||
imageDesc.image_type |= ftc_image_grays;
|
||||
|
||||
// get the face
|
||||
nsresult rv;
|
||||
FTC_Manager mgr;
|
||||
nsSVGLibartFreetype::ft2->GetFTCacheManager(&mgr);
|
||||
rv = nsSVGLibartFreetype::ft2->ManagerLookupSize(mgr, &imageDesc.font, &mFace, nsnull);
|
||||
NS_ASSERTION(mFace, "failed to get face/size");
|
||||
}
|
||||
|
||||
void nsSVGLibartGlyphMetricsFT::InitializeGlyphArray()
|
||||
{
|
||||
if (mGlyphArray) return; // already initialized
|
||||
|
||||
InitializeFace();
|
||||
if (!mFace) {
|
||||
NS_ERROR("no face");
|
||||
return;
|
||||
}
|
||||
FT_GlyphSlot glyphslot=mFace->glyph;
|
||||
|
||||
mBBox.xMin = mBBox.yMin = 3200;
|
||||
mBBox.xMax = mBBox.yMax = -3200;
|
||||
|
||||
nsAutoString text;
|
||||
mSource->GetCharacterData(text);
|
||||
mGlyphArrayLength = text.Length();
|
||||
if (mGlyphArrayLength == 0) return;
|
||||
|
||||
mGlyphArray = new GlyphDescriptor[mGlyphArrayLength];
|
||||
NS_ASSERTION(mGlyphArray, "could not allocate glyph descriptor array");
|
||||
|
||||
GlyphDescriptor* glyph = mGlyphArray;
|
||||
bool use_kerning = FT_HAS_KERNING(mFace);
|
||||
FT_UInt previous_glyph = 0;
|
||||
FT_Vector pen; // pen position in 26.6 format
|
||||
pen.x = 0;
|
||||
pen.y = 0;
|
||||
|
||||
nsAString::const_iterator start, end;
|
||||
text.BeginReading(start);
|
||||
text.EndReading(end);
|
||||
PRUint32 size;
|
||||
|
||||
for ( ; start!=end; start.advance(size)) {
|
||||
const PRUnichar* buf = start.get();
|
||||
size = start.size_forward();
|
||||
// fragment at 'buf' is 'size' characters long
|
||||
for (PRUint32 i=0; i<size; ++i) {
|
||||
nsSVGLibartFreetype::ft2->GetCharIndex(mFace, buf[i], &glyph->index);
|
||||
|
||||
if (use_kerning && previous_glyph && glyph->index) {
|
||||
FT_Vector delta;
|
||||
nsSVGLibartFreetype::ft2->GetKerning(mFace, previous_glyph,
|
||||
glyph->index,
|
||||
FT_KERNING_DEFAULT,
|
||||
&delta);
|
||||
pen.x += delta.x;
|
||||
}
|
||||
|
||||
// load glyph into the face's shared glyph slot:
|
||||
if (NS_FAILED(nsSVGLibartFreetype::ft2->LoadGlyph(mFace,
|
||||
glyph->index,
|
||||
FT_LOAD_DEFAULT))) {
|
||||
NS_ERROR("error loading glyph");
|
||||
continue;
|
||||
}
|
||||
|
||||
// copy glyph image into array:
|
||||
if (NS_FAILED(nsSVGLibartFreetype::ft2->GetGlyph(glyphslot, &glyph->image))) {
|
||||
NS_ERROR("error copying glyph");
|
||||
continue;
|
||||
}
|
||||
|
||||
// translate glyph image to correct location within string:
|
||||
nsSVGLibartFreetype::ft2->GlyphTransform(glyph->image, 0, &pen);
|
||||
|
||||
// update the string's bounding box:
|
||||
FT_BBox glyph_bbox;
|
||||
nsSVGLibartFreetype::ft2->GlyphGetCBox(glyph->image, ft_glyph_bbox_pixels, &glyph_bbox);
|
||||
mBBox.xMin = PR_MIN(mBBox.xMin, glyph_bbox.xMin);
|
||||
mBBox.xMax = PR_MAX(mBBox.xMax, glyph_bbox.xMax);
|
||||
mBBox.yMin = PR_MIN(mBBox.yMin, glyph_bbox.yMin);
|
||||
mBBox.yMax = PR_MAX(mBBox.yMax, glyph_bbox.yMax);
|
||||
|
||||
pen.x += glyphslot->advance.x;
|
||||
previous_glyph = glyph->index;
|
||||
++glyph;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nsSVGLibartGlyphMetricsFT::ClearGlyphArray()
|
||||
{
|
||||
if (mGlyphArray)
|
||||
delete[] mGlyphArray;
|
||||
mGlyphArray = nsnull;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ----- BEGIN LICENSE BLOCK -----
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla SVG project.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Crocodile Clips Ltd..
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ----- END LICENSE BLOCK ----- */
|
||||
|
||||
#ifndef __NS_SVGLIBART_GLYPHMETRICSFT_H__
|
||||
#define __NS_SVGLIBART_GLYPHMETRICSFT_H__
|
||||
|
||||
class nsISVGRendererGlyphMetrics;
|
||||
class nsISVGGlyphMetricsSource;
|
||||
|
||||
nsresult NS_NewSVGLibartGlyphMetricsFT(nsISVGRendererGlyphMetrics **result,
|
||||
nsISVGGlyphMetricsSource *src);
|
||||
void NS_InitSVGLibartGlyphMetricsFTGlobals();
|
||||
void NS_FreeSVGLibartGlyphMetricsFTGlobals();
|
||||
|
||||
#endif // __NS_SVGLIBART_GLYPHMETRICSFT_H__
|
||||
@@ -53,9 +53,14 @@
|
||||
#include "nsMemory.h"
|
||||
#include "prdtoa.h"
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsSVGLibartPathGeometry class
|
||||
|
||||
/**
|
||||
* Libart path geometry implementation
|
||||
*/
|
||||
class nsSVGLibartPathGeometry : public nsISVGRendererPathGeometry
|
||||
{
|
||||
protected:
|
||||
@@ -93,6 +98,8 @@ protected:
|
||||
nsSVGStroke mStroke;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// implementation:
|
||||
|
||||
@@ -249,7 +256,7 @@ nsSVGLibartPathGeometry::GetBezierFlatness()
|
||||
//----------------------------------------------------------------------
|
||||
// nsISVGRendererPathGeometry methods:
|
||||
|
||||
/* void render (in nsISVGRendererCanvas canvas); */
|
||||
/** Implements void render(in nsISVGRendererCanvas canvas); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartPathGeometry::Render(nsISVGRendererCanvas *canvas)
|
||||
{
|
||||
@@ -302,7 +309,7 @@ nsSVGLibartPathGeometry::Render(nsISVGRendererCanvas *canvas)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsISVGRendererRegion update (in unsigned long updatemask); */
|
||||
/** Implements nsISVGRendererRegion update(in unsigned long updatemask); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartPathGeometry::Update(PRUint32 updatemask, nsISVGRendererRegion **_retval)
|
||||
{
|
||||
@@ -356,7 +363,7 @@ nsSVGLibartPathGeometry::Update(PRUint32 updatemask, nsISVGRendererRegion **_ret
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsISVGRendererRegion getCoveredRegion (); */
|
||||
/** Implements nsISVGRendererRegion getCoveredRegion(); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartPathGeometry::GetCoveredRegion(nsISVGRendererRegion **_retval)
|
||||
{
|
||||
@@ -397,7 +404,7 @@ nsSVGLibartPathGeometry::GetCoveredRegion(nsISVGRendererRegion **_retval)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* boolean containsPoint (in float x, in float y); */
|
||||
/** Implements boolean containsPoint(in float x, in float y); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartPathGeometry::ContainsPoint(float x, float y, PRBool *_retval)
|
||||
{
|
||||
|
||||
@@ -42,9 +42,14 @@
|
||||
#include "nsISVGRectangleSink.h"
|
||||
#include <math.h>
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsSVGLibartRegion class
|
||||
|
||||
/**
|
||||
* Libart region implementation
|
||||
*/
|
||||
class nsSVGLibartRegion : public nsISVGLibartRegion // : nsISVGRendererRegion
|
||||
{
|
||||
protected:
|
||||
@@ -73,6 +78,8 @@ private:
|
||||
ArtUta* mUta;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// implementation:
|
||||
|
||||
@@ -157,7 +164,7 @@ nsSVGLibartRegion::GetUta()
|
||||
//----------------------------------------------------------------------
|
||||
// nsISVGRendererRegion methods:
|
||||
|
||||
/* nsISVGRendererRegion combine (in nsISVGRendererRegion other); */
|
||||
/** Implements nsISVGRendererRegion combine(in nsISVGRendererRegion other); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartRegion::Combine(nsISVGRendererRegion *other,
|
||||
nsISVGRendererRegion **_retval)
|
||||
@@ -196,7 +203,7 @@ nsSVGLibartRegion::Combine(nsISVGRendererRegion *other,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void getRectangleScans (in nsISVGRectangleSink sink); */
|
||||
/** Implements void getRectangleScans(in nsISVGRectangleSink sink); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGLibartRegion::GetRectangleScans(nsISVGRectangleSink *sink)
|
||||
{
|
||||
|
||||
@@ -42,6 +42,13 @@
|
||||
#include "nscore.h"
|
||||
#include "libart-incs.h"
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* Wraps a libart sorted vector path.
|
||||
*/
|
||||
class nsSVGRenderItem
|
||||
{
|
||||
public:
|
||||
@@ -61,4 +68,6 @@ protected:
|
||||
ArtSVP* mSvp;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif // __NS_SVGRENDERITEM_H__
|
||||
|
||||
@@ -39,11 +39,46 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsISVGRenderer.h"
|
||||
#include "nsSVGLibartPathGeometry.h"
|
||||
#include "nsSVGLibartGlyphGeometry.h"
|
||||
#include "nsSVGLibartGlyphMetrics.h"
|
||||
#include "nsSVGLibartCanvas.h"
|
||||
#include "nsSVGLibartRegion.h"
|
||||
#include "nsSVGLibartGlyphGeometryDefault.h"
|
||||
#include "nsSVGLibartGlyphMetricsDefault.h"
|
||||
#ifdef MOZ_ENABLE_FREETYPE2
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsSVGLibartFreetype.h"
|
||||
#include "nsSVGLibartGlyphGeometryFT.h"
|
||||
#include "nsSVGLibartGlyphMetricsFT.h"
|
||||
#include "nsIPromptService.h"
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// module initialisation
|
||||
|
||||
void NS_InitSVGRendererLibartGlobals()
|
||||
{
|
||||
// Initialization of freetype (if compiled-in) is done lazily in
|
||||
// NS_NewSVGRendererLibart(). The main reason is that we might want
|
||||
// to show error messages using the prompt service, and that's
|
||||
// probably not a good idea in *this* function, at a time when
|
||||
// layout is still not fully initialized.
|
||||
}
|
||||
|
||||
void NS_FreeSVGRendererLibartGlobals()
|
||||
{
|
||||
#ifdef MOZ_ENABLE_FREETYPE2
|
||||
NS_FreeSVGLibartGlyphMetricsFTGlobals();
|
||||
nsSVGLibartFreetype::Shutdown();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Libart-based renderer implementation
|
||||
*/
|
||||
class nsSVGRendererLibart : public nsISVGRenderer
|
||||
{
|
||||
protected:
|
||||
@@ -60,10 +95,22 @@ public:
|
||||
NS_DECL_NSISVGRENDERER
|
||||
|
||||
private:
|
||||
static PRBool sGlobalsInited;
|
||||
#ifdef MOZ_ENABLE_FREETYPE2
|
||||
static PRBool sUseFreetype;
|
||||
#endif
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// construction/destruction
|
||||
// implementation
|
||||
|
||||
PRBool nsSVGRendererLibart::sGlobalsInited = PR_FALSE;
|
||||
|
||||
#ifdef MOZ_ENABLE_FREETYPE2
|
||||
PRBool nsSVGRendererLibart::sUseFreetype = PR_FALSE;
|
||||
#endif
|
||||
|
||||
nsSVGRendererLibart::nsSVGRendererLibart()
|
||||
{
|
||||
@@ -86,6 +133,35 @@ NS_NewSVGRendererLibart(nsISVGRenderer** aResult)
|
||||
|
||||
NS_ADDREF(result);
|
||||
*aResult = result;
|
||||
|
||||
if (!nsSVGRendererLibart::sGlobalsInited) {
|
||||
#ifdef MOZ_ENABLE_FREETYPE2
|
||||
static NS_NAMED_LITERAL_CSTRING(prompt_service, "@mozilla.org/embedcomp/prompt-service;1");
|
||||
|
||||
if (!nsSVGLibartFreetype::Init()) {
|
||||
nsCOMPtr<nsIPromptService> prompter(do_GetService(prompt_service.get()));
|
||||
nsXPIDLString title(NS_LITERAL_STRING("Freetype error"));
|
||||
nsXPIDLString msg(NS_LITERAL_STRING("The Libart/Freetype SVG rendering engine could not initialize the freetype library. "
|
||||
"Please go to http://www.mozilla.org/projects/fonts/unix/enabling_truetype.html and "
|
||||
"follow steps 2-7."));
|
||||
prompter->Alert(nsnull, title, msg);
|
||||
}
|
||||
else if (!nsSVGLibartFreetype::HasSuitableFonts()) {
|
||||
nsCOMPtr<nsIPromptService> prompter(do_GetService(prompt_service.get()));
|
||||
nsXPIDLString title(NS_LITERAL_STRING("Font Configuration Error"));
|
||||
nsXPIDLString msg(NS_LITERAL_STRING("The Libart/Freetype SVG rendering engine can't find any truetype fonts on your system. "
|
||||
"Please go to http://www.mozilla.org/projects/fonts/unix/enabling_truetype.html and "
|
||||
"follow steps 2-7."));
|
||||
prompter->Alert(nsnull, title, msg);
|
||||
}
|
||||
else {
|
||||
nsSVGRendererLibart::sUseFreetype = PR_TRUE;
|
||||
NS_InitSVGLibartGlyphMetricsFTGlobals();
|
||||
}
|
||||
#endif
|
||||
nsSVGRendererLibart::sGlobalsInited = PR_TRUE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -97,7 +173,7 @@ NS_IMPL_ISUPPORTS1(nsSVGRendererLibart, nsISVGRenderer);
|
||||
//----------------------------------------------------------------------
|
||||
// nsISVGRenderer methods
|
||||
|
||||
/* nsISVGRendererPathGeometry createPathGeometry (in nsISVGPathGeometrySource src); */
|
||||
/** Implements nsISVGRendererPathGeometry createPathGeometry(in nsISVGPathGeometrySource src); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGRendererLibart::CreatePathGeometry(nsISVGPathGeometrySource *src,
|
||||
nsISVGRendererPathGeometry **_retval)
|
||||
@@ -105,24 +181,32 @@ nsSVGRendererLibart::CreatePathGeometry(nsISVGPathGeometrySource *src,
|
||||
return NS_NewSVGLibartPathGeometry(_retval, src);
|
||||
}
|
||||
|
||||
/* nsISVGRendererGlyphMetrics createGlyphMetrics (in nsISVGGlyphMetricsSource src); */
|
||||
/** Implements nsISVGRendererGlyphMetrics createGlyphMetrics(in nsISVGGlyphMetricsSource src); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGRendererLibart::CreateGlyphMetrics(nsISVGGlyphMetricsSource *src,
|
||||
nsISVGRendererGlyphMetrics **_retval)
|
||||
{
|
||||
return NS_NewSVGLibartGlyphMetrics(_retval, src);
|
||||
#ifdef MOZ_ENABLE_FREETYPE2
|
||||
if (sUseFreetype)
|
||||
return NS_NewSVGLibartGlyphMetricsFT(_retval, src);
|
||||
#endif
|
||||
return NS_NewSVGLibartGlyphMetricsDefault(_retval, src);
|
||||
}
|
||||
|
||||
/* nsISVGRendererGlyphGeometry createGlyphGeometry (in nsISVGGlyphGeometrySource src); */
|
||||
/** Implements nsISVGRendererGlyphGeometry createGlyphGeometry(in nsISVGGlyphGeometrySource src); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGRendererLibart::CreateGlyphGeometry(nsISVGGlyphGeometrySource *src,
|
||||
nsISVGRendererGlyphGeometry **_retval)
|
||||
{
|
||||
return NS_NewSVGLibartGlyphGeometry(_retval, src);
|
||||
#ifdef MOZ_ENABLE_FREETYPE2
|
||||
if (sUseFreetype)
|
||||
return NS_NewSVGLibartGlyphGeometryFT(_retval, src);
|
||||
#endif
|
||||
return NS_NewSVGLibartGlyphGeometryDefault(_retval, src);
|
||||
}
|
||||
|
||||
/* [noscript] nsISVGRendererCanvas createCanvas (in nsIRenderingContext ctx,
|
||||
in nsIPresContext presContext, [const] in nsRectRef dirtyRect); */
|
||||
/** Implements [noscript] nsISVGRendererCanvas createCanvas(in nsIRenderingContext ctx,
|
||||
in nsIPresContext presContext, const in nsRectRef dirtyRect); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGRendererLibart::CreateCanvas(nsIRenderingContext *ctx,
|
||||
nsIPresContext *presContext,
|
||||
@@ -132,7 +216,7 @@ nsSVGRendererLibart::CreateCanvas(nsIRenderingContext *ctx,
|
||||
return NS_NewSVGLibartCanvas(_retval, ctx, presContext, dirtyRect);
|
||||
}
|
||||
|
||||
/* nsISVGRendererRegion createRectRegion (in float x, in float y, in float width, in float height); */
|
||||
/** Implements nsISVGRendererRegion createRectRegion(in float x, in float y, in float width, in float height); */
|
||||
NS_IMETHODIMP
|
||||
nsSVGRendererLibart::CreateRectRegion(float x, float y, float width, float height,
|
||||
nsISVGRendererRegion **_retval)
|
||||
|
||||
@@ -44,6 +44,10 @@
|
||||
|
||||
class nsISVGPathGeometrySource;
|
||||
|
||||
/**
|
||||
* \addtogroup libart_renderer Libart Rendering Engine
|
||||
* @{
|
||||
*/
|
||||
class nsSVGStroke : public nsSVGRenderItem
|
||||
{
|
||||
public:
|
||||
@@ -53,4 +57,6 @@ protected:
|
||||
double getFlatness();
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif // __NS_SVGSTROKE_H__
|
||||
|
||||
Reference in New Issue
Block a user