mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-05 09:44:35 +00:00
Improved reading and writing large Office files without copying them into memory (#1243)
This commit is contained in:
1 parent
918572c158
commit
dbe609a9a7
37 files changed
+1161
-471
No files matched your search
@@ -43,7 +43,7 @@ internal static partial class PresentationWriter
|
||||
PlaceholderRole.SUBTITLE when slide.Subtitle.Length > 0 => TextShape(nextId, $"Subtitle {nextId}", placeholder, ParagraphsOf(slide.Subtitle), false),
|
||||
PlaceholderRole.TEXT when index < slide.Texts.Count && slide.Texts[index].Paragraphs.Count > 0 => TextShape(nextId, $"Text {nextId}", placeholder, slide.Texts[index].Paragraphs.Select(ParagraphOf), true),
|
||||
PlaceholderRole.LABEL when index < slide.Labels.Count && slide.Labels[index].Length > 0 => TextShape(nextId, $"Label {nextId}", placeholder, ParagraphsOf(slide.Labels[index]), false),
|
||||
PlaceholderRole.PICTURE when index < slide.Pictures.Count && content.Pictures.TryGetValue(slide.Pictures[index], out var picture) => PictureShape(nextId, placeholder, slidePart, picture, slot.Bounds, slot.Bounds.Area >= content.SlideArea * PresentationTemplate.BACKDROP_AREA_SHARE),
|
||||
PlaceholderRole.PICTURE when index < slide.Pictures.Count && content.Pictures.TryGet(slide.Pictures[index], out var picture) => PictureShape(nextId, placeholder, slidePart, content.Pictures, picture, slot.Bounds, slot.Bounds.Area >= content.SlideArea * PresentationTemplate.BACKDROP_AREA_SHARE),
|
||||
PlaceholderRole.PICTURE when content.KeepEmptyPicturePlaceholders => EmptyPlaceholderShape(nextId, $"Picture Placeholder {nextId}", placeholder),
|
||||
PlaceholderRole.TABLE when index == 0 && slide.Table is { Headers.Count: > 0 } table => TableShape(nextId, placeholder, table, slot.Bounds, content.TableStyleId),
|
||||
|
||||
@@ -128,11 +128,10 @@ internal static partial class PresentationWriter
|
||||
new P.ApplicationNonVisualDrawingProperties(placeholder)),
|
||||
new P.ShapeProperties());
|
||||
|
||||
private static P.Picture PictureShape(uint id, P.PlaceholderShape placeholder, SlidePart slidePart, SlidePicture picture, SlotBounds bounds, bool isBackdrop)
|
||||
private static P.Picture PictureShape(uint id, P.PlaceholderShape placeholder, SlidePart slidePart, StagedPictures pictures, StagedPicture picture, SlotBounds bounds, bool isBackdrop)
|
||||
{
|
||||
var imagePart = slidePart.AddImagePart(picture.ContentType);
|
||||
using (var data = new MemoryStream(picture.Data))
|
||||
imagePart.FeedData(data);
|
||||
pictures.Place(picture, imagePart);
|
||||
|
||||
var blipFill = new P.BlipFill(new A.Blip { Embed = slidePart.GetIdOfPart(imagePart) });
|
||||
var shapeProperties = new P.ShapeProperties();
|
||||
@@ -159,7 +158,7 @@ internal static partial class PresentationWriter
|
||||
/// <summary>
|
||||
/// Crops the picture evenly on two sides, so that it fills the slot without being distorted.
|
||||
/// </summary>
|
||||
private static A.SourceRectangle CropToFill(SlidePicture picture, SlotBounds bounds)
|
||||
private static A.SourceRectangle CropToFill(StagedPicture picture, SlotBounds bounds)
|
||||
{
|
||||
var slotRatio = (double)bounds.Width / bounds.Height;
|
||||
var pictureRatio = (double)picture.Width / picture.Height;
|
||||
@@ -183,7 +182,7 @@ internal static partial class PresentationWriter
|
||||
/// <summary>
|
||||
/// Scales the picture to the largest size which fits into the slot, centered in it.
|
||||
/// </summary>
|
||||
private static A.Transform2D FitInside(SlidePicture picture, SlotBounds bounds)
|
||||
private static A.Transform2D FitInside(StagedPicture picture, SlotBounds bounds)
|
||||
{
|
||||
var scale = Math.Min((double)bounds.Width / picture.Width, (double)bounds.Height / picture.Height);
|
||||
var width = (long)Math.Round(picture.Width * scale);
|
||||
|
||||
Reference in new issue
Block a user