CAPS Universe documentation  1.0.4
All you need to know to be successful
Data Structures | Functions | Variables
backend-mupdf.c File Reference

Backend to rasterize a PDF via the muPDF library. More...

Data Structures

struct  rasterizer_info
 

Functions

fz_stream * fz_open_file_ptr_no_close (fz_context *ctx, FILE *file)
 
static fz_stream * mupdf_attach_stream (struct caps_rasterizer *rstr, int *rc)
 
static int mupdf_init (struct caps_rasterizer *rstr)
 
static int mupdf_detach (struct caps_rasterizer *rstr)
 
static int mupdf_job_start (struct caps_rasterizer *rstr, unsigned *page_count)
 
static int _mupdf_page_number_get (const struct rstr_print_state *state)
 
static int mupdf_page_get_next (struct caps_rasterizer *rstr)
 
static fz_rect caps_rect_2_fz_rec (const struct caps_rect *rect)
 
static fz_matrix _fz_transform_matrix_create (struct caps_rect rect, double resx, double resy, double rotate)
 
static fz_rect caps_area_2_fz_rec (const struct caps_rect *sz, const struct caps_area *area)
 
static int mupdf_page_rasterize (struct caps_rasterizer *rstr, const struct caps_rstr_page *page_conf, struct raster_adapt_preparation *setup)
 
static int mupdf_image_get (struct caps_rasterizer *rstr, struct caps_rstr_raster *desc)
 
static const void * mupdf_line_get (struct caps_rasterizer *rstr, const struct caps_rstr_raster *desc, unsigned line_no)
 

Variables

const struct rstr_provider pdf_raserizer
 

Detailed Description

Author
Jürgen Borleis
Version
1.0.0
Warning
Use as experimental

Install

Provide a /usr/lib/pkgconfig/mupdf.pc:

Name: mupdf
Description: Library for rendering PDF documents
Requires.private: freetype2 jbig2dec libopenjp2 libjpeg harfbuzz
Version: 1.15.0
Libs: -L${libdir} -lmupdf
Libs.private: -lmupdf-third
Cflags: -I${includedir}

Or build the mupdf from its source repository. In this case it will be one huge monolitic block of code.

Function Documentation

◆ fz_open_file_ptr_no_close()

fz_stream * fz_open_file_ptr_no_close ( fz_context *  ctx,
FILE *  file 
)

We need access to this function, even if it isn't exported via the mupdf header file.
Used in mupdf_attach_stream()

◆ mupdf_attach_stream()

static fz_stream * mupdf_attach_stream ( struct caps_rasterizer rstr,
int *  rc 
)
static

Convert a regular file descriptor into what muPDF wants to access the document's file

Parameters
[in,out]rstrOur context
[out]rcNegative errno in case of a failure
Return values
PointerStream representation for muPDF
NULLIn case of a failure. In this case *rc contains a valid negative errno

In the CAPS universe the document is already open…as a file descriptor. In order to connect muPDF to it, we need a stream. And additionally a workaround.

muPDF doesn't support using an already open stream as its document input. But it has an internal function doing so. This function isn't exported via its API header file, but it is still available to link to.

This function wraps this feature for the case in future releases fz_open_file_ptr_no_close() isn't available anymore. Or its implementation changes over releases...

According to some header comments, there should be a function called fz_open_fd() … but it isn't.

◆ mupdf_init()

static int mupdf_init ( struct caps_rasterizer rstr)
static

Rasterizer specific implementation called by caps_rstr_job_attach()

Todo:

Antialiasing settings should follow INI file setting.

What are the limits of muPDF (regarding caps_rstr_page_limits)?

For coloured or grey scale it might makes sense to enable antialising. But for monochrome it doesn't make sense, it just confuses the halftone algorithms.

Note
For a halftone monochrome output, the best is to raster the image into grey scale raster with both antialising settings (text and graphics) to zero.

◆ mupdf_detach()

static int mupdf_detach ( struct caps_rasterizer rstr)
static

Rasterizer specific implementation called by caps_rstr_job_detach()

This will close the still open filedescriptor.

◆ mupdf_job_start()

static int mupdf_job_start ( struct caps_rasterizer rstr,
unsigned *  page_count 
)
static

Rasterizer specific implementation called by caps_rstr_job_attach()

◆ _mupdf_page_number_get()

static int _mupdf_page_number_get ( const struct rstr_print_state state)
static

Translate the pagenumber to be rasterized from CAPS to muPDF

Parameters
[in]stateThe current page state
Returns
Page number to rasterize in muPDF counting

The muPDF API counts from page 0

Precondition
rstr_print_state::current_page must be at least '1'

◆ mupdf_page_get_next()

static int mupdf_page_get_next ( struct caps_rasterizer rstr)
static

Rasterizer specific implementation called by caps_rstr_page_get_next()

Todo:
Ask libpaper for the medium format name and report its exact size instead (already done in the main library after calling this function)

◆ caps_rect_2_fz_rec()

static fz_rect caps_rect_2_fz_rec ( const struct caps_rect rect)
static

◆ _fz_transform_matrix_create()

static fz_matrix _fz_transform_matrix_create ( struct caps_rect  rect,
double  resx,
double  resy,
double  rotate 
)
static

Create a transformation matrix to convert the given rect into a raster

Parameters
[in]rectSource size, all units are [points]
[in]resxHorizontal resolution in [DPI]
[in]resyVertical resolution in [DPI]
[in]rotateRotation in [°]
Returns
Transformation matrix

◆ caps_area_2_fz_rec()

static fz_rect caps_area_2_fz_rec ( const struct caps_rect sz,
const struct caps_area area 
)
static

Convert our CAPS area structure into the muPDF 'fz_rect'

Parameters
[in]szThe full size the area is in
[in]areaThe CAPS area to convert
Returns
The muPDF rectangle

The muPDF 'fz_rect' is defined as four coordinates with floats, but its 0,0 coordinate is top/left in contrast to the bottom/left of the CAPS area.

◆ mupdf_page_rasterize()

static int mupdf_page_rasterize ( struct caps_rasterizer rstr,
const struct caps_rstr_page page_conf,
struct raster_adapt_preparation setup 
)
static

Rasterizer specific implementation called by caps_rstr_page_rasterize()

Note
The info in setup->source_sz might differ from the one we reported in caps_rstr_page_desc::medium_sz. This might happen due to unifying the size and names of well known formats. Refer medium_format_name_and_size_adapt()

◆ mupdf_image_get()

static int mupdf_image_get ( struct caps_rasterizer rstr,
struct caps_rstr_raster desc 
)
static

Rasterizer specific implementation called by caps_rstr_raster_get()

◆ mupdf_line_get()

static const void * mupdf_line_get ( struct caps_rasterizer rstr,
const struct caps_rstr_raster desc,
unsigned  line_no 
)
static

Rasterizer specific implementation called by caps_rstr_line_get()

Variable Documentation

◆ pdf_raserizer

const struct rstr_provider pdf_raserizer
Initial value:
= {
.name = "PDF rasterizer (muPDF)",
.init = mupdf_init,
.job_start = mupdf_job_start,
.page_next = mupdf_page_get_next,
.page_render = mupdf_page_rasterize,
.page_image_get = mupdf_image_get,
.line_get = mupdf_line_get,
.job_end = NULL,
.exit = mupdf_detach,
}
static int mupdf_image_get(struct caps_rasterizer *rstr, struct caps_rstr_raster *desc)
Definition: backend-mupdf.c:457
static int mupdf_job_start(struct caps_rasterizer *rstr, unsigned *page_count)
Definition: backend-mupdf.c:214
static const void * mupdf_line_get(struct caps_rasterizer *rstr, const struct caps_rstr_raster *desc, unsigned line_no)
Definition: backend-mupdf.c:477
static int mupdf_page_get_next(struct caps_rasterizer *rstr)
Definition: backend-mupdf.c:257
static int mupdf_detach(struct caps_rasterizer *rstr)
Definition: backend-mupdf.c:181
static int mupdf_init(struct caps_rasterizer *rstr)
Definition: backend-mupdf.c:116
static int mupdf_page_rasterize(struct caps_rasterizer *rstr, const struct caps_rstr_page *page_conf, struct raster_adapt_preparation *setup)
Definition: backend-mupdf.c:387
@ RSTRS_INHERIT_FILEDESC
Definition: libcapsraster-local.h:73