From 913937277fec521a704fc29253198da1a7dbeb82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 13 Feb 2018 14:42:06 +0100 Subject: Add functions for obtaining glyph informations --- src/sdl_ttf.erl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/sdl_ttf.erl') diff --git a/src/sdl_ttf.erl b/src/sdl_ttf.erl index 314f70a..acacdcd 100644 --- a/src/sdl_ttf.erl +++ b/src/sdl_ttf.erl @@ -19,6 +19,8 @@ -export([get_ascent/1]). -export([get_descent/1]). -export([get_family_name/1]). +-export([get_glyph_metrics/2]). +-export([get_glyphs_kerning_size/3]). -export([get_height/1]). -export([get_hinting/1]). -export([get_line_skip/1]). @@ -26,6 +28,7 @@ -export([get_outline/1]). -export([get_style/1]). -export([get_style_name/1]). +-export([has_glyph/2]). -export([is_fixed_width/1]). -export([is_kerning_enabled/1]). -export([is_started/0]). @@ -45,6 +48,9 @@ -opaque font() :: reference(). -export_type([font/0]). +-type glyph() :: 0..65535. +-export_type([glyph/0]). + -type hinting() :: normal | light | mono | none. -export_type([hinting/0]). @@ -74,6 +80,19 @@ get_family_name(Font) -> esdl2:ttf_font_face_family_name(Font), receive {'_nif_thread_ret_', Ret} -> Ret end. +-spec get_glyph_metrics(font(), glyph()) + -> {ok, {integer(), integer(), integer(), integer(), integer()}} + | sdl:error(). +get_glyph_metrics(Font, Glyph) -> + esdl2:ttf_glyph_metrics(Font, Glyph), + receive {'_nif_thread_ret_', Ret} -> Ret end. + +-spec get_glyphs_kerning_size(font(), glyph(), glyph()) + -> {ok, integer()} | sdl:error(). +get_glyphs_kerning_size(Font, PreviousGlyph, Glyph) -> + esdl2:ttf_get_font_kerning_size_glyphs(Font, PreviousGlyph, Glyph), + receive {'_nif_thread_ret_', Ret} -> Ret end. + -spec get_height(font()) -> non_neg_integer(). get_height(Font) -> esdl2:ttf_font_height(Font), @@ -109,6 +128,11 @@ get_style_name(Font) -> esdl2:ttf_font_face_style_name(Font), receive {'_nif_thread_ret_', Ret} -> Ret end. +-spec has_glyph(font(), glyph()) -> boolean(). +has_glyph(Font, Glyph) -> + esdl2:ttf_glyph_is_provided(Font, Glyph), + receive {'_nif_thread_ret_', Ret} -> Ret end. + -spec is_fixed_width(font()) -> boolean(). is_fixed_width(Font) -> esdl2:ttf_font_face_is_fixed_width(Font), -- cgit v1.2.3