PDFAnnotation.java 26.7 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
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.internal.pdftoolkit.core.cos.CosArray
 *  com.adobe.internal.pdftoolkit.core.cos.CosDictionary
 *  com.adobe.internal.pdftoolkit.core.cos.CosObject
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFException
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException
 *  com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
 *  com.adobe.internal.pdftoolkit.core.types.ASDate
 *  com.adobe.internal.pdftoolkit.core.types.ASMatrix
 *  com.adobe.internal.pdftoolkit.core.types.ASName
 *  com.adobe.internal.pdftoolkit.core.types.ASRectangle
 */
package com.adobe.internal.pdftoolkit.pdf.interactive.annotation;

import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASDate;
import com.adobe.internal.pdftoolkit.core.types.ASMatrix;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASRectangle;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionary;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.document.PDFFileSpecificationList;
import com.adobe.internal.pdftoolkit.pdf.document.PDFText;
import com.adobe.internal.pdftoolkit.pdf.graphics.PDFRectangle;
import com.adobe.internal.pdftoolkit.pdf.graphics.xobject.PDFXObjectForm;
import com.adobe.internal.pdftoolkit.pdf.impl.AnnotationID;
import com.adobe.internal.pdftoolkit.pdf.interactive.action.PDFAction;
import com.adobe.internal.pdftoolkit.pdf.interactive.action.PDFActionFactory;
import com.adobe.internal.pdftoolkit.pdf.interactive.action.PDFAdditionalActions;
import com.adobe.internal.pdftoolkit.pdf.interactive.action.PDFAdditionalActionsAnnotation;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationIterator;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationList;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationMarkup;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationPopup;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationUtils;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAnnotationWidget;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFAppearance;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFBorder;
import com.adobe.internal.pdftoolkit.pdf.interactive.annotation.PDFBorderStyle;
import com.adobe.internal.pdftoolkit.pdf.page.PDFPage;
import com.adobe.internal.pdftoolkit.pdf.page.PDFPageTree;
import com.adobe.internal.pdftoolkit.pdf.utils.PDFUtil;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class PDFAnnotation
extends PDFCosDictionary {
    public static final int kInvisible = 1;
    public static final int kHidden = 2;
    public static final int kPrint = 4;
    public static final int kNoZoom = 8;
    public static final int kNoRotate = 16;
    public static final int kNoView = 32;
    public static final int kReadOnly = 64;
    public static final int kLocked = 128;
    public static final int kToggleNoView = 256;

    protected PDFAnnotation(CosObject cosObject) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        super(cosObject);
    }

    protected PDFAnnotation(PDFDocument pdfDoc) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        super((CosObject)PDFCosObject.newCosDictionary(pdfDoc));
        this.setDictionaryNameValue(ASName.k_Type, ASName.k_Annot);
    }

    public ASName getSubtype() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        ASName subType = this.getDictionaryNameValue(ASName.k_Subtype);
        if (subType == null) {
            throw new PDFInvalidDocumentException("Missing required field Subtype");
        }
        return subType;
    }

    public void setSubtype(ASName subType) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryNameValue(ASName.k_Subtype, subType);
    }

    public boolean hasRect() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.dictionaryContains(ASName.k_Rect);
    }

    public PDFRectangle getRect() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return PDFRectangle.getInstance(this.getDictionaryCosObjectValue(ASName.k_Rect));
    }

    public void setRect(double llx, double lly, double urx, double ury) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        ArrayList<Double> rectArray = new ArrayList<Double>(4);
        rectArray.add(0, llx);
        rectArray.add(1, lly);
        rectArray.add(2, urx);
        rectArray.add(3, ury);
        this.setDictionaryArrayValue(ASName.k_Rect, rectArray);
    }

    public void setRect(PDFRectangle rect) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryArrayValue(ASName.k_Rect, rect.getCosArray());
    }

    public boolean hasContents() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.dictionaryContains(ASName.k_Contents);
    }

    public String getContents() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.getDictionaryTextStringValue(ASName.k_Contents);
    }

    public void setContents(String text) throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
        this.setDictionaryStringValue(ASName.k_Contents, text);
    }

    public boolean hasPage() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.dictionaryContains(ASName.k_P);
    }

    public PDFPage getPage() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        boolean isPEntryTypeCorrect = true;
        if (this.dictionaryContains(ASName.k_P)) {
            CosObject obj = this.getDictionaryCosObjectValue(ASName.k_P);
            if (obj instanceof CosDictionary) {
                return PDFPage.getInstance(this.getDictionaryCosObjectValue(ASName.k_P));
            }
            isPEntryTypeCorrect = false;
        }
        PDFCosObject annotPage = null;
        Iterator<PDFPage> pagesIter = this.getPDFDocument().requirePages().iterator();
        block0 : while (pagesIter.hasNext()) {
            PDFPage curPage = pagesIter.next();
            PDFAnnotationList pageAnnots = curPage.getAnnotationList();
            if (pageAnnots == null) continue;
            PDFAnnotationIterator annotsIter = pageAnnots.iterator();
            while (annotsIter.hasNext()) {
                PDFAnnotation curAnnot = annotsIter.next();
                if (this != curAnnot) continue;
                annotPage = curPage;
                break block0;
            }
        }
        if (!isPEntryTypeCorrect) {
            this.getCosDictionary().setRepairedValue(ASName.k_P, annotPage.getCosObject());
        }
        return annotPage;
    }

    public void setPage(PDFPage parent) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryValue(ASName.k_P, parent);
    }

    public void setName(String name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        PDFText nameText = PDFText.createString(this.getPDFDocument(), name);
        this.setDictionaryTextValue(ASName.k_NM, nameText);
    }

    public String getName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.getDictionaryTextStringValue(ASName.k_NM);
    }

    public boolean hasName() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.dictionaryContains(ASName.k_NM);
    }

    public boolean hasModificationDate() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.dictionaryContains(ASName.k_M);
    }

    public ASDate getModificationDate() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.getDictionaryDateValue(ASName.k_M);
    }

    public String getModificationDateAsString() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.getDictionaryDateValue(ASName.k_M).toString();
    }

    public void setModificationDate(String date) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        PDFText dateText = PDFText.createString(this.getPDFDocument(), date);
        this.setDictionaryTextValue(ASName.k_M, dateText);
    }

    public boolean hasFlags() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.dictionaryContains(ASName.k_F);
    }

    public int getFlags() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        if (this.dictionaryContains(ASName.k_F)) {
            return this.getDictionaryIntValue(ASName.k_F);
        }
        return 0;
    }

    public void setFlags(int flags) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryIntValue(ASName.k_F, flags);
    }

    public boolean hasBorderStyle() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.dictionaryContains(ASName.k_BS);
    }

    public PDFBorderStyle getBorderStyle() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return PDFBorderStyle.getInstance(this.getDictionaryCosObjectValue(ASName.k_BS));
    }

    public PDFBorderStyle procureBorderStyle() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        PDFBorderStyle borderStyle = this.getBorderStyle();
        if (borderStyle == null) {
            borderStyle = PDFBorderStyle.newInstance(this.getPDFDocument());
        }
        return borderStyle;
    }

    public PDFBorder procureBorder() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        PDFBorder border = this.getBorder();
        if (border == null) {
            border = PDFBorder.newInstance(this.getPDFDocument());
        }
        return border;
    }

    public void setBorderStyle(PDFBorderStyle borderStyle) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryValue(ASName.k_BS, borderStyle);
    }

    public PDFAppearance getAppearance() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return PDFAppearance.getInstance(this.getDictionaryCosObjectValue(ASName.k_AP));
    }

    public ASName getAppearanceState() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.getDictionaryNameValue(ASName.k_AS);
    }

    public void setAppearanceState(boolean state) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        if (state) {
            this.setDictionaryNameValue(ASName.k_AS, ASName.create((String)"Yes"));
        } else {
            this.setDictionaryNameValue(ASName.k_AS, ASName.create((String)"Off"));
        }
    }

    public void setAppearanceState(boolean state, String value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        if (state) {
            this.setDictionaryNameValue(ASName.k_AS, ASName.create((String)value));
        } else {
            this.setDictionaryNameValue(ASName.k_AS, ASName.create((String)"Off"));
        }
    }

    public PDFXObjectForm getNormalStateAppearance() throws PDFIOException, PDFInvalidDocumentException, PDFSecurityException {
        PDFAppearance appearance = this.getAppearance();
        if (appearance == null) {
            return null;
        }
        return appearance.getNormalAppearance(this.getAppearanceState());
    }

    public void setAppearance(PDFAppearance appearance) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryValue(ASName.k_AP, appearance);
    }

    public void removeAppearance() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.getCosDictionary().remove(ASName.k_AP);
    }

    public boolean hasBorder() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.dictionaryContains(ASName.k_Border);
    }

    public PDFBorder getBorder() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return PDFBorder.getInstance((CosObject)this.getDictionaryArrayValue(ASName.k_Border));
    }

    public void setBorder(PDFBorder border) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryArrayValue(ASName.k_Border, border.getCosArray());
    }

    public void setBorder(ArrayList border) throws PDFInvalidParameterException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryArrayValue(ASName.k_Border, border);
    }

    public double[] getColor() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        CosArray cosColor = this.getDictionaryArrayValue(ASName.k_C);
        if (cosColor == null) {
            return null;
        }
        return cosColor.getArrayDouble();
    }

    public void setColor(double[] color) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        CosArray cosColor = PDFCosObject.newCosArray(this.getPDFDocument());
        for (int i = 0; i < color.length; ++i) {
            cosColor.addDouble(color[i]);
        }
        this.setDictionaryArrayValue(ASName.k_C, cosColor);
    }

    public boolean hasAction() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.dictionaryContains(ASName.k_A);
    }

    public PDFAction getAction() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return PDFActionFactory.getInstance((CosObject)this.getDictionaryDictionaryValue(ASName.k_A));
    }

    public void setAction(PDFAction action) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryValue(ASName.k_A, action);
    }

    public PDFAdditionalActions getAdditionalActions() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return PDFAdditionalActionsAnnotation.getInstance(this.getDictionaryCosObjectValue(ASName.k_AA));
    }

    public void setAdditionalActions(PDFAdditionalActions additionalActions) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryValue(ASName.k_AA, additionalActions);
    }

    public String getRichTextForContent() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        if (!(this instanceof PDFAnnotationMarkup)) {
            return null;
        }
        return PDFUtil.makeRichTextFromString(this.getDictionaryTextStringValue(ASName.k_Contents));
    }

    public boolean hasOptionalContent() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.dictionaryContains(ASName.k_OC);
    }

    private void rotateXObject(PDFXObjectForm xObject, double rotationAngle) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        double[] xobjMatrix = xObject.getMatrix();
        ASMatrix xobjASMatrix = xobjMatrix == null ? ASMatrix.createIdentityMatrix() : new ASMatrix(xobjMatrix);
        xobjASMatrix = xobjASMatrix.rotate(rotationAngle);
        xObject.setMatrix(xobjASMatrix.getValues());
    }

    void transformAppearances(ASMatrix matrix, double rotationAngle) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        PDFAppearance annotAppearance;
        if (rotationAngle != 0.0 && (annotAppearance = this.getAppearance()) != null) {
            List<ASName> downStates;
            List<ASName> rolloverStates;
            List<ASName> normalStates = annotAppearance.getNormalAppearanceStates();
            if (normalStates != null) {
                if (normalStates.isEmpty()) {
                    this.rotateXObject(annotAppearance.getNormalAppearance(), rotationAngle);
                } else {
                    for (ASName nstate : normalStates) {
                        this.rotateXObject(annotAppearance.getNormalAppearance(nstate), rotationAngle);
                    }
                }
            }
            if ((rolloverStates = annotAppearance.getRolloverAppearanceStates()) != null) {
                if (rolloverStates.isEmpty()) {
                    this.rotateXObject(annotAppearance.getRolloverAppearance(), rotationAngle);
                } else {
                    for (ASName rstate : rolloverStates) {
                        this.rotateXObject(annotAppearance.getRolloverAppearance(rstate), rotationAngle);
                    }
                }
            }
            if ((downStates = annotAppearance.getDownAppearanceStates()) != null) {
                if (downStates.isEmpty()) {
                    this.rotateXObject(annotAppearance.getDownAppearance(), rotationAngle);
                } else {
                    for (ASName dstate : downStates) {
                        this.rotateXObject(annotAppearance.getDownAppearance(dstate), rotationAngle);
                    }
                }
            }
        }
    }

    void transformRect(ASMatrix matrix) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        PDFDocument doc = this.getPDFDocument();
        PDFRectangle annotRectangle = this.getRect();
        PDFRectangle sourceRect = annotRectangle.normalized(doc);
        PDFRectangle destRect = PDFRectangle.newInstance(doc, sourceRect.getRectangle().transform(matrix));
        PDFRectangle normalDestRect = destRect.normalized(doc);
        PDFRectangle destinationRect = PDFRectangle.newInstance(doc, normalDestRect.getRectangle());
        this.setRect(destinationRect);
    }

    public abstract void transform(ASMatrix var1, double var2) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException;

    public ASMatrix getTransformationMatrix(PDFDocument doc, PDFXObjectForm annotAppearance) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        ASRectangle formBBox;
        double[] formMatrixValues;
        PDFRectangle annotPDFRect = this.getRect();
        ASRectangle annotRect = annotPDFRect != null ? annotPDFRect.getRectangle() : new ASRectangle(0.0, 0.0, 0.0, 0.0);
        PDFRectangle formBBoxPDFRect = annotAppearance.getBBox();
        ASRectangle aSRectangle = formBBox = formBBoxPDFRect != null ? formBBoxPDFRect.getRectangle() : new ASRectangle(0.0, 0.0, 0.0, 0.0);
        if (this.getRotation() != 0) {
            formBBoxPDFRect = annotPDFRect;
            formBBox = annotRect;
        }
        ASMatrix formMatrix = (formMatrixValues = annotAppearance.getMatrix()) == null ? ASMatrix.createIdentityMatrix() : new ASMatrix(formMatrixValues);
        formBBox = formBBox.transform(formMatrix);
        double scaleX = 0.0;
        double scaleY = 0.0;
        double annotWidth = annotRect.width();
        double annotHeight = annotRect.height();
        double formWidth = formBBox.width();
        double formHeight = formBBox.height();
        if (formWidth != 0.0) {
            scaleX = annotWidth / formWidth;
        }
        if (formHeight != 0.0) {
            scaleY = annotHeight / formHeight;
        }
        double formOffsetX = - Math.min(formBBox.left(), formBBox.right()) + formWidth / 2.0;
        double formOffsetY = - Math.min(formBBox.top(), formBBox.bottom()) + formHeight / 2.0;
        double annotOffsetX = Math.min(annotRect.left(), annotRect.right()) + annotWidth / 2.0;
        double annotOffsetY = Math.min(annotRect.top(), annotRect.bottom()) + annotHeight / 2.0;
        ASMatrix tm = ASMatrix.createIdentityMatrix();
        tm = tm.translate(formOffsetX, formOffsetY);
        tm = tm.scale(scaleX, scaleY);
        tm = tm.translate(annotOffsetX, annotOffsetY);
        return tm;
    }

    public boolean isHidden() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return (this.getFlags() & 2) != 0;
    }

    public boolean isInvisible() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return (this.getFlags() & 1) != 0;
    }

    public boolean isPrintable() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return (this.getFlags() & 4) != 0;
    }

    public boolean isViewable() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return (this.getFlags() & 32) != 0;
    }

    public boolean isReadOnly() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return (this.getFlags() & 64) != 0;
    }

    private void setBit(boolean value, int kBit) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        if (value) {
            int flg = this.getFlags();
            this.setFlags(flg |= kBit);
        } else {
            int flags = this.getFlags();
            int mask = -1 ^ kBit;
            this.setFlags(flags &= mask);
        }
    }

    public void setHidden(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setBit(value, 2);
    }

    public void setInvisible(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setBit(value, 1);
    }

    public void setPrintable(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setBit(value, 4);
    }

    public void setViewable(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setBit(!value, 32);
    }

    public void setReadOnly(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setBit(value, 64);
    }

    public void setNoZoom(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setBit(value, 8);
    }

    public void setNoRotate(boolean value) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setBit(value, 16);
    }

    public String getID() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        AnnotationID id = new AnnotationID(this);
        return id.asString();
    }

    public String toString() {
        try {
            return this.getID();
        }
        catch (PDFException e) {
            throw new RuntimeException("Could not get or create annotation's ID", (Throwable)e);
        }
    }

    public int getSeqNum() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        PDFPage page = this.getPage();
        PDFAnnotationList annotList = page.getAnnotationList();
        ArrayList<PDFAnnotation> nonPopusps = new ArrayList<PDFAnnotation>();
        for (int i = 0; i < annotList.size(); ++i) {
            if (annotList.get(i) instanceof PDFAnnotationPopup || annotList.get(i) instanceof PDFAnnotationWidget) continue;
            nonPopusps.add(annotList.get(i));
        }
        return nonPopusps.indexOf(this) + 1;
    }

    public PDFFileSpecificationList getAssociatedFiles() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return PDFFileSpecificationList.getInstance(this.getDictionaryCosObjectValue(ASName.k_AF));
    }

    public void setAssociatedFiles(PDFFileSpecificationList fileSpecificationList) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryValue(ASName.k_AF, fileSpecificationList);
    }

    public Integer getOpacityValue() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        Integer ca = this.getDictionaryIntValue(ASName.k_ca);
        if (ca != null) {
            return ca;
        }
        return 1;
    }

    public void setOpacityValue(Integer ca) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryIntValue(ASName.k_ca, ca.intValue());
    }

    public void setBlendMode(ASName name) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryNameValue(ASName.k_BM, name);
    }

    public void setBlendMode(ASName[] names) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        this.setDictionaryArrayValue(ASName.k_BM, 0, names);
    }

    public ASName[] getBlendMode() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        CosArray array = this.getDictionaryArrayValue(ASName.k_BM);
        ASName[] names = new ASName[1];
        if (array != null) {
            return array.getArrayName();
        }
        names[0] = this.getDictionaryNameValue(ASName.k_BM);
        if (names[0] != null) {
            return names;
        }
        names[0] = ASName.k_Normal;
        return names;
    }

    public boolean hasRotation() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        return this.dictionaryContains(ASName.k_Rotate);
    }

    public int getRotation() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
        Number value = this.getDictionaryNumericValue(ASName.k_Rotate);
        return value != null ? value.intValue() : 0;
    }

    public void setRotation(int rotation) throws PDFInvalidDocumentException, PDFIOException, PDFInvalidParameterException, PDFSecurityException {
        this.setDictionaryIntValue(ASName.k_Rotate, rotation);
    }

    public void applyRotation(PDFRectangle cropBox, int rotationAngle) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException, PDFInvalidParameterException {
        if (rotationAngle == 0) {
            rotationAngle = this.getRotation();
        }
        double height = cropBox.height();
        double width = cropBox.width();
        double[] transformedRect = null;
        transformedRect = PDFAnnotationUtils.transfromRectangle(this.getRect().getValues(), width, height, rotationAngle);
        this.setRect(PDFRectangle.newInstance(this.getPDFDocument(), transformedRect[0], transformedRect[1], transformedRect[2], transformedRect[3]));
    }
}