@@ -30,28 +30,48 @@ defmodule Blendend.Text do
3030 * returns the resulting `GlyphRun`
3131
3232 Use this when you want to inspect or reuse the shaped glyphs.
33+
34+ On success, returns a `GlyphRun`.
35+
36+ On failure, returns `{:error, reason}`.
37+
38+ ## Examples
39+
40+ gr = Blendend.Text.shape(font, "blendend!")
41+ Blendend.Text.GlyphRun.fill!(canvas, font, 60, 245, gr, fill: rgb(60, 60, 60))
3342 """
34- @ spec shape ( font ( ) , String . t ( ) ) :: glyph_run ( )
43+ @ spec shape ( font ( ) , String . t ( ) ) :: glyph_run ( ) | { :error , term ( ) }
3544 def shape ( font , text ) do
36- { :ok , gb } = GlyphBuffer . new ( )
37-
38- with :ok <- GlyphBuffer . set_utf8_text ( gb , text ) ,
39- :ok <- Font . shape ( font , gb ) do
40- { :ok , GlyphRun . new ( gb ) }
45+ with { :ok , gb } <- GlyphBuffer . new ( ) ,
46+ :ok <- GlyphBuffer . set_utf8_text ( gb , text ) ,
47+ :ok <- Font . shape ( font , gb ) ,
48+ { :ok , gr } <- GlyphRun . new ( gb ) do
49+ gr
4150 end
4251 end
4352
4453 @ doc """
4554 Computes text metrics for the given `text` and `font`.
4655
4756 Internally this uses a glyph buffer and `Font.get_text_metrics/2`.
48- .
57+
58+ ## Examples
59+
60+ iex>Blendend.Text.metrics(font, "blendend")
61+ {:ok,
62+ %{
63+ "advance_x" => 183.264,
64+ "advance_y" => -0.0,
65+ "bbox_x0" => 1.104,
66+ "bbox_x1" => 183.264,
67+ "bbox_y0" => -0.0,
68+ "bbox_y1" => -0.0
69+ }}
4970 """
50- @ spec metrics ( font ( ) , String . t ( ) ) :: term ( ) | { :error , term ( ) }
71+ @ spec metrics ( font ( ) , String . t ( ) ) :: { :ok , map ( ) } | { :error , term ( ) }
5172 def metrics ( font , text ) do
52- gb = GlyphBuffer . new ( )
53-
54- with :ok <- GlyphBuffer . set_utf8_text ( gb , text ) do
73+ with { :ok , gb } <- GlyphBuffer . new ( ) ,
74+ :ok <- GlyphBuffer . set_utf8_text ( gb , text ) do
5575 Font . get_text_metrics ( font , gb )
5676 end
5777 end
0 commit comments