Return-Path: X-Original-To: apmail-corinthia-commits-archive@minotaur.apache.org Delivered-To: apmail-corinthia-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F3F8018484 for ; Tue, 2 Jun 2015 14:50:07 +0000 (UTC) Received: (qmail 24452 invoked by uid 500); 2 Jun 2015 14:50:07 -0000 Delivered-To: apmail-corinthia-commits-archive@corinthia.apache.org Received: (qmail 24433 invoked by uid 500); 2 Jun 2015 14:50:07 -0000 Mailing-List: contact commits-help@corinthia.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@corinthia.incubator.apache.org Delivered-To: mailing list commits@corinthia.incubator.apache.org Received: (qmail 24424 invoked by uid 99); 2 Jun 2015 14:50:07 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jun 2015 14:50:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 7199D181A4E for ; Tue, 2 Jun 2015 14:50:07 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.77 X-Spam-Level: * X-Spam-Status: No, score=1.77 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id MPO6WhOgqM4B for ; Tue, 2 Jun 2015 14:50:05 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id 16EC820C4B for ; Tue, 2 Jun 2015 14:50:03 +0000 (UTC) Received: (qmail 24406 invoked by uid 99); 2 Jun 2015 14:50:02 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Jun 2015 14:50:02 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 80AFDDFF7B; Tue, 2 Jun 2015 14:50:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jani@apache.org To: commits@corinthia.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-corinthia git commit: Patch from Ian. Date: Tue, 2 Jun 2015 14:50:02 +0000 (UTC) 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 Authored: Tue Jun 2 16:48:18 2015 +0200 Committer: jani 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 #include #include @@ -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 #include #include @@ -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);