mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 15:01:01 +01:00
[raster] Simplify SVG render cleanup
Simplify hb_raster_svg_render() to use one cleanup path and keep the blob lifetime handling in one place. While doing that, drop dead checks that only depended on hb_blob_reference() returning nullptr or hb_blob_get_data() returning nullptr for non-empty blobs. Testing: - meson test -C build Assisted-by: OpenAI Codex
This commit is contained in:
1 parent
329c733e14
commit
fc5bc355d3
1 file changed
+46
-57
+46
-57
@@ -546,63 +546,55 @@ hb_raster_svg_render (hb_raster_paint_t *paint,
|
||||
unsigned palette,
|
||||
hb_color_t foreground)
|
||||
{
|
||||
bool ret = false;
|
||||
hb_blob_t *render_blob = hb_blob_reference (blob);
|
||||
if (!render_blob)
|
||||
return false;
|
||||
|
||||
unsigned data_len = 0;
|
||||
const char *data = hb_blob_get_data (render_blob, &data_len);
|
||||
if (!data || !data_len)
|
||||
{
|
||||
hb_blob_destroy (render_blob);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hb_raster_svg_blob_is_gzip (data, data_len))
|
||||
{
|
||||
uint32_t expected_size = 0;
|
||||
if (hb_raster_svg_gzip_get_uncompressed_size (data, data_len, &expected_size) &&
|
||||
unlikely ((size_t) expected_size > (size_t) HB_SVG_MAX_DOCUMENT_SIZE))
|
||||
{
|
||||
hb_blob_destroy (render_blob);
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
hb_blob_t *uncompressed = hb_raster_svg_decompress_blob (render_blob);
|
||||
if (!uncompressed)
|
||||
{
|
||||
hb_blob_destroy (render_blob);
|
||||
return false;
|
||||
}
|
||||
|
||||
hb_blob_destroy (render_blob);
|
||||
render_blob = uncompressed;
|
||||
data = hb_blob_get_data (render_blob, &data_len);
|
||||
if (!data || !data_len)
|
||||
{
|
||||
hb_blob_destroy (render_blob);
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
hb_blob_destroy (render_blob);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (unlikely ((size_t) data_len > (size_t) HB_SVG_MAX_DOCUMENT_SIZE))
|
||||
{
|
||||
hb_blob_destroy (render_blob);
|
||||
return false;
|
||||
}
|
||||
|
||||
hb_face_t *face HB_UNUSED = hb_font_get_face (font);
|
||||
const OT::SVG::svg_doc_cache_t *doc_cache = nullptr;
|
||||
#ifndef HB_NO_SVG
|
||||
unsigned doc_index = 0;
|
||||
hb_codepoint_t start_glyph = HB_CODEPOINT_INVALID;
|
||||
hb_codepoint_t end_glyph = HB_CODEPOINT_INVALID;
|
||||
#endif
|
||||
hb_paint_funcs_t *pfuncs = hb_raster_paint_get_funcs ();
|
||||
hb_svg_render_context_t ctx;
|
||||
hb_svg_cascade_t initial_state;
|
||||
hb_svg_defs_scan_context_t scan_ctx;
|
||||
bool found_glyph = false;
|
||||
#ifndef HB_NO_SVG
|
||||
unsigned glyph_start = 0, glyph_end = 0;
|
||||
#endif
|
||||
|
||||
unsigned data_len = 0;
|
||||
const char *data = hb_blob_get_data (render_blob, &data_len);
|
||||
if (!data_len)
|
||||
goto done;
|
||||
|
||||
if (hb_raster_svg_blob_is_gzip (data, data_len))
|
||||
{
|
||||
uint32_t expected_size = 0;
|
||||
if (hb_raster_svg_gzip_get_uncompressed_size (data, data_len, &expected_size) &&
|
||||
unlikely ((size_t) expected_size > (size_t) HB_SVG_MAX_DOCUMENT_SIZE))
|
||||
goto done;
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
hb_blob_t *uncompressed = hb_raster_svg_decompress_blob (render_blob);
|
||||
if (!uncompressed)
|
||||
goto done;
|
||||
|
||||
hb_blob_destroy (render_blob);
|
||||
render_blob = uncompressed;
|
||||
data = hb_blob_get_data (render_blob, &data_len);
|
||||
if (!data_len)
|
||||
goto done;
|
||||
#else
|
||||
goto done;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (unlikely ((size_t) data_len > (size_t) HB_SVG_MAX_DOCUMENT_SIZE))
|
||||
goto done;
|
||||
|
||||
#ifndef HB_NO_SVG
|
||||
if (face &&
|
||||
hb_ot_color_glyph_get_svg_document_index (face, glyph, &doc_index) &&
|
||||
hb_ot_color_get_svg_document_glyph_range (face, doc_index, &start_glyph, &end_glyph))
|
||||
@@ -613,9 +605,6 @@ hb_raster_svg_render (hb_raster_paint_t *paint,
|
||||
data = face->table.SVG->doc_cache_get_svg (doc_cache, &data_len);
|
||||
#endif
|
||||
|
||||
hb_paint_funcs_t *pfuncs = hb_raster_paint_get_funcs ();
|
||||
|
||||
hb_svg_render_context_t ctx;
|
||||
ctx.paint = paint;
|
||||
ctx.pfuncs = pfuncs;
|
||||
ctx.font = font;
|
||||
@@ -628,10 +617,9 @@ hb_raster_svg_render (hb_raster_paint_t *paint,
|
||||
#endif
|
||||
ctx.doc_cache = doc_cache;
|
||||
|
||||
hb_svg_cascade_t initial_state;
|
||||
initial_state.color = foreground;
|
||||
|
||||
hb_svg_defs_scan_context_t scan_ctx = {
|
||||
scan_ctx = {
|
||||
&ctx.defs, ctx.pfuncs, ctx.paint,
|
||||
ctx.foreground, hb_font_get_face (ctx.font),
|
||||
ctx.palette,
|
||||
@@ -640,9 +628,7 @@ hb_raster_svg_render (hb_raster_paint_t *paint,
|
||||
};
|
||||
hb_raster_svg_collect_defs (&scan_ctx, data, data_len);
|
||||
|
||||
bool found_glyph = false;
|
||||
#ifndef HB_NO_SVG
|
||||
unsigned glyph_start = 0, glyph_end = 0;
|
||||
if (doc_cache && face->table.SVG->doc_cache_get_glyph_span (doc_cache, glyph, &glyph_start, &glyph_end))
|
||||
{
|
||||
hb_svg_xml_parser_t parser (data + glyph_start, glyph_end - glyph_start);
|
||||
@@ -692,8 +678,11 @@ hb_raster_svg_render (hb_raster_paint_t *paint,
|
||||
}
|
||||
}
|
||||
|
||||
ret = found_glyph;
|
||||
|
||||
done:
|
||||
hb_blob_destroy (render_blob);
|
||||
return found_glyph;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* !HB_NO_RASTER_SVG */
|
||||
Reference in new issue
Block a user