Package com.pdftools.geometry.units
Class Size
- java.lang.Object
-
- com.pdftools.geometry.units.Size
-
public class Size extends java.lang.Object
Class that represents a size that is based on a width and height of type
Length
.Constructs from standard paper sizes, generates a string representation, and provides conversions to portrait and landscape mode.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Size.PaperSizes
-
Constructor Summary
Constructors Constructor Description Size(double width, double height, Length.Units unit)
ConstructSize
object from width, height and a common unit.Size(Length width, Length height)
ConstructSize
object from width and height.Size(Size.PaperSizes paperSize)
Construct aSize
object from standard paper sizes defined in enumSize.PaperSizes
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
double
getAspectRatio()
Calculate ratio between height and width.Length
getHeight()
Gets the height (vertical size) asLength
object.Length
getWidth()
Gets the width (horizontal size) asLength
object.int
hashCode()
static Size
parse(java.lang.String value)
Create aSize
object from a string representation.Size
toLandscape()
Switches width and height if the absolute value of height is greater than the the absolute value of width.Size
toPortrait()
Switches width and height if the absolute value of the width is greater than the absolute value of the height.java.lang.String
toString()
Creates a string representation as width-height-pair with associated suitable metric units, "m", "cm" or "mm".java.lang.String
toString(Length.Units unit)
Creates a string representation as width-height-pair with the specified unit.
-
-
-
Constructor Detail
-
Size
public Size(double width, double height, Length.Units unit)
ConstructSize
object from width, height and a common unit.- Parameters:
width
- as numerical valueheight
- as numerical valueunit
- the unit
-
Size
public Size(Size.PaperSizes paperSize)
Construct aSize
object from standard paper sizes defined in enumSize.PaperSizes
.- Parameters:
paperSize
- enumeration item e.g.Size.PaperSizes.A4
, orSize.PaperSizes.LETTER
.
-
-
Method Detail
-
parse
public static Size parse(java.lang.String value)
Create a
Size
object from a string representation.Allowed are value-unit pairs of the form "<width_value><width_unit> <height_value><height_unit>" or the name of a standard paper size.
Examples: "12.3cm 23.9mm" or "A4"
- Parameters:
value
- the string value- Returns:
-
toString
public java.lang.String toString()
Creates a string representation as width-height-pair with associated suitable metric units, "m", "cm" or "mm".- Overrides:
toString
in classjava.lang.Object
-
toString
public java.lang.String toString(Length.Units unit)
Creates a string representation as width-height-pair with the specified unit.
-
toPortrait
public Size toPortrait()
Switches width and height if the absolute value of the width is greater than the absolute value of the height.
-
toLandscape
public Size toLandscape()
Switches width and height if the absolute value of height is greater than the the absolute value of width.
-
getAspectRatio
public double getAspectRatio()
Calculate ratio between height and width.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-