GRUB 2 font: C++11/STL parsing library

Bitmap font format for the GRUB 2 bootloader.

Application

GRUB 2

File extension

pf2

KS implementation details

License: CC0-1.0

References

This page hosts a formal specification of GRUB 2 font using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Usage

Runtime library

All parsing code for C++11/STL generated by Kaitai Struct depends on the C++/STL runtime library. You have to install it before you can parse data.

For C++, the easiest way is to clone the runtime library sources and build them along with your project.

Code

Using Kaitai Struct in C++/STL usually consists of 3 steps.

  1. We need to create an STL input stream (std::istream). One can open local file for that, or use existing std::string or char* buffer.
    #include <fstream>
    
    std::ifstream is("path/to/local/file.pf2", std::ifstream::binary);
    
    #include <sstream>
    
    std::istringstream is(str);
    
    #include <sstream>
    
    const char buf[] = { ... };
    std::string str(buf, sizeof buf);
    std::istringstream is(str);
    
  2. We need to wrap our input stream into Kaitai stream:
    #include "kaitai/kaitaistream.h"
    
    kaitai::kstream ks(&is);
    
  3. And finally, we can invoke the parsing:
    grub2_font_t data(&ks);
    

After that, one can get various attributes from the structure by invoking getter methods like:

data.sections() // => The "DATA" section acts as a terminator. The documentation says:
"A marker that indicates the remainder of the file is data accessed
via the character index (CHIX) section. When reading this font file,
the rest of the file can be ignored when scanning the sections."

C++11/STL source code to parse GRUB 2 font

grub2_font.h

#pragma once

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "kaitai/kaitaistruct.h"
#include <stdint.h>
#include <memory>
#include <vector>

#if KAITAI_STRUCT_VERSION < 9000L
#error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required"
#endif

/**
 * Bitmap font format for the GRUB 2 bootloader.
 * \sa https://grub.gibibit.com/New_font_format Source
 */

class grub2_font_t : public kaitai::kstruct {

public:
    class ptsz_section_t;
    class fami_section_t;
    class weig_section_t;
    class maxw_section_t;
    class desc_section_t;
    class section_t;
    class asce_section_t;
    class chix_section_t;
    class maxh_section_t;
    class name_section_t;
    class slan_section_t;

    grub2_font_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, grub2_font_t* p__root = nullptr);

private:
    void _read();
    void _clean_up();

public:
    ~grub2_font_t();

    class ptsz_section_t : public kaitai::kstruct {

    public:

        ptsz_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

    private:
        void _read();
        void _clean_up();

    public:
        ~ptsz_section_t();

    private:
        uint16_t m_font_point_size;
        grub2_font_t* m__root;
        grub2_font_t::section_t* m__parent;

    public:
        uint16_t font_point_size() const { return m_font_point_size; }
        grub2_font_t* _root() const { return m__root; }
        grub2_font_t::section_t* _parent() const { return m__parent; }
    };

    class fami_section_t : public kaitai::kstruct {

    public:

        fami_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

    private:
        void _read();
        void _clean_up();

    public:
        ~fami_section_t();

    private:
        std::string m_font_family_name;
        grub2_font_t* m__root;
        grub2_font_t::section_t* m__parent;

    public:
        std::string font_family_name() const { return m_font_family_name; }
        grub2_font_t* _root() const { return m__root; }
        grub2_font_t::section_t* _parent() const { return m__parent; }
    };

    class weig_section_t : public kaitai::kstruct {

    public:

        weig_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

    private:
        void _read();
        void _clean_up();

    public:
        ~weig_section_t();

    private:
        std::string m_font_weight;
        grub2_font_t* m__root;
        grub2_font_t::section_t* m__parent;

    public:
        std::string font_weight() const { return m_font_weight; }
        grub2_font_t* _root() const { return m__root; }
        grub2_font_t::section_t* _parent() const { return m__parent; }
    };

    class maxw_section_t : public kaitai::kstruct {

    public:

        maxw_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

    private:
        void _read();
        void _clean_up();

    public:
        ~maxw_section_t();

    private:
        uint16_t m_maximum_character_width;
        grub2_font_t* m__root;
        grub2_font_t::section_t* m__parent;

    public:
        uint16_t maximum_character_width() const { return m_maximum_character_width; }
        grub2_font_t* _root() const { return m__root; }
        grub2_font_t::section_t* _parent() const { return m__parent; }
    };

    class desc_section_t : public kaitai::kstruct {

    public:

        desc_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

    private:
        void _read();
        void _clean_up();

    public:
        ~desc_section_t();

    private:
        uint16_t m_descent_in_pixels;
        grub2_font_t* m__root;
        grub2_font_t::section_t* m__parent;

    public:
        uint16_t descent_in_pixels() const { return m_descent_in_pixels; }
        grub2_font_t* _root() const { return m__root; }
        grub2_font_t::section_t* _parent() const { return m__parent; }
    };

    class section_t : public kaitai::kstruct {

    public:

        section_t(kaitai::kstream* p__io, grub2_font_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

    private:
        void _read();
        void _clean_up();

    public:
        ~section_t();

    private:
        std::string m_section_type;
        uint32_t m_len_body;
        std::unique_ptr<kaitai::kstruct> m_body;
        bool n_body;

    public:
        bool _is_null_body() { body(); return n_body; };

    private:
        grub2_font_t* m__root;
        grub2_font_t* m__parent;
        std::string m__raw_body;
        bool n__raw_body;

    public:
        bool _is_null__raw_body() { _raw_body(); return n__raw_body; };

    private:
        std::unique_ptr<kaitai::kstream> m__io__raw_body;

    public:
        std::string section_type() const { return m_section_type; }

        /**
         * Should be set to `0xFFFF_FFFF` for `section_type != "DATA"`
         */
        uint32_t len_body() const { return m_len_body; }
        kaitai::kstruct* body() const { return m_body.get(); }
        grub2_font_t* _root() const { return m__root; }
        grub2_font_t* _parent() const { return m__parent; }
        std::string _raw_body() const { return m__raw_body; }
        kaitai::kstream* _io__raw_body() const { return m__io__raw_body.get(); }
    };

    class asce_section_t : public kaitai::kstruct {

    public:

        asce_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

    private:
        void _read();
        void _clean_up();

    public:
        ~asce_section_t();

    private:
        uint16_t m_ascent_in_pixels;
        grub2_font_t* m__root;
        grub2_font_t::section_t* m__parent;

    public:
        uint16_t ascent_in_pixels() const { return m_ascent_in_pixels; }
        grub2_font_t* _root() const { return m__root; }
        grub2_font_t::section_t* _parent() const { return m__parent; }
    };

    class chix_section_t : public kaitai::kstruct {

    public:
        class character_t;
        class character_definition_t;

        chix_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

    private:
        void _read();
        void _clean_up();

    public:
        ~chix_section_t();

        class character_t : public kaitai::kstruct {

        public:

            character_t(kaitai::kstream* p__io, grub2_font_t::chix_section_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

        private:
            void _read();
            void _clean_up();

        public:
            ~character_t();

        private:
            bool f_definition;
            std::unique_ptr<character_definition_t> m_definition;

        public:
            character_definition_t* definition();

        private:
            uint32_t m_code_point;
            uint8_t m_flags;
            uint32_t m_ofs_definition;
            grub2_font_t* m__root;
            grub2_font_t::chix_section_t* m__parent;

        public:

            /**
             * Unicode code point
             */
            uint32_t code_point() const { return m_code_point; }
            uint8_t flags() const { return m_flags; }
            uint32_t ofs_definition() const { return m_ofs_definition; }
            grub2_font_t* _root() const { return m__root; }
            grub2_font_t::chix_section_t* _parent() const { return m__parent; }
        };

        class character_definition_t : public kaitai::kstruct {

        public:

            character_definition_t(kaitai::kstream* p__io, grub2_font_t::chix_section_t::character_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

        private:
            void _read();
            void _clean_up();

        public:
            ~character_definition_t();

        private:
            uint16_t m_width;
            uint16_t m_height;
            int16_t m_x_offset;
            int16_t m_y_offset;
            int16_t m_device_width;
            std::string m_bitmap_data;
            grub2_font_t* m__root;
            grub2_font_t::chix_section_t::character_t* m__parent;

        public:
            uint16_t width() const { return m_width; }
            uint16_t height() const { return m_height; }
            int16_t x_offset() const { return m_x_offset; }
            int16_t y_offset() const { return m_y_offset; }
            int16_t device_width() const { return m_device_width; }

            /**
             * A two-dimensional bitmap, one bit per pixel. It is organized as
             * row-major, top-down, left-to-right. The most significant bit of
             * each byte corresponds to the leftmost or uppermost pixel from all
             * bits of the byte. If a bit is set (1, `true`), the pixel is set to
             * the font color, if a bit is clear (0, `false`), the pixel is
             * transparent.
             * 
             * Rows are **not** padded to byte boundaries (i.e., a
             * single byte may contain bits belonging to multiple rows). The last
             * byte of the bitmap _is_ padded with zero bits at all unused least
             * significant bit positions so that the bitmap ends on a byte
             * boundary.
             */
            std::string bitmap_data() const { return m_bitmap_data; }
            grub2_font_t* _root() const { return m__root; }
            grub2_font_t::chix_section_t::character_t* _parent() const { return m__parent; }
        };

    private:
        std::unique_ptr<std::vector<std::unique_ptr<character_t>>> m_characters;
        grub2_font_t* m__root;
        grub2_font_t::section_t* m__parent;

    public:
        std::vector<std::unique_ptr<character_t>>* characters() const { return m_characters.get(); }
        grub2_font_t* _root() const { return m__root; }
        grub2_font_t::section_t* _parent() const { return m__parent; }
    };

    class maxh_section_t : public kaitai::kstruct {

    public:

        maxh_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

    private:
        void _read();
        void _clean_up();

    public:
        ~maxh_section_t();

    private:
        uint16_t m_maximum_character_height;
        grub2_font_t* m__root;
        grub2_font_t::section_t* m__parent;

    public:
        uint16_t maximum_character_height() const { return m_maximum_character_height; }
        grub2_font_t* _root() const { return m__root; }
        grub2_font_t::section_t* _parent() const { return m__parent; }
    };

    class name_section_t : public kaitai::kstruct {

    public:

        name_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

    private:
        void _read();
        void _clean_up();

    public:
        ~name_section_t();

    private:
        std::string m_font_name;
        grub2_font_t* m__root;
        grub2_font_t::section_t* m__parent;

    public:
        std::string font_name() const { return m_font_name; }
        grub2_font_t* _root() const { return m__root; }
        grub2_font_t::section_t* _parent() const { return m__parent; }
    };

    class slan_section_t : public kaitai::kstruct {

    public:

        slan_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent = nullptr, grub2_font_t* p__root = nullptr);

    private:
        void _read();
        void _clean_up();

    public:
        ~slan_section_t();

    private:
        std::string m_font_slant;
        grub2_font_t* m__root;
        grub2_font_t::section_t* m__parent;

    public:
        std::string font_slant() const { return m_font_slant; }
        grub2_font_t* _root() const { return m__root; }
        grub2_font_t::section_t* _parent() const { return m__parent; }
    };

private:
    std::string m_magic;
    std::unique_ptr<std::vector<std::unique_ptr<section_t>>> m_sections;
    grub2_font_t* m__root;
    kaitai::kstruct* m__parent;

public:
    std::string magic() const { return m_magic; }

    /**
     * The "DATA" section acts as a terminator. The documentation says:
     * "A marker that indicates the remainder of the file is data accessed
     * via the character index (CHIX) section. When reading this font file,
     * the rest of the file can be ignored when scanning the sections."
     */
    std::vector<std::unique_ptr<section_t>>* sections() const { return m_sections.get(); }
    grub2_font_t* _root() const { return m__root; }
    kaitai::kstruct* _parent() const { return m__parent; }
};

grub2_font.cpp

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "grub2_font.h"
#include "kaitai/exceptions.h"

grub2_font_t::grub2_font_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = this;
    m_sections = nullptr;
    _read();
}

void grub2_font_t::_read() {
    m_magic = m__io->read_bytes(12);
    if (!(magic() == std::string("\x46\x49\x4C\x45\x00\x00\x00\x04\x50\x46\x46\x32", 12))) {
        throw kaitai::validation_not_equal_error<std::string>(std::string("\x46\x49\x4C\x45\x00\x00\x00\x04\x50\x46\x46\x32", 12), magic(), _io(), std::string("/seq/0"));
    }
    m_sections = std::unique_ptr<std::vector<std::unique_ptr<section_t>>>(new std::vector<std::unique_ptr<section_t>>());
    {
        int i = 0;
        section_t* _;
        do {
            _ = new section_t(m__io, this, m__root);
            m_sections->push_back(std::move(std::unique_ptr<section_t>(_)));
            i++;
        } while (!(_->section_type() == (std::string("DATA"))));
    }
}

grub2_font_t::~grub2_font_t() {
    _clean_up();
}

void grub2_font_t::_clean_up() {
}

grub2_font_t::ptsz_section_t::ptsz_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void grub2_font_t::ptsz_section_t::_read() {
    m_font_point_size = m__io->read_u2be();
}

grub2_font_t::ptsz_section_t::~ptsz_section_t() {
    _clean_up();
}

void grub2_font_t::ptsz_section_t::_clean_up() {
}

grub2_font_t::fami_section_t::fami_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void grub2_font_t::fami_section_t::_read() {
    m_font_family_name = kaitai::kstream::bytes_to_str(m__io->read_bytes_term(0, false, true, true), std::string("ASCII"));
}

grub2_font_t::fami_section_t::~fami_section_t() {
    _clean_up();
}

void grub2_font_t::fami_section_t::_clean_up() {
}

grub2_font_t::weig_section_t::weig_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void grub2_font_t::weig_section_t::_read() {
    m_font_weight = kaitai::kstream::bytes_to_str(m__io->read_bytes_term(0, false, true, true), std::string("ASCII"));
}

grub2_font_t::weig_section_t::~weig_section_t() {
    _clean_up();
}

void grub2_font_t::weig_section_t::_clean_up() {
}

grub2_font_t::maxw_section_t::maxw_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void grub2_font_t::maxw_section_t::_read() {
    m_maximum_character_width = m__io->read_u2be();
}

grub2_font_t::maxw_section_t::~maxw_section_t() {
    _clean_up();
}

void grub2_font_t::maxw_section_t::_clean_up() {
}

grub2_font_t::desc_section_t::desc_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void grub2_font_t::desc_section_t::_read() {
    m_descent_in_pixels = m__io->read_u2be();
}

grub2_font_t::desc_section_t::~desc_section_t() {
    _clean_up();
}

void grub2_font_t::desc_section_t::_clean_up() {
}

grub2_font_t::section_t::section_t(kaitai::kstream* p__io, grub2_font_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    m__io__raw_body = nullptr;
    _read();
}

void grub2_font_t::section_t::_read() {
    m_section_type = kaitai::kstream::bytes_to_str(m__io->read_bytes(4), std::string("ASCII"));
    m_len_body = m__io->read_u4be();
    n_body = true;
    if (section_type() != std::string("DATA")) {
        n_body = false;
        n_body = true;
        {
            std::string on = section_type();
            if (on == std::string("MAXH")) {
                n_body = false;
                m__raw_body = m__io->read_bytes(len_body());
                m__io__raw_body = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_body));
                m_body = std::unique_ptr<maxh_section_t>(new maxh_section_t(m__io__raw_body.get(), this, m__root));
            }
            else if (on == std::string("FAMI")) {
                n_body = false;
                m__raw_body = m__io->read_bytes(len_body());
                m__io__raw_body = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_body));
                m_body = std::unique_ptr<fami_section_t>(new fami_section_t(m__io__raw_body.get(), this, m__root));
            }
            else if (on == std::string("PTSZ")) {
                n_body = false;
                m__raw_body = m__io->read_bytes(len_body());
                m__io__raw_body = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_body));
                m_body = std::unique_ptr<ptsz_section_t>(new ptsz_section_t(m__io__raw_body.get(), this, m__root));
            }
            else if (on == std::string("MAXW")) {
                n_body = false;
                m__raw_body = m__io->read_bytes(len_body());
                m__io__raw_body = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_body));
                m_body = std::unique_ptr<maxw_section_t>(new maxw_section_t(m__io__raw_body.get(), this, m__root));
            }
            else if (on == std::string("SLAN")) {
                n_body = false;
                m__raw_body = m__io->read_bytes(len_body());
                m__io__raw_body = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_body));
                m_body = std::unique_ptr<slan_section_t>(new slan_section_t(m__io__raw_body.get(), this, m__root));
            }
            else if (on == std::string("WEIG")) {
                n_body = false;
                m__raw_body = m__io->read_bytes(len_body());
                m__io__raw_body = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_body));
                m_body = std::unique_ptr<weig_section_t>(new weig_section_t(m__io__raw_body.get(), this, m__root));
            }
            else if (on == std::string("CHIX")) {
                n_body = false;
                m__raw_body = m__io->read_bytes(len_body());
                m__io__raw_body = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_body));
                m_body = std::unique_ptr<chix_section_t>(new chix_section_t(m__io__raw_body.get(), this, m__root));
            }
            else if (on == std::string("DESC")) {
                n_body = false;
                m__raw_body = m__io->read_bytes(len_body());
                m__io__raw_body = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_body));
                m_body = std::unique_ptr<desc_section_t>(new desc_section_t(m__io__raw_body.get(), this, m__root));
            }
            else if (on == std::string("NAME")) {
                n_body = false;
                m__raw_body = m__io->read_bytes(len_body());
                m__io__raw_body = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_body));
                m_body = std::unique_ptr<name_section_t>(new name_section_t(m__io__raw_body.get(), this, m__root));
            }
            else if (on == std::string("ASCE")) {
                n_body = false;
                m__raw_body = m__io->read_bytes(len_body());
                m__io__raw_body = std::unique_ptr<kaitai::kstream>(new kaitai::kstream(m__raw_body));
                m_body = std::unique_ptr<asce_section_t>(new asce_section_t(m__io__raw_body.get(), this, m__root));
            }
            else {
                m__raw_body = m__io->read_bytes(len_body());
            }
        }
    }
}

grub2_font_t::section_t::~section_t() {
    _clean_up();
}

void grub2_font_t::section_t::_clean_up() {
    if (!n_body) {
    }
}

grub2_font_t::asce_section_t::asce_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void grub2_font_t::asce_section_t::_read() {
    m_ascent_in_pixels = m__io->read_u2be();
}

grub2_font_t::asce_section_t::~asce_section_t() {
    _clean_up();
}

void grub2_font_t::asce_section_t::_clean_up() {
}

grub2_font_t::chix_section_t::chix_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    m_characters = nullptr;
    _read();
}

void grub2_font_t::chix_section_t::_read() {
    m_characters = std::unique_ptr<std::vector<std::unique_ptr<character_t>>>(new std::vector<std::unique_ptr<character_t>>());
    {
        int i = 0;
        while (!m__io->is_eof()) {
            m_characters->push_back(std::move(std::unique_ptr<character_t>(new character_t(m__io, this, m__root))));
            i++;
        }
    }
}

grub2_font_t::chix_section_t::~chix_section_t() {
    _clean_up();
}

void grub2_font_t::chix_section_t::_clean_up() {
}

grub2_font_t::chix_section_t::character_t::character_t(kaitai::kstream* p__io, grub2_font_t::chix_section_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    m_definition = nullptr;
    f_definition = false;
    _read();
}

void grub2_font_t::chix_section_t::character_t::_read() {
    m_code_point = m__io->read_u4be();
    m_flags = m__io->read_u1();
    m_ofs_definition = m__io->read_u4be();
}

grub2_font_t::chix_section_t::character_t::~character_t() {
    _clean_up();
}

void grub2_font_t::chix_section_t::character_t::_clean_up() {
    if (f_definition) {
    }
}

grub2_font_t::chix_section_t::character_definition_t* grub2_font_t::chix_section_t::character_t::definition() {
    if (f_definition)
        return m_definition.get();
    kaitai::kstream *io = _root()->_io();
    std::streampos _pos = io->pos();
    io->seek(ofs_definition());
    m_definition = std::unique_ptr<character_definition_t>(new character_definition_t(io, this, m__root));
    io->seek(_pos);
    f_definition = true;
    return m_definition.get();
}

grub2_font_t::chix_section_t::character_definition_t::character_definition_t(kaitai::kstream* p__io, grub2_font_t::chix_section_t::character_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void grub2_font_t::chix_section_t::character_definition_t::_read() {
    m_width = m__io->read_u2be();
    m_height = m__io->read_u2be();
    m_x_offset = m__io->read_s2be();
    m_y_offset = m__io->read_s2be();
    m_device_width = m__io->read_s2be();
    m_bitmap_data = m__io->read_bytes((((width() * height()) + 7) / 8));
}

grub2_font_t::chix_section_t::character_definition_t::~character_definition_t() {
    _clean_up();
}

void grub2_font_t::chix_section_t::character_definition_t::_clean_up() {
}

grub2_font_t::maxh_section_t::maxh_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void grub2_font_t::maxh_section_t::_read() {
    m_maximum_character_height = m__io->read_u2be();
}

grub2_font_t::maxh_section_t::~maxh_section_t() {
    _clean_up();
}

void grub2_font_t::maxh_section_t::_clean_up() {
}

grub2_font_t::name_section_t::name_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void grub2_font_t::name_section_t::_read() {
    m_font_name = kaitai::kstream::bytes_to_str(m__io->read_bytes_term(0, false, true, true), std::string("ASCII"));
}

grub2_font_t::name_section_t::~name_section_t() {
    _clean_up();
}

void grub2_font_t::name_section_t::_clean_up() {
}

grub2_font_t::slan_section_t::slan_section_t(kaitai::kstream* p__io, grub2_font_t::section_t* p__parent, grub2_font_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = p__root;
    _read();
}

void grub2_font_t::slan_section_t::_read() {
    m_font_slant = kaitai::kstream::bytes_to_str(m__io->read_bytes_term(0, false, true, true), std::string("ASCII"));
}

grub2_font_t::slan_section_t::~slan_section_t() {
    _clean_up();
}

void grub2_font_t::slan_section_t::_clean_up() {
}