/*
 * 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
 */

package com.pullenti.unitext.internal.pdf;

public class PdfText extends PdfRect {

    public String text;

    public boolean fontType3;

    public double fontSize;

    public double spaceWidth;

    @Override
    public String toString() {
        return (super.toString() + ": \"" + ((text != null ? text : "?")) + "\"");
    }

    public void mergeWith(PdfText p) {
        text += p.text;
        if (p.x1 < x1) 
            x1 = p.x1;
        if (p.x2 > x2) 
            x2 = p.x2;
        if (p.y1 < y1) 
            y1 = p.y1;
        if (p.y2 > y2) 
            y2 = p.y2;
    }

    public static boolean MERGESPECIALREGIME = false;

    public boolean canBeMergedWith(PdfText p) {
        if (fontSize != p.fontSize) 
            return false;
        double d = p.x1 - x2;
        if (d < -1) {
            if (p.x2 > x2 && p.x1 > x1) {
            }
            else 
                return false;
        }
        if (d > spaceWidth) {
            if (text.endsWith("Сер")) {
            }
            if ((MERGESPECIALREGIME && p.getWidth() == 0 && (Math.abs(p.y1 - y1) < 3)) && (Math.abs(p.y2 - y2) < 10)) 
                return true;
            return false;
        }
        if (d > (spaceWidth / (2.0))) {
            double wi = ((this.getWidth() + p.getWidth())) / ((double)((text.length() + p.text.length())));
            if (d > (wi / (3.0))) 
                return false;
        }
        if (p.fontType3 || fontType3) 
            return false;
        if (y1 <= p.y1 && p.y2 <= y2) 
            return true;
        if (p.y1 <= y1 && y2 <= p.y2) 
            return true;
        if (com.pullenti.unisharp.Utils.stringsEq(p.text, " ") || ((p.text.length() == 1 && ((int)p.text.charAt(0)) == 0xA0))) {
            if (y1 <= p.y1 && (p.y1 < y2)) 
                return true;
        }
        d = y1 - p.y1;
        if (d < 0) 
            d = -d;
        if (d >= 1) {
            if (p.y1 <= y1 && p.y2 >= y2) {
            }
            return false;
        }
        d = y2 - p.y2;
        if (d < 0) 
            d = -d;
        if (d >= 1) 
            return false;
        return true;
    }
    public PdfText() {
        super();
    }
}
