mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-29 01:23:56 +01:00
Merge branch 'main' into codex-review-pr-5733
This commit is contained in:
238 files changed
+4019
-1285
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -34,6 +34,7 @@ tests = [
|
||||
'test-ot-layout.c',
|
||||
'test-ot-ligature-carets.c',
|
||||
'test-ot-name.c',
|
||||
'test-ot-nullable-output.c',
|
||||
'test-ot-math.c',
|
||||
'test-ot-meta.c',
|
||||
'test-ot-metrics.c',
|
||||
|
||||
@@ -3,11 +3,7 @@ start transform 1 0 0 1 0 0
|
||||
push group
|
||||
push group
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 159
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 128 128 128 102
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 159 solid 128 128 128 102
|
||||
end transform
|
||||
pop group mode 3
|
||||
pop group mode 3
|
||||
|
||||
@@ -29,25 +29,13 @@ start transform 1 0 0 1 0 0
|
||||
end clip
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 15
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 145 103 77 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 15 solid 145 103 77 255
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 16
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 30 136 229 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 16 solid 30 136 229 255
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 21
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 145 103 77 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 21 solid 145 103 77 255
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 16
|
||||
@@ -62,11 +50,7 @@ start transform 1 0 0 1 0 0
|
||||
end clip
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 18
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 66 66 66 51
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 18 solid 66 66 66 51
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 19
|
||||
@@ -85,11 +69,7 @@ start transform 1 0 0 1 0 0
|
||||
end clip
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 20
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 145 103 77 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 20 solid 145 103 77 255
|
||||
end transform
|
||||
end clip
|
||||
end transform
|
||||
@@ -30,25 +30,13 @@ start transform 1 0 0.2 1 0 0
|
||||
end clip
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 15
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 145 103 77 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 15 solid 145 103 77 255
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 16
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 30 136 229 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 16 solid 30 136 229 255
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 21
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 145 103 77 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 21 solid 145 103 77 255
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 16
|
||||
@@ -63,11 +51,7 @@ start transform 1 0 0.2 1 0 0
|
||||
end clip
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 18
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 66 66 66 51
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 18 solid 66 66 66 51
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 19
|
||||
@@ -86,11 +70,7 @@ start transform 1 0 0.2 1 0 0
|
||||
end clip
|
||||
end transform
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 20
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 145 103 77 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 20 solid 145 103 77 255
|
||||
end transform
|
||||
end clip
|
||||
end transform
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
start transform 1 0 0.3 1 0 0
|
||||
start clip glyph 8
|
||||
solid 81 61 50 255
|
||||
end clip
|
||||
start clip glyph 9
|
||||
solid 245 185 68 255
|
||||
end clip
|
||||
start clip glyph 10
|
||||
solid 224 142 55 255
|
||||
end clip
|
||||
start clip glyph 11
|
||||
solid 245 202 86 255
|
||||
end clip
|
||||
fill glyph 8 solid 81 61 50 255
|
||||
fill glyph 9 solid 245 185 68 255
|
||||
fill glyph 10 solid 224 142 55 255
|
||||
fill glyph 11 solid 245 202 86 255
|
||||
end transform
|
||||
@@ -1,14 +1,6 @@
|
||||
start transform 1 0 0.3 1 0 0
|
||||
start clip glyph 12
|
||||
solid 81 61 50 255
|
||||
end clip
|
||||
start clip glyph 13
|
||||
solid 245 185 68 255
|
||||
end clip
|
||||
start clip glyph 14
|
||||
solid 224 142 55 255
|
||||
end clip
|
||||
start clip glyph 15
|
||||
solid 245 202 86 255
|
||||
end clip
|
||||
fill glyph 12 solid 81 61 50 255
|
||||
fill glyph 13 solid 245 185 68 255
|
||||
fill glyph 14 solid 224 142 55 255
|
||||
fill glyph 15 solid 245 202 86 255
|
||||
end transform
|
||||
@@ -1,12 +1,4 @@
|
||||
start clip glyph 16
|
||||
solid 81 61 50 255
|
||||
end clip
|
||||
start clip glyph 17
|
||||
solid 245 185 68 255
|
||||
end clip
|
||||
start clip glyph 18
|
||||
solid 224 142 55 255
|
||||
end clip
|
||||
start clip glyph 19
|
||||
solid 245 202 86 255
|
||||
end clip
|
||||
fill glyph 16 solid 81 61 50 255
|
||||
fill glyph 17 solid 245 185 68 255
|
||||
fill glyph 18 solid 224 142 55 255
|
||||
fill glyph 19 solid 245 202 86 255
|
||||
@@ -1,20 +1,12 @@
|
||||
start transform 1 0 0 1 0 0
|
||||
push group
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 3
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 0 0 255 128
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 3 solid 0 0 255 128
|
||||
end transform
|
||||
push group
|
||||
start transform 1 0.268 0 1 0 -134
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 3
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 255 165 0 179
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 3 solid 255 165 0 179
|
||||
end transform
|
||||
end transform
|
||||
pop group mode 4
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
start transform 1 0 0 1 0 0
|
||||
push group
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 3
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 0 0 255 128
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 3 solid 0 0 255 128
|
||||
end transform
|
||||
push group
|
||||
start transform 1 0 0 1 100 0
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 3
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 255 165 0 179
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 3 solid 255 165 0 179
|
||||
end transform
|
||||
end transform
|
||||
pop group mode 4
|
||||
|
||||
@@ -1,30 +1,18 @@
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip rectangle 0 0 1e+03 1e+03
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 3
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 0 0 0 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 3 solid 0 0 0 255
|
||||
end transform
|
||||
push group
|
||||
start transform 0.5 0 0 0.5 166 334
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 2
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 255 220 1 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 2 solid 255 220 1 255
|
||||
end transform
|
||||
end transform
|
||||
push group
|
||||
start transform 0.5 0 0 0.5 334 166
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 2
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 104 199 232 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 2 solid 104 199 232 255
|
||||
end transform
|
||||
end transform
|
||||
pop group mode 3
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip rectangle 100 250 900 950
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 154
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 0 0 0 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 154 solid 0 0 0 255
|
||||
end transform
|
||||
end clip
|
||||
end transform
|
||||
@@ -1,3 +1 @@
|
||||
start clip glyph 165
|
||||
solid 0 0 0 255
|
||||
end clip
|
||||
fill glyph 165 solid 0 0 0 255
|
||||
@@ -1,3 +1 @@
|
||||
start clip glyph 175
|
||||
solid 0 0 0 255
|
||||
end clip
|
||||
fill glyph 175 solid 0 0 0 255
|
||||
@@ -1,3 +1 @@
|
||||
start clip glyph 6
|
||||
solid 0 0 0 255
|
||||
end clip
|
||||
fill glyph 6 solid 0 0 0 255
|
||||
@@ -1,20 +1,12 @@
|
||||
start transform 1 0 0 1 0 0
|
||||
push group
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 3
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 0 0 255 128
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 3 solid 0 0 255 128
|
||||
end transform
|
||||
push group
|
||||
start transform 1 0.268 0 1 0 -134
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 3
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 255 165 0 179
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 3 solid 255 165 0 179
|
||||
end transform
|
||||
end transform
|
||||
pop group mode 4
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
start transform 1 0 0 1 0 0
|
||||
push group
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 3
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 0 0 255 128
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 3 solid 0 0 255 128
|
||||
end transform
|
||||
push group
|
||||
start transform 1 0 0 1 100 0
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 3
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 255 165 0 179
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 3 solid 255 165 0 179
|
||||
end transform
|
||||
end transform
|
||||
pop group mode 4
|
||||
|
||||
@@ -1,30 +1,18 @@
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip rectangle 0 0 1e+03 1e+03
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 3
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 0 0 0 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 3 solid 0 0 0 255
|
||||
end transform
|
||||
push group
|
||||
start transform 0.5 0 0 0.5 166 334
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 2
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 255 220 1 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 2 solid 255 220 1 255
|
||||
end transform
|
||||
end transform
|
||||
push group
|
||||
start transform 0.5 0 0 0.5 334 166
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 2
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 104 199 232 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 2 solid 104 199 232 255
|
||||
end transform
|
||||
end transform
|
||||
pop group mode 3
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip rectangle 100 250 900 950
|
||||
start transform 1 0 0 1 0 0
|
||||
start clip glyph 154
|
||||
start transform 1 0 0 1 0 0
|
||||
solid 0 0 0 255
|
||||
end transform
|
||||
end clip
|
||||
fill glyph 154 solid 0 0 0 255
|
||||
end transform
|
||||
end clip
|
||||
end transform
|
||||
@@ -1,3 +1 @@
|
||||
start clip glyph 165
|
||||
solid 0 0 0 255
|
||||
end clip
|
||||
fill glyph 165 solid 0 0 0 255
|
||||
@@ -1,3 +1 @@
|
||||
start clip glyph 175
|
||||
solid 0 0 0 255
|
||||
end clip
|
||||
fill glyph 175 solid 0 0 0 255
|
||||
@@ -1,3 +1 @@
|
||||
start clip glyph 6
|
||||
solid 0 0 0 255
|
||||
end clip
|
||||
fill glyph 6 solid 0 0 0 255
|
||||
@@ -49,6 +49,64 @@ test_collect_unicodes_format4 (void)
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
static void
|
||||
test_collect_unicodes_format4_with_range_offsets_and_deltas (void)
|
||||
{
|
||||
const char cmap_data[44] = {
|
||||
0, 0, 0, 1, /* cmap header */
|
||||
0, 0, 0, 3, 0, 0, 0, 12, /* encoding records */
|
||||
/* cmap 4 */
|
||||
0, 4, /* format */
|
||||
0, 44, /* length */
|
||||
0, 0, /* lang */
|
||||
0, 2, /* segcountx2 */
|
||||
0, 0, /* search range */
|
||||
0, 0, /* entry selector */
|
||||
0, 0, /* range shift */
|
||||
0, 73, /* end code [0] */
|
||||
0, 0, /* pad */
|
||||
0, 70, /* start code [0] */
|
||||
0, 5, /* id delta [0] */
|
||||
0, 2, /* id range offset [0] */
|
||||
0, 8, /* glyph id u70 */
|
||||
0, 5, /* glyph id u71 */
|
||||
0, 0, /* glyph id u72 */
|
||||
0, 12, /* glyph id u73 */
|
||||
};
|
||||
|
||||
hb_blob_t* cmap = hb_blob_create(cmap_data, 44, HB_MEMORY_MODE_READONLY, 0, 0);
|
||||
hb_face_t* face = hb_face_builder_create();
|
||||
hb_face_builder_add_table(face, HB_TAG('c', 'm', 'a', 'p'), cmap);
|
||||
hb_blob_destroy(cmap);
|
||||
|
||||
hb_set_t *codepoints = hb_set_create();
|
||||
hb_map_t *mapping = hb_map_create();
|
||||
hb_codepoint_t cp;
|
||||
|
||||
hb_face_collect_unicodes (face, codepoints);
|
||||
|
||||
cp = HB_SET_VALUE_INVALID;
|
||||
g_assert_true (hb_set_next (codepoints, &cp));
|
||||
g_assert_cmpuint (70, ==, cp);
|
||||
g_assert_true (hb_set_next (codepoints, &cp));
|
||||
g_assert_cmpuint (71, ==, cp);
|
||||
g_assert_true (hb_set_next (codepoints, &cp));
|
||||
g_assert_cmpuint (73, ==, cp);
|
||||
g_assert_false (hb_set_next (codepoints, &cp));
|
||||
|
||||
hb_set_clear(codepoints);
|
||||
hb_face_collect_nominal_glyph_mapping(face, mapping, codepoints);
|
||||
|
||||
g_assert_cmpuint (hb_map_get(mapping, 70), ==, 8 + 5);
|
||||
g_assert_cmpuint (hb_map_get(mapping, 71), ==, 5 + 5);
|
||||
g_assert_false (hb_map_has(mapping, 72));
|
||||
g_assert_cmpuint (hb_map_get(mapping, 73), ==, 12 + 5);
|
||||
|
||||
hb_map_destroy(mapping);
|
||||
hb_set_destroy (codepoints);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
static void
|
||||
test_collect_unicodes_format12_notdef (void)
|
||||
{
|
||||
@@ -135,6 +193,7 @@ main (int argc, char **argv)
|
||||
hb_test_add (test_collect_unicodes_format4);
|
||||
hb_test_add (test_collect_unicodes_format12);
|
||||
hb_test_add (test_collect_unicodes_format12_notdef);
|
||||
hb_test_add (test_collect_unicodes_format4_with_range_offsets_and_deltas);
|
||||
|
||||
return hb_test_run();
|
||||
}
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "hb-test.h"
|
||||
|
||||
#include <hb.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_FREETYPE
|
||||
#include <hb-ft.h>
|
||||
#endif
|
||||
@@ -128,6 +129,63 @@ test_get_table_tags_ft (void)
|
||||
FT_Done_FreeType (ft_library);
|
||||
hb_blob_destroy (blob);
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
_ft_stream_read (FT_Stream stream,
|
||||
unsigned long offset,
|
||||
unsigned char *buffer,
|
||||
unsigned long count)
|
||||
{
|
||||
hb_blob_t *blob = (hb_blob_t *) stream->descriptor.pointer;
|
||||
unsigned int length;
|
||||
const char *data = hb_blob_get_data (blob, &length);
|
||||
if (offset > length)
|
||||
return 0;
|
||||
if (count == 0) /* Seek. */
|
||||
return 0;
|
||||
if (offset + count > length)
|
||||
count = length - offset;
|
||||
memcpy (buffer, data + offset, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
_ft_stream_close (FT_Stream stream HB_UNUSED) {}
|
||||
|
||||
static void
|
||||
test_get_table_tags_ft_stream (void)
|
||||
{
|
||||
/* Exercise the streaming-face path, which (unlike an in-memory face) uses
|
||||
* hb-ft's own _hb_ft_get_table_tags callback. */
|
||||
hb_face_t *source = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
|
||||
hb_blob_t *blob = hb_face_reference_blob (source);
|
||||
hb_face_destroy (source);
|
||||
|
||||
FT_Library ft_library;
|
||||
g_assert_cmpint (0, ==, FT_Init_FreeType (&ft_library));
|
||||
|
||||
FT_StreamRec stream = {0};
|
||||
stream.size = hb_blob_get_length (blob);
|
||||
stream.descriptor.pointer = blob;
|
||||
stream.read = _ft_stream_read;
|
||||
stream.close = _ft_stream_close;
|
||||
|
||||
FT_Open_Args args = {0};
|
||||
args.flags = FT_OPEN_STREAM;
|
||||
args.stream = &stream;
|
||||
|
||||
FT_Face ft_face;
|
||||
g_assert_cmpint (0, ==, FT_Open_Face (ft_library, &args, 0, &ft_face));
|
||||
|
||||
hb_face_t *face = hb_ft_face_create (ft_face, NULL);
|
||||
|
||||
_test_get_table_tags (face);
|
||||
|
||||
hb_face_destroy (face);
|
||||
FT_Done_Face (ft_face);
|
||||
FT_Done_FreeType (ft_library);
|
||||
hb_blob_destroy (blob);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CORETEXT
|
||||
@@ -167,6 +225,7 @@ main (int argc, char **argv)
|
||||
hb_test_add (test_get_table_tags_builder);
|
||||
#ifdef HAVE_FREETYPE
|
||||
hb_test_add (test_get_table_tags_ft);
|
||||
hb_test_add (test_get_table_tags_ft_stream);
|
||||
#endif
|
||||
#ifdef HAVE_CORETEXT
|
||||
hb_test_add (test_get_table_tags_ct);
|
||||
|
||||
@@ -519,6 +519,46 @@ test_paint_recycle_blob (void)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_paint_clip_path_depth_overflow (void)
|
||||
{
|
||||
/* push_clip_path_end must honor the same clip-depth cap as
|
||||
* push_clip_glyph and push_clip_path_start. Interleaving clip
|
||||
* pushes drives clip_depth past HB_GPU_PAINT_MAX_CLIP_DEPTH before
|
||||
* the path is closed; without a bound check push_clip_path_end
|
||||
* wrote past the fixed-size clip_stack (heap-buffer-overflow). */
|
||||
hb_gpu_paint_t *p = hb_gpu_paint_create_or_fail ();
|
||||
g_assert_nonnull (p);
|
||||
hb_gpu_paint_set_scale (p, 1000, 1000);
|
||||
|
||||
hb_paint_funcs_t *pf = hb_gpu_paint_get_funcs (p);
|
||||
hb_font_t *font = hb_font_get_empty ();
|
||||
|
||||
void *draw_data = nullptr;
|
||||
hb_draw_funcs_t *df = hb_paint_push_clip_path_start (pf, p, &draw_data);
|
||||
g_assert_nonnull (df);
|
||||
|
||||
hb_draw_state_t st = HB_DRAW_STATE_DEFAULT;
|
||||
hb_draw_move_to (df, draw_data, &st, 0.f, 0.f);
|
||||
hb_draw_line_to (df, draw_data, &st, 100.f, 0.f);
|
||||
hb_draw_line_to (df, draw_data, &st, 100.f, 100.f);
|
||||
hb_draw_close_path (df, draw_data, &st);
|
||||
|
||||
/* Push more clips than the stack holds before closing the path. */
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
hb_paint_push_clip_glyph (pf, p, i, font);
|
||||
|
||||
hb_paint_push_clip_path_end (pf, p);
|
||||
|
||||
/* Overflowing the clip stack marks the paint unsupported rather
|
||||
* than writing past clip_stack, so encode returns NULL. */
|
||||
hb_blob_t *blob = hb_gpu_paint_encode (p, nullptr);
|
||||
g_assert_null (blob);
|
||||
|
||||
hb_gpu_paint_destroy (p);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_shapes (void)
|
||||
{
|
||||
@@ -633,6 +673,7 @@ main (int argc, char **argv)
|
||||
hb_test_add (test_paint_auto_clear_on_encode);
|
||||
hb_test_add (test_paint_reset);
|
||||
hb_test_add (test_paint_recycle_blob);
|
||||
hb_test_add (test_paint_clip_path_depth_overflow);
|
||||
|
||||
return hb_test_run ();
|
||||
}
|
||||
@@ -215,6 +215,30 @@ test_ot_var_axis_on_zero_named_instance (void)
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
#ifndef HB_NO_VERTICAL
|
||||
static void
|
||||
test_ot_font_v_origin_cache_invalidated_by_scale (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/Mplus1p-Regular.660E.ttf");
|
||||
hb_font_t *font = hb_font_create (face);
|
||||
hb_codepoint_t glyph;
|
||||
hb_position_t x, y1, y2;
|
||||
|
||||
g_assert_true (hb_font_get_nominal_glyph (font, 0x660E, &glyph));
|
||||
|
||||
hb_font_set_scale (font, 1000, 1000);
|
||||
g_assert_true (hb_font_get_glyph_v_origin (font, glyph, &x, &y1));
|
||||
|
||||
hb_font_set_scale (font, 1000, 2000);
|
||||
g_assert_true (hb_font_get_glyph_v_origin (font, glyph, &x, &y2));
|
||||
|
||||
g_assert_cmpint (y2, ==, y1 * 2);
|
||||
|
||||
hb_font_destroy (font);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
@@ -222,6 +246,9 @@ main (int argc, char **argv)
|
||||
|
||||
hb_test_add (test_ot_face_empty);
|
||||
hb_test_add (test_ot_var_axis_on_zero_named_instance);
|
||||
#ifndef HB_NO_VERTICAL
|
||||
hb_test_add (test_ot_font_v_origin_cache_invalidated_by_scale);
|
||||
#endif
|
||||
|
||||
return hb_test_run();
|
||||
}
|
||||
|
||||
@@ -27,8 +27,49 @@
|
||||
#include <hb.h>
|
||||
#include <hb-ot.h>
|
||||
|
||||
#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MPROTECT) && defined(HAVE_MMAP)
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#define STATIC_ARRAY_SIZE 255
|
||||
|
||||
#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MPROTECT) && defined(HAVE_MMAP)
|
||||
static void
|
||||
test_ot_layout_gdef_unsupported_version (void)
|
||||
{
|
||||
const char gdef[] = {0x87, 0x00, 0x00, 0x06, 0x30};
|
||||
long pagesize = sysconf (_SC_PAGESIZE);
|
||||
char *mapping;
|
||||
char *table;
|
||||
hb_blob_t *blob;
|
||||
hb_face_t *face;
|
||||
|
||||
g_assert_cmpint (pagesize, >, 0);
|
||||
mapping = mmap (NULL, 2 * pagesize, PROT_NONE,
|
||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
g_assert_true (mapping != MAP_FAILED);
|
||||
g_assert_cmpint (mprotect (mapping, pagesize, PROT_READ | PROT_WRITE), ==, 0);
|
||||
|
||||
table = mapping + pagesize - sizeof (gdef);
|
||||
memcpy (table, gdef, sizeof (gdef));
|
||||
g_assert_cmpint (mprotect (mapping, pagesize, PROT_READ), ==, 0);
|
||||
|
||||
face = hb_face_builder_create ();
|
||||
blob = hb_blob_create (table, sizeof (gdef), HB_MEMORY_MODE_READONLY,
|
||||
NULL, NULL);
|
||||
g_assert_true (hb_face_builder_add_table (face, HB_OT_TAG_GDEF, blob));
|
||||
hb_blob_destroy (blob);
|
||||
|
||||
g_assert_false (hb_ot_layout_has_glyph_classes (face));
|
||||
|
||||
hb_face_destroy (face);
|
||||
g_assert_cmpint (munmap (mapping, 2 * pagesize), ==, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
test_ot_layout_table_get_script_tags (void)
|
||||
{
|
||||
@@ -219,6 +260,9 @@ int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
hb_test_init (&argc, &argv);
|
||||
#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MPROTECT) && defined(HAVE_MMAP)
|
||||
hb_test_add (test_ot_layout_gdef_unsupported_version);
|
||||
#endif
|
||||
hb_test_add (test_ot_layout_table_get_script_tags);
|
||||
hb_test_add (test_ot_layout_table_find_script);
|
||||
hb_test_add (test_ot_layout_script_get_language_tags);
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright © 2026 Behdad Esfahbod
|
||||
*
|
||||
* This is part of HarfBuzz, a text shaping library.
|
||||
*
|
||||
* Permission is hereby granted, without written agreement and without
|
||||
* license or royalty fees, to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose, provided that the
|
||||
* above copyright notice and the following two paragraphs appear in
|
||||
* all copies of this software.
|
||||
*
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
||||
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*
|
||||
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
|
||||
#include "hb-test.h"
|
||||
|
||||
#include <hb-ot.h>
|
||||
#include <hb-aat.h>
|
||||
|
||||
/* Regression test for GHSA-v5mv-8hhw-vff8: the "list getter" APIs document
|
||||
* their output array as nullable ("may be NULL"; pass NULL to just query the
|
||||
* count). Passing a NULL output array together with a non-NULL count on a
|
||||
* populated table used to write through the NULL pointer and crash. Each case
|
||||
* below calls the getter with a non-NULL count and a NULL output array on a
|
||||
* font whose table is populated, and checks it returns the total without
|
||||
* crashing. */
|
||||
|
||||
static void
|
||||
test_nullable_output_cpal_colors (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/cpal-v0.ttf");
|
||||
unsigned int count = 100;
|
||||
g_assert_cmpuint (hb_ot_color_palette_get_colors (face, 0, 0, &count, NULL), ==, 2);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
static void
|
||||
test_nullable_output_colr_layers (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/cpal-v1.ttf");
|
||||
unsigned int count = 100;
|
||||
g_assert_cmpuint (hb_ot_color_glyph_get_layers (face, 2, 0, &count, NULL), ==, 2);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
static void
|
||||
test_nullable_output_meta_entries (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/meta.ttf");
|
||||
unsigned int count = 100;
|
||||
unsigned int total = hb_ot_meta_get_entry_tags (face, 0, &count, NULL);
|
||||
g_assert_cmpuint (total, >, 0);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
#ifndef HB_NO_AAT
|
||||
static void
|
||||
test_nullable_output_aat_feature_types (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/aat-feat.ttf");
|
||||
unsigned int count = 100;
|
||||
g_assert_cmpuint (hb_aat_layout_get_feature_types (face, 0, &count, NULL), ==, 11);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
static void
|
||||
test_nullable_output_aat_selector_infos (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/aat-feat.ttf");
|
||||
unsigned int count = 100;
|
||||
g_assert_cmpuint (hb_aat_layout_feature_type_get_selector_infos (
|
||||
face, HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE,
|
||||
0, &count, NULL, NULL), ==, 4);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
test_nullable_output_cv_characters (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/cv01.otf");
|
||||
unsigned int feature_index;
|
||||
if (hb_ot_layout_language_find_feature (face, HB_OT_TAG_GSUB, 0,
|
||||
HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX,
|
||||
HB_TAG ('c','v','0','1'), &feature_index))
|
||||
{
|
||||
unsigned int count = 100;
|
||||
g_assert_cmpuint (hb_ot_layout_feature_get_characters (face, HB_OT_TAG_GSUB,
|
||||
feature_index, 0,
|
||||
&count, NULL), ==, 2);
|
||||
}
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
static void
|
||||
test_nullable_output_gsub_alternates (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/SourceSansPro-Regular.otf");
|
||||
unsigned int count = 100;
|
||||
g_assert_cmpuint (hb_ot_layout_lookup_get_glyph_alternates (face, 1, 1091, 0,
|
||||
&count, NULL), ==, 7);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
static void
|
||||
test_nullable_output_table_tags (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/cpal-v0.ttf");
|
||||
unsigned int count = 100;
|
||||
unsigned int total = hb_face_get_table_tags (face, 0, &count, NULL);
|
||||
g_assert_cmpuint (total, >, 0);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
static void
|
||||
test_nullable_output_var_axis_infos (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype.abc.otf");
|
||||
unsigned int count = 100;
|
||||
unsigned int total = hb_ot_var_get_axis_infos (face, 0, &count, NULL);
|
||||
g_assert_cmpuint (total, >, 0);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
static void
|
||||
test_nullable_output_math_kernings (void)
|
||||
{
|
||||
hb_face_t *face = hb_test_open_font_file ("fonts/MathTestFontFull.otf");
|
||||
hb_font_t *font = hb_font_create (face);
|
||||
hb_codepoint_t glyph;
|
||||
if (hb_font_get_glyph_from_name (font, "I", -1, &glyph))
|
||||
{
|
||||
unsigned int count = 100;
|
||||
g_assert_cmpuint (hb_ot_math_get_glyph_kernings (font, glyph,
|
||||
HB_OT_MATH_KERN_TOP_RIGHT,
|
||||
0, &count, NULL), ==, 10);
|
||||
}
|
||||
hb_font_destroy (font);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
hb_test_init (&argc, &argv);
|
||||
|
||||
hb_test_add (test_nullable_output_cpal_colors);
|
||||
hb_test_add (test_nullable_output_colr_layers);
|
||||
hb_test_add (test_nullable_output_meta_entries);
|
||||
#ifndef HB_NO_AAT
|
||||
hb_test_add (test_nullable_output_aat_feature_types);
|
||||
hb_test_add (test_nullable_output_aat_selector_infos);
|
||||
#endif
|
||||
hb_test_add (test_nullable_output_cv_characters);
|
||||
hb_test_add (test_nullable_output_gsub_alternates);
|
||||
hb_test_add (test_nullable_output_table_tags);
|
||||
hb_test_add (test_nullable_output_var_axis_infos);
|
||||
hb_test_add (test_nullable_output_math_kernings);
|
||||
|
||||
return hb_test_run ();
|
||||
}
|
||||
@@ -291,6 +291,9 @@ test_ot_tags_to_script_and_language (void)
|
||||
test_tags_to_script_and_language ("dev2", "MAR", "Deva", "mr-x-hbsc-64657632");
|
||||
test_tags_to_script_and_language ("dev3", "MAR", "Deva", "mr");
|
||||
test_tags_to_script_and_language ("qaa", "QTZ0", "Qaaa", "x-hbot-51545a30-hbsc-71616120");
|
||||
/* Default language tag maps to a NULL language; the script-suffix path
|
||||
* must not dereference it. */
|
||||
test_tags_to_script_and_language ("DFLT", "dflt", "", NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -111,6 +111,24 @@ pop_transform (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
print (data, "end transform");
|
||||
}
|
||||
|
||||
static void
|
||||
fill_glyph (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
void *paint_data,
|
||||
hb_codepoint_t glyph,
|
||||
hb_font_t *font HB_UNUSED,
|
||||
hb_bool_t use_foreground HB_UNUSED,
|
||||
hb_color_t color,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
paint_data_t *data = paint_data;
|
||||
|
||||
print (data, "fill glyph %u solid %d %d %d %d", glyph,
|
||||
hb_color_get_red (color),
|
||||
hb_color_get_green (color),
|
||||
hb_color_get_blue (color),
|
||||
hb_color_get_alpha (color));
|
||||
}
|
||||
|
||||
static hb_bool_t
|
||||
paint_color_glyph (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
void *paint_data,
|
||||
@@ -341,6 +359,7 @@ get_test_paint_funcs (void)
|
||||
|
||||
hb_paint_funcs_set_push_transform_func (funcs, push_transform, NULL, NULL);
|
||||
hb_paint_funcs_set_pop_transform_func (funcs, pop_transform, NULL, NULL);
|
||||
hb_paint_funcs_set_fill_glyph_func (funcs, fill_glyph, NULL, NULL);
|
||||
hb_paint_funcs_set_color_glyph_func (funcs, paint_color_glyph, NULL, NULL);
|
||||
hb_paint_funcs_set_push_clip_glyph_func (funcs, push_clip_glyph, NULL, NULL);
|
||||
hb_paint_funcs_set_push_clip_rectangle_func (funcs, push_clip_rectangle, NULL, NULL);
|
||||
@@ -828,6 +847,70 @@ test_push_clip_path_round_trip (void)
|
||||
hb_draw_funcs_destroy (sink);
|
||||
}
|
||||
|
||||
/* Test the default implementation of fill_glyph does the
|
||||
* push_clip_glyph + color + pop_clip sequence. */
|
||||
static void
|
||||
test_fill_glyph_nil_decomposes (void)
|
||||
{
|
||||
hb_paint_funcs_t *funcs = hb_paint_funcs_create ();
|
||||
hb_paint_funcs_set_push_clip_glyph_func (funcs, push_clip_glyph, NULL, NULL);
|
||||
hb_paint_funcs_set_color_func (funcs, paint_color, NULL, NULL);
|
||||
hb_paint_funcs_set_pop_clip_func (funcs, pop_clip, NULL, NULL);
|
||||
hb_paint_funcs_make_immutable (funcs);
|
||||
|
||||
paint_data_t data;
|
||||
data.string = g_string_new ("");
|
||||
data.level = 0;
|
||||
|
||||
hb_paint_fill_glyph (funcs, &data, 42, hb_font_get_empty (),
|
||||
FALSE, HB_COLOR (1, 2, 3, 4));
|
||||
|
||||
g_assert_true (data.level == 0);
|
||||
g_assert_cmpstr (data.string->str, ==,
|
||||
"start clip glyph 42\n"
|
||||
" solid 3 2 1 4\n"
|
||||
"end clip\n");
|
||||
|
||||
g_string_free (data.string, TRUE);
|
||||
hb_paint_funcs_destroy (funcs);
|
||||
}
|
||||
|
||||
static void *color_glyph_user_data_seen;
|
||||
|
||||
static hb_bool_t
|
||||
color_glyph_record_user_data (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
void *paint_data HB_UNUSED,
|
||||
hb_codepoint_t glyph HB_UNUSED,
|
||||
hb_font_t *font HB_UNUSED,
|
||||
void *user_data)
|
||||
{
|
||||
color_glyph_user_data_seen = user_data;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Each callback must be handed the user_data it was registered with,
|
||||
* not another callback's. */
|
||||
static void
|
||||
test_color_glyph_user_data (void)
|
||||
{
|
||||
char color_glyph_ctx = 0;
|
||||
char push_clip_glyph_ctx = 0;
|
||||
|
||||
hb_paint_funcs_t *funcs = hb_paint_funcs_create ();
|
||||
hb_paint_funcs_set_color_glyph_func (funcs, color_glyph_record_user_data,
|
||||
&color_glyph_ctx, NULL);
|
||||
hb_paint_funcs_set_push_clip_glyph_func (funcs, push_clip_glyph,
|
||||
&push_clip_glyph_ctx, NULL);
|
||||
hb_paint_funcs_make_immutable (funcs);
|
||||
|
||||
color_glyph_user_data_seen = NULL;
|
||||
hb_paint_color_glyph (funcs, NULL, 42, hb_font_get_empty ());
|
||||
|
||||
g_assert_true (color_glyph_user_data_seen == &color_glyph_ctx);
|
||||
|
||||
hb_paint_funcs_destroy (funcs);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
@@ -840,6 +923,8 @@ main (int argc, char **argv)
|
||||
* below doesn't prevent them from running. */
|
||||
hb_test_add (test_push_clip_path_nil_returns_null);
|
||||
hb_test_add (test_push_clip_path_round_trip);
|
||||
hb_test_add (test_fill_glyph_nil_decomposes);
|
||||
hb_test_add (test_color_glyph_user_data);
|
||||
|
||||
for (unsigned int i = 0; i < G_N_ELEMENTS (paint_tests); i++)
|
||||
{
|
||||
|
||||
@@ -225,6 +225,67 @@ test_set_glyph_extents_with_transform (void)
|
||||
hb_raster_draw_destroy (rdr);
|
||||
}
|
||||
|
||||
/* ── Test 6: image paint under an overflowing transform ──────────── */
|
||||
|
||||
/* Nested scales, each representable, whose product overflows to infinity.
|
||||
* The inverse transform then carries NaN into the image sampler's texel
|
||||
* coordinates. Exercised for the float-to-int conversion, so this needs a
|
||||
* sanitizer build to catch a regression. */
|
||||
static void
|
||||
test_image_nonfinite_transform (void)
|
||||
{
|
||||
hb_raster_paint_t *paint = hb_raster_paint_create_or_fail ();
|
||||
g_assert_nonnull (paint);
|
||||
|
||||
hb_raster_extents_t ext = {0, 0, 32, 32, 0};
|
||||
hb_raster_paint_set_extents (paint, &ext);
|
||||
|
||||
hb_paint_funcs_t *funcs = hb_raster_paint_get_funcs (paint);
|
||||
|
||||
hb_paint_push_transform (funcs, paint, 1e30f, 0.f, 0.f, 1e30f, 0.f, 0.f);
|
||||
hb_paint_push_transform (funcs, paint, 1e30f, 0.f, 0.f, 1e30f, 0.f, 0.f);
|
||||
|
||||
const unsigned w = 4, h = 4;
|
||||
char pixels[w * h * 4];
|
||||
memset (pixels, 0, sizeof (pixels));
|
||||
hb_blob_t *blob = hb_blob_create (pixels, sizeof (pixels),
|
||||
HB_MEMORY_MODE_READONLY, nullptr, nullptr);
|
||||
|
||||
hb_glyph_extents_t gext = {0, 32, 32, -32};
|
||||
hb_paint_image (funcs, paint, blob, w, h,
|
||||
HB_PAINT_IMAGE_FORMAT_BGRA, 0.f, &gext);
|
||||
|
||||
hb_paint_pop_transform (funcs, paint);
|
||||
hb_paint_pop_transform (funcs, paint);
|
||||
|
||||
hb_blob_destroy (blob);
|
||||
hb_raster_paint_destroy (paint);
|
||||
}
|
||||
|
||||
/* ── Test 7: glyph extents that overflow the int grid ────────────── */
|
||||
|
||||
/* Glyph extents are int32, so a transform that scales them up puts the
|
||||
* corner coordinates far outside the int range before they are floored
|
||||
* back to the integer pixel grid. Exercised for the conversion itself,
|
||||
* so this needs a sanitizer build to catch a regression. */
|
||||
static void
|
||||
test_set_glyph_extents_overflow (void)
|
||||
{
|
||||
hb_glyph_extents_t gext = {-2000000000, 2000000000, 2000000000, -2000000000};
|
||||
|
||||
hb_raster_draw_t *rdr = hb_raster_draw_create_or_fail ();
|
||||
g_assert_nonnull (rdr);
|
||||
hb_raster_draw_set_transform (rdr, 1000.f, 0.f, 0.f, 1000.f, 0.f, 0.f);
|
||||
hb_raster_draw_set_glyph_extents (rdr, &gext);
|
||||
hb_raster_draw_destroy (rdr);
|
||||
|
||||
hb_raster_paint_t *paint = hb_raster_paint_create_or_fail ();
|
||||
g_assert_nonnull (paint);
|
||||
hb_raster_paint_set_transform (paint, 1000.f, 0.f, 0.f, 1000.f, 0.f, 0.f);
|
||||
hb_raster_paint_set_glyph_extents (paint, &gext);
|
||||
hb_raster_paint_destroy (paint);
|
||||
}
|
||||
|
||||
/* ── main ────────────────────────────────────────────────────────── */
|
||||
|
||||
int
|
||||
@@ -237,6 +298,8 @@ main (int argc, char **argv)
|
||||
hb_test_add (test_subpixel_edge);
|
||||
hb_test_add (test_transform);
|
||||
hb_test_add (test_set_glyph_extents_with_transform);
|
||||
hb_test_add (test_image_nonfinite_transform);
|
||||
hb_test_add (test_set_glyph_extents_overflow);
|
||||
|
||||
return hb_test_run ();
|
||||
}
|
||||
@@ -336,6 +336,54 @@ test_subset_cff1_j_retaingids (void)
|
||||
hb_face_destroy (face_41_4c2e);
|
||||
}
|
||||
|
||||
static void
|
||||
test_subset_cff1_identity_charset (void)
|
||||
{
|
||||
/* The flag has no effect on a name-keyed font, so this is the same output
|
||||
* as test_subset_cff1(). */
|
||||
hb_face_t *face_abc = hb_test_open_font_file ("fonts/SourceSansPro-Regular.abc.otf");
|
||||
hb_face_t *face_ac = hb_test_open_font_file ("fonts/SourceSansPro-Regular.ac.otf");
|
||||
|
||||
hb_set_t *codepoints = hb_set_create ();
|
||||
hb_subset_input_t *input;
|
||||
hb_face_t *face_abc_subset;
|
||||
hb_set_add (codepoints, 'a');
|
||||
hb_set_add (codepoints, 'c');
|
||||
input = hb_subset_test_create_input (codepoints);
|
||||
hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET);
|
||||
face_abc_subset = hb_subset_test_create_subset (face_abc, input);
|
||||
hb_set_destroy (codepoints);
|
||||
|
||||
hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('C','F','F',' '));
|
||||
|
||||
hb_face_destroy (face_abc_subset);
|
||||
hb_face_destroy (face_abc);
|
||||
hb_face_destroy (face_ac);
|
||||
}
|
||||
|
||||
static void
|
||||
test_subset_cff1_j_identity_charset (void)
|
||||
{
|
||||
hb_face_t *face_41_3041_4c2e = hb_test_open_font_file ("fonts/SourceHanSans-Regular.41,3041,4C2E.otf");
|
||||
hb_face_t *face_41_4c2e = hb_test_open_font_file ("fonts/SourceHanSans-Regular.41,4C2E.identity.otf");
|
||||
|
||||
hb_set_t *codepoints = hb_set_create ();
|
||||
hb_subset_input_t *input;
|
||||
hb_face_t *face_41_3041_4c2e_subset;
|
||||
hb_set_add (codepoints, 0x41);
|
||||
hb_set_add (codepoints, 0x4C2E);
|
||||
input = hb_subset_test_create_input (codepoints);
|
||||
hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_CFF_IDENTITY_CHARSET);
|
||||
face_41_3041_4c2e_subset = hb_subset_test_create_subset (face_41_3041_4c2e, input);
|
||||
hb_set_destroy (codepoints);
|
||||
|
||||
hb_subset_test_check (face_41_4c2e, face_41_3041_4c2e_subset, HB_TAG ('C','F','F',' '));
|
||||
|
||||
hb_face_destroy (face_41_3041_4c2e_subset);
|
||||
hb_face_destroy (face_41_3041_4c2e);
|
||||
hb_face_destroy (face_41_4c2e);
|
||||
}
|
||||
|
||||
#ifdef HB_EXPERIMENTAL_API
|
||||
static void
|
||||
test_subset_cff1_iftb_requirements (void)
|
||||
@@ -383,6 +431,8 @@ main (int argc, char **argv)
|
||||
hb_test_add (test_subset_cff1_dotsection);
|
||||
hb_test_add (test_subset_cff1_retaingids);
|
||||
hb_test_add (test_subset_cff1_j_retaingids);
|
||||
hb_test_add (test_subset_cff1_identity_charset);
|
||||
hb_test_add (test_subset_cff1_j_identity_charset);
|
||||
|
||||
#ifdef HB_EXPERIMENTAL_API
|
||||
hb_test_add (test_subset_cff1_iftb_requirements);
|
||||
|
||||
+199
-1
@@ -338,7 +338,7 @@ test_subset_cff2_get_charstring_data_no_cff (void)
|
||||
|
||||
hb_blob_t* cs0 = hb_subset_cff2_get_charstring_data (face, 0);
|
||||
g_assert_true (hb_blob_get_length (cs0) == 0);
|
||||
|
||||
|
||||
hb_face_destroy (builder);
|
||||
hb_blob_destroy (face_blob);
|
||||
hb_face_destroy (face);
|
||||
@@ -403,6 +403,202 @@ test_subset_cff2_get_charstring_data_lifetime (void)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HB_EXPERIMENTAL_API
|
||||
static void
|
||||
test_subset_input_to_string (void)
|
||||
{
|
||||
/* Test NULL input */
|
||||
g_assert_null (hb_subset_input_to_string_or_fail (NULL));
|
||||
|
||||
/* Test default input -> empty string */
|
||||
{
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
hb_blob_t *blob = hb_subset_input_to_string_or_fail (input);
|
||||
g_assert_nonnull (blob);
|
||||
unsigned len = 0;
|
||||
const char *data = hb_blob_get_data (blob, &len);
|
||||
g_assert_cmpint (len, ==, 1);
|
||||
g_assert_cmpstr (data, ==, "");
|
||||
hb_blob_destroy (blob);
|
||||
hb_subset_input_destroy (input);
|
||||
}
|
||||
|
||||
/* Test unicodes ranges */
|
||||
{
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
hb_set_t *unicodes = hb_subset_input_unicode_set (input);
|
||||
hb_set_add (unicodes, 0x41);
|
||||
hb_set_add (unicodes, 0x42);
|
||||
hb_set_add (unicodes, 0x43);
|
||||
hb_set_add (unicodes, 0x45);
|
||||
hb_set_add (unicodes, 0x61);
|
||||
hb_set_add (unicodes, 0x62);
|
||||
hb_set_add (unicodes, 0x63);
|
||||
|
||||
hb_blob_t *blob = hb_subset_input_to_string_or_fail (input);
|
||||
g_assert_nonnull (blob);
|
||||
unsigned len = 0;
|
||||
const char *data = hb_blob_get_data (blob, &len);
|
||||
g_assert_cmpstr (data, ==, "--unicodes=41-43,45,61-63");
|
||||
hb_blob_destroy (blob);
|
||||
hb_subset_input_destroy (input);
|
||||
}
|
||||
|
||||
/* Test gids ranges and flags */
|
||||
{
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
hb_set_t *gids = hb_subset_input_glyph_set (input);
|
||||
hb_set_add (gids, 1);
|
||||
hb_set_add (gids, 2);
|
||||
hb_set_add (gids, 3);
|
||||
hb_set_add (gids, 5);
|
||||
hb_set_add (gids, 10);
|
||||
hb_set_add (gids, 11);
|
||||
hb_subset_input_set_flags (input, HB_SUBSET_FLAGS_NO_HINTING | HB_SUBSET_FLAGS_RETAIN_GIDS);
|
||||
|
||||
hb_blob_t *blob = hb_subset_input_to_string_or_fail (input);
|
||||
g_assert_nonnull (blob);
|
||||
unsigned len = 0;
|
||||
const char *data = hb_blob_get_data (blob, &len);
|
||||
g_assert_cmpstr (data, ==, "--no-hinting --retain-gids --gids=1-3,5,10-11");
|
||||
hb_blob_destroy (blob);
|
||||
hb_subset_input_destroy (input);
|
||||
}
|
||||
|
||||
/* Test keep everything */
|
||||
{
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
hb_subset_input_keep_everything (input);
|
||||
|
||||
hb_blob_t *blob = hb_subset_input_to_string_or_fail (input);
|
||||
g_assert_nonnull (blob);
|
||||
unsigned len = 0;
|
||||
const char *data = hb_blob_get_data (blob, &len);
|
||||
const char *expected = "--name-legacy --passthrough-tables --notdef-outline --glyph-names --no-prune-unicode-ranges --unicodes=* --gids=* --name-IDs=* --name-languages=* --layout-features=* --drop-tables-=*";
|
||||
g_assert_cmpstr (data, ==, expected);
|
||||
g_assert_cmpint (len - 1, ==, strlen (expected));
|
||||
hb_blob_destroy (blob);
|
||||
hb_subset_input_destroy (input);
|
||||
}
|
||||
|
||||
/* Test inverted sets with exclusions */
|
||||
{
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
hb_set_t *unicodes = hb_subset_input_set (input, HB_SUBSET_SETS_UNICODE);
|
||||
hb_set_invert (unicodes);
|
||||
hb_set_del (unicodes, 0x20);
|
||||
hb_set_del (unicodes, 0x41);
|
||||
hb_set_del (unicodes, 0x42);
|
||||
hb_set_del (unicodes, 0x43);
|
||||
|
||||
hb_set_t *gids = hb_subset_input_set (input, HB_SUBSET_SETS_GLYPH_INDEX);
|
||||
hb_set_invert (gids);
|
||||
hb_set_del (gids, 5);
|
||||
hb_set_del (gids, 6);
|
||||
hb_set_del (gids, 7);
|
||||
|
||||
hb_set_t *features = hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG);
|
||||
hb_set_clear (features);
|
||||
hb_set_invert (features);
|
||||
hb_set_del (features, HB_TAG ('k', 'e', 'r', 'n'));
|
||||
|
||||
hb_blob_t *blob = hb_subset_input_to_string_or_fail (input);
|
||||
g_assert_nonnull (blob);
|
||||
unsigned len = 0;
|
||||
const char *data = hb_blob_get_data (blob, &len);
|
||||
const char *expected = "--unicodes=* --unicodes-=20,41-43 --gids=* --gids-=5-7 --layout-features=* --layout-features-=kern";
|
||||
g_assert_cmpstr (data, ==, expected);
|
||||
hb_blob_destroy (blob);
|
||||
hb_subset_input_destroy (input);
|
||||
}
|
||||
|
||||
/* Test empty non-default sets */
|
||||
{
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
hb_set_clear (hb_subset_input_set (input, HB_SUBSET_SETS_NAME_ID));
|
||||
hb_set_clear (hb_subset_input_set (input, HB_SUBSET_SETS_NAME_LANG_ID));
|
||||
|
||||
hb_blob_t *blob = hb_subset_input_to_string_or_fail (input);
|
||||
g_assert_nonnull (blob);
|
||||
unsigned len = 0;
|
||||
const char *data = hb_blob_get_data (blob, &len);
|
||||
const char *expected = "--name-IDs-=* --name-languages-=*";
|
||||
g_assert_cmpstr (data, ==, expected);
|
||||
hb_blob_destroy (blob);
|
||||
hb_subset_input_destroy (input);
|
||||
}
|
||||
|
||||
/* Test non-default non-inverted tag sets */
|
||||
{
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
|
||||
hb_set_t *features = hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG);
|
||||
hb_set_clear (features);
|
||||
hb_set_add (features, HB_TAG ('l', 'i', 'g', 'a'));
|
||||
hb_set_add (features, HB_TAG ('k', 'e', 'r', 'n'));
|
||||
|
||||
hb_set_t *scripts = hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_SCRIPT_TAG);
|
||||
hb_set_clear (scripts);
|
||||
hb_set_add (scripts, HB_TAG ('l', 'a', 't', 'n'));
|
||||
|
||||
hb_set_t *drop_tables = hb_subset_input_set (input, HB_SUBSET_SETS_DROP_TABLE_TAG);
|
||||
hb_set_clear (drop_tables);
|
||||
hb_set_add (drop_tables, HB_TAG ('G', 'S', 'U', 'B'));
|
||||
|
||||
hb_blob_t *blob = hb_subset_input_to_string_or_fail (input);
|
||||
g_assert_nonnull (blob);
|
||||
unsigned len = 0;
|
||||
const char *data = hb_blob_get_data (blob, &len);
|
||||
const char *expected = "--layout-features=kern,liga --layout-scripts=latn --drop-tables=GSUB";
|
||||
g_assert_cmpstr (data, ==, expected);
|
||||
hb_blob_destroy (blob);
|
||||
hb_subset_input_destroy (input);
|
||||
}
|
||||
|
||||
/* Test tag sanitization with unsafe ASCII characters */
|
||||
{
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
|
||||
hb_set_t *features = hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG);
|
||||
hb_set_clear (features);
|
||||
/* Tag with space, newline, and single-quote: 'a \n'' */
|
||||
hb_set_add (features, HB_TAG ('a', ' ', '\n', '\''));
|
||||
|
||||
hb_blob_t *blob = hb_subset_input_to_string_or_fail (input);
|
||||
g_assert_nonnull (blob);
|
||||
unsigned len = 0;
|
||||
const char *data = hb_blob_get_data (blob, &len);
|
||||
const char *expected = "--layout-features=a___";
|
||||
g_assert_cmpstr (data, ==, expected);
|
||||
hb_blob_destroy (blob);
|
||||
hb_subset_input_destroy (input);
|
||||
}
|
||||
|
||||
/* Test trimming trailing whitespace from tags */
|
||||
{
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
|
||||
hb_set_t *drop_tables = hb_subset_input_set (input, HB_SUBSET_SETS_DROP_TABLE_TAG);
|
||||
hb_set_clear (drop_tables);
|
||||
hb_set_add (drop_tables, HB_TAG ('c', 'v', 't', ' '));
|
||||
|
||||
hb_set_t *features = hb_subset_input_set (input, HB_SUBSET_SETS_LAYOUT_FEATURE_TAG);
|
||||
hb_set_clear (features);
|
||||
hb_set_add (features, HB_TAG (' ', ' ', ' ', ' '));
|
||||
hb_set_add (features, HB_TAG ('f', 'o', 'o', ' '));
|
||||
|
||||
hb_blob_t *blob = hb_subset_input_to_string_or_fail (input);
|
||||
g_assert_nonnull (blob);
|
||||
unsigned len = 0;
|
||||
const char *data = hb_blob_get_data (blob, &len);
|
||||
const char *expected = "--layout-features=,foo --drop-tables=cvt";
|
||||
g_assert_cmpstr (data, ==, expected);
|
||||
hb_blob_destroy (blob);
|
||||
hb_subset_input_destroy (input);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
@@ -417,6 +613,7 @@ main (int argc, char **argv)
|
||||
hb_test_add (test_subset_create_for_tables_face);
|
||||
|
||||
#ifdef HB_EXPERIMENTAL_API
|
||||
hb_test_add (test_subset_input_to_string);
|
||||
hb_test_add (test_subset_cff2_get_charstring_data);
|
||||
hb_test_add (test_subset_cff2_get_all_charstrings_data);
|
||||
hb_test_add (test_subset_cff2_get_charstring_data_no_cff);
|
||||
@@ -426,3 +623,4 @@ main (int argc, char **argv)
|
||||
|
||||
return hb_test_run();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user