diff options
author | Paul Gardiner <paulg.artifex@glidos.net> | 2013-01-29 14:53:35 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-01-31 11:17:40 +0000 |
commit | cea4109277d5e558f4cfa0707aee7e371ed06504 (patch) | |
tree | fa33497f5666cdf196f523fc412739ac63b2e04c /android/src | |
parent | aeed1e16e440cefbf5137eef7f4af608b0c70569 (diff) | |
download | mupdf-cea4109277d5e558f4cfa0707aee7e371ed06504.tar.xz |
Android: implement strikeout annotation creation
Diffstat (limited to 'android/src')
4 files changed, 77 insertions, 0 deletions
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 @@ -223,6 +223,11 @@ public class MuPDFPageView extends PageView { } @Override + protected void addStrikeOut(RectF[] lines) { + mCore.addStrikeOutAnnotation(mPageNumber, lines); + } + + @Override public void setPage(final int page, PointF size) { mLoadWidgetAreas = new AsyncTask<Void,Void,RectF[]> () { @Override 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<Void,Void,TextWord[][]> mGetText; + private AsyncTask<RectF[],Void,Void> mAddStrikeOut; private AsyncTask<Void,Void,LinkInfo[]> mGetLinkInfo; private AsyncTask<Void,Void,Bitmap> 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<RectF> lines = new ArrayList<RectF>(); + 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<RectF[],Void,Void>() { + @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; |