(From update of attachment 276088)
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...
>- 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
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.
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;
(From update of attachment 276088)
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 me::GetSubStrin gAdvance( PRUint32 charnum, PRUint32 fragmentChars)
>+nsSVGGlyphFra
>+{
>+ 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 me::SetCharPosi tion(gfxTextRun *textRun,
>+nsSVGGlyphFra
>+ 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 ::GetStartPosit ionOfChar( PRUint32 charnum, nsIDOMSVGPoint **_retval)
> nsSVGGlyphFrame
> {
>+ if (angle != 0.0f) {
0.0
> NS_IMETHODIMP ::GetEndPositio nOfChar( PRUint32 charnum, nsIDOMSVGPoint **_retval) ::GetEndPositio nOfChar( PR OUT_OF_ MEMORY;
> nsSVGGlyphFrame
>@@ -834,23 +1013,30 @@ nsSVGGlyphFrame
> return NS_ERROR_
>
>+ gfxFloat angle = cp[charnum].angle;
>+ if (angle != 0.0f) {
0.0
>Index: layout/ svg/base/ src/nsSVGGlyphF rame.h ======= ======= ======= ======= ======= ======= ======= ======= ===== mozilla/ layout/ svg/base/ src/nsSVGGlyphF rame.h, v svg/base/ src/nsSVGGlyphF rame.h 3 Aug 2007 08:39:13 -0000 1.26 svg/base/ src/nsSVGGlyphF rame.h 10 Aug 2007 06:01:19 -0000
>======
>RCS file: /cvsroot/
>retrieving revision 1.26
>diff -u -8 -p -r1.26 nsSVGGlyphFrame.h
>--- layout/
>+++ layout/
>- gfxPoint mPosition; gfxPoint> mCharPositions; // character position of each glyph,
>+ gfxPoint mPosition; // character position of first glyph, includes baseline offset
>+ nsAutoArrayPtr<
>+ // 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] ; nsGkAtoms: :d, charPositions, positionDtorFunc);
SetProperty(
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 positionDtorFun ction is automatically called.
>+ float mBaselineOffset; ling; svg/base/ src/nsSVGTextFr ame.cpp ======= ======= ======= ======= ======= ======= ======= ======= ===== mozilla/ layout/ svg/base/ src/nsSVGTextFr ame.cpp, v svg/base/ src/nsSVGTextFr ame.cpp 3 Aug 2007 08:39:13 -0000 1.61 svg/base/ src/nsSVGTextFr ame.cpp 10 Aug 2007 06:01:19 -0000 :GetCanvasTM( )
> PRUint8 mWhitespaceHand
> };
>
> #endif
>Index: layout/
>======
>RCS file: /cvsroot/
>retrieving revision 1.61
>diff -u -8 -p -r1.61 nsSVGTextFrame.cpp
>--- layout/
>+++ layout/
>@@ -293,71 +293,29 @@ nsSVGTextFrame:
> void :UpdateGlyphPos itioning( )
> nsSVGTextFrame:
> {
>- float x = 0, y = 0;
>+ gfxPoint ctp(0.0,0.0);
add a space after the comma.
> ======= ======= ======= ======= ======= ======= ======= ======= ===== mozilla/ layout/ svg/base/ src/nsSVGTextPa thFrame. cpp,v ame.cpp svg/base/ src/nsSVGTextPa thFrame. cpp 25 Jul 2007 09:16:02 -0000 1.31 svg/base/ src/nsSVGTextPa thFrame. cpp 10 Aug 2007 06:01:19 -0000
>======
>RCS file: /cvsroot/
>retrieving revision 1.31
>diff -u -8 -p -r1.31 nsSVGTextPathFr
>--- layout/
>+++ layout/
> already_ AddRefed< gfxFlattenedPat h> Frame:: GetFlattenedPat h() Frame:: GetFlattenedPat h(nsIFrame *path)
>-nsSVGTextPath
>+nsSVGTextPath
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 Frame:: GetStartOffset( ) {
>+nsSVGTextPath
>+ 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 Frame:: GetPathScale( ) >GetContent( )->HasAttr( kNameSpaceID_ None, :pathLength) ) {
>+nsSVGTextPath
>+{
>+ float scale = 1.0f;
>+ nsIFrame *pathFrame = GetPathFrame();
>+ if (pathFrame && pathFrame-
>+ nsGkAtoms:
You really need some early returns in this function rather than all this indenting. E.g.
if (!pathFrame || !pathFrame- >GetContent( )...)
return 1.0f;
>+ nsCOMPtr< nsIDOMSVGPathEl ement> pathElement = ce(pathFrame- >GetContent( ));
>+ do_QueryInterfa
>+ if (pathElement) {
if (!pathElement)
return 1.0f;
etc. And just return the result if you calculate something non-zero.