使用muPDF卷曲/翻转效果

Dr.*_*cky 11 android opengl-es flip page-curl mupdf

我正在使用muPDF在我的应用程序中阅读PDF.我不喜欢它的默认动画(水平切换).在另一方面,我发现这个辉煌的库对图像的卷曲效果,这个项目的翻转翻盖效果布局.

在curl示例项目中CurlActivity,所有数据都是图像并设置PageProvider如下:

private class PageProvider implements CurlView.PageProvider {

    // Bitmap resources.
    private int[] mBitmapIds = { R.drawable.image1, R.drawable.image2,
            R.drawable.image3, R.drawable.image4};
Run Code Online (Sandbox Code Playgroud)

并像这样使用它:

private CurlView mCurlView;
mCurlView = (CurlView) findViewById(R.id.curl);
mCurlView.setPageProvider(new PageProvider());
Run Code Online (Sandbox Code Playgroud)

CurlView从中扩展GLSurfaceView并实现View.OnTouchListener, CurlRenderer.Observer

但是在muPDF中,如果我没有弄错的话,数据就是core对象.core是的例子MuPDFCore.并使用它像这样:

MuPDFReaderView mDocView;
MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView();
mDocView.setAdapter(new MuPDFPageAdapter(this, this, core));
Run Code Online (Sandbox Code Playgroud)

MuPDFReaderView扩展ReaderView,ReaderView扩展AdapterView<Adapter>和实现GestureDetector.OnGestureListener, ScaleGestureDetector.OnScaleGestureListener, Runnable.

我的问题是如何在muPDF中使用curl效果?我应该在哪里逐页获取页面并将其转换为位图?然后将muPDF中适配器的各个方面更改为CurlView.

在翻盖式样本项目中,FlipHorizontalLayoutActivity(我也喜欢这个效果),我们有这些:

private FlipViewController flipView;
flipView = new FlipViewController(this, FlipViewController.HORIZONTAL);
flipView.setAdapter(new TravelAdapter(this));
setContentView(flipView);
Run Code Online (Sandbox Code Playgroud)

FlipViewController扩展AdapterView<Adapter>,并在TravelAdapter其中扩展数据集BaseAdapter.

以前没有人这样做过吗?或者可以帮我做那个?!

编辑:

我找到了另一个带有卷曲效果的开源PDF阅读器,名为fbreaderJ.它的开发人员说:" 一个允许在FBReader中打开PDF文件的附加模块.基于radaee pdf库. "

我很困惑!因为radaeepdf是闭源的,可下载的项目仅用于演示,插入的用户名和密码用于此包.人们想要改变整个fbreader项目,如包名.

令我困惑的另一个问题是这个额外的模块源代码在哪里?!

无论如何,如果有人想帮助我,fbreader已经做得很好.

编辑:

我与开发muPDF(或其中一个开发人员)的Robin Watts谈过,他说:

你读过platform/android/ClassStructure.txt吗?MuPDF主要是C库.因此标准API是C语言.而不是像Java一样公开api(这将是最好的解决方案,以及我已经完成的一些工作,但由于时间不够而没有完成),我们已经实现了MuPDFCore来包装我们需要的位.MuPDFCore处理打开PDF文件,并从中获取位图以在视图中使用.或者更确切地说,MuPDFCore返回'views',而不是'bitmaps'.如果您需要位图,那么您将需要在MuPDFCore中进行更改.

更改MuPDFReaderView类的一小部分时有太多错误.我有点迷惑不解了!这些是彼此相关的.

请更准确地回答.

编辑:

赏金已经过期了.

A.D*_*.D. 1

我应该在哪里一页一页地获取页面并将它们转换为位图?

在我们的应用程序(报纸应用程序)中,我们使用 MuPDF 来渲染 PDF。工作流程如下:

  1. 下载 PDF 文件(我们每个报纸页面都有一个 PDF 文件)
  2. 使用 MuPDF 渲染它
  3. 将位图保存到文件系统
  4. 将位图从文件系统作为背景图像加载到视图中

所以,最后,我们使用的是 MuPDFCore.java 及其方法 drawPage(...) 和 onDestroy()

这是你想知道的还是我错过了重点?

编辑

1.)我认为没有必要发布如何下载文件的代码。但下载后,我将 RenderTask(从 Runnable 扩展)添加到 Renderqueue 并触发该队列。RenderTask 需要一些渲染信息:

/**
 * constructs a new RenderTask instance
 * @param context: you need Context for MuPdfCore instance
 * @param pageNumber
 * @param pathToPdf 
 * @param renderCallback: callback to set bitmap to the view after    
 * rendering
 * @param heightOfRenderedBitmap: this is the target height
 * @param widthOfRenderedBitmap: this is the target width
 */
public RenderTask (Context context, Integer pageNumber, String pathToPdf, IRenderCallback,    
                   renderCallback, int heightOfRenderedBitmap, 
                   int widthOfRenderedBitmap) {

    //store things in fields
}
Run Code Online (Sandbox Code Playgroud)

2.) + 3.) Renderqueue 将 RenderTask 包装在一个新线程中并启动它。因此 RenderTask 的 run-方法将被调用:

@Override
public void run () {

    //do not render it if file exists
    if (exists () == true) {

        finish();
        return;
    }


    Bitmap bitmap = render();

    //if something went wrong, we can't store the bitmap
    if (bitmap == null) {

        finish();
        return;
    }

    //now save the bitmap
    // in my case i save the destination path in a String field
    imagePath = save(bitmap, new File("path/to/your/destination/folder/" + pageNumber + ".jpg"));

    bitmap.recycle();
    finish();
}

/**
 * let's trigger the callback
 */
private void finish () {

    if (renderCallback != null) {

        // i send the whole Rendertask to callback
        // maybe in your case it is enough to send the pageNumber or path to    
        // renderend bitmap   
        renderCallback.finished(this); 
    }

}

/**
 * renders a bitmap
 * @return
 */
private Bitmap render() {

    MuPDFCore core = null;
    try {
        core = new MuPDFCore(context, pathToPdf);
    } catch (Exception e) {

        return null;
    }

    Bitmap bm = Bitmap.createBitmap(widthOfRenderedBitmap, heightOfRenderedBitmap, Config.ARGB_8888);
    // here you render the WHOLE pdf cause patch-x/-y == 0
    core.drawPage(bm, 0, widthOfRenderedBitmap, heightOfRenderedBitmap, 0, 0, widthOfRenderedBitmap, heightOfRenderedBitmap, core.new Cookie());
    core.onDestroy();
    core = null;
    return bm;
}

/**
 * saves bitmap to filesystem
 * @param bitmap
 * @param image
 * @return
 */
private String save(Bitmap bitmap, File image) {

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(image.getAbsolutePath());
        bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out);
        return image.getAbsolutePath();

    } catch (Exception e) {

        return null;
    }

    finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch(Throwable ignore) {}

    }
}  
Run Code Online (Sandbox Code Playgroud)

}

4.)我认为没有必要发布如何将位图设置为视图背景的代码