static void styleParse(WordStyle *wordStyle, WordConverter *converter, CSSStyle *style)
{
    DFNode *concrete = wordStyle->element;
    WordGetStyle(concrete,style,converter);

    if (wordStyle->basedOn != NULL) {
        WordStyle *parent = WordSheetStyleForTypeId(converter->styles,wordStyle->type,wordStyle->basedOn);
        if (parent != NULL) {
            CSSStyleSetParent(style,parent->selector);
        }
    }
}
static ConcreteInfo *getConcreteInfo(WordConverter *converter, DFNode *concrete)
{
    ConcreteInfo *cinfo = ConcreteInfoNew();

    DFNode *tblPr = DFChildWithTag(concrete,WORD_TBLPR);
    if (tblPr != NULL) {
        const char *styleId = NULL;
        WordGetTblPr(tblPr,cinfo->tableProperties,cinfo->cellProperties,converter->mainSection,&styleId);
        cinfo->style = WordSheetStyleForTypeId(converter->styles,"table",styleId);
    }
    cinfo->structure = tableStructureForConcrete(concrete);

    return cinfo;
}
Exemple #3
0
static void findTargetAndType(WordBookmark *bookmark, WordSheet *sheet)
{
    if (DFStringEquals(bookmark->bookmarkName,"_GoBack")) {
        bookmark->type = WordBookmarkCursor;
        bookmark->target = NULL;
        return;
    }
    // FIXME: Check if the following line is still relevant with the new bookmarks model
    assert(bookmark->element != NULL);
    DFNode *p = WordFindContainingParagraph(bookmark->element);
    if (p == NULL)
        return;
    DFNode *pPr = DFChildWithTag(p,WORD_PPR);
    if (pPr == NULL)
        return;
    DFNode *pStyle = DFChildWithTag(pPr,WORD_PSTYLE);
    if (pStyle == NULL)
        return;
    const char *styleId = DFGetAttribute(pStyle,WORD_VAL);
    if (styleId == NULL)
        return;
    WordStyle *style = WordSheetStyleForTypeId(sheet,"paragraph",styleId);
    if ((style != NULL) && isHeadingOutlineLvl(style->outlineLvl)) {
        bookmark->type = WordBookmarkHeading;
        bookmark->target = p;
    }
    else if (DFStringEquals(styleId,"Caption")) {
        DFNode *prev = findPreviousElement(p);
        if (prev == NULL)
            return;

        if (prev->tag == WORD_TBL) {
            bookmark->type = WordBookmarkTable;
            bookmark->target = prev;
        }
        else if (Word_isFigureParagraph(prev)) {
            bookmark->type = WordBookmarkFigure;
            bookmark->target = prev;
        }
        else if (Word_isEquationParagraph(prev)) {
            bookmark->type = WordBookmarkEquation;
            bookmark->target = prev;
        }
    }
}
static void WordGetStyle(DFNode *concrete, CSSStyle *style, WordConverter *converter)
{
    WordSection *section = converter->mainSection;
    for (DFNode *child = concrete->first; child != NULL; child = child->next) {
        const char *styleId = NULL;
        switch (child->tag) {
            case WORD_NAME:
                CSSStyleSetDisplayName(style,DFGetAttribute(child,WORD_VAL));
                break;
            case WORD_NEXT: {
                // FIXME: do he need to handle style types other than paragraph here?
                const char *nextName = DFGetAttribute(child,WORD_VAL);
                if (nextName == NULL)
                    continue;
                WordStyle *nextStyle = WordSheetStyleForTypeId(converter->styles,"paragraph",nextName);
                if (nextStyle == NULL)
                    continue;
                CSSStyleSetNext(style,nextStyle->selector);
                break;
            }
            case WORD_RPR:
                WordGetRPr(child,CSSStyleRule(style),&styleId,converter->theme);
                break;
            case WORD_PPR: {
                WordGetPPr(child,CSSStyleRule(style),&styleId,section);
                if (style->headingLevel > 0) {
                    DFNode *numPr = DFChildWithTag(child,WORD_NUMPR);
                    if (numPr != NULL)
                        WordGetNumPrStyle(numPr,style,converter);
                }
                break;
            }
            case WORD_TBLPR:
                WordGetTblPr(child,CSSStyleRule(style),CSSStyleCell(style),section,&styleId);
                break;
            case WORD_TRPR:
                // FIXME
                break;
            case WORD_TCPR:
                WordGetTcPr(child,CSSStyleRule(style));
                break;
            case WORD_TBLSTYLEPR:
                WordGetTblStylePr(child,style,section,converter->theme);
                break;
        }
    }

    // Special case: The ListParagraph style that word automatically adds specifies an indentation
    // of 36pt. We don't actually want this, because HTML automatically indents lists anyway. If
    // we see this, clear it, but keep the old value around for when we update the word document.
    StyleFamily family = WordStyleFamilyForSelector(style->selector);
    const char *name = WordSheetStyleIdForSelector(converter->styles,style->selector);
    if ((family == StyleFamilyParagraph) && DFStringEquals(name,"ListParagraph")) {
        CSSProperties *properties = CSSStyleRule(style);
        const char *wordMarginLeft = CSSGet(properties,"margin-left");
        CSSPut(properties,"-word-margin-left",wordMarginLeft);
        CSSPut(properties,"margin-left",NULL);
    }

    DFNode *pPr = DFChildWithTag(concrete,WORD_PPR);
    DFNode *numPr = DFChildWithTag(pPr,WORD_NUMPR);
    const char *numId = DFGetChildAttribute(numPr,WORD_NUMID,WORD_VAL);
    if ((numId != NULL) && (atoi(numId) == 0)) {
        switch (style->tag) {
            case HTML_H1:
            case HTML_H2:
            case HTML_H3:
            case HTML_H4:
            case HTML_H5:
            case HTML_H6:
            case HTML_FIGURE:
            case HTML_TABLE: {
                char *counterIncrement = DFFormatString("%s 0",style->elementName);
                CSSPut(CSSStyleRule(style),"counter-reset","null");
                CSSPut(CSSStyleRule(style),"counter-increment",counterIncrement);
                CSSPut(CSSStyleBefore(style),"content","none");
                free(counterIncrement);
            }
        }
    }
}