in modules/awt/src/main/native/fontlib/shared/T1Font.cpp [465:688]
void T1Font::initFont(FILE *font) {
fchar curStr[MAX_STR_LENGTH];
DecodeState state = HEADER;
ufshort r = DEF_R_EXEC;
ufshort n = 4;
ufshort lenIV = DEF_LENIV;
ufshort charStringR;
ufshort count = 0;
ufshort tempShort = 0;
ufshort length = 0;
ufshort valueLength = 0;
matrixScale = 1000;
bool isASCII = true;
ufchar ch;
EncodedValue *curValue;
ch = getc(font);
if (ch == 0x80 && getc(font) == 0x01) {
isASCII = false;
} else if (ch == '%' && getc(font) == '!') {
isASCII = true;
} else {
error();
}
while (!feof(font)) {
switch (state) {
case HEADER: {
getNextLexeme(curStr, font);
if (!strcmp(curStr, "/UnderlinePosition")) {
getNextLexeme(curStr, font);
_underlineOffset = (ffloat) - atof(curStr);
} else if (!strcmp(curStr, "/UnderlineThickness")) {
getNextLexeme(curStr, font);
_underlineThickness = (ffloat) atof(curStr);
} else if (strstr(curStr, "/FontBBox") != NULL) {
//getNextLexeme(curStr, font);
while (!feof(font) && ((ch = getc(font)) == '{')) {
}
ungetc(ch, font);
getNextLexeme(curStr, font);
_boundingBox[0] = (ffloat) atof(curStr);
getNextLexeme(curStr, font);
_boundingBox[1] = (ffloat) atof(curStr);
getNextLexeme(curStr, font);
_boundingBox[2] = (ffloat) atof(curStr);
getNextLexeme(curStr, font);
_boundingBox[3] = (ffloat) atof(curStr);
_height = ((ffloat)(_boundingBox[2] -_boundingBox[0]));
} else if (!strcmp(curStr, "/FullName")) {
//getNextLexeme(curStr, font);
while (!feof(font) && ((ch = getc(font)) == '(')) {
}
curStr[count ++] = ch;
while (!feof(font) && (ch = getc(font)) != ')') {
curStr[count ++] = ch;
}
curStr[count] = '\0';
fchar *ptr = curStr;
ch = 0;
fullName = new fwchar_t[count + 1];
while (*ptr != '\0') {
fullName[ch ++] = *ptr;
ptr ++;
}
fullName[ch] = L'\0';
} else if (!strcmp(curStr, "eexec")) {
state = PRIVATE_DIR;
if (isASCII) {
for (count = 0; count < lenIV * 2; count ++) {
if (!isascii(ch = getc(font))) {
error();
}
curStr[count] = ch;
}
decodeASCIILine(curStr, &r, n, count);
} else {
for (count = 0; count < 6; count ++) {
curStr[count] = getc(font);
}
if (curStr[0] != (fchar)0x80 || curStr[1] != 0x02) {
error();
}
for (count = 0; count < lenIV; count ++) {
curStr[count] = getc(font);
}
decodeBinaryLine(curStr, &r, n, count);
}
}
break;
}
case PRIVATE_DIR: {
getNextDecodeLexeme(curStr, font, &r, isASCII);
if (!strcmp(curStr, "/Subrs")) {
getNextDecodeLexeme(curStr, font, &r, isASCII);
valueLength = atoi(curStr);
count = 0;
state = SUBRS_MASSIVE;
getNextDecodeLine(curStr, font, &r, isASCII);
} else if (!strcmp(curStr, "/CharStrings")) {
getNextDecodeLexeme(curStr, font, &r, isASCII);
valueLength = atoi(curStr);
count = 0;
state = CHAR_STRING;
getNextDecodeLine(curStr, font, &r, isASCII);
}
break;
}
case SUBRS_MASSIVE: {
curValue = new EncodedValue();
getNextDecodeLexeme(curStr, font, &r, isASCII);
getNextDecodeLexeme(curStr, font, &r, isASCII);
curValue->number = (ufshort) atoi(curStr);
getNextDecodeLexeme(curStr, font, &r, isASCII);
length = (ufshort) atoi(curStr);
curValue->length = length - lenIV;
getNextDecodeLexeme(curStr, font, &r, isASCII);
for (tempShort = 0; tempShort - length < 0; tempShort ++) {
curStr[tempShort] = decryptNextSimbol(font, &r, isASCII);
}
charStringR = DEF_R_CHARSTRING;
decodeBinaryLine(curStr, &charStringR, lenIV, length);
curValue->text = new fchar[curValue->length];
for (tempShort = 0; tempShort - curValue->length < 0; tempShort ++) {
curValue->text[tempShort] = curStr[tempShort];
}
subrsMap[curValue->number] = curValue;
getNextDecodeLine(curStr, font, &r, isASCII);
if (++count >= valueLength) {
state = PRIVATE_DIR;
count = 0;
}
break;
}
case CHAR_STRING: {
getNextDecodeLexeme(curStr, font, &r, isASCII);
tempShort = getUnicode(curStr + 1);
if (tempShort != FONT_NOT_FOUND_UNICODE_VALUE) {
glyphCodeMap[count] = tempShort;
curValue = new EncodedValue();
curValue->number = tempShort;
getNextDecodeLexeme(curStr, font, &r, isASCII);
length = (ufshort) atoi(curStr);
curValue->length = length - lenIV;
getNextDecodeLexeme(curStr, font, &r, isASCII);
for (tempShort = 0; tempShort - length < 0; tempShort ++) {
curStr[tempShort] = decryptNextSimbol(font, &r, isASCII);
}
charStringR = DEF_R_CHARSTRING;
decodeBinaryLine(curStr, &charStringR, lenIV, length);
curValue->text = new fchar[curValue->length];
for (tempShort = 0; tempShort - curValue->length < 0; tempShort ++) {
curValue->text[tempShort] = curStr[tempShort];
}
charStringMap[curValue->number] = curValue;
} else {
getNextDecodeLexeme(curStr, font, &r, isASCII);
length = (ufshort) atoi(curStr);
getNextDecodeLexeme(curStr, font, &r, isASCII);
for (tempShort = 0; tempShort - length < 0; tempShort ++) {
decryptNextSimbol(font, &r, isASCII);
}
}
getNextDecodeLine(curStr, font, &r, isASCII);
if (++count >= valueLength) {
return;
}
break;
}
}
}
}