Package ro.sync.ecss.css
Class RelativeLength
java.lang.Object
ro.sync.ecss.css.RelativeLength
A length that may be expressed as an absolute or relative value, or as an "auto" value, that
is to be computed at later time, by the layout engine.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RelativeLength
createAbsolute
(int value) Create an absolute value length.static RelativeLength
createAbsolute
(org.w3c.css.sac.LexicalUnit lu, float fontSize, ro.sync.ecss.css.LexicalUnitEvaluator evaluator) Create an absolute value length.static RelativeLength
Create an automatic relative length.static RelativeLength
createRelative
(float percentage) Create a relative length representing a relative value.static RelativeLength
createRelativeOrCalc
(org.w3c.css.sac.LexicalUnit lu, float fontSize, ro.sync.ecss.css.LexicalUnitEvaluator evaluator) Create a relative length representing a relative value, like a percent, or a calc expression.boolean
int
get
(int referenceLength) Return the evaluated value of the RelativeLength given a reference value.float
getValue()
int
hashCode()
boolean
boolean
isAuto()
boolean
isCalc()
boolean
toString()
-
Constructor Details
-
RelativeLength
protected RelativeLength(float value, byte type) Constructor- Parameters:
value
- The absolute or percentage value.type
- Indicates if the value is absolute, relative or "auto".
-
-
Method Details
-
createAbsolute
Create an absolute value length.- Parameters:
value
- The value of the absolute length.- Returns:
- The new absolute value RelativeLength.
-
createRelative
Create a relative length representing a relative value.- Parameters:
percentage
- The percentage from the value this length will refer to. (e.g: 50%)- Returns:
- The new relative value RelativeLength.
-
createAuto
Create an automatic relative length. This is just an immutable constant marker.- Returns:
- The "auto" relative length. Always the same object.
-
get
public int get(int referenceLength) Return the evaluated value of the RelativeLength given a reference value. If this object represents an absolute value, that value is simply returned. Otherwise, returns the given reference length multiplied by the given percentage divided to 100 and rounded to the nearest integer, or maybe a calculated expression.- Parameters:
referenceLength
- Reference length for percentage lengths.- Returns:
- The actual value.
-
hashCode
public int hashCode() -
equals
-
getLengthRepr
- Returns:
- a string representing the equivalent CSS expression.
-
toString
-
isAuto
public boolean isAuto()- Returns:
- True if the relative length is automatic.
-
isRelative
public boolean isRelative()- Returns:
- True if the length is relative.
-
isAbsolute
public boolean isAbsolute()- Returns:
- True if the length is absolute.
-
getValue
public float getValue()- Returns:
- The value of the absolute length or the percentage of a relative length.
-
isCalc
public boolean isCalc()- Returns:
- True if the length is a calculated value.
-
createAbsolute
public static RelativeLength createAbsolute(org.w3c.css.sac.LexicalUnit lu, float fontSize, ro.sync.ecss.css.LexicalUnitEvaluator evaluator) Create an absolute value length.- Parameters:
lu
- The value of the absolute length.fontSize
- the size of the font, used to solve ems.evaluator
- The evaluator, used to solve rems, pc, pt, in, cm.- Returns:
- The new absolute value RelativeLength.
-
createRelativeOrCalc
public static RelativeLength createRelativeOrCalc(org.w3c.css.sac.LexicalUnit lu, float fontSize, ro.sync.ecss.css.LexicalUnitEvaluator evaluator) Create a relative length representing a relative value, like a percent, or a calc expression.- Parameters:
lu
- The percentage from the value this length will refer to. (e.g: 50%) or a calc expression (e.g 50% - 3pt).fontSize
- The element font size. This is used to solve em's.evaluator
- The lexical unit evaluator. This is used to solve rem's, pt's, and othersizes.- Returns:
- The new relative value RelativeLength.
-