From fe3f3248dd5c3eff5333a8a1969f3a83fd2249ad Mon Sep 17 00:00:00 2001 From: Robin Mills Date: Sun, 5 May 2019 08:18:46 +0200 Subject: [PATCH] Fix in sidecar files #589 --- src/xmpsidecar.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/xmpsidecar.cpp b/src/xmpsidecar.cpp index 2c958665..b9fa62c6 100644 --- a/src/xmpsidecar.cpp +++ b/src/xmpsidecar.cpp @@ -117,6 +117,21 @@ namespace Exiv2 { copyXmpToExif(xmpData_, exifData_); } // XmpSidecar::readMetadata + // lower case string + static std::string toLowerCase(std::string a) + { + for(size_t i=0 ; i < a.length() ; i++) + { + a[i]=tolower(a[i]); + } + return a; + } + + static bool matchi(const std::string key,const char* substr) + { + return toLowerCase(key).find(substr) != std::string::npos; + } + void XmpSidecar::writeMetadata() { if (io_->open() != 0) { @@ -126,9 +141,23 @@ namespace Exiv2 { if (writeXmpFromPacket() == false) { + // #589 copy XMP tags + Exiv2::XmpData copy ; + for (Exiv2::XmpData::const_iterator it = xmpData_.begin(); it != xmpData_.end(); ++it) { + if ( !matchi(it->key(),"exif") && !matchi(it->key(),"iptc") ) { + copy[it->key()] = it->value(); + } + } + + // run the convertors copyExifToXmp(exifData_, xmpData_); copyIptcToXmp(iptcData_, xmpData_); + // #589 - restore tags which were modified by the convertors + for (Exiv2::XmpData::const_iterator it = copy.begin(); it != copy.end(); ++it) { + xmpData_[it->key()] = it->value() ; + } + // #1112 - restore dates if they lost their TZ info for ( Exiv2::Dictionary_i it = dates_.begin() ; it != dates_.end() ; ++it ) { std::string sKey = it->first;