Record Class ImageWatermark
java.lang.Object
java.lang.Record
com.nsdev.lettergenerator.model.watermark.ImageWatermark
- Record Components:
data- encoded PNG/JPEG/static SVG bytes, required during generationmimeType- exact supported MIME type,image/png,image/jpegorimage/svg+xmlwidthMm- image fitting-box width in millimeters; required and positive during generationheightMm- image fitting-box height in millimeters; required and positive during generationpages- page selection, required during generationopacity- finite paint opacity between zero and one, required during generationrotationDegrees- finite counterclockwise angle in degrees, required during generation
- All Implemented Interfaces:
Watermark
public record ImageWatermark(byte[] data, String mimeType, Double widthMm, Double heightMm, PageSelector pages, Double opacity, Double rotationDegrees)
extends Record
implements Watermark
PNG/JPEG/static SVG image centered behind selected physical pages, with its aspect ratio
preserved inside the supplied millimeter box. Watermark position is independent of page margins.
Opacity ranges from zero to one; positive rotation turns counterclockwise about page center in
PDF coordinates.
The constructor copies image bytes but does not decode them or default null properties. Generation checks the MIME type, signature, decodability, positive finite box dimensions, page selection, opacity, and finite rotation. Factories detect image format and provide complete defaults. Stored bytes are protected by defensive copies on construction and access; equality and hashing compare their contents.
-
Constructor Summary
ConstructorsConstructorDescriptionImageWatermark(byte[] data, String mimeType, Double widthMm, Double heightMm, PageSelector pages, Double opacity, Double rotationDegrees) Defensively copies the encoded bytes. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]data()Returns a defensive copy of the encoded image.booleanCompares image byte contents and every other record component.inthashCode()Hashes byte contents and every other record component consistently with equality.heightMm()Returns the value of theheightMmrecord component.mimeType()Returns the value of themimeTyperecord component.static ImageWatermarkof(byte[] data) Decodes supplied image bytes, detects PNG/JPEG/static SVG format, and proportionally fits the image within an 80 by 40 mm box.static ImageWatermarkReads a local image and creates the same fitted default watermark asof(byte[]).opacity()Returns the value of theopacityrecord component.pages()Returns the value of thepagesrecord component.Returns the value of therotationDegreesrecord component.final StringtoString()Returns a string representation of this record class.widthMm()Returns the value of thewidthMmrecord component.
-
Constructor Details
-
ImageWatermark
public ImageWatermark(byte[] data, String mimeType, Double widthMm, Double heightMm, PageSelector pages, Double opacity, Double rotationDegrees) Defensively copies the encoded bytes. Other components, including nulls, are stored unchanged and validated during generation.- Parameters:
data- bytes to clone, or nullmimeType- declared image formatwidthMm- fitting-box width in millimetersheightMm- fitting-box height in millimeterspages- page selectionopacity- paint opacity from zero to onerotationDegrees- counterclockwise rotation in degrees
-
-
Method Details
-
of
Decodes supplied image bytes, detects PNG/JPEG/static SVG format, and proportionally fits the image within an 80 by 40 mm box. The result selects all pages with opacity 0.12 and zero rotation. Unlike direct record construction, this factory validates image readability.- Parameters:
data- encoded image bytes, copied before decoding- Returns:
- watermark with fitted dimensions and default page/paint settings
- Throws:
IllegalArgumentException- if data is null, unreadable, or not supported PNG/JPEG/static SVG
-
of
Reads a local image and creates the same fitted default watermark asof(byte[]). The file is fully read before the watermark is returned.- Parameters:
path- local PNG/JPEG/static SVG file- Returns:
- watermark fitted within 80 by 40 mm, on all pages, with opacity 0.12 and no rotation
- Throws:
IOException- if the image file cannot be readNullPointerException- if path is nullIllegalArgumentException- if the file is not a readable supported PNG/JPEG/static SVG
-
data
public byte[] data()Returns a defensive copy of the encoded image.- Returns:
- a new byte array, or null when no bytes were supplied
-
equals
Compares image byte contents and every other record component. -
hashCode
public int hashCode()Hashes byte contents and every other record component consistently with equality. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
mimeType
Returns the value of themimeTyperecord component.- Returns:
- the value of the
mimeTyperecord component
-
widthMm
Returns the value of thewidthMmrecord component.- Returns:
- the value of the
widthMmrecord component
-
heightMm
Returns the value of theheightMmrecord component.- Returns:
- the value of the
heightMmrecord component
-
pages
Returns the value of thepagesrecord component. -
opacity
Returns the value of theopacityrecord component. -
rotationDegrees
Returns the value of therotationDegreesrecord component.- Specified by:
rotationDegreesin interfaceWatermark- Returns:
- the value of the
rotationDegreesrecord component
-