0

[PDF] Improve result checking for a few PDFium API calls

In pdfium_ink_writer.cc, use the correct return type for a
FPDFPageObj_AddMark() call. It does not return a bool.

In pdfium_searchify.cc, CHECK() the result for a couple of PDFium API
calls that should never fail, instead of returning early.

Change-Id: I17a8548c793543469ae418fa46d5a60a6103809d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5905559
Reviewed-by: Alan Screen <awscreen@chromium.org>
Reviewed-by: Chu-Hsuan Yang <chuhsuan@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1363483}
This commit is contained in:
Lei Zhang
2024-10-03 05:08:55 +00:00
committed by Chromium LUCI CQ
parent 7add5e22a9
commit 2c132c6eb2
2 changed files with 9 additions and 13 deletions

@ -125,7 +125,7 @@ bool WriteStrokeToPage(FPDF_PAGE page, const ink::Stroke& stroke) {
bool close_result = FPDFPath_Close(path.get());
CHECK(close_result);
bool add_mark_result =
FPDF_PAGEOBJECTMARK add_mark_result =
FPDFPageObj_AddMark(path.get(), kInkAnnotationIdentifierKey);
CHECK(add_mark_result);

@ -136,23 +136,19 @@ void AddWordOnImage(FPDF_DOCUMENT document,
word_string.push_back(' ');
}
if (word_string.empty()) {
std::vector<uint32_t> charcodes = Utf8ToCharcodes(word_string);
if (charcodes.empty()) {
DLOG(ERROR) << "Got empty word";
return;
}
std::vector<uint32_t> charcodes = Utf8ToCharcodes(word_string);
if (!FPDFText_SetCharcodes(text.get(), charcodes.data(), charcodes.size())) {
DLOG(ERROR) << "Failed to set charcodes";
return;
}
bool result =
FPDFText_SetCharcodes(text.get(), charcodes.data(), charcodes.size());
CHECK(result);
// Make text invisible
if (!FPDFTextObj_SetTextRenderMode(text.get(),
FPDF_TEXTRENDERMODE_INVISIBLE)) {
DLOG(ERROR) << "Failed to make text invisible";
return;
}
result =
FPDFTextObj_SetTextRenderMode(text.get(), FPDF_TEXTRENDERMODE_INVISIBLE);
CHECK(result);
const gfx::SizeF text_object_size = GetImageSize(text.get());
CHECK_GT(text_object_size.width(), 0);