Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
PPTX: picture slide backgrounds are drawn
KnifeLemon47fd58681066
diff --git a/src/Filee.Engines/Hwp/Hwpx/Pptx/PptxReader.cs b/src/Filee.Engines/Hwp/Hwpx/Pptx/PptxReader.csindex b90aa8da..fb00f54b 100644--- a/src/Filee.Engines/Hwp/Hwpx/Pptx/PptxReader.cs+++ b/src/Filee.Engines/Hwp/Hwpx/Pptx/PptxReader.cs@@ -117,13 +117,8 @@ internal sealed partial class PptxReader.WithMap(master?.Element(P + "clrMap")?.Attributes().ToDictionary(a => a.Name.LocalName, a => a.Value));var context = new SlideContext(slidePath, slide, layout, layoutPath, master, masterPath, colors, ThemeFonts.From(theme));- if (Background(context) is { } background)- {- background.Width = width;- background.Height = height;- background.Anchor = Anchor(0, 0);+ if (Background(context, width, height) is { } background)output.Add(background);- }// Decorations of the master and the layout (logos, bars) lie under the slide's own objects.var showMaster = (string?)slide.Attribute("showMasterSp") is not ("0" or "false")@@ -140,15 +135,20 @@ internal sealed partial class PptxReaderprivate static HAnchor Anchor(int x, int y) =>new("PAPER", "LEFT", Math.Max(0, x), "PAPER", "TOP", Math.Max(0, y), "IN_FRONT_OF_TEXT", AllowOverlap: true);- /// <summary>The first background of slide, layout or master, as a full-page rectangle (null for plain white).</summary>- private HShape? Background(SlideContext context)+ /// <summary>+ /// The first background of slide, layout or master, as a full-page rectangle, or as a full-page picture for a+ /// picture background (chalkboards, photos); null for plain white.+ /// </summary>+ private HInline? Background(SlideContext context, int width, int height){- foreach (var part in new[] { context.Slide, context.Layout, context.Master })+ foreach (var (part, partPath) in new[] { (context.Slide, context.SlidePath), (context.Layout, context.LayoutPath), (context.Master, context.MasterPath) }){var bg = part?.Element(P + "cSld")?.Element(P + "bg");if (bg is null)continue;var properties = bg.Element(P + "bgPr");+ if (properties?.Element(A + "blipFill") is { } blipFill && partPath is not null)+ return PictureBackground(partPath, blipFill, width, height);string? fill = null;HGradient? gradient = null;if (properties is not null)@@ -157,11 +157,29 @@ internal sealed partial class PptxReaderfill = context.Colors.Drawing(reference);if (gradient is null && (fill is null || fill.Equals("#FFFFFF", StringComparison.OrdinalIgnoreCase)))return null;- return new HShape(HShapeKind.Rectangle) { Fill = fill, Gradient = gradient, Line = HBorder.None };+ return new HShape(HShapeKind.Rectangle)+ {+ Fill = fill,+ Gradient = gradient,+ Line = HBorder.None,+ Width = width,+ Height = height,+ Anchor = Anchor(0, 0),+ };}return null;}+ /// <summary>A picture background stretched over the slide (a tiled one too); null when the picture can't be used.</summary>+ private HImage? PictureBackground(string partPath, XElement blipFill, int width, int height)+ {+ var embed = (string?)blipFill.Element(A + "blip")?.Attribute(R + "embed");+ var target = _package.Target(partPath, embed);+ if (target is null || !PictureTypes.Contains(Path.GetExtension(target)) || _package.Extract(target, _mediaFolder) is not { } file)+ return null;+ return new HImage(file) { Width = width, Height = height, Anchor = Anchor(0, 0) };+ }+// ───────────────────────── Objects ─────────────────────────/// <summary>Maps child coordinates of a group to slide coordinates (EMU).</summary>diff --git a/tests/Filee.Engines.Tests/HwpxReaderTests.cs b/tests/Filee.Engines.Tests/HwpxReaderTests.csindex 9a041cce..a4f0afa9 100644--- a/tests/Filee.Engines.Tests/HwpxReaderTests.cs+++ b/tests/Filee.Engines.Tests/HwpxReaderTests.cs@@ -319,6 +319,23 @@ public class HwpxReaderTests(EngineFixture fx) : IClassFixture<EngineFixture>Assert.All(inlines.OfType<HTextBox>(), b => Assert.NotNull(b.Anchor));}+ [Fact]+ public void A_picture_background_covers_the_slide()+ {+ // Issue #49: a chalkboard picture set as the slide background (Format Background → Picture) was dropped,+ // leaving white titles on a white page.+ var pptx = new PptxBuilder();+ var chalkboard = pptx.Image(Png(MagickColors.DarkSlateGray, 160, 90));+ pptx.Slide(pptx.Title("채널A, 〈금쪽같은 내새끼〉"), backgroundImage: chalkboard);+ var dir = fx.NewFolder();++ var read = PptxReader.Read(pptx.Save(Path.Combine(dir, "칠판.pptx")), Path.Combine(dir, "pptx-media"));++ var background = Assert.Single(AllInlines(read.Sections.SelectMany(s => s.Blocks)).OfType<HImage>());+ Assert.Equal((96000, 54000), (background.Width, background.Height)); // the slide, in HWPUNIT+ Assert.Equal((0, 0), (background.Anchor!.HorizontalOffset, background.Anchor.VerticalOffset));+ }+// ───────────────────────── Other producers ─────────────────────────[Fact]diff --git a/tests/Filee.Engines.Tests/OfficeBuilders.cs b/tests/Filee.Engines.Tests/OfficeBuilders.csindex b23376d5..60fcb11a 100644--- a/tests/Filee.Engines.Tests/OfficeBuilders.cs+++ b/tests/Filee.Engines.Tests/OfficeBuilders.cs@@ -197,10 +197,15 @@ internal sealed class PptxBuilderreturn $"rIdImg{_images.Count}";}- /// <summary>Adds a slide from p:spTree children; <paramref name="background"/> is an optional hex colour.</summary>- public PptxBuilder Slide(string shapes, string? background = null)+ /// <summary>+ /// Adds a slide from p:spTree children; <paramref name="background"/> is an optional hex colour,+ /// <paramref name="backgroundImage"/> an optional picture (relationship id from <see cref="Image"/>) as the background.+ /// </summary>+ public PptxBuilder Slide(string shapes, string? background = null, string? backgroundImage = null){- var bg = background is null ? "" : $"<p:bg><p:bgPr><a:solidFill><a:srgbClr val=\"{background.TrimStart('#')}\"/></a:solidFill><a:effectLst/></p:bgPr></p:bg>";+ var bg = backgroundImage is not null+ ? $"<p:bg><p:bgPr><a:blipFill dpi=\"0\" rotWithShape=\"1\"><a:blip r:embed=\"{backgroundImage}\"/><a:stretch><a:fillRect/></a:stretch></a:blipFill><a:effectLst/></p:bgPr></p:bg>"+ : background is null ? "" : $"<p:bg><p:bgPr><a:solidFill><a:srgbClr val=\"{background.TrimStart('#')}\"/></a:solidFill><a:effectLst/></p:bgPr></p:bg>";_slides.Add($"<p:sld {Namespaces}><p:cSld>{bg}<p:spTree>{TreeStart}{shapes}</p:spTree></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sld>");return this;}