From: Krzysztof KosiƄski Date: Sun, 14 Mar 2010 23:58:16 +0000 (+0100) Subject: Move around files to remove some vanity directories. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5a931dcbd585584fed4990ae6cd1717a3918f90a;p=inkscape.git Move around files to remove some vanity directories. Also remove the obsolete IDL file stub. --- diff --git a/configure.ac b/configure.ac index 00b0e91cb..330e40d7d 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/Makefile.am b/src/Makefile.am index ff5d20f49..b392ef0d2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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) diff --git a/src/Makefile_insert b/src/Makefile_insert index 1e5b1fea0..89c1b17b0 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -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 index 0ac17f57c..000000000 --- a/src/algorithms/CMakeLists.txt +++ /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 index dff5b578d..000000000 --- a/src/algorithms/Makefile_insert +++ /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 index 6a0f63be6..000000000 --- a/src/algorithms/find-if-before.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Inkscape::Algorithms::find_if_before - finds the position before - * the first value that satisifes - * the predicate - * - * Authors: - * MenTaLguY - * - * 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 - -namespace Inkscape { - -namespace Algorithms { - -template -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 index 1ffd63b9c..000000000 --- a/src/algorithms/find-last-if.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Inkscape::Algorithms::find_last_if - * - * Authors: - * MenTaLguY - * - * 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 - -namespace Inkscape { - -namespace Algorithms { - -template -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 index 04d2b179d..000000000 --- a/src/algorithms/longest-common-suffix.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Inkscape::Algorithms::longest_common_suffix - * - * Authors: - * MenTaLguY - * - * 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 -#include -#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 -ForwardIterator longest_common_suffix(ForwardIterator a, ForwardIterator b, - ForwardIterator end) -{ - typedef typename std::iterator_traits::value_type value_type; - return longest_common_suffix(a, b, end, std::equal_to()); -} - -template -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 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 index 112aae15d..000000000 --- a/src/algorithms/makefile.in +++ /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 index e2e9ff892..000000000 --- a/src/api/CMakeLists.txt +++ /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 index 482184f18..000000000 --- a/src/api/inkscape.idl +++ /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; - - /** - * 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 index 000000000..a89af10af --- /dev/null +++ b/src/graphlayout.cpp @@ -0,0 +1,262 @@ +/** @file + * @brief Interface between Inkscape code (SPItem) and graphlayout functions. + */ +/* + * Authors: + * Tim Dwyer + * + * Copyright (C) 2005 Authors + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#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& + selected,vector& rs,map& 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="<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::iterator i(selected.begin()); + i != selected.end(); + ++i) + { + SPItem *iu=*i; + map::iterator i=nodelookup.find(iu->getId()); + if(i==nodelookup.end()) { + continue; + } + unsigned u=i->second; + GSList *nlist=iu->avoidRef->getAttachedConnectors(Avoid::runningFrom); + list connectors; + + connectors.insert >(connectors.end(),nlist,NULL); + for (list::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::iterator v_pair=nodelookup.find(iv->getId()); + if(v_pair!=nodelookup.end()) { + unsigned v=v_pair->second; + //cout << "Edge: (" << u <<","<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 cs; + connectedComponents(rs,es,scx,scy,cs); + for(unsigned i=0;iedges.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::iterator it(selected.begin()); + it != selected.end(); + ++it) + { + SPItem *u=*it; + if(!isConnector(u)) { + map::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 + * + * 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 +void filterConnectors(_GSList const *const items, std::list &filtered); +#endif // SEEN_GRAPHLAYOUT_H diff --git a/src/graphlayout/CMakeLists.txt b/src/graphlayout/CMakeLists.txt deleted file mode 100644 index c8847a228..000000000 --- a/src/graphlayout/CMakeLists.txt +++ /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 index 790c951ae..000000000 --- a/src/graphlayout/Makefile_insert +++ /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 index 23b0ee13b..000000000 --- a/src/graphlayout/graphlayout.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/** @file - * @brief Interface between Inkscape code (SPItem) and graphlayout functions. - */ -/* - * Authors: - * Tim Dwyer - * - * Copyright (C) 2005 Authors - * - * Released under GNU GPL. Read the file 'COPYING' for more information. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#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& - selected,vector& rs,map& 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="<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::iterator i(selected.begin()); - i != selected.end(); - ++i) - { - SPItem *iu=*i; - map::iterator i=nodelookup.find(iu->getId()); - if(i==nodelookup.end()) { - continue; - } - unsigned u=i->second; - GSList *nlist=iu->avoidRef->getAttachedConnectors(Avoid::runningFrom); - list connectors; - - connectors.insert >(connectors.end(),nlist,NULL); - for (list::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::iterator v_pair=nodelookup.find(iv->getId()); - if(v_pair!=nodelookup.end()) { - unsigned v=v_pair->second; - //cout << "Edge: (" << u <<","<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 cs; - connectedComponents(rs,es,scx,scy,cs); - for(unsigned i=0;iedges.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::iterator it(selected.begin()); - it != selected.end(); - ++it) - { - SPItem *u=*it; - if(!isConnector(u)) { - map::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 - * - * 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 -void filterConnectors(_GSList const *const items, std::list &filtered); -#endif // SEEN_GRAPHLAYOUT_H diff --git a/src/graphlayout/makefile b/src/graphlayout/makefile deleted file mode 100644 index 5d8ac906e..000000000 --- a/src/graphlayout/makefile +++ /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 index 7a1e86525..000000000 --- a/src/inkjar/CMakeLists.txt +++ /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 index ef4f1fd19..000000000 --- a/src/inkjar/Makefile_insert +++ /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 index 6897cb317..000000000 --- a/src/inkjar/jar.cpp +++ /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 -//#endif - -#include -#include -#include -#include -#include - -#include "jar.h" - -#include -#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 index 0fe088b24..000000000 --- a/src/inkjar/jar.h +++ /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 -#endif - -#ifdef HAVE_ZLIB_H -# include -#endif - -#ifdef HAVE_INTTYPES_H -# include -#else -# ifdef HAVE_STDINT_H -# include -# endif -#endif - -#include -#include - -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 index 96834aa2f..000000000 --- a/src/inkjar/makefile.in +++ /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) diff --git a/src/inkview.cpp b/src/inkview.cpp index 007438b49..c151991dd 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -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" diff --git a/src/io/Makefile_insert b/src/io/Makefile_insert index 2696e9334..bb47b46b8 100644 --- a/src/io/Makefile_insert +++ b/src/io/Makefile_insert @@ -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 index 000000000..c238aba36 --- /dev/null +++ b/src/io/inkjar.cpp @@ -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 +//#endif + +#include +#include +#include +#include +#include + +#include "inkjar.h" + +#include +#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 index 000000000..0fe088b24 --- /dev/null +++ b/src/io/inkjar.h @@ -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 +#endif + +#ifdef HAVE_ZLIB_H +# include +#endif + +#ifdef HAVE_INTTYPES_H +# include +#else +# ifdef HAVE_STDINT_H +# include +# endif +#endif + +#include +#include + +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/layer-fns.cpp b/src/layer-fns.cpp index 75bb89bcf..ca7c1c493 100644 --- a/src/layer-fns.cpp +++ b/src/layer-fns.cpp @@ -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 index 000000000..975b4becb --- /dev/null +++ b/src/removeoverlap.cpp @@ -0,0 +1,84 @@ +/** \file + * Interface between Inkscape code (SPItem) and remove-overlaps function. + */ +/* +* Authors: +* Tim Dwyer +* +* 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 + +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 selected; + selected.insert >(selected.end(), items, NULL); + std::vector records; + std::vector rs; + + Geom::Point const gap(xGap, yGap); + for (std::list::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::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 index 000000000..5b16e706b --- /dev/null +++ b/src/removeoverlap.h @@ -0,0 +1,20 @@ +/** \file + * \brief Remove overlaps function + */ +/* + * Authors: + * Tim Dwyer + * + * Copyright (C) 2005 Authors + * + * Released under GNU LGPL. Read the file 'COPYING' for more information. + */ + +#ifndef SEEN_REMOVEOVERLAP_H +#define SEEN_REMOVEOVERLAP_H + +#include + +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 index 7f71c29dc..000000000 --- a/src/removeoverlap/CMakeLists.txt +++ /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 index d5e90ec02..000000000 --- a/src/removeoverlap/Makefile_insert +++ /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 index 34e31a9a3..000000000 --- a/src/removeoverlap/makefile.in +++ /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 index 975b4becb..000000000 --- a/src/removeoverlap/removeoverlap.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/** \file - * Interface between Inkscape code (SPItem) and remove-overlaps function. - */ -/* -* Authors: -* Tim Dwyer -* -* 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 - -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 selected; - selected.insert >(selected.end(), items, NULL); - std::vector records; - std::vector rs; - - Geom::Point const gap(xGap, yGap); - for (std::list::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::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 index 5b16e706b..000000000 --- a/src/removeoverlap/removeoverlap.h +++ /dev/null @@ -1,20 +0,0 @@ -/** \file - * \brief Remove overlaps function - */ -/* - * Authors: - * Tim Dwyer - * - * Copyright (C) 2005 Authors - * - * Released under GNU LGPL. Read the file 'COPYING' for more information. - */ - -#ifndef SEEN_REMOVEOVERLAP_H -#define SEEN_REMOVEOVERLAP_H - -#include - -void removeoverlap(GSList const *items, double xGap, double yGap); - -#endif // SEEN_REMOVEOVERLAP_H diff --git a/src/sp-item.cpp b/src/sp-item.cpp index c28940fca..c4411e47d 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -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> diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 5e0f72758..420c7b4a6 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -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 index 791f9cd85..000000000 --- a/src/traits/CMakeLists.txt +++ /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 index 4290ac2dd..000000000 --- a/src/traits/Makefile_insert +++ /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 index 27038ff2d..000000000 --- a/src/traits/copy.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Inkscape::Traits::Copy - traits class to determine types to use when copying - * - * Authors: - * MenTaLguY - * - * 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 -struct Copy { - typedef T Type; -}; - -template -struct Copy { - typedef T Type; -}; - -template -struct Copy { - 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 index d0dd5d87c..000000000 --- a/src/traits/function.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Inkscape::Traits::Function - traits class for C++ "functors" - * - * Authors: - * MenTaLguY - * - * 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 struct Function; - -template -struct Function { - typedef R Result; - - typedef void Arg0; - typedef void Arg1; - typedef void Arg2; - typedef void Arg3; - typedef void Arg4; - typedef void Arg5; -}; - -template -struct Function { - typedef R Result; - - typedef A0 Arg0; - typedef void Arg1; - typedef void Arg2; - typedef void Arg3; - typedef void Arg4; - typedef void Arg5; -}; - -template -struct Function { - typedef R Result; - - typedef A0 Arg0; - typedef A1 Arg1; - typedef void Arg2; - typedef void Arg3; - typedef void Arg4; - typedef void Arg5; -}; - -template -struct Function { - typedef R Result; - - typedef A0 Arg0; - typedef A1 Arg1; - typedef A2 Arg2; - typedef void Arg3; - typedef void Arg4; - typedef void Arg5; -}; - -template -struct Function { - typedef R Result; - - typedef A0 Arg0; - typedef A1 Arg1; - typedef A2 Arg2; - typedef A3 Arg3; - typedef void Arg4; - typedef void Arg5; -}; - -template -struct Function { - typedef R Result; - - typedef A0 Arg0; - typedef A1 Arg1; - typedef A2 Arg2; - typedef A3 Arg3; - typedef A4 Arg4; - typedef void Arg5; -}; - -template -struct Function { - 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 index 9d99c4f29..000000000 --- a/src/traits/list-copy.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Inkscape::Traits::ListCopy - helper traits class for copying lists - * - * Authors: - * MenTaLguY - * - * 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 -#include "traits/copy.h" -#include "util/list.h" - -namespace Inkscape { - -namespace Traits { - -template -struct ListCopy { - typedef typename Copy< - typename std::iterator_traits::value_type - >::Type ResultValue; - typedef typename Util::MutableList 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 index c0f07d432..000000000 --- a/src/traits/makefile.in +++ /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 index 199ae8929..000000000 --- a/src/traits/reference.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Inkscape::Traits::Reference - traits class for dealing with reference types - * - * Authors: - * MenTaLguY - * - * 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 -struct Reference { - typedef T const &RValue; - typedef T &LValue; - typedef T *Pointer; - typedef T const *ConstPointer; -}; - -template -struct Reference { - 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 : diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 8c8d64ec0..a75a8d68d 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -24,11 +24,11 @@ #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" diff --git a/src/ui/tool/node.h b/src/ui/tool/node.h index e502ddea1..d04b87976 100644 --- a/src/ui/tool/node.h +++ b/src/ui/tool/node.h @@ -234,8 +234,16 @@ public: /// @see get_pointer() N *ptr() const { return static_cast(_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 iterator; typedef NodeIterator const_iterator; - typedef std::reverse_iterator reverse_iterator; - typedef std::reverse_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::operator bool() const { return _node && static_cast(_node->ln_list) != _node; } template -NodeIterator NodeIterator::next() const { - NodeIterator ret(*this); - ++ret; - if (G_UNLIKELY(!ret) && _node->ln_list->closed()) ++ret; - return ret; +NodeIterator &NodeIterator::advance() { + ++(*this); + if (G_UNLIKELY(!*this) && _node->ln_list->closed()) ++(*this); + return *this; } template -NodeIterator NodeIterator::prev() const { - NodeIterator ret(*this); - --ret; - if (G_UNLIKELY(!ret) && _node->ln_list->closed()) --ret; - return ret; +NodeIterator &NodeIterator::retreat() { + --(*this); + if (G_UNLIKELY(!*this) && _node->ln_list->closed()) --(*this); + return *this; } } // namespace UI diff --git a/src/util/Makefile_insert b/src/util/Makefile_insert index 1908aea19..259fd762e 100644 --- a/src/util/Makefile_insert +++ b/src/util/Makefile_insert @@ -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 index 000000000..27038ff2d --- /dev/null +++ b/src/util/copy.h @@ -0,0 +1,48 @@ +/* + * Inkscape::Traits::Copy - traits class to determine types to use when copying + * + * Authors: + * MenTaLguY + * + * 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 +struct Copy { + typedef T Type; +}; + +template +struct Copy { + typedef T Type; +}; + +template +struct Copy { + 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/util/filter-list.h b/src/util/filter-list.h index e00c33b08..50aba12fa 100644 --- a/src/util/filter-list.h +++ b/src/util/filter-list.h @@ -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 index 000000000..6a0f63be6 --- /dev/null +++ b/src/util/find-if-before.h @@ -0,0 +1,51 @@ +/* + * Inkscape::Algorithms::find_if_before - finds the position before + * the first value that satisifes + * the predicate + * + * Authors: + * MenTaLguY + * + * 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 + +namespace Inkscape { + +namespace Algorithms { + +template +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 index 000000000..1ffd63b9c --- /dev/null +++ b/src/util/find-last-if.h @@ -0,0 +1,51 @@ +/* + * Inkscape::Algorithms::find_last_if + * + * Authors: + * MenTaLguY + * + * 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 + +namespace Inkscape { + +namespace Algorithms { + +template +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/util/fixed_point.h b/src/util/fixed_point.h index 6afec5e3c..05a73dab5 100644 --- a/src/util/fixed_point.h +++ b/src/util/fixed_point.h @@ -12,229 +12,7 @@ #ifndef SEEN_INKSCAPE_UTIL_FIXED_POINT_H #define SEEN_INKSCAPE_UTIL_FIXED_POINT_H -#include "traits/reference.h" -#include -#include -#include - -namespace Inkscape { - -namespace Util { - -template -class FixedPoint { -public: - FixedPoint() {} - FixedPoint(const FixedPoint& value) : v(value.v) {} - FixedPoint(char value) : v(static_cast(value)<(value)<(value)<(value)<(value)<(value)<(floor(value*(1<>half_size, bh = val.v>>half_size; - v = static_cast(al*bl)>>precision; - if ( half_size >= precision ) { - v += ((al*bh)+(ah*bl)+((ah*bh)<>(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(*this)*val; } - double operator*(double val) const { return static_cast(*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 FixedPoint operator *(char a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned char a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(short a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned short a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(int a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned int a, FixedPoint b) { return b*=a; } - -template float operator *(float a, FixedPoint b) { return b*a; } -template double operator *(double a, FixedPoint 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 - * - * 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 -#include -#include - -namespace Inkscape { - -namespace Util { - -template -class FixedPoint { -public: - FixedPoint() {} - FixedPoint(const FixedPoint& value) : v(value.v) {} - FixedPoint(char value) : v(static_cast(value)<(value)<(value)<(value)<(value)<(value)<(floor(value*(1<>half_size, bh = val.v>>half_size; - v = static_cast(al*bl)>>precision; - if ( half_size >= precision ) { - v += ((al*bh)+(ah*bl)+((ah*bh)<>(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(*this)*val; } - double operator*(double val) const { return static_cast(*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 FixedPoint operator *(char a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned char a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(short a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned short a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(int a, FixedPoint b) { return b*=a; } -template FixedPoint operator *(unsigned int a, FixedPoint b) { return b*=a; } - -template float operator *(float a, FixedPoint b) { return b*a; } -template double operator *(double a, FixedPoint 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 - * - * 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 #include #include diff --git a/src/util/forward-pointer-iterator.h b/src/util/forward-pointer-iterator.h index 2c2345c81..1603fed27 100644 --- a/src/util/forward-pointer-iterator.h +++ b/src/util/forward-pointer-iterator.h @@ -15,7 +15,7 @@ #define SEEN_INKSCAPE_UTIL_FORWARD_POINTER_ITERATOR_H #include -#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 index 000000000..d0dd5d87c --- /dev/null +++ b/src/util/function.h @@ -0,0 +1,122 @@ +/* + * Inkscape::Traits::Function - traits class for C++ "functors" + * + * Authors: + * MenTaLguY + * + * 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 struct Function; + +template +struct Function { + typedef R Result; + + typedef void Arg0; + typedef void Arg1; + typedef void Arg2; + typedef void Arg3; + typedef void Arg4; + typedef void Arg5; +}; + +template +struct Function { + typedef R Result; + + typedef A0 Arg0; + typedef void Arg1; + typedef void Arg2; + typedef void Arg3; + typedef void Arg4; + typedef void Arg5; +}; + +template +struct Function { + typedef R Result; + + typedef A0 Arg0; + typedef A1 Arg1; + typedef void Arg2; + typedef void Arg3; + typedef void Arg4; + typedef void Arg5; +}; + +template +struct Function { + typedef R Result; + + typedef A0 Arg0; + typedef A1 Arg1; + typedef A2 Arg2; + typedef void Arg3; + typedef void Arg4; + typedef void Arg5; +}; + +template +struct Function { + typedef R Result; + + typedef A0 Arg0; + typedef A1 Arg1; + typedef A2 Arg2; + typedef A3 Arg3; + typedef void Arg4; + typedef void Arg5; +}; + +template +struct Function { + typedef R Result; + + typedef A0 Arg0; + typedef A1 Arg1; + typedef A2 Arg2; + typedef A3 Arg3; + typedef A4 Arg4; + typedef void Arg5; +}; + +template +struct Function { + 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 index 000000000..811f93b77 --- /dev/null +++ b/src/util/list-copy.h @@ -0,0 +1,45 @@ +/* + * Inkscape::Traits::ListCopy - helper traits class for copying lists + * + * Authors: + * MenTaLguY + * + * 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 +#include "util/copy.h" +#include "util/list.h" + +namespace Inkscape { + +namespace Traits { + +template +struct ListCopy { + typedef typename Copy< + typename std::iterator_traits::value_type + >::Type ResultValue; + typedef typename Util::MutableList 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/util/list.h b/src/util/list.h index 86a73711a..ebe3a9773 100644 --- a/src/util/list.h +++ b/src/util/list.h @@ -15,7 +15,7 @@ #include #include #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 index 000000000..04d2b179d --- /dev/null +++ b/src/util/longest-common-suffix.h @@ -0,0 +1,114 @@ +/* + * Inkscape::Algorithms::longest_common_suffix + * + * Authors: + * MenTaLguY + * + * 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 +#include +#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 +ForwardIterator longest_common_suffix(ForwardIterator a, ForwardIterator b, + ForwardIterator end) +{ + typedef typename std::iterator_traits::value_type value_type; + return longest_common_suffix(a, b, end, std::equal_to()); +} + +template +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 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 index 000000000..199ae8929 --- /dev/null +++ b/src/util/reference.h @@ -0,0 +1,49 @@ +/* + * Inkscape::Traits::Reference - traits class for dealing with reference types + * + * Authors: + * MenTaLguY + * + * 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 +struct Reference { + typedef T const &RValue; + typedef T &LValue; + typedef T *Pointer; + typedef T const *ConstPointer; +}; + +template +struct Reference { + 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 : diff --git a/src/util/reverse-list.h b/src/util/reverse-list.h index 586f706c7..798b15701 100644 --- a/src/util/reverse-list.h +++ b/src/util/reverse-list.h @@ -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 { diff --git a/src/util/tuple.h b/src/util/tuple.h index bf9338366..42266c8d2 100644 --- a/src/util/tuple.h +++ b/src/util/tuple.h @@ -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 { diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index b4324ca0d..4b0d84d90 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -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" diff --git a/src/xml/Makefile_insert b/src/xml/Makefile_insert index e4269026c..7190b7948 100644 --- a/src/xml/Makefile_insert +++ b/src/xml/Makefile_insert @@ -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 \ diff --git a/src/xml/composite-node-observer.cpp b/src/xml/composite-node-observer.cpp index e65981616..564938dda 100644 --- a/src/xml/composite-node-observer.cpp +++ b/src/xml/composite-node-observer.cpp @@ -15,7 +15,7 @@ #include #include -#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" diff --git a/src/xml/node-fns.cpp b/src/xml/node-fns.cpp index deb88fb5e..bf860d8f3 100644 --- a/src/xml/node-fns.cpp +++ b/src/xml/node-fns.cpp @@ -8,7 +8,7 @@ #include // g_assert() #include "xml/node-iterators.h" -#include "algorithms/find-if-before.h" +#include "util/find-if-before.h" namespace Inkscape { namespace XML { diff --git a/src/xml/repr-sorting.cpp b/src/xml/repr-sorting.cpp index 123df33ee..27293d3c2 100644 --- a/src/xml/repr-sorting.cpp +++ b/src/xml/repr-sorting.cpp @@ -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"