Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 64627b5

Browse files
Olga MikhaltsovaDmitry Cherepanov
authored andcommitted
8261169: Upgrade HarfBuzz to the latest 2.8.0
Reviewed-by: dcherepanov Backport-of: 80323b7
1 parent e183f2d commit 64627b5

File tree

122 files changed

+9624
-5360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+9624
-5360
lines changed

make/lib/Awt2dLibraries.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ else
575575

576576
HARFBUZZ_DISABLED_WARNINGS_gcc := type-limits missing-field-initializers strict-aliasing
577577
HARFBUZZ_DISABLED_WARNINGS_CXX_gcc := reorder delete-non-virtual-dtor strict-overflow \
578-
maybe-uninitialized class-memaccess
578+
maybe-uninitialized class-memaccess unused-result
579579
HARFBUZZ_DISABLED_WARNINGS_clang := unused-value incompatible-pointer-types \
580580
tautological-constant-out-of-range-compare int-to-pointer-cast \
581581
undef missing-field-initializers range-loop-analysis

src/java.desktop/share/legal/harfbuzz.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Harfbuzz v2.7.2
1+
## Harfbuzz v2.8
22

33
### Harfbuzz License
44

src/java.desktop/share/native/libharfbuzz/hb-aat-layout-common.hh

Lines changed: 80 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ struct StateTable
510510
const Entry<Extra> &get_entry (int state, unsigned int klass) const
511511
{
512512
if (unlikely (klass >= nClasses))
513-
klass = StateTable<Types, Entry<Extra>>::CLASS_OUT_OF_BOUNDS;
513+
klass = StateTable::CLASS_OUT_OF_BOUNDS;
514514

515515
const HBUSHORT *states = (this+stateArrayTable).arrayZ;
516516
const Entry<Extra> *entries = (this+entryTable).arrayZ;
@@ -576,7 +576,7 @@ struct StateTable
576576
if (unlikely (stop > states))
577577
return_trace (false);
578578
for (const HBUSHORT *p = states; stop < p; p--)
579-
num_entries = hb_max (num_entries, *(p - 1) + 1);
579+
num_entries = hb_max (num_entries, *(p - 1) + 1u);
580580
state_neg = min_state;
581581
}
582582
}
@@ -597,7 +597,7 @@ struct StateTable
597597
if (unlikely (stop < states))
598598
return_trace (false);
599599
for (const HBUSHORT *p = &states[state_pos * num_classes]; p < stop; p++)
600-
num_entries = hb_max (num_entries, *p + 1);
600+
num_entries = hb_max (num_entries, *p + 1u);
601601
state_pos = max_state + 1;
602602
}
603603
}
@@ -729,7 +729,10 @@ struct ExtendedTypes
729729
template <typename Types, typename EntryData>
730730
struct StateTableDriver
731731
{
732-
StateTableDriver (const StateTable<Types, EntryData> &machine_,
732+
using StateTableT = StateTable<Types, EntryData>;
733+
using EntryT = Entry<EntryData>;
734+
735+
StateTableDriver (const StateTableT &machine_,
733736
hb_buffer_t *buffer_,
734737
hb_face_t *face_) :
735738
machine (machine_),
@@ -742,59 +745,101 @@ struct StateTableDriver
742745
if (!c->in_place)
743746
buffer->clear_output ();
744747

745-
int state = StateTable<Types, EntryData>::STATE_START_OF_TEXT;
748+
int state = StateTableT::STATE_START_OF_TEXT;
746749
for (buffer->idx = 0; buffer->successful;)
747750
{
748751
unsigned int klass = buffer->idx < buffer->len ?
749752
machine.get_class (buffer->info[buffer->idx].codepoint, num_glyphs) :
750-
(unsigned) StateTable<Types, EntryData>::CLASS_END_OF_TEXT;
753+
(unsigned) StateTableT::CLASS_END_OF_TEXT;
751754
DEBUG_MSG (APPLY, nullptr, "c%u at %u", klass, buffer->idx);
752-
const Entry<EntryData> &entry = machine.get_entry (state, klass);
755+
const EntryT &entry = machine.get_entry (state, klass);
756+
const int next_state = machine.new_state (entry.newState);
753757

754-
/* Unsafe-to-break before this if not in state 0, as things might
755-
* go differently if we start from state 0 here.
758+
/* Conditions under which it's guaranteed safe-to-break before current glyph:
756759
*
757-
* Ugh. The indexing here is ugly... */
758-
if (state && buffer->backtrack_len () && buffer->idx < buffer->len)
759-
{
760-
/* If there's no action and we're just epsilon-transitioning to state 0,
761-
* safe to break. */
762-
if (c->is_actionable (this, entry) ||
763-
!(entry.newState == StateTable<Types, EntryData>::STATE_START_OF_TEXT &&
764-
entry.flags == context_t::DontAdvance))
765-
buffer->unsafe_to_break_from_outbuffer (buffer->backtrack_len () - 1, buffer->idx + 1);
766-
}
767-
768-
/* Unsafe-to-break if end-of-text would kick in here. */
769-
if (buffer->idx + 2 <= buffer->len)
770-
{
771-
const Entry<EntryData> &end_entry = machine.get_entry (state, StateTable<Types, EntryData>::CLASS_END_OF_TEXT);
772-
if (c->is_actionable (this, end_entry))
773-
buffer->unsafe_to_break (buffer->idx, buffer->idx + 2);
774-
}
760+
* 1. There was no action in this transition; and
761+
*
762+
* 2. If we break before current glyph, the results will be the same. That
763+
* is guaranteed if:
764+
*
765+
* 2a. We were already in start-of-text state; or
766+
*
767+
* 2b. We are epsilon-transitioning to start-of-text state; or
768+
*
769+
* 2c. Starting from start-of-text state seeing current glyph:
770+
*
771+
* 2c'. There won't be any actions; and
772+
*
773+
* 2c". We would end up in the same state that we were going to end up
774+
* in now, including whether epsilon-transitioning.
775+
*
776+
* and
777+
*
778+
* 3. If we break before current glyph, there won't be any end-of-text action
779+
* after previous glyph.
780+
*
781+
* This triples the transitions we need to look up, but is worth returning
782+
* granular unsafe-to-break results. See eg.:
783+
*
784+
* https://github.com/harfbuzz/harfbuzz/issues/2860
785+
*/
786+
const EntryT *wouldbe_entry;
787+
bool safe_to_break =
788+
/* 1. */
789+
!c->is_actionable (this, entry)
790+
&&
791+
/* 2. */
792+
(
793+
/* 2a. */
794+
state == StateTableT::STATE_START_OF_TEXT
795+
||
796+
/* 2b. */
797+
(
798+
(entry.flags & context_t::DontAdvance) &&
799+
next_state == StateTableT::STATE_START_OF_TEXT
800+
)
801+
||
802+
/* 2c. */
803+
(
804+
wouldbe_entry = &machine.get_entry (StateTableT::STATE_START_OF_TEXT, klass)
805+
,
806+
/* 2c'. */
807+
!c->is_actionable (this, *wouldbe_entry)
808+
&&
809+
/* 2c". */
810+
(
811+
next_state == machine.new_state (wouldbe_entry->newState)
812+
&&
813+
(entry.flags & context_t::DontAdvance) == (wouldbe_entry->flags & context_t::DontAdvance)
814+
)
815+
)
816+
)
817+
&&
818+
/* 3. */
819+
!c->is_actionable (this, machine.get_entry (state, StateTableT::CLASS_END_OF_TEXT))
820+
;
821+
822+
if (!safe_to_break && buffer->backtrack_len () && buffer->idx < buffer->len)
823+
buffer->unsafe_to_break_from_outbuffer (buffer->backtrack_len () - 1, buffer->idx + 1);
775824

776825
c->transition (this, entry);
777826

778-
state = machine.new_state (entry.newState);
827+
state = next_state;
779828
DEBUG_MSG (APPLY, nullptr, "s%d", state);
780829

781-
if (buffer->idx == buffer->len)
830+
if (buffer->idx == buffer->len || unlikely (!buffer->successful))
782831
break;
783832

784833
if (!(entry.flags & context_t::DontAdvance) || buffer->max_ops-- <= 0)
785-
buffer->next_glyph ();
834+
(void) buffer->next_glyph ();
786835
}
787836

788837
if (!c->in_place)
789-
{
790-
for (; buffer->successful && buffer->idx < buffer->len;)
791-
buffer->next_glyph ();
792838
buffer->swap_buffers ();
793-
}
794839
}
795840

796841
public:
797-
const StateTable<Types, EntryData> &machine;
842+
const StateTableT &machine;
798843
hb_buffer_t *buffer;
799844
unsigned int num_glyphs;
800845
};

src/java.desktop/share/native/libharfbuzz/hb-aat-layout-morx-table.hh

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ struct ContextualSubtable
337337
const EntryData &data = entries[i].data;
338338

339339
if (data.markIndex != 0xFFFF)
340-
num_lookups = hb_max (num_lookups, 1 + data.markIndex);
340+
num_lookups = hb_max (num_lookups, 1u + data.markIndex);
341341
if (data.currentIndex != 0xFFFF)
342-
num_lookups = hb_max (num_lookups, 1 + data.currentIndex);
342+
num_lookups = hb_max (num_lookups, 1u + data.currentIndex);
343343
}
344344

345345
return_trace (substitutionTables.sanitize (c, this, num_lookups));
@@ -499,7 +499,7 @@ struct LigatureSubtable
499499
}
500500

501501
DEBUG_MSG (APPLY, nullptr, "Moving to stack position %u", cursor - 1);
502-
buffer->move_to (match_positions[--cursor % ARRAY_LENGTH (match_positions)]);
502+
if (unlikely (!buffer->move_to (match_positions[--cursor % ARRAY_LENGTH (match_positions)]))) return;
503503

504504
if (unlikely (!actionData->sanitize (&c->sanitizer))) break;
505505
action = *actionData;
@@ -525,25 +525,25 @@ struct LigatureSubtable
525525
hb_codepoint_t lig = ligatureData;
526526

527527
DEBUG_MSG (APPLY, nullptr, "Produced ligature %u", lig);
528-
buffer->replace_glyph (lig);
528+
if (unlikely (!buffer->replace_glyph (lig))) return;
529529

530530
unsigned int lig_end = match_positions[(match_length - 1u) % ARRAY_LENGTH (match_positions)] + 1u;
531531
/* Now go and delete all subsequent components. */
532532
while (match_length - 1u > cursor)
533533
{
534534
DEBUG_MSG (APPLY, nullptr, "Skipping ligature component");
535-
buffer->move_to (match_positions[--match_length % ARRAY_LENGTH (match_positions)]);
536-
buffer->replace_glyph (DELETED_GLYPH);
535+
if (unlikely (!buffer->move_to (match_positions[--match_length % ARRAY_LENGTH (match_positions)]))) return;
536+
if (unlikely (!buffer->replace_glyph (DELETED_GLYPH))) return;
537537
}
538538

539-
buffer->move_to (lig_end);
539+
if (unlikely (!buffer->move_to (lig_end))) return;
540540
buffer->merge_out_clusters (match_positions[cursor % ARRAY_LENGTH (match_positions)], buffer->out_len);
541541
}
542542

543543
actionData++;
544544
}
545545
while (!(action & LigActionLast));
546-
buffer->move_to (end);
546+
if (unlikely (!buffer->move_to (end))) return;
547547
}
548548
}
549549

@@ -733,17 +733,16 @@ struct InsertionSubtable
733733
bool before = flags & MarkedInsertBefore;
734734

735735
unsigned int end = buffer->out_len;
736-
buffer->move_to (mark);
736+
if (unlikely (!buffer->move_to (mark))) return;
737737

738738
if (buffer->idx < buffer->len && !before)
739-
buffer->copy_glyph ();
739+
if (unlikely (!buffer->copy_glyph ())) return;
740740
/* TODO We ignore KashidaLike setting. */
741-
for (unsigned int i = 0; i < count; i++)
742-
buffer->output_glyph (glyphs[i]);
741+
if (unlikely (!buffer->replace_glyphs (0, count, glyphs))) return;
743742
if (buffer->idx < buffer->len && !before)
744743
buffer->skip_glyph ();
745744

746-
buffer->move_to (end + count);
745+
if (unlikely (!buffer->move_to (end + count))) return;
747746

748747
buffer->unsafe_to_break_from_outbuffer (mark, hb_min (buffer->idx + 1, buffer->len));
749748
}
@@ -764,10 +763,9 @@ struct InsertionSubtable
764763
unsigned int end = buffer->out_len;
765764

766765
if (buffer->idx < buffer->len && !before)
767-
buffer->copy_glyph ();
766+
if (unlikely (!buffer->copy_glyph ())) return;
768767
/* TODO We ignore KashidaLike setting. */
769-
for (unsigned int i = 0; i < count; i++)
770-
buffer->output_glyph (glyphs[i]);
768+
if (unlikely (!buffer->replace_glyphs (0, count, glyphs))) return;
771769
if (buffer->idx < buffer->len && !before)
772770
buffer->skip_glyph ();
773771

@@ -786,7 +784,7 @@ struct InsertionSubtable
786784
*
787785
* https://github.com/harfbuzz/harfbuzz/issues/1224#issuecomment-427691417
788786
*/
789-
buffer->move_to ((flags & DontAdvance) ? end : end + count);
787+
if (unlikely (!buffer->move_to ((flags & DontAdvance) ? end : end + count))) return;
790788
}
791789
}
792790

0 commit comments

Comments
 (0)