Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / third_party / harfbuzz / chromium.patch
blob371c6e6bb2c181e77d9e244dfe3a1db0ded9f8ca
1 diff --git a/contrib/harfbuzz-unicode.c b/contrib/harfbuzz-unicode.c
2 index 72c5cf2..49e47b0 100644
3 --- a/contrib/harfbuzz-unicode.c
4 +++ b/contrib/harfbuzz-unicode.c
5 @@ -120,7 +120,6 @@ hb_utf16_script_run_next(unsigned *num_code_points, HB_ScriptItem *output,
6 current_script = script;
7 continue;
8 } else if (script == HB_Script_Inherited) {
9 - current_script = script;
10 continue;
11 } else {
12 *iter = prev_iter;
13 @@ -171,7 +170,10 @@ hb_utf16_script_run_prev(unsigned *num_code_points, HB_ScriptItem *output,
14 current_script = script;
15 continue;
16 } else if (script == HB_Script_Inherited) {
17 - current_script = script;
18 + // Just assume that whatever follows this combining character is within
19 + // the same script. This is incorrect if you had language1 + combining
20 + // char + language 2, but that is rare and this code is suspicious
21 + // anyway.
22 continue;
23 } else {
24 *iter = prev_iter;
25 diff --git a/src/harfbuzz-arabic.c b/src/harfbuzz-arabic.c
26 index 51f839a..af40bf8 100644
27 --- a/src/harfbuzz-arabic.c
28 +++ b/src/harfbuzz-arabic.c
29 @@ -1107,6 +1107,7 @@ HB_Bool HB_ArabicShape(HB_ShaperItem *item)
30 assert(item->item.script == HB_Script_Arabic || item->item.script == HB_Script_Syriac
31 || item->item.script == HB_Script_Nko);
33 + item->shaperFlags |= HB_ShaperFlag_ForceMarksToZeroWidth;
34 #ifndef NO_OPENTYPE
36 if (HB_SelectScript(item, item->item.script == HB_Script_Arabic ? arabic_features : syriac_features)) {
37 diff --git a/src/harfbuzz-shaper.cpp b/src/harfbuzz-shaper.cpp
38 index 7fd04a9..66f0ea6 100644
39 --- a/src/harfbuzz-shaper.cpp
40 +++ b/src/harfbuzz-shaper.cpp
41 @@ -430,8 +430,6 @@ void HB_HeuristicSetGlyphAttributes(HB_ShaperItem *item)
43 // ### zeroWidth and justification are missing here!!!!!
45 - assert(item->num_glyphs <= length);
47 // qDebug("QScriptEngine::heuristicSetGlyphAttributes, num_glyphs=%d", item->num_glyphs);
48 HB_GlyphAttributes *attributes = item->attributes;
49 unsigned short *logClusters = item->log_clusters;
50 @@ -448,7 +446,6 @@ void HB_HeuristicSetGlyphAttributes(HB_ShaperItem *item)
52 ++glyph_pos;
54 - assert(glyph_pos == item->num_glyphs);
56 // first char in a run is never (treated as) a mark
57 int cStart = 0;
58 @@ -1151,10 +1148,12 @@ HB_Bool HB_OpenTypeShape(HB_ShaperItem *item, const hb_uint32 *properties)
59 return false;
60 face->tmpLogClusters = tmpLogClusters;
62 + const int itemLength = item->item.length;
63 + assert(itemLength > 0);
64 for (int i = 0; i < face->length; ++i) {
65 hb_buffer_add_glyph(face->buffer, item->glyphs[i], properties ? properties[i] : 0, i);
66 face->tmpAttributes[i] = item->attributes[i];
67 - face->tmpLogClusters[i] = item->log_clusters[i];
68 + face->tmpLogClusters[i] = i < itemLength ? item->log_clusters[i] : item->log_clusters[itemLength - 1];
71 #ifdef OT_DEBUG
72 @@ -1190,6 +1189,24 @@ HB_Bool HB_OpenTypeShape(HB_ShaperItem *item, const hb_uint32 *properties)
73 return true;
76 +/* See comments near the definition of HB_ShaperFlag_ForceMarksToZeroWidth for a description
77 + of why this function exists. */
78 +void HB_FixupZeroWidth(HB_ShaperItem *item)
80 + HB_UShort property;
82 + if (!item->face->gdef)
83 + return;
85 + for (unsigned int i = 0; i < item->num_glyphs; ++i) {
86 + /* If the glyph is a mark, force its advance to zero. */
87 + if (HB_GDEF_Get_Glyph_Property (item->face->gdef, item->glyphs[i], &property) == HB_Err_Ok &&
88 + property == HB_GDEF_MARK) {
89 + item->advances[i] = 0;
90 + }
91 + }
94 HB_Bool HB_OpenTypePosition(HB_ShaperItem *item, int availableGlyphs, HB_Bool doLogClusters)
96 HB_Face face = item->face;
97 @@ -1204,6 +1221,8 @@ HB_Bool HB_OpenTypePosition(HB_ShaperItem *item, int availableGlyphs, HB_Bool do
99 if (!face->glyphs_substituted && !glyphs_positioned) {
100 HB_GetGlyphAdvances(item);
101 + if (item->face->current_flags & HB_ShaperFlag_ForceMarksToZeroWidth)
102 + HB_FixupZeroWidth(item);
103 return true; // nothing to do for us
106 diff --git a/src/harfbuzz-shaper.h b/src/harfbuzz-shaper.h
107 index ab5c07a..72c9aa3 100644
108 --- a/src/harfbuzz-shaper.h
109 +++ b/src/harfbuzz-shaper.h
110 @@ -170,7 +170,11 @@ typedef enum {
111 typedef enum {
112 HB_ShaperFlag_Default = 0,
113 HB_ShaperFlag_NoKerning = 1,
114 - HB_ShaperFlag_UseDesignMetrics = 2
115 + HB_ShaperFlag_UseDesignMetrics = 1 << 1,
116 + /* Arabic vowels in some fonts (Times New Roman, at least) have
117 + non-zero advances, when they should be zero. Setting this shaper
118 + flag causes us to zero out the advances for mark glyphs. */
119 + HB_ShaperFlag_ForceMarksToZeroWidth = 1 << 2
120 } HB_ShaperFlag;
124 diff --git a/third_party/harfbuzz/contrib/harfbuzz-freetype.c b/third_party/harfbuzz
125 index a2962df..f6a1e1a 100644
126 --- a/third_party/harfbuzz/contrib/harfbuzz-freetype.c
127 +++ b/third_party/harfbuzz/contrib/harfbuzz-freetype.c
128 @@ -21,7 +21,8 @@ hb_freetype_string_to_glyphs(HB_Font font,
129 if (len > *numGlyphs)
130 return 0;
132 - size_t i = 0, j = 0;
133 + ssize_t i = 0;
134 + hb_uint32 j = 0;
135 while (i < len) {
136 const uint32_t cp = utf16_to_code_point(chars, len, &i);
137 glyphs[j++] = FT_Get_Char_Index(face, cp);
138 @@ -53,7 +54,7 @@ static HB_Bool
139 hb_freetype_can_render(HB_Font font, const HB_UChar16 *chars, hb_uint32 len) {
140 FT_Face face = (FT_Face)font->userData;
142 - size_t i = 0;
143 + ssize_t i = 0;
144 while (i < len) {
145 const uint32_t cp = utf16_to_code_point(chars, len, &i);
146 if (FT_Get_Char_Index(face, cp) == 0)