Yeah, I've been cranking away at this and it all seems to work.  I
received the expected SVG output.  I got canvas updates working.  The
only thing is this:

<rect x="243" y="40" width="193" height="121" stroke="black"
stroke-opacity="1"></rect>

I omit the fill attributes, but my shapes (Ellipses and Rectangles) are
being filled with the stroke color.  At least I think so.  The
background of the canvas is white and the default stroke color is black.
When I draw with black, I get a filled-in black rectangle.  If I change
the stroke color to red, I get a red rectangle that's filled in with
black:

<rect x="141" y="97" width="191" height="136" stroke="red"
stroke-opacity="1"></rect>

Maybe the JSVGCanvas has a white background but the document uses black
by default?  Where can you set the background of a document?  Getting
awfully close here!

Michael Bishop

-----Original Message-----
From: Thomas DeWeese [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 15, 2005 12:29 PM
To: [email protected]
Subject: Re: Basic SVG management in Batik with white-boarding.

Bishop, Michael W. CONTR J9C880 wrote:
> OK, making some progress here and creating shapes the way I want to.
> I'm a little hung up on color.  I see the SVGColor class has a toSVG()
> method that will take a java.awt.Color (which is what I start with),
but
> return a SVGPaintDescriptor.  How do I translate this information to:
> 
> <rect stroke="..." .../>
> 
> Is this as simple as calling getAttributeMap(null) and iterating
through
> the returned Map and appending attributes to the shape?

    Almost but you will want to request just fill or stroke attributes
otherwise you will get both fill/stroke on the element:

Map attrs = paintDesc.getAttributeMap(null);
if (doFill) {
    e.setAttribute(SVG_FILL_ATTRIBUTE, attrs.get(SVG_FILL_ATTRIBUTE));
    e.setAttribute(SVG_FILL_OPACITY_ATTRIBUTE,
                  attrs.get(SVG_FILL_OPACITY_ATTRIBUTE));
} else {
    // set Stroke
    e.setAttribute(SVG_STROKE_ATTRIBUTE,
                  attrs.get(SVG_STROKE_ATTRIBUTE));
    e.setAttribute(SVG_STROKE_OPACITY_ATTRIBUTE,
                  attrs.get(SVG_STROKE_OPACITY_ATTRIBUTE));
}

> 
> Michael Bishop
> 
> -----Original Message-----
> From: Thomas DeWeese [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, September 13, 2005 4:20 PM
> To: [email protected]
> Subject: Re: Basic SVG management in Batik with white-boarding.
> 
> Hi Michael,
> 
> Bishop, Michael W. CONTR J9C880 wrote:
> 
> 
>>I don't think I need the <g> elements at all for basic shapes
>>which has got me going away from SVGGraphics2D.
> 
> 
>>>The outer 'g' is also mostly useless in the 'one draw operation at a
>>>time' case, so you are left with just the inner 'g' that needs to be
>>>kept.
>>
>>Why?  Can't I have:
>>
>><svg>
>>    <circle .../>
>>    <rect .../>
>></svg>
> 
> 
>     You can have this if you go with SVGShape, getting this from
> the SVGGraphics2D would be difficult (you would have to move
> the fill/stroke/etc attrs from the wrapping 'g' to the primitive).
> 
> 
>>>   Yes, so you would want to do something like:
>>
>>>   Element e = svgShape.toSVG(java2dShape);
>>>   e.setAttributeNS(null, "fill", "red");
>>>   root.appendChild(e).
>>
>>Right, since this is a whiteboard application, I will need to
>>communicate everything about the shape.  Color, fill color, size,
> 
> shape,
> 
>>etc.  Again, according to the SVG specification, I can declare all
> 
> this
> 
>>stuff.  So now I'm thinking:
>>
>>- Create a root document.
>>- Set extra attributes on the root <svg> element; canvas size, etc.
>>- Translate mouse press/release to X/Y coordinates.
>>- Translate X/Y coordinates to Shape.
>>- Translate Shape2D to SVGShape.
>>- Use SVGShape.toSVG() to create the SVG element.
>>- Set extra attributes on the element; ID, fill color, color, etc.
>>- Append the SVG fragment to the document.
>>- At this point, ALWAYS_DYNAMIC should pick up the change and display
> 
> it
> 
>>on the application.
> 
> 
>     This all sounds good (just a friendly reminder to use the
> UpdateManager thread to append the new shape to the document).
> 
> 
>>The only question left in this line of thinking is the
>>SVGGeneratorContext.  It's needed as a constructor argument for the
>>SVGShape class.  I used to get it from SVGGraphics2D.  Where would I
> 
> get
> 
>>one for now?
> 
> 
>     It has a factory method that takes a Document.  This is generally
> what the SVGGraphics2D uses in the default case:
> 
>      SVGGeneratorContext gc = SVGGeneratorContext.createDefault(doc);
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail:
[EMAIL PROTECTED]
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail:
[EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to