Commit Graph

220 Commits

Author SHA1 Message Date
Eliot Jones
a6541f1cfc fix test references
update references for unit tests to reference new core and fonts projects. all tests except the public api scanner tests now run successfully.
2020-01-04 22:56:41 +00:00
Eliot Jones
74774995d6 complete move of truetype, afm and standard14 fonts
the 3 font types mentioned are moved to the new fonts project, any referenced types are moved to the core project. most truetype classes are made public #8.
2020-01-04 22:39:13 +00:00
Eliot Jones
cf1b8651d6 make adler32checksum public
there's no reason to keep adler32checksum internal so it is made public in case people find it useful.
2020-01-04 10:27:07 +00:00
Eliot Jones
b15a3a9b57 tidy up truetype tables
* improves the naming of truetype related classes.
* uses correct numeric type for the loca table.
* makes a few related classes public.
2020-01-04 10:27:07 +00:00
Eliot Jones
90f8f97bfd add simple test case for subsetting issue #98
adds a single test which proves that the invalid truetype subsetting with roboto is related to our font subsetting code, since we can subset the same text correctly with windows calibri we must be reading roboto incorrectly.
2020-01-04 10:27:07 +00:00
Eliot Jones
fe315be2ef fix truetype subsetting for composite glyphs #98
each glyph included in the subset must count towards the number of glyphs, the horizontal metrics and the maximum profile table for the output truetype font. each glyph must also lie on a 4 byte boundary in the output file.

the output file is valid for the windows system font calibri containing accented characters but the roboto subset files are still invalid.

moves all subsetting related classes into their own namespace which will be made public.
2020-01-04 10:27:07 +00:00
Eliot Jones
336947db73 add writing methods to truetype tables #98
since we have verified the problem with the characters not appearing in acrobat reader isn't the checksum (other files also have invalid checksums but work) it seems likely the issue is with the os/2 table.

this change moves the logic for writing out the cmap table, the format 6 cmap sub-table, truetype table headers and the os/2 table into the classes themselves. now we can write an os/2 table and we've tested that the output matches the input, we can overwrite the os/2 table in order to work out which of the os/2 errors is causing our font to be invalid.

the writeable interface should be added to more and more parts of the codebase so that writing, editing and document creation become first class citizens rather than hardcoded additions.

this change also adds the macroman (1,0) cmap subtable to edited fonts so that it is present for consumers which expect it.
2020-01-04 10:27:07 +00:00
Eliot Jones
9fff879bd4 fix tests by using custom equality comparers
since we now round glyph widths for truetype fonts in the widths array of the pdf some values are out by a very small amount from the expected value. since we don't care about such fractional inaccuracy we use a custom comparer for these tests.
2020-01-04 10:27:07 +00:00
Eliot Jones
59c43cc526 truetype encoding replacer and checksum calculator #98
we need to provide a custom cmap for our overridden fonts when creating a document using truetype fonts. in order to do this without writing a complete subsetter (yet) we simply rearrange the font by moving the cmap table to the end of the font.

in order to keep a valid font we need to recalculate the offsets and checksums for all table headers. this adds a calculator which can calculate per-table checksums as well as the whole-font checksum used to calculate the checksum adjustment recorded in the head table.

now that the cmap table has been moved to the end of the font file we can overwrite it with a different-length custom cmap table without further invasive changes to the rest of the truetype file. this isn't implemented yet in this commit but will be the next thing to implement.

in truetype writing font we've temporarily reverted the change which maps characters to bytes until the custom cmap is written so we can ensure for this change the output font file is still valid and can be interpreted by pdf consumers. once the custom cmap is written we can uncomment the mapping logic and it should all just work.
2020-01-04 10:27:07 +00:00
Eliot Jones
f319e7f4b5 adds per character byte mapping to truetype #98
this starts to add logic for per-character mapping of unicode characters to byte values for truetype fonts in the pdf document builder. in order to support unicode characters outside the 0-255 range when creating new pdf documents without using composite fonts, we need to map values outside these range into this range. to do this we start at 1 and map each character we encounter to the next code, up to a maximum of 255. we provide a custom tounicode cmap in the font dictionary which maps these byte values, 0-255, back to unicode code points (short).

we also provide a custom firstchar, lastchar and widths array for the font mapping just the values we use.

since fonts no longer contain just the latin character set the font descriptor enum is set to have the symbolic flag set. this means values will be looked up in either the mac-roman (1, 0) or windows-symbol (3, 0) cmap tables (these cmap tables are distinct from cmap tables in the pdf file) inside the actual truetype font bytes. this means the currently generated font file is invalid, because while the widths array and tounicode cmap return the correct values the actual font itself returns whatever values where in those positions before the remapping occurred.

in order to fix this we will need to override the windows-symbol cmap contained in the underlying truetype font to match our mapping. this will be a lot of work and involve significant rewriting of the font file itself, in order to preserve checksum integrity.
2020-01-04 10:27:07 +00:00
BobLd
07f51712c6 Update PublicApiScannerTests 2020-01-03 12:31:23 +00:00
BobLd
3a060d9769 Update PublicApiScannerTests 2019-12-28 14:43:09 +00:00
Eliot Jones
87528199c6 use byte values when showing text for document builder #98
when writing text content the current show text operator was just writing the unicode string value and hoping it produced the correct value in the resulting document despite the values being consumed in a different encoding. this change adds a method to retrieve the corresponding byte value for a unicode character and uses that to write a hex show text operator to the page content. this is only implemented for standard14 fonts in this change.

for standard14 fonts we look up the corresponding name for the unicode value from the adobe glyph list. once we find the corresponding glyph name we look up the code value in the encoding we have chosen when writing standard14 fonts (macromanencoding). this value is then the byte value written to the show text operator. if the value does not appear in any of the lookups we throw a not support exception.

this also adds a test case which will still fail for czech characters in a truetype font, the issue reported in #98.
2019-12-28 14:42:27 +00:00
Eliot Jones
1e29c298cf use correct numeric types when parsing truetype fonts 2019-12-24 12:22:17 +00:00
Eliot Jones
935d182888 use doubles where calculations are being run 2019-12-24 12:22:17 +00:00
Eliot Jones
e984180b3d add method to retrieve any embedded files 2019-12-21 16:16:36 +00:00
Eliot Jones
4d697e3669 allow the user to supply multiple passwords for decryption
previously the only way to test if a password was correct was to supply a single password and throw if the value was incorrect. this was slow. now parsing options supports a list of passwords as well as a single password option (which is equivalent to a list with a single item). these passwords are all tested at the same time and an exception is only thrown once all passwords are tested.
2019-12-20 15:11:05 +00:00
Eliot Jones
7296c3c125 merge pull request #105 from BobLd/master
whitespace covering algorithm and #104
2019-12-20 11:57:31 +00:00
Eliot Jones
c30cd1b96d use cid font subroutines where applicable. add ucs 2 cmap support for type 1 fonts
* cid cff fonts have multiple sub-fonts and multiple private dictionaries, in addition to a top level font and private dictionary. this fix uses the specific sub-dictionary when getting local subroutines on a per-glyph basis.
* chinese, japanese or korean fonts can use a ucs-2 encoding cmap for retrieving unicode values.
* add support for the additional glyph list for unicode values in true type fonts. adds nonmarkingreturn mapping to carriage return.
* makes font parsing classes static where there's no reason for them to be per-instance.
2019-12-19 13:33:44 +00:00
BobLd
6dba5bb2b4 update PublicApiScannerTests 2019-12-18 11:43:39 +00:00
Eliot Jones
1fb416eee3 add convenience method to retrieve all hyperlinks and their text from annotations on a page 2019-12-18 11:41:02 +00:00
BobLd
5cf1f6c58c Modifications and adding som tests 2019-12-16 14:36:52 +00:00
BobLd
1656411fcb Improving Geometry classes with Tests 2019-12-14 11:41:11 +00:00
Eliot Jones
75a6260501 make cropbox public 2019-12-06 17:34:51 +00:00
Eliot Jones
e38da0a403 add support for alternative colorspace in separation colorspaces #89 2019-12-06 17:23:15 +00:00
Eliot Jones
e01d77b93a add negative test case and make tests non-lenient 2019-12-05 13:56:12 +00:00
Eliot Jones
2e5c995322 make external nodes different to document nodes and finish reimplementation 2019-12-05 13:21:19 +00:00
Eliot Jones
ecf0b8743b make bookmarknode immutable and use scanner when retrieving bookmarks 2019-12-05 12:03:30 +00:00
Eliot Jones
928347bcce merge pull request #84 from BobLd/master
add basic bookmarks extraction capabilities.
2019-12-04 14:24:10 +00:00
Eliot Jones
a967e0898a handle missing width and height correctly for compact font format fonts #75 2019-12-04 14:19:06 +00:00
Eliot Jones
80f024dbed make form access public 2019-11-27 16:36:25 +00:00
Eliot Jones
df3cb43cfc update coverage libraries 2019-11-27 16:16:11 +00:00
Eliot Jones
ed53773c7b handle checked state of radio buttons and checkboxes 2019-11-27 15:34:28 +00:00
Eliot Jones
910e22a4e9 wrap checkboxes and radiobuttons in their own form field types with access to the child collections 2019-11-26 16:33:24 +00:00
BobLd
89daa2818e update PublicApiScannerTests 2019-11-04 15:17:25 +00:00
BobLd
99f260befb Enhancing NearestNeighbourWordExtractor
- Making the code easier to read
- Using 20% of Width instead of 60%
- Making DefaultWordExtractor public
2019-10-21 20:51:27 +01:00
Eliot Jones
efe7896824 #75 support vertical writing mode fonts 2019-10-17 15:57:04 +01:00
Eliot Jones
a2147902a0 merge pull request #72 from uglytoad/fix-export-formatting
fix export formatting
2019-10-17 11:28:06 +01:00
Eliot Jones
57dfee3211 move alto xml exporter to root export namespace 2019-10-17 10:46:43 +01:00
Eliot Jones
3f1321141a #73 process xobject form content when extracting text and images 2019-10-16 14:59:16 +01:00
Eliot Jones
6174877892 #71 ignore malformed dates in true type header table. fix reading of dates from bytes 2019-10-16 10:51:02 +01:00
Eliot Jones
f14c52a05a fix tests for renaming and validating generate alto xml 2019-10-15 13:59:09 +01:00
Eliot Jones
d68bd88824 format and tidy up alto export autogenerated code. tidy up docstrum 2019-10-14 18:30:18 +01:00
BobLd
e76badaeaf Update PublicApiScannerTests with new public classes 2019-10-11 08:57:16 +01:00
BobLd
f886411e12 Merge https://github.com/UglyToad/PdfPig 2019-10-10 16:52:45 +01:00
Eliot Jones
dec4c31a33 fix bug where cross reference stream subsections were skipped
a single cross-reference stream may contain multiple disjoint runs of object numbers, previously we only took the first now we load all objects.

adds indexer to array token for ease-of-use.

adds page number and bounds information to all form fields.
2019-10-10 16:05:21 +01:00
BobLd
fe1a3c4b8b updated from comments
- still need to look at XmlWriter
2019-10-10 12:29:28 +01:00
Eliot Jones
2ef45f71d5 make missing acroform types public and start improving data
also changes pages to use a proper tree structure since this will be required for resource inheritance and for acroform widget dictionaries.
2019-10-09 14:28:37 +01:00
BobLd
9ab943e1f9 Merge branch 'master' of https://github.com/UglyToad/PdfPig 2019-10-08 14:16:59 +01:00
Eliot Jones
68bcaf3901 #55 move support for images to page and add inline images
support both xobject and inline images. adds unsupported filters so that exceptions are only thrown when accessing lazily evaluated image.bytes property rather than when opening the page.

treat all warnings as errors.
2019-10-08 14:04:36 +01:00