On Monday 24 September 2001 09:40, Keiron Liddle wrote:
> The problem is I (may) need to know the size of the svg when creating the
> area tree for the formatting objects. This area tree does not depend on the
> output. When I come to render the output the svg graphics node depends on
> the output in the case of text, links etc. So I need to build a new
> graphics node or do something else to be able to render to the specific
> ouput.
>
> If it is 100% then it is fine but if the svg defines a size and the svg
> area size is defined as use content then I need to get the size of the svg.
I am not sure I understand your problem well, sorry. May be some code might
help... Here is what I do in the ImageTranscoder. Basically, the following
code is equivalent to the getWidth method except that percentages (and
especially percentages on the outermost svg element) are handled correctly.
---
// build the GVT tree
GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(userAgent);
GraphicsNode gvtRoot;
try {
gvtRoot = builder.build(ctx, svgDoc);
} catch (BridgeException ex) {
// ...
}
// get the 'width' and 'height' attributes of the SVG document
float docWidth = (float)ctx.getDocumentSize().getWidth();
float docHeight = (float)ctx.getDocumentSize().getHeight();
---
In this piece of code, that's true that I need to first build the document in
order to get the size of the SVG document. If that's your prom, may be the
following code might help too (comes from the SVGSVGElementBridge - the one
that initializes the dimension returned by the
BridgeContext.getDocumentSize() method).
---
Element e = ...; // your root SVG element (or any other)
String s;
UnitProcessorContext uctx = UnitProcessor.createContext(ctx, e);
// 'width' attribute - default is 100%
s = e.getAttributeNS(null, SVG_WIDTH_ATTRIBUTE);
if (s.length() == 0) {
s = SVG_SVG_WIDTH_DEFAULT_VALUE;
}
float w = UnitProcessor.svgHorizontalLengthToUserSpace
(s, SVG_WIDTH_ATTRIBUTE, uctx);
// 'height' attribute - default is 100%
s = e.getAttributeNS(null, SVG_HEIGHT_ATTRIBUTE);
if (s.length() == 0) {
s = SVG_SVG_HEIGHT_DEFAULT_VALUE;
}
float h = UnitProcessor.svgVerticalLengthToUserSpace
(s, SVG_HEIGHT_ATTRIBUTE, uctx);
// Here you have the size of your SVG document as float values - percentages,
units or whatever have been resolved.
---
Hope that helps. Please let me know if I missed something.
Regards,
Thierry.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]