mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-25 08:51:07 +01:00
[ft] Fix get_table_tags returning no tags on streaming faces
_hb_ft_get_table_tags() (used for FT faces created over a custom stream,
i.e. when ft_face->stream->read is set) did
if (!table_count) return population;
else *table_count = 0;
...
end_offset = hb_min (start_offset + *table_count, population);
zeroing *table_count before using it as the requested buffer size, so
end_offset collapsed to start_offset, the copy loop never ran, and
hb_face_get_table_tags() always reported zero tags (and wrote none).
Restructure to match the CoreText / face-builder / default backends: keep
the caller's *table_count, check the start_offset + *table_count sum for
overflow, clamp to the table population, then copy. Also guard the copy
on table_tags so a NULL output array (count-only query) is handled.
The existing FT test used FT_New_Memory_Face, whose in-memory face routes
through the default blob table-tags path and never exercised this
callback. Add a streaming-face variant (FT_Open_Face with a read stream)
that does; it failed (count 0 vs 3) before this fix.
Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
706a2ba8d3
commit
d287ee3ee2
2 files changed
+75
-10
No files matched your search
+16
-10
@@ -1152,23 +1152,29 @@ _hb_ft_get_table_tags (const hb_face_t *face HB_UNUSED,
|
||||
|
||||
if (!table_count)
|
||||
return population;
|
||||
else
|
||||
*table_count = 0;
|
||||
|
||||
if (unlikely (start_offset >= population))
|
||||
{
|
||||
*table_count = 0;
|
||||
return population;
|
||||
}
|
||||
|
||||
unsigned end_offset = hb_min (start_offset + *table_count, (unsigned) population);
|
||||
if (unlikely (end_offset < start_offset))
|
||||
unsigned end_offset = start_offset + *table_count;
|
||||
if (unlikely (end_offset < start_offset)) /* Overflow. */
|
||||
{
|
||||
*table_count = 0;
|
||||
return population;
|
||||
}
|
||||
end_offset = hb_min (end_offset, (unsigned) population);
|
||||
|
||||
*table_count = end_offset - start_offset;
|
||||
for (unsigned i = start_offset; i < end_offset; i++)
|
||||
{
|
||||
FT_ULong tag = 0, length;
|
||||
FT_Sfnt_Table_Info (ft_face, i, &tag, &length);
|
||||
table_tags[i - start_offset] = tag;
|
||||
}
|
||||
if (table_tags)
|
||||
for (unsigned i = start_offset; i < end_offset; i++)
|
||||
{
|
||||
FT_ULong tag = 0, length;
|
||||
FT_Sfnt_Table_Info (ft_face, i, &tag, &length);
|
||||
table_tags[i - start_offset] = tag;
|
||||
}
|
||||
|
||||
return population;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user