Пример #1
0
void
Operation::draw_patient_info(const Glib::RefPtr<Gtk::PrintContext>& print)
{
	Cairo::RefPtr<Cairo::Context> cairo = print->get_cairo_context();

	Glib::RefPtr<Pango::Layout> layout = print->create_pango_layout();

	Pango::FontDescription font_desc("sans 12");
	layout->set_font_description(font_desc);

	layout->set_width(width_ * Pango::SCALE);

	DICOM::SummaryInfo* info = const_cast<DICOM::SummaryInfo*>(&dicom_info_);
	DICOM::PatientInfo* patient = info->get_patient_info();

	//Set and mark up the text to print:
	Glib::ustring marked_up_form_text;
	Glib::ustring txt = DICOM::format_person_name(patient->get_name());
	marked_up_form_text += "<b>Patient's name</b>: " + txt + "\n";
	marked_up_form_text += "<b>Sex</b>: " + info->get_patient_sex() + "\n";

	DICOM::PatientAge age = info->get_patient_age();
	marked_up_form_text += "<b>Age</b>: " + age.age_string() + "\n\n";

	layout->set_markup(marked_up_form_text);
	layout->show_in_cairo_context(cairo);

	int w, h;
	layout->get_pixel_size( w, h);
	cairo->rel_move_to( 0, h);
	cairo->stroke_preserve();
}
Пример #2
0
void PhotoPrintOperation::on_draw_page(const Glib::RefPtr<Gtk::PrintContext>& Context, int PageNum) {
	if (!PixData || PixData->size()!=4)
		return;

	Cairo::RefPtr<Cairo::Context> CairoContext=Context->get_cairo_context();
	CairoContext->scale(1.0/CairoScale,1.0/CairoScale);

	if (Label) {
		Gdk::Cairo::set_source_pixbuf(CairoContext, Label, LabelArea.X, LabelArea.Y);
		CairoContext->paint();
	}

	/* Draw the photos */
	int Col=0, Row=0, MaxCol=1;
	time_t Timestamp=time(NULL);
	for (std::vector< Glib::RefPtr<Gdk::Pixbuf> >::iterator Pixbufi=PixData->begin();Pixbufi<PixData->end();Pixbufi++) {
		if (*Pixbufi) {
			ArchivePhoto(*Pixbufi,Timestamp,Row*2+Col);

			double PhotoScaleFactor;
			PhotoScaleFactor=std::min(PhotoArea[0].Width/(*Pixbufi)->get_width(),PhotoArea[0].Height/(*Pixbufi)->get_height());

			/* Scale the photo */
			Glib::RefPtr<Gdk::Pixbuf> ScaledPixbuf;
			ScaledPixbuf=(*Pixbufi)->scale_simple(
				(*Pixbufi)->get_width()*PhotoScaleFactor,
				(*Pixbufi)->get_height()*PhotoScaleFactor,
				Gdk::INTERP_BILINEAR);

			if (Cfg->GetFlipPrint())
				ScaledPixbuf=ScaledPixbuf->flip();

			Gdk::Cairo::set_source_pixbuf(CairoContext, ScaledPixbuf, PhotoArea[Col+2*Row].X, PhotoArea[Col+2*Row].Y);

			CairoContext->paint();
		}

		if (Col!=MaxCol) {
			Col++;
		} else {
			Col=0;
			Row++;
		}
	}

	if (Stamp) {
		double X,Y;
		X=PrintArea.X+Cfg->GetStampX()*PrintArea.Width-Stamp->get_width()/2.0;
		Y=PrintArea.Y+Cfg->GetStampY()*PrintArea.Height-Stamp->get_height()/2.0;
		Gdk::Cairo::set_source_pixbuf(CairoContext, Stamp, X, Y);

		CairoContext->paint();
	}
}
Пример #3
0
void
Operation::draw_title(const Glib::RefPtr<Gtk::PrintContext>& print)
{
	double pos_x, pos_y;

	Cairo::RefPtr<Cairo::Context> cairo = print->get_cairo_context();

	DICOM::SummaryInfo* info = const_cast<DICOM::SummaryInfo*>(&dicom_info_);
	DICOM::StudyInfo* study = info->get_study_info();

	// Show Institution Name
	cairo->set_font_size(title_font_size_);
	Cairo::TextExtents cur_ext, prev_ext;
	cairo->get_text_extents( study->get_institution_name(), cur_ext);

	pos_x = (width_ - cur_ext.width) / 2.;
	pos_y = cur_ext.height + OFFSET;
	cairo->move_to( pos_x, pos_y);
	cairo->show_text(study->get_institution_name());

	// Show Institution Address
	prev_ext = cur_ext;
	cairo->set_font_size(subtitle_font_size_);
	cairo->get_text_extents( study->get_institution_address(), cur_ext);

	pos_x = -(prev_ext.width + prev_ext.x_bearing +
		cur_ext.width + cur_ext.x_bearing) / 2.;
	pos_y = cur_ext.height + OFFSET;
	cairo->rel_move_to( pos_x, pos_y);
	cairo->show_text(study->get_institution_address());

	// Show Study Description
	prev_ext = cur_ext;
	cairo->set_font_size(title_font_size_);
	cairo->get_text_extents( study->get_description(), cur_ext);

	pos_x = -(prev_ext.width + prev_ext.x_bearing +
		cur_ext.width + cur_ext.x_bearing) / 2.;
	pos_y = cur_ext.height + OFFSET;
	cairo->rel_move_to( pos_x, pos_y);
	cairo->show_text(study->get_description());


	pos_x = -(width_ + cur_ext.width) / 2.;
	pos_y = cur_ext.height + OFFSET;
	cairo->rel_move_to( pos_x, pos_y);

	cairo->stroke_preserve();
}
Пример #4
0
//------------------------------------------------------------------------------
void WBPrintOperation::on_draw_page(const Glib::RefPtr<Gtk::PrintContext>& ctx, int page_nr)
{
  Cairo::RefPtr<Cairo::Context> context = ctx->get_cairo_context();
  mdc::CairoCtx cairoctx(context->cobj());

  // scaling to transform from cairo coordinates to Cocoa coordinates
  double pwidth, pheight;
  _printer->get_paper_size(pwidth, pheight);
  float xscale= ctx->get_width() / pwidth;
  float yscale= ctx->get_height() / pheight;

  // scale has to be set here, ctx->get_width() returns some different value in on_begin_print()
  _printer->set_scale(xscale, yscale);

  _printer->render_page(&cairoctx, page_nr % _xpages, page_nr / _xpages);
 
}
Пример #5
0
void
Operation::on_begin_print(const Glib::RefPtr<Gtk::PrintContext>& print)
{
	width_ = print->get_width();
	height_ = print->get_height();

	//Get a Cairo Context, which is used as a drawing board:
	Cairo::RefPtr<Cairo::Context> cairo = print->get_cairo_context();

	cairo->select_font_face( "Sans", Cairo::FONT_SLANT_NORMAL,
		Cairo::FONT_WEIGHT_NORMAL);

	//We'll use black letters:
	cairo->set_source_rgb( 0, 0, 0);

	draw_title(print);
	draw_patient_info(print);
	draw_study_info(print);
}
Пример #6
0
void
Operation::draw_study_info(const Glib::RefPtr<Gtk::PrintContext>& print)
{ 
	Cairo::RefPtr<Cairo::Context> cairo = print->get_cairo_context();

	Glib::RefPtr<Pango::Layout> layout = print->create_pango_layout();

	Pango::FontDescription font_desc("sans 12");
	layout->set_font_description(font_desc);

	layout->set_width(width_ * Pango::SCALE);

	DICOM::SummaryInfo* info = const_cast<DICOM::SummaryInfo*>(&dicom_info_);
	DICOM::StudyInfo* study = info->get_study_info();

	//Set and mark up the text to print:
	Glib::ustring marked_up_form_text = "<b>Study ID</b>: " + study->get_id() + "\n";

	layout->set_markup(marked_up_form_text);
	layout->show_in_cairo_context(cairo);
	cairo->stroke();

	Glib::ustring txt = DICOM::format_person_name(study->get_operator_name());
	marked_up_form_text = "<b>Operator's name</b>: " + txt + "\t\t\t\n";

	txt = DICOM::format_person_name(study->get_physician_name());
	marked_up_form_text += "<b>Physician's name</b>: " + txt + "\t\t\t\n";

	layout->set_markup(marked_up_form_text);

	int w, h;
	layout->get_pixel_size( w, h);

	cairo->move_to( width_ - w, height_ - h);
	layout->show_in_cairo_context(cairo);

	cairo->stroke();
}
Пример #7
0
  void PrintNotesNoteAddin::on_draw_page(const Glib::RefPtr<Gtk::PrintContext>& context, guint page_nr)
  {
    Cairo::RefPtr<Cairo::Context> cr = context->get_cairo_context();
    cr->move_to (m_margin_left, m_margin_top);

    PageBreak start;
    if (page_nr != 0) {
      start = m_page_breaks [page_nr - 1];
    }

    PageBreak end(-1, -1);
    if (m_page_breaks.size() > page_nr) {
      end = m_page_breaks [page_nr];
    }

    Gtk::TextIter position;
    Gtk::TextIter end_iter;
    get_buffer()->get_bounds (position, end_iter);

    // Fast-forward to the starting line
    while (position.get_line() < start.get_paragraph()) {
      position.forward_line ();
    }

    bool done = position.compare (end_iter) >= 0;
    while (!done) {
      Gtk::TextIter line_end = position;
      if (!line_end.ends_line ()) {
        line_end.forward_to_line_end ();
      }


      int paragraph_number = position.get_line();
      int indentation;

      {
        Glib::RefPtr<Pango::Layout> layout =
          create_layout_for_paragraph (context,position, line_end, indentation);

        for(int line_number = 0;
            line_number < layout->get_line_count() && !done;
            line_number++) {
          // Skip the lines up to the starting line in the
          // first paragraph on this page
          if ((paragraph_number == start.get_paragraph()) &&
              (line_number < start.get_line())) {
            continue;
          }
          // Break as soon as we hit the end line
          if ((paragraph_number == end.get_paragraph()) &&
              (line_number == end.get_line())) {
            done = true;
            break;
          }



          Glib::RefPtr<Pango::LayoutLine> line = layout->get_line(line_number);
          
          Pango::Rectangle ink_rect;
          Pango::Rectangle logical_rect;
          line->get_extents (ink_rect, logical_rect);

          double curX, curY;
          cr->get_current_point(curX, curY);
          cr->move_to (m_margin_left + indentation, curY);
          int line_height = pango_units_to_double(logical_rect.get_height());

          double x, y;
          x = m_margin_left + indentation;
          cr->get_current_point(curX, curY);
          y = curY + line_height;
          pango_cairo_show_layout_line(cr->cobj(), line->gobj());
          cr->move_to(x, y);
        }
      }

      position.forward_line ();
      done = done || (position.compare (end_iter) >= 0);
    }

    // Print the footer
    int total_height = context->get_height();
    int total_width = context->get_width();
    int footer_height = 0;

    double footer_anchor_x, footer_anchor_y;

    {
      Glib::RefPtr<Pango::Layout> pages_footer 
        = create_layout_for_pagenumbers (context, page_nr + 1, 
                                         m_page_breaks.size() + 1);

      Pango::Rectangle ink_footer_rect;
      Pango::Rectangle logical_footer_rect;
      pages_footer->get_extents(ink_footer_rect, logical_footer_rect);
      
      footer_anchor_x = cm_to_pixel(0.5, context->get_dpi_x());
      footer_anchor_y = total_height - m_margin_bottom;
      footer_height = pango_units_to_double(logical_footer_rect.get_height());
      
      cr->move_to(total_width - pango_units_to_double(logical_footer_rect.get_width()) - cm_to_pixel(0.5, context->get_dpi_x()), footer_anchor_y);
                                                      
      pango_cairo_show_layout_line(cr->cobj(), 
                                   (pages_footer->get_line(0))->gobj());

    }

    cr->move_to(footer_anchor_x, footer_anchor_y);
    pango_cairo_show_layout_line(cr->cobj(), 
                                 (m_timestamp_footer->get_line(0))->gobj());

    cr->move_to(cm_to_pixel(0.5, context->get_dpi_x()), 
                total_height - m_margin_bottom - footer_height);
    cr->line_to(total_width - cm_to_pixel(0.5, context->get_dpi_x()),
                total_height - m_margin_bottom - footer_height);
    cr->stroke();
  }