在 Batik 中设置 SVG 1.1 文档类型(公共和系统 ID)

发布于 2025-01-14 02:29:45 字数 1249 浏览 2 评论 0 原文

使用 Apache Batik (1.14) 时,我试图在 SVG 输出中获取特定的 DOCTYPE 条目。

一个简单的例子如下所示:

        DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
        String svgNS = "http://www.w3.org/2000/svg";
        DocumentType docType = domImpl.createDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd");
        Document document = domImpl.createDocument(svgNS, "svg", docType);
        SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
        SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
        Writer out = new OutputStreamWriter(System.out, "UTF-8");
        svgGenerator.stream(out, true);

产生:

<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
          'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>

我希望得到更多类似的东西:(

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

基于 https://www.w3.org/TR/SVG11/struct.html#NewDocument)。

我怎样才能获得所需的DOCTYPE(最好不要事后修改XML)?

I'm trying to get a specific DOCTYPE entry in my SVG output when using Apache Batik (1.14).

A simple example looks like:

        DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
        String svgNS = "http://www.w3.org/2000/svg";
        DocumentType docType = domImpl.createDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd");
        Document document = domImpl.createDocument(svgNS, "svg", docType);
        SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
        SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
        Writer out = new OutputStreamWriter(System.out, "UTF-8");
        svgGenerator.stream(out, true);

Which produces:

<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
          'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>

I was hoping for something more like:

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

(based on the SVG 1.1 spec entry at https://www.w3.org/TR/SVG11/struct.html#NewDocument).

How can I get the desired DOCTYPE (ideally without munging the XML afterwards)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌化 2025-01-21 02:29:45

与其在 DOCTYPE 生成上与 Batik 斗争,只需跳过它即可。正如罗伯特评论,一般都会被忽略。此外,不建议在 SVG 中使用 DOCTYPE :

事实上,SVG WG 成员甚至告诉人们不要使用 DOCTYPE
SVG 1.0 和 1.1 文档中的声明。相反,始终包括
标记上的 versionbaseProfile 属性,以及
为它们分配适当的值,如下例所示。


Rather than struggle with Batik over DOCTYPE generation, just skip it. As Robert commented, it's generally ignored. Furthermore, using a DOCTYPE is not recommended with SVG:

In fact SVG WG members are even telling people not to use a DOCTYPE
declaration in SVG 1.0 and 1.1 documents. Instead always include the
version and baseProfile attributes on the root <svg> tag, and
assign them appropriate values as in the following example.

<svg version="1.1"
     baseProfile="full"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     xmlns:ev="http://www.w3.org/2001/xml-events">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文