Java源码示例:com.artifex.mupdf.fitz.Matrix
示例1
public synchronized void drawPage(Bitmap bm, int pageNum,
int pageW, int pageH,
int patchX, int patchY,
int patchW, int patchH,
Cookie cookie) {
gotoPage(pageNum);
if (displayList == null)
displayList = page.toDisplayList(false);
float zoom = resolution / 72;
Matrix ctm = new Matrix(zoom, zoom);
RectI bbox = new RectI(page.getBounds().transform(ctm));
float xscale = (float)pageW / (float)(bbox.x1 - bbox.x0);
float yscale = (float)pageH / (float)(bbox.y1 - bbox.y0);
ctm.scale(xscale, yscale);
AndroidDrawDevice dev = new AndroidDrawDevice(bm, patchX, patchY);
displayList.run(dev, ctm, cookie);
dev.destroy();
}
示例2
public synchronized void drawPage(Bitmap bm, int pageNum, int pageW,
int pageH, int patchX, int patchY, int patchW, int patchH, Cookie cookie) {
gotoPage(pageNum);
if (displayList == null)
displayList = page.toDisplayList(false);
float zoom = resolution / 72;
Matrix ctm = new Matrix(zoom, zoom);
RectI bbox = new RectI(page.getBounds().transform(ctm));
float xscale = (float) pageW / (float) (bbox.x1 - bbox.x0);
float yscale = (float) pageH / (float) (bbox.y1 - bbox.y0);
ctm.scale(xscale, yscale);
AndroidDrawDevice dev = new AndroidDrawDevice(bm, patchX, patchY);
displayList.run(dev, ctm, cookie);
dev.destroy();
}
示例3
/**
* 渲染页面,传入一个Bitmap对象.使用硬件加速,虽然速度影响不大.
*
* @param bm 需要渲染的位图,配置为ARGB8888
* @param page 当前渲染页面页码
* @param pageW 页面的宽,由缩放级别计算得到的最后宽,由于这个宽诸页面的裁剪大小,如果不正确,得到的Tile页面是不正确的
* @param pageH 页面的宽,由缩放级别计算得到的最后宽,由于这个宽诸页面的裁剪大小,如果不正确,得到的Tile页面是不正确的
* @param patchX 裁剪的页面的左顶点
* @param patchY 裁剪的页面的上顶点
* @param patchW 页面的宽,具体渲染的页面实际大小.显示出来的大小.
* @param patchH 页面的高,具体渲染的页面实际大小.显示出来的大小.
*/
public synchronized void drawPage(Bitmap bm, int pageNum,
int pageW, int pageH,
int patchX, int patchY,
int patchW, int patchH,
Cookie cookie) {
gotoPage(pageNum);
if (displayList == null)
displayList = page.toDisplayList(false);
float zoom = resolution / 72;
Matrix ctm = new Matrix(zoom);
RectI bbox = new RectI(page.getBounds().transform(ctm));
float xscale = (float)pageW / (float)(bbox.x1-bbox.x0);
float yscale = (float)pageH / (float)(bbox.y1-bbox.y0);
ctm.scale(xscale, yscale);
AndroidDrawDevice dev = new AndroidDrawDevice(bm, patchX, patchY);
displayList.run(dev, ctm, cookie);
dev.destroy();
}
示例4
RenderTaskParams(RenderListener listener, Matrix ctm, Bitmap bitmap,
int pageX0, int pageY0, int pageX1, int pageY1,
int patchX0, int patchY0, int patchX1, int patchY1, boolean showAnnotations)
{
this.listener = listener;
this.ctm = ctm;
this.bitmap = bitmap;
this.pageX0 = pageX0;
this.pageY0 = pageY0;
this.pageX1 = pageX1;
this.pageY1 = pageY1;
this.patchX0 = patchX0;
this.patchY0 = patchY0;
this.patchX1 = patchX1;
this.patchY1 = patchY1;
this.showAnnotations = showAnnotations;
}
示例5
public static Bitmap drawPage(Page page, Matrix ctm) {
Rect fbox = page.getBounds().transform(ctm);
RectI ibox = new RectI((int)fbox.x0, (int)fbox.y0, (int)fbox.x1, (int)fbox.y1);
int w = ibox.x1 - ibox.x0;
int h = ibox.y1 - ibox.y0;
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
AndroidDrawDevice dev = new AndroidDrawDevice(bmp, ibox.x0, ibox.y0);
page.run(dev, ctm, null);
dev.close();
dev.destroy();
return bmp;
}
示例6
public static Matrix fitPage(Page page, int fitW, int fitH) {
Rect bbox = page.getBounds();
float pageW = bbox.x1 - bbox.x0;
float pageH = bbox.y1 - bbox.y0;
float scaleH = (float)fitW / pageW;
float scaleV = (float)fitH / pageH;
float scale = scaleH < scaleV ? scaleH : scaleV;
scaleH = (float)Math.floor(pageW * scale) / pageW;
scaleV = (float)Math.floor(pageH * scale) / pageH;
return new Matrix(scaleH, scaleV);
}
示例7
public static Matrix fitPageWidth(Page page, int fitW) {
Rect bbox = page.getBounds();
float pageW = bbox.x1 - bbox.x0;
float scale = (float)fitW / pageW;
scale = (float)Math.floor(pageW * scale) / pageW;
return new Matrix(scale);
}
示例8
public synchronized void drawPage(Bitmap bm, int pageNum,
int pageW, int pageH,
int patchX, int patchY,
int patchW, int patchH,
Cookie cookie) {
// if bitmap is recycle,just return , because some async task will drawpage after bitmap
if (bm != null && bm.isRecycled()) {
return;
}
gotoPage(pageNum);
if (displayList == null)
displayList = page.toDisplayList(false);
float zoom = resolution / 72;
Matrix ctm = new Matrix(zoom, zoom);
RectI bbox = new RectI(page.getBounds().transform(ctm));
float xscale = (float) pageW / (float) (bbox.x1 - bbox.x0);
float yscale = (float) pageH / (float) (bbox.y1 - bbox.y0);
ctm.scale(xscale, yscale);
if (bm != null && bm.isRecycled()) {
return;
}
AndroidDrawDevice dev = new AndroidDrawDevice(bm, patchX, patchY);
displayList.run(dev, ctm, cookie);
dev.destroy();
}
示例9
public static Bitmap drawPage(Page page, Matrix ctm) {
Rect fbox = page.getBounds().transform(ctm);
RectI ibox = new RectI((int)fbox.x0, (int)fbox.y0, (int)fbox.x1, (int)fbox.y1);
int w = ibox.x1 - ibox.x0;
int h = ibox.y1 - ibox.y0;
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
AndroidDrawDevice dev = new AndroidDrawDevice(bmp, ibox.x0, ibox.y0);
page.run(dev, ctm, null);
dev.close();
dev.destroy();
return bmp;
}
示例10
public static Matrix fitPage(Page page, int fitW, int fitH) {
Rect bbox = page.getBounds();
float pageW = bbox.x1 - bbox.x0;
float pageH = bbox.y1 - bbox.y0;
float scaleH = (float)fitW / pageW;
float scaleV = (float)fitH / pageH;
float scale = scaleH < scaleV ? scaleH : scaleV;
scaleH = (float)Math.floor(pageW * scale) / pageW;
scaleV = (float)Math.floor(pageH * scale) / pageH;
return new Matrix(scaleH, scaleV);
}
示例11
public static Matrix fitPageWidth(Page page, int fitW) {
Rect bbox = page.getBounds();
float pageW = bbox.x1 - bbox.x0;
float scale = (float)fitW / pageW;
scale = (float)Math.floor(pageW * scale) / pageW;
return new Matrix(scale);
}
示例12
public void setPage(int page, PointF pageSize, float zoom) {
mPageNumber = page;
boolean refresh = false;
if (mSize == null || mSize.x != pageSize.x || mSize.y != pageSize.y) {
refresh = true;
caculateSize(pageSize, zoom);
}
int xOrigin = (int) ((mSize.x - mViewSize.x) / 2);
Log.d("view", "view:" + mViewSize + " patchX:" + xOrigin + " mss:" + mSourceScale + " mSize:" + mSize + " zoom:" + zoom);
if (null == mBitmap) {
mBitmap = mBitmapManager.getBitmap(mPageNumber);
}
if (null != mBitmap) {
android.graphics.Matrix matrix = new android.graphics.Matrix();
matrix.postTranslate(-xOrigin, 0);
matrix.postScale(((float) mSize.x) / mBitmap.getWidth(), ((float) mSize.y) / mBitmap.getHeight());
mEntireView.setImageMatrix(matrix);
mEntireView.setImageBitmap(mBitmap);
if (!refresh) {
return;
}
}
if (mDrawTask != null) {
mDrawTask.cancel(true);
mDrawTask = null;
}
mDrawTask = getDrawPageTask(mSize.x, mSize.y, xOrigin, 0);
//mDrawTask.execute();
Util.execute(true, mDrawTask);
}
示例13
public static Bitmap drawPage(Page page, float dpi, int rotate) {
return drawPage(page, new Matrix(dpi / 72).rotate(rotate));
}
示例14
public static Bitmap drawPage(Page page, float dpi) {
return drawPage(page, new Matrix(dpi / 72));
}
示例15
public static Bitmap drawPage(Page page, float dpi, int rotate) {
return drawPage(page, new Matrix(dpi / 72).rotate(rotate));
}
示例16
public static Bitmap drawPage(Page page, float dpi) {
return drawPage(page, new Matrix(dpi / 72));
}
示例17
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
int[] locations = new int[2];
getLocationOnScreen(locations);
Rect pageRect = new Rect(locations[0], locations[1], locations[0] + getScaledWidth(), locations[1] + getScaledHeight());
// 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;
int pageY0 = pageRect.top;
int pageX1 = pageRect.right;
int pageY1 = pageRect.bottom;
int patchX0 = mPatchRect.left;
int patchY0 = mPatchRect.top;
int patchX1 = mPatchRect.right;
int patchY1 = mPatchRect.bottom;
// the patch should be a subset of the page. If not, bail.
// this happens when rotating the device.
if (patchX0>=pageX1 || patchX1<=pageX0 || patchY0>=pageY1 || patchY1<=pageY0)
{
listener.progress(0);
return;
}
// set up a matrix for scaling
Matrix ctm = Matrix.Identity();
ctm.scale((float) getFactor());
// remember the final values
mRenderSrcRect.set(mPatchRect);
mRenderDstRect.set(mDisplayRect);
mRenderScale = mScale;
mRenderBitmap = bitmap;
// Render the page in the background
RenderTaskParams params = new RenderTaskParams(new RenderListener()
{
@Override
public void progress(int error)
{
// specify where to draw to and from
mDrawBitmap = mRenderBitmap;
mDrawSrcRect.set(mRenderSrcRect);
mDrawDstRect.set(mRenderDstRect);
mDrawScale = mRenderScale;
listener.progress(0);
}
}, ctm, mRenderBitmap, pageX0, pageY0, pageX1, pageY1, patchX0, patchY0, patchX1, patchY1, showAnnotations);
new RenderTask().execute(params, null, null);
}