Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

psd text: Allow multiple unitfloat callbacks on the same path with different units.

Wolthera van Hövell tot Westerflier689f0fce37c0
diff --git a/libs/psd/psd_additional_layer_info_block.h b/libs/psd/psd_additional_layer_info_block.h
index e6c6bef6b7..8fae4b1f36 100644
--- a/libs/psd/psd_additional_layer_info_block.h
+++ b/libs/psd/psd_additional_layer_info_block.h
@@ -887,10 +887,18 @@ struct KRITAPSD_EXPORT psd_layer_type_shape {
catcher.subscribeInteger(path + "/TxLr/TextIndex", std::bind(&psd_layer_type_shape::setIndex, data, std::placeholders::_1));
catcher.subscribeRawData(path + "/TxLr/EngineData", std::bind(&psd_layer_type_shape::setEngineData, data, std::placeholders::_1));
catcher.subscribeEnum(path + "/TxLr/Ornt", "Ornt", std::bind(&psd_layer_type_shape::setWritingMode, data, std::placeholders::_1));
+
+ // Older psd use Pnt as the unit, even though its pixel.
catcher.subscribeUnitFloat(path + "/TxLr/bounds/Left", "#Pnt", std::bind(&psd_layer_type_shape::setLeft, data, std::placeholders::_1));
catcher.subscribeUnitFloat(path + "/TxLr/bounds/Top ", "#Pnt", std::bind(&psd_layer_type_shape::setTop, data, std::placeholders::_1));
catcher.subscribeUnitFloat(path + "/TxLr/bounds/Rght", "#Pnt", std::bind(&psd_layer_type_shape::setRight, data, std::placeholders::_1));
catcher.subscribeUnitFloat(path + "/TxLr/bounds/Btom", "#Pnt", std::bind(&psd_layer_type_shape::setBottom, data, std::placeholders::_1));
+
+ // Newer photoshop files use pxl as the unit, which is correct...
+ catcher.subscribeUnitFloat(path + "/TxLr/bounds/Left", "#Pxl", std::bind(&psd_layer_type_shape::setLeft, data, std::placeholders::_1));
+ catcher.subscribeUnitFloat(path + "/TxLr/bounds/Top ", "#Pxl", std::bind(&psd_layer_type_shape::setTop, data, std::placeholders::_1));
+ catcher.subscribeUnitFloat(path + "/TxLr/bounds/Rght", "#Pxl", std::bind(&psd_layer_type_shape::setRight, data, std::placeholders::_1));
+ catcher.subscribeUnitFloat(path + "/TxLr/bounds/Btom", "#Pxl", std::bind(&psd_layer_type_shape::setBottom, data, std::placeholders::_1));
}
QDomDocument textDataASLXML() {
diff --git a/libs/psdutils/asl/kis_asl_callback_object_catcher.cpp b/libs/psdutils/asl/kis_asl_callback_object_catcher.cpp
index 48be34fd16..cb35cd68ed 100644
--- a/libs/psdutils/asl/kis_asl_callback_object_catcher.cpp
+++ b/libs/psdutils/asl/kis_asl_callback_object_catcher.cpp
@@ -33,14 +33,15 @@ struct EnumMapping {
typedef QHash<QString, EnumMapping> MapHashEnum;
struct UnitFloatMapping {
+ UnitFloatMapping() {
+
+ }
UnitFloatMapping(const QString &_unit, ASLCallbackDouble _map)
- : unit(_unit)
- , map(_map)
{
+ unitMap.insert(_unit, _map);
}
- QString unit;
- ASLCallbackDouble map;
+ QMap<QString, ASLCallbackDouble> unitMap;
};
struct UnitRectMapping {
@@ -147,10 +148,11 @@ void KisAslCallbackObjectCatcher::addUnitFloat(const QString &path, const QStrin
{
MapHashUnitFloat::const_iterator it = m_d->mapUnitFloat.constFind(path);
if (it != m_d->mapUnitFloat.constEnd()) {
- if (it->unit == unit) {
- it->map(value);
+ if (it->unitMap.contains(unit)) {
+ ASLCallbackDouble map = it->unitMap.value(unit);
+ map(value);
} else {
- warnKrita << "KisAslCallbackObjectCatcher::addUnitFloat: inconsistent unit" << ppVar(unit) << ppVar(it->unit);
+ warnKrita << "KisAslCallbackObjectCatcher::addUnitFloat: inconsistent unit" << ppVar(unit) << ppVar(it->unitMap.keys());
}
}
}
@@ -256,7 +258,13 @@ void KisAslCallbackObjectCatcher::subscribeEnum(const QString &path, const QStri
void KisAslCallbackObjectCatcher::subscribeUnitFloat(const QString &path, const QString &unit, ASLCallbackDouble callback)
{
- m_d->mapUnitFloat.insert(path, UnitFloatMapping(unit, callback));
+ if (m_d->mapUnitFloat.contains(path)) {
+ UnitFloatMapping mapping = m_d->mapUnitFloat.value(path);
+ mapping.unitMap.insert(unit, callback);
+ m_d->mapUnitFloat.insert(path, mapping);
+ } else {
+ m_d->mapUnitFloat.insert(path, UnitFloatMapping(unit, callback));
+ }
}
void KisAslCallbackObjectCatcher::subscribeText(const QString &path, ASLCallbackString callback)