Patch level : 4.0

Files correlati     : stampe analitiche in genere
Ricompilazione Demo : [ ]
Commento            :
Aggiunto supporto per la suddivisione in piu' fogli
delle pagine di stampa piu' larghe di una pagina fisica


git-svn-id: svn://10.65.10.50/trunk@14341 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2006-09-22 13:30:53 +00:00
parent e41346408f
commit 4deedda029
3 changed files with 128 additions and 46 deletions

View File

@ -8,6 +8,7 @@
#include <reprint.h>
#include <statbar.h>
#include <urldefid.h>
#include <utility.h>
#include <bagn003.h>
#include <bagn009.h>
@ -900,8 +901,11 @@ TPoint TBook::page_res() const
bool TBook::open_page()
{
if (_out == NULL)
if (_out == NULL) // Sto per scrivere la prima pagina
{
_out = new ofstream(_file);
_max_frame = 0; // Azzero la dimensione del massimo frame
}
_page++;
_index.add_long(_out->tellp(), page()); // Scrive alla posizione 1 l'inizio di pagina 1
@ -954,6 +958,8 @@ void TBook::define_frame(const TRectangle& rect)
<< " x=" << _rect.x << " y=" << _rect.y
<< " dx=" << _rect.width() << " dy=" << _rect.height()
<< " />" << endl;
if (_rect.right() > _max_frame)
_max_frame = _rect.right();
}
}
@ -972,7 +978,7 @@ void TBook::set_clip(long top, long bottom)
void TBook::draw_text(const TRectangle& r, const char* txt)
{
const TFixed_string str(txt);
if (!str.blank())
if (str.full())
{
define_frame(r);
*_out << "<text>" << endl << str << endl << "</text>" << endl;
@ -1146,16 +1152,16 @@ void TBook::print_doc(TWindow& win, const TFilename& name)
RCT page; win.log2dev(rect, page);
advanced_draw_text_line(win, name, page, 'C', 'T');
const TPoint pr = page_res();
rect.deflate(pr.x/2, pr.y/2);
win.log2dev(rect, page);
TString4 ext = name.right(3); ext.lower();
if (ext == "bmp" || ext == "gif" || ext == "jpg" || ext == "peg")
TString8 ext = name.ext(); ext.lower();
if (ext == "bmp" || ext == "gif" || ext == "jpg" || ext == "jpeg")
{
const TImage* img = _images.image(name);
if (img != NULL)
{
const TPoint pr = page_res();
rect.deflate(pr.x/2, pr.y/2);
win.log2dev(rect, page);
const double sx = double(page.right) / double(img->width());
const double sy = double(page.bottom) / double(img->height());
const double s = sx < sy ? sx : sy;
@ -1611,23 +1617,94 @@ bool TBook::init()
_pw = _pw * BOOKDPI / _phr;
_pvr = _phr = BOOKDPI;
bool ok = true;
if (_printwin != NULL)
delete _printwin;
_printwin = new TWindow_printer(_rcd, _pdf_file);
if (_pvr < 96 || _phr < 96) // Risoluzione minima di Acrobat Writer
return true;
}
void TBook::close_output()
{
if (_out != NULL)
{
ok = yesno_box(FR("Stampante obsoleta o non adeguatamente configurata:\n"
"Risoluzione %ldx%ld. Continuare ugualmente?"), _phr, _pvr);
_out->close();
delete _out;
}
_out = NULL;
}
bool TBook::split_file_if_needed()
{
const int mf = (_max_frame * _phr) / (100 * cpi()); // log2dev dei poveri
const int colonne = (mf+_pw-1) / _pw;
if (colonne < 2)
return false;
TString str(1024);
str.format(FR("Spezzatura delle pagine su %d fogli"), colonne);
if (!yesno_box(str))
return false;
TProgind pi(pages(), str, true, true);
TFilename temp; temp.temp();
ofstream out(temp);
TPointer_array index;
close_output(); // Chiudo file di stampa eventualmente aperto
ifstream ifs(_file); // Apro file di stampa da splittare
char* buffer = str.get_buffer();
for (unsigned int page = 1; page <= pages(); page++)
{
if (!pi.setstatus(page))
break;
const streampos pos = _index.get_long(page);
for (int c = 0; c < colonne; c++)
{
const TRectangle rct_page(c*_pw, 0, _pw, _ph);
ifs.seekg(pos);
while (!ifs.eof())
{
ifs.getline(buffer, str.size());
if (str.starts_with("<page "))
{
const int p = (page-1)*colonne+1+c;
index.add_long(out.tellp(), p);
str.format("<page number=%d>", p);
} else
if (str.starts_with("<frame "))
{
long x, y, dx, dy;
sscanf(str, "<frame x=%ld y=%ld dx=%ld dy=%ld />", &x, &y, &dx, &dy);
str.format("<frame x=%ld y=%ld dx=%ld dy=%ld />", x-rct_page.x, y, dx, dy);
} else
if (str.starts_with("</page "))
{
str.format("</page number=%d>", index.last());
}
out << str << endl;
if (str.starts_with("</page "))
break;
}
}
}
if (ok)
{
if (_printwin != NULL)
delete _printwin;
_printwin = new TWindow_printer(_rcd, _pdf_file);
}
out.close();
return ok;
// Sostituisce il file di stampa con quello splittato ed aggiorna l'indice delle pagine
fcopy(temp, _file);
xvt_fsys_removefile(temp);
_index = index;
_pages = _index.last();
_max_frame = 0; // Impedisce ulteriore splitting
return true;
}
bool TBook::main_loop()
@ -1708,6 +1785,8 @@ bool TBook::print_to_pdf(size_t pagefrom, size_t pageto, size_t copies)
if (pages() <= 0)
return false;
split_file_if_needed();
if (pagefrom == 0)
{
TPrinter& p = printer();
@ -1735,7 +1814,8 @@ bool TBook::print_to_pdf(size_t pagefrom, size_t pageto, size_t copies)
_pagefrom = pagefrom;
_pageto = pageto;
_copies = copies;
_pdf_file = "campo.pdf";
_pdf_file.tempdir();
_pdf_file.add("campo.pdf");
}
xvt_print_start_thread(main_loop_callback, (long)this);
@ -1744,6 +1824,8 @@ bool TBook::print_to_pdf(size_t pagefrom, size_t pageto, size_t copies)
bool TBook::preview()
{
split_file_if_needed();
TPreview_mask msk(this);
const KEY k = msk.run();
switch (k)
@ -1795,13 +1877,10 @@ TBook::TBook(const char* name)
TBook::~TBook()
{
if (_out != NULL)
{
_out->close();
delete _out;
if (_is_temporary)
xvt_fsys_removefile(_file);
}
close_output();
if (_is_temporary)
xvt_fsys_removefile(_file);
if (_printwin != NULL)
delete _printwin;
}
@ -1982,7 +2061,7 @@ long TReport_book::print_section(TReport_section& rs)
rs.init_dynamic_heights(*this);
// Non sono sicuro se vada prima di load_fields o dopo execute_prescript
if (!rs.condition().blank())
if (rs.condition().full())
{
TVariant var;
_report->evaluate(rs.condition(), var, _alfafld);
@ -2173,15 +2252,16 @@ bool TReport_book::add(TReport& rep, bool progind)
return true;
rex->requery();
if (rex->items() <= 0)
const TRecnotype rex_items = rex->items();
if (rex_items <= 0)
return true;
TString msg = TR("Elaborazione report");
msg << ' ' << _report->filename();
TProgind* pi = NULL;
if (progind)
pi = new TPrintind(rex->items(), msg);
if (progind && rex_items > 1)
pi = new TPrintind(rex_items, msg);
TString_array oldgroup, newgroup;
const int max_group = _report->find_max_level('H');
@ -2276,8 +2356,7 @@ bool TReport_book::add(TReport& rep, bool progind)
if (pi != NULL)
{
pi->addstatus(1);
if (pi->iscancelled())
if (!pi->addstatus(1))
_print_aborted = true;
}
@ -2362,6 +2441,7 @@ bool TReport_book::print(size_t pagefrom, size_t pageto, size_t copies)
{
if (pages() <= 0)
return false;
split_file_if_needed();
if (pagefrom <= 0)
{

View File

@ -11,11 +11,12 @@ class TBook : public TObject
{
size_t _page, _pages;
TPointer_array _index;
TFilename _file;
TFilename _pdf_file;
ofstream* _out;
bool _is_temporary;
TFilename _file, _pdf_file; // Nomi dei file di output
ofstream* _out; // File di output
TPointer_array _index; // Indice delle pagine
bool _is_temporary; // Flag di file di output temporaneo
int _max_frame; // Massimo rettangolo scritto sul file di output
DRAW_CTOOLS _tools;
TReport_font _font;
@ -36,6 +37,8 @@ protected:
TPoint log2dev(const TPoint& ptlog) const;
PNT log2pix(const TPoint& ptlog) const;
bool is_pdf() const { return _pdf_file.full(); }
void close_output();
bool split_file_if_needed();
public:
virtual bool open_page();

View File

@ -1235,7 +1235,7 @@ bool TFilename::ok() const
const TFilename& TFilename::tempdir()
{
static TFilename _tempdir;
const bool create = _tempdir.empty() || user().compare(_tempdir.right(user().len()), -1, true);
const bool create = _tempdir.empty() || !_tempdir.ends_with(user(), true);
if (create)
{
@ -1259,8 +1259,7 @@ const TFilename& TFilename::tempdir()
if (ok)
{
TString16 theuser(user());
TString theuser(user());
if (theuser.empty())
theuser = ::dongle().administrator();
theuser.lower();
@ -1277,7 +1276,7 @@ const TFilename& TFilename::tempdir()
TString tmp = _tempdir;
tmp.insert("TMP=", 0);
putenv((char *)(const char *) tmp);
putenv(tmp);
}
set(_tempdir);