mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 23:41:03 +01:00
[draw] Add rendering work-budget API
Expose budget policy and remaining-work callbacks on draw and paint function objects. The public setters clamp invalid negative caps, distinguish finite defaults from explicit unlimited operation, and report whether a backend participates in accounting. Let draw sessions borrow the live counter owned by draw_data. OpenType glyf and CFF traversal then debit the same counter in place, while unsupported backends retain a finite per-glyph fallback. Forward budget access through the parent-font draw adaptor. Document the new API and cover nil, default, unlimited, clamped, concrete, and live-depletion behavior. Tests: meson test -C build (272/272 passed) Assisted-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
1 parent
a1fa46cbde
commit
472c3e0fd3
13 files changed
+665
-6
No files matched your search
@@ -2,11 +2,39 @@ Overview of changes leading to 14.3.1
|
||||
Thursday, August 13, 2026
|
||||
=====================================
|
||||
- Various fuzzing and build fixes.
|
||||
- Add public draw and paint work-budget APIs. Rendering backends can expose a
|
||||
persistent policy and a live counter so nested outline traversal consumes the
|
||||
same finite budget as emitted output.
|
||||
- Various subsetting fixes.
|
||||
- Fix AAT insertion at the end of the text.
|
||||
- Fix various rendering bugs in the experimental GPU library.
|
||||
- WASM shaper code can now read the user features.
|
||||
|
||||
- New API:
|
||||
* Common:
|
||||
+HB_BUDGET_DEFAULT
|
||||
+HB_BUDGET_UNLIMITED
|
||||
* Draw:
|
||||
+hb_draw_set_budget_func_t
|
||||
+hb_draw_get_budget_func_t
|
||||
+hb_draw_get_budget_remaining_func_t
|
||||
+hb_draw_funcs_set_set_budget_func()
|
||||
+hb_draw_funcs_set_get_budget_func()
|
||||
+hb_draw_funcs_set_get_budget_remaining_func()
|
||||
+hb_draw_set_budget()
|
||||
+hb_draw_get_budget()
|
||||
+hb_draw_get_budget_remaining()
|
||||
* Paint:
|
||||
+hb_paint_set_budget_func_t
|
||||
+hb_paint_get_budget_func_t
|
||||
+hb_paint_get_budget_remaining_func_t
|
||||
+hb_paint_funcs_set_set_budget_func()
|
||||
+hb_paint_funcs_set_get_budget_func()
|
||||
+hb_paint_funcs_set_get_budget_remaining_func()
|
||||
+hb_paint_set_budget()
|
||||
+hb_paint_get_budget()
|
||||
+hb_paint_get_budget_remaining()
|
||||
|
||||
|
||||
Overview of changes leading to 14.3.0
|
||||
Friday, July 31, 2026
|
||||
@@ -4590,4 +4618,3 @@ Summary of API changes follows.
|
||||
hb_version_string()
|
||||
hb_version_check()
|
||||
|
||||
|
||||
@@ -126,6 +126,8 @@ hb_buffer_diff_flags_t
|
||||
|
||||
<SECTION>
|
||||
<FILE>hb-common</FILE>
|
||||
HB_BUDGET_DEFAULT
|
||||
HB_BUDGET_UNLIMITED
|
||||
HB_TAG
|
||||
HB_UNTAG
|
||||
hb_tag_from_string
|
||||
@@ -235,6 +237,15 @@ hb_draw_cubic_to_func_t
|
||||
hb_draw_funcs_set_cubic_to_func
|
||||
hb_draw_close_path_func_t
|
||||
hb_draw_funcs_set_close_path_func
|
||||
hb_draw_set_budget_func_t
|
||||
hb_draw_funcs_set_set_budget_func
|
||||
hb_draw_get_budget_func_t
|
||||
hb_draw_funcs_set_get_budget_func
|
||||
hb_draw_get_budget_remaining_func_t
|
||||
hb_draw_funcs_set_get_budget_remaining_func
|
||||
hb_draw_set_budget
|
||||
hb_draw_get_budget
|
||||
hb_draw_get_budget_remaining
|
||||
hb_draw_move_to
|
||||
hb_draw_line_to
|
||||
hb_draw_quadratic_to
|
||||
@@ -261,6 +272,16 @@ hb_paint_funcs_get_user_data
|
||||
hb_paint_funcs_make_immutable
|
||||
hb_paint_funcs_is_immutable
|
||||
|
||||
hb_paint_set_budget_func_t
|
||||
hb_paint_funcs_set_set_budget_func
|
||||
hb_paint_get_budget_func_t
|
||||
hb_paint_funcs_set_get_budget_func
|
||||
hb_paint_get_budget_remaining_func_t
|
||||
hb_paint_funcs_set_get_budget_remaining_func
|
||||
hb_paint_set_budget
|
||||
hb_paint_get_budget
|
||||
hb_paint_get_budget_remaining
|
||||
|
||||
hb_paint_push_transform_func_t
|
||||
hb_paint_funcs_set_push_transform_func
|
||||
hb_paint_pop_transform_func_t
|
||||
|
||||
@@ -94,6 +94,25 @@ HB_BEGIN_DECLS
|
||||
**/
|
||||
typedef int hb_bool_t;
|
||||
|
||||
/**
|
||||
* HB_BUDGET_DEFAULT:
|
||||
*
|
||||
* Use the implementation's finite default work budget.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
#define HB_BUDGET_DEFAULT ((int64_t) (-0x7FFFFFFFFFFFFFFF - 1))
|
||||
|
||||
/**
|
||||
* HB_BUDGET_UNLIMITED:
|
||||
*
|
||||
* Use an effectively unlimited work budget. Structural safety limits remain
|
||||
* active.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
#define HB_BUDGET_UNLIMITED ((int64_t) 0x7FFFFFFFFFFFFFFF)
|
||||
|
||||
/**
|
||||
* hb_codepoint_t:
|
||||
*
|
||||
|
||||
@@ -96,6 +96,19 @@ hb_draw_close_path_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UN
|
||||
hb_draw_state_t *st HB_UNUSED,
|
||||
void *user_data HB_UNUSED) {}
|
||||
|
||||
static hb_bool_t
|
||||
hb_draw_set_budget_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,
|
||||
int64_t budget HB_UNUSED,
|
||||
void *user_data HB_UNUSED) { return false; }
|
||||
|
||||
static int64_t
|
||||
hb_draw_get_budget_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,
|
||||
void *user_data HB_UNUSED) { return HB_BUDGET_DEFAULT; }
|
||||
|
||||
static int64_t *
|
||||
hb_draw_get_budget_remaining_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,
|
||||
void *user_data HB_UNUSED) { return nullptr; }
|
||||
|
||||
|
||||
static bool
|
||||
_hb_draw_funcs_set_preamble (hb_draw_funcs_t *dfuncs,
|
||||
@@ -355,6 +368,67 @@ hb_draw_funcs_is_immutable (hb_draw_funcs_t *dfuncs)
|
||||
return hb_object_is_immutable (dfuncs);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_draw_set_budget:
|
||||
* @dfuncs: draw functions object
|
||||
* @draw_data: associated draw data
|
||||
* @budget: the new work-budget policy
|
||||
*
|
||||
* Sets the work-budget policy and recharges the live work budget. Negative
|
||||
* values other than #HB_BUDGET_DEFAULT are clamped to zero.
|
||||
*
|
||||
* Return value: `true` if the draw functions support work budgets
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
hb_bool_t
|
||||
hb_draw_set_budget (hb_draw_funcs_t *dfuncs, void *draw_data, int64_t budget)
|
||||
{
|
||||
return dfuncs->set_budget (draw_data, budget);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_draw_get_budget:
|
||||
* @dfuncs: draw functions object
|
||||
* @draw_data: associated draw data
|
||||
*
|
||||
* Fetches the configured work-budget policy.
|
||||
*
|
||||
* Return value: the configured policy, or #HB_BUDGET_DEFAULT if unsupported
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
int64_t
|
||||
hb_draw_get_budget (hb_draw_funcs_t *dfuncs, void *draw_data)
|
||||
{
|
||||
return dfuncs->get_budget (draw_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_draw_get_budget_remaining:
|
||||
* @dfuncs: draw functions object
|
||||
* @draw_data: associated draw data
|
||||
*
|
||||
* Fetches the live work budget. A negative value means the budget was
|
||||
* exhausted. Zero means the preceding work fit exactly, but no positive-cost
|
||||
* work can start.
|
||||
*
|
||||
* Return value: the live work budget; if it is not tracked, the concrete
|
||||
* configured policy or #HB_BUDGET_UNLIMITED
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
int64_t
|
||||
hb_draw_get_budget_remaining (hb_draw_funcs_t *dfuncs, void *draw_data)
|
||||
{
|
||||
int64_t *remaining = dfuncs->get_budget_remaining_ptr (draw_data);
|
||||
if (remaining)
|
||||
return *remaining;
|
||||
|
||||
int64_t budget = dfuncs->get_budget (draw_data);
|
||||
return budget == HB_BUDGET_DEFAULT ? HB_BUDGET_UNLIMITED : budget;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hb_draw_move_to:
|
||||
|
||||
+113
@@ -195,6 +195,61 @@ typedef void (*hb_draw_close_path_func_t) (hb_draw_funcs_t *dfuncs, void *draw_d
|
||||
hb_draw_state_t *st,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_draw_set_budget_func_t:
|
||||
* @dfuncs: draw functions object
|
||||
* @draw_data: The data accompanying the draw functions
|
||||
* @budget: the new work-budget policy
|
||||
* @user_data: User data pointer passed to hb_draw_funcs_set_set_budget_func()
|
||||
*
|
||||
* Sets the work-budget policy and recharges the live work budget. @budget is
|
||||
* #HB_BUDGET_DEFAULT, #HB_BUDGET_UNLIMITED, or a non-negative concrete value.
|
||||
*
|
||||
* Return value: `true` if the budget was set, `false` if unsupported
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef hb_bool_t (*hb_draw_set_budget_func_t) (hb_draw_funcs_t *dfuncs,
|
||||
void *draw_data,
|
||||
int64_t budget,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_draw_get_budget_func_t:
|
||||
* @dfuncs: draw functions object
|
||||
* @draw_data: The data accompanying the draw functions
|
||||
* @user_data: User data pointer passed to hb_draw_funcs_set_get_budget_func()
|
||||
*
|
||||
* Fetches the configured work-budget policy.
|
||||
*
|
||||
* Return value: the configured work-budget policy
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef int64_t (*hb_draw_get_budget_func_t) (hb_draw_funcs_t *dfuncs,
|
||||
void *draw_data,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_draw_get_budget_remaining_func_t:
|
||||
* @dfuncs: draw functions object
|
||||
* @draw_data: The data accompanying the draw functions
|
||||
* @user_data: User data pointer passed to
|
||||
* hb_draw_funcs_set_get_budget_remaining_func()
|
||||
*
|
||||
* Fetches the address of the live work budget. The returned address must stay
|
||||
* valid while @draw_data is used with @dfuncs. The live value must be concrete;
|
||||
* it must not contain #HB_BUDGET_DEFAULT.
|
||||
*
|
||||
* Return value: (nullable) (transfer none): the live work budget, or `NULL` if
|
||||
* live budget accounting is unsupported
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef int64_t *(*hb_draw_get_budget_remaining_func_t) (hb_draw_funcs_t *dfuncs,
|
||||
void *draw_data,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_draw_funcs_set_move_to_func:
|
||||
* @dfuncs: draw functions object
|
||||
@@ -275,6 +330,54 @@ hb_draw_funcs_set_close_path_func (hb_draw_funcs_t *dfuncs,
|
||||
hb_draw_close_path_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
/**
|
||||
* hb_draw_funcs_set_set_budget_func:
|
||||
* @dfuncs: draw functions object
|
||||
* @func: (closure user_data) (destroy destroy) (scope notified): budget setter
|
||||
* @user_data: Data to pass to @func
|
||||
* @destroy: (nullable): callback to destroy @user_data
|
||||
*
|
||||
* Sets the budget setter callback.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
HB_EXTERN void
|
||||
hb_draw_funcs_set_set_budget_func (hb_draw_funcs_t *dfuncs,
|
||||
hb_draw_set_budget_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
/**
|
||||
* hb_draw_funcs_set_get_budget_func:
|
||||
* @dfuncs: draw functions object
|
||||
* @func: (closure user_data) (destroy destroy) (scope notified): budget getter
|
||||
* @user_data: Data to pass to @func
|
||||
* @destroy: (nullable): callback to destroy @user_data
|
||||
*
|
||||
* Sets the budget-policy getter callback.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
HB_EXTERN void
|
||||
hb_draw_funcs_set_get_budget_func (hb_draw_funcs_t *dfuncs,
|
||||
hb_draw_get_budget_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
/**
|
||||
* hb_draw_funcs_set_get_budget_remaining_func:
|
||||
* @dfuncs: draw functions object
|
||||
* @func: (closure user_data) (destroy destroy) (scope notified): live-budget getter
|
||||
* @user_data: Data to pass to @func
|
||||
* @destroy: (nullable): callback to destroy @user_data
|
||||
*
|
||||
* Sets the live-budget getter callback.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
HB_EXTERN void
|
||||
hb_draw_funcs_set_get_budget_remaining_func (hb_draw_funcs_t *dfuncs,
|
||||
hb_draw_get_budget_remaining_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
|
||||
HB_EXTERN hb_draw_funcs_t *
|
||||
hb_draw_funcs_create (void);
|
||||
@@ -306,6 +409,16 @@ hb_draw_funcs_make_immutable (hb_draw_funcs_t *dfuncs);
|
||||
HB_EXTERN hb_bool_t
|
||||
hb_draw_funcs_is_immutable (hb_draw_funcs_t *dfuncs);
|
||||
|
||||
HB_EXTERN hb_bool_t
|
||||
hb_draw_set_budget (hb_draw_funcs_t *dfuncs, void *draw_data,
|
||||
int64_t budget);
|
||||
|
||||
HB_EXTERN int64_t
|
||||
hb_draw_get_budget (hb_draw_funcs_t *dfuncs, void *draw_data);
|
||||
|
||||
HB_EXTERN int64_t
|
||||
hb_draw_get_budget_remaining (hb_draw_funcs_t *dfuncs, void *draw_data);
|
||||
|
||||
|
||||
HB_EXTERN void
|
||||
hb_draw_move_to (hb_draw_funcs_t *dfuncs, void *draw_data,
|
||||
|
||||
+27
-2
@@ -38,6 +38,9 @@
|
||||
HB_DRAW_FUNC_IMPLEMENT (quadratic_to) \
|
||||
HB_DRAW_FUNC_IMPLEMENT (cubic_to) \
|
||||
HB_DRAW_FUNC_IMPLEMENT (close_path) \
|
||||
HB_DRAW_FUNC_IMPLEMENT (set_budget) \
|
||||
HB_DRAW_FUNC_IMPLEMENT (get_budget) \
|
||||
HB_DRAW_FUNC_IMPLEMENT (get_budget_remaining) \
|
||||
/* ^--- Add new callbacks here */
|
||||
|
||||
struct hb_draw_funcs_t
|
||||
@@ -92,6 +95,20 @@ struct hb_draw_funcs_t
|
||||
{ func.close_path (this, draw_data, &st,
|
||||
!user_data ? nullptr : user_data->close_path); }
|
||||
|
||||
bool set_budget (void *draw_data, int64_t budget)
|
||||
{
|
||||
if (budget < 0 && budget != HB_BUDGET_DEFAULT)
|
||||
budget = 0;
|
||||
return func.set_budget (this, draw_data, budget,
|
||||
!user_data ? nullptr : user_data->set_budget);
|
||||
}
|
||||
int64_t get_budget (void *draw_data)
|
||||
{ return func.get_budget (this, draw_data,
|
||||
!user_data ? nullptr : user_data->get_budget); }
|
||||
int64_t *get_budget_remaining_ptr (void *draw_data)
|
||||
{ return func.get_budget_remaining (this, draw_data,
|
||||
!user_data ? nullptr : user_data->get_budget_remaining); }
|
||||
|
||||
|
||||
void
|
||||
HB_ALWAYS_INLINE
|
||||
@@ -176,8 +193,12 @@ DECLARE_NULL_INSTANCE (hb_draw_funcs_t);
|
||||
struct hb_draw_session_t
|
||||
{
|
||||
hb_draw_session_t (hb_draw_funcs_t *funcs_, void *draw_data_)
|
||||
: funcs {funcs_}, draw_data {draw_data_}, st HB_DRAW_STATE_DEFAULT
|
||||
{}
|
||||
: funcs {funcs_}, draw_data {draw_data_}, st HB_DRAW_STATE_DEFAULT,
|
||||
local_budget {HB_BUDGET_GLYPH}, budget {funcs->get_budget_remaining_ptr (draw_data)}
|
||||
{
|
||||
if (!budget)
|
||||
budget = &local_budget;
|
||||
}
|
||||
|
||||
~hb_draw_session_t () { close_path (); }
|
||||
|
||||
@@ -219,10 +240,14 @@ struct hb_draw_session_t
|
||||
funcs->close_path (draw_data, st);
|
||||
}
|
||||
|
||||
int64_t &get_budget () { return *budget; }
|
||||
|
||||
public:
|
||||
hb_draw_funcs_t *funcs;
|
||||
void *draw_data;
|
||||
hb_draw_state_t st;
|
||||
int64_t local_budget;
|
||||
int64_t *budget;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -731,6 +731,31 @@ hb_draw_close_path_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
|
||||
adaptor->draw_funcs->emit_close_path (adaptor->draw_data, *st);
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
hb_draw_set_budget_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
|
||||
int64_t budget,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
|
||||
return adaptor->draw_funcs->set_budget (adaptor->draw_data, budget);
|
||||
}
|
||||
|
||||
static int64_t
|
||||
hb_draw_get_budget_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
|
||||
return adaptor->draw_funcs->get_budget (adaptor->draw_data);
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
hb_draw_get_budget_remaining_default (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_font_draw_glyph_default_adaptor_t *adaptor = (hb_font_draw_glyph_default_adaptor_t *) draw_data;
|
||||
return adaptor->draw_funcs->get_budget_remaining_ptr (adaptor->draw_data);
|
||||
}
|
||||
|
||||
static const hb_draw_funcs_t _hb_draw_funcs_default = {
|
||||
HB_OBJECT_HEADER_STATIC,
|
||||
|
||||
|
||||
+6
-3
@@ -914,11 +914,14 @@ hb_ot_draw_glyph_or_fail (hb_font_t *font,
|
||||
if (font->face->table.VARC->get_path (font, glyph, draw_session)) return true;
|
||||
#endif
|
||||
// Keep the following in synch with VARC::get_path_at()
|
||||
if (font->face->table.glyf->get_path (font, glyph, draw_session, gvar_cache)) return true;
|
||||
if (font->face->table.glyf->get_path (font, glyph, draw_session, gvar_cache,
|
||||
&draw_session.get_budget ())) return true;
|
||||
|
||||
#ifndef HB_NO_CFF
|
||||
if (font->face->table.cff2->get_path (font, glyph, draw_session)) return true;
|
||||
if (font->face->table.cff1->get_path (font, glyph, draw_session)) return true;
|
||||
if (font->face->table.cff2->get_path (font, glyph, draw_session,
|
||||
&draw_session.get_budget ())) return true;
|
||||
if (font->face->table.cff1->get_path (font, glyph, draw_session,
|
||||
&draw_session.get_budget ())) return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
|
||||
@@ -160,6 +160,19 @@ hb_paint_custom_palette_color_nil (hb_paint_funcs_t *funcs, void *paint_data,
|
||||
hb_color_t *color,
|
||||
void *user_data) { return false; }
|
||||
|
||||
static hb_bool_t
|
||||
hb_paint_set_budget_nil (hb_paint_funcs_t *funcs HB_UNUSED, void *paint_data HB_UNUSED,
|
||||
int64_t budget HB_UNUSED,
|
||||
void *user_data HB_UNUSED) { return false; }
|
||||
|
||||
static int64_t
|
||||
hb_paint_get_budget_nil (hb_paint_funcs_t *funcs HB_UNUSED, void *paint_data HB_UNUSED,
|
||||
void *user_data HB_UNUSED) { return HB_BUDGET_DEFAULT; }
|
||||
|
||||
static int64_t *
|
||||
hb_paint_get_budget_remaining_nil (hb_paint_funcs_t *funcs HB_UNUSED, void *paint_data HB_UNUSED,
|
||||
void *user_data HB_UNUSED) { return nullptr; }
|
||||
|
||||
static bool
|
||||
_hb_paint_funcs_set_preamble (hb_paint_funcs_t *funcs,
|
||||
bool func_is_null,
|
||||
@@ -420,6 +433,67 @@ hb_paint_funcs_is_immutable (hb_paint_funcs_t *funcs)
|
||||
return hb_object_is_immutable (funcs);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_paint_set_budget:
|
||||
* @funcs: paint functions object
|
||||
* @paint_data: associated paint data
|
||||
* @budget: the new work-budget policy
|
||||
*
|
||||
* Sets the work-budget policy and recharges the live work budget. Negative
|
||||
* values other than #HB_BUDGET_DEFAULT are clamped to zero.
|
||||
*
|
||||
* Return value: `true` if the paint functions support work budgets
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
hb_bool_t
|
||||
hb_paint_set_budget (hb_paint_funcs_t *funcs, void *paint_data, int64_t budget)
|
||||
{
|
||||
return funcs->set_budget (paint_data, budget);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_paint_get_budget:
|
||||
* @funcs: paint functions object
|
||||
* @paint_data: associated paint data
|
||||
*
|
||||
* Fetches the configured work-budget policy.
|
||||
*
|
||||
* Return value: the configured policy, or #HB_BUDGET_DEFAULT if unsupported
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
int64_t
|
||||
hb_paint_get_budget (hb_paint_funcs_t *funcs, void *paint_data)
|
||||
{
|
||||
return funcs->get_budget (paint_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_paint_get_budget_remaining:
|
||||
* @funcs: paint functions object
|
||||
* @paint_data: associated paint data
|
||||
*
|
||||
* Fetches the live work budget. A negative value means the budget was
|
||||
* exhausted. Zero means the preceding work fit exactly, but no positive-cost
|
||||
* work can start.
|
||||
*
|
||||
* Return value: the live work budget; if it is not tracked, the concrete
|
||||
* configured policy or #HB_BUDGET_UNLIMITED
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
int64_t
|
||||
hb_paint_get_budget_remaining (hb_paint_funcs_t *funcs, void *paint_data)
|
||||
{
|
||||
int64_t *remaining = funcs->get_budget_remaining_ptr (paint_data);
|
||||
if (remaining)
|
||||
return *remaining;
|
||||
|
||||
int64_t budget = funcs->get_budget (paint_data);
|
||||
return budget == HB_BUDGET_DEFAULT ? HB_BUDGET_UNLIMITED : budget;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hb_color_line_get_color_stops:
|
||||
|
||||
+113
@@ -63,6 +63,109 @@ HB_BEGIN_DECLS
|
||||
**/
|
||||
typedef struct hb_paint_funcs_t hb_paint_funcs_t;
|
||||
|
||||
/**
|
||||
* hb_paint_set_budget_func_t:
|
||||
* @funcs: paint functions object
|
||||
* @paint_data: The data accompanying the paint functions
|
||||
* @budget: the new work-budget policy
|
||||
* @user_data: User data pointer passed to hb_paint_funcs_set_set_budget_func()
|
||||
*
|
||||
* Sets the work-budget policy and recharges the live work budget. @budget is
|
||||
* #HB_BUDGET_DEFAULT, #HB_BUDGET_UNLIMITED, or a non-negative concrete value.
|
||||
*
|
||||
* Return value: `true` if the budget was set, `false` if unsupported
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef hb_bool_t (*hb_paint_set_budget_func_t) (hb_paint_funcs_t *funcs,
|
||||
void *paint_data,
|
||||
int64_t budget,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_paint_get_budget_func_t:
|
||||
* @funcs: paint functions object
|
||||
* @paint_data: The data accompanying the paint functions
|
||||
* @user_data: User data pointer passed to hb_paint_funcs_set_get_budget_func()
|
||||
*
|
||||
* Fetches the configured work-budget policy.
|
||||
*
|
||||
* Return value: the configured work-budget policy
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef int64_t (*hb_paint_get_budget_func_t) (hb_paint_funcs_t *funcs,
|
||||
void *paint_data,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_paint_get_budget_remaining_func_t:
|
||||
* @funcs: paint functions object
|
||||
* @paint_data: The data accompanying the paint functions
|
||||
* @user_data: User data pointer passed to
|
||||
* hb_paint_funcs_set_get_budget_remaining_func()
|
||||
*
|
||||
* Fetches the address of the live work budget. The returned address must stay
|
||||
* valid while @paint_data is used with @funcs. The live value must be concrete;
|
||||
* it must not contain #HB_BUDGET_DEFAULT.
|
||||
*
|
||||
* Return value: (nullable) (transfer none): the live work budget, or `NULL` if
|
||||
* live budget accounting is unsupported
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
typedef int64_t *(*hb_paint_get_budget_remaining_func_t) (hb_paint_funcs_t *funcs,
|
||||
void *paint_data,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* hb_paint_funcs_set_set_budget_func:
|
||||
* @funcs: paint functions object
|
||||
* @func: (closure user_data) (destroy destroy) (scope notified): budget setter
|
||||
* @user_data: Data to pass to @func
|
||||
* @destroy: (nullable): callback to destroy @user_data
|
||||
*
|
||||
* Sets the budget setter callback.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
HB_EXTERN void
|
||||
hb_paint_funcs_set_set_budget_func (hb_paint_funcs_t *funcs,
|
||||
hb_paint_set_budget_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
/**
|
||||
* hb_paint_funcs_set_get_budget_func:
|
||||
* @funcs: paint functions object
|
||||
* @func: (closure user_data) (destroy destroy) (scope notified): budget getter
|
||||
* @user_data: Data to pass to @func
|
||||
* @destroy: (nullable): callback to destroy @user_data
|
||||
*
|
||||
* Sets the budget-policy getter callback.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
HB_EXTERN void
|
||||
hb_paint_funcs_set_get_budget_func (hb_paint_funcs_t *funcs,
|
||||
hb_paint_get_budget_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
/**
|
||||
* hb_paint_funcs_set_get_budget_remaining_func:
|
||||
* @funcs: paint functions object
|
||||
* @func: (closure user_data) (destroy destroy) (scope notified): live-budget getter
|
||||
* @user_data: Data to pass to @func
|
||||
* @destroy: (nullable): callback to destroy @user_data
|
||||
*
|
||||
* Sets the live-budget getter callback.
|
||||
*
|
||||
* XSince: REPLACEME
|
||||
**/
|
||||
HB_EXTERN void
|
||||
hb_paint_funcs_set_get_budget_remaining_func (hb_paint_funcs_t *funcs,
|
||||
hb_paint_get_budget_remaining_func_t func,
|
||||
void *user_data, hb_destroy_func_t destroy);
|
||||
|
||||
HB_EXTERN hb_paint_funcs_t *
|
||||
hb_paint_funcs_create (void);
|
||||
|
||||
@@ -93,6 +196,16 @@ hb_paint_funcs_make_immutable (hb_paint_funcs_t *funcs);
|
||||
HB_EXTERN hb_bool_t
|
||||
hb_paint_funcs_is_immutable (hb_paint_funcs_t *funcs);
|
||||
|
||||
HB_EXTERN hb_bool_t
|
||||
hb_paint_set_budget (hb_paint_funcs_t *funcs, void *paint_data,
|
||||
int64_t budget);
|
||||
|
||||
HB_EXTERN int64_t
|
||||
hb_paint_get_budget (hb_paint_funcs_t *funcs, void *paint_data);
|
||||
|
||||
HB_EXTERN int64_t
|
||||
hb_paint_get_budget_remaining (hb_paint_funcs_t *funcs, void *paint_data);
|
||||
|
||||
/**
|
||||
* hb_paint_push_transform_func_t:
|
||||
* @funcs: paint functions object
|
||||
|
||||
@@ -49,6 +49,9 @@
|
||||
HB_PAINT_FUNC_IMPLEMENT (pop_group) \
|
||||
HB_PAINT_FUNC_IMPLEMENT (custom_palette_color) \
|
||||
HB_PAINT_FUNC_IMPLEMENT (fill_glyph) \
|
||||
HB_PAINT_FUNC_IMPLEMENT (set_budget) \
|
||||
HB_PAINT_FUNC_IMPLEMENT (get_budget) \
|
||||
HB_PAINT_FUNC_IMPLEMENT (get_budget_remaining) \
|
||||
/* ^--- Add new callbacks here */
|
||||
|
||||
struct hb_paint_funcs_t
|
||||
@@ -183,6 +186,19 @@ struct hb_paint_funcs_t
|
||||
color_index,
|
||||
color,
|
||||
!user_data ? nullptr : user_data->custom_palette_color); }
|
||||
bool set_budget (void *paint_data, int64_t budget)
|
||||
{
|
||||
if (budget < 0 && budget != HB_BUDGET_DEFAULT)
|
||||
budget = 0;
|
||||
return func.set_budget (this, paint_data, budget,
|
||||
!user_data ? nullptr : user_data->set_budget);
|
||||
}
|
||||
int64_t get_budget (void *paint_data)
|
||||
{ return func.get_budget (this, paint_data,
|
||||
!user_data ? nullptr : user_data->get_budget); }
|
||||
int64_t *get_budget_remaining_ptr (void *paint_data)
|
||||
{ return func.get_budget_remaining (this, paint_data,
|
||||
!user_data ? nullptr : user_data->get_budget_remaining); }
|
||||
|
||||
|
||||
/* Internal specializations. */
|
||||
|
||||
@@ -1075,6 +1075,86 @@ test_hb_draw_immutable (void)
|
||||
hb_draw_funcs_destroy (draw_funcs);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int64_t policy;
|
||||
int64_t live;
|
||||
} draw_budget_data_t;
|
||||
|
||||
static hb_bool_t
|
||||
draw_set_budget (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
void *draw_data,
|
||||
int64_t budget,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
draw_budget_data_t *data = (draw_budget_data_t *) draw_data;
|
||||
data->policy = budget;
|
||||
data->live = budget == HB_BUDGET_DEFAULT ? 1234 : budget;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int64_t
|
||||
draw_get_budget (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
void *draw_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
return ((draw_budget_data_t *) draw_data)->policy;
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
draw_get_budget_remaining (hb_draw_funcs_t *dfuncs HB_UNUSED,
|
||||
void *draw_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
return &((draw_budget_data_t *) draw_data)->live;
|
||||
}
|
||||
|
||||
static void
|
||||
test_hb_draw_budget (void)
|
||||
{
|
||||
draw_budget_data_t data = {HB_BUDGET_DEFAULT, 1234};
|
||||
hb_draw_funcs_t *draw_funcs = hb_draw_funcs_create ();
|
||||
|
||||
g_assert_false (hb_draw_set_budget (draw_funcs, &data, 100));
|
||||
g_assert_cmpint (hb_draw_get_budget (draw_funcs, &data), ==, HB_BUDGET_DEFAULT);
|
||||
g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), ==, HB_BUDGET_UNLIMITED);
|
||||
|
||||
hb_draw_funcs_set_set_budget_func (draw_funcs, draw_set_budget, NULL, NULL);
|
||||
hb_draw_funcs_set_get_budget_func (draw_funcs, draw_get_budget, NULL, NULL);
|
||||
hb_draw_funcs_set_get_budget_remaining_func (draw_funcs, draw_get_budget_remaining, NULL, NULL);
|
||||
|
||||
g_assert_true (hb_draw_set_budget (draw_funcs, &data, -42));
|
||||
g_assert_cmpint (hb_draw_get_budget (draw_funcs, &data), ==, 0);
|
||||
g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), ==, 0);
|
||||
|
||||
g_assert_true (hb_draw_set_budget (draw_funcs, &data, HB_BUDGET_DEFAULT));
|
||||
g_assert_cmpint (hb_draw_get_budget (draw_funcs, &data), ==, HB_BUDGET_DEFAULT);
|
||||
g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), ==, 1234);
|
||||
|
||||
g_assert_true (hb_draw_set_budget (draw_funcs, &data, HB_BUDGET_UNLIMITED));
|
||||
g_assert_cmpint (hb_draw_get_budget (draw_funcs, &data), ==, HB_BUDGET_UNLIMITED);
|
||||
g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), ==, HB_BUDGET_UNLIMITED);
|
||||
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/glyphs.ttf");
|
||||
hb_font_t *font = hb_font_create (face);
|
||||
|
||||
g_assert_true (hb_draw_set_budget (draw_funcs, &data, 100000));
|
||||
g_assert_true (hb_font_draw_glyph_or_fail (font, 0, draw_funcs, &data));
|
||||
g_assert_cmpint (hb_draw_get_budget (draw_funcs, &data), ==, 100000);
|
||||
g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), <, 100000);
|
||||
g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), >=, 0);
|
||||
|
||||
g_assert_true (hb_draw_set_budget (draw_funcs, &data, HB_BUDGET_UNLIMITED));
|
||||
g_assert_true (hb_font_draw_glyph_or_fail (font, 0, draw_funcs, &data));
|
||||
g_assert_cmpint (hb_draw_get_budget (draw_funcs, &data), ==, HB_BUDGET_UNLIMITED);
|
||||
g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), <, HB_BUDGET_UNLIMITED);
|
||||
g_assert_cmpint (hb_draw_get_budget_remaining (draw_funcs, &data), >, 0);
|
||||
|
||||
hb_font_destroy (font);
|
||||
hb_face_destroy (face);
|
||||
hb_draw_funcs_destroy (draw_funcs);
|
||||
}
|
||||
|
||||
static void
|
||||
test_hb_draw_funcs (const void* user_data)
|
||||
{
|
||||
@@ -1190,6 +1270,7 @@ main (int argc, char **argv)
|
||||
hb_test_add (test_hb_draw_synthetic_slant);
|
||||
hb_test_add (test_hb_draw_subfont_scale);
|
||||
hb_test_add (test_hb_draw_immutable);
|
||||
hb_test_add (test_hb_draw_budget);
|
||||
|
||||
const char **font_funcs = hb_font_list_funcs ();
|
||||
for (const char **font_funcs_name = font_funcs; *font_funcs_name; font_funcs_name++)
|
||||
|
||||
@@ -911,6 +911,73 @@ test_color_glyph_user_data (void)
|
||||
hb_paint_funcs_destroy (funcs);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int64_t policy;
|
||||
int64_t live;
|
||||
} paint_budget_data_t;
|
||||
|
||||
static hb_bool_t
|
||||
paint_set_budget (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
void *paint_data,
|
||||
int64_t budget,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
paint_budget_data_t *data = (paint_budget_data_t *) paint_data;
|
||||
data->policy = budget;
|
||||
data->live = budget == HB_BUDGET_DEFAULT ? 4321 : budget;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int64_t
|
||||
paint_get_budget (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
void *paint_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
return ((paint_budget_data_t *) paint_data)->policy;
|
||||
}
|
||||
|
||||
static int64_t *
|
||||
paint_get_budget_remaining (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
void *paint_data,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
return &((paint_budget_data_t *) paint_data)->live;
|
||||
}
|
||||
|
||||
static void
|
||||
test_hb_paint_budget (void)
|
||||
{
|
||||
paint_budget_data_t data = {HB_BUDGET_DEFAULT, 4321};
|
||||
hb_paint_funcs_t *funcs = hb_paint_funcs_create ();
|
||||
|
||||
g_assert_false (hb_paint_set_budget (funcs, &data, 100));
|
||||
g_assert_cmpint (hb_paint_get_budget (funcs, &data), ==, HB_BUDGET_DEFAULT);
|
||||
g_assert_cmpint (hb_paint_get_budget_remaining (funcs, &data), ==, HB_BUDGET_UNLIMITED);
|
||||
|
||||
hb_paint_funcs_set_set_budget_func (funcs, paint_set_budget, NULL, NULL);
|
||||
hb_paint_funcs_set_get_budget_func (funcs, paint_get_budget, NULL, NULL);
|
||||
hb_paint_funcs_set_get_budget_remaining_func (funcs, paint_get_budget_remaining, NULL, NULL);
|
||||
|
||||
g_assert_true (hb_paint_set_budget (funcs, &data, -7));
|
||||
g_assert_cmpint (hb_paint_get_budget (funcs, &data), ==, 0);
|
||||
g_assert_cmpint (hb_paint_get_budget_remaining (funcs, &data), ==, 0);
|
||||
|
||||
g_assert_true (hb_paint_set_budget (funcs, &data, HB_BUDGET_DEFAULT));
|
||||
g_assert_cmpint (hb_paint_get_budget (funcs, &data), ==, HB_BUDGET_DEFAULT);
|
||||
g_assert_cmpint (hb_paint_get_budget_remaining (funcs, &data), ==, 4321);
|
||||
|
||||
g_assert_true (hb_paint_set_budget (funcs, &data, 9876));
|
||||
g_assert_cmpint (hb_paint_get_budget (funcs, &data), ==, 9876);
|
||||
g_assert_cmpint (hb_paint_get_budget_remaining (funcs, &data), ==, 9876);
|
||||
|
||||
g_assert_true (hb_paint_set_budget (funcs, &data, HB_BUDGET_UNLIMITED));
|
||||
g_assert_cmpint (hb_paint_get_budget (funcs, &data), ==, HB_BUDGET_UNLIMITED);
|
||||
g_assert_cmpint (hb_paint_get_budget_remaining (funcs, &data), ==, HB_BUDGET_UNLIMITED);
|
||||
|
||||
hb_paint_funcs_destroy (funcs);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
@@ -925,6 +992,7 @@ main (int argc, char **argv)
|
||||
hb_test_add (test_push_clip_path_round_trip);
|
||||
hb_test_add (test_fill_glyph_nil_decomposes);
|
||||
hb_test_add (test_color_glyph_user_data);
|
||||
hb_test_add (test_hb_paint_budget);
|
||||
|
||||
for (unsigned int i = 0; i < G_N_ELEMENTS (paint_tests); i++)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user