Commit Graph

1040 Commits

Author SHA1 Message Date
Jonas Jenwald
885e7a8aa4 Allow StreamsSequenceStream.readBlock to skip sub-streams with errors (issue 13794)
This patch makes use of the existing `ignoreErrors` option, thus allowing a page to continue parsing/rendering even if (some of) its sub-streams are corrupt. Obviously this may cause *part* of a page to be broken/missing, however it should be better than (potentially) rendering nothing.
Also, to the best of my knowledge, this is the first bug of its kind that we've encountered.

To avoid having to pass in a bunch of, for a `BaseStream`-instance, mostly unrelated parameters when initializing a `StreamsSequenceStream`-instance, I settled on utilizing a callback function instead to allow conditional Error-suppression.
Note that the `StreamsSequenceStream`-class is a *special* stream-implementation that we only use when the `/Contents`-entry, in the `/Page`-dictionary, consists of an Array with streams.
2021-07-26 16:42:50 +02:00
Jonas Jenwald
b82c802dff When parsing corrupt documents, avoid inserting obviously broken data in the XRef-table (issue 13783)
In cases where even the very *first* attempt at reading from an object will throw, simply ignoring such objects will help improve rendering of *some* corrupt documents.
Note that this will lead to more parsing in some cases, but considering that this only applies to *corrupt* documents that shouldn't be a big deal.
2021-07-23 18:10:53 +02:00
Brendan Dahl
da1af02ac8 Improve performance of reused patterns.
Bug 1721218 has a shading pattern that was used thousands of times.
To improve performance of this PDF:
 - add a cache for patterns in the evaluator and only send the IR form once
   to the main thread (this also makes caching in canvas easier)
 - cache the created canvas radial/axial patterns
 - for shading fill radial/axial use the pattern directly instead of creating temporary
   canvas
2021-07-22 16:47:40 -07:00
Jonas Jenwald
2cf90cd9ad
Merge pull request #13766 from Snuffleupagus/issue-13751
XFA - Handle `startIndex` correctly in the `Template.$toHTML` method (issue 13751)
2021-07-21 18:58:29 +02:00
Calixte Denizet
5555114bb3 XFA - Remove namespace from nodes under xfa:data node
- in real life some xfa contains xml like <xfa:data><xfa:Foo><xfa:Bar>...</xfa:data>
    since there are no Foo or Bar in the xfa namespace the JS representation are empty
    and that leads to errors.
  - so the idea is to make all nodes under xfa:data namespace agnostic which means
    that ns are removed from nodes in the parser but only xfa:data descendants.
2021-07-21 17:11:31 +02:00
Jonas Jenwald
7d1c19f8bd XFA - Handle startIndex correctly in the Template.$toHTML method (issue 13751)
*Please note:* The PDF document in issue 13751 is *dynamically* created (in e.g. Adobe Reader), with pages added when certain buttons are clicked, hence this patch simply fixes the breaking error and nothing more.

It looks like the current code contains a little bit too much copy-and-paste from the *similar* `index` branch above, since we cannot set the `startIndex` to a negative value. Note how it's being used to initialize the loop-variable, which is then used to lookup values in an Array and accessing the `-1`th element of an Array obviously makes no sense.
2021-07-21 16:17:13 +02:00
Jonas Jenwald
c2fe493abe XFA - Add a missing method to XFAAttribute, to prevent breaking errors (issue 13748)
*This is yet another case where I've got no idea if the patch is correct, but it does at least fix a breaking error :-)*

Note how in the [`Binder._bindValue` method](683ce66a48/src/core/xfa/bind.js (L92-L93)), we're assuming that if a `data`-value exists then it'll also be possible to actually access it. For the `XFAAttribute`-implementation however, the second method is missing and that's what causes the breaking errors in issue 13748.

Please note that another possible way of "fixing" the error wouldn't been to simply change the exists-check to return `false`, and I could see that being a preferred solution.
However, the reason for submitting the current patch is that we get *fewer* warnings about Nodes with mis-matched types this way.
2021-07-20 17:41:05 +02:00
Jonas Jenwald
cf7978d507 XFA - Prevent breaking errors in Binder, when searchNode doesn't return data (issue 13756)
As can be seen in the code (see below), the `searchNode` helper function will return `null` in some cases and all of its call-sites should protect against that before attempting to access the returned data.
While only one of these changes were necessary to fix the breaking errors in issue 13756, in order to prevent future bugs I've added similar defensive code throughout this file.

 - 07955fa1d3/src/core/xfa/som.js (L169)
 - 07955fa1d3/src/core/xfa/som.js (L239)
 - 07955fa1d3/src/core/xfa/som.js (L254)
2021-07-19 18:07:07 +02:00
Jonas Jenwald
da808aeab3 Ensure that the field value, for checkboxes, refers to an existing appearance state (bug 1720411)
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1720411
2021-07-16 13:11:48 +02:00
Calixte Denizet
3fb30ddde5 XFA - Checkboxes must be printed (bug 1720182)
- to avoid future regressions, annotationStorage is passed to the xfa render in reftests.
2021-07-16 11:32:03 +02:00
Calixte Denizet
5081167e7f XFA - A rectangle must have the width of its parent but without inner margins
- it aims to fix #13584;
  - to avoid bad rendering because of clipping just set overflow to visible on SVG element.
2021-07-14 16:46:13 +02:00
Calixte Denizet
dd55e76f5d XFA - Avoid to have containers not pushed in the html
- it aims to fix issue #13668.
2021-07-12 21:34:58 +02:00
calixteman
140c2bc563
Revert "XFA - Avoid to have containers not pushed in the html" 2021-07-12 09:46:38 +02:00
Calixte Denizet
fccc6c2242 XFA - Avoid to have containers not pushed in the html
- it aims to fix issue #13668.
2021-07-11 19:14:44 +02:00
Calixte Denizet
690b5d1941 XFA - Use fake MyriadPro as a fallback for missing fonts
- aims to fix #13597.
2021-07-11 13:52:13 +02:00
Calixte Denizet
58e1f51688 XFA - Fix text positions (bug 1718741)
- font line height is taken into account by acrobat when it isn't with masterpdfeditor: I extracted a font from a pdf, modified some ascent/descent properties thanks to ttx and the reinjected the font in the pdf: only Acrobat is taken it into account. So in this patch, line heights for some substituted fonts are added.
  - it seems that Acrobat is using a line height of 1.2 when the line height in the font is not enough (it's the only way I found to fix correctly bug 1718741).
   - don't use flex in wrapper container (which was causing an horizontal overflow in the above bug).
   - consequently, the above fixes introduced a lot of small regressions, so in order to see real improvements on reftests, I fixed the regressions in this patch:
     - replace margin by padding in some case where padding is a part of a container dimensions;
     - remove some flex display: some containers are wrongly sized when rendered;
     - set letter-spacing to 0.01px: it helps to be sure that text is not broken because of not enough width in Firefox.
2021-07-09 18:11:12 +02:00
calixteman
c33bf0b5e8
Merge pull request #13692 from calixteman/bind_global
XFA - Correctly bind global data (bug 1718725)
2021-07-08 12:42:22 +02:00
Calixte Denizet
8a06df9253 XFA - Handle correctly nested containers with lr-tb layout (bug 1718670)
- and avoid to push a field with no dimensions when we have some available space in width in a parent.
2021-07-07 18:54:32 +02:00
Calixte Denizet
778800a53a XFA - Correctly bind global data (bug 1718725) 2021-07-07 17:36:56 +02:00
calixteman
1eb9a3e9eb
Merge pull request #13687 from calixteman/failing_som
XFA - Don't fail xfa loading because of a JS subexpression in SOM expressions
2021-07-07 11:50:26 +02:00
Calixte Denizet
0486d24e36 XFA - Don't fail xfa loading because of a JS subexpression in SOM expressions
- Fix for one pdf in bug 1717668 (PDFIUM-292-0.pdf).
2021-07-07 10:47:53 +02:00
Jonas Jenwald
05ebb6329b
Merge pull request #13683 from brendandahl/mask-fixes
Fix transformations when painting image masks and tiling patterns.
2021-07-07 10:24:01 +02:00
Brendan Dahl
a52c0c6988 Fix transformations when painting image masks and tiling patterns.
Previously, when we filled image masks we didn't copy over the current transformation,
this caused patterns to be misaligned when painted. Now we create a temporary
canvas with the mask and have the transform copied over and offset it relative to
where the mask would be painted. We also weren't properly offsetting tiling patterns.
This isn't usually noticeable since patters repeat, but in the case of #13561 the pattern
is only drawn once and has to be in the correct position to line up with the mask image.

These fixes broke #11473, but highlighted that we were drawing that correctly by
accident and not correctly handling negative bounding boxes on tiling patterns.

Fixes #6297,  #13561, #13441

Partially fixes #1344 (still blurry but boxes are in correct position now)
2021-07-06 17:29:32 -07:00
Calixte Denizet
c47f0f0f40 XFA - Default background in rectangle is white
- Fix a typo in order to open the pdf in issue #13679
  - After fixing the fill default color there wer some regressions because of z-index
    and when fixing z-index there were some regressions because of borders
  - So fix the borders rendering.
2021-07-06 21:17:20 +02:00
Calixte Denizet
5f76b6370c XFA - Layout correctly a subform with row layout (bug 1718740)
- Fix issues with subformSet elements which are not a real container.
2021-07-06 14:11:25 +02:00
calixteman
ba2d685166
Merge pull request #13673 from calixteman/images2
XFA - An image can be a stream in the pdf (bug 1718521)
2021-07-06 09:53:29 +02:00
Calixte Denizet
5cdee80c8e XFA - An image can be a stream in the pdf (bug 1718521) - hrefs can be found in catalog > Names > XFAImages 2021-07-05 14:06:23 +02:00
calixteman
783cbc1793
Revert "XFA - An image can be a stream in the pdf (bug 1718521)" 2021-07-05 12:47:14 +02:00
Calixte Denizet
9b5574d3ef XFA - Fix indentation for justified paragraph
- and ceil the reserve for a caption to avoid to split it;
  - both issues are present in the pdf in issue #13633.
2021-07-03 18:07:01 +02:00
Calixte Denizet
f16828be49 XFA - An image can be a stream in the pdf (bug 1718521)
- hrefs can be found in catalog > Names > XFAImages
2021-07-02 20:34:10 +02:00
calixteman
d80651e572
Merge pull request #13598 from calixteman/dhl
XFA - Remove empty pages
2021-06-30 20:43:07 +02:00
Calixte Denizet
08e08d5852 XFA - Don't fill when the fill element is not visible (bug 1718735) 2021-06-30 17:14:08 +02:00
Calixte Denizet
ff440d13e7 XFA - Remove empty pages
- it aims to fix #13583;
  - fix the switch to breakBefore target;
  - force the layout of an unsplittable element on an empty page;
  - don't fail when there is horizontal overflow (except in lr-tb);
  - handle correctly overflow in the same content area (bug 1717805, bug 1717668);
  - fix a typo in radial gradient first argument.
2021-06-30 16:32:27 +02:00
Marco Castelluccio
db15205e2c Add PDFs from #1773 to the reftests 2021-06-29 16:35:06 +02:00
Calixte Denizet
71d17b0cc4 XFA - Implement aspect property on image element
- it aims to fix issue #13634;
  - move some img-related functions in test/drivers.js in order to have images in xfa reftests.
2021-06-28 20:43:39 +02:00
Calixte Denizet
b261446981 XFA - Fix width of a container with lr-tb layout (bug 1718037) 2021-06-28 17:47:04 +02:00
calixteman
03dff1c5f5
Merge pull request #13639 from calixteman/old_break
XFA - Replace deprecated break element (bug 1718053)
2021-06-28 17:44:03 +02:00
Calixte Denizet
677332aa7b XFA - Remove quotes of font name in xhtml 2021-06-27 18:05:12 +02:00
Calixte Denizet
257de0e8c5 XFA - Replace deprecated break element (bug 1718053)
- the break element has been deprecated in XFA 2.4 but some old documents can use it, so replace it with one (or more) of its possible substitutions:
    - breakBefore;
    - breakAfter;
    - overflow.
2021-06-27 15:03:00 +02:00
Tim van der Meij
d7f8a0e9b9
Merge pull request #13628 from Snuffleupagus/issue-13626
Check that TrueType (3, 0) cmap tables, for symbolic fonts, are sorted correctly (issue 13626)
2021-06-26 14:17:11 +02:00
Calixte Denizet
429ffdcd2f XFA - Save filled data in the pdf when downloading the file (Bug 1716288)
- when binding (after parsing) we get a map between some template nodes and some data nodes;
  - so set user data in input handlers in using data node uids in the annotation storage;
  - to save the form, just put the value we have in the storage in the correct data nodes, serialize the xml as a string and then write the string at the end of the pdf using src/core/writer.js;
  - fix few bugs around data bindings:
    - the "Off" issue in Bug 1716980.
2021-06-25 18:57:01 +02:00
Jonas Jenwald
185be678ec Check that TrueType (3, 0) cmap tables, for symbolic fonts, are sorted correctly (issue 13626)
According to a comment in `readCmapTable`, we're assuming that the cmap tables (when more than one exist) are sorted in ascending order. If that's not the case, keep checking the following cmap tables in order to fix the referenced issue.
2021-06-25 16:56:00 +02:00
Tim van der Meij
ad4b2ce021
Merge pull request #13612 from Snuffleupagus/issue-13610
Support corrupt documents with *empty* `Name`-entries (issue 13610)
2021-06-23 21:49:02 +02:00
Calixte Denizet
e82446fa5a XFA - Get line height from the font
- when the CSS line-height property is set to 'normal' then the value depends of the user agent. So use a line height based on the font itself and if for any reasons this value is not available use 1.2 as default.
  - it's a partial fix for https://bugzilla.mozilla.org/show_bug.cgi?id=1717681.
2021-06-23 14:11:10 +02:00
Jonas Jenwald
6467907318 Support corrupt documents with *empty* Name-entries (issue 13610)
Apparently some really bad PDF software can create documents with *empty* `Name`-entries, which we thus need to somehow deal with.
While I don't know if this patch is necessarily the best solution, it should at least ensure that the *empty* `Name`-instance cannot accidentally match a proper `Name`-instance (and it doesn't require changes to a lot of existing code).[1]

---
[1] I briefly considered using a `Symbol` rather than an Object, but quickly decided against that since the former one [is not clonable](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types) and `Name`-instances may be sent to the API.
2021-06-22 16:55:44 +02:00
Calixte Denizet
aca102a35e XFA - Add margins if needed after having layout some text 2021-06-22 10:36:01 +02:00
calixteman
56a75f8b26 Revert "Revert "XFA - Fix the way to select page on breaking"" - and fix the error which caused the backout: add an $extra property when creating html. - switch to next content area when breaking on page area. 2021-06-21 17:07:31 +02:00
calixteman
a9385bbb52
Revert "XFA - Fix the way to select page on breaking" 2021-06-21 15:45:04 +02:00
Calixte Denizet
7aea8faa34 XFA - Fix the way to select page on breaking
- it aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1716838.
  - some fonts in the pdf in the bug where bold when they shouldn't so write the font properties in the html to avoid to use some wrong inherited ones.
2021-06-21 12:45:23 +02:00
Calixte Denizet
7cb92a64b1 XFA - Add support for access property
- it's a partial fix for https://bugzilla.mozilla.org/show_bug.cgi?id=1716816.
2021-06-21 09:56:28 +02:00