Exemple #1
0
static DFNode *imageWithFilename(WordGetData *get, const char *filename, double widthPts, DFNode *concrete)
{
    const char *concretePath = get->conv->concretePath;
    const char *abstractPath = get->conv->abstractPath;

    char *abstractImagesPath = DFAppendPathComponent(abstractPath,"images");
    char *lastComponent = DFPathBaseName(filename);
    char *srcImagePath = DFAppendPathComponent(concretePath,filename);
    char *dstImagePath = DFAppendPathComponent(abstractImagesPath,lastComponent);

    if (DFFileExists(dstImagePath))
        DFDeleteFile(dstImagePath,NULL);

    DFError *error = NULL;
    DFNode *imageNode = NULL;

    if (!DFFileExists(abstractImagesPath) &&
        !DFCreateDirectory(abstractImagesPath,1,&error)) {
        WordConverterWarning(get->conv,"Create %s: %s",abstractImagesPath,DFErrorMessage(&error));
        DFErrorRelease(error);
        imageNode = createAbstractPlaceholder(get,"[Error reading image]",concrete);
    }
    else if (!DFCopyFile(srcImagePath,dstImagePath,&error)) {
        WordConverterWarning(get->conv,"Copy %s to %s: %s",srcImagePath,dstImagePath,DFErrorMessage(&error));
        DFErrorRelease(error);
        imageNode = createAbstractPlaceholder(get,"[Error reading image]",concrete);
    }
    else {
        imageNode = WordConverterCreateAbstract(get,HTML_IMG,concrete);
        DFFormatAttribute(imageNode,HTML_SRC,"images/%s",lastComponent);

        double contentWidthPts = WordSectionContentWidthPts(get->conv->mainSection);
        if (contentWidthPts > 0) {
            double widthPct = widthPts/contentWidthPts*100.0;
            CSSProperties *properties = CSSPropertiesNew();
            char buf[100];
            CSSPut(properties,"width",DFFormatDoublePct(buf,100,widthPct));
            char *propertiesText = CSSPropertiesCopyDescription(properties);
            DFSetAttribute(imageNode,HTML_STYLE,propertiesText);
            free(propertiesText);
            CSSPropertiesRelease(properties);
        }
    }

    free(abstractImagesPath);
    free(lastComponent);
    free(srcImagePath);
    free(dstImagePath);
    return imageNode;
}
char *Word_toPlain(DFStorage *rawStorage, DFHashTable *parts)
{
    DFError *error = NULL;
    char *result = Word_toPlainFromDir(rawStorage,parts,&error);
    if (result == NULL) {
        result = DFFormatString("%s\n",DFErrorMessage(&error));
        DFErrorRelease(error);
    }
    return result;
}
Exemple #3
0
int main(int argc, const char * argv[])
{
    int r = 0;
    DFError *dferr = NULL;
    if (!runCommand(argc,argv,&dferr)) {
        fprintf(stderr,"%s\n",DFErrorMessage(&dferr));
        DFErrorRelease(dferr);
        r = 1;
    }
    return r;
}
static void test_create(void)
{
    DFError *error = NULL;
    DFStorage *htmlStorage = DFStorageNewMemory(DFFileFormatHTML);
    DFDocument *htmlDoc = TestCaseGetHTML(htmlStorage,&error);
    DFStorageRelease(htmlStorage);
    if (htmlDoc == NULL) {
        DFBufferFormat(utgetoutput(),"%s\n",DFErrorMessage(&error));
        DFErrorRelease(error);
        return;
    }

    HTML_normalizeDocument(htmlDoc);
    char *latex = HTMLToLaTeX(htmlDoc);
    DFBufferFormat(utgetoutput(),"%s",latex);
    free(latex);
    DFDocumentRelease(htmlDoc);
}
int main(int argc, const char **argv)
{
    DFError *error = NULL;
    if ((argc == 4) && !strcmp(argv[1],"get")) {
        if (DFGetFile(argv[2],argv[3],&error))
            return 0;
    }
    else if ((argc == 4) && !strcmp(argv[1],"put")) {
        if (DFPutFile(argv[2],argv[3],&error))
            return 0;
    }
    else if ((argc == 4) && !strcmp(argv[1],"create")) {
        if (DFCreateFile(argv[2],argv[3],&error))
            return 0;
    }
    else {
        usage();
        return 0;
    }

    fprintf(stderr,"Error: %s\n",DFErrorMessage(&error));
    DFErrorRelease(error);
    return 1;
}