Class ImageSignature

java.lang.Object
com.nsdev.lettergenerator.signature.ImageSignature
All Implemented Interfaces:
SignatureContent

public final class ImageSignature extends Object implements SignatureContent
Immutable PNG/JPEG/static SVG signature part owning a defensive copy of its image bytes. Factories decode the image immediately and preserve its aspect ratio within a 40 by 20 mm box. sizeMm(double, double) creates another fitted part without mutating this one. Placement within the letter is configured on the letter builder.
  • Method Summary

    Modifier and Type
    Method
    Description
    Exposes the ordered immutable blocks represented by this signature part.
    of(byte[] data)
    Copies and decodes image bytes, fitting the aspect ratio inside a 40 by 20 mm box.
    of(Path path)
    Reads and decodes an image immediately, fitting it inside a 40 by 20 mm box.
    sizeMm(double maxWidth, double maxHeight)
    Creates a signature refitted from the original image bytes into the given box.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • of

      public static ImageSignature of(byte[] data)
      Copies and decodes image bytes, fitting the aspect ratio inside a 40 by 20 mm box. The fit can enlarge a small source image as well as reduce a large one.
      Parameters:
      data - non-null readable PNG, JPEG or static SVG image bytes
      Returns:
      a new immutable image signature
      Throws:
      IllegalArgumentException - if bytes are null, unreadable, or not PNG/JPEG/static SVG
    • of

      public static ImageSignature of(Path path) throws IOException
      Reads and decodes an image immediately, fitting it inside a 40 by 20 mm box. The resulting signature no longer depends on the file.
      Parameters:
      path - non-null PNG, JPEG or static SVG file path
      Returns:
      a new immutable image signature
      Throws:
      IOException - if the file cannot be read
      NullPointerException - if path is null
      IllegalArgumentException - if file bytes are not a readable PNG, JPEG or static SVG image
    • sizeMm

      public ImageSignature sizeMm(double maxWidth, double maxHeight)
      Creates a signature refitted from the original image bytes into the given box. The aspect ratio is preserved, so at least one resulting dimension may be smaller than the box. This operation may enlarge the image; it does not mutate this signature.
      Parameters:
      maxWidth - finite positive maximum width in millimeters
      maxHeight - finite positive maximum height in millimeters
      Returns:
      a new fitted immutable image signature
      Throws:
      IllegalArgumentException - if either dimension is nonpositive or nonfinite
    • blocks

      public List<Block> blocks()
      Exposes the ordered immutable blocks represented by this signature part. Text parts produce paragraphs; image parts produce one fitted image block.
      Specified by:
      blocks in interface SignatureContent
      Returns:
      immutable signature blocks, in display order