Code

Move around files to remove some vanity directories.
authorKrzysztof Kosiński <tweenk.pl@gmail.com>
Sun, 14 Mar 2010 23:58:16 +0000 (00:58 +0100)
committerKrzysztof Kosiński <tweenk.pl@gmail.com>
Sun, 14 Mar 2010 23:58:16 +0000 (00:58 +0100)
Also remove the obsolete IDL file stub.

65 files changed:
configure.ac
src/Makefile.am
src/Makefile_insert
src/algorithms/CMakeLists.txt [deleted file]
src/algorithms/Makefile_insert [deleted file]
src/algorithms/find-if-before.h [deleted file]
src/algorithms/find-last-if.h [deleted file]
src/algorithms/longest-common-suffix.h [deleted file]
src/algorithms/makefile.in [deleted file]
src/api/CMakeLists.txt [deleted file]
src/api/inkscape.idl [deleted file]
src/graphlayout.cpp [new file with mode: 0644]
src/graphlayout.h [new file with mode: 0644]
src/graphlayout/CMakeLists.txt [deleted file]
src/graphlayout/Makefile_insert [deleted file]
src/graphlayout/graphlayout.cpp [deleted file]
src/graphlayout/graphlayout.h [deleted file]
src/graphlayout/makefile [deleted file]
src/inkjar/CMakeLists.txt [deleted file]
src/inkjar/Makefile_insert [deleted file]
src/inkjar/jar.cpp [deleted file]
src/inkjar/jar.h [deleted file]
src/inkjar/makefile.in [deleted file]
src/inkview.cpp
src/io/Makefile_insert
src/io/inkjar.cpp [new file with mode: 0644]
src/io/inkjar.h [new file with mode: 0644]
src/layer-fns.cpp
src/removeoverlap.cpp [new file with mode: 0644]
src/removeoverlap.h [new file with mode: 0644]
src/removeoverlap/CMakeLists.txt [deleted file]
src/removeoverlap/Makefile_insert [deleted file]
src/removeoverlap/makefile.in [deleted file]
src/removeoverlap/removeoverlap.cpp [deleted file]
src/removeoverlap/removeoverlap.h [deleted file]
src/sp-item.cpp
src/sp-object.cpp
src/traits/CMakeLists.txt [deleted file]
src/traits/Makefile_insert [deleted file]
src/traits/copy.h [deleted file]
src/traits/function.h [deleted file]
src/traits/list-copy.h [deleted file]
src/traits/makefile.in [deleted file]
src/traits/reference.h [deleted file]
src/ui/dialog/align-and-distribute.cpp
src/ui/tool/node.h
src/util/Makefile_insert
src/util/copy.h [new file with mode: 0644]
src/util/filter-list.h
src/util/find-if-before.h [new file with mode: 0644]
src/util/find-last-if.h [new file with mode: 0644]
src/util/fixed_point.h
src/util/forward-pointer-iterator.h
src/util/function.h [new file with mode: 0644]
src/util/list-copy.h [new file with mode: 0644]
src/util/list.h
src/util/longest-common-suffix.h [new file with mode: 0644]
src/util/reference.h [new file with mode: 0644]
src/util/reverse-list.h
src/util/tuple.h
src/widgets/toolbox.cpp
src/xml/Makefile_insert
src/xml/composite-node-observer.cpp
src/xml/node-fns.cpp
src/xml/repr-sorting.cpp

index 00b0e91cb3eab42bc90c4ff887baf9d44cc92449..330e40d7dd32ffb091ef91eae4331644d61de24f 100644 (file)
@@ -960,7 +960,6 @@ AC_CONFIG_FILES([
 Makefile
 src/Makefile
 src/check-header-compile
-src/algorithms/makefile
 src/application/makefile
 src/bind/makefile
 src/debug/makefile
@@ -973,7 +972,6 @@ src/extension/makefile
 src/extension/script/makefile
 src/filters/makefile
 src/helper/makefile
-src/inkjar/makefile
 src/io/makefile
 src/libcroco/makefile
 src/libgdl/makefile
@@ -985,10 +983,8 @@ src/live_effects/makefile
 src/live_effects/parameter/makefile
 src/pedro/makefile
 src/jabber_whiteboard/makefile
-src/removeoverlap/makefile
 src/svg/makefile
 src/trace/makefile
-src/traits/makefile
 src/ui/cache/makefile
 src/ui/dialog/makefile
 src/ui/makefile
index ff5d20f49d1da7b6e526c8ad997a70161942370c..b392ef0d216813459e26e6febaa630bc08c02c09 100644 (file)
@@ -110,7 +110,6 @@ include extension/internal/Makefile_insert
 include extension/script/Makefile_insert
 include filters/Makefile_insert
 include helper/Makefile_insert
-include inkjar/Makefile_insert
 include io/Makefile_insert
 #include pedro/Makefile_insert
 #include jabber_whiteboard/Makefile_insert
@@ -124,14 +123,10 @@ include live_effects/Makefile_insert
 include live_effects/parameter/Makefile_insert
 include libvpsc/Makefile_insert
 include libcola/Makefile_insert
-include removeoverlap/Makefile_insert
-include graphlayout/Makefile_insert
 include svg/Makefile_insert
 include widgets/Makefile_insert
 include debug/Makefile_insert
 include xml/Makefile_insert
-include traits/Makefile_insert
-include algorithms/Makefile_insert
 include ui/Makefile_insert
 include ui/cache/Makefile_insert
 include ui/dialog/Makefile_insert
@@ -159,7 +154,6 @@ EXTRA_DIST =        \
        extension/script/makefile.in    \
        filters/makefile.in \
        helper/makefile.in      \
-       inkjar/makefile.in      \
        io/makefile.in  \
        io/crystalegg.xml       \
        io/doc2html.xsl         \
@@ -173,10 +167,8 @@ EXTRA_DIST =       \
        livarot/makefile.in     \
        live_effects/makefile.in        \
        live_effects/parameter/makefile.in      \
-       removeoverlap/makefile.in       \
        svg/makefile.in         \
        trace/makefile.in       \
-       traits/makefile.in      \
        ui/makefile.in          \
        ui/cache/makefile.in    \
        ui/dialog/makefile.in   \
@@ -193,10 +185,6 @@ EXTRA_DIST =       \
        extension/internal/emf-win32-print.cpp  \
        extension/internal/emf-win32-print.h    \
        helper/sp-marshal.list  \
-       traits/copy.h   \
-       traits/function.h       \
-       traits/list-copy.h      \
-       traits/reference.h \
        show-preview.bmp \
        $(jabber_whiteboard_SOURCES) \
        $(CXXTEST_TEMPLATE)
index 1e5b1fea0e3e62092c5aa402146e9ae182d8e259..89c1b17b0368d6d4e52d8b2bc7497ffd90fe4652 100644 (file)
@@ -67,6 +67,7 @@ ink_common_sources += \
        gradient-chemistry.cpp gradient-chemistry.h                     \
        gradient-context.cpp gradient-context.h                         \
        gradient-drag.cpp gradient-drag.h                               \
+       graphlayout.cpp graphlayout.h                                   \
        guide-snapper.cpp guide-snapper.h                               \
        help.cpp help.h                                                 \
        helper-fns.h                                                    \
@@ -117,6 +118,7 @@ ink_common_sources +=       \
        print.cpp print.h                                               \
        profile-manager.cpp profile-manager.h                           \
        proj_pt.cpp proj_pt.h                                           \
+       removeoverlap.cpp removeoverlap.h                               \
        rdf.cpp rdf.h                                                   \
        rect-context.cpp rect-context.h                                 \
        require-config.h                                                \
diff --git a/src/algorithms/CMakeLists.txt b/src/algorithms/CMakeLists.txt
deleted file mode 100644 (file)
index 0ac17f5..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#SET(algorithms_SRC
-#find-if-before.h
-#find-last-if.h
-#longest-common-suffix.h
-#)
-#ADD_LIBRARY(algorithms STATIC ${algorithms_SRC})
\ No newline at end of file
diff --git a/src/algorithms/Makefile_insert b/src/algorithms/Makefile_insert
deleted file mode 100644 (file)
index dff5b57..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-
-algorithms/all:
-
-algorithms/clean:
-
diff --git a/src/algorithms/find-if-before.h b/src/algorithms/find-if-before.h
deleted file mode 100644 (file)
index 6a0f63b..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Inkscape::Algorithms::find_if_before - finds the position before
- *                                        the first value that satisifes
- *                                        the predicate
- *
- * Authors:
- *   MenTaLguY <mental@rydia.net>
- *
- * Copyright (C) 2005 MenTaLguY
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef SEEN_INKSCAPE_ALGORITHMS_FIND_IF_BEFORE_H
-#define SEEN_INKSCAPE_ALGORITHMS_FIND_IF_BEFORE_H
-
-#include <algorithm>
-
-namespace Inkscape {
-
-namespace Algorithms {
-
-template <typename ForwardIterator, typename UnaryPredicate>
-inline ForwardIterator find_if_before(ForwardIterator start,
-                                      ForwardIterator end,
-                                      UnaryPredicate pred)
-{
-    ForwardIterator before=end;
-    while ( start != end && !pred(*start) ) {
-        before = start;
-        ++start;
-    }
-    return ( start != end ) ? before : end;
-}
-
-}
-
-}
-
-#endif
-
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/algorithms/find-last-if.h b/src/algorithms/find-last-if.h
deleted file mode 100644 (file)
index 1ffd63b..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Inkscape::Algorithms::find_last_if
- *
- * Authors:
- *   MenTaLguY <mental@rydia.net>
- *
- * Copyright (C) 2004 MenTaLguY
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef SEEN_INKSCAPE_ALGORITHMS_FIND_LAST_IF_H
-#define SEEN_INKSCAPE_ALGORITHMS_FIND_LAST_IF_H
-
-#include <algorithm>
-
-namespace Inkscape {
-
-namespace Algorithms {
-
-template <typename ForwardIterator, typename UnaryPredicate>
-inline ForwardIterator find_last_if(ForwardIterator start, ForwardIterator end,
-                                    UnaryPredicate pred)
-{
-    ForwardIterator last_found(end);
-    while ( start != end ) {
-        start = std::find_if(start, end, pred);
-        if ( start != end ) {
-            last_found = start;
-            ++start;
-        }
-    }
-    return last_found;
-}
-
-}
-
-}
-
-#endif
-
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/algorithms/longest-common-suffix.h b/src/algorithms/longest-common-suffix.h
deleted file mode 100644 (file)
index 04d2b17..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Inkscape::Algorithms::longest_common_suffix 
- *
- * Authors:
- *   MenTaLguY <mental@rydia.net>
- *
- * Copyright (C) 2004 MenTaLguY
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef SEEN_INKSCAPE_ALGORITHMS_LONGEST_COMMON_SUFFIX_H
-#define SEEN_INKSCAPE_ALGORITHMS_LONGEST_COMMON_SUFFIX_H
-
-#include <iterator>
-#include <functional>
-#include "util/list.h"
-
-namespace Inkscape {
-
-namespace Algorithms {
-
-/**
- * Time costs:
- *
- * The case of sharing a common successor is handled in O(1) time.
- *
- * If \a a is the longest common suffix, then runs in O(len(rest of b)) time.
- *
- * Otherwise, runs in O(len(a) + len(b)) time.
- */
-
-template <typename ForwardIterator>
-ForwardIterator longest_common_suffix(ForwardIterator a, ForwardIterator b,
-                                      ForwardIterator end)
-{
-    typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
-    return longest_common_suffix(a, b, end, std::equal_to<value_type>());
-}
-
-template <typename ForwardIterator, typename BinaryPredicate>
-ForwardIterator longest_common_suffix(ForwardIterator a, ForwardIterator b,
-                                      ForwardIterator end, BinaryPredicate pred)
-{
-    if ( a == end || b == end ) {
-        return end;
-    }
-
-    /* Handle in O(1) time the common cases of identical lists or tails. */
-    {
-        /* identical lists? */
-        if ( a == b ) {
-            return a;
-        }
-
-        /* identical tails? */
-        ForwardIterator tail_a(a);
-        ForwardIterator tail_b(b);
-        if ( ++tail_a == ++tail_b ) {
-            return tail_a;
-        }
-    }
-
-    /* Build parallel lists of suffixes, ordered by increasing length. */
-
-    using Inkscape::Util::List;
-    using Inkscape::Util::cons;
-    ForwardIterator lists[2] = { a, b };
-    List<ForwardIterator> suffixes[2];
-
-    for ( int i=0 ; i < 2 ; i++ ) {
-        for ( ForwardIterator iter(lists[i]) ; iter != end ; ++iter ) {
-            if ( iter == lists[1-i] ) {
-                // the other list is a suffix of this one
-                return lists[1-i];
-            }
-
-            suffixes[i] = cons(iter, suffixes[i]);
-        }
-    }
-
-    /* Iterate in parallel through the lists of suffix lists from shortest to
-     * longest, stopping before the first pair of suffixes that differs
-     */
-
-    ForwardIterator longest_common(end);
-
-    while ( suffixes[0] && suffixes[1] &&
-            pred(**suffixes[0], **suffixes[1]) )
-    {
-        longest_common = *suffixes[0];
-        ++suffixes[0];
-        ++suffixes[1];
-    }
-
-    return longest_common;
-}
-
-}
-
-}
-
-#endif /* !SEEN_INKSCAPE_ALGORITHMS_LONGEST_COMMON_SUFFIX_H */
-
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/algorithms/makefile.in b/src/algorithms/makefile.in
deleted file mode 100644 (file)
index 112aae1..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-# Convenience stub makefile to call the real Makefile.
-
-@SET_MAKE@
-
-OBJEXT = @OBJEXT@
-
-# Explicit so that it's the default rule.
-all:
-       cd .. && $(MAKE) algorithms/all
-
-clean %.a %.$(OBJEXT):
-       cd .. && $(MAKE) algorithms/$@
-
-.PHONY: all clean
-
-.SUFFIXES:
-.SUFFIXES: .a .$(OBJEXT)
diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt
deleted file mode 100644 (file)
index e2e9ff8..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-SET(api_SRC
-#inkscape.idl
-)
diff --git a/src/api/inkscape.idl b/src/api/inkscape.idl
deleted file mode 100644 (file)
index 482184f..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-#ifndef __INKSCAPE_IDL__
-#define __INKSCAPE_IDL__
-/**
- * Inkscape API Description
- *
- * This is a place where people can discuss and modify their ideas
- * of what an Inkscape exported API should look like. 
- * 
- * This IDL file should be considered to be somewhat of a Wish List,
- * and people should feel free to add their ideas to it.   
- *
- * Authors:
- *   Inkscape members
- *
- * Copyright (C) 2007 Inkscape.org
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-
-
-module inkscape
-{
-module api
-{
-
-    /**
-     * This will actually be defined as a Glib::ustring
-     * but people should use the word 'String'
-     */
-    valuetype String sequence<unsigned short>;
-
-    /**
-     * Forward declarations
-     */     
-    interface Env;
-    interface Application;
-    interface Document;
-    interface Desktop;
-    interface DialogManager;
-
-
-
-    exception Exception {
-        unsigned short   code;
-    };
-
-    /**
-     *   ExceptionCodes
-     *   These muse be constants, since languages handle enums
-     *   differently.   
-     */   
-    const unsigned short      INKER                       = 1;
-    const unsigned short      INKERR_NOT_FOUND            = 2;
-    const unsigned short      INKERR_NOT_SUPPORTED        = 3;
-
-
-
-    /**
-     * This is the top-level root of all Inkscape interfaces.
-     * It is the single point of contact from which all other
-     * interfaces can be accessed.  Anything top-level or
-     * global should be parented here.
-     * 
-     * This allows an entire set of interfaces to be exported
-     * to a shared object with only a single symbol.  This symbol
-     * can be accessed something like:
-     *
-     *  typedef (Env *)(EnvCreateFunc)();     
-     *  EnvCreateFunc createEnvironment =
-     *              (EnvCreateFunc) dlsym("createEnvironment");
-     *  Env *ink = createEnvironment();
-     *       
-     *  
-     *  This allows shared object linking to be much easier, and
-     *  allows binding to other languages to be performed however
-     *  is best for each.                    
-     *
-     */
-    interface Env {
-
-        /**
-         *  This is the main application, which
-         */         
-        Application *getApplication();
-
-    };
-    
-    /**
-     *
-     * Top-level Inkscape application
-     *
-     */
-    interface Application {
-
-        /**
-         *  Return the currently-focused desktop
-         */         
-        Desktop *getActiveDesktop();
-
-        /**
-         *  Return the document in the currently-focused desktop
-         */         
-        Document *getActiveDocument();
-
-    };
-    
-    /**
-     *    
-     * This is a main editing window, with all of its chrome.
-     *
-     */
-    interface Desktop {
-
-        /**
-         *  Return the dialog manager for this desktop
-         */         
-        DialogManager *getDialogManager();
-
-    };
-    
-    /**
-     * An Inkscape Document, which is SPObject + XML
-     *
-     */
-    interface Document {
-
-
-        /**
-         *  Copy the document's XML into a DOM tree and
-         *  return a pointer to it.         
-         */         
-        org::w3c::dom::Document *getDOM();
-
-        /**
-         *  Set the Document's repr tree to the specified 
-         *  DOM document
-         */         
-        bool setDOM(org::w3c::dom::Document *doc);
-
-    };
-    
-    /**
-     * The interface that controls Inkscape's dialogs
-     *
-     */
-    interface DialogManager {
-
-        /**
-         *
-         */         
-        //some method
-
-    };
-    
-
-
-
-
-}; // module api
-
-}; // module inkscape
-
-
-#endif // __INKSCAPE_IDL__
-
diff --git a/src/graphlayout.cpp b/src/graphlayout.cpp
new file mode 100644 (file)
index 0000000..a89af10
--- /dev/null
@@ -0,0 +1,262 @@
+/** @file
+ * @brief Interface between Inkscape code (SPItem) and graphlayout functions.
+ */
+/*
+ * Authors:
+ *   Tim Dwyer <Tim.Dwyer@infotech.monash.edu.au>
+ *
+ * Copyright (C) 2005 Authors
+ *
+ * Released under GNU GPL.  Read the file 'COPYING' for more information.
+ */
+
+#include <iostream>
+#include <config.h>
+#include <map>
+#include <vector>
+#include <algorithm>
+#include <cstring>
+#include <cstdlib>
+#include <float.h>
+
+#include "desktop.h"
+#include "inkscape.h"
+#include "sp-namedview.h"
+#include "util/glib-list-iterators.h"
+#include "graphlayout.h"
+#include "sp-path.h"
+#include "sp-item.h"
+#include "sp-item-transform.h"
+#include "sp-conn-end-pair.h"
+#include "style.h"
+#include "conn-avoid-ref.h"
+#include "libavoid/connector.h"
+#include "libavoid/router.h"
+#include "libavoid/geomtypes.h"
+#include "libcola/cola.h"
+#include "libvpsc/generate-constraints.h"
+#include "preferences.h"
+
+using namespace std;
+using namespace cola;
+using namespace vpsc;
+/**
+ * Returns true if item is a connector
+ */
+bool isConnector(SPItem const *const i) {
+    SPPath *path = NULL;
+    if(SP_IS_PATH(i)) {
+        path = SP_PATH(i);
+    }
+    return path && path->connEndPair.isAutoRoutingConn();
+}
+
+struct CheckProgress : TestConvergence {
+    CheckProgress(double d,unsigned i,list<SPItem *>&
+                  selected,vector<Rectangle*>& rs,map<string,unsigned>& nodelookup) :
+        TestConvergence(d,i), selected(selected), rs(rs), nodelookup(nodelookup) {}
+    bool operator()(double new_stress, double* X, double* Y) {
+        /* This is where, if we wanted to animate the layout, we would need to update
+         * the positions of all objects and redraw the canvas and maybe sleep a bit
+         cout << "stress="<<new_stress<<endl;
+        cout << "x[0]="<<rs[0]->getMinX()<<endl;
+        for (list<SPItem *>::iterator it(selected.begin());
+            it != selected.end();
+            ++it)
+        {
+            SPItem *u=*it;
+            if(!isConnector(u)) {
+                Rectangle* r=rs[nodelookup[u->id]];
+                Geom::Rect const item_box(sp_item_bbox_desktop(u));
+                Geom::Point const curr(item_box.midpoint());
+                Geom::Point const dest(r->getCentreX(),r->getCentreY());
+                sp_item_move_rel(u, Geom::Translate(dest - curr));
+            }
+        }
+        */
+        return TestConvergence::operator()(new_stress,X,Y);
+    }
+    list<SPItem *>& selected;
+    vector<Rectangle*>& rs;
+    map<string,unsigned>& nodelookup;
+};
+
+/**
+ * Scans the items list and places those items that are
+ * not connectors in filtered
+ */
+void filterConnectors(GSList const *const items, list<SPItem *> &filtered) {
+    for(GSList *i=(GSList *)items; i!=NULL; i=i->next) {
+        SPItem *item=SP_ITEM(i->data);
+        if(!isConnector(item)) {
+            filtered.push_back(item);
+        }
+    }
+}
+/**
+* Takes a list of inkscape items, extracts the graph defined by
+* connectors between them, and uses graph layout techniques to find
+* a nice layout
+*/
+void graphlayout(GSList const *const items) {
+    if(!items) {
+        return;
+    }
+
+    using Inkscape::Util::GSListConstIterator;
+    list<SPItem *> selected;
+    filterConnectors(items,selected);
+    if (selected.empty()) return;
+
+    const unsigned n=selected.size();
+    //Check 2 or more selected objects
+    if (n < 2) return;
+
+    // add the connector spacing to the size of node bounding boxes
+    // so that connectors can always be routed between shapes
+    SPDesktop* desktop = inkscape_active_desktop();
+    double spacing = 0;
+    if(desktop) spacing = desktop->namedview->connector_spacing+0.1;
+
+    map<string,unsigned> nodelookup;
+    vector<Rectangle*> rs;
+    vector<Edge> es;
+    for (list<SPItem *>::iterator i(selected.begin());
+         i != selected.end();
+         ++i)
+    {
+        SPItem *u=*i;
+        Geom::OptRect const item_box(sp_item_bbox_desktop(u));
+        if(item_box) {
+            Geom::Point ll(item_box->min());
+            Geom::Point ur(item_box->max());
+            nodelookup[u->getId()]=rs.size();
+            rs.push_back(new Rectangle(ll[0]-spacing,ur[0]+spacing,
+                        ll[1]-spacing,ur[1]+spacing));
+        } else {
+            // I'm not actually sure if it's possible for something with a
+            // NULL item-box to be attached to a connector in which case we
+            // should never get to here... but if such a null box can occur it's
+            // probably pretty safe to simply ignore
+            //fprintf(stderr,"NULL item_box found in graphlayout, ignoring!\n");
+        }
+    }
+
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    SimpleConstraints scx,scy;
+    double ideal_connector_length = prefs->getDouble("/tools/connector/length", 100.0);
+    double directed_edge_height_modifier = 1.0;
+
+    bool directed =       prefs->getBool("/tools/connector/directedlayout");
+    bool avoid_overlaps = prefs->getBool("/tools/connector/avoidoverlaplayout");
+
+    for (list<SPItem *>::iterator i(selected.begin());
+         i != selected.end();
+         ++i)
+    {
+        SPItem *iu=*i;
+        map<string,unsigned>::iterator i=nodelookup.find(iu->getId());
+        if(i==nodelookup.end()) {
+            continue;
+        }
+        unsigned u=i->second;
+        GSList *nlist=iu->avoidRef->getAttachedConnectors(Avoid::runningFrom);
+        list<SPItem *> connectors;
+
+        connectors.insert<GSListConstIterator<SPItem *> >(connectors.end(),nlist,NULL);
+        for (list<SPItem *>::iterator j(connectors.begin());
+                j != connectors.end();
+                ++j) {
+            SPItem *conn=*j;
+            SPItem *iv;
+            SPItem *items[2];
+            assert(isConnector(conn));
+            SP_PATH(conn)->connEndPair.getAttachedItems(items);
+            if(items[0]==iu) {
+                iv=items[1];
+            } else {
+                iv=items[0];
+            }
+
+            if (iv == NULL) {
+                // The connector is not attached to anything at the
+                // other end so we should just ignore it.
+                continue;
+            }
+
+            // If iv not in nodelookup we again treat the connector
+            // as disconnected and continue
+            map<string,unsigned>::iterator v_pair=nodelookup.find(iv->getId());
+            if(v_pair!=nodelookup.end()) {
+                unsigned v=v_pair->second;
+                //cout << "Edge: (" << u <<","<<v<<")"<<endl;
+                es.push_back(make_pair(u,v));
+                if(conn->style->marker[SP_MARKER_LOC_END].set) {
+                    if(directed && strcmp(conn->style->marker[SP_MARKER_LOC_END].value,"none")) {
+                        scy.push_back(new SimpleConstraint(v, u,
+                                    (ideal_connector_length * directed_edge_height_modifier)));
+                    }
+                }
+            }
+        }
+        if(nlist) {
+            g_slist_free(nlist);
+        }
+    }
+    const unsigned E = es.size();
+    double eweights[E];
+    fill(eweights,eweights+E,1);
+    vector<Component*> cs;
+    connectedComponents(rs,es,scx,scy,cs);
+    for(unsigned i=0;i<cs.size();i++) {
+        Component* c=cs[i];
+        if(c->edges.size()<2) continue;
+        CheckProgress test(0.0001,100,selected,rs,nodelookup);
+        ConstrainedMajorizationLayout alg(c->rects,c->edges,eweights,ideal_connector_length,test);
+        alg.setupConstraints(NULL,NULL,avoid_overlaps,
+                NULL,NULL,&c->scx,&c->scy,NULL,NULL);
+        alg.run();
+    }
+    separateComponents(cs);
+
+    for (list<SPItem *>::iterator it(selected.begin());
+         it != selected.end();
+         ++it)
+    {
+        SPItem *u=*it;
+        if(!isConnector(u)) {
+            map<string,unsigned>::iterator i=nodelookup.find(u->getId());
+            if(i!=nodelookup.end()) {
+                Rectangle* r=rs[i->second];
+                Geom::OptRect item_box(sp_item_bbox_desktop(u));
+                if(item_box) {
+                    Geom::Point const curr(item_box->midpoint());
+                    Geom::Point const dest(r->getCentreX(),r->getCentreY());
+                    sp_item_move_rel(u, Geom::Translate(dest - curr));
+                }
+            }
+        }
+    }
+    for(unsigned i=0;i<scx.size();i++) {
+        delete scx[i];
+    }
+    for(unsigned i=0;i<scy.size();i++) {
+        delete scy[i];
+    }
+    for(unsigned i=0;i<rs.size();i++) {
+        delete rs[i];
+    }
+}
+// vim: set cindent
+// vim: ts=4 sw=4 et tw=0 wm=0
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/graphlayout.h b/src/graphlayout.h
new file mode 100644 (file)
index 0000000..40090ef
--- /dev/null
@@ -0,0 +1,21 @@
+/**
+ * \brief graph layout functions
+ *
+ * Authors:
+ *   Tim Dwyer <tgdwyer@gmail.com>
+ *
+ * Copyright (C) 2005 Authors
+ *
+ * Released under GNU GPL.  Read the file 'COPYING' for more information.
+ */
+
+#ifndef SEEN_GRAPHLAYOUT_H
+#define SEEN_GRAPHLAYOUT_H
+
+struct _GSList;
+void graphlayout(_GSList const *const items);
+class SPItem;
+bool isConnector(SPItem const *const item);
+#include <list>
+void filterConnectors(_GSList const *const items, std::list<SPItem *> &filtered);
+#endif // SEEN_GRAPHLAYOUT_H
diff --git a/src/graphlayout/CMakeLists.txt b/src/graphlayout/CMakeLists.txt
deleted file mode 100644 (file)
index c8847a2..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-SET(graphlayout_SRC
-graphlayout.cpp
-)
-ADD_LIBRARY(graphlayout STATIC ${graphlayout_SRC})
-TARGET_LINK_LIBRARIES(graphlayout
-2geom ${INKSCAPE_LIBS})
\ No newline at end of file
diff --git a/src/graphlayout/Makefile_insert b/src/graphlayout/Makefile_insert
deleted file mode 100644 (file)
index 790c951..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-## Makefile.am fragment sourced by src/Makefile.am.
-
-ink_common_sources +=  \
-       graphlayout/graphlayout.cpp     \
-       graphlayout/graphlayout.h
diff --git a/src/graphlayout/graphlayout.cpp b/src/graphlayout/graphlayout.cpp
deleted file mode 100644 (file)
index 23b0ee1..0000000
+++ /dev/null
@@ -1,262 +0,0 @@
-/** @file
- * @brief Interface between Inkscape code (SPItem) and graphlayout functions.
- */
-/*
- * Authors:
- *   Tim Dwyer <Tim.Dwyer@infotech.monash.edu.au>
- *
- * Copyright (C) 2005 Authors
- *
- * Released under GNU GPL.  Read the file 'COPYING' for more information.
- */
-
-#include <iostream>
-#include <config.h>
-#include <map>
-#include <vector>
-#include <algorithm>
-#include <cstring>
-#include <cstdlib>
-#include <float.h>
-
-#include "desktop.h"
-#include "inkscape.h"
-#include "sp-namedview.h"
-#include "util/glib-list-iterators.h"
-#include "graphlayout/graphlayout.h"
-#include "sp-path.h"
-#include "sp-item.h"
-#include "sp-item-transform.h"
-#include "sp-conn-end-pair.h"
-#include "style.h"
-#include "conn-avoid-ref.h"
-#include "libavoid/connector.h"
-#include "libavoid/router.h"
-#include "libavoid/geomtypes.h"
-#include "libcola/cola.h"
-#include "libvpsc/generate-constraints.h"
-#include "preferences.h"
-
-using namespace std;
-using namespace cola;
-using namespace vpsc;
-/**
- * Returns true if item is a connector
- */
-bool isConnector(SPItem const *const i) {
-    SPPath *path = NULL;
-    if(SP_IS_PATH(i)) {
-        path = SP_PATH(i);
-    }
-    return path && path->connEndPair.isAutoRoutingConn();
-}
-
-struct CheckProgress : TestConvergence {
-    CheckProgress(double d,unsigned i,list<SPItem *>&
-                  selected,vector<Rectangle*>& rs,map<string,unsigned>& nodelookup) :
-        TestConvergence(d,i), selected(selected), rs(rs), nodelookup(nodelookup) {}
-    bool operator()(double new_stress, double* X, double* Y) {
-        /* This is where, if we wanted to animate the layout, we would need to update
-         * the positions of all objects and redraw the canvas and maybe sleep a bit
-         cout << "stress="<<new_stress<<endl;
-        cout << "x[0]="<<rs[0]->getMinX()<<endl;
-        for (list<SPItem *>::iterator it(selected.begin());
-            it != selected.end();
-            ++it)
-        {
-            SPItem *u=*it;
-            if(!isConnector(u)) {
-                Rectangle* r=rs[nodelookup[u->id]];
-                Geom::Rect const item_box(sp_item_bbox_desktop(u));
-                Geom::Point const curr(item_box.midpoint());
-                Geom::Point const dest(r->getCentreX(),r->getCentreY());
-                sp_item_move_rel(u, Geom::Translate(dest - curr));
-            }
-        }
-        */
-        return TestConvergence::operator()(new_stress,X,Y);
-    }
-    list<SPItem *>& selected;
-    vector<Rectangle*>& rs;
-    map<string,unsigned>& nodelookup;
-};
-
-/**
- * Scans the items list and places those items that are
- * not connectors in filtered
- */
-void filterConnectors(GSList const *const items, list<SPItem *> &filtered) {
-    for(GSList *i=(GSList *)items; i!=NULL; i=i->next) {
-        SPItem *item=SP_ITEM(i->data);
-        if(!isConnector(item)) {
-            filtered.push_back(item);
-        }
-    }
-}
-/**
-* Takes a list of inkscape items, extracts the graph defined by
-* connectors between them, and uses graph layout techniques to find
-* a nice layout
-*/
-void graphlayout(GSList const *const items) {
-    if(!items) {
-        return;
-    }
-
-    using Inkscape::Util::GSListConstIterator;
-    list<SPItem *> selected;
-    filterConnectors(items,selected);
-    if (selected.empty()) return;
-
-    const unsigned n=selected.size();
-    //Check 2 or more selected objects
-    if (n < 2) return;
-
-    // add the connector spacing to the size of node bounding boxes
-    // so that connectors can always be routed between shapes
-    SPDesktop* desktop = inkscape_active_desktop();
-    double spacing = 0;
-    if(desktop) spacing = desktop->namedview->connector_spacing+0.1;
-
-    map<string,unsigned> nodelookup;
-    vector<Rectangle*> rs;
-    vector<Edge> es;
-    for (list<SPItem *>::iterator i(selected.begin());
-         i != selected.end();
-         ++i)
-    {
-        SPItem *u=*i;
-        Geom::OptRect const item_box(sp_item_bbox_desktop(u));
-        if(item_box) {
-            Geom::Point ll(item_box->min());
-            Geom::Point ur(item_box->max());
-            nodelookup[u->getId()]=rs.size();
-            rs.push_back(new Rectangle(ll[0]-spacing,ur[0]+spacing,
-                        ll[1]-spacing,ur[1]+spacing));
-        } else {
-            // I'm not actually sure if it's possible for something with a
-            // NULL item-box to be attached to a connector in which case we
-            // should never get to here... but if such a null box can occur it's
-            // probably pretty safe to simply ignore
-            //fprintf(stderr,"NULL item_box found in graphlayout, ignoring!\n");
-        }
-    }
-
-    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-    SimpleConstraints scx,scy;
-    double ideal_connector_length = prefs->getDouble("/tools/connector/length", 100.0);
-    double directed_edge_height_modifier = 1.0;
-
-    bool directed =       prefs->getBool("/tools/connector/directedlayout");
-    bool avoid_overlaps = prefs->getBool("/tools/connector/avoidoverlaplayout");
-
-    for (list<SPItem *>::iterator i(selected.begin());
-         i != selected.end();
-         ++i)
-    {
-        SPItem *iu=*i;
-        map<string,unsigned>::iterator i=nodelookup.find(iu->getId());
-        if(i==nodelookup.end()) {
-            continue;
-        }
-        unsigned u=i->second;
-        GSList *nlist=iu->avoidRef->getAttachedConnectors(Avoid::runningFrom);
-        list<SPItem *> connectors;
-
-        connectors.insert<GSListConstIterator<SPItem *> >(connectors.end(),nlist,NULL);
-        for (list<SPItem *>::iterator j(connectors.begin());
-                j != connectors.end();
-                ++j) {
-            SPItem *conn=*j;
-            SPItem *iv;
-            SPItem *items[2];
-            assert(isConnector(conn));
-            SP_PATH(conn)->connEndPair.getAttachedItems(items);
-            if(items[0]==iu) {
-                iv=items[1];
-            } else {
-                iv=items[0];
-            }
-
-            if (iv == NULL) {
-                // The connector is not attached to anything at the
-                // other end so we should just ignore it.
-                continue;
-            }
-
-            // If iv not in nodelookup we again treat the connector
-            // as disconnected and continue
-            map<string,unsigned>::iterator v_pair=nodelookup.find(iv->getId());
-            if(v_pair!=nodelookup.end()) {
-                unsigned v=v_pair->second;
-                //cout << "Edge: (" << u <<","<<v<<")"<<endl;
-                es.push_back(make_pair(u,v));
-                if(conn->style->marker[SP_MARKER_LOC_END].set) {
-                    if(directed && strcmp(conn->style->marker[SP_MARKER_LOC_END].value,"none")) {
-                        scy.push_back(new SimpleConstraint(v, u,
-                                    (ideal_connector_length * directed_edge_height_modifier)));
-                    }
-                }
-            }
-        }
-        if(nlist) {
-            g_slist_free(nlist);
-        }
-    }
-    const unsigned E = es.size();
-    double eweights[E];
-    fill(eweights,eweights+E,1);
-    vector<Component*> cs;
-    connectedComponents(rs,es,scx,scy,cs);
-    for(unsigned i=0;i<cs.size();i++) {
-        Component* c=cs[i];
-        if(c->edges.size()<2) continue;
-        CheckProgress test(0.0001,100,selected,rs,nodelookup);
-        ConstrainedMajorizationLayout alg(c->rects,c->edges,eweights,ideal_connector_length,test);
-        alg.setupConstraints(NULL,NULL,avoid_overlaps,
-                NULL,NULL,&c->scx,&c->scy,NULL,NULL);
-        alg.run();
-    }
-    separateComponents(cs);
-
-    for (list<SPItem *>::iterator it(selected.begin());
-         it != selected.end();
-         ++it)
-    {
-        SPItem *u=*it;
-        if(!isConnector(u)) {
-            map<string,unsigned>::iterator i=nodelookup.find(u->getId());
-            if(i!=nodelookup.end()) {
-                Rectangle* r=rs[i->second];
-                Geom::OptRect item_box(sp_item_bbox_desktop(u));
-                if(item_box) {
-                    Geom::Point const curr(item_box->midpoint());
-                    Geom::Point const dest(r->getCentreX(),r->getCentreY());
-                    sp_item_move_rel(u, Geom::Translate(dest - curr));
-                }
-            }
-        }
-    }
-    for(unsigned i=0;i<scx.size();i++) {
-        delete scx[i];
-    }
-    for(unsigned i=0;i<scy.size();i++) {
-        delete scy[i];
-    }
-    for(unsigned i=0;i<rs.size();i++) {
-        delete rs[i];
-    }
-}
-// vim: set cindent
-// vim: ts=4 sw=4 et tw=0 wm=0
-
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/graphlayout/graphlayout.h b/src/graphlayout/graphlayout.h
deleted file mode 100644 (file)
index 40090ef..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * \brief graph layout functions
- *
- * Authors:
- *   Tim Dwyer <tgdwyer@gmail.com>
- *
- * Copyright (C) 2005 Authors
- *
- * Released under GNU GPL.  Read the file 'COPYING' for more information.
- */
-
-#ifndef SEEN_GRAPHLAYOUT_H
-#define SEEN_GRAPHLAYOUT_H
-
-struct _GSList;
-void graphlayout(_GSList const *const items);
-class SPItem;
-bool isConnector(SPItem const *const item);
-#include <list>
-void filterConnectors(_GSList const *const items, std::list<SPItem *> &filtered);
-#endif // SEEN_GRAPHLAYOUT_H
diff --git a/src/graphlayout/makefile b/src/graphlayout/makefile
deleted file mode 100644 (file)
index 5d8ac90..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-# Convenience stub makefile to call the real Makefile.
-
-
-
-# Explicit so that it's the default rule.
-all:
-       cd .. && $(MAKE) graphlayout/all
-
-clean %.a %.o:
-       cd .. && $(MAKE) graphlayout/$@
-
-.PHONY: all clean
-
-OBJEXT = o
-
-.SUFFIXES:
-.SUFFIXES: .a .$(OBJEXT)
diff --git a/src/inkjar/CMakeLists.txt b/src/inkjar/CMakeLists.txt
deleted file mode 100644 (file)
index 7a1e865..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-SET(inkjar_SRC
-jar.cpp
-)
-ADD_LIBRARY(inkjar STATIC ${inkjar_SRC})
-TARGET_LINK_LIBRARIES(inkjar
-2geom ${INKSCAPE_LIBS})
\ No newline at end of file
diff --git a/src/inkjar/Makefile_insert b/src/inkjar/Makefile_insert
deleted file mode 100644 (file)
index ef4f1fd..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-## Makefile.am fragment sourced by src/Makefile.am.
-
-ink_common_sources +=  \
-       inkjar/jar.cpp  \
-       inkjar/jar.h
diff --git a/src/inkjar/jar.cpp b/src/inkjar/jar.cpp
deleted file mode 100644 (file)
index 6897cb3..0000000
+++ /dev/null
@@ -1,544 +0,0 @@
-/*
- * Copyright (C) 1999, 2000  Bryan Burns
- * Copyright (C) 2004 Johan Ceuppens
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-/*
- * TODO/FIXME: 
- * - configure #ifdefs should be enabled
- * - move to cstdlib instead of stdlib.h etc.
- * - remove exit functions
- * - move to clean C++ code
- * - windowsify
- * - remove a few g_free/g_mallocs
- * - unseekable files
- * - move to LGPL by rewriting macros
- * - crcs for compressed files
- * - put in eof
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-
-//#ifdef STDC_HEADERS
-//#endif
-
-//#ifdef HAVE_UNISTD_H
-//#endif
-
-//#ifdef HAVE_SYS_PARAM_H
-//#else
-//#define MAXPATHLEN 1024
-//#endif
-
-//#ifdef HAVE_DIRENT_H
-//#endif
-
-//#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-//#endif
-
-#include <cstring>
-#include <string>
-#include <cstdlib>
-#include <glib.h>
-#include <zlib.h>
-
-#include "jar.h"
-
-#include <fstream>
-#ifdef WORDS_BIGENDIAN
-
-#define L2BI(l) ((l & 0xff000000) >> 24) | \
-((l & 0x00ff0000) >> 8)  | \
-((l & 0x0000ff00) << 8)  | \
-((l & 0x000000ff) << 24);
-
-#define L2BS(l) ((l & 0xff00) >> 8) | ((l & 0x00ff) << 8);
-
-#endif
-
-namespace Inkjar {
-
-JarFile::JarFile(gchar const*new_filename)
-{
-    _filename = g_strdup(new_filename);
-    _last_filename = NULL;
-    fd = -1;
-}
-
-//fixme: the following should probably just return a const gchar* and not 
-//       use strdup
-gchar *JarFile::get_last_filename() const
-{
-    return (_last_filename != NULL ? g_strdup(_last_filename) : NULL);
-}
-
-JarFile::~JarFile()
-{ 
-    if (_filename != NULL)
-       g_free(_filename); 
-    if (_last_filename != NULL)
-       g_free(_last_filename); 
-}
-
-bool JarFile::init_inflation()
-{
-    memset(&_zs, 0, sizeof(z_stream));
-    
-    _zs.zalloc = Z_NULL;
-    _zs.zfree = Z_NULL;
-    _zs.opaque = Z_NULL;
-    
-    if(inflateInit2(&_zs, -15) != Z_OK) {
-       fprintf(stderr,"error initializing inflation!\n");
-       return false;
-    }
-
-    return true;
-}
-
-bool JarFile::open()
-{
-    if ((fd = ::open(_filename, O_RDONLY)) < 0) {
-       fprintf(stderr, "open failed.\n");
-       return false;
-    }
-    if (!init_inflation())
-       return false;
-
-    return true;
-}
-
-bool JarFile::close()
-{
-    if (fd >= 0 && !::close(fd)) {
-       inflateEnd(&_zs);
-       return true;
-    }
-    return false;
-}
-
-bool JarFile::read_signature()
-{
-    guint8 *bytes = (guint8 *)g_malloc(sizeof(guint8) * 4);
-    if (!read(bytes, 4)) {
-       g_free(bytes);
-       return false;
-    }
-
-    guint32 signature = UNPACK_UB4(bytes, 0);
-    g_free(bytes);
-
-#ifdef DEBUG
-    std::printf("signature is %x\n", signature);
-#endif
-
-    if (signature == 0x08074b50) {
-       //skip data descriptor
-       bytes = (guint8 *)malloc(sizeof(guint8) * 12);
-       if (!read(bytes, 12)) {
-           g_free(bytes);
-           return false;
-       }
-    } else if (signature == 0x02014b50 || signature == 0x04034b50) {
-       return true;
-    } else {
-       return false;
-    }
-    return false;
-}
-
-guint32 JarFile::get_crc(guint8 *bytes, guint16 flags)
-{
-    guint32 crc = 0;
-    //no data descriptor
-    if (!(flags & 0x0008)) {
-       crc = UNPACK_UB4(bytes, LOC_CRC);
-       
-#ifdef DEBUG
-       std::printf("CRC from file is %x\n", crc);
-#endif
-    }
-    
-    return crc;
-}
-
-guint8 *JarFile::read_filename(guint16 filename_length)
-{
-    guint8 *filename = (guint8 *)g_malloc(sizeof(guint8)
-                                         * (filename_length+1));
-    if (!read(filename, filename_length)) {
-       g_free(filename);
-       return NULL;
-    }
-    filename[filename_length] = '\0';
-
-#ifdef DEBUG
-    std::printf("Filename is %s\n", filename);
-#endif
-
-    return filename;
-}
-
-bool JarFile::check_compression_method(guint16 method, guint16 flags)
-{
-    return !(method != 8 && flags & 0x0008);
-}
-
-GByteArray *JarFile::get_next_file_contents()
-{
-    guint8 *bytes;
-    GByteArray *gba = g_byte_array_new();
-
-    read_signature();
-    
-    //get compressed size
-    bytes = (guint8 *)g_malloc(sizeof(guint8) * 30);
-    if (!read(bytes+4, 26)) {
-       g_free(bytes);
-       return NULL;
-    }
-    guint32 compressed_size = UNPACK_UB4(bytes, LOC_CSIZE);
-    guint16 filename_length = UNPACK_UB2(bytes, LOC_FNLEN);
-    guint16 eflen = UNPACK_UB2(bytes, LOC_EFLEN);
-    guint16 flags = UNPACK_UB2(bytes, LOC_EXTRA);
-    guint16 method = UNPACK_UB2(bytes, LOC_COMP);
-
-    if (filename_length == 0) {
-       g_byte_array_free(gba, TRUE);
-       if (_last_filename != NULL)
-           g_free(_last_filename);
-       _last_filename = NULL;
-       return NULL;
-    }
-
-
-#ifdef DEBUG    
-    std::printf("Compressed size is %u\n", compressed_size);
-    std::printf("Filename length is %hu\n", filename_length);
-    std::printf("Extra field length is %hu\n", eflen);
-    std::printf("Flags are %#hx\n", flags);
-    std::printf("Compression method is %#hx\n", method);
-#endif
-    
-    guint32 crc = get_crc(bytes, flags);
-    
-    gchar *filename = (gchar *)read_filename(filename_length);
-    g_free(bytes);
-    
-    if (filename == NULL) 
-       return NULL;
-   
-    if (_last_filename != NULL)
-       g_free(_last_filename);
-    _last_filename = filename;
-
-    //check if this is a directory and skip
-    
-    char *c_ptr;
-    if ((c_ptr = std::strrchr(filename, '/')) != NULL) {
-       if (*(++c_ptr) == '\0') {
-           return NULL;
-       }
-    }
-   
-    if (!check_compression_method(method, flags)) {
-       std::fprintf(stderr, "error in jar file\n");
-       return NULL;
-    }    
-    
-    if (method == 8 || flags & 0x0008) {
-       unsigned int file_length = 0;//uncompressed file length
-       lseek(fd, eflen, SEEK_CUR);
-       guint8 *file_data = get_compressed_file(compressed_size, file_length, 
-                                               crc, flags);
-       if (file_data == NULL) {
-           g_byte_array_free(gba, FALSE);
-           return NULL;
-       }
-       g_byte_array_append(gba, file_data, file_length);
-    } else if (method == 0) {
-       guint8 *file_data = get_uncompressed_file(compressed_size, crc, 
-                                                 eflen, flags); 
-
-       if (file_data == NULL) {
-           g_byte_array_free(gba, TRUE);
-           return NULL;
-       }
-       g_byte_array_append(gba, file_data, compressed_size);
-    } else {
-       lseek(fd, compressed_size+eflen, SEEK_CUR);
-       g_byte_array_free(gba, FALSE);
-       return NULL;
-    }
-        
-    
-    return gba;
-}
-
-guint8 *JarFile::get_uncompressed_file(guint32 compressed_size, guint32 crc, 
-                                      guint16 eflen, guint16 flags)
-{
-    GByteArray *gba = g_byte_array_new();
-    unsigned int out_a = 0;
-    unsigned int in_a = compressed_size;
-    guint8 *bytes;
-    guint32 crc2 = 0;
-    
-    crc2 = crc32(crc2, NULL, 0);
-    
-    bytes = (guint8 *)g_malloc(sizeof(guint8) * RDSZ);
-    while(out_a < compressed_size){
-       unsigned int nbytes = (in_a > RDSZ ? RDSZ : in_a);
-       
-       if (!(nbytes = read(bytes, nbytes))) {
-           g_free(bytes);
-           return NULL;
-       }
-       
-       crc2 = crc32(crc2, (Bytef*)bytes, nbytes);
-           
-       g_byte_array_append (gba, bytes, nbytes);
-       out_a += nbytes;
-       in_a -= nbytes;
-           
-#ifdef DEBUG    
-       std::printf("%d bytes written\n", out_a);
-#endif
-    }
-    lseek(fd, eflen, SEEK_CUR);
-    g_free(bytes);
-
-    if (!check_crc(crc, crc2, flags)) {
-        bytes = gba->data;
-        g_byte_array_free(gba, FALSE);//FALSE argument does not free actual data
-       return NULL;
-    }
-    
-    return bytes;
-}
-
-int JarFile::read(guint8 *buf, int count)
-{
-    int nbytes;
-    if ((nbytes = ::read(fd, buf, count)) != count) {
-       fprintf(stderr, "read error\n");
-       exit(1);
-       return 0;
-    }
-    return nbytes;
-}
-
-/* FIXME: this could probably use ZlibBuffer */
-guint8 *JarFile::get_compressed_file(guint32 compressed_size, 
-                                    unsigned int& file_length,
-                                    guint32 oldcrc, guint16 flags)
-{
-    if (compressed_size == 0)
-       return NULL;
-    
-    guint8 in_buffer[RDSZ];
-    guint8 out_buffer[RDSZ];
-    int nbytes;
-    unsigned int leftover_in = compressed_size;
-    GByteArray *gba = g_byte_array_new();
-    
-    _zs.avail_in = 0;
-    guint32 crc = crc32(0, Z_NULL, 0);
-    
-    do {
-               
-       if (!_zs.avail_in) {
-       
-           if ((nbytes = ::read(fd, in_buffer, 
-                                (leftover_in < RDSZ ? leftover_in : RDSZ))) 
-               < 0) {
-               fprintf(stderr, "jarfile read error");
-           }
-           _zs.avail_in = nbytes;
-           _zs.next_in = in_buffer;
-           crc = crc32(crc, in_buffer, _zs.avail_in);
-           leftover_in -= RDSZ;
-       }
-       _zs.next_out = out_buffer;
-       _zs.avail_out = RDSZ;
-       
-       int ret = inflate(&_zs, Z_NO_FLUSH);
-       if (RDSZ != _zs.avail_out) {
-           unsigned int tmp_len = RDSZ - _zs.avail_out;
-           guint8 *tmp_bytes = (guint8 *)g_malloc(sizeof(guint8) 
-                                                  * tmp_len);
-           memcpy(tmp_bytes, out_buffer, tmp_len);
-           g_byte_array_append(gba, tmp_bytes, tmp_len);
-       }
-       
-       if (ret == Z_STREAM_END) {
-           break;
-       }
-       if (ret != Z_OK)
-           std::printf("decompression error %d\n", ret);
-    } while (_zs.total_in < compressed_size);
-    
-    file_length = _zs.total_out;
-#ifdef DEBUG
-    std::printf("done inflating\n");
-    std::printf("%d bytes left over\n", _zs.avail_in);
-    std::printf("CRC is %x\n", crc);
-#endif
-    
-    guint8 *ret_bytes;
-    if (check_crc(oldcrc, crc, flags) && gba->len > 0)
-       ret_bytes = gba->data;
-    else 
-       ret_bytes = NULL;
-    g_byte_array_free(gba, FALSE);
-
-    inflateReset(&_zs); 
-    return ret_bytes;
-}
-
-bool JarFile::check_crc(guint32 oldcrc, guint32 crc, guint16 flags)
-{
-    //fixme: does not work yet
-       
-    if(flags & 0x0008) {
-       guint8 *bytes = (guint8 *)g_malloc(sizeof(guint8) * 16);
-       if (!read(bytes, 16)) {
-           g_free(bytes);
-           return false;
-       }
-       
-       guint32 signature = UNPACK_UB4(bytes, 0);
-       g_free(bytes);
-       if(signature != 0x08074b50) {
-           fprintf(stderr, "missing data descriptor!\n");
-       }
-       
-       crc = UNPACK_UB4(bytes, 4);
-       
-    }
-    if (oldcrc != crc) {
-#ifdef DEBUG
-       std::fprintf(stderr, "Error! CRCs do not match! Got %x, expected %x\n",
-                    oldcrc, crc);
-#endif
-    }
-    return true;
-}
-
-JarFile::JarFile(JarFile const& rhs)
-{
-    *this = rhs;
-}
-
-JarFile& JarFile::operator=(JarFile const& rhs)
-{
-    if (this == &rhs)
-       return *this;
-
-    _zs = rhs._zs;//fixme
-    if (_filename == NULL)
-       _filename = NULL;
-    else
-       _filename = g_strdup(rhs._filename);
-    if (_last_filename == NULL)
-       _last_filename = NULL;
-    else 
-       _last_filename = g_strdup(rhs._last_filename);
-    fd = rhs.fd;
-    
-    return *this;
-}
-
-
-/////////////////////////
-//      JarFileReader  //
-/////////////////////////
-
-GByteArray *JarFileReader::get_next_file()
-{
-    if (_state == CLOSED) {
-       _jarfile.open();
-       _state = OPEN;
-    }
-    
-    return _jarfile.get_next_file_contents();
-}
-
-JarFileReader& JarFileReader::operator=(JarFileReader const& rhs)
-{
-    if (&rhs == this)
-       return *this;
-
-    _jarfile = rhs._jarfile;
-    _state = rhs._state;
-    
-    return *this;
-}
-
-/*
- * If the filename gets reset, a jarfile object gets generated again,
- * ready to be opened for reading.
- */
-void JarFileReader::set_filename(gchar const *new_filename)
-{
-    _jarfile.close();
-    _jarfile = JarFile(new_filename);
-}
-
-void JarFileReader::set_jarfile(JarFile const& new_jarfile)
-{
-    _jarfile = new_jarfile;
-}
-
-JarFileReader::JarFileReader(JarFileReader const& rhs)
-{
-    *this = rhs;
-}
-
-} // namespace Inkjar
-
-
-#if 0 //testing code
-#include "jar.h"
-/*
- * This program writes all the files from a jarfile to stdout and inflates
- * where needed.
- */
-int main(int argc, char *argv[])
-{
-    gchar *filename;
-    if (argc < 2) {
-       filename = "./ide.jar\0";
-    } else {
-       filename = argv[1];
-    }
-
-    Inkjar::JarFileReader jar_file_reader(filename);
-    
-    for (;;) {
-       GByteArray *gba = jar_file_reader.get_next_file();
-       if (gba == NULL) {
-           char *c_ptr;
-           gchar *last_filename = jar_file_reader.get_last_filename();
-           if (last_filename == NULL)
-               break;
-           if ((c_ptr = std::strrchr(last_filename, '/')) != NULL) {
-               if (*(++c_ptr) == '\0') {
-                   g_free(last_filename);
-                   continue;
-               }
-           }
-       } else if (gba->len > 0)
-           ::write(1, gba->data, gba->len);
-       else
-           break;
-    }
-    return 0;
-}
-#endif
diff --git a/src/inkjar/jar.h b/src/inkjar/jar.h
deleted file mode 100644 (file)
index 0fe088b..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-#ifndef __INKJAR_JAR_H_
-#define __INKJAR_JAR_H_
-/*
- * Copyright (C) 1999  Bryan Burns
- * Copyright (C) 2004 Johan Ceuppens
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#if defined(WIN32) || defined(__WIN32__)
-# include <zlib.h>
-#endif
-
-#ifdef HAVE_ZLIB_H
-# include <zlib.h>
-#endif
-
-#ifdef HAVE_INTTYPES_H
-# include <inttypes.h>
-#else
-# ifdef HAVE_STDINT_H
-#  include <stdint.h>
-# endif
-#endif
-
-#include <glib/garray.h>
-#include <glib/gtypes.h>
-
-namespace Inkjar {
-
-unsigned const RDSZ  = 4096;
-
-//#define DEBUG 1 //uncommment for debug messages
-
-enum JarFileReaderState {CLOSED, OPEN};
-
-//fixme: The following will be removed
-typedef uint8_t ub1;
-typedef uint16_t ub2;
-typedef uint32_t ub4;
-
-#define LOC_EXTRA   6  /* extra bytes */
-#define LOC_COMP    8  /* compression method */
-#define LOC_MODTIME 10 /* last modification time */
-#define LOC_MODDATE 12 /* last modification date */
-#define LOC_CRC     14 /* CRC */
-#define LOC_CSIZE   18 /* compressed size */
-#define LOC_USIZE   22 /* uncompressed size */
-#define LOC_FNLEN   26 /* filename length */
-#define LOC_EFLEN   28 /* extra-field length */
-
-#define CEN_COMP    10 /* compression method */
-#define CEN_MODTIME 12
-#define CEN_MODDATE 14
-#define CEN_CRC     16
-#define CEN_CSIZE   20
-#define CEN_USIZE   24
-#define CEN_FNLEN   28
-#define CEN_EFLEN   30
-#define CEN_COMLEN  32
-#define CEN_OFFSET  42
-
-
-/* macros */
-#define PACK_UB4(d, o, v) d[o] = (ub1)((v) & 0x000000ff); \
-                          d[o + 1] = (ub1)(((v) & 0x0000ff00) >> 8); \
-                          d[o + 2] = (ub1)(((v) & 0x00ff0000) >> 16); \
-                          d[o + 3] = (ub1)(((v) & 0xff000000) >> 24)
-
-#define PACK_UB2(d, o, v) d[o] = (ub1)((v) & 0x00ff); \
-                          d[o + 1] = (ub1)(((v) & 0xff00) >> 8)
-
-#define UNPACK_UB4(s, o) (ub4)s[o] + (((ub4)s[o + 1]) << 8) +\
-                         (((ub4)s[o + 2]) << 16) + (((ub4)s[o + 3]) << 24)
-
-#define UNPACK_UB2(s, o)  (ub2)s[o] + (((ub2)s[o + 1]) << 8)
-
-
-
-/*
- * JarFile:
- * 
- * This is a wrapper class for canonical jarfile functions like reading, 
- * writing, seeking etc. JarFile is a dumb class with no state information.
- *
- * All memory allocations are done with g_malloc.
- */
-
-class JarFile {
-public:
-
-    JarFile() : fd(-1), _filename(NULL), _last_filename(NULL) {}
-    virtual ~JarFile();
-    JarFile(gchar const *new_filename);
-    
-    GByteArray *get_next_file_contents();
-    gchar *get_last_filename() const;
-    bool open();
-    bool close();
-    int read(guint8 *buf, int count);
-
-    JarFile(JarFile const &rhs);
-    JarFile &operator=(JarFile const &rhs);
-
-private:
-
-    int fd;
-    gchar *_filename;
-    z_stream _zs;
-    gchar *_last_filename;
-
-    bool init_inflation();
-    bool read_signature();
-    guint32 get_crc(guint8 *bytes, guint16 flags);
-    guint8 *read_filename(guint16 filename_length);
-    bool check_compression_method(guint16 method, guint16 flags);
-    bool check_crc(guint32 oldcrc, guint32 crc, guint16 flags);
-    guint8 *get_compressed_file(guint32 compressed_size,
-                               unsigned int &file_length,
-                               guint32 oldcrc, guint16 flags);
-    guint8 *get_uncompressed_file(guint32 compressed_szie, guint32 crc, 
-                                 guint16 eflen, guint16 flags);
-}; // class JarFile
-
-
-/*
- * JarFileReader:
- *
- * This provides some smarter functions for operating on a jarfile object
- * It should be able to grep for files or return the contents of a specific 
- * file.
- */
-
-class JarFileReader {
-public:
-    
-    JarFileReader(gchar const *new_filename) 
-       : _state(CLOSED), _jarfile(new_filename) {}
-    JarFileReader() : _state(CLOSED) {}
-    virtual ~JarFileReader() { if (_state == OPEN) _jarfile.close(); }
-    //fixme return types are incorrect
-    GByteArray *get_next_file();//fixme clean up return type
-    void set_filename(gchar const *new_filename);
-    void set_jarfile(JarFile const &new_jarfile);
-    gchar *get_last_filename() const { return _jarfile.get_last_filename(); };
-    JarFileReader(JarFileReader const &rhs);
-    JarFileReader &operator=(JarFileReader const &rhs);
-private:
-    JarFileReaderState _state;    
-    JarFile _jarfile;
-
-}; // class JarFileReader
-
-} // namespace Inkjar
-#endif // header guard
-
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/inkjar/makefile.in b/src/inkjar/makefile.in
deleted file mode 100644 (file)
index 96834aa..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-# Convenience stub makefile to call the real Makefile.
-
-@SET_MAKE@
-
-OBJEXT = @OBJEXT@
-
-# Explicit so that it's the default rule.
-all:
-       cd .. && $(MAKE) inkjar/all
-
-clean %.a %.$(OBJEXT):
-       cd .. && $(MAKE) inkjar/$@
-
-.PHONY: all clean
-
-.SUFFIXES:
-.SUFFIXES: .a .$(OBJEXT)
index 007438b49dab13b91e08027f29a9f90aa2e36a12..c151991dd8f469721d6c6b6bd9176f944bc0fbf0 100644 (file)
@@ -63,7 +63,7 @@
 #include "svg-view-widget.h"
 
 #ifdef WITH_INKJAR
-#include "inkjar/jar.h"
+#include "io/inkjar.h"
 #endif
 
 #include "inkscape-private.h"
index 2696e933454dbfa14df53278cc390b182071341e..bb47b46b8ee3ffd7ffa4db188db1253bf527e4b3 100644 (file)
@@ -7,6 +7,8 @@ ink_common_sources += \
        io/ftos.h \
        io/gzipstream.cpp \
        io/gzipstream.h \
+       io/inkjar.cpp \
+       io/inkjar.h \
        io/inkscapestream.cpp \
        io/inkscapestream.h \
        io/resource.cpp \
diff --git a/src/io/inkjar.cpp b/src/io/inkjar.cpp
new file mode 100644 (file)
index 0000000..c238aba
--- /dev/null
@@ -0,0 +1,544 @@
+/*
+ * Copyright (C) 1999, 2000  Bryan Burns
+ * Copyright (C) 2004 Johan Ceuppens
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+/*
+ * TODO/FIXME: 
+ * - configure #ifdefs should be enabled
+ * - move to cstdlib instead of stdlib.h etc.
+ * - remove exit functions
+ * - move to clean C++ code
+ * - windowsify
+ * - remove a few g_free/g_mallocs
+ * - unseekable files
+ * - move to LGPL by rewriting macros
+ * - crcs for compressed files
+ * - put in eof
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+
+//#ifdef STDC_HEADERS
+//#endif
+
+//#ifdef HAVE_UNISTD_H
+//#endif
+
+//#ifdef HAVE_SYS_PARAM_H
+//#else
+//#define MAXPATHLEN 1024
+//#endif
+
+//#ifdef HAVE_DIRENT_H
+//#endif
+
+//#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+//#endif
+
+#include <cstring>
+#include <string>
+#include <cstdlib>
+#include <glib.h>
+#include <zlib.h>
+
+#include "inkjar.h"
+
+#include <fstream>
+#ifdef WORDS_BIGENDIAN
+
+#define L2BI(l) ((l & 0xff000000) >> 24) | \
+((l & 0x00ff0000) >> 8)  | \
+((l & 0x0000ff00) << 8)  | \
+((l & 0x000000ff) << 24);
+
+#define L2BS(l) ((l & 0xff00) >> 8) | ((l & 0x00ff) << 8);
+
+#endif
+
+namespace Inkjar {
+
+JarFile::JarFile(gchar const*new_filename)
+{
+    _filename = g_strdup(new_filename);
+    _last_filename = NULL;
+    fd = -1;
+}
+
+//fixme: the following should probably just return a const gchar* and not 
+//       use strdup
+gchar *JarFile::get_last_filename() const
+{
+    return (_last_filename != NULL ? g_strdup(_last_filename) : NULL);
+}
+
+JarFile::~JarFile()
+{ 
+    if (_filename != NULL)
+       g_free(_filename); 
+    if (_last_filename != NULL)
+       g_free(_last_filename); 
+}
+
+bool JarFile::init_inflation()
+{
+    memset(&_zs, 0, sizeof(z_stream));
+    
+    _zs.zalloc = Z_NULL;
+    _zs.zfree = Z_NULL;
+    _zs.opaque = Z_NULL;
+    
+    if(inflateInit2(&_zs, -15) != Z_OK) {
+       fprintf(stderr,"error initializing inflation!\n");
+       return false;
+    }
+
+    return true;
+}
+
+bool JarFile::open()
+{
+    if ((fd = ::open(_filename, O_RDONLY)) < 0) {
+       fprintf(stderr, "open failed.\n");
+       return false;
+    }
+    if (!init_inflation())
+       return false;
+
+    return true;
+}
+
+bool JarFile::close()
+{
+    if (fd >= 0 && !::close(fd)) {
+       inflateEnd(&_zs);
+       return true;
+    }
+    return false;
+}
+
+bool JarFile::read_signature()
+{
+    guint8 *bytes = (guint8 *)g_malloc(sizeof(guint8) * 4);
+    if (!read(bytes, 4)) {
+       g_free(bytes);
+       return false;
+    }
+
+    guint32 signature = UNPACK_UB4(bytes, 0);
+    g_free(bytes);
+
+#ifdef DEBUG
+    std::printf("signature is %x\n", signature);
+#endif
+
+    if (signature == 0x08074b50) {
+       //skip data descriptor
+       bytes = (guint8 *)malloc(sizeof(guint8) * 12);
+       if (!read(bytes, 12)) {
+           g_free(bytes);
+           return false;
+       }
+    } else if (signature == 0x02014b50 || signature == 0x04034b50) {
+       return true;
+    } else {
+       return false;
+    }
+    return false;
+}
+
+guint32 JarFile::get_crc(guint8 *bytes, guint16 flags)
+{
+    guint32 crc = 0;
+    //no data descriptor
+    if (!(flags & 0x0008)) {
+       crc = UNPACK_UB4(bytes, LOC_CRC);
+       
+#ifdef DEBUG
+       std::printf("CRC from file is %x\n", crc);
+#endif
+    }
+    
+    return crc;
+}
+
+guint8 *JarFile::read_filename(guint16 filename_length)
+{
+    guint8 *filename = (guint8 *)g_malloc(sizeof(guint8)
+                                         * (filename_length+1));
+    if (!read(filename, filename_length)) {
+       g_free(filename);
+       return NULL;
+    }
+    filename[filename_length] = '\0';
+
+#ifdef DEBUG
+    std::printf("Filename is %s\n", filename);
+#endif
+
+    return filename;
+}
+
+bool JarFile::check_compression_method(guint16 method, guint16 flags)
+{
+    return !(method != 8 && flags & 0x0008);
+}
+
+GByteArray *JarFile::get_next_file_contents()
+{
+    guint8 *bytes;
+    GByteArray *gba = g_byte_array_new();
+
+    read_signature();
+    
+    //get compressed size
+    bytes = (guint8 *)g_malloc(sizeof(guint8) * 30);
+    if (!read(bytes+4, 26)) {
+       g_free(bytes);
+       return NULL;
+    }
+    guint32 compressed_size = UNPACK_UB4(bytes, LOC_CSIZE);
+    guint16 filename_length = UNPACK_UB2(bytes, LOC_FNLEN);
+    guint16 eflen = UNPACK_UB2(bytes, LOC_EFLEN);
+    guint16 flags = UNPACK_UB2(bytes, LOC_EXTRA);
+    guint16 method = UNPACK_UB2(bytes, LOC_COMP);
+
+    if (filename_length == 0) {
+       g_byte_array_free(gba, TRUE);
+       if (_last_filename != NULL)
+           g_free(_last_filename);
+       _last_filename = NULL;
+       return NULL;
+    }
+
+
+#ifdef DEBUG    
+    std::printf("Compressed size is %u\n", compressed_size);
+    std::printf("Filename length is %hu\n", filename_length);
+    std::printf("Extra field length is %hu\n", eflen);
+    std::printf("Flags are %#hx\n", flags);
+    std::printf("Compression method is %#hx\n", method);
+#endif
+    
+    guint32 crc = get_crc(bytes, flags);
+    
+    gchar *filename = (gchar *)read_filename(filename_length);
+    g_free(bytes);
+    
+    if (filename == NULL) 
+       return NULL;
+   
+    if (_last_filename != NULL)
+       g_free(_last_filename);
+    _last_filename = filename;
+
+    //check if this is a directory and skip
+    
+    char *c_ptr;
+    if ((c_ptr = std::strrchr(filename, '/')) != NULL) {
+       if (*(++c_ptr) == '\0') {
+           return NULL;
+       }
+    }
+   
+    if (!check_compression_method(method, flags)) {
+       std::fprintf(stderr, "error in jar file\n");
+       return NULL;
+    }    
+    
+    if (method == 8 || flags & 0x0008) {
+       unsigned int file_length = 0;//uncompressed file length
+       lseek(fd, eflen, SEEK_CUR);
+       guint8 *file_data = get_compressed_file(compressed_size, file_length, 
+                                               crc, flags);
+       if (file_data == NULL) {
+           g_byte_array_free(gba, FALSE);
+           return NULL;
+       }
+       g_byte_array_append(gba, file_data, file_length);
+    } else if (method == 0) {
+       guint8 *file_data = get_uncompressed_file(compressed_size, crc, 
+                                                 eflen, flags); 
+
+       if (file_data == NULL) {
+           g_byte_array_free(gba, TRUE);
+           return NULL;
+       }
+       g_byte_array_append(gba, file_data, compressed_size);
+    } else {
+       lseek(fd, compressed_size+eflen, SEEK_CUR);
+       g_byte_array_free(gba, FALSE);
+       return NULL;
+    }
+        
+    
+    return gba;
+}
+
+guint8 *JarFile::get_uncompressed_file(guint32 compressed_size, guint32 crc, 
+                                      guint16 eflen, guint16 flags)
+{
+    GByteArray *gba = g_byte_array_new();
+    unsigned int out_a = 0;
+    unsigned int in_a = compressed_size;
+    guint8 *bytes;
+    guint32 crc2 = 0;
+    
+    crc2 = crc32(crc2, NULL, 0);
+    
+    bytes = (guint8 *)g_malloc(sizeof(guint8) * RDSZ);
+    while(out_a < compressed_size){
+       unsigned int nbytes = (in_a > RDSZ ? RDSZ : in_a);
+       
+       if (!(nbytes = read(bytes, nbytes))) {
+           g_free(bytes);
+           return NULL;
+       }
+       
+       crc2 = crc32(crc2, (Bytef*)bytes, nbytes);
+           
+       g_byte_array_append (gba, bytes, nbytes);
+       out_a += nbytes;
+       in_a -= nbytes;
+           
+#ifdef DEBUG    
+       std::printf("%d bytes written\n", out_a);
+#endif
+    }
+    lseek(fd, eflen, SEEK_CUR);
+    g_free(bytes);
+
+    if (!check_crc(crc, crc2, flags)) {
+        bytes = gba->data;
+        g_byte_array_free(gba, FALSE);//FALSE argument does not free actual data
+       return NULL;
+    }
+    
+    return bytes;
+}
+
+int JarFile::read(guint8 *buf, int count)
+{
+    int nbytes;
+    if ((nbytes = ::read(fd, buf, count)) != count) {
+       fprintf(stderr, "read error\n");
+       exit(1);
+       return 0;
+    }
+    return nbytes;
+}
+
+/* FIXME: this could probably use ZlibBuffer */
+guint8 *JarFile::get_compressed_file(guint32 compressed_size, 
+                                    unsigned int& file_length,
+                                    guint32 oldcrc, guint16 flags)
+{
+    if (compressed_size == 0)
+       return NULL;
+    
+    guint8 in_buffer[RDSZ];
+    guint8 out_buffer[RDSZ];
+    int nbytes;
+    unsigned int leftover_in = compressed_size;
+    GByteArray *gba = g_byte_array_new();
+    
+    _zs.avail_in = 0;
+    guint32 crc = crc32(0, Z_NULL, 0);
+    
+    do {
+               
+       if (!_zs.avail_in) {
+       
+           if ((nbytes = ::read(fd, in_buffer, 
+                                (leftover_in < RDSZ ? leftover_in : RDSZ))) 
+               < 0) {
+               fprintf(stderr, "jarfile read error");
+           }
+           _zs.avail_in = nbytes;
+           _zs.next_in = in_buffer;
+           crc = crc32(crc, in_buffer, _zs.avail_in);
+           leftover_in -= RDSZ;
+       }
+       _zs.next_out = out_buffer;
+       _zs.avail_out = RDSZ;
+       
+       int ret = inflate(&_zs, Z_NO_FLUSH);
+       if (RDSZ != _zs.avail_out) {
+           unsigned int tmp_len = RDSZ - _zs.avail_out;
+           guint8 *tmp_bytes = (guint8 *)g_malloc(sizeof(guint8) 
+                                                  * tmp_len);
+           memcpy(tmp_bytes, out_buffer, tmp_len);
+           g_byte_array_append(gba, tmp_bytes, tmp_len);
+       }
+       
+       if (ret == Z_STREAM_END) {
+           break;
+       }
+       if (ret != Z_OK)
+           std::printf("decompression error %d\n", ret);
+    } while (_zs.total_in < compressed_size);
+    
+    file_length = _zs.total_out;
+#ifdef DEBUG
+    std::printf("done inflating\n");
+    std::printf("%d bytes left over\n", _zs.avail_in);
+    std::printf("CRC is %x\n", crc);
+#endif
+    
+    guint8 *ret_bytes;
+    if (check_crc(oldcrc, crc, flags) && gba->len > 0)
+       ret_bytes = gba->data;
+    else 
+       ret_bytes = NULL;
+    g_byte_array_free(gba, FALSE);
+
+    inflateReset(&_zs); 
+    return ret_bytes;
+}
+
+bool JarFile::check_crc(guint32 oldcrc, guint32 crc, guint16 flags)
+{
+    //fixme: does not work yet
+       
+    if(flags & 0x0008) {
+       guint8 *bytes = (guint8 *)g_malloc(sizeof(guint8) * 16);
+       if (!read(bytes, 16)) {
+           g_free(bytes);
+           return false;
+       }
+       
+       guint32 signature = UNPACK_UB4(bytes, 0);
+       g_free(bytes);
+       if(signature != 0x08074b50) {
+           fprintf(stderr, "missing data descriptor!\n");
+       }
+       
+       crc = UNPACK_UB4(bytes, 4);
+       
+    }
+    if (oldcrc != crc) {
+#ifdef DEBUG
+       std::fprintf(stderr, "Error! CRCs do not match! Got %x, expected %x\n",
+                    oldcrc, crc);
+#endif
+    }
+    return true;
+}
+
+JarFile::JarFile(JarFile const& rhs)
+{
+    *this = rhs;
+}
+
+JarFile& JarFile::operator=(JarFile const& rhs)
+{
+    if (this == &rhs)
+       return *this;
+
+    _zs = rhs._zs;//fixme
+    if (_filename == NULL)
+       _filename = NULL;
+    else
+       _filename = g_strdup(rhs._filename);
+    if (_last_filename == NULL)
+       _last_filename = NULL;
+    else 
+       _last_filename = g_strdup(rhs._last_filename);
+    fd = rhs.fd;
+    
+    return *this;
+}
+
+
+/////////////////////////
+//      JarFileReader  //
+/////////////////////////
+
+GByteArray *JarFileReader::get_next_file()
+{
+    if (_state == CLOSED) {
+       _jarfile.open();
+       _state = OPEN;
+    }
+    
+    return _jarfile.get_next_file_contents();
+}
+
+JarFileReader& JarFileReader::operator=(JarFileReader const& rhs)
+{
+    if (&rhs == this)
+       return *this;
+
+    _jarfile = rhs._jarfile;
+    _state = rhs._state;
+    
+    return *this;
+}
+
+/*
+ * If the filename gets reset, a jarfile object gets generated again,
+ * ready to be opened for reading.
+ */
+void JarFileReader::set_filename(gchar const *new_filename)
+{
+    _jarfile.close();
+    _jarfile = JarFile(new_filename);
+}
+
+void JarFileReader::set_jarfile(JarFile const& new_jarfile)
+{
+    _jarfile = new_jarfile;
+}
+
+JarFileReader::JarFileReader(JarFileReader const& rhs)
+{
+    *this = rhs;
+}
+
+} // namespace Inkjar
+
+
+#if 0 //testing code
+#include "jar.h"
+/*
+ * This program writes all the files from a jarfile to stdout and inflates
+ * where needed.
+ */
+int main(int argc, char *argv[])
+{
+    gchar *filename;
+    if (argc < 2) {
+       filename = "./ide.jar\0";
+    } else {
+       filename = argv[1];
+    }
+
+    Inkjar::JarFileReader jar_file_reader(filename);
+    
+    for (;;) {
+       GByteArray *gba = jar_file_reader.get_next_file();
+       if (gba == NULL) {
+           char *c_ptr;
+           gchar *last_filename = jar_file_reader.get_last_filename();
+           if (last_filename == NULL)
+               break;
+           if ((c_ptr = std::strrchr(last_filename, '/')) != NULL) {
+               if (*(++c_ptr) == '\0') {
+                   g_free(last_filename);
+                   continue;
+               }
+           }
+       } else if (gba->len > 0)
+           ::write(1, gba->data, gba->len);
+       else
+           break;
+    }
+    return 0;
+}
+#endif
diff --git a/src/io/inkjar.h b/src/io/inkjar.h
new file mode 100644 (file)
index 0000000..0fe088b
--- /dev/null
@@ -0,0 +1,169 @@
+#ifndef __INKJAR_JAR_H_
+#define __INKJAR_JAR_H_
+/*
+ * Copyright (C) 1999  Bryan Burns
+ * Copyright (C) 2004 Johan Ceuppens
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#if defined(WIN32) || defined(__WIN32__)
+# include <zlib.h>
+#endif
+
+#ifdef HAVE_ZLIB_H
+# include <zlib.h>
+#endif
+
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#else
+# ifdef HAVE_STDINT_H
+#  include <stdint.h>
+# endif
+#endif
+
+#include <glib/garray.h>
+#include <glib/gtypes.h>
+
+namespace Inkjar {
+
+unsigned const RDSZ  = 4096;
+
+//#define DEBUG 1 //uncommment for debug messages
+
+enum JarFileReaderState {CLOSED, OPEN};
+
+//fixme: The following will be removed
+typedef uint8_t ub1;
+typedef uint16_t ub2;
+typedef uint32_t ub4;
+
+#define LOC_EXTRA   6  /* extra bytes */
+#define LOC_COMP    8  /* compression method */
+#define LOC_MODTIME 10 /* last modification time */
+#define LOC_MODDATE 12 /* last modification date */
+#define LOC_CRC     14 /* CRC */
+#define LOC_CSIZE   18 /* compressed size */
+#define LOC_USIZE   22 /* uncompressed size */
+#define LOC_FNLEN   26 /* filename length */
+#define LOC_EFLEN   28 /* extra-field length */
+
+#define CEN_COMP    10 /* compression method */
+#define CEN_MODTIME 12
+#define CEN_MODDATE 14
+#define CEN_CRC     16
+#define CEN_CSIZE   20
+#define CEN_USIZE   24
+#define CEN_FNLEN   28
+#define CEN_EFLEN   30
+#define CEN_COMLEN  32
+#define CEN_OFFSET  42
+
+
+/* macros */
+#define PACK_UB4(d, o, v) d[o] = (ub1)((v) & 0x000000ff); \
+                          d[o + 1] = (ub1)(((v) & 0x0000ff00) >> 8); \
+                          d[o + 2] = (ub1)(((v) & 0x00ff0000) >> 16); \
+                          d[o + 3] = (ub1)(((v) & 0xff000000) >> 24)
+
+#define PACK_UB2(d, o, v) d[o] = (ub1)((v) & 0x00ff); \
+                          d[o + 1] = (ub1)(((v) & 0xff00) >> 8)
+
+#define UNPACK_UB4(s, o) (ub4)s[o] + (((ub4)s[o + 1]) << 8) +\
+                         (((ub4)s[o + 2]) << 16) + (((ub4)s[o + 3]) << 24)
+
+#define UNPACK_UB2(s, o)  (ub2)s[o] + (((ub2)s[o + 1]) << 8)
+
+
+
+/*
+ * JarFile:
+ * 
+ * This is a wrapper class for canonical jarfile functions like reading, 
+ * writing, seeking etc. JarFile is a dumb class with no state information.
+ *
+ * All memory allocations are done with g_malloc.
+ */
+
+class JarFile {
+public:
+
+    JarFile() : fd(-1), _filename(NULL), _last_filename(NULL) {}
+    virtual ~JarFile();
+    JarFile(gchar const *new_filename);
+    
+    GByteArray *get_next_file_contents();
+    gchar *get_last_filename() const;
+    bool open();
+    bool close();
+    int read(guint8 *buf, int count);
+
+    JarFile(JarFile const &rhs);
+    JarFile &operator=(JarFile const &rhs);
+
+private:
+
+    int fd;
+    gchar *_filename;
+    z_stream _zs;
+    gchar *_last_filename;
+
+    bool init_inflation();
+    bool read_signature();
+    guint32 get_crc(guint8 *bytes, guint16 flags);
+    guint8 *read_filename(guint16 filename_length);
+    bool check_compression_method(guint16 method, guint16 flags);
+    bool check_crc(guint32 oldcrc, guint32 crc, guint16 flags);
+    guint8 *get_compressed_file(guint32 compressed_size,
+                               unsigned int &file_length,
+                               guint32 oldcrc, guint16 flags);
+    guint8 *get_uncompressed_file(guint32 compressed_szie, guint32 crc, 
+                                 guint16 eflen, guint16 flags);
+}; // class JarFile
+
+
+/*
+ * JarFileReader:
+ *
+ * This provides some smarter functions for operating on a jarfile object
+ * It should be able to grep for files or return the contents of a specific 
+ * file.
+ */
+
+class JarFileReader {
+public:
+    
+    JarFileReader(gchar const *new_filename) 
+       : _state(CLOSED), _jarfile(new_filename) {}
+    JarFileReader() : _state(CLOSED) {}
+    virtual ~JarFileReader() { if (_state == OPEN) _jarfile.close(); }
+    //fixme return types are incorrect
+    GByteArray *get_next_file();//fixme clean up return type
+    void set_filename(gchar const *new_filename);
+    void set_jarfile(JarFile const &new_jarfile);
+    gchar *get_last_filename() const { return _jarfile.get_last_filename(); };
+    JarFileReader(JarFileReader const &rhs);
+    JarFileReader &operator=(JarFileReader const &rhs);
+private:
+    JarFileReaderState _state;    
+    JarFile _jarfile;
+
+}; // class JarFileReader
+
+} // namespace Inkjar
+#endif // header guard
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
index 75bb89bcf65f49f1d07d542a94839adc7f98f178..ca7c1c493f5d0dc4939d542df28f39bd332ce87f 100644 (file)
@@ -16,7 +16,7 @@
 #include "document.h"
 #include "sp-item-group.h"
 #include "xml/repr.h"
-#include "algorithms/find-last-if.h"
+#include "util/find-last-if.h"
 #include "layer-fns.h"
 
 namespace Inkscape {
diff --git a/src/removeoverlap.cpp b/src/removeoverlap.cpp
new file mode 100644 (file)
index 0000000..975b4be
--- /dev/null
@@ -0,0 +1,84 @@
+/** \file
+ * Interface between Inkscape code (SPItem) and remove-overlaps function.
+ */
+/*
+* Authors:
+*   Tim Dwyer <tgdwyer@gmail.com>
+*
+* Copyright (C) 2005 Authors
+*
+* Released under GNU LGPL.  Read the file 'COPYING' for more information.
+*/
+#include "util/glib-list-iterators.h"
+#include "sp-item.h"
+#include "sp-item-transform.h"
+#include "libvpsc/generate-constraints.h"
+#include "libvpsc/remove_rectangle_overlap.h"
+#include <utility>
+
+using vpsc::Rectangle;
+
+namespace {
+       struct Record {
+               SPItem *item;
+               Geom::Point midpoint;
+               Rectangle *vspc_rect;
+
+               Record() {}
+               Record(SPItem *i, Geom::Point m, Rectangle *r)
+               : item(i), midpoint(m), vspc_rect(r) {}
+       };
+}
+
+/**
+* Takes a list of inkscape items and moves them as little as possible
+* such that rectangular bounding boxes are separated by at least xGap
+* horizontally and yGap vertically
+*/
+void removeoverlap(GSList const *const items, double const xGap, double const yGap) {
+       using Inkscape::Util::GSListConstIterator;
+       std::list<SPItem *> selected;
+       selected.insert<GSListConstIterator<SPItem *> >(selected.end(), items, NULL);
+       std::vector<Record> records;
+       std::vector<Rectangle *> rs;
+
+       Geom::Point const gap(xGap, yGap);
+       for (std::list<SPItem *>::iterator it(selected.begin());
+               it != selected.end();
+               ++it)
+       {
+               using Geom::X; using Geom::Y;
+               Geom::OptRect item_box(sp_item_bbox_desktop(*it));
+               if (item_box) {
+                       Geom::Point min(item_box->min() - .5*gap);
+                       Geom::Point max(item_box->max() + .5*gap);
+                       // A negative gap is allowed, but will lead to problems when the gap is larger than
+                       // the bounding box (in either X or Y direction, or both); min will have become max
+                       // now, which cannot be handled by Rectangle() which is called below. And how will
+                       // removeRectangleOverlap handle such a case?
+                       // That's why we will enforce some boundaries on min and max here:
+                       if (max[X] < min[X]) {
+                               min[X] = max[X] = (min[X] + max[X])/2;
+                       }
+                       if (max[Y] < min[Y]) {
+                               min[Y] = max[Y] = (min[Y] + max[Y])/2;
+                       }
+                       Rectangle *vspc_rect = new Rectangle(min[X], max[X], min[Y], max[Y]);
+                       records.push_back(Record(*it, item_box->midpoint(), vspc_rect));
+                       rs.push_back(vspc_rect);
+               }
+       }
+       if (!rs.empty()) {
+               removeRectangleOverlap(rs.size(), &rs[0], 0.0, 0.0);
+       }
+       for ( std::vector<Record>::iterator it = records.begin();
+             it != records.end();
+             ++it )
+       {
+               Geom::Point const curr = it->midpoint;
+               Geom::Point const dest(it->vspc_rect->getCentreX(),
+                                    it->vspc_rect->getCentreY());
+               sp_item_move_rel(it->item, Geom::Translate(dest - curr));
+               delete it->vspc_rect;
+       }
+}
diff --git a/src/removeoverlap.h b/src/removeoverlap.h
new file mode 100644 (file)
index 0000000..5b16e70
--- /dev/null
@@ -0,0 +1,20 @@
+/** \file
+ * \brief Remove overlaps function
+ */
+/*
+ * Authors:
+ *   Tim Dwyer <tgdwyer@gmail.com>
+ *
+ * Copyright (C) 2005 Authors
+ *
+ * Released under GNU LGPL.  Read the file 'COPYING' for more information.
+ */
+
+#ifndef SEEN_REMOVEOVERLAP_H
+#define SEEN_REMOVEOVERLAP_H
+
+#include <glib/gslist.h>
+
+void removeoverlap(GSList const *items, double xGap, double yGap);
+
+#endif // SEEN_REMOVEOVERLAP_H
diff --git a/src/removeoverlap/CMakeLists.txt b/src/removeoverlap/CMakeLists.txt
deleted file mode 100644 (file)
index 7f71c29..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-SET(removeoverlap_SRC
-removeoverlap.cpp
-)
-ADD_LIBRARY(removeoverlap STATIC ${removeoverlap_SRC})
-TARGET_LINK_LIBRARIES(removeoverlap
-2geom ${INKSCAPE_LIBS})
\ No newline at end of file
diff --git a/src/removeoverlap/Makefile_insert b/src/removeoverlap/Makefile_insert
deleted file mode 100644 (file)
index d5e90ec..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-## Makefile.am fragment sourced by src/Makefile.am.
-
-ink_common_sources +=  \
-       removeoverlap/removeoverlap.cpp \
-       removeoverlap/removeoverlap.h
diff --git a/src/removeoverlap/makefile.in b/src/removeoverlap/makefile.in
deleted file mode 100644 (file)
index 34e31a9..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-# Convenience stub makefile to call the real Makefile.
-
-@SET_MAKE@
-
-OBJEXT = @OBJEXT@
-
-# Explicit so that it's the default rule.
-all:
-       cd .. && $(MAKE) removeoverlap/all
-
-clean %.a %.$(OBJEXT):
-       cd .. && $(MAKE) removeoverlap/$@
-
-.PHONY: all clean
-
-.SUFFIXES:
-.SUFFIXES: .a .$(OBJEXT)
diff --git a/src/removeoverlap/removeoverlap.cpp b/src/removeoverlap/removeoverlap.cpp
deleted file mode 100644 (file)
index 975b4be..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/** \file
- * Interface between Inkscape code (SPItem) and remove-overlaps function.
- */
-/*
-* Authors:
-*   Tim Dwyer <tgdwyer@gmail.com>
-*
-* Copyright (C) 2005 Authors
-*
-* Released under GNU LGPL.  Read the file 'COPYING' for more information.
-*/
-#include "util/glib-list-iterators.h"
-#include "sp-item.h"
-#include "sp-item-transform.h"
-#include "libvpsc/generate-constraints.h"
-#include "libvpsc/remove_rectangle_overlap.h"
-#include <utility>
-
-using vpsc::Rectangle;
-
-namespace {
-       struct Record {
-               SPItem *item;
-               Geom::Point midpoint;
-               Rectangle *vspc_rect;
-
-               Record() {}
-               Record(SPItem *i, Geom::Point m, Rectangle *r)
-               : item(i), midpoint(m), vspc_rect(r) {}
-       };
-}
-
-/**
-* Takes a list of inkscape items and moves them as little as possible
-* such that rectangular bounding boxes are separated by at least xGap
-* horizontally and yGap vertically
-*/
-void removeoverlap(GSList const *const items, double const xGap, double const yGap) {
-       using Inkscape::Util::GSListConstIterator;
-       std::list<SPItem *> selected;
-       selected.insert<GSListConstIterator<SPItem *> >(selected.end(), items, NULL);
-       std::vector<Record> records;
-       std::vector<Rectangle *> rs;
-
-       Geom::Point const gap(xGap, yGap);
-       for (std::list<SPItem *>::iterator it(selected.begin());
-               it != selected.end();
-               ++it)
-       {
-               using Geom::X; using Geom::Y;
-               Geom::OptRect item_box(sp_item_bbox_desktop(*it));
-               if (item_box) {
-                       Geom::Point min(item_box->min() - .5*gap);
-                       Geom::Point max(item_box->max() + .5*gap);
-                       // A negative gap is allowed, but will lead to problems when the gap is larger than
-                       // the bounding box (in either X or Y direction, or both); min will have become max
-                       // now, which cannot be handled by Rectangle() which is called below. And how will
-                       // removeRectangleOverlap handle such a case?
-                       // That's why we will enforce some boundaries on min and max here:
-                       if (max[X] < min[X]) {
-                               min[X] = max[X] = (min[X] + max[X])/2;
-                       }
-                       if (max[Y] < min[Y]) {
-                               min[Y] = max[Y] = (min[Y] + max[Y])/2;
-                       }
-                       Rectangle *vspc_rect = new Rectangle(min[X], max[X], min[Y], max[Y]);
-                       records.push_back(Record(*it, item_box->midpoint(), vspc_rect));
-                       rs.push_back(vspc_rect);
-               }
-       }
-       if (!rs.empty()) {
-               removeRectangleOverlap(rs.size(), &rs[0], 0.0, 0.0);
-       }
-       for ( std::vector<Record>::iterator it = records.begin();
-             it != records.end();
-             ++it )
-       {
-               Geom::Point const curr = it->midpoint;
-               Geom::Point const dest(it->vspc_rect->getCentreX(),
-                                    it->vspc_rect->getCentreY());
-               sp_item_move_rel(it->item, Geom::Translate(dest - curr));
-               delete it->vspc_rect;
-       }
-}
diff --git a/src/removeoverlap/removeoverlap.h b/src/removeoverlap/removeoverlap.h
deleted file mode 100644 (file)
index 5b16e70..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/** \file
- * \brief Remove overlaps function
- */
-/*
- * Authors:
- *   Tim Dwyer <tgdwyer@gmail.com>
- *
- * Copyright (C) 2005 Authors
- *
- * Released under GNU LGPL.  Read the file 'COPYING' for more information.
- */
-
-#ifndef SEEN_REMOVEOVERLAP_H
-#define SEEN_REMOVEOVERLAP_H
-
-#include <glib/gslist.h>
-
-void removeoverlap(GSList const *items, double xGap, double yGap);
-
-#endif // SEEN_REMOVEOVERLAP_H
index c28940fca6af8ee9ba3153ddf2320931763f4ad6..c4411e47d2ed100f83b3a5290e0d62b51320a2f3 100644 (file)
@@ -64,7 +64,7 @@
 #include "libnr/nr-scale-translate-ops.h"
 #include "libnr/nr-translate-scale-ops.h"
 #include "libnr/nr-convert2geom.h"
-#include "algorithms/find-last-if.h"
+#include "util/find-last-if.h"
 #include "util/reverse-list.h"
 #include <2geom/rect.h>
 #include <2geom/matrix.h>
index 5e0f7275837f0b6a4d1a2e62ff18739d8ba35360..420c7b4a6ca2a545aaf5d12f56bf94c828c01954 100644 (file)
@@ -53,8 +53,8 @@
 #include "debug/demangle.h"
 #include "util/share.h"
 #include "util/format.h"
+#include "util/longest-common-suffix.h"
 
-#include "algorithms/longest-common-suffix.h"
 using std::memcpy;
 using std::strchr;
 using std::strcmp;
diff --git a/src/traits/CMakeLists.txt b/src/traits/CMakeLists.txt
deleted file mode 100644 (file)
index 791f9cd..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-SET(traits_SRC
-)
diff --git a/src/traits/Makefile_insert b/src/traits/Makefile_insert
deleted file mode 100644 (file)
index 4290ac2..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-
-traits/all:
-
-traits/clean:
-
diff --git a/src/traits/copy.h b/src/traits/copy.h
deleted file mode 100644 (file)
index 27038ff..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Inkscape::Traits::Copy - traits class to determine types to use when copying
- *
- * Authors:
- *   MenTaLguY <mental@rydia.net>
- *
- * Copyright (C) 2004 MenTaLguY
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef SEEN_INKSCAPE_TRAITS_COPY_H
-#define SEEN_INKSCAPE_TRAITS_COPY_H
-
-namespace Inkscape {
-
-namespace Traits {
-
-template <typename T>
-struct Copy {
-    typedef T Type;
-};
-
-template <typename T>
-struct Copy<T const> {
-    typedef T Type;
-};
-
-template <typename T>
-struct Copy<T &> {
-    typedef T &Type;
-};
-
-}
-
-}
-
-#endif
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/traits/function.h b/src/traits/function.h
deleted file mode 100644 (file)
index d0dd5d8..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Inkscape::Traits::Function - traits class for C++ "functors"
- *
- * Authors:
- *   MenTaLguY <mental@rydia.net>
- *
- * Copyright (C) 2004 MenTaLguY
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef SEEN_INKSCAPE_TRAITS_FUNCTION_H
-#define SEEN_INKSCAPE_TRAITS_FUNCTION_H
-
-namespace Inkscape {
-
-namespace Traits {
-
-template <typename F> struct Function;
-
-template <typename R>
-struct Function<R (*)()> {
-    typedef R Result;
-
-    typedef void Arg0;
-    typedef void Arg1;
-    typedef void Arg2;
-    typedef void Arg3;
-    typedef void Arg4;
-    typedef void Arg5;
-};
-
-template <typename R, typename A0>
-struct Function<R (*)(A0)> {
-    typedef R Result;
-
-    typedef A0 Arg0;
-    typedef void Arg1;
-    typedef void Arg2;
-    typedef void Arg3;
-    typedef void Arg4;
-    typedef void Arg5;
-};
-
-template <typename R, typename A0, typename A1>
-struct Function<R (*)(A0, A1)> {
-    typedef R Result;
-
-    typedef A0 Arg0;
-    typedef A1 Arg1;
-    typedef void Arg2;
-    typedef void Arg3;
-    typedef void Arg4;
-    typedef void Arg5;
-};
-
-template <typename R, typename A0, typename A1, typename A2>
-struct Function<R (*)(A0, A1, A2)> {
-    typedef R Result;
-
-    typedef A0 Arg0;
-    typedef A1 Arg1;
-    typedef A2 Arg2;
-    typedef void Arg3;
-    typedef void Arg4;
-    typedef void Arg5;
-};
-
-template <typename R, typename A0, typename A1, typename A2,
-                      typename A3>
-struct Function<R (*)(A0, A1, A2, A3)> {
-    typedef R Result;
-
-    typedef A0 Arg0;
-    typedef A1 Arg1;
-    typedef A2 Arg2;
-    typedef A3 Arg3;
-    typedef void Arg4;
-    typedef void Arg5;
-};
-
-template <typename R, typename A0, typename A1, typename A2,
-                      typename A3, typename A4>
-struct Function<R (*)(A0, A1, A2, A3, A4)> {
-    typedef R Result;
-
-    typedef A0 Arg0;
-    typedef A1 Arg1;
-    typedef A2 Arg2;
-    typedef A3 Arg3;
-    typedef A4 Arg4;
-    typedef void Arg5;
-};
-
-template <typename R, typename A0, typename A1, typename A2,
-                      typename A3, typename A4, typename A5>
-struct Function<R (*)(A0, A1, A2, A3, A4, A5)> {
-    typedef R Result;
-
-    typedef A0 Arg0;
-    typedef A1 Arg1;
-    typedef A2 Arg2;
-    typedef A3 Arg3;
-    typedef A4 Arg4;
-    typedef A5 Arg5;
-};
-
-}
-
-}
-
-#endif
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/traits/list-copy.h b/src/traits/list-copy.h
deleted file mode 100644 (file)
index 9d99c4f..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Inkscape::Traits::ListCopy - helper traits class for copying lists
- *
- * Authors:
- *   MenTaLguY <mental@rydia.net>
- *
- * Copyright (C) 2004 MenTaLguY
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef SEEN_INKSCAPE_TRAITS_LIST_COPY_H
-#define SEEN_INKSCAPE_TRAITS_LIST_COPY_H
-
-#include <iterator>
-#include "traits/copy.h"
-#include "util/list.h"
-
-namespace Inkscape {
-
-namespace Traits {
-
-template <typename InputIterator>
-struct ListCopy {
-    typedef typename Copy<
-        typename std::iterator_traits<InputIterator>::value_type
-    >::Type ResultValue;
-    typedef typename Util::MutableList<ResultValue> ResultList;
-};
-
-}
-
-}
-
-#endif
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/traits/makefile.in b/src/traits/makefile.in
deleted file mode 100644 (file)
index c0f07d4..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-# Convenience stub makefile to call the real Makefile.
-
-@SET_MAKE@
-
-OBJEXT = @OBJEXT@
-
-# Explicit so that it's the default rule.
-all:
-       cd .. && $(MAKE) traits/all
-
-clean %.a %.$(OBJEXT):
-       cd .. && $(MAKE) traits/$@
-
-.PHONY: all clean
-
-.SUFFIXES:
-.SUFFIXES: .a .$(OBJEXT)
diff --git a/src/traits/reference.h b/src/traits/reference.h
deleted file mode 100644 (file)
index 199ae89..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Inkscape::Traits::Reference - traits class for dealing with reference types
- *
- * Authors:
- *   MenTaLguY <mental@rydia.net>
- *
- * Copyright (C) 2004 MenTaLguY
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef SEEN_INKSCAPE_TRAITS_REFERENCE_H
-#define SEEN_INKSCAPE_TRAITS_REFERENCE_H
-
-namespace Inkscape {
-
-namespace Traits {
-
-template <typename T>
-struct Reference {
-    typedef T const &RValue;
-    typedef T &LValue;
-    typedef T *Pointer;
-    typedef T const *ConstPointer;
-};
-
-template <typename T>
-struct Reference<T &> {
-    typedef T &RValue;
-    typedef T &LValue;
-    typedef T *Pointer;
-    typedef T const *ConstPointer;
-};
-
-}
-
-}
-
-#endif
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
index 8c8d64ec00554f4d181ed0af779ec0081b22d0a5..a75a8d68d9eea638e162784d9407391aa94b4ae2 100644 (file)
 #include "unclump.h"
 #include "document.h"
 #include "enums.h"
-#include "graphlayout/graphlayout.h"
+#include "graphlayout.h"
 #include "inkscape.h"
 #include "macros.h"
 #include "preferences.h"
-#include "removeoverlap/removeoverlap.h"
+#include "removeoverlap.h"
 #include "selection.h"
 #include "sp-flowtext.h"
 #include "sp-item-transform.h"
index e502ddea1b151394a51d014f4c358489a97bb83b..d04b879761faf99adb3d4db7f8093b5311c054c5 100644 (file)
@@ -234,8 +234,16 @@ public:
     /// @see get_pointer()
     N *ptr() const { return static_cast<N*>(_node); }
 
-    self next() const;
-    self prev() const;
+    self next() const {
+        self r(*this);
+        r.advance();
+        return r;
+    }
+    self prev() const {
+        self r(*this);
+        r.retreat();
+        return r;
+    }
     self &advance();
     self &retreat();
 private:
@@ -256,8 +264,6 @@ public:
     typedef Node value_type;
     typedef NodeIterator<value_type> iterator;
     typedef NodeIterator<value_type const> const_iterator;
-    typedef std::reverse_iterator<iterator> reverse_iterator;
-    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
 
     // TODO Lame. Make this private and make SubpathList a factory
     NodeList(SubpathList &_list);
@@ -268,10 +274,6 @@ public:
     iterator end() { return iterator(this); }
     const_iterator begin() const { return const_iterator(ln_next); }
     const_iterator end() const { return const_iterator(this); }
-    reverse_iterator rbegin() { return reverse_iterator(end()); }
-    reverse_iterator rend() { return reverse_iterator(begin()); }
-    const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
-    const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
 
     // size
     bool empty();
@@ -376,18 +378,16 @@ NodeIterator<N>::operator bool() const {
     return _node && static_cast<ListNode*>(_node->ln_list) != _node;
 }
 template <typename N>
-NodeIterator<N> NodeIterator<N>::next() const {
-    NodeIterator<N> ret(*this);
-    ++ret;
-    if (G_UNLIKELY(!ret) && _node->ln_list->closed()) ++ret;
-    return ret;
+NodeIterator<N> &NodeIterator<N>::advance() {
+    ++(*this);
+    if (G_UNLIKELY(!*this) && _node->ln_list->closed()) ++(*this);
+    return *this;
 }
 template <typename N>
-NodeIterator<N> NodeIterator<N>::prev() const {
-    NodeIterator<N> ret(*this);
-    --ret;
-    if (G_UNLIKELY(!ret) && _node->ln_list->closed()) --ret;
-    return ret;
+NodeIterator<N> &NodeIterator<N>::retreat() {
+    --(*this);
+    if (G_UNLIKELY(!*this) && _node->ln_list->closed()) --(*this);
+    return *this;
 }
 
 } // namespace UI
index 1908aea1913f22d8338777f2951323c87e87439f..259fd762e000c107dedbce49d01ee63d88294a8c 100644 (file)
@@ -2,23 +2,30 @@
 
 ink_common_sources += \
        util/compose.hpp        \
-       util/ucompose.hpp       \
+       util/copy.h \
        util/enums.h \
        util/ege-tags.h \
        util/ege-tags.cpp \
        util/filter-list.h \
+       util/find-if-before.h \
+       util/find-last-if.h \
        util/fixed_point.h \
        util/format.h   \
        util/forward-pointer-iterator.h \
+       util/function.h \
        util/glib-list-iterators.h \
        util/list.h \
        util/list-container.h \
+       util/list-copy.h \
+       util/longest-common-suffix.h \
        util/map-list.h \
        util/mathfns.h \
+       util/reference.h \
        util/reverse-list.h \
        util/share.h \
        util/share.cpp \
        util/tuple.h \
+       util/ucompose.hpp \
        util/units.cpp \
        util/units.h \
        util/unordered-containers.h
diff --git a/src/util/copy.h b/src/util/copy.h
new file mode 100644 (file)
index 0000000..27038ff
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Inkscape::Traits::Copy - traits class to determine types to use when copying
+ *
+ * Authors:
+ *   MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2004 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_TRAITS_COPY_H
+#define SEEN_INKSCAPE_TRAITS_COPY_H
+
+namespace Inkscape {
+
+namespace Traits {
+
+template <typename T>
+struct Copy {
+    typedef T Type;
+};
+
+template <typename T>
+struct Copy<T const> {
+    typedef T Type;
+};
+
+template <typename T>
+struct Copy<T &> {
+    typedef T &Type;
+};
+
+}
+
+}
+
+#endif
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
index e00c33b087839d0ee64dcaf4bfba86f36f727077..50aba12fae79a1286ea9afc7df90ae633c85b8ee 100644 (file)
@@ -13,7 +13,7 @@
 #define SEEN_INKSCAPE_UTIL_FILTER_LIST_H
 
 #include "util/list.h"
-#include "traits/list-copy.h"
+#include "util/list-copy.h"
 
 namespace Inkscape {
 
diff --git a/src/util/find-if-before.h b/src/util/find-if-before.h
new file mode 100644 (file)
index 0000000..6a0f63b
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Inkscape::Algorithms::find_if_before - finds the position before
+ *                                        the first value that satisifes
+ *                                        the predicate
+ *
+ * Authors:
+ *   MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2005 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_ALGORITHMS_FIND_IF_BEFORE_H
+#define SEEN_INKSCAPE_ALGORITHMS_FIND_IF_BEFORE_H
+
+#include <algorithm>
+
+namespace Inkscape {
+
+namespace Algorithms {
+
+template <typename ForwardIterator, typename UnaryPredicate>
+inline ForwardIterator find_if_before(ForwardIterator start,
+                                      ForwardIterator end,
+                                      UnaryPredicate pred)
+{
+    ForwardIterator before=end;
+    while ( start != end && !pred(*start) ) {
+        before = start;
+        ++start;
+    }
+    return ( start != end ) ? before : end;
+}
+
+}
+
+}
+
+#endif
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/util/find-last-if.h b/src/util/find-last-if.h
new file mode 100644 (file)
index 0000000..1ffd63b
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Inkscape::Algorithms::find_last_if
+ *
+ * Authors:
+ *   MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2004 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_ALGORITHMS_FIND_LAST_IF_H
+#define SEEN_INKSCAPE_ALGORITHMS_FIND_LAST_IF_H
+
+#include <algorithm>
+
+namespace Inkscape {
+
+namespace Algorithms {
+
+template <typename ForwardIterator, typename UnaryPredicate>
+inline ForwardIterator find_last_if(ForwardIterator start, ForwardIterator end,
+                                    UnaryPredicate pred)
+{
+    ForwardIterator last_found(end);
+    while ( start != end ) {
+        start = std::find_if(start, end, pred);
+        if ( start != end ) {
+            last_found = start;
+            ++start;
+        }
+    }
+    return last_found;
+}
+
+}
+
+}
+
+#endif
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
index 6afec5e3cb1effebc61ab291a0f4a5b27382ca77..05a73dab515cadf2c32c5935d0bbdba3ed375425 100644 (file)
 #ifndef SEEN_INKSCAPE_UTIL_FIXED_POINT_H
 #define SEEN_INKSCAPE_UTIL_FIXED_POINT_H
 
-#include "traits/reference.h"
-#include <math.h>
-#include <algorithm>
-#include <limits>
-
-namespace Inkscape {
-
-namespace Util {
-
-template <typename T, unsigned int precision>
-class FixedPoint {
-public:
-    FixedPoint() {}
-    FixedPoint(const FixedPoint& value) : v(value.v) {}
-    FixedPoint(char value) : v(static_cast<T>(value)<<precision) {}
-    FixedPoint(unsigned char value) : v(static_cast<T>(value)<<precision) {}
-    FixedPoint(short value) : v(static_cast<T>(value)<<precision) {}
-    FixedPoint(unsigned short value) : v(static_cast<T>(value)<<precision) {}
-    FixedPoint(int value) : v(static_cast<T>(value)<<precision) {}
-    FixedPoint(unsigned int value) : v(static_cast<T>(value)<<precision) {}
-    FixedPoint(double value) : v(static_cast<T>(floor(value*(1<<precision)))) {}
-
-    FixedPoint& operator+=(FixedPoint val) { v += val.v; return *this; }
-    FixedPoint& operator-=(FixedPoint val) { v -= val.v; return *this; }
-    FixedPoint& operator*=(FixedPoint val) {
-        const unsigned int half_size = 8*sizeof(T)/2;
-        const T al = v&((1<<half_size)-1), bl = val.v&((1<<half_size)-1);
-        const T ah = v>>half_size, bh = val.v>>half_size;
-        v = static_cast<unsigned int>(al*bl)>>precision;
-        if ( half_size >= precision ) {
-            v += ((al*bh)+(ah*bl)+((ah*bh)<<half_size))<<(half_size-precision);
-        } else {
-            v += ((al*bh)+(ah*bl))>>(precision-half_size);
-            v += (ah*bh)<<(2*half_size-precision);
-        }
-        return *this;
-    }
-
-    FixedPoint& operator*=(char val) { v *= val; return *this; }
-    FixedPoint& operator*=(unsigned char val) { v *= val; return *this; }
-    FixedPoint& operator*=(short val) { v *= val; return *this; }
-    FixedPoint& operator*=(unsigned short val) { v *= val; return *this; }
-    FixedPoint& operator*=(int val) { v *= val; return *this; }
-    FixedPoint& operator*=(unsigned int val) { v *= val; return *this; }
-
-    FixedPoint operator+(FixedPoint val) const { FixedPoint r(*this); return r+=val; }
-    FixedPoint operator-(FixedPoint val) const { FixedPoint r(*this); return r-=val; }
-    FixedPoint operator*(FixedPoint val) const { FixedPoint r(*this); return r*=val; }
-
-    FixedPoint operator*(char val) const { FixedPoint r(*this); return r*=val; }
-    FixedPoint operator*(unsigned char val) const { FixedPoint r(*this); return r*=val; }
-    FixedPoint operator*(short val) const { FixedPoint r(*this); return r*=val; }
-    FixedPoint operator*(unsigned short val) const { FixedPoint r(*this); return r*=val; }
-    FixedPoint operator*(int val) const { FixedPoint r(*this); return r*=val; }
-    FixedPoint operator*(unsigned int val) const { FixedPoint r(*this); return r*=val; }
-
-    float operator*(float val) const { return static_cast<float>(*this)*val; }
-    double operator*(double val) const { return static_cast<double>(*this)*val; }
-
-    operator char() const { return v>>precision; }
-    operator unsigned char() const { return v>>precision; }
-    operator short() const { return v>>precision; }
-    operator unsigned short() const { return v>>precision; }
-    operator int() const { return v>>precision; }
-    operator unsigned int() const { return v>>precision; }
-
-    operator float() const { return ldexpf(v,-precision); }
-    operator double() const { return ldexp(v,-precision); }
-private:
-    T v;
-};
-
-template<typename T, unsigned int precision> FixedPoint<T,precision> operator *(char a, FixedPoint<T,precision> b) { return b*=a; }
-template<typename T, unsigned int precision> FixedPoint<T,precision> operator *(unsigned char a, FixedPoint<T,precision> b) { return b*=a; }
-template<typename T, unsigned int precision> FixedPoint<T,precision> operator *(short a, FixedPoint<T,precision> b) { return b*=a; }
-template<typename T, unsigned int precision> FixedPoint<T,precision> operator *(unsigned short a, FixedPoint<T,precision> b) { return b*=a; }
-template<typename T, unsigned int precision> FixedPoint<T,precision> operator *(int a, FixedPoint<T,precision> b) { return b*=a; }
-template<typename T, unsigned int precision> FixedPoint<T,precision> operator *(unsigned int a, FixedPoint<T,precision> b) { return b*=a; }
-
-template<typename T, unsigned int precision> float operator *(float a, FixedPoint<T,precision> b) { return b*a; }
-template<typename T, unsigned int precision> double operator *(double a, FixedPoint<T,precision> b) { return b*a; }
-
-}
-
-}
-
-#endif
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
-/*
- * Inkscape::Util::FixedPoint - fixed point type
- *
- * Authors:
- *   Jasper van de Gronde <th.v.d.gronde@hccnet.net>
- *
- * Copyright (C) 2006 Jasper van de Gronde
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef SEEN_INKSCAPE_UTIL_FIXED_POINT_H
-#define SEEN_INKSCAPE_UTIL_FIXED_POINT_H
-
-#include "traits/reference.h"
-#include <math.h>
-#include <algorithm>
-#include <limits>
-
-namespace Inkscape {
-
-namespace Util {
-
-template <typename T, unsigned int precision>
-class FixedPoint {
-public:
-    FixedPoint() {}
-    FixedPoint(const FixedPoint& value) : v(value.v) {}
-    FixedPoint(char value) : v(static_cast<T>(value)<<precision) {}
-    FixedPoint(unsigned char value) : v(static_cast<T>(value)<<precision) {}
-    FixedPoint(short value) : v(static_cast<T>(value)<<precision) {}
-    FixedPoint(unsigned short value) : v(static_cast<T>(value)<<precision) {}
-    FixedPoint(int value) : v(static_cast<T>(value)<<precision) {}
-    FixedPoint(unsigned int value) : v(static_cast<T>(value)<<precision) {}
-    FixedPoint(double value) : v(static_cast<T>(floor(value*(1<<precision)))) {}
-
-    FixedPoint& operator+=(FixedPoint val) { v += val.v; return *this; }
-    FixedPoint& operator-=(FixedPoint val) { v -= val.v; return *this; }
-    FixedPoint& operator*=(FixedPoint val) {
-        const unsigned int half_size = 8*sizeof(T)/2;
-        const T al = v&((1<<half_size)-1), bl = val.v&((1<<half_size)-1);
-        const T ah = v>>half_size, bh = val.v>>half_size;
-        v = static_cast<unsigned int>(al*bl)>>precision;
-        if ( half_size >= precision ) {
-            v += ((al*bh)+(ah*bl)+((ah*bh)<<half_size))<<(half_size-precision);
-        } else {
-            v += ((al*bh)+(ah*bl))>>(precision-half_size);
-            v += (ah*bh)<<(2*half_size-precision);
-        }
-        return *this;
-    }
-
-    FixedPoint& operator*=(char val) { v *= val; return *this; }
-    FixedPoint& operator*=(unsigned char val) { v *= val; return *this; }
-    FixedPoint& operator*=(short val) { v *= val; return *this; }
-    FixedPoint& operator*=(unsigned short val) { v *= val; return *this; }
-    FixedPoint& operator*=(int val) { v *= val; return *this; }
-    FixedPoint& operator*=(unsigned int val) { v *= val; return *this; }
-
-    FixedPoint operator+(FixedPoint val) const { FixedPoint r(*this); return r+=val; }
-    FixedPoint operator-(FixedPoint val) const { FixedPoint r(*this); return r-=val; }
-    FixedPoint operator*(FixedPoint val) const { FixedPoint r(*this); return r*=val; }
-
-    FixedPoint operator*(char val) const { FixedPoint r(*this); return r*=val; }
-    FixedPoint operator*(unsigned char val) const { FixedPoint r(*this); return r*=val; }
-    FixedPoint operator*(short val) const { FixedPoint r(*this); return r*=val; }
-    FixedPoint operator*(unsigned short val) const { FixedPoint r(*this); return r*=val; }
-    FixedPoint operator*(int val) const { FixedPoint r(*this); return r*=val; }
-    FixedPoint operator*(unsigned int val) const { FixedPoint r(*this); return r*=val; }
-
-    float operator*(float val) const { return static_cast<float>(*this)*val; }
-    double operator*(double val) const { return static_cast<double>(*this)*val; }
-
-    operator char() const { return v>>precision; }
-    operator unsigned char() const { return v>>precision; }
-    operator short() const { return v>>precision; }
-    operator unsigned short() const { return v>>precision; }
-    operator int() const { return v>>precision; }
-    operator unsigned int() const { return v>>precision; }
-
-    operator float() const { return ldexpf(v,-precision); }
-    operator double() const { return ldexp(v,-precision); }
-private:
-    T v;
-};
-
-template<typename T, unsigned int precision> FixedPoint<T,precision> operator *(char a, FixedPoint<T,precision> b) { return b*=a; }
-template<typename T, unsigned int precision> FixedPoint<T,precision> operator *(unsigned char a, FixedPoint<T,precision> b) { return b*=a; }
-template<typename T, unsigned int precision> FixedPoint<T,precision> operator *(short a, FixedPoint<T,precision> b) { return b*=a; }
-template<typename T, unsigned int precision> FixedPoint<T,precision> operator *(unsigned short a, FixedPoint<T,precision> b) { return b*=a; }
-template<typename T, unsigned int precision> FixedPoint<T,precision> operator *(int a, FixedPoint<T,precision> b) { return b*=a; }
-template<typename T, unsigned int precision> FixedPoint<T,precision> operator *(unsigned int a, FixedPoint<T,precision> b) { return b*=a; }
-
-template<typename T, unsigned int precision> float operator *(float a, FixedPoint<T,precision> b) { return b*a; }
-template<typename T, unsigned int precision> double operator *(double a, FixedPoint<T,precision> b) { return b*a; }
-
-}
-
-}
-
-#endif
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
-/*
- * Inkscape::Util::FixedPoint - fixed point type
- *
- * Authors:
- *   Jasper van de Gronde <th.v.d.gronde@hccnet.net>
- *
- * Copyright (C) 2006 Jasper van de Gronde
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef SEEN_INKSCAPE_UTIL_FIXED_POINT_H
-#define SEEN_INKSCAPE_UTIL_FIXED_POINT_H
-
-#include "traits/reference.h"
+#include "util/reference.h"
 #include <math.h>
 #include <algorithm>
 #include <limits>
index 2c2345c81a43166e64f2d5e02df384849f2f4687..1603fed2727acaef19a09a065184edcedc607e1a 100644 (file)
@@ -15,7 +15,7 @@
 #define SEEN_INKSCAPE_UTIL_FORWARD_POINTER_ITERATOR_H
 
 #include <iterator>
-#include "traits/reference.h"
+#include "util/reference.h"
 
 namespace Inkscape {
 
diff --git a/src/util/function.h b/src/util/function.h
new file mode 100644 (file)
index 0000000..d0dd5d8
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Inkscape::Traits::Function - traits class for C++ "functors"
+ *
+ * Authors:
+ *   MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2004 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_TRAITS_FUNCTION_H
+#define SEEN_INKSCAPE_TRAITS_FUNCTION_H
+
+namespace Inkscape {
+
+namespace Traits {
+
+template <typename F> struct Function;
+
+template <typename R>
+struct Function<R (*)()> {
+    typedef R Result;
+
+    typedef void Arg0;
+    typedef void Arg1;
+    typedef void Arg2;
+    typedef void Arg3;
+    typedef void Arg4;
+    typedef void Arg5;
+};
+
+template <typename R, typename A0>
+struct Function<R (*)(A0)> {
+    typedef R Result;
+
+    typedef A0 Arg0;
+    typedef void Arg1;
+    typedef void Arg2;
+    typedef void Arg3;
+    typedef void Arg4;
+    typedef void Arg5;
+};
+
+template <typename R, typename A0, typename A1>
+struct Function<R (*)(A0, A1)> {
+    typedef R Result;
+
+    typedef A0 Arg0;
+    typedef A1 Arg1;
+    typedef void Arg2;
+    typedef void Arg3;
+    typedef void Arg4;
+    typedef void Arg5;
+};
+
+template <typename R, typename A0, typename A1, typename A2>
+struct Function<R (*)(A0, A1, A2)> {
+    typedef R Result;
+
+    typedef A0 Arg0;
+    typedef A1 Arg1;
+    typedef A2 Arg2;
+    typedef void Arg3;
+    typedef void Arg4;
+    typedef void Arg5;
+};
+
+template <typename R, typename A0, typename A1, typename A2,
+                      typename A3>
+struct Function<R (*)(A0, A1, A2, A3)> {
+    typedef R Result;
+
+    typedef A0 Arg0;
+    typedef A1 Arg1;
+    typedef A2 Arg2;
+    typedef A3 Arg3;
+    typedef void Arg4;
+    typedef void Arg5;
+};
+
+template <typename R, typename A0, typename A1, typename A2,
+                      typename A3, typename A4>
+struct Function<R (*)(A0, A1, A2, A3, A4)> {
+    typedef R Result;
+
+    typedef A0 Arg0;
+    typedef A1 Arg1;
+    typedef A2 Arg2;
+    typedef A3 Arg3;
+    typedef A4 Arg4;
+    typedef void Arg5;
+};
+
+template <typename R, typename A0, typename A1, typename A2,
+                      typename A3, typename A4, typename A5>
+struct Function<R (*)(A0, A1, A2, A3, A4, A5)> {
+    typedef R Result;
+
+    typedef A0 Arg0;
+    typedef A1 Arg1;
+    typedef A2 Arg2;
+    typedef A3 Arg3;
+    typedef A4 Arg4;
+    typedef A5 Arg5;
+};
+
+}
+
+}
+
+#endif
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/util/list-copy.h b/src/util/list-copy.h
new file mode 100644 (file)
index 0000000..811f93b
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Inkscape::Traits::ListCopy - helper traits class for copying lists
+ *
+ * Authors:
+ *   MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2004 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_TRAITS_LIST_COPY_H
+#define SEEN_INKSCAPE_TRAITS_LIST_COPY_H
+
+#include <iterator>
+#include "util/copy.h"
+#include "util/list.h"
+
+namespace Inkscape {
+
+namespace Traits {
+
+template <typename InputIterator>
+struct ListCopy {
+    typedef typename Copy<
+        typename std::iterator_traits<InputIterator>::value_type
+    >::Type ResultValue;
+    typedef typename Util::MutableList<ResultValue> ResultList;
+};
+
+}
+
+}
+
+#endif
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
index 86a73711ab7f30e12b1f2dfb1995e7b2a691d1f1..ebe3a97730f935a78ffb4ae2a5128b3f6c1bc675 100644 (file)
@@ -15,7 +15,7 @@
 #include <cstddef>
 #include <iterator>
 #include "gc-managed.h"
-#include "traits/reference.h"
+#include "util/reference.h"
 
 namespace Inkscape {
 
diff --git a/src/util/longest-common-suffix.h b/src/util/longest-common-suffix.h
new file mode 100644 (file)
index 0000000..04d2b17
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * Inkscape::Algorithms::longest_common_suffix 
+ *
+ * Authors:
+ *   MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2004 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_ALGORITHMS_LONGEST_COMMON_SUFFIX_H
+#define SEEN_INKSCAPE_ALGORITHMS_LONGEST_COMMON_SUFFIX_H
+
+#include <iterator>
+#include <functional>
+#include "util/list.h"
+
+namespace Inkscape {
+
+namespace Algorithms {
+
+/**
+ * Time costs:
+ *
+ * The case of sharing a common successor is handled in O(1) time.
+ *
+ * If \a a is the longest common suffix, then runs in O(len(rest of b)) time.
+ *
+ * Otherwise, runs in O(len(a) + len(b)) time.
+ */
+
+template <typename ForwardIterator>
+ForwardIterator longest_common_suffix(ForwardIterator a, ForwardIterator b,
+                                      ForwardIterator end)
+{
+    typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
+    return longest_common_suffix(a, b, end, std::equal_to<value_type>());
+}
+
+template <typename ForwardIterator, typename BinaryPredicate>
+ForwardIterator longest_common_suffix(ForwardIterator a, ForwardIterator b,
+                                      ForwardIterator end, BinaryPredicate pred)
+{
+    if ( a == end || b == end ) {
+        return end;
+    }
+
+    /* Handle in O(1) time the common cases of identical lists or tails. */
+    {
+        /* identical lists? */
+        if ( a == b ) {
+            return a;
+        }
+
+        /* identical tails? */
+        ForwardIterator tail_a(a);
+        ForwardIterator tail_b(b);
+        if ( ++tail_a == ++tail_b ) {
+            return tail_a;
+        }
+    }
+
+    /* Build parallel lists of suffixes, ordered by increasing length. */
+
+    using Inkscape::Util::List;
+    using Inkscape::Util::cons;
+    ForwardIterator lists[2] = { a, b };
+    List<ForwardIterator> suffixes[2];
+
+    for ( int i=0 ; i < 2 ; i++ ) {
+        for ( ForwardIterator iter(lists[i]) ; iter != end ; ++iter ) {
+            if ( iter == lists[1-i] ) {
+                // the other list is a suffix of this one
+                return lists[1-i];
+            }
+
+            suffixes[i] = cons(iter, suffixes[i]);
+        }
+    }
+
+    /* Iterate in parallel through the lists of suffix lists from shortest to
+     * longest, stopping before the first pair of suffixes that differs
+     */
+
+    ForwardIterator longest_common(end);
+
+    while ( suffixes[0] && suffixes[1] &&
+            pred(**suffixes[0], **suffixes[1]) )
+    {
+        longest_common = *suffixes[0];
+        ++suffixes[0];
+        ++suffixes[1];
+    }
+
+    return longest_common;
+}
+
+}
+
+}
+
+#endif /* !SEEN_INKSCAPE_ALGORITHMS_LONGEST_COMMON_SUFFIX_H */
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/util/reference.h b/src/util/reference.h
new file mode 100644 (file)
index 0000000..199ae89
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Inkscape::Traits::Reference - traits class for dealing with reference types
+ *
+ * Authors:
+ *   MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2004 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_TRAITS_REFERENCE_H
+#define SEEN_INKSCAPE_TRAITS_REFERENCE_H
+
+namespace Inkscape {
+
+namespace Traits {
+
+template <typename T>
+struct Reference {
+    typedef T const &RValue;
+    typedef T &LValue;
+    typedef T *Pointer;
+    typedef T const *ConstPointer;
+};
+
+template <typename T>
+struct Reference<T &> {
+    typedef T &RValue;
+    typedef T &LValue;
+    typedef T *Pointer;
+    typedef T const *ConstPointer;
+};
+
+}
+
+}
+
+#endif
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
index 586f706c7b4f8aee1e4480ba55443a7bc6b88807..798b157012d1848185e59fe7b65a1f7fc101d65b 100644 (file)
@@ -13,7 +13,7 @@
 #define SEEN_INKSCAPE_UTIL_REVERSE_LIST_H
 
 #include "util/list.h"
-#include "traits/list-copy.h"
+#include "util/list-copy.h"
 
 namespace Inkscape {
 
index bf9338366d4f3b5d81bf262e82ff137b5e4287be..42266c8d25f381bd29c44a9415cf0f24616b685e 100644 (file)
@@ -12,7 +12,7 @@
 #ifndef SEEN_INKSCAPE_UTIL_TUPLE_H
 #define SEEN_INKSCAPE_UTIL_TUPLE_H
 
-#include "traits/reference.h"
+#include "util/reference.h"
 
 namespace Inkscape {
 
index b4324ca0d05100cf3282528d37299d0f3fb3d3e7..4b0d84d90a0a5d0b0ef26811ecaea244f93bc089 100644 (file)
@@ -50,7 +50,7 @@
 #include "../ege-select-one-action.h"
 #include "../flood-context.h"
 #include "gradient-toolbar.h"
-#include "../graphlayout/graphlayout.h"
+#include "../graphlayout.h"
 #include "../helper/unit-menu.h"
 #include "../helper/units.h"
 #include "../helper/unit-tracker.h"
index e4269026c8cde39a0e76d10c1af697eb846e4570..7190b7948deba011d0ee69d7930d253cffee974b 100644 (file)
@@ -1,7 +1,6 @@
 ## Makefile.am fragment sourced by src/Makefile.am.
 
 ink_common_sources +=  \
-       algorithms/find-if-before.h     \
        xml/comment-node.h \
        xml/composite-node-observer.cpp xml/composite-node-observer.h \
        xml/element-node.h \
index e6598161624e75ac3feb5127bf3f1342a6aeaa5c..564938dda30f27c57fb7740c9b9702e5e11db3ef 100644 (file)
@@ -15,7 +15,7 @@
 #include <cstring>
 #include <glib.h>
 
-#include "algorithms/find-if-before.h"
+#include "util/find-if-before.h"
 #include "xml/composite-node-observer.h"
 #include "xml/node-event-vector.h"
 #include "debug/event-tracker.h"
index deb88fb5e03421c03fac19932499ed0999793aac..bf860d8f3924dac73e3b57e284c99c86bb1e2072 100644 (file)
@@ -8,7 +8,7 @@
 #include <glib.h> // g_assert()
 
 #include "xml/node-iterators.h"
-#include "algorithms/find-if-before.h"
+#include "util/find-if-before.h"
 
 namespace Inkscape {
 namespace XML {
index 123df33ee4060b799eeb061fcc975adf8635883a..27293d3c24b6878b7055298f777cde2f55811cf2 100644 (file)
@@ -1,5 +1,5 @@
 
-#include "algorithms/longest-common-suffix.h"
+#include "util/longest-common-suffix.h"
 #include "xml/repr.h"
 #include "xml/node-iterators.h"