Example #1
0
static void enableNumberingForStyle(CSSStyle *style)
{
    int level = style->headingLevel;

    DFBuffer *reset = DFBufferNew();
    for (int after = level+1; after <= 6; after++) {
        if (reset->len == 0)
            DFBufferFormat(reset,"h%d",after);
        else
            DFBufferFormat(reset," h%d",after);
    }

    DFBuffer *content = DFBufferNew();
    for (int upto = 1; upto <= level; upto++) {
        if (content->len == 0)
            DFBufferFormat(content,"counter(h%d)",upto);
        else
            DFBufferFormat(content," \".\" counter(h%d)",upto);
    }
    DFBufferFormat(content," \" \"");

    CSSProperties *rule = CSSStyleRule(style);
    CSSPut(rule,"counter-increment",style->elementName);
    if (reset->len > 0)
        CSSPut(rule,"counter-reset",reset->data);
    CSSPut(CSSStyleBefore(style),"content",content->data);
    style->latent = 0;

    DFBufferRelease(reset);
    DFBufferRelease(content);
}
Example #2
0
DFSAXParser *DFSAXParserNew(void)
{
    DFSAXParser *parser = (DFSAXParser *)xcalloc(1,sizeof(DFSAXParser));
    parser->document = DFDocumentNew();
    parser->parent = parser->document->docNode;
    parser->warnings = DFBufferNew();
    parser->errors = DFBufferNew();
    parser->fatalErrors = DFBufferNew();
    parser->compatibility = DFMarkupCompatibilityNew();
    return parser;
}
Example #3
0
static int parsePackage(TextPackage *package, const char *string, const char *path, DFError **error)
{
    DFBuffer *replaced = DFBufferNew();
    if (!strcmp(path,""))
        path = ".";

    if (!processIncludes(package,string,replaced,path,error)) {
        DFBufferRelease(replaced);
        return 0;
    }


    char *currentKey = strdup("");
    DFBuffer *currentValue = DFBufferNew();
    const char **lines = DFStringSplit(replaced->data,"\n",0);
    for (int lineno = 0; lines[lineno]; lineno++) {
        const char *line = lines[lineno];

        if (!DFStringHasPrefix(line,"#")) {
            DFBufferFormat(currentValue,"%s\n",line);
        }
        else if (DFStringHasPrefix(line,"#item ")) {
            package->keys = (char **)realloc(package->keys,(package->nkeys+2)*sizeof(char *));
            package->keys[package->nkeys++] = strdup(currentKey);
            package->keys[package->nkeys] = NULL;
            DFHashTableAdd(package->items,currentKey,currentValue->data);
            free(currentKey);
            DFBufferRelease(currentValue);
            currentKey = DFSubstring(line,6,strlen(line));
            currentValue = DFBufferNew();
        }
        else if (DFStringHasPrefix(line,"##")) {
            DFBufferFormat(currentValue,"%s\n",&line[1]);
        }
        else {
            DFErrorFormat(error,"Unknown command: %s on line %d",line,(lineno+1));
            return 0;
        }
    }
    package->keys = (char **)realloc(package->keys,(package->nkeys+2)*sizeof(char *));
    package->keys[package->nkeys++] = strdup(currentKey);
    package->keys[package->nkeys] = NULL;
    DFHashTableAdd(package->items,currentKey,currentValue->data);

    free(lines);
    free(currentKey);
    DFBufferRelease(currentValue);
    DFBufferRelease(replaced);
    return 1;
}
Example #4
0
char *CSSSheetCopyText(CSSSheet *sheet)
{
    DFBuffer *result = DFBufferNew();
    const char **allSelectors = CSSSheetCopySelectors(sheet);
    DFSortStringsCaseInsensitive(allSelectors);
    for (int selIndex = 0; allSelectors[selIndex]; selIndex++) {
        CSSStyle *style = CSSSheetLookupSelector(sheet,allSelectors[selIndex],0,0);
        DFBufferFormat(result,"%s\n",style->selector);

        const char **sortedSuffixes = CSSStyleCopySuffixes(style);
        DFSortStringsCaseInsensitive(sortedSuffixes);
        for (int suffixIndex = 0; sortedSuffixes[suffixIndex]; suffixIndex++) {
            const char *suffix = sortedSuffixes[suffixIndex];
            char *quotedSuffix = DFQuote(suffix);
            DFBufferFormat(result,"    %s\n",quotedSuffix);
            free(quotedSuffix);
            CSSProperties *properties = CSSStyleRuleForSuffix(style,suffix);

            const char **sortedNames = CSSPropertiesCopyNames(properties);
            DFSortStringsCaseInsensitive(sortedNames);
            for (int nameIndex = 0; sortedNames[nameIndex]; nameIndex++) {
                const char *name = sortedNames[nameIndex];
                const char *value = CSSGet(properties,name);
                DFBufferFormat(result,"        %s = %s\n",name,value);
            }
            free(sortedNames);
        }
        free(sortedSuffixes);
    }
    free(allSelectors);
    char *str = xstrdup(result->data);
    DFBufferRelease(result);
    return str;
}
Example #5
0
int DFUnzip(const char *zipFilename, DFStorage *storage, DFError **error)
{
    unsigned char   *buf;
    DFextZipHandleP  zipHandle;
    int              i;

    zipHandle = DFextZipOpen(zipFilename);
    if (!zipHandle)
      return zipError(error,"Cannot open file");

    for (i = 0; i < zipHandle->zipFileCount; i++) {
        if ( (buf = DFextZipReadFile(zipHandle, &zipHandle->zipFileEntries[i])) == NULL)
            return zipError(error, "Cannot read file in zip");

        DFBuffer *content = DFBufferNew();
        DFBufferAppendData(content, (void *)buf, zipHandle->zipFileEntries[i].uncompressedSize);
        free(buf);

        if (!DFBufferWriteToStorage(content, storage, zipHandle->zipFileEntries[i].fileName, error)) {
            DFBufferRelease(content);
            return zipError(error, "%s: %s", zipHandle->zipFileEntries[i].fileName, DFErrorMessage(error));
        }
        DFBufferRelease(content);
    }

    DFextZipClose(zipHandle);

    return 1;
}
Example #6
0
char *DFNodeTextToString(DFNode *node)
{
    DFBuffer *buf = DFBufferNew();
    DFNodeTextToBuffer(node,buf);
    char *result = xstrdup(buf->data);
    DFBufferRelease(buf);
    return result;
}
Example #7
0
int DFSerializeXMLFile(DFDocument *doc, NamespaceID defaultNS, int indent, const char *filename, DFError **error)
{
    DFBuffer *buf = DFBufferNew();
    DFSerializeXMLBuffer(doc,defaultNS,indent,buf);
    int r = DFBufferWriteToFile(buf,filename,error);
    DFBufferRelease(buf);
    return r;
}
Example #8
0
char *DFSerializeXMLString(DFDocument *doc, NamespaceID defaultNS, int indent)
{
    DFBuffer *buf = DFBufferNew();
    DFSerializeXMLBuffer(doc,defaultNS,indent,buf);
    char *result = xstrdup(buf->data);
    DFBufferRelease(buf);
    return result;
}
static int writeString(const char *str, const char *filename, DFError **error)
{
    DFBuffer *buf = DFBufferNew();
    DFBufferAppendString(buf,str);
    int ok = writeData(buf,filename,error);
    DFBufferRelease(buf);
    return ok;
}
Example #10
0
int DFSerializeXMLStorage(DFDocument *doc, NamespaceID defaultNS, int indent,
                          DFStorage *storage, const char *filename,
                          DFError **error)
{
    char *str = DFSerializeXMLString(doc,defaultNS,indent);
    DFBuffer *content = DFBufferNew();
    DFBufferAppendString(content,str);
    int r = DFBufferWriteToStorage(content,storage,filename,error);
    DFBufferRelease(content);
    free(str);
    return r;
}
Example #11
0
static char *extractPrefix(DFNode *node, const char *counterName)
{
    if (findSeqChild(node) == NULL)
        return NULL;
    DFBuffer *result = DFBufferNew();
    int foundSeq = 0;
    int foundContent = 0;
    extractPrefixRecursive(node,counterName,result,&foundSeq,&foundContent);
    char *str = strdup(result->data);
    DFBufferRelease(result);
    return str;
}
Example #12
0
void findLabel(WordBookmark *bookmark)
{
    // FIXME: Not covered by tests
    DFBuffer *buffer = DFBufferNew();
    for (DFNode *child = bookmark->element->first; child != NULL; child = child->next) {
        // FIXME: handle inserted and deleted text
        if (child->tag == WORD_R)
            DFNodeTextToBuffer(child,buffer);
    }
    free(bookmark->label);
    bookmark->label = strdup(buffer->data);
    DFBufferRelease(buffer);
}
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 #14
0
static char *Word_toPlainFromDir(DFStorage *storage, DFHashTable *parts, DFError **error)
{
    char *documentPath = NULL;
    DFHashTable *rels = DFHashTableNew((DFCopyFunction)xstrdup,(DFFreeFunction)free);
    DFBuffer *output = DFBufferNew();
    char *relsPathRel = NULL;
    DFDocument *relsDoc = NULL;
    int ok = 0;


    documentPath = findDocumentPath(storage,error);
    if (documentPath == NULL) {
        DFErrorFormat(error,"findDocumentPath: %s",DFErrorMessage(error));
        goto end;
    }

    relsPathRel = computeDocumentRelsPath(documentPath);
    if (DFStorageExists(storage,relsPathRel) && ((relsDoc = DFParseXMLStorage(storage,relsPathRel,error)) == NULL)) {
        DFErrorFormat(error,"%s: %s",relsPathRel,DFErrorMessage(error));
        goto end;
    }

    parseDocumentRels(documentPath,relsDoc,rels,error);

    if (!processParts(parts,documentPath,relsDoc,rels,output,storage,error))
        goto end;

    ok = 1;

end:
    free(relsPathRel);
    free(documentPath);
    DFHashTableRelease(rels);
    DFDocumentRelease(relsDoc);
    if (!ok) {
        DFBufferRelease(output);
        return NULL;
    }
    else {
        char *result = xstrdup(output->data);
        DFBufferRelease(output);
        return result;
    }
}
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;
    }
}