18619 Commits

Author SHA1 Message Date
Aryan
3e58f283cb Add boolean entries to pieceinfo test files
This CL adds boolean values to the /Private dictionary in the
hello_world_pieceinfo test resources. This updates the PDF test files to
support upcoming APIs for getting and setting boolean dictionary
entries.

Bug: 42270521
Change-Id: I4ccbc205955bb7e81308e93bfcc811f6cdc99663
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153490
Reviewed-by: Andy Phan <andyphan@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Andy Phan <andyphan@chromium.org>
2026-07-29 16:36:15 -07:00
Tom Sepez
ff4f3a3e5a Add fflush calls in pdfium_test to prevent buffered output truncation
Bot hypothesis about flakey windows component build tests.

In pdfium_test.cc, call fflush(stdout) after printf calls in example
embedder callbacks (such as ExampleAppAlert and ExampleAppResponse)
and call fflush(stdout) and fflush(stderr) at the end of main().

On Windows MSVC CRT, block-buffered piped streams can be truncated if
the process terminates before the buffer is flushed. Explicitly
flushing stdout prevents truncation in text diff tests.

TAG=agy
CONV=8e1e302a-cea2-4f5a-972f-5b3625f86d6d

Change-Id: Iea9180efccf3ec4b4db329c88c24efb83aca0466
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153630
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
2026-07-29 16:06:08 -07:00
Tom Sepez
993cbfa9f1 Move progressive decoder contexts to separate files.
Move SkiaBmpContext, CJpegContext, CPngContext, and SkiaPngContext out
of anonymous namespaces and internal source files into their own
dedicated header and implementation files.

Eventually, the foo_decoder.{h,cpp} files will be removed as they
are static wrappers with all the action taking place in the context.

There is no funny business in this move: each class is transferred
line by line without renaming, modifying signatures, or changing any
behavior.

TAG=agy
CONV=794fb8a5-48ac-429f-a73a-af68dfabff99

Change-Id: I1677537a2ef502c8f40431ce6c523cf9f2c2ca30
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153550
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-29 14:14:09 -07:00
punishell
e98309f297 Fix out-of-bounds index in CFXJSE_FormCalcContext::IsIsoDateFormat
Short ISO date strings caused out-of-bounds indexing past the end of the
input span at two unguarded digit checks (month- and day-position),
tripping the span's CHECK() and aborting the process.

Add a bounds check before both digit guards, mirroring the existing
IsIsoTimeFormat() handling, and extend the IsIsoDateFormat unittest with
both valid and malformed-short inputs.

Bug: 539204640
Change-Id: I6645831217a418ccc8d8c54ae0a9a36c582114c6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153230
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
2026-07-29 11:57:53 -07:00
Aryan
66f87ccf73 Update formatting in bitmap and gif decoders
This CL removes additional newlines in bmp_decoder.cpp,
skia_bmp_decoder.cpp and gif_decoder.cpp.

Change-Id: I938a891591eca618c738ea334ac69fe31641548a
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153530
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Andy Phan <andyphan@chromium.org>
Auto-Submit: Aryan Krishnan <aryankrishnan4b@gmail.com>
Reviewed-by: Andy Phan <andyphan@chromium.org>
2026-07-29 11:09:50 -07:00
Tom Sepez
4f73137e20 Convert 2 to To in core/fxge/dib/cfx_dibbase.cpp
Longstanding irritation given other numbers in these function names
signify pixel depths.

   sed -i 's/\(ConvertBuffer_\w*\)2\([A-Z]\)/\1To\2/g'

Change-Id: I18e3d705302cbfe8a4bed4f3921418da28ae0fff
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153470
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-29 10:05:57 -07:00
Tom Sepez
8dbb801d5c Use Zip() in remaining variable stride DIB conversions
Refactor ConvertBuffer_8bppMask2Rgb(), ConvertBuffer_8bppPlt2Rgb(),
and ConvertBuffer_Rgb2Rgb32().

This replaces UNSAFE_TODO() raw pointer increments with compile-time
fixed stride loops using GetScanlineAs<>() and fxcrt::Zip() over typed
color structs.

In ConvertBuffer_8bppPlt2Rgb(), also replace the raw array palette
initialization loop with std::array<FX_BGR_STRUCT<uint8_t>, 256> and
fxcrt::Zip().

TAG=agy
CONV=b9441e85-7a2d-45eb-b5fc-45a5305e1279

Change-Id: I042de3f15de41470ec14a543d437af2a98f81326
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153430
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
2026-07-28 16:41:49 -07:00
Tom Sepez
e2ae6fb055 Use templating and Zip() in ConvertBuffer_Rgb2Gray()
Replace UNSAFE_TODO() raw pointer loops with compile-time fixed
stride loops using GetScanlineAs<>() and fxcrt::Zip() by templating
for 24 or 32 BPP and updating caller.

TAG=agy
CONV=79149323-9e55-44bc-a43a-b9aedc44a81b

Change-Id: I0e92603cd6a082de393988130a6b00dabcb3be8b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153410
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
2026-07-28 15:31:43 -07:00
Tom Sepez
5c8ffedbb6 Virtualize DecodeImage in ProgressiveDecoderContext
Add virtual DecodeImage(size_t frame_index) method to
ProgressiveDecoderContext. Override DecodeImage in CFX_BmpContext,
SkiaBmpContext, and CFX_GifContext. Update BmpContinueDecode and
GifContinueDecode in ProgressiveDecoder to call DecodeImage directly
on context_ instead of via static wrapper classes.

TAG=agy
CONV=7a82d35c-037e-4042-8882-448367a075e7

Change-Id: Iea8f46fd873bed74013664ca91dcd8a87df2a6ab
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153290
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-28 15:05:42 -07:00
Tom Sepez
9ca3ca6293 Collapse 5 context members into context_ in ProgressiveDecoder
Replace bmp_context_, gif_context_, jpeg_context_, png_context_, and
tiff_context_ in ProgressiveDecoder with a single context_ member of
type std::unique_ptr<ProgressiveDecoderContext>.

Simplify ProgressiveDecoder to reference context_ across all supported
image formats.

TAG=agy
CONV=be5c4020-7f57-4f8c-b6e2-d0099cfddd2c

Change-Id: I500f1337bfa7d36c81c0af17bff0205abf0eee38
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153130
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-28 14:18:59 -07:00
Aryan
727cfce5cf Add test PDFs containing /PieceInfo dictionaries
This CL adds hello_world_pieceinfo.in/.pdf, which includes the
/PieceInfo dictionary attached to both the document catalog root and
individual page objects. These files allow for future testing of APIs to
access or edit /PieceInfo.

Bug: 42270521
Change-Id: Ic8d110e618703b2f59ab894498b6200eae2397e7
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152970
Reviewed-by: Andy Phan <andyphan@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Andy Phan <andyphan@chromium.org>
2026-07-28 10:20:53 -07:00
Tom Sepez
05f523a53a Virtualize ProgressiveDecoderContext and add decoder factory methods
Refactor ProgressiveDecoderContext into a virtual base class for image
decoding contexts. Replace format-specific context pointers in
ProgressiveDecoder with a single ProgressiveDecoderContext pointer and
eliminate static_cast downcasts across decoder implementations. Add
static Create factory methods to ProgressiveDecoder and
ProgressiveDecoderContext.

TAG=agy
CONV=f7421c5c-5a62-488b-85d3-5c6de8bdc632

Change-Id: Ie29f9fdfc852654f489a51c02c657e21dd52c86f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153090
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-27 18:11:19 -07:00
Tom Sepez
3f1af4f68c Set opaque alpha on BMP palette entries and unify palette resampling
Update CFX_BmpDecompressor::ReadHeader() to explicitly set the alpha
byte of BMP palette entries to opaque (0xFF). Previously, old BMP
palettes set alpha to 0x00 and newer palettes copied the reserved fourth
byte (which is typically 0x00 in BMP files).

With valid alpha in BMP palette entries, remove the BMP-specific special
case block in ProgressiveDecoder 8BPP RGB-to-ARGB resampling, allowing
both BMP and GIF to use the same palette resampling loop.

TAG=agy
CONV=7a82d35c-037e-4042-8882-448367a075e7

Change-Id: I994c27923a70c6d1885b3c427e1b5f97249f3f81
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153350
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
2026-07-27 17:26:53 -07:00
Tom Sepez
b84b57fa1f Unify progressive decoder Status return types
Define Status enum in ProgressiveDecoderContext with kError, kSuccess,
and kContinue values. Update BmpDecoder and GifDecoder to directly
use ProgressiveDecoderContext::Status.

TAG=agy
CONV=7a82d35c-037e-4042-8882-448367a075e7

Change-Id: I42fb0bc107e9d2b6b5c25b40bd4f9beefd6c73bd
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153270
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
2026-07-27 17:16:10 -07:00
Andy Phan
59e5ffd2c8 Improve memory and type safety in CPDF_DIB::GetScanline()
Refactor CPDF_DIB::GetScanline() to improve safety and readability:
- Use fxcrt::Zip() and structured spans instead of raw index
  calculations. This removes several UNSAFE_TODO blocks. Using Zip()
  allows the compiler to prove loop accesses are in-bounds and optimize
  away the runtime checks, avoiding bounds checking performance
  regressions.
- Cache `GetWidth()` as a `const size_t width` at the function scope
  to avoid redundant calls and ensure type-safe loop comparisons.

TAG=agy
CONV=40e28386-4f52-4db6-a72f-2fbe86431c92

Bug: 536543461
Change-Id: Ia98f187dda798e63f8b898376053dafce0a867cc
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152691
Commit-Queue: Andy Phan <andyphan@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
2026-07-27 15:36:56 -07:00
Andy Phan
2a9bb984e1 Fix color key masking for images with > 8 bits per pixel
In CPDF_DIB::GetScanline(), color key masking was only implemented for
images with 8 or fewer bits per pixel, or for 24-bit RGB images. For
other image formats, such as 16-bit grayscale, the code fell back to
filling the mask buffer's alpha channel with 0xFF (opaque), effectively
ignoring the color key mask. This caused masked pixels to render with
their raw color (usually black) instead of being transparent.

To resolve this, generalize the fallback path in CPDF_DIB::GetScanline()
to handle arbitrary bit-depths and component counts. A new helper
function IsPixelInColorKeyRange() extracts pixel components using
GetBits8() and checks them against the color key bounds. The fallback
path uses this helper to correctly populate the alpha channel, setting
it to 0 for masked pixels and 0xFF for opaque pixels.

TAG=agy
CONV=40e28386-4f52-4db6-a72f-2fbe86431c92

Bug: 536543461
Change-Id: I5f7f96adfc35cad5251375ff52aaad12f175eae6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152711
Commit-Queue: Andy Phan <andyphan@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-27 15:36:46 -07:00
Andy Phan
3255b0618d Add class comment to CPDF_DIB
Explain the purpose of CPDF_DIB class.

TAG=agy
CONV=e8ed28e6-3ab6-4f24-956c-232d5559604f

Change-Id: I9c6d5fde1a7e33446adfcdcea1f8685917442b6d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153150
Commit-Queue: Andy Phan <andyphan@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-27 10:05:33 -07:00
Andy Phan
6394ddee3d Add pixel test for 16-bit grayscale masking
The test is currently suppressed because PDFium does not correctly
apply color key masks to 16-bit grayscale images.

TAG=agy
CONV=40e28386-4f52-4db6-a72f-2fbe86431c92

Bug: 536543461
Change-Id: I5a008350438e1a16825e5dad503363106fe6005c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152710
Commit-Queue: Andy Phan <andyphan@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-27 10:05:24 -07:00
pdfium-autoroll@skia-public.iam.gserviceaccount.com
513b246bf0 Roll goldctl from f88222fee08c to 42a268cbf8f7
If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/goldctl-pdfium
Please CC andyphan@google.com,thestig@chromium.org on the revert to ensure that a human
is aware of the problem.

To file a bug in goldctl: https://issues.skia.org
To file a bug in PDFium: https://crbug.com/pdfium

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

Bug: None
Tbr: andyphan@google.com
Change-Id: Ic23a32b13f0c99bcd0116b295b4a47707a97bddc
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153210
Commit-Queue: pdfium-autoroll@skia-public.iam.gserviceaccount.com <pdfium-autoroll@skia-public.iam.gserviceaccount.com>
Bot-Commit: pdfium-autoroll@skia-public.iam.gserviceaccount.com <pdfium-autoroll@skia-public.iam.gserviceaccount.com>
2026-07-26 21:58:27 -07:00
Lei Zhang
1ed609f4f7 Document CFFL_InteractiveFormFiller::Get*PageView()
Document the difference between GetOrCreatePageView() and GetPageView().
Mainly that GetOrCreatePageView() never returns nullptr. Then transitively
document that CFFL_FormField::GetCurPageView() never returns nullptr.

Separately audit all the callers and remove dead code that assumed
GetCurPageView() can return nullptr. Upgrade some cheap DCHECK() calls
to CHECK().

Change-Id: Iaa99257306dd6f152dc03e082c0e19ce80395f19
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153170
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
2026-07-24 17:53:53 -07:00
Rulong Chen(陈汝龙)
65db368888 Make embedder test delegates fixture-owned
Embedder tests often install stack-local delegates, but EmbedderTest can
invoke delegate callbacks while closing the document in TearDown(). By
then, a stack delegate may already have been destroyed.

Add SetOwnedDelegate() so the fixture owns the custom delegate through
document teardown, then restores the default delegate before releasing
it. Migrate all existing call sites, remove the raw SetDelegate() API,
and store the active delegate as an UnownedPtr.

Bug: 535697671
Change-Id: I8e8da028e9c563e82d40099637c63978122077eb
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152110
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
2026-07-24 12:15:07 -07:00
Lei Zhang
17c6d8dae8 Fix mixed-direction line extraction
Disable automatic whole-line Bidi segment reversal for text extraction,
preserving the original logical ordering of text segments on the page to
match Acrobat behavior and prevent semantic phrase reversals in mixed
English/Hebrew sentences. Then update FPDFTextEmbedderTest.ActualTextRtl
test expectations to match this behavior change.

TAG=agy
CONV=f944b222-25e8-4814-ac19-fc1a0101da16

Bug: 525087036
Change-Id: Ia48be8bb74ed60e4bd1bd34b34461ea5d46b3db0
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152910
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Andy Phan <andyphan@chromium.org>
2026-07-24 12:08:09 -07:00
Tom Sepez
62c1230041 Add Rust-based BMP decoder
Honor the pdf_enable_rust_bmp GN build argument to allow building
PDFium with Skia's Rust-based BMP decoder instead of the legacy C++ BMP
decoder.

Add SkiaBmpDecoder and BmpDecoderDelegate to adapt the Rust BMP decoder
for ProgressiveDecoder.

-- Adjust minimum input size calculation for 24/32 bit skia results
   in ProgressiveDecoder.

TAG=agy
CONV=19661998-5d2f-4919-b147-d44fa811807c

Bug: 537855738
Change-Id: If87228e8e2b3b1224d631044a7931c2cdc79fd4d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152570
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-24 10:51:28 -07:00
Lei Zhang
2f7a54a926 Partially fix RTL character and line reading order in CPDF_TextPage
Fix /ActualText character ordering: Identify RTL text segments generated
from marked content /ActualText spans and process their characters in
forward logical order rather than reversing them. Update
FPDFTextEmbedderTest.ActualTextRtl with the improved test expectations
to match the new behavior.

TAG=agy
CONV=117163e4-c12b-43d7-9709-b718d4450d3e

Bug: 525087036
Change-Id: I73529d1103329e741d259002c437afb6bad7fb7b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/151070
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Andy Phan <andyphan@chromium.org>
2026-07-24 10:40:12 -07:00
Lei Zhang
8f3e90282e Give CFX_BidiString a way to turn off auto-ordering
Add a second parameter to the CFX_BidiString constructor to allow the
internal predominant-segment reversal heuristic to be optionally turned
off. This will be used in https://pdfium-review.googlesource.com/151070
to improve /ActualText ordering.

- Migrate existing CFX_BidiString users to explicitly turn on
  auto-ordering to preserve pre-existing behavior.
- Add unit test for turning off auto-ordering.

TAG=agy
CONV=117163e4-c12b-43d7-9709-b718d4450d3e

Bug: 525087036
Change-Id: I062690884127b14e933f74ae9c874d294effd3c5
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152390
Auto-Submit: Lei Zhang <thestig@chromium.org>
Reviewed-by: Andy Phan <andyphan@chromium.org>
Commit-Queue: Andy Phan <andyphan@chromium.org>
2026-07-24 09:18:29 -07:00
Jiewei Qian
a9e3314a84 third_party/agg23: mark as a fork
Bug: 538004146, 538320033
Change-Id: I6f133d18ddf3e71d99eef950da3c11392c57cc3b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153050
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Auto-Submit: Jiewei Qian <qjw@google.com>
2026-07-23 19:58:08 -07:00
Lei Zhang
7bdfa23086 Refactor CPDF_TextPage::ProcessTextObjectItems() to return boolean
Change CPDF_TextPage::ProcessTextObjectItems() to return a boolean to
indicate whether to call ReverseTempTextBufs() or not. Move the RTL and
matrix determinant logic for calculating that boolean from the only
caller into ProcessTextObjectItems(). This refactoring will align
ProcessTextObjectItems() behavior with the upcoming
ProcessMarkedContent() change in
https://pdfium-review.googlesource.com/152751.

TAG=agy
CONV=42897bdc-5c71-4a3e-9f56-a4ef21ac2a39

Change-Id: I15bcd98e3e740ec912c5cf2c39ca9eca777582c4
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152751
Reviewed-by: Andy Phan <andyphan@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
2026-07-23 18:07:41 -07:00
Lei Zhang
2c1f4f8984 Change CFX_BidiString segment tie-breaking to favor LTR
Update CFX_BidiString's constructor to break ties between equal numbers
of LTR and RTL segments by defaulting to LTR rather than RTL.

- Add a CFX_BidiString unit test for this case.
- Update FPDFTextEmbedderTest.ActualTextRtl expectation to match this
  change. The behavior is now closer to Acrobat's behavior.

TAG=agy
CONV=117163e4-c12b-43d7-9709-b718d4450d3e

Bug: 525087036
Change-Id: Ibe2501522012de91cf9ed1e2cca112930bae9211
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152371
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Andy Phan <andyphan@chromium.org>
2026-07-23 17:10:52 -07:00
Seung Hyun Jin
d0d349d9a7 Rewrite CPVT_Section layout using ICU UBA
Replace CFX_BidiString usage in CPVT_Section::OutputLines() with
CFX_BidiResolver to implement the Unicode Bidirectional Algorithm. Pass
the state from CPVT_VariableText::GetDirection() down to the resolver to
establish the base paragraph direction context. Resolve visual runs
globally across the entire paragraph to correctly reverse mixed
direction text and handle trailing spaces. Update unit tests to assert
new layout coordinates.

Bug: 534486929
Change-Id: I67ce57e19f25a7e99ad09e19d0cef0aca076fd67
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152251
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Seung Hyun Jin <seunghyunjin@google.com>
2026-07-23 16:55:30 -07:00
Seung Hyun Jin
1f3472191c Add unit tests for empty CPVT_VariableText caret positioning
Introduce tests for `kCenter` and `kRight` alignments. Document the
correct horizontal positioning behavior for an empty text string, where
the expected caret coordinates are 50.0f and 100.0f respectively.
Demonstrate that internal alignment offset calculation must execute even
when word array contains zero elements. Loop must correctly apply the
offset to the empty line to guarantee the caret is shifted correctly
before the layout engine terminates.

Bug: 534486929
Change-Id: I28233e473a1aeb5d98310bea89f88caed7550e0d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152650
Commit-Queue: Seung Hyun Jin <seunghyunjin@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-23 16:40:14 -07:00
Lei Zhang
b42527ff63 Add MaybeOwnedDataVector and use in CJBig2_Image
Add a new class that is similar to MaybeOwned, but focused on storing
either a span that points to external data, or a span that points to an
owned DataVector. It is currently tailored to CJBig2_Image's needs. Use
it in CJBig2_Image to replace all the manual memory management.

Change-Id: Ia5564685150422a0f20d625f6295345b7c44d476
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/147510
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
2026-07-23 16:38:00 -07:00
Seung Hyun Jin
668c520763 Add unit tests documenting existing CPVT_Section layout behavior
Introduce baseline unit tests for CPVT_Section that assert buggy layout
behaviors of CPVT_Section. Document the exact failure mode where mixed
directional text containing Hebrew and English fail to reverse correctly
due to CFX_BidiString evaluation of each physical line instead of per
paragraph. Layout behavior will be fixed in
https://pdfium-review.googlesource.com/c/152251 by introducing explicit
layout engine.

TAG=agy

Bug: 534486929
Change-Id: Ic781e182ea3bb46e13daa06560d392db0c5af554
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152270
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Seung Hyun Jin <seunghyunjin@google.com>
2026-07-23 16:11:36 -07:00
Seung Hyun Jin
ee62d3b917 Introduce TextDirection enum in CPVT_VariableText
Add CFX_BidiResolver::ParagraphDirection to CPVT_VariableText to track
explicit text directionality (kAuto, kLeftToRight, kRightToLeft). Add
GetTextDirection() and SetTextDirection() accessors to CPVT_VariableText
and pass the state through CPWL_EditImpl. Allow form fields to enforce a
base paragraph direction during layout, overriding the text's natural
direction (implemented in
https://pdfium-review.googlesource.com/c/152251).

Bug: 534486929
Change-Id: I75c25959422a60f7242bbf22071123664f821f41
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152191
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Seung Hyun Jin <seunghyunjin@google.com>
2026-07-23 16:11:05 -07:00
Seung Hyun Jin
4403278d51 Introduce CFX_BidiResolver for ICU paragraph layout
Create a new class with RAII wrappers for ICU UBiDi structs. It extracts
visual text runs for bi-directional text layout, laying the foundation
to replace the legacy Foxit custom bidi logic. Constructor implements
paragraph initialization using ubidi_setPara(), alongside a safe
UBiDiDeleter. It introduces the core logical-to-visual data mapping via
GetVisualRunsForLine(), which uses ubidi_setLine() and
ubidi_getVisualRun() to calculate the correct visual display order of
bidi text segments as a data vector. Add unit tests to verify index
mapping calculations are correct and ensure early exits return without
leaking memory. In upcoming CLs, GetVisualRunsForLine() will be called
by CPVT_Section::OutputLines() for mixed directional text layout
support.

Bug: 534486929
Change-Id: I67c27f1b63c74ef35879f79c2147559bf570fc07
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/151971
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Seung Hyun Jin <seunghyunjin@google.com>
2026-07-23 15:56:49 -07:00
Seung Hyun Jin
b324040a4a Clean up CPVT_Section::OutputLines() implementation
Replace the implicit capture in the `position_word` lambda with an
explicit capture list to comply with Google C++ style. Replace `auto`
with type declarations for std::unique_ptr<CPVT_WordInfo> and
CFX_BidiChar::Segment in the internal loops to improve code readability
Document the overall purpose of CPVT_Section::OutputLines() in header
file.

Bug: 534486929
Change-Id: I2556fbf84b3c6c101fb647f2f34eb900590a8383
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152670
Commit-Queue: Seung Hyun Jin <seunghyunjin@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-23 15:56:39 -07:00
Tom Sepez
16aaf1c51e Fix some looming linker issues with rust codecs
-- Rename LoadImage to DecodeImage to avoid Windows #define LoadImage.
-- Fix component build against unexported skcms_sRGB_profile() symbol.

Bug: 537855738
Change-Id: I7a8c15c36e106d222cbb70d7e1a3ff3882c7063e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/153030
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
2026-07-23 14:58:13 -07:00
Lei Zhang
8f72ac4dd1 Add test case for literal Hebrew text preceding /ActualText span
Update actual_text_rtl.in to include literal Hebrew text rendered using
the same font as hebrew_mirrored.in, followed by /ActualText text. Reuse
hebrew_truetype_font.fragment and hebrew_cmap.fragment to avoid
duplication. Then update FPDFTextEmbedderTest.ActualTextRtl expectations
to match the new test input.

TAG=agy
CONV=117163e4-c12b-43d7-9709-b718d4450d3e

Bug: 525087036
Change-Id: I9ce2030ddb6d146532f4cf83c2c56f4a2c1661ae
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152770
Reviewed-by: Andy Phan <andyphan@chromium.org>
Commit-Queue: Andy Phan <andyphan@chromium.org>
Auto-Submit: Lei Zhang <thestig@chromium.org>
2026-07-23 13:11:30 -07:00
Aryan
5875ad4c3a Remove CPDF_ICCBasedCS::cache_
This CL removes the cache for /ICCBased gradients to remove the
quantization for gradients, hence fixing the issue.

Bug: 41244214
Change-Id: I0c749b43b09e1740f800531fcf055ce352f40418
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/151770
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
2026-07-23 13:05:32 -07:00
Jiewei Qian
47449e8970 third_party/bigint: add the missing README.pdfium file
Bug: 537940787
Change-Id: I0abfa516354f83f6a856d466b6c3841ad9a899f6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152950
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Auto-Submit: Jiewei Qian <qjw@google.com>
2026-07-22 23:25:38 -07:00
Tom Sepez
882b7bf236 Add pdf_enable_rust_bmp GN argument and preprocessor macro
Declare the pdf_enable_rust_bmp build argument, its override
pdf_enable_rust_bmp_override, and define the PDF_ENABLE_RUST_BMP
preprocessor macro when pdf_use_skia && pdf_enable_rust_bmp is active.

This allows external build recipes to configure the GN argument prior to
activating the Rust-based BMP decoder in a follow-up change.

TAG=agy
CONV=f457c92a-036e-44c5-89eb-1caaf0d672f5

Bug: 537855738
Change-Id: Ia44c2b798b5c26cac89a8025b83d8244e1978655
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152810
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-22 18:05:56 -07:00
Andy Phan
9e66a384fe Rename Hungarian notation in CPDF_DIB::GetScanline()
Rename Hungarian notation variables in CPDF_DIB::GetScanline() to
conform with modern style guidelines:
- `pSrcLine` -> `src_line`
- `pPixel` -> `pixel`
- `pSrcPixel` -> `src_pixel`
- `pDestPixel` -> `dest_pixel`

This improves readability and prepares for spans refactoring.

TAG=agy
CONV=40e28386-4f52-4db6-a72f-2fbe86431c92

Bug: 536543461
Change-Id: I2134fdac4cb8840adaa6552854edcd800ca6acc1
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152690
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Andy Phan <andyphan@chromium.org>
2026-07-22 17:34:40 -07:00
Rulong Chen(陈汝龙)
eb68153d40 Reject XFA-only pages in FPDFPage_Flatten()
FPDFPage_Flatten() converted its page handle to CPDF_Page but checked
the original handle for null. A full-XFA page without PDF backing
therefore reached a null CPDF_Page dereference.

Check the converted pointer and cover the failure with an XFA embedder
test.

Bug: 533167360
Change-Id: Ifa1fd59f5fe4d1639f6c6c9e69e0ee412d720758
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/151810
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
2026-07-22 14:57:37 -07:00
Lei Zhang
d30ae3ebd1 Move parts of hebrew_mirrored.in into .fragment files
Move the NotoSansHebrew TrueType font data stream and ToUnicode CMap
stream from hebrew_mirrored.in to separate .fragment files so they can
be reused in other PDFs. This is effectively a refactor, as regenerating
hebrew_mirrored.pdf produces no changes.

TAG=agy
CONV=117163e4-c12b-43d7-9709-b718d4450d3e

Change-Id: I3c249f1380f79415befaa01cd2d4f6815884c663
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152750
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Andy Phan <andyphan@chromium.org>
2026-07-22 14:56:56 -07:00
Lei Zhang
2d60cb9c06 Clean up CPDF_TextPage::SwapTempTextBuf()
Consistently use std::ranges::reverse() within SwapTempTextBuf() to do
the work. With that in mind, rename it to ReverseTempTextBufs() to
better describe what it does. Also switch away from Hungarian notation
along the way.

Change-Id: I765ddddf911f11d7747630a227fb987de21f0c3d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152671
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Andy Phan <andyphan@chromium.org>
2026-07-22 13:33:49 -07:00
Seung Hyun Jin
a55ed9ccf8 Refactor CPVT_Section::GetWordRangeSpan()
Update CPVT_Section::GetWordRangeSpan() to receive start and length
integer arguments instead of explicit bounds. Clarifies and helps
prevent off-by-one errors by removing ambiguity of whether an end index
is inclusive or exclusive. Aligns with standard span slicing semantics.
Adjust CPVT_Section::GetWordRangeIteratorPair() to compute the end
index inline. Update the existing caller in CPVT_Section::OutputLines()
to calculate `line_length` before passing to span generator.

Bug: 534486929
Change-Id: I2eece9bfc6ce7664af5bc7e06bca32d2c024051b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152590
Commit-Queue: Seung Hyun Jin <seunghyunjin@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-22 12:57:42 -07:00
Lei Zhang
45773719c6 Add /Length1 to hebrew_mirrored.pdf font stream
Bring testing/resources/hebrew_mirrored.pdf up to spec so Acrobat Reader
can open it by adding the required /Length1 key-value pair to the
TrueType font stream. Do this by editing hebrew_mirrored.in and
regenerating hebrew_mirrored.pdf. The other /Length values are also
slightly different due to fixup_pdf_template.py changes in
https://pdfium-review.googlesource.com/c/128570.

TAG=agy
CONV=117163e4-c12b-43d7-9709-b718d4450d3e

Change-Id: I4cf2bcf70466e6bdd21f57ee5aca6fa3f04ad5f2
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152730
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Andy Phan <andyphan@chromium.org>
2026-07-22 11:41:10 -07:00
Seung Hyun Jin
6856a016bf Refactor CPVT_Section layout alignment calculation
Refactor alignment coordinate calculations inside
CPVT_Section::OutputLines() by introducing a get_alignment_offset()
lambda. Replace multiple switch statements used to calculate fMinX and
fPosX with direct calls to this lambda. Relies on Alignment enum in
https://pdfium-review.googlesource.com/c/152210.

Bug: 534486929
Change-Id: I688815ef4833c7fe8878f310497f543ca1e535a8
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152230
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Seung Hyun Jin <seunghyunjin@google.com>
2026-07-22 11:28:47 -07:00
Jiewei Qian
a62f5c48c2 third_party/NotoSans*: attach bug number to Static
Attaches bug number to Update Mechanism field to align with metadata
format requirement:

https://chromium.googlesource.com/chromium/src/+/main/docs/adding_to_third_party.md#Static-Static_HardFork

Bug: 422921492
Change-Id: Ic45b4b8c690acc31c5d4762472a454e953039a1d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152790
Auto-Submit: Jiewei Qian <qjw@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-22 10:52:28 -07:00
Seung Hyun Jin
98aefa3af5 Modernize Alignment enum in CPVT_VariableText
Replace the integer-based alignment constants with a strongly typed enum
class Alignment. Update CPVT_VariableText to exclusively store and
return Alignment instead of int32_t primitives. Modify callers to
explicitly use kLeft, KCenter, and kRight. Ensure bounds-checking and
safe casting occurs at I/O boundaries.

Bug: 534486929
Change-Id: I2785c463265544b09745d2e7f0890276b11c2eb2
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152210
Commit-Queue: Seung Hyun Jin <seunghyunjin@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
2026-07-22 10:32:54 -07:00
Aryan
4fdbe5b530 Refactor ICC color space translation and caching
This CL improves the readability, safety, and structure of the color
translation logic in CPDF_ICCBasedCS.

Key changes include:
- Replacing unsafe pointers by swapping raw pointer arithmetic inside
  the UNSAFE_TODO block with safe index-based access on spans.
- Preventing overflows by using FX_SAFE_INT32 for color and pixel count
  calculations to ensure safe integer arithmetic.
- Eliminating magic numbers by define kNumQuantizedLevels (52) and
  kQuantizationDegree (5) constants to replace raw literals and
  document the quantization logic.
- Removing the `components > 3` condition that always evaluates to
  false.
- Replacing some hungarian variable naming with snake case.

Change-Id: I90a2c93bc9279361aeb9b06c17ee52e9fbcd2b73
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/152130
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Andy Phan <andyphan@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
2026-07-21 23:53:04 -07:00