caryll / otfcc

Optimized OpenType builder and inspector.
Apache License 2.0
422 stars 63 forks source link

CFF Subroutinizer #28

Closed be5invis closed 7 years ago

be5invis commented 8 years ago

cc. @huntzhan @schriftgestalt

be5invis commented 7 years ago

Objective: Extract one subroutine from the existing charstrings or subroutine definitions, which is defined as the most "valuable" common substrings in them. The value is calculated as (length - 2) × ((non-overlapping occurrences) - 1).

A program may be either a charstring or a subroutine. A charstring follows:

any* (rmoveto_operator | hmoveto_operator | vmoveto_operator) ((operand * | progid) operator special*)+ endchar_operator
                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

while a subroutine follows

 ((operand * | progid) operator special*)+ return_operator
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

When analyzing a program, you should only analyze the range with wavy underline above, using this pattern:

(operand * | progid) operator special*

as its basic unit.

Your extracted subroutine should follow this pattern either.

Interface: cff_CharstringIL extract_subroutine(cff_CharstringIL *in, uint32_t cs_length, uint32_t sr_length, uint16_t progid);

Limitations:

cc. @clerkma

be5invis commented 7 years ago

@huntzhan @clerkma @schriftgestalt

Found papers about this:

be5invis commented 7 years ago

Done.