Пример #1
0
	void renderLabels(const char* path)
	{
		BOOST_TEST_MESSAGE("Render: " << path);

		Cairo::RefPtr<Cairo::Surface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
			META_TILE_SIZE * TILE_SIZE, META_TILE_SIZE * TILE_SIZE);
		Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
		cr->set_source_rgba(0.0, 0.0, 0.0, 1.0);

		cr->save();
		cr->set_source_rgba(1.0, 1.0, 1.0, 1.0);
		cr->paint();
		cr->restore();

		std::vector<std::pair<string, FloatPoint>> toPlace;
		toPlace.push_back(std::pair<string, FloatPoint>("Karlsruhe", FloatPoint(40, 200)));
		toPlace.push_back(std::pair<string, FloatPoint>("Mannheim", FloatPoint(400, 200)));
		toPlace.push_back(std::pair<string, FloatPoint>("Stuttgard", FloatPoint(200, 260)));
		toPlace.push_back(std::pair<string, FloatPoint>("München", FloatPoint(380, 660)));
		toPlace.push_back(std::pair<string, FloatPoint>("Pforzheim", FloatPoint(200, 600)));
		toPlace.push_back(std::pair<string, FloatPoint>("Wien", FloatPoint(240, 680)));
		toPlace.push_back(std::pair<string, FloatPoint>("Paris", FloatPoint(40, 880)));
		toPlace.push_back(std::pair<string, FloatPoint>("Rom", FloatPoint(-40, 880)));
		toPlace.push_back(std::pair<string, FloatPoint>("Nothing", FloatPoint(400, 760)));
		toPlace.push_back(std::pair<string, FloatPoint>("To See", FloatPoint(720, 880)));
		toPlace.push_back(std::pair<string, FloatPoint>("Here", FloatPoint(720, 560)));
		toPlace.push_back(std::pair<string, FloatPoint>("Bielefeld", FloatPoint(420, 840)));
		renderer->renderLabels(cr, toPlace);

		BOOST_TEST_MESSAGE("Writing.");
		surface->flush();
		surface->write_to_png(path);
	}
Пример #2
0
void make_image(Glib::ustring filename, void (shape_function)( Papyrus::Canvas::pointer ) ) {
  Cairo::RefPtr<Cairo::ImageSurface> surface =
      Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 200, 200);

  Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

  Papyrus::Canvas::pointer canvas = Papyrus::Canvas::create();
  canvas->translate( 100, 100 );
//   canvas->set_background( Cairo::SolidPattern::create_rgb(0.9, 0.9, 0.9) );
  Papyrus::Polyline::pointer line = Papyrus::Polyline::create();
  line->add_vertex(0, -100);
  line->add_vertex(0, 100);
  line->set_stroke( Cairo::SolidPattern::create_rgb(0.0, 0.0, 1.0) );
  line->stroke()->set_width(2);
  canvas->add( line );
  line = Papyrus::Polyline::create();
  line->add_vertex(-100, 0);
  line->add_vertex(100, 0);
  line->set_stroke( Cairo::SolidPattern::create_rgb(0.0, 0.0, 1.0) );
  line->stroke()->set_width(2);
  canvas->add( line );
  shape_function( canvas );

  canvas->render( cr );

  surface->write_to_png(filename);

  std::cout << "Wrote png file \"" << filename << "\"" << std::endl;

}
Пример #3
0
int main(int, char**) {
	Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(
			Cairo::FORMAT_ARGB32, WIDTH, HEIGHT);
	Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
	// fill background in white
	cr->set_source_rgb(1.0, 1.0, 1.0);
	cr->paint();

	// draw a little dot at the point where text will be drawn
	cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2 * M_PI);
	cr->set_source_rgba(0.0, 1.0, 0.0, 0.5);
	cr->fill();

	// draw the text
	cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
	cr->set_source_rgb(0.8, 0.2, 0.2);
	Cairo::RefPtr<Cairo::ToyFontFace> font = Cairo::ToyFontFace::create(
			"Bitstream Charter", Cairo::FONT_SLANT_ITALIC,
			Cairo::FONT_WEIGHT_BOLD);
	cr->set_font_face(font);
	cr->set_font_size(FONT_SIZE);
	cr->show_text("cairomm!");
	surface->write_to_png("toy-text.png");
	return 0;
}
Пример #4
0
void ImageWidget::SavePng(const std::string &filename)
{
	unsigned width = get_width(), height = get_height();
	Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, width, height);
	Cairo::RefPtr<Cairo::Context> cairo = Cairo::Context::create(surface);
	if(HasImage())
	{
		AOLogger::Debug << "Saving PNG of " << get_width() << " x " << get_height() << "\n";
		update(cairo, width, height);
	}
	surface->write_to_png(filename);
}
Пример #5
0
int main (void)
{
    Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, WIDTH, HEIGHT);
    Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
    draw(cr, WIDTH, HEIGHT);
#ifdef CAIRO_HAS_PNG_FUNCTIONS
    const char* filename = "text-rotate.png";
    surface->write_to_png(filename);
    std::cout << "Wrote file " << filename << std::endl;
#else
    std::cout << "You must compile cairo with PNG support for this example to work" << std::endl;
#endif
}
Пример #6
0
int main()
{
  Cairo::RefPtr<Cairo::ImageSurface> surface =
    Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 600, 400);

  Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

  cr->save(); // save the state of the context
  cr->set_source_rgb(0.86, 0.85, 0.47);
  cr->paint();   // fill image with the color
  cr->restore(); // color is back to black now

  cr->save();
  // draw a border around the image
  cr->set_line_width(20.0); // make the line wider
  cr->rectangle(0.0, 0.0, surface->get_width(), surface->get_height());
  cr->stroke();

  cr->set_source_rgba(0.0, 0.0, 0.0, 0.7);
  // draw a circle in the center of the image
  cr->arc(surface->get_width() / 2.0, surface->get_height() / 2.0,
          surface->get_height() / 4.0, 0.0, 2.0 * M_PI);
  cr->stroke();

  // draw a diagonal line
  cr->move_to(surface->get_width() / 4.0, surface->get_height() / 4.0);
  cr->line_to(surface->get_width() * 3.0 / 4.0,
              surface->get_height() * 3.0 / 4.0);
  cr->stroke();
  cr->restore();

#ifdef CAIRO_HAS_PNG_FUNCTIONS

  std::string filename = "image.png";
  surface->write_to_png(filename);

  std::cout << "Wrote png file \"" << filename << "\"" << std::endl;

#else

  std::cout
    << "You must compile cairo with PNG support for this example to work."
    << std::endl;

#endif
}
Пример #7
0
  /** Post-process files. Only valid for PNGs. */
  void postprocess()
  {
    printf("Post-processing PNG files, resizing to %fx%f\n", maxwidth, maxheight);
    struct dirent *d;
    DIR *output_dir = opendir(outdir.c_str());
    while ((d = readdir(output_dir)) != NULL) {
      if (fnmatch("*.png", d->d_name, FNM_PATHNAME | FNM_PERIOD) == 0) {
	infile = outdir + "/" + d->d_name;
	Cairo::RefPtr<Cairo::ImageSurface> imgs = Cairo::ImageSurface::create_from_png(infile);
	if ( (imgs->get_height() != maxheight) || (imgs->get_width() != maxwidth)) {
	  // need to re-create
	  char *tmpout = strdup((outdir + "/tmpXXXXXX").c_str());
	  FILE *f = fdopen(mkstemp(tmpout), "w");
	  outfile = tmpout;
	  free(tmpout);

	  Cairo::RefPtr<Cairo::ImageSurface> outs = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
										(int)ceilf(maxwidth),
										(int)ceilf(maxheight));
	  double tx = (maxwidth  - imgs->get_width()) / 2.0;
	  double ty = (maxheight - imgs->get_height()) / 2.0;
	  printf("Re-creating %s for post-processing, "
		 "resizing from %ix%i, tx=%f, ty=%f\n", infile.c_str(),
		 imgs->get_width(), imgs->get_height(), tx, ty);
	  Cairo::RefPtr<Cairo::Context> cc = Cairo::Context::create(outs);
	  if (white_bg) {
	    cc->set_source_rgb(1, 1, 1);
	    cc->paint();
	  }
	  cc->set_source(imgs, tx, ty);
	  cc->paint();
	  outs->write_to_png(&SkillGuiBatchRenderer::write_func, f);
	  imgs.clear();
	  cc.clear();
	  outs.clear();
	  fclose(f);
	  rename(outfile.c_str(), infile.c_str());
	}
      }
    }
    closedir(output_dir);
  }
Пример #8
0
int main(int, char**) {
	Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(
			Cairo::FORMAT_ARGB32, WIDTH, HEIGHT);
	Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);
	// fill background in white
	cr->set_source_rgb(1.0, 1.0, 1.0);
	cr->paint();

	// draw a little dot at the point where text will be drawn
	cr->arc(TEXT_ORIGIN_X, TEXT_ORIGIN_Y, FONT_SIZE / 4.0, 0, 2 * M_PI);
	cr->set_source_rgba(0.0, 1.0, 0.0, 0.5);
	cr->fill();

	// draw the text
	cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
	cr->set_source_rgb(0.8, 0.2, 0.2);
	Cairo::RefPtr<BoxFontFace> font = BoxFontFace::create();
	cr->set_font_face(font);
	cr->set_font_size(FONT_SIZE);
	cr->show_text("cairomm!");

	// Now show it with the toy text API to
	// demonstrate how the glyphs match up
	cr->move_to(TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
	cr->set_source_rgba(0.2, 0.2, 0.2, 0.3);
	Cairo::RefPtr<Cairo::ToyFontFace> toy_font = Cairo::ToyFontFace::create(
			"Bitstream Charter", Cairo::FONT_SLANT_NORMAL,
			Cairo::FONT_WEIGHT_BOLD);
	cr->set_font_face(toy_font);
	cr->set_font_size(FONT_SIZE);
	cr->show_text("cairomm!");

	const char* filename = "user-font.png";
	try {
		surface->write_to_png(filename);
		std::cout << "Wrote Image " << filename << std::endl;
		return 0;
	} catch (const std::exception& e) {
		std::cout << "** Unable to write Image " << filename << std::endl;
		return 1;
	}
}
Пример #9
0
	void MainWindow::save_file()
	{
		std::cout << "MainWindow::save_file()\n";

		if(m_png)
		{
			//dane są w obrazie teraz można je zapisać
			//więc dialog i te sprawy
			std::string filename = run_open_file_dialog("Select file to save stegocontener", Gtk::FILE_CHOOSER_ACTION_SAVE);

			std::string test_text = m_text.get_buffer()->get_text();
			m_wavelet.hide_text(test_text);

			if(filename != "")
			{
				std::cout << "Saving image\n";
				Cairo::RefPtr<Cairo::ImageSurface> surface = m_wavelet.to_image().to_cairo_image_surface();
				surface->write_to_png(filename);
			}
		}
	}
Пример #10
0
/** save current graph. */
void
SkillGuiGraphDrawingArea::save()
{
  Gtk::Window *w = dynamic_cast<Gtk::Window *>(get_toplevel());
  __fcd_save->set_transient_for(*w);

  int result = __fcd_save->run();
  if (result == Gtk::RESPONSE_OK) {

    Gtk::FileFilter *f = __fcd_save->get_filter();
    std::string filename = __fcd_save->get_filename();
    if (filename != "") {
      if (f == __filter_dot) {
	save_dotfile(filename.c_str());
      } else {
	Cairo::RefPtr<Cairo::Surface> surface;

	bool write_to_png = false;
	if (f == __filter_pdf) {
	  surface = Cairo::PdfSurface::create(filename, __bbw, __bbh);
	} else if (f == __filter_svg) {
	  surface = Cairo::SvgSurface::create(filename, __bbw, __bbh);
	} else if (f == __filter_png) {
	  surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32,
						(int)ceilf(__bbw),
						(int)ceilf(__bbh));
	  write_to_png = true;
	}

	if (surface) {
	  __cairo = Cairo::Context::create(surface);
	  
	  bool old_scale_override = __scale_override;
	  double old_tx = __translation_x;
	  double old_ty = __translation_y;
	  double old_scale = __scale;
	  __translation_x = __pad_x;
	  __translation_y = __bbh - __pad_y;
	  __scale = 1.0;
	  __scale_override = true;

	  if (__graph) {
	    gvRender(__gvc, __graph, (char *)"skillguicairo", NULL);
	  }

	  if (write_to_png) {
	    surface->write_to_png(filename);
	  }

	  __cairo.clear();

	  __translation_x = old_tx;
	  __translation_y = old_ty;
	  __scale = old_scale;
	  __scale_override = old_scale_override;
	}
      }

    } else {
      Gtk::MessageDialog md(*w, "Invalid filename",
			    /* markup */ false, Gtk::MESSAGE_ERROR,
			    Gtk::BUTTONS_OK, /* modal */ true);
      md.set_title("Invalid File Name");
      md.run();
    }
  }

  __fcd_save->hide();
}
Пример #11
0
int render_png(Graph* graph)
{
	int i_side = (graph->side_length - 1) * SPACING + PADDING;

	//Cairo ImageSurface. This one will be saved afterwards as a png file
	Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, i_side + PADDING * 2, i_side + PADDING * 2);
	//Cairo Context.
	Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface);

	cr->save(); // save the state of the context
	cr->set_source_rgb(1.0, 1.0, 1.0);
	cr->paint(); // fill image with the color
	cr->restore(); // color is back to black now

	//Storing state to start drawing
	cr->save();

	//setting brush color to black
	cr->set_source_rgb(0.0, 0.0, 0.0);

	cr->set_line_width(1.0);

	//drawing lines
	for (int i = 0; i < graph->side_length; i++) {
		for (int j = 0; j < graph->side_length; j++) {
			//for a current node
			Node* current = graph->matrix.at(i).at(j);
			//find all friends
			for (int k = 0; k < current->friends.size(); k++) {
				pair<int, int> current_friend = *std::next(current->friends.begin(), k);
				//Move brush to current node
				cr->move_to(current->coors.first * SPACING + PADDING, current->coors.second * SPACING + PADDING);
				//Draw a line to current friend
				cr->line_to(current_friend.first * SPACING + PADDING, current_friend.second * SPACING + PADDING);
				cr->stroke();
			}
		}
	}

	//setting brush color to red
	cr->set_source_rgb(1.0, 0.0, 0.0);

	//drawing vertices after lines are drawn
	for (int i = 0; i < graph->side_length; i++) {
		for (int j = 0; j < graph->side_length; j++) {
			Node* current = graph->matrix.at(i).at(j);
			cr->arc(current->coors.first * SPACING + PADDING, current->coors.second * SPACING + PADDING, 1.0, 0.0, 2.0 * M_PI);
			cr->stroke();
		}
	}

	cr->restore();

#ifdef CAIRO_HAS_PNG_FUNCTIONS

	std::string filename = build_name("result");
	surface->write_to_png(filename);

	std::cout << "Wrote png file \"" << filename << "\"" << std::endl;

#else

	std::cout << "You must compile cairo with PNG support for this example to work."
	          << std::endl;

#endif
}