2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Main header first:
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGTextFrame.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
|
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "nsGkAtoms.h"
|
2013-03-26 08:53:13 -07:00
|
|
|
#include "mozilla/dom/SVGIRect.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsISVGGlyphFragmentNode.h"
|
2013-04-25 02:18:42 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2011-05-07 10:08:41 -07:00
|
|
|
#include "nsSVGGlyphFrame.h"
|
2012-06-30 04:20:46 -07:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGTextPathFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGUtils.h"
|
2013-01-02 22:17:03 -08:00
|
|
|
#include "SVGGraphicsElement.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "SVGLengthList.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2009-01-19 10:31:34 -08:00
|
|
|
nsSVGTextFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2013-01-07 19:22:41 -08:00
|
|
|
NS_ASSERTION(aContent->IsSVG(nsGkAtoms::text),
|
|
|
|
"Content is not an SVG text");
|
2009-01-19 10:31:34 -08:00
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
nsSVGTextFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2009-01-19 10:31:34 -08:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGTextFrame::AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aNameSpaceID != kNameSpaceID_None)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::transform) {
|
2013-05-23 00:04:21 -07:00
|
|
|
// We don't invalidate for transform changes (the layers code does that).
|
|
|
|
// Also note that SVGTransformableElement::GetAttributeChangeHint will
|
|
|
|
// return nsChangeHint_UpdateOverflow for "transform" attribute changes
|
|
|
|
// and cause DoApplyRenderingChangeToTree to make the SchedulePaint call.
|
2012-01-28 05:58:17 -08:00
|
|
|
NotifySVGChanged(TRANSFORM_CHANGED);
|
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) {
|
2013-04-25 02:18:42 -07:00
|
|
|
nsSVGEffects::InvalidateRenderingObservers(this);
|
2012-11-28 01:42:13 -08:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
NotifyGlyphMetricsChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGTextFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgTextFrame;
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2012-07-20 11:12:29 -07:00
|
|
|
nsSVGTextFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
UpdateGlyphPositioning(true);
|
2013-02-14 03:12:27 -08:00
|
|
|
nsSVGTextFrameBase::BuildDisplayList(aBuilder, aDirtyRect, aLists);
|
2012-07-20 11:12:29 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
2009-05-29 03:15:40 -07:00
|
|
|
// nsSVGTextContainerFrame
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2009-05-29 03:15:40 -07:00
|
|
|
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
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGTextFrame::GetSubStringLength(uint32_t charnum, uint32_t nchars)
|
2009-05-29 03:15:40 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(false);
|
2009-05-29 03:15:40 -07:00
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetSubStringLength(charnum, nchars);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2013-01-06 06:14:43 -08:00
|
|
|
nsSVGTextFrame::GetCharNumAtPosition(nsISVGPoint *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
|
2012-12-22 20:54:25 -08:00
|
|
|
nsSVGTextFrame::GetStartPositionOfChar(uint32_t charnum, nsISupports **_retval)
|
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
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetStartPositionOfChar(charnum, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-22 20:54:25 -08:00
|
|
|
nsSVGTextFrame::GetEndPositionOfChar(uint32_t charnum, nsISupports **_retval)
|
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
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetEndPositionOfChar(charnum, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-03-26 08:53:13 -07:00
|
|
|
nsSVGTextFrame::GetExtentOfChar(uint32_t charnum, dom::SVGIRect **_retval)
|
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
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetExtentOfChar(charnum, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGTextFrame::GetRotationOfChar(uint32_t charnum, float *_retval)
|
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
|
|
|
|
|
|
|
return nsSVGTextFrameBase::GetRotationOfChar(charnum, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGTextFrame::NotifySVGChanged(uint32_t aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-11 08:53:36 -07:00
|
|
|
NS_ABORT_IF_FALSE(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED),
|
|
|
|
"Invalidation logic may need adjusting");
|
|
|
|
|
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
|
2012-07-30 07:20:58 -07:00
|
|
|
mCanvasTM = nullptr;
|
2008-01-25 01:27:03 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-23 09:36:46 -07:00
|
|
|
if (updateGlyphMetrics) {
|
|
|
|
// Ancestor changes can't affect how we render from the perspective of
|
|
|
|
// any rendering observers that we may have, so we don't need to
|
|
|
|
// invalidate them. We also don't need to invalidate ourself, since our
|
|
|
|
// changed ancestor will have invalidated its entire area, which includes
|
|
|
|
// our area.
|
|
|
|
// For perf reasons we call this before calling NotifySVGChanged() below.
|
2012-07-21 17:01:44 -07:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-06-23 09:36:46 -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
|
|
|
}
|
|
|
|
|
2008-03-18 12:50:29 -07:00
|
|
|
NS_IMETHODIMP
|
2012-03-02 00:28:59 -08:00
|
|
|
nsSVGTextFrame::PaintSVG(nsRenderingContext* aContext,
|
2013-09-11 00:27:45 -07:00
|
|
|
const nsIntRect *aDirtyRect,
|
|
|
|
nsIFrame* aTransformRoot)
|
2008-03-18 12:50:29 -07:00
|
|
|
{
|
2012-07-20 11:12:29 -07:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
|
2013-07-12 00:13:07 -07:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY),
|
2012-07-20 11:12:29 -07:00
|
|
|
"If display lists are enabled, only painting of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(true);
|
2008-03-18 12:50:29 -07:00
|
|
|
|
2013-09-11 00:27:45 -07:00
|
|
|
return nsSVGTextFrameBase::PaintSVG(aContext, aDirtyRect, aTransformRoot);
|
2008-03-18 12:50:29 -07:00
|
|
|
}
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
NS_IMETHODIMP_(nsIFrame*)
|
|
|
|
nsSVGTextFrame::GetFrameForPoint(const nsPoint &aPoint)
|
2008-03-18 12:50:29 -07:00
|
|
|
{
|
2012-07-20 11:12:29 -07:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListHitTestingEnabled() ||
|
2013-07-12 00:13:07 -07:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY),
|
2012-07-20 11:12:29 -07:00
|
|
|
"If display lists are enabled, only hit-testing of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
void
|
2012-07-21 17:01:44 -07:00
|
|
|
nsSVGTextFrame::ReflowSVG()
|
2008-03-18 12:50:29 -07:00
|
|
|
{
|
2012-07-21 17:01:44 -07:00
|
|
|
NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingReflowSVG(this),
|
|
|
|
"This call is probably a wasteful mistake");
|
2008-03-18 12:50:29 -07:00
|
|
|
|
2013-07-12 00:13:07 -07:00
|
|
|
NS_ABORT_IF_FALSE(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
2012-07-21 17:01:44 -07:00
|
|
|
"ReflowSVG mechanism not designed for this");
|
2012-03-20 05:15:53 -07:00
|
|
|
|
2012-07-21 17:01:44 -07:00
|
|
|
if (!nsSVGUtils::NeedsReflowSVG(this)) {
|
2013-06-24 04:20:38 -07:00
|
|
|
NS_ASSERTION(!(mState & NS_STATE_SVG_POSITIONING_DIRTY), "How did this happen?");
|
2012-03-20 05:15:53 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-24 04:20:38 -07:00
|
|
|
// UpdateGlyphPositioning may have been called under DOM calls and cleared
|
|
|
|
// NS_STATE_SVG_POSITIONING_DIRTY. We may now have better positioning, though, so
|
2012-03-20 05:15:53 -07:00
|
|
|
// set it to true so that UpdateGlyphPositioning will do its work.
|
2013-06-24 04:20:38 -07:00
|
|
|
AddStateBits(NS_STATE_SVG_POSITIONING_DIRTY);
|
2012-03-20 05:15:53 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateGlyphPositioning(false);
|
2008-07-30 12:28:12 -07:00
|
|
|
|
2012-11-06 09:00:11 -08:00
|
|
|
// We leave it up to nsSVGTextFrameBase::ReflowSVG to invalidate. XXXSDL
|
2012-03-20 05:15:53 -07:00
|
|
|
// With glyph positions updated, our descendants can invalidate their new
|
|
|
|
// areas correctly:
|
2012-07-21 17:01:44 -07:00
|
|
|
nsSVGTextFrameBase::ReflowSVG();
|
2012-03-20 05:15:53 -07:00
|
|
|
}
|
2008-07-30 12:28:12 -07:00
|
|
|
|
2012-04-16 01:23:48 -07:00
|
|
|
SVGBBox
|
2011-09-30 02:25:37 -07:00
|
|
|
nsSVGTextFrame::GetBBoxContribution(const gfxMatrix &aToBBoxUserspace,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t 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
|
2013-09-11 00:27:45 -07:00
|
|
|
nsSVGTextFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-09-11 00:27:45 -07:00
|
|
|
if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) {
|
2012-06-30 04:20:46 -07:00
|
|
|
if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
|
|
|
|
(aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
|
|
|
|
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mCanvasTM) {
|
|
|
|
NS_ASSERTION(mParent, "null parent");
|
2009-04-28 21:31:34 -07:00
|
|
|
|
|
|
|
nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent);
|
2013-01-02 22:17:03 -08:00
|
|
|
dom::SVGGraphicsElement *content = static_cast<dom::SVGGraphicsElement*>(mContent);
|
2009-04-28 21:31:34 -07:00
|
|
|
|
2013-09-11 00:27:45 -07:00
|
|
|
gfxMatrix tm = content->PrependLocalTransformsTo(
|
|
|
|
this == aTransformRoot ? gfxMatrix() :
|
|
|
|
parent->GetCanvasTM(aFor, aTransformRoot));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
|
2012-06-23 09:36:46 -07:00
|
|
|
static void
|
|
|
|
MarkDirtyBitsOnDescendants(nsIFrame *aFrame)
|
|
|
|
{
|
2012-06-24 10:02:23 -07:00
|
|
|
// Do not skip marking of aFrame or any of its descendants if they have
|
|
|
|
// the NS_FRAME_IS_DIRTY set, because some of their descendants may not
|
|
|
|
// have it set, and we need all descendants to be dirty.
|
|
|
|
if (aFrame->GetStateBits() & (NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
// Nothing to do if our outer-<svg> hasn't yet had its initial reflow.
|
2012-06-23 09:36:46 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsIFrame* kid = aFrame->GetFirstPrincipalChild();
|
|
|
|
while (kid) {
|
|
|
|
nsISVGChildFrame* svgkid = do_QueryFrame(kid);
|
2012-06-24 10:02:23 -07:00
|
|
|
if (svgkid) {
|
2012-06-23 09:36:46 -07:00
|
|
|
MarkDirtyBitsOnDescendants(kid);
|
|
|
|
kid->AddStateBits(NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsSVGTextFrame::NotifyGlyphMetricsChange()
|
|
|
|
{
|
2012-06-23 09:36:46 -07:00
|
|
|
// NotifySVGChanged isn't appropriate here, so we just mark our descendants
|
2012-07-21 17:01:44 -07:00
|
|
|
// as fully dirty to get ReflowSVG() called on them:
|
2012-06-23 09:36:46 -07:00
|
|
|
MarkDirtyBitsOnDescendants(this);
|
|
|
|
|
2013-04-25 02:18:42 -07:00
|
|
|
nsSVGEffects::InvalidateRenderingObservers(this);
|
2012-11-28 01:42:13 -08:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-03-20 05:15:53 -07:00
|
|
|
|
2013-06-24 04:20:38 -07:00
|
|
|
AddStateBits(NS_STATE_SVG_POSITIONING_DIRTY);
|
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
|
|
|
{
|
2013-06-24 04:20:38 -07:00
|
|
|
if (!(mState & NS_STATE_SVG_POSITIONING_DIRTY))
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
2013-06-24 04:20:38 -07:00
|
|
|
RemoveStateBits(NS_STATE_SVG_POSITIONING_DIRTY);
|
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:
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t 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
|
2013-02-16 13:51:02 -08:00
|
|
|
if (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
|
2011-01-04 00:52:17 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|