Files
harfbuzz/src/hb-vector-path.hh
T
Behdad Esfahbod fd3fe6c54f [vector/raster] Bound output-session work
VARC's traversal budget still allowed one glyph to amplify into large
serialized paths or millions of raster edges.  Vector paint also
charged outline bytes only after a whole glyph, allowing an unbounded
single-operation overshoot.

Charge complete SVG/PDF path commands against cumulative draw and
paint context budgets, reset on clear.  Cap each raster draw session's
stored edges and stop processing outline callbacks after exhaustion.

The pathological VARC seed now keeps raster chunk 7 below 0.8 seconds
and vector chunk 7 below 1 second in the full suite.  SVG and PDF
outputs remain syntactically valid at the budget boundary.

Tested with the vector, raster, fuzzing, and full Meson test suites.

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-08-19 13:39:49 -06:00

78 lines
2.3 KiB
C++

/*
* Copyright © 2026 Behdad Esfahbod
*
* This is part of HarfBuzz, a text shaping library.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Author(s): Behdad Esfahbod
*/
#ifndef HB_VECTOR_PATH_HH
#define HB_VECTOR_PATH_HH
#include "hb.hh"
#include "hb-vector.hh"
#include "hb-vector.h"
#include "hb-draw.h"
#include "hb-vector-buf.hh"
/* Lightweight path sink: serializes hb_draw_* calls into an
* external char buffer as either SVG path-data or PDF path
* operators, depending on format. Used by the vector paint
* backends to accumulate arbitrary clip paths (and by the
* SVG backend to emit glyph outlines into defs). */
struct hb_vector_path_sink_t
{
hb_vector_buf_t *path;
unsigned precision;
float x_scale;
float y_scale;
int64_t *work_left;
bool begin_command (unsigned *before)
{
if (unlikely (path->in_error () ||
(work_left && *work_left <= 0)))
return false;
*before = path->length;
return true;
}
void end_command (unsigned before)
{
if (!work_left) return;
if (unlikely (path->in_error ()))
*work_left = 0;
else
*work_left -= path->length - before;
}
};
HB_INTERNAL hb_draw_funcs_t *
hb_vector_svg_path_draw_funcs_get ();
HB_INTERNAL hb_draw_funcs_t *
hb_vector_pdf_path_draw_funcs_get ();
HB_INTERNAL hb_draw_funcs_t *
hb_vector_path_draw_funcs_get (hb_vector_format_t format);
#endif /* HB_VECTOR_PATH_HH */