AdobePdfContainer.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package epson.print.pdf;
  2. import android.content.Context;
  3. import android.graphics.Bitmap;
  4. import android.graphics.Matrix;
  5. import com.adobe.mps.MPS;
  6. import java.io.File;
  7. import java.nio.ByteBuffer;
  8. import epson.common.ExternalFileUtils;
  9. import epson.image.epsonImage;
  10. import epson.print.Util.EPLog;
  11. public class AdobePdfContainer {
  12. private static final String TAG = "AdobePdfContainer";
  13. private MPS adpbeMPSInterface = new MPS();
  14. /* renamed from: bm */
  15. private Bitmap f385bm = null;
  16. int colorComponent = 4;
  17. private final int colorspace_ARGB = 1;
  18. private Context mContext = null;
  19. private int pageCount = 0;
  20. ByteBuffer rawBuffer;
  21. public class PdfException extends Exception {
  22. public PdfException() {
  23. }
  24. }
  25. public class PasswordException extends PdfException {
  26. public PasswordException() {
  27. super();
  28. }
  29. }
  30. public class NoPdfException extends PdfException {
  31. public NoPdfException() {
  32. super();
  33. }
  34. }
  35. public class ParameterException extends PdfException {
  36. public ParameterException() {
  37. super();
  38. }
  39. }
  40. public AdobePdfContainer(Context context) {
  41. mContext = context;
  42. EPLog.v(TAG, "adpbeMPSInterface.MPSInit()");
  43. adpbeMPSInterface.MPSInit("com/adobe/mps/ARAESCryptor", "com/adobe/mps/ARSHADigest");
  44. }
  45. protected void finalize() {
  46. EPLog.v(TAG, "finalize()");
  47. }
  48. public void LoadDocument(String str, String str2) throws PasswordException, NoPdfException {
  49. EPLog.v(TAG, "call LoadDocument()");
  50. if (str2 == null || str2.length() == 0) {
  51. pageCount = adpbeMPSInterface.PDFDocInit(str);
  52. } else {
  53. pageCount = adpbeMPSInterface.PDFDocInit(str, str2);
  54. }
  55. switch (pageCount) {
  56. case -2:
  57. throw new PasswordException();
  58. case -1:
  59. throw new PasswordException();
  60. case 0:
  61. throw new NoPdfException();
  62. default:
  63. return;
  64. }
  65. }
  66. public int CountPages() {
  67. return pageCount;
  68. }
  69. public int hasPrintPermission() {
  70. return adpbeMPSInterface.PDFHasPrintPermission((String) null);
  71. }
  72. public int GetPageSizeX(int i) throws ParameterException {
  73. if (CountPages() >= i) {
  74. return adpbeMPSInterface.PDFGetPageAttributes(i)[0];
  75. }
  76. throw new ParameterException();
  77. }
  78. public int GetPageSizeY(int i) throws ParameterException {
  79. if (CountPages() >= i) {
  80. return adpbeMPSInterface.PDFGetPageAttributes(i)[1];
  81. }
  82. throw new ParameterException();
  83. }
  84. public Bitmap getPageBitmap(int i, int i2, int i3, int i4) throws Exception {
  85. EPLog.v(TAG, "getPageBitmap() Start");
  86. if (CountPages() >= i) {
  87. Bitmap bitmap = f385bm;
  88. if (bitmap != null) {
  89. bitmap.recycle();
  90. f385bm = null;
  91. }
  92. System.gc();
  93. f385bm = Bitmap.createBitmap(i2, i3, Bitmap.Config.ARGB_8888);
  94. rawBuffer = ByteBuffer.allocateDirect(i2 * i3 * colorComponent);
  95. int[] iArr = {0, 0, 0, 0};
  96. ByteBuffer byteBuffer = rawBuffer;
  97. if (byteBuffer != null) {
  98. if (adpbeMPSInterface.PDFPageRender(i, i2, i3, 1, byteBuffer, 0, iArr) == 0) {
  99. f385bm.copyPixelsFromBuffer(rawBuffer);
  100. if (i4 != 0) {
  101. Matrix matrix = new Matrix();
  102. matrix.postRotate((float) i4);
  103. f385bm = Bitmap.createBitmap(f385bm, 0, 0, i2, i3, matrix, false);
  104. }
  105. }
  106. rawBuffer.clear();
  107. rawBuffer = null;
  108. } else {
  109. EPLog.e(TAG, "Failed ByteBuffer.allocateDirect()");
  110. }
  111. EPLog.v(TAG, "getPageBitmap() End");
  112. return f385bm;
  113. }
  114. throw new ParameterException();
  115. }
  116. public String getPageBitmapFile(int i, int i2, int i3, boolean z) throws Exception {
  117. String str;
  118. EPLog.v(TAG, "getPageBitmapFile() Start");
  119. if (CountPages() >= i) {
  120. String path = new File(ExternalFileUtils.getInstance(mContext).getPrintDir(), "tmpPDF.jpg").getPath();
  121. if (adpbeMPSInterface.PDFPagetoImage(i, path, i2, i3, 0) != 0) {
  122. return null;
  123. }
  124. if (z) {
  125. str = new File(ExternalFileUtils.getInstance(mContext).getPrintDir(), "tmpPDF90.jpg").getPath();
  126. new epsonImage().epsmpRotateImage2(path, str);
  127. } else {
  128. str = path;
  129. }
  130. EPLog.v(TAG, "getPageBitmapFile() End");
  131. return str;
  132. }
  133. throw new ParameterException();
  134. }
  135. public boolean decodeToJpegFile(String str, int i, int i2, int i3) throws ParameterException {
  136. if (CountPages() >= i) {
  137. return adpbeMPSInterface.PDFPagetoImage(i, str, i2, i3, 0) == 0;
  138. }
  139. throw new ParameterException();
  140. }
  141. }