WebCAD-Lib-TS API 文档 - v1.0.0
    Preparing search index...

    Class MTextColor

    Class to handle ACI and RGB color logic for MText.

    This class encapsulates color state for MText, supporting both AutoCAD Color Index (ACI) and RGB color. Only one color mode is active at a time: setting an RGB color disables ACI, and vice versa. RGB is stored as a single 24-bit integer (0xRRGGBB) for efficient comparison and serialization.

    Example usage:

    const color1 = new MTextColor(1); // ACI color
    const color2 = new MTextColor([255, 0, 0]); // RGB color
    const color3 = new MTextColor(); // Default (ACI=256, "by layer")
    Index

    Constructors

    Accessors

    Methods

    Constructors

    • Create a new MTextColor instance.

      Parameters

      • Optionalcolor: number | [number, number, number]

        The initial color: number for ACI, [r,g,b] for RGB, or null/undefined for default (ACI=256).

      Returns MTextColor

    Accessors

    • get aci(): number

      Get the current ACI color value.

      Returns number

      The ACI color (0-256), or null if using RGB.

    • set aci(value: number): void

      Set the ACI color value. Setting this disables any RGB color.

      Parameters

      • value: number

        The ACI color (0-256), or null to unset.

      Returns void

      Error if value is out of range.

    • get rgb(): [number, number, number]

      Get the current RGB color as a tuple [r, g, b], or null if not set.

      Returns [number, number, number]

      The RGB color tuple, or null if using ACI.

    • set rgb(value: [number, number, number]): void

      Set the RGB color. Setting this disables ACI color.

      Parameters

      • value: [number, number, number]

        The RGB color tuple [r, g, b], or null to use ACI.

      Returns void

    • get isRgb(): boolean

      Returns true if the color is set by RGB, false if by ACI.

      Returns boolean

    • get isAci(): boolean

      Returns true if the color is set by ACI, false if by RGB.

      Returns boolean

    • get rgbValue(): number

      Get or set the internal RGB value as a number (0xRRGGBB), or null if not set. Setting this will switch to RGB mode and set ACI to null.

      Returns number

    • set rgbValue(val: number): void

      Parameters

      • val: number

      Returns void

    Methods

    • Returns a deep copy of this color.

      Returns MTextColor

      A new MTextColor instance with the same color state.

    • Returns a plain object for serialization.

      Returns { aci: number; rgb: [number, number, number]; rgbValue: number }

      An object with aci, rgb (tuple), and rgbValue (number or null).

    • Equality check for color.

      Parameters

      • other: MTextColor

        The other MTextColor to compare.

      Returns boolean

      True if both ACI and RGB values are equal.