summaryrefslogtreecommitdiff
path: root/fitz
AgeCommit message (Collapse)Author
2012-02-15Check determinant before inverting a matrix to avoid division by zero.Tor Andersson
2012-02-14Fix potential NULL deref in ensure_space.Robin Watts
Silly mistake in previous commit.
2012-02-13Create mudraw; mupdfdraw cloned and adapted to use fz_documentRobin Watts
All in one command line replacement for muxpsdraw and mupdfdraw.
2012-02-13Add locking around freetype calls.Robin Watts
We only open one instance of freetype per document. We therefore have to ensure that only 1 call to it takes place at a time. We introduce a lock for this purpose (FZ_LOCK_FREETYPE), and arrange to take/release it as required. We also update the font context so it is properly shared.
2012-02-13Remove STORE lock in favour of smarter use of ALLOC lock.Robin Watts
This simplifies other locking issues (notably freetype).
2012-02-11Purge unused and bit rotted fz_accelerate stuff, part 2.Tor Andersson
2012-02-08Lock reworking.Robin Watts
This is a significant change to the use of locks in MuPDF. Previously, the user had the option of passing us lock/unlock functions for a single mutex as part of the allocation struct. Now we remove these entries from the allocation struct, and make a separate 'locks' struct. This enables people to use fz_alloc_default with locking. If multithreaded operation is required, then the user is required to create FZ_LOCK_MAX mutexes, which will be locked or unlocked by MuPDF calling the lock/unlock functions within the new fz_locks_context structure passed in at context creation. These mutexes are not required to be recursive (they may be, but MuPDF should never call them in this way). MuPDF avoids deadlocks by imposing a locking ordering on itself; a thread will never take lock n, if it already holds any lock i for which 0 <= i <= n. Currently, there are 4 locks used within MuPDF. Lock 0: The alloc lock; taken around all calls to user supplied (or default) allocation functions. Also taken around all accesses to the refs field of storable items. Lock 1: The store lock; taken whenever the store data structures (specifically the linked list pointers) are accessed. Lock 2: The file lock; taken whenever a thread is accessing the raw file. We use the debugging macros to insist that this is held whenever we do a file based seek or read. We also insist that this is never held when we resolve an indirect reference, as this can have the effect of moving the file pointer. Lock 3: The glyphcache lock; taken whenever a thread calls freetype, or accesses the glyphcache data structures. This introduces some complexities w.r.t type3 fonts. Locking can be hugely problematic, so to ease our minds as to the correctness of this code, we introduce some debugging macros. These compile away to nothing unless FITZ_DEBUG_LOCKING is defined. fz_assert_lock_held(ctx, lock) checks that we hold lock. fz_assert_lock_not_held(ctx, lock) checks that we do not hold lock. In addition fz_lock_debug_lock and fz_lock_debug_unlock are used on every fz_lock/fz_unlock to check the validity of the operation we are performing - in particular it checks that we do/do not already hold the lock we are trying to take/drop, and that by taking this lock we are not violating our defined locking order. The RESOLVE macro (used throughout the code to check whether we need to resolve an indirect reference) calls fz_assert_lock_not_held to ensure that we aren't about to resolve an indirect reference (and hence move the stream pointer) when the file is locked. In order to implement the file locking properly, pdf_open_stream (and friends) now lock the file as a side effect (because they fz_seek to the start of the stream). The lock is automatically dropped on an fz_close of such streams. Previously, the glyph cache was created in a context when it was first required; this presents problems as it can be shared between several contexts or not, depending on whether it is created before the contexts are cloned. We now always create it at startup, so it is always shared. This means that we need reference counting for the glyph caches. Added here. In fz_render_glyph, we take the glyph cache lock, and check to see whether the glyph is in the cache. If it is, we bump the refcount, drop the lock and returned the cached character. If it is not, we need to render the character. For freetype based fonts we keep the lock throughout the rendering process, thus ensuring that freetype is only called in a single threaded manner. For type3 fonts, however, we need to invoke the interpreter again to render the glyph streams. This can require reentrance to this routine. We therefore drop the glyph cache lock, call the interpreter to render us our pixmap, and take the lock again. This dropping and retaking of the lock introduces a possible race condition; 2 threads may try to render the same character at the same time. We therefore modify our hash table insert routines to behave differently if it comes to insert an entry only to find that an entry with the same key is already there. We spot this case; if we have just rendered a type3 glyph and when we try to insert it into the cache discover that someone has beaten us to it, we just discard our entry and use the cached one. Hopefully this will seldom be a problem in practise; to solve it properly would require greater complexity (probably involving spotting that another thread is already working on the desired rendering, and sleeping on a semaphore until it completes).
2012-02-07Fix broken fz_clone_context; stupid typo.Robin Watts
When cloning a context, it's generally best to return your new context, rather than the one you cloned from.
2012-02-07Implement fz_open_document by hard coding the list of file types.Tor Andersson
2012-02-07Rename a few functions.Tor Andersson
2012-02-03Fix NULL dereference when freeing fz_link objects.Tor Andersson
2012-02-03Be consistent about passing a fz_context in path/text/shade functions.Tor Andersson
2012-02-03Be consistent about passing a fz_context argument in pixmap functions.Tor Andersson
2012-02-03Pass context explicitly to hash table functions.Tor Andersson
2012-02-03Reference count fz_link objects.Tor Andersson
2012-02-03Remove extraneous blank lines.Tor Andersson
2012-02-03Add document interface.Tor Andersson
2012-02-03Make fz_malloc_struct return zeroed memory.Tor Andersson
2012-01-30Do not embed a context in the fz_outline structure.Tor Andersson
2012-01-30Move PNG, JPEG and TIFF image loading from muxps into fitz.Tor Andersson
2012-01-27Remove dependency on fz_obj from the filter creation parameters.Tor Andersson
2012-01-27Rename pdf_xref type to pdf_document.Tor Andersson
2012-01-27Whitespace fixes.Tor Andersson
2012-01-25Fix bug in Fax decoder.Robin Watts
Thanks to Zeniko for this; one line fix in the fax decoder, to cope with a case at the start of lines. This fixes: x - 1d faxd overflow.pdf and x - 1d faxd negative code.pdf
2012-01-21Fix deadlock in fz_drop_storable.Robin Watts
Thanks for filmor for identifying this.
2012-01-20Bitmap 'patch' scaling - second attempt.Robin Watts
When scaling a bitmap, currently we always scale the entire bitmap, even if we only need a small section of the result. This patch changes the code to take an optional 'clip' bbox, and only scales as many pixels as are required to generate the required output region.
2012-01-20Ensure Memento checking is reflected in block numbersRobin Watts
2012-01-20Fix locking problems.Robin Watts
Thanks to filmor's help, fix some problems where locking was going wrong; in 2 cases we failed to unlock, and in 2 cases we tried to free (which relocks) while already locked. All simple fixes.
2012-01-20Revert "Bitmap 'patch' scaling."Tor Andersson
This reverts commit 08e84b18e5c1dbe8f3d32dd0aeb4b4c43debce9f.
2012-01-19Bitmap 'patch' scaling.Robin Watts
When scaling a bitmap, currently we always scale the entire bitmap, even if we only need a small section of the result. This patch changes the code to take an optional 'clip' bbox, and only scales as much of the input as as required for this output region.
2012-01-19Multi-threading support for MuPDFRobin Watts
When we moved over to a context based system, we laid the foundation for a thread-safe mupdf. This commit should complete that process. Firstly, fz_clone_context is properly implemented so that it makes a new context, but shares certain sections (currently just the allocator, and the store). Secondly, we add locking (to parts of the code that have previously just had placeholder LOCK/UNLOCK comments). Functions to lock and unlock a mutex are added to the allocator structure; omit these (as is the case today) and no multithreading is (safely) possible. The context will refuse to clone if these are not provided. Finally we flesh out the LOCK/UNLOCK comments to be real calls of the functions - unfortunately this requires us to plumb fz_context into the fz_keep_storable function (and all the fz_keep_xxx functions that call it). This is the largest section of the patch. No changes expected to any test files.
2012-01-18Better handling of 'uncacheable' Type3 glyphs. Bug 692745.Robin Watts
Some Type 3 fonts contain glyphs that rely on inheriting various aspects of the graphics state from their calling code. (i.e. a glyph might use d0, then fill an area without setting a color first). While the spec is vague on this point, we believe that technically it is invalid. Previously mupdf defaulted all elements of the graphic state back when beginning to draw the glyph. This does not match what Acrobat does though, so we change the approach taken. We now watch (by use of bits in the device flags word) for the use of parts of the graphics state before it is set. If such use is detected, then we note that the glyph is 'uncacheable' and render it direct. This seems to match Acrobats behaviour.
2012-01-14Smarter path construction (avoid needless segments).Robin Watts
Automatically skip segments in a path that serve no purpose at construction time. * MOVE then MOVE -> the original MOVE is ignored. * LINETO the currentpoint -> ignored if previous segment was not a moveto. * CURVETO the currentpoint (with coincident coords) -> ignored if previous segment was not a moveto. * CLOSE then CLOSE -> second close ignored. It's worth noting here that in pdf a closepath leaves the current point at the point which it closes to - any new segments will begin a new subpath, but the current point is defined.
2012-01-13Rework pdf_resolve_indirect to make it idempotent.Robin Watts
pdf_resolve_indirect(x) = pdf_resolve_indirect(pdf_resolve_indirect(x)) now - as long as it doesn't throw an exception. Update the rest of the code to minimise unnecessary function calls. Previously, we were calling one function to find out if an object was a dict, only for that to call a function to see if it needed to resolve the object, then calling another function to actually get the dict, only to have that call the function to check for the dict needing resolving again!
2012-01-13Clipping stack handling tweaks in dev_list.Robin Watts
Thanks to Zeniko for spotting these problems.
2012-01-13Scavenging fixes; overflow and division by zero.Robin Watts
Ensure we don't get a division by zero (when *phase goes to 16). Also ensure we don't overflow the bounds of an unsigned int. Thanks to Zeniko for spotting these problems.
2012-01-13Ensure that client_data pointer for jpx decodes is ctx.Robin Watts
The call to opj_set_event_mgr would overwrite client_data=ctx with client_data=stderr - not what was wanted. Thanks to Zeniko for this.
2012-01-12Support proper XPS mitering. (And stroke fixes).Robin Watts
XPS differs from PS/PDF/etc in the way it handles miters; rather than simply converting a miter that's overly long to a bevel, it truncates it at the miter limit. As such it needs to be handled correctly. For clarity, expose new enumerated types for linejoins and linecaps, and use these throughout code. When we upgrade our freetype, we can move to using proper xps mitering in that too. Add new fz_matrix_max_expansion function to return a safer expansion value that works in the case where we scale up in one direction and down in another. In the xps path drawing code, avoid generating unnecessary linetos. Thanks to Zeniko for spotting these and providing implementations.
2012-01-12Calculate individual glyph bboxes for Type 3 fonts too.Tor Andersson
2012-01-12Fix memory leak in font->bbox_table.Tor Andersson
2012-01-11Flush warnings before printing an error message in fz_throw.Tor Andersson
2012-01-11Use enum for FZ_STORE_DEFAULT default size.Tor Andersson
2012-01-11Hide glyph cache in context.Tor Andersson
2012-01-11Set default values for alloc context and max store size if none are given.Sebastian Rasmussen
2012-01-11Stylistic comment and whitespace fixes.Tor Andersson
2012-01-11Add glyph bbox cache.Tor Andersson
2012-01-11Calculate accurate per-glyph bounding boxes for fz_bound_text.Tor Andersson
2012-01-11Remove fuzzing from fz_round_rect.Tor Andersson
I don't remember exactly why I added it; but there are several progressions when I remove it.
2012-01-10Move fuzz from fz_execute_display_list into fz_bound_text.Robin Watts
Keep the fuzz in just one place. Hopefully will be rendered unnecessary by changes to make fz_bound_text accurate.
2012-01-10Add fz_blend_pixel_function.Robin Watts
Inspired by Sumatras gdi devices need for such a function expose the blending functions. Note that we produce unsigned char's where Zenikos original produces ints, but it's otherwise identical. This requires us to make various knockon changes throughout the code from int to unsigned char, none of which should make any difference at all - I hope! We reserve the right to change/amend this function in future to operate on blocks of pixels (or pixels in different colorspaces) (or anything else we think of) in future.