You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by ja...@apache.org on 2015/06/02 16:50:02 UTC
incubator-corinthia git commit: Patch from Ian.
Repository: incubator-corinthia
Updated Branches:
refs/heads/odf-filter-attempt2 295caa80b -> 409f47b02
Patch from Ian.
Applied patch to odf filter.
Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/409f47b0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/409f47b0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/409f47b0
Branch: refs/heads/odf-filter-attempt2
Commit: 409f47b02200f0fb353594ff9eff72dbd1f33f91
Parents: 295caa8
Author: jani <ja...@apache.org>
Authored: Tue Jun 2 16:48:18 2015 +0200
Committer: jani <ja...@apache.org>
Committed: Tue Jun 2 16:48:18 2015 +0200
----------------------------------------------------------------------
DocFormats/filters/odf/src/text/ODFText.c | 60 +++++++++++--
DocFormats/filters/odf/src/text/gbg_test.c | 112 +++++++++++++++++++++++-
DocFormats/filters/odf/src/text/gbg_test.h | 6 +-
3 files changed, 166 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/409f47b0/DocFormats/filters/odf/src/text/ODFText.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/odf/src/text/ODFText.c b/DocFormats/filters/odf/src/text/ODFText.c
index 4ef0068..b122031 100644
--- a/DocFormats/filters/odf/src/text/ODFText.c
+++ b/DocFormats/filters/odf/src/text/ODFText.c
@@ -21,6 +21,9 @@
#include "ODFPackage.h"
#include "ODFTextConverter.h"
#include "DFDOM.h"
+#include "DFHTML.h"
+#include "DFHTMLNormalization.h"
+#include "CSS.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -42,7 +45,7 @@ static void traverseContent(ODFTextConverter *conv, DFNode *odfNode, DFNode *htm
if (odfChild->tag == DOM_TEXT) { // we have some text or a text modfier here.
// DFNode *check =
- DFCreateChildTextNode(htmlNode, odfChild->value);
+// DFCreateChildTextNode(htmlNode, odfChild->value);
printf(YELLOW "DOM_TEXT: %s \n" RESET,
odfChild->value
);
@@ -70,8 +73,22 @@ static void traverseContent(ODFTextConverter *conv, DFNode *odfNode, DFNode *htm
// DFNode *newChild = DFCreateChildElement(htmlNode, newTag);
}
else {
- DFCreateChildElement(htmlNode, newTag);
- }
+
+ DFNode *node = DFCreateChildElement(htmlNode, HTML_DIV);
+ const char * styleName = DFGetAttribute(odfChild,TEXT_STYLE_NAME);
+ printf("Found style name %s\n", styleName);
+ DFSetAttribute(node, HTML_CLASS, styleName); //DFGetAttribute(odfNode,TEXT_STYLE_NAME));
+ for (DFNode *domChild = odfChild->first; domChild != NULL; domChild = domChild->next)
+ {
+ if (domChild->tag == DOM_TEXT) { // we have some text or a text modfier here.
+ // DFNode *check =
+ DFCreateChildTextNode(node, domChild->value);
+ printf(YELLOW "DOM_TEXT: %s \n" RESET,
+ domChild->value
+ );
+ }
+ }
+ }
}
traverseContent(conv,odfChild,htmlNode);
}
@@ -95,26 +112,53 @@ DFDocument *ODFTextGet(DFStorage *concreteStorage, DFStorage *abstractStorage, c
html = DFDocumentNewWithRoot(HTML_HTML);
body = DFCreateChildElement(html->root, HTML_BODY);
+ DFNode *head = DFChildWithTag(html->root,HTML_HEAD);
+ if (head == NULL) {
+ head = DFCreateElement(html,HTML_HEAD);
+ DFNode *body = DFChildWithTag(html->root,HTML_BODY);
+ DFInsertBefore(html->root,head,body);
+ }
conv = ODFTextConverterNew(html, abstractStorage, package, idPrefix);
- printf(YELLOW
+ printf(RED
"============================================================\n"
- "Showing ODF nodes prior to the traverseContent function\n"
+ "Process ODF style nodes prior to the traverseContent function\n"
"============================================================\n"
RESET);
- show_nodes(package->contentDoc->root);
+ printf(GREEN "Number of style nodes: %lu\n" RESET, (unsigned long)package->stylesDoc->nodesCount);
+ show_nodes(package->stylesDoc->root, 0);
+ //we want to build up the CSS Stylesheet
+ CSSSheet * cssSheet = CSSSheetNew();
+ buildCSS_Styles(cssSheet, package->stylesDoc->root);
+
+ printf(GREEN "CSS: %s\n" RESET, CSSSheetCopyCSSText(cssSheet));
+
print_line(2);
print_line(2);
print_line(2);
+ printf(YELLOW
+ "============================================================\n"
+ "Showing ODF content nodes prior to the traverseContent function\n"
+ "============================================================\n"
+ RESET);
+
+ show_nodes(package->contentDoc->root, 0);
+ print_line(2);
+ print_line(2);
+ print_line(2);
+
+
// TODO: Traverse the DOM tree of package->contentDoc, adding elements to the HTML document.
// contentDoc is loaded from content.xml, and represents the most important information in
// the document, i.e. the text, tables, lists, etc.
traverseContent(conv, package->contentDoc->root, body);
-
+ char *cssText = CSSSheetCopyCSSText(cssSheet);
+ HTMLAddInternalStyleSheet(conv->html, cssText);
+ HTML_safeIndent(conv->html->docNode,0);
// uncomment to see the result. (spammy!)
printf(GREEN
"============================================================\n"
@@ -122,7 +166,7 @@ DFDocument *ODFTextGet(DFStorage *concreteStorage, DFStorage *abstractStorage, c
"============================================================\n"
RESET);
- show_nodes(body);
+ show_nodes(body, 0);
// TODO: Once this basic traversal is implemented and is capable of producing paragraphs,
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/409f47b0/DocFormats/filters/odf/src/text/gbg_test.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/odf/src/text/gbg_test.c b/DocFormats/filters/odf/src/text/gbg_test.c
index fae6c42..b816008 100644
--- a/DocFormats/filters/odf/src/text/gbg_test.c
+++ b/DocFormats/filters/odf/src/text/gbg_test.c
@@ -3,6 +3,9 @@
#include "ODFPackage.h"
#include "ODFTextConverter.h"
#include "DFDOM.h"
+
+#include "CSS.h"
+#include "CSSSheet.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -189,11 +192,114 @@ Tag find_HTML(DFNode *odfNode, DFNode *htmlNode)
/**
* Dev tool: List all the nodes following the given one.
*/
-void show_nodes(DFNode *odfNode)
+void show_nodes(DFNode *odfNode, int level)
+{
+ printf("Level: %d\n",level);
+ level++;
+ print_node_info(odfNode);
+ for (DFNode *odfChild = odfNode->first; odfChild != NULL; odfChild = odfChild->next) {
+ walkChildren(odfChild, level);
+ }
+}
+
+/**
+ * Dev tool: List all the nodes following the given one.
+ */
+void walkChildren(DFNode *odfNode, int level)
{
+ printf("Level: %d\n",level);
+ level++;
+ print_node_info(odfNode);
for (DFNode *odfChild = odfNode->first; odfChild != NULL; odfChild = odfChild->next) {
- print_node_info(odfChild);
- print_line(0);
+ walkChildren(odfChild, level);
+ }
+}
+
+//give me the styles document
+void buildCSS_Styles(CSSSheet * cssSheet, DFNode *odfNode)
+{
+ //walk through the nodes
+ // go to the office:styles can we find it?
+ //iterate each style:style
+ // make a css
+ // dip down to get its attributes
+ printf("buildCSS_Styles\n");
+ printf("name = %s\n", translateXMLEnumName[odfNode->tag]);
+
+ //manually play with the functions first
+
+
+/* CSSStyle* cssStyle = CSSSheetLookupElement(cssSheet,
+ "elementName",
+ "className",
+ 1,
+ 0);
+ CSSProperties * localproperties = CSSStyleRule(cssStyle);
+ CSSPut(localproperties,"font-weight","bold");*/
+
+
+
+ for (DFNode *odfChild = odfNode->first; odfChild != NULL; odfChild = odfChild->next)
+ {
+ if(odfChild->tag == OFFICE_STYLES)
+ {
+ printf("Processing office styles\n");
+ for (DFNode *styleNode = odfChild->first; styleNode != NULL; styleNode = styleNode->next)
+ {
+ if(styleNode->tag == STYLE_STYLE)
+ {
+ for (unsigned int i = 0; i < styleNode->attrsCount; i++)
+ {
+ Tag t = styleNode->attrs[i].tag;
+ if(t == STYLE_NAME)
+ {
+ printf("Create CSS Properties for %s\n", styleNode->attrs[i].value);
+ CSSStyle* cssStyle = CSSSheetLookupElement(cssSheet,
+ "div",
+ styleNode->attrs[i].value,
+ 1,
+ 0);
+ for (DFNode *styleInfo = styleNode->first; styleInfo != NULL; styleInfo = styleInfo->next)
+ {
+ if(styleInfo->tag == STYLE_TEXT_PROPERTIES)
+ {
+ //just looking for bolds as a first cut
+ for (unsigned int i = 0; i < styleInfo->attrsCount; i++)
+ {
+ Tag t = styleInfo->attrs[i].tag;
+ switch(t)
+ {
+ case FO_FONT_WEIGHT:
+ {
+ CSSProperties * localproperties = CSSStyleRule(cssStyle);
+ CSSPut(localproperties,"font-weight",styleInfo->attrs[i].value);
+ break;
+ }
+ case FO_FONT_SIZE:
+ {
+ CSSProperties * localproperties = CSSStyleRule(cssStyle);
+ CSSPut(localproperties,"font-size",styleInfo->attrs[i].value);
+ break;
+ }
+ case STYLE_FONT_NAME:
+ {
+ CSSProperties * localproperties = CSSStyleRule(cssStyle);
+ CSSPut(localproperties,"font-family",styleInfo->attrs[i].value);
+ break;
+ }
+ }
+ }
+ }
+ else if(styleInfo->tag == STYLE_PARAGRAPH_PROPERTIES)
+ {
+ //TBD
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/409f47b0/DocFormats/filters/odf/src/text/gbg_test.h
----------------------------------------------------------------------
diff --git a/DocFormats/filters/odf/src/text/gbg_test.h b/DocFormats/filters/odf/src/text/gbg_test.h
index 636165f..3645c8e 100644
--- a/DocFormats/filters/odf/src/text/gbg_test.h
+++ b/DocFormats/filters/odf/src/text/gbg_test.h
@@ -3,10 +3,14 @@
#define TAG_NOT_FOUND 4040404
#define TAG_NOT_MATCHED 777777
+#include "CSS.h"
+#include "CSSSheet.h"
Tag find_HTML(DFNode *odfNode, DFNode *htmlNode);
void print_node_info(DFNode *node);
-void show_nodes(DFNode *node);
+void show_nodes(DFNode *node, int level);
+void walkChildren(DFNode *odfNode, int level);
+void buildCSS_Styles(CSSSheet * cssSheet, DFNode *odfNode);
char *node_id_info(DFNode *node);
char *missing_tag_info(DFNode *node);
void print_line(int style);