Exemplo n.º 1
0
Arquivo: svg.c Projeto: mstorsjo/vlc
/*****************************************************************************
 * CloseDecoder: png decoder destruction
 *****************************************************************************/
static void CloseDecoder( vlc_object_t *p_this )
{
    VLC_UNUSED( p_this );
#if (GLIB_MAJOR_VERSION < 2 || GLIB_MINOR_VERSION < 36)
    rsvg_term();
#endif
}
Exemplo n.º 2
0
/* Load an SVG file and resize it to given dimensions.
   if width or height is set to 0 no resizing is applied
   (partly based on TuxPaint's SVG loading function) */
SDL_Surface* LoadSVGOfDimensions(char* filename, int width, int height)
{
  cairo_surface_t* temp_surf;
  cairo_t* context;
  RsvgHandle* file_handle;
  RsvgDimensionData dimensions;
  SDL_Surface* dest;
  float scale_x;
  float scale_y;
  int bpp = 32;
  Uint32 Rmask, Gmask, Bmask, Amask;

  DEBUGCODE{
    fprintf(stderr, "LoadSVGOfDimensions(): looking for %s\n", filename);
  }

  rsvg_init();

  file_handle = rsvg_handle_new_from_file(filename, NULL);
  if(file_handle == NULL)
  {
    DEBUGCODE{
      fprintf(stderr, "LoadSVGOfDimensions(): file %s not found\n", filename);
    }
    rsvg_term();
    return NULL;
  }
Exemplo n.º 3
0
Arquivo: svg.c Projeto: zmike/compiz
static void
svgFini(CompPlugin *p)
{
    freeDisplayPrivateIndex(displayPrivateIndex);
    compFiniMetadata(&svgMetadata);

    rsvg_term();
}
Exemplo n.º 4
0
static void
svgFini (CompPlugin *p)
{
    freeDisplayPrivateIndex (displayPrivateIndex);
    compFiniMetadata (&svgMetadata);

#if !LIBRSVG_CHECK_VERSION (2, 36, 0)
    rsvg_term ();
#endif
}
Exemplo n.º 5
0
static void
gsm_color_button_finalize (GObject * object)
{
  GSMColorButton *color_button = GSM_COLOR_BUTTON (object);

  if (color_button->priv->cs_dialog != NULL)
    gtk_widget_destroy (color_button->priv->cs_dialog);
  color_button->priv->cs_dialog = NULL;

  g_free (color_button->priv->title);
  color_button->priv->title = NULL;

  cairo_surface_destroy (color_button->priv->image_buffer);
  color_button->priv->image_buffer = NULL;

  rsvg_term ();
  G_OBJECT_CLASS (gsm_color_button_parent_class)->finalize (object);
}
Exemplo n.º 6
0
int main (int argc, char** argv)
{
  cairo_t* cr3;
  cairo_surface_t* image;
    
  RsvgHandle* r_svg;
  RsvgError rs_err;
  RsvgDimensionData svgdim;
    
  cairo_matrix_t matrix;
    
  rsvg_init();
  r_svg = rsvg_handle_new_from_file(argv[1], NULL);
  rsvg_handle_get_dimensions(r_svg, &svgdim);

  int width = svgdim.width;
  int height = svgdim.height;
  unsigned char* buf = (unsigned char*)malloc(width * height * 4);

  image = cairo_image_surface_create_for_data(buf, CAIRO_FORMAT_ARGB32, width, height, width * 4);
  cr3 = cairo_create(image);
    
  cairo_set_source_rgb(cr3, 1.0, 0.0, 0.0);
  cairo_paint(cr3);
        
  rsvg_handle_render_cairo(r_svg, cr3);
    
  cairo_surface_write_to_png(image, "output.png");

  rsvg_handle_free(r_svg);
  rsvg_term();

  cairo_destroy(cr3);
  cairo_surface_destroy(image);

  free(buf);
    
  return 0;
}
Exemplo n.º 7
0
		bool operator()( EventType &ev ) {
		
			rsvg_term();
			return true;
		}
Exemplo n.º 8
0
int
main (int	  argc,
      char	**argv)
{
    GOptionContext      *context;
    char const          *fragment;
    char const         **filenames;
    char const          *file;
    RsvgHandle          *handle;
    RsvgDimensionData    dimensions;
    RsvgPositionData     position;
    GError              *error;
    int                  exit_code;
    int                  i;

    GOptionEntry options[] = {
        { "fragment", 'f', 0, G_OPTION_ARG_STRING, &fragment, "The SVG fragment to address.", "<string>" },
        { G_OPTION_REMAINING, 0, G_OPTION_FLAG_FILENAME, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, "[FILE...]" },
        { NULL }
    };

    rsvg_init ();

    context = NULL;
    fragment = NULL;
    filenames = NULL;
    handle = NULL;
    error = NULL;

    context = g_option_context_new ("- SVG measuring tool.");
    g_option_context_add_main_entries (context, options, NULL);

    /* No args? */
    if (argc < 2) {
        show_help (context);
        exit_code = EXIT_SUCCESS;
        goto bail;
    }

    error = NULL;
    g_option_context_parse (context, &argc, &argv, &error);
    if (error) {
        show_help (context);
        g_warning ("%s", error->message);
        exit_code = EXIT_FAILURE;
        goto bail;
    }

    /* Invalid / missing args? */
    if (filenames == NULL) {
        show_help (context);
        exit_code = EXIT_FAILURE;
        goto bail;
    }

    g_option_context_free (context), context = NULL;

    for (i = 0; NULL != (file = filenames[i]); i++) {

        error = NULL;
        handle = rsvg_handle_new_from_file (file, &error);
        if (error) {
            g_warning ("%s", error->message);
            exit_code = EXIT_FAILURE;
            goto bail;
        }

        if (fragment && handle) {
            gboolean have_fragment = FALSE;
            have_fragment |= rsvg_handle_get_dimensions_sub (handle,
                    &dimensions, fragment);
            have_fragment |= rsvg_handle_get_position_sub (handle,
                    &position, fragment);
            if (!have_fragment) {
                g_warning ("%s: fragment `'%s' not found.",
                        file, fragment);
                exit_code = EXIT_FAILURE;
                goto bail;
            }

            printf ("%s, fragment `%s': x=%d, y=%d, %dx%d, em=%f, ex=%f\n",
                    file, fragment,
                    position.x, position.y,
                    dimensions.width, dimensions.height,
                    dimensions.em, dimensions.ex);

        } else if (handle) {
            rsvg_handle_get_dimensions (handle, &dimensions);
            printf ("%s: %dx%d, em=%f, ex=%f\n", file,
                    dimensions.width, dimensions.height,
                    dimensions.em, dimensions.ex);
        } else {
            g_warning ("Could not open file `%s'", file);
            exit_code = EXIT_FAILURE;
            goto bail;
        }

        g_object_unref (handle), handle = NULL;
    }

    exit_code = EXIT_SUCCESS;

bail:
    if (handle)
        g_object_unref (handle), handle = NULL;
    if (context)
        g_option_context_free (context), context = NULL;
    if (error)
        g_error_free (error), error = NULL;
    rsvg_term ();
    return exit_code;
}
Exemplo n.º 9
0
int
main (int argc, char **argv)
{
  GOptionContext *context;
  CheeseDbus     *dbus_server;
  GError         *error = NULL;

  GOptionEntry options[] = {
    {"verbose",    'v', 0,                    G_OPTION_ARG_NONE,   &CheeseOptions.verbose,
     _("Be verbose"), NULL},
    {"wide",       'w', 0,                    G_OPTION_ARG_NONE,   &CheeseOptions.wide_mode,
     _("Enable wide mode"), NULL},
    {"version",    0,   0,                    G_OPTION_ARG_NONE,   &CheeseOptions.version,
     _("output version information and exit"), NULL},
    {NULL}
  };

  bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  gtk_rc_parse (APPNAME_DATA_DIR G_DIR_SEPARATOR_S "gtkrc");

  g_thread_init (NULL);
  gdk_threads_init ();

  /* initialize rsvg */
  /* needed to load the camera icon for the countdown widget */
  rsvg_init ();

  g_set_application_name (_("Cheese"));

  context = g_option_context_new (N_("- Take photos and videos with your webcam, with fun graphical effects"));
  g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
  g_option_context_add_group (context, gtk_get_option_group (TRUE));
  g_option_context_add_group (context, gst_init_get_option_group ());
  if (g_option_context_parse (context, &argc, &argv, &error) == FALSE)
  {
    gchar *help_text = g_option_context_get_help (context, TRUE, NULL);
    g_print ("%s\n\n%s", error->message, help_text);
    g_free (help_text);
    g_error_free (error);
    g_option_context_free (context);
    return -1;
  }
  g_option_context_free (context);

  if (CheeseOptions.version)
  {
    g_print ("Cheese " VERSION " \n");
    return 0;
  }

  dbus_server = cheese_dbus_new ();
  if (dbus_server == NULL)
  {
    gdk_notify_startup_complete ();
    return -1;
  }

  g_set_print_handler ((GPrintFunc) cheese_print_handler);
  g_print ("Cheese " VERSION " \n");

  gtk_window_set_default_icon_name ("cheese");
  gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
                                     APPNAME_DATA_DIR G_DIR_SEPARATOR_S "icons");

  CheeseWindow *window = g_object_new (CHEESE_TYPE_WINDOW,
                                       "startup-wide", CheeseOptions.wide_mode,
                                       NULL);

  cheese_dbus_set_window (window);

  gtk_widget_show (GTK_WIDGET (window));

  gdk_threads_enter ();
  gtk_main ();
  gdk_threads_leave ();

  /* cleanup rsvg */
  /* Note: this function is bad with multithread applications as it
   * calls xmlCleanupParser() and should be only called right before
   * exit */
  rsvg_term ();

  return 0;
}
Exemplo n.º 10
0
static RsvgHandle* gvloadimage_rsvg_load(GVJ_t * job, usershape_t *us)
{
    RsvgHandle* rsvgh = NULL;
    guchar *fileBuf = NULL;
    GError *err = NULL;
    gsize fileSize;
    gint result;

    int fd;
    struct stat stbuf;

    assert(job);
    assert(us);
    assert(us->name);

    if (us->data) {
        if (us->datafree == gvloadimage_rsvg_free)
             rsvgh = (RsvgHandle*)(us->data); /* use cached data */
        else {
             us->datafree(us);        /* free incompatible cache data */
             us->data = NULL;
        }

    }

    if (!rsvgh) { /* read file into cache */
	if (!gvusershape_file_access(us))
	    return NULL;
        switch (us->type) {
            case FT_SVG:

		rsvg_init();

      		rsvgh = rsvg_handle_new();
		
		if (rsvgh == NULL) {
			fprintf(stderr, "rsvg_handle_new_from_file returned an error: %s\n", err->message);
			rsvg_term();
			return NULL;
		} 

	 	fd = fileno(us->f);
		fstat(fd, &stbuf);
  		fileSize = stbuf.st_size;	

		fileBuf = calloc(fileSize + 1, sizeof(guchar));

		if (fileBuf == NULL) {
			rsvg_handle_free(rsvgh);
			rsvg_term();
			return NULL;
		}
	
		rewind(us->f);

		if ((result = fread(fileBuf, 1, fileSize, us->f)) < fileSize) {
			rsvg_handle_free(rsvgh);
			rsvg_term();
			return NULL;
		}

		if (rsvg_handle_write(rsvgh, (const guchar *)fileBuf, (gsize)fileSize, &err) == FALSE) {
			fprintf(stderr, "rsvg_handle_write returned an error: %s\n", err->message);
			free(fileBuf);
			rsvg_handle_free(rsvgh);
			rsvg_term();
			return NULL;
		} 

		free(fileBuf);

		rsvg_handle_close(rsvgh, &err);
		rsvg_handle_set_dpi(rsvgh, POINTS_PER_INCH);

                break;
            default:
                rsvgh = NULL;
        }

        if (rsvgh) {
            us->data = (void*)rsvgh;
            us->datafree = gvloadimage_rsvg_free;
        }

	gvusershape_file_release(us);
    }

    return rsvgh;
}
Exemplo n.º 11
0
void
SvgPluginVTable::fini ()
{
    rsvg_term ();
}
Exemplo n.º 12
0
SDL_Surface *LoadSvg(char *fname, int hor_width, int hor_height, bool rot, bool cache)
{
    SDL_Surface *res = NULL;
    bool skip = false;

    rsvg_init();

    GError *error = NULL;
    RsvgHandle *rsvg_handle = rsvg_handle_new_from_file(fname, &error);
    if (!rsvg_handle)
    {
        log_error("can't load vector image `%s'", fname);
        LoadImgErrors++;
        skip = true;
    }

    if (!skip)
    {
        RsvgDimensionData dimensions;
        rsvg_handle_get_dimensions(rsvg_handle, &dimensions);
        int svg_width = dimensions.width;
        int svg_height = dimensions.height;

        float svg_koef = (float)svg_width / svg_height;
        float hor_koef = (float)hor_width / hor_height;
        float scale = (svg_koef > hor_koef ? (float)hor_height / svg_height : (float)hor_width / svg_width);

        int scaled_width = (int)(svg_width * scale);
        int scaled_height = (int)(svg_height * scale);

        int res_width = (rot ? hor_height : hor_width);
        int res_height = (rot ? hor_width : hor_height);

        bool loaded_from_cache = false;
        char *cached_file_full = NULL;
        char *file = NULL;
        char *file_hash = NULL;
        if (cache && can_cache)
        {
            int mod_time = 0;
            struct stat st;
            if (stat(fname, &st) == 0)
                mod_time = st.st_mtime;

            char *last_slash_ptr = strrchr(fname, '/');
            file = (last_slash_ptr ? last_slash_ptr + 1 : fname);
            int max_overhead = 64;
            cached_file_full = (char*)malloc(strlen(cache_dir_full) + strlen("/") + strlen(file) + max_overhead + 1);
            file_hash = (char*)malloc(strlen(file) + max_overhead + 1);

            char *state = (rot ? "rotated" : "normal");
            sprintf(cached_file_full, "%s/%s_%x-%dx%d-%s.png", cache_dir_full, file, mod_time, res_width, res_height, state);
            sprintf(file_hash, "%s_%x", file, mod_time);

            res = LoadImg(cached_file_full, false);
            if (res)
            {
                log_info("vector image `%s' was loaded from cache `%s'", fname, cached_file_full);
                loaded_from_cache = true;
            }
        }

        if (!loaded_from_cache)
        {
            int stride = res_width * 4; /* 4 bytes/pixel (32bpp RGBA) */
            void *image = calloc(stride * res_height, 1);
            cairo_surface_t *cairo_surf = cairo_image_surface_create_for_data(
                                              image, CAIRO_FORMAT_ARGB32,
                                              res_width, res_height, stride);
            cairo_t *cr = cairo_create(cairo_surf);

            if (rot)
            {
                cairo_translate(cr, -(scaled_height-res_width)/2, res_height+(scaled_width-res_height)/2);
                cairo_scale(cr, scale, scale);
                cairo_rotate(cr, -M_PI/2);
            }
            else
            {
                cairo_translate(cr, -(scaled_width-res_width)/2, -(scaled_height-res_height)/2);
                cairo_scale(cr, scale, scale);
            }

            rsvg_handle_render_cairo(rsvg_handle, cr);

            cairo_surface_finish(cairo_surf);
            cairo_destroy(cr);

            uint32_t rmask = 0x00ff0000;
            uint32_t gmask = 0x0000ff00;
            uint32_t bmask = 0x000000ff;
            uint32_t amask = 0xff000000;
            //Notice that it matches CAIRO_FORMAT_ARGB32
            res = SDL_CreateRGBSurfaceFrom(
                      (void*) image,
                      res_width, res_height,
                      32, //4 bytes/pixel = 32bpp
                      stride,
                      rmask, gmask, bmask, amask);
        }

        if (cache && can_cache)
        {
            if (!loaded_from_cache && res)
            {
                if (TouchDir(save_dir_full) && TouchDir(cache_dir_full))
                {
                    ClearCache(file, file_hash);
                    if (IMG_SavePNG(res, cached_file_full) == 0)
                        log_info("vector image `%s' was cached to `%s'", fname, cached_file_full);
                    else
                        log_error("can't cache vector image `%s' to `%s'", fname, cached_file_full);
                }
                else
                    can_cache = false;
            }
            free(cached_file_full);
            free(file_hash);
        }
    }

    rsvg_term();

    return res;
}
Exemplo n.º 13
0
int main(int argc, char** argv)
{

  TheStage stage;

  cmdline::parser opt;
  opt.add<std::string>("file", 'f', "Script file.");
  opt.add("interactive", 'i', "Run in interactive mode.");
  opt.add("quiet", 'q', "Quiet mode; does not emit recorded script.");
  opt.add<std::string>("directory", 'd', "Recording directory.", false, ".");
  opt.add("list-commands", 'l', "List all the avaiable commands.");
  opt.add<int>("start", 's', "Start at.", false, 0);
  opt.parse_check(argc, argv);

  if (opt.exist("list-commands")) {
    std::cout << "Commands supported:" << std::endl;
    exit(0);
  }

  bool isInteractive = opt.exist("interactive");
  bool isQuiet = opt.exist("quiet");
  
  std::string recordingDirectory = opt.get<std::string>("directory");

  // TODO: Do these things inside the Stage
  std::string scriptFileName = opt.get<std::string>("file");
  std::ifstream scriptFile(scriptFileName);

  if (!scriptFile.is_open()) {
    std::cout << "No such file: " << scriptFileName << std::endl;
    exit(1);
  }

  picojson::value json;
  scriptFile >> json;
  scriptFile.close();
  picojson::object& obj = json.get<picojson::object>();
  picojson::array& commands = obj["commands"].get<picojson::array>();

  // TODO: Make VideoConfig and use it to deal with these.
  picojson::object& videoSetting = obj["video"].get<picojson::object>();
  std::string outputDirectory = videoSetting["output"].get<std::string>();
  stage.SetFps((int)videoSetting["fps"].get<double>());
  stage.SetDuration((int)videoSetting["duration"].get<double>());
  stage.SetResolution((int)videoSetting["width"].get<double>(), (int)videoSetting["height"].get<double>());
  stage.SetOutputDirectory(videoSetting["output"].get<std::string>());
  stage.SetResourcesDirectory(videoSetting["resources"].get<std::string>());
  stage.ShowVideoSetting();

  rsvg_init(); // TODO: GCC tells this is deprecated. See the detail. Or about librsvgmm.

  for(picojson::array::iterator it = commands.begin(); it != commands.end(); ++it) {
    stage.storedCommands.push_back(StageCommandFactory::Create(*it));
  }

  stage.Start();

  int startAt = opt.get<int>("start");

  if (isInteractive) {
    StageViewer viewer(&stage);
    viewer.Run();
  } else {
    for(int i = 0; i < stage.GetDuration(); i++) {
      stage.ExecuteCommandsUntilCurrentFrame();
      if (i < startAt) {
	stage.Skip();
	std::cout << stage.GetCurrentFrame() << "th frame skipped." << std::endl;
      } else {
	cairo_surface_t* surface = stage.Render();
	std::stringstream filename;
	filename << outputDirectory << "f" << std::setw(3) << std::setfill('0') << i + 1 << ".png";
	cairo_surface_write_to_png(surface, filename.str().c_str());
	cairo_surface_destroy(surface);
	std::cout << stage.GetCurrentFrame() << "th frame rendered." << std::endl;
      }
    }
  }

  stage.End();

  rsvg_term(); // TODO: GCC tells this is deprecated. See the detail.

  if (!isQuiet) {
    time_t t = time(0);
    std::stringstream ss;
    // TODO: Trim the trailing slash
    // TODO: Make sure the existance of the directory you're about to write into. 
    ss << recordingDirectory << "/recorded-" << t << ".json";
    std::string recordedScriptFileName = ss.str();
    std::ofstream recordedScriptFile(recordedScriptFileName);
    recordedScriptFile << stage.GetRecordedScript();
    recordedScriptFile.close();
  }

  return 0;
}
Exemplo n.º 14
0
Arquivo: svg.c Projeto: 5UN5H1N3/vlc
/*****************************************************************************
 * CloseDecoder: png decoder destruction
 *****************************************************************************/
static void CloseDecoder( vlc_object_t *p_this )
{
    VLC_UNUSED( p_this );
    rsvg_term();
}
Exemplo n.º 15
0
/**
 * fo_doc_cairo_place_image:
 * @fo_doc: 
 * @fo_image: 
 * @x: 
 * @y: 
 * @xscale: 
 * @yscale: 
 * 
 * 
 **/
static void
fo_doc_cairo_place_image (FoDoc   *fo_doc,
			  FoImage *fo_image,
			  gdouble  x G_GNUC_UNUSED,
			  gdouble  y G_GNUC_UNUSED,
			  gdouble  xscale G_GNUC_UNUSED,
			  gdouble  yscale G_GNUC_UNUSED)
{
  GdkPixbuf *pixbuf = g_object_ref (fo_pixbuf_get_pixbuf (fo_image));
  gint width = gdk_pixbuf_get_width (pixbuf);
  gint height = gdk_pixbuf_get_height (pixbuf);
  guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
  int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
  int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
  guchar *cairo_pixels;
  cairo_format_t format;
  cairo_surface_t *surface;
  static const cairo_user_data_key_t key;
  int j;

  cairo_translate (FO_DOC_CAIRO (fo_doc)->cr,
		   0,
		   FO_DOC_CAIRO(fo_doc)->page_height);
  cairo_save (FO_DOC_CAIRO(fo_doc)->cr);
  cairo_scale (FO_DOC_CAIRO (fo_doc)->cr,
	       xscale * 72.0 / PIXELS_PER_INCH,
	       yscale * 72.0 / PIXELS_PER_INCH);

#if HAVE_LIBRSVG
  if (g_str_has_suffix( fo_image_get_uri(fo_image), ".svg"))
    {
      RsvgHandle *rsvg;
      GError *error = NULL;
      g_log (G_LOG_DOMAIN,
             G_LOG_LEVEL_DEBUG,
             "rendering %s as SVG\n",
             fo_image_get_uri(fo_image));
      rsvg_init();
      rsvg_set_default_dpi_x_y (PIXELS_PER_INCH, PIXELS_PER_INCH);
      rsvg = rsvg_handle_new_from_file (fo_image_get_uri(fo_image), &error);
      rsvg_handle_render_cairo (rsvg, FO_DOC_CAIRO(fo_doc)->cr);
      rsvg_term();
      cairo_restore (FO_DOC_CAIRO(fo_doc)->cr);
      if (error) {
	g_log (G_LOG_DOMAIN,
	       G_LOG_LEVEL_ERROR,
	       error->message);
	g_error_free (error);
      }
      return;
    }
#endif

  if (n_channels == 3)
    {
      format = CAIRO_FORMAT_RGB24;
    }
  else
    {
      format = CAIRO_FORMAT_ARGB32;
    }

  cairo_pixels = g_malloc (4 * width * height);
  surface = cairo_image_surface_create_for_data ((unsigned char *)cairo_pixels,
						 format,
						 width, height, 4 * width);
  cairo_surface_set_user_data (surface, &key,
			       cairo_pixels, (cairo_destroy_func_t)g_free);

  for (j = height; j; j--)
    {
      guchar *p = gdk_pixels;
      guchar *q = cairo_pixels;

      if (n_channels == 3)
	{
	  guchar *end = p + 3 * width;
	  
	  while (p < end)
	    {
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
	      q[0] = p[2];
	      q[1] = p[1];
	      q[2] = p[0];
#else	  
	      q[1] = p[0];
	      q[2] = p[1];
	      q[3] = p[2];
#endif
	      p += 3;
	      q += 4;
	    }
	}
      else
	{
	  guchar *end = p + 4 * width;
	  guint t1,t2,t3;
	    
#define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END

	  while (p < end)
	    {
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
	      MULT(q[0], p[2], p[3], t1);
	      MULT(q[1], p[1], p[3], t2);
	      MULT(q[2], p[0], p[3], t3);
	      q[3] = p[3];
#else	  
	      q[0] = p[3];
	      MULT(q[1], p[0], p[3], t1);
	      MULT(q[2], p[1], p[3], t2);
	      MULT(q[3], p[2], p[3], t3);
#endif
	      
	      p += 4;
	      q += 4;
	    }
	  
#undef MULT
	}

      gdk_pixels += gdk_rowstride;
      cairo_pixels += 4 * width;
    }

  cairo_surface_set_fallback_resolution (surface,
					 PIXELS_PER_INCH,
					 PIXELS_PER_INCH);
  cairo_set_source_surface (FO_DOC_CAIRO (fo_doc)->cr, surface, 0, 0);
  cairo_pattern_t *pattern = cairo_get_source (FO_DOC_CAIRO (fo_doc)->cr);
  cairo_pattern_set_extend (pattern,
			    CAIRO_EXTEND_NONE);
  cairo_paint (FO_DOC_CAIRO (fo_doc)->cr);
  cairo_surface_destroy (surface);
  g_object_unref (pixbuf);
  cairo_restore (FO_DOC_CAIRO(fo_doc)->cr);
}
Exemplo n.º 16
0
int
main (int argc, char **argv)
{
    GError *err = NULL;
    GOptionContext *g_option_context;
    double x_zoom = 1.0;
    double y_zoom = 1.0;
    double dpi_x = -1.0;
    double dpi_y = -1.0;
    int width = -1;
    int height = -1;
    int bVersion = 0;
    char *bg_color = NULL;
    char *base_uri = NULL;
    int bKeepAspect = 0;
    char *id = NULL;

    int xid = -1;
    int from_stdin = 0;
    ViewerCbInfo info;

    struct RsvgSizeCallbackData size_data;

    char **args = NULL;
    gint n_args = 0;

    GOptionEntry options_table[] = {
#ifdef ENABLE_XEMBED
        {"xid", 'i', 0, G_OPTION_ARG_INT, &xid, N_("XWindow ID [for X11 embedding]"), N_("<int>")},
#endif
        {"stdin", 's', 0, G_OPTION_ARG_NONE, &from_stdin, N_("Read from stdin instead of a file"),
         NULL},
        {"dpi-x", 'd', 0, G_OPTION_ARG_DOUBLE, &dpi_x, N_("Set the # of Pixels Per Inch"),
         N_("<float>")},
        {"dpi-y", 'p', 0, G_OPTION_ARG_DOUBLE, &dpi_y, N_("Set the # of Pixels Per Inch"),
         N_("<float>")},
        {"x-zoom", 'x', 0, G_OPTION_ARG_DOUBLE, &x_zoom, N_("Set the x zoom factor"),
         N_("<float>")},
        {"y-zoom", 'y', 0, G_OPTION_ARG_DOUBLE, &y_zoom, N_("Set the y zoom factor"),
         N_("<float>")},
        {"width", 'w', 0, G_OPTION_ARG_INT, &width, N_("Set the image's width"), N_("<int>")},
        {"height", 'h', 0, G_OPTION_ARG_INT, &height, N_("Set the image's height"), N_("<int>")},
        {"bg-color", 'b', 0, G_OPTION_ARG_STRING, &bg_color,
         N_("Set the image background color (default: transparent)"), N_("<string>")},
        {"base-uri", 'u', 0, G_OPTION_ARG_STRING, &base_uri, N_("Set the base URI (default: none)"),
         N_("<string>")},
        {"id", 0, 0, G_OPTION_ARG_STRING, &id, N_("Only show one node (default: all)"),
         N_("<string>")},
        {"keep-aspect", 'k', 0, G_OPTION_ARG_NONE, &bKeepAspect,
         N_("Preserve the image's aspect ratio"), NULL},
        {"version", 'v', 0, G_OPTION_ARG_NONE, &bVersion, N_("Show version information"), NULL},
        {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL, N_("[FILE...]")},
        {NULL}
    };

    g_thread_init (NULL);

    info.pixbuf = NULL;
    info.svg_bytes = NULL;
    info.window = NULL;
    info.popup_menu = NULL;

    g_option_context = g_option_context_new ("- SVG Viewer");
    g_option_context_add_main_entries (g_option_context, options_table, NULL);
    g_option_context_add_group (g_option_context, gtk_get_option_group (TRUE));
    g_option_context_set_help_enabled (g_option_context, TRUE);
    if (!g_option_context_parse (g_option_context, &argc, &argv, NULL)) {
        exit (1);
    }

    g_option_context_free (g_option_context);

    if (bVersion != 0) {
        g_message (_("rsvg-view version %s\n"), VERSION);
        return 0;
    }

    if (args) {
        while (args[n_args] != NULL)
            n_args++;
    }

    if ((!from_stdin) && (n_args != 1)) {
        g_print (_("No files specified, and not using --stdin\n"));
        return 1;
    }

    /* initialize gtk+ and rsvg */
    rsvg_init ();

    rsvg_set_default_dpi_x_y (dpi_x, dpi_y);

    /* if both are unspecified, assume user wants to zoom the pixbuf in at least 1 dimension */
    if (width == -1 && height == -1) {
        size_data.type = RSVG_SIZE_ZOOM;
        size_data.x_zoom = x_zoom;
        size_data.y_zoom = y_zoom;
    }
    /* if both are unspecified, assume user wants to resize pixbuf in at least 1 dimension */
    else if (x_zoom == 1.0 && y_zoom == 1.0) {
        size_data.type = RSVG_SIZE_WH;
        size_data.width = width;
        size_data.height = height;
    }
    /* assume the user wants to zoom the pixbuf, but cap the maximum size */
    else {
        size_data.type = RSVG_SIZE_ZOOM_MAX;
        size_data.x_zoom = x_zoom;
        size_data.y_zoom = y_zoom;
        size_data.width = width;
        size_data.height = height;
    }

    size_data.keep_aspect_ratio = bKeepAspect;

    if (!from_stdin) {
        if (base_uri == NULL)
            base_uri = (char *) args[0];

        info.svg_bytes = _rsvg_acquire_xlink_href_resource (args[0], base_uri, NULL);
    } else {
        info.svg_bytes = g_byte_array_new ();

        for (;;) {
            unsigned char buf[1024 * 8];
            size_t nread = fread (buf, 1, sizeof (buf), stdin);

            if (nread > 0)
                g_byte_array_append (info.svg_bytes, buf, nread);

            if (nread < sizeof (buf)) {
                if (ferror (stdin)) {
                    g_print (_("Error reading\n"));
                    g_byte_array_free (info.svg_bytes, TRUE);
                    fclose (stdin);

                    return 1;
                } else if (feof (stdin))
                    break;
            }
        }

        fclose (stdin);
    }

    if (!info.svg_bytes || !info.svg_bytes->len) {
        g_print (_("Couldn't open %s\n"), args[0]);
        return 1;
    }

    info.base_uri = base_uri;
    info.id = id;

    info.pixbuf = 
        pixbuf_from_data_with_size_data (info.svg_bytes->data, info.svg_bytes->len, &size_data,
                                         base_uri, id, &err);

    if (!info.pixbuf) {
        g_print (_("Error displaying image"));

        if (err) {
            g_print (": %s", err->message);
            g_error_free (err);
        }

        g_print ("\n");

        return 1;
    }

    info.accel_group = gtk_accel_group_new ();

    view_pixbuf (&info, xid, bg_color);

    /* run the gtk+ main loop */
    gtk_main ();

    g_object_unref (G_OBJECT (info.pixbuf));
    g_byte_array_free (info.svg_bytes, TRUE);
    rsvg_term ();

    return 0;
}