/*
 * SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software. 
 * This class is generated using the converter UniSharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */


const PdfRect = require("./PdfRect");

class PdfText extends PdfRect {
    
    constructor() {
        super();
        this.text = null;
        this.fontType3 = false;
        this.fontSize = 0;
        this.spaceWidth = 0;
    }
    
    toString() {
        return (super.toString() + ": \"" + ((this.text != null ? this.text : "?")) + "\"");
    }
    
    mergeWith(p) {
        this.text += p.text;
        if (p.x1 < this.x1) 
            this.x1 = p.x1;
        if (p.x2 > this.x2) 
            this.x2 = p.x2;
        if (p.y1 < this.y1) 
            this.y1 = p.y1;
        if (p.y2 > this.y2) 
            this.y2 = p.y2;
    }
    
    canBeMergedWith(p) {
        if (this.fontSize !== p.fontSize) 
            return false;
        let d = p.x1 - this.x2;
        if (d < -1) {
            if (p.x2 > this.x2 && p.x1 > this.x1) {
            }
            else 
                return false;
        }
        if (d > this.spaceWidth) {
            if (this.text.endsWith("Сер")) {
            }
            if ((PdfText.MERGE_SPECIAL_REGIME && p.width === 0 && (Math.abs(p.y1 - this.y1) < 3)) && (Math.abs(p.y2 - this.y2) < 10)) 
                return true;
            return false;
        }
        if (d > (this.spaceWidth / (2))) {
            let wi = ((this.width + p.width)) / ((this.text.length + p.text.length));
            if (d > (wi / (3))) 
                return false;
        }
        if (p.fontType3 || this.fontType3) 
            return false;
        if (this.y1 <= p.y1 && p.y2 <= this.y2) 
            return true;
        if (p.y1 <= this.y1 && this.y2 <= p.y2) 
            return true;
        if (p.text === " " || ((p.text.length === 1 && (p.text.charCodeAt(0)) === 0xA0))) {
            if (this.y1 <= p.y1 && (p.y1 < this.y2)) 
                return true;
        }
        d = this.y1 - p.y1;
        if (d < 0) 
            d = -d;
        if (d >= 1) {
            if (p.y1 <= this.y1 && p.y2 >= this.y2) {
            }
            return false;
        }
        d = this.y2 - p.y2;
        if (d < 0) 
            d = -d;
        if (d >= 1) 
            return false;
        return true;
    }
    
    static static_constructor() {
        PdfText.MERGE_SPECIAL_REGIME = false;
    }
}


PdfText.static_constructor();

module.exports = PdfText