(glyph)
| 3830 | } |
| 3831 | |
| 3832 | function glyphToOps(glyph) { |
| 3833 | var ops = []; |
| 3834 | var path = glyph.path; |
| 3835 | ops.push({name: 'width', type: 'NUMBER', value: glyph.advanceWidth}); |
| 3836 | var x = 0; |
| 3837 | var y = 0; |
| 3838 | for (var i = 0; i < path.commands.length; i += 1) { |
| 3839 | var dx; |
| 3840 | var dy; |
| 3841 | var cmd = path.commands[i]; |
| 3842 | if (cmd.type === 'Q') { |
| 3843 | // CFF only supports bézier curves, so convert the quad to a bézier. |
| 3844 | var _13 = 1 / 3; |
| 3845 | var _23 = 2 / 3; |
| 3846 | |
| 3847 | // We're going to create a new command so we don't change the original path. |
| 3848 | cmd = { |
| 3849 | type: 'C', |
| 3850 | x: cmd.x, |
| 3851 | y: cmd.y, |
| 3852 | x1: _13 * x + _23 * cmd.x1, |
| 3853 | y1: _13 * y + _23 * cmd.y1, |
| 3854 | x2: _13 * cmd.x + _23 * cmd.x1, |
| 3855 | y2: _13 * cmd.y + _23 * cmd.y1 |
| 3856 | }; |
| 3857 | } |
| 3858 | |
| 3859 | if (cmd.type === 'M') { |
| 3860 | dx = Math.round(cmd.x - x); |
| 3861 | dy = Math.round(cmd.y - y); |
| 3862 | ops.push({name: 'dx', type: 'NUMBER', value: dx}); |
| 3863 | ops.push({name: 'dy', type: 'NUMBER', value: dy}); |
| 3864 | ops.push({name: 'rmoveto', type: 'OP', value: 21}); |
| 3865 | x = Math.round(cmd.x); |
| 3866 | y = Math.round(cmd.y); |
| 3867 | } else if (cmd.type === 'L') { |
| 3868 | dx = Math.round(cmd.x - x); |
| 3869 | dy = Math.round(cmd.y - y); |
| 3870 | ops.push({name: 'dx', type: 'NUMBER', value: dx}); |
| 3871 | ops.push({name: 'dy', type: 'NUMBER', value: dy}); |
| 3872 | ops.push({name: 'rlineto', type: 'OP', value: 5}); |
| 3873 | x = Math.round(cmd.x); |
| 3874 | y = Math.round(cmd.y); |
| 3875 | } else if (cmd.type === 'C') { |
| 3876 | var dx1 = Math.round(cmd.x1 - x); |
| 3877 | var dy1 = Math.round(cmd.y1 - y); |
| 3878 | var dx2 = Math.round(cmd.x2 - cmd.x1); |
| 3879 | var dy2 = Math.round(cmd.y2 - cmd.y1); |
| 3880 | dx = Math.round(cmd.x - cmd.x2); |
| 3881 | dy = Math.round(cmd.y - cmd.y2); |
| 3882 | ops.push({name: 'dx1', type: 'NUMBER', value: dx1}); |
| 3883 | ops.push({name: 'dy1', type: 'NUMBER', value: dy1}); |
| 3884 | ops.push({name: 'dx2', type: 'NUMBER', value: dx2}); |
| 3885 | ops.push({name: 'dy2', type: 'NUMBER', value: dy2}); |
| 3886 | ops.push({name: 'dx', type: 'NUMBER', value: dx}); |
| 3887 | ops.push({name: 'dy', type: 'NUMBER', value: dy}); |
| 3888 | ops.push({name: 'rrcurveto', type: 'OP', value: 8}); |
| 3889 | x = Math.round(cmd.x); |
no outgoing calls
no test coverage detected