LibPDF: Add FIXME for CIDFontType2 creation

Move some code only needed for CIDFontType2 creation into a new
function and add a FIXME describing what needs to happen there.
This commit is contained in:
Nico Weber 2023-08-14 09:11:39 -04:00 committed by Andreas Kling
parent 1c263eee61
commit 934340d845
Notes: sideshowbarker 2024-07-17 06:46:15 +09:00

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGfx/Font/ScaledFont.h>
#include <LibPDF/CommonNames.h>
#include <LibPDF/Fonts/Type0Font.h>
@ -36,9 +37,39 @@ PDFErrorOr<Gfx::FloatPoint> CIDFontType0::draw_string(Gfx::Painter&, Gfx::FloatP
class CIDFontType2 : public CIDFontType {
public:
static PDFErrorOr<NonnullOwnPtr<CIDFontType2>> create(Document*, NonnullRefPtr<DictObject> const& descendant, float font_size);
PDFErrorOr<Gfx::FloatPoint> draw_string(Gfx::Painter&, Gfx::FloatPoint, DeprecatedString const&, Color const&, float, float, float, float) override;
};
PDFErrorOr<NonnullOwnPtr<CIDFontType2>> CIDFontType2::create(Document* document, NonnullRefPtr<DictObject> const& descendant, float font_size)
{
auto descriptor = TRY(descendant->get_dict(document, CommonNames::FontDescriptor));
if (descendant->contains(CommonNames::CIDToGIDMap)) {
auto value = TRY(descendant->get_object(document, CommonNames::CIDToGIDMap));
if (value->is<StreamObject>()) {
TODO();
} else if (value->cast<NameObject>()->name() != "Identity") {
TODO();
}
}
RefPtr<Gfx::Font> font;
if (descriptor->contains(CommonNames::FontFile2)) {
auto font_file_stream = TRY(descriptor->get_stream(document, CommonNames::FontFile2));
float point_size = (font_size * POINTS_PER_INCH) / DEFAULT_DPI;
// FIXME: Load font_file_stream->bytes() as TTF data, similar to TrueTypeFont::initialize().
// Unfortunately, TTF data in Type0 CIDFontType2 fonts don't contain the "cmap" table
// that's mandatory per TTF spec and the PDF stores that mapping in CIDToGIDMap instead.
// OpenType::Font::try_load currently rejects TTF data without "cmap" data.
(void)font_file_stream;
(void)point_size;
}
return TRY(adopt_nonnull_own_or_enomem(new (nothrow) CIDFontType2()));
}
PDFErrorOr<Gfx::FloatPoint> CIDFontType2::draw_string(Gfx::Painter&, Gfx::FloatPoint, DeprecatedString const&, Color const&, float, float, float, float)
{
// ISO 32000 (PDF 2.0) 9.7.4.2 Glyph selection in CIDFonts
@ -84,13 +115,11 @@ PDFErrorOr<void> Type0Font::initialize(Document* document, NonnullRefPtr<DictObj
m_cid_font_type = TRY(try_make<CIDFontType0>());
} else if (subtype == CommonNames::CIDFontType2) {
// TrueType-based
m_cid_font_type = TRY(try_make<CIDFontType2>());
m_cid_font_type = TRY(CIDFontType2::create(document, descendant_font, font_size));
} else {
return Error { Error::Type::MalformedPDF, "invalid /Subtype for Type 0 font" };
}
auto font_descriptor = TRY(descendant_font->get_dict(document, CommonNames::FontDescriptor));
u16 default_width = 1000;
if (descendant_font->contains(CommonNames::DW))
default_width = descendant_font->get_value(CommonNames::DW).to_int();
@ -122,15 +151,6 @@ PDFErrorOr<void> Type0Font::initialize(Document* document, NonnullRefPtr<DictObj
}
}
if (dict->contains(CommonNames::CIDToGIDMap)) {
auto value = TRY(dict->get_object(document, CommonNames::CIDToGIDMap));
if (value->is<StreamObject>()) {
TODO();
} else if (value->cast<NameObject>()->name() != "Identity") {
TODO();
}
}
m_system_info = move(system_info);
m_widths = move(widths);
m_missing_width = default_width;