|
@@ -13,8 +13,11 @@ package com.compdfkit.tools.common.utils.annotation;
|
|
|
import android.content.Context;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.graphics.BitmapFactory;
|
|
|
+import android.graphics.Matrix;
|
|
|
import android.graphics.PointF;
|
|
|
import android.graphics.RectF;
|
|
|
+import android.media.ExifInterface;
|
|
|
+import android.util.Log;
|
|
|
|
|
|
import androidx.fragment.app.FragmentActivity;
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
@@ -147,13 +150,35 @@ public class CPDFAnnotationManager {
|
|
|
CPDFPage page = readerView.getPDFDocument().pageAtIndex(readerView.getPageNum());
|
|
|
CPDFStampAnnotation stampAnnotation = (CPDFStampAnnotation) page.addAnnot(CPDFAnnotation.Type.STAMP);
|
|
|
stampAnnotation.setImageStamp(imagePath);
|
|
|
+
|
|
|
+ ExifInterface exif = null;
|
|
|
+ int rotate = 0;
|
|
|
+ try {
|
|
|
+ exif = new ExifInterface(imagePath);
|
|
|
+ int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
|
|
|
+ switch (orientation) {
|
|
|
+ case ExifInterface.ORIENTATION_ROTATE_90:
|
|
|
+ rotate = 90;
|
|
|
+ break;
|
|
|
+ case ExifInterface.ORIENTATION_ROTATE_180:
|
|
|
+ rotate = 180;
|
|
|
+ break;
|
|
|
+ case ExifInterface.ORIENTATION_ROTATE_270:
|
|
|
+ rotate = 270;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
float defaultWidth = 200F;
|
|
|
PointF vertex = new PointF(pointF.x - (defaultWidth / 2), pointF.y);
|
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
|
options.inJustDecodeBounds = true;
|
|
|
BitmapFactory.decodeFile(imagePath, options);
|
|
|
RectF insertRect = new RectF(vertex.x, vertex.y, vertex.x + defaultWidth, vertex.y
|
|
|
- + defaultWidth * options.outHeight / options.outWidth);
|
|
|
+ + defaultWidth * ((rotate == 0 || rotate == 180) ? options.outHeight / options.outWidth : options.outWidth / options.outHeight));
|
|
|
RectF pageSize = readerView.getPageNoZoomSize(readerView.getPageNum());
|
|
|
insertRect.set(page.convertRectToPage(readerView.isCropMode(), pageSize.width(),
|
|
|
pageSize.height(), insertRect));
|
|
@@ -162,7 +187,17 @@ public class CPDFAnnotationManager {
|
|
|
BitmapFactory.Options tmpOptions = new BitmapFactory.Options();
|
|
|
tmpOptions.inMutable = true;
|
|
|
Bitmap bitmap = BitmapFactory.decodeFile(imagePath, tmpOptions);
|
|
|
- stampAnnotation.updateApWithBitmap(bitmap);
|
|
|
+ if (rotate == 0) {
|
|
|
+ stampAnnotation.updateApWithBitmap(bitmap);
|
|
|
+ } else {
|
|
|
+ int width = bitmap.getWidth();
|
|
|
+ int height = bitmap.getHeight();
|
|
|
+ Matrix matrix = new Matrix();
|
|
|
+ matrix.setRotate(rotate);
|
|
|
+ Bitmap newBM = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);
|
|
|
+ stampAnnotation.updateApWithBitmap(newBM);
|
|
|
+ newBM.recycle();
|
|
|
+ }
|
|
|
bitmap.recycle();
|
|
|
} else {
|
|
|
stampAnnotation.setImageStamp(imagePath);
|