var _TextState = /** @class */ (function () {
    function _TextState() {
        this._identityMatrix = [1, 0, 0, 1, 0, 0];
        this._fontIdentityMatrix = [0.001, 0, 0, 0.001, 0, 0];
        this._ctm = this._identityMatrix;
        this._fontName = null;
        this._fontSize = 0;
        this._font = null;
        this._fontMatrix = this._fontIdentityMatrix;
        this._textMatrix = this._identityMatrix.slice();
        this._textLineMatrix = this._identityMatrix.slice();
        this._charSpacing = 0;
        this._wordSpacing = 0;
        this._leading = 0;
        this._textHScale = 1;
        this._textRise = 0;
    }
    _TextState.prototype._setTextMatrix = function (a, b, c, d, e, f) {
        var matrix = this._textMatrix;
        matrix[0] = a;
        matrix[1] = b;
        matrix[2] = c;
        matrix[3] = d;
        matrix[4] = e;
        matrix[5] = f;
    };
    _TextState.prototype._setTextLineMatrix = function (a, b, c, d, e, f) {
        var matrix = this._textLineMatrix;
        matrix[0] = a;
        matrix[1] = b;
        matrix[2] = c;
        matrix[3] = d;
        matrix[4] = e;
        matrix[5] = f;
    };
    _TextState.prototype._translateTextMatrix = function (x, y) {
        var matrix = this._textMatrix;
        matrix[4] = matrix[0] * x + matrix[2] * y + matrix[4];
        matrix[5] = matrix[1] * x + matrix[3] * y + matrix[5];
    };
    _TextState.prototype._translateTextLineMatrix = function (x, y) {
        var matrix = this._textLineMatrix;
        matrix[4] = matrix[0] * x + matrix[2] * y + matrix[4];
        matrix[5] = matrix[1] * x + matrix[3] * y + matrix[5];
    };
    _TextState.prototype._carriageReturn = function () {
        this._translateTextLineMatrix(0, -this._leading);
        this._textMatrix = this._textLineMatrix.slice();
    };
    _TextState.prototype._clone = function () {
        var clone = Object.create(this); //eslint-disable-line
        clone._textMatrix = this._textMatrix.slice();
        clone._textLineMatrix = this._textLineMatrix.slice();
        clone._fontMatrix = this._fontMatrix.slice();
        return clone;
    };
    return _TextState;
}());
export { _TextState };
var _GraphicState = /** @class */ (function () {
    function _GraphicState(currentState) {
        if (!currentState) {
            this._state = new _TextState();
        }
        else {
            this._state = currentState;
        }
        this._stateStack = [];
    }
    _GraphicState.prototype._save = function () {
        var oldState = this._state;
        this._stateStack.push(this._state);
        this._state = oldState._clone();
    };
    _GraphicState.prototype._restore = function () {
        var prev = this._stateStack.pop();
        if (prev) {
            this._state = prev;
        }
    };
    _GraphicState.prototype._transform = function (args) {
        this._state._ctm = this._transformMatrix(this._state._ctm, args);
    };
    _GraphicState.prototype._transformMatrix = function (m1, m2) {
        return [
            m1[0] * m2[0] + m1[2] * m2[1],
            m1[1] * m2[0] + m1[3] * m2[1],
            m1[0] * m2[2] + m1[2] * m2[3],
            m1[1] * m2[2] + m1[3] * m2[3],
            m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
            m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
        ];
    };
    return _GraphicState;
}());
export { _GraphicState };
