summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/xpdf/Gfx.cc2
-rw-r--r--noncore/unsupported/qpdf/xpdf/Object.cc2
-rw-r--r--noncore/unsupported/qpdf/xpdf/Page.cc4
3 files changed, 4 insertions, 4 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/Gfx.cc b/noncore/unsupported/qpdf/xpdf/Gfx.cc
index 17d613e..f016c0e 100644
--- a/noncore/unsupported/qpdf/xpdf/Gfx.cc
+++ b/noncore/unsupported/qpdf/xpdf/Gfx.cc
@@ -1675,385 +1675,385 @@ void Gfx::doRadialShFill(GfxRadialShading *shading) {
ctm = state->getCTM();
t = fabs(ctm[0]);
if (fabs(ctm[1]) > t) {
t = fabs(ctm[1]);
}
if (fabs(ctm[2]) > t) {
t = fabs(ctm[2]);
}
if (fabs(ctm[3]) > t) {
t = fabs(ctm[3]);
}
if (r0 > r1) {
t *= r0;
} else {
t *= r1;
}
if (t < 1) {
n = 3;
} else {
n = (int)(M_PI / acos(1 - 0.1 / t));
if (n < 3) {
n = 3;
} else if (n > 200) {
n = 200;
}
}
// Traverse the t axis and do the shading.
//
// This generates and fills a series of rings. Each ring is defined
// by two circles:
// sa, ta, xa, ya, ra, colorA
// sb, tb, xb, yb, rb, colorB
//
// The s/t axis is divided into radialMaxSplits parts; these parts
// are combined as much as possible while respecting the
// radialColorDelta parameter.
// setup for the start circle
ia = 0;
sa = sMin;
ta = t0 + sa * (t1 - t0);
xa = x0 + sa * (x1 - x0);
ya = y0 + sa * (y1 - y0);
ra = r0 + sa * (r1 - r0);
if (ta < t0) {
shading->getColor(t0, &colorA);
} else if (ta > t1) {
shading->getColor(t1, &colorA);
} else {
shading->getColor(ta, &colorA);
}
while (ia < radialMaxSplits) {
// go as far along the t axis (toward t1) as we can, such that the
// color difference is within the tolerance (radialColorDelta) --
// this uses bisection (between the current value, t, and t1),
// limited to radialMaxSplits points along the t axis
ib = radialMaxSplits;
sb = sMin + ((fouble)ib / (fouble)radialMaxSplits) * (sMax - sMin);
tb = t0 + sb * (t1 - t0);
if (tb < t0) {
shading->getColor(t0, &colorB);
} else if (tb > t1) {
shading->getColor(t1, &colorB);
} else {
shading->getColor(tb, &colorB);
}
while (ib - ia > 1) {
for (k = 0; k < nComps; ++k) {
if (fabs(colorB.c[k] - colorA.c[k]) > radialColorDelta) {
break;
}
}
if (k == nComps) {
break;
}
ib = (ia + ib) / 2;
sb = sMin + ((fouble)ib / (fouble)radialMaxSplits) * (sMax - sMin);
tb = t0 + sb * (t1 - t0);
if (tb < t0) {
shading->getColor(t0, &colorB);
} else if (tb > t1) {
shading->getColor(t1, &colorB);
} else {
shading->getColor(tb, &colorB);
}
}
// compute center and radius of the circle
xb = x0 + sb * (x1 - x0);
yb = y0 + sb * (y1 - y0);
rb = r0 + sb * (r1 - r0);
// use the average of the colors at the two circles
for (k = 0; k < nComps; ++k) {
colorA.c[k] = 0.5 * (colorA.c[k] + colorB.c[k]);
}
state->setFillColor(&colorA);
out->updateFillColor(state);
// construct path for first circle
state->moveTo(xa + ra, ya);
for (k = 1; k < n; ++k) {
angle = ((fouble)k / (fouble)n) * 2 * M_PI;
state->lineTo(xa + ra * cos(angle), ya + ra * sin(angle));
}
state->closePath();
// construct and append path for second circle
state->moveTo(xb + rb, yb);
for (k = 1; k < n; ++k) {
angle = ((fouble)k / (fouble)n) * 2 * M_PI;
state->lineTo(xb + rb * cos(angle), yb + rb * sin(angle));
}
state->closePath();
// fill the ring
out->eoFill(state);
state->clearPath();
// step to the next value of t
ia = ib;
sa = sb;
ta = tb;
xa = xb;
ya = yb;
ra = rb;
colorA = colorB;
}
}
void Gfx::doEndPath() {
if (state->isPath() && clip != clipNone) {
state->clip();
if (clip == clipNormal) {
out->clip(state);
} else {
out->eoClip(state);
}
}
clip = clipNone;
state->clearPath();
}
//------------------------------------------------------------------------
// path clipping operators
//------------------------------------------------------------------------
void Gfx::opClip(Object args[], int numArgs) {
clip = clipNormal;
}
void Gfx::opEOClip(Object args[], int numArgs) {
clip = clipEO;
}
//------------------------------------------------------------------------
// text object operators
//------------------------------------------------------------------------
void Gfx::opBeginText(Object args[], int numArgs) {
state->setTextMat(1, 0, 0, 1, 0, 0);
state->textMoveTo(0, 0);
out->updateTextMat(state);
out->updateTextPos(state);
fontChanged = gTrue;
}
void Gfx::opEndText(Object args[], int numArgs) {
}
//------------------------------------------------------------------------
// text state operators
//------------------------------------------------------------------------
void Gfx::opSetCharSpacing(Object args[], int numArgs) {
state->setCharSpace(args[0].getNum());
out->updateCharSpace(state);
}
void Gfx::opSetFont(Object args[], int numArgs) {
GfxFont *font;
if (!(font = res->lookupFont(args[0].getName()))) {
return;
}
if (printCommands) {
printf(" font: tag=%s name='%s' %g\n",
font->getTag()->getCString(),
font->getName() ? font->getName()->getCString() : "???",
- args[1].getNum());
+ static_cast<double>(args[1].getNum()));
fflush(stdout);
}
state->setFont(font, args[1].getNum());
fontChanged = gTrue;
}
void Gfx::opSetTextLeading(Object args[], int numArgs) {
state->setLeading(args[0].getNum());
}
void Gfx::opSetTextRender(Object args[], int numArgs) {
state->setRender(args[0].getInt());
out->updateRender(state);
}
void Gfx::opSetTextRise(Object args[], int numArgs) {
state->setRise(args[0].getNum());
out->updateRise(state);
}
void Gfx::opSetWordSpacing(Object args[], int numArgs) {
state->setWordSpace(args[0].getNum());
out->updateWordSpace(state);
}
void Gfx::opSetHorizScaling(Object args[], int numArgs) {
state->setHorizScaling(args[0].getNum());
out->updateHorizScaling(state);
fontChanged = gTrue;
}
//------------------------------------------------------------------------
// text positioning operators
//------------------------------------------------------------------------
void Gfx::opTextMove(Object args[], int numArgs) {
fouble tx, ty;
tx = state->getLineX() + args[0].getNum();
ty = state->getLineY() + args[1].getNum();
state->textMoveTo(tx, ty);
out->updateTextPos(state);
}
void Gfx::opTextMoveSet(Object args[], int numArgs) {
fouble tx, ty;
tx = state->getLineX() + args[0].getNum();
ty = args[1].getNum();
state->setLeading(-ty);
ty += state->getLineY();
state->textMoveTo(tx, ty);
out->updateTextPos(state);
}
void Gfx::opSetTextMatrix(Object args[], int numArgs) {
state->setTextMat(args[0].getNum(), args[1].getNum(),
args[2].getNum(), args[3].getNum(),
args[4].getNum(), args[5].getNum());
state->textMoveTo(0, 0);
out->updateTextMat(state);
out->updateTextPos(state);
fontChanged = gTrue;
}
void Gfx::opTextNextLine(Object args[], int numArgs) {
fouble tx, ty;
tx = state->getLineX();
ty = state->getLineY() - state->getLeading();
state->textMoveTo(tx, ty);
out->updateTextPos(state);
}
//------------------------------------------------------------------------
// text string operators
//------------------------------------------------------------------------
void Gfx::opShowText(Object args[], int numArgs) {
if (!state->getFont()) {
error(getPos(), "No font in show");
return;
}
doShowText(args[0].getString());
}
void Gfx::opMoveShowText(Object args[], int numArgs) {
fouble tx, ty;
if (!state->getFont()) {
error(getPos(), "No font in move/show");
return;
}
tx = state->getLineX();
ty = state->getLineY() - state->getLeading();
state->textMoveTo(tx, ty);
out->updateTextPos(state);
doShowText(args[0].getString());
}
void Gfx::opMoveSetShowText(Object args[], int numArgs) {
fouble tx, ty;
if (!state->getFont()) {
error(getPos(), "No font in move/set/show");
return;
}
state->setWordSpace(args[0].getNum());
state->setCharSpace(args[1].getNum());
tx = state->getLineX();
ty = state->getLineY() - state->getLeading();
state->textMoveTo(tx, ty);
out->updateWordSpace(state);
out->updateCharSpace(state);
out->updateTextPos(state);
doShowText(args[2].getString());
}
void Gfx::opShowSpaceText(Object args[], int numArgs) {
Array *a;
Object obj;
int wMode;
int i;
if (!state->getFont()) {
error(getPos(), "No font in show/space");
return;
}
wMode = state->getFont()->getWMode();
a = args[0].getArray();
for (i = 0; i < a->getLength(); ++i) {
a->get(i, &obj);
if (obj.isNum()) {
if (wMode) {
state->textShift(0, -obj.getNum() * 0.001 * state->getFontSize());
} else {
state->textShift(-obj.getNum() * 0.001 * state->getFontSize(), 0);
}
out->updateTextShift(state, obj.getNum());
} else if (obj.isString()) {
doShowText(obj.getString());
} else {
error(getPos(), "Element of show/space array must be number or string");
}
obj.free();
}
}
void Gfx::doShowText(GString *s) {
GfxFont *font;
int wMode;
fouble riseX, riseY;
CharCode code;
Unicode u[8];
fouble x, y, dx, dy, dx2, dy2, curX, curY, tdx, tdy;
fouble originX, originY, tOriginX, tOriginY;
fouble oldCTM[6], newCTM[6];
fouble *mat;
Object charProc;
Dict *resDict;
Parser *oldParser;
char *p;
int len, n, uLen, nChars, nSpaces, i;
if (fontChanged) {
out->updateFont(state);
fontChanged = gFalse;
}
font = state->getFont();
wMode = font->getWMode();
if (out->useDrawChar()) {
out->beginString(state, s);
}
// handle a Type 3 char
if (font->getType() == fontType3 && out->interpretType3Chars()) {
mat = state->getCTM();
for (i = 0; i < 6; ++i) {
oldCTM[i] = mat[i];
}
mat = state->getTextMat();
newCTM[0] = mat[0] * oldCTM[0] + mat[1] * oldCTM[2];
newCTM[1] = mat[0] * oldCTM[1] + mat[1] * oldCTM[3];
newCTM[2] = mat[2] * oldCTM[0] + mat[3] * oldCTM[2];
newCTM[3] = mat[2] * oldCTM[1] + mat[3] * oldCTM[3];
mat = font->getFontMatrix();
newCTM[0] = mat[0] * newCTM[0] + mat[1] * newCTM[2];
newCTM[1] = mat[0] * newCTM[1] + mat[1] * newCTM[3];
newCTM[2] = mat[2] * newCTM[0] + mat[3] * newCTM[2];
newCTM[3] = mat[2] * newCTM[1] + mat[3] * newCTM[3];
newCTM[0] *= state->getFontSize();
diff --git a/noncore/unsupported/qpdf/xpdf/Object.cc b/noncore/unsupported/qpdf/xpdf/Object.cc
index 6d92c6a..77f1317 100644
--- a/noncore/unsupported/qpdf/xpdf/Object.cc
+++ b/noncore/unsupported/qpdf/xpdf/Object.cc
@@ -1,223 +1,223 @@
//========================================================================
//
// Object.cc
//
// Copyright 1996-2002 Glyph & Cog, LLC
//
//========================================================================
#ifdef __GNUC__
#pragma implementation
#endif
#include <aconf.h>
#include <stddef.h>
#include "Object.h"
#include "Array.h"
#include "Dict.h"
#include "Error.h"
#include "Stream.h"
#include "XRef.h"
//------------------------------------------------------------------------
// Object
//------------------------------------------------------------------------
char *objTypeNames[numObjTypes] = {
"boolean",
"integer",
"real",
"string",
"name",
"null",
"array",
"dictionary",
"stream",
"ref",
"cmd",
"error",
"eof",
"none"
};
#ifdef DEBUG_MEM
int Object::numAlloc[numObjTypes] =
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
#endif
Object *Object::initArray(XRef *xref) {
initObj(objArray);
array = new Array(xref);
return this;
}
Object *Object::initDict(XRef *xref) {
initObj(objDict);
dict = new Dict(xref);
return this;
}
Object *Object::initStream(Stream *streamA) {
initObj(objStream);
stream = streamA;
return this;
}
Object *Object::copy(Object *obj) {
*obj = *this;
switch (type) {
case objString:
obj->string = string->copy();
break;
case objName:
obj->name = copyString(name);
break;
case objArray:
array->incRef();
break;
case objDict:
dict->incRef();
break;
case objStream:
stream->incRef();
break;
case objCmd:
obj->cmd = copyString(cmd);
break;
default:
break;
}
#ifdef DEBUG_MEM
++numAlloc[type];
#endif
return obj;
}
Object *Object::fetch(XRef *xref, Object *obj) {
return (type == objRef && xref) ?
xref->fetch(ref.num, ref.gen, obj) : copy(obj);
}
void Object::free() {
switch (type) {
case objString:
delete string;
break;
case objName:
gfree(name);
break;
case objArray:
if (!array->decRef()) {
delete array;
}
break;
case objDict:
if (!dict->decRef()) {
delete dict;
}
break;
case objStream:
if (!stream->decRef()) {
delete stream;
}
break;
case objCmd:
gfree(cmd);
break;
default:
break;
}
#ifdef DEBUG_MEM
--numAlloc[type];
#endif
type = objNone;
}
char *Object::getTypeName() {
return objTypeNames[type];
}
void Object::print(FILE *f) {
Object obj;
int i;
switch (type) {
case objBool:
fprintf(f, "%s", booln ? "true" : "false");
break;
case objInt:
fprintf(f, "%d", intg);
break;
case objReal:
- fprintf(f, "%g", real);
+ fprintf(f, "%g", static_cast<double>(real));
break;
case objString:
fprintf(f, "(");
fwrite(string->getCString(), 1, string->getLength(), stdout);
fprintf(f, ")");
break;
case objName:
fprintf(f, "/%s", name);
break;
case objNull:
fprintf(f, "null");
break;
case objArray:
fprintf(f, "[");
for (i = 0; i < arrayGetLength(); ++i) {
if (i > 0)
fprintf(f, " ");
arrayGetNF(i, &obj);
obj.print(f);
obj.free();
}
fprintf(f, "]");
break;
case objDict:
fprintf(f, "<<");
for (i = 0; i < dictGetLength(); ++i) {
fprintf(f, " /%s ", dictGetKey(i));
dictGetValNF(i, &obj);
obj.print(f);
obj.free();
}
fprintf(f, " >>");
break;
case objStream:
fprintf(f, "<stream>");
break;
case objRef:
fprintf(f, "%d %d R", ref.num, ref.gen);
break;
case objCmd:
fprintf(f, "%s", cmd);
break;
case objError:
fprintf(f, "<error>");
break;
case objEOF:
fprintf(f, "<EOF>");
break;
case objNone:
fprintf(f, "<none>");
break;
}
}
void Object::memCheck(FILE *f) {
#ifdef DEBUG_MEM
int i;
int t;
t = 0;
for (i = 0; i < numObjTypes; ++i)
t += numAlloc[i];
if (t > 0) {
fprintf(f, "Allocated objects:\n");
for (i = 0; i < numObjTypes; ++i) {
if (numAlloc[i] > 0)
fprintf(f, " %-20s: %6d\n", objTypeNames[i], numAlloc[i]);
}
}
#endif
}
diff --git a/noncore/unsupported/qpdf/xpdf/Page.cc b/noncore/unsupported/qpdf/xpdf/Page.cc
index 9cc08c4..aead7da 100644
--- a/noncore/unsupported/qpdf/xpdf/Page.cc
+++ b/noncore/unsupported/qpdf/xpdf/Page.cc
@@ -41,241 +41,241 @@ PageAttrs::PageAttrs(PageAttrs *attrs, Dict *dict) {
rotate = attrs->rotate;
attrs->resources.copy(&resources);
} else {
// set default MediaBox to 8.5" x 11" -- this shouldn't be necessary
// but some (non-compliant) PDF files don't specify a MediaBox
mediaBox.x1 = 0;
mediaBox.y1 = 0;
mediaBox.x2 = 612;
mediaBox.y2 = 792;
cropBox.x1 = cropBox.y1 = cropBox.x2 = cropBox.y2 = 0;
haveCropBox = gFalse;
rotate = 0;
resources.initNull();
}
// media box
readBox(dict, "MediaBox", &mediaBox);
// crop box
cropBox = mediaBox;
haveCropBox = readBox(dict, "CropBox", &cropBox);
// if the MediaBox is excessively larger than the CropBox,
// just use the CropBox
limitToCropBox = gFalse;
if (haveCropBox) {
w = 0.25 * (cropBox.x2 - cropBox.x1);
h = 0.25 * (cropBox.y2 - cropBox.y1);
if ((cropBox.x1 - mediaBox.x1) + (mediaBox.x2 - cropBox.x2) > w ||
(cropBox.y1 - mediaBox.y1) + (mediaBox.y2 - cropBox.y2) > h) {
limitToCropBox = gTrue;
}
}
// other boxes
bleedBox = cropBox;
readBox(dict, "BleedBox", &bleedBox);
trimBox = cropBox;
readBox(dict, "TrimBox", &trimBox);
artBox = cropBox;
readBox(dict, "ArtBox", &artBox);
// rotate
dict->lookup("Rotate", &obj1);
if (obj1.isInt()) {
rotate = obj1.getInt();
}
obj1.free();
while (rotate < 0) {
rotate += 360;
}
while (rotate >= 360) {
rotate -= 360;
}
// misc attributes
dict->lookup("LastModified", &lastModified);
dict->lookup("BoxColorInfo", &boxColorInfo);
dict->lookup("Group", &group);
dict->lookup("Metadata", &metadata);
dict->lookup("PieceInfo", &pieceInfo);
dict->lookup("SeparationInfo", &separationInfo);
// resource dictionary
dict->lookup("Resources", &obj1);
if (obj1.isDict()) {
resources.free();
obj1.copy(&resources);
}
obj1.free();
}
PageAttrs::~PageAttrs() {
lastModified.free();
boxColorInfo.free();
group.free();
metadata.free();
pieceInfo.free();
separationInfo.free();
resources.free();
}
GBool PageAttrs::readBox(Dict *dict, char *key, PDFRectangle *box) {
PDFRectangle tmp;
Object obj1, obj2;
GBool ok;
dict->lookup(key, &obj1);
if (obj1.isArray() && obj1.arrayGetLength() == 4) {
ok = gTrue;
obj1.arrayGet(0, &obj2);
if (obj2.isNum()) {
tmp.x1 = obj2.getNum();
} else {
ok = gFalse;
}
obj2.free();
obj1.arrayGet(1, &obj2);
if (obj2.isNum()) {
tmp.y1 = obj2.getNum();
} else {
ok = gFalse;
}
obj2.free();
obj1.arrayGet(2, &obj2);
if (obj2.isNum()) {
tmp.x2 = obj2.getNum();
} else {
ok = gFalse;
}
obj2.free();
obj1.arrayGet(3, &obj2);
if (obj2.isNum()) {
tmp.y2 = obj2.getNum();
} else {
ok = gFalse;
}
obj2.free();
if (ok) {
*box = tmp;
}
} else {
ok = gFalse;
}
obj1.free();
return ok;
}
//------------------------------------------------------------------------
// Page
//------------------------------------------------------------------------
Page::Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA,
GBool printCommandsA) {
ok = gTrue;
xref = xrefA;
num = numA;
printCommands = printCommandsA;
// get attributes
attrs = attrsA;
// annotations
pageDict->lookupNF("Annots", &annots);
if (!(annots.isRef() || annots.isArray() || annots.isNull())) {
error(-1, "Page annotations object (page %d) is wrong type (%s)",
num, annots.getTypeName());
annots.free();
goto err2;
}
// contents
pageDict->lookupNF("Contents", &contents);
if (!(contents.isRef() || contents.isArray() ||
contents.isNull())) {
error(-1, "Page contents object (page %d) is wrong type (%s)",
num, contents.getTypeName());
contents.free();
goto err1;
}
return;
err2:
annots.initNull();
err1:
contents.initNull();
ok = gFalse;
}
Page::~Page() {
delete attrs;
annots.free();
contents.free();
}
void Page::display(OutputDev *out, fouble dpi, int rotate,
Links *links, Catalog *catalog) {
#ifndef PDF_PARSER_ONLY
PDFRectangle *box, *cropBox;
Gfx *gfx;
Object obj;
Link *link;
int i;
Annots *annotList;
box = getBox();
cropBox = getCropBox();
if (printCommands) {
printf("***** MediaBox = ll:%g,%g ur:%g,%g\n",
- box->x1, box->y1, box->x2, box->y2);
+ static_cast<double>(box->x1), static_cast<double>(box->y1), static_cast<double>(box->x2), static_cast<double>(box->y2));
if (isCropped()) {
printf("***** CropBox = ll:%g,%g ur:%g,%g\n",
- cropBox->x1, cropBox->y1, cropBox->x2, cropBox->y2);
+ static_cast<double>(cropBox->x1), static_cast<double>(cropBox->y1), static_cast<double>(cropBox->x2), static_cast<double>(cropBox->y2));
}
printf("***** Rotate = %d\n", attrs->getRotate());
}
rotate += getRotate();
if (rotate >= 360) {
rotate -= 360;
} else if (rotate < 0) {
rotate += 360;
}
gfx = new Gfx(xref, out, num, attrs->getResourceDict(),
dpi, box, isCropped(), cropBox, rotate, printCommands);
contents.fetch(xref, &obj);
if (!obj.isNull()) {
gfx->display(&obj);
}
obj.free();
// draw links
if (links) {
for (i = 0; i < links->getNumLinks(); ++i) {
link = links->getLink(i);
out->drawLink(link, catalog);
}
out->dump();
}
// draw non-link annotations
//~ need to reset CTM ???
annotList = new Annots(xref, annots.fetch(xref, &obj));
obj.free();
if (annotList->getNumAnnots() > 0) {
if (printCommands) {
printf("***** Annotations\n");
}
for (i = 0; i < annotList->getNumAnnots(); ++i) {
annotList->getAnnot(i)->draw(gfx);
}
out->dump();
}
delete annotList;
delete gfx;
#endif
}