mupdf源码分析(三)加载文档之详细流程

pdf文档的加载流程由pdfapp_open----》pdfapp_open_progressive接口实现,原型:void pdfapp_open_progressive(pdfapp_t *app, char *filename, int reload, int kbps);

接下来具体分析一下这个函数的实现流程。

 

1,注册处理程序为支持的所有标准文档类型 fz_register_document_handlers(ctx);//支持pdf,xps,svg,cbz,img,fb2,html,xhtml

2,设置是否切换到html和epub对应的文档样式 fz_set_use_document_css(ctx, app->layout_use_doc_css);//use_document_css = layout_use_doc_css

3,打开文档,加载基本结构 fz_open_accelerated_document(ctx, filename, accel);

3.1)获取匹配的文档处理程序句柄 ,句柄初始化见附录一 。handler = fz_recognize_document(ctx, filename);

3.2)打开文档,加载文档对象 handler->open(ctx, filename);//进入pdf_open_document

    3.2.1)根据文件名获取文件流对象,打开文件,设置文件流操作回调函数  file = fz_open_file(ctx, filename);

    3.2.2)创建pdf doc对象,赋值doc信息 详细见附录二。doc = pdf_new_document(ctx, file);

    3.2.3)文档初始化并加载交叉引用表 pdf_init_document(ctx, doc);

4,fz_document 对象转成 pdf_document对象 idoc = pdf_specifics(app->ctx, app->doc);

5,判断文档是否加密 fz_needs_password(app->ctx, app->doc),需要的话密钥认证 fz_authenticate_password(app->ctx, app->doc, password);

6,设置应用的布局 fz_layout_document(app->ctx, app->doc, app->layout_w, app->layout_h, app->layout_em);

7,获取文档页数 app->pagecount = fz_count_pages(app->ctx, app->doc);

8,加载文档大纲 app->outline = fz_load_outline(app->ctx, app->doc);

9,渲染页面 pdfapp_showpage(app, 1, 1, 1, 0, 0);

附录一:

fz_document_handler pdf_document_handler =
{
    NULL,
    (fz_document_open_fn*)pdf_open_document,
    (fz_document_open_with_stream_fn*)pdf_open_document_with_stream,
    pdf_extensions,
    pdf_mimetypes,
    NULL,
    NULL
};

附录二:

pdf_new_document(fz_context *ctx, fz_stream *file)
{
    pdf_document *doc = fz_new_derived_document(ctx, pdf_document);
    //超类 函数指针设置fz_document
    doc->super.drop_document = (fz_document_drop_fn*)pdf_drop_document_imp;//doc销毁
    doc->super.get_output_intent = (fz_document_output_intent_fn*)pdf_document_output_intent;//输出意图颜色空间
    doc->super.needs_password = (fz_document_needs_password_fn*)pdf_needs_password;//加密文件处理函数
    doc->super.authenticate_password = (fz_document_authenticate_password_fn*)pdf_authenticate_password;//密钥认证函数
    doc->super.has_permission = (fz_document_has_permission_fn*)pdf_has_permission;//文档权限查询,打印,拷贝,编辑,注释
    doc->super.load_outline = (fz_document_load_outline_fn*)pdf_load_outline;//加载文档大纲函数
    doc->super.resolve_link = pdf_resolve_link_imp;//章节导航函数,快速定位至具体页位置
    doc->super.count_pages = pdf_count_pages_imp;//获取文档页数
    doc->super.load_page = pdf_load_page_imp;//加载指定页资源
    doc->super.lookup_metadata = (fz_document_lookup_metadata_fn*)pdf_lookup_metadata;//查看元数据
    //基本对象解析结构初始化
    pdf_lexbuf_init(ctx, &doc->lexbuf.base, PDF_LEXBUF_LARGE);
    doc->file = fz_keep_stream(ctx, file);//文件流对象拷贝

    return doc;
}

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值