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 "nsIDOMSVGTextElement.h"
|
|
|
|
#include "nsSVGTextFrame.h"
|
2010-07-16 14:42:12 -07:00
|
|
|
#include "SVGLengthList.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMSVGLength.h"
|
|
|
|
#include "nsIDOMSVGAnimatedNumber.h"
|
|
|
|
#include "nsISVGGlyphFragmentNode.h"
|
2011-05-07 10:08:41 -07:00
|
|
|
#include "nsSVGGlyphFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGOuterSVGFrame.h"
|
|
|
|
#include "nsIDOMSVGRect.h"
|
|
|
|
#include "nsSVGRect.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsSVGTextPathFrame.h"
|
|
|
|
#include "nsSVGPathElement.h"
|
|
|
|
#include "nsSVGUtils.h"
|
|
|
|
#include "nsSVGGraphicElement.h"
|
|
|
|
|
2010-07-16 14:42:12 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGTextFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGTextFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGTextFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods
|
2009-01-19 10:31:34 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMSVGTextElement> text = do_QueryInterface(aContent);
|
|
|
|
NS_ASSERTION(text, "Content is not an SVG text");
|
|
|
|
|
|
|
|
return nsSVGTextFrameBase::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
|
|
|
{
|
|
|
|
if (aNameSpaceID != kNameSpaceID_None)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::transform) {
|
|
|
|
|
2012-01-28 05:58:17 -08:00
|
|
|
NotifySVGChanged(TRANSFORM_CHANGED);
|
2008-01-25 01:27:03 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aAttribute == nsGkAtoms::x ||
|
|
|
|
aAttribute == nsGkAtoms::y ||
|
|
|
|
aAttribute == nsGkAtoms::dx ||
|
2010-10-17 09:27:49 -07:00
|
|
|
aAttribute == nsGkAtoms::dy ||
|
|
|
|
aAttribute == nsGkAtoms::rotate) {
|
2007-03-22 10:30:00 -07:00
|
|
|
NotifyGlyphMetricsChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGTextFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgTextFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2009-05-29 03:15:40 -07:00
|
|
|
// nsSVGTextContainerFrame
|
|
|
|
PRUint32
|
|
|
|
nsSVGTextFrame::GetNumberOfChars()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-05-29 03:15:40 -07:00
|
|
|
return nsSVGTextFrameBase::GetNumberOfChars();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-05-29 03:15:40 -07:00
|
|
|
float
|
|
|
|
nsSVGTextFrame::GetComputedTextLength()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-05-29 03:15:40 -07:00
|
|
|
return nsSVGTextFrameBase::GetComputedTextLength();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-05-29 03:15:40 -07:00
|
|
|
float
|
|
|
|
nsSVGTextFrame::GetSubStringLength(PRUint32 charnum, PRUint32 nchars)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(false);
|
2009-05-29 03:15:40 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetSubStringLength(charnum, nchars);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsSVGTextFrame::GetCharNumAtPosition(nsIDOMSVGPoint *point)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-05-29 03:15:40 -07:00
|
|
|
return nsSVGTextFrameBase::GetCharNumAtPosition(point);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetStartPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetStartPositionOfChar(charnum, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetEndPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetEndPositionOfChar(charnum, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetExtentOfChar(charnum, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetRotationOfChar(PRUint32 charnum, float *_retval)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetRotationOfChar(charnum, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
void
|
|
|
|
nsSVGTextFrame::NotifySVGChanged(PRUint32 aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-28 05:58:17 -08:00
|
|
|
bool updateGlyphMetrics = false;
|
|
|
|
|
|
|
|
if (aFlags & COORD_CONTEXT_CHANGED) {
|
|
|
|
updateGlyphMetrics = true;
|
|
|
|
}
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
if (aFlags & TRANSFORM_CHANGED) {
|
2012-01-28 05:58:17 -08:00
|
|
|
if (mCanvasTM && mCanvasTM->IsSingular()) {
|
|
|
|
// We won't have calculated the glyph positions correctly
|
|
|
|
updateGlyphMetrics = true;
|
|
|
|
}
|
2008-01-25 01:27:03 -08:00
|
|
|
// make sure our cached transform matrix gets (lazily) updated
|
|
|
|
mCanvasTM = nsnull;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-12 06:37:20 -08:00
|
|
|
nsSVGTextFrameBase::NotifySVGChanged(aFlags);
|
|
|
|
|
2012-01-28 05:58:17 -08:00
|
|
|
if (updateGlyphMetrics) {
|
2008-01-25 01:27:03 -08:00
|
|
|
// If we are positioned using percentage values we need to update our
|
|
|
|
// position whenever our viewport's dimensions change.
|
|
|
|
|
|
|
|
// XXX We could check here whether the text frame or any of its children
|
|
|
|
// have any percentage co-ordinates and only update if they don't. This
|
|
|
|
// may not be worth it as we might need to check each glyph
|
|
|
|
NotifyGlyphMetricsChange();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-02-04 05:58:46 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGTextFrame::NotifyRedrawUnsuspended()
|
|
|
|
{
|
2012-02-04 05:58:46 -08:00
|
|
|
RemoveStateBits(NS_STATE_SVG_REDRAW_SUSPENDED);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(false);
|
2012-02-04 05:58:46 -08:00
|
|
|
nsSVGTextFrameBase::NotifyRedrawUnsuspended();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
NS_IMETHODIMP
|
2012-03-02 00:28:59 -08:00
|
|
|
nsSVGTextFrame::PaintSVG(nsRenderingContext* aContext,
|
2008-10-20 01:42:03 -07:00
|
|
|
const nsIntRect *aDirtyRect)
|
2008-03-18 12:50:29 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(true);
|
2008-03-18 12:50:29 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::PaintSVG(aContext, aDirtyRect);
|
|
|
|
}
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
NS_IMETHODIMP_(nsIFrame*)
|
|
|
|
nsSVGTextFrame::GetFrameForPoint(const nsPoint &aPoint)
|
2008-03-18 12:50:29 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(true);
|
2008-03-18 12:50:29 -07:00
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
return nsSVGTextFrameBase::GetFrameForPoint(aPoint);
|
2008-03-18 12:50:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::UpdateCoveredRegion()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(true);
|
2008-03-18 12:50:29 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::UpdateCoveredRegion();
|
|
|
|
}
|
|
|
|
|
2008-07-30 12:28:12 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::InitialUpdate()
|
|
|
|
{
|
|
|
|
nsresult rv = nsSVGTextFrameBase::InitialUpdate();
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(false);
|
2008-07-30 12:28:12 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
gfxRect
|
2011-09-30 02:25:37 -07:00
|
|
|
nsSVGTextFrame::GetBBoxContribution(const gfxMatrix &aToBBoxUserspace,
|
|
|
|
PRUint32 aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-30 02:25:37 -07:00
|
|
|
return nsSVGTextFrameBase::GetBBoxContribution(aToBBoxUserspace, aFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGContainerFrame methods:
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
gfxMatrix
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGTextFrame::GetCanvasTM()
|
|
|
|
{
|
|
|
|
if (!mCanvasTM) {
|
|
|
|
NS_ASSERTION(mParent, "null parent");
|
2009-04-28 21:31:34 -07:00
|
|
|
|
|
|
|
nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent);
|
|
|
|
nsSVGGraphicElement *content = static_cast<nsSVGGraphicElement*>(mContent);
|
|
|
|
|
2012-02-17 00:12:47 -08:00
|
|
|
gfxMatrix tm = content->PrependLocalTransformsTo(parent->GetCanvasTM());
|
2009-04-28 21:31:34 -07:00
|
|
|
|
2011-09-25 14:04:32 -07:00
|
|
|
mCanvasTM = new gfxMatrix(tm);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-25 14:04:32 -07:00
|
|
|
return *mCanvasTM;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGTextFrame::NotifyGlyphMetricsChange()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mPositioningDirty = true;
|
|
|
|
UpdateGlyphPositioning(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-03 00:45:30 -07:00
|
|
|
void
|
2011-05-07 10:08:41 -07:00
|
|
|
nsSVGTextFrame::SetWhitespaceHandling(nsSVGGlyphFrame *aFrame)
|
2011-05-03 00:45:30 -07:00
|
|
|
{
|
|
|
|
SetWhitespaceCompression();
|
|
|
|
|
2012-01-14 02:07:26 -08:00
|
|
|
nsSVGGlyphFrame* firstFrame = aFrame;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool trimLeadingWhitespace = true;
|
2011-05-07 10:08:41 -07:00
|
|
|
nsSVGGlyphFrame* lastNonWhitespaceFrame = aFrame;
|
2011-05-03 00:45:30 -07:00
|
|
|
|
2012-01-14 02:07:26 -08:00
|
|
|
// If the previous frame ended with whitespace
|
|
|
|
// then display of leading whitespace should be suppressed
|
|
|
|
// when we are compressing whitespace.
|
2011-05-07 10:08:41 -07:00
|
|
|
while (aFrame) {
|
|
|
|
if (!aFrame->IsAllWhitespace()) {
|
|
|
|
lastNonWhitespaceFrame = aFrame;
|
2011-05-03 00:45:30 -07:00
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
aFrame->SetTrimLeadingWhitespace(trimLeadingWhitespace);
|
|
|
|
trimLeadingWhitespace = aFrame->EndsWithWhitespace();
|
2011-05-03 00:45:30 -07:00
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
aFrame = aFrame->GetNextGlyphFrame();
|
2011-05-03 00:45:30 -07:00
|
|
|
}
|
|
|
|
|
2012-01-14 02:07:26 -08:00
|
|
|
// When there is only whitespace left we need to trim off
|
|
|
|
// the end of the last frame that isn't entirely whitespace.
|
|
|
|
// Making sure that we reset earlier frames as they may once
|
|
|
|
// have been the last non-whitespace frame.
|
|
|
|
aFrame = firstFrame;
|
|
|
|
while (aFrame != lastNonWhitespaceFrame) {
|
|
|
|
aFrame->SetTrimTrailingWhitespace(false);
|
|
|
|
aFrame = aFrame->GetNextGlyphFrame();
|
|
|
|
}
|
|
|
|
|
2012-02-24 02:20:53 -08:00
|
|
|
// We're at the last non-whitespace frame so trim off the end
|
|
|
|
// and make sure we set one of the trim bits so that any
|
|
|
|
// further whitespace is compressed to nothing
|
|
|
|
while (aFrame) {
|
|
|
|
aFrame->SetTrimTrailingWhitespace(true);
|
|
|
|
aFrame = aFrame->GetNextGlyphFrame();
|
|
|
|
}
|
2011-05-03 00:45:30 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsSVGTextFrame::UpdateGlyphPositioning(bool aForceGlobalTransform)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-04 05:58:46 -08:00
|
|
|
if ((GetStateBits() & NS_STATE_SVG_REDRAW_SUSPENDED) || !mPositioningDirty)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mPositioningDirty = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsISVGGlyphFragmentNode* node = GetFirstGlyphFragmentChildNode();
|
2011-05-03 00:45:30 -07:00
|
|
|
if (!node)
|
|
|
|
return;
|
2008-04-08 05:51:19 -07:00
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
nsSVGGlyphFrame *frame, *firstFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
firstFrame = node->GetFirstGlyphFrame();
|
|
|
|
if (!firstFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
SetWhitespaceHandling(firstFrame);
|
2011-05-03 00:45:30 -07:00
|
|
|
|
2010-09-17 20:46:48 -07:00
|
|
|
BuildPositionList(0, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-17 20:46:48 -07:00
|
|
|
gfxPoint ctp(0.0, 0.0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// loop over chunks
|
2011-05-07 10:08:41 -07:00
|
|
|
while (firstFrame) {
|
|
|
|
nsSVGTextPathFrame *textPath = firstFrame->FindTextPathParent();
|
2010-09-17 20:46:48 -07:00
|
|
|
|
|
|
|
nsTArray<float> effectiveXList, effectiveYList;
|
2011-05-07 10:08:41 -07:00
|
|
|
firstFrame->GetEffectiveXY(firstFrame->GetNumberOfChars(),
|
|
|
|
effectiveXList, effectiveYList);
|
2010-09-17 20:46:48 -07:00
|
|
|
if (!effectiveXList.IsEmpty()) ctp.x = effectiveXList[0];
|
|
|
|
if (!textPath && !effectiveYList.IsEmpty()) ctp.y = effectiveYList[0];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-03 22:51:36 -08:00
|
|
|
// check for startOffset on textPath
|
|
|
|
if (textPath) {
|
2009-01-28 01:44:39 -08:00
|
|
|
if (!textPath->GetPathFrame()) {
|
|
|
|
// invalid text path, give up
|
|
|
|
return;
|
|
|
|
}
|
2010-03-30 03:21:19 -07:00
|
|
|
ctp.x = textPath->GetStartOffset();
|
2007-12-03 22:51:36 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// determine x offset based on text_anchor:
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
PRUint8 anchor = firstFrame->GetTextAnchor();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-04 00:52:17 -08:00
|
|
|
/**
|
|
|
|
* XXXsmontagu: The SVG spec is very vague as to how 'text-anchor'
|
|
|
|
* interacts with bidirectional text. It says:
|
|
|
|
*
|
|
|
|
* "For scripts that are inherently right to left such as Hebrew and
|
|
|
|
* Arabic [text-anchor: start] is equivalent to right alignment."
|
|
|
|
* and
|
|
|
|
* "For scripts that are inherently right to left such as Hebrew and
|
|
|
|
* Arabic, [text-anchor: end] is equivalent to left alignment.
|
|
|
|
*
|
|
|
|
* It's not clear how this should be implemented in terms of defined
|
|
|
|
* properties, i.e. how one should determine that a particular element
|
|
|
|
* contains a script that is inherently right to left.
|
|
|
|
*
|
|
|
|
* The code below follows http://www.w3.org/TR/SVGTiny12/text.html#TextAnchorProperty
|
|
|
|
* and swaps the values of text-anchor: end and text-anchor: start
|
|
|
|
* whenever the 'direction' property is rtl.
|
|
|
|
*
|
|
|
|
* This is probably the "right" thing to do, but other browsers don't do it,
|
|
|
|
* so I am leaving it inside #if 0 for now for interoperability.
|
|
|
|
*
|
|
|
|
* See also XXXsmontagu comments in nsSVGGlyphFrame::EnsureTextRun
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
if (GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
|
|
|
|
if (anchor == NS_STYLE_TEXT_ANCHOR_END) {
|
|
|
|
anchor = NS_STYLE_TEXT_ANCHOR_START;
|
|
|
|
} else if (anchor == NS_STYLE_TEXT_ANCHOR_START) {
|
|
|
|
anchor = NS_STYLE_TEXT_ANCHOR_END;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
float chunkLength = 0.0f;
|
|
|
|
if (anchor != NS_STYLE_TEXT_ANCHOR_START) {
|
|
|
|
// need to get the total chunk length
|
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
frame = firstFrame;
|
|
|
|
while (frame) {
|
|
|
|
chunkLength += frame->GetAdvance(aForceGlobalTransform);
|
|
|
|
frame = frame->GetNextGlyphFrame();
|
|
|
|
if (frame && frame->IsAbsolutelyPositioned())
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (anchor == NS_STYLE_TEXT_ANCHOR_MIDDLE)
|
2010-03-30 03:21:19 -07:00
|
|
|
ctp.x -= chunkLength/2.0f;
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (anchor == NS_STYLE_TEXT_ANCHOR_END)
|
2010-03-30 03:21:19 -07:00
|
|
|
ctp.x -= chunkLength;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
// set position of each frame in this chunk:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
frame = firstFrame;
|
|
|
|
while (frame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-07 10:08:41 -07:00
|
|
|
frame->SetGlyphPosition(&ctp, aForceGlobalTransform);
|
|
|
|
frame = frame->GetNextGlyphFrame();
|
|
|
|
if (frame && frame->IsAbsolutelyPositioned())
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2011-05-07 10:08:41 -07:00
|
|
|
firstFrame = frame;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-03-10 07:38:14 -08:00
|
|
|
nsSVGUtils::UpdateGraphic(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|