summaryrefslogtreecommitdiff
path: root/source
AgeCommit message (Collapse)Author
2014-03-25Avoid double closing a stream.Robin Watts
Michael spotted that double closing an fz_stream on an inline image does bad things. Simple fix is not to double close.
2014-03-25Split mjs script generation to separate tool.Tor Andersson
It has no real reason to live in mudraw, and it does pull in the javascript dependency via pdf-form.c.
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-25Break dependency of pdf-annot.c to graphics library.Tor Andersson
2014-03-25Add MuJS submodule, implementation and build.Tor Andersson
Adds simpler choice of Javascript library to makefiles. Will prefer in order: MuJS, JavaScriptCore, V8, none based on HAVE_MUJS, HAVE_JSCORE, and HAVE_V8. For simplicity, we build mujstest even with no javascript implementation.
2014-03-20pdf-util.js: Simplify padZeros.Tor Andersson
2014-03-20pdf-js.c: Use different random number.Tor Andersson
0.4 is not exactly representable using floats, and libjs uses a different atod function than v8.
2014-03-20Respect reverse page ranges in mutool clean.Tor Andersson
2014-03-19Add routine to clean pdf content streams for pages.Robin Watts
New routine to filter the content streams for pages, xobjects, type3 charprocs, patterns etc. The filtered streams are guaranteed to be properly matched with q/Q's, and to not have changed the top level ctm. Additionally we remove (some) repeated settings of colors etc. This filtering can be extended to be smarter later. The idea of this is to both repair after editing, and to leave the streams in a form that can be easily appended to. This is preparatory to work on Bates numbering and Watermarking. Currently the streams produced are uncompressed.
2014-03-19Make mutool clean sanitise the Dests lists when subsetting.Robin Watts
When you use mutool clean to subset pages out of a PDF, we already remove the Name tree entries for named locations that aren't in the target file. We have henceforth failed to remove references to these removed names though. This can cause errors (really warnings) on reading the file back.
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-03-17Don't drop objects if they have been modified.Robin Watts
This avoids leaks when pdf_clear_xref etc are used.
2014-03-17Ensure that BDC operators get both params.Robin Watts
Currently, when parsing, each time we encounter a name, we throw away the last name we had. BDC operators are called with: /Name <object> BDC If the <object> is a name, we lose the original /Name. To fix this, parsing a name when we already have a name will cause the name to be stored as an object. This has various knock on effects throughout the code to read from csi->obj rather than csi->name. Also, ensure that when cleaning, we collect a list of the object names in our new resources dictionary.
2014-03-16Avoid premature dropping of objects in pdf_dict_putRobin Watts
When inserting a new value into a dictionary, if replacing an existing entry, ensure we keep the new value before dropping the old one. This is important in the case where (for example) the existing value is "[ object ]" and the new value is "object". If we drop the array and that loses the only reference to object, we can find that we have lost the value we are adding.
2014-03-13Tweak pdfclean and pdfinfo to be useful as libraries.Robin Watts
Firstly, we remove the use of global variables; this is done by introducing a 'globals' structure for each of these files and passing it internally between functions. Next, split the core of pdfclean_main into pdfclean_clean, and the core of pdfinfo_main into pdfinfo_info. The _main functions now do the argv processing. The new functions now run entirely thread safely, so can be called from library functions.
2014-03-13Make pdf_output_obj consistent with pdf_fprint_objRobin Watts
Pass in the 'tight' flag.
2014-03-04Fix potential leak of pdf_process state.Robin Watts
In the event that an annot is hidden or invisible, the pdf_process would never be freed. Solve that here. Thanks to Simon for spotting this!
2014-03-04Fix memory leaks in pdf-filter code.Robin Watts
We were never freeing the top level filter_gstate, and we were losing a reference to each new resource type dictionary when we create them.
2014-03-04Bug 691691: Add way of clearing cached objects out of the xref.Robin Watts
We add various facilities here, intended to allow us to efficiently minimise the memory we use for holding cached pdf objects. Firstly, we add the ability to 'mark' all the currently loaded objects. Next we add the ability to 'clear the xref' - to drop all the currently loaded objects that have no other references except the ones held by the xref table itself. Finally, we add the ability to 'clear the xref to the last mark' - to drop all the currently loaded objects that have been created since the last 'mark' operation and have no other references except the ones held by the xref table. We expose this to the user by adding a new device hint 'FZ_NO_CACHE'. If set on the device, then the PDF interpreter will pdf_mark_xref before starting and pdf_clear_xref_to_mark afterwards. Thus no additional objects will be retained in memory after a given page is run, unless someone else picks them up and takes a reference to them as part of the run. We amend our simple example app to set this device hint when loading pages as part of a search.
2014-03-04Add pdf_process for filtering operator streams.Robin Watts
Currently this knows about q/Q matching/eliding and avoiding repeated/unneccesary color/colorspace setting. It will also collect a dictionary of resources used by a page. This can be extended to be cleverer in future.
2014-03-04Add pdf_process for writing operator streams out to a buffer.Robin Watts
Using this, we can reconstruct pdf streams out of the process called. This will enable us to do filtering when used in combination with future commits.
2014-03-04Add pdf_process interface.Robin Watts
Currently the only processing we can do of PDF pages is to run them through an fz_device. We introduce new "pdf_process" functionality here to enable us to do more things. We define a pdf_processor structure with a set of function pointers in, one per PDF operator, together with functions for processing xobjects etc. The guts of pdf_run_page_contents and pdf_run_annot operations are then extracted to give pdf_process_page_contents and pdf_process_annot, and the originals implemented in terms of these. This commit contains just one instance of a pdf_processor, namely the "run" processor, which contains the original code refactored. The graphical state (and device pointer) is now part of private data to the run operator set, rather than being in pdf_csi.
2014-02-28Fix harmless copy/paste error in pdf_copy_dict.Robin Watts
Thanks to Sebastian for spotting this.
2014-02-28Ensure that pdf_array_delete works even with indirected objects.Robin Watts
Add a RESOLVE(obj) call in line with other such functions.
2014-02-28Fix potential illegal access.Robin Watts
pdf_flush_text can cause the list of gstates to be extended. This can in turn cause them to move in memory. This means that any gstate pointers already held can be invalidated. Update the code to allow for this.
2014-02-25make pdf_new_obj_from_str throw on errorSimon Bünzli
Currently, pdf_new_obj_from_str returns NULL if the object can't be parsed. This isn't consistent with how all other pdf_new_* methods behave which is to throw on errors.
2014-02-25load StandardEncoding for non-embedded non-symbolic encoding-less fontsSimon Bünzli
See https://code.google.com/p/sumatrapdf/issues/detail?id=2526 for a file which renders wrongly if no encoding is loaded.
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 695040: prevent integer overflow in pdf_xref_size_from_old_trailerSimon Bünzli
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-25Delete unused variablePaul Gardiner
2014-02-25Support text (aka sticky note) annotationsPaul Gardiner
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-14Add function for creating form fields (widgets)Paul Gardiner
This feature is being implemented mostly for the purpose of permitting the addition to a page of invisible signatures. Also change pdf_create_annot to make freshly created annotations printable by default.
2014-02-14pdf-js: Pass a name string to type constructor.Tor Andersson
2014-02-14pdf-js.c: Cluster test fixes.Tor Andersson
Use a fixed number for Math.random(). Return a fixed date for Date.now() and Date.UTC().
2014-02-13pdf-util.js: Improve alert messages (also include the event value).Tor Andersson
2014-02-13pdf-util.js: Fix some regexps.Tor Andersson
2014-02-13pdf-util.js: Hoist var statements out of for statements.Tor Andersson
Make the scoping clearer, since Javascript doesn't have block scoping.
2014-02-13pdf-util.js: Always use strict equality comparisons.Tor Andersson
2014-02-13pdf-util.js: Use explicit type conversions in AFParseDateEx and AFParseTime.Tor Andersson