dia r4170 - in trunk: . app plug-ins/cairo
- From: hans svn gnome org
- To: svn-commits-list gnome org
- Subject: dia r4170 - in trunk: . app plug-ins/cairo
- Date: Fri, 2 Jan 2009 17:00:31 +0000 (UTC)
Author: hans
Date: Fri Jan 2 17:00:30 2009
New Revision: 4170
URL: http://svn.gnome.org/viewvc/dia?rev=4170&view=rev
Log:
2009-01-02 Hans Breuer <hans breuer org>
Patch from Takao Fujiwara fixing bug #564850 â dia crashes on none UTF-8
* app/diagram.c : don't initialize unused filename (with the wrong locale)
* app/filedlg.c : gtk_file_chooser_set_current_name() wants utf-8, not
filename encoding
* plug-ins/cairo/diacairo.c : export_data() first filename already is in
the GLib's filename encoding - but on win32 this is always utf-8, i.e. not
appropriate to be used with cairo
Modified:
trunk/ChangeLog
trunk/app/diagram.c
trunk/app/filedlg.c
trunk/plug-ins/cairo/diacairo.c
Modified: trunk/app/diagram.c
==============================================================================
--- trunk/app/diagram.c (original)
+++ trunk/app/diagram.c Fri Jan 2 17:00:30 2009
@@ -1457,7 +1457,6 @@
GSList *l;
DDisplay *ddisp;
char *title;
- char *filename = dia->filename;
title = diagram_get_name(dia);
Modified: trunk/app/filedlg.c
==============================================================================
--- trunk/app/filedlg.c (original)
+++ trunk/app/filedlg.c Fri Jan 2 17:00:30 2009
@@ -490,9 +490,10 @@
if (filename != NULL) {
char* fnabs = dia_get_absolute_filename (filename);
if (fnabs) {
- gchar *base = g_path_get_basename(fnabs);
+ gchar *base = g_path_get_basename(dia->filename);
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(savedlg), fnabs);
/* FileChooser api insist on exiting files for set_filename */
+ /* ... and does not use filename encoding on this one. */
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(savedlg), base);
g_free(base);
}
@@ -562,9 +563,10 @@
const gchar* ext = NULL;
DiaExportFilter *efilter = efilter_by_index (index, &ext);
gchar *basename = g_path_get_basename (name);
+ gchar *utf8_name = NULL;
if (!efilter || !ext)
- gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(exportdlg), basename);
+ utf8_name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
else {
const gchar *last_dot = strrchr(basename, '.');
GString *s = g_string_new(basename);
@@ -572,9 +574,11 @@
g_string_truncate(s, last_dot-basename);
g_string_append(s, ".");
g_string_append(s, ext);
- gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(exportdlg), s->str);
+ utf8_name = g_filename_to_utf8 (s->str, -1, NULL, NULL, NULL);
g_string_free (s, TRUE);
}
+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(exportdlg), utf8_name);
+ g_free (utf8_name);
g_free (basename);
}
static void
Modified: trunk/plug-ins/cairo/diacairo.c
==============================================================================
--- trunk/plug-ins/cairo/diacairo.c (original)
+++ trunk/plug-ins/cairo/diacairo.c Fri Jan 2 17:00:30 2009
@@ -98,34 +98,40 @@
/* dia export funtion */
static void
-export_data(DiagramData *data, const gchar *filename_utf8,
+export_data(DiagramData *data, const gchar *filename,
const gchar *diafilename, void* user_data)
{
DiaCairoRenderer *renderer;
FILE *file;
real width, height;
OutputKind kind = (OutputKind)user_data;
- gchar* filename = NULL;
+ /* the passed in filename is in GLib's filename encoding. On Linux everything
+ * should be fine in passing it to the C-runtime (or cairo). On win32 GLib's
+ * filename encdong is always utf-8, so another conversion is needed.
+ */
+ gchar *filename_crt = (gchar *)filename;
#if DIA_CAIRO_CAN_EMF
HDC hFileDC = NULL;
#endif
if (kind != OUTPUT_CLIPBOARD) {
- filename = g_locale_from_utf8 (filename_utf8, -1, NULL, NULL, NULL);
- if (!filename) {
- message_error(_("Can't convert output filename '%s' to locale encoding.\n"
- "Please choose a different name to save with cairo.\n"),
- dia_message_filename(filename_utf8), strerror(errno));
- return;
- }
file = g_fopen(filename, "wb"); /* "wb" for binary! */
if (file == NULL) {
message_error(_("Can't open output file %s: %s\n"),
- dia_message_filename(filename_utf8), strerror(errno));
+ dia_message_filename(filename), strerror(errno));
return;
}
fclose (file);
+#ifdef G_OS_WIN32
+ filename_crt = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL);
+ if (!filename_crt) {
+ message_error(_("Can't convert output filename '%s' to locale encoding.\n"
+ "Please choose a different name to save with cairo.\n"),
+ dia_message_filename(filename), strerror(errno));
+ return;
+ }
+#endif
} /* != CLIPBOARD */
renderer = g_object_new (DIA_TYPE_CAIRO_RENDERER, NULL);
renderer->dia = data; /* FIXME: not sure if this a good idea */
@@ -138,7 +144,7 @@
height = data->paper.height * (72.0 / 2.54);
renderer->scale = data->paper.scaling * (72.0 / 2.54);
DIAG_NOTE(g_message ("PS Surface %dx%d\n", (int)width, (int)height));
- renderer->surface = cairo_ps_surface_create (filename,
+ renderer->surface = cairo_ps_surface_create (filename_crt,
width, height); /* in points? */
/* maybe we should increase the resolution here as well */
break;
@@ -170,7 +176,7 @@
width = data->paper.width * (72.0 / 2.54);
height = data->paper.height * (72.0 / 2.54);
DIAG_NOTE(g_message ("PDF Surface %dx%d\n", (int)width, (int)height));
- renderer->surface = cairo_pdf_surface_create (filename,
+ renderer->surface = cairo_pdf_surface_create (filename_crt,
width, height);
cairo_surface_set_fallback_resolution (renderer->surface, DPI, DPI);
#undef DPI
@@ -185,7 +191,7 @@
DIAG_NOTE(g_message ("SVG Surface %dx%d\n", (int)width, (int)height));
/* use case screwed by API shakeup. We need to special case */
renderer->surface = cairo_svg_surface_create(
- filename,
+ filename_crt,
(int)width, (int)height);
break;
#endif
@@ -232,13 +238,13 @@
#if defined CAIRO_HAS_PNG_FUNCTIONS
if (OUTPUT_PNGA == kind || OUTPUT_PNG == kind)
{
- cairo_surface_write_to_png(renderer->surface, filename);
+ cairo_surface_write_to_png(renderer->surface, filename_crt);
cairo_surface_destroy(renderer->surface);
}
#endif
#if DIA_CAIRO_CAN_EMF
if (OUTPUT_EMF == kind) {
- FILE* f = g_fopen(filename_utf8, "wb");
+ FILE* f = g_fopen(filename, "wb");
HENHMETAFILE hEmf = CloseEnhMetaFile(hFileDC);
UINT nSize = GetEnhMetaFileBits (hEmf, 0, NULL);
BYTE* pData = g_new(BYTE, nSize);
@@ -247,12 +253,12 @@
fwrite(pData,1,nSize,f);
fclose(f);
} else {
- message_error (_("Can't write %d bytes to %s"), nSize, filename_utf8);
+ message_error (_("Can't write %d bytes to %s"), nSize, filename);
}
DeleteEnhMetaFile (hEmf);
g_free (pData);
} else if (OUTPUT_WMF == kind) {
- FILE* f = g_fopen(filename_utf8, "wb");
+ FILE* f = g_fopen(filename, "wb");
HENHMETAFILE hEmf = CloseEnhMetaFile(hFileDC);
HDC hdc = GetDC(NULL);
UINT nSize = GetWinMetaFileBits (hEmf, 0, NULL, MM_ANISOTROPIC, hdc);
@@ -263,7 +269,7 @@
fwrite(pData,1,nSize,f);
fclose(f);
} else {
- message_error (_("Can't write %d bytes to %s"), nSize, filename_utf8);
+ message_error (_("Can't write %d bytes to %s"), nSize, filename);
}
ReleaseDC(NULL, hdc);
DeleteEnhMetaFile (hEmf);
@@ -282,6 +288,8 @@
}
#endif
g_object_unref(renderer);
+ if (filename != filename_crt)
+ g_free (filename_crt);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]