summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibPDF
AgeCommit message (Collapse)Author
2022-01-24LibPDF: Make Filter::decode() return ErrorOrSam Atkins
2022-01-24AK+Userland: Make AK::decode_hex() return ErrorOrSam Atkins
This lets us propagate the reason why it failed up to the caller. :^)
2022-01-24Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOrSam Atkins
Apologies for the enormous commit, but I don't see a way to split this up nicely. In the vast majority of cases it's a simple change. A few extra places can use TRY instead of manual error checking though. :^)
2022-01-08LibPDF: Convert `PDF::Parser::m_document` from `RefPtr` to `WeakPtr`Simon Woertz
Otherwise both `PDF::Document` and `PDF::Parser` have a `RefPtr` pointing to each other which leads to a memory leak due to a circular dependency.
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-11-16LibPDF: Check if there is data left before consumingSimon Woertz
Add a check to `Parser::consume_eol` to ensure that there is more data to read before actually consuming any data. Not checking if there is data left leads to failing an assertion in case of e.g., a truncated pdf file.
2021-11-11Userland: Include Vector.h in a few places to make HeaderCheck happyAli Mohammad Pur
This header was being transitively pulled in, but that no longer happens after 5f7d008791f9e358638283dc2f0d709a601344ff.
2021-11-11Everywhere: Pass AK::ReadonlyBytes by valueAndreas Kling
2021-11-11Everywhere: Pass AK::StringView by valueAndreas Kling
2021-11-10AK: Make ByteBuffer::try_* functions return ErrorOr<void>Andreas Kling
Same as Vector, ByteBuffer now also signals allocation failure by returning an ENOMEM Error instead of a bool, allowing us to use the TRY() and MUST() patterns.
2021-10-30LibPDF: Parser::parse_header() return false if remaining bytes is zeroBrendan Coles
2021-09-21LibPDF: Rely on default-constructor of VariantBen Wiederhake
2021-09-20LibPDF: Replace Value class by AK::VariantBen Wiederhake
This decreases the memory consumption by LibPDF by 4 bytes per Value, compensating exactly for the increase in an earlier commit. :^)
2021-09-20LibPDF: Extract reference bitpacking into dedicated classBen Wiederhake
2021-09-20LibPDF: Move inline function definitionBen Wiederhake
This breaks the dependency cycle between Parser and Document.
2021-09-20LibPDF: Break weird dependency cycleBen Wiederhake
Old situation: Object.h defines Object Object.h defines ArrayObject ArrayObject requires the definition of Object ArrayObject requires the definition of Value Value.h defines Value Value requires the definition of Object Therefore, a file with the single line "#include <Value.h>" used to raise compilation errors; certainly not something that one might expect from a library. This patch splits up the definitions in Object.h to break the cycle. Now, Object.h only defines Object, Value.h still only defines Value (and includes Object.h), and the new header ObjectDerivatives.h defines ArrayObject (and includes both Object.h and Value.h).
2021-09-20LibPDF: Add missing headers in Value.hBen Wiederhake
2021-09-20LibPDF: Fix math error in commentsBen Wiederhake
2021-09-20LibPDF: Switch to automatic ref counting, fix memory leakBen Wiederhake
At least `Value::operator=` didn't properly unref the `PDF::Object` when it was called. This type of problem is removed by just letting `RefPtr` do its thing. This patch increases the memory consumption by LibPDF by 4 bytes (the other union objects) per value.
2021-09-20LibPDF: Add missing headers to XRefTable.hBen Wiederhake
2021-09-20LibPDF: Add missing headers to Reader.hBen Wiederhake
2021-09-20LibPDF: Add missing headers to Forward.hBen Wiederhake
2021-09-16LibPDF: Use move to avoid unnecessary ref/unref of network device RefPtrBrian Gianforcaro
Flagged by pvs-studio as a potential perf optimization.
2021-09-06Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safeAli Mohammad Pur
2021-09-06Everywhere: Use OOM-safe ByteBuffer APIs where possibleAli Mohammad Pur
If we can easily communicate failure, let's avoid asserting and report failure instead.
2021-09-03Everywhere: Prevent risky implicit casts of (Nonnull)RefPtrDaniel Bertalan
Our existing implementation did not check the element type of the other pointer in the constructors and move assignment operators. This meant that some operations that would require explicit casting on raw pointers were done implicitly, such as: - downcasting a base class to a derived class (e.g. `Kernel::Inode` => `Kernel::ProcFSDirectoryInode` in Kernel/ProcFS.cpp), - casting to an unrelated type (e.g. `Promise<bool>` => `Promise<Empty>` in LibIMAP/Client.cpp) This, of course, allows gross violations of the type system, and makes the need to type-check less obvious before downcasting. Luckily, while adding the `static_ptr_cast`s, only two truly incorrect usages were found; in the other instances, our casts just needed to be made explicit.
2021-07-19Everywhere: Use AK/Math.h if applicableHendiadyoin1
AK's version should see better inlining behaviors, than the LibM one. We avoid mixed usage for now though. Also clean up some stale math includes and improper floatingpoint usage.
2021-07-16LibPDF: Fix treating not finding the linearized dict as a fatal errorWesley Moret
We now try to parse the first indirect value and see if it's the `Linearization Parameter Dictionary`. if it's not, we fallback to reading the xref table from the end of the document
2021-07-16LibPDF: Fix checking `minor_ver` instead of `major_ver`Wesley Moret
2021-06-12LibPDF: Convert to east-const to comply with the recent style changesMatthew Olsson
2021-06-12LibPDF: Bake the flipped y-axis directly into the CTM matrixMatthew Olsson
2021-06-12LibPDF: Avoid calculating rendering matrix for every glyphMatthew Olsson
2021-06-12LibPDF: Handle the TJ graphical operatorMatthew Olsson
2021-06-12LibPDF: Handle the gs graphical operatorMatthew Olsson
2021-06-12LibPDF: Add support for the CalRGB ColorSpaceMatthew Olsson
This isn't tested all that well, as the PDF I am testing with only uses it for black (which is trivial). It can be tested further when LibPDF is able to process more complex PDFs that actually use this color space non-trivially.
2021-06-12LibPDF: Split ColorSpace into a different class for each color spaceMatthew Olsson
While unnecessary at the moment, this will allow for more fine-grained control when complex color spaces get added.
2021-06-12LibPDF: Parse hint tablesMatthew Olsson
This code isn't _actually_ used as of right now, but I wrote it at the same time as all of the code in the previous commit. I realized after I wrote it that these hint tables aren't super useful if the parser already has access to the full file. However, this will be useful if we ever want to stream PDFs from the web (and possibly view them in the browser).
2021-06-12LibPDF: Parse linearized PDF filesMatthew Olsson
This is a big step, as most PDFs which are downloaded online will be linearized. Pretty much the only difference is that the xref structure is slightly different.
2021-06-12LibPDF: Fix two parser bugsMatthew Olsson
- A newline was assumed to follow the "stream" keyword, when it can also be a windows-style line break - Fix not consuming the "endobj" at the end of every indirect object
2021-06-12LibPDF: Refine the distinction between the Document and ParserMatthew Olsson
The Parser should hold information relevant for parsing, whereas the Document should hold information relevant for displaying pages. With this in mind, there is no reason for the Document to hold the xref table and trailer. These objects have been moved to the Parser, which allows the Parser to expose less public methods (which will be even more evident once linearized PDFs are supported).
2021-06-12LibPDF: Account for inverted y axis when rendering textMatthew Olsson
2021-06-12LibPDF: Harden the document/parser against errorsMatthew Olsson
2021-06-12LibPDF: Differentiate Value's null and empty statesMatthew Olsson
2021-06-06AK+Everywhere: Disallow constructing Functions from incompatible typesAli Mohammad Pur
Previously, AK::Function would accept _any_ callable type, and try to call it when called, first with the given set of arguments, then with zero arguments, and if all of those failed, it would simply not call the function and **return a value-constructed Out type**. This lead to many, many, many hard to debug situations when someone forgot a `const` in their lambda argument types, and many cases of people taking zero arguments in their lambdas to ignore them. This commit reworks the Function interface to not include any such surprising behaviour, if your function instance is not callable with the declared argument set of the Function, it can simply not be assigned to that Function instance, end of story.
2021-06-01Everywhere: codepoint => code pointAndreas Kling
2021-05-25LibPDF: Pre-initialize common FlyStrings in CommonNames.hMatthew Olsson
2021-05-25LibPDF: Handle string encodingsMatthew Olsson
Strings can be encoded in either UTF16-BE or UTF8. In either case, there are a few initial bytes which specify the encoding that must be checked and also removed from the final string.
2021-05-25LibPDF: Parse outline structuresMatthew Olsson
2021-05-25LibPDF: Store indirect value refs in Value objectsMatthew Olsson
IndirectValueRef is so simple that it can be stored directly in the Value class instead of being heap allocated. As the comment in Value says, however, in theory the max bits needed to store is 48 (16 for the generation index and 32(?) for the object index), but 32 should be good enough for now. We can increase it to u64 later if necessary.
2021-05-25LibPDF: Add basic color space support to the rendererMatthew Olsson
This commit only supports the three most basic color spaces: DeviceGray, DeviceRGB, and DeviceCMYK