Esempio n. 1
0
static OPCRelationship *addImageRelationship(WordConverter *converter, const char *src, DFError **error)
{
    const char *mediaDir = DFAppendPathComponent(converter->concretePath,"word/media");

    if (!DFFileExists(mediaDir) && !DFCreateDirectory(mediaDir,1,error))
        return NULL;

    char *ext = DFPathExtension(src);
    char *filename = genImageFilename(mediaDir,ext,error);
    free(ext);
    if (filename == NULL)
        return NULL;

    char *abstractPathSlash = DFFormatString("%s/",converter->abstractPath);
    char *unescapedSrc = DFRemovePercentEncoding(src);
    char *srcPath = DFPathResolveAbsolute(abstractPathSlash,unescapedSrc);
    char *destPath = DFAppendPathComponent(mediaDir,filename);

    OPCRelationship *result = NULL;
    if (DFCopyFile(srcPath,destPath,error)) {
        OPCRelationshipSet *rels = converter->package->documentPart->relationships;
        char *relPath = DFFormatString("/word/media/%s",filename);
        result = OPCRelationshipSetAddType(rels,WORDREL_IMAGE,relPath,0);
        free(relPath);
    }

    free(filename);
    free(abstractPathSlash);
    free(unescapedSrc);
    free(srcPath);
    free(destPath);
    return result;
}
Esempio n. 2
0
static int getImageFile(WordConverter *converter, const char *src, PixelSize *size)
{
    size->widthPx = 0;
    size->heightPx = 0;

    char *unescapedSrc = DFRemovePercentEncoding(src);
    char *abstractPathSlash = DFFormatString("%s/",converter->abstractPath);
    char *newSrcPath = DFPathResolveAbsolute(abstractPathSlash,unescapedSrc);

    int ok = DFPlatformGetImageDimensions(newSrcPath,&size->widthPx,&size->heightPx);
    free(abstractPathSlash);
    free(unescapedSrc);
    free(newSrcPath);
    return ok;
}
Esempio n. 3
0
static void parseDocumentRels(const char *documentPath, DFDocument *relsDoc, DFHashTable *rels, DFError **error)
{
    if (relsDoc == NULL)
        return;;
    const char *basePrefix = (documentPath[0] == '/') ? "" : "/";
    char *basePath = DFFormatString("%s%s",basePrefix,documentPath);
    for (DFNode *child = relsDoc->root->first; child != NULL; child = child->next) {
        if (child->tag != REL_RELATIONSHIP)
            continue;
        const char *type = DFGetAttribute(child,NULL_Type);
        const char *target = DFGetAttribute(child,NULL_TARGET);
        if ((type == NULL) || (target == NULL))
            continue;

        char *absTarget = DFPathResolveAbsolute(basePath,target);
        DFHashTableAdd(rels,type,absTarget);
        free(absTarget);
    }
    free(basePath);
}