From cea4109277d5e558f4cfa0707aee7e371ed06504 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Tue, 29 Jan 2013 14:53:35 +0000 Subject: Android: implement strikeout annotation creation --- .../src/com/artifex/mupdfdemo/MuPDFActivity.java | 12 +++++ android/src/com/artifex/mupdfdemo/MuPDFCore.java | 6 +++ .../src/com/artifex/mupdfdemo/MuPDFPageView.java | 5 ++ android/src/com/artifex/mupdfdemo/PageView.java | 54 ++++++++++++++++++++++ 4 files changed, 77 insertions(+) (limited to 'android/src') diff --git a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java index f095a041..5ad3d630 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java @@ -106,6 +106,7 @@ public class MuPDFActivity extends Activity private ImageButton mSelectButton; private ImageButton mCancelSelectButton; private ImageButton mCopySelectButton; + private ImageButton mStrikeOutButton; private ImageButton mCancelButton; private ImageButton mOutlineButton; private ViewAnimator mTopBarSwitcher; @@ -652,6 +653,16 @@ public class MuPDFActivity extends Activity } }); + mStrikeOutButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + PageView pageView = (PageView) mDocView.getDisplayedView(); + if (pageView != null) + pageView.strikeOutSelection(); + mSelecting = false; + mTopBarSwitcher.setDisplayedChild(0); + } + }); + mCancelButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { searchModeOff(); @@ -943,6 +954,7 @@ public class MuPDFActivity extends Activity mSelectButton = (ImageButton)mButtonsView.findViewById(R.id.selectButton); mCancelSelectButton = (ImageButton)mButtonsView.findViewById(R.id.cancelSelectButton); mCopySelectButton = (ImageButton)mButtonsView.findViewById(R.id.copySelectButton); + mStrikeOutButton = (ImageButton)mButtonsView.findViewById(R.id.strikeOutButton); mCancelButton = (ImageButton)mButtonsView.findViewById(R.id.cancel); mOutlineButton = (ImageButton)mButtonsView.findViewById(R.id.outlineButton); mTopBarSwitcher = (ViewAnimator)mButtonsView.findViewById(R.id.switcher); diff --git a/android/src/com/artifex/mupdfdemo/MuPDFCore.java b/android/src/com/artifex/mupdfdemo/MuPDFCore.java index ed9ded92..73db5073 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFCore.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFCore.java @@ -38,6 +38,7 @@ public class MuPDFCore int patchW, int patchH); private native RectF[] searchPage(String text); private native TextChar[][][][] text(); + private native void addStrikeOutAnnotationInternal(RectF[] lines); private native int passClickEventInternal(int page, float x, float y); private native void setFocusedWidgetChoiceSelectedInternal(String [] selected); private native String [] getFocusedWidgetChoiceSelected(); @@ -235,6 +236,11 @@ public class MuPDFCore return lns.toArray(new TextWord[lns.size()][]); } + public synchronized void addStrikeOutAnnotation(int page, RectF[] lines) { + gotoPage(page); + addStrikeOutAnnotationInternal(lines); + } + public synchronized boolean hasOutline() { return hasOutlineInternal(); } diff --git a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java index 64877198..69157209 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java @@ -222,6 +222,11 @@ public class MuPDFPageView extends PageView { return mCore.textLines(mPageNumber); } + @Override + protected void addStrikeOut(RectF[] lines) { + mCore.addStrikeOutAnnotation(mPageNumber, lines); + } + @Override public void setPage(final int page, PointF size) { mLoadWidgetAreas = new AsyncTask () { diff --git a/android/src/com/artifex/mupdfdemo/PageView.java b/android/src/com/artifex/mupdfdemo/PageView.java index b793db3f..04065174 100644 --- a/android/src/com/artifex/mupdfdemo/PageView.java +++ b/android/src/com/artifex/mupdfdemo/PageView.java @@ -103,6 +103,8 @@ public abstract class PageView extends ViewGroup { private static final int LINK_COLOR = 0x80AC7225; private static final int BACKGROUND_COLOR = 0xFFFFFFFF; private static final int PROGRESS_DIALOG_DELAY = 200; + private static final float LINE_THICKNESS = 0.07f; + private static final float STRIKE_HEIGHT = 0.375f; private final Context mContext; protected int mPageNumber; private Point mParentSize; @@ -112,6 +114,7 @@ public abstract class PageView extends ViewGroup { private ImageView mEntire; // Image rendered at minimum zoom private BitmapHolder mEntireBmh; private AsyncTask mGetText; + private AsyncTask mAddStrikeOut; private AsyncTask mGetLinkInfo; private AsyncTask mDrawEntire; @@ -144,6 +147,7 @@ public abstract class PageView extends ViewGroup { protected abstract Bitmap updatePage(BitmapHolder h, int sizeX, int sizeY, int patchX, int patchY, int patchWidth, int patchHeight); protected abstract LinkInfo[] getLinkInfo(); protected abstract TextWord[][] getText(); + protected abstract void addStrikeOut(RectF[] lines); private void reinit() { // Cancel pending render task @@ -441,6 +445,56 @@ public abstract class PageView extends ViewGroup { return true; } + public void strikeOutSelection() { + final ArrayList lines = new ArrayList(); + TextSelector sel = new TextSelector(mText, mSelectBox) { + RectF rect; + + @Override + protected void onStartLine() { + rect = new RectF(); + } + + @Override + protected void onWord(TextWord word) { + rect.union(word); + } + + @Override + protected void onEndLine() { + if (!rect.isEmpty()) { + // These are vertical lines so we can specify + // both position and thickness with a RectF + float vcenter = rect.bottom - (rect.bottom - rect.top)*STRIKE_HEIGHT; + float thickness = (rect.bottom - rect.top)*LINE_THICKNESS; + rect.top = vcenter - thickness/2; + rect.bottom = vcenter + thickness/2; + lines.add(rect); + } + } + }; + + sel.select(); + + mAddStrikeOut = new AsyncTask() { + @Override + protected Void doInBackground(RectF[]... params) { + addStrikeOut(params[0]); + return null; + } + + @Override + protected void onPostExecute(Void result) { + update(); + } + }; + + mAddStrikeOut.execute(lines.toArray(new RectF[lines.size()])); + + mSelectBox = null; + mSearchView.invalidate(); + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int x, y; -- cgit v1.2.3