SVG ファイルの読み書きをするために、JViews Framework ライブラリーは、SVG 専用の
IlvStreamFactory
の新規インスタンスを定義します。IlvManager
での SVGStreamFactory の設定方法およびその使用法がわかるようになります。SVG ストリーム・ファクトリーを構成するには、以下の手順に従います。
-
作業するマネージャーとストリーム・ファクトリーを作成します。
import ilog.views.*; import ilog.views.svg.*; IlvManager manager = new IlvManager(); SVGStreamFactory factory = new SVGStreamFactory(); manager.setStreamFactory(factory);
-
ストリーム・ファクトリーのオプションを適切に設定して、Rogue Wave JViews が SVG ファイルを読み込みおよび保存する方法 (ファイル・サイズの縮小方法や、リーダーが一部のデータを無視するかどうかなどの指定など) を変更します。
-
ストリーム・ファクトリーの設定後、次を使用してマネージャーに添付する必要があります。
manager.setStreamfactory(factory);
その他の圧縮技術 (不可視のグラフィック・オブジェクトの削除など)、CSS または XML スタイルの間の選択機能などの追加オプションは、クラスの『Java API リファレンス・マニュアル』にあります。
次の例は、ストリーム・ファクトリーの設定を示しています。
// When reading SVG, the parsing of the CSS style will include // the definitions contained in the user.css file. factory.getReaderConfigurator().setUserStyleSheetURL(“user.css”); // When writing SVG, the following compaction techniques will be used: // - style on graphic element will be factored // - an algorithm will be applied to polyline to remove some points factory.getBuilderConfigurator(). setCompactMode(SVGDocumentBuilderConfigurator.COMPACT_STYLE | SVGDocumentBuilderConfigurator.COMPACT_POLY); // With the option set to true on the reader configurator, when reading SVG, // elements that cannot be processed will be memorized // and with the option set to true on the builder configurator, this will // allow regenerating them later. factory.getReaderConfigurator().setFullDocumentOn(true); factory.getBuilderConfigurator().setFullDocumentOn(true);
ストリーム・ファクトリーのセットアップが完了したら、SVG ファイルを読み込めます。
SVG ファイルを読み込むには、以下の手順に従います。
-
IlvManager メソッドを呼び出して、通常の Rogue Wave JViews ファイルではなく SVG ファイルを読み込みます。
以下のコードは、SVG ファイルの読み込み例です。
try { manager.read("mysvgfile.svg"); } catch (ilog.views.io.IlvReadFileException rfe) { System.err.println("The SVG file is badly formatted"); } catch (java.io.IOException ioe) { System.err.println("Cannot access the SVG file"); }
IlvManager オブジェクトが動的に、あるいは SVG または IVL ファイルを読み込んで埋められると、オブジェクトを SVG ファイルに保存できます。
SVG ファイルに保存するには、以下の手順に従います。
-
IlvManager メソッドを呼び出して、通常の Rogue Wave JViews ファイルではなく SVG ファイルに保存します。
以下のコードは、SVG ファイルへの書き込み例です。
try { manager.write("mysvgfilemodified.svg"); } catch (java.io.IOException ioe) { System.err.println("Cannot access the SVG file"); }