Code

Belarusian translation for 0.47, by Hleb Valoshka
[inkscape.git] / src / color-profile.cpp
index 5a2a1efc9d57086a6e71161bb58fe3617784f6d3..5868a958294f23234d2c1b9ecfedd066fd93a5f8 100644 (file)
 
 #include <cstring>
 #include <string>
+// #ifdef WIN32
+// #include <windows.h>
+// #include <Icm.h>
+// #endif
 #include "xml/repr.h"
 #include "color-profile.h"
 #include "color-profile-fns.h"
@@ -23,6 +27,7 @@
 #include "dom/uri.h"
 #include "dom/util/digest.h"
 
+
 using Inkscape::ColorProfile;
 using Inkscape::ColorProfileClass;
 
@@ -254,10 +259,10 @@ void ColorProfile::set( SPObject *object, unsigned key, gchar const *value )
                     //# 1.  Get complete URI of document
                     gchar const *docbase = SP_DOCUMENT_URI( doc );
                     if (!docbase)
-                        {
-                        g_warning("null docbase");
+                    {
+                        // Normal for files that have not yet been saved.
                         docbase = "";
-                        }
+                    }
                     //g_message("docbase:%s\n", docbase);
                     org::w3c::dom::URI docUri(docbase);
                     //# 2. Get href of icc file.  we don't care if it's rel or abs
@@ -265,7 +270,7 @@ void ColorProfile::set( SPObject *object, unsigned key, gchar const *value )
                     //# 3.  Resolve the href according the docBase.  This follows
                     //      the w3c specs.  All absolute and relative issues are considered
                     org::w3c::dom::URI cprofUri = docUri.resolve(hrefUri);
-                    gchar* fullname = (gchar *)cprofUri.getNativePath().c_str();
+                    gchar* fullname = g_strdup((gchar *)cprofUri.getNativePath().c_str());
                     cprof->_clearProfile();
                     cprof->profHandle = cmsOpenProfileFromFile( fullname, "r" );
                     if ( cprof->profHandle ) {
@@ -275,7 +280,7 @@ void ColorProfile::set( SPObject *object, unsigned key, gchar const *value )
 #ifdef DEBUG_LCMS
                     DEBUG_MESSAGE( lcmsOne, "cmsOpenProfileFromFile( '%s'...) = %p", fullname, (void*)cprof->profHandle );
 #endif // DEBUG_LCMS
-
+                    g_free(fullname);
 #endif // ENABLE_LCMS
                 }
             }
@@ -561,10 +566,10 @@ Glib::ustring Inkscape::get_path_for_profile(Glib::ustring const& name)
 
     return result;
 }
+#endif // ENABLE_LCMS
 
-#if ENABLE_LCMS
-std::list<gchar *> ColorProfile::getProfileDirs() {
-    std::list<gchar *> sources;
+std::list<Glib::ustring> ColorProfile::getProfileDirs() {
+    std::list<Glib::ustring> sources;
 
     gchar* base = profile_path("XXX");
     {
@@ -578,29 +583,58 @@ std::list<gchar *> ColorProfile::getProfileDirs() {
 
     // first try user's local dir
     sources.push_back( g_build_filename(g_get_user_data_dir(), "color", "icc", NULL) );
-    sources.push_back( g_build_filename(base, ".color", "icc", NULL) ); // OpenICC recommends to deprecate this
+
 
     const gchar* const * dataDirs = g_get_system_data_dirs();
     for ( int i = 0; dataDirs[i]; i++ ) {
-        sources.push_back(g_build_filename(dataDirs[i], "color", "icc", NULL));
+        gchar* path = g_build_filename(dataDirs[i], "color", "icc", NULL);
+        sources.push_back(path);
+        g_free(path);
+    }
+
+    // On OS X:
+    if ( g_file_test("/Library/ColorSync/Profiles", G_FILE_TEST_EXISTS)  && g_file_test("/Library/ColorSync/Profiles", G_FILE_TEST_IS_DIR) ) {
+        sources.push_back("/Library/ColorSync/Profiles");
+
+        gchar* path = g_build_filename(g_get_home_dir(), "Library", "ColorSync", "Profiles", NULL);
+        if ( g_file_test(path, G_FILE_TEST_EXISTS)  && g_file_test(path, G_FILE_TEST_IS_DIR) ) {
+            sources.push_back(path);
+        }
+        g_free(path);
     }
 
+
+// #ifdef WIN32
+//     wchar_t pathBuf[MAX_PATH + 1];
+//     pathBuf[0] = 0;
+//     DWORD pathSize = sizeof(pathBuf);
+//     g_assert(sizeof(wchar_t) == sizeof(gunichar2));
+//     if ( GetColorDirectoryW( NULL, &pathBuf, &pathSize ) ) {
+//         gchar * utf8Path = g_utf16_to_utf8( (gunichar2*)(&pathBuf[0]), -1, NULL, NULL, NULL );
+//         if ( !g_utf8_validate(utf8Path, -1, NULL) ) {
+//             g_warning( "GetColorDirectoryW() resulted in invalid UTF-8" );
+//         } else {
+//             sources.pushback(utf8Path);
+//         }
+//         g_free( utf8Path );
+//     }
+// #endif // WIN32
+
     return sources;
 }
-#endif // ENABLE_LCMS
 
+#if ENABLE_LCMS
 static void findThings() {
-    std::list<gchar *> sources = ColorProfile::getProfileDirs();
+    std::list<Glib::ustring> sources = ColorProfile::getProfileDirs();
 
-    while (!sources.empty()) {
-        gchar *dirname = sources.front();
-        if ( g_file_test( dirname, G_FILE_TEST_EXISTS ) && g_file_test( dirname, G_FILE_TEST_IS_DIR ) ) {
+    for ( std::list<Glib::ustring>::const_iterator it = sources.begin(); it != sources.end(); ++it ) {
+        if ( g_file_test( it->c_str(), G_FILE_TEST_EXISTS ) && g_file_test( it->c_str(), G_FILE_TEST_IS_DIR ) ) {
             GError *err = 0;
-            GDir *dir = g_dir_open(dirname, 0, &err);
+            GDir *dir = g_dir_open(it->c_str(), 0, &err);
 
             if (dir) {
                 for (gchar const *file = g_dir_read_name(dir); file != NULL; file = g_dir_read_name(dir)) {
-                    gchar *filepath = g_build_filename(dirname, file, NULL);
+                    gchar *filepath = g_build_filename(it->c_str(), file, NULL);
 
 
                     if ( g_file_test( filepath, G_FILE_TEST_IS_DIR ) ) {
@@ -654,10 +688,6 @@ static void findThings() {
                 }
             }
         }
-
-        // toss the dirname
-        g_free(dirname);
-        sources.pop_front();
     }
 }
 
@@ -865,9 +895,9 @@ cmsHTRANSFORM Inkscape::colorprofile_get_display_transform()
                 dwFlags |= cmsFLAGS_PRESERVEBLACK;
             }
 #endif // defined(cmsFLAGS_PRESERVEBLACK)
-            transf = cmsCreateProofingTransform( ColorProfile::getSRGBProfile(), TYPE_RGB_8, hprof, TYPE_RGB_8, proofProf, intent, proofIntent, dwFlags );
+            transf = cmsCreateProofingTransform( ColorProfile::getSRGBProfile(), TYPE_RGBA_8, hprof, TYPE_RGBA_8, proofProf, intent, proofIntent, dwFlags );
         } else if ( hprof ) {
-            transf = cmsCreateTransform( ColorProfile::getSRGBProfile(), TYPE_RGB_8, hprof, TYPE_RGB_8, intent, 0 );
+            transf = cmsCreateTransform( ColorProfile::getSRGBProfile(), TYPE_RGBA_8, hprof, TYPE_RGBA_8, intent, 0 );
         }
     }
 
@@ -1025,9 +1055,9 @@ cmsHTRANSFORM Inkscape::colorprofile_get_display_per( Glib::ustring const& id )
                             dwFlags |= cmsFLAGS_PRESERVEBLACK;
                         }
 #endif // defined(cmsFLAGS_PRESERVEBLACK)
-                        item.transf = cmsCreateProofingTransform( ColorProfile::getSRGBProfile(), TYPE_RGB_8, item.hprof, TYPE_RGB_8, proofProf, intent, proofIntent, dwFlags );
+                        item.transf = cmsCreateProofingTransform( ColorProfile::getSRGBProfile(), TYPE_RGBA_8, item.hprof, TYPE_RGBA_8, proofProf, intent, proofIntent, dwFlags );
                     } else if ( item.hprof ) {
-                        item.transf = cmsCreateTransform( ColorProfile::getSRGBProfile(), TYPE_RGB_8, item.hprof, TYPE_RGB_8, intent, 0 );
+                        item.transf = cmsCreateTransform( ColorProfile::getSRGBProfile(), TYPE_RGBA_8, item.hprof, TYPE_RGBA_8, intent, 0 );
                     }
                 }