From 8577a7cf12ccdb258b773a03471663952fd12a4c Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 13 Jan 2017 13:20:59 +0100 Subject: Fix 697476: Rename header files. Xcode has an idiotic default configuration where it gets confused by include search paths and file names in projects, so that it will load our "mupdf/fitz/math.h" instead of the system . Work around this by renaming header files that have the same base name as a system header (even though they live in a subdirectory, and should never be available directly on the compiler's include path). --- include/mupdf/fitz.h | 4 +- include/mupdf/fitz/annotation.h | 2 +- include/mupdf/fitz/context.h | 2 +- include/mupdf/fitz/device.h | 2 +- include/mupdf/fitz/display-list.h | 2 +- include/mupdf/fitz/document.h | 2 +- include/mupdf/fitz/font.h | 2 +- include/mupdf/fitz/geometry.h | 665 +++++++++++++++++++++++++++++++++++ include/mupdf/fitz/glyph-cache.h | 2 +- include/mupdf/fitz/glyph.h | 2 +- include/mupdf/fitz/link.h | 2 +- include/mupdf/fitz/math.h | 665 ----------------------------------- include/mupdf/fitz/output.h | 2 +- include/mupdf/fitz/path.h | 2 +- include/mupdf/fitz/pixmap.h | 2 +- include/mupdf/fitz/shade.h | 2 +- include/mupdf/fitz/string-util.h | 160 +++++++++ include/mupdf/fitz/string.h | 160 --------- include/mupdf/fitz/structured-text.h | 2 +- include/mupdf/fitz/util.h | 2 +- platform/win32/libmupdf.vcproj | 10 +- source/fitz/glyph-cache-imp.h | 2 +- source/fitz/stream-prog.c | 2 +- 23 files changed, 849 insertions(+), 849 deletions(-) create mode 100644 include/mupdf/fitz/geometry.h delete mode 100644 include/mupdf/fitz/math.h create mode 100644 include/mupdf/fitz/string-util.h delete mode 100644 include/mupdf/fitz/string.h diff --git a/include/mupdf/fitz.h b/include/mupdf/fitz.h index 902f1bf8..54cc6904 100644 --- a/include/mupdf/fitz.h +++ b/include/mupdf/fitz.h @@ -12,10 +12,10 @@ extern "C" { #include "mupdf/fitz/crypt.h" #include "mupdf/fitz/getopt.h" +#include "mupdf/fitz/geometry.h" #include "mupdf/fitz/hash.h" -#include "mupdf/fitz/math.h" #include "mupdf/fitz/pool.h" -#include "mupdf/fitz/string.h" +#include "mupdf/fitz/string-util.h" #include "mupdf/fitz/tree.h" #include "mupdf/fitz/ucdn.h" #include "mupdf/fitz/bidi.h" diff --git a/include/mupdf/fitz/annotation.h b/include/mupdf/fitz/annotation.h index 79df092d..b602409f 100644 --- a/include/mupdf/fitz/annotation.h +++ b/include/mupdf/fitz/annotation.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" #include "mupdf/fitz/document.h" /* diff --git a/include/mupdf/fitz/context.h b/include/mupdf/fitz/context.h index 0c0ee78f..30333a91 100644 --- a/include/mupdf/fitz/context.h +++ b/include/mupdf/fitz/context.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/version.h" #include "mupdf/fitz/system.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" /* Contexts diff --git a/include/mupdf/fitz/device.h b/include/mupdf/fitz/device.h index eab5f3e2..074d9ded 100644 --- a/include/mupdf/fitz/device.h +++ b/include/mupdf/fitz/device.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" #include "mupdf/fitz/colorspace.h" #include "mupdf/fitz/image.h" #include "mupdf/fitz/shade.h" diff --git a/include/mupdf/fitz/display-list.h b/include/mupdf/fitz/display-list.h index 916ced70..e408f943 100644 --- a/include/mupdf/fitz/display-list.h +++ b/include/mupdf/fitz/display-list.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" #include "mupdf/fitz/device.h" /* diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h index dce7a76c..cc95c0a7 100644 --- a/include/mupdf/fitz/document.h +++ b/include/mupdf/fitz/document.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" #include "mupdf/fitz/device.h" #include "mupdf/fitz/transition.h" #include "mupdf/fitz/link.h" diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h index dd624de1..50092278 100644 --- a/include/mupdf/fitz/font.h +++ b/include/mupdf/fitz/font.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" #include "mupdf/fitz/buffer.h" /* forward declaration for circular dependency */ diff --git a/include/mupdf/fitz/geometry.h b/include/mupdf/fitz/geometry.h new file mode 100644 index 00000000..8b38b15b --- /dev/null +++ b/include/mupdf/fitz/geometry.h @@ -0,0 +1,665 @@ +#ifndef MUPDF_FITZ_MATH_H +#define MUPDF_FITZ_MATH_H + +#include "mupdf/fitz/system.h" + +/* + Multiply scaled two integers in the 0..255 range +*/ +static inline int fz_mul255(int a, int b) +{ + /* see Jim Blinn's book "Dirty Pixels" for how this works */ + int x = a * b + 128; + x += x >> 8; + return x >> 8; +} + +/* + Expand a value A from the 0...255 range to the 0..256 range +*/ +#define FZ_EXPAND(A) ((A)+((A)>>7)) + +/* + Combine values A (in any range) and B (in the 0..256 range), + to give a single value in the same range as A was. +*/ +#define FZ_COMBINE(A,B) (((A)*(B))>>8) + +/* + Combine values A and C (in the same (any) range) and B and D (in + the 0..256 range), to give a single value in the same range as A + and C were. +*/ +#define FZ_COMBINE2(A,B,C,D) (((A) * (B) + (C) * (D))>>8) + +/* + Blend SRC and DST (in the same range) together according to + AMOUNT (in the 0...256 range). +*/ +#define FZ_BLEND(SRC, DST, AMOUNT) ((((SRC)-(DST))*(AMOUNT) + ((DST)<<8))>>8) + +/* + Range checking atof +*/ +float fz_atof(const char *s); + +/* + atoi that copes with NULL +*/ +int fz_atoi(const char *s); + +fz_off_t fz_atoo(const char *s); + +/* + Some standard math functions, done as static inlines for speed. + People with compilers that do not adequately implement inlines may + like to reimplement these using macros. +*/ +static inline float fz_abs(float f) +{ + return (f < 0 ? -f : f); +} + +static inline int fz_absi(int i) +{ + return (i < 0 ? -i : i); +} + +static inline float fz_min(float a, float b) +{ + return (a < b ? a : b); +} + +static inline int fz_mini(int a, int b) +{ + return (a < b ? a : b); +} + +static inline size_t fz_minz(size_t a, size_t b) +{ + return (a < b ? a : b); +} + +static inline float fz_max(float a, float b) +{ + return (a > b ? a : b); +} + +static inline int fz_maxi(int a, int b) +{ + return (a > b ? a : b); +} + +static inline fz_off_t fz_maxo(fz_off_t a, fz_off_t b) +{ + return (a > b ? a : b); +} + +static inline float fz_clamp(float f, float min, float max) +{ + return (f > min ? (f < max ? f : max) : min); +} + +static inline int fz_clampi(int i, int min, int max) +{ + return (i > min ? (i < max ? i : max) : min); +} + +static inline double fz_clampd(double d, double min, double max) +{ + return (d > min ? (d < max ? d : max) : min); +} + +static inline void *fz_clampp(void *p, void *min, void *max) +{ + return (p > min ? (p < max ? p : max) : min); +} + +#define DIV_BY_ZERO(a, b, min, max) (((a) < 0) ^ ((b) < 0) ? (min) : (max)) + +/* + fz_point is a point in a two-dimensional space. +*/ +typedef struct fz_point_s fz_point; +struct fz_point_s +{ + float x, y; +}; + +/* + fz_rect is a rectangle represented by two diagonally opposite + corners at arbitrary coordinates. + + Rectangles are always axis-aligned with the X- and Y- axes. + The relationship between the coordinates are that x0 <= x1 and + y0 <= y1 in all cases except for infinite rectangles. The area + of a rectangle is defined as (x1 - x0) * (y1 - y0). If either + x0 > x1 or y0 > y1 is true for a given rectangle then it is + defined to be infinite. + + To check for empty or infinite rectangles use fz_is_empty_rect + and fz_is_infinite_rect. + + x0, y0: The top left corner. + + x1, y1: The bottom right corner. +*/ +typedef struct fz_rect_s fz_rect; +struct fz_rect_s +{ + float x0, y0; + float x1, y1; +}; + +/* + fz_rect_min: get the minimum point from a rectangle as an fz_point. +*/ +static inline fz_point *fz_rect_min(fz_rect *f) +{ + return (fz_point *)&f->x0; +} + +/* + fz_rect_max: get the maximum point from a rectangle as an fz_point. +*/ +static inline fz_point *fz_rect_max(fz_rect *f) +{ + return (fz_point *)&f->x1; +} + +/* + fz_irect is a rectangle using integers instead of floats. + + It's used in the draw device and for pixmap dimensions. +*/ +typedef struct fz_irect_s fz_irect; +struct fz_irect_s +{ + int x0, y0; + int x1, y1; +}; + +/* + A rectangle with sides of length one. + + The bottom left corner is at (0, 0) and the top right corner + is at (1, 1). +*/ +extern const fz_rect fz_unit_rect; + +/* + An empty rectangle with an area equal to zero. + + Both the top left and bottom right corner are at (0, 0). +*/ +extern const fz_rect fz_empty_rect; +extern const fz_irect fz_empty_irect; + +/* + An infinite rectangle with negative area. + + The corner (x0, y0) is at (1, 1) while the corner (x1, y1) is + at (-1, -1). +*/ +extern const fz_rect fz_infinite_rect; +extern const fz_irect fz_infinite_irect; + +/* + fz_is_empty_rect: Check if rectangle is empty. + + An empty rectangle is defined as one whose area is zero. +*/ +static inline int +fz_is_empty_rect(const fz_rect *r) +{ + return ((r)->x0 == (r)->x1 || (r)->y0 == (r)->y1); +} + +static inline int +fz_is_empty_irect(const fz_irect *r) +{ + return ((r)->x0 == (r)->x1 || (r)->y0 == (r)->y1); +} + +/* + fz_is_infinite_rect: Check if rectangle is infinite. + + An infinite rectangle is defined as one where either of the + two relationships between corner coordinates are not true. +*/ +static inline int +fz_is_infinite_rect(const fz_rect *r) +{ + return ((r)->x0 > (r)->x1 || (r)->y0 > (r)->y1); +} + +/* + fz_is_infinite_irect: Check if an integer rectangle + is infinite. + + An infinite rectangle is defined as one where either of the + two relationships between corner coordinates are not true. +*/ +static inline int +fz_is_infinite_irect(const fz_irect *r) +{ + return ((r)->x0 > (r)->x1 || (r)->y0 > (r)->y1); +} + +/* + fz_matrix is a a row-major 3x3 matrix used for representing + transformations of coordinates throughout MuPDF. + + Since all points reside in a two-dimensional space, one vector + is always a constant unit vector; hence only some elements may + vary in a matrix. Below is how the elements map between + different representations. + + / a b 0 \ + | c d 0 | normally represented as [ a b c d e f ]. + \ e f 1 / +*/ +typedef struct fz_matrix_s fz_matrix; +struct fz_matrix_s +{ + float a, b, c, d, e, f; +}; + +/* + fz_identity: Identity transform matrix. +*/ +extern const fz_matrix fz_identity; + +static inline fz_matrix *fz_copy_matrix(fz_matrix *restrict m, const fz_matrix *restrict s) +{ + *m = *s; + return m; +} + +/* + fz_concat: Multiply two matrices. + + The order of the two matrices are important since matrix + multiplication is not commutative. + + Returns result. + + Does not throw exceptions. +*/ +fz_matrix *fz_concat(fz_matrix *result, const fz_matrix *left, const fz_matrix *right); + +/* + fz_scale: Create a scaling matrix. + + The returned matrix is of the form [ sx 0 0 sy 0 0 ]. + + m: Pointer to the matrix to populate + + sx, sy: Scaling factors along the X- and Y-axes. A scaling + factor of 1.0 will not cause any scaling along the relevant + axis. + + Returns m. + + Does not throw exceptions. +*/ +fz_matrix *fz_scale(fz_matrix *m, float sx, float sy); + +/* + fz_pre_scale: Scale a matrix by premultiplication. + + m: Pointer to the matrix to scale + + sx, sy: Scaling factors along the X- and Y-axes. A scaling + factor of 1.0 will not cause any scaling along the relevant + axis. + + Returns m (updated). + + Does not throw exceptions. +*/ +fz_matrix *fz_pre_scale(fz_matrix *m, float sx, float sy); + +/* + fz_post_scale: Scale a matrix by postmultiplication. + + m: Pointer to the matrix to scale + + sx, sy: Scaling factors along the X- and Y-axes. A scaling + factor of 1.0 will not cause any scaling along the relevant + axis. + + Returns m (updated). + + Does not throw exceptions. +*/ +fz_matrix *fz_post_scale(fz_matrix *m, float sx, float sy); + +/* + fz_shear: Create a shearing matrix. + + The returned matrix is of the form [ 1 sy sx 1 0 0 ]. + + m: pointer to place to store returned matrix + + sx, sy: Shearing factors. A shearing factor of 0.0 will not + cause any shearing along the relevant axis. + + Returns m. + + Does not throw exceptions. +*/ +fz_matrix *fz_shear(fz_matrix *m, float sx, float sy); + +/* + fz_pre_shear: Premultiply a matrix with a shearing matrix. + + The shearing matrix is of the form [ 1 sy sx 1 0 0 ]. + + m: pointer to matrix to premultiply + + sx, sy: Shearing factors. A shearing factor of 0.0 will not + cause any shearing along the relevant axis. + + Returns m (updated). + + Does not throw exceptions. +*/ +fz_matrix *fz_pre_shear(fz_matrix *m, float sx, float sy); + +/* + fz_rotate: Create a rotation matrix. + + The returned matrix is of the form + [ cos(deg) sin(deg) -sin(deg) cos(deg) 0 0 ]. + + m: Pointer to place to store matrix + + degrees: Degrees of counter clockwise rotation. Values less + than zero and greater than 360 are handled as expected. + + Returns m. + + Does not throw exceptions. +*/ +fz_matrix *fz_rotate(fz_matrix *m, float degrees); + +/* + fz_pre_rotate: Rotate a transformation by premultiplying. + + The premultiplied matrix is of the form + [ cos(deg) sin(deg) -sin(deg) cos(deg) 0 0 ]. + + m: Pointer to matrix to premultiply. + + degrees: Degrees of counter clockwise rotation. Values less + than zero and greater than 360 are handled as expected. + + Returns m (updated). + + Does not throw exceptions. +*/ +fz_matrix *fz_pre_rotate(fz_matrix *m, float degrees); + +/* + fz_translate: Create a translation matrix. + + The returned matrix is of the form [ 1 0 0 1 tx ty ]. + + m: A place to store the created matrix. + + tx, ty: Translation distances along the X- and Y-axes. A + translation of 0 will not cause any translation along the + relevant axis. + + Returns m. + + Does not throw exceptions. +*/ +fz_matrix *fz_translate(fz_matrix *m, float tx, float ty); + +/* + fz_pre_translate: Translate a matrix by premultiplication. + + m: The matrix to translate + + tx, ty: Translation distances along the X- and Y-axes. A + translation of 0 will not cause any translation along the + relevant axis. + + Returns m. + + Does not throw exceptions. +*/ +fz_matrix *fz_pre_translate(fz_matrix *m, float tx, float ty); + +/* + fz_invert_matrix: Create an inverse matrix. + + inverse: Place to store inverse matrix. + + matrix: Matrix to invert. A degenerate matrix, where the + determinant is equal to zero, can not be inverted and the + original matrix is returned instead. + + Returns inverse. + + Does not throw exceptions. +*/ +fz_matrix *fz_invert_matrix(fz_matrix *inverse, const fz_matrix *matrix); + +/* + fz_try_invert_matrix: Attempt to create an inverse matrix. + + inverse: Place to store inverse matrix. + + matrix: Matrix to invert. A degenerate matrix, where the + determinant is equal to zero, can not be inverted. + + Returns 1 if matrix is degenerate (singular), or 0 otherwise. + + Does not throw exceptions. +*/ + int fz_try_invert_matrix(fz_matrix *inverse, const fz_matrix *matrix); + +/* + fz_is_rectilinear: Check if a transformation is rectilinear. + + Rectilinear means that no shearing is present and that any + rotations present are a multiple of 90 degrees. Usually this + is used to make sure that axis-aligned rectangles before the + transformation are still axis-aligned rectangles afterwards. + + Does not throw exceptions. +*/ +int fz_is_rectilinear(const fz_matrix *m); + +/* + fz_matrix_expansion: Calculate average scaling factor of matrix. +*/ +float fz_matrix_expansion(const fz_matrix *m); /* sumatrapdf */ + +/* + fz_intersect_rect: Compute intersection of two rectangles. + + Given two rectangles, update the first to be the smallest + axis-aligned rectangle that covers the area covered by both + given rectangles. If either rectangle is empty then the + intersection is also empty. If either rectangle is infinite + then the intersection is simply the non-infinite rectangle. + Should both rectangles be infinite, then the intersection is + also infinite. + + Does not throw exceptions. +*/ +fz_rect *fz_intersect_rect(fz_rect *restrict a, const fz_rect *restrict b); + +/* + fz_intersect_irect: Compute intersection of two bounding boxes. + + Similar to fz_intersect_rect but operates on two bounding + boxes instead of two rectangles. + + Does not throw exceptions. +*/ +fz_irect *fz_intersect_irect(fz_irect *restrict a, const fz_irect *restrict b); + +/* + fz_union_rect: Compute union of two rectangles. + + Given two rectangles, update the first to be the smallest + axis-aligned rectangle that encompasses both given rectangles. + If either rectangle is infinite then the union is also infinite. + If either rectangle is empty then the union is simply the + non-empty rectangle. Should both rectangles be empty, then the + union is also empty. + + Does not throw exceptions. +*/ +fz_rect *fz_union_rect(fz_rect *restrict a, const fz_rect *restrict b); + +/* + fz_irect_from_rect: Convert a rect into the minimal bounding box + that covers the rectangle. + + bbox: Place to store the returned bbox. + + rect: The rectangle to convert to a bbox. + + Coordinates in a bounding box are integers, so rounding of the + rects coordinates takes place. The top left corner is rounded + upwards and left while the bottom right corner is rounded + downwards and to the right. + + Returns bbox (updated). + + Does not throw exceptions. +*/ + +fz_irect *fz_irect_from_rect(fz_irect *restrict bbox, const fz_rect *restrict rect); + +/* + fz_round_rect: Round rectangle coordinates. + + Coordinates in a bounding box are integers, so rounding of the + rects coordinates takes place. The top left corner is rounded + upwards and left while the bottom right corner is rounded + downwards and to the right. + + This differs from fz_irect_from_rect, in that fz_irect_from_rect + slavishly follows the numbers (i.e any slight over/under calculations + can cause whole extra pixels to be added). fz_round_rect + allows for a small amount of rounding error when calculating + the bbox. + + Does not throw exceptions. +*/ +fz_irect *fz_round_rect(fz_irect *restrict bbox, const fz_rect *restrict rect); + +/* + fz_rect_from_irect: Convert a bbox into a rect. + + For our purposes, a rect can represent all the values we meet in + a bbox, so nothing can go wrong. + + rect: A place to store the generated rectangle. + + bbox: The bbox to convert. + + Returns rect (updated). + + Does not throw exceptions. +*/ +fz_rect *fz_rect_from_irect(fz_rect *restrict rect, const fz_irect *restrict bbox); + +/* + fz_expand_rect: Expand a bbox by a given amount in all directions. + + Does not throw exceptions. +*/ +fz_rect *fz_expand_rect(fz_rect *b, float expand); + +/* + fz_include_point_in_rect: Expand a bbox to include a given point. + To create a rectangle that encompasses a sequence of points, the + rectangle must first be set to be the empty rectangle at one of + the points before including the others. +*/ +fz_rect *fz_include_point_in_rect(fz_rect *r, const fz_point *p); + +/* + fz_translate_irect: Translate bounding box. + + Translate a bbox by a given x and y offset. Allows for overflow. + + Does not throw exceptions. +*/ +fz_irect *fz_translate_irect(fz_irect *a, int xoff, int yoff); + +/* + fz_contains_rect: Test rectangle inclusion. + + Return true if a entirely contains b. + + Does not throw exceptions. +*/ +int fz_contains_rect(const fz_rect *a, const fz_rect *b); + +/* + fz_transform_point: Apply a transformation to a point. + + transform: Transformation matrix to apply. See fz_concat, + fz_scale, fz_rotate and fz_translate for how to create a + matrix. + + point: Pointer to point to update. + + Returns transform (unchanged). + + Does not throw exceptions. +*/ +fz_point *fz_transform_point(fz_point *restrict point, const fz_matrix *restrict transform); +fz_point *fz_transform_point_xy(fz_point *restrict point, const fz_matrix *restrict transform, float x, float y); + +/* + fz_transform_vector: Apply a transformation to a vector. + + transform: Transformation matrix to apply. See fz_concat, + fz_scale and fz_rotate for how to create a matrix. Any + translation will be ignored. + + vector: Pointer to vector to update. + + Does not throw exceptions. +*/ +fz_point *fz_transform_vector(fz_point *restrict vector, const fz_matrix *restrict transform); + +/* + fz_transform_rect: Apply a transform to a rectangle. + + After the four corner points of the axis-aligned rectangle + have been transformed it may not longer be axis-aligned. So a + new axis-aligned rectangle is created covering at least the + area of the transformed rectangle. + + transform: Transformation matrix to apply. See fz_concat, + fz_scale and fz_rotate for how to create a matrix. + + rect: Rectangle to be transformed. The two special cases + fz_empty_rect and fz_infinite_rect, may be used but are + returned unchanged as expected. + + Does not throw exceptions. +*/ +fz_rect *fz_transform_rect(fz_rect *restrict rect, const fz_matrix *restrict transform); + +/* + fz_normalize_vector: Normalize a vector to length one. +*/ +void fz_normalize_vector(fz_point *p); + +void fz_gridfit_matrix(int as_tiled, fz_matrix *m); + +float fz_matrix_max_expansion(const fz_matrix *m); + +#endif diff --git a/include/mupdf/fitz/glyph-cache.h b/include/mupdf/fitz/glyph-cache.h index 4231a00a..16fff19a 100644 --- a/include/mupdf/fitz/glyph-cache.h +++ b/include/mupdf/fitz/glyph-cache.h @@ -2,7 +2,7 @@ #define MUPDF_FITZ_GLYPH_CACHE_H #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" #include "mupdf/fitz/font.h" #include "mupdf/fitz/pixmap.h" diff --git a/include/mupdf/fitz/glyph.h b/include/mupdf/fitz/glyph.h index d7e6b3e7..3869422e 100644 --- a/include/mupdf/fitz/glyph.h +++ b/include/mupdf/fitz/glyph.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" #include "mupdf/fitz/store.h" #include "mupdf/fitz/colorspace.h" diff --git a/include/mupdf/fitz/link.h b/include/mupdf/fitz/link.h index e00d66d4..ac6f3c7a 100644 --- a/include/mupdf/fitz/link.h +++ b/include/mupdf/fitz/link.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" /* Links diff --git a/include/mupdf/fitz/math.h b/include/mupdf/fitz/math.h deleted file mode 100644 index 8b38b15b..00000000 --- a/include/mupdf/fitz/math.h +++ /dev/null @@ -1,665 +0,0 @@ -#ifndef MUPDF_FITZ_MATH_H -#define MUPDF_FITZ_MATH_H - -#include "mupdf/fitz/system.h" - -/* - Multiply scaled two integers in the 0..255 range -*/ -static inline int fz_mul255(int a, int b) -{ - /* see Jim Blinn's book "Dirty Pixels" for how this works */ - int x = a * b + 128; - x += x >> 8; - return x >> 8; -} - -/* - Expand a value A from the 0...255 range to the 0..256 range -*/ -#define FZ_EXPAND(A) ((A)+((A)>>7)) - -/* - Combine values A (in any range) and B (in the 0..256 range), - to give a single value in the same range as A was. -*/ -#define FZ_COMBINE(A,B) (((A)*(B))>>8) - -/* - Combine values A and C (in the same (any) range) and B and D (in - the 0..256 range), to give a single value in the same range as A - and C were. -*/ -#define FZ_COMBINE2(A,B,C,D) (((A) * (B) + (C) * (D))>>8) - -/* - Blend SRC and DST (in the same range) together according to - AMOUNT (in the 0...256 range). -*/ -#define FZ_BLEND(SRC, DST, AMOUNT) ((((SRC)-(DST))*(AMOUNT) + ((DST)<<8))>>8) - -/* - Range checking atof -*/ -float fz_atof(const char *s); - -/* - atoi that copes with NULL -*/ -int fz_atoi(const char *s); - -fz_off_t fz_atoo(const char *s); - -/* - Some standard math functions, done as static inlines for speed. - People with compilers that do not adequately implement inlines may - like to reimplement these using macros. -*/ -static inline float fz_abs(float f) -{ - return (f < 0 ? -f : f); -} - -static inline int fz_absi(int i) -{ - return (i < 0 ? -i : i); -} - -static inline float fz_min(float a, float b) -{ - return (a < b ? a : b); -} - -static inline int fz_mini(int a, int b) -{ - return (a < b ? a : b); -} - -static inline size_t fz_minz(size_t a, size_t b) -{ - return (a < b ? a : b); -} - -static inline float fz_max(float a, float b) -{ - return (a > b ? a : b); -} - -static inline int fz_maxi(int a, int b) -{ - return (a > b ? a : b); -} - -static inline fz_off_t fz_maxo(fz_off_t a, fz_off_t b) -{ - return (a > b ? a : b); -} - -static inline float fz_clamp(float f, float min, float max) -{ - return (f > min ? (f < max ? f : max) : min); -} - -static inline int fz_clampi(int i, int min, int max) -{ - return (i > min ? (i < max ? i : max) : min); -} - -static inline double fz_clampd(double d, double min, double max) -{ - return (d > min ? (d < max ? d : max) : min); -} - -static inline void *fz_clampp(void *p, void *min, void *max) -{ - return (p > min ? (p < max ? p : max) : min); -} - -#define DIV_BY_ZERO(a, b, min, max) (((a) < 0) ^ ((b) < 0) ? (min) : (max)) - -/* - fz_point is a point in a two-dimensional space. -*/ -typedef struct fz_point_s fz_point; -struct fz_point_s -{ - float x, y; -}; - -/* - fz_rect is a rectangle represented by two diagonally opposite - corners at arbitrary coordinates. - - Rectangles are always axis-aligned with the X- and Y- axes. - The relationship between the coordinates are that x0 <= x1 and - y0 <= y1 in all cases except for infinite rectangles. The area - of a rectangle is defined as (x1 - x0) * (y1 - y0). If either - x0 > x1 or y0 > y1 is true for a given rectangle then it is - defined to be infinite. - - To check for empty or infinite rectangles use fz_is_empty_rect - and fz_is_infinite_rect. - - x0, y0: The top left corner. - - x1, y1: The bottom right corner. -*/ -typedef struct fz_rect_s fz_rect; -struct fz_rect_s -{ - float x0, y0; - float x1, y1; -}; - -/* - fz_rect_min: get the minimum point from a rectangle as an fz_point. -*/ -static inline fz_point *fz_rect_min(fz_rect *f) -{ - return (fz_point *)&f->x0; -} - -/* - fz_rect_max: get the maximum point from a rectangle as an fz_point. -*/ -static inline fz_point *fz_rect_max(fz_rect *f) -{ - return (fz_point *)&f->x1; -} - -/* - fz_irect is a rectangle using integers instead of floats. - - It's used in the draw device and for pixmap dimensions. -*/ -typedef struct fz_irect_s fz_irect; -struct fz_irect_s -{ - int x0, y0; - int x1, y1; -}; - -/* - A rectangle with sides of length one. - - The bottom left corner is at (0, 0) and the top right corner - is at (1, 1). -*/ -extern const fz_rect fz_unit_rect; - -/* - An empty rectangle with an area equal to zero. - - Both the top left and bottom right corner are at (0, 0). -*/ -extern const fz_rect fz_empty_rect; -extern const fz_irect fz_empty_irect; - -/* - An infinite rectangle with negative area. - - The corner (x0, y0) is at (1, 1) while the corner (x1, y1) is - at (-1, -1). -*/ -extern const fz_rect fz_infinite_rect; -extern const fz_irect fz_infinite_irect; - -/* - fz_is_empty_rect: Check if rectangle is empty. - - An empty rectangle is defined as one whose area is zero. -*/ -static inline int -fz_is_empty_rect(const fz_rect *r) -{ - return ((r)->x0 == (r)->x1 || (r)->y0 == (r)->y1); -} - -static inline int -fz_is_empty_irect(const fz_irect *r) -{ - return ((r)->x0 == (r)->x1 || (r)->y0 == (r)->y1); -} - -/* - fz_is_infinite_rect: Check if rectangle is infinite. - - An infinite rectangle is defined as one where either of the - two relationships between corner coordinates are not true. -*/ -static inline int -fz_is_infinite_rect(const fz_rect *r) -{ - return ((r)->x0 > (r)->x1 || (r)->y0 > (r)->y1); -} - -/* - fz_is_infinite_irect: Check if an integer rectangle - is infinite. - - An infinite rectangle is defined as one where either of the - two relationships between corner coordinates are not true. -*/ -static inline int -fz_is_infinite_irect(const fz_irect *r) -{ - return ((r)->x0 > (r)->x1 || (r)->y0 > (r)->y1); -} - -/* - fz_matrix is a a row-major 3x3 matrix used for representing - transformations of coordinates throughout MuPDF. - - Since all points reside in a two-dimensional space, one vector - is always a constant unit vector; hence only some elements may - vary in a matrix. Below is how the elements map between - different representations. - - / a b 0 \ - | c d 0 | normally represented as [ a b c d e f ]. - \ e f 1 / -*/ -typedef struct fz_matrix_s fz_matrix; -struct fz_matrix_s -{ - float a, b, c, d, e, f; -}; - -/* - fz_identity: Identity transform matrix. -*/ -extern const fz_matrix fz_identity; - -static inline fz_matrix *fz_copy_matrix(fz_matrix *restrict m, const fz_matrix *restrict s) -{ - *m = *s; - return m; -} - -/* - fz_concat: Multiply two matrices. - - The order of the two matrices are important since matrix - multiplication is not commutative. - - Returns result. - - Does not throw exceptions. -*/ -fz_matrix *fz_concat(fz_matrix *result, const fz_matrix *left, const fz_matrix *right); - -/* - fz_scale: Create a scaling matrix. - - The returned matrix is of the form [ sx 0 0 sy 0 0 ]. - - m: Pointer to the matrix to populate - - sx, sy: Scaling factors along the X- and Y-axes. A scaling - factor of 1.0 will not cause any scaling along the relevant - axis. - - Returns m. - - Does not throw exceptions. -*/ -fz_matrix *fz_scale(fz_matrix *m, float sx, float sy); - -/* - fz_pre_scale: Scale a matrix by premultiplication. - - m: Pointer to the matrix to scale - - sx, sy: Scaling factors along the X- and Y-axes. A scaling - factor of 1.0 will not cause any scaling along the relevant - axis. - - Returns m (updated). - - Does not throw exceptions. -*/ -fz_matrix *fz_pre_scale(fz_matrix *m, float sx, float sy); - -/* - fz_post_scale: Scale a matrix by postmultiplication. - - m: Pointer to the matrix to scale - - sx, sy: Scaling factors along the X- and Y-axes. A scaling - factor of 1.0 will not cause any scaling along the relevant - axis. - - Returns m (updated). - - Does not throw exceptions. -*/ -fz_matrix *fz_post_scale(fz_matrix *m, float sx, float sy); - -/* - fz_shear: Create a shearing matrix. - - The returned matrix is of the form [ 1 sy sx 1 0 0 ]. - - m: pointer to place to store returned matrix - - sx, sy: Shearing factors. A shearing factor of 0.0 will not - cause any shearing along the relevant axis. - - Returns m. - - Does not throw exceptions. -*/ -fz_matrix *fz_shear(fz_matrix *m, float sx, float sy); - -/* - fz_pre_shear: Premultiply a matrix with a shearing matrix. - - The shearing matrix is of the form [ 1 sy sx 1 0 0 ]. - - m: pointer to matrix to premultiply - - sx, sy: Shearing factors. A shearing factor of 0.0 will not - cause any shearing along the relevant axis. - - Returns m (updated). - - Does not throw exceptions. -*/ -fz_matrix *fz_pre_shear(fz_matrix *m, float sx, float sy); - -/* - fz_rotate: Create a rotation matrix. - - The returned matrix is of the form - [ cos(deg) sin(deg) -sin(deg) cos(deg) 0 0 ]. - - m: Pointer to place to store matrix - - degrees: Degrees of counter clockwise rotation. Values less - than zero and greater than 360 are handled as expected. - - Returns m. - - Does not throw exceptions. -*/ -fz_matrix *fz_rotate(fz_matrix *m, float degrees); - -/* - fz_pre_rotate: Rotate a transformation by premultiplying. - - The premultiplied matrix is of the form - [ cos(deg) sin(deg) -sin(deg) cos(deg) 0 0 ]. - - m: Pointer to matrix to premultiply. - - degrees: Degrees of counter clockwise rotation. Values less - than zero and greater than 360 are handled as expected. - - Returns m (updated). - - Does not throw exceptions. -*/ -fz_matrix *fz_pre_rotate(fz_matrix *m, float degrees); - -/* - fz_translate: Create a translation matrix. - - The returned matrix is of the form [ 1 0 0 1 tx ty ]. - - m: A place to store the created matrix. - - tx, ty: Translation distances along the X- and Y-axes. A - translation of 0 will not cause any translation along the - relevant axis. - - Returns m. - - Does not throw exceptions. -*/ -fz_matrix *fz_translate(fz_matrix *m, float tx, float ty); - -/* - fz_pre_translate: Translate a matrix by premultiplication. - - m: The matrix to translate - - tx, ty: Translation distances along the X- and Y-axes. A - translation of 0 will not cause any translation along the - relevant axis. - - Returns m. - - Does not throw exceptions. -*/ -fz_matrix *fz_pre_translate(fz_matrix *m, float tx, float ty); - -/* - fz_invert_matrix: Create an inverse matrix. - - inverse: Place to store inverse matrix. - - matrix: Matrix to invert. A degenerate matrix, where the - determinant is equal to zero, can not be inverted and the - original matrix is returned instead. - - Returns inverse. - - Does not throw exceptions. -*/ -fz_matrix *fz_invert_matrix(fz_matrix *inverse, const fz_matrix *matrix); - -/* - fz_try_invert_matrix: Attempt to create an inverse matrix. - - inverse: Place to store inverse matrix. - - matrix: Matrix to invert. A degenerate matrix, where the - determinant is equal to zero, can not be inverted. - - Returns 1 if matrix is degenerate (singular), or 0 otherwise. - - Does not throw exceptions. -*/ - int fz_try_invert_matrix(fz_matrix *inverse, const fz_matrix *matrix); - -/* - fz_is_rectilinear: Check if a transformation is rectilinear. - - Rectilinear means that no shearing is present and that any - rotations present are a multiple of 90 degrees. Usually this - is used to make sure that axis-aligned rectangles before the - transformation are still axis-aligned rectangles afterwards. - - Does not throw exceptions. -*/ -int fz_is_rectilinear(const fz_matrix *m); - -/* - fz_matrix_expansion: Calculate average scaling factor of matrix. -*/ -float fz_matrix_expansion(const fz_matrix *m); /* sumatrapdf */ - -/* - fz_intersect_rect: Compute intersection of two rectangles. - - Given two rectangles, update the first to be the smallest - axis-aligned rectangle that covers the area covered by both - given rectangles. If either rectangle is empty then the - intersection is also empty. If either rectangle is infinite - then the intersection is simply the non-infinite rectangle. - Should both rectangles be infinite, then the intersection is - also infinite. - - Does not throw exceptions. -*/ -fz_rect *fz_intersect_rect(fz_rect *restrict a, const fz_rect *restrict b); - -/* - fz_intersect_irect: Compute intersection of two bounding boxes. - - Similar to fz_intersect_rect but operates on two bounding - boxes instead of two rectangles. - - Does not throw exceptions. -*/ -fz_irect *fz_intersect_irect(fz_irect *restrict a, const fz_irect *restrict b); - -/* - fz_union_rect: Compute union of two rectangles. - - Given two rectangles, update the first to be the smallest - axis-aligned rectangle that encompasses both given rectangles. - If either rectangle is infinite then the union is also infinite. - If either rectangle is empty then the union is simply the - non-empty rectangle. Should both rectangles be empty, then the - union is also empty. - - Does not throw exceptions. -*/ -fz_rect *fz_union_rect(fz_rect *restrict a, const fz_rect *restrict b); - -/* - fz_irect_from_rect: Convert a rect into the minimal bounding box - that covers the rectangle. - - bbox: Place to store the returned bbox. - - rect: The rectangle to convert to a bbox. - - Coordinates in a bounding box are integers, so rounding of the - rects coordinates takes place. The top left corner is rounded - upwards and left while the bottom right corner is rounded - downwards and to the right. - - Returns bbox (updated). - - Does not throw exceptions. -*/ - -fz_irect *fz_irect_from_rect(fz_irect *restrict bbox, const fz_rect *restrict rect); - -/* - fz_round_rect: Round rectangle coordinates. - - Coordinates in a bounding box are integers, so rounding of the - rects coordinates takes place. The top left corner is rounded - upwards and left while the bottom right corner is rounded - downwards and to the right. - - This differs from fz_irect_from_rect, in that fz_irect_from_rect - slavishly follows the numbers (i.e any slight over/under calculations - can cause whole extra pixels to be added). fz_round_rect - allows for a small amount of rounding error when calculating - the bbox. - - Does not throw exceptions. -*/ -fz_irect *fz_round_rect(fz_irect *restrict bbox, const fz_rect *restrict rect); - -/* - fz_rect_from_irect: Convert a bbox into a rect. - - For our purposes, a rect can represent all the values we meet in - a bbox, so nothing can go wrong. - - rect: A place to store the generated rectangle. - - bbox: The bbox to convert. - - Returns rect (updated). - - Does not throw exceptions. -*/ -fz_rect *fz_rect_from_irect(fz_rect *restrict rect, const fz_irect *restrict bbox); - -/* - fz_expand_rect: Expand a bbox by a given amount in all directions. - - Does not throw exceptions. -*/ -fz_rect *fz_expand_rect(fz_rect *b, float expand); - -/* - fz_include_point_in_rect: Expand a bbox to include a given point. - To create a rectangle that encompasses a sequence of points, the - rectangle must first be set to be the empty rectangle at one of - the points before including the others. -*/ -fz_rect *fz_include_point_in_rect(fz_rect *r, const fz_point *p); - -/* - fz_translate_irect: Translate bounding box. - - Translate a bbox by a given x and y offset. Allows for overflow. - - Does not throw exceptions. -*/ -fz_irect *fz_translate_irect(fz_irect *a, int xoff, int yoff); - -/* - fz_contains_rect: Test rectangle inclusion. - - Return true if a entirely contains b. - - Does not throw exceptions. -*/ -int fz_contains_rect(const fz_rect *a, const fz_rect *b); - -/* - fz_transform_point: Apply a transformation to a point. - - transform: Transformation matrix to apply. See fz_concat, - fz_scale, fz_rotate and fz_translate for how to create a - matrix. - - point: Pointer to point to update. - - Returns transform (unchanged). - - Does not throw exceptions. -*/ -fz_point *fz_transform_point(fz_point *restrict point, const fz_matrix *restrict transform); -fz_point *fz_transform_point_xy(fz_point *restrict point, const fz_matrix *restrict transform, float x, float y); - -/* - fz_transform_vector: Apply a transformation to a vector. - - transform: Transformation matrix to apply. See fz_concat, - fz_scale and fz_rotate for how to create a matrix. Any - translation will be ignored. - - vector: Pointer to vector to update. - - Does not throw exceptions. -*/ -fz_point *fz_transform_vector(fz_point *restrict vector, const fz_matrix *restrict transform); - -/* - fz_transform_rect: Apply a transform to a rectangle. - - After the four corner points of the axis-aligned rectangle - have been transformed it may not longer be axis-aligned. So a - new axis-aligned rectangle is created covering at least the - area of the transformed rectangle. - - transform: Transformation matrix to apply. See fz_concat, - fz_scale and fz_rotate for how to create a matrix. - - rect: Rectangle to be transformed. The two special cases - fz_empty_rect and fz_infinite_rect, may be used but are - returned unchanged as expected. - - Does not throw exceptions. -*/ -fz_rect *fz_transform_rect(fz_rect *restrict rect, const fz_matrix *restrict transform); - -/* - fz_normalize_vector: Normalize a vector to length one. -*/ -void fz_normalize_vector(fz_point *p); - -void fz_gridfit_matrix(int as_tiled, fz_matrix *m); - -float fz_matrix_max_expansion(const fz_matrix *m); - -#endif diff --git a/include/mupdf/fitz/output.h b/include/mupdf/fitz/output.h index cba8e16c..824612de 100644 --- a/include/mupdf/fitz/output.h +++ b/include/mupdf/fitz/output.h @@ -4,7 +4,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" #include "mupdf/fitz/buffer.h" -#include "mupdf/fitz/string.h" +#include "mupdf/fitz/string-util.h" /* Generic output streams - generalise between outputting to a file, diff --git a/include/mupdf/fitz/path.h b/include/mupdf/fitz/path.h index 59cd900d..da8b2801 100644 --- a/include/mupdf/fitz/path.h +++ b/include/mupdf/fitz/path.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" /* * Vector path buffer. diff --git a/include/mupdf/fitz/pixmap.h b/include/mupdf/fitz/pixmap.h index 6dfd4bae..e6d56a3c 100644 --- a/include/mupdf/fitz/pixmap.h +++ b/include/mupdf/fitz/pixmap.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" #include "mupdf/fitz/store.h" #include "mupdf/fitz/colorspace.h" diff --git a/include/mupdf/fitz/shade.h b/include/mupdf/fitz/shade.h index 871a62c7..8f25c99a 100644 --- a/include/mupdf/fitz/shade.h +++ b/include/mupdf/fitz/shade.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" #include "mupdf/fitz/store.h" #include "mupdf/fitz/colorspace.h" #include "mupdf/fitz/pixmap.h" diff --git a/include/mupdf/fitz/string-util.h b/include/mupdf/fitz/string-util.h new file mode 100644 index 00000000..c9c20c3d --- /dev/null +++ b/include/mupdf/fitz/string-util.h @@ -0,0 +1,160 @@ +#ifndef MUPDF_FITZ_STRING_H +#define MUPDF_FITZ_STRING_H + +#include "mupdf/fitz/system.h" + +/* + Safe string functions +*/ + +/* + fz_strsep: Given a pointer to a C string (or a pointer to NULL) break + it at the first occurrence of a delimiter char (from a given set). + + stringp: Pointer to a C string pointer (or NULL). Updated on exit to + point to the first char of the string after the delimiter that was + found. The string pointed to by stringp will be corrupted by this + call (as the found delimiter will be overwritten by 0). + + delim: A C string of acceptable delimiter characters. + + Returns a pointer to a C string containing the chars of stringp up + to the first delimiter char (or the end of the string), or NULL. +*/ +char *fz_strsep(char **stringp, const char *delim); + +/* + fz_strlcpy: Copy at most n-1 chars of a string into a destination + buffer with null termination, returning the real length of the + initial string (excluding terminator). + + dst: Destination buffer, at least n bytes long. + + src: C string (non-NULL). + + n: Size of dst buffer in bytes. + + Returns the length (excluding terminator) of src. +*/ +size_t fz_strlcpy(char *dst, const char *src, size_t n); + +/* + fz_strlcat: Concatenate 2 strings, with a maximum length. + + dst: pointer to first string in a buffer of n bytes. + + src: pointer to string to concatenate. + + n: Size (in bytes) of buffer that dst is in. + + Returns the real length that a concatenated dst + src would have been + (not including terminator). +*/ +size_t fz_strlcat(char *dst, const char *src, size_t n); + +/* + fz_dirname: extract the directory component from a path. +*/ +void fz_dirname(char *dir, const char *path, size_t dirsize); + +/* + fz_urldecode: decode url escapes. +*/ +char *fz_urldecode(char *url); + +/* + fz_format_output_path: create output file name using a template. + If the path contains %[0-9]*d, the first such pattern will be replaced + with the page number. If the template does not contain such a pattern, the page + number will be inserted before the file suffix. If the template does not have + a file suffix, the page number will be added to the end. +*/ +void fz_format_output_path(fz_context *ctx, char *path, size_t size, const char *fmt, int page); + +/* + fz_cleanname: rewrite path to the shortest string that names the same path. + + Eliminates multiple and trailing slashes, interprets "." and "..". + Overwrites the string in place. +*/ +char *fz_cleanname(char *name); + +/* + FZ_UTFMAX: Maximum number of bytes in a decoded rune (maximum length returned by fz_chartorune). +*/ +enum { FZ_UTFMAX = 4 }; + +/* + fz_chartorune: UTF8 decode a single rune from a sequence of chars. + + rune: Pointer to an int to assign the decoded 'rune' to. + + str: Pointer to a UTF8 encoded string. + + Returns the number of bytes consumed. Does not throw exceptions. +*/ +int fz_chartorune(int *rune, const char *str); + +/* + fz_runetochar: UTF8 encode a rune to a sequence of chars. + + str: Pointer to a place to put the UTF8 encoded character. + + rune: Pointer to a 'rune'. + + Returns the number of bytes the rune took to output. Does not throw + exceptions. +*/ +int fz_runetochar(char *str, int rune); + +/* + fz_runelen: Count how many chars are required to represent a rune. + + rune: The rune to encode. + + Returns the number of bytes required to represent this run in UTF8. +*/ +int fz_runelen(int rune); + +/* + fz_utflen: Count how many runes the UTF-8 encoded string + consists of. + + s: The UTF-8 encoded, NUL-terminated text string. + + Returns the number of runes in the string. +*/ +int fz_utflen(const char *s); + +/* + fz_strtod/fz_strtof: Locale-independent decimal to binary + conversion. On overflow return (-)INFINITY and set errno to ERANGE. On + underflow return 0 and set errno to ERANGE. Special inputs (case + insensitive): "NAN", "INF" or "INFINITY". +*/ +double fz_strtod(const char *s, char **es); +float fz_strtof(const char *s, char **es); + +/* + fz_strtof_no_exp: Like fz_strtof, but does not recognize exponent + format. So fz_strtof_no_exp("1.5e20", &tail) will return 1.5 and tail + will point to "e20". +*/ + +float fz_strtof_no_exp(const char *string, char **tailptr); +/* + fz_grisu: Compute decimal integer m, exp such that: + f = m * 10^exp + m is as short as possible without losing exactness + Assumes special cases (0, NaN, +Inf, -Inf) have been handled. +*/ +int fz_grisu(float f, char *s, int *exp); + +/* + Check and parse string into page ranges: + ( ','? ([0-9]+|'N') ( '-' ([0-9]+|N) )? )+ +*/ +int fz_is_page_range(fz_context *ctx, const char *s); +const char *fz_parse_page_range(fz_context *ctx, const char *s, int *a, int *b, int n); + +#endif diff --git a/include/mupdf/fitz/string.h b/include/mupdf/fitz/string.h deleted file mode 100644 index c9c20c3d..00000000 --- a/include/mupdf/fitz/string.h +++ /dev/null @@ -1,160 +0,0 @@ -#ifndef MUPDF_FITZ_STRING_H -#define MUPDF_FITZ_STRING_H - -#include "mupdf/fitz/system.h" - -/* - Safe string functions -*/ - -/* - fz_strsep: Given a pointer to a C string (or a pointer to NULL) break - it at the first occurrence of a delimiter char (from a given set). - - stringp: Pointer to a C string pointer (or NULL). Updated on exit to - point to the first char of the string after the delimiter that was - found. The string pointed to by stringp will be corrupted by this - call (as the found delimiter will be overwritten by 0). - - delim: A C string of acceptable delimiter characters. - - Returns a pointer to a C string containing the chars of stringp up - to the first delimiter char (or the end of the string), or NULL. -*/ -char *fz_strsep(char **stringp, const char *delim); - -/* - fz_strlcpy: Copy at most n-1 chars of a string into a destination - buffer with null termination, returning the real length of the - initial string (excluding terminator). - - dst: Destination buffer, at least n bytes long. - - src: C string (non-NULL). - - n: Size of dst buffer in bytes. - - Returns the length (excluding terminator) of src. -*/ -size_t fz_strlcpy(char *dst, const char *src, size_t n); - -/* - fz_strlcat: Concatenate 2 strings, with a maximum length. - - dst: pointer to first string in a buffer of n bytes. - - src: pointer to string to concatenate. - - n: Size (in bytes) of buffer that dst is in. - - Returns the real length that a concatenated dst + src would have been - (not including terminator). -*/ -size_t fz_strlcat(char *dst, const char *src, size_t n); - -/* - fz_dirname: extract the directory component from a path. -*/ -void fz_dirname(char *dir, const char *path, size_t dirsize); - -/* - fz_urldecode: decode url escapes. -*/ -char *fz_urldecode(char *url); - -/* - fz_format_output_path: create output file name using a template. - If the path contains %[0-9]*d, the first such pattern will be replaced - with the page number. If the template does not contain such a pattern, the page - number will be inserted before the file suffix. If the template does not have - a file suffix, the page number will be added to the end. -*/ -void fz_format_output_path(fz_context *ctx, char *path, size_t size, const char *fmt, int page); - -/* - fz_cleanname: rewrite path to the shortest string that names the same path. - - Eliminates multiple and trailing slashes, interprets "." and "..". - Overwrites the string in place. -*/ -char *fz_cleanname(char *name); - -/* - FZ_UTFMAX: Maximum number of bytes in a decoded rune (maximum length returned by fz_chartorune). -*/ -enum { FZ_UTFMAX = 4 }; - -/* - fz_chartorune: UTF8 decode a single rune from a sequence of chars. - - rune: Pointer to an int to assign the decoded 'rune' to. - - str: Pointer to a UTF8 encoded string. - - Returns the number of bytes consumed. Does not throw exceptions. -*/ -int fz_chartorune(int *rune, const char *str); - -/* - fz_runetochar: UTF8 encode a rune to a sequence of chars. - - str: Pointer to a place to put the UTF8 encoded character. - - rune: Pointer to a 'rune'. - - Returns the number of bytes the rune took to output. Does not throw - exceptions. -*/ -int fz_runetochar(char *str, int rune); - -/* - fz_runelen: Count how many chars are required to represent a rune. - - rune: The rune to encode. - - Returns the number of bytes required to represent this run in UTF8. -*/ -int fz_runelen(int rune); - -/* - fz_utflen: Count how many runes the UTF-8 encoded string - consists of. - - s: The UTF-8 encoded, NUL-terminated text string. - - Returns the number of runes in the string. -*/ -int fz_utflen(const char *s); - -/* - fz_strtod/fz_strtof: Locale-independent decimal to binary - conversion. On overflow return (-)INFINITY and set errno to ERANGE. On - underflow return 0 and set errno to ERANGE. Special inputs (case - insensitive): "NAN", "INF" or "INFINITY". -*/ -double fz_strtod(const char *s, char **es); -float fz_strtof(const char *s, char **es); - -/* - fz_strtof_no_exp: Like fz_strtof, but does not recognize exponent - format. So fz_strtof_no_exp("1.5e20", &tail) will return 1.5 and tail - will point to "e20". -*/ - -float fz_strtof_no_exp(const char *string, char **tailptr); -/* - fz_grisu: Compute decimal integer m, exp such that: - f = m * 10^exp - m is as short as possible without losing exactness - Assumes special cases (0, NaN, +Inf, -Inf) have been handled. -*/ -int fz_grisu(float f, char *s, int *exp); - -/* - Check and parse string into page ranges: - ( ','? ([0-9]+|'N') ( '-' ([0-9]+|N) )? )+ -*/ -int fz_is_page_range(fz_context *ctx, const char *s); -const char *fz_parse_page_range(fz_context *ctx, const char *s, int *a, int *b, int n); - -#endif diff --git a/include/mupdf/fitz/structured-text.h b/include/mupdf/fitz/structured-text.h index 061fc83c..7ec5772a 100644 --- a/include/mupdf/fitz/structured-text.h +++ b/include/mupdf/fitz/structured-text.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" #include "mupdf/fitz/font.h" #include "mupdf/fitz/colorspace.h" #include "mupdf/fitz/image.h" diff --git a/include/mupdf/fitz/util.h b/include/mupdf/fitz/util.h index a9a0d59d..e5e1c723 100644 --- a/include/mupdf/fitz/util.h +++ b/include/mupdf/fitz/util.h @@ -3,7 +3,7 @@ #include "mupdf/fitz/system.h" #include "mupdf/fitz/context.h" -#include "mupdf/fitz/math.h" +#include "mupdf/fitz/geometry.h" #include "mupdf/fitz/document.h" #include "mupdf/fitz/pixmap.h" #include "mupdf/fitz/structured-text.h" diff --git a/platform/win32/libmupdf.vcproj b/platform/win32/libmupdf.vcproj index 45942e1e..b83f68e3 100644 --- a/platform/win32/libmupdf.vcproj +++ b/platform/win32/libmupdf.vcproj @@ -2331,6 +2331,10 @@ RelativePath="..\..\include\mupdf\fitz\function.h" > + + @@ -2355,10 +2359,6 @@ RelativePath="..\..\include\mupdf\fitz\link.h" > - - @@ -2424,7 +2424,7 @@ >