diff --git a/include/array.cpp b/include/array.cpp
index d34df4b11..776edd495 100755
--- a/include/array.cpp
+++ b/include/array.cpp
@@ -867,10 +867,20 @@ bool TBit_array::ok() const
void TBit_array::set(const char* numbers)
{
TToken_string s(numbers, ' ');
- for (const char* n = s.get(0); n; n = s.get())
- if (isdigit(*n)) set(atol(n));
+ s.trim(); s.strip_double_spaces();
+ FOR_EACH_TOKEN(s, n) if (isdigit(*n))
+ set(atol(n));
}
+void TBit_array::reset(const char* numbers)
+{
+ TToken_string s(numbers, ' ');
+ s.trim(); s.strip_double_spaces();
+ FOR_EACH_TOKEN(s, n) if (isdigit(*n))
+ reset(atol(n));
+}
+
+
// @doc EXTERNAL
//
// @mfunc Stampa un array
diff --git a/include/array.h b/include/array.h
index 1cc5e476b..5dc250a8b 100755
--- a/include/array.h
+++ b/include/array.h
@@ -325,6 +325,8 @@ public:
void reset();
// @cmember Data una stringa setta ad 1 gli elementi indicati della stringa
void set(const char* numbers);
+ // @cmember Data una stringa setta a 0 gli elementi indicati della stringa
+ void reset(const char* numbers);
};
#endif
\ No newline at end of file
diff --git a/include/mask.cpp b/include/mask.cpp
index f0a8271e9..d9b01b9b9 100755
--- a/include/mask.cpp
+++ b/include/mask.cpp
@@ -2421,7 +2421,7 @@ int TMask::save_profile(int num, const char* desc) const
{
TString_array p;
TBit_array b(256);
- b.set(255); b.set(); b.reset(0);
+ b.set(255); b.set(); b.reset(0L);
ini.list_paragraphs(p);
FOR_EACH_ARRAY_ROW_BACK(p, r, row)
{
diff --git a/include/report.cpp b/include/report.cpp
index 83ca1cff6..b646140a0 100755
--- a/include/report.cpp
+++ b/include/report.cpp
@@ -15,6 +15,35 @@
static const char MAX_STRING[2] = { (char)255, 0 };
+///////////////////////////////////////////////////////////
+// TReport_rct
+///////////////////////////////////////////////////////////
+
+bool TReport_rct::contains(const TReport_rct& r) const
+{
+ return r.left() >= left() && r.right() <= right() && r.top() >= top() && r.bottom() <= bottom();
+}
+
+bool TReport_rct::intersects(const TReport_rct& r) const
+{
+ if (r.right() < x) return false;
+ if (r.x > right()) return false;
+ if (r.bottom() < y) return false;
+ if (r.y > bottom()) return false;
+ return true;
+}
+
+void TReport_rct::merge(const TReport_rct& rct)
+{
+ long l = x, t = y, r = right(), b = bottom();
+ if (rct.x < l) l = rct.x;
+ if (rct.y < t) t = rct.y;
+ if (rct.right() > r) r = rct.right();
+ if (rct.bottom() > b) b = rct.bottom();
+ x=l; y=t; _size.x = r-l; _size.y = b-t;
+}
+
+
///////////////////////////////////////////////////////////
// TReport_font
///////////////////////////////////////////////////////////
@@ -81,7 +110,7 @@ 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
+XVT_FNTID TReport_font::get_preview_font(const TWindow& win, const TSize& res) const
{
WINDOW w = win.win();
if (w != _win_mapped)
@@ -488,12 +517,12 @@ bool TReport_section::can_be_broken() const
return _can_break && type() == 'B' && level() > 0;
}
-TPoint TReport_section::compute_size() const
+TReport_size TReport_section::compute_size() const
{
if (hidden())
- return TPoint(0,0);
+ return TReport_size(0,0);
- TPoint s = _size;
+ TReport_size s = _size;
// Lo sfondo occupa sempre tutta la pagina
if (type() == 'B' && level() == 0)
@@ -509,7 +538,7 @@ TPoint TReport_section::compute_size() const
const TReport_field& rf = field(i);
if (rf.active() && rf.shown())
{
- const TRectangle& r = rf.get_draw_rect();
+ const TReport_rct& r = rf.get_draw_rect();
if (_size.x <= 0 && r.right() > s.x) // Richiesto calcolo larghezza
s.x = r.right();
if (_size.y <= 0 && r.bottom() > s.y) // Richiesto calcolo altezza
@@ -525,9 +554,9 @@ TPoint TReport_section::compute_size() const
return s;
}
-bool TReport_section::compute_rect(TRectangle& rct) const
+bool TReport_section::compute_rect(TReport_rct& rct) const
{
- rct.set(TPoint(0, 0), compute_size());
+ rct.set(TReport_pnt(0, 0), compute_size());
return !rct.is_empty();
}
@@ -595,7 +624,7 @@ void TReport_section::print(TBook& book) const
{
if (print_tools(book))
{
- TRectangle rct;
+ TReport_rct rct;
compute_rect(rct);
if (_size.x <= 0)
rct.set_width(book.logical_page_width());
@@ -1081,7 +1110,7 @@ void TReport_field::set_size(long w, long h)
_rct.set_height(h);
}
-void TReport_field::offset(const TPoint& pt)
+void TReport_field::offset(const TReport_size& pt)
{
_rct.x += pt.x;
_rct.y += pt.y;
@@ -1107,7 +1136,7 @@ void TReport_field::set_dynamic_height(bool dh)
bool TReport_field::dynamic_height() const
{ return _dynamic_height; }
-const TRectangle& TReport_field::get_draw_rect() const
+const TReport_rct& TReport_field::get_draw_rect() const
{
// Dalla 4.0 il rettangolo e' sempre gia' calcolato correttamente!
return _draw_rct;
@@ -1438,9 +1467,9 @@ bool TReport_field::print_tools(TBook& book) const
return visible;
}
-const TRectangle& TReport_field::compute_draw_rect(const TBook& book)
+const TReport_rct& TReport_field::compute_draw_rect(const TBook& book)
{
- TRectangle& r = _draw_rct;
+ TReport_rct& r = _draw_rct;
r = _rct;
if (dynamic_height())
{
@@ -1455,20 +1484,20 @@ const TRectangle& TReport_field::compute_draw_rect(const TBook& book)
r.set_height(100);
}
else
- r.set_height(100);
+ r.set_height(100); // r.set_height(0) could be better, but what about MESSAGE_ALIGN?
}
return r;
}
-const TRectangle& TReport_field::print_rect(const TRectangle& rect, TBook& book) const
+const TReport_rct& TReport_field::print_rect(const TReport_rct& rect, TBook& book) const
{
if (pattern() == PAT_SOLID && shade_offset() != 0)
{
book.set_pen(COLOR_GRAY, 0);
const COLOR color = blend_colors(section().back_color(), COLOR_BLACK, 0.5);
book.set_brush(color, PAT_SOLID);
- TRectangle rct = rect;
- rct += TPoint(shade_offset(), shade_offset() * section().report().print_lpi() / print_font().cpi());
+ TReport_rct rct = rect;
+ rct += TReport_size(shade_offset(), shade_offset() * section().report().print_lpi() / print_font().cpi());
if (radius() > 0)
book.draw_round_rectangle(rct, radius());
else
@@ -1485,9 +1514,9 @@ const TRectangle& TReport_field::print_rect(const TRectangle& rect, TBook& book)
return rect;
}
-const TRectangle& TReport_field::print_rect(TBook& book) const
+const TReport_rct& TReport_field::print_rect(TBook& book) const
{
- const TRectangle& rect = get_draw_rect();
+ const TReport_rct& rect = get_draw_rect();
return print_rect(rect, book);
}
@@ -1500,8 +1529,8 @@ void TReport_field::print(TBook& book) const
{
if (link().full()) // Devo "stampare" i link anche se nascosti
{
- TRectangle rct = get_draw_rect();
- rct.set_height(0); rct.set_width(0);
+ TReport_rct rct = get_draw_rect();
+ rct.set_empty();
book.draw_link(rct, formatted_text(), link());
}
return;
@@ -1512,9 +1541,9 @@ void TReport_field::print(TBook& book) const
case 'B':
if (is_power_reseller())
{
- const TRectangle& rctout = get_draw_rect();
+ const TReport_rct& rctout = get_draw_rect();
const int side = 3*rctout.height()/4;
- TRectangle rctin(rctout.x, rctout.y, 2*side, side);
+ TReport_rct rctin(rctout.x, rctout.y, 2*side, side);
if (_halign == 'C') rctin.x += (rctout.width() - rctin.width())/2; else
if (_halign == 'R') rctin.x = rctout.right() - side;
if (_valign == 'C') rctin.y += (rctout.height() - rctin.height())/2; else
@@ -1536,7 +1565,7 @@ void TReport_field::print(TBook& book) const
book.set_font(print_font());
book.set_text_align(horizontal_alignment(), vertical_alignment());
book.set_text_color(fore_color(), back_color());
- const TRectangle& pr = print_rect(book);
+ const TReport_rct& pr = print_rect(book);
TString8 sec_code; section().code(sec_code);
book.draw_text(pr, str, sec_code);
}
@@ -1550,7 +1579,7 @@ void TReport_field::print(TBook& book) const
case 'I':
{
const TString& name = get().as_string();
- const TRectangle& rct = get_draw_rect();
+ const TReport_rct& rct = get_draw_rect();
book.draw_image(rct, name);
if (border() > 0)
{
@@ -1571,15 +1600,22 @@ void TReport_field::print(TBook& book) const
print_rect(book);
break;
case 'T':
- print_rect(book);
if (_picture.full())
{
book.set_font(print_font());
- const TRectangle& pr = print_rect(book); // Calcolo rettangolo dopo aver settato il font!
+ const TReport_rct& pr = print_rect(book); // Calcolo rettangolo dopo aver settato il font!
book.set_text_align(horizontal_alignment(), vertical_alignment());
book.set_text_color(fore_color(), back_color());
TString8 sec_code; section().code(sec_code);
- book.draw_text(pr, _picture, sec_code);
+ if (pr.height() > 100) // Multiriga?
+ {
+ TString_array para;
+ TReport_rct rect = pr; // Potrebbe risultare piu' grande del print_rect!
+ book.compute_text_frame(_picture, print_font(), rect, para);
+ book.draw_text(pr, para, sec_code); // Stampa paragrafo nello spazio assegnato
+ }
+ else
+ book.draw_text(pr, _picture, sec_code);
}
else
print_rect(book);
@@ -1587,7 +1623,7 @@ void TReport_field::print(TBook& book) const
case 'N':
if (field() == "#BOOKPAGES")
{
- const TRectangle& pr = print_rect(book);
+ const TReport_rct& pr = print_rect(book);
book.draw_book_pages(pr);
break;
}
@@ -1604,14 +1640,14 @@ void TReport_field::print(TBook& book) const
if (dynamic_height() || _rct.height() > 100) // Multiriga?
{
TString_array para;
- TRectangle rect = get_draw_rect();
+ TReport_rct rect = get_draw_rect();
book.compute_text_frame(str, print_font(), rect, para);
print_rect(_draw_rct, book); // Stampa eventuale cornice
book.draw_text(_draw_rct, para, sec_code); // Stampa paragrafo
}
else
{
- const TRectangle& pr = print_rect(book);
+ const TReport_rct& pr = print_rect(book);
book.draw_text(pr, str, sec_code);
if (link().full())
book.draw_link(pr, str, link());
@@ -1626,10 +1662,20 @@ void TReport_field::print(TBook& book) const
}
}
+void TReport_field::add_groups(const TString& groups)
+{
+ _groups.set(groups);
+}
+
+void TReport_field::del_groups(const TString& groups)
+{
+ _groups.reset(groups);
+}
+
void TReport_field::set_groups(const TString& groups)
{
_groups.reset();
- _groups.set(groups);
+ add_groups(groups);
}
const TString& TReport_field::groups() const
@@ -1651,7 +1697,7 @@ void TReport_field::save(TXmlItem& root) const
TXmlItem& fld = root.AddChild("field");
fld.SetAttr("type", type_name());
- const TRectangle& rct = get_rect();
+ const TReport_rct& rct = get_rect();
fld.SetAttr("id", _id);
set_num_attr(fld, "x", rct.left());
set_num_attr(fld, "y", rct.top());
@@ -3050,7 +3096,7 @@ bool TReport::execute_usr_word(unsigned int opcode, TVariant_stack& stack)
if (fld != NULL)
{
- const TRectangle& r = fld->get_draw_rect();
+ const TReport_rct& r = fld->get_draw_rect();
x = r.x / CENTO; y = r.y / CENTO;
}
}
@@ -3077,7 +3123,7 @@ bool TReport::execute_usr_word(unsigned int opcode, TVariant_stack& stack)
if (fld != NULL)
{
- const TRectangle& r = fld->get_draw_rect();
+ const TReport_rct& r = fld->get_draw_rect();
w = r.width() / CENTO; h = r.height() / CENTO;
}
}
diff --git a/include/report.h b/include/report.h
index c042e43ea..1e2543675 100755
--- a/include/report.h
+++ b/include/report.h
@@ -57,7 +57,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;
+ XVT_FNTID get_preview_font(const TWindow& win, const TSize& res) const;
void unmap();
void save(TXmlItem& root) const;
@@ -145,14 +145,78 @@ public:
enum TReport_draw_mode { rdm_print, rdm_preview };
+struct TReport_size : public TSize
+{
+ TReport_size(const TSize&) { CHECK(false, "Invalid TReport_size conversion"); }
+
+public:
+ void reset() { x = y = 0; }
+ TReport_size& operator+=(const TReport_size& p) { x+=p.x; y+=p.y; return *this; }
+ TReport_size() {}
+ TReport_size(int sx, int sy) : TSize(sx, sy) { }
+ TReport_size(const TReport_size& s) : TSize(s) { }
+};
+
+// Coordinate (x,y) espresse in (1/100 di carattere, 1/100 di riga)
+struct TReport_pnt : public TPoint
+{
+private:
+ TReport_pnt(const TPoint&) { CHECK(false, "Invalid TReport_pnt conversion"); }
+
+public:
+ TReport_pnt& operator+=(const TReport_size& p) { x+=p.x; y+=p.y; return *this; }
+ TReport_pnt& operator-=(const TReport_size& p) { x-=p.x; y-=p.y; return *this; }
+ TReport_size operator-(const TReport_pnt& p) const { return TReport_size(x-p.x, y-p.y); }
+
+ TReport_pnt() {}
+ TReport_pnt(int cx, int cy) : TPoint(cx, cy) { }
+ TReport_pnt(const TReport_pnt& p) : TPoint(p) {}
+};
+
+
+class TReport_rct : public TReport_pnt
+{
+ TReport_size _size;
+
+protected:
+ void normalize()
+ {
+ if (_size.x < 0) { _size.x=-_size.x; x-=_size.x; }
+ if (_size.y < 0) { _size.y=-_size.y; y-=_size.y; }
+ }
+
+public:
+ const TReport_size& size() const { return _size; }
+ int width() const { return _size.x; }
+ int height() const { return _size.y; }
+ int left() const { return x; }
+ int top() const { return y; }
+ int right() const { return x+_size.x; }
+ int bottom() const { return y+_size.y; }
+ void set_height(int h) { _size.y = h; normalize(); }
+ void set_width(int w) { _size.x = w; normalize(); }
+ void set_empty() { _size.reset(); }
+ bool is_empty() const { return _size.x == 0 || _size.y == 0; }
+ void set(const TReport_pnt& p, const TReport_size& s) { x=p.x; y=p.y; _size=s; normalize(); }
+ void deflate(int dx, int dy) { x+=dx; y+=dy; _size.x-=2*dx; _size.y-=2*dy; normalize(); }
+ bool contains(const TReport_pnt& p) const { return p.x >= x && p.x <= right() && p.y > y && p.y <= bottom(); }
+ bool contains(const TReport_rct& r) const;
+ bool intersects(const TReport_rct& r) const;
+ void merge(const TReport_rct& rct);
+
+ TReport_rct() {}
+ TReport_rct(int cx, int cy, int w, int h) : TReport_pnt(cx, cy), _size(w, h) { normalize(); }
+};
+
+
class TReport_section : public TArray
{
TReport& _report;
char _type; // Head,Body,Tail
int _level; // 0,1,2,...
- TPoint _pos; // Posizione assoluta in centesimi, default (0,0)
- TPoint _size; // Dimensioni in centesimi, default (0,0)
+ TReport_pnt _pos; // Posizione assoluta in centesimi, default (0,0)
+ TReport_size _size; // Dimensioni in centesimi, default (0,0)
TString _condition, _groupby;
bool _page_break, _hidden_if_needed, _can_break, _keep_with_next, _repeat;
bool _hidden, _deactivated;
@@ -186,11 +250,11 @@ public:
int height() const { return _size.y; }
void set_width(short w) { _size.x = w; }
void set_height(short h) { _size.y = h; }
- const TPoint& size() const { return _size; }
- TPoint compute_size() const;
- bool compute_rect(TRectangle& rct) const;
- const TPoint& pos() const { return _pos; }
- void set_pos(const TPoint& p) { _pos = p; }
+ const TReport_size& size() const { return _size; }
+ TReport_size compute_size() const;
+ bool compute_rect(TReport_rct& rct) const;
+ const TReport_pnt& pos() const { return _pos; }
+ void set_pos(const TReport_pnt& p) { _pos = p; }
void set_fore_color(COLOR c) { _fgcolor = c; }
COLOR fore_color() const { return _fgcolor; }
@@ -268,8 +332,8 @@ class TReport_field : public TSortable
{
TReport_section* _section;
int _id;
- char _type; // Text, String, Numeric, Price, Valuta, Date, Line, Rectangle, Image
- TRectangle _rct; // In centesimi
+ char _type; // Text, String, Numeric, Price, Valuta, Date, Boolean, Line, Rectangle, Image
+ TReport_rct _rct; // In centesimi
COLOR _fgcolor, _bgcolor;
int _border, _radius, _shade_offset;
PAT_STYLE _pattern;
@@ -285,7 +349,7 @@ class TReport_field : public TSortable
TReport_font *_font, *_print_font;
bool _hidden, _deactivated, _hide_zeroes, _selected;
- TRectangle _draw_rct; // In centesimi
+ TReport_rct _draw_rct; // In centesimi
bool _draw_hidden, _draw_deactivated;
protected:
@@ -343,7 +407,7 @@ public:
void set_size(long w, long h);
void set_width(long dx) { _rct.set_width(dx); }
void set_height(long dy) { _rct.set_height(dy); }
- const TRectangle& get_rect() const { return _rct; }
+ const TReport_rct& get_rect() const { return _rct; }
void set_dynamic_height(bool dh);
bool dynamic_height() const;
@@ -367,12 +431,16 @@ public:
void set_draw_pos(long x, long y);
void set_draw_size(long x, long y);
- const TRectangle& compute_draw_rect(const TBook& book);
- const TRectangle& get_draw_rect() const;
+ const TReport_rct& compute_draw_rect(const TBook& book);
+ const TReport_rct& get_draw_rect() const;
void set_groups(const TString& groups);
+ void add_groups(const TString& groups);
+ void del_groups(const TString& groups);
const TString& groups() const;
bool in_group(int group) const;
+
+
void set_codval(const char* cod) { _codval = cod; }
const TString& codval() const { return _codval; }
void set_link(const char* l) { _link = l; }
@@ -405,11 +473,11 @@ public:
void select(bool ok = true) { _selected = ok; }
bool selected() const { return _selected; }
- void offset(const TPoint& pt);
+ void offset(const TReport_size& off);
bool print_tools(TBook& book) const;
- const TRectangle& print_rect(const TRectangle& rect, TBook& book) const;
- const TRectangle& print_rect(TBook& book) const;
+ const TReport_rct& print_rect(const TReport_rct& rect, TBook& book) const;
+ const TReport_rct& print_rect(TBook& book) const;
void print(TBook& book) const;
void save(TXmlItem& root) const;
diff --git a/include/reprint.cpp b/include/reprint.cpp
index 18ad3a0f3..7667b121b 100755
--- a/include/reprint.cpp
+++ b/include/reprint.cpp
@@ -73,7 +73,7 @@ void advanced_draw_text_line(WINDOW w, const char* text, const RCT& r, char hali
switch (halign)
{
case 'C': x += (dx - tw)/2; break;
- case 'R': x = r.right-tw; break;
+ case 'R': x = r.right-tw-1; break;
default : break;
}
}
@@ -112,7 +112,6 @@ void advanced_draw_text_line(WINDOW w, const char* text, const RCT& r, char hali
if (restore_clip)
xvt_dwin_set_clip(w, &orig);
}
-
}
bool finisce_per_punto(const TString& str)
@@ -151,17 +150,18 @@ void advanced_draw_paragraph(WINDOW win, const TString_array& para, const RCT& r
default : break;
}
+ const int lastop = rct.bottom - ky10/20; // Ultima y valida = base del rettangolo MENO mezza riga
for (int row = 0; row < rows; row++)
{
const int top = ybase + (ky10 * row) / 10;
- if (top < rct.bottom)
+ if (top < lastop)
{
const TString& line = para.row(row);
if (line.full())
{
RCT rctline = rct;
rctline.top = top;
- rctline.bottom = top + ky10 / 10;
+ rctline.bottom = ybase + (ky10 * (row+1)) / 10; // top + ky10 / 10;
char ha = halign;
if (ha == 'J' && (row == rows-1 || finisce_per_punto(line)))
ha = 'L'; // Le righe finali non vanno giustificate
@@ -277,19 +277,12 @@ public:
short TPrint_preview_window::book2pix(int sz) const
{
- return short(sz * _zoom / 720);
+ return short(sz * _zoom / BOOKDPI);
}
PNT TPrint_preview_window::log2dev(long lx, long ly) const
{
- PNT pnt = { short(ly), short(lx) };
-
- const TPoint res = _book->page_res();
- if (res.x > 0 && res.y > 0) // Should always be true :-)
- {
- pnt.h = short(lx * _zoom / res.x);
- pnt.v = short(ly * _zoom / res.y);
- }
+ PNT pnt = { book2pix(ly), book2pix(lx) };
const TPoint orig = origin();
pnt.h -= short(orig.x);
@@ -302,7 +295,7 @@ void TPrint_preview_window::update_scroll_range()
{
update_thumb(0, 0); // Azzero origine
- const TPoint pag = _book->page_size();
+ const TSize pag = _book->page_size();
const PNT pnt = log2dev(pag.x, pag.y);
RCT rct; xvt_vobj_get_client_rect(win(), &rct);
@@ -316,7 +309,7 @@ void TPrint_preview_window::draw_page(int pg)
{
RCT rct; xvt_vobj_get_client_rect(win(), &rct);
- const TPoint size = _book->page_size();
+ const TSize size = _book->page_size();
const PNT pag = log2dev(size.x, size.y);
const PNT ori = log2dev(0, 0);
if (ori.h > 0) rct.left = ori.h;
@@ -334,7 +327,7 @@ void TPrint_preview_window::draw_page(int pg)
if (_grid)
{
- const TPoint res = _book->page_res();
+ const TSize res = _book->page_res();
const int lpi = _book->lpi();
for (int i = 1; lpi > 0; i++)
{
@@ -370,7 +363,7 @@ void TPrint_preview_window::update()
{
const TPoint o = origin();
set_origin(0, 0);
- const TPoint size = _book->page_size();
+ const TSize size = _book->page_size();
const PNT pag = log2dev(size.x, size.y);
RCT rct; xvt_vobj_get_client_rect(win(), &rct);
const int nh = rct.right / (pag.h+2), nv = rct.bottom / (pag.v+2);
@@ -827,17 +820,26 @@ TWindow_printer::~TWindow_printer()
///////////////////////////////////////////////////////////
// Converte da coordinate logiche (1/100 caratteri) a coordinate di stampa
-TPoint TBook::log2dev(const TPoint& ptlog) const
+TPoint TBook::log2dev(const TReport_pnt& ptlog) const
{
TPoint ptdev;
- ptdev.x = (ptlog.x * _phr) / (100 * cpi());
- ptdev.y = (ptlog.y * _pvr) / (100 * lpi());
+ ptdev.x = (ptlog.x * BOOKDPI) / (100 * cpi());
+ ptdev.y = (ptlog.y * BOOKDPI) / (100 * lpi());
return ptdev;
}
-PNT TBook::log2pix(const TPoint& ptlog) const
+TRectangle TBook::log2dev(const TReport_rct& rctlog) const
{
- TPoint ptdev = log2dev(ptlog);
+ const TReport_pnt& lp0 = rctlog;
+ TReport_pnt lp1 = lp0; lp1 += rctlog.size();
+ const TPoint p0 = log2dev(lp0);
+ const TPoint p1 = log2dev(lp1);
+ return TRectangle(p0, p1-p0);
+}
+
+PNT TBook::log2pix(const TReport_pnt& ptlog) const
+{
+ const TPoint ptdev = log2dev(ptlog);
return _printwin->log2dev(ptdev.x, ptdev.y);
}
@@ -848,13 +850,19 @@ short TBook::book2pix(int t) const
return pnt.h;
}
-int TBook::compute_text_frame(const TString& tmp, const TReport_font& font, TRectangle& rect, TString_array& para) const
+int TBook::compute_text_frame(const TString& tmp, const TReport_font& font, TReport_rct& rect, TString_array& para) const
{
// Calcola la larghezza massima e l'altezza di 10 righe
- const TRectangle rect_riga(0,0,rect.width(),1000);
- const PNT size = log2pix(rect_riga.size());
- const int max_row_width = size.h;
- const int def_10row_height = size.v;
+ // const TReport_rct rect_riga(0,0,rect.width(),1000);
+ // const PNT size = log2pix(rect_riga.size());
+ // const int max_row_width = size.h;
+ // const int def_10row_height = size.v;
+ const PNT p0 = log2pix(TReport_pnt(0,0));
+ const PNT p1 = log2pix(TReport_pnt(rect.width(),1000));
+ const int max_row_width = p1.h-p0.h;
+ const int def_10row_height = p1.v-p0.v;
+ if (max_row_width < 100)
+ return 0; // Con un rettangolo quasi vuoto, si combina poco di buono!
WINDOW w = _printwin->win();
CHECK(w == PRINTER_WIN, "Finestra di stampa non valida");
@@ -915,23 +923,19 @@ int TBook::compute_text_frame(const TString& tmp, const TReport_font& font, TRec
return ky10;
}
-TPoint TBook::page_size() const
+TSize TBook::page_size() const
{
- if (_pw <= 0 || _ph <= 0) // Valori nulli: mi invento un A4
+ if (_page_size.x <= 0 || _page_size.y <= 0) // Valori nulli: mi invento un A4
{
- TPoint pag = page_res();
+ TSize pag = page_res();
pag.x *= 8; pag.y *= 11;
return pag;
}
- return TPoint(_pw, _ph);
+ return _page_size;
}
-TPoint TBook::page_res() const
-{
- const int resx = _phr > 0 ? _phr : 96;
- const int resy = _pvr > 0 ? _pvr : 96;
- return TPoint(resx, resy);
-}
+TSize TBook::page_res() const
+{ return TSize(BOOKDPI, BOOKDPI); }
bool TBook::open_page()
{
@@ -1004,6 +1008,12 @@ void TBook::define_frame(const TRectangle& rect)
}
}
+void TBook::define_frame(const TReport_rct& rr)
+{
+ const TRectangle rb = log2dev(rr); // Converto rr da coordinate logiche a rb a 720 DPI
+ define_frame(rb); // Salvo le coordinate a 720 DPI
+}
+
void TBook::set_clip(long top, long bottom)
{
if (bottom >= top)
@@ -1016,7 +1026,7 @@ void TBook::set_clip(long top, long bottom)
*_out << "" << endl;
}
-void TBook::draw_text(const TRectangle& r, const char* txt, const char* section)
+void TBook::draw_text(const TReport_rct& r, const char* txt, const char* section)
{
if (txt && *txt)
{
@@ -1030,7 +1040,7 @@ void TBook::draw_text(const TRectangle& r, const char* txt, const char* section)
}
}
-void TBook::draw_text(const TRectangle& r, const TString_array& txt, const char* section)
+void TBook::draw_text(const TReport_rct& r, const TString_array& txt, const char* section)
{
if (!txt.empty())
{
@@ -1045,7 +1055,7 @@ void TBook::draw_text(const TRectangle& r, const TString_array& txt, const char*
}
}
-void TBook::draw_book_pages(const TRectangle& r)
+void TBook::draw_book_pages(const TReport_rct& r)
{
define_frame(r);
*_out << "" << endl;
@@ -1097,37 +1107,37 @@ void TBook::set_text_align(char halign, char valign)
}
}
-void TBook::draw_rectangle(const TRectangle& r)
+void TBook::draw_rectangle(const TReport_rct& r)
{
define_frame(r);
*_out << "" << endl;
}
-void TBook::draw_round_rectangle(const TRectangle& r, int radius)
+void TBook::draw_round_rectangle(const TReport_rct& r, int radius)
{
define_frame(r);
*_out << "" << endl;
}
-void TBook::draw_ellipse(const TRectangle& r)
+void TBook::draw_ellipse(const TReport_rct& r)
{
define_frame(r);
*_out << "" << endl;
}
-void TBook::draw_line(const TRectangle& r)
+void TBook::draw_line(const TReport_rct& r)
{
define_frame(r);
*_out << "" << endl;
}
-void TBook::draw_link(const TRectangle& rect, const char* text, const char* link)
+void TBook::draw_link(const TReport_rct& rect, const char* text, const char* link)
{
define_frame(rect);
*_out << "" << text << "" << endl;
}
-void TBook::draw_image(const TRectangle& rect, const char* name)
+void TBook::draw_image(const TReport_rct& rect, const char* name)
{
define_frame(rect);
*_out << "" << endl;
@@ -1195,7 +1205,7 @@ void TBook::print_doc(TWindow& win, const TFilename& name)
}
else
{
- TPoint ps = page_size();
+ const TSize ps = page_size();
TRectangle rect(TPoint(0,0), ps);
RCT page; win.log2dev(rect, page);
advanced_draw_text_line(win.win(), name, page, 'C', 'T');
@@ -1206,7 +1216,7 @@ void TBook::print_doc(TWindow& win, const TFilename& name)
const TImage* img = _images.image(name);
if (img != NULL)
{
- const TPoint pr = page_res();
+ const TSize pr = page_res();
rect.deflate(pr.x/2, pr.y/2);
win.log2dev(rect, page);
@@ -1247,7 +1257,7 @@ bool TBook::print_page(TWindow& win, size_t page)
TString_array paragrafo; // Testo completo di un campo
// Calcolo altezza riga standard
- const TRectangle rect_riga(0,0,1000,1000);
+ const TRectangle rect_riga(0,0,BOOKDPI*10/cpi(),BOOKDPI*10/lpi());
RCT rct_riga; win.log2dev(rect_riga, rct_riga);
const int default_10row_height = rct_riga.bottom - rct_riga.top;
@@ -1440,7 +1450,7 @@ bool TBook::print_page(TWindow& win, size_t page)
{
t = book2pix(width ? 10*width : 5); // width e' in 1/72 di pollice
}
- const int thickness = short(t+0.5); // Arrotonda all'unita' piu' vicina
+ const int thickness = int(t+0.5); // Arrotonda all'unita' piu' vicina
win.set_pen(col, thickness);
}
continue;
@@ -1471,8 +1481,7 @@ bool TBook::print_page(TWindow& win, size_t page)
paragrafo.add(str);
}
advanced_draw_paragraph(win.win(), paragrafo, rct,
- _horizontal_alignment, _vertical_alignment,
- default_10row_height);
+ _horizontal_alignment, _vertical_alignment, default_10row_height);
continue;
}
if (str.starts_with(" _ph) // width > height -> landscape
- xvt_app_escape (XVT_ESC_SET_PRINTER_INFO, _rcd, &_ph, &_pw, &_pvr, &_phr);
+ if (_page_size.x > _page_size.y) // width > height -> landscape
+ {
+ ph = _page_size.y; pw = _page_size.x;
+ xvt_app_escape (XVT_ESC_SET_PRINTER_INFO, _rcd, &ph, &pw, NULL, NULL);
+ }
}
else
_rcd = printer().get_printrcd();
@@ -1838,16 +1852,15 @@ bool TBook::init()
if (!xvt_print_is_valid(_rcd))
return error_box(TR("Stampante non valida"));
- xvt_app_escape (XVT_ESC_GET_PRINTER_INFO, _rcd, &_ph, &_pw, &_pvr, &_phr);
+ xvt_app_escape (XVT_ESC_GET_PRINTER_INFO, _rcd, &ph, &pw, &pvr, &phr);
- if (_pw <= 0 || _ph <= 0)
+ if (pw <= 0 || ph <= 0)
return error_box(TR("Dimensioni pagina NULLE"));
- if (_pvr <= 0 || _phr <= 0)
+ if (pvr <= 0 || phr <= 0)
return error_box(TR("Risoluzione stampante NULLA"));
- _ph = _ph * BOOKDPI / _pvr;
- _pw = _pw * BOOKDPI / _phr;
- _pvr = _phr = BOOKDPI;
+ _page_size.y = ph * BOOKDPI / pvr;
+ _page_size.x = pw * BOOKDPI / phr;
if (_printwin != NULL)
delete _printwin;
@@ -1875,7 +1888,7 @@ void TBook::split_file(int colonne)
const streampos pos = _index.get_long(page);
for (int c = 0; c < colonne; c++)
{
- const TRectangle rct_page(c*_pw, 0, _pw, _ph);
+ const TRectangle rct_page(c*_page_size.x, 0, _page_size.x, _page_size.y);
ifs.seekg(pos);
while (!ifs.eof())
@@ -2017,7 +2030,7 @@ bool TBook::split_file_if_needed()
{
if (_max_frame.x > 100 && _max_frame.y > 100) // Evita calcolo splitting se possibile
{
- const TPoint sheet(_pw, _ph);
+ const TSize sheet = page_size();
const int spp = _max_frame.x > sheet.x ? (_max_frame.x+sheet.x-1) / sheet.x : 1;
if (spp > 1 && can_split(spp)) // Sheets per page
@@ -2257,10 +2270,7 @@ bool TBook::print_or_preview()
{
TFilename f; f.tempdir(); f.add("tmp.pdf");
if (export_pdf(f, false))
- {
printer().acrobatically_print_pdf(f);
- f.fremove();
- }
}
break;
default: ok = print(); break;
@@ -2269,11 +2279,8 @@ bool TBook::print_or_preview()
}
TBook::TBook(const char* name)
- : _out(NULL), _is_temporary(false),
- _pw(0), _ph(0), _pvr(0), _phr(0), _max_frame(0,0),
+ : _out(NULL), _is_temporary(false), _max_frame(0,0),
_pages(0), _page(0), _rcd(NULL), _printwin(NULL), _page_is_open(false)
-
-
{
_file = name;
if (_file.blank())
@@ -2347,12 +2354,10 @@ TPrintind::TPrintind(long n, const char* msg) : TProgind(n, msg, true, true)
// TReport_book
///////////////////////////////////////////////////////////
-void TReport_book::define_frame(const TRectangle& r)
+void TReport_book::define_frame(const TReport_rct& rr)
{
- TPoint ptlog = r; ptlog += _delta;
- TPoint szlog = r.size();
- const TRectangle rect(log2dev(ptlog), log2dev(szlog));
- TBook::define_frame(rect);
+ TReport_rct ro(rr); ro += _delta; // Applico offset al rettangolo logico
+ TBook::define_frame(ro); // Salvo le coordinate a 720 DPI
}
long TReport_book::print_section(char type, int level)
@@ -2377,7 +2382,8 @@ bool TReport_book::open_page()
TReport_section* page_background = _report->find_section('B', 0);
if (page_background != NULL)
{
- _delta = page_background->pos();
+ const TReport_pnt& pos = page_background->pos();
+ _delta.x = pos.x; _delta.y = pos.y;
print_section(*page_background);
_delta.reset();
}
@@ -2392,7 +2398,8 @@ bool TReport_book::open_page()
TReport_section* page_head = _report->find_section('H', 0);
if (page_head != NULL && (_rep_page > 1 || !page_head->hidden_if_needed()))
{
- _delta += page_head->pos();
+ const TReport_pnt& pos = page_head->pos();
+ _delta.x += pos.x; _delta.y += pos.y;
const long height = print_section(*page_head);
if (height > 0)
{
@@ -2523,7 +2530,7 @@ long TReport_book::print_section(TReport_section& rs)
}
const TReport_section& next_section = rs.report().section(next_type, next_level);
if (next_section.page_break())
- h += _ph;
+ h += _page_size.y;
else
h += next_section.compute_size().y;
}
@@ -2607,8 +2614,8 @@ bool TReport_book::init(TReport& rep)
if (rep.use_printer_font())
rep.load_printer_font();
- const TPoint siz = page_size();
- const TPoint res = page_res();
+ const TSize siz = page_size();
+ const TSize res = page_res();
const double pollici_pagina_y = (double)siz.y / (double)res.y;
const double righe_pagina = pollici_pagina_y * lpi();
@@ -2712,8 +2719,7 @@ bool TReport_book::add(TReport& rep, bool progind)
if (rex_items <= 0)
return true;
- TString msg = TR("Elaborazione report");
- msg << ' ' << _report->filename();
+ TString msg; msg << TR("Elaborazione report ") << _report->filename();
TProgind* pi = NULL;
if (progind && rex_items > 1)
diff --git a/include/reprint.h b/include/reprint.h
index 5ee81e7d9..dbb995ddc 100755
--- a/include/reprint.h
+++ b/include/reprint.h
@@ -26,17 +26,22 @@ class TBook : public TObject
size_t _pagefrom, _pageto;
TPoint _max_frame;
word _copies;
-
+
+private:
+ void define_frame(const TRectangle& rect); // Salva su file un a 720 DPI
+
protected:
PRINT_RCD* _rcd;
TWindow* _printwin;
- long _ph, _pw, _pvr, _phr;
+ TSize _page_size; // Dimensioni stampabili a 720 DPI
bool _page_is_open;
- virtual void define_frame(const TRectangle& rect);
+ virtual void define_frame(const TReport_rct& rect);
+
virtual bool init();
- TPoint log2dev(const TPoint& ptlog) const;
- PNT log2pix(const TPoint& ptlog) const;
+ TPoint log2dev(const TReport_pnt& ptlog) const;
+ TRectangle log2dev(const TReport_rct& rctlog) const;
+ PNT log2pix(const TReport_pnt& ptlog) const;
short book2pix(int thickness) const;
void print_doc(TWindow& win, const TFilename& name);
void close_output();
@@ -57,23 +62,23 @@ public:
virtual void set_font(const TReport_font& font);
virtual void set_text_color(COLOR fore, COLOR back = COLOR_WHITE, bool opaque = false);
virtual void set_text_align(char halign ='L', char valign = 'T');
- virtual void draw_rectangle(const TRectangle& rect);
- virtual void draw_round_rectangle(const TRectangle& rect, int radius);
- virtual void draw_ellipse(const TRectangle& rect);
- virtual void draw_line(const TRectangle& rect);
- virtual void draw_image(const TRectangle& rect, const char* filename);
- virtual void draw_text(const TRectangle& rect, const char* text, const char* owner);
- virtual void draw_text(const TRectangle& rect, const TString_array& text, const char* owner);
- virtual void draw_link(const TRectangle& rect, const char* text, const char* link);
- virtual void draw_book_pages(const TRectangle& r);
+ virtual void draw_rectangle(const TReport_rct& rect);
+ virtual void draw_round_rectangle(const TReport_rct& rect, int radius);
+ virtual void draw_ellipse(const TReport_rct& rect);
+ virtual void draw_line(const TReport_rct& rect);
+ virtual void draw_image(const TReport_rct& rect, const char* filename);
+ virtual void draw_text(const TReport_rct& rect, const char* text, const char* owner);
+ virtual void draw_text(const TReport_rct& rect, const TString_array& text, const char* owner);
+ virtual void draw_link(const TReport_rct& rect, const char* text, const char* link);
+ virtual void draw_book_pages(const TReport_rct& r);
virtual void set_clip(long top, long bottom);
- virtual int compute_text_frame(const TString& txt, const TReport_font& font, TRectangle& rect, TString_array& para) const;
+ virtual int compute_text_frame(const TString& txt, const TReport_font& font, TReport_rct& rect, TString_array& para) const;
virtual void add_doc(const TString& name);
virtual bool can_split(int pages) const;
virtual bool can_merge(int pages) const;
- TPoint page_size() const;
- TPoint page_res() const;
+ TSize page_size() const;
+ TSize page_res() const;
size_t page() const { return _page; }
size_t pages() const { return _pages; }
@@ -107,7 +112,7 @@ class TReport_book : public TBook
long _logical_page_height, _logical_page_width;
long _logical_foot_pos;
bool _is_last_page, _page_break_allowed;
- TPoint _delta;
+ TReport_size _delta;
size_t _rep_page;
protected:
@@ -117,7 +122,7 @@ protected:
virtual bool can_split(int pages) const;
virtual bool can_merge(int pages) const;
- virtual void define_frame(const TRectangle& r);
+ virtual void define_frame(const TReport_rct& r);
virtual bool on_link(const TReport_link& lnk);
bool init(TReport& rep);
@@ -142,6 +147,6 @@ bool advanced_set_draw_tools(TWindow& win, PAT_STYLE pat, int border, COLOR fore
void advanced_draw_rect(TWindow& win, const RCT& r, PAT_STYLE pat, int border, COLOR fore, COLOR back, int radius, int shade);
void advanced_draw_text_line(WINDOW win, const char* text, const RCT& r, char halign, char valign);
void advanced_draw_paragraph(WINDOW win, const TString_array& text, const RCT& r,
- char halign, char valign, int default_row_height);
+ char halign, char valign, int default_10row_height);
#endif
diff --git a/include/window.cpp b/include/window.cpp
index fedc335e8..d699cbeb7 100755
--- a/include/window.cpp
+++ b/include/window.cpp
@@ -38,11 +38,11 @@ void TRectangle::normalize()
void TRectangle::set(long cx, long cy, long dx, long dy)
{
x = cx; y = cy;
- _size.set(dx, dy);
+ _size.x = dx; _size.y = dy;
normalize();
}
-void TRectangle::set(const TPoint& pt, const TPoint& sz)
+void TRectangle::set(const TPoint& pt, const TSize& sz)
{
set(pt.x, pt.y, sz.x, sz.y);
}
diff --git a/include/window.h b/include/window.h
index e1415e2b0..d4af42000 100755
--- a/include/window.h
+++ b/include/window.h
@@ -13,6 +13,25 @@ void close_all_dialogs();
bool can_close();
WINDOW cur_win();
+// @doc EXTERNAL
+
+// @class TPoint | Struttura per la definizione di un punto sullo schermo
+//
+// @author:(INTERNAL) Guido
+struct TSize
+{
+ // @cmember Coordinate del punto
+ long x, y;
+
+ bool operator ==(const TSize& s) const { return s.x == x && s.y == y; }
+ bool operator !=(const TSize& s) const { return s.x != x || s.y != y; }
+
+ TSize() : x(0), y(0) {}
+ TSize(long cx, long cy) : x(cx), y(cy) {}
+ TSize(const TSize& s) : x(s.x), y(s.y) {}
+};
+
+
// @doc EXTERNAL
// @class TPoint | Struttura per la definizione di un punto sullo schermo
@@ -30,10 +49,11 @@ struct TPoint
bool operator ==(const TPoint& p) const { return p.x == x && p.y == y; }
// @cmember Confronta se due punti sono diversi (TRUE se diversi)
bool operator !=(const TPoint& p) const { return p.x != x || p.y != y; }
- TPoint& operator +=(const TPoint& pnt) { x += pnt.x; y += pnt.y; return *this; }
- TPoint& operator -=(const TPoint& pnt) { x -= pnt.x; y -= pnt.y; return *this; }
- TPoint operator +(const TPoint& pnt) const { return TPoint(x+pnt.x, y+pnt.y); }
- TPoint operator -(const TPoint& pnt) const { return TPoint(x-pnt.x, y-pnt.y); }
+ TPoint& operator +=(const TSize& pnt) { x += pnt.x; y += pnt.y; return *this; }
+ TPoint& operator -=(const TSize& pnt) { x -= pnt.x; y -= pnt.y; return *this; }
+ TPoint operator +(const TSize& pnt) const { return TPoint(x+pnt.x, y+pnt.y); }
+ TPoint operator -(const TSize& pnt) const { return TPoint(x-pnt.x, y-pnt.y); }
+ TSize operator -(const TPoint& pnt) const { return TSize(x-pnt.x, y-pnt.y); }
void reset() { x = y = 0; }
// @cmember Costruttori
@@ -44,7 +64,7 @@ struct TPoint
class TRectangle : public TPoint
{
- TPoint _size;
+ TSize _size;
protected:
void copy(const TRectangle& r);
@@ -58,13 +78,13 @@ public:
long width() const { return _size.x; }
long height() const { return _size.y; }
const TPoint& pos() const { return *this; }
- const TPoint& size() const { return _size; }
+ const TSize& size() const { return _size; }
const TPoint center() const { return TPoint(x+_size.x/2, y+_size.y/2); }
void set_width(long w) { _size.x = w; normalize(); }
void set_height(long h) { _size.y = h; normalize(); }
void set(long cx, long cy, long dx, long dy);
- void set(const TPoint& pt, const TPoint& sz);
+ void set(const TPoint& pt, const TSize& sz);
void set_bounds(long left, long top, long right, long bottom);
bool contains(const TPoint& p) const;
@@ -82,7 +102,7 @@ public:
TRectangle& operator=(const TRectangle& r) { copy(r); return *this; }
TRectangle() : TPoint(0,0), _size(0,0) { }
- TRectangle(const TPoint& p, const TPoint& s) : TPoint(p), _size(s) { }
+ TRectangle(const TPoint& p, const TSize& s) : TPoint(p), _size(s) { }
TRectangle(long cx, long cy, long dx, long dy) { set(cx, cy, dx, dy); }
TRectangle(const TRectangle& r) { copy(r); }
};