Repository navigation
Simplify ChartForgeX document placement and preserve layout #2979
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
Open
PrzemyslawKlys
wants to merge
14
commits into
master
Choose a base branch
from
feature/chartforgex-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
07cd655
Migrate ChartForgeX document adapters to prepared v2 visuals
PrzemyslawKlys b3cb1a2
Merge remote-tracking branch 'origin/master' into feature/chartforgex-v2
PrzemyslawKlys e7c78bd
Merge remote-tracking branch 'origin/master' into feature/chartforgex-v2
PrzemyslawKlys 80dd66e
Align prepared visual tests with repository namespace style
PrzemyslawKlys ee12e03
Preserve themed document visuals and measured text flow
PrzemyslawKlys d993688
Integrate current document owners with visual consumer qualification
PrzemyslawKlys cbec2d9
Make document delivery example commands executable in PowerShell
PrzemyslawKlys ccccef0
Classify managed document examples in AOT coverage
PrzemyslawKlys bab181d
Merge master and regenerate document catalog
PrzemyslawKlys 1154b74
Simplify visual insertion and fit charts to document layouts
PrzemyslawKlys a843256
Complete drawing continuation fitting and Word page selection
PrzemyslawKlys d2c74ee
Fit kept drawing groups across columns and contain native Visio titles
PrzemyslawKlys 0aa4366
Align Word visual fixtures with measured layout
PrzemyslawKlys d62038a
Merge current master and refresh the document website inventory
PrzemyslawKlys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using OfficeIMO.Drawing; | ||
| using OfficeIMO.Excel; | ||
| using OfficeIMO.Pdf; | ||
| using OfficeIMO.PowerPoint; | ||
| using OfficeIMO.Visio; | ||
| using OfficeIMO.Word; | ||
|
|
||
| namespace OfficeIMO.ChartForgeX.Examples; | ||
|
|
||
| internal static class DeliveryEvidence { | ||
| private static readonly JsonSerializerOptions JsonOptions = new() { | ||
| WriteIndented = true, Converters = { new JsonStringEnumConverter() } | ||
| }; | ||
|
|
||
| public static void RenderSavedDocuments(string output) { | ||
| using (var document = WordDocument.Load(Path.Combine(output, "service-review.docx"))) { | ||
| SaveImages(output, "word-layout", document.ExportImages(OfficeImageExportFormat.Png)); | ||
| SaveImages(output, "word-layout", document.ExportImages(OfficeImageExportFormat.Svg)); | ||
| } | ||
| using (var document = ExcelDocument.Load(Path.Combine(output, "service-review.xlsx"))) | ||
| SaveImages(output, "excel-layout", document.ExportImages(OfficeImageExportFormat.Png, | ||
| new ExcelWorkbookImageExportOptions { ShowGridlines = false })); | ||
| using (var document = PowerPointPresentation.Load(Path.Combine(output, "service-review.pptx"))) | ||
| SaveImages(output, "powerpoint-layout", document.ExportImages(OfficeImageExportFormat.Png)); | ||
| var pdf = PdfDocument.Load(File.ReadAllBytes(Path.Combine(output, "service-review.pdf"))); | ||
| SaveImages(output, "saved-pdf", pdf.Render.ExportImages(OfficeImageExportFormat.Png)); | ||
| var visio = VisioDocument.Load(Path.Combine(output, "service-delivery.vsdx")); | ||
| SaveImages(output, "visio-layout", visio.ExportImages(OfficeImageExportFormat.Png)); | ||
| SaveImages(output, "visio-layout", visio.ExportImages(OfficeImageExportFormat.Svg)); | ||
| } | ||
|
|
||
| private static void SaveImages(string output, string route, IReadOnlyList<OfficeImageExportResult> images) { | ||
| if (images.Count == 0) throw new InvalidOperationException(route + " did not render a saved document image."); | ||
| var reports = new List<object>(); | ||
| for (int index = 0; index < images.Count; index++) { | ||
| var image = images[index]; | ||
| string fileName = route + "-" + (index + 1).ToString("D2") + | ||
| (image.Format == OfficeImageExportFormat.Svg ? ".svg" : ".png"); | ||
| File.WriteAllBytes(Path.Combine(output, fileName), image.Bytes); | ||
| reports.Add(new { File = fileName, image.Width, image.Height, image.Diagnostics }); | ||
| } | ||
| SaveJson(Path.Combine(output, route + "-" + images[0].Format.ToString().ToLowerInvariant() + ".json"), reports); | ||
| } | ||
|
|
||
| public static void SaveJson<T>(string path, T value) => File.WriteAllText(path, JsonSerializer.Serialize(value, JsonOptions)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| using global::ChartForgeX.Themes; | ||
| using global::ChartForgeX.VisualArtifacts; | ||
| using OfficeIMO.Excel; | ||
| using OfficeIMO.Pdf; | ||
| using OfficeIMO.PowerPoint; | ||
| using OfficeIMO.Word; | ||
|
|
||
| namespace OfficeIMO.ChartForgeX.Examples; | ||
|
|
||
| internal static class DocumentDelivery { | ||
| public static void Write(string output, IReadOnlyList<VisualSpecimen> specimens) { | ||
| foreach (var specimen in specimens) { | ||
| File.WriteAllText(Path.Combine(output, "source-" + specimen.Name + ".svg"), specimen.Artifact.ToSvg()); | ||
| File.WriteAllBytes(Path.Combine(output, "source-" + specimen.Name + ".png"), specimen.Artifact.ToPng()); | ||
| } | ||
| WriteWord(Path.Combine(output, "service-review.docx"), specimens); | ||
| WriteExcel(Path.Combine(output, "service-review.xlsx"), specimens); | ||
| WritePowerPoint(Path.Combine(output, "service-review.pptx"), specimens); | ||
| WritePdf(Path.Combine(output, "service-review.pdf"), specimens); | ||
| WriteVisio(output, specimens); | ||
| DeliveryEvidence.SaveJson(Path.Combine(output, "visual-conversions.json"), specimens.Select(item => { | ||
| var conversion = item.Convert(450D); | ||
| return new { item.Name, item.ModeName, conversion.Id, conversion.WidthPoints, conversion.HeightPoints, | ||
| conversion.AlternativeText, conversion.PlacementMediaType, conversion.Report }; | ||
| })); | ||
| } | ||
|
|
||
| private static void WriteWord(string path, IReadOnlyList<VisualSpecimen> specimens) { | ||
| using var document = WordDocument.Create(path); | ||
| document.Sections[0].PageSettings.PageSize = WordPageSize.A4; | ||
| document.Margins.Type = WordMargin.Normal; | ||
| double usableWidth = ((document.Sections[0].PageSettings.Width ?? throw new InvalidOperationException("Missing page width.")) | ||
| - document.Margins.Left - document.Margins.Right) / 20D; | ||
| for (int index = 0; index < specimens.Count; index++) { | ||
| if (index > 0) document.AddPageBreak(); | ||
| var specimen = specimens[index]; | ||
| var heading = document.AddParagraph().AddText(Heading(specimen)); | ||
| heading.FontFamily = "Arial"; heading.FontSizePoints = 18D; | ||
| document.AddParagraph().AddVisualArtifact(specimen.Convert(usableWidth)); | ||
| var caption = document.AddParagraph().AddText(specimen.Caption); | ||
| caption.FontFamily = "Arial"; caption.FontSizePoints = 11D; | ||
| } | ||
| document.Save(); | ||
| } | ||
|
|
||
| private static void WriteExcel(string path, IReadOnlyList<VisualSpecimen> specimens) { | ||
| using var document = ExcelDocument.Create(path); | ||
| foreach (var specimen in specimens) { | ||
| var sheet = document.AddWorksheet(specimen.Name); | ||
| for (int column = 1; column <= 9; column++) sheet.SetColumnWidth(column, 12D); | ||
| for (int row = 1; row <= 26; row++) sheet.SetRowHeight(row, 18D); | ||
| sheet.MergeRange("B1:I2"); | ||
| sheet.CellValue(1, 2, Heading(specimen)); | ||
| sheet.CellFontName(1, 2, "Arial"); sheet.CellFontSize(1, 2, 18D); | ||
| // The picture remains within the authored Letter print width after the half-inch margins. | ||
| sheet.SetPageSetup(fitToWidth: 1, fitToHeight: 0, paperSize: ExcelPaperSize.Letter); | ||
| sheet.SetMarginsPreset(ExcelMarginPreset.Narrow); | ||
| sheet.AddVisualArtifact(4, 2, specimen.Convert(612D - 72D)); | ||
| sheet.MergeRange("B21:I23"); | ||
| sheet.CellValue(21, 2, specimen.Caption); | ||
| sheet.CellFontName(21, 2, "Arial"); sheet.CellFontSize(21, 2, 11D); | ||
| sheet.CellWrapText(21, 2); | ||
| } | ||
| document.Save(); | ||
| } | ||
|
|
||
| private static void WritePowerPoint(string path, IReadOnlyList<VisualSpecimen> specimens) { | ||
| using var presentation = PowerPointPresentation.Create(path); | ||
| presentation.SlideSize.SetPreset(PowerPointSlideSizePreset.Screen16x9); | ||
| double slideWidth = presentation.SlideSize.WidthPoints, slideHeight = presentation.SlideSize.HeightPoints; | ||
| foreach (var specimen in specimens) { | ||
| var slide = presentation.AddSlide(); | ||
| var colors = VisualTheme.Graphite().Resolve(specimen.Mode); | ||
| slide.BackgroundColor = colors.Background.ToHex().TrimStart('#'); | ||
| Text(slide, Heading(specimen), 36D, 16D, slideWidth - 72D, 30D, 18, colors.Foreground.ToHex()); | ||
| var conversion = specimen.Convert(slideWidth - 72D); | ||
| slide.AddVisualArtifact(conversion, (slideWidth - conversion.WidthPoints) / 2D, 60D); | ||
| Text(slide, specimen.Caption, 36D, Math.Min(slideHeight - 52D, 60D + conversion.HeightPoints + 18D), | ||
| slideWidth - 72D, 36D, 11, colors.Foreground.ToHex()); | ||
| } | ||
| presentation.Save(); | ||
| } | ||
|
|
||
| private static void WritePdf(string path, IReadOnlyList<VisualSpecimen> specimens) { | ||
| var options = new PdfOptions { PageSize = PageSizes.A4, DefaultFontSize = 11D }; | ||
| options.EnableTaggedPdfCatalogMarkers(); | ||
| double usableWidth = options.PageWidth - options.MarginLeft - options.MarginRight; | ||
| PdfDocument.Create(document => document.Content(content => { | ||
| for (int index = 0; index < specimens.Count; index++) { | ||
| if (index > 0) content.PageBreak(); | ||
| var specimen = specimens[index]; | ||
| content.H1(Heading(specimen)); | ||
| content.AddVisualArtifact(specimen.Convert(usableWidth), spacingBefore: 12D, spacingAfter: 18D); | ||
| content.Text(specimen.Caption); | ||
| } | ||
| }), options).Save(path); | ||
| } | ||
|
|
||
| private static void WriteVisio(string output, IReadOnlyList<VisualSpecimen> specimens) { | ||
| var diagrams = specimens.Where(item => item.EditableTopology).ToArray(); | ||
| var book = diagrams.Select(item => item.Artifact.ToInterchangeEnvelope()).ToOfficeVisioBook( | ||
| new OfficeVisioVisualOptions { LayoutMode = OfficeVisioVisualLayoutMode.Preserve, PixelsPerInch = 96D }); | ||
| book.Document.Save(Path.Combine(output, "service-delivery.vsdx")); | ||
| DeliveryEvidence.SaveJson(Path.Combine(output, "native-visio-fidelity.json"), book.Pages.Select((page, index) => new { | ||
| diagrams[index].Name, page.Report, page.Page.Width, page.Page.Height, | ||
| Shapes = page.Page.Shapes.Select(shape => new { shape.Id, shape.Text, shape.PinX, shape.PinY, shape.Width, shape.Height }), | ||
| Connectors = page.Page.Connectors.Select(edge => new { edge.Id, edge.Label, edge.Waypoints.Count }) | ||
| })); | ||
| } | ||
|
|
||
| private static void Text(PowerPointSlide slide, string text, double left, double top, double width, double height, | ||
| int size, string color) { | ||
| var box = slide.AddTextBox(text, PowerPointUnits.FromPoints(left), PowerPointUnits.FromPoints(top), | ||
| PowerPointUnits.FromPoints(width), PowerPointUnits.FromPoints(height)); | ||
| box.FontName = "Arial"; box.FontSize = size; box.Color = color.TrimStart('#'); | ||
| } | ||
|
|
||
| private static string Heading(VisualSpecimen specimen) => specimen.Artifact.Title + " · " + specimen.ModeName; | ||
| } |
12 changes: 12 additions & 0 deletions
12
OfficeIMO.ChartForgeX.Examples/OfficeIMO.ChartForgeX.Examples.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFrameworks>net8.0;net10.0</TargetFrameworks> | ||
| <IsPackable>false</IsPackable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="../OfficeIMO.ChartForgeX/OfficeIMO.ChartForgeX.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using OfficeIMO.ChartForgeX.Examples; | ||
| using OfficeIMO.PowerPoint; | ||
|
|
||
| if (args.Length is < 1 or > 2 || (args.Length == 2 && args[1] != "--native-powerpoint")) { | ||
| Console.Error.WriteLine("Usage: OfficeIMO.ChartForgeX.Examples <output-directory> [--native-powerpoint]"); | ||
| return 1; | ||
| } | ||
|
|
||
| string output = Path.GetFullPath(args[0]); | ||
| Directory.CreateDirectory(output); | ||
| var specimens = VisualSpecimens.Create(); | ||
| DocumentDelivery.Write(output, specimens); | ||
| DeliveryEvidence.RenderSavedDocuments(output); | ||
|
|
||
| if (args.Length == 2) { | ||
| var result = PowerPointDesktopReferenceRenderer.TryRender( | ||
| Path.Combine(output, "service-review.pptx"), Path.Combine(output, "powerpoint-desktop"), enabled: true); | ||
| DeliveryEvidence.SaveJson(Path.Combine(output, "powerpoint-desktop.json"), result); | ||
| Console.WriteLine("PowerPoint Desktop: " + result.Status + ": " + result.Message); | ||
| if (!result.IsSuccessful) return 2; | ||
| } | ||
|
|
||
| Console.WriteLine("Saved documents and managed previews: " + output); | ||
| Console.WriteLine("Managed previews describe OfficeIMO layout; they do not establish Microsoft Office application rendering."); | ||
| return 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # ChartForgeX document delivery example | ||
|
|
||
| This executable places the same prepared service chart and topology in Word, Excel, PowerPoint and PDF. It uses the shared paired Graphite palette with document-sized typography, full accessible descriptions and explicit placement dimensions. A repeated light chart follows the dark variant, exercising reuse without treating an artifact identifier as an image-content identifier. | ||
|
|
||
| The visual viewport is 600 × 360 logical pixels. Placements use at most 450 points of width and also respect the actual page or slide content width. Axis and legend text is 15 logical pixels, or 11.25 points at the full placement size. The workbook uses an authored Letter print layout; its picture, heading and full caption occupy separate rows. Dark visuals retain their own filled canvas on white document pages; PowerPoint slide backgrounds use the selected palette. | ||
|
|
||
| Run from the repository root with the adapter's ChartForgeX source-project configuration or a local qualified 2.0.0 package feed: | ||
|
|
||
| ```powershell | ||
| dotnet run --project ./OfficeIMO.ChartForgeX.Examples/OfficeIMO.ChartForgeX.Examples.csproj -c Release -f net10.0 -- <scratch-root>/officeimo-chartforgex-delivery | ||
| ``` | ||
|
|
||
| The output directory contains the source SVG/PNG images, a five-page DOCX/PDF, a five-sheet XLSX, a five-slide PPTX, and a two-page editable topology VSDX. The JSON reports describe placement conversion and native Visio fidelity. Managed PNG previews reopen the saved files and render their document layouts; SVG previews expose the saved editable Visio geometry. | ||
|
|
||
| Managed Word previews use OfficeIMO's estimated pagination. Managed Excel and PowerPoint previews use their respective layout engines. Saved-PDF previews render the serialized PDF page content. These are distinct from Microsoft Office application rendering and must be assessed separately when an application-specific fidelity claim is needed. | ||
|
|
||
| On Windows with PowerPoint Desktop installed, explicitly request its existing reference-render lane: | ||
|
|
||
| ```powershell | ||
| dotnet run --project ./OfficeIMO.ChartForgeX.Examples/OfficeIMO.ChartForgeX.Examples.csproj -c Release -f net10.0 -- <scratch-root>/officeimo-chartforgex-delivery --native-powerpoint | ||
| ``` | ||
|
|
||
| That opt-in produces `powerpoint-desktop/` and a separate result report. Unavailable or failed native rendering returns a nonzero exit code; it does not fall back to managed images and claim native proof. Ordinary generation and managed rendering do not launch Office applications. | ||
|
|
||
| The editable Visio specimen uses prepared topology bounds and connector routes. Its report retains styling, font, accessibility and other conversion limits. Flow and sequence diagrams use their existing native reflow policy; this example does not establish exact editable layout preservation for those families. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.