1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ----- BEGIN LICENSE BLOCK -----
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is the Mozilla SVG project.
17
* The Initial Developer of the Original Code is
19
* Portions created by the Initial Developer are Copyright (C) 2002
20
* the Initial Developer. All Rights Reserved.
23
* Leon Sha <leon.sha@sun.com>
24
* Alex Fritze <alex@croczilla.com>
26
* Alternatively, the contents of this file may be used under the terms of
27
* either the GNU General Public License Version 2 or later (the "GPL"), or
28
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
* in which case the provisions of the GPL or the LGPL are applicable instead
30
* of those above. If you wish to allow use of your version of this file only
31
* under the terms of either the GPL or the LGPL, and not to allow others to
32
* use your version of this file under the terms of the NPL, indicate your
33
* decision by deleting the provisions above and replace them with the notice
34
* and other provisions required by the GPL or the LGPL. If you do not delete
35
* the provisions above, a recipient may use your version of this file under
36
* the terms of any one of the MPL, the GPL or the LGPL.
38
* ----- END LICENSE BLOCK ----- */
42
#include "nsISVGRendererGlyphGeometry.h"
43
#include "nsIDOMSVGMatrix.h"
44
#include "nsISVGGlyphGeometrySource.h"
45
#include "nsPromiseFlatString.h"
46
#include "nsIPresContext.h"
49
#include "nsSVGLibartFreetype.h"
50
#include "nsIServiceManager.h"
51
#include "nsISVGLibartGlyphMetricsFT.h"
52
#include "libart-incs.h"
53
#include "nsISVGLibartCanvas.h"
55
#include "nsIPresContext.h"
56
#include "nsIDeviceContext.h"
57
#include "nsIComponentManager.h"
60
* \addtogroup libart_renderer Libart Rendering Engine
63
////////////////////////////////////////////////////////////////////////
65
* Libart freetype-based glyph geometry implementation
67
class nsSVGLibartGlyphGeometryFT : public nsISVGRendererGlyphGeometry
70
friend nsresult NS_NewSVGLibartGlyphGeometryFT(nsISVGRendererGlyphGeometry **result,
71
nsISVGGlyphGeometrySource *src);
73
nsSVGLibartGlyphGeometryFT();
74
~nsSVGLibartGlyphGeometryFT();
75
nsresult Init(nsISVGGlyphGeometrySource* src);
78
// nsISupports interface:
81
// nsISVGRendererGlyphGeometry interface:
82
NS_DECL_NSISVGRENDERERGLYPHGEOMETRY
85
void PaintFill(nsISVGLibartCanvas* canvas, nsISVGLibartGlyphMetricsFT* metrics);
86
nsCOMPtr<nsISVGGlyphGeometrySource> mSource;
94
//----------------------------------------------------------------------
97
nsSVGLibartGlyphGeometryFT::nsSVGLibartGlyphGeometryFT()
101
nsSVGLibartGlyphGeometryFT::~nsSVGLibartGlyphGeometryFT()
106
nsSVGLibartGlyphGeometryFT::Init(nsISVGGlyphGeometrySource* src)
113
NS_NewSVGLibartGlyphGeometryFT(nsISVGRendererGlyphGeometry **result,
114
nsISVGGlyphGeometrySource *src)
118
nsSVGLibartGlyphGeometryFT* gg = new nsSVGLibartGlyphGeometryFT();
119
if (!gg) return NS_ERROR_OUT_OF_MEMORY;
123
nsresult rv = gg->Init(src);
134
//----------------------------------------------------------------------
135
// nsISupports methods:
137
NS_IMPL_ADDREF(nsSVGLibartGlyphGeometryFT)
138
NS_IMPL_RELEASE(nsSVGLibartGlyphGeometryFT)
140
NS_INTERFACE_MAP_BEGIN(nsSVGLibartGlyphGeometryFT)
141
NS_INTERFACE_MAP_ENTRY(nsISVGRendererGlyphGeometry)
142
NS_INTERFACE_MAP_ENTRY(nsISupports)
146
//----------------------------------------------------------------------
147
// nsISVGRendererGlyphGeometry methods:
149
/** Implements void render(in nsISVGRendererCanvas canvas); */
151
nsSVGLibartGlyphGeometryFT::Render(nsISVGRendererCanvas *canvas)
153
nsCOMPtr<nsISVGLibartCanvas> libartCanvas = do_QueryInterface(canvas);
154
NS_ASSERTION(libartCanvas, "wrong svg render context for geometry!");
155
if (!libartCanvas) return NS_ERROR_FAILURE;
157
nsCOMPtr<nsISVGLibartGlyphMetricsFT> metrics;
159
nsCOMPtr<nsISVGRendererGlyphMetrics> xpmetrics;
160
mSource->GetMetrics(getter_AddRefs(xpmetrics));
161
metrics = do_QueryInterface(xpmetrics);
162
NS_ASSERTION(metrics, "wrong metrics object!");
163
if (!metrics) return NS_ERROR_FAILURE;
166
PRBool hasFill = PR_FALSE;
169
mSource->GetFillPaintType(&filltype);
170
if (filltype == nsISVGGeometrySource::PAINT_TYPE_SOLID_COLOR)
174
PRBool hasStroke = PR_FALSE;
177
mSource->GetStrokePaintType(&stroketype);
178
if (stroketype == nsISVGGeometrySource::PAINT_TYPE_SOLID_COLOR)
183
PaintFill(libartCanvas, metrics);
187
// PaintStroke(libartCanvas, metrics);
193
/** Implements nsISVGRendererRegion update(in unsigned long updatemask); */
195
nsSVGLibartGlyphGeometryFT::Update(PRUint32 updatemask, nsISVGRendererRegion **_retval)
201
/** Implements nsISVGRendererRegion getCoveredRegion(); */
203
nsSVGLibartGlyphGeometryFT::GetCoveredRegion(nsISVGRendererRegion **_retval)
209
/** Implements boolean containsPoint(in float x, in float y); */
211
nsSVGLibartGlyphGeometryFT::ContainsPoint(float x, float y, PRBool *_retval)
218
nsSVGLibartGlyphGeometryFT::PaintFill(nsISVGLibartCanvas* canvas,
219
nsISVGLibartGlyphMetricsFT* metrics)
228
nsCOMPtr<nsIDOMSVGMatrix> ctm;
229
mSource->GetCTM(getter_AddRefs(ctm));
230
NS_ASSERTION(ctm, "graphic source didn't specify a ctm");
232
// negations of B,C,F are to transform matrix from y-down to y-up
236
xform.xx = (FT_Fixed)(a*0x10000L); // convert to 16.16 fixed
238
xform.yx = (FT_Fixed)(-b*0x10000L);
240
xform.xy = (FT_Fixed)(-c*0x10000L);
242
xform.yy = (FT_Fixed)(d*0x10000L);
244
delta.x = (FT_Pos)((a*x+c*y+e)*64); // convert to 26.6 fixed
246
delta.y = (FT_Pos)(-(b*x+d*y+f)*64);
250
mSource->GetFillOpacity(&opacity);
255
mSource->GetFillPaint(&rgb);
256
canvas->GetArtColor(rgb, fill_color);
259
PRUint32 glyph_count = metrics->GetGlyphCount();
261
for (PRUint32 i=0; i<glyph_count; ++i) {
263
nsSVGLibartFreetype::ft2->GlyphCopy(metrics->GetGlyphAt(i), &glyph);
265
nsSVGLibartFreetype::ft2->GlyphTransform(glyph, &xform, &delta);
267
if (NS_SUCCEEDED(nsSVGLibartFreetype::ft2->GlyphToBitmap(&glyph,
268
FT_RENDER_MODE_NORMAL,
269
nsnull, // translation
270
1 // destroy glyph copy
272
FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph;
274
ArtRender* render = canvas->NewRender(bitmap->left,
276
bitmap->left+bitmap->bitmap.width,
277
-bitmap->top+bitmap->bitmap.rows);
279
art_render_image_solid(render, fill_color);
280
art_render_mask_solid(render, (int)(0x10000*opacity));
282
art_render_mask(render,
285
bitmap->left+bitmap->bitmap.width,
286
-bitmap->top+bitmap->bitmap.rows,
287
bitmap->bitmap.buffer,
288
bitmap->bitmap.pitch);
289
canvas->InvokeRender(render);
292
nsSVGLibartFreetype::ft2->DoneGlyph(glyph);