diff options
| -rw-r--r-- | src/text.cc | 6 | ||||
| -rw-r--r-- | src/text.h | 3 | ||||
| -rw-r--r-- | src/utils.h | 7 |
3 files changed, 15 insertions, 1 deletions
diff --git a/src/text.cc b/src/text.cc index ff9b833..2bfc7a3 100644 --- a/src/text.cc +++ b/src/text.cc @@ -97,12 +97,18 @@ enum font_error_e wayc_font_lookup(struct font_s* font, struct atlas_s* atlas, FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL); FT_Bitmap bitmap = slot->bitmap; + if (bitmap.pitch != (i32)bitmap.width) wayc_panic("unsupported pitch"); + ivec2 size = {(i32)bitmap.width, (i32)bitmap.rows}; wayc_atlas_set(atlas, IMAGE_DATA_TYPE_UNSIGNED_BYTE, font->cursor, size[0], size[1], IMAGE_FORMAT_RED_ALIGNMENT, bitmap.buffer); struct glyph_s glyph = {}; + glyph.bearing_x = slot->bitmap_left; + glyph.bearing_y = slot->bitmap_top; + glyph.advance = (f32)slot->advance.x / WAYC_SCALE; + glm_ivec2(font->cursor, glyph.uv0); glm_ivec2_add(glyph.uv0, size, glyph.uv1); @@ -22,6 +22,9 @@ void wayc_font_context_deinit(struct font_context_s* ctx); struct glyph_s { ivec2 uv0, uv1; + + i32 bearing_x, bearing_y; + f32 advance; }; enum font_error_e { diff --git a/src/utils.h b/src/utils.h index f159c9b..10bdd88 100644 --- a/src/utils.h +++ b/src/utils.h @@ -19,6 +19,9 @@ typedef int16_t i16; typedef int32_t i32; typedef int64_t i64; +typedef float f32; +typedef double f64; + #if UINT64_MAX == UINTPTR_MAX typedef u64 usize; typedef i64 isize; @@ -68,6 +71,8 @@ static inline u32 wayc_min(u32 a, u32 b) { return a > b ? a : b; } #define WAYC_CONCAT(a, b) WAYC_CONCAT_IMPL(a, b) #define WAYC_UNIQUE(base) WAYC_CONCAT(base, WAYC_CONCAT(__LINE__, __COUNTER__)) +#define WAYC_FRAC_BITS 6 +#define WAYC_SCALE (1 << WAYC_FRAC_BITS) template <typename A, typename B> struct is_same { @@ -106,4 +111,4 @@ struct defer_cond_s { }; #define wayc_defer_cond(func, cond, expected) \ - auto WAYC_UNIQUE(_defer_) = defer_cond_s([&]() { func; }, &cond, expected)
\ No newline at end of file + auto WAYC_UNIQUE(_defer_) = defer_cond_s([&]() { func; }, &cond, expected) |
