diff options
author | fred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local> | 2016-07-14 17:17:36 -0700 |
---|---|---|
committer | fred ross-perry <fred.ross-perry@artifex.com> | 2016-07-15 10:09:03 -0700 |
commit | 1d847853c9608e52515d5dabb1943d10b29bab91 (patch) | |
tree | a746541af53c1d58c81c29bcf633995da07d4d3e /platform | |
parent | 599f15e3364602f5b2287a81b84037ed8c56250f (diff) | |
download | mupdf-1d847853c9608e52515d5dabb1943d10b29bab91.tar.xz |
android example: An attempt to improve the fluttering at the edges while zooming and scrolling.
Diffstat (limited to 'platform')
-rwxr-xr-x | platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java | 67 | ||||
-rwxr-xr-x | platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocView.java | 22 |
2 files changed, 62 insertions, 27 deletions
diff --git a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java index 52962bb5..8a8d3f6f 100755 --- a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java +++ b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java @@ -37,12 +37,14 @@ public class DocPageView extends View implements Callback private final Rect mRenderSrcRect = new Rect(); private final Rect mRenderDstRect = new Rect(); private float mRenderScale; + private Rect mPatchRect = new Rect(); // drawing private Bitmap mDrawBitmap = null; private final Rect mDrawSrcRect = new Rect(); private final Rect mDrawDstRect = new Rect(); private float mDrawScale; + private Rect mDisplayRect = new Rect(); private final Paint mPainter; private final Rect mSrcRect = new Rect(); @@ -59,6 +61,9 @@ public class DocPageView extends View implements Callback private static final float mResolution = 160f; + public static int bitmapMarginX = 0; + public static int bitmapMarginY = 0; + public DocPageView(Context context, Document theDoc) { super(context); @@ -186,26 +191,51 @@ public class DocPageView extends View implements Callback // do the render. if (DEBUG_PAGE_RENDERING) renderNoPage(bitmap, listener, localVisRect, globalVisRect); - else + else { + cachePage(); renderPage(bitmap, listener, localVisRect, globalVisRect, showAnnotations); + } } // This function renders the document's page. private void renderPage(final Bitmap bitmap, final RenderListener listener, final Rect localVisRect, final Rect globalVisRect, final boolean showAnnotations) { - // make a rect representing the entire page - // This might be outside the bounds of the bitmap + // make a rect representing the entire page; this might be outside the bounds of the bitmap int[] locations = new int[2]; getLocationOnScreen(locations); Rect pageRect = new Rect(locations[0], locations[1], locations[0] + getCalculatedWidth(), locations[1] + getCalculatedHeight()); - // make a rect representing the patch - // clip this to the bitmap - Rect patchRect = new Rect(pageRect); - patchRect.left = Math.max(patchRect.left, 0); - patchRect.top = Math.max(patchRect.top, 0); - patchRect.right = Math.min(patchRect.right, bitmap.getWidth()); - patchRect.bottom = Math.min(patchRect.bottom, bitmap.getHeight()); + // Set rects for rendering and display + mPatchRect.set(globalVisRect); + mDisplayRect.set(localVisRect); + + // enlarge rendering and display rects to account for available margins + int topMargin = Math.min(Math.max(globalVisRect.top -pageRect.top,0), bitmapMarginY); + int bottomMargin = Math.min(Math.max(pageRect.bottom -globalVisRect.bottom,0),bitmapMarginY); + int leftMargin = Math.min(Math.max(globalVisRect.left-pageRect.left,0), bitmapMarginX); + int rightMargin = Math.min(Math.max(pageRect.right -globalVisRect.right,0), bitmapMarginX); + + mPatchRect.top -= topMargin; + mDisplayRect.top -= topMargin; + mPatchRect.bottom += bottomMargin; + mDisplayRect.bottom += bottomMargin; + + mPatchRect.left -= leftMargin; + mDisplayRect.left -= leftMargin; + mPatchRect.right += rightMargin; + mDisplayRect.right += rightMargin; + + // ... but clip to the bitmap + Rect oldPatch = new Rect(mPatchRect); + mPatchRect.left = Math.max(mPatchRect.left, 0); + mPatchRect.top = Math.max(mPatchRect.top, 0); + mPatchRect.right = Math.min(mPatchRect.right, bitmap.getWidth()); + mPatchRect.bottom = Math.min(mPatchRect.bottom, bitmap.getHeight()); + + mDisplayRect.left += (mPatchRect.left-oldPatch.left); + mDisplayRect.top += (mPatchRect.top-oldPatch.top); + mDisplayRect.right -= (mPatchRect.right-oldPatch.right); + mDisplayRect.bottom -= (mPatchRect.bottom-oldPatch.bottom); // set up the page and patch coordinates for the device int pageX0 = pageRect.left; @@ -213,23 +243,21 @@ public class DocPageView extends View implements Callback int pageX1 = pageRect.right; int pageY1 = pageRect.bottom; - int patchX0 = patchRect.left; - int patchY0 = patchRect.top; - int patchX1 = patchRect.right; - int patchY1 = patchRect.bottom; + int patchX0 = mPatchRect.left; + int patchY0 = mPatchRect.top; + int patchX1 = mPatchRect.right; + int patchY1 = mPatchRect.bottom; // set up a matrix for scaling Matrix ctm = Matrix.Identity(); ctm.scale(mScale * mZoom * mResolution / 72f); - mRenderSrcRect.set(globalVisRect); - mRenderDstRect.set(localVisRect); + // remember the final values + mRenderSrcRect.set(mPatchRect); + mRenderDstRect.set(mDisplayRect); mRenderScale = mScale; mRenderBitmap = bitmap; - // cache this page's display and annotation lists - cachePage(); - // Render the page in the background RenderTaskParams params = new RenderTaskParams(new RenderListener() { @Override @@ -240,7 +268,6 @@ public class DocPageView extends View implements Callback mDrawDstRect.set(mRenderDstRect); mDrawScale = mRenderScale; - invalidate(); listener.progress(0); } diff --git a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocView.java b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocView.java index 9d2f1fd9..5e529ed4 100755 --- a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocView.java +++ b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocView.java @@ -45,7 +45,7 @@ public class DocView // bitmaps for rendering // these are created by the activity and set using setBitmaps() - private final static double OVERSIZE_FACTOR = 1.1; + private final static double OVERSIZE_FACTOR = 1.3; private final Bitmap[] bitmaps = {null,null}; private int bitmapIndex = 0; @@ -117,6 +117,8 @@ public class DocView mScroller = new Scroller(context); mStepper = new Stepper(this, this); + this.setClipChildren(false); + // create bitmaps makeBitmaps(); } @@ -139,6 +141,9 @@ public class DocView int size = Math.max(w,h); for (int i=0;i<bitmaps.length;i++) bitmaps[i] = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); + + DocPageView.bitmapMarginX = (w-screenW)/2; + DocPageView.bitmapMarginY = (h-screenH)/2; } public void start(final String path) @@ -384,12 +389,15 @@ public class DocView scaleChildren(); // maintain focus while scaling - float currentFocusX = detector.getFocusX(); - float currentFocusY = detector.getFocusY(); - int viewFocusX = (int)currentFocusX + getScrollX(); - int viewFocusY = (int)currentFocusY + getScrollY(); - mXScroll += viewFocusX - viewFocusX * detector.getScaleFactor(); - mYScroll += viewFocusY - viewFocusY * detector.getScaleFactor(); + double scale = mScale/previousScale; + double currentFocusX = detector.getFocusX(); + double currentFocusY = detector.getFocusY(); + double viewFocusX = (int)currentFocusX + getScrollX(); + double viewFocusY = (int)currentFocusY + getScrollY(); + int diffX = (int)(viewFocusX * (1-scale)); + int diffY = (int)(viewFocusY * (1-scale)); + mXScroll += diffX; + mYScroll += diffY; requestLayout(); |