From cca66b9ec4e494c1d919bff0f71a820d8afab1fa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:24:48 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- src/profile-manager.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/profile-manager.cpp (limited to 'src/profile-manager.cpp') diff --git a/src/profile-manager.cpp b/src/profile-manager.cpp new file mode 100644 index 0000000..b092980 --- /dev/null +++ b/src/profile-manager.cpp @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Inkscape::ProfileManager - a view of a document's color profiles. + * + * Copyright 2007 Jon A. Cruz + * Abhishek Sharma + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include +#include + +#include "profile-manager.h" + +#include "document.h" + +#include "object/color-profile.h" + + +namespace Inkscape { + +ProfileManager::ProfileManager(SPDocument *document) : + _doc(document), + _knownProfiles() +{ + _resource_connection = _doc->connectResourcesChanged( "iccprofile", sigc::mem_fun(*this, &ProfileManager::_resourcesChanged) ); +} + +ProfileManager::~ProfileManager() +{ + _resource_connection.disconnect(); + _doc = nullptr; +} + +void ProfileManager::_resourcesChanged() +{ + std::vector newList; + if (_doc) { + std::vector current = _doc->getResourceList( "iccprofile" ); + newList = current; + } + sort( newList.begin(), newList.end() ); + + std::vector diff1; + std::set_difference( _knownProfiles.begin(), _knownProfiles.end(), newList.begin(), newList.end(), + std::insert_iterator >(diff1, diff1.begin()) ); + + std::vector diff2; + std::set_difference( newList.begin(), newList.end(), _knownProfiles.begin(), _knownProfiles.end(), + std::insert_iterator >(diff2, diff2.begin()) ); + + if ( !diff1.empty() ) { + for ( std::vector::iterator it = diff1.begin(); it < diff1.end(); ++it ) { + SPObject* tmp = *it; + _knownProfiles.erase( remove(_knownProfiles.begin(), _knownProfiles.end(), tmp), _knownProfiles.end() ); + if ( includes(tmp) ) { + _removeOne(tmp); + } + } + } + + if ( !diff2.empty() ) { + for ( std::vector::iterator it = diff2.begin(); it < diff2.end(); ++it ) { + SPObject* tmp = *it; + _knownProfiles.push_back(tmp); + _addOne(tmp); + } + sort( _knownProfiles.begin(), _knownProfiles.end() ); + } +} + +ColorProfile* ProfileManager::find(gchar const* name) +{ + ColorProfile* match = nullptr; + if ( name ) { + unsigned int howMany = childCount(nullptr); + for ( unsigned int index = 0; index < howMany; index++ ) { + SPObject *obj = nthChildOf(nullptr, index); + ColorProfile* prof = reinterpret_cast(obj); + if (prof && (prof->name && !strcmp(name, prof->name))) { + match = prof; + break; + } + } + } + return match; +} + +} + + +/* + 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:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3