corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [16/38] incubator-corinthia git commit: Word: Conversion functions - simpler organisation
Date Fri, 13 Feb 2015 08:52:28 GMT
Word: Conversion functions - simpler organisation

Instead of having WordPackageGet and WordPackagePut (which simply
created a WordConverter object and then called through to the relevant
get or put method), do this directly in the WordGet/WordPut functions.

Also move some functionality into the WordConverter get/put functions
that really belongs there, rather than outside.

Users of WordConverter no longer have to create an instance of the class
first; they simply call WordConverterGet or WordConverterPut. These
functions create an instance internally, simplifying their use. The
parameter both of these functions take are what was previosuly passed to
WordConverterNew.


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/ce0e3d58
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/ce0e3d58
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/ce0e3d58

Branch: refs/heads/experimentZip
Commit: ce0e3d58d5602f2d63a9c8d325451180108fd980
Parents: 474eb4c
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Sun Jan 11 03:41:27 2015 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Sun Jan 11 03:41:27 2015 +0700

----------------------------------------------------------------------
 DocFormats/filters/ooxml/src/word/Word.c        | 25 ++--------
 .../filters/ooxml/src/word/WordConverter.c      | 48 +++++++++++++++++---
 .../filters/ooxml/src/word/WordConverter.h      | 13 +++---
 DocFormats/filters/ooxml/src/word/WordPackage.c | 26 -----------
 DocFormats/filters/ooxml/src/word/WordPackage.h |  4 --
 5 files changed, 52 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ce0e3d58/DocFormats/filters/ooxml/src/word/Word.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/src/word/Word.c b/DocFormats/filters/ooxml/src/word/Word.c
index 5e977e7..a94deaa 100644
--- a/DocFormats/filters/ooxml/src/word/Word.c
+++ b/DocFormats/filters/ooxml/src/word/Word.c
@@ -34,17 +34,10 @@ DFDocument *WordGet(DFStorage *concreteStorage, DFStorage *abstractStorage,
DFEr
     if (wordPackage == NULL)
         goto end;
 
-    htmlDoc = WordPackageGet(wordPackage,abstractStorage,"word",error,warnings);
-    if (htmlDoc == NULL)
+    htmlDoc = DFDocumentNew();
+    if (!WordConverterGet(htmlDoc,abstractStorage,"word",wordPackage,warnings,error))
         goto end;
 
-    if (warnings->len > 0) {
-        DFErrorFormat(error,"%s",warnings->data);
-        goto end;
-    }
-
-    HTML_safeIndent(htmlDoc->docNode,0);
-
     ok = 1;
 
 end:
@@ -71,13 +64,8 @@ int WordPut(DFStorage *concreteStorage, DFStorage *abstractStorage, DFDocument
*
     if (wordPackage == NULL)
         goto end;
 
-    if (!WordPackagePut(wordPackage,htmlDoc,abstractStorage,idPrefix,error,warnings))
-        goto end;
-
-    if (warnings->len > 0) {
-        DFErrorFormat(error,"%s",warnings->data);
+    if (!WordConverterPut(htmlDoc,abstractStorage,idPrefix,wordPackage,warnings,error))
         goto end;
-    }
 
     if (!WordPackageSave(wordPackage,error))
         goto end;
@@ -108,14 +96,9 @@ int WordCreate(DFStorage *concreteStorage, DFStorage *abstractStorage,
DFDocumen
     // a new word or odf file from it.
     HTMLBreakBDTRefs(htmlDoc->docNode,idPrefix);
 
-    if (!WordPackagePut(wordPackage,htmlDoc,abstractStorage,idPrefix,error,warnings))
+    if (!WordConverterPut(htmlDoc,abstractStorage,idPrefix,wordPackage,warnings,error))
         goto end;
 
-    if (warnings->len > 0) {
-        DFErrorFormat(error,"%s",warnings->data);
-        goto end;
-    }
-
     if (!WordPackageSave(wordPackage,error))
         goto end;
 

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ce0e3d58/DocFormats/filters/ooxml/src/word/WordConverter.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/src/word/WordConverter.c b/DocFormats/filters/ooxml/src/word/WordConverter.c
index b0cfd09..ee00253 100644
--- a/DocFormats/filters/ooxml/src/word/WordConverter.c
+++ b/DocFormats/filters/ooxml/src/word/WordConverter.c
@@ -32,6 +32,7 @@
 #include "OPC.h"
 #include "DFDOM.h"
 #include "DFHTML.h"
+#include "DFHTMLNormalization.h"
 #include "DFBDT.h"
 #include "CSS.h"
 #include "CSSProperties.h"
@@ -556,9 +557,9 @@ static void Word_postProcessHTMLDoc(WordConverter *conv)
 //                                                                                      
         //
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 
-WordConverter *WordConverterNew(DFDocument *html, DFStorage *abstractStorage,
-                                const char *idPrefix, WordPackage *package,
-                                DFBuffer *warnings)
+static WordConverter *WordConverterNew(DFDocument *html, DFStorage *abstractStorage,
+                                       const char *idPrefix, WordPackage *package,
+                                       DFBuffer *warnings)
 {
     WordConverter *converter = (WordConverter *)calloc(1,sizeof(WordConverter));
     converter->html = DFDocumentRetain(html);
@@ -585,7 +586,7 @@ WordConverter *WordConverterNew(DFDocument *html, DFStorage *abstractStorage,
     return converter;
 }
 
-void WordConverterFree(WordConverter *converter)
+static void WordConverterFree(WordConverter *converter)
 {
     DFDocumentRelease(converter->html);
     DFStorageRelease(converter->abstractStorage);
@@ -674,7 +675,7 @@ DFNode *WordConverterGetConcrete(WordPutData *put, DFNode *abstract)
     return node;
 }
 
-int WordConverterGet(WordConverter *converter, DFError **error)
+static int WordConverterGet2(WordConverter *converter, DFError **error)
 {
     converter->haveFields = Word_simplifyFields(converter->package);
     Word_mergeRuns(converter->package);
@@ -709,9 +710,26 @@ int WordConverterGet(WordConverter *converter, DFError **error)
     HTMLAddInternalStyleSheet(converter->html,cssText);
     free(cssText);
 
+    HTML_safeIndent(converter->html->docNode,0);
+
+    if (converter->warnings->len > 0) {
+        DFErrorFormat(error,"%s",converter->warnings->data);
+        return 0;
+    }
+
     return 1;
 }
 
+int WordConverterGet(DFDocument *html, DFStorage *abstractStorage,
+                     const char *idPrefix, WordPackage *package,
+                     DFBuffer *warnings, DFError **error)
+{
+    WordConverter *converter = WordConverterNew(html,abstractStorage,idPrefix,package,warnings);
+    int ok = WordConverterGet2(converter,error);
+    WordConverterFree(converter);
+    return ok;
+}
+
 static void buildListMapFromHTML(WordPutData *put, DFNode *node)
 {
     if (node->tag == HTML_P) {
@@ -796,8 +814,11 @@ static void addMissingDefaultStyles(WordConverter *converter)
     }
 }
 
-int WordConverterPut(WordConverter *converter, DFError **error)
+static int WordConverterPut2(WordConverter *converter, DFError **error)
 {
+    HTML_normalizeDocument(converter->html);
+    HTML_pushDownInlineProperties(converter->html->docNode);
+
     if (converter->package->document == NULL) {
         DFErrorFormat(error,"document.xml not found");
         return 0;
@@ -886,9 +907,24 @@ int WordConverterPut(WordConverter *converter, DFError **error)
     DFHashTableRelease(put.numIdByHtmlId);
     DFHashTableRelease(put.htmlIdByNumId);
 
+    if (converter->warnings->len > 0) {
+        DFErrorFormat(error,"%s",converter->warnings->data);
+        return 0;
+    }
+
     return 1;
 }
 
+int WordConverterPut(DFDocument *html, DFStorage *abstractStorage,
+                     const char *idPrefix, WordPackage *package,
+                     DFBuffer *warnings, DFError **error)
+{
+    WordConverter *converter = WordConverterNew(html,abstractStorage,idPrefix,package,warnings);
+    int ok = WordConverterPut2(converter,error);
+    WordConverterFree(converter);
+    return ok;
+}
+
 void WordConverterWarning(WordConverter *converter, const char *format, ...)
 {
     va_list ap;

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ce0e3d58/DocFormats/filters/ooxml/src/word/WordConverter.h
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/src/word/WordConverter.h b/DocFormats/filters/ooxml/src/word/WordConverter.h
index b4accad..eeed849 100644
--- a/DocFormats/filters/ooxml/src/word/WordConverter.h
+++ b/DocFormats/filters/ooxml/src/word/WordConverter.h
@@ -98,13 +98,12 @@ struct WordConverter {
     CSSSheet *styleSheet;
 };
 
-WordConverter *WordConverterNew(DFDocument *html, DFStorage *abstractStorage,
-                                const char *idPrefix, WordPackage *package,
-                                DFBuffer *warnings);
-void WordConverterFree(WordConverter *converter);
-
-int WordConverterGet(WordConverter *converter, DFError **error);
-int WordConverterPut(WordConverter *converter, DFError **error);
+int WordConverterGet(DFDocument *html, DFStorage *abstractStorage,
+                     const char *idPrefix, WordPackage *package,
+                     DFBuffer *warnings, DFError **error);
+int WordConverterPut(DFDocument *html, DFStorage *abstractStorage,
+                     const char *idPrefix, WordPackage *package,
+                     DFBuffer *warnings, DFError **error);
 void WordConverterWarning(WordConverter *converter, const char *format, ...) ATTRIBUTE_FORMAT(printf,2,3);
 
 char *WordStyleIdForStyle(CSSStyle *style);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ce0e3d58/DocFormats/filters/ooxml/src/word/WordPackage.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/src/word/WordPackage.c b/DocFormats/filters/ooxml/src/word/WordPackage.c
index 994eca5..f6159fa 100644
--- a/DocFormats/filters/ooxml/src/word/WordPackage.c
+++ b/DocFormats/filters/ooxml/src/word/WordPackage.c
@@ -21,7 +21,6 @@
 #include "DFXML.h"
 #include "OPC.h"
 #include "DFHTML.h"
-#include "DFHTMLNormalization.h"
 #include "WordField.h"
 #include "WordBookmark.h"
 #include "DFCommon.h"
@@ -383,31 +382,6 @@ int WordPackageSave(WordPackage *package, DFError **error)
     return 1;
 }
 
-DFDocument *WordPackageGet(WordPackage *package, DFStorage *abstractStorage, const char *idPrefix,
-                                    DFError **error, DFBuffer *warnings)
-{
-    DFDocument *html = DFDocumentNew();
-    WordConverter *converter = WordConverterNew(html,abstractStorage,idPrefix,package,warnings);
-    int ok = WordConverterGet(converter,error);
-    WordConverterFree(converter);
-    if (!ok)
-        return 0;
-    return html;
-}
-
-int WordPackagePut(WordPackage *package, DFDocument *input, DFStorage *abstractStorage,
-                              const char *idPrefix, DFError **error, DFBuffer *warnings)
-{
-    HTML_normalizeDocument(input);
-    HTML_pushDownInlineProperties(input->docNode);
-    WordConverter *converter = WordConverterNew(input,abstractStorage,idPrefix,package,warnings);
-    int ok = WordConverterPut(converter,error);
-    WordConverterFree(converter);
-    if (!ok)
-        return 0;
-    return 1;
-}
-
 static DFDocument *parsePart(WordPackage *package, OPCPart *part, DFError **error)
 {
     DFBuffer *content = OPCPackageReadPart(package->opc,part,error);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ce0e3d58/DocFormats/filters/ooxml/src/word/WordPackage.h
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/src/word/WordPackage.h b/DocFormats/filters/ooxml/src/word/WordPackage.h
index 31f8457..eaef4d0 100644
--- a/DocFormats/filters/ooxml/src/word/WordPackage.h
+++ b/DocFormats/filters/ooxml/src/word/WordPackage.h
@@ -58,9 +58,5 @@ void WordPackageExpandBookmarks(WordPackage *package);
 WordPackage *WordPackageOpenNew(DFStorage *storage, DFError **error);
 WordPackage *WordPackageOpenFrom(DFStorage *storage, DFError **error);
 int WordPackageSave(WordPackage *package, DFError **error);
-DFDocument *WordPackageGet(WordPackage *package, DFStorage *abstractStorage, const char *idPrefix,
-                                    DFError **error, DFBuffer *warnings);
-int WordPackagePut(WordPackage *package, DFDocument *input, DFStorage *abstractStorage,
-                              const char *idPrefix, DFError **error, DFBuffer *warnings);
 
 #endif


Mime
View raw message