summarylogtreecommitdiffstats
path: root/add_mozilla_geckoextra.patch
blob: cd2dadf0da29d0003329df596d91644ddfd28f4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
diff -urN a/include/graphite2/GraphiteExtra.h b/include/graphite2/GraphiteExtra.h
--- a/include/graphite2/GraphiteExtra.h	1970-01-01 01:00:00.000000000 +0100
+++ b/include/graphite2/GraphiteExtra.h	2020-05-08 23:05:53.361133478 +0200
@@ -0,0 +1,42 @@
+// -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+// vim: set ts=2 et sw=2 tw=80:
+// This Source Code is subject to the terms of the Mozilla Public License
+// version 2.0 (the "License"). You can obtain a copy of the License at
+// http://mozilla.org/MPL/2.0/.
+
+#ifndef GraphiteExtra_h__
+#define GraphiteExtra_h__
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "graphite2/Segment.h"
+
+typedef struct {
+  uint32_t baseChar;  // in UTF16 code units, not Unicode character indices
+  uint32_t baseGlyph;
+  uint32_t nChars;  // UTF16 code units
+  uint32_t nGlyphs;
+} gr_glyph_to_char_cluster;
+
+typedef struct {
+  gr_glyph_to_char_cluster* clusters;
+  uint16_t* gids;
+  float* xLocs;
+  float* yLocs;
+  uint32_t cIndex;
+} gr_glyph_to_char_association;
+
+gr_glyph_to_char_association* gr_get_glyph_to_char_association(
+    gr_segment* aSegment, uint32_t aLength, const char16_t* aText);
+
+void gr_free_char_association(gr_glyph_to_char_association* aData);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ Kein Zeilenumbruch am Dateiende.
diff -urN a/include/graphite2/GraphiteStructsForRLBox.h b/include/graphite2/GraphiteStructsForRLBox.h
--- a/include/graphite2/GraphiteStructsForRLBox.h	1970-01-01 01:00:00.000000000 +0100
+++ b/include/graphite2/GraphiteStructsForRLBox.h	2020-05-08 23:05:53.361133478 +0200
@@ -0,0 +1,67 @@
+// -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+// vim: set ts=2 et sw=2 tw=80:
+// This Source Code is subject to the terms of the Mozilla Public License
+// version 2.0 (the "License"). You can obtain a copy of the License at
+// http://mozilla.org/MPL/2.0/.
+
+#ifndef GraphiteStructsForRLBox_h__
+#define GraphiteStructsForRLBox_h__
+
+#if defined(__clang__)
+#  pragma clang diagnostic push
+#  pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
+#elif defined(__GNUC__) || defined(__GNUG__)
+// Can't turn off the variadic macro warning emitted from -pedantic
+#  pragma GCC system_header
+#elif defined(_MSC_VER)
+// Doesn't seem to emit the warning
+#else
+// Don't know the compiler... just let it go through
+#endif
+
+#define sandbox_fields_reflection_graphite_class_gr_font_ops(f, g, ...)                       \
+  f(size_t, size, FIELD_NORMAL, ##__VA_ARGS__) g()                                            \
+  f(float (*)(const void*, unsigned short), glyph_advance_x, FIELD_NORMAL, ##__VA_ARGS__) g() \
+  f(float (*)(const void*, unsigned short), glyph_advance_y, FIELD_NORMAL, ##__VA_ARGS__) g()
+
+#define sandbox_fields_reflection_graphite_class_gr_face_ops(f, g, ...)                              \
+  f(size_t, size, FIELD_NORMAL, ##__VA_ARGS__) g()                                                   \
+  f(const void* (*)(const void*, unsigned int, size_t*), get_table, FIELD_NORMAL, ##__VA_ARGS__) g() \
+  f(void (*)(const void*, const void*), release_table, FIELD_NORMAL, ##__VA_ARGS__) g()
+
+#define sandbox_fields_reflection_graphite_class_gr_glyph_to_char_cluster(f, g, ...) \
+  f(unsigned int, baseChar, FIELD_NORMAL, ##__VA_ARGS__) g()                               \
+  f(unsigned int, baseGlyph, FIELD_NORMAL, ##__VA_ARGS__) g()                              \
+  f(unsigned int, nChars, FIELD_NORMAL, ##__VA_ARGS__) g()                                 \
+  f(unsigned int, nGlyphs, FIELD_NORMAL, ##__VA_ARGS__) g()
+
+#define sandbox_fields_reflection_graphite_class_gr_glyph_to_char_association(f, g, ...) \
+  f(gr_glyph_to_char_cluster*, clusters, FIELD_NORMAL, ##__VA_ARGS__) g()           \
+  f(unsigned short*, gids, FIELD_NORMAL, ##__VA_ARGS__) g()                               \
+  f(float*, xLocs, FIELD_NORMAL, ##__VA_ARGS__) g()                                       \
+  f(float*, yLocs, FIELD_NORMAL, ##__VA_ARGS__) g()                                       \
+  f(unsigned int, cIndex, FIELD_NORMAL, ##__VA_ARGS__) g()
+
+#define sandbox_fields_reflection_graphite_class_gr_faceinfo(f, g, ...)                    \
+  f(short, extra_ascent, FIELD_NORMAL, ##__VA_ARGS__) g()                                  \
+  f(short, extra_descent, FIELD_NORMAL, ##__VA_ARGS__) g()                                 \
+  f(short, upem, FIELD_NORMAL, ##__VA_ARGS__) g()                                          \
+  f(gr_faceinfo::gr_space_contextuals, space_contextuals, FIELD_NORMAL, ##__VA_ARGS__) g() \
+  f(unsigned int, has_bidi_pass, FIELD_NORMAL, ##__VA_ARGS__) g()
+  // Remaining bitfields skipped, as bitfields are not fully supported
+
+#define sandbox_fields_reflection_graphite_allClasses(f, ...)                  \
+  f(gr_font_ops, graphite, ##__VA_ARGS__)                                      \
+  f(gr_face_ops, graphite, ##__VA_ARGS__)                                      \
+  f(gr_glyph_to_char_cluster, graphite, ##__VA_ARGS__)                         \
+  f(gr_glyph_to_char_association, graphite, ##__VA_ARGS__)                     \
+  f(gr_faceinfo, graphite, ##__VA_ARGS__)
+
+#if defined(__clang__)
+#  pragma clang diagnostic pop
+#elif defined(__GNUC__) || defined(__GNUG__)
+#elif defined(_MSC_VER)
+#else
+#endif
+
+#endif
\ Kein Zeilenumbruch am Dateiende.
Binärdateien a/python/graphite2/__pycache__/__init__.cpython-38.pyc und b/python/graphite2/__pycache__/__init__.cpython-38.pyc sind verschieden.
diff -urN a/src/CMakeLists.txt b/src/CMakeLists.txt
--- a/src/CMakeLists.txt	2020-05-08 23:05:41.289381019 +0200
+++ b/src/CMakeLists.txt	2020-05-08 23:05:53.361133478 +0200
@@ -59,9 +59,11 @@
     ../include/graphite2/Segment.h
     ../include/graphite2/Types.h
     ../include/graphite2/Log.h
+    ../include/graphite2/GraphiteExtra.h
+    ../include/graphite2/GraphiteStructsForRLBox.h
     )
 
-file(GLOB PRIVATE_HEADERS inc/*.h)
+file(GLOB PRIVATE_HEADERS inc/*.h )
 
 add_library(graphite2
     ${GRAPHITE2_VM_TYPE}_machine.cpp
@@ -92,6 +94,7 @@
     Sparse.cpp
     TtfUtil.cpp
     UtfCodec.cpp
+    GraphiteExtra.cpp
     ${FILEFACE}
     ${TRACING})
 
diff -urN a/src/files.mk b/src/files.mk
--- a/src/files.mk	2020-05-08 23:05:41.290380998 +0200
+++ b/src/files.mk	2020-05-08 23:05:53.361133478 +0200
@@ -67,7 +67,9 @@
     $($(_NS)_BASE)/src/Slot.cpp \
     $($(_NS)_BASE)/src/Sparse.cpp \
     $($(_NS)_BASE)/src/TtfUtil.cpp \
-    $($(_NS)_BASE)/src/UtfCodec.cpp
+    $($(_NS)_BASE)/src/UtfCodec.cpp \
+    $($(_NS)_BASE)/src/GraphiteExtra.cpp
+
 
 $(_NS)_PRIVATE_HEADERS = \
     $($(_NS)_BASE)/src/inc/bits.h \
@@ -111,4 +113,6 @@
     $($(_NS)_BASE)/include/graphite2/Font.h \
     $($(_NS)_BASE)/include/graphite2/Log.h \
     $($(_NS)_BASE)/include/graphite2/Segment.h \
-    $($(_NS)_BASE)/include/graphite2/Types.h
+    $($(_NS)_BASE)/include/graphite2/Types.h \
+    $($(_NS)_BASE)/include/graphite2/GraphiteExtra.h
+    $($(_NS)_BASE)/include/graphite2/GraphiteStructsForRLBox.h
diff -urN a/src/GraphiteExtra.cpp b/src/GraphiteExtra.cpp
--- a/src/GraphiteExtra.cpp	1970-01-01 01:00:00.000000000 +0100
+++ b/src/GraphiteExtra.cpp	2020-05-08 23:05:53.361133478 +0200
@@ -0,0 +1,167 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "graphite2/Font.h"
+#include "graphite2/Segment.h"
+#include "graphite2/GraphiteExtra.h"
+
+#include <stdlib.h>
+#include <memory>
+#include <limits>
+
+#define CHECK(cond, str) \
+  do {                   \
+    if (!(cond)) {       \
+      return false;      \
+    }                    \
+  } while (false)
+
+// High surrogates are in the range 0xD800 -- OxDBFF
+#define NS_IS_HIGH_SURROGATE(u) ((uint32_t(u) & 0xFFFFFC00) == 0xD800)
+// Low surrogates are in the range 0xDC00 -- 0xDFFF
+#define NS_IS_LOW_SURROGATE(u) ((uint32_t(u) & 0xFFFFFC00) == 0xDC00)
+
+#define IS_POWER_OF_2(n) (n & (n - 1)) == 0
+
+typedef gr_glyph_to_char_cluster Cluster;
+
+// returns whether successful
+static bool LoopThrough(gr_segment* aSegment, const uint32_t aLength,
+                        const uint32_t aGlyphCount, const char16_t* aText,
+                        uint32_t& aCIndex, Cluster* aClusters, uint16_t* aGids,
+                        float* aXLocs, float* aYLocs) {
+  // walk through the glyph slots and check which original character
+  // each is associated with
+  uint32_t gIndex = 0;  // glyph slot index
+  for (const gr_slot* slot = gr_seg_first_slot(aSegment); slot != nullptr;
+       slot = gr_slot_next_in_segment(slot), gIndex++) {
+    CHECK(gIndex < aGlyphCount, "iterating past glyphcount");
+    uint32_t before =
+        gr_cinfo_base(gr_seg_cinfo(aSegment, gr_slot_before(slot)));
+    uint32_t after = gr_cinfo_base(gr_seg_cinfo(aSegment, gr_slot_after(slot)));
+    aGids[gIndex] = gr_slot_gid(slot);
+    aXLocs[gIndex] = gr_slot_origin_X(slot);
+    aYLocs[gIndex] = gr_slot_origin_Y(slot);
+
+    // if this glyph has a "before" character index that precedes the
+    // current cluster's char index, we need to merge preceding
+    // aClusters until it gets included
+    while (before < aClusters[aCIndex].baseChar && aCIndex > 0) {
+      aClusters[aCIndex - 1].nChars += aClusters[aCIndex].nChars;
+      aClusters[aCIndex - 1].nGlyphs += aClusters[aCIndex].nGlyphs;
+      --aCIndex;
+    }
+
+    // if there's a gap between the current cluster's base character and
+    // this glyph's, extend the cluster to include the intervening chars
+    if (gr_slot_can_insert_before(slot) && aClusters[aCIndex].nChars &&
+        before >= aClusters[aCIndex].baseChar + aClusters[aCIndex].nChars) {
+      CHECK(aCIndex < aLength - 1, "aCIndex at end of word");
+      Cluster& c = aClusters[aCIndex + 1];
+      c.baseChar = aClusters[aCIndex].baseChar + aClusters[aCIndex].nChars;
+      c.nChars = before - c.baseChar;
+      c.baseGlyph = gIndex;
+      c.nGlyphs = 0;
+      ++aCIndex;
+    }
+
+    // increment cluster's glyph count to include current slot
+    CHECK(aCIndex < aLength, "aCIndex beyond word length");
+    ++aClusters[aCIndex].nGlyphs;
+
+    // bump |after| index if it falls in the middle of a surrogate pair
+    if (NS_IS_HIGH_SURROGATE(aText[after]) && after < aLength - 1 &&
+        NS_IS_LOW_SURROGATE(aText[after + 1])) {
+      after++;
+    }
+
+    // extend cluster if necessary to reach the glyph's "after" index
+    if (aClusters[aCIndex].baseChar + aClusters[aCIndex].nChars < after + 1) {
+      aClusters[aCIndex].nChars = after + 1 - aClusters[aCIndex].baseChar;
+    }
+  }
+
+  // Succeeded
+  return true;
+}
+
+static gr_glyph_to_char_association* calloc_glyph_to_char_association(
+    uint32_t aGlyphCount, uint32_t aLength) {
+  using Type1 = gr_glyph_to_char_association;
+  using Type2 = gr_glyph_to_char_cluster;
+  using Type3 = float;
+  using Type4 = float;
+  using Type5 = uint16_t;
+
+  // We are allocating memory in a pool. To avoid dealing with thorny alignment
+  // issues, we allocate from most to least aligned
+  static_assert(
+      alignof(Type1) >= alignof(Type2) && alignof(Type2) >= alignof(Type3) &&
+          alignof(Type3) >= alignof(Type4) && alignof(Type4) >= alignof(Type5),
+      "Unexpected alignments of types");
+
+  const uint64_t size1 = sizeof(Type1) * static_cast<uint64_t>(1);
+  const uint64_t size2 = sizeof(Type2) * static_cast<uint64_t>(aLength);
+  const uint64_t size3 = sizeof(Type3) * static_cast<uint64_t>(aGlyphCount);
+  const uint64_t size4 = sizeof(Type4) * static_cast<uint64_t>(aGlyphCount);
+  const uint64_t size5 = sizeof(Type5) * static_cast<uint64_t>(aGlyphCount);
+
+  uint64_t totalSize = size1 + size2 + size3 + size4 + size5;
+
+  if (totalSize > std::numeric_limits<uint32_t>::max()) {
+    // allocation request got too large
+    return nullptr;
+  }
+
+  char* const memoryPool = static_cast<char*>(calloc(1, totalSize));
+  if (!memoryPool) {
+    return nullptr;
+  }
+
+  char* currentPoolFront = memoryPool;
+
+  auto data = reinterpret_cast<Type1*>(currentPoolFront);
+  currentPoolFront += size1;
+  data->clusters = reinterpret_cast<Type2*>(currentPoolFront);
+  currentPoolFront += size2;
+  data->xLocs = reinterpret_cast<Type3*>(currentPoolFront);
+  currentPoolFront += size3;
+  data->yLocs = reinterpret_cast<Type4*>(currentPoolFront);
+  currentPoolFront += size4;
+  data->gids = reinterpret_cast<Type5*>(currentPoolFront);
+
+  return data;
+}
+
+// returns nullptr on failure and the glyph to char association on success
+gr_glyph_to_char_association* gr_get_glyph_to_char_association(
+    gr_segment* aSegment, uint32_t aLength, const char16_t* aText) {
+  uint32_t glyphCount = gr_seg_n_slots(aSegment);
+
+  gr_glyph_to_char_association* data =
+      calloc_glyph_to_char_association(glyphCount, aLength);
+  if (!data) {
+    return nullptr;
+  }
+
+  bool succeeded =
+      LoopThrough(aSegment, aLength, glyphCount, aText, data->cIndex,
+                  data->clusters, data->gids, data->xLocs, data->yLocs);
+  if (!succeeded) {
+    gr_free_char_association(data);
+    return nullptr;
+  }
+  return data;
+}
+
+void gr_free_char_association(gr_glyph_to_char_association* aData) {
+  free(aData);
+}
+
+#undef CHECK
+#undef NS_IS_HIGH_SURROGATE
+#undef NS_IS_LOW_SURROGATE
+#undef IS_POWER_OF_2