Closed Bug 388547 Opened 13 years ago Closed 10 years ago

Enhancement to support x,y,dx,dy lists on SVG text and tspan elements to achieve correct character positioning.

Categories

(Core :: SVG, enhancement)

enhancement
Not set

Tracking

()

RESOLVED FIXED

People

(Reporter: mike, Assigned: longsonr)

References

()

Details

(Keywords: dev-doc-complete)

Attachments

(6 files, 15 obsolete files)

300 bytes, image/svg+xml
Details
1.67 KB, image/png
Details
5.22 KB, image/svg+xml
Details
125.16 KB, image/jpeg
Details
148.29 KB, image/png
Details
35.52 KB, patch
Details | Diff | Splinter Review
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0

SVG text and tspan elements in FF 2.0 support only an initial XY position.
The enhancement adds support for x,y,dx,dy lists on text and tspan elements, so that each character may be individually positioned.

Reproducible: Always

Steps to Reproduce:
1.  View the example http://www.svgmaker.com/gallery/charpos.svg with FF 2.0. 

Actual Results:  
The first character is positioned at the initial XY.  Subsequent characters are positioned using the default character advance.

Expected Results:  
The first character should be positioned at the initial XY.  Subsequent characters should be positioned using the XY values specified in the X and Y attributes of the tpans.
patch was implemented by Ken Stacey (ken@svgmaker.com)
Status: UNCONFIRMED → NEW
Component: General → SVG
Ever confirmed: true
Product: Firefox → Core
QA Contact: general → general
Version: unspecified → Trunk
This is a duplicate of bug 311986.

If you are looking for reviews you need to select a reviewer.

Comment on attachment 272746 [details] [diff] [review]
Enhancement that implements x.y.dx.dy lists for SVG tspan and text elements

One general comment.

I think it would be better all round if you tried to adapt the existing character placement mechanism used for textPath elements rather than having two separate implementations. i.e. use nsSVGCharacterPosition and make GetCharacterPosition return  character positions if you have multiple y values. You may need to consider extending this so that you can have multiple characters with a single position for the first one so that you can write a string abcde with positions "x y" as character a at position x and then bcde in one go at position y.

>Index: layout/svg/base/src/nsISVGGlyphFragmentLeaf.h
>===================================================================
...
>-  NS_IMETHOD_(void) SetGlyphPosition(float x, float y)=0;
>+  NS_IMETHOD_(void) SetGlyphPosition(float x, float y, PRUint16 baseline)=0;
>+  NS_IMETHOD_(void) GetNextGlyphPosition(float *x, float *y)=0;

If you change an interface you must update its ID i.e.
// {2C466AED-CF7B-4479-A807-98151215A645}
#define NS_ISVGGLYPHFRAGMENTLEAF_IID \
{ 0x2c466aed, 0xcf7b, 0x4479, { 0xa8, 0x7, 0x98, 0x15, 0x12, 0x15, 0xa6, 0x45 } }

> nsSVGGlyphFrame::nsSVGGlyphFrame(nsStyleContext* aContext)
>     : nsSVGGlyphFrameBase(aContext),
>       mWhitespaceHandling(COMPRESS_WHITESPACE)
> {
>+  mDoCharPlacement = PR_FALSE;
>+  mStrLength = 0;

Initialise member variables in the initialiser bit rather than the constructor body c.f. mWhitespaceHandling above. However see below.

>Index: layout/svg/base/src/nsSVGGlyphFrame.h
>===================================================================
>RCS file: /cvsroot/mozilla/layout/svg/base/src/nsSVGGlyphFrame.h,v
>retrieving revision 1.25
>diff -u -8 -p -r1.25 nsSVGGlyphFrame.h
>--- layout/svg/base/src/nsSVGGlyphFrame.h	4 Jul 2007 03:39:03 -0000	1.25
>+++ layout/svg/base/src/nsSVGGlyphFrame.h	18 Jul 2007 04:32:36 -0000
>@@ -114,29 +114,30 @@ public:
>   nsRefPtr<gfxFontGroup> mFontGroup;
>   nsAutoPtr<gfxFontStyle> mFontStyle;
>   gfxPoint mPosition;
>   PRUint8 mWhitespaceHandling;
>+  nsAutoArrayPtr<nsSVGBaselinePosition> mBaselinePositions;
>+  PRBool mDoCharPlacement;       // do per character placement

This bloats the class size. Reuse the textPath mechanism and calculate this when you need it.

Also don't use PRBool as a class member, use PRPackedBool.

And finally order any member variables in sizeof order to ensure minimal sizeof of the class as a whole.

>+  gfxPoint mNextGlyphPosition;
>+  float mBaselineOffset;
>+  PRUint32 mStrLength;

mStrLength just bloats the class size. 

How many of these new members are absolutely mandatory? Most text will not have multiple x and y positions so we don't want to pay for that all the time. Neither do we want to store anything we can easily calculate.
Reworked after Robert Longson's comments of 2007-07-18 02:21:56 PDT
Attachment #272746 - Attachment is obsolete: true
A few comments:

  * you have some unchecked memory allocations that should be handled.

  * there a few unprotected printfs - wrap with DEBUG_* or remove.

  * since you're treating startOffset differently, nsSVGTextPathFrame::Init
    can be modified to remove the startOffset chunk and just request it from
    the content in GetStartOffset iff that attribute is set.

  * looks like GetStartOffset could use GetPathScale.

  * maybe modify the signature of SetGlyphPosition to take a gfxPoint&
    instead of moving data in and out of that structure?

Could you update your tree to the trunk head before you submit your next patch please? The constructor for nsSVGGlyphFrame is now inline in nsSVGGlyphFrame.h for instance.
(In reply to comment #6)

>   * you have some unchecked memory allocations that should be handled.

Not sure what you mean.  Which allocations ?

>   * there a few unprotected printfs - wrap with DEBUG_* or remove.

Thanks, I thought I got all of them.

>   * since you're treating startOffset differently, nsSVGTextPathFrame::Init
>     can be modified to remove the startOffset chunk and just request it from
>     the content in GetStartOffset iff that attribute is set.

ok.

>   * looks like GetStartOffset could use GetPathScale.

GetStartOffset does scale the value if needed.

>   * maybe modify the signature of SetGlyphPosition to take a gfxPoint&
>     instead of moving data in and out of that structure?

ok.  But will have to move (float) x,y in and out of a gfxPoint in an outer loop of nsSVGTextFrame::UpdateGlyphPositioning().  Because nsIDOMSVGLength::GetValue gets a float.
(In reply to comment #7)

Thanks Robert.

I can generate a new patch.  But I can't test now because the build fails in a macro in extensions/spellcheck/hunspell/src/atypes.hxx  #$@%!!

Is this a common problem: update the source tree and then have the build fail ?
Is there a "safe" source I should update from ?
That's minefield for you. You are suffering from bug 391147. I'll post a patch for that later today unless someone else beats me to it.
(In reply to comment #8)

> Not sure what you mean.  Which allocations ?

+  mCharPositions = new gfxPoint[strLength];

for instance

Attached image testcase
Duplicate of this bug: 311986
(In reply to comment #11)
> +  mCharPositions = new gfxPoint[strLength];
> 
> for instance

ok.

So, this one should be checked too ?

  nsSVGCharacterPosition *cp = new nsSVGCharacterPosition[strLength];

It is unchecked in latest source (nsSVGGlyphFrame::GetCharacterPosition)
I was creating some textPath test cases and ran across this strange problem.  Using a current build, the startOffset should be 50% but ends up 0. If you remove the title element from the document, then it works ok.

This file works as expected with Firefox 2.0.0.6 with or without the title.

The extent to which I tracked it was
nsSVGTextPathFrame::GetFlattenedPath()
  nsSVGTextPathFrame::GetPathFrame()
    nsSVGUtils::GetReferencedFrame()
      *aRefFrame = aPresShell->GetPrimaryFrameFor(content); - fails

?
Updated patch addressing recent comments
screen capture of layout example (id=276089) using patch (id=276088)
Comment on attachment 276088 [details] [diff] [review]
Enhancement that implements x.y.dx.dy lists for SVG tspan and text elements

General points:

If you are working with gfxFloat then literal assignment should not use f as gfxFloat is a double. If you are working with float then you should use an f suffix on literals.

Does inheritance of tspan values work? Have you tested that? Something like this contrived example...

<text x="1 2 3 4 5" y="4 5 6 7">h<tspan dx="5 6">e<tspan>l</tspan>lo</tspan></text> 

The first l in hello has no dx in its tspan so it should pick up the parent tspan dx, presumably the 6.

Neither of the tspans have x or y values so they should pick up the text values where they exist.

>+float
>+nsSVGGlyphFrame::GetSubStringAdvance(PRUint32 charnum, PRUint32 fragmentChars)
>+{

>+  if (fragmentChars == 0) // do the whole run
>+    fragmentChars = text.Length();

Fix the caller to pass in the right value rather than having a magic number.

>+    for (PRUint32 i = charnum; i < dxcount; i++) {
>+      float dx = 0.0;

0.0f

>+void
>+nsSVGGlyphFrame::SetCharPosition(gfxTextRun *textRun,
>+                                 gfxPoint &ctp)
>+{

>+  gfxFloat pathScale = 1.0f;  //only applied to dx,dy lists since x,y lists nsnull for nsSVGTextPathFrame

Put the comment on the previous line to avoid a long line.

>+          x -= advance/2.0f;

2.0

> NS_IMETHODIMP
> nsSVGGlyphFrame::GetStartPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
> {

>+    if (angle != 0.0f) {

0.0

> NS_IMETHODIMP
> nsSVGGlyphFrame::GetEndPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
>@@ -834,23 +1013,30 @@ nsSVGGlyphFrame::GetEndPositionOfChar(PR
>     return NS_ERROR_OUT_OF_MEMORY;
> 
>+    gfxFloat angle = cp[charnum].angle;
>+    if (angle != 0.0f) {

0.0

>Index: layout/svg/base/src/nsSVGGlyphFrame.h
>===================================================================
>RCS file: /cvsroot/mozilla/layout/svg/base/src/nsSVGGlyphFrame.h,v
>retrieving revision 1.26
>diff -u -8 -p -r1.26 nsSVGGlyphFrame.h
>--- layout/svg/base/src/nsSVGGlyphFrame.h	3 Aug 2007 08:39:13 -0000	1.26
>+++ layout/svg/base/src/nsSVGGlyphFrame.h	10 Aug 2007 06:01:19 -0000

>-  gfxPoint mPosition;
>+  gfxPoint mPosition;    // character position of first glyph, includes baseline offset
>+  nsAutoArrayPtr<gfxPoint> mCharPositions;  // character position of each glyph, 
>+                                            // valid if not a simple textrun and/or textPath

Put the comments above the variables so we don't have long lines.

How about storing mCharPositions in a property. It would not be a member variable here then so the memory used by nsSVGGlyphFrame would be that bit smaller in most cases.

You would have 

gfxPoint * charPositions = new gfxPoint[strLength];
SetProperty(nsGkAtoms::d, charPositions, positionDtorFunc);

positionDtorFunc would delete[] the charPositions data.

I picked d as there is no xy atom and d goes with paths.

Then if you needed individual character positions you could call

      charPositions = static_cast<gfxPoint *>
                            (GetProperty(nsGkAtoms::d));

There are various examples of Set/GetProperty: nsBlockFrame shows some usage as does nsSVGUtils (although that uses pointers to classes rather than pointers to POD). Note that when the frame is destroyed the Property goes with it and the positionDtorFunction is automatically called.

>+  float mBaselineOffset;
>   PRUint8 mWhitespaceHandling;
> };
> 
> #endif
>Index: layout/svg/base/src/nsSVGTextFrame.cpp
>===================================================================
>RCS file: /cvsroot/mozilla/layout/svg/base/src/nsSVGTextFrame.cpp,v
>retrieving revision 1.61
>diff -u -8 -p -r1.61 nsSVGTextFrame.cpp
>--- layout/svg/base/src/nsSVGTextFrame.cpp	3 Aug 2007 08:39:13 -0000	1.61
>+++ layout/svg/base/src/nsSVGTextFrame.cpp	10 Aug 2007 06:01:19 -0000
>@@ -293,71 +293,29 @@ nsSVGTextFrame::GetCanvasTM()
 
> void
> nsSVGTextFrame::UpdateGlyphPositioning()
> {

>-  float x = 0, y = 0;
>+  gfxPoint ctp(0.0,0.0);

add a space after the comma.

> 
>===================================================================
>RCS file: /cvsroot/mozilla/layout/svg/base/src/nsSVGTextPathFrame.cpp,v
>retrieving revision 1.31
>diff -u -8 -p -r1.31 nsSVGTextPathFrame.cpp
>--- layout/svg/base/src/nsSVGTextPathFrame.cpp	25 Jul 2007 09:16:02 -0000	1.31
>+++ layout/svg/base/src/nsSVGTextPathFrame.cpp	10 Aug 2007 06:01:19 -0000

> already_AddRefed<gfxFlattenedPath>
>-nsSVGTextPathFrame::GetFlattenedPath()
>+nsSVGTextPathFrame::GetFlattenedPath(nsIFrame *path)

Better to have an private function that takes a path and another public function that does not. The public function calls GetPathFrame() and then calls the private function.

>+float
>+nsSVGTextPathFrame::GetStartOffset() {

>+        startOffset = val * data->GetLength() / 100.0f;

just return val * data->GetLength() / 100.0f;

>+      }  // else startOffset remains 0
>+    } else {
>+      startOffset = val * GetPathScale();

return val * GetPathScale();

>+    }
>+  }
>+  return startOffset;

return 0.0f;

>+float
>+nsSVGTextPathFrame::GetPathScale() 
>+{
>+  float scale = 1.0f;
>+  nsIFrame *pathFrame = GetPathFrame();
>+  if (pathFrame && pathFrame->GetContent()->HasAttr(kNameSpaceID_None, 
>+                                               nsGkAtoms::pathLength)) {

You really need some early returns in this function rather than all this indenting. E.g.

  if (!pathFrame || !pathFrame->GetContent()...)
    return 1.0f;

>+    nsCOMPtr<nsIDOMSVGPathElement> pathElement = 
>+                    do_QueryInterface(pathFrame->GetContent());
>+    if (pathElement) {

  if (!pathElement)
    return 1.0f;

etc. And just return the result if you calculate something non-zero.
(In reply to comment #20)
> >-  gfxPoint mPosition;
> >+  gfxPoint mPosition;    // character position of first glyph, includes baseline offset
> >+  nsAutoArrayPtr<gfxPoint> mCharPositions;  // character position of each glyph, 
> >+                                            // valid if not a simple textrun and/or textPath
> 

Even better than a property would be not storing the values at all and simply calculating them on the fly. All you really need is the starting point of the first glyph (mPosition) as that may depend on where the previous frame left you and so would be O(N2). Everything else you should be able to calculate using GetParent where necessary. If we find it is unacceptably slow we can always add caching of the positions in later.

This article explains where we were and what we're trying to avoid :-)
http://weblogs.mozillazine.org/roc/archives/2006/02/anatomy_of_bloat.html 

I think it should be possible to get rid of everything except the mPosition member variable (although getting rid of the whitespacehandling member belongs in another bug).
(In reply to comment #20)

Thanks for the comments Robert.

> Does inheritance of tspan values work? Have you tested that? Something like
> this contrived example...
> 
> <text x="1 2 3 4 5" y="4 5 6 7">h<tspan dx="5
> 6">e<tspan>l</tspan>lo</tspan></text> 

Inherited positioning values still don't work.  I wanted to support "simple" or direct lists first then address the implications of inheritance with another bug.

As I see it, the inheritance needs to be done in nsSVGTextFrame::UpdateGlyphPositioning.  The looping of glyph framgments needs to change to traverse the text nodes (like in your comment https://bugzilla.mozilla.org/show_bug.cgi?id=333698#c18) and pass the appropriate (sub)sections of lists to nsSVGGlyphFrame::SetGlyphPosition().
(In reply to comment #21)

> Even better than a property would be not storing the values at all and simply
> calculating them on the fly. All you really need is the starting point of the
> first glyph (mPosition) as that may depend on where the previous frame left you
> and so would be O(N2). Everything else you should be able to calculate using
> GetParent where necessary. If we find it is unacceptably slow we can always add
> caching of the positions in later.

The code is already slow.

mPosition only stores the first glyph position.  No problem if everything is a
simple text run and no inherited x,y,dx,dy lists.

To support your contrived example in Comment #20, 

> <text x="1 2 3 4 5" y="4 5 6 7">h<tspan dx="5
> 6">e<tspan>l</tspan>lo</tspan></text> 

even having mPosition for each fragment, you still have to determine if layout
calculations are required.  That means going out to the current text element,
checking for inherited lists and then re-layout (calculate) each GlyphFragment
until you get back to the one you want the positioning for.  In the example
above, determining the position of 'o' requires this action.

There would be a significant performance hit for painting the contents of a
text element using nsSVGGlyphFrame::PaintSVG().  For each successive glyph
fragment in a text element you would have to go back and check/recalculate all
the previous fragments.  Resizing the browser window with a lot of text in the
document will become slower than it is.  I can't see how SMIL animation of text
could ever be acceptable.

> This article explains where we were and what we're trying to avoid :-)
> http://weblogs.mozillazine.org/roc/archives/2006/02/anatomy_of_bloat.html 

The article seems to point the finger mostly at XPCOM objects.

> 
> I think it should be possible to get rid of everything except the mPosition
> member variable (although getting rid of the whitespacehandling member belongs
> in another bug).
> 

Why even keep mPosition? or do UpdateGlyphPositioning() at all?  or have
mPositioningDirty ?  Just recalculate everything on demand.

Seriously, it would be helpful to understand how decisions are made regarding
bloat vs performance.  Are there general guidelines I can use or is it hit or
miss at every patch?
(In reply to comment #23)

> even having mPosition for each fragment, you still have to determine if layout
> calculations are required.  That means going out to the current text element,
> checking for inherited lists and then re-layout (calculate) each GlyphFragment
> until you get back to the one you want the positioning for.  In the example
> above, determining the position of 'o' requires this action.
> 
> There would be a significant performance hit for painting the contents of a
> text element using nsSVGGlyphFrame::PaintSVG().  For each successive glyph
> fragment in a text element you would have to go back and check/recalculate all
> the previous fragments.  Resizing the browser window with a lot of text in the
> document will become slower than it is.  I can't see how SMIL animation of text
> could ever be acceptable.

It's performance vs memory. We can always put in caching afterwards.

> The article seems to point the finger mostly at XPCOM objects.

But also partly at frames storing things that content has.

> 
> Why even keep mPosition? or do UpdateGlyphPositioning() at all?  or have
> mPositioningDirty ?  Just recalculate everything on demand.

Because you can only calculate mPosition if you know where the previous fragment ended and as frames are connected via a singly linked list there is no GetPreviousFrame function. All you could do is call GetParent then iterate through its children which would be order N^2.

> 
> Seriously, it would be helpful to understand how decisions are made regarding
> bloat vs performance.  Are there general guidelines I can use or is it hit or
> miss at every patch?
> 

What I've picked over the patches I've submitted and review comments I've received is this...

Go for lack of bloat first and then add performance later if necessary in a separate patch. Order N performance is acceptable, order N^2 generally not. 

It's easier to have a discussion on speeding up performance of a feature once that feature exists rather than as that feature is being developed.

In the FX3 timeframe we've removed most of the caching that happened in glyph frames. We used to cache all the characters for instance after we'd whitespace compressed them.

One additional argument is that when Tor implemented textPath, he didn't cache the glyph positions and he's in charge ;-)

You've chosen something that is quite complicated for a first patch. I'm glad you are persevering.

Best regards

Robert
See also bug 282579 comment 9 which suggested caching positions for textPath and Tor's reply bug 282579 comment 10
My general feeling is to go for the simplest implementation first, and revisit if needed for performance or footprint reasons.  At least to my interpretation, "simplest" should be within reason - avoiding gratuitous performance bottlenecks or data bloat.

A pointer for storing an array which is only allocated when needed (multiple x/y/dx/dy) seems under this threshold and could go in if it simplifies the code, which from Ken's description it seems to do.  Individual character positions would seem to be the exceptional case for most SVG content, so it storing cached values won't affect most users.
Ken, can you fix the other issues in comment 20 i.e. those other than inheritance support and caching removal? Then set the review flag on the attachment for me as a reviewer.

Please raise another mozilla bug for inheritance of x, y, dx, dy so we can track that we still need to do that.
(In reply to comment #27)

Robert,

Fixed all the other issues and removed mBaselineOffset from nsSVGGlyphFrame and calculate it on demand.  This has a side effect of fixing a bug relating to dominant-baseline.

<text dominant-baseline="alphabetic">
 <tspan>alphabetic</tspan>
 <tspan dominant-baseline="hanging">hanging</tspan>
</text>

the old code ignores the nested (hanging) baseline.
Attachment #276088 - Attachment is obsolete: true
Attachment #277664 - Flags: review+
Ken, you need to select ? from the review dropdown and put my email address in as the requestee.

There is good information here http://wiki.mozilla.org/Bugzilla:Review

Once you get a review + you would repeat the process for super-review, for which I would suggest you chose Tor.

Best regards

Robert
Comment on attachment 277664 [details] [diff] [review]
x.y.dx.dy lists for SVG tspan and text elements

>+static void
>+GetListValue(nsIDOMSVGLengthList *list, PRUint32 ival, gfxFloat *val)

Make this return the value you want rather than taking a gfxFloat *val argument. It will make the calling code simpler.

> static void
>-GetSingleValue(nsISVGGlyphFragmentLeaf *fragment,
>-               nsIDOMSVGLengthList *list, float *val)
>+GetSingleValue(nsIDOMSVGLengthList *list, gfxFloat *val)

Again I think it would be simpler just to return the result you want rather than passing a pointer argument, even though that's what the current code does ;-)

> already_AddRefed<gfxFlattenedPath>
> nsSVGTextPathFrame::GetFlattenedPath()
> {
>-  nsIFrame *path = GetPathFrame();
>-  if (!path)
>-    return nsnull;
>+  return GetFlattenedPath(nsnull);

I think this should be implemented as:

  nsIFrame *path = path = GetPathFrame();
  if (!path)
    return nsnull;
  return GetFlattenedPath(path);

>+}
>+
>+already_AddRefed<gfxFlattenedPath>
>+nsSVGTextPathFrame::GetFlattenedPath(nsIFrame *path)
>+{
>+  if (!path) {
>+    path = GetPathFrame();
>+    if (!path)
>+      return nsnull;
>+  }

This change is then not necessary and can be removed.

>+gfxFloat
>+nsSVGTextPathFrame::GetStartOffset() {

Nit: Could you put the { on a new line please?
(In reply to comment #29)

Thanks, Robert.  Wasn't sure what to do there.
(In reply to comment #30)
> (From update of attachment 277664 [details] [diff] [review])
> >+static void
> >+GetListValue(nsIDOMSVGLengthList *list, PRUint32 ival, gfxFloat *val)
> 
> Make this return the value you want rather than taking a gfxFloat *val
> argument. It will make the calling code simpler.
> 

Should be ok since the calling code checks the list length (as a shortcut) before calling the function.

> > static void
> >-GetSingleValue(nsISVGGlyphFragmentLeaf *fragment,
> >-               nsIDOMSVGLengthList *list, float *val)
> >+GetSingleValue(nsIDOMSVGLengthList *list, gfxFloat *val)
> 
> Again I think it would be simpler just to return the result you want rather
> than passing a pointer argument, even though that's what the current code does
> ;-)

In this case the calling code takes advantage of the fact that *val is not changed if there is no list or an empty list.

What value should the function return in these cases?  How will the calling code know that the return value should be ignored?  Either the calling code has to check before making the call (like above) or pass in a default value and return that.

> 
> > already_AddRefed<gfxFlattenedPath>
> > nsSVGTextPathFrame::GetFlattenedPath()
> > {
> >-  nsIFrame *path = GetPathFrame();
> >-  if (!path)
> >-    return nsnull;
> >+  return GetFlattenedPath(nsnull);
> 
> I think this should be implemented as:
> 
>   nsIFrame *path = path = GetPathFrame();
>   if (!path)
>     return nsnull;
>   return GetFlattenedPath(path);
> 
> >+}
> >+
> >+already_AddRefed<gfxFlattenedPath>
> >+nsSVGTextPathFrame::GetFlattenedPath(nsIFrame *path)
> >+{
> >+  if (!path) {
> >+    path = GetPathFrame();
> >+    if (!path)
> >+      return nsnull;
> >+  }
> 
> This change is then not necessary and can be removed.

Shouldn't there at least be 

  if (!path)
    return nsnull;

In case the private method is called with path == nsnull ?


At present, GetFlattenedPath is called in 3 places

1. nsSVGGlyphFrame::GetCharacterPosition(...)
     textPath->GetFlattenedPath();  // public method

2. nsSVGTextPathFrame::GetStartOffset()
     GetFlattenedPath(nsnull);  //private

3. nsSVGTextPathFrame::GetPathScale()
     GetFlattenedPath(pathFrame); //private

If the "(!path) etc" is removed, then case#2 needs to change to call the public method or do GetPathFrame() and check before calling.

Case#3 would be ok since that code would not be called if pathFrame == nsnull anyway.

> 
> >+gfxFloat
> >+nsSVGTextPathFrame::GetStartOffset() {
> 
> Nit: Could you put the { on a new line please?
> 

No problem.
(In reply to comment #32)
> (In reply to comment #30)
> > (From update of attachment 277664 [details] [diff] [review] [details])
> > >+static void
> > >+GetListValue(nsIDOMSVGLengthList *list, PRUint32 ival, gfxFloat *val)
> > 
> > Make this return the value you want rather than taking a gfxFloat *val
> > argument. It will make the calling code simpler.
> > 
> 
> Should be ok since the calling code checks the list length (as a shortcut)
> before calling the function.

I wouldn't bother with the shortcut check. This code is only called when things change; either once on load or if you do something in DOM so I think simplicity is better.

nsSVGGlyphFrame::SetCharPosition becomes much simpler.

+      gfxFloat dx = 0.0, dy = 0.0;
+      if (dxcount)
+        GetListValue(dxlist, 0, &dx);
+      x += dx;

would become

+      x += GetListValue(dxlist, 0);

for instance

> 
> > > static void
> > >-GetSingleValue(nsISVGGlyphFragmentLeaf *fragment,
> > >-               nsIDOMSVGLengthList *list, float *val)
> > >+GetSingleValue(nsIDOMSVGLengthList *list, gfxFloat *val)
> > 
> > Again I think it would be simpler just to return the result you want rather
> > than passing a pointer argument, even though that's what the current code does
> > ;-)
> 
> In this case the calling code takes advantage of the fact that *val is not
> changed if there is no list or an empty list.

OK, leave it as you have it then.

> > >+already_AddRefed<gfxFlattenedPath>
> > >+nsSVGTextPathFrame::GetFlattenedPath(nsIFrame *path)
> > >+{
> > >+  if (!path) {
> > >+    path = GetPathFrame();
> > >+    if (!path)
> > >+      return nsnull;
> > >+  }
> > 
> > This change is then not necessary and can be removed.
> 
> Shouldn't there at least be 
> 
>   if (!path)
>     return nsnull;

How about

    NS_ASSERTION(path, NS_ERROR_INVALID_POINTER);

instead? Since this is a private function, it's reasonable for it to assume its callers know not to call it with nsnull.

> 
> In case the private method is called with path == nsnull ?
> 
> 
> At present, GetFlattenedPath is called in 3 places
> 
> 1. nsSVGGlyphFrame::GetCharacterPosition(...)
>      textPath->GetFlattenedPath();  // public method
> 
> 2. nsSVGTextPathFrame::GetStartOffset()
>      GetFlattenedPath(nsnull);  //private
> 
> 3. nsSVGTextPathFrame::GetPathScale()
>      GetFlattenedPath(pathFrame); //private
> 
> If the "(!path) etc" is removed, then case#2 needs to change to call the public
> method or do GetPathFrame() and check before calling.
> 

Calling the public method seems best.
Comment on attachment 277664 [details] [diff] [review]
x.y.dx.dy lists for SVG tspan and text elements

clear invalid flag
Attachment #277664 - Flags: review+
(In reply to comment #33)
> > Should be ok since the calling code checks the list length (as a shortcut)
> > before calling the function.
> 
> I wouldn't bother with the shortcut check. This code is only called when things
> change; either once on load or if you do something in DOM so I think simplicity
> is better.

Without the shortcut check there is no way to know if the return value is valid or not (similar to discussion for GetSingleValue() in nsSVGTextFrame.cpp)

I take your point about making it simpler.  I made an SVGLengthListHelper class to hide the list length checking etc.

> > > >+already_AddRefed<gfxFlattenedPath>
> > > >+nsSVGTextPathFrame::GetFlattenedPath(nsIFrame *path)
> > > >+{
> > > >+  if (!path) {
> > > >+    path = GetPathFrame();
> > > >+    if (!path)
> > > >+      return nsnull;
> > > >+  }
> > > 
> > > This change is then not necessary and can be removed.
> > 
> > Shouldn't there at least be 
> > 
> >   if (!path)
> >     return nsnull;
> 
> How about
> 
>     NS_ASSERTION(path, NS_ERROR_INVALID_POINTER);
> 
> instead? Since this is a private function, it's reasonable for it to assume its
> callers know not to call it with nsnull.

Sounds good.

Attachment #278721 - Flags: review?(longsonr)
Comment on attachment 278721 [details] [diff] [review]
x.y.dx.dy lists for SVG tspan and text elements

Apologies for the delay. Somehow I got it into my head that I'd already commented on this.

> nsSVGGlyphFrame::GetCharacterPosition(gfxContext *aContext,
>                                       const nsString &aText,
>                                       

>+  nsSVGTextPathFrame *textPath = FindTextPathParent();
>+  if (!textPath) { // normal x,y,dx,dy placement

Get rid of the ! in the if and reverse the order of the following parts to suit. The fewer !s the better.

>+class SVGLengthListHelper
>+{
>+  nsCOMPtr<nsIDOMSVGLengthList> mList;
>+  PRUint32 mCount;
>+public:
>+  SVGLengthListHelper(const already_AddRefed<nsIDOMSVGLengthList> list);

I don't think you can use already_AddRefed as a function argument. AFAIK that construct is only for return values. You want to make the argument a raw pointer and probably use already_AddRefed when you call it.

>+SVGLengthListHelper::SVGLengthListHelper(const already_AddRefed<nsIDOMSVGLengthList> list)
>+{
>+  mList = list;
>+  mCount = 0;

Use constructor style initialisation for member variables.
  : mList(list), mCount(0)

>+void
>+nsSVGGlyphFrame::SetCharPosition(gfxTextRun *textRun,
>+                                 gfxPoint &ctp)
>+{

>+  if (!textPath) {

Again, please get rid of the ! and swap the order of the clauses below so the logic still works.  

> 
>+gfxFloat
>+nsSVGTextPathFrame::GetStartOffset() {

Please put the { on a new line
Attachment #278721 - Flags: review?(longsonr) → review-
(In reply to comment #37)
> >+class SVGLengthListHelper
> >+{
> >+  nsCOMPtr<nsIDOMSVGLengthList> mList;
> >+  PRUint32 mCount;
> >+public:
> >+  SVGLengthListHelper(const already_AddRefed<nsIDOMSVGLengthList> list);
> 
> I don't think you can use already_AddRefed as a function argument. AFAIK that
> construct is only for return values. You want to make the argument a raw
> pointer and probably use already_AddRefed when you call it.

Yes, on further research (bug #172030), |already_AddRefed<T>| is used as a temporary _short_ lived return value.

Also (bug #178187), using the raw pointer result of already_AddRefed<T>::get() doesn't make clear the transfer of ownership.

I struggled with this for a while because I wanted the ownership to be inside the helper class.  Rather than extract and pass the raw pointer it might be clearer to keep the ownership outside of the class.

Fixes for Comment #37
Attachment #277664 - Attachment is obsolete: true
Attachment #278721 - Attachment is obsolete: true
Attachment #280428 - Flags: review?(longsonr)
Comment on attachment 280428 [details] [diff] [review]
x.y.dx.dy lists for SVG tspan and text elements

>+    if (((xlist.count() <= 1) && (ylist.count() <= 1) && 
>+         (dxlist.count() <= 1) && (dylist.count() <= 1)) 
>+        || (strLength == 1)) {

Nit: Usual convention is to have || at the end of the previous line.

r=longsonr
Attachment #280428 - Flags: review?(longsonr) → review+
Robert,

Thanks for the +.  I'm not sure what to do next.  Do I need to submit another patch and request Tor for a super review ?  Or do I request Tor on the existing patch ?

Thanks,
Ken
up to you really. you could just ask tor for sr with this and if he wants any changes fix it as part of that or if not just go with this patch for check in.
Fixed "||" nit
Attachment #280428 - Attachment is obsolete: true
Attachment #282058 - Flags: superreview?(tor)
Comment on attachment 282058 [details] [diff] [review]
x.y.dx.dy lists for SVG tspan and text elements

It seems that SetCharPosition is only called from SetGlyphPosition.  If that is the case and you don't have future plans for other things to call it, it seems that the code should be in the latter.

SetCharPosition allocates the mCharPositions array for a textPath even if there aren't adjustments needed.

GetBaselineOffset - do you mean to only use the dominant-baseline from the outer <text> container, and not any nested text content elements?

GetStartOffset - you can get the start offset more directly, ie: static_cast<nsSVGTextPathElement*>(mContent)->mLengthAttributes[STARTOFFSET].GetBaseValue().  You will need to split the class definition of nsSVGTextPathElement into a seperate file for that.

GetPathScale likewise could be simplified if nsSVGTextPathFrame was also made a friend of nsSVGPathElement.
(In reply to comment #44)
> GetStartOffset - you can get the start offset more directly, ie:
> static_cast<nsSVGTextPathElement*>(mContent)->mLengthAttributes[STARTOFFSET].GetBaseValue().
>  You will need to split the class definition of nsSVGTextPathElement into a
> seperate file for that.

That should be GetAnimValue rather than GetBaseValue as startOffset is animatable.

(In reply to comment #44)
> It seems that SetCharPosition is only called from SetGlyphPosition.  If that is
> the case and you don't have future plans for other things to call it, it seems
> that the code should be in the latter.

OK

> SetCharPosition allocates the mCharPositions array for a textPath even if there
> aren't adjustments needed.

OK, mCharPosions only allocated when adjustments are needed.

> GetBaselineOffset - do you mean to only use the dominant-baseline from the
> outer <text> container, and not any nested text content elements?

It is meant to work like the latter - use the nearest parent text content element's dominant-baseline.

The loop at the beginning searches back up towards the text parent only while
dominant-baseline="auto" (NS_STYLE_DOMINANT_BASELINE_AUTO). This is the initial value for dominant-baseline and works like "inherit" for nested text content elements.

> GetStartOffset - you can get the start offset more directly, ie:
> static_cast<nsSVGTextPathElement*>(mContent)->mLengthAttributes[STARTOFFSET].GetBaseValue().
>  You will need to split the class definition of nsSVGTextPathElement into a
> seperate file for that.

OK

> GetPathScale likewise could be simplified if nsSVGTextPathFrame was also made a
> friend of nsSVGPathElement.
> 

OK
New header file in seperate attachment
Attachment #282058 - Attachment is obsolete: true
Attachment #284402 - Flags: superreview?(tor)
Attachment #282058 - Flags: superreview?(tor)
A comment on attachment (id=284402) 

Lately, I have been unable to update my source tree.  I tracked it down to a line in client.mk.  (included in patch (id=284402))

 CONFIG_STATUS_DEPS := \
 	$(TOPSRCDIR)/configure \
 	$(TOPSRCDIR)/.mozconfig.mk \
 	$(wildcard $(TOPSRCDIR)/nsprpub/configure) \
 	$(wildcard $(TOPSRCDIR)/directory/c-sdk/configure) \
 	$(wildcard $(TOPSRCDIR)/config/milestone.txt) \
 	$(wildcard $(TOPSRCDIR)/config/chrome-versions.sh) \
-  $(wildcard $(addsuffix confvars.sh,$(wildcard */))) \
+	$(wildcard $(addsuffix confvars.sh,$(wildcard $(TOPSRCDIR)/*/))) \
 	$(NULL)

Note that $(wildcard */) depends on the current directory.

This variable is ifdefed out for the first checkout.

When updating the source tree, this variable is expanded from $(TOPSRCDIR), then
the following line is executed in checkout:

	@cd $(ROOTDIR) && $(MAKE) -f mozilla/client.mk real_checkout

When making real_checkout it is evaluated from $(ROOTDIR).  On my computer, make failed while trying to open a hidden system directory in the rootdir when evaluating $(wildcard */).  The only confvars.h files I could find are in subdirs of $(TOPSRCDIR) so I changed the line to get it to not fail.  No apparrent problems with build.

A bug ?
(In reply to comment #48)
> Created an attachment (id=284403) [details]
> New file - nsSVGTextPathElement.h - for patch 284402
> 

While you don't have write access to cvs you should use the cvsdo perl script to add new files to your local repository. You can then submit a single patch which will include the new file. See http://viper.haque.net/~timeless/redbean/

(In reply to comment #49)

> -  $(wildcard $(addsuffix confvars.sh,$(wildcard */))) \
> +       $(wildcard $(addsuffix confvars.sh,$(wildcard $(TOPSRCDIR)/*/))) \

My client.mk looks like the - line and bonsai agrees. http://mxr.mozilla.org/mozilla/source/client.mk?mark=1020#1009
Includes new file nsSVGTextPathElement.h
Attachment #284402 - Attachment is obsolete: true
Attachment #284403 - Attachment is obsolete: true
Attachment #284581 - Flags: superreview?
Attachment #284402 - Flags: superreview?(tor)
(In reply to comment #52)

Meant to set superreview for tor but hit enter at wrong time.
Attachment #284581 - Flags: superreview? → superreview?(tor)
I've used part of this bug to fix bug 406312
I've checked in the fix for bug 406312 so perhaps 25% of this patch is no longer required.

Also the changes to nsSVGTextContainerFrame.cpp are probably not desirable as the code will work without them.

Just to let you know what's going on, this is new functionality and I'm afraid it missed the cutoff time to land for firefox 3.0. An updated patch could still make firefox 3.1
Robert Longson: could you find some time for rewriting your patch againts current trunk? Would be nice to see your patch in Gecko 1.9.2 together will all other SVG improvements.
I meant Ken Stacey of course, sorry.
Assignee: nobody → longsonr
Depends on: 406312
Depends on: 496989
Robert, just so you know, we're planning some changes to the SVG text code that would impact this quite heavily ... to be precise, rewriting it to use hidden nsBlockFrame/nsInlineFrame/nsTextFrames for layout and then extracting glyph data from them for rendering. The main goal is to handle bidi better.
I'm hoping to reuse the existing textpath positioning code so hopefully I won't make that rewrite any worse. I'll be doing this one small step at a time too.
Attachment #275429 - Attachment is obsolete: true
Attachment #275926 - Attachment is obsolete: true
Attachment #284581 - Attachment is obsolete: true
Attachment #389307 - Flags: review?(roc)
Attachment #284581 - Flags: superreview?(tor)
(In reply to comment #60)
> Created an attachment (id=389307) [details]
> update to tip and add support for rotate

This patch regresses the <tspan dy> in a <textPath> testcase :-(.
http://www.w3.org/Graphics/SVG/Test/20061213/htmlObjectHarness/full-text-path-01-b.html
Attachment #389307 - Flags: review?(roc)
Attached patch updated patch with reftest (obsolete) — Splinter Review
Fixes reported issue.
Attachment #389307 - Attachment is obsolete: true
Attachment #389392 - Flags: review?(roc)
+GetNumberOfNumberListItems(nsIDOMSVGNumberList *list)
+GetLengthListValue(nsIDOMSVGLengthList *list, PRUint32 index)
+GetNumberListValue(nsIDOMSVGNumberList *list, PRUint32 index)

Use a* for parameters

+  NS_IMETHOD_(void) SetGlyphPosition(gfxPoint &position, PRBool aForceGlobalTransform)=0;

Prefer gfxPoint* here for the in-out parameter.

+      // have we run off the end of the path?
+      if (pos.x + halfAdvance > length)
+        break;

Is it possible for us to go past the end of the path but then negative dx pulls us back into the path?

You're not handling 'rotate' for text on a path?

Can't GetDx/GetDy/GetRotate just return a non-addrefed pointer?

We really need some love for nsIDOMSVGLengthList/nsIDOMSVGNumberList so that we have optimized storage and a COM-less internal interface, but I guess that can wait.

Why are you checking for the presence of the attributes in GetDx/GetDy/GetRotate? An optimization? Seems like these could be animated so that even if there's no attribute, there's still an animated value?
Attached patch address review comments (obsolete) — Splinter Review
(In reply to comment #63)
> +GetNumberOfNumberListItems(nsIDOMSVGNumberList *list)
> +GetLengthListValue(nsIDOMSVGLengthList *list, PRUint32 index)
> +GetNumberListValue(nsIDOMSVGNumberList *list, PRUint32 index)
> 
> Use a* for parameters

Done.

> 
> +  NS_IMETHOD_(void) SetGlyphPosition(gfxPoint &position, PRBool
> aForceGlobalTransform)=0;
> 
> Prefer gfxPoint* here for the in-out parameter.

Done.

> 
> +      // have we run off the end of the path?
> +      if (pos.x + halfAdvance > length)
> +        break;
> 
> Is it possible for us to go past the end of the path but then negative dx pulls
> us back into the path?

Fixed.

> 
> You're not handling 'rotate' for text on a path?

Fixed.

> 
> Can't GetDx/GetDy/GetRotate just return a non-addrefed pointer?

I'm going to punt that to whatever fix addresses nsIDOMSVGLengthList/nsIDOMSVGNumberList if that's OK.

> 
> We really need some love for nsIDOMSVGLengthList/nsIDOMSVGNumberList so that we
> have optimized storage and a COM-less internal interface, but I guess that can
> wait.

Indeed.

> 
> Why are you checking for the presence of the attributes in
> GetDx/GetDy/GetRotate? An optimization? Seems like these could be animated so
> that even if there's no attribute, there's still an animated value?

Fixed.
Attachment #389392 - Attachment is obsolete: true
Attachment #390669 - Flags: review?(roc)
Attachment #389392 - Flags: review?(roc)
Comment on attachment 390669 [details] [diff] [review]
address review comments

(In reply to comment #64)
> (In reply to comment #63)
> > +      // have we run off the end of the path?
> > +      if (pos.x + halfAdvance > length)
> > +        break;
> > 
> > Is it possible for us to go past the end of the path but then negative dx
> > pulls us back into the path?
> 
> Fixed.

Can you add a test for this? Generally I think it's good to create regression tests even for the bugs you find during development before checking in.

> > You're not handling 'rotate' for text on a path?
> 
> Fixed.

You don't seem to have any tests for rotate? We need tests with and without a path.

> > Can't GetDx/GetDy/GetRotate just return a non-addrefed pointer?
> 
> I'm going to punt that to whatever fix addresses
> nsIDOMSVGLengthList/nsIDOMSVGNumberList if that's OK.

OK

r+ assuming those tests are added.
Duplicate of this bug: 463990
Blocks: 433345
Attachment #390669 - Attachment is obsolete: true
Blocks: 521636
Blocks: 521637
landed then backed out due to mac test orange. The test looks the same as the reference to me so I don't know what's wrong at the moment.

http://tinderbox.mozilla.org/showlog.cgi?log=Firefox-Unittest/1255263471.1255264753.32026.gz&fulltext=1#err1
Keywords: dev-doc-needed
Duplicate of this bug: 537062
Attachment #405745 - Attachment is obsolete: true
The tests in comment 69 partially work. Some require SVG fonts and one is affected by a cairo bug causing rotation of characters not to work (already known to bugzilla).

pushed http://hg.mozilla.org/mozilla-central/rev/dde594b087c5
pushed http://hg.mozilla.org/mozilla-central/rev/08d3f0cf8a69 (because the reftest files went missing somehow)
Also http://hg.mozilla.org/mozilla-central/rev/1eba5671da3a and http://hg.mozilla.org/mozilla-central/rev/cc980f275250
Status: NEW → RESOLVED
Closed: 10 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Whiteboard: [check tests in comment 69 before marking fixed]
Blocks: 333698
No longer blocks: 521637
There's a note about this change now here:

https://developer.mozilla.org/en/Firefox_4_for_developers#Graphics_and_video

Given that our SVG documentation is currently a work in progress, the text and tspan elements aren't yet documented at all, but when they are this will be included there.
You need to log in before you can comment on or make changes to this bug.