SVGUtilities (Apache FOP Core 2.11 API)
Date: 2025-04-24

org.apache.fop.svg

## Class SVGUtilities

- java.lang.Object
- - org.apache.fop.svg.SVGUtilities

-     public final class SVGUtilities
      extends Object

  Some utilities for creating svg DOM documents and elements.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Element` | `createClip(Document doc, Element els, String id)` Create an SVG Clip.
    `static Element` | `createEllipse(Document doc, float cx, float cy, float rx, float ry)` Create an SVG Ellipse
    `static Element` | `createG(Document doc)` Create an SVG G.
    `static Element` | `createImage(Document doc, String ref, float width, float height)` Create and svg image element.
    `static Element` | `createLine(Document doc, float x, float y, float x2, float y2)` Create an SVG Line
    `static Element` | `createPath(Document doc, String str)` Create an SVG Path.
    `static Element` | `createRect(Document doc, float x, float y, float width, float height)` Create an SVG Rectangle.
    `static Document` | `createSVGDocument(float width, float height)` Create a new svg document with batik.
    `static Element` | `createText(Document doc, float x, float y, String str)` Create an SVG Text object.
    `static Rectangle2D` | `getStringBounds(String str, Font font)` Get the string bounds for a particular string given the font.
    `static float` | `getStringHeight(String str, Font font)` Get the string height for a particular string given the font.
    `static float` | `getStringWidth(String str, Font font)` Get the string width for a particular string given the font.
    `static Element` | `wrapText(Document doc, String str, Font font, float width)` Create some SVG text that is wrapped into a specified width.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### createSVGDocument

          public static Document createSVGDocument(float width,
                                                   float height)

      Create a new svg document with batik.
      Parameters:
        `width` - the width of the root svg element
        `height` - the height of the root svg element
      Returns:
        a new SVG Document

    - #### getStringWidth

          public static float getStringWidth(String str,
                                             Font font)

      Get the string width for a particular string given the font.
      Parameters:
        `str` - the string
        `font` - the font
      Returns:
        the width of the string in the given font

    - #### getStringHeight

          public static float getStringHeight(String str,
                                              Font font)

      Get the string height for a particular string given the font.
      Parameters:
        `str` - the string
        `font` - the font
      Returns:
        the height of the string in the given font

    - #### getStringBounds

          public static Rectangle2D getStringBounds(String str,
                                                    Font font)

      Get the string bounds for a particular string given the font.
      Parameters:
        `str` - the string
        `font` - the font
      Returns:
        the bounds of the string

    - #### createLine

          public static Element createLine(Document doc,
                                           float x,
                                           float y,
                                           float x2,
                                           float y2)

      Create an SVG Line
      Parameters:
        `doc` - the document to create the element
        `x` - the start x position
        `y` - the start y position
        `x2` - the end x position
        `y2` - the end y position
      Returns:
        the new line element

    - #### createEllipse

          public static Element createEllipse(Document doc,
                                              float cx,
                                              float cy,
                                              float rx,
                                              float ry)

      Create an SVG Ellipse
      Parameters:
        `doc` - the document to create the element
        `cx` - the centre x position
        `cy` - the centre y position
        `rx` - the x axis radius
        `ry` - the y axis radius
      Returns:
        the new ellipse element

    - #### createPath

          public static Element createPath(Document doc,
                                           String str)

      Create an SVG Path.
      Parameters:
        `doc` - the document to create the element
        `str` - the string for the d attribute on the path
      Returns:
        the new path element

    - #### createText

          public static Element createText(Document doc,
                                           float x,
                                           float y,
                                           String str)

      Create an SVG Text object.
      Parameters:
        `doc` - the document to create the element
        `x` - the start x position
        `y` - the start y position
        `str` - the string
      Returns:
        the new text element

    - #### createRect

          public static Element createRect(Document doc,
                                           float x,
                                           float y,
                                           float width,
                                           float height)

      Create an SVG Rectangle.
      Parameters:
        `doc` - the document to create the element
        `x` - the start x position
        `y` - the start y position
        `width` - the width of the rectangle
        `height` - the height of the rectangle
      Returns:
        the new rectangle element

    - #### createG

          public static Element createG(Document doc)

      Create an SVG G.
      Parameters:
        `doc` - the document to create the element
      Returns:
        the new g element

    - #### createClip

          public static Element createClip(Document doc,
                                           Element els,
                                           String id)

      Create an SVG Clip.
      Parameters:
        `doc` - the document to create the element
        `els` - the child elements that make the clip
        `id` - the id of the clipping path
      Returns:
        the new clip element

    - #### createImage

          public static Element createImage(Document doc,
                                            String ref,
                                            float width,
                                            float height)

      Create and svg image element.
      Parameters:
        `doc` - the document to create the element
        `ref` - the href link to the image
        `width` - the width to set on the image
        `height` - the height to set on the image
      Returns:
        a new image element

    - #### wrapText

          public static Element wrapText(Document doc,
                                         String str,
                                         Font font,
                                         float width)

      Create some SVG text that is wrapped into a specified width.
      Parameters:
        `doc` - the document to create the elements
        `str` - the string to wrap
        `font` - the font
        `width` - the width to wrap
      Returns:
        the new element containing the wrapped text

Copyright © 2025 Apache Software Foundation. All rights reserved.