mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
LibPDF: Sink m_base_font_name from PDFFont into subclasses
/BaseFont is a required key for type 0, type 1, and truetype font dictionaries, but not for type 3 font dictionaries. This is mechanical; type 0 fonts don't even use this yet (but probably should). PDFFont::initialize() is now empty and could be removed, but maybe we'll put stuff there again later, so I'm leaving it around for a bit longer.
This commit is contained in:
parent
6c1da5db54
commit
7f999b1ff5
8 changed files with 16 additions and 7 deletions
|
@ -54,9 +54,8 @@ PDFErrorOr<NonnullRefPtr<PDFFont>> PDFFont::create(Document* document, NonnullRe
|
|||
return font.release_nonnull();
|
||||
}
|
||||
|
||||
PDFErrorOr<void> PDFFont::initialize(Document* document, NonnullRefPtr<DictObject> const& dict, float)
|
||||
PDFErrorOr<void> PDFFont::initialize(Document*, NonnullRefPtr<DictObject> const&, float)
|
||||
{
|
||||
m_base_font_name = TRY(dict->get_name(document, CommonNames::BaseFont))->name();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -23,14 +23,9 @@ public:
|
|||
virtual void set_font_size(float font_size) = 0;
|
||||
virtual PDFErrorOr<Gfx::FloatPoint> draw_string(Gfx::Painter&, Gfx::FloatPoint, DeprecatedString const&, Color const&, float font_size, float character_spacing, float word_spacing, float horizontal_scaling) = 0;
|
||||
|
||||
DeprecatedFlyString base_font_name() const { return m_base_font_name; }
|
||||
|
||||
protected:
|
||||
virtual PDFErrorOr<void> initialize(Document* document, NonnullRefPtr<DictObject> const& dict, float font_size);
|
||||
static PDFErrorOr<NonnullRefPtr<Gfx::Font>> replacement_for(StringView name, float font_size);
|
||||
|
||||
private:
|
||||
DeprecatedFlyString m_base_font_name;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ PDFErrorOr<void> TrueTypeFont::initialize(Document* document, NonnullRefPtr<Dict
|
|||
{
|
||||
TRY(SimpleFont::initialize(document, dict, font_size));
|
||||
|
||||
m_base_font_name = TRY(dict->get_name(document, CommonNames::BaseFont))->name();
|
||||
|
||||
// If there's an embedded font program we use that; otherwise we try to find a replacement font
|
||||
if (dict->contains(CommonNames::FontDescriptor)) {
|
||||
auto descriptor = MUST(dict->get_dict(document, CommonNames::FontDescriptor));
|
||||
|
|
|
@ -18,10 +18,13 @@ public:
|
|||
void set_font_size(float font_size) override;
|
||||
PDFErrorOr<void> draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float, u8, Color) override;
|
||||
|
||||
DeprecatedFlyString base_font_name() const { return m_base_font_name; }
|
||||
|
||||
protected:
|
||||
PDFErrorOr<void> initialize(Document*, NonnullRefPtr<DictObject> const&, float font_size) override;
|
||||
|
||||
private:
|
||||
DeprecatedFlyString m_base_font_name;
|
||||
RefPtr<Gfx::Font> m_font;
|
||||
};
|
||||
|
||||
|
|
|
@ -95,6 +95,8 @@ PDFErrorOr<void> Type0Font::initialize(Document* document, NonnullRefPtr<DictObj
|
|||
{
|
||||
TRY(PDFFont::initialize(document, dict, font_size));
|
||||
|
||||
m_base_font_name = TRY(dict->get_name(document, CommonNames::BaseFont))->name();
|
||||
|
||||
// FIXME: Support arbitrary CMaps
|
||||
auto cmap_value = TRY(dict->get_object(document, CommonNames::Encoding));
|
||||
if (!cmap_value->is<NameObject>() || cmap_value->cast<NameObject>()->name() != CommonNames::IdentityH)
|
||||
|
|
|
@ -28,12 +28,15 @@ public:
|
|||
void set_font_size(float font_size) override;
|
||||
PDFErrorOr<Gfx::FloatPoint> draw_string(Gfx::Painter&, Gfx::FloatPoint pos, DeprecatedString const&, Color const&, float, float, float, float) override;
|
||||
|
||||
DeprecatedFlyString base_font_name() const { return m_base_font_name; }
|
||||
|
||||
protected:
|
||||
PDFErrorOr<void> initialize(Document*, NonnullRefPtr<DictObject> const&, float) override;
|
||||
|
||||
private:
|
||||
float get_char_width(u16 char_code) const;
|
||||
|
||||
DeprecatedFlyString m_base_font_name;
|
||||
CIDSystemInfo m_system_info;
|
||||
HashMap<u16, u16> m_widths;
|
||||
u16 m_missing_width;
|
||||
|
|
|
@ -17,6 +17,8 @@ PDFErrorOr<void> Type1Font::initialize(Document* document, NonnullRefPtr<DictObj
|
|||
{
|
||||
TRY(SimpleFont::initialize(document, dict, font_size));
|
||||
|
||||
m_base_font_name = TRY(dict->get_name(document, CommonNames::BaseFont))->name();
|
||||
|
||||
// auto is_standard_font = is_standard_latin_font(font->base_font_name());
|
||||
|
||||
// If there's an embedded font program we use that; otherwise we try to find a replacement font
|
||||
|
|
|
@ -26,10 +26,13 @@ public:
|
|||
void set_font_size(float font_size) override;
|
||||
PDFErrorOr<void> draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u8 char_code, Color color) override;
|
||||
|
||||
DeprecatedFlyString base_font_name() const { return m_base_font_name; }
|
||||
|
||||
protected:
|
||||
PDFErrorOr<void> initialize(Document*, NonnullRefPtr<DictObject> const&, float font_size) override;
|
||||
|
||||
private:
|
||||
DeprecatedFlyString m_base_font_name;
|
||||
RefPtr<Type1FontProgram> m_font_program;
|
||||
RefPtr<Gfx::Font> m_font;
|
||||
HashMap<Type1GlyphCacheKey, RefPtr<Gfx::Bitmap>> m_glyph_cache;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue