summaryrefslogtreecommitdiff
path: root/source/fitz
AgeCommit message (Collapse)Author
2014-06-26Add missing fz_var() and fix potential memory leak.Matt Holgate
2014-06-19Fix compiler warning.Matt Holgate
2014-06-18Fix for bug #694405 - iOS Pdf CrashMatt Holgate
If an iOS app uses too much memory, the OS asks it to free up some space. If it doesn't do so in a timely manner, it will get a second warning before being killed by the OS. In other platforms, where malloc() return NULL in OOM, the store scavenger releases memory when mallocs fail. In iOS, mallocs usually never return NULL because the app is killed before this can happen. Therefore, we need to initiate a scavenge from the low memory notification instead. We evict the store to 50% of its current size when a memory warning occurs when it is in the foreground, and 0% when a memory warning occurs whilst it is in the background. Having said this, I didn't manage to get a background warning to occur, presumably because we don't request background execution Therefore, I think in practice the OS just kills the process. However, this will be useful if we ever add background execution.
2014-06-10Fix library/header version error message and makefile dependency.Tor Andersson
2014-06-09Bug 695300: Sanitize draw-device stack handling in error cases.Robin Watts
When throwing an error during fz_alpha_from_gray, the stack depth can get confused. Fix this by moving some more code into the appropriate fz_try(). In the course of fixing this bug, I added some new optional debug code to display the stack level as it runs. This is committed here disabled; just change the appropriate #define in draw-device.c to enable it. Also, add some code to run_xobject, to avoid throwing in an fz_always() clause.
2014-05-28Further fix for Bug 695260: Cope with out of memory in fz_draw_end_maskRobin Watts
If we hit an out of memory error in fz_draw_end_mask, then pop the stack, and rethrow. Ensure that the generic device code catches this error and sets the error_depth to 1 so that the final pop is ignored.
2014-05-27Fix 693517: Support /SMask/Matte preblended images.Tor Andersson
2014-05-26Fix 695261: separate TM and CTM in outline extraction and stroking steps.Tor Andersson
We used to extract the outline using the combined TM*CTM matrix and use the identity transform for stroking, thus ending up with the wrong line width. If we instead extract using the TM and then stroke with the CTM we get the correct results.
2014-05-23Fix 695041: add special fast case for 8bpp TIFF predictor.Tor Andersson
2014-05-23Bug 695183: Inflate large buffers at a time for speed.Robin Watts
When I changed the stream implementations to use implementation specific buffers, rather than a generic public one in every fz_stream, I changed fz_read_byte to only get a single byte at a time. I noted at the time that the underlying stream was free to decode larger blocks if it wanted too, but I forgot to actually do this for the flate decoder. Fixing this here should solve the speed issues.
2014-05-22Fix 695222: Treat non-breaking space (U+00A0) as white space for search.Tor Andersson
2014-05-22Fix 695247: Use exponential realloc pattern and qsort for huge paths.Tor Andersson
Grow the edge list using an exponential realloc pattern. Use qsort for huge paths and only fall back to the simple shell sort for small paths.
2014-05-19Remove jmorecfg.h from includes.Chris Liddell
2014-05-19Add an application agnostic memory handler for libjpegChris Liddell
This adds a custom memory management layer between libjpeg and the calling app - in such a way that the code can be shared between mupdf and Ghostscript/PDL.
2014-05-19Fix 694952: Limit Type 3 font glyph bbox size.Tor Andersson
Don't let a glyph's bbox be too much bigger than the font bbox.
2014-05-12better buffer underflow protection for ba15a8cd3238a3a3c098ad8b7d96cb0e405fc26fSimon Bünzli
2014-05-12correctly bound image mask clippings in bbox deviceSimon Bünzli
Same as for fz_bbox_fill_image_mask, fz_bbox_clip_image_mask must transform the unit rectangle to get the bounding bbox.
2014-05-12prevent indeterminacy by uninitialized variablesSimon Bünzli
There are two issues where variables may be used unitialized: * extract_exif_resolution fails to set xres and yres for JPEG images if there's no valid resolution unit (mainly affects XPS documents) * xps_measure_font_glyph uses hadv and vadv unitialized if the glyph id isn't valid (i.e. if FT_Get_Advance fails)
2014-05-10Fix stack overflow in fz_vfprintf.Tor Andersson
Thanks to Triet Lai.
2014-05-07minor clean-upSimon Bünzli
2014-05-07Correctly round PNG image resolutionSimon Bünzli
Currently, png_read_phys always rounds the resolution down. Many images have a resolution just slightly shy of 96 DPI and are thus rendered too large when they're resized from 95 to match the required 96 for output.
2014-05-07Bug 695112: only patch height values in JPEG streamsSimon Bünzli
If the reported height is 0 or too large, use the image size reported in the PDF itself instead (in the case of height 0, the JPEG library is supposed to read the correct value from the DNL segment, but libjpeg doesn't support that).
2014-05-07Fix 695112: patch JPEG streams with missing dimensionsTor Andersson
If a JPEG stream is missing valid values for width/height (usually -1), Adobe Reader substitutes these using the values read from the PDF object. This can be done by scanning and patching the data before passing it to libjpeg. Thanks to zeniko for the patch.
2014-05-07Bug 694801: fast_cmyk_to_rgb caching broken.Robin Watts
fast_cmyk_to_rgb had a simple 1 place cache to avoid recalculating the same conversions again and again. The implementation was broken though, both in C and ARM code versions. This seems to fix it.
2014-05-06Fix 694909: revert "Force colorspaces to match with JPX images." and ...Tor Andersson
... instead convert a JPEG2000 used as a soft mask into grayscale. This is more robust than trusting the PDF specified colorspace over the internal JPX colorspace. The spec implies that in a colorspace conflict, the internal JPX colorspace should be used. The PDF colorspace may be a DeviceN or Separation colorspace. DeviceN and Separation colorspaces are not valid destination colorspaces, so we may not always be able to convert the internal JPX colorspace into the PDF specified colorspace. Converting from the internal colorspace into grayscale is more robust, and solves the issue that the original commit was intended to fix.
2014-05-01Fix 694084: compute number of segments in radial shading from radius.Tor Andersson
2014-04-27Bug 695171: Pointer error when padding an fz_concat machineRobin Watts
When we return the padding byte in an fz_concat stream, ensure that we remember to increment rp to point just past in. If not, then we'll read 2 whitespace chars out. This is fine unless we try and fz_unread_byte the first one, when we'll leave rp pointing to an out of buffer address. Credit to Malc for the bisecting/debugging that got me to the fix. Many thanks.
2014-04-23Fix bug 693580 by skipping xml tag namespace prefixes.Tor Andersson
fts_5904.xps and fts_5905.xps use namespace prefixes. Work around that by ignoring the namespace prefix for tag names. A more robust solution would be to expand or record the tag and attribute namespaces in the fz_xml node structure, but that's a overkill for our current needs.
2014-03-25Add va_copy/va_copy_end macros to support both C89 and C99.Tor Andersson
2014-03-25fix warnings in fitz/printf.cSimon Bünzli
This fixes three instances of warning C4706, allows compilation with VS2013 and prevents an accidental va_end for when va_end is defined (which is the case for debug builds).
2014-03-25Break dependencies on pdf-form.c and pdf-js.cTor Andersson
Split functions out of pdf-form.c that shouldn't be there, and make javascript initialization explicit.
2014-03-19Fix MSVC compiles of printf.cRobin Watts
Stupid MSVC has no strtof.
2014-03-19Add %q and %( formatting to fz_printf to print escaped strings.Tor Andersson
%q escapes using C syntax and wraps the string in double quotes. %( escapes using PS/PDF syntax and wraps the string in parens.
2014-03-19Implement our own vsnprintf variant.Tor Andersson
The primary motivator for this is so that we can print floating point values and get the full accuracy out, without having to print 1.5 as 1.5000000, and without getting 23e24 etc. We only support %c, %f, %d, %o, %x and %s currently. We only support the zero padding qualifier, for integers. We do support some extensions: %C turns values >=128 into UTF-8. %M prints a fz_matrix. %R prints a fz_rect. %P prints a fz_point. We also implement a fprintf variant on top of this to allow for consistent results when using fz_output. a
2014-03-18Fix operator buffering of inline images.Robin Watts
Previously pdf_process buffer did not understand inline images. In order to make this work without needlessly duplicating complex code from within pdf-op-run, the parsing of inline images has been moved to happen in pdf-interpret.c. When the op_table entry for BI is called it now expects the inline image to be in csi->img and the dictionary object to be in csi->obj. To make this work, we have had to improve the handling of inline images in general. While non-inline images have been loaded and held in memory in their compressed form and only decoded when required, until now we have always loaded and decoded inline images immediately. This has been due to the difficulty in knowing how many bytes of data to read from the stream - we know the length of the stream once uncompressed, but relating this to the compressed length is hard. To cure this we introduce a new type of filter stream, a 'leecher'. We insert a leecher stream before we build the filters required to decode the image. We then read and discard the appropriate number of uncompressed bytes from the filters. This pulls the compressed data through the leecher stream, which stores it in an fz_buffer. Thus images are now always held in their compressed forms in memory. The pdf-op-run implementation is now trivial. The only real complexity in the pdf-op-buffer implementation is the need to ensure that the /Filter entry in the dictionary object matches the exact point at which we backstopped the decompression.
2014-03-17Rework fz_streams.Robin Watts
Currently fz_streams have a 4K buffer within their header. The call to read from a stream fills this buffer, resulting in more data being pulled from any underlying stream than we might like. This causes problems with the forthcoming 'leech' filter. Here we simplify the fields available in the public stream header. No specific buffer is given; simply the read and write pointers. The underlying 'read' function is replaced by a 'next' function that makes the next block of data available and returns the first character of it (or EOF). A caller to the 'next' function should supply the maximum number of bytes that it knows it will need (possibly not now, but eventually). This enables the underlying stream to efficiently decode just enough. The underlying stream is free to return fewer, or a greater number if it wants to. The exact size of the 'block' of data returned will depend on the filter in use and (possibly) the data therein. Callers can get the currently available amount of data by calling fz_available (but again should pass the maximum amount of data they know they will need). The only time this will ever return 0 is if we have hit EOF.
2014-03-17Ensure that small images don't subdivide more than they should.Robin Watts
Gridfitting can increase the required width/height of images by up to 2 pixels. This makes images that are rendered very small very sensitive to over quantisation. This can produce 'mushier' images than it should, for instance on tests/Ghent_V3.0/090_Font-Support_x3.pdf (pgmraw, 72dpi)
2014-02-25Bug 695040: prevent hang in path flatteningSimon Bünzli
If the expansion of a transformation matrix is huge, the path flatness becomes so small that even simple paths consist of millions of edges which easily causes MuPDF to hang quite long for simple documents. One solution for this is to limit the allowed flatness.
2014-02-25Bug 694851: pass more information to fz_load_system_fontSimon Bünzli
The following changes allow font providers to make better choices WRT what font to provide and under what circumstances: * bold and italic flags are passed in so that implementors can decide themselves whether to ask for simulated boldening/italicising if a font claims not to be bold/italic * is_substitute is replaced with needs_exact_metrics to make the meaning of this argument hopefully clearer (that argument is set only for PDF fonts without a FontDescriptor) * the font name is always passed as requested by the document instead of the cleaned name for the standard 14 fonts which allows distinguishing e.g. Symbol and Symbol,Bold
2014-02-18Make the OpenJPEG I/O callbacks static.....Chris Liddell
and give them names more likely to be unique.
2014-02-17Tweak fz_eval_function fakein/out buffer copying.Tor Andersson
2014-02-17Simplify shade vertex preparation and remove redundant memcpy calls.Tor Andersson
2014-02-17Add fz_transform_point_xy to simplify transforming a point.Tor Andersson
Many times, the idiom p.x = x; p.y = y; fz_transform_point() is used. This function should simplify that use case by both initializing and transforming the point in one call.
2014-02-17Add const to colorspace source arguments and dependencies.Tor Andersson
2014-02-10Bug 695022: Add TIFF format handlerRobin Watts
Patch from Thomas Fach-Pedersen. Many thanks! Add a new format handler that copes with TIFF files. This replaces the TIFF functionality within the image format handler, and is better because this copes with multiple images (as one image per page).
2014-02-10Bug 695022: Add support for multuple image tiff files.Robin Watts
Patch from Thomas Fach-Pedersen. Many Thanks.
2014-02-04Improve glyph bounding, outlining and SVG output text.Robin Watts
Luiz Henrique de Figueiredo reports that glyphs output from the SVG device contain 'lumpy' outlines. Investigation reveals that this is because the current code extracts the outlines from freetype at unit scale, and then relies on SVG to scale them up. Unfortunately, freetype insists on working in integer maths, so any sort of scaling runs the risk of distorting the outlines. The fix is to change the way we call freetype; we now request an 'UNSCALED' char, and set the required size to be the design size. We then transform the results in the floating point domain ourself. This cures the lumpy outlines, but reveals a second problem, namely that the bbox given for characters is inaccurate (and sometimes too small). Investigation shows that this is again caused by freetypes scaling, so we apply the same trick; ask for the glyph without scaling (as far as possible), and then scale the results down. We also take care to spot the 'ft_hint' flag in the font. If set this indicates that hinting must be performed to ensure that the returned outlines are sane. We therefore take note of this when calculating both bbox and outlines. This means that 'tricky' fonts such as dynalab ones now render correctly. This produces many changes in the bitmaps, the vast majority of which are neutral. The ones that aren't are all progressions.
2014-01-22Make fz_tree_lookup iterative rather than recursive.Tor Andersson
2014-01-17Avoid overflows in floating point causing illegal accessesRobin Watts
If the scale is too large, the calculation to determine the required size of a pixmap can overflow. This can lead to negative width/heights being passed in, which confuses the subsampling code, leading to SEGVs.
2014-01-17Fix more Memento/Valgrind interactions.Robin Watts
Seen when valgrinding a memento build of mudraw on: e0e44ed8692671b820de72c6c0a32608_asan_heap-uaf_8c2b76_1530_2026.pdf