Patch level : 2.1 50
Files correlati : reports Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/trunk@12120 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
c030375ba0
commit
b6d60057f4
@ -1081,7 +1081,6 @@ bool TAVM::execute(const TBytecode& cmdline)
|
||||
|
||||
if (_mon.is_open()) // Gestione debugger
|
||||
{
|
||||
lock_preview_update(true);
|
||||
TAVM_list_window& monitor = _mon.monitor();
|
||||
monitor.set_bytecode(_bc, _ip, _user_words);
|
||||
TAVM_stack_window& stacker = _mon.stacker();
|
||||
@ -1101,7 +1100,7 @@ bool TAVM::execute(const TBytecode& cmdline)
|
||||
}
|
||||
break;
|
||||
case K_QUIT: abort_printing();
|
||||
case K_F5 : _mon.close_modal(); lock_preview_update(false); break;
|
||||
case K_F5 : _mon.close_modal(); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@ -1112,10 +1111,7 @@ bool TAVM::execute(const TBytecode& cmdline)
|
||||
}
|
||||
|
||||
if (_mon.is_open()) // Chiudi debugger
|
||||
{
|
||||
_mon.close_modal();
|
||||
lock_preview_update(false);
|
||||
}
|
||||
|
||||
//const bool ok = _bc != NULL; // Not aborted
|
||||
_bc = old_bc;
|
||||
|
@ -3,13 +3,45 @@
|
||||
#include <image.h>
|
||||
#include <recarray.h>
|
||||
#include <relation.h>
|
||||
#include <report.h>
|
||||
#include <reprint.h>
|
||||
#include <xml.h>
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TReport_font
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
int compute_font_match(WINDOW win, int size, int ppi, int cpi)
|
||||
{
|
||||
const TString emme(cpi, 'M');
|
||||
|
||||
int mi = 0, ma = 2*size;
|
||||
int best = 0, best_error = 0;
|
||||
while (mi <= ma)
|
||||
{
|
||||
const int me = (mi+ma)/2;
|
||||
|
||||
XVT_FNTID fontid = xvt_font_create();
|
||||
xvt_font_set_family(fontid, "Courier New");
|
||||
xvt_font_set_size(fontid, me);
|
||||
xvt_dwin_set_font(win, fontid);
|
||||
const int width = xvt_dwin_get_text_width(win, emme, -1);
|
||||
const int error = abs(width - ppi);
|
||||
xvt_font_destroy(fontid);
|
||||
if (best == 0 || error < best_error)
|
||||
{
|
||||
best = me;
|
||||
best_error = error;
|
||||
if (error == 0)
|
||||
break;
|
||||
}
|
||||
if (width > ppi)
|
||||
ma = me-1;
|
||||
else
|
||||
mi = me+1;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
XVT_FNTID TReport_font::get_xvt_font(const TWindow& win) const
|
||||
{
|
||||
if (win.win() != _win_mapped)
|
||||
@ -22,33 +54,7 @@ XVT_FNTID TReport_font::get_xvt_font(const TWindow& win) const
|
||||
const PNT pnt0 = win.log2dev(0,0);
|
||||
const PNT pnt1 = win.log2dev(cpi*100,100);
|
||||
const int ppi = pnt1.h - pnt0.h;
|
||||
const TString emme(cpi, 'M');
|
||||
|
||||
int mi = 0, me = 0, ma = 2*(pnt1.v - pnt0.v);
|
||||
int best = 0, best_error = 0;
|
||||
while (mi <= ma)
|
||||
{
|
||||
me = (mi+ma)/2;
|
||||
|
||||
XVT_FNTID fontid = xvt_font_create();
|
||||
xvt_font_set_family(fontid, "Courier New");
|
||||
xvt_font_set_size(fontid, me);
|
||||
xvt_dwin_set_font(win.win(), fontid);
|
||||
const int width = xvt_dwin_get_text_width(win.win(), emme, -1);
|
||||
const int error = abs(width - ppi);
|
||||
xvt_font_destroy(fontid);
|
||||
if (best == 0 || error < best_error)
|
||||
{
|
||||
best = me;
|
||||
best_error = error;
|
||||
if (error == 0)
|
||||
break;
|
||||
}
|
||||
if (width > ppi)
|
||||
ma = me-1;
|
||||
else
|
||||
mi = me+1;
|
||||
}
|
||||
const int best = compute_font_match(win.win(), (pnt1.v - pnt0.v), ppi, cpi);
|
||||
nSize = cpi * best / _cpi;
|
||||
}
|
||||
|
||||
@ -66,6 +72,31 @@ XVT_FNTID TReport_font::get_xvt_font(const TWindow& win) const
|
||||
return _fontid;
|
||||
}
|
||||
|
||||
XVT_FNTID TReport_font::get_preview_font(const TWindow& win, const TPoint& res) const
|
||||
{
|
||||
if (win.win() != _win_mapped)
|
||||
{
|
||||
const int cpi = 120 / DEFAULT_FONT_SIZE;
|
||||
const PNT pnt0 = win.log2dev(0,0);
|
||||
const PNT pnt1 = win.log2dev(res.x,res.y);
|
||||
const int ppi = pnt1.h - pnt0.h;
|
||||
const int best = compute_font_match(win.win(), (pnt1.v - pnt0.v), ppi, cpi);
|
||||
const int nSize = cpi * best / _cpi;
|
||||
|
||||
XVT_FNTID fontid = xvt_font_create();
|
||||
xvt_font_set_family(fontid, (char*)(const char*)_name);
|
||||
xvt_font_set_size(fontid, nSize);
|
||||
xvt_font_set_style(fontid, _style);
|
||||
|
||||
TReport_font& myself = *(TReport_font*)this;
|
||||
myself.unmap();
|
||||
myself._fontid = fontid;
|
||||
myself._win_mapped = win.win();
|
||||
xvt_dwin_get_font_metrics(_win_mapped, &myself._leading, &myself._ascent, &myself._descent);
|
||||
}
|
||||
return _fontid;
|
||||
}
|
||||
|
||||
void TReport_font::unmap()
|
||||
{
|
||||
if (_fontid != NULL)
|
||||
@ -520,18 +551,6 @@ bool TReport_section::compute_rect(TRectangle& rct) const
|
||||
return !rct.is_empty();
|
||||
}
|
||||
|
||||
void TReport_section::draw(TWindow& win, TReport_draw_mode rdm) const
|
||||
{
|
||||
if (shown() && active())
|
||||
{
|
||||
for (int i = 0; i < items(); i++)
|
||||
{
|
||||
const TReport_field& f = field(i);
|
||||
f.draw(win, rdm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TReport_section::load_fields()
|
||||
{
|
||||
const bool ok = active();
|
||||
@ -565,6 +584,18 @@ bool TReport_section::execute_prescript()
|
||||
return ok;
|
||||
}
|
||||
|
||||
void TReport_section::print(TBook& book) const
|
||||
{
|
||||
if (shown() && active())
|
||||
{
|
||||
for (int i = 0; i < items(); i++)
|
||||
{
|
||||
const TReport_field& f = field(i);
|
||||
f.print(book);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TReport_section::execute_postscript()
|
||||
{
|
||||
bool ok = true;
|
||||
@ -1311,6 +1342,25 @@ void TReport_field::draw(TWindow& win, TReport_draw_mode rdm) const
|
||||
}
|
||||
}
|
||||
|
||||
bool TReport_field::print_tools(TBook& book) const
|
||||
{
|
||||
const bool has_pen = border() > 0;
|
||||
const bool has_brush = (back_color() & 0xFFFFFF) != (COLOR_WHITE & 0xFFFFFF);
|
||||
const bool visible = has_pen || has_brush;
|
||||
if (visible)
|
||||
{
|
||||
book.set_pen(fore_color(), border()-1);
|
||||
book.set_brush(back_color(), has_brush ? PAT_SOLID : PAT_HOLLOW);
|
||||
}
|
||||
return visible;
|
||||
}
|
||||
|
||||
void TReport_field::print_rect(TBook& book) const
|
||||
{
|
||||
if (print_tools(book))
|
||||
book.draw_rectangle(get_draw_rect());
|
||||
}
|
||||
|
||||
void TReport_field::print(TBook& book) const
|
||||
{
|
||||
if (draw_hidden() || draw_deactivated())
|
||||
@ -1319,9 +1369,8 @@ void TReport_field::print(TBook& book) const
|
||||
switch (_type)
|
||||
{
|
||||
case 'E':
|
||||
book.set_pen(fore_color(), border());
|
||||
book.set_brush(back_color());
|
||||
book.draw_ellipse(get_draw_rect());
|
||||
if (print_tools(book))
|
||||
book.draw_ellipse(get_draw_rect());
|
||||
break;
|
||||
case 'I':
|
||||
{
|
||||
@ -1329,22 +1378,24 @@ void TReport_field::print(TBook& book) const
|
||||
book.draw_image(get_draw_rect(), name);
|
||||
if (border() > 0)
|
||||
{
|
||||
book.set_pen(fore_color(), border());
|
||||
book.set_brush(COLOR_WHITE);
|
||||
book.set_pen(fore_color(), border()-1);
|
||||
book.set_brush(COLOR_WHITE, PAT_HOLLOW);
|
||||
book.draw_rectangle(get_draw_rect());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
book.set_pen(fore_color(), border());
|
||||
if (border() > 0)
|
||||
{
|
||||
book.set_pen(fore_color(), border()-1);
|
||||
book.draw_line(get_draw_rect());
|
||||
}
|
||||
break;
|
||||
case 'R':
|
||||
book.set_pen(fore_color(), border());
|
||||
book.set_brush(back_color());
|
||||
book.draw_rectangle(get_draw_rect());
|
||||
print_rect(book);
|
||||
break;
|
||||
case 'T':
|
||||
print_rect(book);
|
||||
if (!_picture.blank())
|
||||
{
|
||||
book.set_font(font());
|
||||
@ -1354,10 +1405,7 @@ void TReport_field::print(TBook& book) const
|
||||
break;
|
||||
default :
|
||||
{
|
||||
book.set_pen(fore_color(), border());
|
||||
book.set_brush(back_color());
|
||||
book.draw_rectangle(get_draw_rect());
|
||||
|
||||
print_rect(book);
|
||||
const TString& str = formatted_text();
|
||||
if (!str.blank())
|
||||
{
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
XVT_FONT_STYLE_MASK style() const { return _style; }
|
||||
int cpi() const { return _cpi; }
|
||||
XVT_FNTID get_xvt_font(const TWindow& win) const;
|
||||
XVT_FNTID get_preview_font(const TWindow& win, const TPoint& res) const;
|
||||
void unmap();
|
||||
|
||||
int leading() const { return _leading; }
|
||||
@ -63,45 +64,8 @@ public:
|
||||
virtual ~TReport_font();
|
||||
};
|
||||
|
||||
class TBook : public TObject
|
||||
{
|
||||
size_t _pages;
|
||||
TPointer_array _index;
|
||||
TFilename _file;
|
||||
ofstream* _out;
|
||||
TPoint _delta;
|
||||
|
||||
DRAW_CTOOLS _tools;
|
||||
TReport_font _font;
|
||||
TRectangle _rect;
|
||||
|
||||
protected:
|
||||
void define_frame(const TRectangle& rect);
|
||||
void do_text(const TString& str);
|
||||
|
||||
public:
|
||||
void start_page();
|
||||
void close_page();
|
||||
|
||||
void set_pen(COLOR color, int width = 0, int style = P_SOLID);
|
||||
void set_brush(COLOR color, int pattern = PAT_SOLID);
|
||||
void set_font(const TReport_font& font);
|
||||
void set_text_color(COLOR color);
|
||||
void set_text_align(char halign ='L', char valign = 'T');
|
||||
void draw_rectangle(const TRectangle& rect);
|
||||
void draw_ellipse(const TRectangle& rect);
|
||||
void draw_line(const TRectangle& rect);
|
||||
void draw_image(const TRectangle& rect, const char* filename);
|
||||
void draw_text(const TRectangle& rect, const char* text);
|
||||
void draw_link(const TRectangle& rect, const char* text, const char* link);
|
||||
|
||||
size_t pages() const { return _pages; }
|
||||
bool draw_page(TWindow& win, size_t page);
|
||||
|
||||
TBook(const char* name);
|
||||
virtual ~TBook();
|
||||
};
|
||||
|
||||
class TBook;
|
||||
class TReport;
|
||||
class TReport_field;
|
||||
|
||||
@ -250,7 +214,7 @@ public:
|
||||
bool load_fields();
|
||||
bool execute_prescript();
|
||||
bool execute_postscript();
|
||||
void draw(TWindow& win, TReport_draw_mode mode) const;
|
||||
void print(TBook& book) const;
|
||||
|
||||
void save(TXmlItem& report) const;
|
||||
void load(const TXmlItem& sec);
|
||||
@ -394,6 +358,9 @@ public:
|
||||
virtual void draw_text(TWindow& win, const char* text, TReport_draw_mode mode) const;
|
||||
|
||||
virtual void draw(TWindow& win, TReport_draw_mode mode) const;
|
||||
|
||||
virtual bool print_tools(TBook& book) const;
|
||||
virtual void print_rect(TBook& book) const;
|
||||
virtual void print(TBook& book) const;
|
||||
|
||||
void save(TXmlItem& root) const;
|
||||
|
1189
include/reprint.cpp
1189
include/reprint.cpp
File diff suppressed because it is too large
Load Diff
@ -5,96 +5,91 @@
|
||||
#include <report.h>
|
||||
#endif
|
||||
|
||||
class TPage_printer : public TWindow
|
||||
class TBook : public TObject
|
||||
{
|
||||
PRINT_RCD* _rcd;
|
||||
long _pw, _ph, _phr, _pvr; // Printer width, height, horizontal and vertical resolution
|
||||
TArray _links;
|
||||
bool _links_sorted;
|
||||
|
||||
protected:
|
||||
word _copies, _pagefrom, _pageto, _page, _lastprinted;
|
||||
bool _page_is_open, _draw_grid;
|
||||
size_t _page, _pages;
|
||||
|
||||
TMask* _preview_mask; // owned object
|
||||
TWindow* _preview_window; // referenced object
|
||||
TPointer_array _index;
|
||||
TFilename _file;
|
||||
ofstream* _out;
|
||||
bool _is_temporary;
|
||||
|
||||
DRAW_CTOOLS _tools;
|
||||
TReport_font _font;
|
||||
TRectangle _rect;
|
||||
char _horizontal_alignment, _vertical_alignment;
|
||||
|
||||
virtual word pages() const { return 0; }
|
||||
virtual bool print_loop() pure;
|
||||
|
||||
private:
|
||||
virtual TPoint dev2log(const PNT& p) const; // Never use this!
|
||||
size_t _pagefrom, _pageto, _copies;
|
||||
|
||||
protected:
|
||||
virtual PNT log2dev(long lx, long ly) const; // Always override this!
|
||||
PRINT_RCD* _rcd;
|
||||
long _ph, _pw, _pvr, _phr;
|
||||
bool _page_is_open;
|
||||
|
||||
virtual const char* form_name() const;
|
||||
virtual const char* font_name() const;
|
||||
virtual int font_size() const;
|
||||
virtual bool ask_pages();
|
||||
|
||||
virtual bool open_page();
|
||||
virtual bool close_page();
|
||||
bool page_in_range() const;
|
||||
|
||||
// Called by print(bool)
|
||||
virtual bool do_print();
|
||||
virtual bool do_preview();
|
||||
virtual void define_frame(const TRectangle& rect);
|
||||
virtual bool init();
|
||||
|
||||
public:
|
||||
bool main_loop(); // Internal use only
|
||||
virtual void print_page(word page); // Inefficient default implementation
|
||||
virtual bool open_page();
|
||||
virtual bool close_page();
|
||||
virtual bool main_loop();
|
||||
|
||||
virtual TPoint page_size() const;
|
||||
virtual TPoint page_res() const;
|
||||
virtual word last_printed_page() { return _lastprinted; }
|
||||
void set_pen(COLOR color, int width = 0, PEN_STYLE style = P_SOLID);
|
||||
void set_brush(COLOR color, PAT_STYLE pattern = PAT_SOLID);
|
||||
void set_font(const TReport_font& font);
|
||||
void set_text_color(COLOR fore, COLOR back = COLOR_WHITE, bool opaque = false);
|
||||
void set_text_align(char halign ='L', char valign = 'T');
|
||||
void draw_rectangle(const TRectangle& rect);
|
||||
void draw_ellipse(const TRectangle& rect);
|
||||
void draw_line(const TRectangle& rect);
|
||||
void draw_image(const TRectangle& rect, const char* filename);
|
||||
void draw_text(const TRectangle& rect, const char* text);
|
||||
void draw_link(const TRectangle& rect, const char* text, const char* link);
|
||||
|
||||
virtual bool print(bool preview = false);
|
||||
bool print_mode() const { return _preview_mask == NULL; }
|
||||
bool preview_mode() const { return _preview_mask != NULL; }
|
||||
TPoint page_size() const;
|
||||
TPoint page_res() const;
|
||||
size_t page() const { return _page; }
|
||||
size_t pages() const { return _pages; }
|
||||
|
||||
virtual bool print_page(TWindow& win, size_t page);
|
||||
|
||||
void toggle_preview_grid() { _draw_grid = !_draw_grid; }
|
||||
bool show_preview_grid() const { return _draw_grid; }
|
||||
virtual bool print(size_t pagefrom = 0, size_t pageto = 0, size_t copies = 0);
|
||||
virtual bool preview();
|
||||
bool print_or_preview(); // Calls one of the above
|
||||
|
||||
void add_link(TReport_link* link);
|
||||
const TReport_link* find_link(const PNT& pnt) const;
|
||||
virtual bool on_link(const TReport_link& lnk);
|
||||
|
||||
TPage_printer();
|
||||
virtual ~TPage_printer();
|
||||
TBook(const char* name);
|
||||
virtual ~TBook();
|
||||
};
|
||||
|
||||
class TReport_printer : public TPage_printer
|
||||
|
||||
class TReport_book : public TBook
|
||||
{
|
||||
TReport& _report;
|
||||
TPoint _delta;
|
||||
TReport* _report;
|
||||
long _logical_page_height, _logical_page_width;
|
||||
long _logical_foot_pos;
|
||||
bool _is_last_page, _page_break_allowed;
|
||||
TPoint _delta;
|
||||
|
||||
protected:
|
||||
virtual const char* form_name() const;
|
||||
virtual const char* font_name() const;
|
||||
virtual int font_size() const;
|
||||
|
||||
virtual PNT log2dev(long x, long y) const;
|
||||
virtual bool print_loop();
|
||||
|
||||
virtual void draw_preview_page();
|
||||
virtual bool open_page();
|
||||
virtual bool close_page();
|
||||
|
||||
TPoint log2dev(const TPoint& ptlog) const;
|
||||
virtual void define_frame(const TRectangle& r);
|
||||
|
||||
bool init(TReport& rep);
|
||||
long print_section(TReport_section& rs);
|
||||
long print_section(char type, int level);
|
||||
void create_links(const TReport_section& rs);
|
||||
|
||||
public:
|
||||
virtual bool print(bool preview = false);
|
||||
virtual bool on_link(const TReport_link& lnk);
|
||||
bool add(TReport& report);
|
||||
|
||||
virtual bool print(size_t pagefrom = 0, size_t pageto = 0, size_t copies = 0);
|
||||
|
||||
TReport_printer(TReport& r) : _report(r) { }
|
||||
TReport_book(const char* name = NULL) : TBook(name) { }
|
||||
};
|
||||
|
||||
void lock_preview_update(bool yes);
|
||||
void abort_printing();
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user