TextDisplay.java 20.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.xfa.text;

import com.adobe.xfa.gfx.GFXEnv;
import com.adobe.xfa.text.DispChange;
import com.adobe.xfa.text.DispLineRaw;
import com.adobe.xfa.text.DispLineWrapped;
import com.adobe.xfa.text.DispMapSet;
import com.adobe.xfa.text.DispTab;
import com.adobe.xfa.text.DrawParm;
import com.adobe.xfa.text.FormatInfo;
import com.adobe.xfa.text.FrameCaretRect;
import com.adobe.xfa.text.FrameCaretStartEnd;
import com.adobe.xfa.text.FrameDispInfo;
import com.adobe.xfa.text.FrameGfxDraw;
import com.adobe.xfa.text.LocaleInfo;
import com.adobe.xfa.text.TextAttr;
import com.adobe.xfa.text.TextBreakFinder;
import com.adobe.xfa.text.TextContext;
import com.adobe.xfa.text.TextDrawInfo;
import com.adobe.xfa.text.TextField;
import com.adobe.xfa.text.TextFrame;
import com.adobe.xfa.text.TextPosn;
import com.adobe.xfa.text.TextPosnBase;
import com.adobe.xfa.text.TextSparseStream;
import com.adobe.xfa.text.TextStream;
import com.adobe.xfa.ut.LcLocale;
import com.adobe.xfa.ut.Rect;
import com.adobe.xfa.ut.Storage;
import com.adobe.xfa.ut.UnitSpan;
import java.util.List;

public class TextDisplay {
    TextSparseStream mpoStream;
    public GFXEnv mpoEnv;
    public int mnLineCount;
    public int mnSuppressFormat;
    public int mnIgnoreUpdates;
    public final DispChange moChange = new DispChange();
    public final Storage<DispTab> moTabs = new Storage();
    public LocaleInfo moLocaleInfo;
    public TextBreakFinder mpoBreakFinder;
    public int meLayoutOrientation = 0;
    public boolean mbHasFontSubstitution;

    public boolean gfxDraw(TextDrawInfo oDrawInfo) {
        Rect oTranslated = oDrawInfo.getInvalid();
        if (oTranslated == null || oTranslated.isDegenerate()) {
            oTranslated = TextDisplay.computeClipRect(this.mpoStream, oDrawInfo.getInvalidDefault());
        }
        DrawParm oParm = new DrawParm(oDrawInfo);
        oParm.setInvalid(oTranslated);
        if (oDrawInfo.getTruncate()) {
            Rect oExtent = TextDisplay.computeClipRect(this.mpoStream);
            oParm.setTruncate(oExtent);
        }
        FrameGfxDraw oDraw = new FrameGfxDraw(this.mpoStream, oParm);
        oDraw.processFrames();
        return oDraw.fits();
    }

    public int lines() {
        return this.mnLineCount;
    }

    public boolean suppressFormat() {
        return this.mnSuppressFormat > 0;
    }

    public void pushSuppressFormat() {
        ++this.mnSuppressFormat;
    }

    public void popSuppressFormat() {
        if (this.mnSuppressFormat > 0) {
            if (this.mnSuppressFormat > 1) {
                --this.mnSuppressFormat;
            } else {
                this.clearSuppressFormat();
            }
        }
    }

    public void clearSuppressFormat() {
        if (this.mnSuppressFormat == 0) {
            return;
        }
        this.mnSuppressFormat = 0;
        this.layout(true);
    }

    public boolean hasFontSubstitution() {
        return this.mbHasFontSubstitution;
    }

    public void setFontSubstitution(boolean bSubstitution) {
        this.mbHasFontSubstitution = bSubstitution;
    }

    public void updateSuspectLayout() {
        boolean bUpdated = false;
        for (int i = 0; i < this.mpoStream.getFrameCount(); ++i) {
            int nEndIndex;
            TextFrame poFrame = this.mpoStream.getFrame(i);
            if (poFrame == null || poFrame.getLayoutState() != 2) continue;
            int nStartIndex = poFrame.getStart().index();
            int nNextFrame = i + 1;
            if (nNextFrame >= this.mpoStream.getFrameCount()) {
                nEndIndex = this.mpoStream.posnCount();
            } else {
                DispLineWrapped poLast;
                TextFrame poNextFrame = this.mpoStream.getFrame(nNextFrame, true);
                TextPosnBase oEndPosn = new TextPosnBase(poNextFrame.getStart());
                int nLines = poFrame.getLineCount();
                if (nLines > 0 && (poLast = poFrame.getLine(nLines - 1)).getLastParaLine() >= 2) {
                    oEndPosn.prevUserPosn();
                }
                nEndIndex = oEndPosn.index();
            }
            this.moChange.frame(this.mpoStream, nStartIndex, nEndIndex - nStartIndex);
            this.layout(true, i, true, null);
            bUpdated = true;
        }
        if (bUpdated) {
            // empty if block
        }
    }

    public TextSparseStream stream() {
        return this.mpoStream;
    }

    Rect runtimeExtent(boolean bExtended) {
        FrameDispInfo oInfoFinder = new FrameDispInfo(this.mpoStream, bExtended);
        oInfoFinder.processFrames();
        return oInfoFinder.getExtent();
    }

    public Rect runtimeExtent() {
        return this.runtimeExtent(false);
    }

    Rect frame0Extent() {
        if (this.mpoStream == null) {
            return null;
        }
        TextFrame poFrame = this.mpoStream.forceFrame(0);
        if (poFrame == null) {
            return null;
        }
        return poFrame.getExtent();
    }

    void recomputeLineCount() {
        this.mnLineCount = 0;
        int nFrames = this.mpoStream.getFrameCount();
        for (int i = 0; i < nFrames; ++i) {
            TextFrame poFrame = this.mpoStream.getFrame(i);
            if (poFrame == null) continue;
            this.mnLineCount += poFrame.getLineCount();
        }
    }

    void connectStream(TextSparseStream poNewStream, boolean bSuppressLayout, TextAttr poDefaultAttr) {
        this.cleanup();
        this.mpoStream = poNewStream;
        this.mpoStream.textDisplaySet(this);
        if (!bSuppressLayout) {
            this.create(poDefaultAttr);
        }
    }

    void connectStream(TextSparseStream poNewStream, boolean bSuppressLayout) {
        this.connectStream(poNewStream, false, null);
    }

    void connectStream(TextSparseStream poNewStream) {
        this.connectStream(poNewStream, false);
    }

    void create(TextAttr poDefaultAttr) {
        this.moChange.full();
        this.layout(false, 0, false, poDefaultAttr);
    }

    boolean update() {
        if (this.mnIgnoreUpdates > 0) {
            return true;
        }
        this.moChange.full();
        return this.layout(true);
    }

    boolean updateInsert(TextStream poStream, int nIndex, int nChange) {
        if (this.mnIgnoreUpdates > 0) {
            return true;
        }
        this.moChange.insert(poStream, nIndex, nChange);
        return this.layout(true);
    }

    boolean updateDelete(TextStream poStream, int nIndex, int nChange) {
        if (this.mnIgnoreUpdates > 0) {
            return true;
        }
        this.moChange.delete(poStream, nIndex, nChange);
        return this.layout(true);
    }

    boolean updateOther(TextStream poStream, int nIndex, int nCount) {
        if (this.mnIgnoreUpdates > 0) {
            return true;
        }
        this.moChange.other(poStream, nIndex, nCount);
        return this.layout(true);
    }

    boolean updateToEnd(TextStream poStream, int nIndex) {
        if (this.mnIgnoreUpdates > 0) {
            return true;
        }
        this.moChange.toEnd(poStream, nIndex);
        return this.layout(true);
    }

    void updateJustify() {
        if (this.mnIgnoreUpdates > 0) {
            return;
        }
        this.moChange.setJustify();
        this.layout(true);
    }

    void detach(TextStream poStream) {
        if (poStream != this.mpoStream) {
            this.update();
        }
        poStream.textDisplaySet(null);
    }

    void ignoreUpdates(boolean bIgnore) {
        if (bIgnore) {
            ++this.mnIgnoreUpdates;
        } else {
            assert (this.mnIgnoreUpdates > 0);
            --this.mnIgnoreUpdates;
        }
    }

    UnitSpan caretUp(TextPosnBase oPosn, UnitSpan poTarget, TextPosnBase oResult) {
        return this.vertMove(oPosn, true, poTarget, oResult);
    }

    UnitSpan caretDown(TextPosnBase oPosn, UnitSpan poTarget, TextPosnBase oResult) {
        return this.vertMove(oPosn, false, poTarget, oResult);
    }

    boolean caretStartEnd(TextPosnBase oPosn, boolean bEnd, boolean bVisual, TextPosnBase oResult) {
        FrameCaretStartEnd oCaret = new FrameCaretStartEnd(this.mpoStream, oPosn, bEnd, bVisual, oResult);
        oCaret.processFrames();
        return oCaret.success();
    }

    /*
     * Exception decompiling
     */
    int caretLeftRight(TextPosnBase oPosn, boolean bRight, TextPosnBase oResult) {
        // This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
        // org.benf.cfr.reader.util.ConfusedCFRException: Tried to end blocks [0[DOLOOP]], but top level block is 6[SIMPLE_IF_TAKEN]
        // org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.processEndingBlocks(Op04StructuredStatement.java:397)
        // org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:449)
        // org.benf.cfr.reader.bytecode.analysis.opgraph.Op03SimpleStatement.createInitialStructuredBlock(Op03SimpleStatement.java:2877)
        // org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:825)
        // org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:217)
        // org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:162)
        // org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:95)
        // org.benf.cfr.reader.entities.Method.analyse(Method.java:355)
        // org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:768)
        // org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:700)
        // org.benf.cfr.reader.Main.doJar(Main.java:134)
        // org.benf.cfr.reader.Main.main(Main.java:189)
        throw new IllegalStateException("Decompilation failed");
    }

    void checkAXTELigature(TextPosnBase oPosn, boolean bForward) {
        FindCaretInfo info = this.findCaretLine(oPosn);
        if (info == null) {
            return;
        }
        TextFrame poFrame = this.mpoStream.getFrame(info.mFrameIndex);
        poFrame.getLine(info.mLineIndex).checkAXTELigature(oPosn, bForward);
    }

    boolean isAtStart(TextPosnBase oPosn, boolean bCheckFirstLineOnly) {
        FindCaretInfo info = this.findCaretLine(oPosn);
        if (info == null) {
            return false;
        }
        if (bCheckFirstLineOnly && (info.mFrameIndex > 0 || info.mLineIndex > 0)) {
            return false;
        }
        TextFrame poFrame = this.mpoStream.getFrame(info.mFrameIndex);
        return poFrame.getLine(info.mLineIndex).isAtStart(oPosn);
    }

    TextContext getContext() {
        return this.mpoStream == null ? null : this.mpoStream.forceContext();
    }

    GFXEnv getGFXEnv() {
        return this.mpoEnv;
    }

    DispChange getChange() {
        return this.moChange;
    }

    DispMapSet getDisposableMaps() {
        return this.getContext().getDisposableMaps();
    }

    public void releaseDisposableMaps(DispMapSet poMaps) {
        this.getContext().releaseDisposableMaps(poMaps);
    }

    void setLocale(TextAttr poAttr) {
        int eDirection = 0;
        String sLocale = "";
        if (poAttr != null) {
            eDirection = poAttr.paraDirection();
            if (eDirection == 0) {
                eDirection = poAttr.direction();
            }
            sLocale = poAttr.actualLocale();
        }
        this.moLocaleInfo = this.getContext().lookupLocale(sLocale);
        this.moLocaleInfo = new LocaleInfo(this.moLocaleInfo);
        if (this.mpoStream.defaultDirection() != 0) {
            eDirection = this.mpoStream.defaultDirection();
        }
        switch (eDirection) {
            case 1: {
                this.moLocaleInfo.mbIsRTL = false;
                break;
            }
            case 2: {
                this.moLocaleInfo.mbIsRTL = true;
            }
        }
    }

    LocaleInfo getLocale(String sLocaleName) {
        return this.getContext().lookupLocale(sLocaleName);
    }

    TextBreakFinder getBreakFinder() {
        this.mpoBreakFinder = TextBreakFinder.recycle(this.moLocaleInfo.mpoLocale, this.mpoBreakFinder);
        return this.mpoBreakFinder;
    }

    int getLayoutOrientation() {
        return this.meLayoutOrientation;
    }

    boolean isRTL(TextAttr poAttr) {
        boolean bRTL = this.moLocaleInfo.mbIsRTL;
        if (poAttr != null) {
            int eDirection = poAttr.direction();
            if (eDirection == 1) {
                bRTL = false;
            } else if (eDirection == 2) {
                bRTL = true;
            } else {
                LocaleInfo oLocaleInfo = this.getContext().lookupLocale(poAttr.actualLocale());
                bRTL = oLocaleInfo.mbIsRTL;
            }
        }
        return bRTL;
    }

    boolean isRTL() {
        return this.isRTL(null);
    }

    boolean isIdeographic(TextAttr poAttr) {
        boolean bIdeographic = this.moLocaleInfo.mbIsIdeographic;
        if (poAttr != null) {
            LocaleInfo oLocaleInfo = this.getContext().lookupLocale(poAttr.actualLocale());
            bIdeographic = oLocaleInfo.mbIsIdeographic;
        }
        return bIdeographic;
    }

    boolean isIdeographic() {
        return this.isIdeographic(null);
    }

    int getDigits(TextAttr poAttr) {
        if (poAttr == null || poAttr.digits() == 0) {
            return this.moLocaleInfo.meDigits;
        }
        return poAttr.digits();
    }

    boolean[] getBreakCandidates(int nCount, int nPreserve) {
        return this.getContext().getBreakCandidates(nCount, nPreserve);
    }

    boolean[] getBreakCandidates(int nCount) {
        return this.getContext().getBreakCandidates(nCount, 0);
    }

    int getLegacyLevel() {
        return this.mpoStream.getLegacyLevel();
    }

    FindCaretInfo findCaretLine(TextPosnBase oPosn) {
        FrameCaretRect oSearch = new FrameCaretRect(this.mpoStream, oPosn, false, true);
        oSearch.processFrames();
        if (!oSearch.success()) {
            return null;
        }
        return new FindCaretInfo(oSearch.getFrameIndex(), oSearch.getLineIndex(), oSearch.getCaret());
    }

    private boolean layout(boolean bUpdate, int nFrameIndex, boolean bSuppressSuspectFrames, TextAttr poDefaultAttr) {
        TextFrame poFrame;
        if (this.mnSuppressFormat > 0 || this.mnIgnoreUpdates > 0) {
            return true;
        }
        if (this.mpoStream.getFrameCount() > 0 && (poFrame = this.mpoStream.getFrame(0)) != null && !poFrame.alignHPoint() && poFrame.minWidth() != poFrame.maxWidth()) {
            this.moChange.full();
        }
        TextPosnBase oStartStream = new TextPosnBase(this.mpoStream);
        TextAttr poAttr = oStartStream.attributePtr();
        int eJustH = 5;
        int eJustV = 1;
        this.meLayoutOrientation = 0;
        if (poAttr != null) {
            eJustH = poAttr.justifyH();
            eJustV = poAttr.justifyV();
            if (poAttr.layoutOrientationEnable()) {
                this.meLayoutOrientation = poAttr.layoutOrientation();
            }
            if (poAttr.fontEnable() && poAttr.substituteFont()) {
                this.setFontSubstitution(true);
            }
        }
        this.setLocale(poAttr);
        FormatInfo oInfo = new FormatInfo(this, this.moTabs, bUpdate, eJustH, eJustV, nFrameIndex, poDefaultAttr);
        if (oInfo.isUpdate() && oInfo.getChange().type() != 0) {
            this.mpoStream.updateLastLineFlag(false);
        }
        if (oInfo.getChange().type() != 0 && !oInfo.allInitialLayout()) {
            boolean bNewPara = oInfo.isNewPara();
            boolean bContinue = true;
            do {
                DispLineRaw oRawLine = new DispLineRaw(oInfo, bNewPara);
                bContinue = oRawLine.fill();
                bNewPara = oRawLine.isLastParaLine();
                oRawLine.detach();
            } while (bContinue);
        }
        if (oInfo.getChange().type() != 0) {
            this.mpoStream.updateLastLineFlag(true);
        }
        oInfo.finish();
        this.mnLineCount = 0;
        int nFrames = this.mpoStream.getFrameCount();
        for (int i = 0; i < nFrames; ++i) {
            TextFrame poFrame2 = this.mpoStream.getFrame(i);
            if (poFrame2 == null) continue;
            if (this.moChange.type() == 0) {
                // empty if block
            }
            this.mnLineCount += poFrame2.getLineCount();
        }
        if (oInfo.updateConnect()) {
            // empty if block
        }
        this.moChange.reset();
        if (!bSuppressSuspectFrames) {
            // empty if block
        }
        return oInfo.fits();
    }

    private boolean layout(boolean bUpdate) {
        return this.layout(bUpdate, 0, true, null);
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    UnitSpan vertMove(TextPosnBase oPosn, boolean bUp, UnitSpan poTarget, TextPosnBase oResult) {
        FindCaretInfo info = this.findCaretLine(oPosn);
        if (info == null) {
            return null;
        }
        Rect oCaret = info.mCaret;
        int nFrameIndex = info.mFrameIndex;
        int nLineIndex = info.mLineIndex;
        if (poTarget == null) {
            poTarget = oCaret.left().add(oCaret.right());
            poTarget = poTarget.divide(2);
        }
        TextFrame poFrame = this.mpoStream.getFrame(nFrameIndex);
        boolean bFound = false;
        if (bUp) {
            while (!bFound) {
                DispLineWrapped poLine;
                if (nLineIndex == 0) {
                    if (nFrameIndex == 0) return poTarget;
                    poFrame = this.mpoStream.forceFrame(--nFrameIndex);
                    nLineIndex = poFrame.getLineCount();
                }
                if (nLineIndex <= 0 || (poLine = poFrame.getLine(--nLineIndex)).getCaretPosn(oPosn.stream(), poTarget, oResult) == 0) continue;
                return poTarget;
            }
            return poTarget;
        } else {
            ++nLineIndex;
            while (!bFound) {
                DispLineWrapped poLine;
                if (nLineIndex >= poFrame.getLineCount()) {
                    if (++nFrameIndex >= this.mpoStream.getFrameCount()) return poTarget;
                    poFrame = this.mpoStream.forceFrame(nFrameIndex);
                    nLineIndex = 0;
                }
                if ((poLine = poFrame.getLine(nLineIndex)).getCaretPosn(oPosn.stream(), poTarget, oResult) != 0) {
                    bFound = true;
                }
                ++nLineIndex;
            }
        }
        return poTarget;
    }

    void detachStream(TextStream poStream) {
        if (poStream == null) {
            return;
        }
        poStream.textDisplaySet(null);
        Storage<TextField> oFields = new Storage<TextField>();
        poStream.enumField(oFields);
        for (int i = 0; i < oFields.size(); ++i) {
            this.detachStream(oFields.get(i));
        }
    }

    void cleanup() {
        this.detachStream(this.mpoStream);
        this.mpoStream = null;
        this.mnSuppressFormat = 0;
        this.mnIgnoreUpdates = 0;
        this.mpoBreakFinder = null;
        this.moTabs.setSize(0);
        this.mnLineCount = 0;
        this.mbHasFontSubstitution = false;
    }

    private static Rect computeClipRect(TextSparseStream poStream) {
        return TextDisplay.computeClipRect(poStream, 1);
    }

    private static Rect computeClipRect(TextSparseStream poStream, int eInvalidDefault) {
        Rect oExtent;
        if (eInvalidDefault == 0 && poStream.display() != null) {
            oExtent = poStream.display().runtimeExtent();
        } else {
            TextFrame poFrame = poStream.forceFrame(0);
            oExtent = poFrame.getExtent();
            if (eInvalidDefault == 1) {
                UnitSpan oMaxHeight;
                UnitSpan oMaxWidth = poFrame.maxWidth();
                if (oMaxWidth.value() >= 0) {
                    oExtent = oExtent.leftRight(UnitSpan.ZERO, oMaxWidth);
                }
                if ((oMaxHeight = poFrame.maxHeight()).value() > 0) {
                    oExtent = oExtent.topBottom(UnitSpan.ZERO, oMaxHeight);
                }
            }
        }
        return oExtent;
    }

    static class FindCaretInfo {
        final int mFrameIndex;
        final int mLineIndex;
        final Rect mCaret;

        FindCaretInfo(int frameIndex, int lineIndex, Rect caret) {
            this.mFrameIndex = frameIndex;
            this.mLineIndex = lineIndex;
            this.mCaret = caret;
        }
    }

}