[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++)
|
||||
{
|
||||
hb_codepoint_t start_glyph_id, end_glyph_id;
|
||||
hb_blob_t *blob = hb_ot_color_glyph_svg_create_blob (face, glyph_id,
|
||||
&start_glyph_id, &end_glyph_id);
|
||||
hb_blob_t *blob = hb_ot_color_glyph_svg_create_blob (face, glyph_id);
|
||||
|
||||
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;
|
||||
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'))
|
||||
strcat (output_path, "z");
|
||||
|
||||
char output_path[256];
|
||||
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");
|
||||
fwrite (data, 1, length, 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
|
||||
{
|
||||
friend struct SVG;
|
||||
friend struct SVGDocumentIndex;
|
||||
|
||||
inline int cmp (hb_codepoint_t g) const
|
||||
{ return g < startGlyphID ? -1 : g > endGlyphID ? 1 : 0; }
|
||||
|
||||
|
@ -53,6 +50,13 @@ struct SVGDocumentIndexEntry
|
|||
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
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
|
@ -85,7 +89,7 @@ struct SVGDocumentIndex
|
|||
entries.len,
|
||||
sizeof (SVGDocumentIndexEntry),
|
||||
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
|
||||
|
@ -120,34 +124,12 @@ struct SVG
|
|||
hb_blob_destroy (svg_blob);
|
||||
}
|
||||
|
||||
inline hb_blob_t*
|
||||
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
|
||||
inline hb_blob_t* create_blob_for_glyph (hb_codepoint_t glyph_id) const
|
||||
{
|
||||
if (unlikely (svg_len == 0))
|
||||
return failed_create_blob (glyph_id, start_glyph_id, end_glyph_id);
|
||||
const SVGDocumentIndex &index = svg+svg->svgDocIndex;
|
||||
const SVGDocumentIndexEntry &entry = index.get_glyph_entry (glyph_id);
|
||||
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);
|
||||
return hb_blob_get_empty ();
|
||||
return (svg+svg->svgDocIndex).get_glyph_entry (glyph_id).create_blob (svg_blob,
|
||||
svg->svgDocIndex);
|
||||
}
|
||||
|
||||
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:
|
||||
* @face:
|
||||
* @glyph:
|
||||
* @start_glyph: (out) (optional): Start of range this SVG supports
|
||||
* @end_glyph: (out) (optional): End of range this SVG supports
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
* Since: REPLACEME
|
||||
*/
|
||||
hb_blob_t *
|
||||
hb_ot_color_glyph_svg_create_blob (hb_face_t *face,
|
||||
hb_codepoint_t glyph,
|
||||
hb_codepoint_t *start_glyph, /* OUT. May be NULL. */
|
||||
hb_codepoint_t *end_glyph /* OUT. May be NULL. */)
|
||||
hb_ot_color_glyph_svg_create_blob (hb_face_t *face, hb_codepoint_t glyph)
|
||||
{
|
||||
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_EXTERN hb_blob_t *
|
||||
hb_ot_color_glyph_svg_create_blob (hb_face_t *face,
|
||||
hb_codepoint_t glyph,
|
||||
hb_codepoint_t *start_glyph, /* OUT. May be NULL. */
|
||||
hb_codepoint_t *end_glyph /* OUT. May be NULL. */);
|
||||
hb_ot_color_glyph_svg_create_blob (hb_face_t *face, hb_codepoint_t glyph);
|
||||
|
||||
|
||||
HB_END_DECLS
|
||||
|
|
|
@ -375,28 +375,21 @@ test_hb_ot_color_has_data (void)
|
|||
static void
|
||||
test_hb_ot_color_svg (void)
|
||||
{
|
||||
hb_codepoint_t start_glyph, end_glyph;
|
||||
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 (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;
|
||||
const char *data = hb_blob_get_data (blob, &length);
|
||||
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 + 140, "</svg>", 5) == 0);
|
||||
hb_blob_destroy (blob);
|
||||
|
||||
blob = hb_ot_color_glyph_svg_create_blob (empty, 0, &start_glyph, &end_glyph);
|
||||
g_assert (hb_blob_get_length (blob) == 0);
|
||||
g_assert (start_glyph == 0);
|
||||
g_assert (end_glyph == 0);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Reference in New Issue