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"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsIDOMSVGLengthList.h"
|
|
|
|
#include "nsIDOMSVGLength.h"
|
|
|
|
#include "nsIDOMSVGAnimatedNumber.h"
|
|
|
|
#include "nsISVGGlyphFragmentNode.h"
|
|
|
|
#include "nsISVGGlyphFragmentLeaf.h"
|
|
|
|
#include "nsSVGOuterSVGFrame.h"
|
|
|
|
#include "nsIDOMSVGRect.h"
|
|
|
|
#include "nsISVGTextContentMetrics.h"
|
|
|
|
#include "nsSVGRect.h"
|
|
|
|
#include "nsSVGMatrix.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsSVGTextPathFrame.h"
|
|
|
|
#include "nsSVGPathElement.h"
|
|
|
|
#include "nsSVGUtils.h"
|
|
|
|
#include "nsSVGGraphicElement.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewSVGTextFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext)
|
|
|
|
{
|
2007-08-03 01:39:12 -07:00
|
|
|
nsCOMPtr<nsIDOMSVGTextElement> text = do_QueryInterface(aContent);
|
|
|
|
if (!text) {
|
|
|
|
NS_ERROR("Can't create frame! Content is not an SVG text");
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new (aPresShell) nsSVGTextFrame(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
|
|
|
{
|
|
|
|
if (aNameSpaceID != kNameSpaceID_None)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::transform) {
|
|
|
|
// transform has changed
|
|
|
|
|
|
|
|
// make sure our cached transform matrix gets (lazily) updated
|
|
|
|
mCanvasTM = nsnull;
|
2008-01-25 01:27:03 -08:00
|
|
|
|
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(this, TRANSFORM_CHANGED);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aAttribute == nsGkAtoms::x ||
|
|
|
|
aAttribute == nsGkAtoms::y ||
|
|
|
|
aAttribute == nsGkAtoms::dx ||
|
|
|
|
aAttribute == nsGkAtoms::dy) {
|
|
|
|
NotifyGlyphMetricsChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::DidSetStyleContext()
|
|
|
|
{
|
|
|
|
nsSVGUtils::StyleEffects(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGTextFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgTextFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGTextContentMetrics
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetNumberOfChars(PRInt32 *_retval)
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
UpdateGlyphPositioning(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetNumberOfChars(_retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetComputedTextLength(float *_retval)
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
UpdateGlyphPositioning(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetComputedTextLength(_retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetSubStringLength(PRUint32 charnum, PRUint32 nchars, float *_retval)
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
UpdateGlyphPositioning(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetSubStringLength(charnum, nchars, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetStartPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
UpdateGlyphPositioning(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetStartPositionOfChar(charnum, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetEndPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
UpdateGlyphPositioning(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetEndPositionOfChar(charnum, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
UpdateGlyphPositioning(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetExtentOfChar(charnum, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetRotationOfChar(PRUint32 charnum, float *_retval)
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
UpdateGlyphPositioning(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetRotationOfChar(charnum, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetCharNumAtPosition(nsIDOMSVGPoint *point, PRInt32 *_retval)
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
UpdateGlyphPositioning(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetCharNumAtPosition(point, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
void
|
|
|
|
nsSVGTextFrame::NotifySVGChanged(PRUint32 aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-25 01:27:03 -08:00
|
|
|
if (aFlags & TRANSFORM_CHANGED) {
|
|
|
|
// make sure our cached transform matrix gets (lazily) updated
|
|
|
|
mCanvasTM = nsnull;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
if (aFlags & COORD_CONTEXT_CHANGED) {
|
|
|
|
// 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-12-20 06:26:34 -08:00
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
nsSVGTextFrameBase::NotifySVGChanged(aFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::NotifyRedrawSuspended()
|
|
|
|
{
|
|
|
|
mMetricsState = suspended;
|
|
|
|
|
|
|
|
return nsSVGTextFrameBase::NotifyRedrawSuspended();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::NotifyRedrawUnsuspended()
|
|
|
|
{
|
|
|
|
mMetricsState = unsuspended;
|
2008-03-18 12:50:29 -07:00
|
|
|
UpdateGlyphPositioning(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsSVGTextFrameBase::NotifyRedrawUnsuspended();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::SetMatrixPropagation(PRBool aPropagate)
|
|
|
|
{
|
|
|
|
mPropagateTransform = aPropagate;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::SetOverrideCTM(nsIDOMSVGMatrix *aCTM)
|
|
|
|
{
|
|
|
|
mOverrideCTM = aCTM;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-08-30 11:45:06 -07:00
|
|
|
already_AddRefed<nsIDOMSVGMatrix>
|
|
|
|
nsSVGTextFrame::GetOverrideCTM()
|
|
|
|
{
|
|
|
|
nsIDOMSVGMatrix *matrix = mOverrideCTM.get();
|
|
|
|
NS_IF_ADDREF(matrix);
|
|
|
|
return matrix;
|
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::PaintSVG(nsSVGRenderState* aContext, nsRect *aDirtyRect)
|
|
|
|
{
|
|
|
|
UpdateGlyphPositioning(PR_TRUE);
|
|
|
|
|
|
|
|
return nsSVGTextFrameBase::PaintSVG(aContext, aDirtyRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetFrameForPointSVG(float x, float y, nsIFrame** hit)
|
|
|
|
{
|
|
|
|
UpdateGlyphPositioning(PR_TRUE);
|
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetFrameForPointSVG(x, y, hit);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::UpdateCoveredRegion()
|
|
|
|
{
|
|
|
|
UpdateGlyphPositioning(PR_TRUE);
|
|
|
|
|
|
|
|
return nsSVGTextFrameBase::UpdateCoveredRegion();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextFrame::GetBBox(nsIDOMSVGRect **_retval)
|
|
|
|
{
|
2008-03-18 12:50:29 -07:00
|
|
|
UpdateGlyphPositioning(PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetBBox(_retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGContainerFrame methods:
|
|
|
|
|
|
|
|
already_AddRefed<nsIDOMSVGMatrix>
|
|
|
|
nsSVGTextFrame::GetCanvasTM()
|
|
|
|
{
|
|
|
|
if (!mPropagateTransform) {
|
|
|
|
nsIDOMSVGMatrix *retval;
|
|
|
|
if (mOverrideCTM) {
|
|
|
|
retval = mOverrideCTM;
|
|
|
|
NS_ADDREF(retval);
|
|
|
|
} else {
|
|
|
|
NS_NewSVGMatrix(&retval);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mCanvasTM) {
|
|
|
|
// get our parent's tm and append local transforms (if any):
|
|
|
|
NS_ASSERTION(mParent, "null parent");
|
2007-07-08 00:08:04 -07:00
|
|
|
nsSVGContainerFrame *containerFrame = static_cast<nsSVGContainerFrame*>
|
|
|
|
(mParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMSVGMatrix> parentTM = containerFrame->GetCanvasTM();
|
|
|
|
NS_ASSERTION(parentTM, "null TM");
|
|
|
|
|
|
|
|
// got the parent tm, now check for local tm:
|
|
|
|
nsSVGGraphicElement *element =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsSVGGraphicElement*>(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMSVGMatrix> localTM = element->GetLocalTransformMatrix();
|
|
|
|
|
|
|
|
if (localTM)
|
|
|
|
parentTM->Multiply(localTM, getter_AddRefs(mCanvasTM));
|
|
|
|
else
|
|
|
|
mCanvasTM = parentTM;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMSVGMatrix* retval = mCanvasTM.get();
|
|
|
|
NS_IF_ADDREF(retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGTextFrame::NotifyGlyphMetricsChange()
|
|
|
|
{
|
|
|
|
mPositioningDirty = PR_TRUE;
|
2008-04-08 05:51:19 -07:00
|
|
|
UpdateGlyphPositioning(PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetSingleValue(nsISVGGlyphFragmentLeaf *fragment,
|
|
|
|
nsIDOMSVGLengthList *list, float *val)
|
|
|
|
{
|
|
|
|
if (!list)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PRUint32 count = 0;
|
|
|
|
list->GetNumberOfItems(&count);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (count > 1)
|
|
|
|
NS_WARNING("multiple lengths for x/y attributes on <text> elements not implemented yet!");
|
|
|
|
#endif
|
|
|
|
if (count) {
|
|
|
|
nsCOMPtr<nsIDOMSVGLength> length;
|
|
|
|
list->GetItem(0, getter_AddRefs(length));
|
|
|
|
length->GetValue(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-18 12:50:29 -07:00
|
|
|
nsSVGTextFrame::UpdateGlyphPositioning(PRBool aForceGlobalTransform)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mMetricsState == suspended || !mPositioningDirty)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SetWhitespaceHandling();
|
|
|
|
|
|
|
|
nsISVGGlyphFragmentNode* node = GetFirstGlyphFragmentChildNode();
|
|
|
|
if (!node) return;
|
|
|
|
|
2008-04-08 05:51:19 -07:00
|
|
|
mPositioningDirty = PR_FALSE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// we'll align every fragment in this chunk on the dominant-baseline:
|
|
|
|
// XXX should actually inspect 'alignment-baseline' for each fragment
|
|
|
|
|
|
|
|
PRUint8 baseline;
|
|
|
|
switch(GetStyleSVGReset()->mDominantBaseline) {
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_TEXT_BEFORE_EDGE:
|
|
|
|
baseline = nsISVGGlyphFragmentLeaf::BASELINE_TEXT_BEFORE_EDGE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_TEXT_AFTER_EDGE:
|
|
|
|
baseline = nsISVGGlyphFragmentLeaf::BASELINE_TEXT_AFTER_EDGE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_MIDDLE:
|
|
|
|
baseline = nsISVGGlyphFragmentLeaf::BASELINE_MIDDLE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_CENTRAL:
|
|
|
|
baseline = nsISVGGlyphFragmentLeaf::BASELINE_CENTRAL;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_MATHEMATICAL:
|
|
|
|
baseline = nsISVGGlyphFragmentLeaf::BASELINE_MATHEMATICAL;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_IDEOGRAPHIC:
|
|
|
|
baseline = nsISVGGlyphFragmentLeaf::BASELINE_IDEOGRAPHC;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_HANGING:
|
|
|
|
baseline = nsISVGGlyphFragmentLeaf::BASELINE_HANGING;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_AUTO:
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_USE_SCRIPT:
|
|
|
|
case NS_STYLE_DOMINANT_BASELINE_ALPHABETIC:
|
|
|
|
default:
|
|
|
|
baseline = nsISVGGlyphFragmentLeaf::BASELINE_ALPHABETIC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISVGGlyphFragmentLeaf *fragment, *firstFragment;
|
|
|
|
|
|
|
|
firstFragment = node->GetFirstGlyphFragment();
|
|
|
|
if (!firstFragment) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float x = 0, y = 0;
|
|
|
|
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMSVGLengthList> list = GetX();
|
|
|
|
GetSingleValue(firstFragment, list, &x);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMSVGLengthList> list = GetY();
|
|
|
|
GetSingleValue(firstFragment, list, &y);
|
|
|
|
}
|
|
|
|
|
|
|
|
// loop over chunks
|
|
|
|
while (firstFragment) {
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMSVGLengthList> list = firstFragment->GetX();
|
|
|
|
GetSingleValue(firstFragment, list, &x);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMSVGLengthList> list = firstFragment->GetY();
|
|
|
|
GetSingleValue(firstFragment, list, &y);
|
|
|
|
}
|
|
|
|
|
2007-12-03 22:51:36 -08:00
|
|
|
// check for startOffset on textPath
|
|
|
|
nsSVGTextPathFrame *textPath = firstFragment->FindTextPathParent();
|
|
|
|
if (textPath) {
|
|
|
|
x = textPath->GetStartOffset();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// determine x offset based on text_anchor:
|
|
|
|
|
|
|
|
PRUint8 anchor = firstFragment->GetTextAnchor();
|
|
|
|
|
|
|
|
float chunkLength = 0.0f;
|
|
|
|
if (anchor != NS_STYLE_TEXT_ANCHOR_START) {
|
|
|
|
// need to get the total chunk length
|
|
|
|
|
|
|
|
fragment = firstFragment;
|
|
|
|
while (fragment) {
|
|
|
|
float dx = 0.0f;
|
|
|
|
nsCOMPtr<nsIDOMSVGLengthList> list = fragment->GetDx();
|
|
|
|
GetSingleValue(fragment, list, &dx);
|
2008-03-18 12:50:29 -07:00
|
|
|
chunkLength += dx + fragment->GetAdvance(aForceGlobalTransform);
|
2007-03-22 10:30:00 -07:00
|
|
|
fragment = fragment->GetNextGlyphFragment();
|
|
|
|
if (fragment && fragment->IsAbsolutelyPositioned())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (anchor == NS_STYLE_TEXT_ANCHOR_MIDDLE)
|
|
|
|
x -= chunkLength/2.0f;
|
|
|
|
else if (anchor == NS_STYLE_TEXT_ANCHOR_END)
|
|
|
|
x -= chunkLength;
|
|
|
|
|
|
|
|
// set position of each fragment in this chunk:
|
|
|
|
|
|
|
|
fragment = firstFragment;
|
|
|
|
while (fragment) {
|
|
|
|
|
|
|
|
float dx = 0.0f, dy = 0.0f;
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMSVGLengthList> list = fragment->GetDx();
|
|
|
|
GetSingleValue(fragment, list, &dx);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMSVGLengthList> list = fragment->GetDy();
|
|
|
|
GetSingleValue(fragment, list, &dy);
|
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
float baseline_offset =
|
|
|
|
fragment->GetBaselineOffset(baseline, aForceGlobalTransform);
|
2007-03-22 10:30:00 -07:00
|
|
|
fragment->SetGlyphPosition(x + dx, y + dy - baseline_offset);
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
x += dx + fragment->GetAdvance(aForceGlobalTransform);
|
2007-03-22 10:30:00 -07:00
|
|
|
y += dy;
|
|
|
|
fragment = fragment->GetNextGlyphFragment();
|
|
|
|
if (fragment && fragment->IsAbsolutelyPositioned())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
firstFragment = fragment;
|
|
|
|
}
|
|
|
|
}
|