gpforge
An advanced bitmap font editor
Loading...
Searching...
No Matches
undo.h File Reference

The undo journal. More...

#include "font.h"

Go to the source code of this file.

Enumerations

enum  gpf_undo_what { GPF_UNDO_NONE , GPF_UNDO_GLYPH , GPF_UNDO_FAMILY }
 Undo type. More...

Functions

struct gpf_undo * gpf_undo_new (void)
 Creates a new undo.
void gpf_undo_free (struct gpf_undo *self)
 Frees undo.
void gpf_undo_group_begin (struct gpf_undo *self)
 Starts an undo group.
void gpf_undo_group_end (struct gpf_undo *self)
 Ends an undo group.
int gpf_undo_begin (struct gpf_undo *self, struct gpf_font *font, enum gpf_variant_id id, uint32_t code)
 Snapshots a glyph before it is changed.
int gpf_undo_retarget (struct gpf_undo *self, struct gpf_font *font, enum gpf_variant_id id, uint32_t code)
 Finishes a snapshot and starts a snapshot for a different glyph.
void gpf_undo_commit (struct gpf_undo *self, struct gpf_font *font)
 Finishes an undo on a glyph started by gpf_undo_begin().
int gpf_undo_family (struct gpf_undo *self, struct gpf_font *font, const struct gpf_family_meta *meta, const struct gpf_author *authors)
 Sets the font metadata and authors and saves the old ones into the undo journal.
enum gpf_undo_what gpf_undo (struct gpf_undo *self, struct gpf_font *font, enum gpf_variant_id *id, uint32_t *code)
 Undoes the last entry, or group of entries.
enum gpf_undo_what gpf_redo (struct gpf_undo *self, struct gpf_font *font, enum gpf_variant_id *id, uint32_t *code)
 Redoes the next entry, or group of entries.
void gpf_undo_saved (struct gpf_undo *self)
 Marks the current state as the one written to the file.
int gpf_undo_is_saved (struct gpf_undo *self)
 Returns if the font is in the state written to the file.
int gpf_undo_can_undo (struct gpf_undo *self)
 Returns if undo is possible.
int gpf_undo_can_redo (struct gpf_undo *self)
 Returns if redo is possible.

Detailed Description

The undo journal.

One journal for the whole family, one entry per stroke, per command, per metric change, per overlay created or reverted. An entry is a before and an after snapshot of a single glyph entry in a single variant, either of which may be "the entry did not exist" — which is what creating an overlay and reverting one are.

The other kind of entry is a change to the family metadata, a before and an after snapshot of struct gpf_family_meta and of the font authors.

Definition in file undo.h.

Enumeration Type Documentation

◆ gpf_undo_what

Undo type.

Enumerator
GPF_UNDO_NONE 

The journal had nothing at that end.

GPF_UNDO_GLYPH 

A glyph changed.

Id and code say which.

GPF_UNDO_FAMILY 

The family metadata or the authors changed.

Definition at line 131 of file undo.h.

Function Documentation

◆ gpf_redo()

enum gpf_undo_what gpf_redo ( struct gpf_undo * self,
struct gpf_font * font,
enum gpf_variant_id * id,
uint32_t * code )

Redoes the next entry, or group of entries.

Parameters
selfAn undo journal.
fontA font to apply the redo on.
idWhen glyph was redone this carries the glyph variant e.g. GPF_BOLD.
codeWhen glyph was redone this carries the glyph unicode codepoint.
Returns
What was redone, GPF_UNDO_NONE if there was nothing to redo. A group that carried a glyph returns GPF_UNDO_GLYPH.

Definition at line 448 of file undo.c.

References GPF_UNDO_NONE.

◆ gpf_undo()

enum gpf_undo_what gpf_undo ( struct gpf_undo * self,
struct gpf_font * font,
enum gpf_variant_id * id,
uint32_t * code )

Undoes the last entry, or group of entries.

Parameters
selfAn undo journal.
fontA font to apply the undo on.
idWhen glyph was undone this carries the glyph variant e.g. GPF_BOLD.
codeWhen glyph was undone this carries the glyph unicode codepoint.
Returns
What was undone, GPF_UNDO_NONE if there was nothing to undo. A group that carried a glyph returns GPF_UNDO_GLYPH.

Definition at line 421 of file undo.c.

References GPF_UNDO_NONE.

◆ gpf_undo_begin()

int gpf_undo_begin ( struct gpf_undo * self,
struct gpf_font * font,
enum gpf_variant_id id,
uint32_t code )

Snapshots a glyph before it is changed.

Called before every glyph edit. A second call without a commit in between replaces the snapshot, so a stroke that starts over is not half recorded.

Parameters
selfAn undo journal.
fontA font to snapshot the glyph from.
idA glyph variant e.g. GPF_BOLD.
codeA unicode codepoint of the glyph to snapshot.
Returns
Non-zero on allocation failure.

Definition at line 154 of file undo.c.

References gpf_glyph::bits, and gpf_glyph::code.

◆ gpf_undo_can_redo()

int gpf_undo_can_redo ( struct gpf_undo * self)

Returns if redo is possible.

Parameters
selfAn undo journal, may be NULL.
Returns
True if redo is possible.

Definition at line 490 of file undo.c.

◆ gpf_undo_can_undo()

int gpf_undo_can_undo ( struct gpf_undo * self)

Returns if undo is possible.

Parameters
selfAn undo journal, may be NULL.
Returns
True if undo is possible.

Definition at line 485 of file undo.c.

◆ gpf_undo_commit()

void gpf_undo_commit ( struct gpf_undo * self,
struct gpf_font * font )

Finishes an undo on a glyph started by gpf_undo_begin().

Records what the glyph became. An edit that changed nothing is dropped.

Parameters
selfAn undo journal.
fontA font.

Definition at line 220 of file undo.c.

References gpf_glyph::modified.

◆ gpf_undo_family()

int gpf_undo_family ( struct gpf_undo * self,
struct gpf_font * font,
const struct gpf_family_meta * meta,
const struct gpf_author * authors )

Sets the font metadata and authors and saves the old ones into the undo journal.

Sets the family metadata and the authors, as one journal entry.

The call is a no-op if both are the same as the font's.

Parameters
selfAn undo journal.
fontA font family.
metaNew font family metadata.
authorsNew gp_vec of authors, copied, may be NULL for none.
Returns
Non-zero on an allocation failure.

Definition at line 282 of file undo.c.

References gpf_font::authors, and gpf_font::meta.

◆ gpf_undo_free()

void gpf_undo_free ( struct gpf_undo * self)

Frees undo.

Parameters
selfAn undo journal to be freed.

Definition at line 85 of file undo.c.

References gpf_glyph::bits.

◆ gpf_undo_group_begin()

void gpf_undo_group_begin ( struct gpf_undo * self)

Starts an undo group.

Entries recorded between a group begin and end are undone and redone together.

E.g. deleting a range of glyphs is one action to the user, however many glyphs and variants it touches.

Parameters
selfAn undo journal.

Definition at line 65 of file undo.c.

◆ gpf_undo_group_end()

void gpf_undo_group_end ( struct gpf_undo * self)

Ends an undo group.

Entries recorded between a group begin and end are undone and redone together.

E.g. deleting a range of glyphs is one action to the user, however many glyphs and variants it touches.

Parameters
selfAn undo journal.

Definition at line 70 of file undo.c.

◆ gpf_undo_is_saved()

int gpf_undo_is_saved ( struct gpf_undo * self)

Returns if the font is in the state written to the file.

That is the state at the last gpf_undo_saved(), or the one the journal was created with.

Parameters
selfAn undo journal.
Returns
True if the journal is at the saved state.

Definition at line 480 of file undo.c.

◆ gpf_undo_new()

struct gpf_undo * gpf_undo_new ( void )

Creates a new undo.

Returns
A pointer to newly allocated and initialized undo or NULL in a case of a failure.

Definition at line 49 of file undo.c.

◆ gpf_undo_retarget()

int gpf_undo_retarget ( struct gpf_undo * self,
struct gpf_font * font,
enum gpf_variant_id id,
uint32_t code )

Finishes a snapshot and starts a snapshot for a different glyph.

If the pending snapshot is already for this glyph and variant it's a no-op. Otherwise commits whatever was pending first with gpf_undo_commit(), then starts a new glyph snapshot with gpf_undo_begin().

Parameters
selfAn undo journal.
fontA font to snapshot the glyph from.
idA glyph variant e.g. GPF_BOLD.
codeA unicode codepoint of the glyph to snapshot.
Returns
Non-zero on allocation failure.

Definition at line 173 of file undo.c.

References gpf_glyph::code.

◆ gpf_undo_saved()

void gpf_undo_saved ( struct gpf_undo * self)

Marks the current state as the one written to the file.

Undo and redo then clear the modified flag of glyphs they bring back to that state.

Parameters
selfAn undo journal.

Definition at line 475 of file undo.c.