cynest-java

          My Links

          Blog Stats

          常用鏈接

          留言簿(1)

          隨筆檔案

          文章分類

          鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          [導入]Batik之SVGGraphics2D生成SVG

          在Java平臺上,通過java.awt.Graphics2D抽象類來實現圖形功能,該類提供了諸如

          drawRect,fillRect,以及drawString等方法。而Batik的SVGGraphics2D是一個專門的工具

          ,用來生成SVG文本內容而不是在屏幕上顯示或打印。

          SVGGraphics2D提供了如下特點的功能

          1、允許應用程序將圖形輸出成SVG格式
          2、輸出為SVG的過程不需要修改任何圖形代碼
          3、提供給用戶DOM API功能來處理產生的文檔

          生成SVG的三個步驟:
          1、創(chuàng)建org.w3c.dom.Document的實例,生成器利用它建立XML內容。創(chuàng)建一個SVG生

          成器則使用Document實例。

          // Get a DOMImplementation
          DOMImplementation domImpl =
          ??? GenericDOMImplementation.getDOMImplementation();

          // Create an instance of org.w3c.dom.Document
          Document document = domImpl.createDocument(null, "svg", null);

          // Create an instance of the SVG Generator
          SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

          2、在SVG生成器上調用表現代碼,如paint方法

          // Ask the test to render into the SVG Graphics2D implementation
          TestSVGGen test = new TestSVGGen();
          test.paint(svgGenerator);

          3、輸出SVG內容,生成器可以通過任何一個java.io.Writer把內容stream出來。

          // Finally, stream out SVG to the standard output using UTF-8
          // character to byte encoding
          boolean useCSS = true; // we want to use CSS style attribute
          Writer out = new OutputStreamWriter(System.out, "UTF-8");
          svgGenerator.stream(out, useCSS);

          注:SVG在表達屬性時可以由兩種方式,XML屬性和CSS方式。


          文章來源:http://cynest.cn/drupal/?q=node/612

          posted on 2006-02-14 15:38 cyqian 閱讀(1951) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網站導航:
           
          主站蜘蛛池模板: 大姚县| 咸丰县| 固原市| 嵩明县| 汉沽区| 昆山市| 澳门| 壤塘县| 呼图壁县| 陆良县| 随州市| 金坛市| 长沙市| 海原县| 新平| 建瓯市| 彰化市| 丰原市| 浦城县| 龙游县| 桦南县| 黄梅县| 孝感市| 南充市| 遂宁市| 柳江县| 无棣县| 凤庆县| 溆浦县| 苏尼特左旗| 泰和县| 渑池县| 女性| 重庆市| 宝兴县| 林甸县| 正宁县| 铜鼓县| 涪陵区| 南涧| 南投市|