[svg] Hide start_glyph and end_glyph from API
This commit is contained in:
parent
c7a4e3dfb5
commit
4ceabb8c21
|
@ -75,29 +75,24 @@ svg_dump (hb_face_t *face)
|
||||||
|
|
||||||
for (unsigned int glyph_id = 0; glyph_id < glyph_count; glyph_id++)
|
for (unsigned int glyph_id = 0; glyph_id < glyph_count; glyph_id++)
|
||||||
{
|
{
|
||||||
hb_codepoint_t start_glyph_id, end_glyph_id;
|
hb_blob_t *blob = hb_ot_color_glyph_svg_create_blob (face, glyph_id);
|
||||||
hb_blob_t *blob = hb_ot_color_glyph_svg_create_blob (face, glyph_id,
|
|
||||||
&start_glyph_id, &end_glyph_id);
|
|
||||||
|
|
||||||
if (hb_blob_get_length (blob) == 0) continue;
|
if (hb_blob_get_length (blob) == 0) continue;
|
||||||
|
|
||||||
char output_path[255];
|
|
||||||
if (start_glyph_id == end_glyph_id)
|
|
||||||
sprintf (output_path, "out/svg-%d.svg", start_glyph_id);
|
|
||||||
else
|
|
||||||
sprintf (output_path, "out/svg-%d-%d.svg", start_glyph_id, end_glyph_id);
|
|
||||||
|
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
const char *data = hb_blob_get_data (blob, &length);
|
const char *data = hb_blob_get_data (blob, &length);
|
||||||
// append "z" if the content is gzipped, https://stackoverflow.com/a/6059405
|
|
||||||
if (length > 2 && (data[0] == '\x1F') && (data[1] == '\x8B'))
|
char output_path[256];
|
||||||
strcat (output_path, "z");
|
sprintf (output_path, "out/svg-%d.svg%s",
|
||||||
|
glyph_id,
|
||||||
|
// append "z" if the content is gzipped, https://stackoverflow.com/a/6059405
|
||||||
|
(length > 2 && (data[0] == '\x1F') && (data[1] == '\x8B')) ? "z" : "");
|
||||||
|
|
||||||
FILE *f = fopen (output_path, "wb");
|
FILE *f = fopen (output_path, "wb");
|
||||||
fwrite (data, 1, length, f);
|
fwrite (data, 1, length, f);
|
||||||
fclose (f);
|
fclose (f);
|
||||||
|
|
||||||
if (glyph_id < end_glyph_id) glyph_id = end_glyph_id;
|
hb_blob_destroy (blob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,6 @@ namespace OT {
|
||||||
|
|
||||||
struct SVGDocumentIndexEntry
|
struct SVGDocumentIndexEntry
|
||||||
{
|
{
|
||||||
friend struct SVG;
|
|
||||||
friend struct SVGDocumentIndex;
|
|
||||||
|
|
||||||
inline int cmp (hb_codepoint_t g) const
|
inline int cmp (hb_codepoint_t g) const
|
||||||
{ return g < startGlyphID ? -1 : g > endGlyphID ? 1 : 0; }
|
{ return g < startGlyphID ? -1 : g > endGlyphID ? 1 : 0; }
|
||||||
|
|
||||||
|
@ -53,6 +50,13 @@ struct SVGDocumentIndexEntry
|
||||||
return b->cmp (*a);
|
return b->cmp (*a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline hb_blob_t* create_blob (hb_blob_t *svg_blob, unsigned int index_offset) const
|
||||||
|
{
|
||||||
|
if (svgDocLength == 0) return hb_blob_get_empty ();
|
||||||
|
return hb_blob_create_sub_blob (svg_blob, (unsigned int) svgDoc + index_offset,
|
||||||
|
svgDocLength);
|
||||||
|
}
|
||||||
|
|
||||||
inline bool sanitize (hb_sanitize_context_t *c) const
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
||||||
{
|
{
|
||||||
TRACE_SANITIZE (this);
|
TRACE_SANITIZE (this);
|
||||||
|
@ -85,7 +89,7 @@ struct SVGDocumentIndex
|
||||||
entries.len,
|
entries.len,
|
||||||
sizeof (SVGDocumentIndexEntry),
|
sizeof (SVGDocumentIndexEntry),
|
||||||
SVGDocumentIndexEntry::cmp);
|
SVGDocumentIndexEntry::cmp);
|
||||||
return likely (rec && glyph_id <= rec->endGlyphID) ? *rec : Null(SVGDocumentIndexEntry);
|
return likely (rec) ? *rec : Null(SVGDocumentIndexEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool sanitize (hb_sanitize_context_t *c) const
|
inline bool sanitize (hb_sanitize_context_t *c) const
|
||||||
|
@ -120,34 +124,12 @@ struct SVG
|
||||||
hb_blob_destroy (svg_blob);
|
hb_blob_destroy (svg_blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline hb_blob_t*
|
inline hb_blob_t* create_blob_for_glyph (hb_codepoint_t glyph_id) const
|
||||||
failed_create_blob (hb_codepoint_t glyph_id,
|
|
||||||
hb_codepoint_t *start_glyph_id,
|
|
||||||
hb_codepoint_t *end_glyph_id) const
|
|
||||||
{
|
|
||||||
if (start_glyph_id) *start_glyph_id = 0;
|
|
||||||
if (end_glyph_id) *end_glyph_id = 0;
|
|
||||||
return hb_blob_get_empty ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline hb_blob_t*
|
|
||||||
create_blob (hb_codepoint_t glyph_id,
|
|
||||||
hb_codepoint_t *start_glyph_id,
|
|
||||||
hb_codepoint_t *end_glyph_id) const
|
|
||||||
{
|
{
|
||||||
if (unlikely (svg_len == 0))
|
if (unlikely (svg_len == 0))
|
||||||
return failed_create_blob (glyph_id, start_glyph_id, end_glyph_id);
|
return hb_blob_get_empty ();
|
||||||
const SVGDocumentIndex &index = svg+svg->svgDocIndex;
|
return (svg+svg->svgDocIndex).get_glyph_entry (glyph_id).create_blob (svg_blob,
|
||||||
const SVGDocumentIndexEntry &entry = index.get_glyph_entry (glyph_id);
|
svg->svgDocIndex);
|
||||||
if (unlikely (entry.svgDocLength == 0))
|
|
||||||
return failed_create_blob (glyph_id, start_glyph_id, end_glyph_id);
|
|
||||||
unsigned int blob_offset = entry.svgDoc;
|
|
||||||
blob_offset += svg->svgDocIndex;
|
|
||||||
if (unlikely (blob_offset > svg_len || blob_offset + entry.svgDocLength > svg_len))
|
|
||||||
return failed_create_blob (glyph_id, start_glyph_id, end_glyph_id);
|
|
||||||
if (start_glyph_id) *start_glyph_id = entry.startGlyphID;
|
|
||||||
if (end_glyph_id) *end_glyph_id = entry.endGlyphID;
|
|
||||||
return hb_blob_create_sub_blob (svg_blob, blob_offset, entry.svgDocLength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool has_data () const
|
inline bool has_data () const
|
||||||
|
|
|
@ -262,18 +262,13 @@ hb_ot_color_has_svg (hb_face_t *face)
|
||||||
* hb_ot_color_glyph_svg_create_blob:
|
* hb_ot_color_glyph_svg_create_blob:
|
||||||
* @face:
|
* @face:
|
||||||
* @glyph:
|
* @glyph:
|
||||||
* @start_glyph: (out) (optional): Start of range this SVG supports
|
|
||||||
* @end_glyph: (out) (optional): End of range this SVG supports
|
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
*
|
*
|
||||||
* Since: REPLACEME
|
* Since: REPLACEME
|
||||||
*/
|
*/
|
||||||
hb_blob_t *
|
hb_blob_t *
|
||||||
hb_ot_color_glyph_svg_create_blob (hb_face_t *face,
|
hb_ot_color_glyph_svg_create_blob (hb_face_t *face, hb_codepoint_t glyph)
|
||||||
hb_codepoint_t glyph,
|
|
||||||
hb_codepoint_t *start_glyph, /* OUT. May be NULL. */
|
|
||||||
hb_codepoint_t *end_glyph /* OUT. May be NULL. */)
|
|
||||||
{
|
{
|
||||||
return _get_svg (face).create_blob (glyph, start_glyph, end_glyph);
|
return _get_svg (face).create_blob_for_glyph (glyph);
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,10 +119,7 @@ HB_EXTERN hb_bool_t
|
||||||
hb_ot_color_has_svg (hb_face_t *face);
|
hb_ot_color_has_svg (hb_face_t *face);
|
||||||
|
|
||||||
HB_EXTERN hb_blob_t *
|
HB_EXTERN hb_blob_t *
|
||||||
hb_ot_color_glyph_svg_create_blob (hb_face_t *face,
|
hb_ot_color_glyph_svg_create_blob (hb_face_t *face, hb_codepoint_t glyph);
|
||||||
hb_codepoint_t glyph,
|
|
||||||
hb_codepoint_t *start_glyph, /* OUT. May be NULL. */
|
|
||||||
hb_codepoint_t *end_glyph /* OUT. May be NULL. */);
|
|
||||||
|
|
||||||
|
|
||||||
HB_END_DECLS
|
HB_END_DECLS
|
||||||
|
|
|
@ -375,28 +375,21 @@ test_hb_ot_color_has_data (void)
|
||||||
static void
|
static void
|
||||||
test_hb_ot_color_svg (void)
|
test_hb_ot_color_svg (void)
|
||||||
{
|
{
|
||||||
hb_codepoint_t start_glyph, end_glyph;
|
|
||||||
hb_blob_t *blob;
|
hb_blob_t *blob;
|
||||||
|
|
||||||
blob = hb_ot_color_glyph_svg_create_blob (svg, 0, &start_glyph, &end_glyph);
|
blob = hb_ot_color_glyph_svg_create_blob (svg, 0);
|
||||||
g_assert (hb_blob_get_length (blob) == 0);
|
g_assert (hb_blob_get_length (blob) == 0);
|
||||||
g_assert (start_glyph == 0);
|
|
||||||
g_assert (end_glyph == 0);
|
|
||||||
|
|
||||||
blob = hb_ot_color_glyph_svg_create_blob (svg, 1, &start_glyph, &end_glyph);
|
blob = hb_ot_color_glyph_svg_create_blob (svg, 1);
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
const char *data = hb_blob_get_data (blob, &length);
|
const char *data = hb_blob_get_data (blob, &length);
|
||||||
g_assert_cmpuint (length, ==, 146);
|
g_assert_cmpuint (length, ==, 146);
|
||||||
g_assert_cmpuint (start_glyph, ==, 1);
|
|
||||||
g_assert_cmpuint (end_glyph, ==, 1);
|
|
||||||
g_assert (strncmp (data, "<?xml", 4) == 0);
|
g_assert (strncmp (data, "<?xml", 4) == 0);
|
||||||
g_assert (strncmp (data + 140, "</svg>", 5) == 0);
|
g_assert (strncmp (data + 140, "</svg>", 5) == 0);
|
||||||
hb_blob_destroy (blob);
|
hb_blob_destroy (blob);
|
||||||
|
|
||||||
blob = hb_ot_color_glyph_svg_create_blob (empty, 0, &start_glyph, &end_glyph);
|
blob = hb_ot_color_glyph_svg_create_blob (empty, 0, &start_glyph, &end_glyph);
|
||||||
g_assert (hb_blob_get_length (blob) == 0);
|
g_assert (hb_blob_get_length (blob) == 0);
|
||||||
g_assert (start_glyph == 0);
|
|
||||||
g_assert (end_glyph == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Reference in New Issue