Skip to content
GitHub Action edited this page Aug 29, 2024 · 2 revisions

Class Text

The Text class is designed to represent and manipulate text within a coordinate system, allowing for the creation of text objects with specific fonts, sizes, and positions. It is capable of generating and translating text into a series of geometric representations.

Constructor

__init__(self, text: str = None, font_family: str = None, cs=CoordinateSystem, height=None) -> Text

Initializes a new Text instance

    - `id` (str): A unique identifier for the text object.
    - `type` (str): The class name, "Text".
    - `text` (str, optional): The text string to be represented.
    - `font_family` (str, optional): The font family of the text, defaulting to "Arial".
    - `xyz` (Vector): The origin point of the text in the coordinate system.
    - `csglobal` (CoordinateSystem): The global coordinate system applied to the text.
    - `x`, `y`, `z` (float): The position offsets for the text within its coordinate system.
    - `scale` (float, optional): The scale factor applied to the text size.
    - `height` (float, optional): The height of the text characters.
    - `bbHeight` (float, optional): The bounding box height of the text.
    - `width` (float, optional): The calculated width of the text string.
    - `character_offset` (int): The offset between characters.
    - `space` (int): The space between words.
    - `curves` (list): A list of curves representing the text geometry.
    - `points` (list): A list of points derived from the text geometry.
    - `path_list` (list): A list containing the path data for each character.

Methods

  • calculate_bounding_box(self, points: list[Point]) -> tuple: Calculates the bounding box for a given set of points.

  • convert_points_to_polyline(self, points: list[Point]) -> PolyCurve: Converts a list of points into a PolyCurve. This method is used to generate a PolyCurve from a series of points, typically derived from text path data.

  • load_path(self) -> str: Loads the glyph paths for the specified text from a JSON file. This method fetches the glyph paths for each character in the text attribute, using a predefined font JSON file.

  • serialize(self) -> dict: Serializes the text object's attributes into a dictionary. This method is useful for exporting the text object's properties, making it easier to save or transmit as JSON.

  • translate(self, polyCurve: PolyCurve) -> PolyCurve: Translates a PolyCurve according to the text object's global coordinate system and scale.

  • write(self) -> List[List[PolyCurve]]: Generates a list of PolyCurve objects representing the text. Transforms the text into geometric representations based on the specified font, scale, and position.

Documentation

calculate_bounding_box(self, points: list[Point]) -> tuple

Calculates the bounding box for a given set of points.

Parameters:

points (list): A list of points to calculate the bounding box for.

Returns:

tuple: A tuple containing the bounding box, its width, and its height.

Example usage:


convert_points_to_polyline(self, points: list[Point]) -> PolyCurve

Converts a list of points into a PolyCurve. This method is used to generate a PolyCurve from a series of points, typically derived from text path data.

Parameters:

points (list): A list of points to be converted into a PolyCurve.

Returns:

PolyCurve: A PolyCurve object representing the points.

Example usage:


load_path(self) -> str

Loads the glyph paths for the specified text from a JSON file. This method fetches the glyph paths for each character in the text attribute, using a predefined font JSON file.

Returns:

str: A string representation of the glyph paths for the text.

Example usage:


serialize(self) -> dict

Serializes the text object's attributes into a dictionary. This method is useful for exporting the text object's properties, making it easier to save or transmit as JSON.

Returns:

dict: A dictionary containing the serialized attributes of the text object.

Example usage:


translate(self, polyCurve: PolyCurve) -> PolyCurve

Translates a PolyCurve according to the text object's global coordinate system and scale.

Parameters:

polyCurve (PolyCurve): The PolyCurve to be translated.

Returns:

PolyCurve: The translated PolyCurve.

Example usage:


write(self) -> List[List[PolyCurve]]

Generates a list of PolyCurve objects representing the text. Transforms the text into geometric representations based on the specified font, scale, and position.

Returns:

List[List[PolyCurve]]: A list of lists containing PolyCurve objects representing the text geometry.

Example usage:


Clone this wiki locally