Skip to content

8355528: Update HarfBuzz to 11.2.0 #3757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/java.desktop/share/legal/harfbuzz.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Harfbuzz v10.4.0
## Harfbuzz 11.2.0

### Harfbuzz License

Expand Down
12 changes: 6 additions & 6 deletions src/java.desktop/share/native/libharfbuzz/OT/Color/CBDT/CBDT.hh
Original file line number Diff line number Diff line change
Expand Up @@ -949,25 +949,25 @@ struct CBDT

hb_glyph_extents_t extents;
hb_glyph_extents_t pixel_extents;
hb_blob_t *blob = reference_png (font, glyph);

if (unlikely (blob == hb_blob_get_empty ()))
if (unlikely (!font->get_glyph_extents (glyph, &extents, false)))
return false;

if (unlikely (!hb_font_get_glyph_extents (font, glyph, &extents)))
if (unlikely (!get_extents (font, glyph, &pixel_extents, false)))
return false;

if (unlikely (!get_extents (font, glyph, &pixel_extents, false)))
hb_blob_t *blob = reference_png (font, glyph);
if (unlikely (hb_blob_is_immutable (blob)))
return false;

bool ret = funcs->image (data,
blob,
pixel_extents.width, -pixel_extents.height,
HB_PAINT_IMAGE_FORMAT_PNG,
font->slant_xy,
0.f,
&extents);

hb_blob_destroy (blob);

return ret;
}

Expand Down
158 changes: 131 additions & 27 deletions src/java.desktop/share/native/libharfbuzz/OT/Color/COLR/COLR.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "../../../hb-open-type.hh"
#include "../../../hb-ot-var-common.hh"
#include "../../../hb-paint.hh"
#include "../../../hb-paint-bounded.hh"
#include "../../../hb-paint-extents.hh"

#include "../CPAL/CPAL.hh"
Expand All @@ -47,6 +48,12 @@ namespace OT {
struct hb_paint_context_t;
}

struct hb_colr_scratch_t
{
hb_paint_bounded_context_t paint_bounded;
hb_paint_extents_context_t paint_extents;
};

namespace OT {

struct COLR;
Expand Down Expand Up @@ -90,12 +97,27 @@ public:
font (font_),
palette (
#ifndef HB_NO_COLOR
font->face->table.CPAL->get_palette_colors (palette_)
// https://github.com/harfbuzz/harfbuzz/issues/5116
font->face->table.CPAL->get_palette_colors (palette_ < font->face->table.CPAL->get_palette_count () ? palette_ : 0)
#endif
),
foreground (foreground_),
instancer (instancer_)
{ }
{
if (font->is_synthetic ())
{
font = hb_font_create_sub_font (font);
hb_font_set_synthetic_bold (font, 0, 0, true);
hb_font_set_synthetic_slant (font, 0);
}
else
hb_font_reference (font);
}

~hb_paint_context_t ()
{
hb_font_destroy (font);
}

hb_color_t get_color (unsigned int color_index, float alpha, hb_bool_t *is_foreground)
{
Expand Down Expand Up @@ -932,9 +954,9 @@ struct PaintGlyph
void paint_glyph (hb_paint_context_t *c) const
{
TRACE_PAINT (this);
c->funcs->push_inverse_root_transform (c->data, c->font);
c->funcs->push_inverse_font_transform (c->data, c->font);
c->funcs->push_clip_glyph (c->data, gid, c->font);
c->funcs->push_root_transform (c->data, c->font);
c->funcs->push_font_transform (c->data, c->font);
c->recurse (this+paint);
c->funcs->pop_transform (c->data);
c->funcs->pop_clip (c->data);
Expand Down Expand Up @@ -1511,10 +1533,12 @@ struct PaintComposite
void paint_glyph (hb_paint_context_t *c) const
{
TRACE_PAINT (this);
c->funcs->push_group (c->data);
c->recurse (this+backdrop);
c->funcs->push_group (c->data);
c->recurse (this+src);
c->funcs->pop_group (c->data, (hb_paint_composite_mode_t) (int) mode);
c->funcs->pop_group (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER);
}

HBUINT8 format; /* format = 32 */
Expand Down Expand Up @@ -1612,7 +1636,7 @@ struct ClipBox
void closurev1 (hb_colrv1_closure_context_t* c) const
{
switch (u.format) {
case 2: u.format2.closurev1 (c);
case 2: u.format2.closurev1 (c); return;
default:return;
}
}
Expand Down Expand Up @@ -2079,6 +2103,8 @@ struct COLR
{
static constexpr hb_tag_t tableTag = HB_OT_TAG_COLR;

bool has_data () const { return has_v0_data () || version; }

bool has_v0_data () const { return numBaseGlyphs; }
bool has_v1_data () const
{
Expand Down Expand Up @@ -2112,7 +2138,53 @@ struct COLR
{
accelerator_t (hb_face_t *face)
{ colr = hb_sanitize_context_t ().reference_table<COLR> (face); }
~accelerator_t () { this->colr.destroy (); }

~accelerator_t ()
{
auto *scratch = cached_scratch.get_relaxed ();
if (scratch)
{
scratch->~hb_colr_scratch_t ();
hb_free (scratch);
}

colr.destroy ();
}


bool has_data () const { return colr->has_data (); }

#ifndef HB_NO_PAINT
bool
get_extents (hb_font_t *font,
hb_codepoint_t glyph,
hb_glyph_extents_t *extents) const
{
if (unlikely (!has_data ())) return false;

hb_colr_scratch_t *scratch = acquire_scratch ();
if (unlikely (!scratch)) return true;
bool ret = colr->get_extents (font, glyph, extents, *scratch);
release_scratch (scratch);
return ret;
}

bool paint_glyph (hb_font_t *font,
hb_codepoint_t glyph,
hb_paint_funcs_t *funcs, void *data,
unsigned int palette_index,
hb_color_t foreground,
bool clip = true) const
{
if (unlikely (!has_data ())) return false;

hb_colr_scratch_t *scratch = acquire_scratch ();
if (unlikely (!scratch)) return true;
bool ret = colr->paint_glyph (font, glyph, funcs, data, palette_index, foreground, clip, *scratch);
release_scratch (scratch);
return ret;
}
#endif

bool is_valid () { return colr.get_blob ()->length; }

Expand Down Expand Up @@ -2148,7 +2220,33 @@ struct COLR
{ return colr->get_delta_set_index_map_ptr (); }

private:

hb_colr_scratch_t *acquire_scratch () const
{
hb_colr_scratch_t *scratch = cached_scratch.get_acquire ();

if (!scratch || unlikely (!cached_scratch.cmpexch (scratch, nullptr)))
{
scratch = (hb_colr_scratch_t *) hb_calloc (1, sizeof (hb_colr_scratch_t));
if (unlikely (!scratch))
return nullptr;
}

return scratch;
}
void release_scratch (hb_colr_scratch_t *scratch) const
{
if (!cached_scratch.cmpexch (nullptr, scratch))
{
scratch->~hb_colr_scratch_t ();
hb_free (scratch);
}
}

public:
hb_blob_ptr_t<COLR> colr;
private:
mutable hb_atomic_t<hb_colr_scratch_t *> cached_scratch;
};

void closure_glyphs (hb_codepoint_t glyph,
Expand Down Expand Up @@ -2520,7 +2618,10 @@ struct COLR

#ifndef HB_NO_PAINT
bool
get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const
get_extents (hb_font_t *font,
hb_codepoint_t glyph,
hb_glyph_extents_t *extents,
hb_colr_scratch_t &scratch) const
{

ItemVarStoreInstancer instancer (get_var_store_ptr (),
Expand All @@ -2534,10 +2635,10 @@ struct COLR
}

auto *extents_funcs = hb_paint_extents_get_funcs ();
hb_paint_extents_context_t extents_data;
bool ret = paint_glyph (font, glyph, extents_funcs, &extents_data, 0, HB_COLOR(0,0,0,0));
scratch.paint_extents.clear ();
bool ret = paint_glyph (font, glyph, extents_funcs, &scratch.paint_extents, 0, HB_COLOR(0,0,0,0), true, scratch);

hb_extents_t e = extents_data.get_extents ();
auto e = scratch.paint_extents.get_extents ();
if (e.is_void ())
{
extents->x_bearing = 0;
Expand Down Expand Up @@ -2583,7 +2684,12 @@ struct COLR

#ifndef HB_NO_PAINT
bool
paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data, unsigned int palette_index, hb_color_t foreground, bool clip = true) const
paint_glyph (hb_font_t *font,
hb_codepoint_t glyph,
hb_paint_funcs_t *funcs, void *data,
unsigned int palette_index, hb_color_t foreground,
bool clip,
hb_colr_scratch_t &scratch) const
{
ItemVarStoreInstancer instancer (get_var_store_ptr (),
get_delta_set_index_map_ptr (),
Expand Down Expand Up @@ -2617,26 +2723,26 @@ struct COLR
}
else
{
auto *extents_funcs = hb_paint_extents_get_funcs ();
hb_paint_extents_context_t extents_data;
clip = false;
is_bounded = false;
}

if (!is_bounded)
{
auto *bounded_funcs = hb_paint_bounded_get_funcs ();
scratch.paint_bounded.clear ();

paint_glyph (font, glyph,
extents_funcs, &extents_data,
bounded_funcs, &scratch.paint_bounded,
palette_index, foreground,
false);

hb_extents_t extents = extents_data.get_extents ();
is_bounded = extents_data.is_bounded ();
false,
scratch);

c.funcs->push_clip_rectangle (c.data,
extents.xmin,
extents.ymin,
extents.xmax,
extents.ymax);
is_bounded = scratch.paint_bounded.is_bounded ();
}
}

c.funcs->push_root_transform (c.data, font);
c.funcs->push_font_transform (c.data, font);

if (is_bounded)
c.recurse (*paint);
Expand Down Expand Up @@ -2714,9 +2820,7 @@ void PaintColrLayers::paint_glyph (hb_paint_context_t *c) const
return;

const Paint &paint = paint_offset_lists.get_paint (i);
c->funcs->push_group (c->data);
c->recurse (paint);
c->funcs->pop_group (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER);
}
}

Expand All @@ -2728,7 +2832,7 @@ void PaintColrGlyph::paint_glyph (hb_paint_context_t *c) const
if (unlikely (!node.visit (gid)))
return;

c->funcs->push_inverse_root_transform (c->data, c->font);
c->funcs->push_inverse_font_transform (c->data, c->font);
if (c->funcs->color_glyph (c->data, gid, c->font))
{
c->funcs->pop_transform (c->data);
Expand Down
11 changes: 6 additions & 5 deletions src/java.desktop/share/native/libharfbuzz/OT/Color/sbix/sbix.hh
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,28 @@ struct sbix

int x_offset = 0, y_offset = 0;
unsigned int strike_ppem = 0;
hb_blob_t *blob = reference_png (font, glyph, &x_offset, &y_offset, &strike_ppem);
hb_glyph_extents_t extents;
hb_glyph_extents_t pixel_extents;

if (blob == hb_blob_get_empty ())
if (!font->get_glyph_extents (glyph, &extents, false))
return false;

if (!hb_font_get_glyph_extents (font, glyph, &extents))
if (unlikely (!get_extents (font, glyph, &pixel_extents, false)))
return false;

if (unlikely (!get_extents (font, glyph, &pixel_extents, false)))
hb_blob_t *blob = reference_png (font, glyph, &x_offset, &y_offset, &strike_ppem);
if (hb_blob_is_immutable (blob))
return false;

bool ret = funcs->image (data,
blob,
pixel_extents.width, -pixel_extents.height,
HB_PAINT_IMAGE_FORMAT_PNG,
font->slant_xy,
0.f,
&extents);

hb_blob_destroy (blob);

return ret;
}

Expand Down
15 changes: 8 additions & 7 deletions src/java.desktop/share/native/libharfbuzz/OT/Color/svg/svg.hh
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,16 @@ struct SVG
if (blob == hb_blob_get_empty ())
return false;

funcs->image (data,
blob,
0, 0,
HB_PAINT_IMAGE_FORMAT_SVG,
font->slant_xy,
nullptr);
bool ret = funcs->image (data,
blob,
0, 0,
HB_PAINT_IMAGE_FORMAT_SVG,
0.f,
nullptr);

hb_blob_destroy (blob);
return true;

return ret;
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct CoverageFormat1_3

bool intersects (const hb_set_t *glyphs) const
{
if (glyphArray.len > glyphs->get_population () * hb_bit_storage ((unsigned) glyphArray.len) / 2)
if (glyphArray.len > glyphs->get_population () * hb_bit_storage ((unsigned) glyphArray.len))
{
for (auto g : *glyphs)
if (get_coverage (g) != NOT_COVERED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct CoverageFormat2_4

bool intersects (const hb_set_t *glyphs) const
{
if (rangeRecord.len > glyphs->get_population () * hb_bit_storage ((unsigned) rangeRecord.len) / 2)
if (rangeRecord.len > glyphs->get_population () * hb_bit_storage ((unsigned) rangeRecord.len))
{
for (auto g : *glyphs)
if (get_coverage (g) != NOT_COVERED)
Expand Down
Loading