| 1 |
/* Copyright 2014 Adobe Systems Incorporated (http://www.adobe.com/). All Rights Reserved. |
| 2 |
This software is licensed as OpenSource, under the Apache License, Version 2.0. |
| 3 |
This license is available at: http://opensource.org/licenses/Apache-2.0. */ |
| 4 |
|
| 5 |
/* |
| 6 |
* Type 1 charstring services. |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef T1CSTR_H |
| 10 |
#define T1CSTR_H |
| 11 |
|
| 12 |
#include "ctlshare.h" |
| 13 |
|
| 14 |
#define T1C_VERSION CTL_MAKE_VERSION(1, 0, 21) |
| 15 |
|
| 16 |
#include "absfont.h" |
| 17 |
|
| 18 |
#ifdef __cplusplus |
| 19 |
extern "C" { |
| 20 |
#endif |
| 21 |
|
| 22 |
typedef int (*t1cDecryptFunc)(int, long *, char *, char *); |
| 23 |
|
| 24 |
int t1cDecrypt(int lenIV, long *length, char *cipher, char *plain); |
| 25 |
|
| 26 |
/* t1cDecrypt() decrypts the Type 1 charstring specified by the "cipher" string |
| 27 |
and "length" parameters and copies the result to the string specified by the |
| 28 |
"plain" string parameter. |
| 29 |
|
| 30 |
The "lenIV" parameter controls the decryption according to the "Adobe Type 1 |
| 31 |
Font Format" specification. A value of -1 indicates no encryption and should |
| 32 |
thus not be passed to this function (no decryption will be performed and |
| 33 |
t1cErrBadLenIV will be returned in this case). Positive values (including 0) |
| 34 |
specify both encryption and the number of initial random bytes in the |
| 35 |
charstring. The initial random bytes are discarded before the remaining |
| 36 |
decrypted bytes are copied to the plain string and the length parameter is |
| 37 |
reduced accordingly. (The value of lenIV for all charstrings in a font is |
| 38 |
typically specified with the /lenIV key in a font's Private dictionary or by |
| 39 |
its default value of 4 if this key is absent.) |
| 40 |
|
| 41 |
The buffer pointed to by the "plain" parameter must be at least "length" - |
| 42 |
"lenIV" bytes long. The "cipher" and "plain" parameters may point to the |
| 43 |
same buffer. */ |
| 44 |
|
| 45 |
int t1cUnprotect(int lenIV, long *length, char *cipher, char *plain); |
| 46 |
|
| 47 |
/* t1cUnprotect() removes protection from charstrings contained in protected |
| 48 |
CJK fonts (identified by the /RunInt key value of /eCCRun) but otherwise |
| 49 |
operates identically to t1cDecrypt(). */ |
| 50 |
|
| 51 |
typedef struct |
| 52 |
{ |
| 53 |
long flags; |
| 54 |
#define T1C_WIDTH_ONLY (1 << 0) |
| 55 |
#define T1C_USE_MATRIX (1 << 1) /* Matrix applied to entire charstring; used by 'rotateFont'.*/ |
| 56 |
#define T1C_UPDATE_OPS (1 << 2) |
| 57 |
void *src; |
| 58 |
ctlStreamCallbacks *stm; |
| 59 |
ctlSubrs subrs; |
| 60 |
long subrsEnd; |
| 61 |
void *ctx; |
| 62 |
long (*getStdEncGlyphOffset)(void *ctx, int stdcode); |
| 63 |
unsigned char bchar; |
| 64 |
unsigned char achar; |
| 65 |
float matrix[6]; |
| 66 |
short nMasters; |
| 67 |
float UDV[15]; |
| 68 |
float NDV[15]; |
| 69 |
float WV[64]; /* cube fonts can have up to 64 master designs*/ |
| 70 |
} t1cAuxData; |
| 71 |
|
| 72 |
int t1cParse(long offset, t1cAuxData *aux, abfGlyphCallbacks *glyph); |
| 73 |
|
| 74 |
/* t1cParse() is called to parse a plain text Type 1 charstring into its |
| 75 |
constituent parts. |
| 76 |
|
| 77 |
The "offset" parameter specifies the stream offset of the plain text |
| 78 |
charstring to be parsed. |
| 79 |
|
| 80 |
The "aux" parameter specifies charstring parse data that is normally stable |
| 81 |
across charstrings. A client may therefore set this up once before parsing |
| 82 |
all the charstrings in a font. The "aux" parameter fields are described |
| 83 |
below. |
| 84 |
|
| 85 |
The "flags" field allows client control over the parse by setting bits |
| 86 |
as follows: |
| 87 |
|
| 88 |
T1C_WIDTH_ONLY - terminate parse after calling back the width |
| 89 |
|
| 90 |
T1C_USE_MATRIX - transform path coordinates using the "matrix" field before |
| 91 |
they are called back to the client. This facility would not normally be used |
| 92 |
during font format conversion since it is generally better to leave the path |
| 93 |
coordinates unmodified and specify a non-default matrix in the font |
| 94 |
|
| 95 |
T1C_UPDATE_OPS - charstrings using the deprecated seac operator are |
| 96 |
converted to a regular path by combining the component glyphs specified in |
| 97 |
the charstring and the deprecated dotsection operator is removed |
| 98 |
|
| 99 |
The "getStdEncGlyphOffset" field holds the address of a function that |
| 100 |
will return the stream offset of a standard encoded glyph. It is only called |
| 101 |
when the T1C_UPDATE_OPS bit is set and a seac operator is encountered. The |
| 102 |
glyph is specified as a character code in StandardEncoding via the "stdcode" |
| 103 |
parameter which is merely acts a synonym for the glyph's name. A client |
| 104 |
should return the stream offset of a glyph whose name is at that standard |
| 105 |
code point or -1 if an error is encountered. The function passes a copy of |
| 106 |
the "ctx" field via the "ctx" parameter. |
| 107 |
|
| 108 |
The "bchar" and "achar" fields specify the base and accent standard |
| 109 |
character codes for seac charstrings, respectively. Non-zero values for |
| 110 |
either of these fields after return from t1cParse() indicates that the |
| 111 |
charstring contained a seac operator. A client building a subset font may |
| 112 |
use this information to ensure that the glyphs with the standard encodings |
| 113 |
of "achar" and "bchar" are added to the subset. |
| 114 |
|
| 115 |
Charstring data is obtained via a stream interface specified by the |
| 116 |
"src" stream field and the stream callbacks specified via the "stm" |
| 117 |
field. The stream is assumed to have been opened by the client and will be |
| 118 |
closed by the client. t1cParse() only makes seek() and read() calls this |
| 119 |
stream. |
| 120 |
|
| 121 |
Subroutine stream offsets are specified by the "subrs" field (see |
| 122 |
ctlshare.h). |
| 123 |
|
| 124 |
The glyph callback functions are specified via the "glyph" parameter (see |
| 125 |
absfont.h). The glyph callbacks pass path construction data back to the |
| 126 |
client. However, the glyph.new() and glyph.end() callbacks are not called |
| 127 |
from t1cParse() since the client is directly initiating the callbacks. |
| 128 |
|
| 129 |
The parse proceeds until one of the following conditions: |
| 130 |
|
| 131 |
o an "endchar" or "seac" operator is encountered in the charstring or a |
| 132 |
subroutine (t1cSuccess is returned) |
| 133 |
o the width has be called back to the client and the T1C_WIDTH_ONLY bit |
| 134 |
is set (t1cSuccess is returned) |
| 135 |
o an error is encountered and returned |
| 136 |
|
| 137 |
Multiple master charstrings (those containing blend operators) are snapshot |
| 138 |
at the instance specified by a weight vector supplied via the "WV" field. |
| 139 |
The number of master designs is specified by the "nMasters" field which |
| 140 |
should be set to 1 when parsing charstrings from a single master font. |
| 141 |
|
| 142 |
A User Design Vector (UDV) for a specific font may be converted to a Weight |
| 143 |
Vector (WV) if the Normalize Design Vector (NDV) and Convert Design Vector |
| 144 |
(CDV) subroutines are available in the font. This process is carried out by |
| 145 |
initializing the "UDV" field to the desired UDV instance and executing the |
| 146 |
NDV subroutine followed by the CDV subroutine by calling t1cParse() on each |
| 147 |
of these subroutines. The result will appear in the "WV" field which can be |
| 148 |
subsequently used to blend charstring coordinates. (Note that the NDV |
| 149 |
subroutine leaves an intermediate result in the "NDV" field that must be |
| 150 |
preserved for the subsequent CDV subroutine to operate correctly.) |
| 151 |
|
| 152 |
t1cParse() returns zero (t1cSuccess) if successful, but otherwise returns a |
| 153 |
positive non-zero error code described below. |
| 154 |
|
| 155 |
Clients obtaining encrypted charstrings directly from font files must call |
| 156 |
one of the above decryption functions in order to obtain a plain text |
| 157 |
version of the charstring before calling t1cParse(). |
| 158 |
|
| 159 |
This library doesn't have knowledge of the lengths of charstrings that it's |
| 160 |
parsing. Consequently, it is possible to read beyond the end of a charstring |
| 161 |
that isn't correctly terminated. Thus, attempts to read beyond the end of |
| 162 |
the source stream should be detected and an error returned. The client may |
| 163 |
also check for correct operator termination when preparing the charstrings. |
| 164 |
|
| 165 |
A charstring should terminate with one of the "endchar", "seac", or |
| 166 |
"callsubr" operators. A subroutine should terminate with one of the |
| 167 |
preceding operators or "return" operator. */ |
| 168 |
|
| 169 |
enum { |
| 170 |
#undef CTL_DCL_ERR |
| 171 |
#define CTL_DCL_ERR(name, string) name, |
| 172 |
#include "t1cerr.h" |
| 173 |
t1cErrCount |
| 174 |
}; |
| 175 |
|
| 176 |
/* Library functions return either zero (t1cSuccess) to indicate success or a |
| 177 |
positive non-zero error code that is defined in the above enumeration that |
| 178 |
is built from t1cerr.h. */ |
| 179 |
|
| 180 |
char *t1cErrStr(int err_code); |
| 181 |
|
| 182 |
/* t1cErrStr() maps the "err_code" parameter to a null-terminated error |
| 183 |
string. */ |
| 184 |
|
| 185 |
void t1cGetVersion(ctlVersionCallbacks *cb); |
| 186 |
|
| 187 |
/* t1cGetVersion() returns the library version number and name via the client |
| 188 |
callbacks passed with the "cb" parameter (see ctlshare.h). */ |
| 189 |
|
| 190 |
#ifdef __cplusplus |
| 191 |
} |
| 192 |
#endif |
| 193 |
|
| 194 |
#endif /* T1CSTR_H */ |