示例#1
0
static int isSeqField(DFNode *node)
{
    if (node->tag != HTML_SPAN)
        return 0;
    if (!DFStringEquals(DFGetAttribute(node,HTML_CLASS),DFFieldClass))
        return 0;
    char *instr = DFNodeTextToString(node);
    const char **args = Word_parseField(instr);
    int result = (args[0] != NULL) && !strcmp(args[0],"SEQ");
    free(args);
    free(instr);
    return result;
}
示例#2
0
CaptionParts WordBookmarkGetCaptionParts(WordBookmark *bookmark)
{
    CaptionParts parts;
    parts.beforeNum = 0;
    parts.num = 0;
    parts.afterNum = 0;

    // FIXME: Check if the following line is still relevant with the new bookmarks model
    if (bookmark->element == NULL)
        return parts;

    DFArray *nodes = DFArrayNew(NULL,NULL);
    findAllNodes(bookmark->element,nodes);

    for (size_t i = 0; i < DFArrayCount(nodes); i++) {
        DFNode *node = DFArrayItemAt(nodes,i);
        if (node->tag == WORD_FLDSIMPLE) {
            const char *instr = DFGetAttribute(node,WORD_INSTR);
            if (instr != NULL) {
                const char **args = Word_parseField(instr);
                if ((args[0] != NULL) && !strcmp(args[0],"SEQ"))
                    parts.num = 1;
                free(args);
            }
        }
        else if (node->tag != WORD_BOOKMARK) {
            if (!parts.num)
                parts.beforeNum = 1;
            else
                parts.afterNum = 1;
        }
    }
    DFArrayRelease(nodes);

    return parts;
}
static DFNode *WordFieldGet(WordGetData *get, DFNode *concrete)
{
    if (concrete->tag != WORD_FLDSIMPLE)
        return NULL;;

    const char *instr = DFGetAttribute(concrete,WORD_INSTR);
    if (instr != NULL) {
        const char **args = Word_parseField(instr);
        size_t argCount = DFStringArrayCount(args);

        if ((argCount >= 2) && !strcmp(args[0],"REF")) {
            WordBookmark *bookmark = WordObjectsBookmarkWithName(get->conv->objects,args[1]);
            if ((bookmark != NULL) && (bookmark->target != NULL)) {

                WordRefType type = WordRefTypeGet(args,bookmark);

                DFNode *a = WordConverterCreateAbstract(get,HTML_A,concrete);
                DFFormatAttribute(a,HTML_HREF,"#%s%u",get->conv->idPrefix,bookmark->target->seqNo);
                DFSetAttribute(a,HTML_CLASS,WordRefTypeClassName(type));

                free(args);
                return a;
            }
        }
        else if ((argCount >= 1) && !strcmp(args[0],"TOC")) {

            if ((argCount >= 2) && !strcmp(args[1],"\\o")) {
                DFNode *nav = WordConverterCreateAbstract(get,HTML_NAV,concrete);
                DFSetAttribute(nav,HTML_CLASS,DFTableOfContentsClass);
                free(args);
                return nav;
            }
            else if ((argCount >= 3) && !strcmp(args[1],"\\c")) {
                // FIXME: The names "Figure" and "Table" here will be different if the document
                // was created in a language other than English. We need to look through the
                // document to figure out which counter names are used in captions adjacent to
                // figures and tables to know what the counter names used in the document
                // actually are.

                // Another option might be just to collect a static list of names used in all the
                // major languages and base the detection on that. These would need to be checked
                // with multiple versions of word, as the names used could in theory change
                // between releases.

                // We should keep track of a set of "document parameters", which record the names
                // used for figure and table counters, as well as the prefixes used on numbered
                // figures and tables. The latter would correspond to the content property of the
                // caption::before and figcaption::before CSS rules.

                if (!strcmp(args[2],"Figure")) {
                    DFNode *nav = WordConverterCreateAbstract(get,HTML_NAV,concrete);
                    DFSetAttribute(nav,HTML_CLASS,DFListOfFiguresClass);
                    free(args);
                    return nav;
                }
                else if (!strcmp(args[2],"Table")) {
                    DFNode *nav = WordConverterCreateAbstract(get,HTML_NAV,concrete);
                    DFSetAttribute(nav,HTML_CLASS,DFListOfTablesClass);
                    free(args);
                    return nav;
                }
            }
        }

        DFNode *span = WordConverterCreateAbstract(get,HTML_SPAN,concrete);
        DFSetAttribute(span,HTML_CLASS,DFFieldClass);
        DFNode *text = DFCreateTextNode(get->conv->html,instr);
        DFAppendChild(span,text);
        free(args);
        return span;
    }
    return NULL;
}