2007-03-22 10:30:00 -07:00
|
|
|
/* -*- 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 of 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 MPL, 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 "nsSVGTextFrame.h"
|
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsTextFragment.h"
|
|
|
|
#include "nsSVGUtils.h"
|
|
|
|
#include "nsIDOMSVGLengthList.h"
|
|
|
|
#include "nsIDOMSVGLength.h"
|
|
|
|
#include "nsIDOMSVGRect.h"
|
|
|
|
#include "nsIDOMSVGPoint.h"
|
|
|
|
#include "nsSVGGlyphFrame.h"
|
|
|
|
#include "nsSVGTextPathFrame.h"
|
|
|
|
#include "nsSVGPathElement.h"
|
|
|
|
#include "nsSVGPoint.h"
|
|
|
|
#include "nsSVGRect.h"
|
|
|
|
#include "nsDOMError.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxMatrix.h"
|
2007-04-18 14:09:31 -07:00
|
|
|
#include "gfxPlatform.h"
|
2008-03-18 12:50:29 -07:00
|
|
|
#include "gfxTextRunWordCache.h"
|
2007-04-18 14:09:31 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
struct CharacterPosition {
|
|
|
|
gfxPoint pos;
|
|
|
|
gfxFloat angle;
|
|
|
|
PRBool draw;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a do-it-all helper class. It supports iterating through the
|
|
|
|
* drawable characters of a string. For each character, it can set up
|
|
|
|
* a graphics context with a transform appropriate for drawing the
|
|
|
|
* character, or a transform appropriate for emitting geometry in the
|
|
|
|
* text metrics coordinate system (which differs from the drawing
|
|
|
|
* coordinate system by a scale factor of AppUnitPerCSSPixels). These
|
|
|
|
* transforms include offsets and rotations of characters along paths, and
|
|
|
|
* the mPosition of the nsSVGGlyphFrame.
|
|
|
|
*
|
|
|
|
* This helper also creates the textrun as needed. It supports detecting
|
|
|
|
* the special case when the entire textrun can be drawn or measured
|
|
|
|
* as a unit, and setting the graphics context transform up for that. It
|
|
|
|
* takes care of setting up the global transform if requested. It also
|
|
|
|
* provides direct access to the character path position data for the
|
|
|
|
* DOM APIs that need that.
|
|
|
|
*
|
|
|
|
* If an error occurs, for example, a canvas TM is not available because
|
|
|
|
* the element is in a <defs> section, then the CharacterIterator will
|
|
|
|
* behave as if the frame has no drawable characters.
|
|
|
|
*
|
|
|
|
* XXX should make this iterate clusters instead
|
|
|
|
* XXX needs RTL love
|
|
|
|
* XXX might want to make AdvanceToCharacter constant time (e.g. by
|
|
|
|
* caching advances and/or the CharacterPosition array across DOM
|
|
|
|
* API calls) to ensure that calling Get*OfChar (etc) for each character
|
|
|
|
* in the text is O(N)
|
|
|
|
*/
|
|
|
|
class CharacterIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Sets up the iterator so that NextChar will return the first drawable
|
|
|
|
* char.
|
|
|
|
* @param aForceGlobalTransform passed on to EnsureTextRun (see below)
|
|
|
|
*/
|
|
|
|
CharacterIterator(nsSVGGlyphFrame *aSource, PRBool aForceGlobalTransform);
|
|
|
|
/**
|
|
|
|
* This matrix will be applied to aContext in the SetupFor methods below,
|
|
|
|
* before any glyph translation/rotation.
|
|
|
|
*/
|
2008-03-31 06:40:18 -07:00
|
|
|
void SetInitialMatrix(gfxContext *aContext) {
|
|
|
|
mInitialMatrix = aContext->CurrentMatrix();
|
|
|
|
if (mInitialMatrix.IsSingular()) {
|
|
|
|
mInError = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-03-18 12:50:29 -07:00
|
|
|
/**
|
|
|
|
* Try to set up aContext so we can draw the whole textrun at once.
|
2008-03-31 06:40:18 -07:00
|
|
|
* This applies any global transform requested by SetInitialMatrix,
|
2008-03-18 12:50:29 -07:00
|
|
|
* then applies the positioning of the text. Returns false if drawing
|
|
|
|
* the whole textrun at once is impossible due to individual positioning
|
|
|
|
* and/or rotation of glyphs.
|
|
|
|
*/
|
|
|
|
PRBool SetupForDirectTextRunDrawing(gfxContext *aContext) {
|
|
|
|
return SetupForDirectTextRun(aContext, mDrawScale);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Try to set up aContext so we can measure the whole textrun at once.
|
2008-03-31 06:40:18 -07:00
|
|
|
* This applies any global transform requested by SetInitialMatrix,
|
2008-03-18 12:50:29 -07:00
|
|
|
* then applies the positioning of the text, then applies a scale
|
|
|
|
* from appunits to device pixels so drawing in appunits works.
|
|
|
|
* Returns false if drawing the whole textrun at once is impossible due
|
|
|
|
* to individual positioning and/or rotation of glyphs.
|
|
|
|
*/
|
|
|
|
PRBool SetupForDirectTextRunMetrics(gfxContext *aContext) {
|
|
|
|
return SetupForDirectTextRun(aContext, mMetricsScale);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the index of the next char in the string that should be
|
|
|
|
* drawn, or -1 if there is no such character.
|
|
|
|
*/
|
|
|
|
PRInt32 NextChar();
|
|
|
|
/**
|
|
|
|
* Repeated calls NextChar until it returns aIndex (i.e. aIndex is the
|
|
|
|
* current drawable character). Returns false if that never happens
|
|
|
|
* (because aIndex is before or equal to the current character, or
|
|
|
|
* out of bounds, or not drawable).
|
|
|
|
*/
|
|
|
|
PRBool AdvanceToCharacter(PRInt32 aIndex);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up aContext for glyph drawing. This applies any global transform
|
2008-03-31 06:40:18 -07:00
|
|
|
* requested by SetInitialMatrix, then applies any positioning and
|
2008-03-18 12:50:29 -07:00
|
|
|
* rotation for the current character.
|
|
|
|
*/
|
|
|
|
void SetupForDrawing(gfxContext *aContext) {
|
|
|
|
return SetupFor(aContext, mDrawScale);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Set up aContext for glyph measuring. This applies any global transform
|
2008-03-31 06:40:18 -07:00
|
|
|
* requested by SetInitialMatrix, then applies any positioning and
|
2008-03-18 12:50:29 -07:00
|
|
|
* rotation for the current character, then applies a scale from appunits
|
|
|
|
* to device pixels so that drawing in appunits sizes works.
|
|
|
|
*/
|
|
|
|
void SetupForMetrics(gfxContext *aContext) {
|
|
|
|
return SetupFor(aContext, mMetricsScale);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Get the raw position data for the current character.
|
|
|
|
*/
|
|
|
|
CharacterPosition GetPositionData();
|
|
|
|
|
|
|
|
private:
|
|
|
|
PRBool SetupForDirectTextRun(gfxContext *aContext, float aScale);
|
|
|
|
void SetupFor(gfxContext *aContext, float aScale);
|
|
|
|
|
|
|
|
nsSVGGlyphFrame *mSource;
|
|
|
|
nsAutoTArray<CharacterPosition,80> mPositions;
|
|
|
|
gfxMatrix mInitialMatrix;
|
|
|
|
// Textrun advance width from start to mCurrentChar, in appunits
|
|
|
|
gfxFloat mCurrentAdvance;
|
|
|
|
PRInt32 mCurrentChar;
|
|
|
|
float mDrawScale;
|
|
|
|
float mMetricsScale;
|
|
|
|
PRPackedBool mInError;
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewSVGGlyphFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsIFrame* parentFrame, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(parentFrame, "null parent");
|
|
|
|
nsISVGTextContentMetrics *metrics;
|
|
|
|
CallQueryInterface(parentFrame, &metrics);
|
|
|
|
NS_ASSERTION(metrics, "trying to construct an SVGGlyphFrame for an invalid container");
|
|
|
|
|
|
|
|
NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
|
|
|
|
"trying to construct an SVGGlyphFrame for wrong content element");
|
|
|
|
|
|
|
|
return new (aPresShell) nsSVGGlyphFrame(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsSVGGlyphFrame)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISVGGlyphFragmentLeaf)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISVGGlyphFragmentNode)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISVGChildFrame)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsSVGGlyphFrameBase)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::CharacterDataChanged(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRBool aAppend)
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
ClearTextRun();
|
2008-04-08 05:51:19 -07:00
|
|
|
NotifyGlyphMetricsChange();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
// Usable font size range in devpixels / user-units
|
|
|
|
#define CLAMP_MIN_SIZE 8
|
|
|
|
#define CLAMP_MAX_SIZE 200
|
|
|
|
#define PRECISE_SIZE 200
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::DidSetStyleContext()
|
|
|
|
{
|
|
|
|
nsSVGGlyphFrameBase::DidSetStyleContext();
|
2008-07-30 12:28:12 -07:00
|
|
|
|
|
|
|
if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
ClearTextRun();
|
|
|
|
NotifyGlyphMetricsChange();
|
|
|
|
}
|
2008-04-08 05:51:19 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::SetSelected(nsPresContext* aPresContext,
|
|
|
|
nsIDOMRange* aRange,
|
|
|
|
PRBool aSelected,
|
2008-09-07 07:12:50 -07:00
|
|
|
nsSpread aSpread,
|
|
|
|
SelectionType aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#if defined(DEBUG) && defined(SVG_DEBUG_SELECTION)
|
|
|
|
printf("nsSVGGlyphFrame(%p)::SetSelected()\n", this);
|
|
|
|
#endif
|
2008-09-07 07:12:50 -07:00
|
|
|
// return nsSVGGlyphFrameBase::SetSelected(aPresContext, aRange, aSelected, aSpread, aType);
|
|
|
|
|
|
|
|
if (aType == nsISelectionController::SELECTION_NORMAL) {
|
|
|
|
// check whether style allows selection
|
|
|
|
PRBool selectable;
|
|
|
|
IsSelectable(&selectable, nsnull);
|
|
|
|
if (!selectable)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if ( aSelected ){
|
|
|
|
mState |= NS_FRAME_SELECTED_CONTENT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mState &= ~NS_FRAME_SELECTED_CONTENT;
|
|
|
|
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGUtils::UpdateGraphic(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::GetSelected(PRBool *aSelected) const
|
|
|
|
{
|
|
|
|
nsresult rv = nsSVGGlyphFrameBase::GetSelected(aSelected);
|
|
|
|
#if defined(DEBUG) && defined(SVG_DEBUG_SELECTION)
|
|
|
|
printf("nsSVGGlyphFrame(%p)::GetSelected()=%d\n", this, *aSelected);
|
|
|
|
#endif
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::IsSelectable(PRBool* aIsSelectable,
|
|
|
|
PRUint8* aSelectStyle) const
|
|
|
|
{
|
|
|
|
nsresult rv = nsSVGGlyphFrameBase::IsSelectable(aIsSelectable, aSelectStyle);
|
|
|
|
#if defined(DEBUG) && defined(SVG_DEBUG_SELECTION)
|
|
|
|
printf("nsSVGGlyphFrame(%p)::IsSelectable()=(%d,%d)\n", this, *aIsSelectable, aSelectStyle);
|
|
|
|
#endif
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGGlyphFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgGlyphFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-08-25 02:23:54 -07:00
|
|
|
nsSVGGlyphFrame::PaintSVG(nsSVGRenderState *aContext, nsIntRect *aDirtyRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!GetStyleVisibility()->IsVisible())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
gfxContext *gfx = aContext->GetGfxContext();
|
|
|
|
PRUint16 renderMode = aContext->GetRenderMode();
|
|
|
|
|
|
|
|
if (renderMode != nsSVGRenderState::NORMAL) {
|
2008-03-31 06:40:18 -07:00
|
|
|
|
|
|
|
gfxMatrix matrix = gfx->CurrentMatrix();
|
|
|
|
SetupGlobalTransform(gfx);
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterIterator iter(this, PR_TRUE);
|
2008-03-31 06:40:18 -07:00
|
|
|
iter.SetInitialMatrix(gfx);
|
2008-03-18 12:50:29 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (GetClipRule() == NS_STYLE_FILL_RULE_EVENODD)
|
2007-04-18 14:09:31 -07:00
|
|
|
gfx->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
2007-04-18 14:09:31 -07:00
|
|
|
gfx->SetFillRule(gfxContext::FILL_RULE_WINDING);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (renderMode == nsSVGRenderState::CLIP_MASK) {
|
2007-04-18 14:09:31 -07:00
|
|
|
gfx->SetAntialiasMode(gfxContext::MODE_ALIASED);
|
|
|
|
gfx->SetColor(gfxRGBA(1.0f, 1.0f, 1.0f, 1.0f));
|
2008-03-18 12:50:29 -07:00
|
|
|
FillCharacters(&iter, gfx);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2008-03-18 12:50:29 -07:00
|
|
|
AddCharactersToPath(&iter, gfx);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-18 14:09:31 -07:00
|
|
|
gfx->SetMatrix(matrix);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-31 06:40:18 -07:00
|
|
|
// We are adding patterns or gradients to the context. Save
|
|
|
|
// it so we don't leak them into the next object we draw
|
2008-03-18 12:50:29 -07:00
|
|
|
gfx->Save();
|
2008-03-31 06:40:18 -07:00
|
|
|
SetupGlobalTransform(gfx);
|
|
|
|
|
2008-09-30 04:28:20 -07:00
|
|
|
if (HasFill() && SetupCairoFill(gfx)) {
|
2008-03-31 06:40:18 -07:00
|
|
|
gfxMatrix matrix = gfx->CurrentMatrix();
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterIterator iter(this, PR_TRUE);
|
2008-03-31 06:40:18 -07:00
|
|
|
iter.SetInitialMatrix(gfx);
|
2008-03-18 12:50:29 -07:00
|
|
|
|
|
|
|
FillCharacters(&iter, gfx);
|
2008-03-31 06:40:18 -07:00
|
|
|
gfx->SetMatrix(matrix);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-30 04:28:20 -07:00
|
|
|
if (HasStroke() && SetupCairoStroke(gfx)) {
|
2008-03-31 06:40:18 -07:00
|
|
|
// SetupCairoStroke will clear mTextRun whenever
|
|
|
|
// there is a pattern or gradient on the text
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterIterator iter(this, PR_TRUE);
|
2008-03-31 06:40:18 -07:00
|
|
|
iter.SetInitialMatrix(gfx);
|
2008-03-18 12:50:29 -07:00
|
|
|
|
2007-04-18 14:09:31 -07:00
|
|
|
gfx->NewPath();
|
2008-03-18 12:50:29 -07:00
|
|
|
AddCharactersToPath(&iter, gfx);
|
2007-04-18 14:09:31 -07:00
|
|
|
gfx->Stroke();
|
2008-03-18 12:50:29 -07:00
|
|
|
// We need to clear the context's path so state doesn't leak
|
|
|
|
// out. See bug 337753.
|
2007-04-18 14:09:31 -07:00
|
|
|
gfx->NewPath();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-04-18 14:09:31 -07:00
|
|
|
gfx->Restore();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
NS_IMETHODIMP_(nsIFrame*)
|
|
|
|
nsSVGGlyphFrame::GetFrameForPoint(const nsPoint &aPoint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
//printf("nsSVGGlyphFrame(%p)::GetFrameForPoint\n", this);
|
|
|
|
#endif
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
if (!mRect.Contains(aPoint))
|
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRBool events = PR_FALSE;
|
|
|
|
switch (GetStyleSVG()->mPointerEvents) {
|
|
|
|
case NS_STYLE_POINTER_EVENTS_NONE:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEPAINTED:
|
|
|
|
if (GetStyleVisibility()->IsVisible() &&
|
|
|
|
(GetStyleSVG()->mFill.mType != eStyleSVGPaintType_None ||
|
|
|
|
GetStyleSVG()->mStroke.mType != eStyleSVGPaintType_None))
|
|
|
|
events = PR_TRUE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEFILL:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLESTROKE:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLE:
|
|
|
|
if (GetStyleVisibility()->IsVisible())
|
|
|
|
events = PR_TRUE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_PAINTED:
|
|
|
|
if (GetStyleSVG()->mFill.mType != eStyleSVGPaintType_None ||
|
|
|
|
GetStyleSVG()->mStroke.mType != eStyleSVGPaintType_None)
|
|
|
|
events = PR_TRUE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_FILL:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_STROKE:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_ALL:
|
|
|
|
events = PR_TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("not reached");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
if (events && ContainsPoint(aPoint))
|
|
|
|
return this;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsRect)
|
|
|
|
nsSVGGlyphFrame::GetCoveredRegion()
|
|
|
|
{
|
|
|
|
return mRect;
|
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
static gfxContext *
|
|
|
|
MakeTmpCtx() {
|
|
|
|
return new gfxContext(nsSVGUtils::GetThebesComputationalSurface());
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::UpdateCoveredRegion()
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
nsRefPtr<gfxContext> tmpCtx = MakeTmpCtx();
|
2008-03-31 06:40:18 -07:00
|
|
|
SetupGlobalTransform(tmpCtx);
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterIterator iter(this, PR_TRUE);
|
2008-03-31 06:40:18 -07:00
|
|
|
iter.SetInitialMatrix(tmpCtx);
|
2008-03-18 12:50:29 -07:00
|
|
|
|
2007-04-18 14:09:31 -07:00
|
|
|
gfxRect extent;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-30 04:28:20 -07:00
|
|
|
if (HasStroke()) {
|
2008-03-18 12:50:29 -07:00
|
|
|
AddCharactersToPath(&iter, tmpCtx);
|
2008-09-30 04:28:20 -07:00
|
|
|
SetupCairoStrokeGeometry(tmpCtx);
|
2008-03-18 12:50:29 -07:00
|
|
|
extent = tmpCtx->UserToDevice(tmpCtx->GetUserStrokeExtent());
|
2008-09-30 04:28:20 -07:00
|
|
|
} else if (HasFill()) {
|
2008-03-18 12:50:29 -07:00
|
|
|
AddBoundingBoxesToPath(&iter, tmpCtx);
|
|
|
|
tmpCtx->IdentityMatrix();
|
|
|
|
extent = tmpCtx->GetUserPathExtent();
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2008-03-18 12:50:29 -07:00
|
|
|
extent = gfxRect(0, 0, 0, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
mRect = nsSVGUtils::ToAppPixelRect(PresContext(), extent);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::InitialUpdate()
|
|
|
|
{
|
2007-10-19 04:07:08 -07:00
|
|
|
NS_ASSERTION(GetStateBits() & NS_FRAME_FIRST_REFLOW,
|
|
|
|
"Yikes! We've been called already! Hopefully we weren't called "
|
|
|
|
"before our nsSVGOuterSVGFrame's initial Reflow()!!!");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(!(mState & NS_FRAME_IN_REFLOW),
|
|
|
|
"We don't actually participate in reflow");
|
2008-04-08 05:51:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Do unset the various reflow bits, though.
|
|
|
|
mState &= ~(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
|
2007-08-03 01:39:12 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
void
|
|
|
|
nsSVGGlyphFrame::NotifySVGChanged(PRUint32 aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
if (aFlags & TRANSFORM_CHANGED) {
|
|
|
|
ClearTextRun();
|
|
|
|
}
|
2008-04-08 05:51:19 -07:00
|
|
|
if (!(aFlags & SUPPRESS_INVALIDATION)) {
|
|
|
|
nsSVGUtils::UpdateGraphic(this);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::NotifyRedrawSuspended()
|
|
|
|
{
|
|
|
|
// XXX should we cache the fact that redraw is suspended?
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::NotifyRedrawUnsuspended()
|
|
|
|
{
|
|
|
|
if (GetStateBits() & NS_STATE_SVG_DIRTY)
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGUtils::UpdateGraphic(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
void
|
|
|
|
nsSVGGlyphFrame::AddCharactersToPath(CharacterIterator *aIter,
|
|
|
|
gfxContext *aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
if (aIter->SetupForDirectTextRunDrawing(aContext)) {
|
|
|
|
mTextRun->DrawToPath(aContext, gfxPoint(0, 0), 0,
|
|
|
|
mTextRun->GetLength(), nsnull, nsnull);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
PRInt32 i;
|
|
|
|
while ((i = aIter->NextChar()) >= 0) {
|
|
|
|
aIter->SetupForDrawing(aContext);
|
|
|
|
mTextRun->DrawToPath(aContext, gfxPoint(0, 0), i, 1, nsnull, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-03-18 12:50:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
void
|
|
|
|
nsSVGGlyphFrame::AddBoundingBoxesToPath(CharacterIterator *aIter,
|
|
|
|
gfxContext *aContext)
|
|
|
|
{
|
|
|
|
if (aIter->SetupForDirectTextRunMetrics(aContext)) {
|
|
|
|
gfxTextRun::Metrics metrics =
|
|
|
|
mTextRun->MeasureText(0, mTextRun->GetLength(),
|
|
|
|
PR_FALSE, nsnull, nsnull);
|
|
|
|
aContext->Rectangle(metrics.mBoundingBox);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 i;
|
|
|
|
while ((i = aIter->NextChar()) >= 0) {
|
|
|
|
aIter->SetupForMetrics(aContext);
|
|
|
|
gfxTextRun::Metrics metrics =
|
|
|
|
mTextRun->MeasureText(i, 1, PR_FALSE, nsnull, nsnull);
|
|
|
|
aContext->Rectangle(metrics.mBoundingBox);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
void
|
|
|
|
nsSVGGlyphFrame::FillCharacters(CharacterIterator *aIter,
|
|
|
|
gfxContext *aContext)
|
|
|
|
{
|
|
|
|
if (aIter->SetupForDirectTextRunDrawing(aContext)) {
|
|
|
|
mTextRun->Draw(aContext, gfxPoint(0, 0), 0,
|
|
|
|
mTextRun->GetLength(), nsnull, nsnull, nsnull);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
PRInt32 i;
|
|
|
|
while ((i = aIter->NextChar()) >= 0) {
|
|
|
|
aIter->SetupForDrawing(aContext);
|
|
|
|
mTextRun->Draw(aContext, gfxPoint(0, 0), i, 1, nsnull, nsnull, nsnull);
|
|
|
|
}
|
|
|
|
}
|
2007-04-17 20:54:53 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::GetBBox(nsIDOMSVGRect **_retval)
|
|
|
|
{
|
|
|
|
*_retval = nsnull;
|
2007-04-17 20:54:53 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
nsRefPtr<gfxContext> tmpCtx = MakeTmpCtx();
|
2008-03-31 06:40:18 -07:00
|
|
|
SetupGlobalTransform(tmpCtx);
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterIterator iter(this, PR_TRUE);
|
2008-03-31 06:40:18 -07:00
|
|
|
iter.SetInitialMatrix(tmpCtx);
|
2008-03-18 12:50:29 -07:00
|
|
|
AddCharactersToPath(&iter, tmpCtx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
tmpCtx->IdentityMatrix();
|
|
|
|
return NS_NewSVGRect(_retval, tmpCtx->GetUserPathExtent());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGGeometryFrame methods:
|
|
|
|
|
|
|
|
/* readonly attribute nsIDOMSVGMatrix canvasTM; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::GetCanvasTM(nsIDOMSVGMatrix * *aCTM)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mParent, "null parent");
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsSVGContainerFrame *containerFrame = static_cast<nsSVGContainerFrame*>
|
|
|
|
(mParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMSVGMatrix> parentTM = containerFrame->GetCanvasTM();
|
2008-03-18 12:50:29 -07:00
|
|
|
*aCTM = nsnull;
|
|
|
|
parentTM.swap(*aCTM);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGGlyphFrame methods:
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSVGGlyphFrame::GetCharacterData(nsAString & aCharacterData)
|
|
|
|
{
|
|
|
|
nsAutoString characterData;
|
|
|
|
mContent->AppendTextTo(characterData);
|
|
|
|
|
|
|
|
if (mWhitespaceHandling & COMPRESS_WHITESPACE) {
|
|
|
|
PRBool trimLeadingWhitespace, trimTrailingWhitespace;
|
|
|
|
trimLeadingWhitespace = ((mWhitespaceHandling & TRIM_LEADING_WHITESPACE) != 0);
|
|
|
|
trimTrailingWhitespace = ((mWhitespaceHandling & TRIM_TRAILING_WHITESPACE) != 0);
|
|
|
|
characterData.CompressWhitespace(trimLeadingWhitespace,
|
|
|
|
trimTrailingWhitespace);
|
|
|
|
} else {
|
|
|
|
nsAString::iterator start, end;
|
|
|
|
characterData.BeginWriting(start);
|
|
|
|
characterData.EndWriting(end);
|
|
|
|
while (start != end) {
|
|
|
|
if (NS_IsAsciiWhitespace(*start))
|
|
|
|
*start = ' ';
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aCharacterData = characterData;
|
|
|
|
|
|
|
|
return !characterData.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
PRBool
|
|
|
|
nsSVGGlyphFrame::GetCharacterPositions(nsTArray<CharacterPosition>* aCharacterPositions,
|
|
|
|
float aMetricsScale)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
NS_ASSERTION(mTextRun->GetLength() > 0, "no text");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSVGTextPathFrame *textPath = FindTextPathParent();
|
|
|
|
|
|
|
|
/* we're an ordinary fragment - return */
|
|
|
|
/* XXX: we might want to use this for individual x/y/dx/dy adjustment */
|
|
|
|
if (!textPath)
|
2008-03-18 12:50:29 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-16 13:57:09 -07:00
|
|
|
nsRefPtr<gfxFlattenedPath> data = textPath->GetFlattenedPath();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* textPath frame, but invalid target */
|
|
|
|
if (!data)
|
2008-03-18 12:50:29 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-23 01:39:54 -07:00
|
|
|
gfxFloat length = data->GetLength();
|
2008-03-18 12:50:29 -07:00
|
|
|
PRUint32 strLength = mTextRun->GetLength();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
if (!aCharacterPositions->SetLength(strLength))
|
|
|
|
return PR_FALSE;
|
2007-04-18 14:09:31 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterPosition *cp = aCharacterPositions->Elements();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for (PRUint32 k = 0; k < strLength; k++)
|
|
|
|
cp[k].draw = PR_FALSE;
|
|
|
|
|
2007-04-23 01:39:54 -07:00
|
|
|
gfxFloat x = mPosition.x;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (PRUint32 i = 0; i < strLength; i++) {
|
2008-03-18 12:50:29 -07:00
|
|
|
gfxFloat halfAdvance =
|
|
|
|
mTextRun->GetAdvanceWidth(i, 1, nsnull)*aMetricsScale / 2.0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* have we run off the end of the path? */
|
2007-04-16 13:57:09 -07:00
|
|
|
if (x + halfAdvance > length)
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* check that we've advanced to the start of the path */
|
2007-04-23 01:39:54 -07:00
|
|
|
if (x + halfAdvance >= 0.0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
cp[i].draw = PR_TRUE;
|
|
|
|
|
|
|
|
// add y (normal)
|
|
|
|
// add rotation
|
|
|
|
// move point back along tangent
|
2007-04-18 14:09:31 -07:00
|
|
|
gfxPoint pt = data->FindPoint(gfxPoint(x + halfAdvance, mPosition.y),
|
2007-04-16 13:57:09 -07:00
|
|
|
&(cp[i].angle));
|
2007-04-18 14:09:31 -07:00
|
|
|
cp[i].pos =
|
|
|
|
pt - gfxPoint(cos(cp[i].angle), sin(cp[i].angle)) * halfAdvance;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-04-16 13:57:09 -07:00
|
|
|
x += 2 * halfAdvance;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-03-18 12:50:29 -07:00
|
|
|
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Utilities for converting from indices in the uncompressed content
|
|
|
|
// element strings to compressed frame string and back:
|
|
|
|
static int
|
|
|
|
CompressIndex(int index, const nsTextFragment*fragment)
|
|
|
|
{
|
|
|
|
int ci=0;
|
|
|
|
if (fragment->Is2b()) {
|
|
|
|
const PRUnichar *data=fragment->Get2b();
|
|
|
|
while(*data && index) {
|
|
|
|
if (XP_IS_SPACE_W(*data)){
|
|
|
|
do {
|
|
|
|
++data;
|
|
|
|
--index;
|
|
|
|
}while(XP_IS_SPACE_W(*data) && index);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++data;
|
|
|
|
--index;
|
|
|
|
}
|
|
|
|
++ci;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const char *data=fragment->Get1b();
|
|
|
|
while(*data && index) {
|
|
|
|
if (XP_IS_SPACE_W(*data)){
|
|
|
|
do {
|
|
|
|
++data;
|
|
|
|
--index;
|
|
|
|
}while(XP_IS_SPACE_W(*data) && index);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++data;
|
|
|
|
--index;
|
|
|
|
}
|
|
|
|
++ci;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
UncompressIndex(int index, PRBool bRightAffinity, const nsTextFragment*fragment)
|
|
|
|
{
|
|
|
|
// XXX
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGGlyphFrame::GetHighlight(PRUint32 *charnum, PRUint32 *nchars,
|
|
|
|
nscolor *foreground, nscolor *background)
|
|
|
|
{
|
|
|
|
*foreground = NS_RGB(255,255,255);
|
|
|
|
*background = NS_RGB(0,0,0);
|
|
|
|
*charnum=0;
|
|
|
|
*nchars=0;
|
|
|
|
|
|
|
|
PRBool hasHighlight =
|
|
|
|
(mState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT;
|
|
|
|
|
|
|
|
if (!hasHighlight) {
|
|
|
|
NS_ERROR("nsSVGGlyphFrame::GetHighlight() called by renderer when there is no highlight");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext *presContext = PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The selection ranges are relative to the uncompressed text in
|
|
|
|
// the content element. We'll need the text fragment:
|
|
|
|
const nsTextFragment *fragment = mContent->GetText();
|
|
|
|
NS_ASSERTION(fragment, "no text");
|
|
|
|
|
|
|
|
// get the selection details
|
|
|
|
SelectionDetails *details = nsnull;
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsFrameSelection> frameSelection;
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelectionController> controller;
|
|
|
|
GetSelectionController(presContext, getter_AddRefs(controller));
|
|
|
|
|
|
|
|
if (!controller) {
|
|
|
|
NS_ERROR("no selection controller");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
frameSelection = do_QueryInterface(controller);
|
|
|
|
}
|
|
|
|
if (!frameSelection) {
|
|
|
|
frameSelection = presContext->PresShell()->FrameSelection();
|
|
|
|
}
|
|
|
|
if (!frameSelection) {
|
|
|
|
NS_ERROR("no frameselection interface");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
details = frameSelection->LookUpSelection(
|
|
|
|
mContent, 0, fragment->GetLength(), PR_FALSE
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DEBUG) && defined(SVG_DEBUG_SELECTION)
|
|
|
|
{
|
|
|
|
SelectionDetails *dp = details;
|
|
|
|
printf("nsSVGGlyphFrame(%p)::GetHighlight() [\n", this);
|
|
|
|
while (dp) {
|
|
|
|
printf("selection detail: %d(%d)->%d(%d) type %d\n",
|
|
|
|
dp->mStart, CompressIndex(dp->mStart, fragment),
|
|
|
|
dp->mEnd, CompressIndex(dp->mEnd, fragment),
|
|
|
|
dp->mType);
|
|
|
|
dp = dp->mNext;
|
|
|
|
}
|
|
|
|
printf("]\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (details) {
|
|
|
|
NS_ASSERTION(details->mNext==nsnull, "can't do multiple selection ranges");
|
|
|
|
|
|
|
|
*charnum=CompressIndex(details->mStart, fragment);
|
|
|
|
*nchars=CompressIndex(details->mEnd, fragment)-*charnum;
|
|
|
|
|
|
|
|
nsILookAndFeel *look = presContext->LookAndFeel();
|
|
|
|
|
|
|
|
look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, *background);
|
|
|
|
look->GetColor(nsILookAndFeel::eColor_TextSelectForeground, *foreground);
|
|
|
|
|
|
|
|
SelectionDetails *dp = details;
|
|
|
|
while ((dp=details->mNext) != nsnull) {
|
|
|
|
delete details;
|
|
|
|
details = dp;
|
|
|
|
}
|
|
|
|
delete details;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGGlyphFragmentLeaf interface:
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsSVGGlyphFrame::SetGlyphPosition(float x, float y)
|
|
|
|
{
|
2007-04-18 14:09:31 -07:00
|
|
|
mPosition.MoveTo(x, y);
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGUtils::UpdateGraphic(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-03-18 12:50:29 -07:00
|
|
|
nsSVGGlyphFrame::GetStartPositionOfChar(PRUint32 charnum,
|
|
|
|
nsIDOMSVGPoint **_retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*_retval = nsnull;
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterIterator iter(this, PR_FALSE);
|
|
|
|
if (!iter.AdvanceToCharacter(charnum))
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
2008-03-18 01:37:48 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
return NS_NewSVGPoint(_retval, iter.GetPositionData().pos);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-03-18 12:50:29 -07:00
|
|
|
nsSVGGlyphFrame::GetEndPositionOfChar(PRUint32 charnum,
|
|
|
|
nsIDOMSVGPoint **_retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*_retval = nsnull;
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterIterator iter(this, PR_FALSE);
|
|
|
|
if (!iter.AdvanceToCharacter(charnum))
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
2008-03-18 01:37:48 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
nsRefPtr<gfxContext> tmpCtx = MakeTmpCtx();
|
|
|
|
iter.SetupForMetrics(tmpCtx);
|
|
|
|
tmpCtx->MoveTo(gfxPoint(mTextRun->GetAdvanceWidth(charnum, 1, nsnull), 0));
|
|
|
|
tmpCtx->IdentityMatrix();
|
|
|
|
return NS_NewSVGPoint(_retval, tmpCtx->CurrentPoint());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)
|
|
|
|
{
|
|
|
|
*_retval = nsnull;
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterIterator iter(this, PR_FALSE);
|
|
|
|
if (!iter.AdvanceToCharacter(charnum))
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-18 14:09:31 -07:00
|
|
|
gfxTextRun::Metrics metrics =
|
2008-03-18 12:50:29 -07:00
|
|
|
mTextRun->MeasureText(charnum, 1, PR_FALSE, nsnull, nsnull);
|
2008-03-18 01:37:48 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
nsRefPtr<gfxContext> tmpCtx = MakeTmpCtx();
|
|
|
|
iter.SetupForMetrics(tmpCtx);
|
|
|
|
tmpCtx->Rectangle(metrics.mBoundingBox);
|
|
|
|
tmpCtx->IdentityMatrix();
|
|
|
|
return NS_NewSVGRect(_retval, tmpCtx->GetUserPathExtent());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::GetRotationOfChar(PRUint32 charnum, float *_retval)
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterIterator iter(this, PR_FALSE);
|
|
|
|
if (!iter.AdvanceToCharacter(charnum))
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
2008-03-17 19:36:17 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterPosition pos = iter.GetPositionData();
|
|
|
|
if (!pos.draw)
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
2008-03-18 01:37:48 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
const gfxFloat radPerDeg = M_PI/180.0;
|
|
|
|
*_retval = float(pos.angle / radPerDeg);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(float)
|
2008-03-18 12:50:29 -07:00
|
|
|
nsSVGGlyphFrame::GetBaselineOffset(PRUint16 baselineIdentifier,
|
|
|
|
PRBool aForceGlobalTransform)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
float drawScale, metricsScale;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
if (!EnsureTextRun(&drawScale, &metricsScale, aForceGlobalTransform))
|
2007-04-18 14:09:31 -07:00
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
gfxTextRun::Metrics metrics =
|
2008-03-18 12:50:29 -07:00
|
|
|
mTextRun->MeasureText(0, mTextRun->GetLength(),
|
|
|
|
PR_FALSE, nsnull, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
gfxFloat baselineAppUnits;
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (baselineIdentifier) {
|
|
|
|
case BASELINE_HANGING:
|
|
|
|
// not really right, but the best we can do with the information provided
|
|
|
|
// FALLTHROUGH
|
|
|
|
case BASELINE_TEXT_BEFORE_EDGE:
|
2008-03-18 12:50:29 -07:00
|
|
|
baselineAppUnits = -metrics.mAscent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case BASELINE_TEXT_AFTER_EDGE:
|
2008-03-18 12:50:29 -07:00
|
|
|
baselineAppUnits = metrics.mDescent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case BASELINE_CENTRAL:
|
|
|
|
case BASELINE_MIDDLE:
|
2008-03-18 12:50:29 -07:00
|
|
|
baselineAppUnits = -(metrics.mAscent - metrics.mDescent) / 2.0f;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case BASELINE_ALPHABETIC:
|
|
|
|
default:
|
2008-03-18 12:50:29 -07:00
|
|
|
baselineAppUnits = 0.0;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2008-03-18 12:50:29 -07:00
|
|
|
return float(baselineAppUnits)*metricsScale;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(float)
|
2008-03-18 12:50:29 -07:00
|
|
|
nsSVGGlyphFrame::GetAdvance(PRBool aForceGlobalTransform)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
float drawScale, metricsScale;
|
|
|
|
if (!EnsureTextRun(&drawScale, &metricsScale, aForceGlobalTransform))
|
2007-04-18 14:09:31 -07:00
|
|
|
return 0.0f;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
gfxFloat advanceAppUnits =
|
|
|
|
mTextRun->GetAdvanceWidth(0, mTextRun->GetLength(), nsnull);
|
|
|
|
return float(advanceAppUnits)*metricsScale;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsSVGTextPathFrame*)
|
|
|
|
nsSVGGlyphFrame::FindTextPathParent()
|
|
|
|
{
|
|
|
|
/* check if we're the child of a textPath */
|
|
|
|
for (nsIFrame *frame = GetParent();
|
|
|
|
frame != nsnull;
|
|
|
|
frame = frame->GetParent()) {
|
|
|
|
nsIAtom* type = frame->GetType();
|
|
|
|
if (type == nsGkAtoms::svgTextPathFrame) {
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<nsSVGTextPathFrame*>(frame);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (type == nsGkAtoms::svgTextFrame)
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
nsSVGGlyphFrame::IsStartOfChunk()
|
|
|
|
{
|
|
|
|
// this fragment is a chunk if it has a corresponding absolute
|
|
|
|
// position adjustment in an ancestors' x or y array. (At the moment
|
|
|
|
// we don't map the full arrays, but only the first elements.)
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsSVGGlyphFrame::GetAdjustedPosition(/* inout */ float &x, /* inout */ float &y)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<nsIDOMSVGLengthList>)
|
|
|
|
nsSVGGlyphFrame::GetX()
|
|
|
|
{
|
|
|
|
nsSVGTextContainerFrame *containerFrame;
|
2007-07-08 00:08:04 -07:00
|
|
|
containerFrame = static_cast<nsSVGTextContainerFrame *>(mParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (containerFrame)
|
|
|
|
return containerFrame->GetX();
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<nsIDOMSVGLengthList>)
|
|
|
|
nsSVGGlyphFrame::GetY()
|
|
|
|
{
|
|
|
|
nsSVGTextContainerFrame *containerFrame;
|
2007-07-08 00:08:04 -07:00
|
|
|
containerFrame = static_cast<nsSVGTextContainerFrame *>(mParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (containerFrame)
|
|
|
|
return containerFrame->GetY();
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<nsIDOMSVGLengthList>)
|
|
|
|
nsSVGGlyphFrame::GetDx()
|
|
|
|
{
|
|
|
|
nsSVGTextContainerFrame *containerFrame;
|
2007-07-08 00:08:04 -07:00
|
|
|
containerFrame = static_cast<nsSVGTextContainerFrame *>(mParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (containerFrame)
|
|
|
|
return containerFrame->GetDx();
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<nsIDOMSVGLengthList>)
|
|
|
|
nsSVGGlyphFrame::GetDy()
|
|
|
|
{
|
|
|
|
nsSVGTextContainerFrame *containerFrame;
|
2007-07-08 00:08:04 -07:00
|
|
|
containerFrame = static_cast<nsSVGTextContainerFrame *>(mParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (containerFrame)
|
|
|
|
return containerFrame->GetDy();
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(PRUint16)
|
|
|
|
nsSVGGlyphFrame::GetTextAnchor()
|
|
|
|
{
|
|
|
|
return GetStyleSVG()->mTextAnchor;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
nsSVGGlyphFrame::IsAbsolutelyPositioned()
|
|
|
|
{
|
|
|
|
nsIFrame *lastFrame = this;
|
|
|
|
|
|
|
|
for (nsIFrame *frame = GetParent();
|
|
|
|
frame != nsnull;
|
|
|
|
lastFrame = frame, frame = frame->GetParent()) {
|
|
|
|
|
|
|
|
/* need to be the first child if we are absolutely positioned */
|
|
|
|
if (!frame ||
|
|
|
|
frame->GetFirstChild(nsnull) != lastFrame)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// textPath is always absolutely positioned for our purposes
|
|
|
|
if (frame->GetType() == nsGkAtoms::svgTextPathFrame)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
if (frame &&
|
|
|
|
(frame->GetContent()->HasAttr(kNameSpaceID_None, nsGkAtoms::x) ||
|
|
|
|
frame->GetContent()->HasAttr(kNameSpaceID_None, nsGkAtoms::y)))
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
if (frame->GetType() == nsGkAtoms::svgTextFrame)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGGlyphFragmentNode interface:
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(PRUint32)
|
|
|
|
nsSVGGlyphFrame::GetNumberOfChars()
|
|
|
|
{
|
|
|
|
if (mWhitespaceHandling == PRESERVE_WHITESPACE)
|
|
|
|
return mContent->TextLength();
|
|
|
|
|
|
|
|
nsAutoString text;
|
|
|
|
GetCharacterData(text);
|
|
|
|
return text.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(float)
|
|
|
|
nsSVGGlyphFrame::GetComputedTextLength()
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
return GetAdvance(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(float)
|
|
|
|
nsSVGGlyphFrame::GetSubStringLength(PRUint32 charnum, PRUint32 fragmentChars)
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
float drawScale, metricsScale;
|
|
|
|
if (!EnsureTextRun(&drawScale, &metricsScale, PR_FALSE))
|
2007-04-18 14:09:31 -07:00
|
|
|
return 0.0f;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
gfxFloat advanceAppUnits =
|
|
|
|
mTextRun->GetAdvanceWidth(charnum, fragmentChars, nsnull);
|
|
|
|
return float(advanceAppUnits)*metricsScale;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(PRInt32)
|
|
|
|
nsSVGGlyphFrame::GetCharNumAtPosition(nsIDOMSVGPoint *point)
|
|
|
|
{
|
|
|
|
float xPos, yPos;
|
|
|
|
point->GetX(&xPos);
|
|
|
|
point->GetY(&yPos);
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
nsRefPtr<gfxContext> tmpCtx = MakeTmpCtx();
|
|
|
|
CharacterIterator iter(this, PR_FALSE);
|
2007-04-18 14:09:31 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
PRInt32 i;
|
|
|
|
PRInt32 last = -1;
|
|
|
|
gfxPoint pt(xPos, yPos);
|
|
|
|
while ((i = iter.NextChar()) >= 0) {
|
2007-04-18 14:09:31 -07:00
|
|
|
gfxTextRun::Metrics metrics =
|
2008-03-18 12:50:29 -07:00
|
|
|
mTextRun->MeasureText(i, 1, PR_FALSE, nsnull, nsnull);
|
|
|
|
iter.SetupForMetrics(tmpCtx);
|
|
|
|
tmpCtx->NewPath();
|
|
|
|
tmpCtx->Rectangle(metrics.mBoundingBox);
|
|
|
|
tmpCtx->IdentityMatrix();
|
|
|
|
if (tmpCtx->PointInFill(pt)) {
|
|
|
|
// Can't return now. If there's glyph overlap, the last character
|
|
|
|
// to be rendered wins.
|
|
|
|
last = i;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-03-18 01:37:48 -07:00
|
|
|
}
|
2008-03-18 12:50:29 -07:00
|
|
|
|
|
|
|
return last;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsISVGGlyphFragmentLeaf *)
|
|
|
|
nsSVGGlyphFrame::GetFirstGlyphFragment()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsISVGGlyphFragmentLeaf *)
|
|
|
|
nsSVGGlyphFrame::GetNextGlyphFragment()
|
|
|
|
{
|
|
|
|
nsIFrame* sibling = mNextSibling;
|
|
|
|
while (sibling) {
|
|
|
|
nsISVGGlyphFragmentNode *node = nsnull;
|
|
|
|
CallQueryInterface(sibling, &node);
|
|
|
|
if (node)
|
|
|
|
return node->GetFirstGlyphFragment();
|
|
|
|
sibling = sibling->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
// no more siblings. go back up the tree.
|
|
|
|
|
|
|
|
NS_ASSERTION(mParent, "null parent");
|
|
|
|
nsISVGGlyphFragmentNode *node = nsnull;
|
|
|
|
CallQueryInterface(mParent, &node);
|
|
|
|
return node ? node->GetNextGlyphFragment() : nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsSVGGlyphFrame::SetWhitespaceHandling(PRUint8 aWhitespaceHandling)
|
|
|
|
{
|
|
|
|
mWhitespaceHandling = aWhitespaceHandling;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
|
2008-04-08 05:51:19 -07:00
|
|
|
void
|
|
|
|
nsSVGGlyphFrame::NotifyGlyphMetricsChange()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGTextContainerFrame *containerFrame =
|
|
|
|
static_cast<nsSVGTextContainerFrame *>(mParent);
|
|
|
|
if (containerFrame)
|
|
|
|
containerFrame->NotifyGlyphMetricsChange();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2008-08-25 02:23:54 -07:00
|
|
|
nsSVGGlyphFrame::ContainsPoint(const nsPoint &aPoint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
nsRefPtr<gfxContext> tmpCtx = MakeTmpCtx();
|
2008-03-31 06:40:18 -07:00
|
|
|
SetupGlobalTransform(tmpCtx);
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterIterator iter(this, PR_TRUE);
|
2008-03-31 06:40:18 -07:00
|
|
|
iter.SetInitialMatrix(tmpCtx);
|
2008-03-18 12:50:29 -07:00
|
|
|
|
|
|
|
PRInt32 i;
|
|
|
|
while ((i = iter.NextChar()) >= 0) {
|
|
|
|
gfxTextRun::Metrics metrics =
|
|
|
|
mTextRun->MeasureText(i, 1, PR_FALSE, nsnull, nsnull);
|
|
|
|
iter.SetupForMetrics(tmpCtx);
|
|
|
|
tmpCtx->Rectangle(metrics.mBoundingBox);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
tmpCtx->IdentityMatrix();
|
2008-08-25 02:23:54 -07:00
|
|
|
return tmpCtx->PointInFill(gfxPoint(PresContext()->AppUnitsToGfxUnits(aPoint.x),
|
|
|
|
PresContext()->AppUnitsToGfxUnits(aPoint.y)));
|
2008-03-18 12:50:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
PRBool
|
|
|
|
nsSVGGlyphFrame::GetGlobalTransform(gfxMatrix *aMatrix)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMSVGMatrix> ctm;
|
|
|
|
GetCanvasTM(getter_AddRefs(ctm));
|
|
|
|
if (!ctm)
|
2007-10-09 17:00:05 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-31 06:40:18 -07:00
|
|
|
*aMatrix = nsSVGUtils::ConvertSVGMatrixToThebes(ctm);
|
|
|
|
return !aMatrix->IsSingular();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-31 06:40:18 -07:00
|
|
|
void
|
|
|
|
nsSVGGlyphFrame::SetupGlobalTransform(gfxContext *aContext)
|
|
|
|
{
|
|
|
|
gfxMatrix matrix;
|
|
|
|
GetGlobalTransform(&matrix);
|
|
|
|
aContext->Multiply(matrix);
|
2008-03-18 12:50:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGGlyphFrame::ClearTextRun()
|
|
|
|
{
|
|
|
|
if (!mTextRun)
|
|
|
|
return;
|
|
|
|
gfxTextRunWordCache::RemoveTextRun(mTextRun);
|
|
|
|
delete mTextRun;
|
|
|
|
mTextRun = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSVGGlyphFrame::EnsureTextRun(float *aDrawScale, float *aMetricsScale,
|
|
|
|
PRBool aForceGlobalTransform)
|
|
|
|
{
|
|
|
|
// Compute the size at which the text should render (excluding the CTM)
|
|
|
|
const nsStyleFont* fontData = GetStyleFont();
|
|
|
|
// Since SVG has its own scaling, we really don't want
|
|
|
|
// fonts in SVG to respond to the browser's "TextZoom"
|
|
|
|
// (Ctrl++,Ctrl+-)
|
|
|
|
nsPresContext *presContext = PresContext();
|
|
|
|
float textZoom = presContext->TextZoom();
|
|
|
|
double size =
|
|
|
|
presContext->AppUnitsToFloatCSSPixels(fontData->mSize) / textZoom;
|
|
|
|
|
|
|
|
double textRunSize;
|
|
|
|
if (mTextRun) {
|
|
|
|
textRunSize = mTextRun->GetFontGroup()->GetStyle()->size;
|
|
|
|
} else {
|
|
|
|
nsAutoString text;
|
|
|
|
if (!GetCharacterData(text))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
gfxMatrix m;
|
|
|
|
if (aForceGlobalTransform ||
|
|
|
|
!(GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD)) {
|
|
|
|
if (!GetGlobalTransform(&m))
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
// The context scale is the ratio of the length of the transformed
|
|
|
|
// diagonal vector (1,1) to the length of the untransformed diagonal
|
|
|
|
// (which is sqrt(2)).
|
|
|
|
gfxPoint p = m.Transform(gfxPoint(1, 1)) - m.Transform(gfxPoint(0, 0));
|
2008-07-15 01:46:54 -07:00
|
|
|
double contextScale = nsSVGUtils::ComputeNormalizedHypotenuse(p.x, p.y);
|
2008-03-18 12:50:29 -07:00
|
|
|
|
|
|
|
nsCAutoString langGroup;
|
|
|
|
nsIAtom *langGroupAtom = presContext->GetLangGroup();
|
|
|
|
if (langGroupAtom) {
|
|
|
|
const char* lg;
|
|
|
|
langGroupAtom->GetUTF8String(&lg);
|
|
|
|
langGroup.Assign(lg);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
if (GetStyleSVG()->mTextRendering ==
|
|
|
|
NS_STYLE_TEXT_RENDERING_GEOMETRICPRECISION) {
|
|
|
|
textRunSize = PRECISE_SIZE;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2008-03-18 12:50:29 -07:00
|
|
|
textRunSize = size*contextScale;
|
|
|
|
textRunSize = PR_MAX(textRunSize, CLAMP_MIN_SIZE);
|
|
|
|
textRunSize = PR_MIN(textRunSize, CLAMP_MAX_SIZE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
const nsFont& font = fontData->mFont;
|
|
|
|
gfxFontStyle fontStyle(font.style, font.weight, textRunSize, langGroup,
|
|
|
|
font.sizeAdjust, font.systemFont,
|
|
|
|
font.familyNameQuirks);
|
2007-04-18 14:09:31 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
nsRefPtr<gfxFontGroup> fontGroup =
|
|
|
|
gfxPlatform::GetPlatform()->CreateFontGroup(font.name, &fontStyle);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
PRUint32 flags = gfxTextRunFactory::TEXT_NEED_BOUNDING_BOX |
|
|
|
|
nsLayoutUtils::GetTextRunFlagsForStyle(GetStyleContext(), GetStyleText(), GetStyleFont());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
// XXX We should use a better surface here! But then we'd have to
|
|
|
|
// change things so we can ensure we always have the "right" sort of
|
|
|
|
// surface available, by creating the textrun only at the right times
|
|
|
|
nsRefPtr<gfxContext> tmpCtx = MakeTmpCtx();
|
|
|
|
tmpCtx->SetMatrix(m);
|
|
|
|
|
|
|
|
// Use only the word cache here. We don't want to cache the textrun
|
|
|
|
// globally because we'll never hit in that cache, since we create
|
|
|
|
// a new fontgroup every time. Even if we cached fontgroups, we
|
|
|
|
// might render at very many different sizes (e.g. during zoom
|
|
|
|
// animation) and caching a textrun for each such size would be bad.
|
|
|
|
gfxTextRunFactory::Parameters params = {
|
|
|
|
tmpCtx, nsnull, nsnull, nsnull, 0, GetTextRunUnitsFactor()
|
|
|
|
};
|
|
|
|
mTextRun = gfxTextRunWordCache::MakeTextRun(text.get(), text.Length(),
|
|
|
|
fontGroup, ¶ms, flags);
|
|
|
|
if (!mTextRun)
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
*aDrawScale = float(size/textRunSize);
|
|
|
|
*aMetricsScale = (*aDrawScale)/GetTextRunUnitsFactor();
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::SetMatrixPropagation(PRBool aPropagate)
|
|
|
|
{
|
|
|
|
if (aPropagate) {
|
|
|
|
AddStateBits(NS_STATE_SVG_PROPAGATE_TRANSFORM);
|
|
|
|
} else {
|
|
|
|
RemoveStateBits(NS_STATE_SVG_PROPAGATE_TRANSFORM);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsSVGGlyphFrame::GetMatrixPropagation()
|
|
|
|
{
|
|
|
|
return (GetStateBits() & NS_STATE_SVG_PROPAGATE_TRANSFORM) != 0;
|
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// helper class
|
2007-04-18 14:09:31 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterIterator::CharacterIterator(nsSVGGlyphFrame *aSource,
|
|
|
|
PRBool aForceGlobalTransform)
|
|
|
|
: mSource(aSource), mCurrentAdvance(0), mCurrentChar(-1),
|
|
|
|
mInError(PR_FALSE)
|
|
|
|
{
|
|
|
|
if (!aSource->EnsureTextRun(&mDrawScale, &mMetricsScale,
|
|
|
|
aForceGlobalTransform) ||
|
|
|
|
!aSource->GetCharacterPositions(&mPositions, mMetricsScale)) {
|
|
|
|
mInError = PR_TRUE;
|
2008-03-18 01:37:48 -07:00
|
|
|
}
|
2008-03-18 12:50:29 -07:00
|
|
|
}
|
2008-03-18 00:42:07 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
PRBool
|
|
|
|
CharacterIterator::SetupForDirectTextRun(gfxContext *aContext, float aScale)
|
|
|
|
{
|
|
|
|
if (!mPositions.IsEmpty() || mInError)
|
|
|
|
return PR_FALSE;
|
|
|
|
aContext->SetMatrix(mInitialMatrix);
|
|
|
|
aContext->Translate(mSource->mPosition);
|
|
|
|
aContext->Scale(aScale, aScale);
|
2008-06-22 08:45:38 -07:00
|
|
|
// We are scaling the glyphs up/down to the size we want so we need to
|
|
|
|
// inverse scale the outline widths of those glyphs so they are invariant
|
|
|
|
aContext->SetLineWidth(aContext->CurrentLineWidth() / aScale);
|
2008-03-18 12:50:29 -07:00
|
|
|
return PR_TRUE;
|
2008-03-17 18:45:05 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
PRInt32
|
|
|
|
CharacterIterator::NextChar()
|
2008-03-18 00:42:07 -07:00
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
if (mInError)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (PR_TRUE) {
|
|
|
|
if (mCurrentChar >= 0 &&
|
|
|
|
(mPositions.IsEmpty() || mPositions[mCurrentChar].draw)) {
|
|
|
|
mCurrentAdvance +=
|
|
|
|
mSource->mTextRun->GetAdvanceWidth(mCurrentChar, 1, nsnull);
|
|
|
|
}
|
|
|
|
++mCurrentChar;
|
|
|
|
|
|
|
|
if (mCurrentChar >= PRInt32(mSource->mTextRun->GetLength()))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (mPositions.IsEmpty() || mPositions[mCurrentChar].draw)
|
|
|
|
return mCurrentChar;
|
|
|
|
}
|
2008-03-18 00:42:07 -07:00
|
|
|
}
|
2008-03-17 19:36:17 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
PRBool
|
|
|
|
CharacterIterator::AdvanceToCharacter(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
while (NextChar() != -1) {
|
|
|
|
if (mCurrentChar == aIndex)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-03-18 01:37:48 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
void
|
|
|
|
CharacterIterator::SetupFor(gfxContext *aContext, float aScale)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
NS_ASSERTION(!mInError, "We should not have reached here");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
aContext->SetMatrix(mInitialMatrix);
|
|
|
|
if (mPositions.IsEmpty()) {
|
2008-04-07 15:27:52 -07:00
|
|
|
aContext->Translate(mSource->mPosition);
|
|
|
|
aContext->Scale(aScale, aScale);
|
|
|
|
aContext->Translate(gfxPoint(mCurrentAdvance, 0));
|
2008-03-18 12:50:29 -07:00
|
|
|
} else {
|
|
|
|
aContext->Translate(mPositions[mCurrentChar].pos);
|
|
|
|
aContext->Rotate(mPositions[mCurrentChar].angle);
|
2008-04-07 15:27:52 -07:00
|
|
|
aContext->Scale(aScale, aScale);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-06-22 08:45:38 -07:00
|
|
|
// We are scaling the glyphs up/down to the size we want so we need to
|
|
|
|
// inverse scale the outline widths of those glyphs so they are invariant
|
|
|
|
aContext->SetLineWidth(aContext->CurrentLineWidth() / aScale);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterPosition
|
|
|
|
CharacterIterator::GetPositionData()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
if (!mPositions.IsEmpty())
|
|
|
|
return mPositions[mCurrentChar];
|
|
|
|
|
2008-09-28 02:05:26 -07:00
|
|
|
gfxFloat advance = mCurrentAdvance * mMetricsScale;
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterPosition cp =
|
|
|
|
{ mSource->mPosition + gfxPoint(advance, 0), 0, PR_TRUE };
|
|
|
|
return cp;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|