#include #include #include #include "ba8301.h" #include /////////////////////////////////////////////////////////// // TXVT_font /////////////////////////////////////////////////////////// // boxing di un XVT_FNTID in un TObject per poterlo inserire in un TArray class TXVT_font : public TObject { XVT_FNTID _fontid; public: operator XVT_FNTID() const { return _fontid; } void create(const TString& name, int size, XVT_FONT_STYLE_MASK style); void destroy(); TXVT_font() : _fontid(NULL) { } virtual ~TXVT_font() { destroy(); } }; void TXVT_font::create(const TString& name, int size, XVT_FONT_STYLE_MASK style) { destroy(); _fontid = xvt_font_create(); xvt_font_set_family(_fontid, (char*)(const char*)name); xvt_font_set_size(_fontid, size); xvt_font_set_style(_fontid, style); } void TXVT_font::destroy() { if (_fontid != NULL) { xvt_font_destroy(_fontid); _fontid = NULL; } } /////////////////////////////////////////////////////////// // TReport_font /////////////////////////////////////////////////////////// XVT_FNTID TReport_font::get_xvt_font(WINDOW win, int ppi) const { TXVT_font* font = (TXVT_font*)_physical.objptr(ppi); if (font == NULL) { int mi = 0, me = 0, ma = ppi/4; int best = 0, best_error = 0; TXVT_font f; while (mi < ma) { me = (mi+ma)/2; f.create("Courier New", me, XVT_FS_NONE); xvt_dwin_set_font(win, f); const int width = xvt_dwin_get_text_width(win, "MMMMMMMMMMMMMMMMMMMMMMMM", _cpi); const int error = abs(width - ppi); 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; } XVT_FONT_STYLE_MASK style = 0; if (_bold) style |= XVT_FS_BOLD; if (_italic) style |= XVT_FS_ITALIC; if (_underline) style |= XVT_FS_UNDERLINE; font = new TXVT_font; font->create(_name, best, style); ((TArray&)_physical).add(font, ppi); } return *font; } TReport_font::TReport_font() : _name("Courier New"), _size(DEFAULT_FONT_SIZE), _bold(false), _italic(false), _underline(false) { _cpi = 120 / _size; } /////////////////////////////////////////////////////////// // TReport_section /////////////////////////////////////////////////////////// void TReport_section::description(TString& str) const { switch (_type) { case 'B': str = TR("Corpo"); break; case 'F': str = TR("Coda"); break; case 'H': str = TR("Testa"); break; case 'P': str = TR("Sfondo"); break; // Virtual section case 'R': str = TR("Report"); break; // Virtual section default : break; } if (_level > 0) str << ' ' << _level; } const TReport_font& TReport_section::font() const { const TReport_font* f = _font; if (f == NULL) { if (_father == NULL) { (TReport_font*)_font = new TReport_font; f = _font; } else f = &_father->font(); } return *f; } TReport_section::TReport_section(const TReport_section* f, char t, int l) : _father(f), _type(t), _level(l), _font(NULL) { } TReport_section::~TReport_section() { if (_font) delete _font; } /////////////////////////////////////////////////////////// // TReport_field /////////////////////////////////////////////////////////// void TReport_field::set_pos(short x, short y) { _x = x; _y = y; } void TReport_field::set_size(short w, short h) { _width = w; _height = h; } void TReport_field::get_rect(RCT& r) const { r.left = _x; r.top = _y; r.right = _x + _width; r.bottom = _y+_height; } void TReport_field::offset(const TPoint& pt) { _x += short(pt.x); _y += short(pt.y); } const TReport_font& TReport_field::font() const { return _font != NULL ? *_font : _section->font(); } TReport_field::TReport_field(TReport_section* sec) : _section(sec), _type('T'), _selected(false), _font(NULL), _color(COLOR_BLACK) { set_pos(0,0); set_size(1200,100); _picture = "###.###.##@,@@"; } /////////////////////////////////////////////////////////// // TReport /////////////////////////////////////////////////////////// void TReport::build_section_key(char type, int level, TString& key) const { key.format("%c%d", type, level); } TReport_section* TReport::find_section(char type, int level) const { TString4 key; build_section_key(type, level, key); TReport_section* sec = (TReport_section*)_sections.objptr(key); return sec; } TReport_section& TReport::section(char type, int level) { TReport_section* sec = find_section(type, level); if (sec == NULL) { TString4 key; build_section_key(type, level, key); TReport_section* father = NULL; if (level > 1) father = find_section('B', level-1); else { if (type != 'R') father = find_section('R', 0); } CHECK(type == 'R' || father != NULL, "Mater certa est..."); sec = new TReport_section(father, type, level); _sections.add(key, sec); } return *sec; } TReport::TReport() : _cpi(12), _lpi(6) { } /////////////////////////////////////////////////////////// // TPage_printer /////////////////////////////////////////////////////////// const char* TPage_printer::form_name() const { return printer().get_form_name(); } const char* TPage_printer::font_name() const { return printer().fontname(); } int TPage_printer::font_size() const { return printer().get_char_size(); } bool TPage_printer::ask_pages() { const int last_page = pages(); TPrinter& p = printer(); TMask msk("bagn003"); msk.set(F_PRINTER, p.printername()); msk.set(F_FORM, form_name()); msk.set(F_FONT, font_name()); msk.set(F_SIZE, font_size()); msk.set(F_ISGRAPHICS, p.isgraphics() ? "X" : ""); msk.set(F_FROMPAGE, _pagefrom); msk.set(F_TOPAGE, last_page); msk.set(F_COPIES, _copies); const bool ok = msk.run() == K_ENTER; if (ok) { _copies = msk.get_int(F_COPIES); _pagefrom = msk.get_int(F_FROMPAGE); _pageto = msk.get_int(F_TOPAGE); if (_pageto < _pagefrom || _pageto > last_page) _pageto = 0; } return ok; }