| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 26 天前 | ||
| 26 天前 | ||
| 1 个月前 | ||
| 15 天前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 13 天前 |
wzzc-dev - MoonBit Graphics & Text Rendering
A collection of MoonBit libraries for 2D graphics rendering, text processing, and display.
Project Structure
wzzc-dev/
├── moon.mod # Root module
├── moon.work # Workspace configuration
│
├── graphics/ # 2D graphics rendering
│ ├── moon.mod
│ ├── color.mbt # RGBA color
│ ├── path.mbt # Vector path
│ ├── paint.mbt # Paint configuration
│ ├── pixmap.mbt # Pixel buffer
│ ├── layer.mbt # Off-screen layer cache
│ ├── layer_tree.mbt # Z-ordered cached layer composition
│ ├── render_frame.mbt # Frame canvas + layer tree submit unit
│ ├── rasterizer.mbt # Scanline rasterizer
│ └── canvas.mbt # Drawing canvas
│
├── text/ # Text processing
│ ├── moon.mod
│ ├── reader.mbt # Binary reader
│ ├── tables.mbt # TTF tables
│ ├── parser.mbt # TTF parser
│ ├── font.mbt # Font data
│ ├── glyph.mbt # Glyph representation
│ ├── shaper.mbt # Text shaping
│ ├── layout.mbt # Layout engine
│ ├── rasterizer.mbt # Glyph rasterizer
│ ├── renderer.mbt # Font renderer
│ └── file_io.mbt # File I/O (uses moonbitlang/x/fs)
│
├── renderer/ # Graphics + text integration
│ ├── moon.mod
│ ├── renderer.mbt # Renderer core and text mask composition
│ └── renderer_test.mbt
│
├── softbuffer/ # Pixel display
│ ├── moon.mod
│ ├── ffi.mbt # FFI bindings
│ ├── surface.mbt # graphics.Surface native present targets
│ ├── native_renderer.h # Native present declarations
│ └── native_renderer.c # Win32 present implementation and non-Windows stubs
│
└── examples/
├── headless_render/ # MemorySurface off-screen render smoke test
│ ├── moon.mod
│ ├── moon.pkg
│ └── main.mbt
├── render_bench/ # Deterministic CPU render microbenchmark smoke
│ ├── moon.mod
│ ├── moon.pkg
│ └── main.mbt
├── hello_world/ # RenderFrame + LayerTree window demo
│ ├── moon.mod
│ ├── moon.pkg
│ └── main.mbt
├── font_demo/ # Font rendering demo
│ ├── moon.mod
│ ├── moon.pkg
│ └── main.mbt
└── triangle_window/ # Triangle rendering demo
├── moon.mod
├── moon.pkg
└── main.mbt
Libraries
graphics
2D graphics rendering library.
Features:
- Color, Path, Paint, Pixmap, Canvas, Layer, LayerTree, RenderFrame
- Scanline triangle/polygon fill
- Bresenham line drawing
- Bezier curve rendering
Canvasline/polyline/polygon/arc/pie/rect/circle/ellipse and uniform/per-corner rounded-rect helpers for reusable GUI dividers, borders, progress rings, badges, ovals, panels, tabs, buttons, charts, simple icons, and input backgroundsPathconservative control-point bounds, fill-rule point containment queries, exact no-op simplification, and path-local affine transforms for hit testing, planning, reuse, and later geometry refinementCanvas::draw_placeholder_textfor debug text boxes; real text drawing lives inrenderer- Canvas save/restore state stack, transform-aware rect/path drawing, transform helpers, and intersecting clip scopes for nested GUI drawing
PaintShaderdevice-space linear/radial/sweep gradients, color stops, spread modes, local transform inspection, and color-stop/geometry metadata queries for vector fills/strokes and coverage-mask drawing, with solid-color fallback throughPaintPaintFilteridentity/modulate/grayscale color filter chains with stage metadata for solid/shader/mask and paint-aware Pixmap drawing pathsSurfacetrait,MemorySurfacewith present-operation records, aggregate present telemetry plus telemetry reset, isolated full/rectPixmap, raw RGBA byte, and PPM snapshots, full/rect pixel checksums, present helpers, preflight-validated present batches with source-byte telemetry, and dirty-present batch dry-runs forCanvas,LayerTree,RenderFrame, andPixmap- Pixmap blitting, source-rect atlas drawing, source-rect coverage-mask drawing, tiled Pixmap fills, explicit nearest/bilinear/bicubic sampling modes, quality strategies for fast/balanced/high image drawing, transform-aware sampled Pixmap drawing, Porter-Duff and artistic Paint blend modes, deterministic full/rect raw RGBA bytes, PPM(P6) export, and lightweight full/rect pixel checksums for headless fixtures, and straight-alpha composition for image, glyph atlas, and layer caching
PixmapCachefor keyed reuse of image/layer pixmaps with copy-isolated cache entries, membership introspection, optional hit/insert telemetry, and opt-in LRU entry limits- Nine-patch Pixmap scaling for reusable GUI panel/background image composition
PixelRect/DirtyRegiontracking with merge, explicit dirty-present/dirty-submit plans, scheduler states, andCanvasbounded dirty-present helpersLayeroff-screen caches with resize, overlap preservation, opacity/blend-mode composition, and dirty-region composition back into a targetCanvasLayerTreez-order composition with dirty rectangle propagation, layer resize/remove/replace/reorder lifecycle, opacity/blend-mode property-change invalidation, dirty-present planning/batch dry-runs, and partial present submissionRenderFrameas a frame-sized canvas and layer-tree submit unit with resize lifecycle, single/batched layer resize/clear and replacement/redraw helpers, dirty queries/marking, dirty-submit planning/results, event-loop schedule snapshots, explicit DirtyOnly/CachedRedraw/FullRedraw submit policies, policy-aware submit requests, cached redraw schedule execution, precomputed schedule submit execution, result-level scheduler, did-present, planned rect/cost telemetry, dirty batch dry-runs, Skip/Partial/Full present strategy planning, and strategy-aware submit helpers for backend event-loop integration
text
Text processing library (font parsing, shaping, layout).
Features:
- TTF font loading and parsing
- Checked TTF structural validation through
FontFace/FontDataparsing - Documented
FontParseErrorcategories for callers that load untrusted font bytes FontFace,GlyphRun, andTextLayoutfacades for renderer and GUI-facing text APIs, including glyph coverage queries for fallback/resource selectionFontFallbackPlanfor segmenting text across an orderedFontFacestack and reporting missing-glyph spans before fallback shaping or cache schedulingFontFaceCachefor keyed reuse of checked parsed faces in GUI/resource code, with membership introspection, optional hit/parse-miss telemetry, and opt-in LRU entry limitsTextSystemfor GUI/editor-facing keyed in-memory font registration/removal, checked parsed-face reuse, registeredFontDatalookup/replacement telemetry, registered-font layout, and caret geometry in layout-local coordinatesGlyphMaskCachefor keyed reuse of individual glyph coverage masks, with membership introspection, optional hit/rasterize-miss telemetry, and opt-in LRU entry limitsGlyphMaskAtlasfor text-local row-packed placement of copied glyph masks, with capacity, occupancy, free-space, fit-query, rotate-on-full insert, and atlas hit/new-insert telemetry helpers for resource lifecycle decisionsTextMaskCachefor keyed reuse of rendered coverage masks with copy-isolated cache entries, membership introspection, optional hit/render-miss telemetry, and opt-in LRU entry limits- Left, center, right, and basic non-final-line justify alignment through the
TextLayoutfacade - Explicit newline and empty-line preservation in
TextLayout, text masks, and renderer text drawing - Configurable letter spacing and word spacing through
LayoutConfig - Trailing-space measurement and wrapping semantics suitable for editor-style text blocks
- Simplified LTR/RTL shaping order with inspectable
ShapedTextglyphs and positions - Text layout and basic Unicode line-break classes for digits, combining marks, Hangul clusters, joiners, emoji modifiers, CJK ranges, and supplementary-plane format-12 cmap input, with unspaced CJK/Hangul wrapping through
TextLayout - Glyph rasterization with anti-aliasing
- Kerning support
renderer
Renderer integration layer that composes graphics.Canvas with text coverage masks.
Features:
Renderer::draw_text_facefor checkedFontFace -> TextLayout -> CanvasdrawingRenderer::draw_text_fallback_linefor orderedFontFacefallback spans, with missing-glyph span telemetry for GUI labels and resource schedulingRenderer::draw_text_fallback_line_cachedfor repeated orderedFontFacefallback labels backed byTextMaskCache, with render-hit telemetry per spanRenderer::draw_text_face_cachedfor caller-ownedTextMaskCachebacked label/text-run drawing with hit/render telemetryRenderer::draw_text_face_atlasfor caller-owned glyph mask cache andGlyphMaskAtlasbacked text drawing with per-call draw/skip/cache/atlas/clear telemetryRenderer::draw_text_fallback_line_atlasfor orderedFontFacefallback labels backed by glyph mask cache andGlyphMaskAtlastelemetryRendererTextResourcesfor sharing bounded text-mask cache, glyph-mask cache, glyph atlas state, text/glyph residency checks, and cache/atlas snapshot telemetry across renderer text drawsRendererResourcesfor sharing checked font-face cache, renderer text resources, imagePixmapCache, and font/text/glyph/image residency and snapshot telemetry from one GUI/resource objectRenderer::draw_font_bytes_cached_with_renderer_resources, fallback-line, fallback atlas, and single-face atlas-backed font-byte drawing for checked parse reuse with font/span/text/glyph/atlas telemetryRenderer::draw_pixmap_cachedand quality-scaled cached pixmap drawing forRendererResourcesbacked image reuse with hit/insert telemetryRenderer::draw_coverage_maskfor testing and low-level mask compositionRenderer::draw_glyph_atlas_entryfor compositing one glyph placement from aGlyphMaskAtlascoverage snapshot- End-to-end regression from a parsed TTF printable ASCII fixture to rendered
Pixmappixels - Keeps
graphicsindependent from font parsing and text layout
softbuffer
Native-handle pixel presentation adapter.
Features:
NativeSurfaceimplementation of thegraphics.Surfacepresent contract for external native window handlesRenderFrame -> NativeSurfacedirty/full present methods plus dry-run packed present batches, event-loop schedule snapshots, explicit native submit policies, policy-aware submit requests, cached redraw submit methods, precomputed schedule submit methods, and adapters for graphics-core strategy-aware submit/query/plan results with dirty bounds, fallback state, planned rect/cost, and full-present savings telemetry for window integrationNativeSurfaceframe-size match/sync helpers and synced policy/strategy submit wrappers for persistent backend surfaces across window resize events- Optional
NativeSurfacepre-present hook for window lifecycle notifications before validated native presents NativeSurface::presentuses the same validated full-frame contract asSurface::present_pixels, including error propagation and hook timing- Native full-frame and rectangle present entry points for dirty redraw plumbing;
the current C backend presents through Win32 GDI on Windows and AppKit
NSViewlayer contents on macOS, with no-op stubs for other native hosts
examples
Small build-checked programs that exercise the public packages together.
Features:
headless_renderrenders a GUI-style frame throughRenderFrame,LayerTree, andMemorySurface, then self-checks graphics-core strategy-aware submit planning/results and PPM fixture bytes without creating a windowrender_benchruns a deterministic CPU render workload covering fill rect, path fill, stroke, glyph raster/mask composition, Pixmap blit, and full present-copy telemetryhello_worldusesgraphics.RenderFrame,LayerTree, frame-level resize/clear/replacement redraw helpers, andsoftbufferpolicy-aware submit requests as a minimal window submit path with resize/redraw lifecycle reusefont_demorenders real TTF text through therendererpackagetriangle_windowkeeps a simple native pixel-output smoke test
Building & Running
Prerequisites
- MoonBit - https://www.moonbitlang.com/
- Visual Studio Build Tools - For native compilation on Windows
Using VS Developer Command Prompt (Recommended)
The easiest way to build and run on Windows is using the VS Developer Command Prompt:
# 1. Open VS Developer PowerShell
& "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64
# 2. Then validate the native softbuffer package
moon test softbuffer
Or create a batch file check-softbuffer.bat:
@echo off
call "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64
moon test softbuffer
The current GUI example packages import wzzc-dev/window/macos, so they are
macOS build/run examples until the example packages are split by host window
backend.
Manual Environment Setup (PowerShell)
If you prefer to set environment variables manually:
$env:PATH = "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Tools\MSVC\14.51.36231\bin\Hostx64\x64;$env:PATH"
$env:INCLUDE = "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Tools\MSVC\14.51.36231\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\shared;C:\Program Files (x86)\Windows Kits\10\Include\10.0.26100.0\um"
$env:LIB = "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Tools\MSVC\14.51.36231\lib\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.26100.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.26100.0\um\x64"
moon test softbuffer
Commands
# Check all packages
moon check
# Run the local validation gate
scripts/check_ci.sh
# Run deterministic render microbenchmark smoke workload
moon run examples/render_bench
# Run renderer package tests directly
moon test graphics
moon test text
moon test renderer
moon test softbuffer
# Build native GUI examples (current packages are macOS window examples)
moon build examples/hello_world --target native
moon build examples/font_demo --target native
moon build examples/triangle_window --target native
# Run headless rendering smoke test
moon run examples/headless_render
# Manual GUI smoke tests; these open windows and run until closed
moon run examples/hello_world --target native
moon run examples/font_demo --target native
moon run examples/triangle_window --target native
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Application │
│ (examples/font_demo) │
└───────────────────────────┬─────────────────────────────────┘
│
┌───────────────────┼───────────────────┐
▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ graphics │ │ text │ │ softbuffer │
│ (渲染图形) │ │ (解析字体) │ │ (显示到屏幕) │
└───────┬───────┘ └───────┬───────┘ └───────────────┘
│ │
└─────────┬─────────┘
▼
┌───────────────┐
│ renderer │
│ (组合渲染管线) │
└───────────────┘
Project Direction
The long-term goal is to grow this repository into a MoonBit-native, CPU-first, testable, cross-platform lightweight 2D rendering stack for text, vector graphics, pixel output, and GUI foundations. See ROADMAP.md for milestones and acceptance criteria, and docs/testing.md for the local validation gate. The checked font parser error contract is tracked in docs/font-parser-errors.md, and text API facade boundaries are tracked in docs/text-api-boundaries.md.
License
Apache-2.0