summaryrefslogtreecommitdiff
path: root/Build/source/texk/xdv2pdf
diff options
context:
space:
mode:
authorJonathan Kew <jfkthame@googlemail.com>2007-11-21 12:32:29 +0000
committerJonathan Kew <jfkthame@googlemail.com>2007-11-21 12:32:29 +0000
commit17aeed8e129118bdb3b7eb0ef3a18241dcda40eb (patch)
treed6faebee2c4a64d8e504650b5cb40d78c0c68b56 /Build/source/texk/xdv2pdf
parent952d69f85d43b087ce9fa79d3fc6f1c076000bc7 (diff)
merged XeTeX 0.997 from SIL repository
git-svn-id: svn://tug.org/texlive/trunk@5537 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/xdv2pdf')
-rwxr-xr-xBuild/source/texk/xdv2pdf/xdv2pdf.cpp47
-rw-r--r--Build/source/texk/xdv2pdf/xdv2pdf_globals.h3
-rw-r--r--Build/source/texk/xdv2pdf/xdv2pdf_specials.cpp80
3 files changed, 102 insertions, 28 deletions
diff --git a/Build/source/texk/xdv2pdf/xdv2pdf.cpp b/Build/source/texk/xdv2pdf/xdv2pdf.cpp
index e51aa7fb216..277bfc0ff86 100755
--- a/Build/source/texk/xdv2pdf/xdv2pdf.cpp
+++ b/Build/source/texk/xdv2pdf/xdv2pdf.cpp
@@ -85,6 +85,8 @@ authorization from SIL International.
#define XDV_FLAG_COLORED 0x0200
#define XDV_FLAG_FEATURES 0x0400
#define XDV_FLAG_VARIATIONS 0x0800
+#define XDV_FLAG_EXTEND 0x1000
+#define XDV_FLAG_SLANT 0x2000
#define pdfbox_crop 1
#define pdfbox_media 2
@@ -154,8 +156,8 @@ paperSizeRec gPaperSizes[] =
{ 0, 0, 0 }
};
-static CGAffineTransform horizontalMatrix = { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 };
-static CGAffineTransform verticalMatrix = { 0.0, 1.0, -1.0, 0.0, 0.0, 0.0 };
+static const CGAffineTransform kHorizontalMatrix = { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 };
+static const CGAffineTransform kVerticalMatrix = { 0.0, 1.0, -1.0, 0.0, 0.0, 0.0 };
struct nativeFont {
nativeFont()
@@ -164,6 +166,7 @@ struct nativeFont {
, atsuStyleH(0)
, atsuStyleV(0)
, size(Long2Fix(10))
+ , matrix(kHorizontalMatrix)
, isColored(false)
, isVertical(false)
{
@@ -174,6 +177,7 @@ struct nativeFont {
ATSUStyle atsuStyleV;
Fixed size;
CGColorRef color;
+ CGAffineTransform matrix;
bool isColored;
bool isVertical;
};
@@ -454,7 +458,7 @@ setChar(UInt32 c, bool adv)
flushGlyphs();
CGContextSetFont(gCtx, gTeXFonts[f].cgFont);
CGContextSetFontSize(gCtx, Fix2X(gTeXFonts[f].size) * gMagScale);
- CGContextSetTextMatrix(gCtx, horizontalMatrix);
+ CGContextSetTextMatrix(gCtx, kHorizontalMatrix);
cur_cgFont = f;
}
@@ -545,8 +549,7 @@ doGlyphArray(FILE* xdv, bool yLocs)
if (f != cur_cgFont) {
CGContextSetFont(gCtx, sNativeFonts[f].cgFont);
CGContextSetFontSize(gCtx, Fix2X(sNativeFonts[f].size));
- CGContextSetTextMatrix(gCtx, sNativeFonts[f].isVertical
- ? verticalMatrix : horizontalMatrix);
+ CGContextSetTextMatrix(gCtx, sNativeFonts[f].matrix);
cur_cgFont = f;
}
@@ -1756,7 +1759,7 @@ doNativeFontDef(FILE* xdv)
delete[] axes;
}
}
-
+
nativeFont fontRec;
fontRec.cgFont = cgFont;
fontRec.atsFont = fontRef;
@@ -1789,6 +1792,23 @@ doNativeFontDef(FILE* xdv)
vert = kATSUStronglyVertical;
status = ATSUSetAttributes(style, numTags, tags, sizes, values);
fontRec.atsuStyleV = style;
+
+ fontRec.matrix = kVerticalMatrix;
+ }
+
+ if (flags & XDV_FLAG_EXTEND) {
+ Fixed x = readUnsigned(xdv, 4);
+ if (fontRec.isVertical)
+ fontRec.matrix.c *= Fix2X(x);
+ else
+ fontRec.matrix.a *= Fix2X(x);
+ }
+ if (flags & XDV_FLAG_SLANT) {
+ Fixed s = readSigned(xdv, 4);
+ if (fontRec.isVertical)
+ fontRec.matrix.d = Fix2X(s);
+ else
+ fontRec.matrix.c = Fix2X(s);
}
sNativeFonts.insert(std::pair<const UInt32,nativeFont>(f, fontRec));
@@ -2197,9 +2217,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) {
@@ -2212,7 +2231,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);
}
@@ -2236,7 +2255,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;
@@ -2257,12 +2276,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 a747a18b010..4a0e7a6a176 100644
--- a/Build/source/texk/xdv2pdf/xdv2pdf_globals.h
+++ b/Build/source/texk/xdv2pdf/xdv2pdf_globals.h
@@ -52,6 +52,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 cad873900d2..a19e028da56 100644
--- a/Build/source/texk/xdv2pdf/xdv2pdf_specials.cpp
+++ b/Build/source/texk/xdv2pdf/xdv2pdf_specials.cpp
@@ -499,8 +499,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')) {
@@ -519,7 +530,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;
}
@@ -551,8 +562,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) {
@@ -567,14 +580,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
@@ -601,7 +632,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))
@@ -770,9 +823,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;