diff options
Diffstat (limited to 'Build/source')
-rwxr-xr-x | Build/source/texk/xdv2pdf/xdv2pdf.cpp | 17 | ||||
-rw-r--r-- | Build/source/texk/xdv2pdf/xdv2pdf_globals.h | 3 | ||||
-rw-r--r-- | Build/source/texk/xdv2pdf/xdv2pdf_specials.cpp | 80 |
3 files changed, 77 insertions, 23 deletions
diff --git a/Build/source/texk/xdv2pdf/xdv2pdf.cpp b/Build/source/texk/xdv2pdf/xdv2pdf.cpp index cae51b2c25d..b4518edf3c5 100755 --- a/Build/source/texk/xdv2pdf/xdv2pdf.cpp +++ b/Build/source/texk/xdv2pdf/xdv2pdf.cpp @@ -1583,7 +1583,7 @@ doFontDef(FILE* xdv, int k) const fontMapRec* fr = getFontRec(nameStr); if (fr != NULL) { font.cgFont = fr->cgFont; - if (fr->cmap->size() > 0) { + if (fr->cmap != NULL && fr->cmap->size() > 0) { if (font.charMap != NULL) delete font.charMap; font.charMap = fr->cmap; // replacing map that was synthesized from the tfm coverage @@ -2178,9 +2178,8 @@ xdv2pdf(int argc, char** argv) gTagLevel = -1; - double_t paperWd = 0.0; - double_t paperHt = 0.0; - + gPaperWd = gPaperHt = 0.0; + int ch; while ((ch = getopt(argc, argv, "o:p:m:d:hv" /*r:*/)) != -1) { switch (ch) { @@ -2193,7 +2192,7 @@ xdv2pdf(int argc, char** argv) break; case 'p': - if (!getPaperSize(optarg, paperWd, paperHt)) { + if (!getPaperSize(optarg, gPaperWd, gPaperHt)) { fprintf(stderr, "*** unknown paper name: %s\n", optarg); exit(1); } @@ -2217,7 +2216,7 @@ xdv2pdf(int argc, char** argv) } } - if ((paperWd == 0.0) || (paperHt == 0.0)) { + if ((gPaperWd == 0.0) || (gPaperHt == 0.0)) { // get default paper size from printing system PMRect paperRect = { 0, 0, 792, 612 }; PMPrintSession printSession; @@ -2238,12 +2237,12 @@ xdv2pdf(int argc, char** argv) } status = PMRelease(printSession); } - paperWd = paperRect.right - paperRect.left; - paperHt = paperRect.bottom - paperRect.top; + gPaperWd = paperRect.right - paperRect.left; + gPaperHt = paperRect.bottom - paperRect.top; } // set the media box for PDF generation - gMediaBox = CGRectMake(0, 0, paperWd, paperHt); + gMediaBox = CGRectMake(0, 0, gPaperWd, gPaperHt); argc -= optind; argv += optind; diff --git a/Build/source/texk/xdv2pdf/xdv2pdf_globals.h b/Build/source/texk/xdv2pdf/xdv2pdf_globals.h index 63baa0b7e30..cea8c2bc7d7 100644 --- a/Build/source/texk/xdv2pdf/xdv2pdf_globals.h +++ b/Build/source/texk/xdv2pdf/xdv2pdf_globals.h @@ -33,6 +33,9 @@ GLOBAL CGColorSpaceRef gGrayColorSpace; GLOBAL bool gPageStarted; GLOBAL CGRect gMediaBox; +GLOBAL double_t gPaperWd; +GLOBAL double_t gPaperHt; + struct dviVars { SInt32 h; diff --git a/Build/source/texk/xdv2pdf/xdv2pdf_specials.cpp b/Build/source/texk/xdv2pdf/xdv2pdf_specials.cpp index 58af6f4bfab..f1c08878e1e 100644 --- a/Build/source/texk/xdv2pdf/xdv2pdf_specials.cpp +++ b/Build/source/texk/xdv2pdf/xdv2pdf_specials.cpp @@ -480,8 +480,19 @@ doColorSpecial(const char* s, bool background) } } +static bool +prefixMatch(const char* str, const char* prefix, const char*& remainder) +{ + int len = strlen(prefix); + if (strncmp(str, prefix, len) == 0) { + remainder = str + len; + return true; + } + return false; +} + static double_t -readDimen(const char* arg) // currently reads unsigned dimens only; no negative paper sizes! +readDimen(const char*& arg) // currently reads unsigned dimens only; no negative paper sizes! { double_t rval = 0.0; while ((*arg >= '0') && (*arg <= '9')) { @@ -500,7 +511,7 @@ readDimen(const char* arg) // currently reads unsigned dimens only; no negative } const dimenRec* dim = &sDimenRatios[0]; while (dim->name != 0) { - if (strcasecmp(arg, dim->name) == 0) { + if (prefixMatch(arg, dim->name, arg)) { rval *= dim->factor; break; } @@ -532,8 +543,10 @@ getPaperSize(const char* arg, double_t& paperWd, double_t& paperHt) char* s3 = strchr(s1, ','); if (s3 != NULL) { *s3++ = 0; - paperWd = readDimen(s1); - paperHt = readDimen(s3); + const char* s4 = s1; + paperWd = readDimen(s4); + s4 = s3; + paperHt = readDimen(s4); } } if (s2 != NULL && strcasecmp(s2, "landscape") == 0) { @@ -548,14 +561,32 @@ getPaperSize(const char* arg, double_t& paperWd, double_t& paperHt) } static bool -prefixMatch(const char* str, const char* prefix, const char*& remainder) +getPageSize(const char* arg, double_t& pageWd, double_t& pageHt) { - int len = strlen(prefix); - if (strncmp(str, prefix, len) == 0) { - remainder = str + len; - return true; + pageHt = pageWd = 0.0; + while (*arg) { + while (*arg == ' ') + ++arg; + if (prefixMatch(arg, "width", arg)) { + while (*arg == ' ') + ++arg; + pageWd = readDimen(arg); + continue; + } + if (prefixMatch(arg, "height", arg)) { + while (*arg == ' ') + ++arg; + pageHt = readDimen(arg); + continue; + } + if (prefixMatch(arg, "default", arg)) { + pageWd = gPaperWd; + pageHt = gPaperHt; + continue; + } + ++arg; } - return false; + return (pageHt > 0.0) && (pageWd > 0.0); } inline bool @@ -582,7 +613,29 @@ doSpecial(const char* special) int u = strlen(special); const char* specialArg; - if (prefixMatch(special, "pdf:", specialArg)) + if (prefixMatch(special, "pdf:pagesize", specialArg)) { + // NOTE: must come before the general pdf special check! + // syntax: \special{pdf:pagesize width <dim> height <dim>} etc + while (*specialArg && (*specialArg <= ' ')) + ++specialArg; + double_t paperWd, paperHt; + if (getPageSize(specialArg, paperWd, paperHt)) { + gMediaBox = CGRectMake(0, 0, paperWd, paperHt); + if (gPageStarted) { + fprintf(stderr, "\n### warning on page ["); + int i, j; + for (j = 9; j > 1; --j) + if (gCounts[j] != 0) + break; + for (i = 0; i < j; ++i) + fprintf(stderr, "%d.", gCounts[i]); + fprintf(stderr, "%d", gCounts[j]); + fprintf(stderr, "]: pdf page size \"%s\" will take effect from NEXT page ", specialArg); + } + } + } + + else if (prefixMatch(special, "pdf:", specialArg)) doPDFspecial(specialArg); else if (prefixMatch(special, "color ", specialArg)) @@ -751,9 +804,8 @@ doSpecial(const char* special) while (*specialArg && (*specialArg <= ' ')) ++specialArg; } - double_t paperWd, paperHt; - if (getPaperSize(specialArg, paperWd, paperHt)) { - gMediaBox = CGRectMake(0, 0, paperWd, paperHt); + if (getPaperSize(specialArg, gPaperWd, gPaperHt)) { + gMediaBox = CGRectMake(0, 0, gPaperWd, gPaperHt); if (gPageStarted) { fprintf(stderr, "\n### warning on page ["); int i, j; |