Implement missing Microsoft.Maui.Graphics platform support#12
Merged
Conversation
Phase 1 - Fix core drawing correctness: - Rewrite DrawPathInternal to handle all PathOperation segment types (Move, Line, Cubic bezier, Quad bezier, Arc, Close) using PathF.GetSegmentType/GetPointsForSegment API - Apply stroke properties (dash patterns, line caps/joins, miter limit) to Cairo context in ApplyStroke() - Replace fake GetStringSize (length*fontSize*0.6) with proper Cairo TextExtents/FontExtents measurement - Implement gradient paint support (LinearGradientPaint, RadialGradientPaint) via cairo_pattern_create_linear/radial P/Invoke - Implement text alignment (horizontal/vertical) and font weight/style in DrawString using text/font extents for positioning Phase 2 - Complete missing canvas operations: - Implement ConcatenateTransform via Cairo.Matrix.Init + cr.Transform - Implement DrawImage with CairoPlatformImage (IImage backed by Cairo.ImageSurface) including Downsize, Resize, Save, FromStream - Apply Antialias and BlendMode properties to Cairo context - Implement SubtractFromClip via even-odd fill rule trick - Store SetShadow parameters (rendering deferred to future work) Phase 3 - GraphicsView interaction events: - Wire GestureClick for StartInteraction/EndInteraction/CancelInteraction - Wire GestureDrag for DragInteraction - Wire EventControllerMotion for hover events Architecture: - Extract CairoCanvas from GraphicsViewHandler.cs to dedicated Graphics/CairoCanvas.cs file (grew from ~280 to ~660 lines) - Add Graphics/CairoPlatformImage.cs implementing IImage + IDrawable Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Phase 3 - Platform services: - CairoStringSizeService (IStringSizeService): Text measurement using temporary Cairo surface + TextExtents/FontExtents - CairoBitmapExportService (IBitmapExportService): Creates CairoBitmapExportContext backed by Cairo ImageSurface with ICanvas and IImage properties, plus WriteToStream via PNG export - CairoImageLoadingService (IImageLoadingService): Loads images from streams via CairoPlatformImage.FromStream All three registered as singletons in AppHostBuilderExtensions.cs. Shadow rendering: - SetShadow now stores offset/blur/color and DrawShadowFill renders offset copies with decreasing alpha to approximate blur for fill operations (FillRectangle, FillRoundedRectangle, FillEllipse, FillPath) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds a comprehensive demo page to the sample app with 9 IDrawable sections that exercise every graphics feature implemented for issue #11: 1. Path operations: cubic bezier, quadratic bezier, arc, closed paths 2. Stroke properties: dash patterns, line caps (butt/round/square), line joins (miter/round/bevel) 3. Gradient paint: linear gradient, radial gradient, gradient on path 4. Text features: horizontal/vertical alignment, font weight/style, GetStringSize measurement 5. ConcatenateTransform: rotation, scale, skew, composite transforms 6. Shadow rendering: shadows on rect, rounded rect, ellipse, path 7. Antialias & BlendMode: aliased vs antialiased, Xor and DestOver 8. SubtractFromClip: ClipRectangle, SubtractFromClip, ClipPath 9. Interaction events: StartInteraction, EndInteraction, DragInteraction, hover events with live log display Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Upgrades all text rendering in CairoCanvas from Cairo's toy font API (ShowText/TextExtents/SelectFontFace) to PangoCairo layout: Text rendering: - DrawString uses Pango.Layout with word wrapping via SetWidth/SetWrap - Horizontal alignment via Pango.Alignment (Left/Center/Right) - Vertical alignment computed from GetPixelSize (Top/Center/Bottom) - lineSpacingAdjustment applied via SetSpacing - Font weight/style via Pango.FontDescription (SetWeight/SetStyle) - TextFlow.ClipBounds clips to bounding rectangle Text measurement: - GetStringSize uses Pango.Layout.GetPixelSize for accurate sizing - CairoStringSizeService updated to use PangoCairo instead of Cairo IAttributedText support: - DrawText builds PangoAttrList from IAttributedTextRun attributes - Supports Bold, Italic, Underline, Strikethrough, FontSize, Color - Correct UTF-8 byte index conversion for attribute ranges Sample app: - Added section 10 (Multi-line Text Wrapping) to GraphicsFeaturePage - Shows wrapped text with Left/Top, Center/Center, Right/Bottom alignment Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Addresses #11 — implements the missing platform layer for the GTK4 backend.
What changed
New files:
Graphics/CairoCanvas.cs— FullICanvasimplementation backed by Cairo + PangoCairo text layoutGraphics/CairoPlatformImage.cs—IImageimplementation backed byCairo.ImageSurfaceGraphics/CairoGraphicsServices.cs— Platform services:IStringSizeService,IBitmapExportService,IImageLoadingServicePages/GraphicsFeaturePage.cs— Comprehensive demo page exercising all graphics features (10 sections)Modified:
Handlers/GraphicsViewHandler.cs— Uses extracted CairoCanvas; adds interaction eventsHosting/AppHostBuilderExtensions.cs— Registers graphics platform servicesPhase 1 — Core drawing fixes
Phase 2 — Missing canvas operations
Phase 3 — Platform services and effects
Phase 4 — Pango text layout
Still TODO (future PRs)