mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:47:35 +00:00
LibPDF: Give TrueTypePainter a ScaledFont instead of a Font
This will allow us to get at the font's glyphs as paths, which will eventually enable us to implement glyph rotation. We'll have to do our own caching then, but we can then hopefully share the caching across the Type0 / Type1 / TrueType codepaths. It also gives us access to a font's glyphs by glyph id, which will help us implementing looking up glyph ids by postscript name. (Else we'd have to plumb through a whole Painter::draw_glyph_by_postscript_name() API just for LibPDF.) No behavior change.
This commit is contained in:
parent
5dad8b693e
commit
f374ad50a1
2 changed files with 7 additions and 8 deletions
|
@ -15,7 +15,7 @@
|
|||
|
||||
namespace PDF {
|
||||
|
||||
TrueTypePainter::TrueTypePainter(AK::NonnullRefPtr<Gfx::Font> font, NonnullRefPtr<Encoding> encoding, bool encoding_is_mac_roman_or_win_ansi, bool is_nonsymbolic, Optional<u8> high_byte, bool is_zapf_dingbats)
|
||||
TrueTypePainter::TrueTypePainter(AK::NonnullRefPtr<Gfx::ScaledFont> font, NonnullRefPtr<Encoding> encoding, bool encoding_is_mac_roman_or_win_ansi, bool is_nonsymbolic, Optional<u8> high_byte, bool is_zapf_dingbats)
|
||||
: m_font(move(font))
|
||||
, m_encoding(move(encoding))
|
||||
, m_encoding_is_mac_roman_or_win_ansi(encoding_is_mac_roman_or_win_ansi)
|
||||
|
@ -25,7 +25,7 @@ TrueTypePainter::TrueTypePainter(AK::NonnullRefPtr<Gfx::Font> font, NonnullRefPt
|
|||
{
|
||||
}
|
||||
|
||||
NonnullOwnPtr<TrueTypePainter> TrueTypePainter::create(Document* document, NonnullRefPtr<DictObject> const& dict, SimpleFont const& containing_pdf_font, AK::NonnullRefPtr<Gfx::Font> font, NonnullRefPtr<Encoding> encoding, bool is_zapf_dingbats)
|
||||
NonnullOwnPtr<TrueTypePainter> TrueTypePainter::create(Document* document, NonnullRefPtr<DictObject> const& dict, SimpleFont const& containing_pdf_font, AK::NonnullRefPtr<Gfx::ScaledFont> font, NonnullRefPtr<Encoding> encoding, bool is_zapf_dingbats)
|
||||
{
|
||||
bool encoding_is_mac_roman_or_win_ansi = false;
|
||||
if (dict->contains(CommonNames::Encoding)) {
|
||||
|
@ -150,8 +150,7 @@ Optional<float> TrueTypePainter::get_glyph_width(u8 char_code) const
|
|||
|
||||
void TrueTypePainter::set_font_size(float font_size)
|
||||
{
|
||||
// Guaranteed non-null for ScaledFonts.
|
||||
m_font = *m_font->with_size((font_size * POINTS_PER_INCH) / DEFAULT_DPI);
|
||||
m_font = m_font->scaled_with_size((font_size * POINTS_PER_INCH) / DEFAULT_DPI);
|
||||
}
|
||||
|
||||
PDFErrorOr<void> TrueTypeFont::initialize(Document* document, NonnullRefPtr<DictObject> const& dict, float font_size)
|
||||
|
@ -161,7 +160,7 @@ PDFErrorOr<void> TrueTypeFont::initialize(Document* document, NonnullRefPtr<Dict
|
|||
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
|
||||
RefPtr<Gfx::Font> font;
|
||||
RefPtr<Gfx::ScaledFont> font;
|
||||
if (dict->contains(CommonNames::FontDescriptor)) {
|
||||
auto descriptor = MUST(dict->get_dict(document, CommonNames::FontDescriptor));
|
||||
if (descriptor->contains(CommonNames::FontFile2)) {
|
||||
|
|
|
@ -14,16 +14,16 @@ namespace PDF {
|
|||
|
||||
class TrueTypePainter {
|
||||
public:
|
||||
static NonnullOwnPtr<TrueTypePainter> create(Document*, NonnullRefPtr<DictObject> const&, SimpleFont const& containing_pdf_font, AK::NonnullRefPtr<Gfx::Font>, NonnullRefPtr<Encoding>, bool is_zapf_dingbats);
|
||||
static NonnullOwnPtr<TrueTypePainter> create(Document*, NonnullRefPtr<DictObject> const&, SimpleFont const& containing_pdf_font, AK::NonnullRefPtr<Gfx::ScaledFont>, NonnullRefPtr<Encoding>, bool is_zapf_dingbats);
|
||||
|
||||
PDFErrorOr<void> draw_glyph(Gfx::Painter&, Gfx::FloatPoint, float width, u8 char_code, Renderer const&);
|
||||
Optional<float> get_glyph_width(u8 char_code) const;
|
||||
void set_font_size(float font_size);
|
||||
|
||||
private:
|
||||
TrueTypePainter(AK::NonnullRefPtr<Gfx::Font>, NonnullRefPtr<Encoding>, bool encoding_is_mac_roman_or_win_ansi, bool is_nonsymbolic, Optional<u8> high_byte, bool is_zapf_dingbats);
|
||||
TrueTypePainter(AK::NonnullRefPtr<Gfx::ScaledFont>, NonnullRefPtr<Encoding>, bool encoding_is_mac_roman_or_win_ansi, bool is_nonsymbolic, Optional<u8> high_byte, bool is_zapf_dingbats);
|
||||
|
||||
NonnullRefPtr<Gfx::Font> m_font;
|
||||
NonnullRefPtr<Gfx::ScaledFont> m_font;
|
||||
NonnullRefPtr<Encoding> m_encoding;
|
||||
bool m_encoding_is_mac_roman_or_win_ansi { false };
|
||||
bool m_is_nonsymbolic { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue