static void WordFieldPut(WordPutData *put, DFNode *abstract, DFNode *concrete)
{
    switch (abstract->tag) {
        case HTML_SPAN: {
            const char *className = DFGetAttribute(abstract,HTML_CLASS);
            if (!DFStringEquals(className,DFFieldClass))
                return;
            char *text = DFNodeTextToString(abstract);
            DFSetAttribute(concrete,WORD_INSTR,text);
            free(text);
            break;
        }
        case HTML_A: {
            const char *href = DFGetAttribute(abstract,HTML_HREF);
            if ((href == NULL) || (href[0] != '#'))
                return;;

            const char *targetId = &href[1];
            const char *className = DFGetAttribute(abstract,HTML_CLASS);
            if (className == NULL)
                className = "";;
            const char *bookmarkName = bookmarkNameForHtmlId(put->conv,targetId,className);
            if (bookmarkName == NULL)
                return;;

            DFNode *htmlElem = DFElementForIdAttr(put->conv->html,targetId);
            if ((htmlElem != NULL) && ((htmlElem->tag == HTML_TABLE) || (htmlElem->tag == HTML_FIGURE))) {
                if (!DFStringEquals(className,DFRefTextClass) &&
                    !DFStringEquals(className,DFRefLabelNumClass) &&
                    !DFStringEquals(className,DFRefCaptionTextClass))
                    className = DFRefTextClass;
            }

            if (DFStringEquals(className,DFRefTextClass) ||
                DFStringEquals(className,DFRefLabelNumClass) ||
                DFStringEquals(className,DFRefCaptionTextClass))
                DFFormatAttribute(concrete,WORD_INSTR," REF %s \\h ",bookmarkName);
            else if (DFStringEquals(className,DFRefDirectionClass))
                DFFormatAttribute(concrete,WORD_INSTR," REF %s \\p \\h ",bookmarkName);
            else
                DFFormatAttribute(concrete,WORD_INSTR," REF %s \\r \\h ",bookmarkName);
            break;
        }
    }
}
static void simplifyRecursive(WordSimplification *simp, DFNode *node)
{
    switch (node->tag) {
        case WORD_FLDCHAR: {
            const char *type = DFGetAttribute(node,WORD_FLDCHARTYPE);
            if (DFStringEquals(type,"begin")) {
                if (simp->depth == 0) {
                    DFBufferRelease(simp->instrText);
                    simp->instrText = DFBufferNew();
                    simp->beginNode = node;
                    simp->endNode = NULL;
                    simp->inSeparate = 0;
                }
                simp->depth++;
            }
            else if (DFStringEquals(type,"end") && (simp->depth > 0)) {
                simp->depth--;
                if (simp->depth == 0) {
                    simp->endNode = node;
                    replaceField(simp);
                }
            }
            else if (DFStringEquals(type,"separate")) {
                if (simp->depth == 1)
                    simp->inSeparate = 1;
            }
            break;
        }
        case WORD_INSTRTEXT: {
            if ((simp->depth == 1) && !simp->inSeparate) {
                char *value = DFNodeTextToString(node);
                DFBufferFormat(simp->instrText,"%s",value);
                free(value);
            }
            break;
        }
    }

    DFNode *next;
    for (DFNode *child = node->first; child != NULL; child = next) {
        next = child->next;
        simplifyRecursive(simp,child);
    }
}
Example #3
0
static int isWhitespaceRun(DFNode *run)
{
    for (DFNode *child = run->first; child != NULL; child = child->next) {
        switch (child->tag) {
            case WORD_RPR:
                break;
            case WORD_T: {
                char *str = DFNodeTextToString(child);
                int isWhitespace = DFStringIsWhitespace(str);
                free(str);
                if (!isWhitespace)
                    return 0;
                break;
            }
            default:
                return 0;
        }
    }
    return 1;
}