[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [krita] plugins/python/comics_project_management_tools: CPMT: move the svg to acbf text to acbf file
From: Wolthera_van_Hövell_tot_Westerflier <null () kde ! org>
Date: 2018-02-28 22:26:47
Message-ID: E1erABT-0005ao-R8 () code ! kde ! org
[Download RAW message or body]
Git commit 95adc320714e7aad82d862d7ef310976ff8bbd60 by Wolthera van Hövell tot \
Westerflier. Committed on 28/02/2018 at 22:25.
Pushed by woltherav into branch 'master'.
CPMT: move the svg to acbf text to acbf file and port to minidom.
This allows us to fix some issues with the output as well.
M +3 -70 plugins/python/comics_project_management_tools/comics_exporter.py
M +54 -1 plugins/python/comics_project_management_tools/exporters/CPMT_ACBF_XML_Exporter.py
https://commits.kde.org/krita/95adc320714e7aad82d862d7ef310976ff8bbd60
diff --git a/plugins/python/comics_project_management_tools/comics_exporter.py \
b/plugins/python/comics_project_management_tools/comics_exporter.py index \
285c7128b86..e2d12ba83a3 100644
--- a/plugins/python/comics_project_management_tools/comics_exporter.py
+++ b/plugins/python/comics_project_management_tools/comics_exporter.py
@@ -23,8 +23,8 @@ An exporter that take the comicsConfig and uses it to generate \
several files. import sys
from pathlib import Path
import zipfile
-import xml.etree.ElementTree as ET
from xml.dom import minidom
+from xml.etree import ElementTree as ET
import types
import re
from PyQt5.QtWidgets import QLabel, QProgressDialog, qApp # For the progress \
dialog. @@ -479,76 +479,9 @@ class comicsExporter():
listOfPoints.append(point)
shapeDesc["boundingBox"] = listOfPoints
if (shape.type() == "KoSvgTextShapeID" and textOnly is True):
- textRoot = ET.fromstring(shape.toSvg())
- paragraph = ET.Element("p")
- if (len(textRoot) > 0):
- self.parseTextChildren(textRoot, paragraph)
- shapeDesc["text"] = ET.tostring(paragraph, "unicode")
+ shapeDesc["text"] = shape.toSvg()
list.append(shapeDesc)
- """
- Function to parse svg text to acbf ready text
- TODO: Move to a new file.
- """
-
- def parseTextChildren(self, elRead, elWrite):
-
- if elRead.text is not None:
- if len(elWrite) > 0:
- if (elWrite[-1].tail is None):
- elWrite[-1].tail = str()
- elWrite[-1].tail = " ".join([elWrite[-1].tail, elRead.text])
- else:
- if elWrite.text is None:
- elWrite.text = elRead.text
- else:
- elWrite.text = " ".join([elWrite.text, elRead.text])
-
- for childNode in elRead:
- fontWeight = childNode.get("font-weight")
- fontItalic = childNode.get("font-style")
- fontStrikeThrough = childNode.get("text-decoration")
- fontBaseLine = childNode.get("baseline-shift")
- newElementMade = False
- if fontItalic is not None:
- if (fontItalic == "italic"):
- newElement = ET.Element("Emphasis")
- newElementMade = True
- elif fontWeight is not None:
- if (fontWeight == "bold" or int(fontWeight) > 400):
- newElement = ET.Element("Strong")
- newElementMade = True
- elif fontStrikeThrough is not None:
- if (fontStrikeThrough == "line-through"):
- newElement = ET.Element("Strikethrough")
- newElementMade = True
- elif fontBaseLine is not None:
- if (fontBaseLine == "super"):
- newElement = ET.Element("Sup")
- newElementMade = True
- elif (fontBaseLine == "sub"):
- newElement = ET.Element("Sub")
- newElementMade = True
-
- if newElementMade is True:
- if (len(childNode) > 0):
- self.parseTextChildren(childNode, newElement)
- else:
- newElement.text = childNode.text
- elWrite.append(newElement)
- else:
- if (len(childNode) > 0):
- self.parseTextChildren(childNode, elWrite)
- else:
- if len(elWrite) > 0:
- if (elWrite[-1].tail is None):
- elWrite[-1].tail = str()
- elWrite[-1].tail = " ".join([elWrite[-1].tail, \
childNode.text])
- else:
- if elWrite.text is None:
- elWrite.text = str()
- elWrite.text = " ".join([elWrite.text, childNode.text])
-
"""
Function to remove layers when they have the given labels.
@@ -575,7 +508,7 @@ class comicsExporter():
title = self.configDictionary["title"]
# Get the appropriate path.
- url = str(exportPath / "metadata"/ str(title + ".cbz"))
+ url = str(exportPath / str(title + ".cbz"))
# Create a zip file.
cbzArchive = zipfile.ZipFile(url, mode="w", compression=zipfile.ZIP_STORED)
diff --git a/plugins/python/comics_project_management_tools/exporters/CPMT_ACBF_XML_Exporter.py \
b/plugins/python/comics_project_management_tools/exporters/CPMT_ACBF_XML_Exporter.py \
index 5c7cc7e4a8b..f01a57faf20 100644
--- a/plugins/python/comics_project_management_tools/exporters/CPMT_ACBF_XML_Exporter.py
+++ b/plugins/python/comics_project_management_tools/exporters/CPMT_ACBF_XML_Exporter.py
@@ -324,7 +324,10 @@ def write_xml(configDictionary = {}, pageData = [], \
pagesLocationList = [], loc textArea = document.createElement("text-area")
textArea.setAttribute("points", " ".join(boundingBoxText))
# TODO: Rotate will require proper global transform api as transform \
info is not written intotext. \
#textArea.setAttribute("text-rotation", str(v["rotate"]))
- paragraph = minidom.parseString(v["text"])
+ svg = minidom.parseString(v["text"])
+ paragraph = minidom.Document()
+ paragraph.appendChild(paragraph.createElement("p"))
+ parseTextChildren(paragraph, svg.documentElement, \
paragraph.documentElement) textArea.appendChild(paragraph.documentElement)
textLayer.appendChild(textArea)
else:
@@ -416,3 +419,53 @@ def createStandAloneACBF(configDictionary, document, location, \
pagesLocationList f.write(document.toprettyxml(indent=" "))
f.close()
return True
+
+"""
+Function to parse svg text to acbf ready text
+"""
+
+def parseTextChildren(document, elRead, elWrite):
+ for childNode in elRead.childNodes:
+ if childNode.nodeType == minidom.Node.TEXT_NODE:
+ if len(childNode.data) > 0:
+ if len(elWrite.childNodes)>0 and str(childNode.data).startswith(" ") \
is False: + elWrite.appendChild(document.createTextNode(" "))
+ elWrite.appendChild(document.createTextNode(str(childNode.data)))
+ elif len(childNode.childNodes)>0:
+ fontWeight = str(childNode.getAttribute("font-weight"))
+ fontItalic = str(childNode.getAttribute("font-style"))
+ fontStrikeThrough = str(childNode.getAttribute("text-decoration"))
+ fontBaseLine = str(childNode.getAttribute("baseline-shift"))
+ newElementMade = False
+ if fontItalic.isalnum():
+ if (fontItalic == "italic"):
+ newElement = document.createElement("Emphasis")
+ newElementMade = True
+ elif fontWeight.isalnum():
+ if (fontWeight == "bold" or int(fontWeight) > 400):
+ newElement = document.createElement("Strong")
+ newElementMade = True
+ elif fontStrikeThrough.isalnum():
+ if (fontStrikeThrough == "line-through"):
+ newElement = document.createElement("Strikethrough")
+ newElementMade = True
+ elif fontBaseLine.isalnum():
+ if (fontBaseLine == "super"):
+ newElement = document.createElement("Sup")
+ newElementMade = True
+ elif (fontBaseLine == "sub"):
+ newElement = document.createElement("Sub")
+ newElementMade = True
+
+ if newElementMade is True:
+ parseTextChildren(document, childNode, newElement)
+ elWrite.appendChild(newElement)
+ else:
+ parseTextChildren(document, childNode, elWrite)
+
+ # If it is not a text node, nor does it have children(which could be \
textnodes), + # we should assume it's empty and ignore it.
+ elWrite.normalize()
+ for e in elWrite.childNodes:
+ if e.nodeType == minidom.Node.TEXT_NODE:
+ e.data = str(e.data).replace(" ", " ")
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic