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 "nsSVGTextFrame.h"
|
|
|
|
#include "nsIDOMSVGTextPathElement.h"
|
|
|
|
#include "nsIDOMSVGAnimatedLength.h"
|
|
|
|
#include "nsSVGLength.h"
|
|
|
|
#include "nsIDOMSVGURIReference.h"
|
|
|
|
#include "nsSVGUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIDOMSVGAnimatedPathData.h"
|
|
|
|
#include "nsSVGPathElement.h"
|
2007-12-03 22:51:36 -08:00
|
|
|
#include "nsSVGTextPathElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-26 08:46:29 -07:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsSVGPathListener, nsIMutationObserver)
|
|
|
|
|
|
|
|
nsSVGPathListener::nsSVGPathListener(nsIContent *aPathElement,
|
|
|
|
nsSVGTextPathFrame *aTextPathFrame) :
|
|
|
|
mTextPathFrame(aTextPathFrame)
|
|
|
|
{
|
|
|
|
mObservedPath = do_GetWeakReference(aPathElement);
|
|
|
|
aPathElement->AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGPathListener::~nsSVGPathListener()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> path = do_QueryReferent(mObservedPath);
|
|
|
|
if (path)
|
|
|
|
path->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGPathListener::AttributeChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent *aContent,
|
|
|
|
PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom *aAttribute,
|
2007-07-12 13:05:45 -07:00
|
|
|
PRInt32 aModType,
|
|
|
|
PRUint32 aStateMask)
|
2007-04-26 08:46:29 -07:00
|
|
|
{
|
2008-04-08 05:51:19 -07:00
|
|
|
mTextPathFrame->NotifyGlyphMetricsChange();
|
2007-04-26 08:46:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewSVGTextPathFrame(nsIPresShell* aPresShell, nsIContent* aContent,
|
|
|
|
nsIFrame* parentFrame, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(parentFrame, "null parent");
|
|
|
|
if (parentFrame->GetType() != nsGkAtoms::svgTextFrame) {
|
|
|
|
NS_ERROR("trying to construct an SVGTextPathFrame for an invalid container");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2007-07-25 02:16:02 -07:00
|
|
|
nsCOMPtr<nsIDOMSVGTextPathElement> textPath = do_QueryInterface(aContent);
|
|
|
|
if (!textPath) {
|
|
|
|
NS_ERROR("Can't create frame! Content is not an SVG textPath");
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new (aPresShell) nsSVGTextPathFrame(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextPathFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsSVGTextPathFrameBase::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMSVGURIReference> aRef = do_QueryInterface(mContent);
|
|
|
|
if (aRef)
|
|
|
|
aRef->GetHref(getter_AddRefs(mHref));
|
|
|
|
if (!mHref)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame *path = nsnull;
|
|
|
|
|
|
|
|
nsAutoString str;
|
|
|
|
mHref->GetAnimVal(str);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
nsCOMPtr<nsIURI> base = mContent->GetBaseURI();
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), str,
|
|
|
|
mContent->GetCurrentDoc(), base);
|
|
|
|
|
|
|
|
nsSVGUtils::GetReferencedFrame(&path, targetURI, mContent,
|
2007-03-30 14:11:41 -07:00
|
|
|
PresContext()->PresShell());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!path || (path->GetType() != nsGkAtoms::svgPathGeometryFrame))
|
|
|
|
return nsnull;
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
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-07-08 00:08:04 -07:00
|
|
|
nsSVGPathGeometryElement *element = static_cast<nsSVGPathGeometryElement*>
|
|
|
|
(path->GetContent());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-26 08:46:29 -07:00
|
|
|
if (!mPathListener) {
|
|
|
|
mPathListener = new nsSVGPathListener(path->GetContent(), this);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-26 08:46:29 -07:00
|
|
|
nsCOMPtr<nsIDOMSVGMatrix> localTM = element->GetLocalTransformMatrix();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-26 08:46:29 -07:00
|
|
|
return element->GetFlattenedPath(localTM);
|
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) {
|
2007-04-26 08:46:29 -07:00
|
|
|
mPathListener = nsnull;
|
2008-04-08 05:51:19 -07:00
|
|
|
NotifyGlyphMetricsChange();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|