[gs-commits] mupdf 1.16.1.epub-prerelease-27 Parse FB2 as XML.

[email protected] (Tor Andersson) Wed, 6 Nov 2019 11:48:54 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
commit 06aec98986c9b471a22762b3a04a9fb69c4bdcd0
Author: Tor Andersson <[email protected]>
Date:   Tue Nov 5 12:37:34 2019 +0100

    Parse FB2 as XML.
    
    Parsing it in HTML mode causes the parser to insert extra 'inferred' tags in
    the tree, etc. This is not desirable for FictionBook documents.

diff --git a/source/fitz/html-tags.h b/source/fitz/html-tags.h
index 39e452d..c5a4f3e 100644
--- a/source/fitz/html-tags.h
+++ b/source/fitz/html-tags.h
@@ -33,6 +33,7 @@ HTML_TAG(div,		body,	_NONE,	_NONE,	CONTAINER),
 HTML_TAG(dl,		body,	_NONE,	_NONE,	CONTAINER),
 HTML_TAG(dt,		dl,	_NONE,	_NONE,	0),
 HTML_TAG(em,		body,	_NONE,	_NONE,	0),
+HTML_TAG(fictionbook,	_NONE,	_NONE,	_NONE,	0),
 HTML_TAG(fieldset,	form,	_NONE,	_NONE,	0),
 HTML_TAG(font,		body,	_NONE,	_NONE,	DEPRECATED | DTD_LOOSE),
 HTML_TAG(form,		body,	_NONE,	_NONE,	0),
diff --git a/source/fitz/xml.c b/source/fitz/xml.c
index b12cb36..c2da627 100644
--- a/source/fitz/xml.c
+++ b/source/fitz/xml.c
@@ -528,9 +528,16 @@ static int xml_emit_open_tag(fz_context *ctx, struct parser *parser, char *a, ch
 				*s++ = c;
 			}
 
-			tag_num = find_html_tag(a, b-a);
+			tag_num = find_html_tag(head->u.d.name, b-a);
 			if (tag_num != fz_xml_html_tag__NONE && (html_tags[tag_num].flags & END_FORBIDDEN))
 				autoclose = 1;
+			/* If parsing as HTML, and we see a FictionBook tag, turn off HTML fixups. */
+			if (tag_num == fz_xml_html_tag_fictionbook)
+			{
+				/* Restore original case. */
+				memcpy(head->u.d.name, "FictionBook", 11);
+				parser->for_html = 0;
+			}
 		}
 		else
 			memcpy(head->u.d.name, a, b - a);
diff --git a/source/html/html-parse.c b/source/html/html-parse.c
index add1bfd..680d3b9 100644
--- a/source/html/html-parse.c
+++ b/source/html/html-parse.c
@@ -1050,7 +1050,7 @@ load_fb2_images(fz_context *ctx, fz_xml *root)
 	fz_xml *fictionbook, *binary;
 	fz_tree *images = NULL;
 
-	fictionbook = fz_xml_find(root, "fictionbook");
+	fictionbook = fz_xml_find(root, "FictionBook");
 	for (binary = fz_xml_find_down(fictionbook, "binary"); binary; binary = fz_xml_find_next(binary, "binary"))
 	{
 		const char *id = fz_xml_att(binary, "id");
@@ -1302,7 +1302,7 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha
 
 	fz_try(ctx)
 	{
-		if (fz_xml_find(root, "fictionbook"))
+		if (fz_xml_find(root, "FictionBook"))
 		{
 			g.is_fb2 = 1;
 			fz_parse_css(ctx, g.css, fb2_default_css, "<default:fb2>");
@@ -1364,7 +1364,7 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha
 
 		if (g.is_fb2)
 		{
-			node = fz_xml_find(root, "fictionbook");
+			node = fz_xml_find(root, "FictionBook");
 			node = fz_xml_find_down(node, "description");
 			node = fz_xml_find_down(node, "title-info");
 			node = fz_xml_find_down(node, "book-title");

http://git.ghostscript.com/?p=mupdf.git;a=commit;h=06aec98986c9b471a22762b3a04a9fb69c4bdcd0

--
MuPDF library
Artifex Software, Inc.