BoxModelCaptionable.java 20.6 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
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.xfa.layout;

import com.adobe.xfa.AppModel;
import com.adobe.xfa.Attribute;
import com.adobe.xfa.Element;
import com.adobe.xfa.Measurement;
import com.adobe.xfa.Node;
import com.adobe.xfa.XFA;
import com.adobe.xfa.content.Content;
import com.adobe.xfa.content.DateTimeValue;
import com.adobe.xfa.content.DateValue;
import com.adobe.xfa.content.DecimalValue;
import com.adobe.xfa.content.ExDataValue;
import com.adobe.xfa.content.FloatValue;
import com.adobe.xfa.content.IntegerValue;
import com.adobe.xfa.content.TextValue;
import com.adobe.xfa.content.TimeValue;
import com.adobe.xfa.font.FontService;
import com.adobe.xfa.font.GfxTextAttrs;
import com.adobe.xfa.gfx.GFXColour;
import com.adobe.xfa.layout.BoxModelLayout;
import com.adobe.xfa.layout.BoxModelRenderProxy;
import com.adobe.xfa.layout.LayoutEnv;
import com.adobe.xfa.layout.LayoutHandler;
import com.adobe.xfa.template.TemplateResolver;
import com.adobe.xfa.template.containers.Draw;
import com.adobe.xfa.template.containers.ExclGroup;
import com.adobe.xfa.template.containers.Field;
import com.adobe.xfa.text.TextAttr;
import com.adobe.xfa.text.TextBaselineShift;
import com.adobe.xfa.text.TextDisplay;
import com.adobe.xfa.text.TextMeasurement;
import com.adobe.xfa.text.TextPosn;
import com.adobe.xfa.text.TextPosnBase;
import com.adobe.xfa.text.TextRange;
import com.adobe.xfa.text.TextRegion;
import com.adobe.xfa.text.TextStream;
import com.adobe.xfa.text.markup.MarkupAttr;
import com.adobe.xfa.text.markup.MarkupOut;
import com.adobe.xfa.text.markup.MarkupRtfOut;
import com.adobe.xfa.text.markup.MarkupXHTMLAttr;
import com.adobe.xfa.text.markup.MarkupXHTMLIn;
import com.adobe.xfa.text.markup.MarkupXHTMLOut;
import com.adobe.xfa.ut.Angle;
import com.adobe.xfa.ut.CoordPair;
import com.adobe.xfa.ut.ExFull;
import com.adobe.xfa.ut.Margins;
import com.adobe.xfa.ut.Rect;
import com.adobe.xfa.ut.ResId;
import com.adobe.xfa.ut.StringUtils;
import com.adobe.xfa.ut.UnitSpan;
import java.util.ArrayList;
import java.util.List;

abstract class BoxModelCaptionable
extends BoxModelRenderProxy {
    protected boolean m_bReserveCaptionSpace = false;
    protected UnitSpan m_oReserveCaptionSpace = UnitSpan.ZERO;
    protected int m_eCaptionPlacement = 4194307;
    protected int m_eCaptionPresence = 1076494336;
    protected UnitSpan m_oLineHeight = UnitSpan.ZERO;
    protected Rect m_oCaptionDisplayExtent = Rect.ZERO;
    protected boolean m_bSplitCaption = false;
    protected TextPosn m_oStartCaptionPosn = new TextPosn();
    protected TextPosn m_oEndCaptionPosn = new TextPosn();
    protected boolean m_bKeepCaptionTextStream = false;
    protected boolean m_bAllowRenderProxy;

    public BoxModelCaptionable(LayoutEnv oEnv, boolean bAllowRenderProxy) {
        super(oEnv);
        this.m_bAllowRenderProxy = bAllowRenderProxy;
    }

    @Override
    public void clear() {
        this.m_bKeepCaptionTextStream = false;
        this.m_bReserveCaptionSpace = false;
        this.m_eCaptionPlacement = 4194307;
        this.m_eCaptionPresence = 1076494336;
        this.m_bSplitCaption = false;
        this.m_bKeepCaptionTextStream = false;
        this.m_oReserveCaptionSpace = UnitSpan.ZERO;
        super.clear();
    }

    @Override
    public void reinitialize(Element oNode) {
        if (!this.m_bKeepCaptionTextStream) {
            super.reinitialize(oNode);
            return;
        }
        assert (oNode != null);
        this.initialize(oNode);
    }

    @Override
    public boolean allowRenderProxy() {
        return this.m_bAllowRenderProxy;
    }

    @Override
    public Rect getContentExtent() {
        if (this.hasCaption()) {
            return this.m_oContentExtent;
        }
        return super.getContentExtent();
    }

    @Override
    public Rect getContentBorderExtent() {
        Rect oCE = this.getContentExtent();
        return new Rect(oCE.left().add(this.m_oContentBorderMargins.marginLeft()).subtract(this.m_oContMargins.marginLeft()), oCE.top().add(this.m_oContentBorderMargins.marginTop()).subtract(this.m_oContMargins.marginTop()), oCE.right().subtract(this.m_oContentBorderMargins.marginRight()).add(this.m_oContMargins.marginRight()), oCE.bottom().subtract(this.m_oContentBorderMargins.marginBottom()).add(this.m_oContMargins.marginBottom()));
    }

    @Override
    public Rect getCaptionExtent() {
        if (this.hasCaption()) {
            return this.m_oCaptionExtent;
        }
        return super.getCaptionExtent();
    }

    @Override
    public abstract boolean hasContent();

    @Override
    public abstract String getContentByType(String var1, List<TemplateResolver.RGB> var2, List<String> var3);

    @Override
    public abstract boolean enumerateContent(LayoutHandler var1, CoordPair var2, boolean var3, boolean var4, Rect var5);

    @Override
    public boolean enumerateCaption(LayoutHandler pHandler, CoordPair oLocalOrigin, boolean bTruncate, Rect oInvalidatedRect) {
        boolean bTextFits = true;
        if (this.hasCaption() && this.hasVisibleCaption()) {
            CoordPair oNewOrigin = oLocalOrigin;
            Rect oInvalid = oInvalidatedRect;
            if (oInvalid.width().equals(UnitSpan.ZERO) && oInvalid.height().equals(UnitSpan.ZERO)) {
                oInvalid = Rect.ZERO;
            }
            if (this.m_bSplitCaption) {
                oInvalid = this.m_oCaptionDisplayExtent;
                oNewOrigin = new CoordPair(oNewOrigin.x(), oNewOrigin.y().subtract(this.m_oCaptionDisplayExtent.top()));
            }
            boolean bSplitCaptionFits = true;
            if (this.m_oCaptionDisplayExtent.width().gt(this.getCaptionExtent().width())) {
                oInvalid = oInvalid.width(this.getCaptionExtent().width(), false);
                bSplitCaptionFits = false;
            }
            if (this.m_oCaptionDisplayExtent.height().gt(this.getCaptionExtent().height())) {
                oInvalid = oInvalid.height(this.getCaptionExtent().height(), false);
                bSplitCaptionFits = false;
            }
            bTextFits = this.m_oGfxLayoutEnv.renderText(pHandler, this.getCaptionDisplay(), oNewOrigin, false, bTruncate, this.m_oRotationAngle, oInvalid);
            if (this.m_bSplitCaption) {
                return bSplitCaptionFits;
            }
        }
        return bTextFits;
    }

    @Override
    public String getCaptionByType(String sType, List<TemplateResolver.RGB> colorTable, List<String> fontTable) {
        if (this.hasCaption() && null != this.getCaption()) {
            return this.getStringByType(this.getCaption(), null, sType, this.m_oStartCaptionPosn, this.m_oEndCaptionPosn, colorTable, fontTable);
        }
        return "";
    }

    @Override
    public abstract void resizeToNominal(UnitSpan var1, UnitSpan var2, Element var3);

    @Override
    public abstract void resizeToNominalWidth(UnitSpan var1, Element var2);

    @Override
    public abstract void resizeToContent(UnitSpan var1, UnitSpan var2, Element var3);

    @Override
    public abstract boolean splitImpl(UnitSpan var1, BoxModelLayout var2, Element var3);

    @Override
    public boolean isFontSubstituted() {
        boolean bIsFontSubstituted = false;
        TextDisplay pDisp = this.getCaptionDisplay();
        if (pDisp != null) {
            bIsFontSubstituted = pDisp.hasFontSubstitution();
        }
        return bIsFontSubstituted;
    }

    public boolean getKeepCaptionTextStreamFlag() {
        return this.m_bKeepCaptionTextStream;
    }

    public void setKeepCaptionTextStreamFlag(boolean bKeepTextStream) {
        this.m_bKeepCaptionTextStream = bKeepTextStream;
    }

    public abstract void update(Element var1);

    public TextDisplay getCaptionDisplay() {
        return null;
    }

    public TextRegion getCaption() {
        return null;
    }

    public TextRange getCaptionRangeAttrs() {
        return null;
    }

    protected void setVertAlign(int eVAlign, TextAttr attr) {
        if (eVAlign == 4063232) {
            attr.justifyV(1);
        } else if (eVAlign == 4063233) {
            attr.justifyV(2);
        } else if (eVAlign == 4063234) {
            attr.justifyV(3);
        } else {
            attr.justifyV(0);
        }
    }

    protected void setHorizAlign(int eHAlign, TextAttr attr) {
        if (eHAlign == 1441792) {
            attr.justifyH(5);
        } else if (eHAlign == 1441793) {
            attr.justifyH(6);
        } else if (eHAlign == 1441794) {
            attr.justifyH(7);
        } else if (eHAlign == 1441795) {
            attr.justifyH(8);
        } else if (eHAlign == 1441796) {
            attr.justifyH(9);
        } else if (eHAlign == 1441797) {
            attr.justifyH(10);
        } else {
            attr.justifyH(4);
        }
    }

    protected void setFont(Element oFontNode, Element oParaNode, boolean bContentFont, TextAttr attr, String sLang) {
        assert (oFontNode != null);
        GfxTextAttrs oGfxExtras = new GfxTextAttrs();
        attr.fontService(this.m_oGfxLayoutEnv.fontService());
        attr.colour(oGfxExtras.m_oColour);
        attr.underline(oGfxExtras.m_eUndercode);
        attr.overline(oGfxExtras.m_eOvercode);
        attr.strikeout(oGfxExtras.m_eStrikeOut);
        attr.baselineShift(new TextBaselineShift(oGfxExtras.m_oBaseLineShift));
        boolean bLineSpace = false;
        attr.spaceBefore(TextMeasurement.ZERO);
        attr.spaceAfter(TextMeasurement.ZERO);
        attr.special(TextMeasurement.ZERO);
        attr.marginL(TextMeasurement.ZERO);
        attr.marginR(TextMeasurement.ZERO);
        if (oParaNode != null) {
            if (oParaNode.isPropertySpecified(XFA.LINEHEIGHTTAG, true, 0)) {
                Measurement oLineHeight = new Measurement(oParaNode.getAttribute(XFA.LINEHEIGHTTAG));
                if (!bContentFont) {
                    this.m_oLineHeight = oLineHeight.getUnitSpan();
                }
                attr.spacing(new TextMeasurement(oLineHeight.getUnitSpan()));
                bLineSpace = true;
            }
            if (oParaNode.isPropertySpecified(XFA.SPACEABOVETAG, true, 0)) {
                Measurement oSpaceBefore = new Measurement(oParaNode.getAttribute(XFA.SPACEABOVETAG));
                attr.spaceBefore(new TextMeasurement(oSpaceBefore.getUnitSpan()));
            }
            if (oParaNode.isPropertySpecified(XFA.SPACEBELOWTAG, true, 0)) {
                Measurement oSpaceAfter = new Measurement(oParaNode.getAttribute(XFA.SPACEBELOWTAG));
                attr.spaceAfter(new TextMeasurement(oSpaceAfter.getUnitSpan()));
            }
            if (oParaNode.isPropertySpecified(XFA.TEXTINDENTTAG, true, 0)) {
                Measurement oSpecial = new Measurement(oParaNode.getAttribute(XFA.TEXTINDENTTAG));
                attr.special(new TextMeasurement(oSpecial.getUnitSpan()));
            }
            if (oParaNode.isPropertySpecified(XFA.MARGINLEFTTAG, true, 0)) {
                Measurement oLeftIndent = new Measurement(oParaNode.getAttribute(XFA.MARGINLEFTTAG));
                attr.marginL(new TextMeasurement(oLeftIndent.getUnitSpan()));
            }
            if (oParaNode.isPropertySpecified(XFA.MARGINRIGHTTAG, true, 0)) {
                Measurement oRightIndent = new Measurement(oParaNode.getAttribute(XFA.MARGINRIGHTTAG));
                attr.marginR(new TextMeasurement(oRightIndent.getUnitSpan()));
            }
        }
        if (!bLineSpace) {
            UnitSpan oSpan = new UnitSpan(0.0, 17);
            attr.spacing(new TextMeasurement(oSpan));
        }
    }

    protected void setTabs(Attribute oTabsDefault, Attribute oTabStops, TextAttr attr) {
        boolean bTabStops;
        String sTabsDefault = oTabsDefault.toString();
        boolean bTabsDefault = !StringUtils.isEmpty(sTabsDefault);
        String sTabStops = oTabStops.toString();
        boolean bl = bTabStops = !StringUtils.isEmpty(sTabStops);
        if (bTabsDefault || bTabStops) {
            if (bTabsDefault) {
                MarkupXHTMLIn.tabDefault(sTabsDefault, attr, MarkupXHTMLAttr.getDefault());
            }
            if (bTabStops) {
                MarkupXHTMLIn.tabSet(sTabStops, attr, MarkupXHTMLAttr.getDefault());
            }
        }
    }

    protected void initCaption(Element oNode) {
        String sCaption = null;
        this.hasCaption(false);
        this.m_bReserveCaptionSpace = false;
        if (oNode instanceof Draw || oNode instanceof Field || oNode instanceof ExclGroup) {
            if (oNode.isPropertySpecified(XFA.CAPTIONTAG, true, 0)) {
                boolean bRichCaption = false;
                Element oCaption = oNode.peekElement(XFA.CAPTIONTAG, true, 0);
                this.m_eCaptionPresence = oCaption.getEnum(XFA.PRESENCETAG);
                Element oCapValue = oCaption.peekElement(XFA.VALUETAG, true, 0);
                Content oCapContent = (Content)oCapValue.getOneOfChild(true, true);
                this.m_eCaptionPlacement = oCaption.getEnum(XFA.PLACEMENTTAG);
                if (1076494338 == this.m_eCaptionPresence || 1076494339 == this.m_eCaptionPresence) {
                    return;
                }
                this.hasCaption(true);
                boolean bExData = oCapContent instanceof ExDataValue;
                if (bExData) {
                    String sContentType = oCapContent.getAttribute(XFA.CONTENTTYPETAG).toString();
                    bRichCaption = "text/html".equals(sContentType);
                }
                if (oCapContent instanceof TextValue) {
                    sCaption = ((TextValue)oCapContent).getValue();
                } else if (oCapContent instanceof DecimalValue) {
                    double dTemp = ((DecimalValue)oCapContent).getValue();
                    sCaption = Double.toString(dTemp);
                } else if (oCapContent instanceof IntegerValue) {
                    int nTemp = ((IntegerValue)oCapContent).getValue();
                    sCaption = Integer.toString(nTemp);
                } else if (oCapContent instanceof FloatValue) {
                    double dTemp = ((FloatValue)oCapContent).getValue();
                    sCaption = Double.toString(dTemp);
                } else if (oCapContent instanceof DateValue) {
                    sCaption = ((DateValue)oCapContent).getValue();
                } else if (oCapContent instanceof DateTimeValue) {
                    sCaption = ((DateTimeValue)oCapContent).getValue();
                } else if (oCapContent instanceof TimeValue) {
                    sCaption = ((TimeValue)oCapContent).getValue();
                } else if (oCapContent instanceof ExDataValue) {
                    AppModel appModel = oCapContent.getAppModel();
                    boolean bLegacy = appModel.getLegacySetting(AppModel.XFA_LEGACY_V27_XHTMLVERSIONPROCESSING);
                    if (bExData && !bRichCaption) {
                        sCaption = ((ExDataValue)oCapContent).getValue(false, false, bLegacy);
                    }
                }
                if (!this.m_bKeepCaptionTextStream) {
                    boolean bLegacy;
                    AppModel appModel;
                    TextAttr oCaptionAttr = new TextAttr();
                    oCaptionAttr.transparent(true);
                    oCaptionAttr.fontService(this.m_oGfxLayoutEnv.fontService());
                    String sLang = oNode.getInstalledLocale();
                    if (!StringUtils.isEmpty(sLang)) {
                        oCaptionAttr.locale(sLang);
                    }
                    if (!this.hasInlineCaption()) {
                        Element oPara = oCaption.peekElement(XFA.PARATAG, true, 0);
                        int eCaptionVAlign = oPara.getEnum(XFA.VALIGNTAG);
                        int eCaptionHAlign = oPara.getEnum(XFA.HALIGNTAG);
                        if (1441796 == eCaptionHAlign && this.hasGrowableW()) {
                            eCaptionHAlign = 1441795;
                        }
                        this.setVertAlign(eCaptionVAlign, oCaptionAttr);
                        this.setHorizAlign(eCaptionHAlign, oCaptionAttr);
                        if (1441797 == eCaptionHAlign) {
                            UnitSpan oRO = new Measurement(oPara.getAttribute(XFA.RADIXOFFSETTAG)).getUnitSpan();
                            oCaptionAttr.radixOffset(new TextMeasurement(oRO));
                        }
                        this.setFont(oCaption.peekElement(XFA.FONTTAG, true, 0), oPara, false, oCaptionAttr, oCaption.getInstalledLocale());
                        this.m_bReserveCaptionSpace = oCaption.isPropertySpecified(XFA.RESERVETAG, true, 0);
                    } else {
                        this.m_bReserveCaptionSpace = false;
                    }
                    if (!bRichCaption || !StringUtils.isEmpty(sCaption = ((ExDataValue)oCapContent).getValue(true, false, bLegacy = (appModel = oCapContent.getAppModel()).getLegacySetting(AppModel.XFA_LEGACY_V27_XHTMLVERSIONPROCESSING)))) {
                        // empty if block
                    }
                    if (this.hasInlineCaption()) {
                        this.hasCaption(false);
                    }
                } else {
                    this.m_bReserveCaptionSpace = !this.hasInlineCaption() ? oCaption.isPropertySpecified(XFA.RESERVETAG, true, 0) : false;
                }
                if (this.m_bReserveCaptionSpace) {
                    assert (oCaption.isPropertySpecified(XFA.RESERVETAG, true, 0));
                    Measurement oMeas = new Measurement(oCaption.getAttribute(XFA.RESERVETAG));
                    this.m_oReserveCaptionSpace = oMeas.getUnitSpan();
                    if (UnitSpan.ZERO.gte(this.m_oReserveCaptionSpace)) {
                        this.m_bReserveCaptionSpace = false;
                    }
                }
                if (!this.m_bReserveCaptionSpace && this.hasCaption() && sCaption.length() != 0) {
                    throw new ExFull(ResId.UNSUPPORTED_OPERATION, "BoxModelCaptionable#initCaption");
                }
            } else {
                this.m_bKeepCaptionTextStream = false;
                this.m_bHasCaption = false;
                this.m_bReserveCaptionSpace = false;
                this.m_eCaptionPlacement = 4194307;
                this.m_eCaptionPresence = 1076494336;
                this.m_bSplitCaption = false;
                this.m_bKeepCaptionTextStream = false;
                this.m_oCaptionExtent = Rect.ZERO;
                this.m_oContentExtent = Rect.ZERO;
                this.m_oReserveCaptionSpace = UnitSpan.ZERO;
            }
        }
        if (this.hasCaption()) {
            TextPosnBase oPosn = new TextPosnBase(this.getCaption());
            this.m_oStartCaptionPosn = new TextPosn(oPosn.stream());
            this.m_oEndCaptionPosn = new TextPosn(oPosn.stream());
            this.m_oStartCaptionPosn.first();
            this.m_oEndCaptionPosn.last();
        }
    }

    protected String getStringByType(TextRegion pTB, TextAttr poAmbientAttr, String sType, TextPosn oStart, TextPosn oEnd, List<TemplateResolver.RGB> colorTable, List<String> fontTable) {
        assert (null != pTB);
        assert (!StringUtils.isEmpty(sType));
        String sText = null;
        if (null != pTB) {
            if (sType.equals("rtf")) {
                ArrayList<GFXColour> oColours = new ArrayList<GFXColour>();
                if (null != colorTable) {
                    for (int i = 0; i < colorTable.size(); ++i) {
                        TemplateResolver.RGB rgb = colorTable.get(i);
                        oColours.add(new GFXColour(rgb.mnRed, rgb.mnGreen, rgb.mnBlue, 255));
                    }
                }
                TextRange oRange = new TextRange(pTB);
                oRange.start(oStart);
                oRange.end(oEnd);
                MarkupRtfOut oMarkupOut = new MarkupRtfOut(null, oColours, fontTable);
                oRange.markup(oMarkupOut, null, true, false);
                sText = oMarkupOut.translation();
            } else if (sType.equals("html")) {
                TextRange oRange = new TextRange(pTB);
                oRange.start(oStart);
                oRange.end(oEnd);
                MarkupXHTMLOut oMarkupOut = new MarkupXHTMLOut(null, 3, poAmbientAttr, true);
                oRange.markup(oMarkupOut, null, true, false);
                sText = oMarkupOut.translation();
            } else if (sType.equals("plain")) {
                TextRange oRange = new TextRange(pTB);
                oRange.start(oStart);
                oRange.end(oEnd);
                oRange.text(true);
            }
        }
        return sText;
    }

    protected boolean hasInlineCaption() {
        return 4194308 == this.m_eCaptionPlacement;
    }

    protected boolean hasVisibleCaption() {
        return this.hasCaption() && 1076494336 == this.m_eCaptionPresence;
    }

    @Override
    public boolean hasOverflowingCaptionText() {
        return false;
    }
}