Permalink
Browse files

Bug #769736 - Saving a file with non-English letters is not saved wit…

…h correct name

The problem is windows gtk specific. The gdk_pixbuf_save and
gdk_pixbuf_savev are renamed to gdk_pixbuf_save_utf8 and
gdk_pixbuf_savev_utf8 in the windows implementation.
Similar to
http://stackoverflow.com/questions/12946991/how-to-create-a-gdk-pixbuf-from-a-unicode-filename-in-windows.
  • Loading branch information...
1 parent 2cfc384 commit 7f682a387509b0c1dea35ad557e373a6bb7aa376 @nunofonseca nunofonseca committed Nov 25, 2012
Showing with 191 additions and 135 deletions.
  1. +141 −86 Pinta.Core/ImageFormats/GdkPixbufFormat.cs
  2. +50 −49 Pinta.Core/ImageFormats/JpegFormat.cs
@@ -1,86 +1,141 @@
-//
-// GdkPixbufFormat.cs
-//
-// Author:
-// Maia Kozheva <sikon@ubuntu.com>
-//
-// Copyright (c) 2010 Maia Kozheva <sikon@ubuntu.com>
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-using System;
-using System.IO;
-
-using Gdk;
-
-namespace Pinta.Core
-{
- public class GdkPixbufFormat: IImageImporter, IImageExporter
- {
- private string filetype;
-
- public GdkPixbufFormat(string filetype)
- {
- this.filetype = filetype;
- }
-
- public void Import (string fileName)
- {
- Pixbuf bg;
-
- // Handle any EXIF orientation flags
- using (var fs = new FileStream (fileName, FileMode.Open, FileAccess.Read))
- bg = new Pixbuf (fs);
-
- bg = bg.ApplyEmbeddedOrientation ();
-
- Size imagesize = new Size (bg.Width, bg.Height);
-
- Document doc = PintaCore.Workspace.CreateAndActivateDocument (fileName, imagesize);
- doc.HasFile = true;
- doc.ImageSize = imagesize;
- doc.Workspace.CanvasSize = imagesize;
-
- Layer layer = doc.AddNewLayer (Path.GetFileName (fileName));
-
- using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
- CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
- g.Paint ();
- }
-
- bg.Dispose ();
- }
-
- protected virtual void DoSave (Pixbuf pb, string fileName, string fileType)
- {
- pb.Save (fileName, fileType);
- }
-
- public void Export (Document document, string fileName)
- {
- Cairo.ImageSurface surf = document.GetFlattenedImage ();
-
- Pixbuf pb = surf.ToPixbuf ();
- DoSave(pb, fileName, filetype);
-
- (pb as IDisposable).Dispose ();
- (surf as IDisposable).Dispose ();
- }
- }
-}
+//
+// GdkPixbufFormat.cs
+//
+// Author:
+// Maia Kozheva <sikon@ubuntu.com>
+//
+// Copyright (c) 2010 Maia Kozheva <sikon@ubuntu.com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+
+using Gdk;
+
+namespace Pinta.Core
+{
+ public class GdkPixbufFormat: IImageImporter, IImageExporter
+ {
+ private string filetype;
+
+ public GdkPixbufFormat(string filetype)
+ {
+ this.filetype = filetype;
+ }
+
+ public void Import (string fileName)
+ {
+ Pixbuf bg;
+
+ // Handle any EXIF orientation flags
+ using (var fs = new FileStream (fileName, FileMode.Open, FileAccess.Read))
+ bg = new Pixbuf (fs);
+
+ bg = bg.ApplyEmbeddedOrientation ();
+
+ Size imagesize = new Size (bg.Width, bg.Height);
+
+ Document doc = PintaCore.Workspace.CreateAndActivateDocument (fileName, imagesize);
+ doc.HasFile = true;
+ doc.ImageSize = imagesize;
+ doc.Workspace.CanvasSize = imagesize;
+
+ Layer layer = doc.AddNewLayer (Path.GetFileName (fileName));
+
+ using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
+ CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
+ g.Paint ();
+ }
+
+ bg.Dispose ();
+ }
+
+ protected virtual void DoSave (Pixbuf pb, string fileName, string fileType)
+ {
+ pb.SaveUtf8(fileName, fileType);
+ }
+
+ public void Export (Document document, string fileName)
+ {
+ Cairo.ImageSurface surf = document.GetFlattenedImage ();
+
+ Pixbuf pb = surf.ToPixbuf ();
+ DoSave(pb, fileName, filetype);
+
+ (pb as IDisposable).Dispose ();
+ (surf as IDisposable).Dispose ();
+ }
+ }
+
+ internal static class PixbufExtensions
+ {
+ [DllImport ("libgdk_pixbuf-2.0-0.dll")]
+ private static extern bool gdk_pixbuf_save_utf8 (IntPtr raw, IntPtr filename, IntPtr type, out IntPtr error, IntPtr dummy);
+
+ public static bool SaveUtf8 (this Pixbuf pb, string filename, string type)
+ {
+ if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
+ IntPtr zero = IntPtr.Zero;
+ IntPtr intPtr = GLib.Marshaller.StringToPtrGStrdup (filename);
+ IntPtr intPtr2 = GLib.Marshaller.StringToPtrGStrdup (type);
+ bool result = gdk_pixbuf_save_utf8 (pb.Handle, intPtr, intPtr2, out zero, IntPtr.Zero);
+ GLib.Marshaller.Free (intPtr);
+ GLib.Marshaller.Free (intPtr2);
+ if (zero != IntPtr.Zero) {
+ throw new GLib.GException (zero);
+ }
+ return result;
+ }
+ return pb.Save(filename, type);
+ }
+
+ [DllImport ("libgdk_pixbuf-2.0-0.dll")]
+ private static extern bool gdk_pixbuf_savev_utf8 (IntPtr raw, IntPtr filename, IntPtr type, IntPtr[] option_keys, IntPtr[] option_values, out IntPtr error);
+
+ public static bool SavevUtf8 (this Pixbuf pb, string filename, string type, string[] option_keys, string[] option_values)
+ {
+ if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
+ IntPtr intPtr = GLib.Marshaller.StringToPtrGStrdup (filename);
+ IntPtr intPtr2 = GLib.Marshaller.StringToPtrGStrdup (type);
+ int num = (option_keys == null) ? 0 : option_keys.Length;
+ IntPtr[] array = new IntPtr[num];
+ for (int i = 0; i < num; i++) {
+ array [i] = GLib.Marshaller.StringToPtrGStrdup (option_keys [i]);
+ }
+ int num2 = (option_values == null) ? 0 : option_values.Length;
+ IntPtr[] array2 = new IntPtr[num2];
+ for (int j = 0; j < num2; j++) {
+ array2 [j] = GLib.Marshaller.StringToPtrGStrdup (option_values [j]);
+ }
+ IntPtr zero = IntPtr.Zero;
+ bool flag = gdk_pixbuf_savev_utf8 (pb.Handle, intPtr, intPtr2, array, array2, out zero);
+ bool result = flag;
+ GLib.Marshaller.Free (intPtr);
+ GLib.Marshaller.Free (intPtr2);
+ if (zero != IntPtr.Zero) {
+ throw new GLib.GException (zero);
+ }
+ return result;
+ }
+ return pb.Savev(filename, type, option_keys, option_values);
+ }
+ }
+}
@@ -1,49 +1,50 @@
-//
-// JpegFormat.cs
-//
-// Author:
-// Maia Kozheva <sikon@ubuntu.com>
-//
-// Copyright (c) 2010 Maia Kozheva <sikon@ubuntu.com>
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-using System;
-using System.IO;
-
-using Gdk;
-
-namespace Pinta.Core
-{
- public class JpegFormat: GdkPixbufFormat
- {
- public JpegFormat()
- : base ("jpeg")
- {
- }
-
- protected override void DoSave (Pixbuf pb, string fileName, string fileType)
- {
- int level = PintaCore.Actions.File.RaiseModifyCompression (85);
-
- if (level != -1)
- pb.Savev (fileName, fileType, new string[] { "quality", null }, new string[] { level.ToString(), null });
- }
- }
-}
+//
+// JpegFormat.cs
+//
+// Author:
+// Maia Kozheva <sikon@ubuntu.com>
+//
+// Copyright (c) 2010 Maia Kozheva <sikon@ubuntu.com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.IO;
+
+using Gdk;
+
+namespace Pinta.Core
+{
+ public class JpegFormat: GdkPixbufFormat
+ {
+ public JpegFormat()
+ : base ("jpeg")
+ {
+ }
+
+ protected override void DoSave (Pixbuf pb, string fileName, string fileType)
+ {
+ int level = PintaCore.Actions.File.RaiseModifyCompression (85);
+
+ if (level != -1) {
+ pb.SavevUtf8(fileName, fileType, new string[] { "quality", null }, new string[] { level.ToString(), null });
+ }
+ }
+ }
+}

0 comments on commit 7f682a3

Please sign in to comment.