-module(starprnt). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/starprnt.gleam"). -export([print_speed/1, render_text/5]). -export_type([speed/0, wrap/0]). -type speed() :: slow | normal | fast. -type wrap() :: no_wrap | wrap_anywhere | wrap_only_words | wrap_prefer_words. -file("src/starprnt.gleam", 14). -spec print_speed(speed()) -> bitstring(). print_speed(Speed) -> <<16#1b, 16#1e, "r"/utf8, (case Speed of slow -> 2; normal -> 1; fast -> 0 end)>>. -file("src/starprnt.gleam", 117). -spec do_process_codepoints( list(integer()), bitstring(), fun((binary()) -> {ok, bitstring()} | {error, nil}), list({binary(), bitstring()}) ) -> list({binary(), bitstring()}). do_process_codepoints(Codepoints, Default_glyph, Render_glyph, Acc) -> case Codepoints of [] -> Acc; [Codepoint | Codepoints@1] -> Char = gleam_stdlib:utf_codepoint_list_to_string([Codepoint]), Acc@1 = case Render_glyph(Char) of {ok, Bits} -> [{Char, Bits} | Acc]; {error, nil} -> [{Char, Default_glyph} | Acc] end, do_process_codepoints( Codepoints@1, Default_glyph, Render_glyph, Acc@1 ) end. -file("src/starprnt.gleam", 81). -spec do_process_graphemes( list(binary()), bitstring(), fun((binary()) -> {ok, bitstring()} | {error, nil}), list({binary(), bitstring()}) ) -> list({binary(), bitstring()}). do_process_graphemes(Graphemes, Default_glyph, Render_glyph, Acc) -> case Graphemes of [] -> lists:reverse(Acc); [<<"\r"/utf8>> | Graphemes@1] -> do_process_graphemes(Graphemes@1, Default_glyph, Render_glyph, Acc); [<<"\t"/utf8>> | Graphemes@2] -> do_process_graphemes( [<<" "/utf8>>, <<" "/utf8>> | Graphemes@2], Default_glyph, Render_glyph, Acc ); [<<"\f"/utf8>> | Graphemes@3] -> do_process_graphemes( [<<"\n"/utf8>>, <<"\n"/utf8>> | Graphemes@3], Default_glyph, Render_glyph, Acc ); [Grapheme | Graphemes@4] -> Acc@1 = case Render_glyph(Grapheme) of {ok, Bits} -> [{Grapheme, Bits} | Acc]; {error, nil} -> _pipe = gleam@string:to_utf_codepoints(Grapheme), do_process_codepoints( _pipe, Default_glyph, Render_glyph, Acc ) end, do_process_graphemes( Graphemes@4, Default_glyph, Render_glyph, Acc@1 ) end. -file("src/starprnt.gleam", 146). -spec do_no_wrap( list({binary(), bitstring()}), integer(), integer(), list(bitstring()), list(list(bitstring())) ) -> list(list(bitstring())). do_no_wrap(Chars, Line_limit, Line_len, Line, Lines) -> case Chars of [] -> lists:reverse([lists:reverse(Line) | Lines]); [{<<"\n"/utf8>>, _} | Chars@1] -> do_no_wrap( Chars@1, Line_limit, 0, [], [lists:reverse(Line) | Lines] ); [{_, Bits} | Chars@2] when Line_len < Line_limit -> do_no_wrap(Chars@2, Line_limit, Line_len + 1, [Bits | Line], Lines); [_ | Chars@3] -> do_no_wrap(Chars@3, Line_limit, Line_len, Line, Lines) end. -file("src/starprnt.gleam", 163). -spec do_wrap_anywhere( list({binary(), bitstring()}), integer(), integer(), list(bitstring()), list(list(bitstring())) ) -> list(list(bitstring())). do_wrap_anywhere(Chars, Line_limit, Line_len, Line, Lines) -> case Chars of [] -> lists:reverse([lists:reverse(Line) | Lines]); [{<<"\n"/utf8>>, _} | Chars@1] -> Acc = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@1, Line_limit, 0, [], Acc); [{_, Bits} | Chars@2] when Line_len < Line_limit -> Line@1 = [Bits | Line], do_wrap_anywhere(Chars@2, Line_limit, Line_len + 1, Line@1, Lines); [{<<" "/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{1680}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{2000}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{2001}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{2002}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{2003}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{2004}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{2005}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{2006}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{2008}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{2009}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{200a}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{205f}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{<<"\x{3000}"/utf8>>, _} | Chars@3] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@3, Line_limit, 0, [], Lines@1); [{_, Bits@1} | Chars@4] -> Lines@2 = [lists:reverse(Line) | Lines], do_wrap_anywhere(Chars@4, Line_limit, 1, [Bits@1], Lines@2) end. -file("src/starprnt.gleam", 246). -spec do_wrap_only_words( list({binary(), bitstring()}), integer(), bitstring(), integer(), list(bitstring()), integer(), list(bitstring()), list(list(bitstring())) ) -> list(list(bitstring())). do_wrap_only_words( Chars, Line_limit, Break, Word_len, Word, Line_len, Line, Lines ) -> case Chars of [] when (Line_len + Word_len) < Line_limit -> Line@1 = case Line of [] -> lists:reverse(Word); _ -> lists:reverse(Line, [Break | lists:reverse(Word)]) end, lists:reverse([Line@1 | Lines]); [] -> lists:reverse([lists:reverse(Word), lists:reverse(Line) | Lines]); [{<<"\n"/utf8>>, _} | Chars@1] when (Line_len + Word_len) < Line_limit -> Line@2 = case Line of [] -> lists:reverse(Word); _ -> lists:reverse(Line, [Break | lists:reverse(Word)]) end, Lines@1 = [Line@2 | Lines], do_wrap_only_words( Chars@1, Line_limit, Break, 0, [], 0, [], Lines@1 ); [{<<"\n"/utf8>>, _} | Chars@2] -> Lines@2 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@2, Line_limit, Break, Word_len, Word, 0, [], Lines@2 ); [{<<" "/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{1680}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2000}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2001}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2002}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2003}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2004}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2005}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2006}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2008}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2009}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{200a}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{205f}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{3000}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_only_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<" "/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{1680}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2000}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2001}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2002}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2003}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2004}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2005}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2006}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2008}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2009}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{200a}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{205f}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{3000}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_only_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{_, Bits} | Chars@5] when Word_len < Line_limit -> do_wrap_only_words( Chars@5, Line_limit, Break, Word_len + 1, [Bits | Word], Line_len, Line, Lines ); [_ | Chars@6] -> do_wrap_only_words( Chars@6, Line_limit, Break, Word_len, Word, Line_len, Line, Lines ) end. -file("src/starprnt.gleam", 204). -spec do_wrap_only_words_unbroken( list({binary(), bitstring()}), integer(), integer(), list(bitstring()), list(list(bitstring())) ) -> list(list(bitstring())). do_wrap_only_words_unbroken(Chars, Line_limit, Line_len, Line, Lines) -> case Chars of [] -> lists:reverse([lists:reverse(Line) | Lines]); [{<<"\n"/utf8>>, _} | Chars@1] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_only_words_unbroken(Chars@1, Line_limit, 0, [], Lines@1); [{<<" "/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{1680}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2000}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2001}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2002}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2003}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2004}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2005}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2006}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2008}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2009}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{200a}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{205f}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{3000}"/utf8>>, Break} | Chars@2] -> do_wrap_only_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{_, Bits} | Chars@3] when Line_len < Line_limit -> do_wrap_only_words_unbroken( Chars@3, Line_limit, Line_len + 1, [Bits | Line], Lines ); [_ | Chars@4] -> do_wrap_only_words_unbroken( Chars@4, Line_limit, Line_len, Line, Lines ) end. -file("src/starprnt.gleam", 406). -spec do_wrap_prefer_words( list({binary(), bitstring()}), integer(), bitstring(), integer(), list(bitstring()), integer(), list(bitstring()), list(list(bitstring())) ) -> list(list(bitstring())). do_wrap_prefer_words( Chars, Line_limit, Break, Word_len, Word, Line_len, Line, Lines ) -> case Chars of [] when (Line_len + Word_len) < Line_limit -> Line@1 = case Line of [] -> lists:reverse(Word); _ -> lists:reverse(Line, [Break | lists:reverse(Word)]) end, lists:reverse([Line@1 | Lines]); [] -> lists:reverse([lists:reverse(Word), lists:reverse(Line) | Lines]); [{<<"\n"/utf8>>, _} | Chars@1] when (Line_len + Word_len) < Line_limit -> Line@2 = case Line of [] -> lists:reverse(Word); _ -> lists:reverse(Line, [Break | lists:reverse(Word)]) end, Lines@1 = [Line@2 | Lines], do_wrap_prefer_words( Chars@1, Line_limit, Break, 0, [], 0, [], Lines@1 ); [{<<"\n"/utf8>>, _} | Chars@2] -> Lines@2 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@2, Line_limit, Break, Word_len, Word, 0, [], Lines@2 ); [{<<" "/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{1680}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2000}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2001}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2002}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2003}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2004}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2005}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2006}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2008}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{2009}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{200a}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{205f}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<"\x{3000}"/utf8>>, New_break} | Chars@3] when (Line_len + Word_len) < Line_limit -> {Line@3, Line_len@1} = case Line of [] -> {Word, Word_len}; _ -> {lists:reverse([Break | lists:reverse(Word)], Line), (Line_len + Word_len) + 1} end, do_wrap_prefer_words( Chars@3, Line_limit, New_break, 0, [], Line_len@1, Line@3, Lines ); [{<<" "/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{1680}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2000}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2001}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2002}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2003}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2004}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2005}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2006}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2008}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{2009}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{200a}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{205f}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{<<"\x{3000}"/utf8>>, Break@1} | Chars@4] -> Lines@3 = [lists:reverse(Line) | Lines], do_wrap_prefer_words( Chars@4, Line_limit, Break@1, 0, [], Word_len, Word, Lines@3 ); [{_, Bits} | Chars@5] when Word_len < Line_limit -> do_wrap_prefer_words( Chars@5, Line_limit, Break, Word_len + 1, [Bits | Word], Line_len, Line, Lines ); [{_, Bits@1} | Chars@6] -> Lines@4 = case Line of [] -> [lists:reverse(Word) | Lines]; _ -> [lists:reverse(Word), lists:reverse(Line) | Lines] end, do_wrap_prefer_words( Chars@6, Line_limit, Break, 1, [Bits@1], 0, [], Lines@4 ) end. -file("src/starprnt.gleam", 353). -spec do_wrap_prefer_words_unbroken( list({binary(), bitstring()}), integer(), integer(), list(bitstring()), list(list(bitstring())) ) -> list(list(bitstring())). do_wrap_prefer_words_unbroken(Chars, Line_limit, Line_len, Line, Lines) -> case Chars of [] -> lists:reverse([lists:reverse(Line) | Lines]); [{<<"\n"/utf8>>, _} | Chars@1] -> Lines@1 = [lists:reverse(Line) | Lines], do_wrap_prefer_words_unbroken(Chars@1, Line_limit, 0, [], Lines@1); [{<<" "/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{1680}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2000}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2001}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2002}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2003}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2004}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2005}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2006}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2008}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{2009}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{200a}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{205f}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{<<"\x{3000}"/utf8>>, Break} | Chars@2] -> do_wrap_prefer_words( Chars@2, Line_limit, Break, 0, [], Line_len, Line, Lines ); [{_, Bits} | Chars@3] when Line_len < Line_limit -> do_wrap_prefer_words_unbroken( Chars@3, Line_limit, Line_len + 1, [Bits | Line], Lines ); [{_, Bits@1} | Chars@4] -> Lines@2 = [lists:reverse(Line) | Lines], do_wrap_prefer_words_unbroken( Chars@4, Line_limit, 1, [Bits@1], Lines@2 ) end. -file("src/starprnt.gleam", 136). -spec layout_chars(list({binary(), bitstring()}), wrap(), integer()) -> list(list(bitstring())). layout_chars(Chars, Wrap, Line_limit) -> case Wrap of no_wrap -> do_no_wrap(Chars, Line_limit, 0, [], []); wrap_anywhere -> do_wrap_anywhere(Chars, Line_limit, 0, [], []); wrap_only_words -> do_wrap_only_words_unbroken(Chars, Line_limit, 0, [], []); wrap_prefer_words -> do_wrap_prefer_words_unbroken(Chars, Line_limit, 0, [], []) end. -file("src/starprnt.gleam", 626). -spec do_scale_bits(bitstring(), integer(), bitstring()) -> bitstring(). do_scale_bits(Bits, Scale, Acc) -> case Bits of <<0:1, Bits@1/bitstring>> -> do_scale_bits( Bits@1, Scale, <> ); <<1:1, Bits@2/bitstring>> -> do_scale_bits( Bits@2, Scale, <> ); _ -> Acc end. -file("src/starprnt.gleam", 618). -spec scale_bits(bitstring(), integer()) -> bitstring(). scale_bits(Bits, Scale) -> case Scale of 0 -> <<>>; 1 -> Bits; -1 -> Bits; _ -> do_scale_bits(Bits, gleam@int:absolute_value(Scale), <<>>) end. -file("src/starprnt.gleam", 644). -spec do_repeat_bits(bitstring(), integer(), bitstring()) -> bitstring(). do_repeat_bits(Bits, Times, Acc) -> case Times of 0 -> Acc; _ -> do_repeat_bits(Bits, Times - 1, <>) end. -file("src/starprnt.gleam", 636). -spec repeat_bits(bitstring(), integer()) -> bitstring(). repeat_bits(Bits, Times) -> case Times of 0 -> <<>>; 1 -> Bits; -1 -> Bits; _ -> do_repeat_bits(Bits, gleam@int:absolute_value(Times) - 1, Bits) end. -file("src/starprnt.gleam", 567). -spec do_render_char_line( list(bitstring()), integer(), integer(), integer(), bitstring(), list(bitstring()) ) -> {bitstring(), list(bitstring())}. do_render_char_line(Chars, Padding, Width, Scale, Acc, Leftover_chars) -> case Chars of [] -> {begin _pipe = case Acc of <> -> <<"b"/utf8, 72, 0, Line_data/bitstring>>; _ -> Line_data@1 = gleam_stdlib:bit_array_pad_to_bytes( Acc ), <<"b"/utf8, (erlang:byte_size(Line_data@1)), 0, Line_data@1/bitstring>> end, repeat_bits(_pipe, Scale) end, lists:reverse(Leftover_chars)}; [Char | Chars@1] -> case Char of <> -> do_render_char_line( Chars@1, Padding, Width, Scale, <>, [Leftover_char | Leftover_chars] ); _ -> do_render_char_line( Chars@1, Padding, Width, Scale, <>, [Char | Leftover_chars] ) end end. -file("src/starprnt.gleam", 535). -spec do_render_lines( list(list(bitstring())), integer(), integer(), integer(), integer(), integer(), bitstring() ) -> bitstring(). do_render_lines(Lines, Padding, Width, Height, Rem_height, Scale, Acc) -> case Lines of [] -> Acc; [Chars | Lines@1] -> case Rem_height of 0 -> do_render_lines( Lines@1, Padding, Width, Height, Height, Scale, Acc ); _ -> {Line_data, Chars@1} = do_render_char_line( Chars, Padding, Width, Scale, <<>>, [] ), Acc@1 = <>, do_render_lines( [Chars@1 | Lines@1], Padding, Width, Height, Rem_height - 1, Scale, Acc@1 ) end end. -file("src/starprnt.gleam", 55). -spec render_text(binary(), starprnt@font:font(), integer(), wrap(), boolean()) -> bitstring(). render_text(Text, Font, Scale, Wrap, Cut) -> gleam@bool:guard( Scale =:= 0, <<>>, fun() -> {font, Width, Height, Default_glyph, Render_glyph} = Font, Line_limit = case (Width * gleam@int:absolute_value(Scale)) of 0 -> 0; Gleam@denominator -> 8 * 72 div Gleam@denominator end, Padding = case Width rem 8 of 0 -> 0; Rem -> 8 - Rem end, Start_bits = case Cut of true -> <<(<<(<<(16#1b), "*r"/utf8>>)/bitstring, "A"/utf8>>)/bitstring, (<<(<<(16#1b), "*r"/utf8>>)/bitstring, "P0"/utf8, 0>>)/bitstring>>; false -> <<(<<(<<(<<(16#1b), "*r"/utf8>>)/bitstring, "A"/utf8>>)/bitstring, (<<(<<(16#1b), "*r"/utf8>>)/bitstring, "P0"/utf8, 0>>)/bitstring>>)/bitstring, (<<(<<(16#1b), "*r"/utf8>>)/bitstring, "E1"/utf8, 0>>)/bitstring>> end, _pipe = gleam@string:to_graphemes(Text), _pipe@1 = do_process_graphemes( _pipe, Default_glyph, Render_glyph, [] ), _pipe@2 = layout_chars(_pipe@1, Wrap, Line_limit), _pipe@3 = do_render_lines( _pipe@2, Padding, Width, Height, Height, Scale, Start_bits ), gleam@bit_array:append( _pipe@3, <<(<<(16#1b), "*r"/utf8>>)/bitstring, "B"/utf8>> ) end ).