diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2021-09-21 17:42:25 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-22 21:35:42 +0200 |
commit | 0a4640e89226f7278c9bc58caae7086da374668d (patch) | |
tree | 53f6de5b7bd065aef9a8271c70bfbdab8c0dae1b /Userland/Applications/FontEditor/UndoGlyph.h | |
parent | 1ae4caca4b1df4676649edb1441d04a2713b864b (diff) | |
download | serenity-0a4640e89226f7278c9bc58caae7086da374668d.zip |
FontEditor: Put glyph width changes on the undo stack
And select the restored glyph on undo/redo.
Diffstat (limited to 'Userland/Applications/FontEditor/UndoGlyph.h')
-rw-r--r-- | Userland/Applications/FontEditor/UndoGlyph.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Userland/Applications/FontEditor/UndoGlyph.h b/Userland/Applications/FontEditor/UndoGlyph.h index 63e571248c..d5e326107b 100644 --- a/Userland/Applications/FontEditor/UndoGlyph.h +++ b/Userland/Applications/FontEditor/UndoGlyph.h @@ -21,26 +21,34 @@ public: { auto state = adopt_ref(*new UndoGlyph(m_code_point, *m_font)); auto glyph = font().glyph(m_code_point).glyph_bitmap(); - for (int x = 0; x < glyph.width(); x++) - for (int y = 0; y < glyph.height(); y++) + for (int x = 0; x < font().max_glyph_width(); x++) + for (int y = 0; y < font().glyph_height(); y++) state->m_bits[x][y] = glyph.bit_at(x, y); + state->m_width = glyph.width(); return state; } void restore_state(const UndoGlyph& state) const { auto bitmap = font().glyph(state.m_code_point).glyph_bitmap(); - for (int x = 0; x < bitmap.width(); x++) - for (int y = 0; y < bitmap.height(); y++) + for (int x = 0; x < font().max_glyph_width(); x++) + for (int y = 0; y < font().glyph_height(); y++) bitmap.set_bit_at(x, y, state.m_bits[x][y]); + m_restored_width = state.m_width; + m_restored_code_point = state.m_code_point; } void set_code_point(size_t point) { m_code_point = point; } void set_font(Gfx::BitmapFont& font) { m_font = font; } const Gfx::BitmapFont& font() const { return *m_font; } + u8 restored_width() const { return m_restored_width; } + u32 restored_code_point() const { return m_restored_code_point; } private: size_t m_code_point; RefPtr<Gfx::BitmapFont> m_font; u8 m_bits[32][36] = {}; + u8 m_width { 0 }; + mutable u8 m_restored_width { 0 }; + mutable u32 m_restored_code_point { 0 }; }; class GlyphUndoCommand : public GUI::Command { |