units

New in version 0.9.0.

Contents

class ooodev.units.Angle(value)[source]

Represents an angle value from 0 to 359.

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:

Angle

static from_angle10(value)[source]

Get an angle from 1/10 degree units.

Parameters:

value (int) – Angle in 1/10 degree units.

Return type:

Angle

static from_angle100(value)[source]

Get an angle from 1/100 degree units.

Parameters:

value (int) – Angle in 1/10 degree units.

Return type:

Angle

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:

Angle

New in version 0.32.0.

get_angle()[source]

Gets Angle Value as degrees

New in version 0.17.4.

Return type:

int

get_angle10()[source]

Gets Angle Value as 1/10 degree

Return type:

int

get_angle100()[source]

Gets Angle Value as 1/100 degree

Return type:

int

value: int

Int value.

class ooodev.units.Angle10(value)[source]

Represents an angle value from 0 to 3599.

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:

Angle10

static from_angle10(value)[source]

Get an angle from 1/10 degree units.

Parameters:

value (int) – Angle10 in 1/10 degree units.

Return type:

Angle10

static from_angle100(value)[source]

Get an angle from 1/100 degree units.

Parameters:

value (int) – Angle10 in 1/10 degree units.

Return type:

Angle10

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 in 1/10th degrees.

Return type:

Angle10

New in version 0.32.0.

get_angle()[source]

Gets Angle10 Value as degrees

Return type:

int

get_angle10()[source]

Gets Angle10 Value as 1/10 degree

Return type:

int

get_angle100()[source]

Gets Angle10 Value as 1/100 degree

Return type:

int

value: int

Int value.

class ooodev.units.Angle100(value)[source]

Represents an angle value from 0 to 35999 in 1/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:

Angle100

static from_angle10(value)[source]

Get an angle from 1/10 degree units.

Parameters:

value (int) – Angle in 1/10 degree units.

Return type:

Angle

static from_angle100(value)[source]

Get an angle from 1/100 degree units.

Parameters:

value (int) – Angle in 1/100 degree units.

Return type:

Angle

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 in 1/100th degrees.

Return type:

Angle100

New in version 0.32.0.

get_angle()[source]

Gets Angle Value as degrees

Return type:

int

get_angle10()[source]

Gets Angle Value as 1/10 degree

Return type:

int

get_angle100()[source]

Gets Angle Value as 1/100 degree

Return type:

int

value: int

Int value.

class ooodev.units.AngleUnitT[source]

Protocol Class for Angle units.

See also

units

__init__()
get_angle()[source]

Gets Angle Value as degrees

Return type:

int

get_angle10()[source]

Gets Angle Value as 1/10 degree

Return type:

int

get_angle100()[source]

Gets Angle Value as 1/100 degree

Return type:

int

property value: float | int

Angle actual value. Generally a float or int

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 and Y application font position units.

Note

The X and Y units are based on the application font position ratio. This means that the X and Y units may not not be based on the same unit length.

Parameters:
__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:

AppFontPos

property x: UnitAppFontX

Gets/Sets the X unit of the application font position.

When setting can be a float or a UnitT.

Return type:

UnitAppFontX

property y: UnitAppFontY

Get/Sets the Y unit of the application font position.

When setting can be a float or a UnitT.

Return type:

UnitAppFontY

class ooodev.units.AppFontSize(width, height)[source]

A class to represent the application font size.

This class is a container for the Width and Height application font size units.

Note

The Width and Height units are based on the application font size ratio. This means that the Width and Height units may not be based on the same unit length.

Parameters:
__init__(width, height)[source]

Constructor

Parameters:
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:

SizeMM100

property height: UnitAppFontHeight

Get/Sets the Height unit of the application font size.

When setting can be a float or a UnitT.

Return type:

UnitAppFontHeight

property width: UnitAppFontWidth

Gets/Sets the Width`` unit of the application font size.

When setting can be a float or a UnitT.

Return type:

UnitAppFontWidth

class ooodev.units.SizeMM100(width, height)[source]

Size Width and Height in 1/100th mm units.

New in version 0.27.0.

__init__(width, height)[source]

Constructor

Parameters:
  • width (UnitMM100) – Width value as 1/100th mm.

  • height (UnitMM100) – Height value as 1/100th mm.

Return type:

None

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:

SizeMM100

get_size()

Gets instance value as Size

Return type:

GenericSize[TypeVar(TNum, bound= Union[int, float])]

get_uno_size()

Gets current values as Size

Returns:

UNO Size instance

Return type:

Size

property height: _T

Gets/Sets height

Return type:

TypeVar(_T, bound= UnitT)

property width: _T

Gets/Sets width

Return type:

TypeVar(_T, bound= UnitT)

class ooodev.units.SizePX(width, height)[source]

Size Width and Height in px units.

New in version 0.27.0.

__init__(width, height)[source]

Constructor

Parameters:
  • width (UnitPX) – Width value as px.

  • height (UnitPX) – Height value as px.

Return type:

None

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:

SizePX

classmethod from_unit_val(width, height)[source]

Get instance from UnitT or float value.

Parameters:
  • width (UnitT, float, int) – UnitT or float value. If float then it is assumed to be in px units.

  • height (UnitT, float, int) – UnitT or float value. If float then it is assumed to be in px units.

Return type:

SizePX

get_size()

Gets instance value as Size

Return type:

GenericSize[TypeVar(TNum, bound= Union[int, float])]

get_uno_size()

Gets current values as Size

Returns:

UNO Size instance

Return type:

Size

property height: _T

Gets/Sets height

Return type:

TypeVar(_T, bound= UnitT)

property width: _T

Gets/Sets width

Return type:

TypeVar(_T, bound= UnitT)

class ooodev.units.SizePosMM100(x, y, width, height)[source]

Size and Position in 1/100 mm units.

New in version 0.39.0.

__init__(x, y, width, height)[source]

Constructor

Parameters:
  • x (UnitMM100) – Width value as 1/100 mm.

  • y (UnitMM100) – Width value as 1/100 mm.

  • width (UnitMM100) – Width value as 1/100 mm.

  • height (UnitMM100) – Height value as 1/100 mm.

Return type:

None

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 in 1/100 mm units.

  • y (UnitT, float, int) – UnitT or float value. If float then it is assumed to be in 1/100 mm units.

  • width (UnitT, float, int) – UnitT or float value. If float then it is assumed to be in 1/100 mm units.

  • height (UnitT, float, int) – UnitT or float value. If float then it is assumed to be in 1/100 mm units.

Return type:

SizePosMM100

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

Returns:

UNO Point and Size.

Return type:

Tuple[Point, Size]

get_uno_rectangle()

Gets current values as Rectangle

Returns:

UNO Rectangle.

Return type:

Rectangle

property height: _T

Gets/Sets height

Return type:

TypeVar(_T, bound= UnitT)

property width: _T

Gets/Sets width

Return type:

TypeVar(_T, bound= UnitT)

property x: _T

Gets/Sets x

Return type:

TypeVar(_T, bound= UnitT)

property y: _T

Gets/Sets y

Return type:

TypeVar(_T, bound= UnitT)

class ooodev.units.SizePosPX(x, y, width, height)[source]

Size and Position in px units.

New in version 0.39.0.

__init__(x, y, width, height)[source]

Constructor

Parameters:
  • x (UnitPX) – Width value as px.

  • y (UnitPX) – Width value as px.

  • width (UnitPX) – Width value as px.

  • height (UnitPX) – Height value as px.

Return type:

None

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 in px units.

  • y (UnitT, float, int) – UnitT or float value. If float then it is assumed to be in px units.

  • width (UnitT, float, int) – UnitT or float value. If float then it is assumed to be in px units.

  • height (UnitT, float, int) – UnitT or float value. If float then it is assumed to be in px units.

Return type:

SizePosPX

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

Returns:

UNO Point and Size.

Return type:

Tuple[Point, Size]

get_uno_rectangle()

Gets current values as Rectangle

Returns:

UNO Rectangle.

Return type:

Rectangle

property height: _T

Gets/Sets height

Return type:

TypeVar(_T, bound= UnitT)

property width: _T

Gets/Sets width

Return type:

TypeVar(_T, bound= UnitT)

property x: _T

Gets/Sets x

Return type:

TypeVar(_T, bound= UnitT)

property y: _T

Gets/Sets y

Return type:

TypeVar(_T, bound= UnitT)

class ooodev.units.UnitAppFontHeight(value)[source]

Unit in AppFont units.

Supports UnitT protocol.

Warning

Although this class support UnitT protocol, get_unit_length() method returns UnitLength.INVALID.

Note

Unlike most other units in this module, this unit is not based on UnitLength. This means that it does not have a valid UnitLength value and returns UnitLength.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

Class UnitT

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 which a and b are considered equal. You can adjust epsilon based on the precision you need.

Parameters:
  • val (float) – The value to compare with.

  • epsilon (float) – The maximum difference for which a and b 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 from ooodev.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 of AppFont 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 in mm units.

Return type:

Self

get_app_font_kind()[source]

Gets the kind of the unit.

Returns:

Returns PointSizeKind.HEIGHT

Return type:

PointSizeKind

static get_unit_length()

Gets instance unit length.

Returns:

Instance unit length UnitLength.INVALID.

Return type:

UnitLength

get_value_app_font(kind=None)

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (Any): Ignored in the context of AppFont 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 returns UnitLength.INVALID.

Note

Unlike most other units in this module, this unit is not based on UnitLength. This means that it does not have a valid UnitLength value and returns UnitLength.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

Class UnitT

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 which a and b are considered equal. You can adjust epsilon based on the precision you need.

Parameters:
  • val (float) – The value to compare with.

  • epsilon (float) – The maximum difference for which a and b 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 from ooodev.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 of AppFont 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 in mm units.

Return type:

Self

get_app_font_kind()[source]

Gets the kind of the unit.

Returns:

Returns PointSizeKind.WIDTH

Return type:

PointSizeKind

static get_unit_length()

Gets instance unit length.

Returns:

Instance unit length UnitLength.INVALID.

Return type:

UnitLength

get_value_app_font(kind=None)

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (Any): Ignored in the context of AppFont 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 returns UnitLength.INVALID.

Note

Unlike most other units in this module, this unit is not based on UnitLength. This means that it does not have a valid UnitLength value and returns UnitLength.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

Class UnitT

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 which a and b are considered equal. You can adjust epsilon based on the precision you need.

Parameters:
  • val (float) – The value to compare with.

  • epsilon (float) – The maximum difference for which a and b 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 from ooodev.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 of AppFont 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 in mm units.

Return type:

Self

get_app_font_kind()[source]

Gets the kind of the unit.

Returns:

Returns PointSizeKind.X

Return type:

PointSizeKind

static get_unit_length()

Gets instance unit length.

Returns:

Instance unit length UnitLength.INVALID.

Return type:

UnitLength

get_value_app_font(kind=None)

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (Any): Ignored in the context of AppFont 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 returns UnitLength.INVALID.

Note

Unlike most other units in this module, this unit is not based on UnitLength. This means that it does not have a valid UnitLength value and returns UnitLength.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

Class UnitT

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 which a and b are considered equal. You can adjust epsilon based on the precision you need.

Parameters:
  • val (float) – The value to compare with.

  • epsilon (float) – The maximum difference for which a and b 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 from ooodev.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 of AppFont 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 in mm units.

Return type:

Self

get_app_font_kind()[source]

Gets the kind of the unit.

Returns:

Returns PointSizeKind.Y

Return type:

PointSizeKind

static get_unit_length()

Gets instance unit length.

Returns:

Instance unit length UnitLength.INVALID.

Return type:

UnitLength

get_value_app_font(kind=None)

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (Any): Ignored in the context of AppFont 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

Class UnitT

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 which a and b are considered equal. You can adjust epsilon based on the precision you need.

Parameters:
  • val (float) – The value to compare with.

  • epsilon (float) – The maximum difference for which a and b 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:

UnitCM

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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.utils.kind.point_size_kind.

classmethod from_cm(value)[source]

Get instance from cm value.

Parameters:

value (float) – cm value.

Return type:

UnitCM

classmethod from_inch(value)[source]

Get instance from in (inch) value.

Parameters:

value (int) – in value.

Return type:

UnitCM

classmethod from_inch10(value)[source]

Get instance from 1/10th in (inch) value.

Parameters:

value (int) – `/10th in value.

Return type:

UnitCM

classmethod from_inch100(value)[source]

Get instance from 1/100th in (inch) value.

Parameters:

value (int) – 1/100th in value.

Return type:

UnitCM

classmethod from_inch1000(value)[source]

Get instance from 1/1,000th in (inch) value.

Parameters:

value (int) – 1/1,000th in value.

Return type:

UnitCM

classmethod from_mm(value)[source]

Get instance from mm value.

Parameters:

value (int) – mm value.

Return type:

UnitCM

classmethod from_mm10(value)[source]

Get instance from 1/10th mm value.

Parameters:

value (int) – 1/10th mm value.

Return type:

UnitCM

classmethod from_mm100(value)[source]

Get instance from 1/100th mm value.

Parameters:

value (int) – 1/100th mm value.

Return type:

UnitCM

classmethod from_pt(value)[source]

Get instance from pt (points) value.

Parameters:

value (float) – pt value.

Return type:

UnitCM

classmethod from_px(value)[source]

Get instance from px (pixel) value.

Parameters:

value (float) – px value.

Return type:

UnitCM

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 in cm units.

Return type:

UnitCM

static get_unit_length()[source]

Gets instance unit length.

Returns:

Instance unit length UnitLength.CM.

Return type:

UnitLength

get_value_app_font(kind)[source]

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (PointSizeKind, optional): The kind of AppFont 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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.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 or int.

  • 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 then mul_div() is called directly.

classmethod convert_mm100_mm(num)[source]

Converts mm to 1/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 to mm

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

static mul_div(num, mul, div)[source]

Multiplies and divides.

Parameters:
  • num (N) – number

  • mul (N) – multiplier

  • div (N) – divisor

Returns:

Converted Number

Return type:

float

Note

Formula num * (mul / div)

classmethod to_twips(num, frm)[source]

Converts number to twips

Parameters:
  • num (N) – Number to convert

  • frm (Length) – The number kind to convert to twips

Returns:

Converted number

Return type:

float

class ooodev.units.UnitInch(value)[source]

Unit in inch units.

Supports UnitT protocol.

See also

Class UnitT

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 which a and b are considered equal. You can adjust epsilon based on the precision you need.

Parameters:
  • val (float) – The value to compare with.

  • epsilon (float) – The maximum difference for which a and b 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:

UnitInch

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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.utils.kind.point_size_kind.

classmethod from_cm(value)[source]

Get instance from cm value.

Parameters:

value (float) – cm value.

Return type:

UnitInch

classmethod from_inch(value)[source]

Get instance from inch value.

Parameters:

value (int) – Inch value.

Return type:

UnitInch

classmethod from_inch10(value)[source]

Get instance from 1/10th in (inch) value.

Parameters:

value (int) – 1/10th in value.

Return type:

UnitInch

classmethod from_inch100(value)[source]

Get instance from 1/100th in (inch) value.

Parameters:

value (int) – 1/100th in value.

Return type:

UnitInch

classmethod from_inch1000(value)[source]

Get instance from 1/1,000th in (inch) value.

Parameters:

value (int) – 1/1,000th in value.

Return type:

UnitInch

classmethod from_mm(value)[source]

Get instance from mm value.

Parameters:

value (float) – mm value.

Return type:

UnitInch

classmethod from_mm10(value)[source]

Get instance from 1/10th mm value.

Parameters:

value (int) – 1/10th mm value.

Return type:

UnitInch

classmethod from_mm100(value)[source]

Get instance from 1/100th mm value.

Parameters:

value (int) – 1/100th mm value.

Return type:

UnitInch

classmethod from_pt(value)[source]

Get instance from pt (points) value.

Parameters:

value (float) – pt value.

Return type:

UnitInch

classmethod from_px(value)[source]

Get instance from px (pixel) value.

Parameters:

value (float) – px value.

Return type:

UnitInch

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 in inch units.

Return type:

UnitInch

static get_unit_length()[source]

Gets instance unit length.

Returns:

Instance unit length UnitLength.IN.

Return type:

UnitLength

get_value_app_font(kind)[source]

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (PointSizeKind, optional): The kind of AppFont 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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.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

Class UnitT

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 which a and b are considered equal. You can adjust epsilon based on the precision you need.

Parameters:
  • val (float) – The value to compare with.

  • epsilon (float) – The maximum difference for which a and b 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:

UnitInch10

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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.utils.kind.point_size_kind.

classmethod from_cm(value)[source]

Get instance from cm value.

Parameters:

value (float) – cm value.

Return type:

UnitInch10

classmethod from_in(value)

Get instance from in (inch) value.

Parameters:

value (float) – in value.

Return type:

UnitInch10

classmethod from_inch(value)[source]

Get instance from in (inch) value.

Parameters:

value (float) – in value.

Return type:

UnitInch10

classmethod from_inch10(value)[source]

Get instance from 1/10th in (inch) value.

Parameters:

value (int) – 1/10th in value.

Return type:

UnitInch10

classmethod from_inch100(value)[source]

Get instance from 1/100th in (inch) value.

Parameters:

value (int) – 1/100th in value.

Return type:

UnitInch10

classmethod from_inch1000(value)[source]

Get instance from 1/1,000th in (inch) value.

Parameters:

value (int) – 1/1,000th in value.

Return type:

UnitInch10

classmethod from_mm100(value)[source]

Get instance from 1/100th mm value.

Parameters:

value (int) – 1/100th mm value.

Return type:

UnitInch10

classmethod from_pt(value)[source]

Get instance from pt (points) value.

Parameters:

value (float) – pt value.

Return type:

UnitInch10

classmethod from_px(value)[source]

Get instance from px (pixel) value.

Parameters:

value (float) – px value.

Return type:

UnitInch10

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 in inch10 units.

Return type:

UnitInch10

static get_unit_length()[source]

Gets instance unit length.

Returns:

Instance unit length UnitLength.IN10.

Return type:

UnitLength

get_value_app_font(kind)[source]

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (PointSizeKind, optional): The kind of AppFont 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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.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

Class UnitT

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 which a and b are considered equal. You can adjust epsilon based on the precision you need.

Parameters:
  • val (float) – The value to compare with.

  • epsilon (float) – The maximum difference for which a and b 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:

UnitInch100

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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.utils.kind.point_size_kind.

classmethod from_cm(value)[source]

Get instance from cm value.

Parameters:

value (float) – cm value.

Return type:

UnitInch100

classmethod from_in(value)

Get instance from in (inch) value.

Parameters:

value (float) – in value.

Return type:

UnitInch100

classmethod from_inch(value)[source]

Get instance from in (inch) value.

Parameters:

value (float) – in value.

Return type:

UnitInch100

classmethod from_inch10(value)[source]

Get instance from 1/10th in (inch) value.

Parameters:

value (int) – 1/10th in value.

Return type:

UnitInch100

classmethod from_inch100(value)[source]

Get instance from 1/10th in (inch) value.

Parameters:

value (int) – 1/10th in value.

Return type:

UnitInch100

classmethod from_inch1000(value)[source]

Get instance from 1/1,000th in (inch) value.

Parameters:

value (int) – 1/1,000th in value.

Return type:

UnitInch100

classmethod from_mm100(value)[source]

Get instance from 1/100th mm value.

Parameters:

value (int) – 1/100th mm value.

Return type:

UnitInch100

classmethod from_pt(value)[source]

Get instance from pt (points) value.

Parameters:

value (float) – pt value.

Return type:

UnitInch100

classmethod from_px(value)[source]

Get instance from px (pixel) value.

Parameters:

value (float) – px value.

Return type:

UnitInch100

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 in inch100 units.

Return type:

UnitInch100

static get_unit_length()[source]

Gets instance unit length.

Returns:

Instance unit length UnitLength.IN100.

Return type:

UnitLength

get_value_app_font(kind)[source]

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (PointSizeKind, optional): The kind of AppFont 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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.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

Class UnitT

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:

UnitInch100

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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.utils.kind.point_size_kind.

classmethod from_cm(value)[source]

Get instance from cm value.

Parameters:

value (int) – cm value.

Return type:

UnitInch1000

classmethod from_inch(value)[source]

Get instance from in (inch) value.

Parameters:

value (int) – in value.

Return type:

UnitInch1000

classmethod from_inch10(value)[source]

Get instance from 1/10th in (inch) value.

Parameters:

value (int) – `/10th in value.

Return type:

UnitInch1000

classmethod from_inch100(value)[source]

Get instance from 1/100th in (inch) value.

Parameters:

value (int) – 1/100th in value.

Return type:

UnitInch1000

classmethod from_inch1000(value)[source]

Get instance from 1/1,000th in (inch) value.

Parameters:

value (int) – 1/1,000th in value.

Return type:

UnitInch1000

classmethod from_mm(value)[source]

Get instance from mm value.

Parameters:

value (int) – mm value.

Return type:

UnitInch1000

classmethod from_mm100(value)[source]

Get instance from 1/100th mm value.

Parameters:

value (int) – 1/100th mm value.

Return type:

UnitInch1000

classmethod from_pt(value)[source]

Get instance from pt (points) value.

Parameters:

value (int) – pt value.

Return type:

UnitInch1000

classmethod from_px(value)[source]

Get instance from px (pixel) value.

Parameters:

value (float) – px value.

Return type:

UnitInch1000

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 in inch1000 units.

Return type:

UnitInch100

static get_unit_length()[source]

Gets instance unit length.

Returns:

Instance unit length UnitLength.IN1000.

Return type:

UnitLength

get_value_app_font(kind)[source]

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (PointSizeKind, optional): The kind of AppFont 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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.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

PT = 8

1/72 in

Type:

Point

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

Class UnitT

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 which a and b are considered equal. You can adjust epsilon based on the precision you need.

Parameters:
  • val (float) – The value to compare with.

  • epsilon (float) – The maximum difference for which a and b 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:

UnitMM

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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.utils.kind.point_size_kind.

classmethod from_cm(value)[source]

Get instance from cm value.

Parameters:

value (int) – cm value.

Return type:

UnitMM

classmethod from_inch(value)[source]

Get instance from in (inch) value.

Parameters:

value (int) – in value.

Return type:

UnitMM

classmethod from_inch10(value)[source]

Get instance from 1/10th in (inch) value.

Parameters:

value (int) – 1/10th in value.

Return type:

UnitMM

classmethod from_inch100(value)[source]

Get instance from 1/100th in (inch) value.

Parameters:

value (int) – 1/100th in value.

Return type:

UnitMM

classmethod from_inch1000(value)[source]

Get instance from 1/1,000th in (inch) value.

Parameters:

value (int) – 1/1,000th in value.

Return type:

UnitMM

classmethod from_mm(value)[source]

Get instance from mm value.

Parameters:

value (int) – mm value.

Return type:

UnitMM

classmethod from_mm10(value)[source]

Get instance from 1/10th mm value.

Parameters:

value (int) – 1/10th mm value.

Return type:

UnitMM

classmethod from_mm100(value)[source]

Get instance from 1/100th mm value.

Parameters:

value (int) – 1/100th mm value.

Return type:

UnitMM

classmethod from_pt(value)[source]

Get instance from pt (points) value.

Parameters:

value (float) – pt value.

Return type:

UnitMM

classmethod from_px(value)[source]

Get instance from px (pixel) value.

Parameters:

value (float) – px value.

Return type:

UnitMM

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 in mm units.

Return type:

UnitMM

static get_unit_length()[source]

Gets instance unit length.

Returns:

Instance unit length UnitLength.MM.

Return type:

UnitLength

get_value_app_font(kind)[source]

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (PointSizeKind, optional): The kind of AppFont 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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.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

Class UnitT

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 which a and b are considered equal. You can adjust epsilon based on the precision you need.

Parameters:
  • val (float) – The value to compare with.

  • epsilon (float) – The maximum difference for which a and b 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:

UnitMM10

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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.utils.kind.point_size_kind.

classmethod from_cm(value)[source]

Get instance from cm value.

Parameters:

value (int) – cm value.

Return type:

UnitMM10

classmethod from_inch(value)[source]

Get instance from in (inch) value.

Parameters:

value (int) – in value.

Return type:

UnitMM10

classmethod from_inch10(value)[source]

Get instance from 1/10th in (inch) value.

Parameters:

value (int) – `/10th in value.

Return type:

UnitMM10

classmethod from_inch100(value)[source]

Get instance from 1/100th in (inch) value.

Parameters:

value (int) – 1/100th in value.

Return type:

UnitMM10

classmethod from_inch1000(value)[source]

Get instance from 1/1,000th in (inch) value.

Parameters:

value (int) – 1/1,000th in value.

Return type:

UnitMM10

classmethod from_mm(value)[source]

Get instance from mm value.

Parameters:

value (int) – mm value.

Return type:

UnitMM10

classmethod from_mm10(value)[source]

Get instance from 1/10th mm value.

Parameters:

value (int) – 1/10th mm value.

Return type:

UnitMM10

classmethod from_mm100(value)[source]

Get instance from 1/100th mm value.

Parameters:

value (int) – 1/100th mm value.

Return type:

UnitMM10

classmethod from_pt(value)[source]

Get instance from pt (points) value.

Parameters:

value (float) – pt value.

Return type:

UnitMM10

classmethod from_px(value)[source]

Get instance from px (pixel) value.

Parameters:

value (float) – px value.

Return type:

UnitMM10

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 in mm units.

Return type:

UnitMM10

static get_unit_length()[source]

Gets instance unit length.

Returns:

Instance unit length UnitLength.MM10.

Return type:

UnitLength

get_value_app_font(kind)[source]

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (PointSizeKind, optional): The kind of AppFont 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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.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

Class UnitT

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:

UnitMM100

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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.utils.kind.point_size_kind.

classmethod from_cm(value)[source]

Get instance from cm value.

Parameters:

value (int) – cm value.

Return type:

UnitMM100

classmethod from_inch(value)[source]

Get instance from in (inch) value.

Parameters:

value (int) – in value.

Return type:

UnitMM100

classmethod from_inch10(value)[source]

Get instance from 1/10th in (inch) value.

Parameters:

value (int) – `/10th in value.

Return type:

UnitMM100

classmethod from_inch100(value)[source]

Get instance from 1/100th in (inch) value.

Parameters:

value (int) – 1/100th in value.

Return type:

UnitMM100

classmethod from_inch1000(value)[source]

Get instance from 1/1,000th in (inch) value.

Parameters:

value (int) – 1/1,000th in value.

Return type:

UnitMM100

classmethod from_mm(value)[source]

Get instance from mm value.

Parameters:

value (int) – mm value.

Return type:

UnitMM100

classmethod from_mm10(value)[source]

Get instance from 1/10th mm value.

Parameters:

value (int) – 1/10th mm value.

Return type:

UnitMM100

classmethod from_mm100(value)[source]

Get instance from 1/100th mm value.

Parameters:

value (int) – 1/100th mm value.

Return type:

UnitMM100

classmethod from_pt(value)[source]

Get instance from pt (points) value.

Parameters:

value (int) – pt value.

Return type:

UnitMM100

classmethod from_px(value)[source]

Get instance from px (pixel) value.

Parameters:

value (float) – px value.

Return type:

UnitMM100

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 in 1/100th mm units.

Return type:

UnitMM100

static get_unit_length()[source]

Gets instance unit length.

Returns:

Instance unit length UnitLength.MM100.

Return type:

UnitLength

get_value_app_font(kind)[source]

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (PointSizeKind, optional): The kind of AppFont 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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.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

Class UnitT

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 which a and b are considered equal. You can adjust epsilon based on the precision you need.

Parameters:
  • val (float) – The value to compare with.

  • epsilon (float) – The maximum difference for which a and b 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:

UnitPT

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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.utils.kind.point_size_kind.

classmethod from_cm(value)[source]

Get instance from cm value.

Parameters:

value (int) – cm value.

Return type:

UnitPT

classmethod from_inch(value)[source]

Get instance from in (inch) value.

Parameters:

value (int) – in value.

Return type:

UnitPT

classmethod from_inch10(value)[source]

Get instance from 1/10th in (inch) value.

Parameters:

value (int) – 1/10th in value.

Return type:

UnitPT

classmethod from_inch100(value)[source]

Get instance from 1/100th in (inch) value.

Parameters:

value (int) – 1/100th in value.

Return type:

UnitPT

classmethod from_inch1000(value)[source]

Get instance from 1/1,000th in (inch) value.

Parameters:

value (int) – 1/1,000th in value.

Return type:

UnitPT

classmethod from_mm(value)[source]

Get instance from mm value.

Parameters:

value (int) – mm value.

Return type:

UnitPT

classmethod from_mm10(value)[source]

Get instance from 1/10th mm value.

Parameters:

value (int) – 1/10th mm value.

Return type:

UnitPT

classmethod from_mm100(value)[source]

Get instance from 1/100th mm value.

Parameters:

value (int) – 1/100th mm value.

Return type:

UnitPT

classmethod from_pt(value)[source]

Get instance from pt (points) value.

Parameters:

value (float) – pt value.

Return type:

UnitPT

classmethod from_px(value)[source]

Get instance from px (pixel) value.

Parameters:

value (float) – px value.

Return type:

UnitPT

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 in pt units.

Return type:

UnitPT

static get_unit_length()[source]

Gets instance unit length.

Returns:

Instance unit length UnitLength.PT.

Return type:

UnitLength

get_value_app_font(kind)[source]

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (PointSizeKind, optional): The kind of AppFont 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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.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

Class UnitT

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 which a and b are considered equal. You can adjust epsilon based on the precision you need.

Parameters:
  • val (float) – The value to compare with.

  • epsilon (float) – The maximum difference for which a and b 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:

UnitPX

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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.utils.kind.point_size_kind.

classmethod from_cm(value)[source]

Get instance from cm value.

Parameters:

value (int) – cm value.

Return type:

UnitPX

classmethod from_inch(value)[source]

Get instance from in (inch) value.

Parameters:

value (int) – in value.

Return type:

UnitPX

classmethod from_inch10(value)[source]

Get instance from 1/10th in (inch) value.

Parameters:

value (int) – 1/10th in value.

Return type:

UnitPX

classmethod from_inch100(value)[source]

Get instance from 1/100th in (inch) value.

Parameters:

value (int) – 1/100th in value.

Return type:

UnitPX

classmethod from_inch1000(value)[source]

Get instance from 1/1,000th in (inch) value.

Parameters:

value (int) – 1/1,000th in value.

Return type:

UnitPX

classmethod from_mm(value)[source]

Get instance from mm value.

Parameters:

value (int) – mm value.

Return type:

UnitPX

classmethod from_mm10(value)[source]

Get instance from 1/10th mm value.

Parameters:

value (int) – 1/10th mm value.

Return type:

UnitPX

classmethod from_mm100(value)[source]

Get instance from 1/100th mm value.

Parameters:

value (int) – 1/100th mm value.

Return type:

UnitPX

classmethod from_pt(value)[source]

Get instance from pt (points) value.

Parameters:

value (float) – pt value.

Return type:

UnitPX

classmethod from_px(value)[source]

Get instance from px (pixel) value.

Parameters:

value (float) – px value.

Return type:

UnitPX

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 in px units.

Return type:

UnitPX

static get_unit_length()[source]

Gets instance unit length.

Returns:

Instance unit length UnitLength.PX.

Return type:

UnitLength

get_value_app_font(kind)[source]

Gets instance value in AppFont units.

Returns:

Value in AppFont units. kind (PointSizeKind, optional): The kind of AppFont 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 to AppFontY(10) when they are converted to different units.

Kind when int is used, the value must be one of the following:

  • 0 is PointSizeKind.X,

  • 1 is PointSizeKind.Y,

  • 2 is PointSizeKind.WIDTH,

  • 3 is PointSizeKind.HEIGHT.

Hint

  • PointSizeKind can be imported from ooodev.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:

UnitT

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.