Ver Fonte

PDFTool(Android) - 1.Bug修复

liuxiaolong há 1 ano atrás
pai
commit
1904767209

+ 27 - 19
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/contextmenu/impl/CEditTextContextMenuView.java

@@ -105,25 +105,33 @@ public class CEditTextContextMenuView implements ContextMenuEditTextProvider {
                 }
             });
         }
-        if (!TextUtils.isEmpty(text) && isEditAreaValid == false) {
-            menuView.addItem(R.string.tools_context_menu_paste, 0, v -> {
-                pageView.pasteEditTextArea(point, pageView.getCopyTextAreaWidth(), pageView.getCopyTextAreaHeight());
-                helper.dismissContextMenu();
-            });
-        } else if (!TextUtils.isEmpty(text) && isEditAreaValid == true) {
-            menuView.addItem(R.string.tools_context_menu_select_paste, 0, v -> {
-                pageView.pasteEditTextArea(point, pageView.getCopyTextAreaWidth(), pageView.getCopyTextAreaHeight(), false);
-                helper.dismissContextMenu();
-            });
-            menuView.addItem(R.string.tools_context_menu_select_paste_with_style, 1, v -> {
-                pageView.pasteEditTextArea(point, pageView.getCopyTextAreaWidth(), pageView.getCopyTextAreaHeight(), true);
-                helper.dismissContextMenu();
-            });
-        } else if (TextUtils.isEmpty(text) && pageView.getAreaInfoType() == CPDFEditPage.LoadImage) {
-            menuView.addItem(R.string.tools_context_menu_paste, 0, v -> {
-                pageView.pasteEditImageArea(point, pageView.getCopyTextAreaWidth(), pageView.getCopyTextAreaHeight());
-                helper.dismissContextMenu();
-            });
+        if (type == CPDFEditPage.LoadText) {
+            if (!TextUtils.isEmpty(text) && isEditAreaValid == false) {
+                menuView.addItem(R.string.tools_context_menu_paste, 0, v -> {
+                    pageView.pasteEditTextArea(point, pageView.getCopyTextAreaWidth(), pageView.getCopyTextAreaHeight());
+                    helper.dismissContextMenu();
+                });
+            } else if (!TextUtils.isEmpty(text) && isEditAreaValid == true) {
+                menuView.addItem(R.string.tools_context_menu_select_paste, 0, v -> {
+                    pageView.pasteEditTextArea(point, pageView.getCopyTextAreaWidth(), pageView.getCopyTextAreaHeight(), false);
+                    helper.dismissContextMenu();
+                });
+                menuView.addItem(R.string.tools_context_menu_select_paste_with_style, 1, v -> {
+                    pageView.pasteEditTextArea(point, pageView.getCopyTextAreaWidth(), pageView.getCopyTextAreaHeight(), true);
+                    helper.dismissContextMenu();
+                });
+            } else {
+
+            }
+        } else if (type == CPDFEditPage.LoadImage) {
+            if (TextUtils.isEmpty(text) && pageView.getAreaInfoType() == CPDFEditPage.LoadImage) {
+                menuView.addItem(R.string.tools_context_menu_paste, 0, v -> {
+                    pageView.pasteEditImageArea(point, pageView.getCopyTextAreaWidth(), pageView.getCopyTextAreaHeight());
+                    helper.dismissContextMenu();
+                });
+            }
+        } else {
+
         }
         return menuView;
     }

+ 39 - 7
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/utils/CUriUtil.java

@@ -2,6 +2,7 @@ package com.compdfkit.tools.common.utils;
 
 import android.content.Context;
 import android.database.Cursor;
+import android.media.ExifInterface;
 import android.net.Uri;
 import android.provider.MediaStore;
 import android.text.TextUtils;
@@ -17,13 +18,13 @@ public class CUriUtil {
         final String[] projection = {column};
 
         try {
-            cursor = context.getContentResolver().query(uri, projection,null,null,
+            cursor = context.getContentResolver().query(uri, projection, null, null,
                     null);
             if (cursor != null && cursor.moveToFirst()) {
                 final int column_index = cursor.getColumnIndexOrThrow(column);
                 return cursor.getString(column_index);
             }
-        }catch (Exception e){
+        } catch (Exception e) {
 
         } finally {
             if (cursor != null) {
@@ -33,18 +34,49 @@ public class CUriUtil {
         return "";
     }
 
-    public static String copyUriToInternalCache(Context context, Uri uri){
-        try{
+    public static String copyUriToInternalCache(Context context, Uri uri) {
+        try {
             File file = new File(context.getFilesDir(), CFileUtils.CACHE_FOLDER);
             String fileName = CUriUtil.getUriFileName(context, uri);
-            if (TextUtils.isEmpty(fileName)){
-                fileName = "pic_"+System.currentTimeMillis()+".png";
+            if (TextUtils.isEmpty(fileName)) {
+                fileName = "pic_" + System.currentTimeMillis() + ".png";
             }
             String image = CFileUtils.copyImageToInternalDirectory(
                     context, uri, file.getAbsolutePath(), fileName);
             return image;
-        }catch (Exception e){
+        } catch (Exception e) {
             return "";
         }
     }
+
+
+    public static int getBitmapDegree(String path) {
+        int degree = 0;
+        if (TextUtils.isEmpty(path)) {
+            return degree;
+        }
+        try { // 从指定路径下读取图片,并获取其EXIF信息
+            ExifInterface exifInterface = new ExifInterface(path);
+            // 获取图片的旋转信息
+            int orientation = exifInterface.getAttributeInt(
+                    ExifInterface.TAG_ORIENTATION,
+                    ExifInterface.ORIENTATION_NORMAL
+            );
+            switch (orientation) {
+                case ExifInterface.ORIENTATION_ROTATE_90:
+                    degree = 90;
+                    break;
+                case ExifInterface.ORIENTATION_ROTATE_180:
+                    degree = 180;
+                    break;
+                case ExifInterface.ORIENTATION_ROTATE_270:
+                    degree = 270;
+                    break;
+                default:break;
+            }
+            return degree;
+        } catch (Exception e) {
+            return degree;
+        }
+    }
 }

+ 20 - 2
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/utils/image/CBitmapUtil.java

@@ -11,16 +11,19 @@ package com.compdfkit.tools.common.utils.image;
 
 
 import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Matrix;
 
 import com.compdfkit.tools.common.utils.CFileUtils;
+import com.compdfkit.tools.common.utils.CUriUtil;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 
 public class CBitmapUtil {
 
-
-
     public static Bitmap cropTransparent(Bitmap sourceBitmap) {
         try {
             int sourceHeight = sourceBitmap.getHeight();
@@ -121,4 +124,19 @@ public class CBitmapUtil {
             return false;
         }
     }
+
+    public static Bitmap decodeBitmap(String path)  {
+        try {
+            FileInputStream fileInputStream = new FileInputStream(path);
+            Bitmap bitmap = BitmapFactory.decodeStream(fileInputStream);
+            int degrees = CUriUtil.getBitmapDegree(path);
+            Matrix matrix = new Matrix();
+            matrix.setRotate(degrees);
+            Bitmap bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
+            bitmap.recycle();
+            return bmp;
+        } catch (Exception e) {
+            return null;
+        }
+    }
 }

+ 2 - 4
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/forms/pdfformbar/CFormToolbar.java

@@ -152,8 +152,7 @@ public class CFormToolbar extends FrameLayout {
                 }
                 pdfView.getCPdfReaderView().getUndoManager().undo();
             }
-        } catch (CPDFUndoFailedException e) {
-            throw new RuntimeException(e);
+        } catch (Exception e) {
         }
     }
 
@@ -167,8 +166,7 @@ public class CFormToolbar extends FrameLayout {
                 }
                 pdfView.getCPdfReaderView().getUndoManager().redo();
             }
-        } catch (CPDFRedoFailedException e) {
-            throw new RuntimeException(e);
+        } catch (Exception e) {
         }
     }
 

+ 3 - 3
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/forms/pdfproperties/pdfsign/CustomSignatureWidgetImpl.java

@@ -17,6 +17,7 @@ import androidx.fragment.app.FragmentActivity;
 
 import com.compdfkit.core.annotation.CPDFImageScaleType;
 import com.compdfkit.core.annotation.form.CPDFSignatureWidget;
+import com.compdfkit.tools.common.utils.image.CBitmapUtil;
 import com.compdfkit.tools.common.views.pdfproperties.pdfstyle.CAnnotStyle;
 import com.compdfkit.tools.common.views.pdfproperties.pdfstyle.CStyleDialogFragment;
 import com.compdfkit.tools.common.views.pdfproperties.pdfstyle.CStyleType;
@@ -40,11 +41,10 @@ public class CustomSignatureWidgetImpl extends CPDFSignatureWidgetImpl {
             CAnnotStyle annotStyle = styleDialogFragment.getAnnotStyle();
             if (!TextUtils.isEmpty(annotStyle.getImagePath())) {
                 try {
-                    FileInputStream fileInputStream = new FileInputStream(annotStyle.getImagePath());
-                    Bitmap bitmap = BitmapFactory.decodeStream(fileInputStream);
+                    Bitmap bitmap = CBitmapUtil.decodeBitmap(annotStyle.getImagePath());
                     ((CPDFSignatureWidget) pdfAnnotation).updateApWithBitmap(bitmap, CPDFImageScaleType.SCALETYPE_fitCenter);
                     refresh();
-                } catch (FileNotFoundException e) {
+                } catch (Exception e) {
                     e.printStackTrace();
                 }
             }