使用具有卷曲/翻转效果的 muPDF [英] Using muPDF with curl/flip effect

查看:20
本文介绍了使用具有卷曲/翻转效果的 muPDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 muPDF 在我的应用程序中阅读 PDF.我不喜欢它的默认动画(水平切换).在另一边,我发现 this 出色的图像卷曲效果库,以及 this 用于布局上的翻盖效果的项目.

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

私有类 PageProvider 实现 CurlView.PageProvider {//位图资源.私有 int[] mBitmapIds = { R.drawable.image1, R.drawable.image2,R.drawable.image3,R.drawable.image4};

并像这样使用它:

私有CurlView mCurlView;mCurlView = (CurlView) findViewById(R.id.curl);mCurlView.setPageProvider(new PageProvider());

CurlViewGLSurfaceView扩展而来,实现了View.OnTouchListener,CurlRenderer.Observer

但如果我没记错的话,在 muPDF 中,数据位于 core 对象中.coreMuPDFCore 的实例.并像这样使用它:

MuPDFReaderView mDocView;MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView();mDocView.setAdapter(new MuPDFPageAdapter(this, this, core));

MuPDFReaderView 扩展 ReaderViewReaderView 扩展 AdapterView 并实现 GestureDetector.OnGestureListener,ScaleGestureDetector.OnScaleGestureListener,可运行.

我的问题是如何在 muPDF 中使用卷曲效果?我应该在哪里一页一页地获取页面并将它们转换为位图?然后将 muPDF 中的 Adapter 的各个方面更改为 CurlView.

在翻盖示例项目中,在 FlipHorizo​​ntalLayoutActivity 中(我也喜欢这个效果),我们有这些:

private FlipViewController FlipView;flipView = new FlipViewController(this, FlipViewController.HORIZONTAL);flipView.setAdapter(new TravelAdapter(this));设置内容视图(翻转视图);

FlipViewController扩展AdapterViewTravelAdapter中的数据集扩展BaseAdapter.p>

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

我发现了另一个很好的具有卷曲效果的开源 PDF 阅读器,名为 fbreaderJ.它的开发者说一个允许在 FBReader 中打开 PDF 文件的附加模块.基于 radaee pdf 库."

我糊涂了!因为 radaeepdf 是封闭源代码并且 可下载项目仅用于演示,插入的用户名和密码用于此包.人们想要更改整个 fbreader 项目,例如包名.

另一个让我困惑的问题是这个附加模块源代码在哪里?!

不管怎样,如果有人想帮助我,fbreader 已经做得很好了.

我与开发 muPDF(或其中一位开发人员)的 Robin Watts 进行了交谈,他说:

<块引用>

你读过 platform/android/ClassStructure.txt 吗?MuPDF 是主要是一个 C 库.因此,标准 api 是 C 的.相当而不是将 API 完全按原样暴露给 Java(这将是最好的解决方案,我已经做了一些工作,但是有由于时间不够,没有完成),我们已经实现了 MuPDFCore总结我们需要的部分.MuPDFCore 处理打开 PDF 文件,并从中获取位图以在视图中使用.或者更确切地说,MuPDFCore返回视图",而不是位图".如果你需要位图,那你就去需要在 MuPDFCore 中进行更改.

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

请准确回答.

赏金已过期.

解决方案

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

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

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

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

这是你想知道的还是我没抓住重点?

编辑

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

/*** 构造一个新的 RenderTask 实例* @param context: 你需要 MuPdfCore 实例的上下文* @param pageNumber* @param pathToPdf* @param renderCallback: 回调设置位图到视图之后* 渲染* @param heightOfRenderedBitmap: 这是目标高度* @param widthOfRenderedBitmap: 这是目标宽度*/公共 RenderTask(上下文上下文,整数 pageNumber,字符串 pathToPdf,IRenderCallback,renderCallback, int heightOfRenderedBitmap,int widthOfRenderedBitmap) {//在字段中存储东西}

2.) + 3.) Renderqueue 将 RenderTask 包装在一个新线程中并启动它.所以会调用 RenderTask 的运行方法:

@Override公共无效运行(){//如果文件存在则不渲染如果(存在()==真){结束();返回;}位图位图 = 渲染();//如果出现问题,我们不能存储位图如果(位图==空){结束();返回;}//现在保存位图//在我的情况下,我将目标路径保存在字符串字段中imagePath = save(bitmap, new File("path/to/your/destination/folder/" + pageNumber + ".jpg"));bitmap.recycle();结束();}/*** 让我们触发回调*/私人无效完成(){if (renderCallback != null) {//我将整个 Rendertask 发送到回调//也许在你的情况下,发送 pageNumber 或路径就足够了//渲染位图renderCallback.finished(this);}}/*** 渲染位图* @返回*/私人位图渲染(){MuPDFCore核心=空;尝试 {core = new MuPDFCore(context, pathToPdf);} 捕捉(异常 e){返回空值;}位图 bm = Bitmap.createBitmap(widthOfRenderedBitmap, heightOfRenderedBitmap, Config.ARGB_8888);//在这里渲染整个 pdf,因为 patch-x/-y == 0core.drawPage(bm, 0, widthOfRenderedBitmap, heightOfRenderedBitmap, 0, 0, widthOfRenderedBitmap, heightOfRenderedBitmap, core.new Cookie());核心.onDestroy();核心=空;返回 bm;}/*** 将位图保存到文件系统* @param 位图* @param 图片* @返回*/私人字符串保存(位图位图,文件图像){FileOutputStream out = null;尝试 {out = new FileOutputStream(image.getAbsolutePath());bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out);返回 image.getAbsolutePath();} 捕捉(异常 e){返回空值;}最后 {尝试 {如果(出!= null){out.close();}} 捕捉(可抛出的忽略){}}}

}

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

I'm using muPDF for reading PDFs in my application. I don't like its default animation (Switching horizontally). In other side i found this brilliant library for curl effect on images, and this project for flip-flap effect on layouts.

In curl sample project, in CurlActivity, all of data are images and set in PageProvider like this:

private class PageProvider implements CurlView.PageProvider {

    // Bitmap resources.
    private int[] mBitmapIds = { R.drawable.image1, R.drawable.image2,
            R.drawable.image3, R.drawable.image4};

And use it like this:

private CurlView mCurlView;
mCurlView = (CurlView) findViewById(R.id.curl);
mCurlView.setPageProvider(new PageProvider());

And CurlView extends from GLSurfaceView and implements View.OnTouchListener, CurlRenderer.Observer

But in muPDF if i'm not mistaken, data are in core object. core is instance of MuPDFCore. And using it like this:

MuPDFReaderView mDocView;
MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView();
mDocView.setAdapter(new MuPDFPageAdapter(this, this, core));

MuPDFReaderView extends ReaderView and ReaderView extends AdapterView<Adapter> and implements GestureDetector.OnGestureListener, ScaleGestureDetector.OnScaleGestureListener, Runnable.

My question is where how can I using curl effect in muPDF? Where should I get pages one by one and converting them to bitmaps? and then changing aspects of the Adapter in muPDF to CurlView.

In flip-flap sample project, in FlipHorizontalLayoutActivity (I like this effect too), we have these:

private FlipViewController flipView;
flipView = new FlipViewController(this, FlipViewController.HORIZONTAL);
flipView.setAdapter(new TravelAdapter(this));
setContentView(flipView);

And FlipViewController extends AdapterView<Adapter>, and data set in TravelAdapter that extends BaseAdapter.

No one has done this before? Or can help me to do that?!

EDIT:

I found another good open source PDF reader with curl effect called fbreaderJ. its developer says "An additional module that allows to open PDF files in FBReader. Based on radaee pdf library."

I got confused! cause radaeepdf is closed source and downloadable project is just for demo and inserted username and password is for this package. People want to change whole fbreader project such as package name.

Another issue for make me confused is where is this additional module source code?!

Anyway, if someone wants to help me, fbreader has done it very well.

EDIT:

I talked to Robin Watts, who developed muPDF (or one of developers), and he said:

Have you read platform/android/ClassStructure.txt ? MuPDF is primarily a C library. The standard api is therefore a C one. Rather than exposing that api exactly as is to Java (which would be the nicest solution, and something that I've done some work on, but have not completed due to lack of time), we've implemented MuPDFCore to wrap up just the bits we needed. MuPDFCore handles opening a PDF file, and getting bitmaps from it to be used in views. or rather, MuPDFCore returns 'views', not 'bitmaps'. If you need bitmaps, then you're going to need to make changes in MuPDFCore.

There are too many errors when changing a little part of MuPDFReaderView class. I get confused! These are related to each other.

Please answer more precisely.

EDIT:

And bounty has expired.

解决方案

Where should i get pages one by one and converting them to bitmaps?

In our application (newspaper app) we use MuPDF to render PDFs. The workflow goes like this:

  1. Download PDF file (we have one PDF per newspaper page)
  2. Render it with MuPDF
  3. Save the bitmap to the filesystem
  4. Load the Bitmap from filesystem as background image to a view

So, finally, what we use is MuPDFCore.java and its methods drawPage(...) and onDestroy()

Is this what you want to know or do i miss the point?

EDIT

1.) I think it is not necessary to post code how to download a file. But after downloading i add a RenderTask (extends from Runnable) to a Renderqueue and trigger that queue. The RenderTask needs some information for rendering:

/**
 * 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
}

2.) + 3.) The Renderqueue wraps the RenderTask in a new Thread and starts it. So the run-method of the RenderTask will be invoked:

@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) {}

    }
}  

}

4.) I think it is not necessary to post code how to set a bitmap as background of a view

这篇关于使用具有卷曲/翻转效果的 muPDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆