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"
|
2011-09-08 19:27:13 -07:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsTextFragment.h"
|
2011-01-04 00:52:17 -08:00
|
|
|
#include "nsBidiPresUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGUtils.h"
|
2010-07-16 14:42:12 -07:00
|
|
|
#include "SVGLengthList.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMSVGLength.h"
|
|
|
|
#include "nsIDOMSVGRect.h"
|
2010-12-08 04:15:53 -08:00
|
|
|
#include "DOMSVGPoint.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGGlyphFrame.h"
|
|
|
|
#include "nsSVGTextPathFrame.h"
|
|
|
|
#include "nsSVGPathElement.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
|
|
|
|
2010-07-16 14:42:12 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
struct CharacterPosition {
|
|
|
|
gfxPoint pos;
|
|
|
|
gfxFloat angle;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool draw;
|
2008-03-18 12:50:29 -07:00
|
|
|
};
|
2011-01-27 22:35:35 -08:00
|
|
|
|
|
|
|
static gfxContext* MakeTmpCtx() {
|
|
|
|
return new gfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface());
|
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
/**
|
|
|
|
* This is a do-it-all helper class. It supports iterating through the
|
2011-01-11 03:17:00 -08:00
|
|
|
* drawable character clusters of a string. For each cluster, it can set up
|
2008-03-18 12:50:29 -07:00
|
|
|
* 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 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:
|
|
|
|
/**
|
2011-01-11 03:17:00 -08:00
|
|
|
* Sets up the iterator so that NextCluster will return the first drawable
|
|
|
|
* cluster.
|
2008-03-18 12:50:29 -07:00
|
|
|
* @param aForceGlobalTransform passed on to EnsureTextRun (see below)
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
CharacterIterator(nsSVGGlyphFrame *aSource, bool aForceGlobalTransform);
|
2008-03-18 12:50:29 -07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SetupForDirectTextRunDrawing(gfxContext *aContext) {
|
2008-03-18 12:50:29 -07:00
|
|
|
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.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SetupForDirectTextRunMetrics(gfxContext *aContext) {
|
2008-03-18 12:50:29 -07:00
|
|
|
return SetupForDirectTextRun(aContext, mMetricsScale);
|
|
|
|
}
|
2010-10-29 00:18:03 -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
|
|
|
|
*/
|
|
|
|
void SetLineWidthForDrawing(gfxContext *aContext) {
|
|
|
|
aContext->SetLineWidth(aContext->CurrentLineWidth() / mDrawScale);
|
|
|
|
}
|
2008-03-18 12:50:29 -07:00
|
|
|
|
|
|
|
/**
|
2011-08-23 05:31:56 -07:00
|
|
|
* Returns the index of the next cluster in the string that should be drawn,
|
|
|
|
* or InvalidCluster() (i.e. PRUint32(-1)) if there is no such cluster.
|
2008-03-18 12:50:29 -07:00
|
|
|
*/
|
2011-08-23 05:31:56 -07:00
|
|
|
PRUint32 NextCluster();
|
2011-01-11 03:17:00 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the length of the current cluster (usually 1, unless there
|
|
|
|
* are combining marks)
|
|
|
|
*/
|
2011-08-23 05:31:56 -07:00
|
|
|
PRUint32 ClusterLength();
|
2011-01-11 03:17:00 -08:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
/**
|
2011-01-11 03:17:00 -08:00
|
|
|
* Repeated calls NextCluster until it returns aIndex (i.e. aIndex is the
|
2008-03-18 12:50:29 -07:00
|
|
|
* 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).
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AdvanceToCharacter(PRUint32 aIndex);
|
2008-03-18 12:50:29 -07:00
|
|
|
|
2010-11-01 22:40:30 -07:00
|
|
|
/**
|
|
|
|
* Resets the iterator to the beginning of the string.
|
|
|
|
*/
|
|
|
|
void Reset() {
|
|
|
|
// There are two ways mInError can be set
|
|
|
|
// a) If there was a problem creating the iterator (mCurrentChar == -1)
|
|
|
|
// b) If we ran off the end of the string (mCurrentChar != -1)
|
|
|
|
// We can only reset the mInError flag in case b)
|
2011-08-23 05:31:56 -07:00
|
|
|
if (mCurrentChar != InvalidCluster()) {
|
|
|
|
mCurrentChar = InvalidCluster();
|
2010-11-01 22:40:30 -07:00
|
|
|
mInError = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
2011-08-23 05:31:56 -07:00
|
|
|
/**
|
|
|
|
* "Invalid" cluster index returned to indicate error state
|
|
|
|
*/
|
|
|
|
PRUint32 InvalidCluster() {
|
|
|
|
return PRUint32(-1);
|
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
private:
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SetupForDirectTextRun(gfxContext *aContext, float aScale);
|
2008-03-18 12:50:29 -07:00
|
|
|
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;
|
2011-08-23 05:31:56 -07:00
|
|
|
PRUint32 mCurrentChar;
|
2008-03-18 12:50:29 -07:00
|
|
|
float mDrawScale;
|
|
|
|
float mMetricsScale;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mInError;
|
2008-03-18 12:50:29 -07:00
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGGlyphFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGGlyphFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGGlyphFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
2009-01-12 11:20:59 -08:00
|
|
|
// nsQueryFrame methods
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsSVGGlyphFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsISVGGlyphFragmentNode)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsISVGChildFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsSVGGlyphFrameBase)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-08-04 18:38:10 -07:00
|
|
|
nsSVGGlyphFrame::CharacterDataChanged(CharacterDataChangeInfo* aInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
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
|
|
|
|
|
2008-10-13 15:03:28 -07:00
|
|
|
/* virtual */ void
|
2008-10-26 03:11:34 -07:00
|
|
|
nsSVGGlyphFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-26 03:11:34 -07:00
|
|
|
nsSVGGlyphFrameBase::DidSetStyleContext(aOldStyleContext);
|
2008-07-30 12:28:12 -07:00
|
|
|
|
|
|
|
if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
ClearTextRun();
|
|
|
|
NotifyGlyphMetricsChange();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-26 15:05:41 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSVGGlyphFrame::SetSelected(bool aSelected,
|
2009-07-26 15:05:41 -07:00
|
|
|
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
|
|
|
|
2009-07-26 15:05:41 -07:00
|
|
|
if (aType != nsISelectionController::SELECTION_NORMAL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// check whether style allows selection
|
2011-09-28 23:19:26 -07:00
|
|
|
bool selectable;
|
2009-07-26 15:05:41 -07:00
|
|
|
IsSelectable(&selectable, nsnull);
|
|
|
|
if (!selectable)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-26 15:05:41 -07:00
|
|
|
if (aSelected) {
|
|
|
|
AddStateBits(NS_FRAME_SELECTED_CONTENT);
|
|
|
|
} else {
|
|
|
|
RemoveStateBits(NS_FRAME_SELECTED_CONTENT);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGUtils::UpdateGraphic(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSVGGlyphFrame::GetSelected(bool *aSelected) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
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
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSVGGlyphFrame::IsSelectable(bool* aIsSelectable,
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2009-03-30 12:03:42 -07:00
|
|
|
#ifdef DEBUG
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_ASSERTION(aParent, "null parent");
|
|
|
|
|
|
|
|
nsIFrame* ancestorFrame = nsSVGUtils::GetFirstNonAAncestorFrame(aParent);
|
|
|
|
NS_ASSERTION(ancestorFrame, "Must have ancestor");
|
|
|
|
|
2009-05-29 03:15:40 -07:00
|
|
|
nsSVGTextContainerFrame *metrics = do_QueryFrame(ancestorFrame);
|
2009-01-19 10:31:34 -08:00
|
|
|
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");
|
2009-03-30 12:03:42 -07:00
|
|
|
#endif /* DEBUG */
|
2009-01-19 10:31:34 -08:00
|
|
|
|
|
|
|
return nsSVGGlyphFrameBase::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGGlyphFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgGlyphFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-10-20 01:42:03 -07:00
|
|
|
nsSVGGlyphFrame::PaintSVG(nsSVGRenderState *aContext,
|
|
|
|
const nsIntRect *aDirtyRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!GetStyleVisibility()->IsVisible())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
gfxContext *gfx = aContext->GetGfxContext();
|
|
|
|
PRUint16 renderMode = aContext->GetRenderMode();
|
|
|
|
|
2009-04-24 06:11:03 -07:00
|
|
|
switch (GetStyleSVG()->mTextRendering) {
|
|
|
|
case NS_STYLE_TEXT_RENDERING_OPTIMIZESPEED:
|
|
|
|
gfx->SetAntialiasMode(gfxContext::MODE_ALIASED);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gfx->SetAntialiasMode(gfxContext::MODE_COVERAGE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
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->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);
|
|
|
|
|
2010-11-01 22:40:30 -07:00
|
|
|
CharacterIterator iter(this, PR_TRUE);
|
|
|
|
iter.SetInitialMatrix(gfx);
|
2008-03-18 12:50:29 -07:00
|
|
|
|
2010-11-01 22:40:30 -07:00
|
|
|
if (SetupCairoFill(gfx)) {
|
2010-11-27 01:24:32 -08:00
|
|
|
gfxMatrix matrix = gfx->CurrentMatrix();
|
2008-03-18 12:50:29 -07:00
|
|
|
FillCharacters(&iter, gfx);
|
2010-11-27 01:24:32 -08:00
|
|
|
gfx->SetMatrix(matrix);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-30 17:51:05 -07:00
|
|
|
if (SetupCairoStroke(gfx)) {
|
2008-03-31 06:40:18 -07:00
|
|
|
// SetupCairoStroke will clear mTextRun whenever
|
|
|
|
// there is a pattern or gradient on the text
|
2010-11-01 22:40:30 -07:00
|
|
|
iter.Reset();
|
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
|
|
|
{
|
2011-07-08 06:20:14 -07:00
|
|
|
PRUint16 hitTestFlags = GetHitTestFlags();
|
|
|
|
if (!hitTestFlags) {
|
2008-08-25 02:23:54 -07:00
|
|
|
return nsnull;
|
2011-01-27 22:35:35 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-27 22:35:35 -08:00
|
|
|
nsRefPtr<gfxContext> context = MakeTmpCtx();
|
|
|
|
SetupGlobalTransform(context);
|
|
|
|
CharacterIterator iter(this, PR_TRUE);
|
|
|
|
iter.SetInitialMatrix(context);
|
|
|
|
|
|
|
|
// The SVG 1.1 spec says that text is hit tested against the character cells
|
|
|
|
// of the text, not the fill and stroke. See the section starting "For text
|
|
|
|
// elements..." here:
|
|
|
|
//
|
|
|
|
// http://www.w3.org/TR/SVG11/interact.html#PointerEventsProperty
|
|
|
|
//
|
2011-07-08 06:20:14 -07:00
|
|
|
// Currently we just test the character cells if GetHitTestFlags says we're
|
2011-01-27 22:35:35 -08:00
|
|
|
// supposed to be testing either the fill OR the stroke:
|
|
|
|
|
2011-08-23 05:31:56 -07:00
|
|
|
PRUint32 i;
|
|
|
|
while ((i = iter.NextCluster()) != iter.InvalidCluster()) {
|
2011-01-27 22:35:35 -08:00
|
|
|
gfxTextRun::Metrics metrics =
|
|
|
|
mTextRun->MeasureText(i, iter.ClusterLength(),
|
|
|
|
gfxFont::LOOSE_INK_EXTENTS, nsnull, nsnull);
|
|
|
|
iter.SetupForMetrics(context);
|
|
|
|
context->Rectangle(metrics.mBoundingBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxPoint userSpacePoint =
|
|
|
|
context->DeviceToUser(gfxPoint(PresContext()->AppUnitsToGfxUnits(aPoint.x),
|
|
|
|
PresContext()->AppUnitsToGfxUnits(aPoint.y)));
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHit = false;
|
2011-07-08 06:20:14 -07:00
|
|
|
if (hitTestFlags & SVG_HIT_TEST_FILL || hitTestFlags & SVG_HIT_TEST_STROKE) {
|
2011-01-27 22:35:35 -08:00
|
|
|
isHit = context->PointInFill(userSpacePoint);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-01-27 22:35:35 -08:00
|
|
|
// If isHit is false, we may also want to fill and stroke the text to check
|
|
|
|
// whether the pointer is over an area of fill or stroke that lies outside
|
|
|
|
// the character cells. (With a thick stroke, or with fonts like Zapfino, such
|
|
|
|
// areas may be very significant.) This is what Opera appears to do, but
|
|
|
|
// currently we do not.
|
|
|
|
|
|
|
|
if (isHit && nsSVGUtils::HitTestClip(this, aPoint))
|
2008-08-25 02:23:54 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGGlyphFrame::UpdateCoveredRegion()
|
|
|
|
{
|
2011-04-18 20:07:23 -07:00
|
|
|
mRect.SetEmpty();
|
2008-11-03 02:04:25 -08:00
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
gfxMatrix matrix = GetCanvasTM();
|
2009-03-31 05:19:39 -07:00
|
|
|
if (matrix.IsSingular()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
nsRefPtr<gfxContext> tmpCtx = MakeTmpCtx();
|
2009-03-31 05:19:39 -07:00
|
|
|
tmpCtx->Multiply(matrix);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasStroke = HasStroke();
|
2009-07-12 11:50:45 -07:00
|
|
|
if (hasStroke) {
|
|
|
|
SetupCairoStrokeGeometry(tmpCtx);
|
|
|
|
} else if (GetStyleSVG()->mFill.mType == eStyleSVGPaintType_None) {
|
2009-03-31 05:19:39 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-03-31 05:19:39 -07:00
|
|
|
|
2011-04-20 02:16:01 -07:00
|
|
|
mPropagateTransform = PR_FALSE;
|
2009-03-31 05:19:39 -07:00
|
|
|
CharacterIterator iter(this, PR_TRUE);
|
|
|
|
iter.SetInitialMatrix(tmpCtx);
|
2010-11-01 22:40:30 -07:00
|
|
|
AddBoundingBoxesToPath(&iter, tmpCtx);
|
2011-04-20 02:16:01 -07:00
|
|
|
mPropagateTransform = PR_TRUE;
|
2009-03-31 05:19:39 -07:00
|
|
|
tmpCtx->IdentityMatrix();
|
|
|
|
|
|
|
|
// Be careful when replacing the following logic to get the fill and stroke
|
|
|
|
// extents independently (instead of computing the stroke extents from the
|
|
|
|
// path extents). You may think that you can just use the stroke extents if
|
|
|
|
// there is both a fill and a stroke. In reality it's necessary to calculate
|
|
|
|
// both the fill and stroke extents, and take the union of the two. There are
|
|
|
|
// two reasons for this:
|
|
|
|
//
|
|
|
|
// # Due to stroke dashing, in certain cases the fill extents could actually
|
|
|
|
// extend outside the stroke extents.
|
|
|
|
// # If the stroke is very thin, cairo won't paint any stroke, and so the
|
|
|
|
// stroke bounds that it will return will be empty.
|
|
|
|
//
|
|
|
|
// Another thing to be aware of is that under AddBoundingBoxesToPath the
|
|
|
|
// gfxContext has SetLineWidth() called on it, so if we want to ask the
|
|
|
|
// gfxContext for *stroke* extents, we'll neet to wrap the
|
|
|
|
// AddBoundingBoxesToPath() call with CurrentLineWidth()/SetLineWidth()
|
|
|
|
// calls to record and then reset the stroke width.
|
|
|
|
gfxRect extent = tmpCtx->GetUserPathExtent();
|
|
|
|
if (hasStroke) {
|
|
|
|
extent = nsSVGUtils::PathExtentsToMaxStrokeExtents(extent, this);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-11-03 02:04:25 -08:00
|
|
|
if (!extent.IsEmpty()) {
|
|
|
|
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
|
|
|
{
|
2010-10-29 00:18:03 -07:00
|
|
|
aIter->SetLineWidthForDrawing(aContext);
|
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
|
|
|
|
2011-08-23 05:31:56 -07:00
|
|
|
PRUint32 i;
|
|
|
|
while ((i = aIter->NextCluster()) != aIter->InvalidCluster()) {
|
2008-03-18 12:50:29 -07:00
|
|
|
aIter->SetupForDrawing(aContext);
|
2011-01-11 03:17:00 -08:00
|
|
|
mTextRun->DrawToPath(aContext, gfxPoint(0, 0), i, aIter->ClusterLength(),
|
|
|
|
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(),
|
2009-02-24 00:32:58 -08:00
|
|
|
gfxFont::LOOSE_INK_EXTENTS, nsnull, nsnull);
|
2008-03-18 12:50:29 -07:00
|
|
|
aContext->Rectangle(metrics.mBoundingBox);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-23 05:31:56 -07:00
|
|
|
PRUint32 i;
|
|
|
|
while ((i = aIter->NextCluster()) != aIter->InvalidCluster()) {
|
2008-03-18 12:50:29 -07:00
|
|
|
aIter->SetupForMetrics(aContext);
|
|
|
|
gfxTextRun::Metrics metrics =
|
2011-01-11 03:17:00 -08:00
|
|
|
mTextRun->MeasureText(i, aIter->ClusterLength(),
|
|
|
|
gfxFont::LOOSE_INK_EXTENTS, nsnull, nsnull);
|
2008-03-18 12:50:29 -07:00
|
|
|
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,
|
2011-01-11 03:17:00 -08:00
|
|
|
mTextRun->GetLength(), nsnull, nsnull);
|
2008-03-18 12:50:29 -07:00
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-23 05:31:56 -07:00
|
|
|
PRUint32 i;
|
|
|
|
while ((i = aIter->NextCluster()) != aIter->InvalidCluster()) {
|
2008-03-18 12:50:29 -07:00
|
|
|
aIter->SetupForDrawing(aContext);
|
2011-01-11 03:17:00 -08:00
|
|
|
mTextRun->Draw(aContext, gfxPoint(0, 0), i, aIter->ClusterLength(),
|
|
|
|
nsnull, nsnull);
|
2008-03-18 12:50:29 -07:00
|
|
|
}
|
|
|
|
}
|
2007-04-17 20:54:53 -07:00
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
gfxRect
|
|
|
|
nsSVGGlyphFrame::GetBBoxContribution(const gfxMatrix &aToBBoxUserspace)
|
2008-03-18 12:50:29 -07:00
|
|
|
{
|
2011-09-25 14:04:32 -07:00
|
|
|
if (mOverrideCanvasTM) {
|
|
|
|
*mOverrideCanvasTM = aToBBoxUserspace;
|
|
|
|
} else {
|
|
|
|
mOverrideCanvasTM = new gfxMatrix(aToBBoxUserspace);
|
|
|
|
}
|
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);
|
2009-11-18 12:59:24 -08:00
|
|
|
AddBoundingBoxesToPath(&iter, tmpCtx);
|
2008-03-18 12:50:29 -07:00
|
|
|
tmpCtx->IdentityMatrix();
|
2009-04-28 21:31:34 -07:00
|
|
|
|
|
|
|
mOverrideCanvasTM = nsnull;
|
|
|
|
|
|
|
|
return tmpCtx->GetUserPathExtent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGGeometryFrame methods:
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
gfxMatrix
|
|
|
|
nsSVGGlyphFrame::GetCanvasTM()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-28 21:31:34 -07:00
|
|
|
if (mOverrideCanvasTM) {
|
2011-09-25 14:04:32 -07:00
|
|
|
return *mOverrideCanvasTM;
|
2009-04-28 21:31:34 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(mParent, "null parent");
|
2009-04-28 21:31:34 -07:00
|
|
|
return static_cast<nsSVGContainerFrame*>(mParent)->GetCanvasTM();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGGlyphFrame methods:
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGGlyphFrame::GetCharacterData(nsAString & aCharacterData)
|
|
|
|
{
|
|
|
|
nsAutoString characterData;
|
2009-12-10 20:02:13 -08:00
|
|
|
mContent->AppendTextTo(characterData);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-03 00:45:30 -07:00
|
|
|
if (mCompressWhitespace) {
|
|
|
|
characterData.CompressWhitespace(mTrimLeadingWhitespace,
|
|
|
|
mTrimTrailingWhitespace);
|
2007-03-22 10:30:00 -07:00
|
|
|
} 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();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-03-18 12:50:29 -07:00
|
|
|
nsSVGGlyphFrame::GetCharacterPositions(nsTArray<CharacterPosition>* aCharacterPositions,
|
|
|
|
float aMetricsScale)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-30 03:21:19 -07:00
|
|
|
PRUint32 strLength = mTextRun->GetLength();
|
2011-05-06 03:45:17 -07:00
|
|
|
NS_ABORT_IF_FALSE(strLength > 0, "no text");
|
2010-03-30 03:21:19 -07:00
|
|
|
|
|
|
|
const gfxFloat radPerDeg = M_PI / 180.0;
|
|
|
|
|
2010-09-17 20:46:48 -07:00
|
|
|
nsTArray<float> xList, yList;
|
2010-10-13 21:16:48 -07:00
|
|
|
GetEffectiveXY(strLength, xList, yList);
|
2010-09-17 20:46:48 -07:00
|
|
|
nsTArray<float> dxList, dyList;
|
2010-10-13 21:16:48 -07:00
|
|
|
GetEffectiveDxDy(strLength, dxList, dyList);
|
2010-09-17 20:46:48 -07:00
|
|
|
nsTArray<float> rotateList;
|
2010-10-13 21:16:48 -07:00
|
|
|
GetEffectiveRotate(strLength, rotateList);
|
2010-03-31 01:57:28 -07:00
|
|
|
|
2010-03-30 03:21:19 -07:00
|
|
|
gfxPoint pos = mPosition;
|
2010-09-17 20:46:48 -07:00
|
|
|
gfxFloat angle = 0.0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSVGTextPathFrame *textPath = FindTextPathParent();
|
|
|
|
|
2010-03-30 03:21:19 -07:00
|
|
|
if (textPath) {
|
|
|
|
nsRefPtr<gfxFlattenedPath> data = textPath->GetFlattenedPath();
|
|
|
|
|
|
|
|
// textPath frame, but invalid target
|
|
|
|
if (!data)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (!aCharacterPositions->SetLength(strLength))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
gfxFloat pathScale = textPath->GetPathScale();
|
|
|
|
|
|
|
|
CharacterPosition *cp = aCharacterPositions->Elements();
|
|
|
|
|
|
|
|
gfxFloat length = data->GetLength();
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < strLength; i++) {
|
|
|
|
gfxFloat halfAdvance =
|
|
|
|
mTextRun->GetAdvanceWidth(i, 1, nsnull)*aMetricsScale / 2.0;
|
|
|
|
|
2010-09-17 20:46:48 -07:00
|
|
|
// use only x position for horizontal writing
|
|
|
|
if (i > 0 && i < xList.Length()) {
|
|
|
|
pos.x = xList[i];
|
|
|
|
}
|
|
|
|
pos.x += (i > 0 && i < dxList.Length()) ? dxList[i] * pathScale : 0.0;
|
|
|
|
pos.y += (i > 0 && i < dyList.Length()) ? dyList[i] * pathScale : 0.0;
|
|
|
|
if (i < rotateList.Length()) {
|
|
|
|
angle = rotateList[i] * radPerDeg;
|
|
|
|
}
|
2010-03-30 03:21:19 -07:00
|
|
|
|
|
|
|
// check that we're within the path boundaries
|
|
|
|
cp[i].draw = (pos.x + halfAdvance >= 0.0 &&
|
|
|
|
pos.x + halfAdvance <= length);
|
|
|
|
|
|
|
|
if (cp[i].draw) {
|
|
|
|
|
|
|
|
// add y (normal)
|
|
|
|
// add rotation
|
|
|
|
// move point back along tangent
|
|
|
|
gfxPoint pt = data->FindPoint(gfxPoint(pos.x + halfAdvance, pos.y),
|
|
|
|
&(cp[i].angle));
|
|
|
|
cp[i].pos =
|
|
|
|
pt - gfxPoint(cos(cp[i].angle), sin(cp[i].angle)) * halfAdvance;
|
2010-09-17 20:46:48 -07:00
|
|
|
cp[i].angle += angle;
|
2010-03-30 03:21:19 -07:00
|
|
|
}
|
|
|
|
pos.x += 2 * halfAdvance;
|
|
|
|
}
|
2008-03-18 12:50:29 -07:00
|
|
|
return PR_TRUE;
|
2010-03-30 03:21:19 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-17 20:46:48 -07:00
|
|
|
if (xList.Length() <= 1 &&
|
|
|
|
yList.Length() <= 1 &&
|
|
|
|
dxList.Length() <= 1 &&
|
|
|
|
dyList.Length() <= 1 &&
|
|
|
|
rotateList.IsEmpty()) {
|
2010-03-30 03:21:19 -07:00
|
|
|
// simple text without individual positioning
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
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
|
|
|
|
2010-03-30 03:21:19 -07:00
|
|
|
PRUint16 anchor = GetTextAnchor();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < strLength; i++) {
|
2010-03-30 03:21:19 -07:00
|
|
|
cp[i].draw = PR_TRUE;
|
|
|
|
|
|
|
|
gfxFloat advance = mTextRun->GetAdvanceWidth(i, 1, nsnull)*aMetricsScale;
|
2010-09-17 20:46:48 -07:00
|
|
|
if (xList.Length() > 1 && i < xList.Length()) {
|
2010-07-16 14:42:12 -07:00
|
|
|
pos.x = xList[i];
|
2010-09-17 20:46:48 -07:00
|
|
|
|
2010-03-30 03:21:19 -07:00
|
|
|
// apply text-anchor to character
|
|
|
|
if (anchor == NS_STYLE_TEXT_ANCHOR_MIDDLE)
|
|
|
|
pos.x -= advance/2.0;
|
|
|
|
else if (anchor == NS_STYLE_TEXT_ANCHOR_END)
|
|
|
|
pos.x -= advance;
|
|
|
|
}
|
2010-09-17 20:46:48 -07:00
|
|
|
if (yList.Length() > 1 && i < yList.Length()) {
|
2010-07-16 14:42:12 -07:00
|
|
|
pos.y = yList[i];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-09-17 20:46:48 -07:00
|
|
|
pos.x += (i > 0 && i < dxList.Length()) ? dxList[i] : 0.0;
|
|
|
|
pos.y += (i > 0 && i < dyList.Length()) ? dyList[i] : 0.0;
|
2010-03-30 03:21:19 -07:00
|
|
|
cp[i].pos = pos;
|
|
|
|
pos.x += advance;
|
2010-09-17 20:46:48 -07:00
|
|
|
if (i < rotateList.Length()) {
|
|
|
|
angle = rotateList[i] * radPerDeg;
|
|
|
|
}
|
|
|
|
cp[i].angle = angle;
|
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
|
|
|
}
|
|
|
|
|
2010-10-17 09:27:48 -07:00
|
|
|
PRUint32
|
|
|
|
nsSVGGlyphFrame::GetTextRunFlags(PRUint32 strLength)
|
|
|
|
{
|
|
|
|
// Keep the logic here consistent with GetCharacterPositions
|
|
|
|
|
|
|
|
if (FindTextPathParent()) {
|
|
|
|
return gfxTextRunFactory::TEXT_DISABLE_OPTIONAL_LIGATURES;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<float> xList, yList;
|
|
|
|
GetEffectiveXY(strLength, xList, yList);
|
|
|
|
nsTArray<float> dxList, dyList;
|
|
|
|
GetEffectiveDxDy(strLength, dxList, dyList);
|
|
|
|
nsTArray<float> rotateList;
|
|
|
|
GetEffectiveRotate(strLength, rotateList);
|
|
|
|
|
|
|
|
return (xList.Length() > 1 ||
|
|
|
|
yList.Length() > 1 ||
|
|
|
|
dxList.Length() > 1 ||
|
|
|
|
dyList.Length() > 1 ||
|
|
|
|
!rotateList.IsEmpty()) ?
|
|
|
|
gfxTextRunFactory::TEXT_DISABLE_OPTIONAL_LIGATURES : 0;
|
|
|
|
}
|
|
|
|
|
2009-06-17 14:05:02 -07:00
|
|
|
float
|
2010-03-30 03:21:19 -07:00
|
|
|
nsSVGGlyphFrame::GetSubStringAdvance(PRUint32 aCharnum,
|
|
|
|
PRUint32 aFragmentChars,
|
|
|
|
float aMetricsScale)
|
2009-06-17 14:05:02 -07:00
|
|
|
{
|
2010-03-30 03:21:19 -07:00
|
|
|
if (aFragmentChars == 0)
|
2009-06-17 14:05:02 -07:00
|
|
|
return 0.0f;
|
2010-03-30 03:21:19 -07:00
|
|
|
|
|
|
|
gfxFloat advance =
|
|
|
|
mTextRun->GetAdvanceWidth(aCharnum, aFragmentChars, nsnull) * aMetricsScale;
|
|
|
|
|
2010-09-17 20:46:48 -07:00
|
|
|
nsTArray<float> dxlist, notUsed;
|
2010-10-13 21:16:48 -07:00
|
|
|
GetEffectiveDxDy(mTextRun->GetLength(), dxlist, notUsed);
|
2010-07-16 14:42:12 -07:00
|
|
|
PRUint32 dxcount = dxlist.Length();
|
2010-03-30 03:21:19 -07:00
|
|
|
if (dxcount) {
|
|
|
|
gfxFloat pathScale = 1.0;
|
|
|
|
nsSVGTextPathFrame *textPath = FindTextPathParent();
|
|
|
|
if (textPath)
|
|
|
|
pathScale = textPath->GetPathScale();
|
|
|
|
if (dxcount > aFragmentChars)
|
|
|
|
dxcount = aFragmentChars;
|
|
|
|
for (PRUint32 i = aCharnum; i < dxcount; i++) {
|
2010-07-16 14:42:12 -07:00
|
|
|
advance += dxlist[i] * pathScale;
|
2010-03-30 03:21:19 -07:00
|
|
|
}
|
|
|
|
}
|
2009-06-17 14:05:02 -07:00
|
|
|
|
|
|
|
return float(advance);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat
|
2010-03-30 03:21:19 -07:00
|
|
|
nsSVGGlyphFrame::GetBaselineOffset(float aMetricsScale)
|
2009-06-17 14:05:02 -07:00
|
|
|
{
|
|
|
|
gfxTextRun::Metrics metrics =
|
|
|
|
mTextRun->MeasureText(0, mTextRun->GetLength(),
|
|
|
|
gfxFont::LOOSE_INK_EXTENTS, nsnull, nsnull);
|
|
|
|
|
|
|
|
PRUint16 dominantBaseline;
|
|
|
|
|
|
|
|
for (nsIFrame *frame = GetParent(); frame; frame = frame->GetParent()) {
|
|
|
|
dominantBaseline = frame->GetStyleSVGReset()->mDominantBaseline;
|
|
|
|
if (dominantBaseline != NS_STYLE_DOMINANT_BASELINE_AUTO ||
|
|
|
|
frame->GetType() == nsGkAtoms::svgTextFrame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat baselineAppUnits;
|
|
|
|
switch (dominantBaseline) {
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_HANGING:
|
|
|
|
// not really right, but the best we can do with the information provided
|
|
|
|
// FALLTHROUGH
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_TEXT_BEFORE_EDGE:
|
|
|
|
baselineAppUnits = -metrics.mAscent;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_TEXT_AFTER_EDGE:
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_IDEOGRAPHIC:
|
|
|
|
baselineAppUnits = metrics.mDescent;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_CENTRAL:
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_MIDDLE:
|
|
|
|
baselineAppUnits = -(metrics.mAscent - metrics.mDescent) / 2.0;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_AUTO:
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_ALPHABETIC:
|
|
|
|
return 0.0;
|
|
|
|
default:
|
|
|
|
NS_WARNING("We don't know about this type of dominant-baseline");
|
|
|
|
return 0.0;
|
|
|
|
}
|
2010-03-30 03:21:19 -07:00
|
|
|
return baselineAppUnits * aMetricsScale;
|
2009-06-17 14:05:02 -07:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasHighlight =
|
2007-03-22 10:30:00 -07:00
|
|
|
(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:
|
2009-12-10 20:02:13 -08:00
|
|
|
const nsTextFragment *fragment = mContent->GetText();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(fragment, "no text");
|
|
|
|
|
|
|
|
// get the selection details
|
|
|
|
SelectionDetails *details = nsnull;
|
|
|
|
{
|
2011-05-18 20:10:49 -07:00
|
|
|
nsRefPtr<nsFrameSelection> frameSelection = presContext->PresShell()->FrameSelection();
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
|
2011-09-08 19:27:13 -07:00
|
|
|
LookAndFeel::GetColor(LookAndFeel::eColorID_TextSelectBackground,
|
|
|
|
background);
|
|
|
|
LookAndFeel::GetColor(LookAndFeel::eColorID_TextSelectForeground,
|
|
|
|
foreground);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
SelectionDetails *dp = details;
|
|
|
|
while ((dp=details->mNext) != nsnull) {
|
|
|
|
delete details;
|
|
|
|
details = dp;
|
|
|
|
}
|
|
|
|
delete details;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2011-05-07 10:08:41 -07:00
|
|
|
// Internal methods
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSVGGlyphFrame::SetGlyphPosition(gfxPoint *aPosition, bool aForceGlobalTransform)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-30 03:21:19 -07:00
|
|
|
float drawScale, metricsScale;
|
|
|
|
|
2010-09-17 20:46:48 -07:00
|
|
|
nsSVGTextPathFrame *textPath = FindTextPathParent();
|
|
|
|
// In a textPath, the 'y' attribute has no effect, so we reset 'y' here
|
|
|
|
// to use aPosition.y for dy only
|
2011-08-24 13:54:30 -07:00
|
|
|
if (textPath && textPath->GetFirstPrincipalChild() == this) {
|
2010-09-17 20:46:48 -07:00
|
|
|
aPosition->y = 0.0;
|
|
|
|
}
|
|
|
|
|
2010-03-30 03:21:19 -07:00
|
|
|
if (!EnsureTextRun(&drawScale, &metricsScale, aForceGlobalTransform))
|
|
|
|
return;
|
|
|
|
|
|
|
|
mPosition.MoveTo(aPosition->x, aPosition->y - GetBaselineOffset(metricsScale));
|
|
|
|
|
|
|
|
PRUint32 strLength = mTextRun->GetLength();
|
2010-09-17 20:46:48 -07:00
|
|
|
|
|
|
|
nsTArray<float> xList, yList;
|
2010-10-13 21:16:48 -07:00
|
|
|
GetEffectiveXY(strLength, xList, yList);
|
2010-09-17 20:46:48 -07:00
|
|
|
PRUint32 xCount = NS_MIN(xList.Length(), strLength);
|
|
|
|
PRUint32 yCount = NS_MIN(yList.Length(), strLength);
|
|
|
|
|
|
|
|
// move aPosition to the last glyph position
|
|
|
|
gfxFloat x = aPosition->x;
|
|
|
|
if (xCount > 1) {
|
|
|
|
x = xList[xCount - 1];
|
|
|
|
x +=
|
|
|
|
mTextRun->GetAdvanceWidth(xCount - 1, 1, nsnull) * metricsScale;
|
|
|
|
|
|
|
|
// advance to the last glyph
|
|
|
|
if (strLength > xCount) {
|
|
|
|
x +=
|
|
|
|
mTextRun->GetAdvanceWidth(xCount, strLength - xCount, nsnull) *
|
|
|
|
metricsScale;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
x += mTextRun->GetAdvanceWidth(0, strLength, nsnull) * metricsScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat y = (textPath || yCount <= 1) ? aPosition->y : yList[yCount - 1];
|
2011-07-31 11:36:40 -07:00
|
|
|
aPosition->MoveTo(x, y);
|
2010-03-30 03:21:19 -07:00
|
|
|
|
|
|
|
gfxFloat pathScale = 1.0;
|
|
|
|
if (textPath)
|
|
|
|
pathScale = textPath->GetPathScale();
|
|
|
|
|
2010-09-17 20:46:48 -07:00
|
|
|
nsTArray<float> dxList, dyList;
|
2010-10-13 21:16:48 -07:00
|
|
|
GetEffectiveDxDy(strLength, dxList, dyList);
|
2010-03-30 03:21:19 -07:00
|
|
|
|
2010-09-17 20:46:48 -07:00
|
|
|
PRUint32 dxcount = NS_MIN(dxList.Length(), strLength);
|
|
|
|
if (dxcount > 0) {
|
|
|
|
mPosition.x += dxList[0] * pathScale;
|
|
|
|
}
|
2010-03-30 03:21:19 -07:00
|
|
|
for (PRUint32 i = 0; i < dxcount; i++) {
|
2010-07-16 14:42:12 -07:00
|
|
|
aPosition->x += dxList[i] * pathScale;
|
2010-03-30 03:21:19 -07:00
|
|
|
}
|
2010-09-17 20:46:48 -07:00
|
|
|
PRUint32 dycount = NS_MIN(dyList.Length(), strLength);
|
|
|
|
if (dycount > 0) {
|
|
|
|
mPosition.y += dyList[0]* pathScale;
|
|
|
|
}
|
2010-03-30 03:21:19 -07:00
|
|
|
for (PRUint32 i = 0; i < dycount; i++) {
|
2010-07-16 14:42:12 -07:00
|
|
|
aPosition->y += dyList[i] * pathScale;
|
2010-03-30 03:21:19 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
nsresult
|
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
|
|
|
|
2010-12-08 04:15:53 -08:00
|
|
|
NS_ADDREF(*_retval = new DOMSVGPoint(iter.GetPositionData().pos));
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
nsresult
|
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();
|
2010-12-08 04:15:53 -08:00
|
|
|
NS_ADDREF(*_retval = new DOMSVGPoint(tmpCtx->CurrentPoint()));
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGGlyphFrame::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)
|
|
|
|
{
|
|
|
|
*_retval = nsnull;
|
|
|
|
|
2010-09-10 12:58:48 -07:00
|
|
|
CharacterIterator iter(this, PR_FALSE);
|
|
|
|
if (!iter.AdvanceToCharacter(0))
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
|
2009-02-22 17:19:30 -08:00
|
|
|
PRUint32 start = charnum, limit = charnum + 1;
|
|
|
|
while (start > 0 && !mTextRun->IsClusterStart(start)) {
|
|
|
|
--start;
|
|
|
|
}
|
|
|
|
while (limit < mTextRun->GetLength() && !mTextRun->IsClusterStart(limit)) {
|
|
|
|
++limit;
|
|
|
|
}
|
|
|
|
|
2010-09-10 12:58:48 -07:00
|
|
|
if (start > 0 && !iter.AdvanceToCharacter(start))
|
2008-03-18 12:50:29 -07:00
|
|
|
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 =
|
2009-02-24 00:32:58 -08:00
|
|
|
mTextRun->MeasureText(start, limit - start, gfxFont::LOOSE_INK_EXTENTS,
|
|
|
|
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);
|
2009-02-22 17:19:30 -08:00
|
|
|
tmpCtx->Rectangle(gfxRect(0, -metrics.mAscent,
|
|
|
|
metrics.mAdvanceWidth,
|
|
|
|
metrics.mAscent + metrics.mDescent));
|
2008-03-18 12:50:29 -07:00
|
|
|
tmpCtx->IdentityMatrix();
|
|
|
|
return NS_NewSVGRect(_retval, tmpCtx->GetUserPathExtent());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
float
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSVGGlyphFrame::GetAdvance(bool 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
|
|
|
|
2010-03-30 03:21:19 -07:00
|
|
|
return GetSubStringAdvance(0, mTextRun->GetLength(), metricsScale);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
nsSVGTextPathFrame*
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
void
|
2010-07-16 14:42:12 -07:00
|
|
|
nsSVGGlyphFrame::GetXY(SVGUserUnitList *aX, SVGUserUnitList *aY)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-17 20:46:48 -07:00
|
|
|
static_cast<nsSVGTextContainerFrame *>(mParent)->GetXY(aX, aY);
|
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
void
|
2010-09-17 20:46:48 -07:00
|
|
|
nsSVGGlyphFrame::SetStartIndex(PRUint32 aStartIndex)
|
|
|
|
{
|
|
|
|
mStartIndex = aStartIndex;
|
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
void
|
2010-10-13 21:16:48 -07:00
|
|
|
nsSVGGlyphFrame::GetEffectiveXY(PRInt32 strLength, nsTArray<float> &aX, nsTArray<float> &aY)
|
2010-09-17 20:46:48 -07:00
|
|
|
{
|
|
|
|
nsTArray<float> x, y;
|
|
|
|
static_cast<nsSVGTextContainerFrame *>(mParent)->GetEffectiveXY(x, y);
|
|
|
|
|
|
|
|
PRInt32 xCount = NS_MAX((PRInt32)(x.Length() - mStartIndex), 0);
|
|
|
|
xCount = NS_MIN(xCount, strLength);
|
|
|
|
aX.AppendElements(x.Elements() + mStartIndex, xCount);
|
|
|
|
|
|
|
|
PRInt32 yCount = NS_MAX((PRInt32)(y.Length() - mStartIndex), 0);
|
|
|
|
yCount = NS_MIN(yCount, strLength);
|
|
|
|
aY.AppendElements(y.Elements() + mStartIndex, yCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-16 14:42:12 -07:00
|
|
|
void
|
|
|
|
nsSVGGlyphFrame::GetDxDy(SVGUserUnitList *aDx, SVGUserUnitList *aDy)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-17 20:46:48 -07:00
|
|
|
static_cast<nsSVGTextContainerFrame *>(mParent)->GetDxDy(aDx, aDy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-13 21:16:48 -07:00
|
|
|
nsSVGGlyphFrame::GetEffectiveDxDy(PRInt32 strLength, nsTArray<float> &aDx, nsTArray<float> &aDy)
|
2010-09-17 20:46:48 -07:00
|
|
|
{
|
|
|
|
nsTArray<float> dx, dy;
|
|
|
|
static_cast<nsSVGTextContainerFrame *>(mParent)->GetEffectiveDxDy(dx, dy);
|
|
|
|
|
|
|
|
PRInt32 dxCount = NS_MAX((PRInt32)(dx.Length() - mStartIndex), 0);
|
|
|
|
dxCount = NS_MIN(dxCount, strLength);
|
|
|
|
aDx.AppendElements(dx.Elements() + mStartIndex, dxCount);
|
|
|
|
|
|
|
|
PRInt32 dyCount = NS_MAX((PRInt32)(dy.Length() - mStartIndex), 0);
|
|
|
|
dyCount = NS_MIN(dyCount, strLength);
|
|
|
|
aDy.AppendElements(dy.Elements() + mStartIndex, dyCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-12-03 08:40:23 -08:00
|
|
|
const SVGNumberList*
|
2010-03-30 03:21:19 -07:00
|
|
|
nsSVGGlyphFrame::GetRotate()
|
|
|
|
{
|
|
|
|
nsSVGTextContainerFrame *containerFrame;
|
|
|
|
containerFrame = static_cast<nsSVGTextContainerFrame *>(mParent);
|
|
|
|
if (containerFrame)
|
|
|
|
return containerFrame->GetRotate();
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2010-09-17 20:46:48 -07:00
|
|
|
void
|
2010-10-13 21:16:48 -07:00
|
|
|
nsSVGGlyphFrame::GetEffectiveRotate(PRInt32 strLength, nsTArray<float> &aRotate)
|
2010-09-17 20:46:48 -07:00
|
|
|
{
|
|
|
|
nsTArray<float> rotate;
|
|
|
|
static_cast<nsSVGTextContainerFrame *>(mParent)->GetEffectiveRotate(rotate);
|
|
|
|
|
|
|
|
PRInt32 rotateCount = NS_MAX((PRInt32)(rotate.Length() - mStartIndex), 0);
|
|
|
|
rotateCount = NS_MIN(rotateCount, strLength);
|
|
|
|
if (rotateCount > 0) {
|
|
|
|
aRotate.AppendElements(rotate.Elements() + mStartIndex, rotateCount);
|
|
|
|
} else if (!rotate.IsEmpty()) {
|
|
|
|
// rotate is applied for extra characters too
|
|
|
|
aRotate.AppendElement(rotate[rotate.Length() - 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
PRUint16
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGGlyphFrame::GetTextAnchor()
|
|
|
|
{
|
|
|
|
return GetStyleSVG()->mTextAnchor;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGGlyphFrame::IsAbsolutelyPositioned()
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasTextPathAncestor = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (nsIFrame *frame = GetParent();
|
|
|
|
frame != nsnull;
|
2010-09-17 20:46:48 -07:00
|
|
|
frame = frame->GetParent()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-17 20:46:48 -07:00
|
|
|
// at the start of a 'text' element
|
|
|
|
// at the start of each 'textPath' element
|
|
|
|
if (frame->GetType() == nsGkAtoms::svgTextPathFrame) {
|
|
|
|
hasTextPathAncestor = PR_TRUE;
|
|
|
|
}
|
|
|
|
if ((frame->GetType() == nsGkAtoms::svgTextFrame ||
|
|
|
|
frame->GetType() == nsGkAtoms::svgTextPathFrame) &&
|
2011-08-24 13:54:30 -07:00
|
|
|
frame->GetFirstPrincipalChild() == this) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
2010-09-17 20:46:48 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (frame->GetType() == nsGkAtoms::svgTextFrame)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-17 20:46:48 -07:00
|
|
|
// for each character within a 'text', 'tspan', 'tref' and 'altGlyph' element
|
|
|
|
// which has an x or y attribute value assigned to it explicitly
|
|
|
|
nsTArray<float> x, y;
|
2010-10-13 21:16:48 -07:00
|
|
|
GetEffectiveXY(GetNumberOfChars(), x, y);
|
2010-09-17 20:46:48 -07:00
|
|
|
// Note: the y of descendants of textPath has no effect in horizontal writing
|
|
|
|
return (!x.IsEmpty() || (!hasTextPathAncestor && !y.IsEmpty()));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGGlyphFragmentNode interface:
|
|
|
|
|
2009-05-29 03:15:40 -07:00
|
|
|
PRUint32
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGGlyphFrame::GetNumberOfChars()
|
|
|
|
{
|
2011-05-03 00:45:30 -07:00
|
|
|
if (mCompressWhitespace) {
|
|
|
|
nsAutoString text;
|
|
|
|
GetCharacterData(text);
|
|
|
|
return text.Length();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-03 00:45:30 -07:00
|
|
|
return mContent->TextLength();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-05-29 03:15:40 -07:00
|
|
|
float
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGGlyphFrame::GetComputedTextLength()
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
return GetAdvance(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-05-29 03:15:40 -07:00
|
|
|
float
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
|
|
|
2010-03-30 03:21:19 -07:00
|
|
|
return GetSubStringAdvance(charnum, fragmentChars, metricsScale);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-05-29 03:15:40 -07:00
|
|
|
PRInt32
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
|
|
|
2011-08-23 05:31:56 -07:00
|
|
|
PRUint32 i;
|
2008-03-18 12:50:29 -07:00
|
|
|
PRInt32 last = -1;
|
|
|
|
gfxPoint pt(xPos, yPos);
|
2011-08-23 05:31:56 -07:00
|
|
|
while ((i = iter.NextCluster()) != iter.InvalidCluster()) {
|
|
|
|
PRUint32 limit = i + iter.ClusterLength();
|
2007-04-18 14:09:31 -07:00
|
|
|
gfxTextRun::Metrics metrics =
|
2009-02-24 00:32:58 -08:00
|
|
|
mTextRun->MeasureText(i, limit - i, gfxFont::LOOSE_INK_EXTENTS,
|
|
|
|
nsnull, nsnull);
|
2009-02-22 17:19:30 -08:00
|
|
|
|
|
|
|
// the SVG spec tells us to divide the width of the cluster equally among
|
|
|
|
// its chars, so we'll step through the chars, allocating a share of the
|
|
|
|
// total advance to each
|
|
|
|
PRInt32 current, end, step;
|
|
|
|
if (mTextRun->IsRightToLeft()) {
|
|
|
|
current = limit - 1;
|
|
|
|
end = i - 1;
|
|
|
|
step = -1;
|
|
|
|
} else {
|
|
|
|
current = i;
|
|
|
|
end = limit;
|
|
|
|
step = 1;
|
|
|
|
}
|
|
|
|
gfxFloat leftEdge = 0.0;
|
|
|
|
gfxFloat width = metrics.mAdvanceWidth / (limit - i);
|
|
|
|
while (current != end) {
|
|
|
|
iter.SetupForMetrics(tmpCtx);
|
|
|
|
tmpCtx->NewPath();
|
|
|
|
tmpCtx->Rectangle(gfxRect(leftEdge, -metrics.mAscent,
|
|
|
|
width, metrics.mAscent + metrics.mDescent));
|
|
|
|
tmpCtx->IdentityMatrix();
|
|
|
|
if (tmpCtx->PointInFill(pt)) {
|
|
|
|
// Can't return yet; if there's glyph overlap, the last character
|
|
|
|
// to be rendered wins, so we still have to check the rest...
|
|
|
|
last = current;
|
|
|
|
break; // ...but we don't need to check more slices of this cluster
|
|
|
|
}
|
|
|
|
current += step;
|
|
|
|
leftEdge += width;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
NS_IMETHODIMP_(nsSVGGlyphFrame *)
|
|
|
|
nsSVGGlyphFrame::GetFirstGlyphFrame()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-05-07 10:08:41 -07:00
|
|
|
nsSVGGlyphFrame *frame = this;
|
|
|
|
while (frame && frame->IsTextEmpty()) {
|
|
|
|
frame = frame->GetNextGlyphFrame();
|
2011-05-06 03:45:17 -07:00
|
|
|
}
|
2011-05-07 10:08:41 -07:00
|
|
|
return frame;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
NS_IMETHODIMP_(nsSVGGlyphFrame *)
|
|
|
|
nsSVGGlyphFrame::GetNextGlyphFrame()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-09-18 04:09:36 -07:00
|
|
|
nsIFrame* sibling = GetNextSibling();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (sibling) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsISVGGlyphFragmentNode *node = do_QueryFrame(sibling);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (node)
|
2011-05-07 10:08:41 -07:00
|
|
|
return node->GetFirstGlyphFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
sibling = sibling->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
// no more siblings. go back up the tree.
|
|
|
|
|
2009-09-18 04:09:36 -07:00
|
|
|
NS_ASSERTION(GetParent(), "null parent");
|
|
|
|
nsISVGGlyphFragmentNode *node = do_QueryFrame(GetParent());
|
2011-05-07 10:08:41 -07:00
|
|
|
return node ? node->GetNextGlyphFrame() : nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-05-03 00:45:30 -07:00
|
|
|
nsSVGGlyphFrame::EndsWithWhitespace() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-05-03 00:45:30 -07:00
|
|
|
const nsTextFragment* text = mContent->GetText();
|
2011-05-06 03:45:17 -07:00
|
|
|
NS_ABORT_IF_FALSE(text->GetLength() > 0, "text expected");
|
|
|
|
|
2011-05-03 00:45:30 -07:00
|
|
|
return NS_IsAsciiWhitespace(text->CharAt(text->GetLength() - 1));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-05-03 00:45:30 -07:00
|
|
|
nsSVGGlyphFrame::IsAllWhitespace() const
|
2010-12-16 02:57:35 -08:00
|
|
|
{
|
|
|
|
const nsTextFragment* text = mContent->GetText();
|
|
|
|
|
|
|
|
if (text->Is2b())
|
|
|
|
return PR_FALSE;
|
|
|
|
PRInt32 len = text->GetLength();
|
|
|
|
const char* str = text->Get1b();
|
|
|
|
for (PRInt32 i = 0; i < len; ++i) {
|
|
|
|
if (!NS_IsAsciiWhitespace(str[i]))
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-03-18 12:50:29 -07:00
|
|
|
nsSVGGlyphFrame::GetGlobalTransform(gfxMatrix *aMatrix)
|
|
|
|
{
|
2011-04-20 02:16:01 -07:00
|
|
|
if (!mPropagateTransform) {
|
2008-11-29 11:23:57 -08:00
|
|
|
aMatrix->Reset();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
*aMatrix = GetCanvasTM();
|
2008-03-31 06:40:18 -07:00
|
|
|
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);
|
2009-04-28 21:31:34 -07:00
|
|
|
if (!matrix.IsSingular()) {
|
|
|
|
aContext->Multiply(matrix);
|
|
|
|
}
|
2008-03-18 12:50:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGGlyphFrame::ClearTextRun()
|
|
|
|
{
|
|
|
|
if (!mTextRun)
|
|
|
|
return;
|
|
|
|
gfxTextRunWordCache::RemoveTextRun(mTextRun);
|
|
|
|
delete mTextRun;
|
|
|
|
mTextRun = nsnull;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-03-18 12:50:29 -07:00
|
|
|
nsSVGGlyphFrame::EnsureTextRun(float *aDrawScale, float *aMetricsScale,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aForceGlobalTransform)
|
2008-03-18 12:50:29 -07:00
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
|
2011-04-13 02:23:49 -07:00
|
|
|
nsAutoString visualText;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXXsmontagu: The SVG spec says:
|
|
|
|
*
|
|
|
|
* http://www.w3.org/TR/SVG11/text.html#DirectionProperty
|
|
|
|
* "For the 'direction' property to have any effect, the 'unicode-bidi'
|
|
|
|
* property's value must be embed or bidi-override."
|
|
|
|
*
|
|
|
|
* The SVGTiny spec, on the other hand, says
|
|
|
|
*
|
|
|
|
* http://www.w3.org/TR/SVGTiny12/text.html#DirectionProperty
|
|
|
|
* "For the 'direction' property to have any effect on an element that
|
|
|
|
* does not by itself establish a new text chunk (such as the 'tspan'
|
|
|
|
* element in SVG 1.2 Tiny), the 'unicode-bidi' property's value must
|
|
|
|
* be embed or bidi-override."
|
|
|
|
*
|
|
|
|
* Note that this is different from HTML/CSS, where setting the 'dir'
|
|
|
|
* attribute on an inline element automatically sets unicode-bidi: embed
|
|
|
|
*
|
|
|
|
* Our current implementation of bidi in SVG does not distinguish between
|
|
|
|
* different text elements, but treats every text container frame as a
|
|
|
|
* new text chunk, so we always set the base direction according to the
|
|
|
|
* direction property
|
|
|
|
*
|
|
|
|
* See also XXXsmontagu comments in nsSVGTextFrame::UpdateGlyphPositioning
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Get the unicodeBidi property from the parent, because it doesn't
|
|
|
|
// inherit
|
2011-09-28 23:19:26 -07:00
|
|
|
bool bidiOverride = (mParent->GetStyleTextReset()->mUnicodeBidi ==
|
2011-04-13 02:23:49 -07:00
|
|
|
NS_STYLE_UNICODE_BIDI_OVERRIDE);
|
|
|
|
nsBidiLevel baseDirection =
|
|
|
|
GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL ?
|
|
|
|
NSBIDI_RTL : NSBIDI_LTR;
|
|
|
|
nsBidiPresUtils::CopyLogicalToVisual(text, visualText,
|
|
|
|
baseDirection, bidiOverride);
|
|
|
|
if (!visualText.IsEmpty()) {
|
|
|
|
text = visualText;
|
2011-01-04 00:52:17 -08:00
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
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
|
|
|
|
|
|
|
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;
|
2009-09-16 08:01:36 -07:00
|
|
|
textRunSize = NS_MAX(textRunSize, double(CLAMP_MIN_SIZE));
|
|
|
|
textRunSize = NS_MIN(textRunSize, double(CLAMP_MAX_SIZE));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
const nsFont& font = fontData->mFont;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool printerFont = (presContext->Type() == nsPresContext::eContext_PrintPreview ||
|
2008-12-16 19:17:50 -08:00
|
|
|
presContext->Type() == nsPresContext::eContext_Print);
|
2009-01-29 12:39:18 -08:00
|
|
|
gfxFontStyle fontStyle(font.style, font.weight, font.stretch, textRunSize,
|
2010-02-24 09:57:57 -08:00
|
|
|
mStyleContext->GetStyleVisibility()->mLanguage,
|
|
|
|
font.sizeAdjust, font.systemFont,
|
2010-07-13 13:30:42 -07:00
|
|
|
printerFont,
|
|
|
|
font.featureSettings,
|
|
|
|
font.languageOverride);
|
2007-04-18 14:09:31 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
nsRefPtr<gfxFontGroup> fontGroup =
|
2008-09-30 20:01:53 -07:00
|
|
|
gfxPlatform::GetPlatform()->CreateFontGroup(font.name, &fontStyle, presContext->GetUserFontSet());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
PRUint32 flags = gfxTextRunFactory::TEXT_NEED_BOUNDING_BOX |
|
2010-10-17 09:27:48 -07:00
|
|
|
GetTextRunFlags(text.Length()) |
|
2008-03-18 12:50:29 -07:00
|
|
|
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-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,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aForceGlobalTransform)
|
2011-08-23 05:31:56 -07:00
|
|
|
: mSource(aSource)
|
|
|
|
, mCurrentAdvance(0)
|
|
|
|
, mCurrentChar(PRUint32(-1))
|
|
|
|
, mInError(PR_FALSE)
|
2008-03-18 12:50:29 -07:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-03-18 12:50:29 -07:00
|
|
|
CharacterIterator::SetupForDirectTextRun(gfxContext *aContext, float aScale)
|
|
|
|
{
|
|
|
|
if (!mPositions.IsEmpty() || mInError)
|
|
|
|
return PR_FALSE;
|
|
|
|
aContext->SetMatrix(mInitialMatrix);
|
|
|
|
aContext->Translate(mSource->mPosition);
|
|
|
|
aContext->Scale(aScale, aScale);
|
|
|
|
return PR_TRUE;
|
2008-03-17 18:45:05 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-23 05:31:56 -07:00
|
|
|
PRUint32
|
2011-01-11 03:17:00 -08:00
|
|
|
CharacterIterator::NextCluster()
|
2008-03-18 00:42:07 -07:00
|
|
|
{
|
2010-11-01 22:40:30 -07:00
|
|
|
if (mInError) {
|
|
|
|
#ifdef DEBUG
|
2011-08-23 05:31:56 -07:00
|
|
|
if (mCurrentChar != InvalidCluster()) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool pastEnd = (mCurrentChar >= mSource->mTextRun->GetLength());
|
2010-11-01 22:40:30 -07:00
|
|
|
NS_ABORT_IF_FALSE(pastEnd, "Past the end of CharacterIterator. Missing Reset?");
|
|
|
|
}
|
|
|
|
#endif
|
2011-08-23 05:31:56 -07:00
|
|
|
return InvalidCluster();
|
2010-11-01 22:40:30 -07:00
|
|
|
}
|
2008-03-18 12:50:29 -07:00
|
|
|
|
|
|
|
while (PR_TRUE) {
|
2011-08-23 05:31:56 -07:00
|
|
|
if (mCurrentChar != InvalidCluster() &&
|
2008-03-18 12:50:29 -07:00
|
|
|
(mPositions.IsEmpty() || mPositions[mCurrentChar].draw)) {
|
|
|
|
mCurrentAdvance +=
|
|
|
|
mSource->mTextRun->GetAdvanceWidth(mCurrentChar, 1, nsnull);
|
|
|
|
}
|
|
|
|
++mCurrentChar;
|
|
|
|
|
2011-08-23 05:31:56 -07:00
|
|
|
if (mCurrentChar >= mSource->mTextRun->GetLength()) {
|
2010-11-01 22:40:30 -07:00
|
|
|
mInError = PR_TRUE;
|
2011-08-23 05:31:56 -07:00
|
|
|
return InvalidCluster();
|
2010-11-01 22:40:30 -07:00
|
|
|
}
|
2008-03-18 12:50:29 -07:00
|
|
|
|
2011-01-11 03:17:00 -08:00
|
|
|
if (mSource->mTextRun->IsClusterStart(mCurrentChar) &&
|
|
|
|
(mPositions.IsEmpty() || mPositions[mCurrentChar].draw)) {
|
2008-03-18 12:50:29 -07:00
|
|
|
return mCurrentChar;
|
2011-01-11 03:17:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-23 05:31:56 -07:00
|
|
|
PRUint32
|
2011-01-11 03:17:00 -08:00
|
|
|
CharacterIterator::ClusterLength()
|
|
|
|
{
|
|
|
|
if (mInError) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-23 05:31:56 -07:00
|
|
|
PRUint32 i = mCurrentChar;
|
2011-01-11 03:17:00 -08:00
|
|
|
while (++i < mSource->mTextRun->GetLength()) {
|
|
|
|
if (mSource->mTextRun->IsClusterStart(i)) {
|
|
|
|
break;
|
|
|
|
}
|
2008-03-18 12:50:29 -07:00
|
|
|
}
|
2011-01-11 03:17:00 -08:00
|
|
|
return i - mCurrentChar;
|
2008-03-18 00:42:07 -07:00
|
|
|
}
|
2008-03-17 19:36:17 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-08-23 05:31:56 -07:00
|
|
|
CharacterIterator::AdvanceToCharacter(PRUint32 aIndex)
|
2008-03-18 12:50:29 -07:00
|
|
|
{
|
2011-08-23 05:31:56 -07:00
|
|
|
while (NextCluster() != InvalidCluster()) {
|
2008-03-18 12:50:29 -07:00
|
|
|
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-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
|
|
|
}
|