diff --git a/pdf/pdfium/pdfium_font_linux.cc b/pdf/pdfium/pdfium_font_linux.cc index 43e4af765ae07..24dd7c65d0732 100644 --- a/pdf/pdfium/pdfium_font_linux.cc +++ b/pdf/pdfium/pdfium_font_linux.cc @@ -144,7 +144,12 @@ void* MapFont(FPDF_SYSFONTINFO*, if (strcmp(face, "Symbol") == 0) return nullptr; + // TODO(crbug.com/702993): `blink::WebFontDescription::family` is a + // `blink::WebString`, which can only be used if Blink is initialized. Store + // the field in `font_family` for now, but remove the variable when this code + // will only execute in a renderer process. blink::WebFontDescription desc; + std::string font_family; if (pitch_family & FXFONT_FF_FIXEDPITCH) { desc.generic_family = blink::WebFontDescription::kGenericFamilyMonospace; @@ -203,7 +208,7 @@ void* MapFont(FPDF_SYSFONTINFO*, size_t i; for (i = 0; i < base::size(kPdfFontSubstitutions); ++i) { if (strcmp(face, kPdfFontSubstitutions[i].pdf_name) == 0) { - desc.family = blink::WebString::FromUTF8(kPdfFontSubstitutions[i].face); + font_family = kPdfFontSubstitutions[i].face; if (kPdfFontSubstitutions[i].bold) desc.weight = blink::WebFontDescription::kWeightBold; if (kPdfFontSubstitutions[i].italic) @@ -228,15 +233,16 @@ void* MapFont(FPDF_SYSFONTINFO*, if (face_utf8.empty()) return nullptr; - desc.family = blink::WebString::FromUTF8(face_utf8); + font_family = face_utf8; desc.weight = WeightToBlinkWeight(weight); desc.italic = italic > 0; } if (PDFiumEngine::GetFontMappingMode() == FontMappingMode::kPepper) - return MapPepperFont(desc, charset); + return MapPepperFont(desc, font_family, charset); DCHECK_EQ(PDFiumEngine::GetFontMappingMode(), FontMappingMode::kBlink); + desc.family = blink::WebString::FromUTF8(font_family); return GetBlinkFontMapper().MapFont(desc, charset); } diff --git a/pdf/ppapi_migration/pdfium_font_linux.cc b/pdf/ppapi_migration/pdfium_font_linux.cc index ae3447de59bd6..ab840af4b813d 100644 --- a/pdf/ppapi_migration/pdfium_font_linux.cc +++ b/pdf/ppapi_migration/pdfium_font_linux.cc @@ -39,8 +39,11 @@ FONT_WEIGHT_MATCH_ASSERT(900); } // namespace -void* MapPepperFont(const blink::WebFontDescription& desc, int charset) { +void* MapPepperFont(const blink::WebFontDescription& desc, + const std::string& font_family, + int charset) { DCHECK(pp::PDF::IsAvailable()); + DCHECK(desc.family.IsEmpty()); pp::BrowserFontDescription description; @@ -52,7 +55,7 @@ void* MapPepperFont(const blink::WebFontDescription& desc, int charset) { description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SERIF); } - description.set_face(desc.family.Utf8()); + description.set_face(font_family); description.set_weight(ToPepperWeight(desc.weight)); description.set_italic(desc.italic); diff --git a/pdf/ppapi_migration/pdfium_font_linux.h b/pdf/ppapi_migration/pdfium_font_linux.h index e1334ddaa37a6..8f140743bef20 100644 --- a/pdf/ppapi_migration/pdfium_font_linux.h +++ b/pdf/ppapi_migration/pdfium_font_linux.h @@ -5,6 +5,8 @@ #ifndef PDF_PPAPI_MIGRATION_PDFIUM_FONT_LINUX_H_ #define PDF_PPAPI_MIGRATION_PDFIUM_FONT_LINUX_H_ +#include <string> + namespace blink { struct WebFontDescription; } @@ -15,9 +17,12 @@ class Instance; namespace chrome_pdf { -// Returns a handle to the font mapped based on `desc` and `charset`, for use -// as the font_id in GetPepperFontData() and DeletePepperFont() below. -void* MapPepperFont(const blink::WebFontDescription& desc, int charset); +// Returns a handle to the font mapped based on `desc`, `font_family`, and +// `charset`. The handle is for use as the `font_id` in `GetPepperFontData()` +// and `DeletePepperFont()` below. +void* MapPepperFont(const blink::WebFontDescription& desc, + const std::string& font_family, + int charset); // Reads data from the `font_id` handle for `table` into a `buffer` of // `buf_size`. Returns the amount of data read on success, or 0 on failure. If