Commit Graph

693 Commits

Author SHA1 Message Date
Calixte Denizet
405f573d70 Take into account empty lines when extracting text content from the appearance
Fixes #17492.
2024-01-14 20:23:29 +01:00
Calixte Denizet
0392feaee4 Remove terminal white spaces when extracting text from annotation appearances 2024-01-09 10:42:53 +01:00
Calixte Denizet
7839e7b495 Preserve the whitespaces when getting text from FreeText annotations (bug 1871353)
When the text of an annotation is extracted in using getTextContent, consecutive white spaces
are just replaced by one space and. So this patch add an option to make sure that white
spaces are preserved when appearance is parsed.
For the case where there's no appearance, we can have a fast path to get the correct string
from the Content entry.
When an existing FreeText is edited, space (0x20) are replaced by non-breakable (0xa0) ones
to make to see all of them on screen.
2024-01-05 10:20:32 +01:00
Calixte Denizet
35863cd54b [Editor] Take into account the crop box when saving/printing some highlighted text (bug 1872721) 2024-01-02 18:53:33 +01:00
Calixte Denizet
ae5828c968 [Editor] Avoid conflicts between new persistent refs and the ones created when saving (bug 1865341)
When a pdf as a FreeText without appearance, we use a fake font in order to render it
and that leads to create few new refs for the font.
But then when we're saving, we create some new refs which start at the same number
as the previous created ones.
Consequently, when saving we're using some wrong objects (like a font) to check if
we're able to render the newly added FreeText.
In order to fix this bug, we just remove the persistent refs (which are only used
when rendering/printing) during the saving.
2023-12-05 12:33:21 +01:00
Calixte Denizet
ec396c2150 Don't avoid to execute the Blur callback when blurring a text field (bug 1863910) 2023-11-09 13:50:33 +01:00
Calixte Denizet
085aa4207d Render rich text with only one text element 2023-11-02 15:35:52 +01:00
JT-External
0eacd5c107 Fix size of maskCanvas to draw image masks correctly
Use existing helper to calculate the Box

Co-authored-by: Jonas Jenwald <jonas.jenwald@gmail.com>

Ensure that there are non-zero

Co-authored-by: Jonas Jenwald <jonas.jenwald@gmail.com>

Add a reference test for #17147
2023-10-20 23:46:24 +09:00
Calixte Denizet
40b1d92044 Update the noHTML flag to take into account the hasOwnCanvas one (fixes #17069)
When an element has the hasOwnCanvas flag we must have an HTML container to attach
the canvas where the element will be rendered.
So the noHTML flag must take this information into account:
 - in some cases the noHTML flag is resetted depending on the hasOwnCanvas value;
 - in some others, the hasOwnCanvas flag is set depending on the value of noHTML.
2023-10-04 18:06:21 +02:00
Jonas Jenwald
bf9c33e60f Add support for "GoToE" actions with destinations (issue 17056)
This shouldn't be very common in practice, since "GoToE" actions themselves seem quite uncommon; see PR 15537.
2023-10-04 11:14:23 +02:00
Calixte Denizet
1be9bbd2e1 Compute correctly the bounding box of a transformed rectangle (fixes #17065) 2023-10-03 23:50:59 +02:00
Jonas Jenwald
f113320bd5 Ensure that readonly TextWidget-annotations are rendered when forms are disabled (issue 17064)
To reduced the risk of regressing something else, given that the issue only applies to a (for the default viewer) non-default configuration, this patch is purposely limited to only TextWidget-annotations in the display layer.
2023-10-03 21:26:08 +02:00
Calixte Denizet
a00b542f2f Unconditionally render non-form annotations in the annotation layer (bug 1851498)
The goal is to always have something which is focusable to let the user select
it with the keyboard.
It fixes the mentioned bug because, the annotation layer will now have a container
to attach the canvas for annotations having their own canvas.
2023-09-05 10:41:01 +02:00
Calixte Denizet
d185db2b70 Add tagged annotations in the structure tree (bug 1850797) 2023-08-31 12:35:32 +02:00
Calixte Denizet
7a5b3423d6 [Editor] Don't forget to encrypt image streams (see issue #16821)
and encrypt a compressed stream after having been compressed.
2023-08-10 15:19:45 +02:00
Calixte Denizet
71960bea64 Don't print hidden annotatons (bug 1815196)
and handle correctly the NoView and NoPrint flags when they're changed
from JS.
2023-07-31 13:04:15 +02:00
Calixte Denizet
d470e91223 Don't get the text content for an annotation when /NeedAppearances is true (bug 1844583)
When the flag is set, the appearance has to be generated from the value so it's
useless/meaningless to extract the content from the existing appearance.
2023-07-21 12:26:27 +02:00
Calixte Denizet
9277801493 Text annotations must use their own canvas when their appearance is generated (bug 1844576)
When a pdf has /NeedAppearances set to true, the annotation appearance must be
generated from its value and we must take into account the hasOwnCanvas property.
2023-07-21 09:51:50 +02:00
Calixte Denizet
944c68ee85 [Editor] Try to make the position of an edited FreeText the more accurated as possible
- Take into account the page translation,
- Take into account the correct translation for the editor border,
- Take into account the position of the first glyph in the annotation,
- Take into account the rotation of the editor.

Close #16633.
2023-07-12 19:53:57 +02:00
Calixte Denizet
85b38fc247 Add a test to check that the compression is ok when saving an annotation 2023-06-16 10:05:42 +02:00
Calixte Denizet
be25ee12bb Add a container for Signature with their own canvas 2023-06-15 16:11:52 +02:00
Calixte Denizet
1a047f843c [Editor] Add the possibility to update an existing annotation with some new properties when saving or printing 2023-06-09 17:14:53 +02:00
Calixte Denizet
3d0ce1cff2 Concat data when push fails in the CFF compiler 2023-06-09 15:48:01 +02:00
Jonas Jenwald
459d26edec Improve handling of mismatching /BaseFont and /FontName entries for non-embedded fonts (issue 7454)
This patch is the result of me going through some old issues regarding non-embedded Wingdings support.

There's a few different things wrong in the referenced PDF document:
 - The /BaseFont and /FontName entries don't agree on the name of the fonts, with one font using `/BaseFont /Wingdings-Regular` and `/FontName /wg09np` which obviously makes no sense.
   To address this we'll compare the font-names against our lists of known ones and ignore /FontName entries that don't make sense iff the /BaseFont entry is a known font-name.
 - The non-embedded Wingdings font also set an incorrect /Encoding, in this case /MacRomanEncoding, which should have been fixed by PR 16465. However this doesn't work since the font has *bogus* font-flags, that fail to categorize the font as Symbolic.
   To address this we'll also compare the font-name against the list of known symbol fonts.
2023-06-02 17:10:25 +02:00
Calixte Denizet
0e610cab04 Try to not omit some values when printing a choice list with several selected items 2023-05-31 21:17:22 +02:00
Calixte Denizet
78e6020a6e [OTS] Remove cntrmask instruction with no stem in charstring (bug 1529502) 2023-05-28 19:03:37 +02:00
Calixte Denizet
be5db13005 Reset the formatted value when after a text field has been modified 2023-05-26 10:17:14 +02:00
Jonas Jenwald
f657de7de2 Extend getNonStdFontMap for non-embedded Impact fonts (bug 1365930)
According to https://en.wikipedia.org/wiki/Impact_(typeface) this font should be available on all current versions of Windows, and with the recently added font-substitution we should actually be able to render it correctly (at least on Windows).
2023-05-19 18:40:03 +02:00
Calixte Denizet
3091e70aad Flush the current chunk when the font changed because of a restore op (issue #14755) 2023-05-18 19:37:16 +02:00
Calixte Denizet
177036e6ae For text widgets, get the text from the AP stream instead of from the format callback (bug 1825002)
When fixing bug 1766987, I thought the field formatted value came from
the result of the format callback: I was wrong. The format callback is ran
but the value is unused (maybe it's useful to set some global vars... or
it's just a bug in Acrobat). Anyway the value to display is the one rendered
in the AP stream.
The field value setter has been simplified and that fixes issue #16409.
2023-05-17 14:07:28 +02:00
Calixte Denizet
2486536843 Compress the data when saving annotions
CompressionStream API has been added in Firefox 113
(see https://bugzilla.mozilla.org/show_bug.cgi?id=1823619)
hence we can use it to compress the streams with added/modified
annotations.
2023-05-09 14:46:50 +02:00
Calixte Denizet
6c0fdc6ec2 Make something similar to Acrobat when Underline annotation has no appearance 2023-05-06 21:19:25 +02:00
calixteman
a24e11a91c
Merge pull request #16106 from bungeman/improve_color_stop_detection
Better approximate gradient color stops
2023-05-04 19:48:57 +02:00
Calixte Denizet
19ca41896e Correctly clip the text in the text layer (fixes #16316) 2023-04-18 17:00:42 +02:00
Calixte Denizet
117bbf7cd9 [api-minor] Don't normalize the text used in the text layer.
Some arabic chars like \ufe94 could be searched in a pdf, hence it must be normalized
when creating the search query. So to avoid to duplicate the normalization code,
everything is moved in the find controller.
The previous code to normalize text was using NFKC but with a hardcoded map, hence it
has been replaced by the use of normalize("NFKC") (it helps to reduce the bundle size
by 30kb).
In playing with this \ufe94 char, I noticed that the bidi algorithm wasn't taking into
account some RTL unicode ranges, the generated font wasn't embedding the mapping this
char and the unicode ranges in the OS/2 table weren't up-to-date.

When normalized some chars can be replaced by several ones and it induced to have
some extra chars in the text layer. To avoid any regression, when copying some text
from the text layer, a copied string is normalized (NFKC) before being put in the
clipboard (it works like this in either Acrobat or Chrome).
2023-04-17 14:31:23 +02:00
Calixte Denizet
8e5f4c0622 [Editor] Take into account the initial rotation (issue #16278) 2023-04-16 21:36:26 +02:00
Jonas Jenwald
3a36a9d337
Merge pull request #16268 from Snuffleupagus/RegionalImageCache
Attempt to also cache images at the "page"-level (issue 16263)
2023-04-11 12:06:29 +02:00
Jonas Jenwald
9881dbf927 Attempt to also cache images at the "page"-level (issue 16263)
Currently we have two separate image-caches on the worker-thread:
 - A local one, which is unique to each `PartialEvaluator.getOperatorList` invocation. This one caches both names *and* references, since image-resources may be accessed in either way.
 - A global one, which applies to the entire PDF documents and all its pages. This one only caches references, since nothing else would work.

This patch introduces a third image-cache, which essentially sits "between" the two existing ones. The new `RegionalImageCache`[1] will be usable throughout a `PartialEvaluator` instance, and consequently it *only* caches references, which thus allows us to keep track of repeated image-resources found in e.g. different /Form and /SMask objects.

---
[1] For lack of a better word, since naming things is hard...
2023-04-10 11:34:41 +02:00
Calixte Denizet
4b7eb1436d Thin whitespaces must have their own span 2023-03-29 11:23:58 +02:00
Calixte Denizet
a96f10e55d Create a new chunk when the char is too rised compared to the previouse one 2023-03-28 13:56:46 +02:00
Jonas Jenwald
d4bcfe8c16 Support multi-byte ToUnicode entries, when using predefined CMaps (issue 16176)
Hopefully this makes sense, since we already "create" multi-byte ToUnicode entries in other cases (see e.g. the `getNormalizedUnicodes` table).
2023-03-21 21:35:57 +01:00
calixteman
b2a86350fc
Merge pull request #16096 from bungeman/fix_trig_functions
Correct PostScript trigonometric operators
2023-03-11 14:32:23 +01:00
Calixte Denizet
07b094729e Fix search in pdf a containing some UTF-32 characters (bug 1820909)
Some chars were supposed to have a length equals to 1 but UTF-32 chars
can be longuer.
2023-03-09 15:03:01 +01:00
Ben Wagner
5fad91a680 Better approximate gradient color stops
PDF gradients do not have color stops but an arbitrary PDF function of
the type f(t) -> color. CSS gradients are only based on color stops.
Most PDF gradient functions are produced from color stop oriented
gradients.

Take advantage of this by sampling the PDF function at a higher
frequency but not converting any samples which could be interpolated to
color stops. The sampling frequency is chosen to be the least common
multiple of as many values as practical to exactly re-create the common
case of the PDF function implementing equally spaced linearly
interpolated stops in RGB color space. This also allows for better
approximation of other smooth PDF functions (non-linear, or non-equally
spaced, or in different color space).

Fixes: #10572, #14165
2023-03-09 08:49:50 -05:00
Ben Wagner
158c836e26 Correct PostScript trigonometric operators
PDF 32000-1:2008 7.10.5.1 "Type 4 (PostScript Calculator) Functions"
defers to the PostScript Language Reference for the description of these
functions. The PostScript Language Reference, third edition chapter 8
"Operators" defines the `angle` type as a "number of degrees". Section
8.1 defines "angle `sin` real", "angle `cos` real", and "num den `atan`
angle". The documentation for `atan` further states that it will return
an angle in degrees between 0 and 360.

Handle these operators correctly in `PostScriptEvaluator.execute`.
Convert the inputs to `sin` and `cos` from degrees to radians for use
with `Math.sin` and `Math.cos`. Correctly pop two values from the stack
for `atan`, use `Math.atan2`, and convert from radians to (positive)
degrees.
2023-03-03 17:25:11 -05:00
Calixte Denizet
dca54c8f8a [JS] Send a Validate action on change on Choice widget 2023-02-19 16:33:05 +01:00
Calixte Denizet
fc7d74385f Don't replace an eol by a whitespace when the last char is a Katakana-Hiragana diacritic 2023-02-16 11:31:58 +01:00
Calixte Denizet
58e4d92884 [Annotation] For choice widget, use the I entry instead of the V one (bug 1770750)
It isn't really conform to the specifications but Acrobat is working like that...
2023-02-09 17:26:13 +01:00
Calixte Denizet
a25895bf72 [Annotation] Take into account the stroke alpha for a FreeText without appearance 2023-02-07 22:15:27 +01:00
Calixte Denizet
ea7b4b4d6c [Annotation] Avoid to encrypt the appearance stream two times (bug 1815476) 2023-02-07 19:26:46 +01:00