Add HtmlRenderer.WinUI adapter for WinUI 3 / Win2D - #268
Open
jhaygood86 wants to merge 2 commits into
Open
Conversation
New adapter beside HtmlRenderer.WinForms and HtmlRenderer.WPF, targeting WinUI 3 (Windows App SDK) via Win2D for 2D rendering. Implements the full RAdapter/RGraphics/RFont/RImage/RBrush/RPen/RGraphicsPath/RControl/ RContextMenu adapter surface, an HtmlControl/HtmlPanel/HtmlLabel/HtmlRender control layer mirroring the WPF adapter's shape, dark-mode support via UISettings, CF_HTML clipboard copy/paste, and a minimal demo app with the same sample-browser experience as the WinForms/WPF demos. Solution/csproj wiring: new HtmlRenderer.WinUI and HtmlRenderer.Demo.WinUI projects added to HtmlRenderer.sln; InternalsVisibleTo added to the core HtmlRenderer.csproj for the new adapter's test-seam access.
HtmlRenderer.WinUI/HtmlRenderer.Demo.WinUI depend on the Windows App SDK's
MSIX PRI-generation step, which shells out to native Windows x86 binaries
(makepri.exe/makeappx.exe) - unlike the WinForms/WPF adapters, which
cross-compile cleanly everywhere via EnableWindowsTargeting's reference-
assembly story, there is no non-Windows equivalent for those native tools
at all ("Exec format error" on Ubuntu/macOS).
Adds Source/HtmlRenderer.CrossPlatform.slnf, excluding just those two
projects, and has the workflow build the full .sln on Windows but the
filtered one everywhere else - every other project (including the WinUI
adapter's own test-relevant siblings) still builds and tests identically
on all three OSes.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
HtmlRenderer.WinUIadapter project, living besideHtmlRenderer.WinFormsandHtmlRenderer.WPF, targeting WinUI 3 (Windows App SDK 2.4.0) with Win2D as the 2D rendering backend.RAdapter/RGraphics/RFont/RFontFamily/RImage/RBrush/RPen/RGraphicsPath/RControl/RContextMenu) and anHtmlControl/HtmlPanel/HtmlLabel/HtmlRendercontrol layer mirroring the WPF adapter's shape (sharedHtmlControlbase,DependencyPropertys), with plainEventHandler<T>events instead of WPF's customRoutedEventwrapper (WinUI 3 has no equivalent for user-defined routed events).UISettings.ColorValuesChanged, CF_HTML clipboard copy/paste,@font-faceloading viaCanvasFontSet.HtmlRenderer.Demo.WinUIdemo app with the same sample-browser experience (TreeView+SamplesLoader/HtmlSamplefromHtmlRenderer.Demo.Common) as the WinForms/WPF demos.HtmlRenderer.sln;InternalsVisibleToadded to the coreHtmlRenderer.csprojfor the new adapter's test-seam access (SystemColorSchemeOverride).Notable implementation notes
CanvasTextLayout.LayoutBoundsexcludes trailing-whitespace advance width entirely, so measuring a single space came back zero —GraphicsAdapter.MeasureStringfalls back to an append-a-sentinel-glyph trick to recover the true advance width when this happens.CssBox.PaintBackground(shared Core code) unconditionally disposes the brush it paints with after use; this is harmless for WPF/WinForms (their brushDispose()is a no-op) but was fatal for Win2D's realICanvasBrushresources, sinceRAdapter.GetSolidBrushis a process-lifetime cache —BrushAdapter.Dispose()is a no-op here too, matching the WPF adapter's own pattern.Microsoft.UI.Xaml.Controls.Primitives.ScrollBar(used outside aScrollViewer) needsIndicatorModeset explicitly or it renders nothing regardless ofVisibility.TreeView.RootNodesconstruction displaysTreeViewNode.Contentdirectly for plain strings — noItemTemplate/{Binding}needed for that case (used in the demo's sample picker).Test plan
dotnet buildon the full solution succeeds across all TFMs, including the new WinUI/Win2D targets.HtmlRenderer.Test/HtmlRenderer.IntegrationTest/HtmlRenderer.PdfSharp.Testsuites pass unchanged (core library and existing WinForms/WPF/PdfSharp adapters untouched).CanvasRenderTargetrenders of real sample HTML) for the whitespace-measurement and brush-disposal fixes, including a real double-paint reproduction of the brush-disposal bug before/after the fix.