Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate ITargetFeature use to redirect target path for EmbeddedPackage and EmbeddedObject (and other) parts. #1406

Open
tomjebo opened this issue Apr 16, 2023 · 1 comment
Assignees

Comments

@tomjebo
Copy link
Collaborator

tomjebo commented Apr 16, 2023

From #1318.

TLDR:
We should investigate using the features (perhaps ITargetFeature) to customize added parts like EmbeddedPackagePart and ImagePart where the target path was specified as a compromise between the apps' specific structures so that we can mimic Excel, Word and PowerPoint's exact targeting behaviors.

MORE:

I was looking at this and I see why EmbeddedPackageParts are saved to a new embeddings folder in the folder of the referencing part. EmbeddedPackagePart is a shared type in ISO 29500-1. That means that it is a target of an explicit relationship of several parts in WordprocessingML, SpreadsheetML and PresentationML documents. However, these documents don't have the same structures wrt where those referencing parts live path-wise. So when the SDK designers were considering how to declaratively specify using XML definitions with a targetPath specification like embeddings or ../embeddings or /embeddings, they couldn't come up with one that would satisfy all three apps. For Excel, it would be ../embeddings but for Word it would be ./embeddings or just embeddings. And PowerPoint is one of those two options. So the alternative was to write front end code or generate more back end code for the front end to mimic the behavior of the three apps. When considering this with all the other behaviors that don't actually impact the consumption of the package by those apps, they opted to just pick one, effectively ./embeddings, and call it a day. I'm sure there are tons of other behaviors like this in the SDK. "Correcting" them all to mimic Office exactly starts to bloat the SDK and approach a large codebase like the apps themselves.

Effectively this is an enhancement to the SDK, vs a bug fix since the produced packages are not broken now. Regarding using features, I see that we generate:

        private sealed class GeneratedFeatures : TypedPartFeatureCollection, ITargetFeature
        {
            public GeneratedFeatures(OpenXmlPart part) : base(part) { }
            string ITargetFeature.Extension => ".bin";
            string ITargetFeature.Name => "image";
            string ITargetFeature.Path => "../media";
        }

So perhaps we can use ITargetFeature to customize this behavior.

@Asbjoedt
Copy link
Contributor

Hi @tomjebo!

I don't know if this is the right place to write this.

EmbeddedObjectParts are saved as ".bin" extension files. Both Excel and Open XML SDK does this. Imitating Excel is the best way to go about this, but the issue is, if you want to extract the embedded objects or convert them to another file format inside of the OOXML package, this is difficult without knowing what file format the embedded object is by targeting the extension and using some conversion routine (ImageMagick, FFmpeg etc.).

Another way to do this is to use magic numbers, but this would require integrating your programs with a file format identification software i.e. DROID or Siegfried. I would prefer to avoid this complexity.

Would it be possible to have all EmbeddedObjectParts saved with original extension to the package?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants