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 vectors: improve loading patterns and strokes

Wolthera van Hövell tot Westerflier2fdc761714b9
diff --git a/libs/psd/psd_additional_layer_info_block.h b/libs/psd/psd_additional_layer_info_block.h
index c1bea42f24..e83b468408 100644
--- a/libs/psd/psd_additional_layer_info_block.h
+++ b/libs/psd/psd_additional_layer_info_block.h
@@ -22,6 +22,7 @@
#include <kis_paint_device.h>
#include <kis_generator_registry.h>
#include <KisGlobalResourcesInterface.h>
+#include <KisEmbeddedResourceStorageProxy.h>
#include <KoStopGradient.h>
#include <KoSegmentGradient.h>
#include <KoShapeBackground.h>
@@ -587,6 +588,7 @@ struct KRITAPSD_EXPORT psd_layer_gradient_fill {
g->setFinalStop(line.p2());
line.setAngle(180+angle);
g->setStart(line.p2());
+ pointer = g;
}
}
@@ -751,22 +753,42 @@ struct KRITAPSD_EXPORT psd_layer_pattern_fill {
w.writePoint("phase", offset);
}
- QSharedPointer<KoShapeBackground> getBackground() {
- QSharedPointer<KoPatternBackground> bg = QSharedPointer<KoPatternBackground>(new KoPatternBackground());
-
+ void loadPattern(KisEmbeddedResourceStorageProxy &embeddedProxy) {
const QString patternMD5 = "";
- const QString patternNameTemp = QString(patternID + ".pat");
- const QString patternFileName = patternName;
- KoResourceLoadResult res = KisGlobalResourcesInterface::instance()->source(ResourceType::Patterns).bestMatchLoadResult(patternMD5, patternFileName, patternNameTemp);
+ const QString patternNameTemp = patternName;
+ const QString patternFileName = QString(patternID + ".pat");
+
+ KoResourceLoadResult res = embeddedProxy.resourcesInterface()->source(ResourceType::Patterns).bestMatchLoadResult(patternMD5, patternFileName, patternNameTemp);
pattern = res.resource<KoPattern>();
+ }
+
+ QSharedPointer<KoShapeBackground> getBackground(KisEmbeddedResourceStorageProxy &embeddedProxy) {
+ QSharedPointer<KoPatternBackground> bg = QSharedPointer<KoPatternBackground>(new KoPatternBackground());
+
+ loadPattern(embeddedProxy);
if (pattern) {
bg->setPattern(pattern->pattern());
} else {
- res = KisGlobalResourcesInterface::instance()->source(ResourceType::Patterns).fallbackResource();
+ KoResourceLoadResult res = KisGlobalResourcesInterface::instance()->source(ResourceType::Patterns).fallbackResource();
bg->setPattern(res.resource<KoPattern>()->pattern());
}
return bg;
}
+
+ QBrush getBrush(KisEmbeddedResourceStorageProxy &embeddedProxy) {
+ QBrush brush;
+ loadPattern(embeddedProxy);
+ if (pattern) {
+ brush.setTextureImage(pattern->pattern());
+ } else {
+ KoResourceLoadResult res = KisGlobalResourcesInterface::instance()->source(ResourceType::Patterns).fallbackResource();
+ brush.setTextureImage(res.resource<KoPattern>()->pattern());
+ }
+ QTransform t = QTransform::fromScale(scale*0.01, scale*0.01);
+ t.rotate(angle);
+ brush.setTransform(t);
+ return brush;
+ }
};
struct KRITAPSD_EXPORT psd_layer_type_face {
@@ -962,7 +984,7 @@ struct KRITAPSD_EXPORT psd_vector_stroke_data {
double opacity {1.0};
- double resolution {72};
+ double resolution {72.0};
bool pixelWidth {false};
void setVersion(int version) {
@@ -1041,8 +1063,8 @@ struct KRITAPSD_EXPORT psd_vector_stroke_data {
catcher.subscribeBoolean(path + "/strokeStyle/strokeEnabled", std::bind(&psd_vector_stroke_data::setStrokeEnabled, data, std::placeholders::_1));
catcher.subscribeBoolean(path + "/strokeStyle/fillEnabled", std::bind(&psd_vector_stroke_data::setFillEnabled, data, std::placeholders::_1));
- catcher.subscribeUnitFloat(path + "/strokeStyle/strokeStyleLineWidth", "#Pnt", std::bind(&psd_vector_stroke_data::setStrokeWidth, data, std::placeholders::_1));
- //catcher.subscribeUnitFloat(path + "/strokeStyle/strokeStyleLineWidth", "#Pxl", std::bind(&psd_vector_stroke_data::setStrokePixel, data, std::placeholders::_1));
+ catcher.subscribeUnitFloat(path + "/strokeStyle/strokeStyleLineWidth", "#Pxl", std::bind(&psd_vector_stroke_data::setStrokeWidth, data, std::placeholders::_1));
+ //catcher.subscribeUnitFloat(path + "/strokeStyle/strokeStyleLineWidth", "#Pnt", std::bind(&psd_vector_stroke_data::setStrokePixel, data, std::placeholders::_1));
catcher.subscribeUnitFloat(path + "/strokeStyle/strokeStyleLineDashOffset", "#Pnt", std::bind(&psd_vector_stroke_data::setStrokeDashOffset, data, std::placeholders::_1));
catcher.subscribeDouble(path + "/strokeStyle/strokeStyleMiterLimit", std::bind(&psd_vector_stroke_data::setStrokeMiterLimit, data, std::placeholders::_1));
@@ -1066,7 +1088,7 @@ struct KRITAPSD_EXPORT psd_vector_stroke_data {
w.writeBoolean("strokeEnabled", strokeEnabled);
w.writeBoolean("fillEnabled", fillEnabled);
- w.writeUnitFloat("strokeStyleLineWidth", "#Pnt", pen.widthF());
+ w.writeUnitFloat("strokeStyleLineWidth", "#Pxl", pen.widthF() * (resolution / 72.0));
w.writeUnitFloat("strokeStyleLineDashOffset ", "#Pnt", pen.dashOffset());
w.writeDouble("strokeStyleMiterLimit", pen.miterLimit());
@@ -1132,9 +1154,7 @@ struct KRITAPSD_EXPORT psd_vector_stroke_data {
void setupShapeStroke(KoShapeStrokeSP stroke) {
double width = pen.widthF();
- if (pixelWidth) {
- width = (width / resolution) * 72.0;
- }
+ width = (width / resolution) * 72.0;
stroke->setLineWidth(width);
stroke->setCapStyle(pen.capStyle());
stroke->setJoinStyle(pen.joinStyle());
diff --git a/libs/psd/psd_layer_section.cpp b/libs/psd/psd_layer_section.cpp
index 61dc873e5e..df4b1f15b1 100644
--- a/libs/psd/psd_layer_section.cpp
+++ b/libs/psd/psd_layer_section.cpp
@@ -731,6 +731,7 @@ void PSDLayerMaskSection::writePsdImpl(QIODevice &io, KisNodeSP rootLayer, psd_c
strokeDataStruct.loadFromShapeStroke(shapeStroke);
strokeDataStruct.strokeEnabled = true;
strokeDataStruct.fillEnabled = pathShape->background()? true: false;
+ strokeDataStruct.resolution = node->image()->xRes()*72.0;
strokeData = strokeDataStruct.getASLXML();
}
}
diff --git a/plugins/impex/psd/psd_loader.cpp b/plugins/impex/psd/psd_loader.cpp
index e8fbbb8b86..48846a338f 100644
--- a/plugins/impex/psd/psd_loader.cpp
+++ b/plugins/impex/psd/psd_loader.cpp
@@ -348,7 +348,7 @@ KisImportExportErrorCode PSDLoader::decode(QIODevice &io)
parser.parseXML(layerRecord->infoBlocks.fillConfig, catcher);
fillConfig = fill.getFillLayerConfig();
if (vectorMask) {
- vectorMask->setBackground(fill.getBackground());
+ vectorMask->setBackground(fill.getBackground(resourceProxy));
}
} else {
@@ -374,11 +374,13 @@ KisImportExportErrorCode PSDLoader::decode(QIODevice &io)
psd_vector_stroke_data data;
psd_layer_solid_color fill;
psd_layer_gradient_fill grad;
+ psd_layer_pattern_fill patt;
fill.cs = m_image->colorSpace();
KisAslCallbackObjectCatcher strokeCatcher;
psd_vector_stroke_data::setupCatcher("", strokeCatcher, &data);
psd_layer_solid_color::setupCatcher("/strokeStyle/strokeStyleContent", strokeCatcher, &fill);
psd_layer_gradient_fill::setupCatcher("/strokeStyle/strokeStyleContent", strokeCatcher, &grad);
+ psd_layer_pattern_fill::setupCatcher("/strokeStyle/strokeStyleContent", strokeCatcher, &patt);
KisAslXmlParser parser;
parser.parseXML(layerRecord->infoBlocks.vectorStroke, strokeCatcher);
@@ -389,7 +391,9 @@ KisImportExportErrorCode PSDLoader::decode(QIODevice &io)
QColor c = fill.getBrush().color();
c.setAlphaF(data.opacity);
stroke->setColor(c);
- if (grad.getBrush().gradient()) {
+ if (!patt.patternID.isEmpty()) {
+ stroke->setLineBrush(patt.getBrush(resourceProxy));
+ } else if (!grad.gradient.isNull()) {
stroke->setLineBrush(grad.getBrush());
}
} else {