Skip to content

Wrap non-seekable stream in XamlToRtfWriter #995

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

Merged
merged 4 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ internal DeobfuscatingStream(Stream obfuscatedStream, Uri streamUri, bool leaveO

// Make sure streamUri is in the correct form; getting partUri from it will do all necessary checks for error
// conditions; We also have to make sure that it has a part name
Uri partUri = PackUriHelper.GetPartUri(streamUri);
Uri partUri = System.IO.Packaging.PackUriHelper.GetPartUri(streamUri);
if (partUri == null)
{
throw new InvalidOperationException(SR.Get(SRID.InvalidPartName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ WebRequest IWebRequestCreate.Create(Uri uri)
#endif
// only inspect cache if part name is present because cache only contains an object, not
// the stream it was derived from
Uri packageUri;
Uri partUri;
MS.Internal.IO.Packaging.PackUriHelper.ValidateAndGetPackUriComponents(uri, out packageUri, out partUri);
Uri packageUri = System.IO.Packaging.PackUriHelper.GetPackageUri(uri);
Uri partUri = System.IO.Packaging.PackUriHelper.GetPartUri(uri);

if (partUri != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
using System.ComponentModel;
using System.Windows.Controls;

using PackUriHelper = MS.Internal.IO.Packaging.PackUriHelper;

namespace MS.Internal.AppModel
{
// !!!! Note: Those methods are registered as MimeObjectFactory.StreamToObjectFactoryDelegate. The caller expects the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,8 @@ public static StreamResourceInfo GetRemoteStream(Uri uriRemote)

Uri resolvedUri = BindUriHelper.GetResolvedUri(BaseUriHelper.SiteOfOriginBaseUri, uriRemote);

// Using PackUriHelper.ValidateAndGetPackUriComponents internal method
// to get Package and Part Uri in one step
Uri packageUri;
Uri partUri;
MS.Internal.IO.Packaging.PackUriHelper.ValidateAndGetPackUriComponents(resolvedUri, out packageUri, out partUri);
Uri packageUri = PackUriHelper.GetPackageUri(resolvedUri);
Uri partUri = PackUriHelper.GetPartUri(resolvedUri);

//
// SiteOfOriginContainer must have been added into the package cache, the code should just
Expand Down Expand Up @@ -2012,12 +2009,9 @@ private static PackagePart GetResourceOrContentPart(Uri uri)
Uri packAppUri = BaseUriHelper.PackAppBaseUri;
Uri resolvedUri = BindUriHelper.GetResolvedUri(packAppUri, uri);

// Using PackUriHelper.ValidateAndGetPackUriComponents internal method
// to get Package and Part Uri in one step
Uri packageUri;
Uri partUri;
MS.Internal.IO.Packaging.PackUriHelper.ValidateAndGetPackUriComponents(resolvedUri, out packageUri, out partUri);

Uri packageUri = PackUriHelper.GetPackageUri(resolvedUri);
Uri partUri = PackUriHelper.GetPartUri(resolvedUri);

//
// ResourceContainer must have been added into the package cache, the code should just
// take use of that ResourceContainer instance, instead of creating a new instance here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ static private Uri GetStructureUriFromRelationship(Uri contentUri, string relati
Uri absTargetUri = null;
if (contentUri != null && relationshipName != null)
{
Uri partUri = MS.Internal.IO.Packaging.PackUriHelper.GetPartUri(contentUri);
Uri partUri = PackUriHelper.GetPartUri(contentUri);
if (partUri != null)
{
Uri packageUri = PackUriHelper.GetPackageUri(contentUri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2023,8 +2023,14 @@ private void WriteImage(DocumentNode documentNode)
// Get image type to be added to rtf content
RtfImageFormat imageFormat = GetImageFormatFromImageSourceName(documentNode.FormatState.ImageSource);

// Write the shape image like as "\pngblip" or "\jpegblip" rtf control
WriteShapeImage(documentNode, imageStream, imageFormat);
// Write the shape image like as "\pngblip" or "\jpegblip" rtf control. We wrap the stream that comes
// from the package because we require the stream to be seekable.
Debug.Assert(!imageStream.CanSeek);
using (var seekableStream = new MemoryStream((int)imageStream.Length))
{
imageStream.CopyTo(seekableStream);
WriteShapeImage(documentNode, seekableStream, imageFormat);
}

#if WindowsMetaFile
// This block is disabled because of performance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ private object Load(Stream stream, Uri parentUri, ParserContext pc, ContentType
XpsSchema schema = XpsSchema.GetSchema(mimeType);
Uri uri = pc.BaseUri;

// Using PackUriHelper.ValidateAndGetPackUriComponents internal method
// to get Package and Part Uri in one step
Uri packageUri;
Uri partUri;
InternalPackUriHelper.ValidateAndGetPackUriComponents(uri, out packageUri, out partUri);

Uri packageUri = PackUriHelper.GetPackageUri(uri);
Uri partUri = PackUriHelper.GetPartUri(uri);

Package package = PreloadedPackages.GetPackage(packageUri);

Uri parentPackageUri = null;
Expand Down
Loading