summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qpdf/xpdf/GfxFont.cc
authorsandman <sandman>2002-05-23 23:51:52 (UTC)
committer sandman <sandman>2002-05-23 23:51:52 (UTC)
commit2f3bb7b07f833273d966d41813e68bfe8b9d8d76 (patch) (unidiff)
tree00beb1bd9e7f4ba79e22334a0d258269b28f4564 /noncore/unsupported/qpdf/xpdf/GfxFont.cc
parent6e82b45dd416ceeba78765717b700e853c96a137 (diff)
downloadopie-2f3bb7b07f833273d966d41813e68bfe8b9d8d76.zip
opie-2f3bb7b07f833273d966d41813e68bfe8b9d8d76.tar.gz
opie-2f3bb7b07f833273d966d41813e68bfe8b9d8d76.tar.bz2
Port to xpdf 1.01
Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/GfxFont.cc') (more/less context) (show whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/xpdf/GfxFont.cc62
1 files changed, 51 insertions, 11 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/GfxFont.cc b/noncore/unsupported/qpdf/xpdf/GfxFont.cc
index 518f97b..8d722d6 100644
--- a/noncore/unsupported/qpdf/xpdf/GfxFont.cc
+++ b/noncore/unsupported/qpdf/xpdf/GfxFont.cc
@@ -2,7 +2,7 @@
2// 2//
3// GfxFont.cc 3// GfxFont.cc
4// 4//
5// Copyright 1996-2001 Derek B. Noonburg 5// Copyright 1996-2002 Glyph & Cog, LLC
6// 6//
7//======================================================================== 7//========================================================================
8 8
@@ -454,13 +454,24 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
454 } 454 }
455 obj1.free(); 455 obj1.free();
456 456
457 // get Type3 font definition 457 // get Type 3 bounding box, font definition, and resources
458 if (type == fontType3) { 458 if (type == fontType3) {
459 fontDict->lookup("CharProcs", &charProcs); 459 if (fontDict->lookup("FontBBox", &obj1)->isArray()) {
460 if (!charProcs.isDict()) { 460 for (i = 0; i < 4 && i < obj1.arrayGetLength(); ++i) {
461 if (obj1.arrayGet(i, &obj2)->isNum()) {
462 fontBBox[i] = obj2.getNum();
463 }
464 obj2.free();
465 }
466 }
467 obj1.free();
468 if (!fontDict->lookup("CharProcs", &charProcs)->isDict()) {
461 error(-1, "Missing or invalid CharProcs dictionary in Type 3 font"); 469 error(-1, "Missing or invalid CharProcs dictionary in Type 3 font");
462 charProcs.free(); 470 charProcs.free();
463 } 471 }
472 if (!fontDict->lookup("Resources", &resources)->isDict()) {
473 resources.free();
474 }
464 } 475 }
465 476
466 //----- build the font encoding ----- 477 //----- build the font encoding -----
@@ -513,9 +524,11 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
513 } 524 }
514 525
515 // check embedded or external font file for base encoding 526 // check embedded or external font file for base encoding
527 // (only for Type 1 fonts - trying to get an encoding out of a
528 // TrueType font is a losing proposition)
516 fontFile = NULL; 529 fontFile = NULL;
517 buf = NULL; 530 buf = NULL;
518 if ((type == fontType1 || type == fontType1C || type == fontTrueType) && 531 if ((type == fontType1 || type == fontType1C) &&
519 (extFontFile || embFontID.num >= 0)) { 532 (extFontFile || embFontID.num >= 0)) {
520 if (extFontFile) { 533 if (extFontFile) {
521 buf = readExtFontFile(&len); 534 buf = readExtFontFile(&len);
@@ -524,12 +537,15 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
524 } 537 }
525 if (buf) { 538 if (buf) {
526#if 0 539#if 0
540 if (type == fontType1C && !strncmp(buf, "%!", 2)) {
541 // various tools (including Adobe's) occasionally embed Type 1
542 // fonts but label them Type 1C
543 type = fontType1;
544 }
527 if (type == fontType1) { 545 if (type == fontType1) {
528 fontFile = new Type1FontFile(buf, len); 546 fontFile = new Type1FontFile(buf, len);
529 } else if (type == fontType1C) {
530 fontFile = new Type1CFontFile(buf, len);
531 } else { 547 } else {
532 fontFile = new TrueTypeFontFile(buf, len); 548 fontFile = new Type1CFontFile(buf, len);
533 } 549 }
534 if (fontFile->getName()) { 550 if (fontFile->getName()) {
535 if (embFontName) { 551 if (embFontName) {
@@ -569,6 +585,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
569 if (obj1.isDict()) { 585 if (obj1.isDict()) {
570 obj1.dictLookup("Differences", &obj2); 586 obj1.dictLookup("Differences", &obj2);
571 if (obj2.isArray()) { 587 if (obj2.isArray()) {
588 hasEncoding = gTrue;
572 code = 0; 589 code = 0;
573 for (i = 0; i < obj2.arrayGetLength(); ++i) { 590 for (i = 0; i < obj2.arrayGetLength(); ++i) {
574 obj2.arrayGet(i, &obj3); 591 obj2.arrayGet(i, &obj3);
@@ -636,8 +653,9 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
636 } 653 }
637 654
638 // pass 2: try to fill in the missing chars, looking for names of 655 // pass 2: try to fill in the missing chars, looking for names of
639 // the form 'Axx', 'xx', 'Ann', or 'nn', where 'A' is any letter, 656 // the form 'Axx', 'xx', 'Ann', 'ABnn', or 'nn', where 'A' and 'B'
640 // 'xx' is two hex digits, and 'nn' is 2-4 decimal digits 657 // are any letters, 'xx' is two hex digits, and 'nn' is 2-4
658 // decimal digits
641 if (missing && globalParams->getMapNumericCharNames()) { 659 if (missing && globalParams->getMapNumericCharNames()) {
642 for (code = 0; code < 256; ++code) { 660 for (code = 0; code < 256; ++code) {
643 if ((charName = enc[code]) && !toUnicode[code] && 661 if ((charName = enc[code]) && !toUnicode[code] &&
@@ -656,6 +674,9 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
656 } else if (n >= 3 && n <= 5 && 674 } else if (n >= 3 && n <= 5 &&
657 isdigit(charName[1]) && isdigit(charName[2])) { 675 isdigit(charName[1]) && isdigit(charName[2])) {
658 code2 = atoi(charName+1); 676 code2 = atoi(charName+1);
677 } else if (n >= 4 && n <= 6 &&
678 isdigit(charName[2]) && isdigit(charName[3])) {
679 code2 = atoi(charName+2);
659 } 680 }
660 if (code2 >= 0 && code2 <= 0xff) { 681 if (code2 >= 0 && code2 <= 0xff) {
661 toUnicode[code] = (Unicode)code2; 682 toUnicode[code] = (Unicode)code2;
@@ -684,10 +705,14 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
684 mul = (type == fontType3) ? fontMat[0] : fouble(0.001); 705 mul = (type == fontType3) ? fontMat[0] : fouble(0.001);
685 fontDict->lookup("Widths", &obj1); 706 fontDict->lookup("Widths", &obj1);
686 if (obj1.isArray()) { 707 if (obj1.isArray()) {
708 flags |= fontFixedWidth;
687 for (code = firstChar; code <= lastChar; ++code) { 709 for (code = firstChar; code <= lastChar; ++code) {
688 obj1.arrayGet(code - firstChar, &obj2); 710 obj1.arrayGet(code - firstChar, &obj2);
689 if (obj2.isNum()) { 711 if (obj2.isNum()) {
690 widths[code] = obj2.getNum() * mul; 712 widths[code] = obj2.getNum() * mul;
713 if (widths[code] != widths[firstChar]) {
714 flags &= ~fontFixedWidth;
715 }
691 } 716 }
692 obj2.free(); 717 obj2.free();
693 } 718 }
@@ -752,6 +777,9 @@ Gfx8BitFont::~Gfx8BitFont() {
752 if (charProcs.isDict()) { 777 if (charProcs.isDict()) {
753 charProcs.free(); 778 charProcs.free();
754 } 779 }
780 if (resources.isDict()) {
781 resources.free();
782 }
755} 783}
756 784
757int Gfx8BitFont::getNextChar(char *s, int len, CharCode *code, 785int Gfx8BitFont::getNextChar(char *s, int len, CharCode *code,
@@ -771,6 +799,10 @@ CharCodeToUnicode *Gfx8BitFont::getToUnicode() {
771 return ctu; 799 return ctu;
772} 800}
773 801
802Dict *Gfx8BitFont::getCharProcs() {
803 return charProcs.isDict() ? charProcs.getDict() : (Dict *)NULL;
804}
805
774Object *Gfx8BitFont::getCharProc(int code, Object *proc) { 806Object *Gfx8BitFont::getCharProc(int code, Object *proc) {
775 if (charProcs.isDict()) { 807 if (charProcs.isDict()) {
776 charProcs.dictLookup(enc[code], proc); 808 charProcs.dictLookup(enc[code], proc);
@@ -780,6 +812,10 @@ Object *Gfx8BitFont::getCharProc(int code, Object *proc) {
780 return proc; 812 return proc;
781} 813}
782 814
815Dict *Gfx8BitFont::getResources() {
816 return resources.isDict() ? resources.getDict() : (Dict *)NULL;
817}
818
783//------------------------------------------------------------------------ 819//------------------------------------------------------------------------
784// GfxCIDFont 820// GfxCIDFont
785//------------------------------------------------------------------------ 821//------------------------------------------------------------------------
@@ -1186,6 +1222,10 @@ int GfxCIDFont::getNextChar(char *s, int len, CharCode *code,
1186 return n; 1222 return n;
1187} 1223}
1188 1224
1225int GfxCIDFont::getWMode() {
1226 return cMap ? cMap->getWMode() : 0;
1227}
1228
1189CharCodeToUnicode *GfxCIDFont::getToUnicode() { 1229CharCodeToUnicode *GfxCIDFont::getToUnicode() {
1190 ctu->incRefCnt(); 1230 ctu->incRefCnt();
1191 return ctu; 1231 return ctu;
@@ -1216,7 +1256,7 @@ GfxFontDict::GfxFontDict(XRef *xref, Dict *fontDict) {
1216 fonts[i] = NULL; 1256 fonts[i] = NULL;
1217 } 1257 }
1218 } else { 1258 } else {
1219 error(-1, "font resource is not a dictionary"); 1259 error(-1, "font resource is not a dictionary reference");
1220 fonts[i] = NULL; 1260 fonts[i] = NULL;
1221 } 1261 }
1222 obj1.free(); 1262 obj1.free();