<commit_before>/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-
 * test-display: 
 *
 * Copyright (C) 2002-2004 <NAME>
 *
 * This program is released into the PUBLIC DOMAIN, and is meant to be a
 * useful example if how to draw a SVG image inside of a GtkWidget. This 
 * program is free software; you can redistribute it and/or modify it at your
 * will.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
 *
 * Simple utility to view a SVG file inside of a GtkWindow
 */

#include "config.h"
#include "rsvg.h"
#include "rsvg-private.h"

#include <stdio.h>
#include <stdlib.h>
#include <popt.h>

#include <gtk/gtk.h>
#include <gdk/gdk.h>

#ifdef ENABLE_XEMBED
#include <gdk/gdkx.h>
#endif

#define DEFAULT_WIDTH  240
#define DEFAULT_HEIGHT 240

#define ICON_NAME "svg-viewer.svg"

typedef struct _ViewerCbInfo ViewerCbInfo;
struct _ViewerCbInfo
{
	GtkWidget  * window;
	GdkPixbuf  * pixbuf;
	GByteArray * svg_bytes;
};

static void
center_dialog (GtkWidget * child, GtkWidget * parent)
{
	GdkPixbuf * icon;

	gtk_window_set_transient_for(GTK_WINDOW(child),
								 GTK_WINDOW(parent));

	icon = gtk_window_get_icon(GTK_WINDOW(parent));	

	if (NULL != icon)
		gtk_window_set_icon(GTK_WINDOW(child), icon);
}

#ifdef HAVE_GNOME_PRINT

#include <libgnomeprint/gnome-print.h>
#include <libgnomeprint/gnome-print-job.h>
#include <libgnomeprintui/gnome-print-dialog.h>
#include <libgnomeprintui/gnome-print-job-preview.h>

static void 
print_pixbuf (GObject * ignored, gpointer user_data)
{
	ViewerCbInfo * info = (ViewerCbInfo *)user_data;
	GtkWidget *gpd;	
	gint result;

	gpd = gnome_print_dialog_new (gnome_print_job_new(gnome_print_config_default()), _("Print SVG"), 0);
	center_dialog (gpd, info->window);
			  
	if ((result = gtk_dialog_run (GTK_DIALOG (gpd))) != GNOME_PRINT_DIALOG_RESPONSE_CANCEL) {
		GnomePrintJob *gpm;
		GnomePrintContext * gpc;
		GdkPixbuf * image;

		gint width, height, rowstride;
		const guchar * pixels;

		gdouble page_width, page_height;

		gpm = gnome_print_job_new (gnome_print_dialog_get_config (GNOME_PRINT_DIALOG(gpd)));
		gpc = gnome_print_job_get_context (gpm);

		gnome_print_config_get_page_size (gnome_print_job_get_config (gpm), &page_width, &page_height);		
		image = info->pixbuf;

		width     = gdk_pixbuf_get_width (image);
		height    = gdk_pixbuf_get_height (image);

		if (width > page_width ||
			height > page_height) {
			/* TODO: scale this image to the page's dimensions, preserving the aspect ratio */
			g_object_ref (G_OBJECT (image));
		} else {
			g_object_ref (G_OBJECT (image));
		}

		rowstride = gdk_pixbuf_get_rowstride (image);
		pixels    = gdk_pixbuf_get_pixels (image);

		gnome_print_beginpage(gpc, "1");
		gnome_print_gsave (gpc);
		gnome_print_translate (gpc, 0, page_height - height);
		gnome_print_scale (gpc, width, height);
		gnome_print_moveto (gpc, 0, 0);

		gnome_print_rgbaimage (gpc, pixels, width, height, rowstride);

		gnome_print_grestore (gpc);
		gnome_print_showpage (gpc);
		gnome_print_job_close (gpm);
		
		if(result == GNOME_PRINT_DIALOG_RESPONSE_PRINT)
			gnome_print_job_print (gpm);
		else
			{
				GtkWidget * preview;

				preview = gnome_print_job_preview_new (gpm, _("SVG Preview"));
				gtk_widget_show (GTK_WIDGET (preview));
			}
		
		g_object_unref (G_OBJECT (gpm));
		g_object_unref (G_OBJECT (image));
	}

	gtk_widget_destroy (gpd);
}

#endif

static void 
save_pixbuf (GObject * ignored, gpointer user_data)
{
	GtkWidget * filesel;
	ViewerCbInfo * info = (ViewerCbInfo *)user_data;<commit_msg>change a stupid string<commit_after>/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-
 * test-display: 
 *
 * Copyright (C) 2002-2004 <NAME>
 *
 * This program is released into the PUBLIC DOMAIN, and is meant to be a
 * useful example if how to draw a SVG image inside of a GtkWidget. This 
 * program is free software; you can redistribute it and/or modify it at your
 * will.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
 *
 * Simple utility to view a SVG file inside of a GtkWindow
 */

#include "config.h"
#include "rsvg.h"
#include "rsvg-private.h"

#include <stdio.h>
#include <stdlib.h>
#include <popt.h>

#include <gtk/gtk.h>
#include <gdk/gdk.h>

#ifdef ENABLE_XEMBED
#include <gdk/gdkx.h>
#endif

#define DEFAULT_WIDTH  240
#define DEFAULT_HEIGHT 240

#define ICON_NAME "svg-viewer.svg"

typedef struct _ViewerCbInfo ViewerCbInfo;
struct _ViewerCbInfo
{
	GtkWidget  * window;
	GdkPixbuf  * pixbuf;
	GByteArray * svg_bytes;
};

static void
center_dialog (GtkWidget * child, GtkWidget * parent)
{
	GdkPixbuf * icon;

	gtk_window_set_transient_for(GTK_WINDOW(child),
								 GTK_WINDOW(parent));

	icon = gtk_window_get_icon(GTK_WINDOW(parent));	

	if (NULL != icon)
		gtk_window_set_icon(GTK_WINDOW(child), icon);
}

#ifdef HAVE_GNOME_PRINT

#include <libgnomeprint/gnome-print.h>
#include <libgnomeprint/gnome-print-job.h>
#include <libgnomeprintui/gnome-print-dialog.h>
#include <libgnomeprintui/gnome-print-job-preview.h>

static void 
print_pixbuf (GObject * ignored, gpointer user_data)
{
	ViewerCbInfo * info = (ViewerCbInfo *)user_data;
	GtkWidget *gpd;	
	gint result;

	gpd = gnome_print_dialog_new (gnome_print_job_new(gnome_print_config_default()), _("Print SVG"), 0);
	center_dialog (gpd, info->window);
			  
	if ((result = gtk_dialog_run (GTK_DIALOG (gpd))) != GNOME_PRINT_DIALOG_RESPONSE_CANCEL) {
		GnomePrintJob *gpm;
		GnomePrintContext * gpc;
		GdkPixbuf * image;

		gint width, height, rowstride;
		const guchar * pixels;

		gdouble page_width, page_height;

		gpm = gnome_print_job_new (gnome_print_dialog_get_config (GNOME_PRINT_DIALOG(gpd)));
		gpc = gnome_print_job_get_context (gpm);

		gnome_print_config_get_page_size (gnome_print_job_get_config (gpm), &page_width, &page_height);		
		image = info->pixbuf;

		width     = gdk_pixbuf_get_width (image);
		height    = gdk_pixbuf_get_height (image);

		if (width > page_width ||
			height > page_height) {
			/* TODO: scale this image to the page's dimensions, preserving the aspect ratio */
			g_object_ref (G_OBJECT (image));
		} else {
			g_object_ref (G_OBJECT (image));
		}

		rowstride = gdk_pixbuf_get_rowstride (image);
		pixels    = gdk_pixbuf_get_pixels (image);

		gnome_print_beginpage(gpc, "1");
		gnome_print_gsave (gpc);
		gnome_print_translate (gpc, 0, page_height - height);
		gnome_print_scale (gpc, width, height);
		gnome_print_moveto (gpc, 0, 0);

		gnome_print_rgbaimage (gpc, pixels, width, height, rowstride);

		gnome_print_grestore (gpc);
		gnome_print_showpage (gpc);
		gnome_print_job_close (gpm);
		
		if(result == GNOME_PRINT_DIALOG_RESPONSE_PRINT)
			gnome_print_job_print (gpm);
		else
			{
				GtkWidget * preview;

				preview = gnome_print_job_preview_new (gpm, _("SVG Print Preview"));
				gtk_widget_show (GTK_WIDGET (preview));
			}
		
		g_object_unref (G_OBJECT (gpm));
		g_object_unref (G_OBJECT (image));
	}

	gtk_widget_destroy (gpd);
}

#endif

static void 
save_pixbuf (GObject * ignored, gpointer user_data)
{
	GtkWidget * filesel;
	ViewerCbInfo * info = (ViewerCbInfo *)user_data;
{'fraction_non_alphanumeric': 0.10791660989235591, 'fraction_numerical': 0.0057228505245946314, 'mean_word_length': 4.659213569776407, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1723522', 'n_tokens_mistral': 3053, 'n_tokens_neox': 2729, 'n_words': 659}