コード例 #1
0
static DFNode *WordRunContentGet(WordGetData *get, DFNode *concrete)
{
    switch (concrete->tag) {
        case WORD_T:
        case WORD_DELTEXT: {
            DFBuffer *buf = DFBufferNew();
            DFNodeTextToBuffer(concrete,buf);
            DFNode *abstract = DFCreateTextNode(get->conv->html,buf->data);
            DFBufferRelease(buf);
            return abstract;
        }
        case WORD_DRAWING:
        case WORD_OBJECT:
        case WORD_PICT:
            return WordDrawingGet(get,concrete);
        case WORD_TAB: {
            DFNode *span = WordConverterCreateAbstract(get,HTML_SPAN,concrete);
            DFSetAttribute(span,HTML_CLASS,DFTabClass);
            return span;
        }
        case WORD_BR: {
            const char *type = DFGetAttribute(concrete,WORD_TYPE);
            if (DFStringEquals(type,"column")) {
                DFNode *span = WordConverterCreateAbstract(get,HTML_SPAN,concrete);
                DFSetAttribute(span,HTML_CLASS,DFPlaceholderClass);
                DFCreateChildTextNode(span,"[Column break]");
                return span;
            }
            else if (DFStringEquals(type,"page")) {
                DFNode *span = WordConverterCreateAbstract(get,HTML_SPAN,concrete);
                DFSetAttribute(span,HTML_CLASS,DFPlaceholderClass);
                DFCreateChildTextNode(span,"[Page break]");
                return span;
            }
            else {
                return WordConverterCreateAbstract(get,HTML_BR,concrete);
            }
        }
        default:
            return NULL;
    }
}
コード例 #2
0
ファイル: WordConverter.c プロジェクト: flyonok/DocFormats
static void Word_addContentParts(DFNode *child, const char *content, WordCaption *caption)
{
    if (content == NULL)
        return;
    DFNode *nextSibling = child->first;
    DFArray *parts = CSSParseContent(content);
    for (int i = 0; i < DFArrayCount(parts); i++) {
        ContentPart *part = DFArrayItemAt(parts,i);
        switch (part->type) {
            case ContentPartString: {
                DFNode *text = DFCreateTextNode(child->doc,part->value);
                if (strlen(part->value) > 0) {
                    DFNode *span = DFCreateElement(child->doc,HTML_SPAN);
                    DFAppendChild(span,text);
                    DFInsertBefore(child,span,nextSibling);
                }
                break;
            }
            case ContentPartCounter: {
                if (DFStringEquals(part->value,"figure")) {
                    DFNode *span = DFCreateElement(child->doc,HTML_SPAN);
                    DFSetAttribute(span,HTML_CLASS,DFFieldClass);
                    DFCreateChildTextNode(span," SEQ Figure \\* ARABIC ");
                    DFInsertBefore(child,span,nextSibling);
                    caption->number = span;
                }
                else if (DFStringEquals(part->value,"table")) {
                    DFNode *span = DFCreateElement(child->doc,HTML_SPAN);
                    DFSetAttribute(span,HTML_CLASS,DFFieldClass);
                    DFCreateChildTextNode(span," SEQ Table \\* ARABIC ");
                    DFInsertBefore(child,span,nextSibling);
                    caption->number = span;
                }
                break;
            default:
                break;
            }
        }
    }
    DFArrayRelease(parts);
}
コード例 #3
0
ファイル: WordConverter.c プロジェクト: flyonok/DocFormats
static void Word_preProcessHTML(WordConverter *word, DFNode *node)
{
    switch (node->tag) {
        case HTML_TABLE:
        case HTML_FIGURE: {
            DFNode *next;
            for (DFNode *child = node->first; child != NULL; child = next) {
                next = child->next;

                if ((child->tag != HTML_CAPTION) && (child->tag != HTML_FIGCAPTION))
                    continue;

                WordCaption *caption = WordCaptionNew(child);
                WordObjectsSetCaption(word->objects,caption,node);
                caption->contentStart = child->first;
                WordCaptionRelease(caption);

                const char *className = DFGetAttribute(child,HTML_CLASS);
                CSSStyle *style;
                if (child->tag == HTML_CAPTION)
                    style = CSSSheetLookupElement(word->styleSheet,"caption",className,0,0);
                else
                    style = CSSSheetLookupElement(word->styleSheet,"figcaption",className,0,0);

                CSSProperties *before = CSSStyleBefore(style);
                if (CSSGet(before,"content") != NULL)
                    Word_addContentParts(child,CSSGet(before,"content"),caption);

                child->tag = HTML_P;
                DFSetAttribute(child,HTML_CLASS,"Caption");
                DFInsertBefore(node->parent,child,node->next);
                Word_preProcessHTML(word,child);
            }

            // The HTML normalization process ensures that apart from the <figcaption> element,
            // all children of a <figure> are paragraphs or containers. Currently the editor only
            // lets you create figures that contain a single image, so it's always a single
            // paragraph. Since the HTML <figure> element gets mapped to a single <w:p> element
            // by WordParagraphLens, we want to make sure it only contains inline children.

            for (DFNode *child = node->first; child != NULL; child = next) {
                next = child->next;
                if (HTML_isParagraphTag(child->tag))
                    DFRemoveNodeButKeepChildren(child);
            }

            // FIXME: Handle <div>, <pre>, lists, tables etc which could also theoretically
            // exist inside the <figure> element

            break;
        }
        case HTML_NAV: {
            const char *className = DFGetAttribute(node,HTML_CLASS);
            const char *instr = NULL;
            if (DFStringEquals(className,DFTableOfContentsClass))
                instr = " TOC \\o \"1-3\" ";
            else if (DFStringEquals(className,DFListOfFiguresClass))
                instr = " TOC \\c \"Figure\" ";
            else if (DFStringEquals(className,DFListOfTablesClass))
                instr = " TOC \\c \"Table\" ";

            if (instr != NULL) {
                DFNode *p = DFCreateElement(word->html,HTML_P);
                DFNode *field = DFCreateChildElement(p,HTML_SPAN);
                DFSetAttribute(field,HTML_CLASS,DFFieldClass);
                DFCreateChildTextNode(field,instr);
                DFInsertBefore(node->parent,p,node);
                DFRemoveNode(node);
            }
            break;
        }
    }

    DFNode *next;
    for (DFNode *child = node->first; child != NULL; child = next) {
        next = child->next;
        Word_preProcessHTML(word,child);
    }
}