Blame libdjvu/ddjvuapi.h

Packit df99a1
/* 
Packit df99a1
//C- -------------------------------------------------------------------
Packit df99a1
//C- DjVuLibre-3.5
Packit df99a1
//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
Packit df99a1
//C- Copyright (c) 2001  AT&T
Packit df99a1
//C-
Packit df99a1
//C- This software is subject to, and may be distributed under, the
Packit df99a1
//C- GNU General Public License, either Version 2 of the license,
Packit df99a1
//C- or (at your option) any later version. The license should have
Packit df99a1
//C- accompanied the software or you may obtain a copy of the license
Packit df99a1
//C- from the Free Software Foundation at http://www.fsf.org .
Packit df99a1
//C-
Packit df99a1
//C- This program is distributed in the hope that it will be useful,
Packit df99a1
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit df99a1
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit df99a1
//C- GNU General Public License for more details.
Packit df99a1
//C- 
Packit df99a1
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
Packit df99a1
//C- Lizardtech Software.  Lizardtech Software has authorized us to
Packit df99a1
//C- replace the original DjVu(r) Reference Library notice by the following
Packit df99a1
//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
Packit df99a1
//C-
Packit df99a1
//C-  ------------------------------------------------------------------
Packit df99a1
//C- | DjVu (r) Reference Library (v. 3.5)
Packit df99a1
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
Packit df99a1
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
Packit df99a1
//C- | 6,058,214 and patents pending.
Packit df99a1
//C- |
Packit df99a1
//C- | This software is subject to, and may be distributed under, the
Packit df99a1
//C- | GNU General Public License, either Version 2 of the license,
Packit df99a1
//C- | or (at your option) any later version. The license should have
Packit df99a1
//C- | accompanied the software or you may obtain a copy of the license
Packit df99a1
//C- | from the Free Software Foundation at http://www.fsf.org .
Packit df99a1
//C- |
Packit df99a1
//C- | The computer code originally released by LizardTech under this
Packit df99a1
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
Packit df99a1
//C- | ORIGINAL CODE."  Subject to any third party intellectual property
Packit df99a1
//C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
Packit df99a1
//C- | non-exclusive license to make, use, sell, or otherwise dispose of 
Packit df99a1
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
Packit df99a1
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
Packit df99a1
//C- | General Public License.   This grant only confers the right to 
Packit df99a1
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
Packit df99a1
//C- | the extent such infringement is reasonably necessary to enable 
Packit df99a1
//C- | recipient to make, have made, practice, sell, or otherwise dispose 
Packit df99a1
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
Packit df99a1
//C- | any greater extent that may be necessary to utilize further 
Packit df99a1
//C- | modifications or combinations.
Packit df99a1
//C- |
Packit df99a1
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
Packit df99a1
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
Packit df99a1
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
Packit df99a1
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
Packit df99a1
//C- +------------------------------------------------------------------
Packit df99a1
*/
Packit df99a1
Packit df99a1
#ifndef DDJVUAPI_H
Packit df99a1
#define DDJVUAPI_H
Packit df99a1
Packit df99a1
#ifdef __cplusplus
Packit df99a1
extern "C" { 
Packit df99a1
#endif
Packit df99a1
#if 0
Packit df99a1
}
Packit df99a1
#endif
Packit df99a1
Packit df99a1
#include <stddef.h>
Packit df99a1
#include <stdlib.h>
Packit df99a1
#include <stdio.h>
Packit df99a1
Packit df99a1
#ifndef DDJVUAPI
Packit df99a1
# ifdef _WIN32
Packit df99a1
#  ifdef DDJVUAPI_EXPORT
Packit df99a1
#   define DDJVUAPI __declspec(dllexport)
Packit df99a1
#  else
Packit df99a1
#   define DDJVUAPI __declspec(dllimport)
Packit df99a1
#  endif
Packit df99a1
# endif
Packit df99a1
#endif
Packit df99a1
#ifndef DDJVUAPI
Packit df99a1
# define DDJVUAPI /**/
Packit df99a1
#endif
Packit df99a1
Packit df99a1
#ifndef TRUE
Packit df99a1
# define TRUE  (1)
Packit df99a1
#endif
Packit df99a1
Packit df99a1
#ifndef FALSE
Packit df99a1
# define FALSE (0)
Packit df99a1
#endif
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* DDJVU API                                          */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
/* The DDJVU API provides for efficiently decoding and
Packit df99a1
   displaying DjVu documents.  It provides for displaying
Packit df99a1
   images without waiting for the complete DjVu data. Images
Packit df99a1
   can be displayed as soon as sufficient data is
Packit df99a1
   available. A higher quality image might later be
Packit df99a1
   displayed when further data is available.  The DjVu
Packit df99a1
   library achieves this using a complicated scheme
Packit df99a1
   involving multiple threads. The DDJVU API hides this
Packit df99a1
   complexity with a familiar event model.
Packit df99a1
*/
Packit df99a1
Packit df99a1
/* Compiler symbol DDJVUAPI_VERSION tracks 
Packit df99a1
   backward compatible additions to the DDJVU API.
Packit df99a1
Packit df99a1
   Version   Change
Packit df99a1
   -----------------------------
Packit df99a1
     23    Added:
Packit df99a1
              miniexp_mutate()
Packit df99a1
     22    Changed
Packit df99a1
              miniexp strings accept unicode escapes
Packit df99a1
              deprecated miniexp_io_t::p_print7bits
Packit df99a1
              added miniexp_io_t::p_flags
Packit df99a1
     21    Added:
Packit df99a1
              reentrant version of miniexp input/output
Packit df99a1
     20    Added:
Packit df99a1
              ddjvu_get_version_string()
Packit df99a1
              ddjvu_format_set_white()
Packit df99a1
              ddjvu_anno_get_xmp()
Packit df99a1
     19    Added:
Packit df99a1
              ddjvu_document_create_by_filename_utf8()
Packit df99a1
     18    Added:
Packit df99a1
              ddjvu_document_get_{anno,pagedump,filedump}()
Packit df99a1
           Modifed (binary compatible):
Packit df99a1
              ddjvu_document_get_{fileinfo,pageinfo}()   
Packit df99a1
              ddjvu_document_save() [--pages, --indirect=]
Packit df99a1
           Deprecated:
Packit df99a1
              ddjvu_document_search_pageno()
Packit df99a1
              ddjvu_page_get_{short,long}_description()
Packit df99a1
     17    Added:
Packit df99a1
              ddjvu_page_get_initial_rotation(), ddjvu_code_get_version()
Packit df99a1
              ddjvu_document_{get_filenum,get_fileinfo}}()
Packit df99a1
              ddjvu_document_{search_pageno,check_pagedata}()
Packit df99a1
              ddjvu_rectmapper_t and related functions.
Packit df99a1
     16    Added:
Packit df99a1
              miniexp.h and related functions.
Packit df99a1
     15    Added:
Packit df99a1
              ddjvu_document_get_pageinfo()
Packit df99a1
              ddjvu_document_print()
Packit df99a1
     14    Initial version.
Packit df99a1
*/
Packit df99a1
Packit df99a1
#define DDJVUAPI_VERSION 23
Packit df99a1
Packit df99a1
typedef struct ddjvu_context_s    ddjvu_context_t;
Packit df99a1
typedef union  ddjvu_message_s    ddjvu_message_t;
Packit df99a1
typedef struct ddjvu_job_s        ddjvu_job_t;
Packit df99a1
typedef struct ddjvu_document_s   ddjvu_document_t;
Packit df99a1
typedef struct ddjvu_page_s       ddjvu_page_t;
Packit df99a1
typedef struct ddjvu_format_s     ddjvu_format_t;
Packit df99a1
typedef struct ddjvu_rect_s       ddjvu_rect_t;
Packit df99a1
typedef struct ddjvu_rectmapper_s ddjvu_rectmapper_t;
Packit df99a1
Packit df99a1
Packit df99a1
/* GENERAL CONVENTIONS:
Packit df99a1
Packit df99a1
   - all strings use locale encoding (unless specified otherwise).
Packit df99a1
   - all filenames are unencoded byte strings,
Packit df99a1
   - all errors are signaled with error event messages,
Packit df99a1
   - all functions returning a pointer might return a null pointer.
Packit df99a1
Packit df99a1
   HEADER:
Packit df99a1
   Always use the following idiom to include this file.
Packit df99a1
Packit df99a1
     #include <libdjvu/ddjvuapi.h>
Packit df99a1
     #include <libdjvu/miniexp.h>
Packit df99a1
Packit df99a1
   This file does not declare functions ddjvu_get_DjVuImage() 
Packit df99a1
   and djvu_get_DjVuDocument() unless you include files 
Packit df99a1
   "DjVuImage.h" and "DjVuDocument.h" before this file.
Packit df99a1
Packit df99a1
   PREREQUISITES:
Packit df99a1
   - Please read the djvu man page: <"tools/djvu.1">.
Packit df99a1
   - Please browse the file format specifications 
Packit df99a1
     <"doc/djvu3changes.txt"> and <"doc/djvu3spec.djvu">.
Packit df99a1
*/
Packit df99a1
Packit df99a1
  
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* DDJVU_CONTEXT_T                                    */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
/* There is usually only one <ddjvu_context_t> object.  
Packit df99a1
   This object holds global data structures such as the 
Packit df99a1
   cache of decoded pages, or the list of pending 
Packit df99a1
   event messages.
Packit df99a1
 */
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_get_version_string() ---
Packit df99a1
   Returns a string that described the underlying code. */
Packit df99a1
Packit df99a1
DDJVUAPI const char*
Packit df99a1
ddjvu_get_version_string(void);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_context_create ---
Packit df99a1
   Creates a <ddjvu_context_t> object.
Packit df99a1
   Argument <programname> is the name of the calling executable. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_context_t *
Packit df99a1
ddjvu_context_create(const char *programname);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_context_release ---
Packit df99a1
   Release a reference to a <ddjvu_context_t> object.
Packit df99a1
   The calling program should no longer reference this object.
Packit df99a1
   The object itself will be destroyed as soon as no other object
Packit df99a1
   or thread needs it. */
Packit df99a1
Packit df99a1
DDJVUAPI void 
Packit df99a1
ddjvu_context_release(ddjvu_context_t *context);
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* ------- CACHE ------- */
Packit df99a1
Packit df99a1
/* ddjvu_cache_set_size ---
Packit df99a1
   Sets the maximum size of the cache of decoded page data.
Packit df99a1
   The argument is expressed in bytes. */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_cache_set_size(ddjvu_context_t *context,
Packit df99a1
                     unsigned long cachesize);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_cache_get_size ---
Packit df99a1
   Returns the maximum size of the cache. */
Packit df99a1
Packit df99a1
DDJVUAPI unsigned long
Packit df99a1
ddjvu_cache_get_size(ddjvu_context_t *context);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_cache_clear ---
Packit df99a1
   Clears all cached data. */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_cache_clear(ddjvu_context_t *context);
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* ------- MESSAGE QUEUE ------- */
Packit df99a1
Packit df99a1
/* Messages produced by the ddjvu api accumulate into
Packit df99a1
   the message queue. Processing messages is not optional!
Packit df99a1
   A typical message handling routine looks like this:
Packit df99a1
   
Packit df99a1
   void handle_ddjvu_messages(ddjvu_context_t *ctx, int wait)
Packit df99a1
   {
Packit df99a1
     const ddjvu_message_t *msg;
Packit df99a1
     if (wait)
Packit df99a1
       ddjvu_message_wait(ctx);
Packit df99a1
     while ((msg = ddjvu_message_peek(ctx)))
Packit df99a1
     {
Packit df99a1
       switch(msg->m_any.tag)
Packit df99a1
       { 
Packit df99a1
       case DDJVU_ERROR:      .... ; break;
Packit df99a1
       case DDJVU_INFO:       .... ; break;
Packit df99a1
       case DDJVU_NEWSTREAM:  .... ; break;
Packit df99a1
       ....
Packit df99a1
       default: break;
Packit df99a1
       }
Packit df99a1
       ddjvu_message_pop(ctx);
Packit df99a1
     }
Packit df99a1
   }
Packit df99a1
*/
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_peek ---
Packit df99a1
   Returns a pointer to the next DDJVU message.
Packit df99a1
   This function returns 0 if no message is available.
Packit df99a1
   It does not remove the message from the queue. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_message_t *
Packit df99a1
ddjvu_message_peek(ddjvu_context_t *context);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_wait ---
Packit df99a1
   Returns a pointer to the next DDJVU message.
Packit df99a1
   This function waits until a message is available.
Packit df99a1
   It does not remove the message from the queue. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_message_t *
Packit df99a1
ddjvu_message_wait(ddjvu_context_t *context);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_pop ---
Packit df99a1
   Removes one message from the queue.
Packit df99a1
   This function must be called after processing the message.
Packit df99a1
   Pointers returned by previous calls to <ddjvu_message_peek> 
Packit df99a1
   or <ddjvu_message_wait> are no longer valid after 
Packit df99a1
   calling <ddjvu_message_pop>. */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_message_pop(ddjvu_context_t *context);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_set_callback ---
Packit df99a1
   Defines a callback function invoked whenever
Packit df99a1
   a new message is posted to the ddjvuapi message queue,
Packit df99a1
   and returns a pointer to the previous callback function.
Packit df99a1
   This callback function can be called at any time
Packit df99a1
   while other code is executing. Do not call ddjvuapi
Packit df99a1
   functions from this callback. It should simply signal
Packit df99a1
   the main application event loop that new ddjvuapi messages
Packit df99a1
   are available.  Under WIN32, this is usually achieved
Packit df99a1
   by posting a user window message.  Under UNIX, this is
Packit df99a1
   usually achieved using a pipe: the callback writes 
Packit df99a1
   a single byte into the pipe; the main application loop
Packit df99a1
   monitors the reading end of the pipe and detects
Packit df99a1
   the presence of data. */
Packit df99a1
Packit df99a1
typedef void 
Packit df99a1
(*ddjvu_message_callback_t)(ddjvu_context_t *context, void *closure);
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_message_set_callback(ddjvu_context_t *context,
Packit df99a1
                           ddjvu_message_callback_t callback,
Packit df99a1
                           void *closure);
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* DDJVU_JOB_T                                        */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* Many essential ddjvuapi functions initiate asynchronous operations. 
Packit df99a1
   These "jobs" run in seperate threads and report their
Packit df99a1
   progress by posting messages into the ddjvu context event queue. 
Packit df99a1
   Jobs are sometimes represented by a ddjvu_job_t object. */
Packit df99a1
Packit df99a1
/* ddjvu_job_status ---
Packit df99a1
   Returns the status of the specified job. */
Packit df99a1
Packit df99a1
typedef enum {
Packit df99a1
  DDJVU_JOB_NOTSTARTED, /* operation was not even started */
Packit df99a1
  DDJVU_JOB_STARTED,    /* operation is in progress */
Packit df99a1
  DDJVU_JOB_OK,         /* operation terminated successfully */
Packit df99a1
  DDJVU_JOB_FAILED,     /* operation failed because of an error */
Packit df99a1
  DDJVU_JOB_STOPPED     /* operation was interrupted by user */
Packit df99a1
} ddjvu_status_t;
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_status_t
Packit df99a1
ddjvu_job_status(ddjvu_job_t *job);
Packit df99a1
Packit df99a1
#define ddjvu_job_done(job) \
Packit df99a1
    (ddjvu_job_status(job) >= DDJVU_JOB_OK)
Packit df99a1
#define ddjvu_job_error(job) \
Packit df99a1
    (ddjvu_job_status(job) >= DDJVU_JOB_FAILED)
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_job_stop ---
Packit df99a1
   Attempts to cancel the specified job.
Packit df99a1
   This is a best effort function. 
Packit df99a1
   There no guarantee that the job will 
Packit df99a1
   actually stop.
Packit df99a1
 */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_job_stop(ddjvu_job_t *job);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_job_set_user_data ---
Packit df99a1
   ddjvu_job_get_user_data ---
Packit df99a1
   Each job can store an arbitrary pointer
Packit df99a1
   that callers can use for any purpose. These two 
Packit df99a1
   functions provide for accessing or setting this pointer. 
Packit df99a1
   This pointer is cleared when the job is released */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_job_set_user_data(ddjvu_job_t *job, void *userdata);
Packit df99a1
Packit df99a1
DDJVUAPI void *
Packit df99a1
ddjvu_job_get_user_data(ddjvu_job_t *job);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_job_release ---
Packit df99a1
   Releases a reference to a job object and clears its user 
Packit df99a1
   data field.  This does not cause the job to stop executing.
Packit df99a1
   The calling program should no longer reference this object.
Packit df99a1
   The object itself will be destroyed as soon as no 
Packit df99a1
   other object or thread needs it. 
Packit df99a1
*/
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_job_release(ddjvu_job_t *job);
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* DDJVU_MESSAGE_T                                    */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_t ---
Packit df99a1
   This union type represents messages delivered by the
Packit df99a1
   DDJVU API. Each member of the union pertains to a
Packit df99a1
   specific kind of message.  Member <m_any> represents the
Packit df99a1
   information common to all kinds of messages.  Given a
Packit df99a1
   pointer 

to a <djvu_message_t>, the message kind can

Packit df99a1
   be accessed as <"p->m_any.tag">. */
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_tag_t ---
Packit df99a1
   This enumerated type identifies each kind of 
Packit df99a1
   message delivered by the DDJVU API.  */
Packit df99a1
Packit df99a1
typedef enum {
Packit df99a1
  DDJVU_ERROR,
Packit df99a1
  DDJVU_INFO,
Packit df99a1
  DDJVU_NEWSTREAM,
Packit df99a1
  DDJVU_DOCINFO,
Packit df99a1
  DDJVU_PAGEINFO,
Packit df99a1
  DDJVU_RELAYOUT,
Packit df99a1
  DDJVU_REDISPLAY,
Packit df99a1
  DDJVU_CHUNK,
Packit df99a1
  DDJVU_THUMBNAIL,
Packit df99a1
  DDJVU_PROGRESS,
Packit df99a1
} ddjvu_message_tag_t;
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_t::m_any ---
Packit df99a1
   This structure is a member of the union <djvu_message_t>.
Packit df99a1
   It represents the information common to all kinds of
Packit df99a1
   messages.  Member <tag> indicates the kind of message.
Packit df99a1
   Members <context>, <document>, <page>, and <job> indicate 
Packit df99a1
   the origin of the message.  These fields contain null
Packit df99a1
   pointers when they are not relevant.
Packit df99a1
   These fields are also cleared when the corresponding
Packit df99a1
   object is released with <ddjvu_{job,page,document}_release>.
Packit df99a1
   If the message has not yet been passed to the user 
Packit df99a1
   with <ddjvu_message_{peek,wait}>, it is silently 
Packit df99a1
   removed from the message queue. */
Packit df99a1
Packit df99a1
typedef struct ddjvu_message_any_s {
Packit df99a1
  ddjvu_message_tag_t   tag;
Packit df99a1
  ddjvu_context_t      *context;
Packit df99a1
  ddjvu_document_t     *document;
Packit df99a1
  ddjvu_page_t         *page;
Packit df99a1
  ddjvu_job_t          *job;
Packit df99a1
} ddjvu_message_any_t; 
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_t::m_error ---
Packit df99a1
   Error messages are generated whenever the decoder or the
Packit df99a1
   DDJVU API encounters an error condition.  All errors are
Packit df99a1
   reported as error messages because they can occur
Packit df99a1
   asynchronously.  Member <message> is the error message.
Packit df99a1
   Members <function>, <filename> and <lineno>
Packit df99a1
   indicates the place where the error was detected. */
Packit df99a1
Packit df99a1
struct ddjvu_message_error_s {  /* ddjvu_message_t::m_error */
Packit df99a1
  ddjvu_message_any_t   any;
Packit df99a1
  const char           *message;
Packit df99a1
  const char           *function;
Packit df99a1
  const char           *filename;
Packit df99a1
  int                   lineno;
Packit df99a1
}; 
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_t::m_info ---
Packit df99a1
   This messages provides informational text indicating
Packit df99a1
   the progress of the decoding process. This might
Packit df99a1
   be displayed in the browser status bar. */
Packit df99a1
Packit df99a1
struct ddjvu_message_info_s {   /* ddjvu_message_t::m_info */
Packit df99a1
  ddjvu_message_any_t  any;
Packit df99a1
  const char          *message;
Packit df99a1
}; 
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* DDJVU_DOCUMENT_T                                    */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_create ---
Packit df99a1
   Creates a decoder for a DjVu document and starts
Packit df99a1
   decoding.  This function returns immediately.  The
Packit df99a1
   decoding job then generates messages to request the raw
Packit df99a1
   data and to indicate the state of the decoding process.
Packit df99a1
Packit df99a1
   Argument <url> specifies an optional URL for the document.  
Packit df99a1
   The URL follows the usual syntax (<"protocol://machine/path">). 
Packit df99a1
   It should not end with a slash. It only serves two purposes:
Packit df99a1
   - The URL is used as a key for the cache of decoded pages.
Packit df99a1
   - The URL is used to document <m_newstream> messages.
Packit df99a1
Packit df99a1
   Setting argument <cache> to <TRUE> indicates that decoded pages
Packit df99a1
   should be cached when possible.  This only works when
Packit df99a1
   argument <url> is not the null pointer.
Packit df99a1
Packit df99a1
   It is important to understand that the URL is not used to
Packit df99a1
   access the data.  The document generates <m_newstream>
Packit df99a1
   messages to indicate which data is needed.  The caller must 
Packit df99a1
   then provide the raw data using <ddjvu_stream_write> 
Packit df99a1
   and <ddjvu_stream_close>.
Packit df99a1
Packit df99a1
   Localized characters in argument <url> should be in 
Packit df99a1
   urlencoded UTF-8 (like "%2A"). What is happening for non 
Packit df99a1
   ascii characters is unclear (probably UTF-8). */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_document_t *
Packit df99a1
ddjvu_document_create(ddjvu_context_t *context,
Packit df99a1
                      const char *url,
Packit df99a1
                      int cache);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_create_by_filename ---
Packit df99a1
   Creates a document for a DjVu document stored in a file.
Packit df99a1
   The document will directly access the specified DjVu file 
Packit df99a1
   or related files without generating <m_newstream> messages.
Packit df99a1
   The standard function expects the filename in locale encoding. 
Packit df99a1
   The utf8 variant expects an utf8 encoded filename. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_document_t *
Packit df99a1
ddjvu_document_create_by_filename(ddjvu_context_t *context,
Packit df99a1
                                  const char *filename,
Packit df99a1
                                  int cache);
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_document_t *
Packit df99a1
ddjvu_document_create_by_filename_utf8(ddjvu_context_t *context,
Packit df99a1
                                       const char *filename,
Packit df99a1
                                       int cache);
Packit df99a1
Packit df99a1
/* ddjvu_document_job ---
Packit df99a1
   Access the job object in charge of decoding the document header. 
Packit df99a1
   In fact <ddjvu_document_t> is a subclass of <ddjvu_job_t>
Packit df99a1
   and this function is a type cast. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_job_t *
Packit df99a1
ddjvu_document_job(ddjvu_document_t *document);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_release ---
Packit df99a1
   Release a reference to a <ddjvu_document_t> object.
Packit df99a1
   The calling program should no longer reference this object.  
Packit df99a1
   The object itself will be destroyed as soon as no other object
Packit df99a1
   or thread needs it. */
Packit df99a1
 
Packit df99a1
#define ddjvu_document_release(document) \
Packit df99a1
   ddjvu_job_release(ddjvu_document_job(document))
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_set_user_data ---
Packit df99a1
   ddjvu_document_get_user_data ---
Packit df99a1
   Each <ddjvu_document_t> object can store an arbitray pointer
Packit df99a1
   that callers can use for any purpose. These two functions
Packit df99a1
   provide for accessing or setting this pointer. */
Packit df99a1
Packit df99a1
#define ddjvu_document_set_user_data(document,userdata) \
Packit df99a1
   ddjvu_job_set_user_data(ddjvu_document_job(document),userdata)
Packit df99a1
#define ddjvu_document_get_user_data(document) \
Packit df99a1
   ddjvu_job_get_user_data(ddjvu_document_job(document))
Packit df99a1
Packit df99a1
/* ddjvu_document_decoding_status ---
Packit df99a1
   ddjvu_document_decoding_done, ddjvu_document_decoding_error ---
Packit df99a1
   This function returns the status of the document header decoding job */
Packit df99a1
   
Packit df99a1
#define ddjvu_document_decoding_status(document) \
Packit df99a1
   ddjvu_job_status(ddjvu_document_job(document))
Packit df99a1
#define ddjvu_document_decoding_done(document) \
Packit df99a1
   (ddjvu_document_decoding_status(document) >= DDJVU_JOB_OK)
Packit df99a1
#define ddjvu_document_decoding_error(document) \
Packit df99a1
   (ddjvu_document_decoding_status(document) >= DDJVU_JOB_FAILED)
Packit df99a1
Packit df99a1
Packit df99a1
/* ------- STREAMS ------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_t::m_newstream --- 
Packit df99a1
   Newstream messages are generated whenever the decoder
Packit df99a1
   needs to access raw DjVu data.  The caller must then
Packit df99a1
   provide the requested data using <ddjvu_stream_write> 
Packit df99a1
   and <ddjvu_stream_close>. 
Packit df99a1
Packit df99a1
   In the case of indirect documents, a single decoder 
Packit df99a1
   might simultaneously request several streams of data.  
Packit df99a1
   Each stream is identified by a small integer <streamid>.
Packit df99a1
Packit df99a1
   The first <m_newstream> message always has member
Packit df99a1
   <streamid> set to zero and member <name> set to the null
Packit df99a1
   pointer.  It indicates that the decoder needs to access
Packit df99a1
   the data in the main DjVu file.  In fact, data can be
Packit df99a1
   written to stream <0> as soon as the <ddjvu_document_t>
Packit df99a1
   object is created.
Packit df99a1
Packit df99a1
   Further <m_newstream> messages are generated to access
Packit df99a1
   the auxiliary files of indirect or indexed DjVu
Packit df99a1
   documents.  Member <name> then provides the basename of
Packit df99a1
   the auxiliary file.
Packit df99a1
Packit df99a1
   Member <url> is set according to the url argument
Packit df99a1
   provided to function <ddjvu_document_create>.  The first
Packit df99a1
   newstream message always contain the url passed to
Packit df99a1
   <ddjvu_document_create>.  Subsequent newstream messages
Packit df99a1
   contain the url of the auxiliary files for indirect or
Packit df99a1
   indexed DjVu documents. */
Packit df99a1
   
Packit df99a1
struct ddjvu_message_newstream_s { /* ddjvu_message_t::m_newstream */
Packit df99a1
  ddjvu_message_any_t  any;
Packit df99a1
  int                  streamid;
Packit df99a1
  const char          *name;
Packit df99a1
  const char          *url;
Packit df99a1
}; 
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_stream_write ---
Packit df99a1
   Provide raw data to the DjVu decoder.
Packit df99a1
   This function should be called as soon as the data is available,
Packit df99a1
   for instance when receiving DjVu data from a network connection.
Packit df99a1
 */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_stream_write(ddjvu_document_t *document,
Packit df99a1
                   int streamid,
Packit df99a1
                   const char *data,
Packit df99a1
                   unsigned long datalen );
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_stream_close ---
Packit df99a1
   Indicates that no more data will be provided on a
Packit df99a1
   particular stream.  Argument <stop> most likely should be
Packit df99a1
   set to <FALSE>. Setting argument <stop> to <TRUE>
Packit df99a1
   indicates that the user has interrupted the data transfer
Packit df99a1
   (for instance by pressing the stop button of a browser)
Packit df99a1
   and that the decoding threads should be stopped as 
Packit df99a1
   soon as feasible. */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_stream_close(ddjvu_document_t *document,
Packit df99a1
                   int streamid,
Packit df99a1
                   int stop );
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* ------- QUERIES ------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_t::m_docinfo ---
Packit df99a1
   The <m_docinfo> message indicates that basic information
Packit df99a1
   about the document has been obtained and decoded.
Packit df99a1
   Not much can be done before this happens.
Packit df99a1
   Call <ddjvu_document_decoding_status> to determine
Packit df99a1
   whether the operation was successful. */
Packit df99a1
Packit df99a1
struct ddjvu_message_docinfo_s {
Packit df99a1
  ddjvu_message_any_t  any;
Packit df99a1
};
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_get_type ---
Packit df99a1
   Returns the type of a DjVu document.
Packit df99a1
   This function might return <DDJVU_DOCTYPE_UNKNOWN>
Packit df99a1
   when called before receiving a <m_docinfo> message. */
Packit df99a1
Packit df99a1
typedef enum {
Packit df99a1
  DDJVU_DOCTYPE_UNKNOWN=0,
Packit df99a1
  DDJVU_DOCTYPE_SINGLEPAGE,
Packit df99a1
  DDJVU_DOCTYPE_BUNDLED, 
Packit df99a1
  DDJVU_DOCTYPE_INDIRECT,
Packit df99a1
  DDJVU_DOCTYPE_OLD_BUNDLED, /* obsolete */
Packit df99a1
  DDJVU_DOCTYPE_OLD_INDEXED, /* obsolete */
Packit df99a1
} ddjvu_document_type_t;
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_document_type_t
Packit df99a1
ddjvu_document_get_type(ddjvu_document_t *document);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_get_pagenum ---
Packit df99a1
   Returns the number of pages in a DjVu document.
Packit df99a1
   This function might return 1 when called 
Packit df99a1
   before receiving a <m_docinfo> message */
Packit df99a1
   
Packit df99a1
DDJVUAPI int
Packit df99a1
ddjvu_document_get_pagenum(ddjvu_document_t *document);
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* ------- ADVANCED ------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_get_filenum --
Packit df99a1
   Returns the number of component files.
Packit df99a1
   This function might return 0 when called
Packit df99a1
   before receiving a <m_docinfo> message */
Packit df99a1
   
Packit df99a1
DDJVUAPI int
Packit df99a1
ddjvu_document_get_filenum(ddjvu_document_t *document);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_get_fileinfo --
Packit df99a1
   Returns information about component file <fileno>.
Packit df99a1
   This function might return <DDJVU_JOB_STARTED> when
Packit df99a1
   called before receiving a <m_docinfo> message.
Packit df99a1
   String pointers in the returned data structure 
Packit df99a1
   might be null. Strings are UTF8 encoded and remain 
Packit df99a1
   allocated as long as the ddjvu_document_t object exists.
Packit df99a1
Packit df99a1
   Changes for ddjvuapi=18
Packit df99a1
   - Redefined as a macro passing the structure size.
Packit df99a1
*/
Packit df99a1
Packit df99a1
typedef struct ddjvu_fileinfo_s {
Packit df99a1
  char  type;                   /* [P]age, [T]humbnails, [I]nclude. */
Packit df99a1
  int   pageno;                 /* Negative when not applicable. */
Packit df99a1
  int   size;                   /* Negative when unknown. */
Packit df99a1
  const char *id;               /* File identifier. */
Packit df99a1
  const char *name;             /* Name for indirect documents. */
Packit df99a1
  const char *title;            /* Page title. */
Packit df99a1
} ddjvu_fileinfo_t;
Packit df99a1
Packit df99a1
#define ddjvu_document_get_fileinfo(d,f,i) \
Packit df99a1
   ddjvu_document_get_fileinfo_imp(d,f,i,sizeof(ddjvu_fileinfo_t))
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_status_t
Packit df99a1
ddjvu_document_get_fileinfo_imp(ddjvu_document_t *document, int fileno, 
Packit df99a1
                                ddjvu_fileinfo_t *info, unsigned int infosz);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_search_pageno --- DEPRECATED. */
Packit df99a1
Packit df99a1
DDJVUAPI int ddjvu_document_search_pageno(ddjvu_document_t*, const char*);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_check_pagedata ---
Packit df99a1
   Returns a non zero result if the data for page <pageno>
Packit df99a1
   is already in memory. When this is the case, functions 
Packit df99a1
   <ddjvu_document_get_pageinfo> and <ddjvu_document_get_pagetext> 
Packit df99a1
   return the information immediately.
Packit df99a1
   This function causes the emission of <m_pageinfo> messages 
Packit df99a1
   with zero in the <m_any.page> field whenever a new file
Packit df99a1
   is completely downloaded. */
Packit df99a1
Packit df99a1
DDJVUAPI int 
Packit df99a1
ddjvu_document_check_pagedata(ddjvu_document_t *document, int pageno);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_get_pageinfo ---
Packit df99a1
   Attempts to obtain information about page <pageno>
Packit df99a1
   without decoding the page. If the information is available,
Packit df99a1
   the function returns <DDJVU_JOB_OK> and fills the <info> structure. 
Packit df99a1
   Otherwise it starts fetching page data and returns <DDJVU_JOB_STARTED>. 
Packit df99a1
   This function causes the emission of <m_pageinfo> messages 
Packit df99a1
   with zero in the <m_any.page> field.
Packit df99a1
   Typical synchronous usage:
Packit df99a1
Packit df99a1
   ddjvu_status_t r;
Packit df99a1
   ddjvu_pageinfo_t info;
Packit df99a1
   while ((r=ddjvu_document_get_pageinfo(doc,pageno,&info))
Packit df99a1
     handle_ddjvu_messages(ctx, TRUE);
Packit df99a1
   if (r>=DDJVU_JOB_FAILED)
Packit df99a1
     signal_error();
Packit df99a1
Packit df99a1
   Changes for ddjvuapi=18
Packit df99a1
   - Redefined as a macro passing the structure size.
Packit df99a1
   - Added fields 'rotation' and 'version'.
Packit df99a1
*/      
Packit df99a1
Packit df99a1
typedef struct ddjvu_pageinfo_s {
Packit df99a1
  int width;                    /* page width (in pixels) */
Packit df99a1
  int height;                   /* page height (in pixels) */
Packit df99a1
  int dpi;                      /* page resolution (in dots per inche) */
Packit df99a1
  int rotation;                 /* initial page orientation */
Packit df99a1
  int version;                  /* page version */
Packit df99a1
} ddjvu_pageinfo_t;
Packit df99a1
Packit df99a1
#define ddjvu_document_get_pageinfo(d,p,i) \
Packit df99a1
   ddjvu_document_get_pageinfo_imp(d,p,i,sizeof(ddjvu_pageinfo_t))
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_status_t
Packit df99a1
ddjvu_document_get_pageinfo_imp(ddjvu_document_t *document, int pageno, 
Packit df99a1
                                ddjvu_pageinfo_t *info, unsigned int infosz );
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_get_pagedump --
Packit df99a1
   This function returns a UTF8 encoded text describing the contents 
Packit df99a1
   of page <pageno> using the same format as command <djvudump>. 
Packit df99a1
   The returned string must be deallocated using <free()>.
Packit df99a1
   It returns <0> when the information is not yet available. 
Packit df99a1
   It may then cause then the emission of <m_pageinfo> 
Packit df99a1
   messages with null <m_any.page>.
Packit df99a1
*/   
Packit df99a1
Packit df99a1
DDJVUAPI char *
Packit df99a1
ddjvu_document_get_pagedump(ddjvu_document_t *document, int pageno);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_get_filedump --
Packit df99a1
   This function returns a UTF8 encoded text describing the contents 
Packit df99a1
   of file <fileno> using the same format as command <djvudump>. 
Packit df99a1
   The returned string must be deallocated using <free()>.
Packit df99a1
   It returns <0> when the information is not yet available. 
Packit df99a1
   It may then cause then the emission of <m_pageinfo> 
Packit df99a1
   messages with null <m_any.page>.
Packit df99a1
*/   
Packit df99a1
Packit df99a1
DDJVUAPI char *
Packit df99a1
ddjvu_document_get_filedump(ddjvu_document_t *document, int fileno);
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* DJVU_PAGE_T                                        */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_create_by_pageno ---
Packit df99a1
   Each page of a document can be accessed by creating a
Packit df99a1
   <ddjvu_page_t> object with this function.  Argument
Packit df99a1
   <pageno> indicates the page number, starting with page
Packit df99a1
   <0> to <pagenum-1>. This function may return NULL
Packit df99a1
   when called before receiving the <m_docinfo> message.
Packit df99a1
   Calling this function also initiates the data transfer 
Packit df99a1
   and the decoding threads for the specified page.  
Packit df99a1
   Various messages will document the progress of these 
Packit df99a1
   operations. Error messages will be generated if 
Packit df99a1
   the page does not exists. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_page_t *
Packit df99a1
ddjvu_page_create_by_pageno(ddjvu_document_t *document,
Packit df99a1
                            int pageno);
Packit df99a1
Packit df99a1
/* ddjvu_page_create_by_pageid ---
Packit df99a1
   This function is similar to <ddjvu_page_create_by_pageno>
Packit df99a1
   but identifies the desired page by name instead of page
Packit df99a1
   number. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_page_t *
Packit df99a1
ddjvu_page_create_by_pageid(ddjvu_document_t *document,
Packit df99a1
                            const char *pageid);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_job ---
Packit df99a1
   Access the job object in charge of decoding the document header. 
Packit df99a1
   In fact <ddjvu_page_t> is a subclass of <ddjvu_job_t>
Packit df99a1
   and this function is a type cast. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_job_t *
Packit df99a1
ddjvu_page_job(ddjvu_page_t *page);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_release ---
Packit df99a1
   Release a reference to a <ddjvu_page_t> object.
Packit df99a1
   The calling program should no longer reference this object.
Packit df99a1
   The object itself will be destroyed as soon as no other object
Packit df99a1
   or thread needs it. */
Packit df99a1
Packit df99a1
#define ddjvu_page_release(page) \
Packit df99a1
  ddjvu_job_release(ddjvu_page_job(page))
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_set_user_data ---
Packit df99a1
   ddjvu_page_get_user_data ---
Packit df99a1
   Each <ddjvu_paqge_t> object can store an arbitray pointer
Packit df99a1
   that callers can use for any purpose. These two functions
Packit df99a1
   provide for accessing or setting this pointer. */
Packit df99a1
Packit df99a1
#define ddjvu_page_set_user_data(page,userdata) \
Packit df99a1
   ddjvu_job_set_user_data(ddjvu_page_job(page),userdata)
Packit df99a1
#define ddjvu_page_get_user_data(page) \
Packit df99a1
   ddjvu_job_get_user_data(ddjvu_page_job(page))
Packit df99a1
Packit df99a1
/* ddjvu_page_decoding_status ---
Packit df99a1
   ddjvu_page_decoding_done ---
Packit df99a1
   ddjvu_page_decoding_error ---
Packit df99a1
   These calls return the status of the page decoding job. */
Packit df99a1
   
Packit df99a1
#define ddjvu_page_decoding_status(page) \
Packit df99a1
   ddjvu_job_status(ddjvu_page_job(page))
Packit df99a1
#define ddjvu_page_decoding_done(page) \
Packit df99a1
    (ddjvu_page_decoding_status(page) >= DDJVU_JOB_OK)
Packit df99a1
#define ddjvu_page_decoding_error(page) \
Packit df99a1
    (ddjvu_page_decoding_status(page) >= DDJVU_JOB_FAILED)
Packit df99a1
Packit df99a1
Packit df99a1
/* ------- MESSAGES ------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_t::m_pageinfo ---
Packit df99a1
   The page decoding process generates this message
Packit df99a1
   - when basic page information is available and 
Packit df99a1
     before any <m_relayout> or <m_redisplay> message,
Packit df99a1
   - when the page decoding thread terminates.
Packit df99a1
   You can distinguish both cases using 
Packit df99a1
   function ddjvu_page_decoding_status().
Packit df99a1
   Messages <m_pageinfo> are also generated as a consequence of 
Packit df99a1
   functions such as <ddjvu_document_get_pageinfo>. 
Packit df99a1
   The field <m_any.page> of such message is null.
Packit df99a1
*/
Packit df99a1
Packit df99a1
struct ddjvu_message_pageinfo_s {  /* ddjvu_message_t::m_pageinfo */
Packit df99a1
  ddjvu_message_any_t  any;
Packit df99a1
}; 
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_t::m_relayout ---
Packit df99a1
   This message is generated when a DjVu viewer
Packit df99a1
   should recompute the layout of the page viewer
Packit df99a1
   because the page size and resolution information has
Packit df99a1
   been updated. */
Packit df99a1
Packit df99a1
struct ddjvu_message_relayout_s {  /* ddjvu_message_t::m_relayout */
Packit df99a1
  ddjvu_message_any_t  any;
Packit df99a1
}; 
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_t::m_redisplay ---
Packit df99a1
   This message is generated when a DjVu viewer
Packit df99a1
   should call <ddjvu_page_render> and redisplay
Packit df99a1
   the page. This happens, for instance, when newly 
Packit df99a1
   decoded DjVu data provides a better image. */
Packit df99a1
Packit df99a1
struct ddjvu_message_redisplay_s { /* ddjvu_message_t::m_redisplay */
Packit df99a1
  ddjvu_message_any_t  any;
Packit df99a1
}; 
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_t::m_chunk ---
Packit df99a1
   This message indicates that an additional chunk
Packit df99a1
   of DjVu data has been decoded.  Member <chunkid>
Packit df99a1
   indicates the type of the DjVu chunk. */
Packit df99a1
Packit df99a1
struct ddjvu_message_chunk_s {     /* ddjvu_message_t::m_chunk */
Packit df99a1
  ddjvu_message_any_t  any;
Packit df99a1
  const char *chunkid;
Packit df99a1
}; 
Packit df99a1
Packit df99a1
/* About page messages --
Packit df99a1
   Both the <m_relayout> and <m_redisplay> messages are derived from the
Packit df99a1
   <m_chunk> message.  They are intended for driving a djvu image viewer. 
Packit df99a1
   When receiving <m_relayout>, the viewer should get the image size, decide
Packit df99a1
   zoom factors, and place the image area, scrollbars, toolbars, and other gui
Packit df99a1
   objects.  When receiving <m_redisplay>, the viewer should invalidate the
Packit df99a1
   image area so that the gui toolkit calls the repaint event handler. This
Packit df99a1
   handler should call ddjvu_page_render() and paint the part of the
Packit df99a1
   image that needs repainting. */
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* ------- QUERIES ------- */
Packit df99a1
Packit df99a1
/* ddjvu_page_get_width ---
Packit df99a1
   Returns the page width in pixels. Calling this function 
Packit df99a1
   before receiving a <m_pageinfo> message always yields <0>. */
Packit df99a1
Packit df99a1
DDJVUAPI int
Packit df99a1
ddjvu_page_get_width(ddjvu_page_t *page);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_get_height---
Packit df99a1
   Returns the page height in pixels. Calling this function 
Packit df99a1
   before receiving a <m_pageinfo> message always yields <0>. */
Packit df99a1
Packit df99a1
DDJVUAPI int
Packit df99a1
ddjvu_page_get_height(ddjvu_page_t *page);
Packit df99a1
Packit df99a1
/* ddjvu_page_get_resolution ---
Packit df99a1
   Returns the page resolution in pixels per inch  (dpi).
Packit df99a1
   Calling this function before receiving a <m_pageinfo>
Packit df99a1
   message yields a meaningless but plausible value. */
Packit df99a1
Packit df99a1
DDJVUAPI int
Packit df99a1
ddjvu_page_get_resolution(ddjvu_page_t *page);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_get_gamma ---
Packit df99a1
   Returns the gamma of the display for which this page was designed.
Packit df99a1
   Calling this function before receiving a <m_pageinfo>
Packit df99a1
   message yields a meaningless but plausible value. */
Packit df99a1
Packit df99a1
DDJVUAPI double
Packit df99a1
ddjvu_page_get_gamma(ddjvu_page_t *page);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_get_version ---
Packit df99a1
   Returns the version of the djvu file format.
Packit df99a1
   Calling this function before receiving a <m_pageinfo>
Packit df99a1
   message yields a meaningless but plausible value. */
Packit df99a1
Packit df99a1
DDJVUAPI int
Packit df99a1
ddjvu_page_get_version(ddjvu_page_t *page);
Packit df99a1
Packit df99a1
/* ddjvu_code_get_version ---
Packit df99a1
   Returns the version of the djvu file format
Packit df99a1
   implemented by this library. More or less graceful 
Packit df99a1
   degradation might arise if this is smaller than
Packit df99a1
   the number returned by <ddjvu_page_get_version>. */
Packit df99a1
Packit df99a1
DDJVUAPI int
Packit df99a1
ddjvu_code_get_version(void);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_get_type ---
Packit df99a1
   Returns the type of the page data.
Packit df99a1
   Calling this function before the termination of the
Packit df99a1
   decoding process might returns <DDJVU_PAGETYPE_UNKNOWN>. */
Packit df99a1
Packit df99a1
typedef enum {
Packit df99a1
  DDJVU_PAGETYPE_UNKNOWN,
Packit df99a1
  DDJVU_PAGETYPE_BITONAL,
Packit df99a1
  DDJVU_PAGETYPE_PHOTO,
Packit df99a1
  DDJVU_PAGETYPE_COMPOUND,
Packit df99a1
} ddjvu_page_type_t;
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_page_type_t
Packit df99a1
ddjvu_page_get_type(ddjvu_page_t *page);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_get_{short,long}_description --- DEPRECATED */
Packit df99a1
Packit df99a1
DDJVUAPI char *ddjvu_page_get_short_description(ddjvu_page_t *);
Packit df99a1
DDJVUAPI char *ddjvu_page_get_long_description(ddjvu_page_t *);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_set_rotation ---
Packit df99a1
   Changes the counter-clockwise rotation angle for a DjVu page.
Packit df99a1
   Calling this function before receiving a <m_pageinfo>
Packit df99a1
   message has no good effect. */
Packit df99a1
Packit df99a1
typedef enum {
Packit df99a1
  DDJVU_ROTATE_0   = 0,
Packit df99a1
  DDJVU_ROTATE_90  = 1,
Packit df99a1
  DDJVU_ROTATE_180 = 2,
Packit df99a1
  DDJVU_ROTATE_270 = 3,
Packit df99a1
} ddjvu_page_rotation_t;
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_page_set_rotation(ddjvu_page_t *page,
Packit df99a1
                        ddjvu_page_rotation_t rot);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_get_rotation ---
Packit df99a1
   Returns the counter-clockwise rotation angle for the DjVu page.
Packit df99a1
   The rotation is automatically taken into account
Packit df99a1
   by <ddjvu_page_render>, <ddjvu_page_get_width>
Packit df99a1
   and <ddjvu_page_get_height>. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_page_rotation_t
Packit df99a1
ddjvu_page_get_rotation(ddjvu_page_t *page);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_get_initial_rotation ---
Packit df99a1
   Returns the page rotation specified by the 
Packit df99a1
   orientation flags in the DjVu file. 
Packit df99a1
   [brain damage warning] This is useful because
Packit df99a1
   maparea coordinates in the annotation chunks
Packit df99a1
   are expressed relative to the rotated coordinates
Packit df99a1
   whereas text coordinates in the hidden text data
Packit df99a1
   are expressed relative to the unrotated coordinates. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_page_rotation_t
Packit df99a1
ddjvu_page_get_initial_rotation(ddjvu_page_t *page);
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* ------- RENDER ------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_render_mode_t ---
Packit df99a1
   Various ways to render a page. */
Packit df99a1
Packit df99a1
typedef enum {
Packit df99a1
  DDJVU_RENDER_COLOR = 0,       /* color page or stencil */
Packit df99a1
  DDJVU_RENDER_BLACK,           /* stencil or color page */
Packit df99a1
  DDJVU_RENDER_COLORONLY,       /* color page or fail */
Packit df99a1
  DDJVU_RENDER_MASKONLY,        /* stencil or fail */
Packit df99a1
  DDJVU_RENDER_BACKGROUND,      /* color background layer */
Packit df99a1
  DDJVU_RENDER_FOREGROUND,      /* color foreground layer */
Packit df99a1
} ddjvu_render_mode_t;
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_rect_t ---
Packit df99a1
   This structure specifies the location of a rectangle.
Packit df99a1
   Coordinates are usually expressed in pixels relative to 
Packit df99a1
   the BOTTOM LEFT CORNER (but see ddjvu_format_set_y_direction).
Packit df99a1
   Members <x> and <y> indicate the position of the bottom left 
Packit df99a1
   corner of the rectangle Members <w> and <h> indicate the 
Packit df99a1
   width and height of the rectangle. */
Packit df99a1
Packit df99a1
struct ddjvu_rect_s {
Packit df99a1
  int x, y;
Packit df99a1
  unsigned int w, h;
Packit df99a1
};
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_page_render --
Packit df99a1
   Renders a segment of a page with arbitrary scale.
Packit df99a1
   Argument <mode> indicates what image layers 
Packit df99a1
   should be rendered. 
Packit df99a1
Packit df99a1
   Conceptually this function renders the full page
Packit df99a1
   into a rectangle <pagerect> and copies the
Packit df99a1
   pixels specified by rectangle <renderrect>
Packit df99a1
   into the buffer starting at position <imagebuffer>.
Packit df99a1
   The actual code is much more efficient than that.
Packit df99a1
Packit df99a1
   The final image is written into buffer <imagebuffer>.  
Packit df99a1
   Argument <pixelformat> specifies the expected pixel format.  
Packit df99a1
   Argument <rowsize> specifies the number of BYTES from 
Packit df99a1
   one row to the next in the buffer. The buffer must be 
Packit df99a1
   large enough to accomodate the desired image.
Packit df99a1
Packit df99a1
   This function makes a best effort to compute an image
Packit df99a1
   that reflects the most recently decoded data.  It might
Packit df99a1
   return <FALSE> to indicate that no image could be
Packit df99a1
   computed at this point, and that nothing was written into
Packit df99a1
   the buffer. */
Packit df99a1
Packit df99a1
DDJVUAPI int
Packit df99a1
ddjvu_page_render(ddjvu_page_t *page,
Packit df99a1
                  const ddjvu_render_mode_t mode,
Packit df99a1
                  const ddjvu_rect_t *pagerect,
Packit df99a1
                  const ddjvu_rect_t *renderrect,
Packit df99a1
                  const ddjvu_format_t *pixelformat,
Packit df99a1
                  unsigned long rowsize,
Packit df99a1
                  char *imagebuffer );
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* COORDINATE TRANSFORMS                              */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
/* ddjvu_rectmapper_create --
Packit df99a1
   Creates a <ddjvu_rectmapper_t> data structure 
Packit df99a1
   representing an affine coordinate transformation that
Packit df99a1
   maps points from rectangle <input> to rectangle <output>.
Packit df99a1
   The transformation maintains the positions relative 
Packit df99a1
   to the coordinates of the rectangle corners. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_rectmapper_t *
Packit df99a1
ddjvu_rectmapper_create(ddjvu_rect_t *input, ddjvu_rect_t *output);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_rectmapper_modify ---
Packit df99a1
   Modifies the coordinate transform <mapper> by redefining
Packit df99a1
   which corners of the output rectangle match those of the 
Packit df99a1
   input rectangle. This function first applies a counter-clockwise 
Packit df99a1
   rotation of <rotation> quarter-turns, and then reverses the X 
Packit df99a1
   (resp. Y) coordinates when <mirrorx> (resp. <mirrory>) is non zero. */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_rectmapper_modify(ddjvu_rectmapper_t *mapper,
Packit df99a1
                        int rotation, int mirrorx, int mirrory);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_rectmapper_release ---
Packit df99a1
   Destroys the <ddjvu_rect_mapper_t> structure
Packit df99a1
   returned by <ddjvu_rect_mapper_create>. */
Packit df99a1
Packit df99a1
DDJVUAPI void 
Packit df99a1
ddjvu_rectmapper_release(ddjvu_rectmapper_t *mapper);
Packit df99a1
Packit df99a1
/* ddjvu_map_point, ddjvu_map_rect ---
Packit df99a1
   Applies the coordinate transform 
Packit df99a1
   to a point or a rectangle */
Packit df99a1
Packit df99a1
DDJVUAPI void 
Packit df99a1
ddjvu_map_point(ddjvu_rectmapper_t *mapper, int *x, int *y);
Packit df99a1
Packit df99a1
DDJVUAPI void 
Packit df99a1
ddjvu_map_rect(ddjvu_rectmapper_t *mapper, ddjvu_rect_t *rect);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_unmap_point, ddjvu_unmap_rect ---
Packit df99a1
   Applies the inverse coordinate transform 
Packit df99a1
   to a point or a rectangle */
Packit df99a1
Packit df99a1
DDJVUAPI void 
Packit df99a1
ddjvu_unmap_point(ddjvu_rectmapper_t *mapper, int *x, int *y);
Packit df99a1
Packit df99a1
DDJVUAPI void 
Packit df99a1
ddjvu_unmap_rect(ddjvu_rectmapper_t *mapper, ddjvu_rect_t *rect);
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* DJVU_FORMAT_T                                      */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_format_style_t ---
Packit df99a1
   Enumerated type for pixel formats. */
Packit df99a1
Packit df99a1
typedef enum {
Packit df99a1
  DDJVU_FORMAT_BGR24,           /* truecolor 24 bits in BGR order */
Packit df99a1
  DDJVU_FORMAT_RGB24,           /* truecolor 24 bits in RGB order */
Packit df99a1
  DDJVU_FORMAT_RGBMASK16,       /* truecolor 16 bits with masks */
Packit df99a1
  DDJVU_FORMAT_RGBMASK32,       /* truecolor 32 bits with masks */
Packit df99a1
  DDJVU_FORMAT_GREY8,           /* greylevel 8 bits */
Packit df99a1
  DDJVU_FORMAT_PALETTE8,        /* paletized 8 bits (6x6x6 color cube) */
Packit df99a1
  DDJVU_FORMAT_MSBTOLSB,        /* packed bits, msb on the left */
Packit df99a1
  DDJVU_FORMAT_LSBTOMSB,        /* packed bits, lsb on the left */
Packit df99a1
} ddjvu_format_style_t;
Packit df99a1
   
Packit df99a1
Packit df99a1
/* ddjvu_format_create ---
Packit df99a1
   Creates a <ddjvu_format_t> object describing a pixel format.
Packit df99a1
   Argument <style> describes the generic pixel format.
Packit df99a1
   Argument <args> is an array of <nargs> unsigned ints
Packit df99a1
   providing additionnal information:
Packit df99a1
   - When style is <RGBMASK*>, argument <nargs> must be <3> or <4>.
Packit df99a1
     The three first entries of array <args> are three contiguous 
Packit df99a1
     bit masks for the red, green, and blue components of each pixel.
Packit df99a1
     The resulting color is then xored with the optional fourth entry.
Packit df99a1
   - When style is <PALETTE*>, argument <nargs> must be <216>
Packit df99a1
     and array <args> contains the 6*6*6 entries of a web
Packit df99a1
     color cube.
Packit df99a1
   - Otherwise <nargs> must be <0>. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_format_t *
Packit df99a1
ddjvu_format_create(ddjvu_format_style_t style, 
Packit df99a1
                    int nargs, unsigned int *args);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_format_set_row_order ---
Packit df99a1
   Sets a flag indicating whether the rows in the pixel buffer
Packit df99a1
   are stored starting from the top or the bottom of the image.
Packit df99a1
   Default ordering starts from the bottom of the image.
Packit df99a1
   This is the opposite of the X11 convention. */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_format_set_row_order(ddjvu_format_t *format, int top_to_bottom);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_format_set_y_direction ---
Packit df99a1
   Sets a flag indicating whether the y coordinates in the drawing 
Packit df99a1
   area are oriented from bottom to top, or from top to botttom.  
Packit df99a1
   The default is bottom to top, similar to PostScript.
Packit df99a1
   This is the opposite of the X11 convention. */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_format_set_y_direction(ddjvu_format_t *format, int top_to_bottom);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_format_set_ditherbits ---
Packit df99a1
   Specifies the final depth of the image on the screen.
Packit df99a1
   This is used to decide which dithering algorithm should be used.
Packit df99a1
   The default is usually appropriate. */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_format_set_ditherbits(ddjvu_format_t *format, int bits);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_format_set_gamma ---
Packit df99a1
   Sets the gamma of the display for which the pixels are
Packit df99a1
   intended.  This will be combined with the gamma stored in
Packit df99a1
   DjVu documents in order to compute a suitable color
Packit df99a1
   correction.  The default value is 2.2. */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_format_set_gamma(ddjvu_format_t *format, double gamma);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_format_set_white ---
Packit df99a1
   Sets the whitepoint of the display for which the pixels are
Packit df99a1
   intended.  This will be combined with the gamma stored in
Packit df99a1
   DjVu documents in order to compute a suitable color
Packit df99a1
   correction.  The default value is 0xff,0xff,0xff. */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_format_set_white(ddjvu_format_t *format, 
Packit df99a1
                       unsigned char b, unsigned char g, unsigned char r);
Packit df99a1
Packit df99a1
/* ddjvu_format_release ---
Packit df99a1
   Release a reference to a <ddjvu_format_t> object.
Packit df99a1
   The calling program should no longer reference this object. */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_format_release(ddjvu_format_t *format);
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* THUMBNAILS                                         */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_thumbnail_status ---
Packit df99a1
   Determine whether a thumbnail is available for page <pagenum>.
Packit df99a1
   Calling this function with non zero argument <start> initiates
Packit df99a1
   a thumbnail calculation job. Regardless of its success,
Packit df99a1
   the completion of the job is signalled by a subsequent 
Packit df99a1
   <m_thumbnail> message. */
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_status_t
Packit df99a1
ddjvu_thumbnail_status(ddjvu_document_t *document, int pagenum, int start);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_t::m_thumbnail ---
Packit df99a1
   This message is sent when additional thumbnails are available. */
Packit df99a1
Packit df99a1
struct ddjvu_message_thumbnail_s { /* ddjvu_message_t::m_thumbnail */
Packit df99a1
  ddjvu_message_any_t  any;
Packit df99a1
  int pagenum;
Packit df99a1
}; 
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_thumbnail_render ---
Packit df99a1
   Renders a thumbnail for page <pagenum>.
Packit df99a1
   Argument <imagebuffer> must be large enough to contain
Packit df99a1
   an image of size <*wptr> by <*hptr> using pixel format
Packit df99a1
   <pixelformat>. Argument <rowsize> specifies the number 
Packit df99a1
   of BYTES from one row to the next in the buffer.
Packit df99a1
   This function returns <FALSE> when no thumbnail is available.
Packit df99a1
   Otherwise it returns <TRUE>, adjusts <*wptr> and <*hptr> to 
Packit df99a1
   reflect the thumbnail size, and, if the pointer <imagebuffer>
Packit df99a1
   is non zero, writes the pixel data into the image buffer. */
Packit df99a1
Packit df99a1
DDJVUAPI int
Packit df99a1
ddjvu_thumbnail_render(ddjvu_document_t *document, int pagenum, 
Packit df99a1
                       int *wptr, int *hptr,
Packit df99a1
                       const ddjvu_format_t *pixelformat,
Packit df99a1
                       unsigned long rowsize,
Packit df99a1
                       char *imagebuffer);
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* SAVE AND PRINT JOBS                                */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_message_t::m_progress ---
Packit df99a1
   These messages are generated to indicate progress 
Packit df99a1
   towards the completion of a print or save job. */
Packit df99a1
Packit df99a1
struct ddjvu_message_progress_s {
Packit df99a1
  ddjvu_message_any_t any;
Packit df99a1
  ddjvu_status_t status;
Packit df99a1
  int percent;
Packit df99a1
};
Packit df99a1
Packit df99a1
/* ddjvu_document_print ---
Packit df99a1
   Converts specified pages of a djvu document into postscript.  
Packit df99a1
   This function works asynchronously in a separate thread.
Packit df99a1
   You can use the following idiom for synchronous operation:
Packit df99a1
Packit df99a1
     ddjvu_job_t *job = ddjvu_document_print(....);
Packit df99a1
     while (! ddjvu_job_done(job) )
Packit df99a1
       handle_ddjvu_messages(context, TRUE);
Packit df99a1
       
Packit df99a1
   The postscript data is written to stdio file <output>.
Packit df99a1
   Arguments <optc> and <optv> specify printing options.
Packit df99a1
   All options described on the <djvups> man page are 
Packit df99a1
   recognized, except <"-help"> and <"-verbose">.
Packit df99a1
*/
Packit df99a1
Packit df99a1
DDJVUAPI ddjvu_job_t *
Packit df99a1
ddjvu_document_print(ddjvu_document_t *document, FILE *output,
Packit df99a1
                     int optc, const char * const * optv);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_save ---
Packit df99a1
   Saves the djvu document as a bundled djvu file.
Packit df99a1
   This function works asynchronously in a separate thread.
Packit df99a1
   You can use the following idiom for synchronous operation:
Packit df99a1
Packit df99a1
     ddjvu_job_t *job = ddjvu_document_save(....);
Packit df99a1
     while (! ddjvu_job_done(job) )
Packit df99a1
       handle_ddjvu_messages(context, TRUE);
Packit df99a1
     
Packit df99a1
   The bundled djvu data is written to file <output>
Packit df99a1
   which must be seekable. Arguments <optc> and <optv>
Packit df99a1
   can be used to pass the following options:
Packit df99a1
   * Option "-pages=<pagespec>" specify a subset of pages
Packit df99a1
     using the same syntax as program <ddjvu>.
Packit df99a1
     Reordering or duplicating pages is prohibited. 
Packit df99a1
   * Option "-indirect=<filename>" causes the creation
Packit df99a1
     of an indirect document with index file <filename>
Packit df99a1
     and auxiliary files in the same directory.
Packit df99a1
     The file name is UTF-8 encoded.
Packit df99a1
     When this option is specified, the argument <output>
Packit df99a1
     is ignored and should be NULL.
Packit df99a1
*/
Packit df99a1
DDJVUAPI ddjvu_job_t *
Packit df99a1
ddjvu_document_save(ddjvu_document_t *document, FILE *output, 
Packit df99a1
                    int optc, const char * const * optv);
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* S-EXPRESSIONS                                      */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* DjVu files can contain ancillary information such as
Packit df99a1
   document outline, hidden text, hyperlinks, and metadata.
Packit df99a1
   Program <djvused> provides for manipulating such
Packit df99a1
   information.  Like <djvused>, the DDJVU API represents
Packit df99a1
   this information using a lisp s-expressions.  See file
Packit df99a1
   <"libdjvu/miniexp.h"> for the s-expression documentation
Packit df99a1
   and manipulation functions.  See the <djvused> man page
Packit df99a1
   for the specification of the s-expressions representing
Packit df99a1
   outlines, hidden text and annotations. It often help 
Packit df99a1
   to print s-expressions using function <miniexp_pprint>.
Packit df99a1
Packit df99a1
   WARNING: All strings in s-expression are UTF-8 encoded.  
Packit df99a1
   Strings returned by miniexp_to_str might have to be 
Packit df99a1
   converted to the locale encoding. */
Packit df99a1
Packit df99a1
Packit df99a1
/* miniexp_t --
Packit df99a1
   Opaque type representing s-expressions.
Packit df99a1
   The same definition also appears in 
Packit df99a1
   file <"libdjvu/miniexp.h">. */
Packit df99a1
Packit df99a1
#ifndef MINIEXP_H
Packit df99a1
typedef struct miniexp_s* miniexp_t;
Packit df99a1
#endif
Packit df99a1
Packit df99a1
/* ddjvu_miniexp_release -- 
Packit df99a1
   This function controls the allocation of the
Packit df99a1
   s-expressions returned by functions from the DDJVU
Packit df99a1
   API. It indicates that the s-expression <expr> is no
Packit df99a1
   longer needed and can be deallocated as soon as
Packit df99a1
   necessary. Otherwise the s-expression remains allocated
Packit df99a1
   as long as the document object exists. */
Packit df99a1
Packit df99a1
DDJVUAPI void
Packit df99a1
ddjvu_miniexp_release(ddjvu_document_t *document, miniexp_t expr);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_get_outline -- 
Packit df99a1
   This function tries to obtain the document outline.  
Packit df99a1
   If this information is available, it returns a
Packit df99a1
   s-expression with the same syntax as function
Packit df99a1
   <print-outline> of program <djvused>.  
Packit df99a1
   Otherwise it returns <miniexp_dummy> until 
Packit df99a1
   the document header gets fully decoded.
Packit df99a1
   Typical synchronous usage:
Packit df99a1
Packit df99a1
    miniexp_t r;
Packit df99a1
    while ((r=ddjvu_document_get_outline(doc))==miniexp_dummy)
Packit df99a1
      handle_ddjvu_messages(ctx, TRUE); 
Packit df99a1
Packit df99a1
   This function returns the empty list <miniexp_nil> when
Packit df99a1
   the document contains no outline information. It can also
Packit df99a1
   return symbols <failed> or <stopped> when an error occurs
Packit df99a1
   while accessing the desired information. */
Packit df99a1
Packit df99a1
DDJVUAPI miniexp_t
Packit df99a1
ddjvu_document_get_outline(ddjvu_document_t *document);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_get_anno --
Packit df99a1
   This function returns the document-wide annotations.
Packit df99a1
   This corresponds to a proposed change in the djvu format.
Packit df99a1
   When no new-style document-wide annotations are available
Packit df99a1
   and <compat> is true, this function searches a shared 
Packit df99a1
   annotation chunk and returns its contents.
Packit df99a1
Packit df99a1
   This function returns <miniexp_dummy> if the information
Packit df99a1
   is not yet available. It may then cause the emission 
Packit df99a1
   of <m_pageinfo> messages with null <m_any.page>.
Packit df99a1
Packit df99a1
   This function returns the empty list <miniexp_nil> when
Packit df99a1
   the document does not contain page annotations. It can also
Packit df99a1
   return symbols <failed> or <stopped> when an error occurs
Packit df99a1
   while accessing the desired information. */
Packit df99a1
Packit df99a1
DDJVUAPI miniexp_t
Packit df99a1
ddjvu_document_get_anno(ddjvu_document_t *document, int compat);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_get_pagetext -- 
Packit df99a1
   This function tries to obtain the text information for
Packit df99a1
   page <pageno>. If this information is available, it
Packit df99a1
   returns a s-expression with the same syntax as function
Packit df99a1
   <print-txt> of program <djvused>.  Otherwise it starts
Packit df99a1
   fetching the page data and returns <miniexp_dummy>.
Packit df99a1
   This function causes the emission of <m_pageinfo> messages 
Packit df99a1
   with zero in the <m_any.page> field.
Packit df99a1
   Typical synchronous usage:
Packit df99a1
Packit df99a1
    miniexp_t r;
Packit df99a1
    while ((r=ddjvu_document_get_pagetext(doc,pageno,0))==miniexp_dummy)
Packit df99a1
      handle_ddjvu_messages(ctx, TRUE); 
Packit df99a1
Packit df99a1
   This function returns the empty list <miniexp_nil> when
Packit df99a1
   the page contains no text information. It can also return
Packit df99a1
   symbols <failed> or <stopped> when an error occurs while
Packit df99a1
   accessing the desired information. 
Packit df99a1
Packit df99a1
   Argument <maxdetail> controls the level of detail in the
Packit df99a1
   returned s-expression. Values "page", "column", "region", "para", 
Packit df99a1
   "line", and "word" restrict the output to the specified granularity.
Packit df99a1
   All other values produce a s-expression that represents
Packit df99a1
   the hidden text data as finely as possible. */
Packit df99a1
Packit df99a1
DDJVUAPI miniexp_t
Packit df99a1
ddjvu_document_get_pagetext(ddjvu_document_t *document, int pageno, 
Packit df99a1
                            const char *maxdetail);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_document_get_pageanno -- 
Packit df99a1
   This function tries to obtain the annotations for
Packit df99a1
   page <pageno>. If this information is available, it
Packit df99a1
   returns a s-expression with the same syntax as function
Packit df99a1
   <print-ant> of program <djvused>.  Otherwise it starts
Packit df99a1
   fetching the page data and returns <miniexp_dummy>.
Packit df99a1
   This function causes the emission of <m_pageinfo> messages 
Packit df99a1
   with zero in the <m_any.page> field.
Packit df99a1
   Typical synchronous usage:
Packit df99a1
Packit df99a1
     miniexp_t r;
Packit df99a1
     while ((r = ddjvu_document_get_pageanno(doc,pageno))==miniexp_dummy)
Packit df99a1
       handle_ddjvu_messages(ctx, TRUE); 
Packit df99a1
Packit df99a1
   This function returns the empty list <miniexp_nil> when
Packit df99a1
   the page contains no annotations. It can also return
Packit df99a1
   symbols <failed> or <stopped> when an error occurs while
Packit df99a1
   accessing the desired information. */
Packit df99a1
Packit df99a1
DDJVUAPI miniexp_t
Packit df99a1
ddjvu_document_get_pageanno(ddjvu_document_t *document, int pageno);
Packit df99a1
Packit df99a1
Packit df99a1
/* --- Helper functions to parse annotations --- */
Packit df99a1
Packit df99a1
/* ddjvu_anno_get_bgcolor --
Packit df99a1
   Parse the annotations and extracts the desired 
Packit df99a1
   background color as a color string ("#FFFFFF"). 
Packit df99a1
   See <(background ...)> in the djvused man page.
Packit df99a1
   Returns zero if this information is not specified. */
Packit df99a1
Packit df99a1
DDJVUAPI const char *
Packit df99a1
ddjvu_anno_get_bgcolor(miniexp_t annotations);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_anno_get_zoom --
Packit df99a1
   Parse the annotations and extracts the desired zoom factor.
Packit df99a1
   See <(zoom ...)> in the djvused man page.
Packit df99a1
   Returns zero if this information is not specified. */
Packit df99a1
Packit df99a1
DDJVUAPI const char *
Packit df99a1
ddjvu_anno_get_zoom(miniexp_t annotations);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_anno_get_mode --
Packit df99a1
   Parse the annotations and extracts the desired display mode.
Packit df99a1
   See <(mode ...)> in the djvused man page.
Packit df99a1
   Returns zero if this information is not specified. */
Packit df99a1
Packit df99a1
DDJVUAPI const char *
Packit df99a1
ddjvu_anno_get_mode(miniexp_t annotations);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_anno_get_horizalign --
Packit df99a1
   Parse the annotations and extracts how the page
Packit df99a1
   image should be aligned horizontally.
Packit df99a1
   See <(align ...)> in the djvused man page.
Packit df99a1
   Returns zero if this information is not specified. */
Packit df99a1
Packit df99a1
DDJVUAPI const char *
Packit df99a1
ddjvu_anno_get_horizalign(miniexp_t annotations);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_anno_get_vertalign --
Packit df99a1
   Parse the annotations and extracts how the page
Packit df99a1
   image should be aligned vertically.
Packit df99a1
   See <(align ...)> in the djvused man page.
Packit df99a1
   Returns zero if this information is not specified. */
Packit df99a1
Packit df99a1
DDJVUAPI const char *
Packit df99a1
ddjvu_anno_get_vertalign(miniexp_t annotations);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_anno_get_hyperlinks --
Packit df99a1
   Parse the annotations and returns a zero terminated 
Packit df99a1
   array of <(maparea ...)> s-expressions.
Packit df99a1
   The caller should free this array with function <free>.
Packit df99a1
   These s-expressions remain allocated as long
Packit df99a1
   as the annotations remain allocated.
Packit df99a1
   See also <(maparea ...)> in the djvused man page. */
Packit df99a1
Packit df99a1
DDJVUAPI miniexp_t *
Packit df99a1
ddjvu_anno_get_hyperlinks(miniexp_t annotations);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_anno_get_metadata_keys --
Packit df99a1
   Parse the annotations and returns a zero terminated 
Packit df99a1
   array of key symbols for the page metadata.
Packit df99a1
   The caller should free this array with function <free>.
Packit df99a1
   See also <(metadata ...)> in the djvused man page. */
Packit df99a1
Packit df99a1
DDJVUAPI miniexp_t *
Packit df99a1
ddjvu_anno_get_metadata_keys(miniexp_t annotations);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_anno_get_metadata --
Packit df99a1
   Parse the annotations and returns the metadata string
Packit df99a1
   corresponding to the metadata key symbol <key>.
Packit df99a1
   The string remains allocated as long as the 
Packit df99a1
   annotations s-expression remain allocated.
Packit df99a1
   Returns zero if no such key is present. */
Packit df99a1
Packit df99a1
DDJVUAPI const char *
Packit df99a1
ddjvu_anno_get_metadata(miniexp_t annotations, miniexp_t key);
Packit df99a1
Packit df99a1
Packit df99a1
/* ddjvu_anno_get_xmp --
Packit df99a1
   Parse the annotations and returns the xmp metadata string.
Packit df99a1
   The string remains allocated as long as the 
Packit df99a1
   annotations s-expression remain allocated.
Packit df99a1
   Returns zero if no such key is present. */
Packit df99a1
Packit df99a1
DDJVUAPI const char *
Packit df99a1
ddjvu_anno_get_xmp(miniexp_t annotations);
Packit df99a1
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* DJVU_MESSAGE_T                                     */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
Packit df99a1
/* We can now define the djvu_message_t union */
Packit df99a1
Packit df99a1
union ddjvu_message_s {
Packit df99a1
  struct ddjvu_message_any_s        m_any;
Packit df99a1
  struct ddjvu_message_error_s      m_error;
Packit df99a1
  struct ddjvu_message_info_s       m_info;
Packit df99a1
  struct ddjvu_message_newstream_s  m_newstream;
Packit df99a1
  struct ddjvu_message_docinfo_s    m_docinfo;
Packit df99a1
  struct ddjvu_message_pageinfo_s   m_pageinfo;
Packit df99a1
  struct ddjvu_message_chunk_s      m_chunk;
Packit df99a1
  struct ddjvu_message_relayout_s   m_relayout;
Packit df99a1
  struct ddjvu_message_redisplay_s  m_redisplay;
Packit df99a1
  struct ddjvu_message_thumbnail_s  m_thumbnail;
Packit df99a1
  struct ddjvu_message_progress_s   m_progress;
Packit df99a1
};
Packit df99a1
Packit df99a1
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
/* BACKDOORS                                          */
Packit df99a1
/* -------------------------------------------------- */
Packit df99a1
Packit df99a1
#ifdef __cplusplus
Packit df99a1
} // extern "C"
Packit df99a1
#endif
Packit df99a1
Packit df99a1
/* ddjvu_get_DjVuImage ---
Packit df99a1
   ddjvu_get_DjVuDocument ---
Packit df99a1
   These functions provide an access to the libdjvu objects 
Packit df99a1
   associated with the ddjvuapi objects.  These backdoors can
Packit df99a1
   be useful for advanced manipulations.  These two functions 
Packit df99a1
   are declared in C++ when file <"ddjvuapi.h"> is included 
Packit df99a1
   after the libdjvu header files <"DjVuImage.h"> and
Packit df99a1
   <"DjVuDocument.h">. */
Packit df99a1
Packit df99a1
#ifdef __cplusplus
Packit df99a1
# ifndef NOT_USING_DJVU_NAMESPACE
Packit df99a1
#  ifdef _DJVUIMAGE_H
Packit df99a1
DDJVUAPI GP<DjVuImage>
Packit df99a1
ddjvu_get_DjVuImage(ddjvu_page_t *page);
Packit df99a1
#  endif
Packit df99a1
#  ifdef _DJVUDOCUMENT_H
Packit df99a1
DDJVUAPI GP<DjVuDocument>
Packit df99a1
ddjvu_get_DjVuDocument(ddjvu_document_t *document);
Packit df99a1
#  endif
Packit df99a1
# endif
Packit df99a1
#endif
Packit df99a1
Packit df99a1
#endif /* DDJVUAPI_H */