Commit e17f0956 authored by Albert Astals Cid's avatar Albert Astals Cid

[xpdf303] TextOutputDev and associated changes

parent 548648bf
......@@ -208,24 +208,24 @@ bool page::search(const ustring &text, rectf &r, search_direction_enum direction
double rect_right = r.right();
double rect_bottom = r.bottom();
TextOutputDev td(NULL, gTrue, gFalse, gFalse);
TextOutputDev td(NULL, gTrue, 0, gFalse, gFalse);
d->doc->doc->displayPage(&td, d->index + 1, 72, 72, rotation_value, false, true, false);
TextPage *text_page = td.takeText();
switch (direction) {
case search_from_top:
found = text_page->findText(&u[0], len,
gTrue, gTrue, gFalse, gFalse, sCase, gFalse,
gTrue, gTrue, gFalse, gFalse, sCase, gFalse, gFalse,
&rect_left, &rect_top, &rect_right, &rect_bottom);
break;
case search_next_result:
found = text_page->findText(&u[0], len,
gFalse, gTrue, gTrue, gFalse, sCase, gFalse,
gFalse, gTrue, gTrue, gFalse, sCase, gFalse, gFalse,
&rect_left, &rect_top, &rect_right, &rect_bottom);
break;
case search_previous_result:
found = text_page->findText(&u[0], len,
gFalse, gTrue, gTrue, gFalse, sCase, gTrue,
gFalse, gTrue, gTrue, gFalse, sCase, gTrue, gFalse,
&rect_left, &rect_top, &rect_right, &rect_bottom);
break;
}
......@@ -267,7 +267,7 @@ ustring page::text(const rectf &r, text_layout_enum layout_mode) const
{
std::auto_ptr<GooString> s;
const GBool use_raw_order = (layout_mode == raw_order_layout);
TextOutputDev td(0, gFalse, use_raw_order, gFalse);
TextOutputDev td(0, gFalse, 0, use_raw_order, gFalse);
d->doc->doc->displayPage(&td, d->index + 1, 72, 72, 0, false, true, false);
if (r.is_empty()) {
const PDFRectangle *rect = d->page->getCropBox();
......
......@@ -263,7 +263,7 @@ poppler_page_get_text_page (PopplerPage *page)
TextOutputDev *text_dev;
Gfx *gfx;
text_dev = new TextOutputDev (NULL, gTrue, gFalse, gFalse);
text_dev = new TextOutputDev (NULL, gTrue, 0, gFalse, gFalse);
gfx = page->page->createGfx(text_dev,
72.0, 72.0, 0,
gFalse, /* useMediaBox */
......@@ -888,6 +888,7 @@ poppler_page_find_text (PopplerPage *page,
gFalse, gTrue, // startAtTop, stopAtBottom
gFalse, gFalse, // startAtLast, stopAtLast
gFalse, gFalse, // caseSensitive, backwards
gFalse, // wholeWord
&xMin, &yMin, &xMax, &yMax))
{
match = poppler_rectangle_new ();
......@@ -1064,7 +1065,7 @@ poppler_page_render_to_ps (PopplerPage *page,
ps_file->first_page, ps_file->last_page,
psModePS, (int)ps_file->paper_width,
(int)ps_file->paper_height, ps_file->duplex,
0, 0, 0, 0, gFalse, gFalse);
0, 0, 0, 0, gFalse);
ps_file->document->doc->displayPage (ps_file->out, page->index + 1, 72.0, 72.0,
......
......@@ -292,6 +292,7 @@ void ArthurOutputDev::updateFont(GfxState *state)
m_font = NULL;
fileName = NULL;
tmpBuf = NULL;
fontLoc = NULL;
if (!(gfxFont = state->getFont())) {
goto err1;
......
......@@ -246,7 +246,7 @@ void CairoOutputDev::startPage(int pageNum, GfxState *state) {
void CairoOutputDev::endPage() {
if (text) {
text->endPage();
text->coalesce(gTrue, gFalse);
text->coalesce(gTrue, 0, gFalse);
}
}
......
......@@ -2866,7 +2866,7 @@ void Gfx::doRadialShFill(GfxRadialShading *shading) {
GfxColor colorA, colorB;
double xa, ya, xb, yb, ra, rb;
double ta, tb, sa, sb;
double sz, sMin, sMax, h;
double sMin, sMax, h;
double sLeft, sRight, sTop, sBottom, sZero, sDiag;
GBool haveSLeft, haveSRight, haveSTop, haveSBottom, haveSZero;
GBool haveSMin, haveSMax;
......@@ -2888,18 +2888,14 @@ void Gfx::doRadialShFill(GfxRadialShading *shading) {
if (h == 0) {
enclosed = gTrue;
theta = 0; // make gcc happy
sz = 0; // make gcc happy
} else if (r1 - r0 == 0) {
enclosed = gFalse;
theta = 0;
sz = 0; // make gcc happy
} else if (fabs(r1 - r0) >= h) {
enclosed = gTrue;
theta = 0; // make gcc happy
sz = 0; // make gcc happy
} else {
enclosed = gFalse;
sz = -r0 / (r1 - r0);
theta = asin((r1 - r0) / h);
}
......
......@@ -4178,7 +4178,7 @@ GBool PSOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading,
double xMin, yMin, xMax, yMax;
double x0, y0, r0, x1, y1, r1, t0, t1;
double xa, ya, ra;
double sz, sMin, sMax, h, ta;
double sMin, sMax, h, ta;
double sLeft, sRight, sTop, sBottom, sZero, sDiag;
GBool haveSLeft, haveSRight, haveSTop, haveSBottom, haveSZero;
GBool haveSMin, haveSMax;
......@@ -4206,18 +4206,14 @@ GBool PSOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading,
if (h == 0) {
enclosed = gTrue;
theta = 0; // make gcc happy
sz = 0; // make gcc happy
} else if (r1 - r0 == 0) {
enclosed = gFalse;
theta = 0;
sz = 0; // make gcc happy
} else if (fabs(r1 - r0) >= h) {
enclosed = gTrue;
theta = 0; // make gcc happy
sz = 0; // make gcc happy
} else {
enclosed = gFalse;
sz = -r0 / (r1 - r0);
theta = asin((r1 - r0) / h);
}
if (enclosed) {
......
This diff is collapsed.
......@@ -333,7 +333,7 @@ public:
void addWord(TextWord *word);
void coalesce(UnicodeMap *uMap);
void coalesce(UnicodeMap *uMap, double fixedPitch);
// Update this block's priMin and priMax values, looking at <blk>.
void updatePriMinMax(TextBlock *blk);
......@@ -521,7 +521,7 @@ public:
void addLink(int xMin, int yMin, int xMax, int yMax, AnnotLink *link);
// Coalesce strings that look like parts of the same line.
void coalesce(GBool physLayout, GBool doHTML);
void coalesce(GBool physLayout, double fixedPitch, GBool doHTML);
// Find a string. If <startAtTop> is true, starts looking at the
// top of the page; else if <startAtLast> is true, starts looking
......@@ -534,6 +534,7 @@ public:
GBool startAtTop, GBool stopAtBottom,
GBool startAtLast, GBool stopAtLast,
GBool caseSensitive, GBool backward,
GBool wholeWord,
double *xMin, double *yMin,
double *xMax, double *yMax);
......@@ -676,14 +677,16 @@ public:
// is maintained. If <rawOrder> is true, the text is kept in
// content stream order.
TextOutputDev(char *fileName, GBool physLayoutA,
GBool rawOrderA, GBool append);
double fixedPitchA, GBool rawOrderA,
GBool append);
// Create a TextOutputDev which will write to a generic stream. If
// <physLayoutA> is true, the original physical layout of the text
// is maintained. If <rawOrder> is true, the text is kept in
// content stream order.
TextOutputDev(TextOutputFunc func, void *stream,
GBool physLayoutA, GBool rawOrderA);
GBool physLayoutA, double fixedPitchA,
GBool rawOrderA);
// Destructor.
virtual ~TextOutputDev();
......@@ -719,6 +722,9 @@ public:
// End a page.
virtual void endPage();
//----- save/restore graphics state
virtual void restoreState(GfxState *state);
//----- update text state
virtual void updateFont(GfxState *state);
......@@ -754,6 +760,7 @@ public:
GBool startAtTop, GBool stopAtBottom,
GBool startAtLast, GBool stopAtLast,
GBool caseSensitive, GBool backward,
GBool wholeWord,
double *xMin, double *yMin,
double *xMax, double *yMax);
......@@ -804,6 +811,9 @@ private:
TextPage *text; // text for the current page
GBool physLayout; // maintain original physical layout when
// dumping text
double fixedPitch; // if physLayout is true and this is non-zero,
// assume fixed-pitch characters with this
// width
GBool rawOrder; // keep text in content stream order
GBool doHTML; // extra processing for HTML conversion
GBool ok; // set up ok?
......
......@@ -330,7 +330,7 @@ QString Page::text(const QRectF &r, TextLayout textLayout) const
QString result;
const GBool rawOrder = textLayout == RawOrderLayout;
output_dev = new TextOutputDev(0, gFalse, rawOrder, gFalse);
output_dev = new TextOutputDev(0, gFalse, 0, rawOrder, gFalse);
m_page->parentDoc->doc->displayPageSlice(output_dev, m_page->index + 1, 72, 72,
0, false, true, false, -1, -1, -1, -1);
if (r.isNull())
......@@ -371,19 +371,19 @@ bool Page::search(const QString &text, double &sLeft, double &sTop, double &sRig
int rotation = (int)rotate * 90;
// fetch ourselves a textpage
TextOutputDev td(NULL, gTrue, gFalse, gFalse);
TextOutputDev td(NULL, gTrue, 0, gFalse, gFalse);
m_page->parentDoc->doc->displayPage( &td, m_page->index + 1, 72, 72, rotation, false, true, false );
TextPage *textPage=td.takeText();
if (direction == FromTop)
found = textPage->findText( u.data(), len,
gTrue, gTrue, gFalse, gFalse, sCase, gFalse, &sLeft, &sTop, &sRight, &sBottom );
gTrue, gTrue, gFalse, gFalse, sCase, gFalse, gFalse, &sLeft, &sTop, &sRight, &sBottom );
else if ( direction == NextResult )
found = textPage->findText( u.data(), len,
gFalse, gTrue, gTrue, gFalse, sCase, gFalse, &sLeft, &sTop, &sRight, &sBottom );
gFalse, gTrue, gTrue, gFalse, sCase, gFalse, gFalse, &sLeft, &sTop, &sRight, &sBottom );
else if ( direction == PreviousResult )
found = textPage->findText( u.data(), len,
gFalse, gTrue, gTrue, gFalse, sCase, gTrue, &sLeft, &sTop, &sRight, &sBottom );
gFalse, gTrue, gTrue, gFalse, sCase, gTrue, gFalse, &sLeft, &sTop, &sRight, &sBottom );
textPage->decRefCnt();
......@@ -414,7 +414,7 @@ QList<TextBox*> Page::textList(Rotation rotate) const
QList<TextBox*> output_list;
output_dev = new TextOutputDev(0, gFalse, gFalse, gFalse);
output_dev = new TextOutputDev(0, gFalse, 0, gFalse, gFalse);
int rotation = (int)rotate * 90;
......
......@@ -840,7 +840,7 @@ static void RenderPdfAsText(const char *fileName)
LogInfo("started: %s\n", fileName);
TextOutputDev * textOut = new TextOutputDev(NULL, gTrue, gFalse, gFalse);
TextOutputDev * textOut = new TextOutputDev(NULL, gTrue, 0, gFalse, gFalse);
if (!textOut->isOk()) {
delete textOut;
return;
......
......@@ -53,6 +53,10 @@ Maintain (as best as possible) the original physical layout of the
text. The default is to \'undo' physical layout (columns,
hyphenation, etc.) and output the text in reading order.
.TP
.BI \-fixed " number"
Assume fixed-pitch (or tabular) text, with the specified character
width (in points). This forces physical layout mode.
.TP
.B \-raw
Keep the text in content stream order. This is a hack which often
"undoes" column formatting, etc. Use of raw mode is no longer
......
......@@ -68,6 +68,7 @@ static int w = 0;
static int h = 0;
static GBool bbox = gFalse;
static GBool physLayout = gFalse;
static double fixedPitch = 0;
static GBool rawOrder = gFalse;
static GBool htmlMeta = gFalse;
static char textEncName[128] = "";
......@@ -97,6 +98,8 @@ static const ArgDesc argDesc[] = {
"height of crop area in pixels (default is 0)"},
{"-layout", argFlag, &physLayout, 0,
"maintain original physical layout"},
{"-fixed", argFP, &fixedPitch, 0,
"assume fixed-pitch (or tabular) text"},
{"-raw", argFlag, &rawOrder, 0,
"keep strings in content stream order"},
{"-htmlmeta", argFlag, &htmlMeta, 0,
......@@ -197,6 +200,9 @@ int main(int argc, char *argv[]) {
}
fileName = new GooString(argv[1]);
if (fixedPitch) {
physLayout = gTrue;
}
if (textEncName[0]) {
globalParams->setTextEncoding(textEncName);
......@@ -333,7 +339,7 @@ int main(int argc, char *argv[]) {
// write text file
if (bbox) {
textOut = new TextOutputDev(NULL, physLayout, rawOrder, htmlMeta);
textOut = new TextOutputDev(NULL, physLayout, fixedPitch, rawOrder, htmlMeta);
if (!(f = fopen(textFileName->getCString(), "ab"))) {
error(errIO, -1, "Couldn't open text file '{0:t}' for append", textFileName);
exitCode = 2;
......@@ -367,7 +373,7 @@ int main(int argc, char *argv[]) {
fclose(f);
} else {
textOut = new TextOutputDev(textFileName->getCString(),
physLayout, rawOrder, htmlMeta);
physLayout, fixedPitch, rawOrder, htmlMeta);
if (textOut->isOk()) {
if ((w==0) && (h==0) && (x==0) && (y==0)) {
doc->displayPages(textOut, firstPage, lastPage, resolution, resolution, 0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment