units
New in version 0.9.0.
Contents
- class ooodev.units.Angle(value)[source]
Represents an angle value from
0
to359
.All input integers are converted into a positive angle.
Example
>>> print(Angle(360)) Angle(Value=0) >>> print(Angle(413)) Angle(Value=53) >>> print(Angle(-235)) Angle(Value=125) >>> print(Angle(1794)) Angle(Value=354)
Changed in version 0.8.1: Now will accept any integer value, negative or positive.
- Parameters:
value (int) –
- __init__(value)
- Parameters:
value (int) –
- Return type:
None
- static from_angle(value)[source]
Get an angle from
degree
units.- Parameters:
value (int) – Angle in
degree
units.- Return type:
- static from_angle10(value)[source]
Get an angle from
1/10 degree
units.- Parameters:
value (int) – Angle in
1/10 degree
units.- Return type:
- static from_angle100(value)[source]
Get an angle from
1/100 degree
units.- Parameters:
value (int) – Angle in
1/10 degree
units.- Return type:
- classmethod from_unit_val(value)[source]
Get instance from
Angle
or int value.- Parameters:
value (Angle, int) –
Angle
or int value. If int then it is assumed to be in degrees.- Return type:
New in version 0.32.0.
- value: int
Int value.
- class ooodev.units.Angle10(value)[source]
Represents an angle value from
0
to3599
.All input integers are converted into a positive angle.
Example
>>> print(Angle10(3600)) Angle10(Value=0) >>> print(Angle10(4130)) Angle10(Value=530) >>> print(Angle10(-2350)) Angle10(Value=1250) >>> print(Angle10(17940)) Angle10(Value=3540)
New in version 0.17.4.
- Parameters:
value (int) –
- __init__(value)
- Parameters:
value (int) –
- Return type:
None
- static from_angle(value)[source]
Get an angle from
degree
units.- Parameters:
value (int) – Angle10 in
degree
units.- Return type:
- static from_angle10(value)[source]
Get an angle from
1/10 degree
units.- Parameters:
value (int) – Angle10 in
1/10 degree
units.- Return type:
- static from_angle100(value)[source]
Get an angle from
1/100 degree
units.- Parameters:
value (int) – Angle10 in
1/10 degree
units.- Return type:
- classmethod from_unit_val(value)[source]
Get instance from
Angle10
or int value.- Parameters:
value (Angle10, int) –
Angle10
or int value. If int then it is assumed to be in1/10th
degrees.- Return type:
New in version 0.32.0.
- value: int
Int value.
- class ooodev.units.Angle100(value)[source]
Represents an angle value from
0
to35999
in1/100 units
.All input integers are converted into a positive angle.
Example
>>> print(Angle100(36000)) Angle100(Value=0) >>> print(Angle(41300)) Angle100(Value=5300) >>> print(Angle(-23500)) Angle(Value=12500) >>> Angle100(Angle(179400)) Angle(Value=35400)
New in version 0.17.4.
- Parameters:
value (int) –
- __init__(value)
- Parameters:
value (int) –
- Return type:
None
- static from_angle(value)[source]
Get an angle from
degree
units.- Parameters:
value (int) – Angle in
degree
units.- Return type:
- static from_angle10(value)[source]
Get an angle from
1/10 degree
units.- Parameters:
value (int) – Angle in
1/10 degree
units.- Return type:
- static from_angle100(value)[source]
Get an angle from
1/100 degree
units.- Parameters:
value (int) – Angle in
1/100 degree
units.- Return type:
- classmethod from_unit_val(value)[source]
Get instance from
Angle100
or int value.- Parameters:
value (Angle100, int) –
Angle100
or int value. If int then it is assumed to be in1/100th
degrees.- Return type:
New in version 0.32.0.
- value: int
Int value.
- class ooodev.units.AngleUnitT[source]
Protocol Class for Angle units.
See also
- __init__()
- property value: float | int
Angle actual value. Generally a
float
orint
- Return type:
float | int
- class ooodev.units.AppFontPos(x, y)[source]
A class to represent the application font position.
This class is a container for the
X
andY
application font position units.Note
The
X
andY
units are based on the application font position ratio. This means that theX
andY
units may not not be based on the same unit length.- Parameters:
x (UnitAppFontX) –
y (UnitAppFontY) –
- __init__(x, y)[source]
Constructor
- Parameters:
x (UnitAppFontX) – The X value of the application font position.
y (UnitAppFontY) – The Y value of the application font position.
- Return type:
None
- classmethod from_app_font(x, y)[source]
Creates an instance from
1/100th mm
values.- Parameters:
x (float) – The X value of the application font position.
y (float) – The Y value of the application font position.
- Returns:
An instance of AppFontPos.
- Return type:
- property x: UnitAppFontX
Gets/Sets the
X
unit of the application font position.When setting can be a float or a
UnitT
.- Return type:
- property y: UnitAppFontY
Get/Sets the
Y
unit of the application font position.When setting can be a float or a
UnitT
.- Return type:
- class ooodev.units.AppFontSize(width, height)[source]
A class to represent the application font size.
This class is a container for the
Width
andHeight
application font size units.Note
The
Width
andHeight
units are based on the application font size ratio. This means that theWidth
andHeight
units may not be based on the same unit length.- Parameters:
width (UnitAppFontWidth) –
height (UnitAppFontHeight) –
- __init__(width, height)[source]
Constructor
- Parameters:
width (UnitAppFontWidth) – The
Width
value of the application font size.height (UnitAppFontHeight) – The
Height
value of the application font size.
- Return type:
None
- classmethod from_app_font(x, y)[source]
Creates an instance from
1/100th mm
values.- Parameters:
x (float) – The
Width
value of the application font size.y (float) – The
Height
value of the application font size.
- Returns:
An instance of SizeMM100.
- Return type:
- property height: UnitAppFontHeight
Get/Sets the
Height
unit of the application font size.When setting can be a float or a
UnitT
.- Return type:
- property width: UnitAppFontWidth
Gets/Sets the
Width``
unit of the application font size.When setting can be a float or a
UnitT
.- Return type:
- class ooodev.units.SizeMM100(width, height)[source]
Size Width and Height in
1/100th mm
units.New in version 0.27.0.
- convert_to(unit_length)
Converts current values to specified unit length.
- Parameters:
unit_length (UnitLength) – Unit length to convert to.
- Returns:
Converted Units.
- Return type:
GenericUnitSize[UnitT, Union[int, float]]
- classmethod from_mm100(width, height)[source]
Creates an instance from
1/100th mm
values.- Parameters:
width (int) – Width value as
1/100th mm
.height (int) – Height value as
1/100th mm
.
- Returns:
An instance of SizeMM100.
- Return type:
- get_size()
Gets instance value as Size
- Return type:
GenericSize
[TypeVar
(TNum
, bound=Union
[int
,float
])]
- class ooodev.units.SizePX(width, height)[source]
Size Width and Height in
px
units.New in version 0.27.0.
- convert_to(unit_length)
Converts current values to specified unit length.
- Parameters:
unit_length (UnitLength) – Unit length to convert to.
- Returns:
Converted Units.
- Return type:
GenericUnitSize[UnitT, Union[int, float]]
- classmethod from_px(width, height)[source]
Creates an instance from
px
values.- Parameters:
width (float) – Width value as
px
.height (float) – Height value as
px
.
- Returns:
An instance of SizePX.
- Return type:
- get_size()
Gets instance value as Size
- Return type:
GenericSize
[TypeVar
(TNum
, bound=Union
[int
,float
])]
- class ooodev.units.SizePosMM100(x, y, width, height)[source]
Size and Position in
1/100 mm
units.New in version 0.39.0.
- convert_to(unit_length)
Converts current values to specified unit length.
- Parameters:
unit_length (UnitLength) – Unit length to convert to.
- Returns:
Converted Units.
- Return type:
GenericUnitSize[UnitT, Union[int, float]]
- classmethod from_unit_val(x, y, width, height)[source]
Get instance from
UnitT
or float value.- Parameters:
x (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be in1/100 mm
units.y (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be in1/100 mm
units.width (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be in1/100 mm
units.height (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be in1/100 mm
units.
- Return type:
- get_size_pos()
Gets instance value as Size
- Return type:
GenericSizePos
[TypeVar
(TNum
, bound=Union
[int
,float
])]
- get_uno_point_size()
Gets current values as Point and Size
- get_uno_rectangle()
Gets current values as Rectangle
- Returns:
UNO Rectangle.
- Return type:
Rectangle
- class ooodev.units.SizePosPX(x, y, width, height)[source]
Size and Position in
px
units.New in version 0.39.0.
- convert_to(unit_length)
Converts current values to specified unit length.
- Parameters:
unit_length (UnitLength) – Unit length to convert to.
- Returns:
Converted Units.
- Return type:
GenericUnitSize[UnitT, Union[int, float]]
- classmethod from_unit_val(x, y, width, height)[source]
Get instance from
UnitT
or float value.- Parameters:
x (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be inpx
units.y (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be inpx
units.width (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be inpx
units.height (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be inpx
units.
- Return type:
- get_size_pos()
Gets instance value as Size
- Return type:
GenericSizePos
[TypeVar
(TNum
, bound=Union
[int
,float
])]
- get_uno_point_size()
Gets current values as Point and Size
- get_uno_rectangle()
Gets current values as Rectangle
- Returns:
UNO Rectangle.
- Return type:
Rectangle
- class ooodev.units.UnitAppFontHeight(value)[source]
Unit in
AppFont
units.Supports
UnitT
protocol.Warning
Although this class support
UnitT
protocol,get_unit_length()
method returnsUnitLength.INVALID
.Note
Unlike most other units in this module, this unit is not based on
UnitLength
. This means that it does not have a validUnitLength
value and returnsUnitLength.INVALID
.This unit require that the application font pixel ratio be set before it can be used. Which means office must be loaded before this unit can be used.
See also
- Parameters:
value (float) –
- __init__(value)
- Parameters:
value (float) –
- Return type:
None
- almost_equal(val, epsilon=1e-09)
Comparing float values directly using equality (
==
) can sometimes lead to unexpected results due to the way floating-point numbers are represented in computers. A small rounding error can make two floats that should be equal appear unequal.A common way to compare floats is to check if the absolute difference between them is less than a small number, often called the machine epsilon.
In this function,
epsilon
is the maximum difference for whicha
andb
are considered equal. You can adjustepsilon
based on the precision you need.- Parameters:
val (float) – The value to compare with.
epsilon (float) – The maximum difference for which
a
andb
are considered equal.
- Returns:
True if current value and
val
are considered equal, False otherwise.- Return type:
bool
- convert_to(unit)
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
Hint
UnitLength
can be imported fromooodev.units
.
- classmethod from_app_font(value, kind=None)
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use. This is not used in the context ofAppFont
units.
- Return type:
Self
- classmethod from_cm(value)
Get instance from
cm
value.- Parameters:
value (int) –
cm
value.- Return type:
Self
- classmethod from_inch(value)
Get instance from
in
(inch) value.- Parameters:
value (int) –
in
value.- Return type:
Self
- classmethod from_inch10(value)
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
1/10th in
value.- Return type:
Self
- classmethod from_inch100(value)
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
Self
- classmethod from_inch1000(value)
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
Self
- classmethod from_mm(value)
Get instance from
mm
value.- Parameters:
value (int) –
mm
value.- Return type:
Self
- classmethod from_mm10(value)
Get instance from
1/10th mm
value.- Parameters:
value (int) –
1/10th mm
value.- Return type:
Self
- classmethod from_mm100(value)
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
Self
- classmethod from_pt(value)
Get instance from
pt
(points) value.- Parameters:
value (float) –
pt
value.- Return type:
Self
- classmethod from_px(value)
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
Self
- classmethod from_unit_val(value)
Get instance from
UnitT
or float value.- Parameters:
value (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be inmm
units.- Return type:
Self
- get_app_font_kind()[source]
Gets the kind of the unit.
- Returns:
Returns
PointSizeKind.HEIGHT
- Return type:
- static get_unit_length()
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.INVALID
.- Return type:
- get_value_app_font(kind=None)
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (Any): Ignored in the context ofAppFont
units. It is used in other units.- Return type:
float
- Parameters:
kind (Any | None) –
- get_value_cm()
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
float
- get_value_inch()
Gets instance value in
in
(inch) units.- Returns:
Value in
in
units.- Return type:
float
- get_value_inch10()
Gets instance value in
1/10th inch
units.- Returns:
Value in
1/10th inch
units.- Return type:
int
- get_value_inch100()
Gets instance value in
1/100th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_inch1000()
Gets instance value in
1/1000th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_mm()
Gets instance value converted to Size in
mm
units.- Returns:
Value in
mm
units.- Return type:
float
- get_value_mm100()
Gets instance value converted to Size in
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_oth_unit()[source]
Return the Y value of the unit.
- Returns:
The Y value of the unit. This is the value of a
UnitAppFontY
unit.- Return type:
float
- get_value_pt()
Gets instance value converted to Size in
pt
(points) units.- Returns:
Value in
pt
units.- Return type:
float
- get_value_px()
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
float
- value: float
Float value.
- class ooodev.units.UnitAppFontWidth(value)[source]
Unit in
AppFont
units.Supports
UnitT
protocol.Warning
Although this class support
UnitT
protocol,get_unit_length()
method returnsUnitLength.INVALID
.Note
Unlike most other units in this module, this unit is not based on
UnitLength
. This means that it does not have a validUnitLength
value and returnsUnitLength.INVALID
.This unit require that the application font pixel ratio be set before it can be used. Which means office must be loaded before this unit can be used.
See also
- Parameters:
value (float) –
- __init__(value)
- Parameters:
value (float) –
- Return type:
None
- almost_equal(val, epsilon=1e-09)
Comparing float values directly using equality (
==
) can sometimes lead to unexpected results due to the way floating-point numbers are represented in computers. A small rounding error can make two floats that should be equal appear unequal.A common way to compare floats is to check if the absolute difference between them is less than a small number, often called the machine epsilon.
In this function,
epsilon
is the maximum difference for whicha
andb
are considered equal. You can adjustepsilon
based on the precision you need.- Parameters:
val (float) – The value to compare with.
epsilon (float) – The maximum difference for which
a
andb
are considered equal.
- Returns:
True if current value and
val
are considered equal, False otherwise.- Return type:
bool
- convert_to(unit)
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
Hint
UnitLength
can be imported fromooodev.units
.
- classmethod from_app_font(value, kind=None)
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use. This is not used in the context ofAppFont
units.
- Return type:
Self
- classmethod from_cm(value)
Get instance from
cm
value.- Parameters:
value (int) –
cm
value.- Return type:
Self
- classmethod from_inch(value)
Get instance from
in
(inch) value.- Parameters:
value (int) –
in
value.- Return type:
Self
- classmethod from_inch10(value)
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
1/10th in
value.- Return type:
Self
- classmethod from_inch100(value)
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
Self
- classmethod from_inch1000(value)
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
Self
- classmethod from_mm(value)
Get instance from
mm
value.- Parameters:
value (int) –
mm
value.- Return type:
Self
- classmethod from_mm10(value)
Get instance from
1/10th mm
value.- Parameters:
value (int) –
1/10th mm
value.- Return type:
Self
- classmethod from_mm100(value)
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
Self
- classmethod from_pt(value)
Get instance from
pt
(points) value.- Parameters:
value (float) –
pt
value.- Return type:
Self
- classmethod from_px(value)
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
Self
- classmethod from_unit_val(value)
Get instance from
UnitT
or float value.- Parameters:
value (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be inmm
units.- Return type:
Self
- get_app_font_kind()[source]
Gets the kind of the unit.
- Returns:
Returns
PointSizeKind.WIDTH
- Return type:
- static get_unit_length()
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.INVALID
.- Return type:
- get_value_app_font(kind=None)
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (Any): Ignored in the context ofAppFont
units. It is used in other units.- Return type:
float
- Parameters:
kind (Any | None) –
- get_value_cm()
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
float
- get_value_inch()
Gets instance value in
in
(inch) units.- Returns:
Value in
in
units.- Return type:
float
- get_value_inch10()
Gets instance value in
1/10th inch
units.- Returns:
Value in
1/10th inch
units.- Return type:
int
- get_value_inch100()
Gets instance value in
1/100th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_inch1000()
Gets instance value in
1/1000th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_mm()
Gets instance value converted to Size in
mm
units.- Returns:
Value in
mm
units.- Return type:
float
- get_value_mm100()
Gets instance value converted to Size in
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_oth_unit()[source]
Return the Y value of the unit.
- Returns:
The Y value of the unit. This is the value of a
UnitAppFontY
unit.- Return type:
float
- get_value_pt()
Gets instance value converted to Size in
pt
(points) units.- Returns:
Value in
pt
units.- Return type:
float
- get_value_px()
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
float
- value: float
Float value.
- class ooodev.units.UnitAppFontX(value)[source]
Unit in
AppFont
units.Supports
UnitT
protocol.Warning
Although this class support
UnitT
protocol,get_unit_length()
method returnsUnitLength.INVALID
.Note
Unlike most other units in this module, this unit is not based on
UnitLength
. This means that it does not have a validUnitLength
value and returnsUnitLength.INVALID
.This unit require that the application font pixel ratio be set before it can be used. Which means office must be loaded before this unit can be used.
See also
- Parameters:
value (float) –
- __init__(value)
- Parameters:
value (float) –
- Return type:
None
- almost_equal(val, epsilon=1e-09)
Comparing float values directly using equality (
==
) can sometimes lead to unexpected results due to the way floating-point numbers are represented in computers. A small rounding error can make two floats that should be equal appear unequal.A common way to compare floats is to check if the absolute difference between them is less than a small number, often called the machine epsilon.
In this function,
epsilon
is the maximum difference for whicha
andb
are considered equal. You can adjustepsilon
based on the precision you need.- Parameters:
val (float) – The value to compare with.
epsilon (float) – The maximum difference for which
a
andb
are considered equal.
- Returns:
True if current value and
val
are considered equal, False otherwise.- Return type:
bool
- convert_to(unit)
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
Hint
UnitLength
can be imported fromooodev.units
.
- classmethod from_app_font(value, kind=None)
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use. This is not used in the context ofAppFont
units.
- Return type:
Self
- classmethod from_cm(value)
Get instance from
cm
value.- Parameters:
value (int) –
cm
value.- Return type:
Self
- classmethod from_inch(value)
Get instance from
in
(inch) value.- Parameters:
value (int) –
in
value.- Return type:
Self
- classmethod from_inch10(value)
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
1/10th in
value.- Return type:
Self
- classmethod from_inch100(value)
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
Self
- classmethod from_inch1000(value)
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
Self
- classmethod from_mm(value)
Get instance from
mm
value.- Parameters:
value (int) –
mm
value.- Return type:
Self
- classmethod from_mm10(value)
Get instance from
1/10th mm
value.- Parameters:
value (int) –
1/10th mm
value.- Return type:
Self
- classmethod from_mm100(value)
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
Self
- classmethod from_pt(value)
Get instance from
pt
(points) value.- Parameters:
value (float) –
pt
value.- Return type:
Self
- classmethod from_px(value)
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
Self
- classmethod from_unit_val(value)
Get instance from
UnitT
or float value.- Parameters:
value (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be inmm
units.- Return type:
Self
- get_app_font_kind()[source]
Gets the kind of the unit.
- Returns:
Returns
PointSizeKind.X
- Return type:
- static get_unit_length()
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.INVALID
.- Return type:
- get_value_app_font(kind=None)
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (Any): Ignored in the context ofAppFont
units. It is used in other units.- Return type:
float
- Parameters:
kind (Any | None) –
- get_value_cm()
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
float
- get_value_inch()
Gets instance value in
in
(inch) units.- Returns:
Value in
in
units.- Return type:
float
- get_value_inch10()
Gets instance value in
1/10th inch
units.- Returns:
Value in
1/10th inch
units.- Return type:
int
- get_value_inch100()
Gets instance value in
1/100th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_inch1000()
Gets instance value in
1/1000th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_mm()
Gets instance value converted to Size in
mm
units.- Returns:
Value in
mm
units.- Return type:
float
- get_value_mm100()
Gets instance value converted to Size in
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_oth_unit()[source]
Return the Y value of the unit.
- Returns:
The Y value of the unit. This is the value of a
UnitAppFontY
unit.- Return type:
float
- get_value_pt()
Gets instance value converted to Size in
pt
(points) units.- Returns:
Value in
pt
units.- Return type:
float
- get_value_px()
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
float
- value: float
Float value.
- class ooodev.units.UnitAppFontY(value)[source]
Unit in
AppFont
units.Supports
UnitT
protocol.Warning
Although this class support
UnitT
protocol,get_unit_length()
method returnsUnitLength.INVALID
.Note
Unlike most other units in this module, this unit is not based on
UnitLength
. This means that it does not have a validUnitLength
value and returnsUnitLength.INVALID
.This unit require that the application font pixel ratio be set before it can be used. Which means office must be loaded before this unit can be used.
See also
- Parameters:
value (float) –
- __init__(value)
- Parameters:
value (float) –
- Return type:
None
- almost_equal(val, epsilon=1e-09)
Comparing float values directly using equality (
==
) can sometimes lead to unexpected results due to the way floating-point numbers are represented in computers. A small rounding error can make two floats that should be equal appear unequal.A common way to compare floats is to check if the absolute difference between them is less than a small number, often called the machine epsilon.
In this function,
epsilon
is the maximum difference for whicha
andb
are considered equal. You can adjustepsilon
based on the precision you need.- Parameters:
val (float) – The value to compare with.
epsilon (float) – The maximum difference for which
a
andb
are considered equal.
- Returns:
True if current value and
val
are considered equal, False otherwise.- Return type:
bool
- convert_to(unit)
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
Hint
UnitLength
can be imported fromooodev.units
.
- classmethod from_app_font(value, kind=None)
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use. This is not used in the context ofAppFont
units.
- Return type:
Self
- classmethod from_cm(value)
Get instance from
cm
value.- Parameters:
value (int) –
cm
value.- Return type:
Self
- classmethod from_inch(value)
Get instance from
in
(inch) value.- Parameters:
value (int) –
in
value.- Return type:
Self
- classmethod from_inch10(value)
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
1/10th in
value.- Return type:
Self
- classmethod from_inch100(value)
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
Self
- classmethod from_inch1000(value)
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
Self
- classmethod from_mm(value)
Get instance from
mm
value.- Parameters:
value (int) –
mm
value.- Return type:
Self
- classmethod from_mm10(value)
Get instance from
1/10th mm
value.- Parameters:
value (int) –
1/10th mm
value.- Return type:
Self
- classmethod from_mm100(value)
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
Self
- classmethod from_pt(value)
Get instance from
pt
(points) value.- Parameters:
value (float) –
pt
value.- Return type:
Self
- classmethod from_px(value)
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
Self
- classmethod from_unit_val(value)
Get instance from
UnitT
or float value.- Parameters:
value (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be inmm
units.- Return type:
Self
- get_app_font_kind()[source]
Gets the kind of the unit.
- Returns:
Returns
PointSizeKind.Y
- Return type:
- static get_unit_length()
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.INVALID
.- Return type:
- get_value_app_font(kind=None)
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (Any): Ignored in the context ofAppFont
units. It is used in other units.- Return type:
float
- Parameters:
kind (Any | None) –
- get_value_cm()
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
float
- get_value_inch()
Gets instance value in
in
(inch) units.- Returns:
Value in
in
units.- Return type:
float
- get_value_inch10()
Gets instance value in
1/10th inch
units.- Returns:
Value in
1/10th inch
units.- Return type:
int
- get_value_inch100()
Gets instance value in
1/100th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_inch1000()
Gets instance value in
1/1000th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_mm()
Gets instance value converted to Size in
mm
units.- Returns:
Value in
mm
units.- Return type:
float
- get_value_mm100()
Gets instance value converted to Size in
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_oth_unit()[source]
Return the X value of the unit.
- Returns:
The X value of the unit. This is the value of a
UnitAppFontX
unit.- Return type:
float
- get_value_pt()
Gets instance value converted to Size in
pt
(points) units.- Returns:
Value in
pt
units.- Return type:
float
- get_value_px()
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
float
- value: float
Float value.
- class ooodev.units.UnitCM(value)[source]
Unit in
cm
units.Supports
UnitT
protocol.See also
New in version 0.9.4.
- Parameters:
value (float) –
- __init__(value)
- Parameters:
value (float) –
- Return type:
None
- almost_equal(val, epsilon=1e-09)
Comparing float values directly using equality (
==
) can sometimes lead to unexpected results due to the way floating-point numbers are represented in computers. A small rounding error can make two floats that should be equal appear unequal.A common way to compare floats is to check if the absolute difference between them is less than a small number, often called the machine epsilon.
In this function,
epsilon
is the maximum difference for whicha
andb
are considered equal. You can adjustepsilon
based on the precision you need.- Parameters:
val (float) – The value to compare with.
epsilon (float) – The maximum difference for which
a
andb
are considered equal.
- Returns:
True if current value and
val
are considered equal, False otherwise.- Return type:
bool
- convert_to(unit)[source]
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
- classmethod from_app_font(value, kind)[source]
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use.
- Return type:
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- classmethod from_cm(value)[source]
Get instance from
cm
value.- Parameters:
value (float) –
cm
value.- Return type:
- classmethod from_inch(value)[source]
Get instance from
in
(inch) value.- Parameters:
value (int) –
in
value.- Return type:
- classmethod from_inch10(value)[source]
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
`/10th in
value.- Return type:
- classmethod from_inch100(value)[source]
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
- classmethod from_inch1000(value)[source]
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
- classmethod from_mm(value)[source]
Get instance from
mm
value.- Parameters:
value (int) –
mm
value.- Return type:
- classmethod from_mm10(value)[source]
Get instance from
1/10th mm
value.- Parameters:
value (int) –
1/10th mm
value.- Return type:
- classmethod from_mm100(value)[source]
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
- classmethod from_pt(value)[source]
Get instance from
pt
(points) value.- Parameters:
value (float) –
pt
value.- Return type:
- classmethod from_px(value)[source]
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
- static get_unit_length()[source]
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.CM
.- Return type:
- get_value_app_font(kind)[source]
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (PointSizeKind, optional): The kind ofAppFont
to use.- Return type:
float
- Parameters:
kind (PointSizeKind | int) –
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- get_value_cm()[source]
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
int
- get_value_inch()[source]
Gets instance value in
in
(inch) units.- Returns:
Value in
in
units.- Return type:
float
- get_value_inch10()[source]
Gets instance value in
1/10th inch
units.- Returns:
Value in
1/10th inch
units.- Return type:
int
- get_value_inch100()[source]
Gets instance value in
1/100th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_inch1000()[source]
Gets instance value in
1/1000th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_mm()[source]
Gets instance value converted to
mm
units.- Returns:
Value in
mm
units.- Return type:
int
- get_value_mm100()[source]
Gets instance value converted to
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_pt()[source]
Gets instance value converted to
pt
(points) units.- Returns:
Value in
pt
units.- Return type:
int
- get_value_px()[source]
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
int
- value: float
Float value.
- class ooodev.units.UnitConvert[source]
- __init__()
- static asserting_gcd(m, n)[source]
Find the greatest common divisor of the two integers
- Parameters:
m (int) – The first integer to find the GCD for
n (int) – The second integer to find the GCD for
- Raises:
AssertionError – If GCD result equals
0
.- Returns:
A value, representing the greatest common divisor (GCD) for two integers
- Return type:
int
- classmethod convert(num: int | float, frm: ooodev.units.unit_convert.UnitLength, to: ooodev.units.unit_convert.UnitLength) float [source]
- classmethod convert(num: int | float, frm: int, to: int) float
- classmethod convert(num, frm, to)
Converts a number from one unit to another unit.
- Parameters:
num (N) – Number to convert such as a
float
orint
.frm (int | Length) – Current number kind.
to (int | Length) – Kind to convert to.
- Returns:
Converted number
- Return type:
float
Note
If
Length
is not used thenmul_div()
is called directly.
- classmethod convert_mm100_mm(num)[source]
Converts
mm
to1/100th mm
- Parameters:
num (N) – Number to convert
- Returns:
Converted number
- Return type:
float
- classmethod convert_mm100_pt(num)[source]
Converts
1/100th mm
to points- Parameters:
num (N) – Number to convert
- Returns:
Converted number
- Return type:
float
- classmethod convert_mm_mm100(num)[source]
Converts
1/100th mm
tomm
- Parameters:
num (N) – Number to convert
- Returns:
Converted number
- Return type:
float
- classmethod convert_pt_mm100(num)[source]
Converts points to
1/100th mm
- Parameters:
num (N) – Number to convert
- Returns:
Converted number
- Return type:
float
- classmethod convert_twip_mm100(num)[source]
Converts twips to
1/100th mm
- Parameters:
num (N) – Number to convert
- Returns:
Converted number
- Return type:
float
- static make_unsigned(num)[source]
Gets unsigned number
- Parameters:
num (N) – Number
- Raises:
AssertionError – If
num
is a negative number.- Returns:
Value of
num
if positive number.- Return type:
N
- class ooodev.units.UnitInch(value)[source]
Unit in
inch
units.Supports
UnitT
protocol.See also
- Parameters:
value (float) –
- __init__(value)
- Parameters:
value (float) –
- Return type:
None
- almost_equal(val, epsilon=1e-09)
Comparing float values directly using equality (
==
) can sometimes lead to unexpected results due to the way floating-point numbers are represented in computers. A small rounding error can make two floats that should be equal appear unequal.A common way to compare floats is to check if the absolute difference between them is less than a small number, often called the machine epsilon.
In this function,
epsilon
is the maximum difference for whicha
andb
are considered equal. You can adjustepsilon
based on the precision you need.- Parameters:
val (float) – The value to compare with.
epsilon (float) – The maximum difference for which
a
andb
are considered equal.
- Returns:
True if current value and
val
are considered equal, False otherwise.- Return type:
bool
- convert_to(unit)[source]
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
- classmethod from_app_font(value, kind)[source]
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use.
- Return type:
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- classmethod from_cm(value)[source]
Get instance from
cm
value.- Parameters:
value (float) –
cm
value.- Return type:
- classmethod from_inch(value)[source]
Get instance from inch value.
- Parameters:
value (int) – Inch value.
- Return type:
- classmethod from_inch10(value)[source]
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
1/10th in
value.- Return type:
- classmethod from_inch100(value)[source]
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
- classmethod from_inch1000(value)[source]
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
- classmethod from_mm(value)[source]
Get instance from
mm
value.- Parameters:
value (float) –
mm
value.- Return type:
- classmethod from_mm10(value)[source]
Get instance from
1/10th mm
value.- Parameters:
value (int) –
1/10th mm
value.- Return type:
- classmethod from_mm100(value)[source]
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
- classmethod from_pt(value)[source]
Get instance from
pt
(points) value.- Parameters:
value (float) –
pt
value.- Return type:
- classmethod from_px(value)[source]
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
- static get_unit_length()[source]
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.IN
.- Return type:
- get_value_app_font(kind)[source]
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (PointSizeKind, optional): The kind ofAppFont
to use.- Return type:
float
- Parameters:
kind (PointSizeKind | int) –
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- get_value_cm()[source]
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
int
- get_value_inch()[source]
Gets instance value in inch units.
- Returns:
Value in inch units.
- Return type:
float
- get_value_inch10()[source]
Gets instance value in
1/10th inch
units.- Returns:
Value in
1/10th inch
units.- Return type:
float
- get_value_inch100()[source]
Gets instance value in
1/100th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
float
- get_value_inch1000()[source]
Gets instance value in
1/1000th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_mm()[source]
Gets instance value converted to Size in
mm
units.- Returns:
Value in
mm
units.- Return type:
int
- get_value_mm100()[source]
Gets instance value converted to Size in
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_pt()[source]
Gets instance value converted to Size in
pt
(points) units.- Returns:
Value in
pt
units.- Return type:
int
- get_value_px()[source]
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
int
- value: float
Float value.
- class ooodev.units.UnitInch10(value)[source]
Unit in
1/10th in
units.Supports
UnitT
protocol.See also
- Parameters:
value (float) –
- __init__(value)
- Parameters:
value (float) –
- Return type:
None
- almost_equal(val, epsilon=1e-09)
Comparing float values directly using equality (
==
) can sometimes lead to unexpected results due to the way floating-point numbers are represented in computers. A small rounding error can make two floats that should be equal appear unequal.A common way to compare floats is to check if the absolute difference between them is less than a small number, often called the machine epsilon.
In this function,
epsilon
is the maximum difference for whicha
andb
are considered equal. You can adjustepsilon
based on the precision you need.- Parameters:
val (float) – The value to compare with.
epsilon (float) – The maximum difference for which
a
andb
are considered equal.
- Returns:
True if current value and
val
are considered equal, False otherwise.- Return type:
bool
- convert_to(unit)[source]
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
- classmethod from_app_font(value, kind)[source]
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use.
- Return type:
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- classmethod from_cm(value)[source]
Get instance from
cm
value.- Parameters:
value (float) –
cm
value.- Return type:
- classmethod from_in(value)
Get instance from
in
(inch) value.- Parameters:
value (float) –
in
value.- Return type:
- classmethod from_inch(value)[source]
Get instance from
in
(inch) value.- Parameters:
value (float) –
in
value.- Return type:
- classmethod from_inch10(value)[source]
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
1/10th in
value.- Return type:
- classmethod from_inch100(value)[source]
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
- classmethod from_inch1000(value)[source]
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
- classmethod from_mm100(value)[source]
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
- classmethod from_pt(value)[source]
Get instance from
pt
(points) value.- Parameters:
value (float) –
pt
value.- Return type:
- classmethod from_px(value)[source]
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
- classmethod from_unit_val(value)[source]
Get instance from
UnitT
or float value.- Parameters:
value (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be ininch10
units.- Return type:
- static get_unit_length()[source]
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.IN10
.- Return type:
- get_value_app_font(kind)[source]
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (PointSizeKind, optional): The kind ofAppFont
to use.- Return type:
float
- Parameters:
kind (PointSizeKind | int) –
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- get_value_cm()[source]
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
int
- get_value_inch()[source]
Gets instance value in inch units.
- Returns:
Value in inch units.
- Return type:
float
- get_value_inch10()[source]
Gets instance value in
1/10th inch
units.- Returns:
Value in
1/10th inch
units.- Return type:
float
- get_value_inch100()[source]
Gets instance value in
1/100th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
float
- get_value_inch1000()[source]
Gets instance value in
1/1000th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_mm()[source]
Gets instance value converted to
mm
units.- Returns:
Value in
mm
units.- Return type:
int
- get_value_mm100()[source]
Gets instance value converted to
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_pt()[source]
Gets instance value converted to Size in
pt
(points) units.- Returns:
Value in
pt
units.- Return type:
int
- get_value_px()[source]
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
int
- value: float
Float value.
- class ooodev.units.UnitInch100(value)[source]
Unit in
1/100th in
units.Supports
UnitT
protocol.See also
- Parameters:
value (float) –
- __init__(value)
- Parameters:
value (float) –
- Return type:
None
- almost_equal(val, epsilon=1e-09)
Comparing float values directly using equality (
==
) can sometimes lead to unexpected results due to the way floating-point numbers are represented in computers. A small rounding error can make two floats that should be equal appear unequal.A common way to compare floats is to check if the absolute difference between them is less than a small number, often called the machine epsilon.
In this function,
epsilon
is the maximum difference for whicha
andb
are considered equal. You can adjustepsilon
based on the precision you need.- Parameters:
val (float) – The value to compare with.
epsilon (float) – The maximum difference for which
a
andb
are considered equal.
- Returns:
True if current value and
val
are considered equal, False otherwise.- Return type:
bool
- convert_to(unit)[source]
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
- classmethod from_app_font(value, kind)[source]
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use.
- Return type:
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- classmethod from_cm(value)[source]
Get instance from
cm
value.- Parameters:
value (float) –
cm
value.- Return type:
- classmethod from_in(value)
Get instance from
in
(inch) value.- Parameters:
value (float) –
in
value.- Return type:
- classmethod from_inch(value)[source]
Get instance from
in
(inch) value.- Parameters:
value (float) –
in
value.- Return type:
- classmethod from_inch10(value)[source]
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
1/10th in
value.- Return type:
- classmethod from_inch100(value)[source]
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
1/10th in
value.- Return type:
- classmethod from_inch1000(value)[source]
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
- classmethod from_mm100(value)[source]
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
- classmethod from_pt(value)[source]
Get instance from
pt
(points) value.- Parameters:
value (float) –
pt
value.- Return type:
- classmethod from_px(value)[source]
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
- classmethod from_unit_val(value)[source]
Get instance from
UnitT
or float value.- Parameters:
value (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be ininch100
units.- Return type:
- static get_unit_length()[source]
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.IN100
.- Return type:
- get_value_app_font(kind)[source]
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (PointSizeKind, optional): The kind ofAppFont
to use.- Return type:
float
- Parameters:
kind (PointSizeKind | int) –
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- get_value_cm()[source]
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
int
- get_value_inch1000()[source]
Gets instance value in
1/1000th inch
units.- Returns:
Value in
1/1000th inch
units.- Return type:
int
- get_value_mm()[source]
Gets instance value converted to Size in
mm
units.- Returns:
Value in
mm
units.- Return type:
int
- get_value_mm100()[source]
Gets instance value converted to Size in
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_pt()[source]
Gets instance value converted to Size in
pt
(points) units.- Returns:
Value in
pt
units.- Return type:
int
- get_value_px()[source]
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
int
- value: float
Float value.
- class ooodev.units.UnitInch1000(value)[source]
Represents
1/1,000th in
units.Supports
UnitT
protocol.See also
- Parameters:
value (int) –
- __init__(value)
- Parameters:
value (int) –
- Return type:
None
- convert_to(unit)[source]
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
- classmethod from_app_font(value, kind)[source]
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use.
- Return type:
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- classmethod from_cm(value)[source]
Get instance from
cm
value.- Parameters:
value (int) –
cm
value.- Return type:
- classmethod from_inch(value)[source]
Get instance from
in
(inch) value.- Parameters:
value (int) –
in
value.- Return type:
- classmethod from_inch10(value)[source]
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
`/10th in
value.- Return type:
- classmethod from_inch100(value)[source]
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
- classmethod from_inch1000(value)[source]
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
- classmethod from_mm(value)[source]
Get instance from
mm
value.- Parameters:
value (int) –
mm
value.- Return type:
- classmethod from_mm100(value)[source]
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
- classmethod from_pt(value)[source]
Get instance from
pt
(points) value.- Parameters:
value (int) –
pt
value.- Return type:
- classmethod from_px(value)[source]
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
- classmethod from_unit_val(value)[source]
Get instance from
UnitT
or float value.- Parameters:
value (UnitT, float, int) –
UnitT
or float value. If float then it is assumed to be ininch1000
units.- Return type:
- static get_unit_length()[source]
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.IN1000
.- Return type:
- get_value_app_font(kind)[source]
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (PointSizeKind, optional): The kind ofAppFont
to use.- Return type:
float
- Parameters:
kind (PointSizeKind | int) –
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- get_value_cm()[source]
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
int
- get_value_inch1000()[source]
Gets instance value in
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_mm()[source]
Gets instance value converted to
mm
units.- Returns:
Value in
mm
units.- Return type:
int
- get_value_mm100()[source]
Gets instance value in
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_pt()[source]
Gets instance value converted to
pt
(point) units.- Returns:
Value in
pt
units.- Return type:
int
- get_value_px()[source]
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
int
- value: int
Int value.
- class ooodev.units.UnitLength(value)[source]
An enumeration.
- CH = 18
210
twip (14 px
)- Type:
char unit
- CM = 3
centimeter
- COUNT = 20
- EMU = 6
1/360000 cm
,1/914400 in
- Type:
English Metric Unit
- FT = 14
foot
- IN = 13
inch
- IN10 = 12
1/10 in
- IN100 = 11
1/100 in
- IN1000 = 10
1/1000 in
- INVALID = -1
invalid
- KM = 5
kilometer
- LINE = 19
312
twip- Type:
line unit
- M = 4
meter
- MASTER = 16
1/576 in
- Type:
PPT Master Unit
- MI = 15
mile
- MM = 2
millimeter
- MM10 = 1
1/10 mm
- MM100 = 0
1/100th mm
- PC = 9
1/6 in
- Type:
Pica
- PX = 17
15
twip (96 ppi
)- Type:
pixel unit
- TWIP = 7
1/20 pt
- Type:
Twentieth of a point aka
dxa
- class ooodev.units.UnitMM(value)[source]
Unit in
mm
units.Supports
UnitT
protocol.See also
- Parameters:
value (float) –
- __init__(value)
- Parameters:
value (float) –
- Return type:
None
- almost_equal(val, epsilon=1e-09)
Comparing float values directly using equality (
==
) can sometimes lead to unexpected results due to the way floating-point numbers are represented in computers. A small rounding error can make two floats that should be equal appear unequal.A common way to compare floats is to check if the absolute difference between them is less than a small number, often called the machine epsilon.
In this function,
epsilon
is the maximum difference for whicha
andb
are considered equal. You can adjustepsilon
based on the precision you need.- Parameters:
val (float) – The value to compare with.
epsilon (float) – The maximum difference for which
a
andb
are considered equal.
- Returns:
True if current value and
val
are considered equal, False otherwise.- Return type:
bool
- convert_to(unit)[source]
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
- classmethod from_app_font(value, kind)[source]
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use.
- Return type:
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- classmethod from_cm(value)[source]
Get instance from
cm
value.- Parameters:
value (int) –
cm
value.- Return type:
- classmethod from_inch(value)[source]
Get instance from
in
(inch) value.- Parameters:
value (int) –
in
value.- Return type:
- classmethod from_inch10(value)[source]
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
1/10th in
value.- Return type:
- classmethod from_inch100(value)[source]
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
- classmethod from_inch1000(value)[source]
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
- classmethod from_mm(value)[source]
Get instance from
mm
value.- Parameters:
value (int) –
mm
value.- Return type:
- classmethod from_mm10(value)[source]
Get instance from
1/10th mm
value.- Parameters:
value (int) –
1/10th mm
value.- Return type:
- classmethod from_mm100(value)[source]
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
- classmethod from_pt(value)[source]
Get instance from
pt
(points) value.- Parameters:
value (float) –
pt
value.- Return type:
- classmethod from_px(value)[source]
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
- static get_unit_length()[source]
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.MM
.- Return type:
- get_value_app_font(kind)[source]
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (PointSizeKind, optional): The kind ofAppFont
to use.- Return type:
float
- Parameters:
kind (PointSizeKind | int) –
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- get_value_cm()[source]
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
float
- get_value_inch()[source]
Gets instance value in
in
(inch) units.- Returns:
Value in
in
units.- Return type:
float
- get_value_inch10()[source]
Gets instance value in
1/10th inch
units.- Returns:
Value in
1/10th inch
units.- Return type:
int
- get_value_inch100()[source]
Gets instance value in
1/100th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_inch1000()[source]
Gets instance value in
1/1000th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_mm()[source]
Gets instance value converted to Size in
mm
units.- Returns:
Value in
mm
units.- Return type:
float
- get_value_mm100()[source]
Gets instance value converted to Size in
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_pt()[source]
Gets instance value converted to Size in
pt
(points) units.- Returns:
Value in
pt
units.- Return type:
float
- get_value_px()[source]
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
float
- value: float
Float value.
- class ooodev.units.UnitMM10(value)[source]
Unit in
1/10th mm
units.Supports
UnitT
protocol.See also
- Parameters:
value (float) –
- __init__(value)
- Parameters:
value (float) –
- Return type:
None
- almost_equal(val, epsilon=1e-09)
Comparing float values directly using equality (
==
) can sometimes lead to unexpected results due to the way floating-point numbers are represented in computers. A small rounding error can make two floats that should be equal appear unequal.A common way to compare floats is to check if the absolute difference between them is less than a small number, often called the machine epsilon.
In this function,
epsilon
is the maximum difference for whicha
andb
are considered equal. You can adjustepsilon
based on the precision you need.- Parameters:
val (float) – The value to compare with.
epsilon (float) – The maximum difference for which
a
andb
are considered equal.
- Returns:
True if current value and
val
are considered equal, False otherwise.- Return type:
bool
- convert_to(unit)[source]
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
- classmethod from_app_font(value, kind)[source]
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use.
- Return type:
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- classmethod from_cm(value)[source]
Get instance from
cm
value.- Parameters:
value (int) –
cm
value.- Return type:
- classmethod from_inch(value)[source]
Get instance from
in
(inch) value.- Parameters:
value (int) –
in
value.- Return type:
- classmethod from_inch10(value)[source]
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
`/10th in
value.- Return type:
- classmethod from_inch100(value)[source]
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
- classmethod from_inch1000(value)[source]
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
- classmethod from_mm(value)[source]
Get instance from
mm
value.- Parameters:
value (int) –
mm
value.- Return type:
- classmethod from_mm10(value)[source]
Get instance from
1/10th mm
value.- Parameters:
value (int) –
1/10th mm
value.- Return type:
- classmethod from_mm100(value)[source]
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
- classmethod from_pt(value)[source]
Get instance from
pt
(points) value.- Parameters:
value (float) –
pt
value.- Return type:
- classmethod from_px(value)[source]
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
- static get_unit_length()[source]
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.MM10
.- Return type:
- get_value_app_font(kind)[source]
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (PointSizeKind, optional): The kind ofAppFont
to use.- Return type:
float
- Parameters:
kind (PointSizeKind | int) –
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- get_value_cm()[source]
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
int
- get_value_mm()[source]
Gets instance value converted to
mm
units.- Returns:
Value in
mm
units.- Return type:
int
- get_value_mm10()[source]
Gets instance value in
1/10th mm
units.- Returns:
Value in
1/10th mm
units.- Return type:
float
- get_value_mm100()[source]
Gets instance value converted to
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_pt()[source]
Gets instance value converted to
pt
(points) units.- Returns:
Value in
pt
units.- Return type:
int
- get_value_px()[source]
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
int
- value: float
Float value.
- class ooodev.units.UnitMM100(value)[source]
Represents
1/100th mm
units.Supports
UnitT
protocol.See also
- Parameters:
value (int) –
- __init__(value)
- Parameters:
value (int) –
- Return type:
None
- convert_to(unit)[source]
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
- classmethod from_app_font(value, kind)[source]
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use.
- Return type:
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- classmethod from_cm(value)[source]
Get instance from
cm
value.- Parameters:
value (int) –
cm
value.- Return type:
- classmethod from_inch(value)[source]
Get instance from
in
(inch) value.- Parameters:
value (int) –
in
value.- Return type:
- classmethod from_inch10(value)[source]
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
`/10th in
value.- Return type:
- classmethod from_inch100(value)[source]
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
- classmethod from_inch1000(value)[source]
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
- classmethod from_mm(value)[source]
Get instance from
mm
value.- Parameters:
value (int) –
mm
value.- Return type:
- classmethod from_mm10(value)[source]
Get instance from
1/10th mm
value.- Parameters:
value (int) –
1/10th mm
value.- Return type:
- classmethod from_mm100(value)[source]
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
- classmethod from_pt(value)[source]
Get instance from
pt
(points) value.- Parameters:
value (int) –
pt
value.- Return type:
- classmethod from_px(value)[source]
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
- static get_unit_length()[source]
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.MM100
.- Return type:
- get_value_app_font(kind)[source]
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (PointSizeKind, optional): The kind ofAppFont
to use.- Return type:
float
- Parameters:
kind (PointSizeKind | int) –
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- get_value_cm()[source]
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
int
- get_value_mm()[source]
Gets instance value converted to
mm
units.- Returns:
Value in
mm
units.- Return type:
int
- get_value_mm10()[source]
Gets instance value in
1/10th mm
units.- Returns:
Value in
1/10th mm
units.- Return type:
float
- get_value_mm100()[source]
Gets instance value in
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_pt()[source]
Gets instance value converted to
pt
(point) units.- Returns:
Value in
pt
units.- Return type:
int
- get_value_px()[source]
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
int
- value: int
Int value.
- class ooodev.units.UnitPT(value)[source]
Represents a
PT
(points) value.Supports
UnitT
protocol.See also
- Parameters:
value (float) –
- __init__(value)
- Parameters:
value (float) –
- Return type:
None
- almost_equal(val, epsilon=1e-09)
Comparing float values directly using equality (
==
) can sometimes lead to unexpected results due to the way floating-point numbers are represented in computers. A small rounding error can make two floats that should be equal appear unequal.A common way to compare floats is to check if the absolute difference between them is less than a small number, often called the machine epsilon.
In this function,
epsilon
is the maximum difference for whicha
andb
are considered equal. You can adjustepsilon
based on the precision you need.- Parameters:
val (float) – The value to compare with.
epsilon (float) – The maximum difference for which
a
andb
are considered equal.
- Returns:
True if current value and
val
are considered equal, False otherwise.- Return type:
bool
- convert_to(unit)[source]
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
- classmethod from_app_font(value, kind)[source]
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use.
- Return type:
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- classmethod from_cm(value)[source]
Get instance from
cm
value.- Parameters:
value (int) –
cm
value.- Return type:
- classmethod from_inch(value)[source]
Get instance from
in
(inch) value.- Parameters:
value (int) –
in
value.- Return type:
- classmethod from_inch10(value)[source]
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
1/10th in
value.- Return type:
- classmethod from_inch100(value)[source]
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
- classmethod from_inch1000(value)[source]
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
- classmethod from_mm(value)[source]
Get instance from
mm
value.- Parameters:
value (int) –
mm
value.- Return type:
- classmethod from_mm10(value)[source]
Get instance from
1/10th mm
value.- Parameters:
value (int) –
1/10th mm
value.- Return type:
- classmethod from_mm100(value)[source]
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
- classmethod from_pt(value)[source]
Get instance from
pt
(points) value.- Parameters:
value (float) –
pt
value.- Return type:
- classmethod from_px(value)[source]
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
- static get_unit_length()[source]
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.PT
.- Return type:
- get_value_app_font(kind)[source]
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (PointSizeKind, optional): The kind ofAppFont
to use.- Return type:
float
- Parameters:
kind (PointSizeKind | int) –
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- get_value_cm()[source]
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
int
- get_value_inch()[source]
Gets instance value in
in
(inch) units.- Returns:
Value in
in
units.- Return type:
float
- get_value_inch10()[source]
Gets instance value in
1/10th inch
units.- Returns:
Value in
1/10th inch
units.- Return type:
int
- get_value_inch100()[source]
Gets instance value in
1/100th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_inch1000()[source]
Gets instance value in
1/1000th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_mm()[source]
Gets instance value converted to
mm
units.- Returns:
Value in
mm
units.- Return type:
int
- get_value_mm100()[source]
Gets instance value converted to
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_pt()[source]
Gets instance value in
pt
(point) units.- Returns:
Value in
pt
units.- Return type:
int
- get_value_px()[source]
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
int
- value: float
Float value.
- class ooodev.units.UnitPX(value)[source]
Represents a
PX
(pixel) value.Supports
UnitT
protocol.See also
- Parameters:
value (float) –
- __init__(value)
- Parameters:
value (float) –
- Return type:
None
- almost_equal(val, epsilon=1e-09)
Comparing float values directly using equality (
==
) can sometimes lead to unexpected results due to the way floating-point numbers are represented in computers. A small rounding error can make two floats that should be equal appear unequal.A common way to compare floats is to check if the absolute difference between them is less than a small number, often called the machine epsilon.
In this function,
epsilon
is the maximum difference for whicha
andb
are considered equal. You can adjustepsilon
based on the precision you need.- Parameters:
val (float) – The value to compare with.
epsilon (float) – The maximum difference for which
a
andb
are considered equal.
- Returns:
True if current value and
val
are considered equal, False otherwise.- Return type:
bool
- convert_to(unit)[source]
Converts instance value to specified unit.
- Parameters:
unit (UnitLength) – Unit to convert to.
- Returns:
Value in specified unit.
- Return type:
float
- classmethod from_app_font(value, kind)[source]
Get instance from
AppFont
value.- Parameters:
value (int) –
AppFont
value.kind (PointSizeKind, optional) – The kind of
AppFont
to use.
- Return type:
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- classmethod from_cm(value)[source]
Get instance from
cm
value.- Parameters:
value (int) –
cm
value.- Return type:
- classmethod from_inch(value)[source]
Get instance from
in
(inch) value.- Parameters:
value (int) –
in
value.- Return type:
- classmethod from_inch10(value)[source]
Get instance from
1/10th in
(inch) value.- Parameters:
value (int) –
1/10th in
value.- Return type:
- classmethod from_inch100(value)[source]
Get instance from
1/100th in
(inch) value.- Parameters:
value (int) –
1/100th in
value.- Return type:
- classmethod from_inch1000(value)[source]
Get instance from
1/1,000th in
(inch) value.- Parameters:
value (int) –
1/1,000th in
value.- Return type:
- classmethod from_mm(value)[source]
Get instance from
mm
value.- Parameters:
value (int) –
mm
value.- Return type:
- classmethod from_mm10(value)[source]
Get instance from
1/10th mm
value.- Parameters:
value (int) –
1/10th mm
value.- Return type:
- classmethod from_mm100(value)[source]
Get instance from
1/100th mm
value.- Parameters:
value (int) –
1/100th mm
value.- Return type:
- classmethod from_pt(value)[source]
Get instance from
pt
(points) value.- Parameters:
value (float) –
pt
value.- Return type:
- classmethod from_px(value)[source]
Get instance from
px
(pixel) value.- Parameters:
value (float) –
px
value.- Return type:
- static get_unit_length()[source]
Gets instance unit length.
- Returns:
Instance unit length
UnitLength.PX
.- Return type:
- get_value_app_font(kind)[source]
Gets instance value in
AppFont
units.- Returns:
Value in
AppFont
units. kind (PointSizeKind, optional): The kind ofAppFont
to use.- Return type:
float
- Parameters:
kind (PointSizeKind | int) –
Note
AppFont units have different values when converted. This is true even if they have the same value in
AppFont
units.AppFontX(10)
is not equal toAppFontY(10)
when they are converted to different units.Kind
whenint
is used, the value must be one of the following:0
isPointSizeKind.X
,1
isPointSizeKind.Y
,2
isPointSizeKind.WIDTH
,3
isPointSizeKind.HEIGHT
.
Hint
PointSizeKind
can be imported fromooodev.utils.kind.point_size_kind
.
- get_value_cm()[source]
Gets instance value converted to
cm
units.- Returns:
Value in
cm
units.- Return type:
int
- get_value_inch()[source]
Gets instance value in
in
(inch) units.- Returns:
Value in
in
units.- Return type:
float
- get_value_inch10()[source]
Gets instance value in
1/10th inch
units.- Returns:
Value in
1/10th inch
units.- Return type:
int
- get_value_inch100()[source]
Gets instance value in
1/100th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_inch1000()[source]
Gets instance value in
1/1000th inch
units.- Returns:
Value in
1/100th inch
units.- Return type:
int
- get_value_mm()[source]
Gets instance value converted to
mm
units.- Returns:
Value in
mm
units.- Return type:
int
- get_value_mm100()[source]
Gets instance value converted to
1/100th mm
units.- Returns:
Value in
1/100th mm
units.- Return type:
int
- get_value_pt()[source]
Gets instance value in
pt
(point) units.- Returns:
Value in
pt
units.- Return type:
int
- get_value_px()[source]
Gets instance value in
px
(pixel) units.- Returns:
Value in
px
units.- Return type:
int
- value: float
Float value.
- ooodev.units.unit_factory.get_unit(unit_length, value)[source]
Gets the unit.
- Parameters:
unit_length (UnitLength) – Unit Length.
value (int | float) – Value.
- Returns:
Unit.
- Return type:
Example
>>> from ooodev.units.unit_factory import get_unit >>> from ooodev.units UnitLength >>> unit_mm100 = get_unit(UnitLength.MM100, 500) >>> print(unit_mm100) UnitMM100(value=500)
New in version 0.34.1.
- ooodev.units.unit_factory.get_unit_type(unit_length)[source]
Gets the unit type.
- Parameters:
unit_length (UnitLength) – Unit Length.
- Raises:
ValueError – If unknown unit length or there is not type to match the unit length.
- Returns:
Unit Type.
- Return type:
Type[UnitT]
Example
from ooodev.units.unit_factory import get_unit_type from ooodev.units UnitLength unit_mm100_type = get_unit_type(UnitLength.MM100)
New in version 0.34.1.