Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MuPDF version #142

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ save_to_png_output save_to_png(save_to_png_input input) {
page = pdf_load_page(ctx, doc, input.page);

float scale_factor = 1.5;
fz_rect bounds = pdf_bound_page(ctx, page);
fz_rect bounds = pdf_bound_page(ctx, page, FZ_CROP_BOX);
if (input.width != 0) {
scale_factor = input.width / bounds.x1;
} else if (input.scale != 0) {
Expand Down
9 changes: 7 additions & 2 deletions misc/mupdf/include/mupdf/fitz.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
//
// Alternative licensing terms are available from the licensor.
// For commercial licensing, see <https://www.artifex.com/> or contact
// Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato,
// CA 94945, U.S.A., +1(415)492-9861, for further information.
// Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
// CA 94129, USA, for further information.

#ifndef MUDPF_FITZ_H
#define MUDPF_FITZ_H
Expand Down Expand Up @@ -51,6 +51,8 @@ extern "C" {
#include "mupdf/fitz/compressed-buffer.h"
#include "mupdf/fitz/filter.h"
#include "mupdf/fitz/archive.h"
#include "mupdf/fitz/heap.h"


/* Resources */
#include "mupdf/fitz/store.h"
Expand Down Expand Up @@ -85,6 +87,9 @@ extern "C" {
#include "mupdf/fitz/write-pixmap.h"
#include "mupdf/fitz/output-svg.h"

#include "mupdf/fitz/story.h"
#include "mupdf/fitz/story-writer.h"

#ifdef __cplusplus
}
#endif
Expand Down
174 changes: 163 additions & 11 deletions misc/mupdf/include/mupdf/fitz/archive.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2004-2021 Artifex Software, Inc.
// Copyright (C) 2004-2022 Artifex Software, Inc.
//
// This file is part of MuPDF.
//
Expand All @@ -17,8 +17,8 @@
//
// Alternative licensing terms are available from the licensor.
// For commercial licensing, see <https://www.artifex.com/> or contact
// Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato,
// CA 94945, U.S.A., +1(415)492-9861, for further information.
// Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
// CA 94129, USA, for further information.

#ifndef MUPDF_FITZ_ARCHIVE_H
#define MUPDF_FITZ_ARCHIVE_H
Expand All @@ -27,6 +27,7 @@
#include "mupdf/fitz/context.h"
#include "mupdf/fitz/buffer.h"
#include "mupdf/fitz/stream.h"
#include "mupdf/fitz/tree.h"

/* PUBLIC API */

Expand Down Expand Up @@ -61,6 +62,15 @@ fz_archive *fz_open_archive(fz_context *ctx, const char *filename);
*/
fz_archive *fz_open_archive_with_stream(fz_context *ctx, fz_stream *file);

/**
Open zip or tar archive stream.

Does the same as fz_open_archive_with_stream, but will not throw
an error in the event of failing to recognise the format. Will
still throw errors in other cases though!
*/
fz_archive *fz_try_open_archive_with_stream(fz_context *ctx, fz_stream *file);

/**
Open a directory as if it was an archive.

Expand All @@ -78,17 +88,26 @@ fz_archive *fz_open_directory(fz_context *ctx, const char *path);

/**
Determine if a given path is a directory.

In the case of the path not existing, or having no access
we will return 0.
*/
int fz_is_directory(fz_context *ctx, const char *path);

/**
Drop the reference to an archive.
Drop a reference to an archive.

Closes and releases any memory or filehandles associated
with the archive.
When the last reference is dropped, this closes and releases
any memory or filehandles associated with the archive.
*/
void fz_drop_archive(fz_context *ctx, fz_archive *arch);

/**
Keep a reference to an archive.
*/
fz_archive *
fz_keep_archive(fz_context *ctx, fz_archive *arch);

/**
Return a pointer to a string describing the format of the
archive.
Expand Down Expand Up @@ -137,33 +156,71 @@ int fz_has_archive_entry(fz_context *ctx, fz_archive *arch, const char *name);

name: Entry name to look for, this must be an exact match to
the entry name in the archive.

Throws an exception if a matching entry cannot be found.
*/
fz_stream *fz_open_archive_entry(fz_context *ctx, fz_archive *arch, const char *name);

/**
Opens an archive entry as a stream.

Returns NULL if a matching entry cannot be found, otherwise
behaves exactly as fz_open_archive_entry.
*/
fz_stream *fz_try_open_archive_entry(fz_context *ctx, fz_archive *arch, const char *name);

/**
Reads all bytes in an archive entry
into a buffer.

name: Entry name to look for, this must be an exact match to
the entry name in the archive.

Throws an exception if a matching entry cannot be found.
*/
fz_buffer *fz_read_archive_entry(fz_context *ctx, fz_archive *arch, const char *name);

/**
Reads all bytes in an archive entry
into a buffer.

name: Entry name to look for, this must be an exact match to
the entry name in the archive.

Returns NULL if a matching entry cannot be found. Otherwise behaves
the same as fz_read_archive_entry. Exceptions may be thrown.
*/
fz_buffer *fz_try_read_archive_entry(fz_context *ctx, fz_archive *arch, const char *name);

/**
fz_archive: tar implementation
*/

/**
Detect if stream object is a tar achieve.
Detect if stream object is a tar archive.

Assumes that the stream object is seekable.
*/
int fz_is_tar_archive(fz_context *ctx, fz_stream *file);

/**
Detect if stream object is an archive supported by libarchive.

Assumes that the stream object is seekable.
*/
int fz_is_libarchive_archive(fz_context *ctx, fz_stream *file);

/**
Detect if stream object is a cfb archive.

Assumes that the stream object is seekable.
*/
int fz_is_cfb_archive(fz_context *ctx, fz_stream *file);

/**
Open a tar archive file.

An exception is throw if the file is not a tar archive as
An exception is thrown if the file is not a tar archive as
indicated by the presence of a tar signature.

filename: a path to a tar archive file as it would be given to
Expand All @@ -177,12 +234,52 @@ fz_archive *fz_open_tar_archive(fz_context *ctx, const char *filename);
Open an archive using a seekable stream object rather than
opening a file or directory on disk.

An exception is throw if the stream is not a tar archive as
An exception is thrown if the stream is not a tar archive as
indicated by the presence of a tar signature.

*/
fz_archive *fz_open_tar_archive_with_stream(fz_context *ctx, fz_stream *file);

/**
Open an archive using libarchive.

An exception is thrown if the file is not supported by libarchive.

filename: a path to an archive file as it would be given to
open(2).
*/
fz_archive *fz_open_libarchive_archive(fz_context *ctx, const char *filename);

/**
Open an archive using libarchive.

Open an archive using a seekable stream object rather than
opening a file or directory on disk.

An exception is thrown if the stream is not supported by libarchive.
*/
fz_archive *fz_open_libarchive_archive_with_stream(fz_context *ctx, fz_stream *file);

/**
Open a cfb file as an archive.

An exception is thrown if the file is not recognised as a cfb.

filename: a path to an archive file as it would be given to
open(2).
*/
fz_archive *fz_open_cfb_archive(fz_context *ctx, const char *filename);

/**
Open a cfb file as an archive.

Open an archive using a seekable stream object rather than
opening a file or directory on disk.

An exception is thrown if the file is not recognised as a chm.
*/
fz_archive *fz_open_cfb_archive_with_stream(fz_context *ctx, fz_stream *file);

/**
fz_archive: zip implementation
*/
Expand All @@ -197,7 +294,7 @@ int fz_is_zip_archive(fz_context *ctx, fz_stream *file);
/**
Open a zip archive file.

An exception is throw if the file is not a zip archive as
An exception is thrown if the file is not a zip archive as
indicated by the presence of a zip signature.

filename: a path to a zip archive file as it would be given to
Expand All @@ -211,7 +308,7 @@ fz_archive *fz_open_zip_archive(fz_context *ctx, const char *path);
Open an archive using a seekable stream object rather than
opening a file or directory on disk.

An exception is throw if the stream is not a zip archive as
An exception is thrown if the stream is not a zip archive as
indicated by the presence of a zip signature.

*/
Expand Down Expand Up @@ -265,13 +362,68 @@ void fz_close_zip_writer(fz_context *ctx, fz_zip_writer *zip);
*/
void fz_drop_zip_writer(fz_context *ctx, fz_zip_writer *zip);

/**
Create an archive that holds named buffers.

tree can either be a preformed tree with fz_buffers as values,
or it can be NULL for an empty tree.
*/
fz_archive *fz_new_tree_archive(fz_context *ctx, fz_tree *tree);

/**
Add a named buffer to an existing tree archive.

The tree will take a new reference to the buffer. Ownership
is not transferred.
*/
void fz_tree_archive_add_buffer(fz_context *ctx, fz_archive *arch_, const char *name, fz_buffer *buf);

/**
Add a named block of data to an existing tree archive.

The data will be copied into a buffer, and so the caller
may free it as soon as this returns.
*/
void fz_tree_archive_add_data(fz_context *ctx, fz_archive *arch_, const char *name, const void *data, size_t size);

/**
Create a new multi archive (initially empty).
*/
fz_archive *fz_new_multi_archive(fz_context *ctx);

/**
Add an archive to the set of archives handled by a multi
archive.

If path is NULL, then the archive contents will appear at the
top level, otherwise, the archives contents will appear prefixed
by path.
*/
void fz_mount_multi_archive(fz_context *ctx, fz_archive *arch_, fz_archive *sub, const char *path);

typedef int (fz_recognize_archive_fn)(fz_context *, fz_stream *);
typedef fz_archive *(fz_open_archive_fn)(fz_context *, fz_stream *);

typedef struct
{
fz_recognize_archive_fn *recognize;
fz_open_archive_fn *open;
}
fz_archive_handler;

FZ_DATA extern const fz_archive_handler fz_libarchive_archive_handler;

void fz_register_archive_handler(fz_context *ctx, const fz_archive_handler *handler);

/**
Implementation details: Subject to change.
*/

struct fz_archive
{
int refs;
fz_stream *file;

const char *format;

void (*drop_archive)(fz_context *ctx, fz_archive *arch);
Expand Down
14 changes: 12 additions & 2 deletions misc/mupdf/include/mupdf/fitz/band-writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
//
// Alternative licensing terms are available from the licensor.
// For commercial licensing, see <https://www.artifex.com/> or contact
// Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato,
// CA 94945, U.S.A., +1(415)492-9861, for further information.
// Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
// CA 94129, USA, for further information.

#ifndef MUPDF_FITZ_BAND_WRITER_H
#define MUPDF_FITZ_BAND_WRITER_H

#include "mupdf/fitz/system.h"
#include "mupdf/fitz/context.h"
#include "mupdf/fitz/output.h"
#include "mupdf/fitz/color.h"
#include "mupdf/fitz/separation.h"

/**
fz_band_writer
Expand Down Expand Up @@ -66,6 +68,12 @@ void fz_write_header(fz_context *ctx, fz_band_writer *writer, int w, int h, int
*/
void fz_write_band(fz_context *ctx, fz_band_writer *writer, int stride, int band_height, const unsigned char *samples);

/**
Finishes up the output and closes the band writer. After this
call no more headers or bands may be written.
*/
void fz_close_band_writer(fz_context *ctx, fz_band_writer *writer);

/**
Drop the reference to the band writer, causing it to be
destroyed.
Expand All @@ -79,11 +87,13 @@ void fz_drop_band_writer(fz_context *ctx, fz_band_writer *writer);
typedef void (fz_write_header_fn)(fz_context *ctx, fz_band_writer *writer, fz_colorspace *cs);
typedef void (fz_write_band_fn)(fz_context *ctx, fz_band_writer *writer, int stride, int band_start, int band_height, const unsigned char *samples);
typedef void (fz_write_trailer_fn)(fz_context *ctx, fz_band_writer *writer);
typedef void (fz_close_band_writer_fn)(fz_context *ctx, fz_band_writer *writer);
typedef void (fz_drop_band_writer_fn)(fz_context *ctx, fz_band_writer *writer);

struct fz_band_writer
{
fz_drop_band_writer_fn *drop;
fz_close_band_writer_fn *close;
fz_write_header_fn *header;
fz_write_band_fn *band;
fz_write_trailer_fn *trailer;
Expand Down
1 change: 1 addition & 0 deletions misc/mupdf/include/mupdf/fitz/bidi.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define FITZ_BIDI_H

#include "mupdf/fitz/system.h"
#include "mupdf/fitz/context.h"

/* Implementation details: subject to change. */

Expand Down
Loading