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 IBM Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* 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 "nsSVGTextPathFrame.h"
|
|
|
|
#include "nsIDOMSVGTextPathElement.h"
|
2008-10-11 04:29:35 -07:00
|
|
|
#include "nsSVGLength2.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMSVGURIReference.h"
|
2008-10-11 04:29:35 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsSVGPathElement.h"
|
2007-12-03 22:51:36 -08:00
|
|
|
#include "nsSVGTextPathElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGTextPathFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-19 10:31:34 -08:00
|
|
|
return new (aPresShell) nsSVGTextPathFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGTextPathFrame)
|
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextPathFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aParent, "null parent");
|
|
|
|
|
|
|
|
nsIFrame* ancestorFrame = nsSVGUtils::GetFirstNonAAncestorFrame(aParent);
|
|
|
|
NS_ASSERTION(ancestorFrame, "Must have ancestor");
|
|
|
|
|
|
|
|
NS_ASSERTION(ancestorFrame->GetType() == nsGkAtoms::svgTextFrame,
|
|
|
|
"trying to construct an SVGTextPathFrame for an invalid "
|
|
|
|
"container");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-25 02:16:02 -07:00
|
|
|
nsCOMPtr<nsIDOMSVGTextPathElement> textPath = do_QueryInterface(aContent);
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_ASSERTION(textPath, "Content is not an SVG textPath");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
|
|
|
|
return nsSVGTextPathFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-01-19 10:31:34 -08:00
|
|
|
#endif /* DEBUG */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGTextPathFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgTextPathFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<nsIDOMSVGLengthList>)
|
|
|
|
nsSVGTextPathFrame::GetX()
|
|
|
|
{
|
2007-12-03 22:51:36 -08:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<nsIDOMSVGLengthList>)
|
|
|
|
nsSVGTextPathFrame::GetY()
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<nsIDOMSVGLengthList>)
|
|
|
|
nsSVGTextPathFrame::GetDx()
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<nsIDOMSVGLengthList>)
|
|
|
|
nsSVGTextPathFrame::GetDy()
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGTextPathFrame methods:
|
|
|
|
|
|
|
|
nsIFrame *
|
2007-07-25 02:16:02 -07:00
|
|
|
nsSVGTextPathFrame::GetPathFrame()
|
|
|
|
{
|
2008-10-11 04:29:35 -07:00
|
|
|
nsSVGTextPathProperty *property =
|
|
|
|
static_cast<nsSVGTextPathProperty*>(GetProperty(nsGkAtoms::href));
|
|
|
|
|
|
|
|
if (!property) {
|
|
|
|
nsSVGTextPathElement *tp = static_cast<nsSVGTextPathElement*>(mContent);
|
2009-01-21 16:56:51 -08:00
|
|
|
nsAutoString href;
|
|
|
|
tp->mStringAttributes[nsSVGTextPathElement::HREF].GetAnimValue(href, tp);
|
2008-10-11 04:29:35 -07:00
|
|
|
if (href.IsEmpty()) {
|
|
|
|
return nsnull; // no URL
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
nsCOMPtr<nsIURI> base = mContent->GetBaseURI();
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), href,
|
|
|
|
mContent->GetCurrentDoc(), base);
|
|
|
|
|
|
|
|
property = nsSVGEffects::GetTextPathProperty(
|
|
|
|
targetURI, this, nsGkAtoms::href);
|
|
|
|
if (!property)
|
|
|
|
return nsnull;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-11 04:29:35 -07:00
|
|
|
nsIFrame *result = property->GetReferencedFrame();
|
|
|
|
if (!result || result->GetType() != nsGkAtoms::svgPathGeometryFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
2008-10-11 04:29:35 -07:00
|
|
|
|
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-16 13:57:09 -07:00
|
|
|
already_AddRefed<gfxFlattenedPath>
|
2007-07-25 02:16:02 -07:00
|
|
|
nsSVGTextPathFrame::GetFlattenedPath()
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame *path = GetPathFrame();
|
2007-12-03 22:51:36 -08:00
|
|
|
return path ? GetFlattenedPath(path) : nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxFlattenedPath>
|
|
|
|
nsSVGTextPathFrame::GetFlattenedPath(nsIFrame *path)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(path, "Unexpected null path");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
nsSVGPathGeometryElement *element =
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(path->GetContent());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
return element->GetFlattenedPath(element->PrependLocalTransformTo(gfxMatrix()));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-12-03 22:51:36 -08:00
|
|
|
gfxFloat
|
|
|
|
nsSVGTextPathFrame::GetStartOffset()
|
|
|
|
{
|
|
|
|
nsSVGTextPathElement *tp = static_cast<nsSVGTextPathElement*>(mContent);
|
|
|
|
nsSVGLength2 *length = &tp->mLengthAttributes[nsSVGTextPathElement::STARTOFFSET];
|
|
|
|
float val = length->GetAnimValInSpecifiedUnits();
|
|
|
|
|
|
|
|
if (val == 0.0f)
|
|
|
|
return 0.0;
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
if (length->IsPercentage()) {
|
2007-12-03 22:51:36 -08:00
|
|
|
nsRefPtr<gfxFlattenedPath> data = GetFlattenedPath();
|
|
|
|
return data ? (val * data->GetLength() / 100.0) : 0.0;
|
|
|
|
} else {
|
|
|
|
return val * GetPathScale();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat
|
|
|
|
nsSVGTextPathFrame::GetPathScale()
|
|
|
|
{
|
|
|
|
nsIFrame *pathFrame = GetPathFrame();
|
|
|
|
if (!pathFrame)
|
|
|
|
return 1.0;
|
|
|
|
|
|
|
|
nsSVGPathElement *path = static_cast<nsSVGPathElement*>(pathFrame->GetContent());
|
|
|
|
float pl = path->mPathLength.GetAnimValue();
|
|
|
|
|
|
|
|
if (pl == 0.0f)
|
|
|
|
return 1.0;
|
|
|
|
|
|
|
|
nsRefPtr<gfxFlattenedPath> data = GetFlattenedPath(pathFrame);
|
|
|
|
return data ? data->GetLength() / pl : 1.0;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextPathFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
aAttribute == nsGkAtoms::startOffset) {
|
2008-04-08 05:51:19 -07:00
|
|
|
NotifyGlyphMetricsChange();
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aNameSpaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
2008-10-11 04:29:35 -07:00
|
|
|
// Blow away our reference, if any
|
|
|
|
DeleteProperty(nsGkAtoms::href);
|
2008-04-08 05:51:19 -07:00
|
|
|
NotifyGlyphMetricsChange();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|