|
@@ -1,184 +0,0 @@
|
|
|
-/**
|
|
|
- * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
|
|
|
- *
|
|
|
- * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
|
|
|
- * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
|
|
|
- * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
|
|
|
- * This notice may not be removed from this file.
|
|
|
- */
|
|
|
-
|
|
|
-package com.compdfkit.tools.utils.glide.pdf;
|
|
|
-
|
|
|
-import android.graphics.Color;
|
|
|
-
|
|
|
-import androidx.annotation.NonNull;
|
|
|
-import androidx.annotation.Nullable;
|
|
|
-
|
|
|
-import com.bumptech.glide.load.Key;
|
|
|
-import com.bumptech.glide.load.model.Headers;
|
|
|
-import com.compdfkit.core.document.CPDFDocument;
|
|
|
-
|
|
|
-import java.security.MessageDigest;
|
|
|
-import java.util.Locale;
|
|
|
-
|
|
|
-
|
|
|
-public class CGlidePDFUrl implements Key {
|
|
|
- private static final String TAG = "CGlidePDFUrl";
|
|
|
- public static final String TPDF = "TPDF:";
|
|
|
- public static final String TAG_PAGEINDEX = "pageIndex";
|
|
|
- public static final String TAG_WIDTH = "width";
|
|
|
- public static final String TAG_HEIGHT = "height";
|
|
|
- public static final String TAG_PATCHX = "patchx";
|
|
|
- public static final String TAG_PATCHY = "patchy";
|
|
|
- public static final String TAG_PATCHW = "patchw";
|
|
|
- public static final String TAG_PATCHH = "patchh";
|
|
|
- public static final String TAG_BGCOLOR = "bgcolor";
|
|
|
- public static final String TAG_DRAWANNOT = "drawannot";
|
|
|
- public static final String TAG_IS_UPDATE = "isupdate";
|
|
|
-
|
|
|
- private CPDFDocument tpdfDocument;
|
|
|
- private int pageIndex;
|
|
|
- private int width;
|
|
|
- private int height;
|
|
|
- private int patchX;
|
|
|
- private int patchY;
|
|
|
- private int patchW;
|
|
|
- private int patchH;
|
|
|
- private int bgColor;
|
|
|
- private boolean isDrawAnnot;
|
|
|
- private boolean isUpdate;
|
|
|
-
|
|
|
- private final Headers headers = Headers.DEFAULT;
|
|
|
- private int hashCode;
|
|
|
- @Nullable
|
|
|
- private volatile byte[] cacheKeyBytes;
|
|
|
-
|
|
|
- public CGlidePDFUrl(CPDFDocument tpdfDocument, int pageIndex, int width, int height, int patchX, int patchY, int patchW, int patchH, int bgColor, boolean isDrawAnnot, boolean isUpdate) {
|
|
|
- this.tpdfDocument = tpdfDocument;
|
|
|
- this.pageIndex = pageIndex;
|
|
|
- this.width = width;
|
|
|
- this.height = height;
|
|
|
- this.patchX = patchX;
|
|
|
- this.patchY = patchY;
|
|
|
- this.patchW = patchW;
|
|
|
- this.patchH = patchH;
|
|
|
- this.bgColor = bgColor;
|
|
|
- this.isDrawAnnot = isDrawAnnot;
|
|
|
- this.isUpdate = isUpdate;
|
|
|
- }
|
|
|
-
|
|
|
- public CGlidePDFUrl(CPDFDocument tpdfDocument, int pageIndex, int width, int height){
|
|
|
- this.tpdfDocument = tpdfDocument;
|
|
|
- this.pageIndex = pageIndex;
|
|
|
- this.width = width;
|
|
|
- this.height = height;
|
|
|
- this.patchX = 0;
|
|
|
- this.patchY = 0;
|
|
|
- this.patchW = width;
|
|
|
- this.patchH = height;
|
|
|
- this.bgColor = Color.WHITE;
|
|
|
- this.isDrawAnnot = true;
|
|
|
- this.isUpdate = false;
|
|
|
- }
|
|
|
-
|
|
|
- public CPDFDocument getTpdfDocument() {
|
|
|
- return tpdfDocument;
|
|
|
- }
|
|
|
-
|
|
|
- public int getPageIndex() {
|
|
|
- return pageIndex;
|
|
|
- }
|
|
|
-
|
|
|
- public int getWidth() {
|
|
|
- return width;
|
|
|
- }
|
|
|
-
|
|
|
- public int getHeight() {
|
|
|
- return height;
|
|
|
- }
|
|
|
-
|
|
|
- public int getPatchX() {
|
|
|
- return patchX;
|
|
|
- }
|
|
|
-
|
|
|
- public int getPatchY() {
|
|
|
- return patchY;
|
|
|
- }
|
|
|
-
|
|
|
- public int getPatchW() {
|
|
|
- return patchW;
|
|
|
- }
|
|
|
-
|
|
|
- public int getPatchH() {
|
|
|
- return patchH;
|
|
|
- }
|
|
|
-
|
|
|
- public int getBgColor() {
|
|
|
- return bgColor;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isDrawAnnot() {
|
|
|
- return isDrawAnnot;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isUpdate() {
|
|
|
- return isUpdate;
|
|
|
- }
|
|
|
-
|
|
|
- public String getCacheKey() {
|
|
|
- String urlFormat = "%s{" +
|
|
|
- "\"%s\":\"%d\"," +
|
|
|
- "\"%s\":\"%d\"," +
|
|
|
- "\"%s\":\"%d\"," +
|
|
|
- "\"%s\":\"%d\"," +
|
|
|
- "\"%s\":\"%d\"," +
|
|
|
- "\"%s\":\"%d\"," +
|
|
|
- "\"%s\":\"%d\"," +
|
|
|
- "\"%s\":\"%d\"," +
|
|
|
- "\"%s\":\"%d\"," +
|
|
|
- "\"%s\":\"%d\"}";
|
|
|
- String cacheKey = String.format(Locale.US, urlFormat,
|
|
|
- TPDF,
|
|
|
- TAG_PAGEINDEX, pageIndex,
|
|
|
- TAG_WIDTH, width,
|
|
|
- TAG_HEIGHT, height,
|
|
|
- TAG_PATCHX, patchX,
|
|
|
- TAG_PATCHY, patchY,
|
|
|
- TAG_PATCHW, patchW,
|
|
|
- TAG_PATCHH, patchH,
|
|
|
- TAG_BGCOLOR, bgColor,
|
|
|
- TAG_DRAWANNOT, (isDrawAnnot ? 1 : 0),
|
|
|
- TAG_IS_UPDATE, (isUpdate ? 1 : 0));
|
|
|
- return cacheKey;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
|
|
|
- messageDigest.update(getCacheKeyBytes());
|
|
|
- }
|
|
|
-
|
|
|
- private byte[] getCacheKeyBytes() {
|
|
|
- if (cacheKeyBytes == null) {
|
|
|
- cacheKeyBytes = getCacheKey().getBytes(CHARSET);
|
|
|
- }
|
|
|
- return cacheKeyBytes;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean equals(Object o) {
|
|
|
- if (o instanceof CGlidePDFUrl) {
|
|
|
- CGlidePDFUrl other = (CGlidePDFUrl) o;
|
|
|
- return getCacheKey().equals(other.getCacheKey());
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int hashCode() {
|
|
|
- if (hashCode == 0) {
|
|
|
- hashCode = getCacheKey().hashCode();
|
|
|
- hashCode = 31 * hashCode + headers.hashCode();
|
|
|
- }
|
|
|
- return hashCode;
|
|
|
- }
|
|
|
-}
|