Added font merging into font atlas and font baker

This commit is contained in:
vurtun 2016-04-02 19:16:00 +02:00
parent a97ac0ea4d
commit f1e81a59ea
4 changed files with 745 additions and 205 deletions

View File

@ -330,6 +330,7 @@ static void mem_free(zr_handle unused, void* ptr)
config.spacing = zr_vec2(0, 0);
config.oversample_h = 1;
config.oversample_v = 1;
config.merge_mode = 0;
// query needed amount of memory for the font baking process
int glyph_count;

View File

@ -621,7 +621,9 @@ demo_window(struct demo *gui, struct zr_context *ctx)
static char field_buffer[64];
static char text[9][64];
static size_t text_len[9];
static char box_buffer[512];
static size_t field_len;
static size_t box_len;
zr_flags active;
zr_layout_row(ctx, ZR_STATIC, 25, 2, ratio);
@ -653,9 +655,21 @@ demo_window(struct demo *gui, struct zr_context *ctx)
zr_label(ctx, "Field:", ZR_TEXT_LEFT);
zr_edit_string(ctx, ZR_EDIT_FIELD, field_buffer, &field_len, 64, zr_filter_default);
zr_label(ctx, "Box:", ZR_TEXT_LEFT);
zr_layout_row_static(ctx, 180, 278, 1);
zr_edit_string(ctx, ZR_EDIT_BOX, box_buffer, &box_len, 512, zr_filter_default);
zr_layout_row(ctx, ZR_STATIC, 25, 2, ratio);
active = zr_edit_string(ctx, ZR_EDIT_FIELD|ZR_EDIT_SIGCOMIT, text[7], &text_len[7], 64, zr_filter_ascii);
zr_button_label(ctx, "Submit", ZR_BUTTON_DEFAULT);
if (zr_button_label(ctx, "Submit", ZR_BUTTON_DEFAULT) ||
(active & ZR_EDIT_COMMITED))
{
text[7][text_len[7]] = '\n';
text_len[7]++;
memcpy(&box_buffer[box_len], &text[7], text_len[7]);
box_len += text_len[7];
text_len[7] = 0;
}
zr_layout_row_end(ctx);
zr_layout_pop(ctx);
}
@ -2576,7 +2590,7 @@ control_window(struct zr_context *ctx, struct demo *gui)
}
if (zr_layout_push(ctx, ZR_LAYOUT_TAB, "Color", ZR_MINIMIZED))
{
struct zr_panel tab, combo;
struct zr_panel combo;
enum theme old = gui->theme;
static const char *themes[] = {"Black", "White", "Red", "Blue", "Dark", "Grey"};

910
zahnrad.c

File diff suppressed because it is too large Load Diff

View File

@ -179,7 +179,9 @@ int zr_stricmp(const char *s1, const char *s2);
int zr_stricmpn(const char *s1, const char *s2, int n);
int zr_strtof(float *number, const char *buffer);
int zr_strfilter(const char *text, const char *regexp);
int zr_strmatch_fuzzy(char const *pattern, char const *str, int *out_score);
int zr_strmatch_fuzzy_string(char const *str, char const *pattern, int *out_score);
int zr_strmatch_fuzzy_text(const char *txt, int txt_len, const char *pattern,
int *out_score);
#if ZR_COMPILE_WITH_STANDARD_IO
int zr_strfmt(char *buf, zr_size len, const char *fmt,...);
#endif
@ -475,6 +477,8 @@ struct zr_font_config {
/* font to setup in the baking process: NOTE: not needed for font atlas */
zr_rune fallback_glyph;
/* fallback glyph to use if a given rune is not found */
int merge_mode;
/* merges this font into the last font */
};
struct zr_font_glyph {
@ -486,14 +490,11 @@ struct zr_font_glyph {
struct zr_font {
struct zr_user_font handle;
float size;
struct zr_baked_font info;
float scale;
float ascent, descent;
struct zr_font_glyph *glyphs;
const struct zr_font_glyph *fallback;
zr_rune fallback_codepoint;
zr_rune glyph_count;
const zr_rune *ranges;
zr_handle texture;
int config;
};
@ -622,14 +623,15 @@ enum zr_edit_flags {
/* edit widget allows text selection */
ZR_EDIT_CLIPBOARD = ZR_FLAG(3),
/* edit widget tries to use the clipbard callback for copy & paste */
ZR_EDIT_SIGCOMIT = ZR_FLAG(4)
ZR_EDIT_SIGCOMIT = ZR_FLAG(4),
/* edit widget generateds ZR_EDIT_COMMITED event on enter */
ZR_EDIT_MULTILINE = ZR_FLAG(5)
};
enum zr_edit_types {
ZR_EDIT_SIMPLE = 0,
ZR_EDIT_FIELD = (ZR_EDIT_CURSOR|ZR_EDIT_SELECTABLE|ZR_EDIT_CLIPBOARD),
ZR_EDIT_BOX = (ZR_EDIT_CURSOR|ZR_EDIT_SELECTABLE| ZR_EDIT_CLIPBOARD)
ZR_EDIT_BOX = (ZR_EDIT_CURSOR|ZR_EDIT_SELECTABLE| ZR_EDIT_CLIPBOARD|ZR_EDIT_MULTILINE)
};
enum zr_edit_events {
@ -915,7 +917,7 @@ void zr_stroke_arc(struct zr_command_buffer*, float cx, float cy, float radius,
void zr_stroke_triangle(struct zr_command_buffer*, float, float, float, float,
float, float, float line_thichness, struct zr_color);
void zr_stroke_polyline(struct zr_command_buffer*, float *points, int point_count,
struct zr_color col);
float line_thickness, struct zr_color col);
void zr_stroke_polygon(struct zr_command_buffer*, float*, int point_count,
float line_thickness, struct zr_color);
@ -1439,6 +1441,7 @@ struct zr_style_edit {
struct zr_style_item hover;
struct zr_style_item active;
struct zr_color border_color;
struct zr_style_scrollbar scrollbar;
/* cursor */
struct zr_style_item cursor_normal;
@ -1456,10 +1459,12 @@ struct zr_style_edit {
struct zr_color selected_text_normal;
struct zr_color selected_text_hover;
/* properties */
float border;
float rounding;
float cursor_size;
float scrollbar_size;
struct zr_vec2 padding;
/* optional user callbacks */