cynest-java

          [導入]Batik之SVGGraphics2D生成SVG

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

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

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

          SVGGraphics2D提供了如下特點的功能

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

          生成SVG的三個步驟:
          1、創建org.w3c.dom.Document的實例,生成器利用它建立XML內容。創建一個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)  編輯  收藏


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


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 杂多县| 长武县| 仁寿县| 资源县| 莱西市| 田东县| 平阳县| 四川省| 朝阳区| 无棣县| 开远市| 尖扎县| 沭阳县| 宜黄县| 勃利县| 鄱阳县| 响水县| 霍林郭勒市| 丘北县| 富宁县| 新野县| 泰兴市| 景谷| 泸溪县| 东宁县| 石河子市| 广州市| 武川县| 重庆市| 民县| 蒙自县| 辉南县| 龙里县| 阿拉善右旗| 鹤庆县| 平利县| 日喀则市| 凌源市| 溧水县| 宁明县| 麻栗坡县|