Code

cleanup: Remove some commented-out code.
[inkscape.git] / src / color-profile.cpp
index 5f4e8324e16189cdb5906bbc9bb69a6cc23ac98a..b9e42ccbdde34a3634e37034d727aa7ed81b240d 100644 (file)
@@ -4,6 +4,7 @@
 #include "color-profile.h"
 #include "color-profile-fns.h"
 #include "attributes.h"
+#include "document.h"
 
 using Inkscape::ColorProfile;
 using Inkscape::ColorProfileClass;
@@ -136,7 +137,19 @@ static void colorprofile_set( SPObject *object, unsigned key, gchar const *value
                     // TODO open filename and URIs properly
                     //FILE* fp = fopen_utf8name( filename, "r" );
                     //LCMSAPI cmsHPROFILE   LCMSEXPORT cmsOpenProfileFromMem(LPVOID MemPtr, DWORD dwSize);
-                    cprof->profHandle = cmsOpenProfileFromFile( value, "r" );
+
+                    if ( !g_path_is_absolute(cprof->href) ) {
+                        // Try to open relative
+                        gchar* docbase = SP_DOCUMENT_BASE( SP_OBJECT_DOCUMENT(object) );
+                       gchar* fullname = g_build_filename( docbase ? docbase : ".", cprof->href, NULL );
+
+                        cprof->profHandle = cmsOpenProfileFromFile( fullname, "r" );
+
+                       g_free (fullname);
+                    } else {
+                        cprof->profHandle = cmsOpenProfileFromFile( cprof->href, "r" );
+                    }
+
 #endif // ENABLE_LCMS
                 }
             }
@@ -207,6 +220,51 @@ static Inkscape::XML::Node* colorprofile_write( SPObject *object, Inkscape::XML:
 }
 
 
+#if ENABLE_LCMS
+
+
+static SPObject* bruteFind( SPObject* curr, gchar* const name )
+{
+    SPObject* result = 0;
+
+    if ( curr ) {
+        if ( IS_COLORPROFILE(curr) ) {
+            ColorProfile* prof = COLORPROFILE(curr);
+            if ( prof ) {
+                if ( prof->name && (strcmp(prof->name, name) == 0) ) {
+                    result = curr;
+                }
+            }
+        } else {
+            if ( curr->hasChildren() ) {
+                SPObject* child = curr->firstChild();
+                while ( child && !result ) {
+                    result = bruteFind( child, name );
+                    if ( !result ) {
+                        child = child->next;
+                    }
+                };
+            }
+        }
+    }
+
+    return result;
+}
+
+cmsHPROFILE Inkscape::colorprofile_get_handle( SPDocument* document, gchar* const name )
+{
+    cmsHPROFILE prof = 0;
+
+    SPObject* root = SP_DOCUMENT_ROOT(document);
+    SPObject* thing = bruteFind( root, name );
+    if ( thing ) {
+        prof = COLORPROFILE(thing)->profHandle;
+    }
+
+    return prof;
+}
+#endif // ENABLE_LCMS
+
 /*
   Local Variables:
   mode:c++