-
Notifications
You must be signed in to change notification settings - Fork 2
fix(svg): split text fallback for symbols and render color emoji glyphs #319
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
base: spx4.4.1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,11 +256,15 @@ static glyph_t* plutovg_font_face_get_glyph(plutovg_font_face_t* face, plutovg_c | |
| unsigned int msb = (codepoint >> 8) & 0xFF; | ||
| if(face->glyphs[msb] == NULL) { | ||
| face->glyphs[msb] = calloc(GLYPH_CACHE_SIZE, sizeof(glyph_t*)); | ||
| if(face->glyphs[msb] == NULL) | ||
| return NULL; | ||
| } | ||
|
|
||
| unsigned int lsb = codepoint & 0xFF; | ||
| if(face->glyphs[msb][lsb] == NULL) { | ||
| glyph_t* glyph = malloc(sizeof(glyph_t)); | ||
| if(glyph == NULL) | ||
| return NULL; | ||
| glyph->index = stbtt_FindGlyphIndex(&face->info, codepoint); | ||
| glyph->nvertices = stbtt_GetGlyphShape(&face->info, glyph->index, &glyph->vertices); | ||
| stbtt_GetGlyphHMetrics(&face->info, glyph->index, &glyph->advance_width, &glyph->left_side_bearing); | ||
|
|
@@ -276,6 +280,13 @@ void plutovg_font_face_get_glyph_metrics(plutovg_font_face_t* face, float size, | |
| { | ||
| float scale = plutovg_font_face_get_scale(face, size); | ||
| glyph_t* glyph = plutovg_font_face_get_glyph(face, codepoint); | ||
| if(glyph == NULL) { | ||
| if(advance_width) *advance_width = 0.f; | ||
| if(left_side_bearing) *left_side_bearing = 0.f; | ||
| if(extents) | ||
| extents->x = extents->y = extents->w = extents->h = 0.f; | ||
| return; | ||
| } | ||
| if(advance_width) *advance_width = glyph->advance_width * scale; | ||
| if(left_side_bearing) *left_side_bearing = glyph->left_side_bearing * scale; | ||
| if(extents) { | ||
|
|
@@ -286,6 +297,18 @@ void plutovg_font_face_get_glyph_metrics(plutovg_font_face_t* face, float size, | |
| } | ||
| } | ||
|
|
||
| int plutovg_font_face_get_glyph_svg(plutovg_font_face_t* face, plutovg_codepoint_t codepoint, const char** svg) | ||
| { | ||
| if(svg) | ||
| *svg = NULL; | ||
| if(face == NULL || svg == NULL) | ||
| return 0; | ||
| glyph_t* glyph = plutovg_font_face_get_glyph(face, codepoint); | ||
| if(glyph == NULL) | ||
| return 0; | ||
| return stbtt_GetGlyphSVG(&face->info, glyph->index, svg); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Null pointer dereference: glyph_t* glyph = plutovg_font_face_get_glyph(face, codepoint);
if(glyph == NULL)
return 0;
return stbtt_GetGlyphSVG(&face->info, glyph->index, svg); |
||
| } | ||
|
Comment on lines
+300
to
+310
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If int plutovg_font_face_get_glyph_svg(plutovg_font_face_t* face, plutovg_codepoint_t codepoint, const char** svg)
{
if(svg)
*svg = NULL;
if(face == NULL || svg == NULL)
return 0;
glyph_t* glyph = plutovg_font_face_get_glyph(face, codepoint);
if(glyph == NULL)
return 0;
return stbtt_GetGlyphSVG(&face->info, glyph->index, svg);
} |
||
|
|
||
| static void glyph_traverse_func(void* closure, plutovg_path_command_t command, const plutovg_point_t* points, int npoints) | ||
| { | ||
| plutovg_path_t* path = (plutovg_path_t*)(closure); | ||
|
|
@@ -319,6 +342,8 @@ float plutovg_font_face_traverse_glyph_path(plutovg_font_face_t* face, float siz | |
| plutovg_point_t points[3]; | ||
| plutovg_point_t current_point = {0, 0}; | ||
| glyph_t* glyph = plutovg_font_face_get_glyph(face, codepoint); | ||
| if(glyph == NULL) | ||
| return 0.f; | ||
| for(int i = 0; i < glyph->nvertices; i++) { | ||
| switch(glyph->vertices[i].type) { | ||
| case STBTT_vmove: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing lifetime constraint in API doc: The
@param svgline says "owned by the font face" but the pointer is actually an interior pointer into the raw font binary (returned bystbtt_GetGlyphSVG). Callers must not free it, must not modify it, and it becomes invalid oncefaceis destroyed. The current wording does not convey the raw-interior-pointer nature. Suggested addition: