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

Accented letters: the decomposition table and accent composition. More...

#include <stdint.h>
#include "font.h"
#include "resolve.h"

Go to the source code of this file.

Data Structures

struct  gpf_decomposition
 A glyph decomposition. More...

Enumerations

enum  gpf_accent_place { GPF_ACCENT_ABOVE , GPF_ACCENT_BELOW , GPF_ACCENT_OGONEK }
 Accent location in the glyph rectangle. More...

Functions

unsigned int gpf_decompose_accented (uint32_t base_code, uint32_t *codes, unsigned int max)
 Returns all accented forms of a letter.
unsigned int gpf_decompose_by_accent (uint32_t accent, uint32_t *codes, unsigned int max)
 Looks up all glyphs for a given accent.
uint32_t gpf_decompose_base (uint32_t code)
 Looks up the base letter of an accented letter.
const struct gpf_decomposition * gpf_decompose (uint32_t code)
 Looks up the decomposition of an accented letter.
void gpf_accent_offset (const struct gpf_font *font, const struct gpf_glyph *base, const struct gpf_glyph *accent, enum gpf_accent_place place, int *dx, int *dy)
 The default offset for an accent on a base.
int gpf_compose (struct gpf_glyph *dst, const struct gpf_glyph *base, const struct gpf_glyph *accent, int dx, int dy)
 Composes the base ink with the accent ink.
int gpf_compose_remainder (const struct gpf_glyph *glyph, const struct gpf_glyph *base, struct gpf_glyph *rem)
 Subtracts the base ink from a glyph.
int gpf_draw_base (struct gpf_font *font, enum gpf_variant_id id, const struct gpf_decomposition *decomp, struct gpf_resolved *res)
 The letter a new accented letter is drawn from.
int gpf_accent_ink (struct gpf_font *font, enum gpf_variant_id id, const struct gpf_decomposition *decomp, struct gpf_glyph *out)
 The accent of a decomposition, as this font draws it.

Variables

const struct gpf_decomposition gpf_decompositions []
 A decomposition table.

Detailed Description

Accented letters: the decomposition table and accent composition.

The table is generated from the unicode decompositions. It says which letters are accented forms of which letter — that is what the editor works on, the letters that have to follow when a letter is edited — and, for drawing a new one, what to draw it from and which accent to put on it.

The composition is what draws a new letter: the accent taken off a letter that has it, put on the base at gpf_accent_offset().

Definition in file compose.h.

Enumeration Type Documentation

◆ gpf_accent_place

Accent location in the glyph rectangle.

Enumerator
GPF_ACCENT_ABOVE 

Centred over the ink, one blank row above it.

GPF_ACCENT_BELOW 

Centred under the ink, right below it.

GPF_ACCENT_OGONEK 

Right aligned with the ink, right below it.

Definition at line 28 of file compose.h.

Function Documentation

◆ gpf_accent_ink()

int gpf_accent_ink ( struct gpf_font * font,
enum gpf_variant_id id,
const struct gpf_decomposition * decomp,
struct gpf_glyph * out )

The accent of a decomposition, as this font draws it.

Attempts to resolve accent ink from existing letters. E.g. caron can be resolved from 'Č' minus 'C'. The accent is subtracted from whichever glyph carries it. Where it goes on the new letter is gpf_accent_offset().

Falls back to the combining mark and then to the spacing accent, for a font that has no letter to take it from.

Parameters
fontA font.
idA glyph variant id e.g. GPF_BOLD.
decompA decomposition description.
outWhere to store the result to.
Returns
Non-zero when the font has no way to draw this accent.

Definition at line 725 of file compose.c.

References gpf_decomposition::accent, gpf_glyph::bits, gpf_resolved::glyph, gpf_resolve(), gpf_resolved_clear(), and gpf_decomposition::mark.

◆ gpf_accent_offset()

void gpf_accent_offset ( const struct gpf_font * font,
const struct gpf_glyph * base,
const struct gpf_glyph * accent,
enum gpf_accent_place place,
int * dx,
int * dy )

The default offset for an accent on a base.

The starting point a hand adjustment moves from. The accent is kept inside the font's box: a letter that already reaches the ascent leaves no room above it, and an accent drawn outside the box is drawn into the line above. It is pushed down (or up) until it fits, which is what a bitmap font does at small sizes anyway.

Parameters
fontA font, its ascent and descent are the box; NULL for no clamp.
baseThe base glyph.
accentThe accent glyph.
placeWhere the accent goes.
dxWhere to store the offset for the accent ink, positive right.
dyWhere to store the offset for the accent ink, positive up.

Definition at line 418 of file compose.c.

References gpf_decomposition::accent, gpf_family_meta::ascent, gpf_glyph::bearing_x, gpf_glyph::bearing_y, gpf_family_meta::descent, GPF_ACCENT_ABOVE, GPF_ACCENT_BELOW, GPF_ACCENT_OGONEK, gpf_glyph::height, gpf_font::meta, gpf_decomposition::place, and gpf_glyph::width.

◆ gpf_compose()

int gpf_compose ( struct gpf_glyph * dst,
const struct gpf_glyph * base,
const struct gpf_glyph * accent,
int dx,
int dy )

Composes the base ink with the accent ink.

The metrics come from the base.

Parameters
dstWhere to store the composed glyph into.
baseA base glyph.
accentAn accent glyph.
dxOffset for the accent ink, positive right.
dyOffset for the accent ink, positive up.
Returns
Non-zero on an allocation failure.

Definition at line 494 of file compose.c.

References gpf_decomposition::accent, gpf_glyph::advance, gpf_glyph::bearing_x, gpf_glyph::bearing_y, gpf_glyph::bits, GPF_GLYPH_INK, GPF_MAX, GPF_MIN, gpf_glyph::has_advance, gpf_glyph::has_bearing, gpf_glyph::height, gpf_glyph::kind, and gpf_glyph::width.

◆ gpf_compose_remainder()

int gpf_compose_remainder ( const struct gpf_glyph * glyph,
const struct gpf_glyph * base,
struct gpf_glyph * rem )

Subtracts the base ink from a glyph.

Fails when the base does not sit inside the glyph pixel for pixel, or when nothing is left after the subtraction.

Parameters
glyphAn accented letter.
baseThe letter it is drawn from.
remWhere to store what is left, the accent.
Returns
Zero on success, non-zero otherwise.

Definition at line 543 of file compose.c.

References gpf_glyph::advance, gpf_glyph::bearing_x, gpf_glyph::bearing_y, GPF_GLYPH_INK, gpf_glyph_pixel(), GPF_MAX, GPF_MIN, gpf_glyph::has_advance, gpf_glyph::has_bearing, gpf_glyph::height, gpf_glyph::kind, and gpf_glyph::width.

◆ gpf_decompose()

const struct gpf_decomposition * gpf_decompose ( uint32_t code)

Looks up the decomposition of an accented letter.

Parameters
codeA codepoint to look up.
Returns
The decomposition of a codepoint, or NULL when it is not one.

Definition at line 357 of file compose.c.

References gpf_decomposition::code.

Referenced by gpf_decompose_base(), and gpf_gui_create_glyph().

◆ gpf_decompose_accented()

unsigned int gpf_decompose_accented ( uint32_t base_code,
uint32_t * codes,
unsigned int max )

Returns all accented forms of a letter.

The accented forms of a letter, sorted by the codepoint: A has À Á Â Ã Ä Å Ā Ă Ą Ǎ, i has ì í î ï ĩ ī ĭ į ǐ. These are the letters the update box copies an edit of the letter into.

Parameters
base_codeA base code to lookup the accented variants for.
codesAn array to fill the accented letters into.
maxThe size of the codes array.
Returns
How many codes were written into codes, at most max.

Definition at line 372 of file compose.c.

References gpf_decomposition::base_code.

◆ gpf_decompose_base()

uint32_t gpf_decompose_base ( uint32_t code)

Looks up the base letter of an accented letter.

The letter whose accented forms to work with when this glyph is selected: the glyph itself, or the letter it is an accented form of. Selecting í and selecting i show the same family.

Parameters
codeA codepoint to lookup the base variant for.
Returns
A base codepoint, if found, the code passed as argument otherwise.

Definition at line 411 of file compose.c.

References gpf_decomposition::base_code, gpf_decomposition::code, and gpf_decompose().

◆ gpf_decompose_by_accent()

unsigned int gpf_decompose_by_accent ( uint32_t accent,
uint32_t * codes,
unsigned int max )

Looks up all glyphs for a given accent.

The letters an accent goes on, sorted by the codepoint: the caron — the combining U+030C or the spacing U+02C7, either names it — has Č Ď Ě Ľ Ň Ř Š Ť Ž and their lower case. These are the letters the accented letters strip shows composed while the mark is selected.

Parameters
accentAn accent to lookup the accented variants for.
codesAn array to fill the accented letters into.
maxThe size of the codes array.
Returns
How many codes were written into codes, at most max.

Definition at line 392 of file compose.c.

References gpf_decomposition::accent, and gpf_decomposition::mark.

◆ gpf_draw_base()

int gpf_draw_base ( struct gpf_font * font,
enum gpf_variant_id id,
const struct gpf_decomposition * decomp,
struct gpf_resolved * res )

The letter a new accented letter is drawn from.

The decomposition's gpf_decomposition::draw_base, and for an i or a j that the font has no dotless form of, the letter with its dot taken off.

Parameters
fontA font.
idA glyph variant id e.g. GPF_BOLD.
decompA decomposition description.
resWhere to store the base, free it with gpf_resolved_clear().
Returns
Non-zero when the font has no letter to draw it from.

Definition at line 660 of file compose.c.

References gpf_decomposition::base_code, gpf_decomposition::draw_base, and gpf_resolved::glyph.

Variable Documentation

◆ gpf_decompositions

const struct gpf_decomposition gpf_decompositions[]
extern

A decomposition table.

Zero terminated, sorted by the codepoint.

Definition at line 25 of file compose.c.