Model::Document* DjVuPlugin::loadDocument(const QString& filePath) const { ddjvu_context_t* context = ddjvu_context_create("qpdfview"); ddjvu_document_t* document = ddjvu_document_create_by_filename(context, QFile::encodeName(filePath), FALSE); if(document == 0) { ddjvu_context_release(context); return 0; } waitForMessageTag(context, DDJVU_DOCINFO); if(ddjvu_document_decoding_error(document)) { ddjvu_document_release(document); ddjvu_context_release(context); return 0; } return new Model::DjVuDocument(context, document); }
zathura_error_t djvu_document_open(zathura_document_t* document) { zathura_error_t error = ZATHURA_ERROR_OK; if (document == NULL) { error = ZATHURA_ERROR_INVALID_ARGUMENTS; goto error_out; } djvu_document_t* djvu_document = calloc(1, sizeof(djvu_document_t)); if (djvu_document == NULL) { error = ZATHURA_ERROR_OUT_OF_MEMORY; goto error_out; } /* setup format */ static unsigned int masks[4] = {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}; djvu_document->format = ddjvu_format_create(DDJVU_FORMAT_RGBMASK32, 4, masks); if (djvu_document->format == NULL) { error = ZATHURA_ERROR_UNKNOWN; goto error_free; } ddjvu_format_set_row_order(djvu_document->format, TRUE); /* setup context */ djvu_document->context = ddjvu_context_create("zathura"); if (djvu_document->context == NULL) { error = ZATHURA_ERROR_UNKNOWN; goto error_free; } /* setup document */ djvu_document->document = ddjvu_document_create_by_filename( djvu_document->context, zathura_document_get_path(document), FALSE ); if (djvu_document->document == NULL) { error = ZATHURA_ERROR_UNKNOWN; goto error_free; } /* load document info */ ddjvu_message_t* msg; ddjvu_message_wait(djvu_document->context); while ((msg = ddjvu_message_peek(djvu_document->context)) && (msg->m_any.tag != DDJVU_DOCINFO)) { if (msg->m_any.tag == DDJVU_ERROR) { error = ZATHURA_ERROR_UNKNOWN; goto error_free; } ddjvu_message_pop(djvu_document->context); } /* decoding error */ if (ddjvu_document_decoding_error(djvu_document->document)) { handle_messages(djvu_document, true); error = ZATHURA_ERROR_UNKNOWN; goto error_free; } zathura_document_set_data(document, djvu_document); zathura_document_set_number_of_pages(document, ddjvu_document_get_pagenum(djvu_document->document)); return error; error_free: if (djvu_document->format != NULL) { ddjvu_format_release(djvu_document->format); } if (djvu_document->context != NULL) { ddjvu_context_release(djvu_document->context); } free(djvu_document); error_out: return error; }