How chromium/pdfium works
Overall Architecture and Main Components
• PDF Parsing Subsystem:
• “fpdfapi/parser” components (found under core/fpdfapi/parser) which are responsible for tokenizing and building the internal representation of PDF objects.
• This layer feeds into higher-level components, such as document assembly (core/fpdfdoc) and text extraction (core/fpdftext).
• Document Model and Object Management:
• "fpdfdoc" module that maintains the internal PDF document structure and metadata.
• Aspects such as bookmark trees, annotations, and form objects.
• Rendering Engine:
• Rendering modules under core/fpdfapi/render and the graphics engine in fxge.
• Connection between the device-independent rendering and computation routines (e.g., in fxcrt for low-level utilities and fxge for platform-specific rendering) and the higher-level PDF rendering calls.
• Experimental Skia backend (configured via pdf_use_skia) and integration with font rendering subsystems.
• Font, Image, and Codec Modules:
• Font system (core/fpdfapi/font) as well as fxcrt utilities that manage memory, string handling, and numerical operations that are essential to rendering.
• JavaScript and XFA Support:
• Fxjs and xfa directories as separate modules.
• The fxjs engine interacts with V8 (as indicated by cfx_v8 files) to support embedded JavaScript execution.
• The xfa and fxfa directories (plus supplementary XFA form modules under fpdfxfa and fpdfsdk/formfiller) represent support for Adobe’s XML Forms Architecture, integrating with PDF content if XFA is enabled.
• Public API / SDK Interface:
• “public” and “fpdfsdk” directories that expose embeddable APIs for external developers.
• Components as stable interfaces that sit on top of the core engine.
Supporting Infrastructure and Build Tools
• Build System & Configuration:
• A component for GN build configuration and Ninja-based build execution.
• Reference the integration with depot_tools (used to obtain compilers and toolchains) and the role of the provided scripts (such as install-build-deps.sh in Linux).
• Third-Party Libraries:
• Third-party dependencies such as libraries for JPEG, PNG, OpenJPEG, freetype, and others (located in the third_party directory).
• These serve as low-level libraries supporting decoding, font rendering, or image processing operations.
Relationships and Data Flow
• Also, show the optional flow for JavaScript and XFA: if enabled, the parsed document gives rise to script data that is processed by fxjs, and if there is form support, the XFA subsystem handles forms and interactive elements.
• Component Dependency Relationships:
• Modules like fxcrt provide utility functions that are used widely across the parser, rendering, and other submodules.
• The rendering engine may depend on both the document layer and the codec libraries for embedded image support.
• The public API/SDK acts as a façade for external calls to the core engine.
Architectural Patterns / Design Principles
• Modular and Layered Design:
• Use distinct layers (e.g., parsing, document assembly, rendering, platform abstractions) that communicate via clearly defined interfaces.
• Each module (such as parser, renderer, and form-handling) can be further broken down to show that they follow separation of concerns.
• Platform Abstraction:
• Extensibility:
• That the project is built with extensibility in mind (e.g., support for multiple rendering backends, optional JavaScript engine integration, and XFA support that can be toggled via GN args).