28def write_xml(configDictionary = {}, pageData = [], pagesLocationList = [], locationBasic = str(), locationStandAlone = str(), projectUrl = str()):
29 acbfGenreList = [
"science_fiction",
"fantasy",
"adventure",
"horror",
"mystery",
"crime",
"military",
"real_life",
"superhero",
"humor",
"western",
"manga",
"politics",
"caricature",
"sports",
"history",
"biography",
"education",
"computer",
"religion",
"romance",
"children",
"non-fiction",
"adult",
"alternative",
"other",
"artbook"]
30 acbfAuthorRolesList = [
"Writer",
"Adapter",
"Artist",
"Penciller",
"Inker",
"Colorist",
"Letterer",
"Cover Artist",
"Photographer",
"Editor",
"Assistant Editor",
"Translator",
"Other",
"Designer"]
31 document = QDomDocument()
32 root = document.createElement(
"ACBF")
33 root.setAttribute(
"xmlns",
"http://www.acbf.info/xml/acbf/1.1")
34 document.appendChild(root)
38 if "acbfStyles" in configDictionary.keys():
39 stylesDictionary = configDictionary.get(
"acbfStyles", {})
40 emphasisStyle = stylesDictionary.get(
"emphasis", {})
41 strongStyle = stylesDictionary.get(
"strong", {})
44 for key
in sorted(stylesDictionary.keys()):
45 style = stylesDictionary.get(key, {})
46 if key ==
"emphasis" or key ==
"strong":
47 styleClass = key+
" {\n"
49 styleClass =
"text-area {\n"
50 elif key ==
"general":
52 elif key ==
"inverted":
53 styleClass =
"text-area[inverted=\"true\"] {\n"
55 styleClass =
"text-area[type=\""+key+
"\"] {\n"
56 styleString += tabs+styleClass
57 if "color" in style.keys():
58 styleString += tabs+tabs+
"color:"+style[
"color"]+
";\n"
59 if "font" in style.keys():
61 genericfont = style.get(
"genericfont",
"sans-serif")
62 if isinstance(fonts, list):
63 styleString += tabs+tabs+
"font-family:\""+str(
"\", \"").join(fonts)+
"\", "+genericfont+
";\n"
65 styleString += tabs+tabs+
"font-family:\""+fonts+
"\", "+genericfont+
";\n"
66 if "bold" in style.keys():
68 styleString += tabs+tabs+
"font-weight: bold;\n"
69 if "ital" in style.keys():
71 styleString += tabs+tabs+
"font-style: italic;\n"
73 styleString += tabs+tabs+
"font-style: normal;\n"
74 styleString += tabs+
"}\n"
75 style = document.createElement(
"style")
76 style.setAttribute(
"type",
"text/css")
77 style.appendChild(document.createTextNode(styleString))
78 root.appendChild(style)
81 meta = document.createElement(
"meta-data")
83 translationFolder = configDictionary.get(
"translationLocation",
"translations")
84 fullTranslationPath = os.path.join(projectUrl, translationFolder)
85 poParser = po_parser.po_file_parser(fullTranslationPath,
True)
87 bookInfo = document.createElement(
"book-info")
88 if "authorList" in configDictionary.keys():
89 for authorE
in range(len(configDictionary[
"authorList"])):
90 author = document.createElement(
"author")
91 authorDict = configDictionary[
"authorList"][authorE]
92 if "first-name" in authorDict.keys():
93 authorN = document.createElement(
"first-name")
94 authorN.appendChild(document.createTextNode(str(authorDict[
"first-name"])))
95 author.appendChild(authorN)
96 if "last-name" in authorDict.keys():
97 authorN = document.createElement(
"last-name")
98 authorN.appendChild(document.createTextNode(str(authorDict[
"last-name"])))
99 author.appendChild(authorN)
100 if "initials" in authorDict.keys():
101 authorN = document.createElement(
"middle-name")
102 authorN.appendChild(document.createTextNode(str(authorDict[
"initials"])))
103 author.appendChild(authorN)
104 if "nickname" in authorDict.keys():
105 authorN = document.createElement(
"nickname")
106 authorN.appendChild(document.createTextNode(str(authorDict[
"nickname"])))
107 author.appendChild(authorN)
108 if "homepage" in authorDict.keys():
109 authorN = document.createElement(
"home-page")
110 authorN.appendChild(document.createTextNode(str(authorDict[
"homepage"])))
111 author.appendChild(authorN)
112 if "email" in authorDict.keys():
113 authorN = document.createElement(
"email")
114 authorN.appendChild(document.createTextNode(str(authorDict[
"email"])))
115 author.appendChild(authorN)
116 if "role" in authorDict.keys():
117 if str(authorDict[
"role"]).title()
in acbfAuthorRolesList:
118 author.setAttribute(
"activity", str(authorDict[
"role"]))
119 if "language" in authorDict.keys():
120 author.setAttribute(
"lang", str(authorDict[
"language"]).replace(
"_",
"-"))
121 bookInfo.appendChild(author)
122 bookTitle = document.createElement(
"book-title")
123 if "title" in configDictionary.keys():
124 bookTitle.appendChild(document.createTextNode(str(configDictionary[
"title"])))
126 bookTitle.appendChild(document.createTextNode(str(
"Comic with no Name")))
127 bookInfo.appendChild(bookTitle)
130 if "genre" in configDictionary.keys():
131 genreListConf = configDictionary[
"genre"]
132 if isinstance(configDictionary[
"genre"], dict):
133 genreListConf = configDictionary[
"genre"].keys()
134 for genre
in genreListConf:
135 genreModified = str(genre).lower()
136 genreModified.replace(
" ",
"_")
137 if genreModified
in acbfGenreList:
138 bookGenre = document.createElement(
"genre")
139 bookGenre.appendChild(document.createTextNode(str(genreModified)))
140 if isinstance(configDictionary[
"genre"], dict):
141 genreMatch = configDictionary[
"genre"][genreModified]
143 bookGenre.setAttribute(
"match", str(genreMatch))
144 bookInfo.appendChild(bookGenre)
146 extraGenres.append(genre)
148 if "characters" in configDictionary.keys():
149 character = document.createElement(
"characters")
150 for name
in configDictionary[
"characters"]:
151 char = document.createElement(
"name")
152 char.appendChild(document.createTextNode(str(name)))
153 character.appendChild(char)
154 bookInfo.appendChild(character)
156 annotation = document.createElement(
"annotation")
157 if "summary" in configDictionary.keys():
158 paragraphList = str(configDictionary[
"summary"]).split(
"\n")
159 for para
in paragraphList:
160 p = document.createElement(
"p")
161 p.appendChild(document.createTextNode(str(para)))
162 annotation.appendChild(p)
164 p = document.createElement(
"p")
165 p.appendChild(document.createTextNode(str(
"There was no summary upon generation of this file.")))
166 annotation.appendChild(p)
167 bookInfo.appendChild(annotation)
169 keywords = document.createElement(
"keywords")
170 stringKeywordsList = []
171 for key
in extraGenres:
172 stringKeywordsList.append(str(key))
173 if "otherKeywords" in configDictionary.keys():
174 for key
in configDictionary[
"otherKeywords"]:
175 stringKeywordsList.append(str(key))
176 if "format" in configDictionary.keys():
177 for key
in configDictionary[
"format"]:
178 stringKeywordsList.append(str(key))
179 keywords.appendChild(document.createTextNode(
", ".join(stringKeywordsList)))
180 bookInfo.appendChild(keywords)
183 coverpage = document.createElement(
"coverpage")
184 if "pages" in configDictionary.keys():
185 if "cover" in configDictionary.keys():
187 pageList = configDictionary[
"pages"]
188 coverNumber = max([pageList.index(configDictionary[
"cover"]), 0])
189 image = document.createElement(
"image")
190 if len(pagesLocationList) >= coverNumber:
191 coverpageurl = pagesLocationList[coverNumber]
192 image.setAttribute(
"href", os.path.basename(coverpageurl))
193 coverpage.appendChild(image)
194 bookInfo.appendChild(coverpage)
196 if "language" in configDictionary.keys():
197 language = document.createElement(
"languages")
198 textlayer = document.createElement(
"text-layer")
199 textlayer.setAttribute(
"lang", str(configDictionary[
"language"]).replace(
"_",
"-"))
200 textlayer.setAttribute(
"show",
"false")
201 textlayerNative = document.createElement(
"text-layer")
202 textlayerNative.setAttribute(
"lang", str(configDictionary[
"language"]).replace(
"_",
"-"))
203 textlayerNative.setAttribute(
"show",
"true")
204 language.appendChild(textlayer)
205 language.appendChild(textlayerNative)
206 translationComments = {}
207 for lang
in poParser.get_translation_list():
208 textlayer = document.createElement(
"text-layer")
209 textlayer.setAttribute(
"lang", lang)
210 textlayer.setAttribute(
"show",
"true")
211 language.appendChild(textlayer)
212 translationComments[lang] = []
213 translation = poParser.get_entry_for_key(
"@meta-title "+configDictionary[
"title"], lang).
get(
"trans",
None)
214 if translation
is not None:
215 bookTitleTr = document.createElement(
"book-title")
216 bookTitleTr.setAttribute(
"lang", lang)
217 bookTitleTr.appendChild(document.createTextNode(translation))
218 bookInfo.insertAfter(bookTitleTr, bookTitle)
219 translation = poParser.get_entry_for_key(
"@meta-summary "+configDictionary[
"summary"], lang).
get(
"trans",
None)
220 if translation
is not None:
221 annotationTr = document.createElement(
"annotation")
222 annotationTr.setAttribute(
"lang", lang)
223 paragraph = document.createElement(
"p")
224 paragraph.appendChild(document.createTextNode(translation))
225 annotationTr.appendChild(paragraph)
226 bookInfo.insertAfter(annotationTr, annotation)
227 translation = poParser.get_entry_for_key(
"@meta-keywords "+
", ".join(configDictionary[
"otherKeywords"]), lang).
get(
"trans",
None)
228 if translation
is not None:
229 keywordsTr = document.createElement(
"keywords")
230 keywordsTr.setAttribute(
"lang", lang)
231 keywordsTr.appendChild(document.createTextNode(translation))
232 bookInfo.insertAfter(keywordsTr, keywords)
233 bookInfo.appendChild(language)
235 bookTitle.setAttribute(
"lang", str(configDictionary[
"language"]).replace(
"_",
"-"))
236 annotation.setAttribute(
"lang", str(configDictionary[
"language"]).replace(
"_",
"-"))
237 keywords.setAttribute(
"lang", str(configDictionary[
"language"]).replace(
"_",
"-"))
239 if "databaseReference" in configDictionary.keys():
240 database = document.createElement(
"databaseref")
241 dbRef = configDictionary[
"databaseReference"]
242 database.setAttribute(
"dbname", dbRef.get(
"name",
""))
243 if "type" in dbRef.keys():
244 database.setAttribute(
"type", dbRef[
"type"])
245 database.appendChild(document.createTextNode(dbRef.get(
"entry",
"")))
246 bookInfo.appendChild(database)
248 if "seriesName" in configDictionary.keys():
249 sequence = document.createElement(
"sequence")
250 sequence.setAttribute(
"title", configDictionary[
"seriesName"])
251 if "seriesVolume" in configDictionary.keys():
252 sequence.setAttribute(
"volume", str(configDictionary[
"seriesVolume"]))
253 if "seriesNumber" in configDictionary.keys():
254 sequence.appendChild(document.createTextNode(str(configDictionary[
"seriesNumber"])))
256 sequence.appendChild(document.createTextNode(str(0)))
257 bookInfo.appendChild(sequence)
258 contentrating = document.createElement(
"content-rating")
260 if "rating" in configDictionary.keys():
261 contentrating.appendChild(document.createTextNode(str(configDictionary[
"rating"])))
263 contentrating.appendChild(document.createTextNode(str(
"Unrated.")))
264 if "ratingSystem" in configDictionary.keys():
265 contentrating.setAttribute(
"type", configDictionary[
"ratingSystem"])
266 bookInfo.appendChild(contentrating)
268 if "readingDirection" in configDictionary.keys():
269 readingDirection = document.createElement(
"reading-direction")
270 if configDictionary[
"readingDirection"] ==
"rightToLeft":
271 readingDirection.appendChild(document.createTextNode(str(
"RTL")))
273 readingDirection.appendChild(document.createTextNode(str(
"LTR")))
274 bookInfo.appendChild(readingDirection)
275 meta.appendChild(bookInfo)
277 publisherInfo = document.createElement(
"publish-info")
278 if "publisherName" in configDictionary.keys():
279 publisherName = document.createElement(
"publisher")
280 publisherName.appendChild(document.createTextNode(str(configDictionary[
"publisherName"])))
281 publisherInfo.appendChild(publisherName)
282 if "publishingDate" in configDictionary.keys():
283 publishingDate = document.createElement(
"publish-date")
284 publishingDate.setAttribute(
"value", configDictionary[
"publishingDate"])
285 publishingDate.appendChild(document.createTextNode(QDate.fromString(configDictionary[
"publishingDate"], Qt.DateFormat.ISODate).toString(Qt.DateFormat.SystemLocaleLongDate)))
286 publisherInfo.appendChild(publishingDate)
287 if "publisherCity" in configDictionary.keys():
288 publishCity = document.createElement(
"city")
289 publishCity.appendChild(document.createTextNode(str(configDictionary[
"publisherCity"])))
290 publisherInfo.appendChild(publishCity)
291 if "isbn-number" in configDictionary.keys():
292 publishISBN = document.createElement(
"isbn")
293 publishISBN.appendChild(document.createTextNode(str(configDictionary[
"isbn-number"])))
294 publisherInfo.appendChild(publishISBN)
295 license = str(configDictionary.get(
"license",
""))
296 if license.isspace()
is False and len(license) > 0:
297 publishLicense = document.createElement(
"license")
298 publishLicense.appendChild(document.createTextNode(license))
299 publisherInfo.appendChild(publishLicense)
301 meta.appendChild(publisherInfo)
303 documentInfo = document.createElement(
"document-info")
306 if "acbfAuthor" in configDictionary.keys():
307 if isinstance(configDictionary[
"acbfAuthor"], list):
308 for e
in configDictionary[
"acbfAuthor"]:
309 acbfAuthor = document.createElement(
"author")
311 if "first-name" in authorDict.keys():
312 authorN = document.createElement(
"first-name")
313 authorN.appendChild(document.createTextNode(str(authorDict[
"first-name"])))
314 acbfAuthor.appendChild(authorN)
315 if "last-name" in authorDict.keys():
316 authorN = document.createElement(
"last-name")
317 authorN.appendChild(document.createTextNode(str(authorDict[
"last-name"])))
318 acbfAuthor.appendChild(authorN)
319 if "initials" in authorDict.keys():
320 authorN = document.createElement(
"middle-name")
321 authorN.appendChild(document.createTextNode(str(authorDict[
"initials"])))
322 acbfAuthor.appendChild(authorN)
323 if "nickname" in authorDict.keys():
324 authorN = document.createElement(
"nickname")
325 authorN.appendChild(document.createTextNode(str(authorDict[
"nickname"])))
326 acbfAuthor.appendChild(authorN)
327 if "homepage" in authorDict.keys():
328 authorN = document.createElement(
"home-page")
329 authorN.appendChild(document.createTextNode(str(authorDict[
"homepage"])))
330 acbfAuthor.appendChild(authorN)
331 if "email" in authorDict.keys():
332 authorN = document.createElement(
"email")
333 authorN.appendChild(document.createTextNode(str(authorDict[
"email"])))
334 acbfAuthor.appendChild(authorN)
335 if "language" in authorDict.keys():
336 acbfAuthor.setAttribute(
"lang", str(authorDict[
"language"]).replace(
"_",
"-"))
337 documentInfo.appendChild(acbfAuthor)
339 acbfAuthor = document.createElement(
"author")
340 acbfAuthorNick = document.createElement(
"nickname")
341 acbfAuthorNick.appendChild(document.createTextNode(str(configDictionary[
"acbfAuthor"])))
342 acbfAuthor.appendChild(acbfAuthorNick)
343 documentInfo.appendChild(acbfAuthor)
345 acbfAuthor = document.createElement(
"author")
346 acbfAuthorNick = document.createElement(
"nickname")
347 acbfAuthorNick.appendChild(document.createTextNode(str(
"Anon")))
348 acbfAuthor.appendChild(acbfAuthorNick)
349 documentInfo.appendChild(acbfAuthor)
351 acbfDate = document.createElement(
"creation-date")
352 now = QDate.currentDate()
353 acbfDate.setAttribute(
"value", now.toString(Qt.DateFormat.ISODate))
354 acbfDate.appendChild(document.createTextNode(QLocale().toString(now, QLocale.FormatType.LongFormat)))
355 documentInfo.appendChild(acbfDate)
357 if "acbfSource" in configDictionary.keys():
358 acbfSource = document.createElement(
"source")
359 acbfSourceP = document.createElement(
"p")
360 acbfSourceP.appendChild(document.createTextNode(str(configDictionary[
"acbfSource"])))
361 acbfSource.appendChild(acbfSourceP)
362 documentInfo.appendChild(acbfSource)
364 if "acbfID" in configDictionary.keys():
365 acbfID = document.createElement(
"id")
366 acbfID.appendChild(document.createTextNode(str(configDictionary[
"acbfID"])))
367 documentInfo.appendChild(acbfID)
369 if "acbfVersion" in configDictionary.keys():
370 acbfVersion = document.createElement(
"version")
371 acbfVersion.appendChild(document.createTextNode(str(configDictionary[
"acbfVersion"])))
372 documentInfo.appendChild(acbfVersion)
374 if "acbfHistory" in configDictionary.keys():
375 if len(configDictionary[
"acbfHistory"])>0:
376 acbfHistory = document.createElement(
"history")
377 for h
in configDictionary[
"acbfHistory"]:
378 p = document.createElement(
"p")
379 p.appendChild(document.createTextNode(str(h)))
380 acbfHistory.appendChild(p)
381 documentInfo.appendChild(acbfHistory)
382 meta.appendChild(documentInfo)
384 root.appendChild(meta)
386 body = document.createElement(
"body")
388 references = document.createElement(
"references")
390 def figure_out_type(svg = QDomElement()):
392 skipList = [
"speech",
"emphasis",
"strong",
"inverted",
"general"]
393 if svg.attribute(
"text-anchor") ==
"middle" or svg.attribute(
"text-align") ==
"center":
394 if "acbfStyles" in configDictionary.keys():
395 stylesDictionary = configDictionary.get(
"acbfStyles", {})
396 for key
in stylesDictionary.keys():
397 if key
not in skipList:
398 style = stylesDictionary.get(key, {})
399 font = style.get(
"font",
"")
400 if isinstance(fonts, list):
401 if svg.attribute(
"family")
in font:
403 elif svg.attribute(
"family") == font:
407 elif svg.attribute(
"text-align") ==
"justified":
413 if svg.hasAttribute(
"fill"):
414 stylesDictionary = configDictionary.get(
"acbfStyles", {})
415 key = stylesDictionary.get(
"general", {})
416 regular = QColor(key.get(
"color",
"#000000"))
417 key = stylesDictionary.get(
"inverted", {})
418 invertedColor = QColor(key.get(
"color",
"#FFFFFF"))
419 textColor = QColor(svg.attribute(
"fill"))
421 lightnessR = (0.21 * regular.redF()) + (0.72 * regular.greenF()) + (0.07 * regular.blueF())
422 lightnessI = (0.21 * invertedColor.redF()) + (0.72 * invertedColor.greenF()) + (0.07 * invertedColor.blueF())
423 lightnessT = (0.21 * textColor.redF()) + (0.72 * textColor.greenF()) + (0.07 * textColor.blueF())
424 if lightnessI > lightnessR:
425 if lightnessT > (lightnessI+lightnessR)*0.5:
428 if lightnessT < (lightnessI+lightnessR)*0.5:
430 return [type, inverted]
432 listOfPageColors = []
434 for p
in range(0, len(pagesLocationList)):
435 page = pagesLocationList[p]
438 imageRect = imageFile.rect().adjusted(0, 0, -1, -1)
439 pageColor =
findDominantColor([imageFile.pixelColor(imageRect.topLeft()), imageFile.pixelColor(imageRect.topRight()), imageFile.pixelColor(imageRect.bottomRight()), imageFile.pixelColor(imageRect.bottomLeft())])
440 listOfPageColors.append(pageColor)
442 if "language" in configDictionary.keys():
443 language = str(configDictionary[
"language"]).replace(
"_",
"-")
444 textLayer = document.createElement(
"text-layer")
445 textLayer.setAttribute(
"lang", language)
447 transform = data[
"transform"]
449 listOfTextColors = []
450 for v
in data[
"vector"]:
452 listOfBoundaryColors = []
453 for point
in v[
"boundingBox"]:
454 offset = QPointF(transform[
"offsetX"], transform[
"offsetY"])
455 pixelPoint = QPointF(point.x() * transform[
"resDiff"], point.y() * transform[
"resDiff"])
456 newPoint = pixelPoint - offset
457 x = max(0, min(imageRect.width(), int(newPoint.x() * transform[
"scaleWidth"])))
458 y = max(0, min(imageRect.height(), int(newPoint.y() * transform[
"scaleHeight"])))
459 listOfBoundaryColors.append(imageFile.pixelColor(x, y))
460 pointText = str(x) +
"," + str(y)
461 boundingBoxText.append(pointText)
464 if "text" in v.keys():
465 textArea = document.createElement(
"text-area")
466 textArea.setAttribute(
"points",
" ".join(boundingBoxText))
469 svg.setContent(v[
"text"])
470 figureOut = figure_out_type(svg.documentElement())
472 inverted = figureOut[1]
473 paragraph = QDomDocument()
474 paragraph.appendChild(paragraph.createElement(
"p"))
475 parseTextChildren(paragraph, svg.documentElement(), paragraph.documentElement(), emphasisStyle, strongStyle)
476 textArea.appendChild(paragraph.documentElement())
477 textArea.setAttribute(
"bgcolor", mainColor.name())
479 textArea.setAttribute(
"type", type)
480 if inverted
is not None:
481 textArea.setAttribute(
"inverted", inverted)
482 textLayer.appendChild(textArea)
485 f[
"points"] =
" ".join(boundingBoxText)
487 listOfTextColors.append(mainColor)
489 textLayerList = document.createElement(
"trlist")
490 for lang
in poParser.get_translation_list():
491 textLayerTr = document.createElement(
"text-layer")
492 textLayerTr.setAttribute(
"lang", lang)
493 for i
in range(len(data[
"vector"])):
497 for point
in v[
"boundingBox"]:
498 offset = QPointF(transform[
"offsetX"], transform[
"offsetY"])
499 pixelPoint = QPointF(point.x() * transform[
"resDiff"], point.y() * transform[
"resDiff"])
500 newPoint = pixelPoint - offset
501 x = int(newPoint.x() * transform[
"scaleWidth"])
502 y = int(newPoint.y() * transform[
"scaleHeight"])
503 pointText = str(x) +
"," + str(y)
504 boundingBoxText.append(pointText)
506 if "text" in v.keys():
507 textArea = document.createElement(
"text-area")
508 textArea.setAttribute(
"points",
" ".join(boundingBoxText))
511 svg.setContent(v[
"text"])
512 figureOut = figure_out_type(svg.documentElement())
514 inverted = figureOut[1]
515 string = re.sub(
r"<\/*?text.*?>",
'', str(v[
"text"]))
516 string = re.sub(
r"\s+?",
" ", string)
517 translationEntry = poParser.get_entry_for_key(string, lang)
518 string = translationEntry.get(
"trans", string)
519 svg.setContent(
"<text>"+string+
"</text>")
520 paragraph = QDomDocument()
521 paragraph.appendChild(paragraph.createElement(
"p"))
522 parseTextChildren(paragraph, svg.documentElement(), paragraph.documentElement(), emphasisStyle, strongStyle)
523 if "translComment" in translationEntry.keys():
524 key = translationEntry[
"translComment"]
526 listOfComments = translationComments[lang]
528 if key
in listOfComments:
529 index = listOfComments.index(key)+1
531 listOfComments.append(key)
532 index = len(listOfComments)
533 translationComments[lang] = listOfComments
534 refID =
"-".join([
"tn", lang, str(index)])
535 anchor = document.createElement(
"a")
536 anchor.setAttribute(
"href",
"#"+refID)
537 anchor.appendChild(document.createTextNode(
"*"))
538 paragraph.documentElement().appendChild(anchor)
539 textArea.appendChild(paragraph.documentElement())
540 textLayerTr.appendChild(textArea)
542 textArea.setAttribute(
"type", type)
543 if inverted
is not None:
544 textArea.setAttribute(
"inverted", inverted)
545 textArea.setAttribute(
"bgcolor", listOfTextColors[i].name())
546 if textLayerTr.hasChildNodes():
548 textLayerList.appendChild(textLayerTr)
552 if page
is not coverpageurl:
553 pg = document.createElement(
"page")
554 image = document.createElement(
"image")
555 image.setAttribute(
"href", os.path.basename(page))
556 pg.appendChild(image)
557 if "acbf_title" in data[
"keys"]:
558 title = document.createElement(
"title")
559 title.setAttribute(
"lang", language)
560 title.appendChild(document.createTextNode(str(data[
"title"])))
561 pg.appendChild(title)
562 for lang
in poParser.get_translation_list():
564 titlekey =
"@page-title "+str(data[
"title"])
565 translationEntry = poParser.get_entry_for_key(titlekey, lang)
566 titleTrans = translationEntry.get(
"trans", titleTrans)
567 if titleTrans.isspace()
is False:
568 titleT = document.createElement(
"title")
569 titleT.setAttribute(
"lang", lang)
570 titleT.appendChild(document.createTextNode(titleTrans))
571 pg.appendChild(titleT)
572 if "acbf_none" in data[
"keys"]:
573 pg.setAttribute(
"transition",
"none")
574 if "acbf_blend" in data[
"keys"]:
575 pg.setAttribute(
"transition",
"blend")
576 if "acbf_fade" in data[
"keys"]:
577 pg.setAttribute(
"transition",
"fade")
578 if "acbf_horizontal" in data[
"keys"]:
579 pg.setAttribute(
"transition",
"scroll_right")
580 if "acbf_vertical" in data[
"keys"]:
581 pg.setAttribute(
"transition",
"scroll_down")
582 if textLayer.hasChildNodes():
583 pg.appendChild(textLayer)
584 pg.setAttribute(
"bgcolor", pageColor.name())
585 for n
in range(0, textLayerList.childNodes().size()):
586 node = textLayerList.childNodes().at(n)
589 frame = document.createElement(
"frame")
590 frame.setAttribute(
"points", f[
"points"])
591 pg.appendChild(frame)
595 frame = document.createElement(
"frame")
596 frame.setAttribute(
"points", f[
"points"])
597 coverpage.appendChild(frame)
598 coverpage.appendChild(textLayer)
599 for n
in range(0, textLayerList.childNodes().size()):
600 node = textLayerList.childNodes().at(n)
601 coverpage.appendChild(node)
603 body.setAttribute(
"bgcolor", bodyColor.name())
605 if configDictionary.get(
"includeTranslComment",
False):
606 for lang
in translationComments.keys():
607 for key
in translationComments[lang]:
608 index = translationComments[lang].index(key)+1
609 refID =
"-".join([
"tn", lang, str(index)])
610 ref = document.createElement(
"reference")
611 ref.setAttribute(
"lang", lang)
612 ref.setAttribute(
"id", refID)
613 transHeaderStr = configDictionary.get(
"translatorHeader",
"Translator's Notes")
614 transHeaderStr = poParser.get_entry_for_key(
"@meta-translator "+transHeaderStr, lang).
get(
"trans", transHeaderStr)
615 translatorHeader = document.createElement(
"p")
616 translatorHeader.appendChild(document.createTextNode(transHeaderStr+
":"))
617 ref.appendChild(translatorHeader)
618 refPara = document.createElement(
"p")
619 refPara.appendChild(document.createTextNode(key))
620 ref.appendChild(refPara)
621 references.appendChild(ref)
623 root.appendChild(body)
624 if references.childNodes().size():
625 root.appendChild(references)
627 f = open(locationBasic,
'w', newline=
"", encoding=
"utf-8")
628 f.write(document.toString(indent=2))
631 success =
createStandAloneACBF(configDictionary, document, locationStandAlone, pagesLocationList)