fixed serialize_fdselect_3_4

This commit is contained in:
Michiharu Ariza 2018-09-12 16:08:54 -07:00
parent 1608481d88
commit 0f159a38a6
6 changed files with 63 additions and 51 deletions

View File

@ -55,6 +55,12 @@ inline unsigned int calcOffSize(unsigned int dataSize)
return size;
}
struct code_pair
{
hb_codepoint_t code;
hb_codepoint_t glyph;
};
/* CFF INDEX */
template <typename COUNT>
struct CFFIndex

View File

@ -158,12 +158,6 @@ struct CFF1SuppEncData {
DEFINE_SIZE_ARRAY (1, supps);
};
struct code_pair
{
hb_codepoint_t code;
hb_codepoint_t glyph;
};
struct Encoding {
inline bool sanitize (hb_sanitize_context_t *c) const
{

View File

@ -43,14 +43,14 @@ hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs,
unsigned int fdCount,
const FDSelect &src, /* IN */
unsigned int &subset_fd_count /* OUT */,
unsigned int &subst_fdselect_size /* OUT */,
unsigned int &subst_fdselect_format /* OUT */,
hb_vector_t<hb_codepoint_t> &subst_first_glyphs /* OUT */,
unsigned int &subset_fdselect_size /* OUT */,
unsigned int &subset_fdselect_format /* OUT */,
hb_vector_t<code_pair> &fdselect_ranges /* OUT */,
Remap &fdmap /* OUT */)
{
subset_fd_count = 0;
subst_fdselect_size = 0;
subst_fdselect_format = 0;
subset_fdselect_size = 0;
subset_fdselect_format = 0;
unsigned int num_ranges = 0;
unsigned int subset_num_glyphs = glyphs.len;
@ -72,7 +72,8 @@ hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs,
{
num_ranges++;
prev_fd = fd;
subst_first_glyphs.push (i);
code_pair pair = { fd, i };
fdselect_ranges.push (pair);
}
}
@ -96,14 +97,18 @@ hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs,
fdmap.add (fd);
assert (fdmap.get_count () == subset_fd_count);
hb_set_destroy (set);
/* update each font dict index stored as "code" in fdselect_ranges */
for (unsigned int i = 0; i < fdselect_ranges.len; i++)
fdselect_ranges[i].code = fdmap[fdselect_ranges[i].code];
}
/* determine which FDSelect format is most compact */
if (subset_fd_count > 0xFF)
{
assert (src.format == 4);
subst_fdselect_format = 4;
subst_fdselect_size = FDSelect4::min_size + FDSelect4_Range::static_size * num_ranges;
subset_fdselect_format = 4;
subset_fdselect_size = FDSelect4::min_size + FDSelect4_Range::static_size * num_ranges;
}
else
{
@ -112,14 +117,13 @@ hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs,
if (format0_size <= format3_size)
{
// subst_fdselect_format = 0;
subst_fdselect_size = format0_size;
subst_first_glyphs.fini ();
// subset_fdselect_format = 0;
subset_fdselect_size = format0_size;
}
else
{
subst_fdselect_format = 3;
subst_fdselect_size = format3_size;
subset_fdselect_format = 3;
subset_fdselect_size = format3_size;
}
}
@ -129,21 +133,20 @@ hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs,
template <typename FDSELECT3_4>
static inline bool
serialize_fdselect_3_4 (hb_serialize_context_t *c,
unsigned int num_glyphs,
const unsigned int num_glyphs,
const FDSelect &src,
unsigned int size,
const hb_vector_t<hb_codepoint_t> &first_glyphs,
const hb_vector_t<code_pair> &fdselect_ranges,
const Remap &fdmap)
{
TRACE_SERIALIZE (this);
FDSELECT3_4 *p = c->allocate_size<FDSELECT3_4> (size);
if (unlikely (p == nullptr)) return_trace (false);
p->nRanges.set (first_glyphs.len);
for (unsigned int i = 0; i < first_glyphs.len; i++)
p->nRanges.set (fdselect_ranges.len);
for (unsigned int i = 0; i < fdselect_ranges.len; i++)
{
hb_codepoint_t glyph = first_glyphs[i];
p->ranges[i].first.set (glyph);
p->ranges[i].fd.set (fdmap[src.get_fd (glyph)]);
p->ranges[i].first.set (fdselect_ranges[i].glyph);
p->ranges[i].fd.set (fdselect_ranges[i].code);
}
p->sentinel().set (num_glyphs);
return_trace (true);
@ -155,12 +158,12 @@ serialize_fdselect_3_4 (hb_serialize_context_t *c,
**/
bool
hb_serialize_cff_fdselect (hb_serialize_context_t *c,
const hb_vector_t<hb_codepoint_t> &glyphs,
const unsigned int num_glyphs,
const FDSelect &src,
unsigned int fd_count,
unsigned int fdselect_format,
unsigned int size,
const hb_vector_t<hb_codepoint_t> &first_glyphs,
const hb_vector_t<code_pair> &fdselect_ranges,
const Remap &fdmap)
{
TRACE_SERIALIZE (this);
@ -175,25 +178,34 @@ hb_serialize_cff_fdselect (hb_serialize_context_t *c,
{
FDSelect0 *p = c->allocate_size<FDSelect0> (size);
if (unlikely (p == nullptr)) return_trace (false);
for (unsigned int i = 0; i < glyphs.len; i++)
p->fds[i].set (fdmap[src.get_fd (glyphs[i])]);
unsigned int range_index = 0;
unsigned int fd = fdselect_ranges[range_index].code;
for (unsigned int i = 0; i < num_glyphs; i++)
{
if ((range_index < fdselect_ranges.len) &&
(i >= fdselect_ranges[range_index + 1].glyph))
{
fd = fdselect_ranges[++range_index].code;
}
p->fds[i].set (fd);
}
break;
}
case 3:
return serialize_fdselect_3_4<FDSelect3> (c,
glyphs.len,
num_glyphs,
src,
size,
first_glyphs,
fdselect_ranges,
fdmap);
case 4:
return serialize_fdselect_3_4<FDSelect4> (c,
glyphs.len,
num_glyphs,
src,
size,
first_glyphs,
fdselect_ranges,
fdmap);
default:

View File

@ -291,19 +291,19 @@ hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs,
unsigned int fdCount,
const CFF::FDSelect &src, /* IN */
unsigned int &subset_fd_count /* OUT */,
unsigned int &subst_fdselect_size /* OUT */,
unsigned int &subst_fdselect_format /* OUT */,
hb_vector_t<hb_codepoint_t> &subst_first_glyphs /* OUT */,
unsigned int &subset_fdselect_size /* OUT */,
unsigned int &subset_fdselect_format /* OUT */,
hb_vector_t<CFF::code_pair> &fdselect_ranges /* OUT */,
CFF::Remap &fdmap /* OUT */);
HB_INTERNAL bool
hb_serialize_cff_fdselect (hb_serialize_context_t *c,
const hb_vector_t<hb_codepoint_t> &glyphs,
unsigned int num_glyphs,
const CFF::FDSelect &src,
unsigned int fd_count,
unsigned int fdselect_format,
unsigned int size,
const hb_vector_t<hb_codepoint_t> &first_glyphs,
const hb_vector_t<CFF::code_pair> &fdselect_ranges,
const CFF::Remap &fdmap);
#endif /* HB_SUBSET_CFF_COMMON_HH */

View File

@ -348,7 +348,7 @@ struct cff_subset_plan {
topdict_sizes.init ();
topdict_sizes.resize (1);
topdict_mod.init ();
subset_fdselect_first_glyphs.init ();
subset_fdselect_ranges.init ();
fdmap.init ();
subset_charstrings.init ();
flat_charstrings.init ();
@ -365,7 +365,7 @@ struct cff_subset_plan {
{
topdict_sizes.fini ();
topdict_mod.fini ();
subset_fdselect_first_glyphs.fini ();
subset_fdselect_ranges.fini ();
fdmap.fini ();
subset_charstrings.fini ();
flat_charstrings.fini ();
@ -566,7 +566,7 @@ struct cff_subset_plan {
subset_fdcount,
offsets.FDSelectInfo.size,
subset_fdselect_format,
subset_fdselect_first_glyphs,
subset_fdselect_ranges,
fdmap)))
return false;
@ -685,7 +685,7 @@ struct cff_subset_plan {
unsigned int subset_fdcount;
inline bool is_fds_subsetted (void) const { return subset_fdcount < orig_fdcount; }
unsigned int subset_fdselect_format;
hb_vector_t<hb_codepoint_t> subset_fdselect_first_glyphs;
hb_vector_t<code_pair> subset_fdselect_ranges;
/* font dict index remap table from fullset FDArray to subset FDArray.
* set to CFF_UNDEF_CODE if excluded from subset */
@ -823,9 +823,9 @@ static inline bool _write_cff1 (const cff_subset_plan &plan,
if (plan.is_fds_subsetted ())
{
if (unlikely (!hb_serialize_cff_fdselect (&c, glyphs, *acc.fdSelect, acc.fdCount,
if (unlikely (!hb_serialize_cff_fdselect (&c, glyphs.len, *acc.fdSelect, acc.fdCount,
plan.subset_fdselect_format, plan.offsets.FDSelectInfo.size,
plan.subset_fdselect_first_glyphs,
plan.subset_fdselect_ranges,
plan.fdmap)))
{
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF subset FDSelect");

View File

@ -176,7 +176,7 @@ struct cff2_subset_plan {
subset_fdselect_format (0),
drop_hints (false)
{
subset_fdselect_first_glyphs.init ();
subset_fdselect_ranges.init ();
fdmap.init ();
subset_charstrings.init ();
flat_charstrings.init ();
@ -185,7 +185,7 @@ struct cff2_subset_plan {
inline ~cff2_subset_plan (void)
{
subset_fdselect_first_glyphs.fini ();
subset_fdselect_ranges.fini ();
fdmap.fini ();
subset_charstrings.fini ();
flat_charstrings.fini ();
@ -242,7 +242,7 @@ struct cff2_subset_plan {
subset_fdcount,
offsets.FDSelectInfo.size,
subset_fdselect_format,
subset_fdselect_first_glyphs,
subset_fdselect_ranges,
fdmap)))
return false;
@ -300,7 +300,7 @@ struct cff2_subset_plan {
unsigned int subset_fdcount;
inline bool is_fds_subsetted (void) const { return subset_fdcount < orig_fdcount; }
unsigned int subset_fdselect_format;
hb_vector_t<hb_codepoint_t> subset_fdselect_first_glyphs;
hb_vector_t<code_pair> subset_fdselect_ranges;
Remap fdmap;
@ -368,9 +368,9 @@ static inline bool _write_cff2 (const cff2_subset_plan &plan,
if (plan.is_fds_subsetted ())
{
if (unlikely (!hb_serialize_cff_fdselect (&c, glyphs, *(const FDSelect *)acc.fdSelect, acc.fdArray->count,
if (unlikely (!hb_serialize_cff_fdselect (&c, glyphs.len, *(const FDSelect *)acc.fdSelect, acc.fdArray->count,
plan.subset_fdselect_format, plan.offsets.FDSelectInfo.size,
plan.subset_fdselect_first_glyphs,
plan.subset_fdselect_ranges,
plan.fdmap)))
{
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF2 subset FDSelect");