Loading ...
Sorry, an error occurred while loading the content.
 

Re: [svg-developers] help with adding and editing svg text element in java swing application

Expand Messages
  • Thomas DeWeese
    ... Hi Rita, The code below looks pretty good in general. There are a few small typo s (appen Child). The only thing that jumps out at me is that you don t
    Message 1 of 2 , Mar 5, 2004
      Rita wrote:

      > Hello svg-developers,
      >
      > I am currently developing a presentation editor, written in java. But
      > I also use the batik toolkit to generate the graphic elements for the
      > application.
      >
      > I didn't have any problem with creating line, rect and oval elements,
      > however I am stuck with creating text element. I am pretty confused
      > about where to start really. I will be grateful if you could help me
      > out a bit.

      Hi Rita,
      The code below looks pretty good in general. There are a few
      small typo's (appen<d>Child). The only thing that jumps out at
      me is that you don't set the 'x' and 'y' attributes on the 'text'
      element. This generally results in your text being off the top of
      the document (often if you look closely you can see the descenders
      for the text run along the top edge of the window).

      >
      > Here is a segment of the code I wrote to create a text element,
      > please comment on it:
      >
      > public static Element createText(Document doc, double x, double y,
      > String inputText,String id) {
      >
      > String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
      > Element text = doc.createElementNS(svgNS, "text");
      > text.setAttributeNS(null, "font", "sans-serif");
      > text.setAttributeNS(null, "style", "fill:black");
      > text.setAttributeNS(null, "font-size", "12");
      > Text textNode = doc.createTextNode(inputText);
      > // define the root element
      > Element svgRoot = doc.getDocumentElement();
      > svgRoot.setAttributeNS(null, "width", "400");
      > svgRoot.setAttributeNS(null, "height", "450");
      > // append the text element to the root
      > text.appenChild(textNode);
      > svgRoot.appendChild(text);
      > if (id != null)
      > text.setAttributeNS(null, "id", id);
      > return text;
      > }
      >
      > What do you reckon?
      >
      >
      >
      >
      > -----
      > To unsubscribe send a message to: svg-developers-unsubscribe@yahoogroups.com
      > -or-
      > visit http://groups.yahoo.com/group/svg-developers and click "edit my membership"
      > ----
      > Yahoo! Groups Links
      >
      >
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.