void WordDrawingRemove(WordPutData *put, DFNode *concrete) { // FIXME: This only causes the relationship to be deleted - the image file itself is not removed if (concrete->tag == WORD_DRAWING) { EMUSize wordEMUSize = DrawingInfoSize(concrete); const char *wordRId = DrawingInfoRId(concrete); const char *drawingId = DrawingInfoDrawingId(concrete); OPCRelationship *rel = NULL; if (wordRId != NULL) rel = OPCRelationshipSetLookupById(put->conv->package->documentPart->relationships,wordRId); if ((wordEMUSize.widthEmu > 0) && (wordEMUSize.heightEmu > 0) && (rel != NULL) && (drawingId != NULL)) { rel->needsRemoveCheck = 1; } } else if (concrete->tag == WORD_OBJECT) { } }
static void collect(WordPackage *package, DFHashTable *referencedIds) { findReferences(referencedIds,package->document->docNode); OPCRelationshipSet *relationships = package->documentPart->relationships; const char **allIds = OPCRelationshipSetAllIds(relationships); for (int i = 0; allIds[i]; i++) { const char *rId = allIds[i]; // FIXME: We should check all targets of all relationships in the package to determine // the set of referenced files, and only delete the file if there are no more references // to it. OPCRelationship *rel = OPCRelationshipSetLookupById(relationships,rId); if (rel->needsRemoveCheck && (DFHashTableLookup(referencedIds,rel->rId) == NULL)) { if (!rel->external) DFStorageDelete(package->opc->storage,rel->target,NULL); OPCRelationshipSetRemove(relationships,rel); } } free(allIds); }
static int internalPut2(WordPutData *put, DFNode *abstract, DFNode *concrete, int isNew, const char *htmlSrc, const char *htmlPath) { int imageChanged = 0; int sizeChanged = 0; if (!DFFileExists(htmlPath)) { WordConverterWarning(put->conv,"HTML image %s does not exist",htmlSrc); return 0; } PixelSize htmlFileSize = PixelSizeZero; if (!getImageFile(put->conv,htmlSrc,&htmlFileSize)) { WordConverterWarning(put->conv,"Could not get aspect ratio of image: %s",htmlSrc); return 0; } PointsSize htmlSize = pointsSizeFromHTMLImg(put->conv,abstract,htmlFileSize); OPCRelationship *rel = NULL; const char *drawingId = NULL; if (isNew) { imageChanged = 1; sizeChanged = 1; } else { ImageInfo *wordInfo = getImageInfo(concrete); if (wordInfo == NULL) return 0; rel = OPCRelationshipSetLookupById(put->conv->package->documentPart->relationships,wordInfo->rId); if ((wordInfo != NULL) && (wordInfo->widthPts > 0) && (wordInfo->heightPts > 0) && (rel != NULL)) { const char *wordSrc = rel->target; char *wordPath = DFAppendPathComponent(put->conv->concretePath,wordSrc); if (!DFFileExists(wordPath)) { WordConverterWarning(put->conv,"Word image %s does not exist",wordSrc); free(wordPath); ImageInfoFree(wordInfo); return 0; } if (!DFPathContentsEqual(htmlPath,wordPath)) { rel->needsRemoveCheck = 1; imageChanged = 1; } if (fabs(wordInfo->widthPts - htmlSize.widthPts) >= 0.1) sizeChanged = 1; free(wordPath); } ImageInfoFree(wordInfo); if (concrete->tag == WORD_DRAWING) drawingId = DrawingInfoDrawingId(concrete); } if (imageChanged || sizeChanged) { if (imageChanged || (rel == NULL)) { // FIXME: is the rel == NULL needed? DFError *error = NULL; rel = addImageRelationship(put->conv,htmlSrc,&error); if (rel == NULL) { WordConverterWarning(put->conv,"%s",DFErrorMessage(&error)); return 0; } } if (drawingId == NULL) drawingId = WordObjectsAddDrawing(put->conv->objects)->drawingId; populateDrawingElement(put->conv,concrete,htmlSize.widthPts,htmlSize.heightPts, drawingId,rel->rId); } return 1; }