Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/xairo/text/extents.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ defmodule Xairo.Text.Extents do
y_advance: number()
}

@doc """
Returns the text exetnts of the given text in the context of the
image's configuration.
"""
def for(text, %Xairo.Image{resource: resource}) do
with {:ok, extents} <- Xairo.Native.text_extents(resource, text) do
extents
end
end

defimpl Inspect do
import Inspect.Algebra

Expand Down
15 changes: 15 additions & 0 deletions test/xairo/text/extents_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Xairo.Text.ExtentsTest do
use ExUnit.Case, async: true

alias Xairo.Text.Extents

describe "for/2" do
test "returns a Text.Extents struct for the given string in the context of the image" do
image = Xairo.new_image(1000, 1000, 20)

%Extents{} = extents = Extents.for("hello", image)

assert extents.text == "hello"
end
end
end