mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-26 09:21:06 +01:00
[vector] Address review feedback
- Default hb_vector_{draw,paint}_t::format to HB_VECTOR_FORMAT_INVALID
instead of HB_VECTOR_FORMAT_SVG.
- Update renamed hb_vector_{draw,paint}_set_{flat,precision} API docs
from "Since: 13.0.0" to "XSince: REPLACEME".
- Extract hb_vector_draw_render_svg() helper to match the
hb_vector_draw_render_pdf() pattern; move the misplaced
hb_vector_draw_render doc comment to the actual function and update
it to say "output blob" since the renderer is no longer SVG-only.
- Revert 14.0.0 NEWS entry edits; the API rename will be announced in
the next release entry.
- Update docs/harfbuzz-sections.txt to reflect the API renames.
- hb-vector tool: expose -O/--output-format with supported formats
"svg/pdf", validate format, update description string, and switch
PDF detection to g_ascii_strcasecmp for case-insensitive matching.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
3f6c0e48ad
commit
7b6f26e844
7 files changed
+106
-84
No files matched your search
@@ -259,10 +259,10 @@ Wednesday, March 4, 2026
|
||||
+hb_vector_paint_set_scale_factor()
|
||||
+hb_vector_paint_set_transform()
|
||||
+hb_vector_paint_set_user_data()
|
||||
+hb_vector_paint_set_flat()
|
||||
+hb_vector_paint_set_precision()
|
||||
+hb_vector_draw_set_flat()
|
||||
+hb_vector_draw_set_precision()
|
||||
+hb_vector_svg_paint_set_flat()
|
||||
+hb_vector_svg_paint_set_precision()
|
||||
+hb_vector_svg_set_flat()
|
||||
+hb_vector_svg_set_precision()
|
||||
|
||||
|
||||
Overview of changes leading to 12.3.2
|
||||
|
||||
@@ -1081,8 +1081,8 @@ hb_vector_draw_get_extents
|
||||
hb_vector_draw_set_glyph_extents
|
||||
hb_vector_draw_get_funcs
|
||||
hb_vector_draw_glyph
|
||||
hb_vector_svg_set_flat
|
||||
hb_vector_svg_set_precision
|
||||
hb_vector_draw_set_flat
|
||||
hb_vector_draw_set_precision
|
||||
hb_vector_draw_render
|
||||
hb_vector_draw_reset
|
||||
hb_vector_draw_recycle_blob
|
||||
@@ -1105,8 +1105,8 @@ 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_svg_paint_set_flat
|
||||
hb_vector_svg_paint_set_precision
|
||||
hb_vector_paint_set_flat
|
||||
hb_vector_paint_set_precision
|
||||
hb_vector_paint_render
|
||||
hb_vector_paint_reset
|
||||
hb_vector_paint_recycle_blob
|
||||
|
||||
+73
-69
@@ -670,7 +670,7 @@ hb_vector_draw_glyph (hb_vector_draw_t *draw,
|
||||
*
|
||||
* Enables or disables draw flattening.
|
||||
*
|
||||
* Since: 13.0.0
|
||||
* XSince: REPLACEME
|
||||
*/
|
||||
void
|
||||
hb_vector_draw_set_flat (hb_vector_draw_t *draw,
|
||||
@@ -686,7 +686,7 @@ hb_vector_draw_set_flat (hb_vector_draw_t *draw,
|
||||
*
|
||||
* Sets numeric output precision for draw output.
|
||||
*
|
||||
* Since: 13.0.0
|
||||
* XSince: REPLACEME
|
||||
*/
|
||||
void
|
||||
hb_vector_draw_set_precision (hb_vector_draw_t *draw,
|
||||
@@ -695,16 +695,6 @@ hb_vector_draw_set_precision (hb_vector_draw_t *draw,
|
||||
draw->precision = hb_min (precision, 12u);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_vector_draw_render:
|
||||
* @draw: a draw context.
|
||||
*
|
||||
* Renders accumulated draw content to an SVG blob.
|
||||
*
|
||||
* Return value: (transfer full) (nullable): output blob, or `NULL` if rendering cannot proceed.
|
||||
*
|
||||
* Since: 13.0.0
|
||||
*/
|
||||
static hb_blob_t *
|
||||
hb_vector_draw_render_pdf (hb_vector_draw_t *draw)
|
||||
{
|
||||
@@ -798,71 +788,85 @@ hb_vector_draw_render_pdf (hb_vector_draw_t *draw)
|
||||
return blob;
|
||||
}
|
||||
|
||||
static hb_blob_t *
|
||||
hb_vector_draw_render_svg (hb_vector_draw_t *draw)
|
||||
{
|
||||
if (!draw->has_extents)
|
||||
return nullptr;
|
||||
|
||||
hb_vector_t<char> out;
|
||||
hb_buf_recover_recycled (draw->recycled_blob, &out);
|
||||
unsigned estimated = draw->defs.length +
|
||||
(draw->body.length ? draw->body.length : draw->path.length) +
|
||||
256;
|
||||
out.alloc (estimated);
|
||||
hb_buf_append_str (&out, "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"");
|
||||
hb_buf_append_num (&out, draw->extents.x, draw->precision);
|
||||
hb_buf_append_c (&out, ' ');
|
||||
hb_buf_append_num (&out, draw->extents.y, draw->precision);
|
||||
hb_buf_append_c (&out, ' ');
|
||||
hb_buf_append_num (&out, draw->extents.width, draw->precision);
|
||||
hb_buf_append_c (&out, ' ');
|
||||
hb_buf_append_num (&out, draw->extents.height, draw->precision);
|
||||
hb_buf_append_str (&out, "\" width=\"");
|
||||
hb_buf_append_num (&out, draw->extents.width, draw->precision);
|
||||
hb_buf_append_str (&out, "\" height=\"");
|
||||
hb_buf_append_num (&out, draw->extents.height, draw->precision);
|
||||
hb_buf_append_str (&out, "\">\n");
|
||||
|
||||
if (draw->defs.length)
|
||||
{
|
||||
hb_buf_append_str (&out, "<defs>\n");
|
||||
hb_buf_append_len (&out, draw->defs.arrayZ, draw->defs.length);
|
||||
hb_buf_append_str (&out, "</defs>\n");
|
||||
}
|
||||
|
||||
if (draw->body.length)
|
||||
{
|
||||
hb_buf_append_len (&out, draw->body.arrayZ, draw->body.length);
|
||||
}
|
||||
else if (draw->path.length)
|
||||
{
|
||||
hb_buf_append_str (&out, "<path d=\"");
|
||||
hb_buf_append_len (&out, draw->path.arrayZ, draw->path.length);
|
||||
hb_buf_append_str (&out, "\"/>\n");
|
||||
}
|
||||
|
||||
hb_buf_append_str (&out, "</svg>\n");
|
||||
|
||||
hb_blob_t *blob = hb_buf_blob_from (&draw->recycled_blob, &out);
|
||||
|
||||
draw->path.clear ();
|
||||
draw->defs.clear ();
|
||||
draw->body.clear ();
|
||||
hb_set_clear (draw->defined_glyphs);
|
||||
draw->has_extents = false;
|
||||
draw->extents = {0, 0, 0, 0};
|
||||
|
||||
return blob;
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_vector_draw_render:
|
||||
* @draw: a draw context.
|
||||
*
|
||||
* Renders accumulated draw content to an output blob.
|
||||
*
|
||||
* Return value: (transfer full) (nullable): output blob, or `NULL` if rendering cannot proceed.
|
||||
*
|
||||
* Since: 13.0.0
|
||||
*/
|
||||
hb_blob_t *
|
||||
hb_vector_draw_render (hb_vector_draw_t *draw)
|
||||
{
|
||||
switch (draw->format)
|
||||
{
|
||||
case HB_VECTOR_FORMAT_SVG:
|
||||
return hb_vector_draw_render_svg (draw);
|
||||
|
||||
case HB_VECTOR_FORMAT_PDF:
|
||||
return hb_vector_draw_render_pdf (draw);
|
||||
|
||||
case HB_VECTOR_FORMAT_SVG:
|
||||
{
|
||||
if (!draw->has_extents)
|
||||
return nullptr;
|
||||
|
||||
hb_vector_t<char> out;
|
||||
hb_buf_recover_recycled (draw->recycled_blob, &out);
|
||||
unsigned estimated = draw->defs.length +
|
||||
(draw->body.length ? draw->body.length : draw->path.length) +
|
||||
256;
|
||||
out.alloc (estimated);
|
||||
hb_buf_append_str (&out, "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"");
|
||||
hb_buf_append_num (&out, draw->extents.x, draw->precision);
|
||||
hb_buf_append_c (&out, ' ');
|
||||
hb_buf_append_num (&out, draw->extents.y, draw->precision);
|
||||
hb_buf_append_c (&out, ' ');
|
||||
hb_buf_append_num (&out, draw->extents.width, draw->precision);
|
||||
hb_buf_append_c (&out, ' ');
|
||||
hb_buf_append_num (&out, draw->extents.height, draw->precision);
|
||||
hb_buf_append_str (&out, "\" width=\"");
|
||||
hb_buf_append_num (&out, draw->extents.width, draw->precision);
|
||||
hb_buf_append_str (&out, "\" height=\"");
|
||||
hb_buf_append_num (&out, draw->extents.height, draw->precision);
|
||||
hb_buf_append_str (&out, "\">\n");
|
||||
|
||||
if (draw->defs.length)
|
||||
{
|
||||
hb_buf_append_str (&out, "<defs>\n");
|
||||
hb_buf_append_len (&out, draw->defs.arrayZ, draw->defs.length);
|
||||
hb_buf_append_str (&out, "</defs>\n");
|
||||
}
|
||||
|
||||
if (draw->body.length)
|
||||
{
|
||||
hb_buf_append_len (&out, draw->body.arrayZ, draw->body.length);
|
||||
}
|
||||
else if (draw->path.length)
|
||||
{
|
||||
hb_buf_append_str (&out, "<path d=\"");
|
||||
hb_buf_append_len (&out, draw->path.arrayZ, draw->path.length);
|
||||
hb_buf_append_str (&out, "\"/>\n");
|
||||
}
|
||||
|
||||
hb_buf_append_str (&out, "</svg>\n");
|
||||
|
||||
hb_blob_t *blob = hb_buf_blob_from (&draw->recycled_blob, &out);
|
||||
|
||||
draw->path.clear ();
|
||||
draw->defs.clear ();
|
||||
draw->body.clear ();
|
||||
hb_set_clear (draw->defined_glyphs);
|
||||
draw->has_extents = false;
|
||||
draw->extents = {0, 0, 0, 0};
|
||||
|
||||
return blob;
|
||||
}
|
||||
|
||||
case HB_VECTOR_FORMAT_INVALID: default:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ struct hb_vector_draw_t
|
||||
{
|
||||
hb_object_header_t header;
|
||||
|
||||
hb_vector_format_t format = HB_VECTOR_FORMAT_SVG;
|
||||
hb_vector_format_t format = HB_VECTOR_FORMAT_INVALID;
|
||||
hb_transform_t<> transform = {1, 0, 0, 1, 0, 0};
|
||||
float x_scale_factor = 1.f;
|
||||
float y_scale_factor = 1.f;
|
||||
|
||||
@@ -1490,7 +1490,7 @@ hb_vector_paint_glyph (hb_vector_paint_t *paint,
|
||||
*
|
||||
* Enables or disables paint flattening.
|
||||
*
|
||||
* Since: 13.0.0
|
||||
* XSince: REPLACEME
|
||||
*/
|
||||
void
|
||||
hb_vector_paint_set_flat (hb_vector_paint_t *paint,
|
||||
@@ -1506,7 +1506,7 @@ hb_vector_paint_set_flat (hb_vector_paint_t *paint,
|
||||
*
|
||||
* Sets numeric output precision for paint output.
|
||||
*
|
||||
* Since: 13.0.0
|
||||
* XSince: REPLACEME
|
||||
*/
|
||||
void
|
||||
hb_vector_paint_set_precision (hb_vector_paint_t *paint,
|
||||
|
||||
@@ -40,7 +40,7 @@ struct hb_vector_paint_t
|
||||
{
|
||||
hb_object_header_t header;
|
||||
|
||||
hb_vector_format_t format = HB_VECTOR_FORMAT_SVG;
|
||||
hb_vector_format_t format = HB_VECTOR_FORMAT_INVALID;
|
||||
hb_transform_t<> transform = {1, 0, 0, 1, 0, 0};
|
||||
float x_scale_factor = 1.f;
|
||||
float y_scale_factor = 1.f;
|
||||
|
||||
+21
-3
@@ -36,6 +36,12 @@
|
||||
#include "hb-ot.h"
|
||||
|
||||
|
||||
static const char *vector_supported_formats[] = {
|
||||
"svg",
|
||||
"pdf",
|
||||
nullptr
|
||||
};
|
||||
|
||||
struct vector_output_t : output_options_t<>, view_options_t
|
||||
{
|
||||
static const bool repeat_shape = false;
|
||||
@@ -49,9 +55,9 @@ struct vector_output_t : output_options_t<>, view_options_t
|
||||
void add_options (option_parser_t *parser)
|
||||
{
|
||||
parser->set_summary ("Draw text with given font.");
|
||||
parser->set_description ("Shows shaped glyph outlines as SVG.");
|
||||
parser->set_description ("Shows shaped glyph outlines as SVG or PDF.");
|
||||
|
||||
output_options_t::add_options (parser);
|
||||
output_options_t::add_options (parser, vector_supported_formats);
|
||||
view_options_t::add_options (parser);
|
||||
|
||||
GOptionEntry entries[] =
|
||||
@@ -80,6 +86,18 @@ struct vector_output_t : output_options_t<>, view_options_t
|
||||
return;
|
||||
}
|
||||
|
||||
if (output_format &&
|
||||
g_ascii_strcasecmp (output_format, "svg") != 0 &&
|
||||
g_ascii_strcasecmp (output_format, "pdf") != 0)
|
||||
{
|
||||
char *items = g_strjoinv ("/", const_cast<char **> (vector_supported_formats));
|
||||
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
|
||||
"Unknown output format `%s'; supported formats are: %s",
|
||||
output_format, items);
|
||||
g_free (items);
|
||||
return;
|
||||
}
|
||||
|
||||
foreground = HB_COLOR (foreground_color.b,
|
||||
foreground_color.g,
|
||||
foreground_color.r,
|
||||
@@ -180,7 +198,7 @@ struct vector_output_t : output_options_t<>, view_options_t
|
||||
final_extents = extents;
|
||||
|
||||
hb_vector_format_t fmt = HB_VECTOR_FORMAT_SVG;
|
||||
if (output_format && !strcmp (output_format, "pdf"))
|
||||
if (output_format && g_ascii_strcasecmp (output_format, "pdf") == 0)
|
||||
fmt = HB_VECTOR_FORMAT_PDF;
|
||||
|
||||
hb_vector_draw_t *draw = hb_vector_draw_create_or_fail (fmt);
|
||||
|
||||
Reference in new issue
Block a user