Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved text API #77

Open
bvisness opened this issue Sep 24, 2024 · 1 comment
Open

Improved text API #77

bvisness opened this issue Sep 24, 2024 · 1 comment
Assignees

Comments

@bvisness
Copy link
Collaborator

bvisness commented Sep 24, 2024

At our last meeting @martinfouilleul expressed a desire to rework the text API. Specifically:

  • Lazily loading unicode ranges
  • Basic glyph shaping
  • Better ways to lay out and measure text (currently you can only draw lines, no layout / segmentation / wrapping)
@bvisness bvisness converted this from a draft issue Sep 24, 2024
@martinfouilleul
Copy link
Collaborator

I integrated harfbuzz into orca to handle glyph shaping (see #81). This allows shaping unicode strings to glyph runs that can then be used for measuring and rendering text.

Now glyph runs only handle a single script / language / direction and don't have styling (beyond the font with which they were shaped, obviously). This is enough for the simplest use cases, but even UI labels might have two scripts, so we need an API to shape a line of text that can be composed of several styles and scripts (note: it might be tempting to keep style separate from the shaping and layout of a line, but style changes sometimes must split text into separate runs, e.g. to avoid having a style change in the middle of a ligature).

Here's the kind of API I'm going to try next:

typedef struct oc_text_attributes
{
	oc_font font;
	f32 fontSize;
	oc_color color;
	oc_color bgColor;
	//...
} oc_text_attributes;

// make text line from (possibly) multilingual text (but with a single style). Later we can have an API to construct multi-style text.
oc_text_line* oc_text_line_from_utf8(oc_arena* arena, oc_str8 string, oc_text_attributes* attributes);
oc_text_line* oc_text_line_from_utf32(oc_arena* arena, oc_str32 string, oc_text_attributes* attributes);

oc_text_metrics oc_text_line_get_metrics(oc_text_line* line);
u64 oc_text_line_codepoint_index_for_position(oc_text_line* line, oc_vec2 position);
oc_vec2 oc_text_line_position_for_codepoint_index(oc_text_line* line, u64 index);
												  
void oc_text_line_draw(oc_text_line* line);
//...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

No branches or pull requests

2 participants