Gnumeric ソースコード改変

目次
Gnumeric
Gnumeric ソースコード改変
Gnumeric example
Gnumeric move worksheet to another Wookbook problem
Gnumeric code memo
Gnumeric bubble plot label problem
Gnumeric goffice開発事始め
Gnumeric tree
Gnumeric selecting one column or row problem
Gnumeric position shifts at copy-pasting a chart
Gnumeric copy paste multiple chart problem

http://caesar.acc.umu.se/pub/GNOME/sources/gnumeric/1.10/gnumeric-1.10.17.tar.bz2
(最新git版は開発環境の要求が満たせなかった)

【index】

  1. default row height=13.50pts column width=54pts
  2. resize image keep aspect ratio
  3. default vertical align=Center
  4. insert multiple images Gnumericでプラグインの作成
バイナリ gnumeric-1.10.17 https://docs.google.com/file/d/0Bxx8FrCtx3TOdGhsZFNzM25mSWs/edit?usp=sharing

ldd

r@r-ThinkPad-T60:~$ ldd /usr/local/bin/gnumeric-1.10.17 
	linux-gate.so.1 =>  (0xb770f000)
	libspreadsheet-1.10.17.so => /usr/local/lib/libspreadsheet-1.10.17.so (0xb7403000)
	libgoffice-0.8.so.8 => /usr/lib/libgoffice-0.8.so.8 (0xb72bc000)
	libgmodule-2.0.so.0 => /usr/lib/i386-linux-gnu/libgmodule-2.0.so.0 (0xb72b6000)
	libgtk-x11-2.0.so.0 => /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0 (0xb6e4d000)
	libgdk-x11-2.0.so.0 => /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so.0 (0xb6d9f000)
	libgdk_pixbuf-2.0.so.0 => /usr/lib/i386-linux-gnu/libgdk_pixbuf-2.0.so.0 (0xb6d7d000)
	libgobject-2.0.so.0 => /usr/lib/i386-linux-gnu/libgobject-2.0.so.0 (0xb6d2d000)
	libglib-2.0.so.0 => /lib/i386-linux-gnu/libglib-2.0.so.0 (0xb6c30000)
	libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb6c15000)
	libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb6a6b000)
	libgsf-1.so.114 => /usr/lib/libgsf-1.so.114 (0xb6a2b000)
	libxml2.so.2 => /usr/lib/i386-linux-gnu/libxml2.so.2 (0xb68db000)
	libgthread-2.0.so.0 => /usr/lib/i386-linux-gnu/libgthread-2.0.so.0 (0xb68d7000)
	libatk-1.0.so.0 => /usr/lib/i386-linux-gnu/libatk-1.0.so.0 (0xb68b6000)
	libpangocairo-1.0.so.0 => /usr/lib/i386-linux-gnu/libpangocairo-1.0.so.0 (0xb68a9000)
	libcairo.so.2 => /usr/lib/i386-linux-gnu/libcairo.so.2 (0xb679f000)
	libpango-1.0.so.0 => /usr/lib/i386-linux-gnu/libpango-1.0.so.0 (0xb6756000)
	libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb6729000)
	libgconf-2.so.4 => /usr/lib/i386-linux-gnu/libgconf-2.so.4 (0xb66fb000)
	libgio-2.0.so.0 => /usr/lib/i386-linux-gnu/libgio-2.0.so.0 (0xb659c000)
	libpcre.so.3 => /lib/i386-linux-gnu/libpcre.so.3 (0xb655c000)
	libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb6557000)
	libX11.so.6 => /usr/lib/i386-linux-gnu/libX11.so.6 (0xb6420000)
	libXfixes.so.3 => /usr/lib/i386-linux-gnu/libXfixes.so.3 (0xb6419000)
	libpangoft2-1.0.so.0 => /usr/lib/i386-linux-gnu/libpangoft2-1.0.so.0 (0xb63ea000)
	libfontconfig.so.1 => /usr/lib/i386-linux-gnu/libfontconfig.so.1 (0xb63b2000)
	libXext.so.6 => /usr/lib/i386-linux-gnu/libXext.so.6 (0xb63a0000)
	libXrender.so.1 => /usr/lib/i386-linux-gnu/libXrender.so.1 (0xb6395000)
	libXinerama.so.1 => /usr/lib/i386-linux-gnu/libXinerama.so.1 (0xb6391000)
	libXi.so.6 => /usr/lib/i386-linux-gnu/libXi.so.6 (0xb6381000)
	libXrandr.so.2 => /usr/lib/i386-linux-gnu/libXrandr.so.2 (0xb6376000)
	libXcursor.so.1 => /usr/lib/i386-linux-gnu/libXcursor.so.1 (0xb636b000)
	libXcomposite.so.1 => /usr/lib/i386-linux-gnu/libXcomposite.so.1 (0xb6366000)
	libXdamage.so.1 => /usr/lib/i386-linux-gnu/libXdamage.so.1 (0xb6362000)
	libffi.so.6 => /usr/lib/i386-linux-gnu/libffi.so.6 (0xb635b000)
	librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb6352000)
	/lib/ld-linux.so.2 (0xb7710000)
	libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb6339000)
	libbz2.so.1.0 => /lib/i386-linux-gnu/libbz2.so.1.0 (0xb6327000)
	liblzma.so.5 => /lib/i386-linux-gnu/liblzma.so.5 (0xb6301000)
	libfreetype.so.6 => /usr/lib/i386-linux-gnu/libfreetype.so.6 (0xb6267000)
	libpixman-1.so.0 => /usr/lib/i386-linux-gnu/libpixman-1.so.0 (0xb61d0000)
	libpng12.so.0 => /lib/i386-linux-gnu/libpng12.so.0 (0xb61a7000)
	libxcb-shm.so.0 => /usr/lib/i386-linux-gnu/libxcb-shm.so.0 (0xb61a2000)
	libxcb-render.so.0 => /usr/lib/i386-linux-gnu/libxcb-render.so.0 (0xb6198000)
	libxcb.so.1 => /usr/lib/i386-linux-gnu/libxcb.so.1 (0xb6176000)
	libdbus-glib-1.so.2 => /usr/lib/i386-linux-gnu/libdbus-glib-1.so.2 (0xb6150000)
	libdbus-1.so.3 => /lib/i386-linux-gnu/libdbus-1.so.3 (0xb6106000)
	libselinux.so.1 => /lib/i386-linux-gnu/libselinux.so.1 (0xb60e6000)
	libresolv.so.2 => /lib/i386-linux-gnu/libresolv.so.2 (0xb60cf000)
	libexpat.so.1 => /lib/i386-linux-gnu/libexpat.so.1 (0xb60a7000)
	libXau.so.6 => /usr/lib/i386-linux-gnu/libXau.so.6 (0xb60a3000)
	libXdmcp.so.6 => /usr/lib/i386-linux-gnu/libXdmcp.so.6 (0xb609b000)

default row height=13.50pts column width=54pts

/file/Gnumericでプラグインの作成/12.75.png
gnumeric-1.10.17/src/sheet.c

	sheet_col_set_default_size_pts (sheet, 54);
	sheet_row_set_default_size_pts (sheet, 13.50);

resize image keep aspect ratio

kratiob.png
bugってwidth側のスピンしか操作できなくなったkeep ratio checkboxをつけて対応した

gnumeric-1.10.17/src/dialogs/dialog-sheetobject-size.c
/file/Gnumeric ソースコード改変/sheetobject-size.ui
/file/Gnumeric ソースコード改変/dialog-sheetobject-size.c

static void
cb_dialog_so_size_value_changed (G_GNUC_UNUSED GtkSpinButton *spinbutton,
				   SOSizeState *state)
{
	        if ( !gtk_widget_get_sensitive (GTK_WIDGET (state->hspin)) && new_width != width) {
	                new_height = (int)(height * new_width  / width);
			gtk_spin_button_set_value (state->hspin,
						   new_height);
		}
etc

default vertical align=Center

valign.png
gnumeric-1.10.17/src/mstyle.c

/**
 * gnm_style_new_default:
 *
 * Caller is responsible for unrefing the result.
 *
 * Return value: a new style initialized to the default state.
 **/
GnmStyle *
gnm_style_new_default (void)
{
	GnmStyle *new_style = gnm_style_new ();
	int i;

	gnm_style_set_font_name	  (new_style, gnm_conf_get_core_defaultfont_name ());
	gnm_style_set_font_size	  (new_style, gnm_conf_get_core_defaultfont_size ());
	gnm_style_set_font_bold	  (new_style, gnm_conf_get_core_defaultfont_bold ());
	gnm_style_set_font_italic (new_style, gnm_conf_get_core_defaultfont_italic ());

	gnm_style_set_format      (new_style, go_format_general ());
	gnm_style_set_align_v     (new_style, VALIGN_CENTER);
...

insert multiple images

普通のアスペクト比4:3のデジカメ画像群をドロップされると並べる。
セル罫線は上で13.5pts x 54ptsに改変してあるものとしている。

allpng.png
gdk_pixbufとclipboardを使う特性上、元画像がjpegでもpng形式でファイル内に保存され、サイズが大きくなる

130503_2054~001.jpg
メモ
src/sheet-control-gui.c /file/Gnumeric ソースコード改変/sheet-control-gui.c https://drive.google.com/folderview?id=0Bxx8FrCtx3TOYmNnUUN0QVdqS00&usp=sharing

#include <clipboard.h>
#include <cmd-edit.h>
#include <selection.h>
#include <sheet-view.h>

...

static void
tile_image (SheetControlGUI *scg, GSList *img_uris, int width, int xshift, int yshift, gboolean rotate)
{
	GtkClipboard *cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
	GSList *m;
	for (m = img_uris; m; m = m-> next) {
		char const *filename = g_filename_from_uri (m->data,NULL,NULL);
		GdkPixbuf *gpb = gdk_pixbuf_new_from_file_at_size (filename, width, -1, NULL);		
		if (!rotate){
			gtk_clipboard_set_image (cb, gpb);
		} else {
			GdkPixbuf *gpb_rotate = gdk_pixbuf_rotate_simple (gpb, GDK_PIXBUF_ROTATE_CLOCKWISE);
			gtk_clipboard_set_image (cb, gpb_rotate);
			g_object_unref (gpb_rotate);
		}
		g_object_unref (gpb);

		SheetView *sv = wb_control_cur_sheet_view (WORKBOOK_CONTROL (scg_wbc(scg)));
		GnmRange const *ss;
		g_return_if_fail (IS_SHEET_VIEW (sv));
        	g_return_if_fail (sv->selections != NULL);
		ss = sv->selections->data;
		sv->edit_pos.col=ss->start.col;
		sv->edit_pos.row=ss->start.row;
		cmd_paste_to_selection (scg_wbcg(scg), sv, PASTE_DEFAULT);
		sv_selection_set (sv, &sv->edit_pos,
				  ss->start.col + xshift,
				  ss->start.row + yshift,
				  ss->start.col + xshift ,
				  ss->start.row + yshift);
	}
}

static void
insert_images (SheetControlGUI *scg, double x, double y,
			   const char *data, unsigned len, GSList *img_uris)
{
	int shift = 0;
	GSList *m;
	for (m = img_uris; m; m = m-> next) {
		char const *uri_str = m->data;
		scg_drag_receive_img_uri (scg, x + shift, y + shift, uri_str);
		shift += 10;
	}
}

static void
scg_drag_receive_uri_list (SheetControlGUI *scg, double x, double y,
			   const char *data, unsigned len)
{
	char *cdata = g_strndup (data, len);
	GSList *urls = go_file_split_urls (cdata);
	GSList *l;
	GSList *img_uris = NULL;

	g_free (cdata);
	for (l = urls; l; l = l-> next) {
		char const *uri_str = l->data;
		gchar *mime = go_get_mime_type (uri_str);
		/* Note that we have imperfect detection of mime-type with some
		 * platforms, e.g. Win32. In the worst case if
		 * go_get_mime_type() doesn't return "application/x-gnumeric"
		 * (registry corruption?) it will give "text/plain" and a
		 * spreadsheet file is assumed. */
		if (!mime)
			continue;

		if (!strncmp (mime, "image/", 6))
			img_uris =  g_slist_append (img_uris, uri_str);
			//scg_drag_receive_img_uri (scg, x, y, uri_str);
		else if (!strcmp (mime, "application/x-gnumeric") ||
			 !strcmp (mime, "application/vnd.ms-excel") ||
			 !strcmp (mime, "application/vnd.sun.xml.calc") ||
			 !strcmp (mime, "application/vnd.oasis.opendocument.spreadsheet") ||
			 !strcmp (mime, "application/vnd.lotus-1-2-3") ||
			 !strcmp (mime, "application/x-applix-spreadsheet") ||
			 !strcmp (mime, "application/x-dbase") ||
			 !strcmp (mime, "application/x-oleo") ||
			 !strcmp (mime, "application/x-quattropro") ||
			 !strcmp (mime, "application/x-sc") ||
			 /* !strcmp (mime, "application/xhtml+xml") || */
			 !strcmp (mime, "text/spreadsheet") ||
			 !strcmp (mime, "text/tab-separated-values") ||
			 !strcmp (mime, "text/x-comma-separated-values") ||
			 !strcmp (mime, "text/html") ||
			 !strcmp (mime, "text/plain")) {
			scg_drag_receive_spreadsheet (scg, uri_str);
		} else {
			g_printerr ("Received URI %s with mime type %s.\n", uri_str, mime);
			g_printerr ("I have no idea what to do with that.\n");
		}
		g_free (mime);
	}


	if(img_uris!=NULL) {
		GtkWidget *dialog;
		dialog = gtk_dialog_new_with_buttons ("Tile Image method chooser",
								  wbcg_toplevel (WBC_GTK (scg_wbcg(scg))),
								  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
								  GTK_STOCK_OK,
								  GTK_RESPONSE_ACCEPT,
								  GTK_STOCK_CANCEL,
								  GTK_RESPONSE_REJECT,
								  NULL);

		GtkWidget *rad162r, *rad162b;
		GtkWidget *rad216r, *rad216b, *rad216rr, *rad216rb;
		GtkWidget *rad270r, *rad270b;
		GtkWidget *rad432r, *rad432b, *rad432rr, *rad432rb;
		GtkWidget *rad648b, *radorig;

		rad162r 	= gtk_radio_button_new_with_label (NULL,"width 162pts/216pixels →");
		rad162b 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "width 162pts/216pixels ↓");
		rad216r 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "width 216pts/288pixels →");
		rad216b 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "width 216pts/288pixels ↓");
		rad216rr 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "width 216pts/288pixels ↴→");
		rad216rb 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "width 216pts/288pixels ↴↓");
		rad270r 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "width 270pts/360pixels →");
		rad270b 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "width 270pts/360pixels ↓");
		rad432r 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "width 432pts/576pixels →");
		rad432b 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "width 432pts/576pixels ↓");
		rad432rr 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "width 432pts/576pixels ↴→");
		rad432rb 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "width 432pts/576pixels ↴↓");
		rad648b 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "width 648pts/864pixels ↓");
		radorig 	= gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rad162r), "original");

		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad162r );
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad162b );
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad216r );
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad216b );
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad216rr);
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad216rb);
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad270r );
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad270b );
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad432r );
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad432b );
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad432rr);
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad432rb);
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), rad648b );
		gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), radorig );
		gtk_widget_show_all (dialog);

		gint result = gtk_dialog_run(GTK_DIALOG(dialog));
		switch (result)
		{
		    case GTK_RESPONSE_ACCEPT://-3
			if      (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad162r ))) tile_image(scg,img_uris,216,3,0, FALSE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad162b ))) tile_image(scg,img_uris,216,0,9, FALSE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad216r ))) tile_image(scg,img_uris,288,4,0, FALSE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad216b ))) tile_image(scg,img_uris,288,0,12,FALSE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad216rr))) tile_image(scg,img_uris,288,3,0, TRUE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad216rb))) tile_image(scg,img_uris,288,0,16,TRUE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad270r ))) tile_image(scg,img_uris,360,5,0, FALSE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad270b ))) tile_image(scg,img_uris,360,0,15,FALSE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad432r ))) tile_image(scg,img_uris,576,8,0, FALSE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad432b ))) tile_image(scg,img_uris,576,0,24,FALSE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad432rr))) tile_image(scg,img_uris,576,6,0, TRUE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad432rb))) tile_image(scg,img_uris,576,0,32,TRUE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rad648b ))) tile_image(scg,img_uris,864,0,36,FALSE);
			else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radorig ))) insert_images(scg,x,y,data,len,img_uris);
	       		break;
		    default:
		       break;
		}

		gtk_widget_destroy(dialog);
	}

	go_slist_free_custom (urls, (GFreeFunc) g_free);
	g_slist_free(img_uris);
	//go_slist_free_custom (img_uris, (GFreeFunc) g_free);
}

JPEG 版

static void
tile_image (SheetControlGUI *scg, GSList *img_uris, int width, int xshift, int yshift, gboolean rotate, gboolean inpng)
{
	GError *err = NULL;

	GSList *m;
	for (m = img_uris; m; m = m-> next) {

		char const *filename = g_filename_from_uri (m->data,NULL,NULL);
		
		guint8 *sd = NULL;
		unsigned len;
		GdkPixbuf *gpb = NULL;

		gpb = gdk_pixbuf_new_from_file_at_size (filename, width, -1, NULL);
		if (rotate) gpb = gdk_pixbuf_rotate_simple (gpb, GDK_PIXBUF_ROTATE_CLOCKWISE);		
		
		if(!inpng) //jpeg
			gdk_pixbuf_save_to_buffer (gpb, &sd, &len, "jpeg", &err, NULL);//, "quality", "97.5", NULL);
		else {    //.GdkPixdata	
			GdkPixdata pd;
			gdk_pixdata_from_pixbuf (&pd, gpb, FALSE);
			sd = gdk_pixdata_serialize (&pd, &len);
			gdk_pixdata_deserialize(&pd, len, sd, &err);
			  //png
			//gdk_pixbuf_save_to_buffer (gpb, &sd, &len, "png", &err, "compression", "2", NULL);
		}

		g_object_unref (G_OBJECT(gpb));

		SheetView *sv = wb_control_cur_sheet_view (WORKBOOK_CONTROL (scg_wbc(scg)));
		GnmRange const *ss = sv->selections->data;
		g_return_if_fail (IS_SHEET_VIEW (sv));
        	g_return_if_fail (sv->selections != NULL);

		sv->edit_pos.col=ss->start.col;
		sv->edit_pos.row=ss->start.row;
		
		scg_paste_image(scg, ss, sd, len);
		g_free(sd);

		sv_selection_set (sv, &sv->edit_pos,
				  ss->start.col + xshift,
				  ss->start.row + yshift,
				  ss->start.col + xshift ,
				  ss->start.row + yshift);
	}
}
    last modified: 06 May 2013 [ View wiki source Close ]
     
SEARCH DIFFERENCE ATTACHMENT RECENT POST