diff --git a/src/include/report.cpp b/src/include/report.cpp index 06e484a28..af78a4871 100755 --- a/src/include/report.cpp +++ b/src/include/report.cpp @@ -1634,7 +1634,9 @@ void TReport_field::print(TBook& book) const { const TString& name = get().as_string(); const TReport_rct& rct = get_draw_rect(); - book.draw_image(rct, name); + const TString4 resize_type = get_image_resize_type(); + + book.draw_image(rct, name, resize_type); if (border() > 0) { book.set_pen(fore_color(), border()-1); @@ -1780,7 +1782,8 @@ void TReport_field::save(TXmlItem& root) const set_col_attr(fld, "bg_color", back_color(), COLOR_WHITE); set_col_attr(fld, "fg_color", fore_color(), COLOR_BLACK); set_col_attr(fld, "txt_color", text_color(), fore_color()); - + if (_type == 'I') + fld.SetAttr("image_resize_type", _image_resize_type); if (has_font()) _font->save(fld); if (in_group(0)) @@ -1863,6 +1866,8 @@ bool TReport_field::load(const TXmlItem& fld) set_back_color(get_col_attr(fld, "bg_color", COLOR_WHITE)); set_fore_color(get_col_attr(fld, "fg_color", COLOR_BLACK)); set_text_color(get_col_attr(fld, "txt_color", fore_color())); + if (_type == 'I') + set_image_resize_type(fld.GetAttr("image_resize_type")); if (pattern() == PAT_SPECIAL) { set_shade_color(get_col_attr(fld, "sh_color", COLOR_GRAY)); diff --git a/src/include/report.h b/src/include/report.h index fe0c5f66d..f644ac1be 100755 --- a/src/include/report.h +++ b/src/include/report.h @@ -357,6 +357,7 @@ class TReport_field : public TSortable TVariant _var; TReport_script _prescript, _postscript; TArray _list; // Elementi di un campo lista + TString4 _image_resize_type; TReport_font *_font, *_print_font; bool _hidden, _deactivated, _hide_zeroes, _selected; @@ -442,9 +443,11 @@ public: void set_draw_pos(long x, long y); void set_draw_size(long x, long y); + void set_image_resize_type(const char * image_resize_type) { _image_resize_type = image_resize_type; } const TReport_rct& compute_draw_rect(const TBook& book); const TReport_rct& get_draw_rect() const; + const TString & get_image_resize_type() const { return _image_resize_type; } void set_groups(const TString& groups); void add_groups(const TString& groups); diff --git a/src/include/reprint.cpp b/src/include/reprint.cpp index fdf67d13a..fc5b786f3 100755 --- a/src/include/reprint.cpp +++ b/src/include/reprint.cpp @@ -1162,10 +1162,48 @@ void TBook::draw_link(const TReport_rct& rect, const char* text, const char* lin *_out << "" << text << "" << endl; } -void TBook::draw_image(const TReport_rct& rect, const char* name) +void TBook::draw_image(const TReport_rct& rect, const char* filename, const char * resize) { - define_frame(rect); - *_out << "" << endl; + TReport_rct new_rect(rect); + + if (resize && *resize) + { + TImage* img = _images.image(filename); + + switch (resize[0]) + { + case 'N': + new_rect.set_width(img->width()); + new_rect.set_height(img->height()); + break; + case 'X': + { + long ratio = long((double(img->height()) / double(img->width())) * 100000.0); + short old_ysize = rect.height(); + long new_ysize = rect.width() * ratio / 100000L; + TReport_size s(rect.width(), (new_ysize * lpi()) / cpi()); + TReport_pnt o(rect.left(), rect.top() + ((old_ysize - new_ysize) * cpi())/ (2 * lpi())); + + new_rect.set(o, s); + } + break; + case 'Y': + { + long ratio = long((double(img->width()) / double(img->height())) * 100000.0); + short old_xsize = rect.width(); + long new_xsize = rect.height() * ratio / 100000L; + TReport_size s((new_xsize * cpi()) / lpi(), rect.height()); + TReport_pnt o(rect.left() + ((old_xsize - new_xsize) * lpi()) / (2 * cpi()), rect.top()); + + new_rect.set(o, s); + } + break; + default: + break; + } + } + define_frame(new_rect); + *_out << "" << endl; } void TBook::add_doc(const TString& name) diff --git a/src/include/reprint.h b/src/include/reprint.h index eae2e1c4a..459a62c6d 100755 --- a/src/include/reprint.h +++ b/src/include/reprint.h @@ -68,7 +68,7 @@ public: 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_image(const TReport_rct& rect, const char* filename, const char *resize = ""); 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);