mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-21 15:01:01 +01:00
[hvgl] Use a context object
This commit is contained in:
1 parent
c577cd6c98
commit
01453ba1a0
2 files changed
+55
-81
No files matched your search
@@ -87,15 +87,9 @@ __attribute__((target("fma")))
|
||||
#endif
|
||||
#endif
|
||||
void
|
||||
PartShape::get_path_at (const struct hvgl &hvgl,
|
||||
hb_draw_session_t *draw_session,
|
||||
hb_extents_t<> *extents,
|
||||
PartShape::get_path_at (const hb_hvgl_context_t *c,
|
||||
hb_array_t<const double> coords,
|
||||
hb_array_t<hb_transform_t<double>> transforms,
|
||||
hb_hvgl_scratch_t &scratch,
|
||||
signed *nodes_left,
|
||||
signed *edges_left,
|
||||
signed depth_left) const
|
||||
hb_array_t<hb_transform_t<double>> transforms) const
|
||||
{
|
||||
hb_transform_t<double> transform = transforms[0];
|
||||
|
||||
@@ -105,7 +99,7 @@ PartShape::get_path_at (const struct hvgl &hvgl,
|
||||
const auto &coordinates = StructAfter<decltype (coordinatesX)> (padding, this);
|
||||
|
||||
auto a = coordinates.get_coords (segmentCount);
|
||||
auto &v = scratch.points;
|
||||
auto &v = c->scratch.points;
|
||||
|
||||
#ifdef __BYTE_ORDER
|
||||
constexpr bool le = __BYTE_ORDER == __LITTLE_ENDIAN;
|
||||
@@ -320,10 +314,10 @@ PartShape::get_path_at (const struct hvgl &hvgl,
|
||||
double x0 = next_segment[SEGMENT_POINT_ON_CURVE_X];
|
||||
double y0 = next_segment[SEGMENT_POINT_ON_CURVE_Y];
|
||||
transform.transform_point (x0, y0);
|
||||
if (draw_session)
|
||||
draw_session->move_to ((float) x0, (float) y0);
|
||||
if (extents)
|
||||
extents->add_point ((float) x0, (float) y0);
|
||||
if (c->draw_session)
|
||||
c->draw_session->move_to ((float) x0, (float) y0);
|
||||
if (c->extents)
|
||||
c->extents->add_point ((float) x0, (float) y0);
|
||||
for (unsigned i = start; i < end; i++)
|
||||
{
|
||||
segment_t segment = next_segment;
|
||||
@@ -336,16 +330,16 @@ PartShape::get_path_at (const struct hvgl &hvgl,
|
||||
double y2 = next_segment[SEGMENT_POINT_ON_CURVE_Y];
|
||||
transform.transform_point (x1, y1);
|
||||
transform.transform_point (x2, y2);
|
||||
if (draw_session)
|
||||
draw_session->quadratic_to ((float) x1, (float) y1, (float) x2, (float) y2);
|
||||
if (extents)
|
||||
if (c->draw_session)
|
||||
c->draw_session->quadratic_to ((float) x1, (float) y1, (float) x2, (float) y2);
|
||||
if (c->extents)
|
||||
{
|
||||
extents->add_point ((float) x1, (float) y1);
|
||||
extents->add_point ((float) x2, (float) y2);
|
||||
c->extents->add_point ((float) x1, (float) y1);
|
||||
c->extents->add_point ((float) x2, (float) y2);
|
||||
}
|
||||
}
|
||||
if (draw_session)
|
||||
draw_session->close_path ();
|
||||
if (c->draw_session)
|
||||
c->draw_session->close_path ();
|
||||
}
|
||||
|
||||
start = end;
|
||||
@@ -547,15 +541,9 @@ PartComposite::apply_to_transforms (hb_array_t<hb_transform_t<double>> transform
|
||||
}
|
||||
|
||||
void
|
||||
PartComposite::get_path_at (const struct hvgl &hvgl,
|
||||
hb_draw_session_t *draw_session,
|
||||
hb_extents_t<> *extents,
|
||||
PartComposite::get_path_at (const hb_hvgl_context_t *c,
|
||||
hb_array_t<double> coords,
|
||||
hb_array_t<hb_transform_t<double>> transforms,
|
||||
hb_hvgl_scratch_t &scratch,
|
||||
signed *nodes_left,
|
||||
signed *edges_left,
|
||||
signed depth_left) const
|
||||
hb_array_t<hb_transform_t<double>> transforms) const
|
||||
{
|
||||
const auto &subParts = StructAtOffset<SubParts> (this, subPartsOff4 * 4);
|
||||
|
||||
@@ -574,11 +562,10 @@ PartComposite::get_path_at (const struct hvgl &hvgl,
|
||||
for (const auto &subPart : subParts.as_array (subPartCount))
|
||||
{
|
||||
transforms_tail[subPart.treeTransformIndex].transform (transforms_head, true);
|
||||
hvgl.get_part_path_at (subPart.partIndex,
|
||||
draw_session, extents,
|
||||
coords_tail.sub_array (subPart.treeAxisIndex),
|
||||
transforms_tail.sub_array (subPart.treeTransformIndex),
|
||||
scratch, nodes_left, edges_left, depth_left);
|
||||
c->hvgl_table.get_part_path_at (c,
|
||||
subPart.partIndex,
|
||||
coords_tail.sub_array (subPart.treeAxisIndex),
|
||||
transforms_tail.sub_array (subPart.treeTransformIndex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,17 @@ struct hb_hvgl_scratch_t
|
||||
|
||||
struct hvgl;
|
||||
|
||||
struct hb_hvgl_context_t
|
||||
{
|
||||
const hvgl &hvgl_table;
|
||||
hb_draw_session_t *draw_session;
|
||||
hb_extents_t<> *extents;
|
||||
hb_hvgl_scratch_t &scratch;
|
||||
mutable signed nodes_left;
|
||||
mutable signed edges_left;
|
||||
mutable signed depth_left;
|
||||
};
|
||||
|
||||
namespace hvgl_impl {
|
||||
|
||||
struct coordinates_t
|
||||
@@ -106,15 +117,9 @@ struct PartShape
|
||||
{ return 1; }
|
||||
|
||||
HB_INTERNAL void
|
||||
get_path_at (const struct hvgl &hvgl,
|
||||
hb_draw_session_t *draw_session,
|
||||
hb_extents_t<> *extents,
|
||||
get_path_at (const hb_hvgl_context_t *c,
|
||||
hb_array_t<const double> coords,
|
||||
hb_array_t<hb_transform_t<double>> transforms,
|
||||
hb_hvgl_scratch_t &scratch,
|
||||
signed *nodes_left,
|
||||
signed *edges_left,
|
||||
signed depth_left) const;
|
||||
hb_array_t<hb_transform_t<double>> transforms) const;
|
||||
|
||||
bool sanitize (hb_sanitize_context_t *c) const
|
||||
{
|
||||
@@ -334,15 +339,9 @@ struct PartComposite
|
||||
{ return totalNumParts; }
|
||||
|
||||
HB_INTERNAL void
|
||||
get_path_at (const struct hvgl &hvgl,
|
||||
hb_draw_session_t *draw_session,
|
||||
hb_extents_t<> *extents,
|
||||
get_path_at (const hb_hvgl_context_t *c,
|
||||
hb_array_t<double> coords,
|
||||
hb_array_t<hb_transform_t<double>> transforms,
|
||||
hb_hvgl_scratch_t &scratch,
|
||||
signed *nodes_left,
|
||||
signed *edges_left,
|
||||
signed depth_left) const;
|
||||
hb_array_t<hb_transform_t<double>> transforms) const;
|
||||
|
||||
bool sanitize (hb_sanitize_context_t *c) const
|
||||
{
|
||||
@@ -412,19 +411,13 @@ struct Part
|
||||
}
|
||||
|
||||
void
|
||||
get_path_at (const struct hvgl &hvgl,
|
||||
hb_draw_session_t *draw_session,
|
||||
hb_extents_t<> *extents,
|
||||
get_path_at (const hb_hvgl_context_t *c,
|
||||
hb_array_t<double> coords,
|
||||
hb_array_t<hb_transform_t<double>> transforms,
|
||||
hb_hvgl_scratch_t &scratch,
|
||||
signed *nodes_left,
|
||||
signed *edges_left,
|
||||
signed depth_left) const
|
||||
hb_array_t<hb_transform_t<double>> transforms) const
|
||||
{
|
||||
switch (u.flags & 1) {
|
||||
case 0: hb_barrier(); u.shape.get_path_at (hvgl, draw_session, extents, coords, transforms, scratch, nodes_left, edges_left, depth_left); break;
|
||||
case 1: hb_barrier(); u.composite.get_path_at (hvgl, draw_session, extents, coords, transforms, scratch, nodes_left, edges_left, depth_left); break;
|
||||
case 0: hb_barrier(); u.shape.get_path_at (c, coords, transforms); break;
|
||||
case 1: hb_barrier(); u.composite.get_path_at (c, coords, transforms); break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -518,31 +511,29 @@ struct hvgl
|
||||
protected:
|
||||
|
||||
bool
|
||||
get_part_path_at (hb_codepoint_t part_id,
|
||||
hb_draw_session_t *draw_session,
|
||||
hb_extents_t<> *extents,
|
||||
get_part_path_at (const hb_hvgl_context_t *c,
|
||||
hb_codepoint_t part_id,
|
||||
hb_array_t<double> coords,
|
||||
hb_array_t<hb_transform_t<double>> transforms,
|
||||
hb_hvgl_scratch_t &scratch,
|
||||
signed *nodes_left,
|
||||
signed *edges_left,
|
||||
signed depth_left) const
|
||||
hb_array_t<hb_transform_t<double>> transforms) const
|
||||
{
|
||||
if (unlikely (depth_left <= 0))
|
||||
if (unlikely (c->edges_left <= 0))
|
||||
return true;
|
||||
c->edges_left--;
|
||||
|
||||
if (unlikely (*edges_left <= 0))
|
||||
if (unlikely (c->nodes_left <= 0))
|
||||
return true;
|
||||
(*edges_left)--;
|
||||
c->nodes_left--;
|
||||
|
||||
if (unlikely (*nodes_left <= 0))
|
||||
if (unlikely (c->depth_left <= 0))
|
||||
return true;
|
||||
(*nodes_left)--;
|
||||
c->depth_left--;
|
||||
|
||||
const auto &parts = StructAtOffset<hvgl_impl::PartsIndex> (this, partsOff);
|
||||
const auto &part = parts.get (part_id, partCount);
|
||||
|
||||
part.get_path_at (*this, draw_session, extents, coords, transforms, scratch, nodes_left, edges_left, depth_left);
|
||||
part.get_path_at (c, coords, transforms);
|
||||
|
||||
c->depth_left++;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -577,17 +568,13 @@ struct hvgl
|
||||
if (unlikely (transforms.in_error ())) return true;
|
||||
transforms[0] = hb_transform_t<double>{(double) font->x_multf, 0, 0, (double) font->y_multf, 0, 0};
|
||||
|
||||
int edges_left = HB_MAX_GRAPH_EDGE_COUNT;
|
||||
signed nodes_left = total_num_parts;
|
||||
signed depth_left = HB_MAX_NESTING_LEVEL;
|
||||
hb_hvgl_context_t c = {*this, draw_session, extents,
|
||||
scratch,
|
||||
(int) total_num_parts, HB_MAX_GRAPH_EDGE_COUNT, HB_MAX_NESTING_LEVEL};
|
||||
|
||||
scratch.points.alloc (128);
|
||||
|
||||
return get_part_path_at (gid,
|
||||
draw_session, extents,
|
||||
coords_f, transforms,
|
||||
scratch,
|
||||
&nodes_left, &edges_left, depth_left);
|
||||
return get_part_path_at (&c, gid, coords_f, transforms);
|
||||
}
|
||||
|
||||
bool sanitize (hb_sanitize_context_t *c) const
|
||||
|
||||
Reference in new issue
Block a user