Commit 80d4031d authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fixed saving multiple layer styles into .kra

BUG:348178
parent aec7c8c6
......@@ -54,7 +54,6 @@ struct TestConfig {
bool keep_original;
void writeProperties(KisPSDLayerStyleSP style) const {
style->context()->global_angle = angle;
style->context()->keep_original = keep_original;
style->dropShadow()->setEffectEnabled(true);
......
......@@ -143,45 +143,6 @@ int calculateNumStyles(const QDomElement &root)
return numStyles;
}
void writeSingleStyle(QIODevice *device, QDomNode child)
{
KisAslWriterUtils::OffsetStreamPusher<quint32> theOnlyStyleSizeField(device);
KIS_ASSERT_RECOVER_RETURN(!child.isNull());
{
quint32 stylesFormatVersion = 16;
SAFE_WRITE_EX(device, stylesFormatVersion);
}
while (!child.isNull()) {
QDomElement el = child.toElement();
QString key = el.attribute("key", "");
if (key != "Patterns") break;
child = child.nextSibling();
}
parseElement(child.toElement(), device);
child = child.nextSibling();
{
quint32 stylesFormatVersion = 16;
SAFE_WRITE_EX(device, stylesFormatVersion);
}
parseElement(child.toElement(), device);
child = child.nextSibling();
// ASL files' size should be 4-bytes aligned
const qint64 paddingSize = 4 - (device->pos() & 0x3);
if (paddingSize != 4) {
QByteArray padding(paddingSize, '\0');
device->write(padding);
}
}
void writeFileImpl(QIODevice *device, const QDomDocument &doc)
{
{
......@@ -222,7 +183,41 @@ void writeFileImpl(QIODevice *device, const QDomDocument &doc)
QDomNode child = root.firstChild();
for (int styleIndex = 0; styleIndex < numStyles; styleIndex++) {
writeSingleStyle(device, child);
KisAslWriterUtils::OffsetStreamPusher<quint32> theOnlyStyleSizeField(device);
KIS_ASSERT_RECOVER_RETURN(!child.isNull());
{
quint32 stylesFormatVersion = 16;
SAFE_WRITE_EX(device, stylesFormatVersion);
}
while (!child.isNull()) {
QDomElement el = child.toElement();
QString key = el.attribute("key", "");
if (key != "Patterns") break;
child = child.nextSibling();
}
parseElement(child.toElement(), device);
child = child.nextSibling();
{
quint32 stylesFormatVersion = 16;
SAFE_WRITE_EX(device, stylesFormatVersion);
}
parseElement(child.toElement(), device);
child = child.nextSibling();
// ASL files' size should be 4-bytes aligned
const qint64 paddingSize = 4 - (device->pos() & 0x3);
if (paddingSize != 4) {
QByteArray padding(paddingSize, '\0');
device->write(padding);
}
}
}
......
......@@ -201,8 +201,9 @@ QString composite_op_to_psd_blendmode(const QString& compositeop)
QPoint psd_layer_effects_shadow_base::calculateOffset(const psd_layer_effects_context *context) const
{
qint32 angle = this->m_useGlobalLight ?
context->global_angle : this->m_angle;
Q_UNUSED(context);
qint32 angle = this->m_angle;
qint32 distanceX = -qRound(this->m_distance * cos(kisDegreesToRadians(qreal(angle))));
qint32 distanceY = qRound(this->m_distance * sin(kisDegreesToRadians(qreal(angle))));
......
......@@ -220,12 +220,10 @@ struct psd_pattern {
struct psd_layer_effects_context {
psd_layer_effects_context()
: global_angle(120),
keep_original(false)
: keep_original(false)
{
}
qint32 global_angle;
bool keep_original;
};
......
......@@ -1177,7 +1177,6 @@ void KisAslLayerStyleSerializer::newStyleStarted(bool isPsdStructure)
KisPSDLayerStyle *currentStyle = m_stylesVector.last().data();
psd_layer_effects_context *context = currentStyle->context();
context->global_angle = 0;
context->keep_original = 0;
QString prefix = isPsdStructure ? "/null" : "/Styl/Lefx";
......
......@@ -188,5 +188,62 @@ void KisKraSaverTest::testRoundTripFillLayerPattern()
testRoundTripFillLayerImpl("fill_layer_pattern", config);
}
#include "kis_psd_layer_style.h"
void KisKraSaverTest::testRoundTripLayerStyles()
{
TestUtil::ExternalImageChecker chk("kra_saver_test", "layer_styles");
QRect imageRect(0,0,512,512);
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisImageSP image = new KisImage(new KisSurrogateUndoStore(), imageRect.width(), imageRect.height(), cs, "test image");
KisPaintLayerSP layer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8);
KisPaintLayerSP layer2 = new KisPaintLayer(image, "paint2", OPACITY_OPAQUE_U8);
KisPaintLayerSP layer3 = new KisPaintLayer(image, "paint3", OPACITY_OPAQUE_U8);
image->addNode(layer1);
image->addNode(layer2);
image->addNode(layer3);
QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());
doc->setCurrentImage(image);
doc->documentInfo()->setAboutInfo("title", image->objectName());
layer1->paintDevice()->fill(QRect(100, 100, 100, 100), KoColor(Qt::red, cs));
layer2->paintDevice()->fill(QRect(200, 200, 100, 100), KoColor(Qt::green, cs));
layer3->paintDevice()->fill(QRect(300, 300, 100, 100), KoColor(Qt::blue, cs));
KisPSDLayerStyleSP style(new KisPSDLayerStyle());
style->dropShadow()->setEffectEnabled(true);
style->dropShadow()->setAngle(-90);
style->dropShadow()->setUseGlobalLight(false);
layer1->setLayerStyle(style->clone());
style->dropShadow()->setAngle(180);
style->dropShadow()->setUseGlobalLight(true);
layer2->setLayerStyle(style->clone());
style->dropShadow()->setAngle(90);
style->dropShadow()->setUseGlobalLight(false);
layer3->setLayerStyle(style->clone());
image->initialRefreshGraph();
chk.checkImage(image, "00_initial_layers");
doc->saveNativeFormat("roundtrip_layer_styles.kra");
QScopedPointer<KisDocument> doc2(KisPart::instance()->createDocument());
doc2->loadNativeFormat("roundtrip_layer_styles.kra");
doc2->image()->waitForDone();
chk.checkImage(doc2->image(), "00_initial_layers");
QVERIFY(chk.testPassed());
}
QTEST_KDEMAIN(KisKraSaverTest, GUI)
#include "kis_kra_saver_test.moc"
......@@ -35,6 +35,8 @@ private Q_SLOTS:
void testRoundTripFillLayerColor();
void testRoundTripFillLayerPattern();
void testRoundTripLayerStyles();
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment