Browse Source

PDFTools(Android) - 1.修改签名画板 2.移除kmhandwriting

liuxiaolong 1 year ago
parent
commit
72f649ccbf

+ 0 - 1
ComPDFKit_Tools/build.gradle

@@ -42,7 +42,6 @@ dependencies {
     api fileTree(include: ['*.jar'], dir: 'libs')
     api project(path:':compdfkit-repo:compdfkit')
     api project(path:':compdfkit-repo:compdfkit-ui')
-    api project(path:':compdfkit-repo:compdfkit-kmhandwriting')
     api 'com.github.bumptech.glide:glide:4.15.1'
     annotationProcessor 'com.github.bumptech.glide:compiler:4.15.1'
 

+ 12 - 11
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/annotation/pdfproperties/pdfsignature/CAddSignatureActivity.java

@@ -39,8 +39,7 @@ import com.compdfkit.tools.common.utils.view.colorpicker.ColorPickerDialogFragme
 import com.compdfkit.tools.common.utils.viewutils.CViewUtils;
 import com.compdfkit.tools.common.views.CToolBar;
 import com.compdfkit.tools.common.views.pdfproperties.colorlist.ColorListView;
-import com.compdfkit.tools.common.views.pdfproperties.writing.CKMHandWritingHelper;
-import com.compdfkit.tools.common.views.pdfproperties.writing.CPDFWritingView;
+import com.compdfkit.tools.common.views.pdfproperties.writing.CPDFSignatureEditView;
 import com.google.android.material.floatingactionbutton.FloatingActionButton;
 
 
@@ -54,7 +53,7 @@ public class CAddSignatureActivity extends AppCompatActivity implements View.OnC
 
     private CToolBar cToolBar;
 
-    private CPDFWritingView writingView;
+    private CPDFSignatureEditView writingView;
 
     private AppCompatEditText editText;
 
@@ -154,7 +153,7 @@ public class CAddSignatureActivity extends AppCompatActivity implements View.OnC
         sbThickness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
             @Override
             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-                writingView.setPenWidth(Math.max(0, progress));
+                writingView.setLineWidth(Math.max(0, progress));
             }
 
             @Override
@@ -170,9 +169,7 @@ public class CAddSignatureActivity extends AppCompatActivity implements View.OnC
     }
 
     private void initView() {
-        writingView.setDrawEffect(CKMHandWritingHelper.DrawEffect.NORMAL);
-        writingView.setPenWidth(20);
-        writingView.setColor(Color.BLACK);
+        writingView.setAttribute(20,  Color.BLACK, 255);
     }
 
     private void switchTab(int selectPosition) {
@@ -223,7 +220,8 @@ public class CAddSignatureActivity extends AppCompatActivity implements View.OnC
 
     private void cleanSignature() {
         if (ivAddDrawSignature.isSelected()) {
-            writingView.clean();
+            writingView.cancelDraw();
+            writingView.invalidate();
         } else if (ivAddTextSignature.isSelected()) {
             editText.setText("");
         } else {
@@ -234,7 +232,7 @@ public class CAddSignatureActivity extends AppCompatActivity implements View.OnC
 
     private void setSignatureColor(int color) {
         if (ivAddDrawSignature.isSelected()) {
-            writingView.setColor(color);
+            writingView.setLineColor(color);
         } else if (ivAddTextSignature.isSelected()) {
             editText.setTextColor(color);
         }
@@ -243,7 +241,7 @@ public class CAddSignatureActivity extends AppCompatActivity implements View.OnC
     private int getSignatureColor() {
         int color = Color.BLACK;
         if (ivAddDrawSignature.isSelected()) {
-            color = writingView.getColor();
+            color = writingView.getLineColor();
         } else if (ivAddTextSignature.isSelected()) {
             color = editText.getCurrentTextColor();
         }
@@ -255,7 +253,10 @@ public class CAddSignatureActivity extends AppCompatActivity implements View.OnC
         CThreadPoolUtils.getInstance().execute(() -> {
             String savePath = null;
             if (ivAddDrawSignature.isSelected()) {
-                Bitmap resultBitmap = CBitmapUtil.cropTransparent(writingView.getBitmap());
+                Bitmap resultBitmap = writingView.getBitmap();
+                if (resultBitmap == null){
+                    return;
+                }
                 savePath = CSignatureDatas.saveSignatureBitmap(this, resultBitmap);
             } else if (ivAddTextSignature.isSelected()) {
                 if (editText.getText() != null && editText.getText().length() > 0) {

+ 0 - 550
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/pdfproperties/writing/CKMHandWritingHelper.java

@@ -1,550 +0,0 @@
-package com.compdfkit.tools.common.views.pdfproperties.writing;
-
-/**
- * @classname:
- * @author: LiuXiaoLong
- * @date: 2023/5/24
- * description:
- */
-
-
-import android.graphics.Bitmap;
-import android.graphics.Bitmap.Config;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Paint.Cap;
-import android.graphics.Paint.Join;
-import android.graphics.Paint.Style;
-import android.graphics.Path;
-import android.graphics.PointF;
-import android.graphics.PorterDuff.Mode;
-import android.graphics.PorterDuffXfermode;
-import android.graphics.RectF;
-
-import com.kdanmobile.handwriting.KMLineProcess;
-import com.kdanmobile.handwriting.LPPoint;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-public class CKMHandWritingHelper {
-    private static final String TAG = "KMHandwritingHelper";
-    private KMLineProcess lineProcess;
-    private LPPoint[] lpPoints;
-    private Paint mPaint;
-    private Paint erasePaint;
-    private Bitmap mBitmap;
-    private Canvas mCanvas;
-    private int color;
-    private float penWidth = 60.0F;
-    private float eraseWidth = 60.0F;
-    private float halfPenWidth = 30.0F;
-    private LPPoint prePoint = null;
-    private CKMHandWritingHelper.DrawMode drawMode;
-    private CKMHandWritingHelper.DrawEffect drawEffect;
-    private Path erasePath;
-    private Path drawNormalTmpPath;
-    private float oldX;
-    private float oldY;
-    private int canvasWidth;
-    private int canvasHeight;
-    private boolean isInited;
-    private boolean isOnMoving;
-    private ArrayList<Float[]> srcPoints;
-    private ArrayList<Float[]> recoverPoints;
-    private ArrayList<Float> tmpPoints;
-    private int START;
-    private RectF area;
-
-    public CKMHandWritingHelper() {
-        this.drawMode = CKMHandWritingHelper.DrawMode.DRAW;
-        this.drawEffect = CKMHandWritingHelper.DrawEffect.PENSTROKE;
-        this.isInited = false;
-        this.isOnMoving = false;
-        this.srcPoints = new ArrayList();
-        this.recoverPoints = new ArrayList();
-        this.tmpPoints = new ArrayList();
-        this.START = 6;
-        this.mPaint = new Paint();
-        this.mPaint.setColor(-65536);
-        this.color = -65536;
-        this.mPaint.setStyle(Style.STROKE);
-        this.mPaint.setStrokeCap(Cap.ROUND);
-        this.mPaint.setStrokeJoin(Join.ROUND);
-        this.mPaint.setAntiAlias(true);
-        this.mPaint.setStrokeMiter(1.0F);
-        this.mPaint.setXfermode(new PorterDuffXfermode(Mode.SRC));
-        this.erasePaint = new Paint();
-        this.erasePaint.setStyle(Style.STROKE);
-        this.erasePaint.setStrokeCap(Cap.ROUND);
-        this.erasePaint.setStrokeJoin(Join.ROUND);
-        this.erasePaint.setAntiAlias(true);
-        this.erasePaint.setStrokeMiter(1.0F);
-        this.erasePaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
-        this.lineProcess = new KMLineProcess();
-        this.lineProcess.setPenWidth(this.penWidth);
-        this.erasePath = new Path();
-        this.drawNormalTmpPath = new Path();
-    }
-
-    public void initCanvas(int width, int height) {
-        if (width != 0 && height != 0) {
-            this.canvasWidth = width;
-            this.canvasHeight = height;
-            this.mBitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
-            this.mCanvas = new Canvas(this.mBitmap);
-            this.mCanvas.drawColor(0);
-            this.isInited = true;
-        }
-    }
-
-    public int getCanvasWidth() {
-        return this.canvasWidth;
-    }
-
-    public int getCanvasHeight() {
-        return this.canvasHeight;
-    }
-
-    public boolean isInited() {
-        return this.isInited;
-    }
-
-    public void setPenWidth(float penWidth) {
-        this.penWidth = penWidth;
-        this.halfPenWidth = penWidth / 2.0F;
-        this.lineProcess.setPenWidth(penWidth);
-    }
-
-    public void setEraseWidth(float eraseWidth) {
-        this.eraseWidth = eraseWidth;
-    }
-
-    public void setDrawMode(CKMHandWritingHelper.DrawMode drawMode) {
-        this.drawMode = drawMode;
-    }
-
-    public void setDrawEffect(CKMHandWritingHelper.DrawEffect drawEffect) {
-        this.drawEffect = drawEffect;
-    }
-
-    public CKMHandWritingHelper.DrawMode getDrawMode() {
-        return this.drawMode;
-    }
-
-    public void setColor(int color) {
-        this.mPaint.setColor(color);
-        this.color = this.color & -16777216 | color;
-    }
-
-    public void refreshSrcPointsColor(int color){
-        if (srcPoints != null) {
-            for (Float[] srcPoint : srcPoints) {
-                srcPoint[2] = (float) Color.alpha(color);
-                srcPoint[3] = (float) Color.red(color);
-                srcPoint[4] = (float) Color.green(color);
-                srcPoint[5] = (float) Color.blue(color);
-            }
-            reDrawBitmap();
-        }
-    }
-
-    public void refreshPenWidth(float penWidth){
-        if (srcPoints != null) {
-            for (Float[] srcPoint : srcPoints) {
-                float currentPenWidth = srcPoint[1];
-                if (currentPenWidth != -1F){
-                    srcPoint[1] = penWidth;
-                }
-            }
-            reDrawBitmap();
-        }
-    }
-
-    public void setAlpha(int alpha) {
-        this.mPaint.setAlpha(alpha);
-        this.color = this.color & 16777215 | alpha << 24;
-    }
-
-    public void clean() {
-        if (this.mCanvas != null) {
-            this.mCanvas.drawColor(0, Mode.CLEAR);
-        }
-
-        if (this.mBitmap != null && !this.mBitmap.isRecycled()) {
-            this.mBitmap.recycle();
-        }
-
-        this.mBitmap = null;
-        this.isInited = false;
-        this.area = null;
-        this.srcPoints.clear();
-        this.recoverPoints.clear();
-        this.tmpPoints.clear();
-    }
-
-    public boolean onDown(float x, float y, float pressure, float altitude) {
-        x = this.limitPoint(x, true);
-        y = this.limitPoint(y, false);
-        x = Math.max(0.0F, x);
-        x = Math.min((float)this.canvasWidth, x);
-        y = Math.max(0.0F, y);
-        y = Math.min((float)this.canvasHeight, y);
-        this.tmpPoints.clear();
-        if (this.drawMode == CKMHandWritingHelper.DrawMode.DRAW) {
-            this.lineProcess.onDown(x, y, pressure, altitude);
-            this.tmpPoints.add(-1.0F);
-            this.mPaint.setStrokeWidth(this.penWidth);
-            this.drawNormalTmpPath.reset();
-            if (this.drawEffect == CKMHandWritingHelper.DrawEffect.NORMAL) {
-                this.tmpPoints.add(this.penWidth);
-                this.tmpPoints.add((float)Color.alpha(this.color));
-                this.tmpPoints.add((float)Color.red(this.color));
-                this.tmpPoints.add((float)Color.green(this.color));
-                this.tmpPoints.add((float)Color.blue(this.color));
-                this.tmpPoints.add(x);
-                this.tmpPoints.add(y);
-                this.drawNormalTmpPath.moveTo(x, y);
-                if (this.area == null) {
-                    this.area = new RectF(x - this.penWidth, y - this.penWidth, x + this.penWidth, y + this.penWidth);
-                } else {
-                    this.area.union(x - this.penWidth, y - this.penWidth, x + this.penWidth, y + this.penWidth);
-                }
-            } else {
-                this.tmpPoints.add(-1.0F);
-                this.tmpPoints.add((float)Color.alpha(this.color));
-                this.tmpPoints.add((float)Color.red(this.color));
-                this.tmpPoints.add((float)Color.green(this.color));
-                this.tmpPoints.add((float)Color.blue(this.color));
-            }
-
-            this.prePoint = new LPPoint(x, y, 0.0F);
-        } else {
-            this.erasePaint.setStrokeWidth(this.eraseWidth);
-            this.erasePath.reset();
-            this.erasePath.moveTo(x, y);
-            this.oldX = x;
-            this.oldY = y;
-            this.tmpPoints.add(this.eraseWidth);
-            this.tmpPoints.add(this.eraseWidth);
-            this.tmpPoints.add(x);
-            this.tmpPoints.add(y);
-        }
-
-        return true;
-    }
-
-    public boolean onMove(float x, float y, float pressure, float altitude) {
-        x = this.limitPoint(x, true);
-        y = this.limitPoint(y, false);
-        x = Math.max(0.0F, x);
-        x = Math.min((float)this.canvasWidth, x);
-        y = Math.max(0.0F, y);
-        y = Math.min((float)this.canvasHeight, y);
-        if (this.drawMode == CKMHandWritingHelper.DrawMode.DRAW) {
-            if (this.drawEffect == CKMHandWritingHelper.DrawEffect.PENSTROKE) {
-                this.lpPoints = this.lineProcess.onMove(x, y, pressure, altitude);
-                if (this.lpPoints != null && this.lpPoints.length > 0) {
-                    LPPoint[] var5 = this.lpPoints;
-                    int var6 = var5.length;
-
-                    for(int var7 = 0; var7 < var6; ++var7) {
-                        LPPoint point = var5[var7];
-                        if (point != null) {
-                            this.mPaint.setStrokeWidth(point.size);
-                            if (this.mCanvas != null) {
-                                this.mCanvas.drawLine(this.prePoint.x, this.prePoint.y, point.x, point.y, this.mPaint);
-                            }
-
-                            this.prePoint = point;
-                            if (this.area == null) {
-                                this.area = new RectF(point.x - point.size, point.y - point.size, point.x + point.size, point.y + point.size);
-                            } else {
-                                this.area.union(point.x - point.size, point.y - point.size, point.x + point.size, point.y + point.size);
-                            }
-
-                            this.tmpPoints.add(point.x);
-                            this.tmpPoints.add(point.y);
-                            this.tmpPoints.add(point.size);
-                        }
-                    }
-
-                    this.isOnMoving = true;
-                    return true;
-                } else {
-                    return false;
-                }
-            } else {
-                this.drawNormalTmpPath.quadTo(this.prePoint.x, this.prePoint.y, (this.prePoint.x + x) / 2.0F, (this.prePoint.y + y) / 2.0F);
-                this.prePoint.x = x;
-                this.prePoint.y = y;
-                if (this.mCanvas != null) {
-                    this.mCanvas.drawPath(this.drawNormalTmpPath, this.mPaint);
-                }
-
-                this.tmpPoints.add(x);
-                this.tmpPoints.add(y);
-                if (this.area == null) {
-                    this.area = new RectF(x - this.penWidth, y - this.penWidth, x + this.penWidth, y + this.penWidth);
-                } else {
-                    this.area.union(x - this.penWidth, y - this.penWidth, x + this.penWidth, y + this.penWidth);
-                }
-
-                this.isOnMoving = true;
-                return true;
-            }
-        } else {
-            this.erasePath.quadTo(this.oldX, this.oldY, (this.oldX + x) / 2.0F, (this.oldY + y) / 2.0F);
-            this.oldX = x;
-            this.oldY = y;
-            this.tmpPoints.add(x);
-            this.tmpPoints.add(y);
-            return true;
-        }
-    }
-
-    public boolean onUp(float x, float y, float pressure, float altitude) {
-        this.isOnMoving = false;
-        x = Math.max(0.0F, x);
-        x = Math.min((float)this.canvasWidth, x);
-        y = Math.max(0.0F, y);
-        y = Math.min((float)this.canvasHeight, y);
-        if (this.drawMode == CKMHandWritingHelper.DrawMode.DRAW) {
-            if (this.drawEffect == CKMHandWritingHelper.DrawEffect.PENSTROKE) {
-                this.lpPoints = this.lineProcess.onUp(x, y, pressure, altitude);
-                if (this.lpPoints != null && this.lpPoints.length > 0) {
-                    LPPoint[] var5 = this.lpPoints;
-                    int var6 = var5.length;
-
-                    for(int var7 = 0; var7 < var6; ++var7) {
-                        LPPoint point = var5[var7];
-                        if (point != null) {
-                            this.mPaint.setStrokeWidth(point.size);
-                            if (this.mCanvas != null) {
-                                this.mCanvas.drawLine(this.prePoint.x, this.prePoint.y, point.x, point.y, this.mPaint);
-                            }
-
-                            this.prePoint = point;
-                            if (this.area == null) {
-                                this.area = new RectF(point.x - point.size, point.y - point.size, point.x + point.size, point.y + point.size);
-                            } else {
-                                this.area.union(point.x - point.size, point.y - point.size, point.x + point.size, point.y + point.size);
-                            }
-
-                            this.tmpPoints.add(point.x);
-                            this.tmpPoints.add(point.y);
-                            this.tmpPoints.add(point.size);
-                        }
-                    }
-
-                    this.addSrcPoints(this.tmpPoints);
-                    return true;
-                } else {
-                    return false;
-                }
-            } else {
-                this.drawNormalTmpPath.lineTo(x, y);
-                if (this.mCanvas != null) {
-                    this.mCanvas.drawPath(this.drawNormalTmpPath, this.mPaint);
-                }
-
-                this.tmpPoints.add(x);
-                this.tmpPoints.add(y);
-                this.addSrcPoints(this.tmpPoints);
-                if (this.area == null) {
-                    this.area = new RectF(x - this.penWidth, y - this.penWidth, x + this.penWidth, y + this.penWidth);
-                } else {
-                    this.area.union(x - this.penWidth, y - this.penWidth, x + this.penWidth, y + this.penWidth);
-                }
-
-                return true;
-            }
-        } else {
-            this.erasePath.lineTo(x, y);
-            if (this.mCanvas != null) {
-                this.mCanvas.drawPath(this.erasePath, this.erasePaint);
-            }
-
-            this.erasePath.reset();
-            this.tmpPoints.add(x);
-            this.tmpPoints.add(y);
-            this.addSrcPoints(this.tmpPoints);
-            return true;
-        }
-    }
-
-    public void onUndo() {
-        int len = this.srcPoints.size();
-        if (len > 0) {
-            Float[] undoPoints = (Float[])this.srcPoints.remove(len - 1);
-            this.recoverPoints.add(undoPoints);
-            this.reDrawBitmap();
-        }
-    }
-
-    public void onRedo() {
-        int len = this.recoverPoints.size();
-        if (len > 0) {
-            Float[] redoPoints = (Float[])this.recoverPoints.remove(len - 1);
-            this.srcPoints.add(redoPoints);
-            this.reDrawBitmap();
-        }
-    }
-
-    public void onMisTouch() {
-        if (this.isOnMoving) {
-            this.addSrcPoints(this.tmpPoints);
-            int len = this.srcPoints.size();
-            if (len <= 0) {
-                return;
-            }
-
-            this.srcPoints.remove(len - 1);
-            this.reDrawBitmap();
-        }
-
-        this.isOnMoving = false;
-    }
-
-    public Path getErasePath() {
-        return this.erasePath;
-    }
-
-    public RectF getArea() {
-        RectF resRect = new RectF(this.area);
-        resRect.intersect(0.0F, 0.0F, (float)this.canvasWidth, (float)this.canvasHeight);
-        return resRect;
-    }
-
-    public Bitmap getBitmap() {
-        return this.mBitmap;
-    }
-
-    private float limitPoint(float point, Boolean isXCoordinate) {
-        int canvasWidth = this.mCanvas.getWidth();
-        int canvasHeight = this.mCanvas.getHeight();
-        if (point < this.halfPenWidth) {
-            point = this.halfPenWidth;
-        }
-
-        float maxRight;
-        if (isXCoordinate) {
-            maxRight = (float)canvasWidth - this.halfPenWidth;
-            if (point > maxRight) {
-                point = maxRight;
-            }
-        } else {
-            maxRight = (float)canvasHeight - this.halfPenWidth;
-            if (point > maxRight) {
-                point = maxRight;
-            }
-        }
-
-        return point;
-    }
-
-    private void addSrcPoints(ArrayList<Float> points) {
-        Float[] fpoints = new Float[points.size()];
-        points.toArray(fpoints);
-        this.srcPoints.add(fpoints);
-        this.recoverPoints.clear();
-        points.clear();
-    }
-
-    private void reDrawBitmap() {
-        if (this.mCanvas != null) {
-            this.mCanvas.drawColor(0, Mode.CLEAR);
-        }
-
-        Iterator var1 = this.srcPoints.iterator();
-
-        while(true) {
-            while(true) {
-                while(true) {
-                    Float[] line;
-                    do {
-                        if (!var1.hasNext()) {
-                            return;
-                        }
-
-                        line = (Float[])var1.next();
-                    } while(line.length <= 2);
-
-                    if (line[0] < 0.0F) {
-                        PointF prePoint = null;
-                        Float alpha = line[2];
-                        Float red = line[3];
-                        Float green = line[4];
-                        Float blue = line[5];
-                        this.mPaint.setColor(Color.argb(alpha.intValue(), red.intValue(), green.intValue(), blue.intValue()));
-                        if (line[1] < 0.0F) {
-                            for(int i = 0; i < (line.length - this.START) / 3; ++i) {
-                                if (prePoint != null) {
-                                    this.mPaint.setStrokeWidth(line[i * 3 + this.START + 2]);
-                                    if (this.mCanvas != null) {
-                                        this.mCanvas.drawLine(prePoint.x, prePoint.y, line[i * 3 + this.START], line[i * 3 + this.START + 1], this.mPaint);
-                                    }
-
-                                    prePoint.set(line[i * 3 + this.START], line[i * 3 + this.START + 1]);
-                                } else {
-                                    prePoint = new PointF(line[i * 3 + this.START], line[i * 3 + this.START + 1]);
-                                }
-                            }
-                        } else {
-                            Path path = new Path();
-
-                            for(int i = 0; i < (line.length - this.START) / 2; ++i) {
-                                if (i == 0) {
-                                    path.moveTo(line[i * 2 + this.START], line[i * 2 + this.START + 1]);
-                                } else if (i < (line.length - this.START) / 2 - 1) {
-                                    path.quadTo(line[i * 2 + this.START - 2], line[i * 2 + this.START - 1], (line[i * 2 + this.START - 2] + line[i * 2 + this.START]) / 2.0F, (line[i * 2 + this.START - 1] + line[i * 2 + this.START + 1]) / 2.0F);
-                                } else {
-                                    path.lineTo(line[i * 2 + this.START], line[i * 2 + this.START + 1]);
-                                }
-                            }
-
-                            this.mPaint.setStrokeWidth(line[1]);
-                            if (this.mCanvas != null) {
-                                this.mCanvas.drawPath(path, this.mPaint);
-                            }
-                        }
-                    } else {
-                        Path path = new Path();
-
-                        for(int i = 0; i < (line.length - 2) / 2; ++i) {
-                            if (i == 0) {
-                                path.moveTo(line[i * 2 + 2], line[i * 2 + 3]);
-                            } else if (i < (line.length - 2) / 2 - 1) {
-                                path.quadTo(line[i * 2], line[i * 2 + 1], (line[i * 2] + line[i * 2 + 2]) / 2.0F, (line[i * 2 + 1] + line[i * 2 + 3]) / 2.0F);
-                            } else {
-                                path.lineTo(line[i * 2 + 2], line[i * 2 + 3]);
-                            }
-                        }
-
-                        this.erasePaint.setStrokeWidth(line[0]);
-                        if (this.mCanvas != null) {
-                            this.mCanvas.drawPath(path, this.erasePaint);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    public static enum DrawEffect {
-        NORMAL,
-        PENSTROKE;
-
-        private DrawEffect() {
-        }
-    }
-
-    public static enum DrawMode {
-        DRAW,
-        ERASE;
-
-        private DrawMode() {
-        }
-    }
-}

+ 0 - 172
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/pdfproperties/writing/CKmWritingView.java

@@ -1,172 +0,0 @@
-package com.compdfkit.tools.common.views.pdfproperties.writing;
-
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.Paint.Cap;
-import android.graphics.Paint.Join;
-import android.graphics.Paint.Style;
-import android.graphics.Path;
-import android.graphics.RectF;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.view.View;
-
-import androidx.annotation.Nullable;
-
-
-public class CKmWritingView extends View {
-    private Context mContext;
-    protected CKMHandWritingHelper handwritingHelper;
-    private Paint erasePathPaint;
-    private int erasePathColor = -7829368;
-
-    public CKmWritingView(Context context) {
-        super(context);
-        this.initView(context);
-    }
-
-    public CKmWritingView(Context context, @Nullable AttributeSet attrs) {
-        super(context, attrs);
-        this.initView(context);
-    }
-
-    public CKmWritingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
-        super(context, attrs, defStyleAttr);
-        this.initView(context);
-    }
-
-    private void initView(Context context) {
-        this.mContext = context;
-        this.setWillNotDraw(false);
-        this.handwritingHelper = new CKMHandWritingHelper();
-        this.erasePathPaint = new Paint();
-        this.erasePathPaint.setColor(this.erasePathColor);
-        this.erasePathPaint.setStyle(Style.STROKE);
-        this.erasePathPaint.setStrokeCap(Cap.ROUND);
-        this.erasePathPaint.setStrokeJoin(Join.ROUND);
-        this.erasePathPaint.setAntiAlias(true);
-        this.erasePathPaint.setStrokeMiter(1.0F);
-        this.erasePathPaint.setStrokeWidth(60.0F);
-    }
-
-    public void onWindowFocusChanged(boolean hasWindowFocus) {
-        super.onWindowFocusChanged(hasWindowFocus);
-        if (hasWindowFocus) {
-            this.post(() -> {
-                if (this.handwritingHelper != null && !this.handwritingHelper.isInited()) {
-                    this.handwritingHelper.initCanvas(this.getWidth(), this.getHeight());
-                }
-            });
-        }
-
-    }
-
-    public void setDrawMode(CKMHandWritingHelper.DrawMode drawMode) {
-        if (this.handwritingHelper != null) {
-            this.handwritingHelper.setDrawMode(drawMode);
-        }
-
-    }
-
-    public void setDrawEffect(CKMHandWritingHelper.DrawEffect drawEffect) {
-        if (this.handwritingHelper != null) {
-            this.handwritingHelper.setDrawEffect(drawEffect);
-        }
-
-    }
-
-    public CKMHandWritingHelper.DrawMode getDrawMode() {
-        return this.handwritingHelper != null ? this.handwritingHelper.getDrawMode() : CKMHandWritingHelper.DrawMode.DRAW;
-    }
-
-    public void setPenWidth(float penWidth) {
-        if (this.handwritingHelper != null) {
-            this.handwritingHelper.setPenWidth(penWidth);
-        }
-    }
-
-    public void setEraseWidth(float eraseWidth) {
-        if (this.handwritingHelper != null) {
-            this.handwritingHelper.setEraseWidth(eraseWidth);
-        }
-        this.erasePathPaint.setStrokeWidth(eraseWidth);
-    }
-
-    public void setColor(int color) {
-        if (this.handwritingHelper != null) {
-            this.handwritingHelper.setColor(color);
-        }
-    }
-
-    public void setAlpha(int alpha) {
-        if (this.handwritingHelper != null) {
-            this.handwritingHelper.setAlpha(alpha);
-        }
-    }
-
-    public void clean() {
-        if (this.handwritingHelper != null) {
-            this.handwritingHelper.clean();
-        }
-    }
-
-    public boolean onTouchEvent(MotionEvent event) {
-        if (this.handwritingHelper == null) {
-            return false;
-        } else {
-            if (!this.handwritingHelper.isInited()) {
-                this.handwritingHelper.initCanvas(this.getWidth(), this.getHeight());
-            }
-
-            switch (event.getActionMasked()) {
-                case 0:
-                    this.handwritingHelper.onDown(event.getX(), event.getY(), -1.0F, -1.0F);
-                    break;
-                case 1:
-                    if (this.handwritingHelper.onUp(event.getX(), event.getY(), -1.0F, -1.0F)) {
-                        this.invalidate();
-                    }
-                    break;
-                case 2:
-                    if (this.handwritingHelper.onMove(event.getX(), event.getY(), -1.0F, -1.0F)) {
-                        this.invalidate();
-                    }
-            }
-
-            return true;
-        }
-    }
-
-    protected void onDraw(Canvas canvas) {
-        if (this.handwritingHelper != null) {
-            Bitmap bitmap = this.handwritingHelper.getBitmap();
-            if (bitmap != null && !bitmap.isRecycled()) {
-                canvas.drawBitmap(bitmap, 0.0F, 0.0F, (Paint)null);
-            }
-
-            Path erasePath = this.handwritingHelper.getErasePath();
-            if (erasePath != null && !erasePath.isEmpty()) {
-                canvas.drawPath(erasePath, this.erasePathPaint);
-            }
-        }
-
-    }
-
-    public boolean isBlank() {
-        if (this.handwritingHelper != null) {
-            RectF area = this.handwritingHelper.getArea();
-            if (area != null && Math.abs(area.width()) > 2.0F && Math.abs(area.height()) > 2.0F) {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
-    public Bitmap getBitmap() {
-        return this.handwritingHelper == null ? null : this.handwritingHelper.getBitmap();
-    }
-}

+ 343 - 0
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/pdfproperties/writing/CPDFSignatureEditView.java

@@ -0,0 +1,343 @@
+package com.compdfkit.tools.common.views.pdfproperties.writing;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.PointF;
+import android.graphics.Rect;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+
+import androidx.annotation.Nullable;
+
+import com.compdfkit.ui.utils.CPDFBitmapUtils;
+import com.compdfkit.ui.utils.CPDFScreenUtils;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+public class CPDFSignatureEditView extends View {
+
+    private final int padding = 50;
+
+    /****** 涂鸦的路径 ******/
+    private ArrayList<PathPoints> drawPathPoints = null;
+    /****** 需要在该控件上绘制的bitmap ******/
+    private Bitmap pictureBitmap;
+
+    /****** 上一次点击的坐标,防止记录重复的绘制点 ******/
+    private float lastTouchX = 0;
+    private float lastTouchY = 0;
+
+    /****** 记录绘制区域的大小 ******/
+    private float left = 0;
+    private float right = 0;
+    private float top = 0;
+    private float bottom = 0;
+    private PointF firstTouchPoint;
+    private Paint markerPenPaint_signEdit;
+
+    /****** 画笔属性值 ******/
+    private float lineWidth;
+    private int lineColor = Color.parseColor("#DD2C00");
+    private int lineAlpha = 255;
+
+    public CPDFSignatureEditView(Context context) {
+        super(context);
+        initView(context);
+    }
+
+    public CPDFSignatureEditView(Context context, @Nullable AttributeSet attrs) {
+        super(context, attrs);
+        initView(context);
+    }
+
+    public CPDFSignatureEditView(Context context, @Nullable AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        initView(context);
+    }
+
+    private void initView(Context context){
+        lineWidth = CPDFScreenUtils.dp2px(context, 3.3f);
+    }
+
+    public void setPictureBitmap(Bitmap bitmap) {
+        if (pictureBitmap != null && !pictureBitmap.isRecycled()) {
+            pictureBitmap.recycle();
+        }
+        this.pictureBitmap = Bitmap.createBitmap(bitmap);
+    }
+
+    public void setLineWidth(int lineWidth){
+        this.lineWidth = lineWidth;
+        markerPenPaint_signEdit.setStrokeWidth(lineWidth);
+        if (drawPathPoints != null && drawPathPoints.size() > 0) {
+            for (int i = 0; i < drawPathPoints.size(); i++) {
+                PathPoints points = drawPathPoints.get(i);
+                points.pointSize = lineWidth;
+            }
+        }
+        invalidate();
+    }
+
+    public void setLineColor(int lineColor) {
+        this.lineColor = lineColor;
+        markerPenPaint_signEdit.setColor(lineColor);
+        if (drawPathPoints != null && drawPathPoints.size() > 0) {
+            for (int i = 0; i < drawPathPoints.size(); i++) {
+                PathPoints points = drawPathPoints.get(i);
+                points.pointColor = lineColor;
+            }
+        }
+        invalidate();
+    }
+
+    public int getLineColor() {
+        return lineColor;
+    }
+
+    public void setAttribute(float lineWidth, int lineColor, int lineAlpha) {
+        if (markerPenPaint_signEdit == null) {
+            markerPenPaint_signEdit = new Paint();
+        }
+
+        this.lineWidth = lineWidth;
+        this.lineColor = lineColor;
+        this.lineAlpha = lineAlpha;
+
+        markerPenPaint_signEdit.setStrokeWidth(lineWidth);
+        markerPenPaint_signEdit.setColor(lineColor);
+        markerPenPaint_signEdit.setAlpha(lineAlpha);
+    }
+
+    public Rect getSignViewRect() {
+        float l = left > 0 ? left : 0;
+        float t = top > 0 ? top : 0;
+        float r = right < getWidth() ? right : getWidth();
+        float b = bottom < getHeight() ? bottom : getHeight();
+        float offset = lineWidth / 2.0f;
+        l -= offset;
+        t -= offset;
+        r += offset;
+        b += offset;
+        //添加一些padding
+        return new Rect((int) l-padding, (int) t-padding, (int) r+padding, (int) b+padding);
+    }
+
+    public ArrayList<PathPoints> getDrawPathPoints() {
+        return drawPathPoints;
+    }
+
+    @Override
+    public void draw(Canvas canvas) {
+        super.draw(canvas);
+        drawBitmap(canvas);
+        drawPaintPath(canvas);
+    }
+
+    private void drawBitmap(Canvas canvas) {
+        int width = getWidth();
+        int height = getHeight();
+        int pw = 0;
+        int ph = 0;
+        if (pictureBitmap != null && !pictureBitmap.isRecycled()) {
+            pw = pictureBitmap.getWidth();
+            ph = pictureBitmap.getHeight();
+            canvas.drawBitmap(pictureBitmap, (width - pw) / 2, (height - ph) / 2, null);
+        }
+        if ((width - pw) / 2 < left) {
+            left = (width - pw) / 2;
+        }
+        if ((height - ph) / 2 < top) {
+            top = (height - ph) / 2;
+        }
+        if (((width - pw) / 2 + pw) > right) {
+            right = (width - pw) / 2 + pw;
+        }
+        if (((height - ph) / 2 + ph) > bottom) {
+            bottom = (height - ph) / 2 + ph;
+        }
+    }
+
+    private void drawPaintPath(Canvas canvas) {
+        if (drawPathPoints != null) {
+            PointF p;
+            /****** 保存绘制的每条路径 ******/
+            ArrayList<PathItem> pathList = new ArrayList<>();
+
+            Iterator<PathPoints> it = drawPathPoints.iterator();
+            while (it.hasNext()) {
+                PathPoints pps = it.next();
+                ArrayList<PointF> arc = pps.locations;
+                /****** 获取每条线的颜色值 ******/
+                int lineColor = pps.pointColor;
+                float lineSize = pps.pointSize;
+                int lineAlpha = pps.pointAlpha;
+                if (arc.size() >= 2) {
+                    Path drawingPath = new Path();
+                    Iterator<PointF> iit = arc.iterator();
+                    p = iit.next();
+                    float mX = p.x;
+                    float mY = p.y;
+                    drawingPath.moveTo(mX, mY);
+                    while (iit.hasNext()) {
+                        p = iit.next();
+                        float x = p.x;
+                        float y = p.y;
+                        drawingPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
+                        mX = x;
+                        mY = y;
+                    }
+                    drawingPath.lineTo(mX, mY);
+                    /****** 每条绘制的线和颜色值保存下来 ******/
+                    pathList.add(new PathItem(drawingPath, lineColor, lineSize, lineAlpha));
+                } else {
+                    p = arc.get(0);
+                    markerPenPaint_signEdit.setStyle(Paint.Style.FILL);
+                    markerPenPaint_signEdit.setColor(lineColor);
+                    markerPenPaint_signEdit.setAlpha(lineAlpha);
+                    canvas.drawCircle(p.x, p.y, lineSize / 2, markerPenPaint_signEdit);
+                }
+            }
+
+            Iterator<PathItem> ipath = pathList.iterator();
+            /****** 绘制每一条保存的路径 ******/
+            while (ipath.hasNext()) {
+                PathItem iipath = ipath.next();
+                markerPenPaint_signEdit.setStyle(Paint.Style.STROKE);
+                markerPenPaint_signEdit.setColor(iipath.pathColor);
+                markerPenPaint_signEdit.setAlpha(iipath.pathAlpha);
+                markerPenPaint_signEdit.setStrokeWidth(iipath.pathSize);
+                canvas.drawPath(iipath.path, markerPenPaint_signEdit);
+            }
+        }
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent event) {
+        float x = event.getX();
+        float y = event.getY();
+        if (firstTouchPoint == null) {
+            firstTouchPoint = new PointF(x, y);
+        }
+        findPaintingRect(x, y);
+        if (x != lastTouchX || y != lastTouchY) {
+            switch (event.getAction()) {
+                case MotionEvent.ACTION_DOWN:
+                    startDraw(x, y);
+                    lastTouchX = x;
+                    lastTouchY = y;
+                    return true;
+                case MotionEvent.ACTION_MOVE:
+                    continueDraw(x, y);
+                    lastTouchX = x;
+                    lastTouchY = y;
+                    return true;
+                case MotionEvent.ACTION_UP:
+                    return true;
+                default:
+                    return super.onTouchEvent(event);
+            }
+        }
+
+        return super.onTouchEvent(event);
+    }
+
+    private void findPaintingRect(float x, float y) {
+        if (firstTouchPoint.x == x && firstTouchPoint.y == y) {
+            left = x;
+            right = x;
+            top = y;
+            bottom = y;
+        } else {
+            if (x < left) {
+                left = x;
+            }
+            if (x > right) {
+                right = x;
+            }
+            if (y < top) {
+                top = y;
+            }
+            if (y > bottom) {
+                bottom = y;
+            }
+        }
+    }
+
+    private void startDraw(float x, float y) {
+        if (drawPathPoints == null) {
+            drawPathPoints = new ArrayList<>();
+        }
+
+        ArrayList<PointF> arc = new ArrayList<>();
+        arc.add(new PointF(x, y));
+        PathPoints pps = new PathPoints(arc, lineColor,
+                lineWidth,
+                lineAlpha);
+        drawPathPoints.add(pps);
+        invalidate();
+    }
+
+    private void continueDraw(float x, float y) {
+        if (drawPathPoints != null && drawPathPoints.size() > 0) {
+            PathPoints pps = drawPathPoints.get(drawPathPoints.size() - 1);
+            ArrayList<PointF> arc = pps.locations;
+            arc.add(new PointF(x, y));
+            invalidate();
+        }
+    }
+
+    public void cancelDraw() {
+        drawPathPoints = null;
+        firstTouchPoint = null;
+        if (pictureBitmap != null) {
+            pictureBitmap.recycle();
+            pictureBitmap = null;
+        }
+    }
+
+    public Bitmap getBitmap(){
+        if (getDrawPathPoints() == null || getDrawPathPoints().size()<=0){
+            return null;
+        }
+        Bitmap signEditPic = CPDFBitmapUtils.loadBitmapFromView(this);
+        signEditPic = CPDFBitmapUtils.cropBitmap(signEditPic, getSignViewRect());
+        return signEditPic;
+    }
+
+    class PathPoints {
+        ArrayList<PointF> locations;
+        int pointColor;
+        float pointSize;
+        int pointAlpha;
+
+        public PathPoints(ArrayList<PointF> locations, int pointColor, float pointSize, int pointAlpha) {
+            this.locations = locations;
+            this.pointColor = pointColor;
+            this.pointSize = pointSize;
+            this.pointAlpha = pointAlpha;
+        }
+    }
+
+    class PathItem {
+        Path path;
+        int pathColor;
+        float pathSize;
+        int pathAlpha;
+
+        public PathItem(Path path, int pathColor, float pathSize, int pathAlpha) {
+            this.path = path;
+            this.pathColor = pathColor;
+            this.pathSize = pathSize;
+            this.pathAlpha = pathAlpha;
+        }
+    }
+}
+
+
+

+ 0 - 116
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/pdfproperties/writing/CPDFWritingView.java

@@ -1,116 +0,0 @@
-/**
- * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
- * <p>
- * 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.common.views.pdfproperties.writing;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.util.AttributeSet;
-
-import androidx.annotation.Nullable;
-
-import com.compdfkit.ui.utils.CPDFBitmapUtils;
-
-public class CPDFWritingView extends CKmWritingView {
-
-    private Canvas canvas;
-
-    private Bitmap backgroundBitmap;
-
-    private int penColor;
-
-    public CPDFWritingView(Context context) {
-        super(context);
-    }
-
-    public CPDFWritingView(Context context, @Nullable AttributeSet attrs) {
-        super(context, attrs);
-    }
-
-    public CPDFWritingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
-        super(context, attrs, defStyleAttr);
-    }
-
-    @Override
-    public void clean() {
-        super.clean();
-        if (backgroundBitmap != null && !backgroundBitmap.isRecycled()) {
-            backgroundBitmap.recycle();
-        }
-        backgroundBitmap = null;
-    }
-
-    @Override
-    protected void onDraw(Canvas canvas) {
-        if (handwritingHelper != null) {
-            if (backgroundBitmap != null && !backgroundBitmap.isRecycled()) {
-                canvas.drawBitmap(backgroundBitmap, (float) ((handwritingHelper.getCanvasWidth() - getWidth()) / 2),
-                        (float) ((handwritingHelper.getCanvasHeight() - getHeight()) / 2), null);
-            }
-        }
-        super.onDraw(canvas);
-    }
-
-    @Override
-    public boolean isBlank() {
-        if (backgroundBitmap != null && !backgroundBitmap.isRecycled()) {
-            return false;
-        } else {
-            return super.isBlank();
-        }
-    }
-
-    @Override
-    public Bitmap getBitmap() {
-        Bitmap handWritingBitmap = super.getBitmap();
-        if (handWritingBitmap == null || handWritingBitmap.isRecycled()){
-            return null;
-        }
-        Bitmap viewBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
-        canvas = new Canvas(viewBitmap);
-        if (handwritingHelper != null) {
-            RectF area = handwritingHelper.getArea();
-            if (backgroundBitmap != null && !backgroundBitmap.isRecycled()) {
-                float bitmapWidth = getWidth();
-                float bitmapHeight = getHeight();
-                float canvasWidth = handwritingHelper.getCanvasWidth();
-                float canvasHeight = handwritingHelper.getCanvasHeight();
-                area.union(new RectF(((canvasWidth - bitmapWidth) / 2), ((canvasHeight - bitmapHeight) / 2), ((canvasWidth + bitmapWidth) / 2), ((canvasHeight + bitmapHeight) / 2)));
-                canvas.drawBitmap(backgroundBitmap, ((canvasWidth - bitmapWidth) / 2), ((canvasHeight - bitmapHeight) / 2), null);
-            }
-            canvas.drawBitmap(handWritingBitmap, 0f, 0f, null);
-            return CPDFBitmapUtils.cropBitmap(viewBitmap, new Rect((int) area.left, (int) area.top, (int) area.right, (int) area.bottom));
-        } else {
-            return null;
-        }
-    }
-
-
-    @Override
-    public void setColor(int color) {
-        penColor = color;
-        super.setColor(color);
-        handwritingHelper.refreshSrcPointsColor(color);
-        invalidate();
-    }
-
-    @Override
-    public void setPenWidth(float penWidth) {
-        super.setPenWidth(penWidth);
-        handwritingHelper.refreshPenWidth(penWidth);
-        invalidate();
-    }
-
-    public int getColor(){
-        return penColor;
-    }
-}

+ 4 - 3
ComPDFKit_Tools/src/main/res/layout-land/tools_properties_signature_style_add_activity.xml

@@ -140,10 +140,11 @@
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintTop_toBottomOf="@id/cl_menu">
 
-        <com.compdfkit.tools.common.views.pdfproperties.writing.CPDFWritingView
-            android:id="@+id/writing_view"
+        <com.compdfkit.tools.common.views.pdfproperties.writing.CPDFSignatureEditView
             android:layout_width="match_parent"
-            android:layout_height="match_parent" />
+            android:layout_height="match_parent"
+            android:id="@+id/writing_view"
+            />
 
         <androidx.appcompat.widget.AppCompatEditText
             android:id="@+id/et_text"

+ 5 - 3
ComPDFKit_Tools/src/main/res/layout/tools_properties_signature_style_add_activity.xml

@@ -139,10 +139,12 @@
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintTop_toBottomOf="@id/cl_thickness">
 
-        <com.compdfkit.tools.common.views.pdfproperties.writing.CPDFWritingView
-            android:id="@+id/writing_view"
+
+        <com.compdfkit.tools.common.views.pdfproperties.writing.CPDFSignatureEditView
             android:layout_width="match_parent"
-            android:layout_height="match_parent" />
+            android:layout_height="match_parent"
+            android:id="@+id/writing_view"
+            />
 
         <androidx.appcompat.widget.AppCompatEditText
             android:id="@+id/et_text"

+ 0 - 2
compdfkit-repo/compdfkit-kmhandwriting/build.gradle

@@ -1,2 +0,0 @@
-configurations.maybeCreate("default")
-artifacts.add("default", file('kmhandwriting-v1.0.0.0(202112211011)_release.aar'))

BIN
compdfkit-repo/compdfkit-kmhandwriting/kmhandwriting-v1.0.0.0(202112211011)_release.aar


+ 0 - 1
settings.gradle

@@ -22,4 +22,3 @@ include ':DocsEditor'
 include ':ComPDFKit_Tools'
 include ':compdfkit-repo:compdfkit'
 include ':compdfkit-repo:compdfkit-ui'
-include ':compdfkit-repo:compdfkit-kmhandwriting'