321 if (classId ==
"null") {
326 }
else if (el.attribute(
"key",
" ") ==
"Clr ") {
328 }
else if (el.attribute(
"key",
" ") ==
"hglC" || el.attribute(
"key",
" ") ==
"sdwC") {
331 }
else if (classId ==
"ShpC") {
334 QDomNode child = el.firstChild();
335 while (!child.isNull()) {
337 child = child.nextSibling();
342 }
else if (classId ==
"CrPt") {
345 QDomNode child = el.firstChild();
346 while (!child.isNull()) {
347 QDomElement childEl = child.toElement();
349 QString type = childEl.attribute(
"type",
"<unknown>");
350 QString key = childEl.attribute(
"key",
"");
352 if (type ==
"Boolean" && key ==
"Cnty") {
353 warnKrita <<
"WARNING: tryParseDescriptor: The points of the curve object contain \'Cnty\' flag which is unsupported by Krita";
356 child = child.nextSibling();
360 if (type !=
"Double") {
369 }
else if (key ==
"Vrtc") {
376 child = child.nextSibling();
381 }
else if (classId ==
"Pnt ") {
384 QDomNode child = el.firstChild();
385 while (!child.isNull()) {
386 QDomElement childEl = child.toElement();
388 QString type = childEl.attribute(
"type",
"<unknown>");
389 QString key = childEl.attribute(
"key",
"");
390 QString unit = childEl.attribute(
"unit",
"");
392 if (type !=
"Double" && !(type ==
"UnitFloat" && unit ==
"#Prc")) {
401 }
else if (key ==
"Vrtc") {
408 child = child.nextSibling();
413 }
else if (classId ==
"KisPattern") {
414 QByteArray patternData;
417 QDomNode child = el.firstChild();
418 while (!child.isNull()) {
419 QDomElement childEl = child.toElement();
421 QString type = childEl.attribute(
"type",
"<unknown>");
422 QString key = childEl.attribute(
"key",
"");
424 if (type ==
"Text" && key ==
"Idnt") {
425 patternUuid = childEl.attribute(
"value",
"").trimmed();
428 if (type ==
"KisPatternData" && key ==
"Data") {
429 QDomNode dataNode = child.firstChild();
431 if (!dataNode.isCDATASection()) {
432 warnKrita <<
"WARNING: failed to parse KisPatternData XML section!";
436 QDomCDATASection dataSection = dataNode.toCDATASection();
437 QByteArray data = dataSection.data().toLatin1();
438 data = QByteArray::fromBase64(data);
439 data = qUncompress(data);
441 if (data.isEmpty()) {
442 warnKrita <<
"WARNING: failed to parse KisPatternData XML section!";
449 child = child.nextSibling();
452 if (!patternUuid.isEmpty() && !patternData.isEmpty()) {
453 QString fileName = QString(
"%1.pat").arg(patternUuid);
457 QBuffer buffer(&patternData);
458 buffer.open(QIODevice::ReadOnly);
460 if (pattern->loadPatFromDevice(&buffer) && pattern->valid()) {
461 catcher.
addPattern(path, pattern, patternUuid);
467 warnKrita <<
"WARNING: failed to load KisPattern XML section!" <<
ppVar(patternUuid);
470 }
else if (classId ==
"Ptrn") {
474 QDomNode child = el.firstChild();
475 while (!child.isNull()) {
476 QDomElement childEl = child.toElement();
478 QString type = childEl.attribute(
"type",
"<unknown>");
479 QString key = childEl.attribute(
"key",
"");
481 if (type ==
"Text" && key ==
"Idnt") {
482 patternUuid = childEl.attribute(
"value",
"");
483 }
else if (type ==
"Text" && key ==
"Nm ") {
484 patternName = childEl.attribute(
"value",
"");
486 warnKrita <<
"WARNING: unrecognized pattern-ref section key:" <<
ppVar(type) <<
ppVar(key);
489 child = child.nextSibling();
494 }
else if (classId ==
"Grdn") {
495 QString gradientName;
496 qreal gradientSmoothness = 100.0;
507 QDomNode child = el.firstChild();
508 while (!child.isNull()) {
509 QDomElement childEl = child.toElement();
511 QString type = childEl.attribute(
"type",
"<unknown>");
512 QString key = childEl.attribute(
"key",
"");
514 if (type ==
"Text" && key ==
"Nm ") {
515 gradientName = childEl.attribute(
"value",
"");
516 }
else if (type ==
"Enum" && key ==
"GrdF") {
517 QString typeId = childEl.attribute(
"typeId",
"");
518 QString
value = childEl.attribute(
"value",
"");
520 if (typeId !=
"GrdF" ||
value !=
"CstS") {
521 warnKrita <<
"WARNING: Unsupported gradient type (probably, noise-based):" <<
value;
524 }
else if (type ==
"Double" && key ==
"Intr") {
526 gradientSmoothness = 100.0 *
value / 4096.0;
527 }
else if (type ==
"List" && key ==
"Clrs") {
529 }
else if (type ==
"List" && key ==
"Trns") {
533 child = child.nextSibling();
536 if (colors.size() < transparencies.size()) {
537 const KoColor lastColor = !colors.isEmpty() ? colors.last() :
KoColor();
539 while (colors.size() != transparencies.size()) {
540 const int index = colors.size();
541 colors.append(lastColor);
542 startLocations.append(transpStartLocations[index]);
543 middleOffsets.append(transpMiddleOffsets[index]);
544 types.append(lastType);
548 if (colors.size() > transparencies.size()) {
549 const qreal lastTransparency = !transparencies.isEmpty() ? transparencies.last() : 1.0;
550 while (colors.size() != transparencies.size()) {
551 const int index = transparencies.size();
552 transparencies.append(lastTransparency);
553 transpStartLocations.append(startLocations[index]);
554 transpMiddleOffsets.append(middleOffsets[index]);
558 if (colors.size() == 1) {
559 colors.append(colors.last());
560 startLocations.append(1.0);
561 middleOffsets.append(0.5);
564 transparencies.append(transparencies.last());
565 transpStartLocations.append(1.0);
566 transpMiddleOffsets.append(0.5);
579 const QString fileName = QFileInfo(gradientName).fileName() +
".ggr";
581 Q_UNUSED(gradientSmoothness);
582 gradient->setName(gradientName);
584 if (colors.size() >= 2) {
585 for (
int i = 1; i < colors.size(); i++) {
586 KoColor startColor = colors[i - 1];
591 qreal start = startLocations[i - 1];
592 qreal end = startLocations[i];
593 qreal middle = start + middleOffsets[i - 1] * (end - start);
600 gradient->setValid(
true);
601 gradient->updatePreview();
603 gradient->setValid(
false);
607 }
else if (classId ==
"Trnf") {
616 QDomNode child = el.firstChild();
617 while (!child.isNull()) {
618 QDomElement childEl = child.toElement();
620 QString type = childEl.attribute(
"type",
"<unknown>");
621 QString key = childEl.attribute(
"key",
"");
625 if (type ==
"Double") {
628 }
else if (key ==
"xy") {
630 }
else if (key ==
"yx") {
632 }
else if (key ==
"yy") {
634 }
else if (key ==
"tx") {
636 }
else if (key ==
"ty") {
641 child = child.nextSibling();
643 catcher.
addTransform(path, QTransform(xx, xy, yx, yy, tx, ty));
644 }
else if (classId ==
"classFloatRect") {
648 QDomNode child = el.firstChild();
649 while (!child.isNull()) {
650 QDomElement childEl = child.toElement();
652 QString type = childEl.attribute(
"type",
"<unknown>");
653 QString key = childEl.attribute(
"key",
"");
657 if (type ==
"Double") {
660 }
else if (key ==
"Left") {
662 }
else if (key ==
"Btom") {
664 }
else if (key ==
"Rght") {
668 child = child.nextSibling();
671 if (el.attribute(
"key",
" ") ==
"keyOriginShapeBBox") {
676 }
else if (classId ==
"unitRect") {
679 QDomNode child = el.firstChild();
681 while (!child.isNull()) {
682 QDomElement childEl = child.toElement();
684 QString type = childEl.attribute(
"type",
"<unknown>");
685 QString key = childEl.attribute(
"key",
"");
686 unit = childEl.attribute(
"unit", unit);
690 if (type ==
"UnitFloat") {
693 }
else if (key ==
"Left") {
695 }
else if (key ==
"Btom") {
697 }
else if (key ==
"Rght") {
701 child = child.nextSibling();
717 QString type = el.attribute(
"type",
"<unknown>");
718 QString key = el.attribute(
"key",
"");
720 if (type ==
"Descriptor") {
721 QString classId = el.attribute(
"classId",
"<noClassId>");
722 QString containerName = key.isEmpty() ? classId : key;
723 QString containerPath =
buildPath(parentPath, containerName);
726 QDomNode child = el.firstChild();
727 while (!child.isNull()) {
728 parseElement(child.toElement(), containerPath, catcher);
729 child = child.nextSibling();
732 }
else if (type ==
"List") {
735 QString containerName = key;
736 QString containerPath =
buildPath(parentPath, containerName);
738 QDomNode child = el.firstChild();
739 while (!child.isNull()) {
740 parseElement(child.toElement(), containerPath, catcher);
741 child = child.nextSibling();
745 }
else if (type ==
"Double") {
748 }
else if (type ==
"UnitFloat") {
749 QString unit = el.attribute(
"unit",
"<unknown>");
752 }
else if (type ==
"Text") {
753 QString
v = el.attribute(
"value",
"");
755 }
else if (type ==
"Enum") {
756 QString
v = el.attribute(
"value",
"");
757 QString typeId = el.attribute(
"typeId",
"<unknown>");
759 }
else if (type ==
"Integer") {
762 }
else if (type ==
"Boolean") {
765 }
else if (type ==
"RawData") {
766 QDomNode dataNode = el.firstChild();
768 if (!dataNode.isCDATASection()) {
769 warnKrita <<
"WARNING: failed to parse RawData XML section!";
773 QDomCDATASection dataSection = dataNode.toCDATASection();
774 QByteArray data = dataSection.data().toLatin1();
775 data = QByteArray::fromBase64(data);
777 if (data.isEmpty()) {
778 warnKrita <<
"WARNING: failed to parse RawData XML section!";
782 warnKrita <<
"WARNING: XML (ASL) Unknown element type:" << type <<
ppVar(parentPath) <<
ppVar(key);