[vector] Drop hb_vector_{draw,paint}_{set,get}_flat (#5927)

Flat mode disabled glyph reuse / caching to produce inline-
everything SVG output.  Its main use case was making
hb-vector SVGs safe to concatenate side-by-side in a single
document, but the recently-added svg_set_prefix API solves
that without giving up the cache.  No remaining callers in
tree (util/vector-output.hh's --flat option goes too).

Removes:
  - hb_vector_draw_set_flat / get_flat
  - hb_vector_paint_set_flat / get_flat
  - the `flat` field on both contexts
  - all `if (flat)` / `bool can_cache = !flat` branches
  - the --flat option in util/vector-output.hh
  - the four "flat*" expected files in test/vector/basic
  - the flat_draw / flat_paint params in the vector fuzzer
  - sections-list entries

meson test --no-rebuild green (241/241).

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Opus 4.6 authored and GitHub committed 2026-04-15 15:03:43 -06:00
1 parent ec63b7d921
commit ca75fd5ff9
13 files changed
+5 -163

No files matched your search

-4
View File
@@ -1086,8 +1086,6 @@ hb_vector_draw_get_extents
hb_vector_draw_set_glyph_extents
hb_vector_draw_get_funcs
hb_vector_draw_glyph
hb_vector_draw_set_flat
hb_vector_draw_get_flat
hb_vector_draw_set_precision
hb_vector_draw_get_precision
hb_vector_draw_svg_set_prefix
@@ -1117,8 +1115,6 @@ hb_vector_paint_set_custom_palette_color
hb_vector_paint_clear_custom_palette_colors
hb_vector_paint_get_funcs
hb_vector_paint_glyph
hb_vector_paint_set_flat
hb_vector_paint_get_flat
hb_vector_paint_set_precision
hb_vector_paint_get_precision
hb_vector_paint_svg_set_prefix
+2 -65
View File
@@ -591,8 +591,7 @@ hb_vector_draw_glyph (hb_vector_draw_t *draw,
case HB_VECTOR_FORMAT_SVG:
{
bool needs_def = !draw->flat && !hb_set_has (draw->defined_glyphs, glyph);
if (needs_def)
if (!hb_set_has (draw->defined_glyphs, glyph))
{
draw->path.clear ();
hb_vector_svg_path_sink_t sink = {&draw->path, draw->precision};
@@ -609,34 +608,6 @@ hb_vector_draw_glyph (hb_vector_draw_t *draw,
hb_set_add (draw->defined_glyphs, glyph);
}
if (draw->flat)
{
draw->path.clear ();
hb_vector_svg_path_sink_t sink = {&draw->path, draw->precision};
hb_font_draw_glyph (font, glyph, hb_vector_svg_path_draw_funcs_get (), &sink);
if (!draw->path.length)
return false;
float xx = draw->transform.xx;
float yx = draw->transform.yx;
float xy = draw->transform.xy;
float yy = draw->transform.yy;
float tx = draw->transform.x0 + xx * pen_x + xy * pen_y;
float ty = draw->transform.y0 + yx * pen_x + yy * pen_y;
hb_buf_append_str (&draw->body, "<path d=\"");
hb_buf_append_len (&draw->body, draw->path.arrayZ, draw->path.length);
hb_buf_append_str (&draw->body, "\" transform=\"");
hb_vector_svg_append_instance_transform (&draw->body,
draw->precision,
draw->x_scale_factor,
draw->y_scale_factor,
xx, yx, xy, yy, tx, ty);
hb_buf_append_str (&draw->body, "\"/>\n");
return true;
}
float xx = draw->transform.xx;
float yx = draw->transform.yx;
float xy = draw->transform.xy;
@@ -663,39 +634,6 @@ hb_vector_draw_glyph (hb_vector_draw_t *draw,
}
}
/**
* hb_vector_draw_set_flat:
* @draw: a draw context.
* @flat: whether to flatten geometry and disable reuse.
*
* Enables or disables draw flattening.
*
* XSince: REPLACEME
*/
void
hb_vector_draw_set_flat (hb_vector_draw_t *draw,
hb_bool_t flat)
{
draw->flat = !!flat;
}
/**
* hb_vector_draw_get_flat:
* @draw: a draw context.
*
* Returns the flatten flag previously set on @draw, or `false` if
* none was set.
*
* Return value: the flatten flag.
*
* XSince: REPLACEME
*/
hb_bool_t
hb_vector_draw_get_flat (const hb_vector_draw_t *draw)
{
return draw->flat;
}
/**
* hb_vector_draw_svg_set_prefix:
* @draw: a draw context.
@@ -946,7 +884,7 @@ hb_vector_draw_render (hb_vector_draw_t *draw)
*
* Discards accumulated draw output so @draw can be reused for
* another render. User configuration (transform, scale factors,
* precision, flat) is preserved. Call hb_vector_draw_reset() to
* precision) is preserved. Call hb_vector_draw_reset() to
* also reset user configuration to defaults.
*
* XSince: REPLACEME
@@ -977,7 +915,6 @@ hb_vector_draw_reset (hb_vector_draw_t *draw)
draw->x_scale_factor = 1.f;
draw->y_scale_factor = 1.f;
draw->precision = 2;
draw->flat = false;
hb_vector_draw_clear (draw);
}
-1
View File
@@ -20,7 +20,6 @@ struct hb_vector_draw_t
hb_vector_extents_t extents = {0, 0, 0, 0};
bool has_extents = false;
unsigned precision = 2;
bool flat = false;
hb_vector_t<char> id_prefix;
hb_vector_t<char> defs;
+1 -38
View File
@@ -1361,11 +1361,9 @@ hb_vector_paint_glyph (hb_vector_paint_t *paint,
case HB_VECTOR_FORMAT_SVG:
{
bool can_cache = !paint->flat;
hb_vector_color_glyph_cache_key_t cache_key = hb_vector_color_glyph_cache_key (glyph,
(unsigned) paint->palette,
paint->foreground);
if (can_cache)
{
if (paint->defined_color_glyphs.has (cache_key))
{
@@ -1385,7 +1383,6 @@ hb_vector_paint_glyph (hb_vector_paint_t *paint,
}
}
if (can_cache)
{
if (unlikely (!paint->group_stack.push_or_fail (hb_vector_t<char> {})))
return false;
@@ -1454,39 +1451,6 @@ hb_vector_paint_glyph (hb_vector_paint_t *paint,
}
}
/**
* hb_vector_paint_set_flat:
* @paint: a paint context.
* @flat: whether to flatten paint output and disable glyph-group reuse.
*
* Enables or disables paint flattening.
*
* XSince: REPLACEME
*/
void
hb_vector_paint_set_flat (hb_vector_paint_t *paint,
hb_bool_t flat)
{
paint->flat = !!flat;
}
/**
* hb_vector_paint_get_flat:
* @paint: a paint context.
*
* Returns the flatten flag previously set on @paint, or `false` if
* none was set.
*
* Return value: the flatten flag.
*
* XSince: REPLACEME
*/
hb_bool_t
hb_vector_paint_get_flat (const hb_vector_paint_t *paint)
{
return paint->flat;
}
/**
* hb_vector_paint_svg_set_prefix:
* @paint: a paint context.
@@ -1575,7 +1539,7 @@ hb_vector_paint_get_precision (const hb_vector_paint_t *paint)
*
* Discards accumulated paint output so @paint can be reused for
* another render. User configuration (transform, scale factors,
* precision, flat, foreground, palette, custom palette colors)
* precision, foreground, palette, custom palette colors)
* is preserved. Call hb_vector_paint_reset() to also reset
* user configuration to defaults.
*
@@ -1699,7 +1663,6 @@ hb_vector_paint_reset (hb_vector_paint_t *paint)
paint->foreground = HB_COLOR (0, 0, 0, 255);
paint->palette = 0;
paint->precision = 2;
paint->flat = false;
hb_vector_paint_clear (paint);
}
-1
View File
@@ -51,7 +51,6 @@ struct hb_vector_paint_t
int palette = 0;
hb_hashmap_t<unsigned, hb_color_t> custom_palette_colors;
unsigned precision = 2;
bool flat = false;
hb_vector_t<char> id_prefix;
hb_vector_t<char> defs;
-14
View File
@@ -162,13 +162,6 @@ hb_vector_draw_glyph (hb_vector_draw_t *draw,
float pen_y,
hb_vector_extents_mode_t extents_mode);
HB_EXTERN void
hb_vector_draw_set_flat (hb_vector_draw_t *draw,
hb_bool_t flat);
HB_EXTERN hb_bool_t
hb_vector_draw_get_flat (const hb_vector_draw_t *draw);
HB_EXTERN void
hb_vector_draw_set_precision (hb_vector_draw_t *draw,
unsigned precision);
@@ -286,13 +279,6 @@ hb_vector_paint_glyph (hb_vector_paint_t *paint,
float pen_y,
hb_vector_extents_mode_t extents_mode);
HB_EXTERN void
hb_vector_paint_set_flat (hb_vector_paint_t *paint,
hb_bool_t flat);
HB_EXTERN hb_bool_t
hb_vector_paint_get_flat (const hb_vector_paint_t *paint);
HB_EXTERN void
hb_vector_paint_set_precision (hb_vector_paint_t *paint,
unsigned precision);
+2 -8
View File
@@ -6,8 +6,6 @@ static void
exercise_format (const _fuzzing_shape_input_t *input,
hb_vector_format_t format,
unsigned precision,
bool flat_draw,
bool flat_paint,
volatile unsigned *counter)
{
hb_vector_draw_t *draw = hb_vector_draw_create_or_fail (format);
@@ -22,8 +20,6 @@ exercise_format (const _fuzzing_shape_input_t *input,
hb_vector_draw_set_precision (draw, precision);
hb_vector_paint_set_precision (paint, precision);
hb_vector_draw_set_flat (draw, flat_draw);
hb_vector_paint_set_flat (paint, flat_paint);
unsigned glyph_count = hb_face_get_glyph_count (input->face);
unsigned limit = glyph_count > 16 ? 16 : glyph_count;
@@ -71,8 +67,6 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
return 0;
unsigned precision = size ? data[size - 1] % 5 : 0;
bool flat_draw = size > 1 && (data[size - 2] & 1);
bool flat_paint = size > 2 && (data[size - 3] & 1);
unsigned glyph_count = hb_face_get_glyph_count (input.face);
volatile unsigned counter = !glyph_count;
@@ -80,8 +74,8 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
/* Exercise both output formats. Each has its own serializer, path
* encoder, gradient machinery, and (for PDF) indexed-PNG SMask +
* Type 6 Coons-patch encoder. */
exercise_format (&input, HB_VECTOR_FORMAT_SVG, precision, flat_draw, flat_paint, &counter);
exercise_format (&input, HB_VECTOR_FORMAT_PDF, precision, flat_draw, flat_paint, &counter);
exercise_format (&input, HB_VECTOR_FORMAT_SVG, precision, &counter);
exercise_format (&input, HB_VECTOR_FORMAT_PDF, precision, &counter);
return counter ? 0 : 0;
}
@@ -1,6 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-16 -1000 1545 1289" width="1545" height="1289">
<path d="M194,-12C255,-12 309,20 355,58L358,58L365,0L433,0L433,298C433,419 383,498 264,498C186,498 118,464 73,435L105,378C143,404 194,430 250,430C330,430 350,370 350,308C143,285 52,232 52,126C52,39 113,-12 194,-12ZM218,54C170,54 132,77 132,132C132,194 188,234 350,254L350,119C303,77 265,54 218,54Z" transform="translate(0,0) scale(1,-1)"/>
<path d="M297,-12C408,-12 507,85 507,251C507,401 440,498 314,498C260,498 206,469 162,430L164,518L164,712L82,712L82,0L148,0L155,50L158,50C201,11 252,-12 297,-12ZM283,57C251,57 207,71 164,108L164,363C210,406 253,429 294,429C386,429 422,357 422,250C422,130 363,57 283,57Z" transform="translate(504,0) scale(1,-1)"/>
<path d="M274,-12C332,-12 387,11 431,50L395,105C365,78 326,56 281,56C192,56 131,131 131,242C131,354 195,430 283,430C322,430 352,412 380,387L422,441C388,472 344,498 280,498C155,498 46,405 46,242C46,81 145,-12 274,-12Z" transform="translate(1057,0) scale(1,-1)"/>
</svg>

Before

Width:  |  Height:  |  Size: 1021 B

@@ -1,6 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-16 -1916 3367 2432" width="3367" height="2432">
<path d="M808,0Q792,32 782,114Q653,-20 474,-20Q314,-20 212,70Q109,161 109,300Q109,469 238,562Q366,656 599,656L779,656L779,741Q779,838 721,896Q663,953 550,953Q451,953 384,903Q317,853 317,782L131,782Q131,863 188,938Q246,1014 344,1058Q443,1102 561,1102Q748,1102 854,1008Q960,915 964,751L964,253Q964,104 1002,16L1002,0L808,0ZM501,141Q588,141 666,186Q744,231 779,303L779,525L634,525Q294,525 294,326Q294,239 352,190Q410,141 501,141Z" transform="translate(0,0) scale(1,-1)"/>
<path d="M1056,529Q1056,281 942,130Q828,-20 636,-20Q431,-20 319,125L310,0L140,0L140,1536L325,1536L325,963Q437,1102 634,1102Q831,1102 944,953Q1056,804 1056,545L1056,529ZM871,550Q871,739 798,842Q725,945 588,945Q405,945 325,775L325,307Q410,137 590,137Q723,137 797,240Q871,343 871,550Z" transform="translate(1114,0) scale(1,-1)"/>
<path d="M574,131Q673,131 747,191Q821,251 829,341L1004,341Q999,248 940,164Q881,80 782,30Q684,-20 574,-20Q353,-20 222,128Q92,275 92,531L92,562Q92,720 150,843Q208,966 316,1034Q425,1102 573,1102Q755,1102 876,993Q996,884 1004,710L829,710Q821,815 750,882Q678,950 573,950Q432,950 354,848Q277,747 277,555L277,520Q277,333 354,232Q431,131 574,131Z" transform="translate(2263,0) scale(1,-1)"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

@@ -1,6 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-16 -1916 3367 2432" width="3367" height="2432">
<path d="M808,0Q792,32 782,114Q653,-20 474,-20Q314,-20 211.5,70.5Q109,161 109,300Q109,469 237.5,562.5Q366,656 599,656L779,656L779,741Q779,838 721,895.5Q663,953 550,953Q451,953 384,903Q317,853 317,782L131,782Q131,863 188.5,938.5Q246,1014 344.5,1058Q443,1102 561,1102Q748,1102 854,1008.5Q960,915 964,751L964,253Q964,104 1002,16L1002,0L808,0ZM501,141Q588,141 666,186Q744,231 779,303L779,525L634,525Q294,525 294,326Q294,239 352,190Q410,141 501,141Z" transform="translate(0,0) scale(1,-1)"/>
<path d="M1056,529Q1056,281 942,130.5Q828,-20 636,-20Q431,-20 319,125L310,0L140,0L140,1536L325,1536L325,963Q437,1102 634,1102Q831,1102 943.5,953Q1056,804 1056,545L1056,529ZM871,550Q871,739 798,842Q725,945 588,945Q405,945 325,775L325,307Q410,137 590,137Q723,137 797,240Q871,343 871,550Z" transform="translate(1114,0) scale(1,-1)"/>
<path d="M574,131Q673,131 747,191Q821,251 829,341L1004,341Q999,248 940,164Q881,80 782.5,30Q684,-20 574,-20Q353,-20 222.5,127.5Q92,275 92,531L92,562Q92,720 150,843Q208,966 316.5,1034Q425,1102 573,1102Q755,1102 875.5,993Q996,884 1004,710L829,710Q821,815 749.5,882.5Q678,950 573,950Q432,950 354.5,848.5Q277,747 277,555L277,520Q277,333 354,232Q431,131 574,131Z" transform="translate(2263,0) scale(1,-1)"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

-6
View File
@@ -1,6 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-16 -1916 3367 2432" width="3367" height="2432">
<path d="M808,0Q792,32 782,114Q653,-20 474,-20Q314,-20 211.5,70.5Q109,161 109,300Q109,469 237.5,562.5Q366,656 599,656L779,656L779,741Q779,838 721,895.5Q663,953 550,953Q451,953 384,903Q317,853 317,782L131,782Q131,863 188.5,938.5Q246,1014 344.5,1058Q443,1102 561,1102Q748,1102 854,1008.5Q960,915 964,751L964,253Q964,104 1002,16L1002,0L808,0ZM501,141Q588,141 666,186Q744,231 779,303L779,525L634,525Q294,525 294,326Q294,239 352,190Q410,141 501,141Z" transform="translate(0,0) scale(1,-1)"/>
<path d="M1056,529Q1056,281 942,130.5Q828,-20 636,-20Q431,-20 319,125L310,0L140,0L140,1536L325,1536L325,963Q437,1102 634,1102Q831,1102 943.5,953Q1056,804 1056,545L1056,529ZM871,550Q871,739 798,842Q725,945 588,945Q405,945 325,775L325,307Q410,137 590,137Q723,137 797,240Q871,343 871,550Z" transform="translate(1114,0) scale(1,-1)"/>
<path d="M574,131Q673,131 747,191Q821,251 829,341L1004,341Q999,248 940,164Q881,80 782.5,30Q684,-20 574,-20Q353,-20 222.5,127.5Q92,275 92,531L92,562Q92,720 150,843Q208,966 316.5,1034Q425,1102 573,1102Q755,1102 875.5,993Q996,884 1004,710L829,710Q821,815 749.5,882.5Q678,950 573,950Q432,950 354.5,848.5Q277,747 277,555L277,520Q277,333 354,232Q431,131 574,131Z" transform="translate(2263,0) scale(1,-1)"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

-4
View File
@@ -1,13 +1,9 @@
# font-file;options;unicodes;expected-file
../../../api/fonts/Roboto-Regular.abc.ttf;;U+0061,U+0062,U+0063;../expected/basic/default.svg
../../../api/fonts/Roboto-Regular.abc.ttf;--flat;U+0061,U+0062,U+0063;../expected/basic/flat.svg
../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=upem;U+0061,U+0062,U+0063;../expected/basic/upem-default.svg
../../../api/fonts/Roboto-Regular.abc.ttf;--direction=ttb;U+0061,U+0062,U+0063;../expected/basic/ttb.svg
../../../api/fonts/Roboto-Regular.abc.ttf;;U+0061,U+000A,U+0062,U+0063;../expected/basic/multiline.svg
../../../api/fonts/Roboto-Regular.abc.ttf;--flat --precision=0;U+0061,U+0062,U+0063;../expected/basic/flat-precision-0.svg
../../../api/fonts/Roboto-Regular.abc.ttf;--flat --precision=4;U+0061,U+0062,U+0063;../expected/basic/flat-precision-4.svg
../../../api/fonts/SourceSansPro-Regular.abc.otf;;U+0061,U+0062,U+0063;../expected/basic/cff1.svg
../../../api/fonts/SourceSansPro-Regular.abc.otf;--flat;U+0061,U+0062,U+0063;../expected/basic/flat-cff1.svg
../../../api/fonts/Roboto-Variable.abc.ttf;--variations=wght=900;U+0061,U+0062,U+0063;../expected/basic/glyf-var-wght900.svg
../../../api/fonts/TestCFF2VF.otf;--variations=wght=900;U+0061,U+0062,U+0063;../expected/basic/cff2-var-wght900.svg
../../../api/fonts/AdobeVFPrototype.abc.otf;--variations=wght=900,CNTR=100;U+0061,U+0062,U+0063;../expected/basic/cff2-var-cntr.svg
-4
View File
@@ -62,7 +62,6 @@ struct vector_output_t : output_options_t<>, view_options_t
GOptionEntry entries[] =
{
{"flat", 0, 0, G_OPTION_ARG_NONE, &this->flat, "Flatten geometry and disable reuse", nullptr},
{"precision", 0, 0, G_OPTION_ARG_INT, &this->precision, "Decimal precision (default: 2)", "N"},
{nullptr}
};
@@ -207,7 +206,6 @@ struct vector_output_t : output_options_t<>, view_options_t
hb_vector_draw_set_scale_factor (draw, 1.f, 1.f);
hb_vector_draw_set_extents (draw, &extents);
hb_vector_draw_set_precision (draw, precision);
hb_vector_draw_set_flat (draw, flat);
if (paint)
{
@@ -218,7 +216,6 @@ struct vector_output_t : output_options_t<>, view_options_t
apply_custom_palette (paint);
init_palette_color_cache ();
hb_vector_paint_set_precision (paint, precision);
hb_vector_paint_set_flat (paint, flat);
}
bool had_draw = false;
@@ -1076,7 +1073,6 @@ struct vector_output_t : output_options_t<>, view_options_t
if (gap) *gap = (float) fext.line_gap;
}
hb_bool_t flat = false;
int precision = 2;
hb_color_t background = HB_COLOR (255, 255, 255, 255);
hb_color_t foreground = HB_COLOR (0, 0, 0, 255);