1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 19:05:07 +00:00
serenity/Userland/Libraries/LibPDF/Fonts/PDFFont.h
Rodrigo Tobar fb0c3a9e18 LibPDF: Stop calculating code points for glyphs
When rendering text, a sequence of bytes corresponds to a glyph, but not
necessarily to a character. This misunderstanding permeated through the
Encoding through to the Font classes, which were all trying to calculate
such values. Moreover, this was done only to identify "space"
characters/glyphs, which were getting a special treatment (e.g., avoid
rendering). Spaces are not special though -- there might be fonts that
render something for them -- and thus should not be skipped
2023-02-02 14:50:38 +01:00

56 lines
1.5 KiB
C++

/*
* Copyright (c) 2022, Matthew Olsson <mattco@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <AK/Tuple.h>
#include <LibGfx/Forward.h>
#include <LibPDF/Document.h>
#include <LibPDF/Encoding.h>
namespace PDF {
class PDFFont : public RefCounted<PDFFont> {
public:
enum class Type {
Type0,
Type1,
TrueType
};
// This is used both by Type 1 and TrueType fonts.
struct CommonData {
DeprecatedFlyString base_font_name;
RefPtr<Gfx::Font> font;
RefPtr<StreamObject> to_unicode;
RefPtr<Encoding> encoding;
HashMap<u16, u16> widths;
u16 missing_width;
bool is_standard_font;
PDFErrorOr<void> load_from_dict(Document*, NonnullRefPtr<DictObject>, float font_size);
};
static PDFErrorOr<NonnullRefPtr<PDFFont>> create(Document*, NonnullRefPtr<DictObject>, float font_size);
virtual ~PDFFont() = default;
virtual float get_char_width(u16 char_code) const = 0;
virtual void draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float width, u32 char_code, Color color) = 0;
virtual bool is_standard_font() const { return m_is_standard_font; }
virtual Type type() const = 0;
virtual DeprecatedFlyString base_font_name() const = 0;
protected:
static Tuple<DeprecatedString, DeprecatedString> replacement_for_standard_latin_font(StringView);
bool m_is_standard_font { false };
};
}