"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Geometry
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextString = void 0;
const core_geometry_1 = require("@itwin/core-geometry");
/** A single line of text, all with the same font, styles (underline, bold, italic), and size.
 * This class also holds the origin and direction for the text.
 * A paragraph is composed of one or more instances of TextStrings.
 * @public
 */
class TextString {
    get width() { return this.height * (this.widthFactor ? this.widthFactor : 1.0); }
    constructor(props) {
        this.text = props.text;
        this.font = props.font;
        this.height = props.height;
        this.widthFactor = props.widthFactor;
        this.bold = props.bold;
        this.italic = props.italic;
        this.underline = props.underline;
        this.origin = core_geometry_1.Point3d.fromJSON(props.origin);
        this.rotation = core_geometry_1.YawPitchRollAngles.fromJSON(props.rotation);
    }
    toJSON() {
        const props = {
            text: this.text,
            font: this.font,
            height: this.height,
            widthFactor: this.widthFactor,
            bold: this.bold,
            italic: this.italic,
            underline: this.underline,
        };
        if (!this.origin.isAlmostZero) {
            props.origin = this.origin.toJSON();
        }
        if (!this.rotation.isIdentity()) {
            props.rotation = this.rotation.toJSON();
        }
        return props;
    }
    transformInPlace(transform) {
        const newOrigin = transform.multiplyPoint3d(this.origin, this.origin);
        const newTransform = this.rotation.toMatrix3d().multiplyMatrixTransform(transform);
        const scales = new core_geometry_1.Vector3d();
        if (!newTransform.matrix.normalizeColumnsInPlace(scales))
            return false;
        const newRotation = core_geometry_1.YawPitchRollAngles.createFromMatrix3d(newTransform.matrix);
        if (undefined === newRotation)
            return false;
        const newHeight = this.height * scales.y;
        const newWidth = this.width * scales.x;
        if (newHeight < 1.0e-10 || newWidth < 1.0e-10)
            return false;
        this.origin.setFrom(newOrigin);
        this.rotation.setFrom(newRotation);
        this.height = newHeight;
        this.widthFactor = (newHeight === newWidth ? undefined : (newWidth / newHeight));
        return true;
    }
}
exports.TextString = TextString;
//# sourceMappingURL=TextString.js.map