@native-sdk/cli 0.0.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +44 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,1949 @@
|
|
|
1
|
+
const support = @import("test_support.zig");
|
|
2
|
+
const std = support.std;
|
|
3
|
+
const geometry = support.geometry;
|
|
4
|
+
const canvas = support.canvas;
|
|
5
|
+
const drawing_model = support.drawing_model;
|
|
6
|
+
const text_model = support.text_model;
|
|
7
|
+
const render_model = support.render_model;
|
|
8
|
+
const event_model = support.event_model;
|
|
9
|
+
const equality_model = support.equality_model;
|
|
10
|
+
const widget_runtime = support.widget_runtime;
|
|
11
|
+
const Error = support.Error;
|
|
12
|
+
const ObjectId = support.ObjectId;
|
|
13
|
+
const ImageId = support.ImageId;
|
|
14
|
+
const FontId = support.FontId;
|
|
15
|
+
const default_sans_font_id = support.default_sans_font_id;
|
|
16
|
+
const default_mono_font_id = support.default_mono_font_id;
|
|
17
|
+
const default_sans_font_family = support.default_sans_font_family;
|
|
18
|
+
const default_mono_font_family = support.default_mono_font_family;
|
|
19
|
+
const default_glyph_atlas_cache_retention_frames = support.default_glyph_atlas_cache_retention_frames;
|
|
20
|
+
const default_text_layout_cache_retention_frames = support.default_text_layout_cache_retention_frames;
|
|
21
|
+
const Color = support.Color;
|
|
22
|
+
const Affine = support.Affine;
|
|
23
|
+
const Radius = support.Radius;
|
|
24
|
+
const GradientStop = support.GradientStop;
|
|
25
|
+
const LinearGradient = support.LinearGradient;
|
|
26
|
+
const Fill = support.Fill;
|
|
27
|
+
const Stroke = support.Stroke;
|
|
28
|
+
const Clip = support.Clip;
|
|
29
|
+
const FillRect = support.FillRect;
|
|
30
|
+
const StrokeRect = support.StrokeRect;
|
|
31
|
+
const FillRoundedRect = support.FillRoundedRect;
|
|
32
|
+
const Line = support.Line;
|
|
33
|
+
const PathVerb = support.PathVerb;
|
|
34
|
+
const PathElement = support.PathElement;
|
|
35
|
+
const FillPath = support.FillPath;
|
|
36
|
+
const StrokePath = support.StrokePath;
|
|
37
|
+
const ImageFit = support.ImageFit;
|
|
38
|
+
const ImageSampling = support.ImageSampling;
|
|
39
|
+
const DrawImage = support.DrawImage;
|
|
40
|
+
const Shadow = support.Shadow;
|
|
41
|
+
const Blur = support.Blur;
|
|
42
|
+
const Glyph = support.Glyph;
|
|
43
|
+
const GlyphAtlasKey = support.GlyphAtlasKey;
|
|
44
|
+
const GlyphAtlasEntry = support.GlyphAtlasEntry;
|
|
45
|
+
const GlyphAtlasPlan = support.GlyphAtlasPlan;
|
|
46
|
+
const GlyphAtlasPlanner = support.GlyphAtlasPlanner;
|
|
47
|
+
const GlyphAtlasCacheEntry = support.GlyphAtlasCacheEntry;
|
|
48
|
+
const GlyphAtlasCacheActionKind = support.GlyphAtlasCacheActionKind;
|
|
49
|
+
const GlyphAtlasCacheAction = support.GlyphAtlasCacheAction;
|
|
50
|
+
const GlyphAtlasCachePlan = support.GlyphAtlasCachePlan;
|
|
51
|
+
const GlyphAtlasCachePlanner = support.GlyphAtlasCachePlanner;
|
|
52
|
+
const DrawText = support.DrawText;
|
|
53
|
+
const TextWrap = support.TextWrap;
|
|
54
|
+
const TextAlign = support.TextAlign;
|
|
55
|
+
const TextLayoutOptions = support.TextLayoutOptions;
|
|
56
|
+
const TextLine = support.TextLine;
|
|
57
|
+
const TextLayout = support.TextLayout;
|
|
58
|
+
const TextLayoutKey = support.TextLayoutKey;
|
|
59
|
+
const TextLayoutPlan = support.TextLayoutPlan;
|
|
60
|
+
const TextLayoutPlanSet = support.TextLayoutPlanSet;
|
|
61
|
+
const TextLayoutPlanner = support.TextLayoutPlanner;
|
|
62
|
+
const TextLayoutCacheEntry = support.TextLayoutCacheEntry;
|
|
63
|
+
const TextLayoutCacheActionKind = support.TextLayoutCacheActionKind;
|
|
64
|
+
const TextLayoutCacheAction = support.TextLayoutCacheAction;
|
|
65
|
+
const TextLayoutCachePlan = support.TextLayoutCachePlan;
|
|
66
|
+
const TextLayoutCachePlanner = support.TextLayoutCachePlanner;
|
|
67
|
+
const TextRange = support.TextRange;
|
|
68
|
+
const TextSelectionRect = support.TextSelectionRect;
|
|
69
|
+
const TextSelection = support.TextSelection;
|
|
70
|
+
const TextCaretDirection = support.TextCaretDirection;
|
|
71
|
+
const TextCaretMove = support.TextCaretMove;
|
|
72
|
+
const TextCompositionUpdate = support.TextCompositionUpdate;
|
|
73
|
+
const TextInputEvent = support.TextInputEvent;
|
|
74
|
+
const TextEditState = support.TextEditState;
|
|
75
|
+
const CanvasCommand = support.CanvasCommand;
|
|
76
|
+
const CommandRef = support.CommandRef;
|
|
77
|
+
const DiffKind = support.DiffKind;
|
|
78
|
+
const DiffChange = support.DiffChange;
|
|
79
|
+
const Builder = support.Builder;
|
|
80
|
+
const max_render_state_stack = support.max_render_state_stack;
|
|
81
|
+
const RenderState = support.RenderState;
|
|
82
|
+
const RenderCommand = support.RenderCommand;
|
|
83
|
+
const CanvasRenderOverride = support.CanvasRenderOverride;
|
|
84
|
+
const CanvasRenderAnimation = support.CanvasRenderAnimation;
|
|
85
|
+
const applyRenderOverrides = support.applyRenderOverrides;
|
|
86
|
+
const renderOverrideDirtyBounds = support.renderOverrideDirtyBounds;
|
|
87
|
+
const RenderPlan = support.RenderPlan;
|
|
88
|
+
const RenderPlanner = support.RenderPlanner;
|
|
89
|
+
const RenderPipelineKind = support.RenderPipelineKind;
|
|
90
|
+
const RenderBatch = support.RenderBatch;
|
|
91
|
+
const RenderBatchPlanner = support.RenderBatchPlanner;
|
|
92
|
+
const RenderBatchPlan = support.RenderBatchPlan;
|
|
93
|
+
const RenderPipelineCacheEntry = support.RenderPipelineCacheEntry;
|
|
94
|
+
const RenderPipelineCacheActionKind = support.RenderPipelineCacheActionKind;
|
|
95
|
+
const RenderPipelineCacheAction = support.RenderPipelineCacheAction;
|
|
96
|
+
const RenderPipelineCachePlanner = support.RenderPipelineCachePlanner;
|
|
97
|
+
const RenderPipelineCachePlan = support.RenderPipelineCachePlan;
|
|
98
|
+
const RenderPathGeometryKind = support.RenderPathGeometryKind;
|
|
99
|
+
const RenderPathGeometry = support.RenderPathGeometry;
|
|
100
|
+
const RenderPathGeometryPlan = support.RenderPathGeometryPlan;
|
|
101
|
+
const RenderPathGeometryPlanner = support.RenderPathGeometryPlanner;
|
|
102
|
+
const RenderPathGeometryKey = support.RenderPathGeometryKey;
|
|
103
|
+
const RenderPathGeometryCacheEntry = support.RenderPathGeometryCacheEntry;
|
|
104
|
+
const RenderPathGeometryCacheActionKind = support.RenderPathGeometryCacheActionKind;
|
|
105
|
+
const RenderPathGeometryCacheAction = support.RenderPathGeometryCacheAction;
|
|
106
|
+
const RenderPathGeometryCachePlan = support.RenderPathGeometryCachePlan;
|
|
107
|
+
const RenderPathGeometryCachePlanner = support.RenderPathGeometryCachePlanner;
|
|
108
|
+
const RenderImage = support.RenderImage;
|
|
109
|
+
const RenderImagePlan = support.RenderImagePlan;
|
|
110
|
+
const RenderImagePlanner = support.RenderImagePlanner;
|
|
111
|
+
const RenderImageKey = support.RenderImageKey;
|
|
112
|
+
const RenderImageCacheEntry = support.RenderImageCacheEntry;
|
|
113
|
+
const RenderImageCacheActionKind = support.RenderImageCacheActionKind;
|
|
114
|
+
const RenderImageCacheAction = support.RenderImageCacheAction;
|
|
115
|
+
const RenderImageCachePlan = support.RenderImageCachePlan;
|
|
116
|
+
const RenderImageCachePlanner = support.RenderImageCachePlanner;
|
|
117
|
+
const RenderResourceKind = support.RenderResourceKind;
|
|
118
|
+
const RenderResource = support.RenderResource;
|
|
119
|
+
const RenderResourcePlan = support.RenderResourcePlan;
|
|
120
|
+
const RenderResourcePlanner = support.RenderResourcePlanner;
|
|
121
|
+
const RenderResourceKey = support.RenderResourceKey;
|
|
122
|
+
const RenderResourceCacheEntry = support.RenderResourceCacheEntry;
|
|
123
|
+
const RenderResourceCacheActionKind = support.RenderResourceCacheActionKind;
|
|
124
|
+
const RenderResourceCacheAction = support.RenderResourceCacheAction;
|
|
125
|
+
const RenderResourceCachePlan = support.RenderResourceCachePlan;
|
|
126
|
+
const RenderResourceCachePlanner = support.RenderResourceCachePlanner;
|
|
127
|
+
const RenderLayer = support.RenderLayer;
|
|
128
|
+
const RenderLayerPlan = support.RenderLayerPlan;
|
|
129
|
+
const RenderLayerPlanner = support.RenderLayerPlanner;
|
|
130
|
+
const RenderLayerKey = support.RenderLayerKey;
|
|
131
|
+
const RenderLayerCacheEntry = support.RenderLayerCacheEntry;
|
|
132
|
+
const RenderLayerCacheActionKind = support.RenderLayerCacheActionKind;
|
|
133
|
+
const RenderLayerCacheAction = support.RenderLayerCacheAction;
|
|
134
|
+
const RenderLayerCachePlan = support.RenderLayerCachePlan;
|
|
135
|
+
const RenderLayerCachePlanner = support.RenderLayerCachePlanner;
|
|
136
|
+
const VisualEffectKind = support.VisualEffectKind;
|
|
137
|
+
const VisualEffect = support.VisualEffect;
|
|
138
|
+
const VisualEffectPlan = support.VisualEffectPlan;
|
|
139
|
+
const VisualEffectPlanner = support.VisualEffectPlanner;
|
|
140
|
+
const VisualEffectKey = support.VisualEffectKey;
|
|
141
|
+
const VisualEffectCacheEntry = support.VisualEffectCacheEntry;
|
|
142
|
+
const VisualEffectCacheActionKind = support.VisualEffectCacheActionKind;
|
|
143
|
+
const VisualEffectCacheAction = support.VisualEffectCacheAction;
|
|
144
|
+
const VisualEffectCachePlan = support.VisualEffectCachePlan;
|
|
145
|
+
const VisualEffectCachePlanner = support.VisualEffectCachePlanner;
|
|
146
|
+
const CanvasFrameOptions = support.CanvasFrameOptions;
|
|
147
|
+
const CanvasFrameStorage = support.CanvasFrameStorage;
|
|
148
|
+
const CanvasFrameBudget = support.CanvasFrameBudget;
|
|
149
|
+
const CanvasFrameBudgetStatus = support.CanvasFrameBudgetStatus;
|
|
150
|
+
const CanvasFrameDiagnostics = support.CanvasFrameDiagnostics;
|
|
151
|
+
const CanvasFrameProfileRisk = support.CanvasFrameProfileRisk;
|
|
152
|
+
const CanvasFrameProfile = support.CanvasFrameProfile;
|
|
153
|
+
const CanvasRenderPass = support.CanvasRenderPass;
|
|
154
|
+
const CanvasFrame = support.CanvasFrame;
|
|
155
|
+
const buildCanvasFrame = support.buildCanvasFrame;
|
|
156
|
+
const CanvasRenderPassLoadAction = support.CanvasRenderPassLoadAction;
|
|
157
|
+
const RenderEncoderBeginPass = support.RenderEncoderBeginPass;
|
|
158
|
+
const RenderEncoderCommand = support.RenderEncoderCommand;
|
|
159
|
+
const RenderEncoderPlan = support.RenderEncoderPlan;
|
|
160
|
+
const RenderEncoderPlanner = support.RenderEncoderPlanner;
|
|
161
|
+
const CanvasGpuCommandKind = support.CanvasGpuCommandKind;
|
|
162
|
+
const CanvasGpuRoundedRect = support.CanvasGpuRoundedRect;
|
|
163
|
+
const CanvasGpuStrokeRect = support.CanvasGpuStrokeRect;
|
|
164
|
+
const CanvasGpuLine = support.CanvasGpuLine;
|
|
165
|
+
const CanvasGpuShape = support.CanvasGpuShape;
|
|
166
|
+
const CanvasGpuPaint = support.CanvasGpuPaint;
|
|
167
|
+
const CanvasGpuImage = support.CanvasGpuImage;
|
|
168
|
+
const CanvasGpuText = support.CanvasGpuText;
|
|
169
|
+
const CanvasGpuShadow = support.CanvasGpuShadow;
|
|
170
|
+
const CanvasGpuBlur = support.CanvasGpuBlur;
|
|
171
|
+
const CanvasGpuEffect = support.CanvasGpuEffect;
|
|
172
|
+
const CanvasGpuCommand = support.CanvasGpuCommand;
|
|
173
|
+
const CanvasGpuPacket = support.CanvasGpuPacket;
|
|
174
|
+
const CanvasGpuPacketSummary = support.CanvasGpuPacketSummary;
|
|
175
|
+
const CanvasGpuPacketPlanner = support.CanvasGpuPacketPlanner;
|
|
176
|
+
const ReferenceImage = support.ReferenceImage;
|
|
177
|
+
const ReferenceRenderSurface = support.ReferenceRenderSurface;
|
|
178
|
+
const Density = support.Density;
|
|
179
|
+
const Easing = support.Easing;
|
|
180
|
+
const ColorScheme = support.ColorScheme;
|
|
181
|
+
const ColorContrast = support.ColorContrast;
|
|
182
|
+
const ThemeOptions = support.ThemeOptions;
|
|
183
|
+
const ColorTokens = support.ColorTokens;
|
|
184
|
+
const FontFamily = support.FontFamily;
|
|
185
|
+
const TypographyTokens = support.TypographyTokens;
|
|
186
|
+
const SpacingTokens = support.SpacingTokens;
|
|
187
|
+
const RadiusTokens = support.RadiusTokens;
|
|
188
|
+
const StrokeTokens = support.StrokeTokens;
|
|
189
|
+
const ShadowToken = support.ShadowToken;
|
|
190
|
+
const ShadowTokens = support.ShadowTokens;
|
|
191
|
+
const BlurTokens = support.BlurTokens;
|
|
192
|
+
const MotionDuration = support.MotionDuration;
|
|
193
|
+
const MotionAnimationOptions = support.MotionAnimationOptions;
|
|
194
|
+
const MotionTokens = support.MotionTokens;
|
|
195
|
+
const SpringToken = support.SpringToken;
|
|
196
|
+
const BlurTokenRef = support.BlurTokenRef;
|
|
197
|
+
const ScrollPhysics = support.ScrollPhysics;
|
|
198
|
+
const ScrollState = support.ScrollState;
|
|
199
|
+
const VirtualListOptions = support.VirtualListOptions;
|
|
200
|
+
const VirtualListRange = support.VirtualListRange;
|
|
201
|
+
const virtualListRange = support.virtualListRange;
|
|
202
|
+
const LayerTokens = support.LayerTokens;
|
|
203
|
+
const PixelSnapTokens = support.PixelSnapTokens;
|
|
204
|
+
const ControlVisualTokens = support.ControlVisualTokens;
|
|
205
|
+
const ControlTokens = support.ControlTokens;
|
|
206
|
+
const ColorTokenOverrides = support.ColorTokenOverrides;
|
|
207
|
+
const TypographyTokenOverrides = support.TypographyTokenOverrides;
|
|
208
|
+
const SpacingTokenOverrides = support.SpacingTokenOverrides;
|
|
209
|
+
const RadiusTokenOverrides = support.RadiusTokenOverrides;
|
|
210
|
+
const StrokeTokenOverrides = support.StrokeTokenOverrides;
|
|
211
|
+
const ShadowTokenOverrides = support.ShadowTokenOverrides;
|
|
212
|
+
const ShadowTokensOverrides = support.ShadowTokensOverrides;
|
|
213
|
+
const BlurTokenOverrides = support.BlurTokenOverrides;
|
|
214
|
+
const SpringTokenOverrides = support.SpringTokenOverrides;
|
|
215
|
+
const MotionTokenOverrides = support.MotionTokenOverrides;
|
|
216
|
+
const ScrollPhysicsOverrides = support.ScrollPhysicsOverrides;
|
|
217
|
+
const LayerTokenOverrides = support.LayerTokenOverrides;
|
|
218
|
+
const PixelSnapTokenOverrides = support.PixelSnapTokenOverrides;
|
|
219
|
+
const ControlVisualTokenOverrides = support.ControlVisualTokenOverrides;
|
|
220
|
+
const ControlTokenOverrides = support.ControlTokenOverrides;
|
|
221
|
+
const DesignTokenOverrides = support.DesignTokenOverrides;
|
|
222
|
+
const DesignTokens = support.DesignTokens;
|
|
223
|
+
const WidgetKind = support.WidgetKind;
|
|
224
|
+
const WidgetCursor = support.WidgetCursor;
|
|
225
|
+
const WidgetState = support.WidgetState;
|
|
226
|
+
const WidgetRenderState = support.WidgetRenderState;
|
|
227
|
+
const WidgetMainAlignment = support.WidgetMainAlignment;
|
|
228
|
+
const WidgetCrossAlignment = support.WidgetCrossAlignment;
|
|
229
|
+
const WidgetLayoutStyle = support.WidgetLayoutStyle;
|
|
230
|
+
const WidgetStyle = support.WidgetStyle;
|
|
231
|
+
const WidgetVariant = support.WidgetVariant;
|
|
232
|
+
const WidgetSize = support.WidgetSize;
|
|
233
|
+
const WidgetRole = support.WidgetRole;
|
|
234
|
+
const BuiltinComponentStyle = support.BuiltinComponentStyle;
|
|
235
|
+
const BuiltinComponentKind = support.BuiltinComponentKind;
|
|
236
|
+
const builtin_component_kinds = support.builtin_component_kinds;
|
|
237
|
+
const builtin_component_names = support.builtin_component_names;
|
|
238
|
+
const BuiltinComponentDescriptor = support.BuiltinComponentDescriptor;
|
|
239
|
+
const builtinComponentCount = support.builtinComponentCount;
|
|
240
|
+
const builtinComponentName = support.builtinComponentName;
|
|
241
|
+
const builtinComponentDescriptor = support.builtinComponentDescriptor;
|
|
242
|
+
const WidgetActions = support.WidgetActions;
|
|
243
|
+
const WidgetSemantics = support.WidgetSemantics;
|
|
244
|
+
const Widget = support.Widget;
|
|
245
|
+
const BuiltinComponentOptions = support.BuiltinComponentOptions;
|
|
246
|
+
const WidgetCommandPart = support.WidgetCommandPart;
|
|
247
|
+
const BuiltinSurfacePlacementOptions = support.BuiltinSurfacePlacementOptions;
|
|
248
|
+
const BuiltinSurfaceBackdropOptions = support.BuiltinSurfaceBackdropOptions;
|
|
249
|
+
const BuiltinStatusBarOptions = support.BuiltinStatusBarOptions;
|
|
250
|
+
const BuiltinSurfaceEnterAnimationOptions = support.BuiltinSurfaceEnterAnimationOptions;
|
|
251
|
+
const builtinComponentWidget = support.builtinComponentWidget;
|
|
252
|
+
const widgetCommandPartId = support.widgetCommandPartId;
|
|
253
|
+
const builtinSurfaceBackdropWidget = support.builtinSurfaceBackdropWidget;
|
|
254
|
+
const builtinStatusBarWidget = support.builtinStatusBarWidget;
|
|
255
|
+
const builtinSurfaceFrame = support.builtinSurfaceFrame;
|
|
256
|
+
const appendBuiltinSurfaceEnterAnimations = support.appendBuiltinSurfaceEnterAnimations;
|
|
257
|
+
const builtinSurfaceEnterOffset = support.builtinSurfaceEnterOffset;
|
|
258
|
+
const max_widget_depth = support.max_widget_depth;
|
|
259
|
+
const max_widget_text_range_rects = support.max_widget_text_range_rects;
|
|
260
|
+
const WidgetLayoutNode = support.WidgetLayoutNode;
|
|
261
|
+
const WidgetHit = support.WidgetHit;
|
|
262
|
+
const WidgetPointerPhase = support.WidgetPointerPhase;
|
|
263
|
+
const WidgetPointerEvent = support.WidgetPointerEvent;
|
|
264
|
+
const WidgetKeyboardPhase = support.WidgetKeyboardPhase;
|
|
265
|
+
const WidgetKeyboardModifiers = support.WidgetKeyboardModifiers;
|
|
266
|
+
const WidgetKeyboardEvent = support.WidgetKeyboardEvent;
|
|
267
|
+
const WidgetControlIntentKind = support.WidgetControlIntentKind;
|
|
268
|
+
const WidgetControlIntent = support.WidgetControlIntent;
|
|
269
|
+
const WidgetSemanticAction = support.WidgetSemanticAction;
|
|
270
|
+
const WidgetFileDropEvent = support.WidgetFileDropEvent;
|
|
271
|
+
const WidgetDragEvent = support.WidgetDragEvent;
|
|
272
|
+
const WidgetEventPhase = support.WidgetEventPhase;
|
|
273
|
+
const WidgetEventRouteEntry = support.WidgetEventRouteEntry;
|
|
274
|
+
const WidgetEventRoute = support.WidgetEventRoute;
|
|
275
|
+
const WidgetKeyboardRoute = support.WidgetKeyboardRoute;
|
|
276
|
+
const WidgetFocusDirection = support.WidgetFocusDirection;
|
|
277
|
+
const WidgetFocusTarget = support.WidgetFocusTarget;
|
|
278
|
+
const WidgetScrollMetrics = support.WidgetScrollMetrics;
|
|
279
|
+
const WidgetListMetrics = support.WidgetListMetrics;
|
|
280
|
+
const WidgetSemanticsNode = support.WidgetSemanticsNode;
|
|
281
|
+
const WidgetInvalidationKind = support.WidgetInvalidationKind;
|
|
282
|
+
const WidgetInvalidation = support.WidgetInvalidation;
|
|
283
|
+
const widgetKeyboardControlIntent = support.widgetKeyboardControlIntent;
|
|
284
|
+
const widgetSemanticControlIntent = support.widgetSemanticControlIntent;
|
|
285
|
+
const widgetSemanticControlIntentWithActions = support.widgetSemanticControlIntentWithActions;
|
|
286
|
+
const isWidgetActivationKey = support.isWidgetActivationKey;
|
|
287
|
+
const widgetSliderKeyboardValue = support.widgetSliderKeyboardValue;
|
|
288
|
+
const widgetScrollKeyboardIntent = support.widgetScrollKeyboardIntent;
|
|
289
|
+
const widgetScrollKeyboardDelta = support.widgetScrollKeyboardDelta;
|
|
290
|
+
const WidgetLayoutTree = support.WidgetLayoutTree;
|
|
291
|
+
const DisplayList = support.DisplayList;
|
|
292
|
+
const emitWidgetTree = support.emitWidgetTree;
|
|
293
|
+
const layoutWidgetTree = support.layoutWidgetTree;
|
|
294
|
+
const layoutWidgetTreeWithTokens = support.layoutWidgetTreeWithTokens;
|
|
295
|
+
const layoutTextRun = support.layoutTextRun;
|
|
296
|
+
const layoutTextRunPlan = support.layoutTextRunPlan;
|
|
297
|
+
const layoutTextCaretRect = support.layoutTextCaretRect;
|
|
298
|
+
const textCaretRectForLayout = support.textCaretRectForLayout;
|
|
299
|
+
const layoutTextSelectionRects = support.layoutTextSelectionRects;
|
|
300
|
+
const textSelectionRectsForLayout = support.textSelectionRectsForLayout;
|
|
301
|
+
const layoutTextOffsetForPoint = support.layoutTextOffsetForPoint;
|
|
302
|
+
const textOffsetForLayoutPoint = support.textOffsetForLayoutPoint;
|
|
303
|
+
const applyTextInputEvent = support.applyTextInputEvent;
|
|
304
|
+
const sampleCanvasRenderAnimations = support.sampleCanvasRenderAnimations;
|
|
305
|
+
const emitWidgetLayout = support.emitWidgetLayout;
|
|
306
|
+
const toggleWidgetKnobCommandId = support.toggleWidgetKnobCommandId;
|
|
307
|
+
const toggleWidgetKnobTravel = support.toggleWidgetKnobTravel;
|
|
308
|
+
const textSelectionForWidgetPoint = support.textSelectionForWidgetPoint;
|
|
309
|
+
const textOffsetForWidgetPoint = support.textOffsetForWidgetPoint;
|
|
310
|
+
const textInputViewportForWidget = support.textInputViewportForWidget;
|
|
311
|
+
const textInputContentExtentForWidget = support.textInputContentExtentForWidget;
|
|
312
|
+
const textInputMaxScrollOffsetForWidget = support.textInputMaxScrollOffsetForWidget;
|
|
313
|
+
const clampedTextInputScrollOffsetForWidget = support.clampedTextInputScrollOffsetForWidget;
|
|
314
|
+
const intrinsicWidgetSize = support.intrinsicWidgetSize;
|
|
315
|
+
const cursorForWidgetHit = support.cursorForWidgetHit;
|
|
316
|
+
const cursorForWidgetTarget = support.cursorForWidgetTarget;
|
|
317
|
+
const WidgetTextGeometry = support.WidgetTextGeometry;
|
|
318
|
+
const textGeometryForWidget = support.textGeometryForWidget;
|
|
319
|
+
const virtualWidgetScrollContentExtent = support.virtualWidgetScrollContentExtent;
|
|
320
|
+
const virtualWidgetScrollContentExtentWithTokens = support.virtualWidgetScrollContentExtentWithTokens;
|
|
321
|
+
const writeCanvasGpuPacketJson = support.writeCanvasGpuPacketJson;
|
|
322
|
+
const strokeBounds = support.strokeBounds;
|
|
323
|
+
const shadowBounds = support.shadowBounds;
|
|
324
|
+
const semanticActions = support.semanticActions;
|
|
325
|
+
const defaultSemanticActions = support.defaultSemanticActions;
|
|
326
|
+
const defaultFocusable = support.defaultFocusable;
|
|
327
|
+
const textLineBounds = support.textLineBounds;
|
|
328
|
+
const textBounds = support.textBounds;
|
|
329
|
+
const estimateTextWidth = support.estimateTextWidth;
|
|
330
|
+
const estimateTextWidthForFont = support.estimateTextWidthForFont;
|
|
331
|
+
const estimateTextAdvanceForBytes = support.estimateTextAdvanceForBytes;
|
|
332
|
+
const estimatedGlyphAdvance = support.estimatedGlyphAdvance;
|
|
333
|
+
const snapTextSelection = support.snapTextSelection;
|
|
334
|
+
const snapTextRange = support.snapTextRange;
|
|
335
|
+
const nextTextOffset = support.nextTextOffset;
|
|
336
|
+
const nextTextLineEnd = support.nextTextLineEnd;
|
|
337
|
+
const isTextBreakByte = support.isTextBreakByte;
|
|
338
|
+
const textLineRange = support.textLineRange;
|
|
339
|
+
const textLineCaretX = support.textLineCaretX;
|
|
340
|
+
const motionProgress = support.motionProgress;
|
|
341
|
+
const renderImageFingerprint = support.renderImageFingerprint;
|
|
342
|
+
const renderImageFingerprintForResource = support.renderImageFingerprintForResource;
|
|
343
|
+
const commandsEqual = support.commandsEqual;
|
|
344
|
+
const rectsEqual = support.rectsEqual;
|
|
345
|
+
const optionalRectsEqual = support.optionalRectsEqual;
|
|
346
|
+
const sizesEqual = support.sizesEqual;
|
|
347
|
+
const insetsEqual = support.insetsEqual;
|
|
348
|
+
const optionalColorsEqual = support.optionalColorsEqual;
|
|
349
|
+
const radiiEqual = support.radiiEqual;
|
|
350
|
+
const affinesEqual = support.affinesEqual;
|
|
351
|
+
const optionalF32Equal = support.optionalF32Equal;
|
|
352
|
+
const optionalTextSelectionsEqual = support.optionalTextSelectionsEqual;
|
|
353
|
+
const optionalTextRangesEqual = support.optionalTextRangesEqual;
|
|
354
|
+
const widgetPartId = support.widgetPartId;
|
|
355
|
+
const colorWithAlpha = support.colorWithAlpha;
|
|
356
|
+
const widgetControlHeight = support.widgetControlHeight;
|
|
357
|
+
const textSelectionFillColor = support.textSelectionFillColor;
|
|
358
|
+
const transparentColor = support.transparentColor;
|
|
359
|
+
const expectRect = support.expectRect;
|
|
360
|
+
const expectRectApprox = support.expectRectApprox;
|
|
361
|
+
const expectPixelRgba8 = support.expectPixelRgba8;
|
|
362
|
+
const expectVisiblePixel = support.expectVisiblePixel;
|
|
363
|
+
const referenceSurfaceSignature = support.referenceSurfaceSignature;
|
|
364
|
+
const expectLayoutFrame = support.expectLayoutFrame;
|
|
365
|
+
const expectRouteEntry = support.expectRouteEntry;
|
|
366
|
+
const expectFillColor = support.expectFillColor;
|
|
367
|
+
const expectGpuPaintColor = support.expectGpuPaintColor;
|
|
368
|
+
|
|
369
|
+
test "text offset walks always advance through invalid utf8" {
|
|
370
|
+
// Every scalar loop in the engine (glyph-atlas planning, line wrap,
|
|
371
|
+
// caret movement) trusts nextTextOffset to make progress. An orphan
|
|
372
|
+
// continuation byte used to snap the cursor BACK to the previous
|
|
373
|
+
// lead and return an offset at-or-before the input — an infinite
|
|
374
|
+
// loop reachable from one stray 0x80 in any rendered text.
|
|
375
|
+
const hostile_texts = [_][]const u8{
|
|
376
|
+
"a\x80b", // orphan continuation after ascii
|
|
377
|
+
"\x80\x80\x80", // continuation-only text
|
|
378
|
+
"é\x80é", // orphan between multi-byte scalars
|
|
379
|
+
"a\xc3", // truncated lead at end
|
|
380
|
+
"\xf0\x9f\x80", // truncated 4-byte lead
|
|
381
|
+
"\x00\x80\xff\xfe", // NUL + orphan + invalid leads
|
|
382
|
+
"ok \xed\xa0\x80 end", // CESU surrogate half
|
|
383
|
+
};
|
|
384
|
+
for (hostile_texts) |text| {
|
|
385
|
+
var offset: usize = 0;
|
|
386
|
+
var steps: usize = 0;
|
|
387
|
+
while (offset < text.len) {
|
|
388
|
+
const next = nextTextOffset(text, offset);
|
|
389
|
+
try std.testing.expect(next > offset);
|
|
390
|
+
offset = next;
|
|
391
|
+
steps += 1;
|
|
392
|
+
try std.testing.expect(steps <= text.len);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
test "text edit state applies utf8-aware caret insert and delete events" {
|
|
398
|
+
var storage_a: [64]u8 = undefined;
|
|
399
|
+
var storage_b: [64]u8 = undefined;
|
|
400
|
+
var state = TextEditState.init("AéB");
|
|
401
|
+
|
|
402
|
+
state = try state.apply(.{ .move_caret = .{ .direction = .previous } }, &storage_a);
|
|
403
|
+
try std.testing.expectEqual(@as(usize, 3), state.selection.focus);
|
|
404
|
+
|
|
405
|
+
state = try state.apply(.delete_backward, &storage_a);
|
|
406
|
+
try std.testing.expectEqualStrings("AB", state.text);
|
|
407
|
+
try std.testing.expectEqual(@as(usize, 1), state.selection.focus);
|
|
408
|
+
|
|
409
|
+
state = try state.apply(.{ .insert_text = "x" }, &storage_b);
|
|
410
|
+
try std.testing.expectEqualStrings("AxB", state.text);
|
|
411
|
+
try std.testing.expectEqual(@as(usize, 2), state.selection.focus);
|
|
412
|
+
|
|
413
|
+
state = try state.apply(.clear, &storage_a);
|
|
414
|
+
try std.testing.expectEqualStrings("", state.text);
|
|
415
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(0), state.selection);
|
|
416
|
+
|
|
417
|
+
state = TextEditState{ .text = "hello brave world", .selection = TextSelection.collapsed(17) };
|
|
418
|
+
state = try state.apply(.delete_word_backward, &storage_b);
|
|
419
|
+
try std.testing.expectEqualStrings("hello brave ", state.text);
|
|
420
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(12), state.selection);
|
|
421
|
+
|
|
422
|
+
state = TextEditState{ .text = "hello brave world", .selection = TextSelection.collapsed(0) };
|
|
423
|
+
state = try state.apply(.delete_word_forward, &storage_a);
|
|
424
|
+
try std.testing.expectEqualStrings(" brave world", state.text);
|
|
425
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(0), state.selection);
|
|
426
|
+
|
|
427
|
+
state = TextEditState{ .text = "éclair cafe", .selection = TextSelection.collapsed(7) };
|
|
428
|
+
state = try state.apply(.delete_word_backward, &storage_b);
|
|
429
|
+
try std.testing.expectEqualStrings(" cafe", state.text);
|
|
430
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(0), state.selection);
|
|
431
|
+
|
|
432
|
+
state = TextEditState.init("");
|
|
433
|
+
state = try state.apply(.{ .insert_text = "AxB" }, &storage_b);
|
|
434
|
+
try std.testing.expectEqualStrings("AxB", state.text);
|
|
435
|
+
try std.testing.expectEqual(@as(usize, 3), state.selection.focus);
|
|
436
|
+
|
|
437
|
+
state = try state.apply(.{ .set_selection = .{ .anchor = 1, .focus = 3 } }, &storage_a);
|
|
438
|
+
state = try state.apply(.delete_forward, &storage_a);
|
|
439
|
+
try std.testing.expectEqualStrings("A", state.text);
|
|
440
|
+
try std.testing.expectEqual(@as(usize, 1), state.selection.focus);
|
|
441
|
+
|
|
442
|
+
var small: [1]u8 = undefined;
|
|
443
|
+
try std.testing.expectError(error.TextEditBufferTooSmall, state.apply(.{ .insert_text = "toolong" }, &small));
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
test "widget keyboard control intents map activation keys" {
|
|
447
|
+
const press = widgetKeyboardControlIntent(.{ .kind = .button, .text = "Save" }, .{ .phase = .key_down, .key = "enter" }).?;
|
|
448
|
+
try std.testing.expectEqual(WidgetControlIntentKind.press, press.kind);
|
|
449
|
+
try std.testing.expect(press.actions.press);
|
|
450
|
+
|
|
451
|
+
const select = widgetKeyboardControlIntent(.{ .kind = .select, .text = "Environment" }, .{ .phase = .key_down, .key = "space" }).?;
|
|
452
|
+
try std.testing.expectEqual(WidgetControlIntentKind.press, select.kind);
|
|
453
|
+
try std.testing.expect(select.actions.press);
|
|
454
|
+
|
|
455
|
+
const combobox = widgetKeyboardControlIntent(.{ .kind = .combobox, .text = "Search", .command = "search.open" }, .{ .phase = .key_down, .key = "enter" }).?;
|
|
456
|
+
try std.testing.expectEqual(WidgetControlIntentKind.press, combobox.kind);
|
|
457
|
+
try std.testing.expect(combobox.actions.press);
|
|
458
|
+
|
|
459
|
+
const toggle = widgetKeyboardControlIntent(.{ .kind = .toggle, .text = "Live" }, .{ .phase = .key_down, .key = "space" }).?;
|
|
460
|
+
try std.testing.expectEqual(WidgetControlIntentKind.toggle, toggle.kind);
|
|
461
|
+
try std.testing.expect(toggle.actions.toggle);
|
|
462
|
+
|
|
463
|
+
const accordion = widgetKeyboardControlIntent(.{ .kind = .accordion, .text = "Details" }, .{ .phase = .key_down, .key = "enter" }).?;
|
|
464
|
+
try std.testing.expectEqual(WidgetControlIntentKind.toggle, accordion.kind);
|
|
465
|
+
try std.testing.expect(accordion.actions.toggle);
|
|
466
|
+
|
|
467
|
+
const selected = widgetKeyboardControlIntent(.{ .kind = .segmented_control, .text = "Revenue", .command = "mode.change" }, .{ .phase = .key_down, .key = "enter" }).?;
|
|
468
|
+
try std.testing.expectEqual(WidgetControlIntentKind.select, selected.kind);
|
|
469
|
+
try std.testing.expect(selected.actions.select);
|
|
470
|
+
try std.testing.expect(selected.actions.press);
|
|
471
|
+
|
|
472
|
+
const radio = widgetKeyboardControlIntent(.{ .kind = .radio, .text = "Annual", .command = "billing.cadence" }, .{ .phase = .key_down, .key = "space" }).?;
|
|
473
|
+
try std.testing.expectEqual(WidgetControlIntentKind.select, radio.kind);
|
|
474
|
+
try std.testing.expect(radio.actions.select);
|
|
475
|
+
try std.testing.expect(radio.actions.press);
|
|
476
|
+
try std.testing.expect(!radio.actions.toggle);
|
|
477
|
+
|
|
478
|
+
try std.testing.expect(widgetKeyboardControlIntent(.{ .kind = .button, .text = "Save" }, .{ .phase = .key_down, .key = "enter", .modifiers = .{ .super = true } }) == null);
|
|
479
|
+
try std.testing.expect(widgetKeyboardControlIntent(.{ .kind = .button, .text = "Save", .state = .{ .disabled = true } }, .{ .phase = .key_down, .key = "enter" }) == null);
|
|
480
|
+
try std.testing.expect(widgetKeyboardControlIntent(.{ .kind = .button, .text = "Save" }, .{ .phase = .key_up, .key = "enter" }) == null);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
test "widget keyboard control intents map slider and scroll keys" {
|
|
484
|
+
const slider = Widget{ .kind = .slider, .value = 0.5 };
|
|
485
|
+
const increment = widgetKeyboardControlIntent(slider, .{ .phase = .key_down, .key = "arrowright" }).?;
|
|
486
|
+
try std.testing.expectEqual(WidgetControlIntentKind.set_value, increment.kind);
|
|
487
|
+
try std.testing.expect(increment.actions.increment);
|
|
488
|
+
try std.testing.expect(!increment.actions.decrement);
|
|
489
|
+
try std.testing.expectApproxEqAbs(@as(f32, 0.55), increment.value.?, 0.001);
|
|
490
|
+
|
|
491
|
+
const decrement = widgetKeyboardControlIntent(slider, .{ .phase = .key_down, .key = "arrowleft", .modifiers = .{ .shift = true } }).?;
|
|
492
|
+
try std.testing.expectEqual(WidgetControlIntentKind.set_value, decrement.kind);
|
|
493
|
+
try std.testing.expect(decrement.actions.decrement);
|
|
494
|
+
try std.testing.expectApproxEqAbs(@as(f32, 0.4), decrement.value.?, 0.001);
|
|
495
|
+
|
|
496
|
+
const end = widgetKeyboardControlIntent(slider, .{ .phase = .key_down, .key = "end" }).?;
|
|
497
|
+
try std.testing.expectEqual(WidgetControlIntentKind.set_value, end.kind);
|
|
498
|
+
try std.testing.expectApproxEqAbs(@as(f32, 1), end.value.?, 0.001);
|
|
499
|
+
|
|
500
|
+
const scroll = Widget{ .kind = .scroll_view, .frame = geometry.RectF.init(0, 0, 120, 100) };
|
|
501
|
+
const line_down = widgetKeyboardControlIntent(scroll, .{ .phase = .key_down, .key = "arrowdown" }).?;
|
|
502
|
+
try std.testing.expectEqual(WidgetControlIntentKind.scroll_by, line_down.kind);
|
|
503
|
+
try std.testing.expect(line_down.actions.increment);
|
|
504
|
+
try std.testing.expectApproxEqAbs(@as(f32, 35), line_down.delta, 0.001);
|
|
505
|
+
|
|
506
|
+
const page_up = widgetKeyboardControlIntent(scroll, .{ .phase = .key_down, .key = "pageup" }).?;
|
|
507
|
+
try std.testing.expectEqual(WidgetControlIntentKind.scroll_by, page_up.kind);
|
|
508
|
+
try std.testing.expect(page_up.actions.decrement);
|
|
509
|
+
try std.testing.expectApproxEqAbs(@as(f32, -85), page_up.delta, 0.001);
|
|
510
|
+
|
|
511
|
+
try std.testing.expectEqual(WidgetControlIntentKind.scroll_to_start, widgetKeyboardControlIntent(scroll, .{ .phase = .key_down, .key = "home" }).?.kind);
|
|
512
|
+
try std.testing.expectEqual(WidgetControlIntentKind.scroll_to_end, widgetKeyboardControlIntent(scroll, .{ .phase = .key_down, .key = "end" }).?.kind);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
test "widget semantic control intents map built-in actions" {
|
|
516
|
+
const press = widgetSemanticControlIntent(.{ .kind = .button, .text = "Save" }, .press).?;
|
|
517
|
+
try std.testing.expectEqual(WidgetControlIntentKind.press, press.kind);
|
|
518
|
+
try std.testing.expect(press.actions.press);
|
|
519
|
+
|
|
520
|
+
const select = widgetSemanticControlIntent(.{ .kind = .select, .text = "Environment" }, .press).?;
|
|
521
|
+
try std.testing.expectEqual(WidgetControlIntentKind.press, select.kind);
|
|
522
|
+
try std.testing.expect(select.actions.press);
|
|
523
|
+
|
|
524
|
+
const combobox = widgetSemanticControlIntent(.{ .kind = .combobox, .text = "Search", .command = "search.open" }, .press).?;
|
|
525
|
+
try std.testing.expectEqual(WidgetControlIntentKind.press, combobox.kind);
|
|
526
|
+
try std.testing.expect(combobox.actions.press);
|
|
527
|
+
|
|
528
|
+
const toggle = widgetSemanticControlIntent(.{ .kind = .checkbox, .text = "Selected" }, .toggle).?;
|
|
529
|
+
try std.testing.expectEqual(WidgetControlIntentKind.toggle, toggle.kind);
|
|
530
|
+
try std.testing.expect(toggle.actions.toggle);
|
|
531
|
+
|
|
532
|
+
const accordion = widgetSemanticControlIntent(.{ .kind = .accordion, .text = "Details" }, .toggle).?;
|
|
533
|
+
try std.testing.expectEqual(WidgetControlIntentKind.toggle, accordion.kind);
|
|
534
|
+
try std.testing.expect(accordion.actions.toggle);
|
|
535
|
+
|
|
536
|
+
const selected = widgetSemanticControlIntent(.{ .kind = .segmented_control, .text = "Revenue", .command = "mode.change" }, .select).?;
|
|
537
|
+
try std.testing.expectEqual(WidgetControlIntentKind.select, selected.kind);
|
|
538
|
+
try std.testing.expect(selected.actions.select);
|
|
539
|
+
try std.testing.expect(selected.actions.press);
|
|
540
|
+
|
|
541
|
+
const radio = widgetSemanticControlIntent(.{ .kind = .radio, .text = "Annual", .command = "billing.cadence" }, .select).?;
|
|
542
|
+
try std.testing.expectEqual(WidgetControlIntentKind.select, radio.kind);
|
|
543
|
+
try std.testing.expect(radio.actions.select);
|
|
544
|
+
try std.testing.expect(radio.actions.press);
|
|
545
|
+
try std.testing.expect(!radio.actions.toggle);
|
|
546
|
+
|
|
547
|
+
const pressed_menu_item = widgetSemanticControlIntent(.{ .kind = .menu_item, .text = "Archive", .command = "archive" }, .press).?;
|
|
548
|
+
try std.testing.expectEqual(WidgetControlIntentKind.select, pressed_menu_item.kind);
|
|
549
|
+
try std.testing.expect(pressed_menu_item.actions.select);
|
|
550
|
+
try std.testing.expect(pressed_menu_item.actions.press);
|
|
551
|
+
|
|
552
|
+
try std.testing.expect(widgetSemanticControlIntent(.{ .kind = .button, .text = "Save" }, .toggle) == null);
|
|
553
|
+
try std.testing.expect(widgetSemanticControlIntent(.{ .kind = .button, .text = "Save", .state = .{ .disabled = true } }, .press) == null);
|
|
554
|
+
try std.testing.expect(widgetSemanticControlIntent(.{ .kind = .button, .text = "Save", .semantics = .{ .hidden = true } }, .press) == null);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
test "widget semantic control intents map slider and scroll actions" {
|
|
558
|
+
const slider = Widget{ .kind = .slider, .value = 0.5 };
|
|
559
|
+
const increment = widgetSemanticControlIntent(slider, .increment).?;
|
|
560
|
+
try std.testing.expectEqual(WidgetControlIntentKind.set_value, increment.kind);
|
|
561
|
+
try std.testing.expect(increment.actions.increment);
|
|
562
|
+
try std.testing.expect(!increment.actions.decrement);
|
|
563
|
+
try std.testing.expectApproxEqAbs(@as(f32, 0.55), increment.value.?, 0.001);
|
|
564
|
+
|
|
565
|
+
const decrement = widgetSemanticControlIntent(slider, .decrement).?;
|
|
566
|
+
try std.testing.expectEqual(WidgetControlIntentKind.set_value, decrement.kind);
|
|
567
|
+
try std.testing.expect(decrement.actions.decrement);
|
|
568
|
+
try std.testing.expectApproxEqAbs(@as(f32, 0.45), decrement.value.?, 0.001);
|
|
569
|
+
|
|
570
|
+
const max_slider = Widget{ .kind = .slider, .value = 0.98 };
|
|
571
|
+
try std.testing.expectApproxEqAbs(@as(f32, 1), widgetSemanticControlIntent(max_slider, .increment).?.value.?, 0.001);
|
|
572
|
+
|
|
573
|
+
const scroll = Widget{ .kind = .scroll_view, .frame = geometry.RectF.init(0, 0, 120, 100) };
|
|
574
|
+
try std.testing.expect(widgetSemanticControlIntent(scroll, .increment) == null);
|
|
575
|
+
|
|
576
|
+
const scroll_actions = WidgetActions{ .increment = true, .decrement = true };
|
|
577
|
+
const page_down = widgetSemanticControlIntentWithActions(scroll, .increment, scroll_actions).?;
|
|
578
|
+
try std.testing.expectEqual(WidgetControlIntentKind.scroll_by, page_down.kind);
|
|
579
|
+
try std.testing.expect(page_down.actions.increment);
|
|
580
|
+
try std.testing.expectApproxEqAbs(@as(f32, 85), page_down.delta, 0.001);
|
|
581
|
+
|
|
582
|
+
const page_up = widgetSemanticControlIntentWithActions(scroll, .decrement, scroll_actions).?;
|
|
583
|
+
try std.testing.expectEqual(WidgetControlIntentKind.scroll_by, page_up.kind);
|
|
584
|
+
try std.testing.expect(page_up.actions.decrement);
|
|
585
|
+
try std.testing.expectApproxEqAbs(@as(f32, -85), page_up.delta, 0.001);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
test "widget keyboard events map to text edit events" {
|
|
589
|
+
var storage_a: [64]u8 = undefined;
|
|
590
|
+
var storage_b: [64]u8 = undefined;
|
|
591
|
+
var state = TextEditState.init("Hi");
|
|
592
|
+
|
|
593
|
+
const insert = (WidgetKeyboardEvent{ .phase = .text_input, .text = "!" }).textEditEvent().?;
|
|
594
|
+
state = try state.apply(insert, &storage_a);
|
|
595
|
+
try std.testing.expectEqualStrings("Hi!", state.text);
|
|
596
|
+
try std.testing.expectEqual(@as(usize, 3), state.selection.focus);
|
|
597
|
+
|
|
598
|
+
const backspace = (WidgetKeyboardEvent{ .phase = .key_down, .key = "backspace" }).textEditEvent().?;
|
|
599
|
+
state = try state.apply(backspace, &storage_b);
|
|
600
|
+
try std.testing.expectEqualStrings("Hi", state.text);
|
|
601
|
+
try std.testing.expectEqual(@as(usize, 2), state.selection.focus);
|
|
602
|
+
|
|
603
|
+
const extend_left = (WidgetKeyboardEvent{ .phase = .key_down, .key = "arrowleft", .modifiers = .{ .shift = true } }).textEditEvent().?;
|
|
604
|
+
state = try state.apply(extend_left, &storage_a);
|
|
605
|
+
try std.testing.expectEqual(@as(usize, 2), state.selection.anchor);
|
|
606
|
+
try std.testing.expectEqual(@as(usize, 1), state.selection.focus);
|
|
607
|
+
|
|
608
|
+
const delete_forward = (WidgetKeyboardEvent{ .phase = .key_down, .key = "delete" }).textEditEvent().?;
|
|
609
|
+
state = try state.apply(delete_forward, &storage_b);
|
|
610
|
+
try std.testing.expectEqualStrings("H", state.text);
|
|
611
|
+
try std.testing.expectEqual(@as(usize, 1), state.selection.focus);
|
|
612
|
+
|
|
613
|
+
const home = (WidgetKeyboardEvent{ .phase = .key_down, .key = "home" }).textEditEvent().?;
|
|
614
|
+
state = try state.apply(home, &storage_a);
|
|
615
|
+
try std.testing.expectEqual(@as(usize, 0), state.selection.focus);
|
|
616
|
+
|
|
617
|
+
const select_all = (WidgetKeyboardEvent{ .phase = .key_down, .key = "a", .modifiers = .{ .super = true } }).textEditEvent().?;
|
|
618
|
+
state = try state.apply(select_all, &storage_b);
|
|
619
|
+
try std.testing.expectEqual(@as(usize, 0), state.selection.anchor);
|
|
620
|
+
try std.testing.expectEqual(@as(usize, 1), state.selection.focus);
|
|
621
|
+
|
|
622
|
+
state = try state.apply(.{ .insert_text = "!" }, &storage_a);
|
|
623
|
+
try std.testing.expectEqualStrings("!", state.text);
|
|
624
|
+
try std.testing.expectEqual(@as(usize, 1), state.selection.focus);
|
|
625
|
+
|
|
626
|
+
const option_insert = (WidgetKeyboardEvent{ .phase = .text_input, .text = "@", .modifiers = .{ .alt = true } }).textEditEvent().?;
|
|
627
|
+
switch (option_insert) {
|
|
628
|
+
.insert_text => |text| try std.testing.expectEqualStrings("@", text),
|
|
629
|
+
else => try std.testing.expect(false),
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
var nav_storage: [64]u8 = undefined;
|
|
633
|
+
var nav_state = TextEditState{ .text = "hello", .selection = TextSelection.collapsed(2) };
|
|
634
|
+
const command_left = (WidgetKeyboardEvent{ .phase = .key_down, .key = "arrowleft", .modifiers = .{ .super = true } }).textEditEvent().?;
|
|
635
|
+
nav_state = try nav_state.apply(command_left, &nav_storage);
|
|
636
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(0), nav_state.selection);
|
|
637
|
+
|
|
638
|
+
nav_state = TextEditState{ .text = "hello", .selection = TextSelection.collapsed(2) };
|
|
639
|
+
const command_right = (WidgetKeyboardEvent{ .phase = .key_down, .key = "arrowright", .modifiers = .{ .super = true } }).textEditEvent().?;
|
|
640
|
+
nav_state = try nav_state.apply(command_right, &nav_storage);
|
|
641
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(5), nav_state.selection);
|
|
642
|
+
|
|
643
|
+
nav_state = TextEditState{ .text = "hello", .selection = TextSelection.collapsed(4) };
|
|
644
|
+
const shift_command_left = (WidgetKeyboardEvent{ .phase = .key_down, .key = "arrowleft", .modifiers = .{ .super = true, .shift = true } }).textEditEvent().?;
|
|
645
|
+
nav_state = try nav_state.apply(shift_command_left, &nav_storage);
|
|
646
|
+
try std.testing.expectEqualDeep(TextSelection{ .anchor = 4, .focus = 0 }, nav_state.selection);
|
|
647
|
+
|
|
648
|
+
nav_state = TextEditState{ .text = "hello brave world", .selection = TextSelection.collapsed(17) };
|
|
649
|
+
const option_left = (WidgetKeyboardEvent{ .phase = .key_down, .key = "arrowleft", .modifiers = .{ .alt = true } }).textEditEvent().?;
|
|
650
|
+
nav_state = try nav_state.apply(option_left, &nav_storage);
|
|
651
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(12), nav_state.selection);
|
|
652
|
+
|
|
653
|
+
nav_state = try nav_state.apply(option_left, &nav_storage);
|
|
654
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(6), nav_state.selection);
|
|
655
|
+
|
|
656
|
+
nav_state = TextEditState{ .text = "hello brave world", .selection = TextSelection.collapsed(0) };
|
|
657
|
+
const control_right = (WidgetKeyboardEvent{ .phase = .key_down, .key = "arrowright", .modifiers = .{ .control = true } }).textEditEvent().?;
|
|
658
|
+
nav_state = try nav_state.apply(control_right, &nav_storage);
|
|
659
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(5), nav_state.selection);
|
|
660
|
+
|
|
661
|
+
nav_state = try nav_state.apply(control_right, &nav_storage);
|
|
662
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(11), nav_state.selection);
|
|
663
|
+
|
|
664
|
+
nav_state = TextEditState{ .text = "hello brave world", .selection = TextSelection.collapsed(17) };
|
|
665
|
+
const shift_option_left = (WidgetKeyboardEvent{ .phase = .key_down, .key = "arrowleft", .modifiers = .{ .alt = true, .shift = true } }).textEditEvent().?;
|
|
666
|
+
nav_state = try nav_state.apply(shift_option_left, &nav_storage);
|
|
667
|
+
try std.testing.expectEqualDeep(TextSelection{ .anchor = 17, .focus = 12 }, nav_state.selection);
|
|
668
|
+
|
|
669
|
+
nav_state = TextEditState{ .text = "éclair cafe", .selection = TextSelection.collapsed(0) };
|
|
670
|
+
const unicode_control_right = (WidgetKeyboardEvent{ .phase = .key_down, .key = "arrowright", .modifiers = .{ .control = true } }).textEditEvent().?;
|
|
671
|
+
nav_state = try nav_state.apply(unicode_control_right, &nav_storage);
|
|
672
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(7), nav_state.selection);
|
|
673
|
+
|
|
674
|
+
nav_state = TextEditState{ .text = "hello brave world", .selection = TextSelection.collapsed(17) };
|
|
675
|
+
const option_backspace = (WidgetKeyboardEvent{ .phase = .key_down, .key = "backspace", .modifiers = .{ .alt = true } }).textEditEvent().?;
|
|
676
|
+
nav_state = try nav_state.apply(option_backspace, &nav_storage);
|
|
677
|
+
try std.testing.expectEqualStrings("hello brave ", nav_state.text);
|
|
678
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(12), nav_state.selection);
|
|
679
|
+
|
|
680
|
+
nav_state = TextEditState{ .text = "hello brave world", .selection = TextSelection.collapsed(0) };
|
|
681
|
+
const control_delete = (WidgetKeyboardEvent{ .phase = .key_down, .key = "delete", .modifiers = .{ .control = true } }).textEditEvent().?;
|
|
682
|
+
nav_state = try nav_state.apply(control_delete, &nav_storage);
|
|
683
|
+
try std.testing.expectEqualStrings(" brave world", nav_state.text);
|
|
684
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(0), nav_state.selection);
|
|
685
|
+
|
|
686
|
+
try std.testing.expect((WidgetKeyboardEvent{ .phase = .text_input, .text = "a", .modifiers = .{ .super = true } }).textEditEvent() == null);
|
|
687
|
+
try std.testing.expect((WidgetKeyboardEvent{ .phase = .key_down, .key = "arrowleft", .modifiers = .{ .alt = true, .control = true } }).textEditEvent() == null);
|
|
688
|
+
try std.testing.expect((WidgetKeyboardEvent{ .phase = .key_down, .key = "backspace", .modifiers = .{ .alt = true, .control = true } }).textEditEvent() == null);
|
|
689
|
+
try std.testing.expect((WidgetKeyboardEvent{ .phase = .key_down, .key = "a", .modifiers = .{ .super = true, .shift = true } }).textEditEvent() == null);
|
|
690
|
+
try std.testing.expect((WidgetKeyboardEvent{ .phase = .key_up, .key = "backspace" }).textEditEvent() == null);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
test "text edit state tracks ime composition ranges" {
|
|
694
|
+
var storage_a: [64]u8 = undefined;
|
|
695
|
+
var storage_b: [64]u8 = undefined;
|
|
696
|
+
var state = TextEditState.init("hello");
|
|
697
|
+
|
|
698
|
+
state = try state.apply(.{ .set_selection = .{ .anchor = 1, .focus = 4 } }, &storage_a);
|
|
699
|
+
state = try state.apply(.{ .set_composition = .{ .text = "é", .cursor = 2 } }, &storage_a);
|
|
700
|
+
try std.testing.expectEqualStrings("héo", state.text);
|
|
701
|
+
try std.testing.expectEqualDeep(TextRange.init(1, 3), state.composition.?);
|
|
702
|
+
try std.testing.expectEqual(@as(usize, 3), state.selection.focus);
|
|
703
|
+
|
|
704
|
+
state = try state.apply(.commit_composition, &storage_b);
|
|
705
|
+
try std.testing.expectEqualStrings("héo", state.text);
|
|
706
|
+
try std.testing.expect(state.composition == null);
|
|
707
|
+
|
|
708
|
+
state = try state.apply(.{ .set_composition = .{ .text = "ll", .cursor = 2 } }, &storage_b);
|
|
709
|
+
try std.testing.expectEqualStrings("héllo", state.text);
|
|
710
|
+
state = try state.apply(.cancel_composition, &storage_a);
|
|
711
|
+
try std.testing.expectEqualStrings("héo", state.text);
|
|
712
|
+
try std.testing.expectEqual(@as(usize, 3), state.selection.focus);
|
|
713
|
+
try std.testing.expect(state.composition == null);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
test "text bounds follow utf8 scalar fallback and shaped y offsets" {
|
|
717
|
+
// Metric boxes inflate by the ink allowance (left/bottom 0.1em,
|
|
718
|
+
// right 0.35em) so real glyph outlines never clip at the bounds.
|
|
719
|
+
try expectRectApprox(geometry.RectF.init(1, 8, 19.47, 13.5), textBounds(.{
|
|
720
|
+
.font_id = 1,
|
|
721
|
+
.size = 10,
|
|
722
|
+
.origin = geometry.PointF.init(2, 18),
|
|
723
|
+
.color = Color.rgb8(0, 0, 0),
|
|
724
|
+
.text = "é B",
|
|
725
|
+
}));
|
|
726
|
+
|
|
727
|
+
const glyphs = [_]Glyph{
|
|
728
|
+
.{ .id = 1, .x = 0, .y = -2, .advance = 6 },
|
|
729
|
+
.{ .id = 2, .x = 8, .y = 3, .advance = 5 },
|
|
730
|
+
};
|
|
731
|
+
try expectRect(geometry.RectF.init(3, 8, 17.5, 18.5), textBounds(.{
|
|
732
|
+
.font_id = 1,
|
|
733
|
+
.size = 10,
|
|
734
|
+
.origin = geometry.PointF.init(4, 20),
|
|
735
|
+
.color = Color.rgb8(0, 0, 0),
|
|
736
|
+
.glyphs = &glyphs,
|
|
737
|
+
}));
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
test "text bounds and reference renderer honor per-run wrapping" {
|
|
741
|
+
const text = DrawText{
|
|
742
|
+
.font_id = 1,
|
|
743
|
+
.size = 10,
|
|
744
|
+
.origin = geometry.PointF.init(0, 10),
|
|
745
|
+
.color = Color.rgb8(255, 255, 255),
|
|
746
|
+
.text = "ABCD",
|
|
747
|
+
.text_layout = .{ .max_width = 10, .line_height = 12, .wrap = .character },
|
|
748
|
+
};
|
|
749
|
+
// Metric box (0, 0, 7.11, 48) plus the ink allowance.
|
|
750
|
+
try expectRectApprox(geometry.RectF.init(-1, 0, 11.61, 49), textBounds(text));
|
|
751
|
+
|
|
752
|
+
const commands = [_]CanvasCommand{.{ .draw_text = text }};
|
|
753
|
+
var render_commands: [1]RenderCommand = undefined;
|
|
754
|
+
const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
|
|
755
|
+
try std.testing.expectEqual(@as(usize, 1), render_plan.commandCount());
|
|
756
|
+
try expectRectApprox(geometry.RectF.init(-1, 0, 11.61, 49), render_plan.commands[0].bounds);
|
|
757
|
+
|
|
758
|
+
var pixels: [16 * 32 * 4]u8 = [_]u8{0} ** (16 * 32 * 4);
|
|
759
|
+
const surface = try ReferenceRenderSurface.init(16, 32, &pixels);
|
|
760
|
+
try surface.renderPass(.{
|
|
761
|
+
.commands = render_plan.commands,
|
|
762
|
+
.surface_size = geometry.SizeF.init(16, 32),
|
|
763
|
+
.full_repaint = true,
|
|
764
|
+
}, Color.rgb8(0, 0, 0));
|
|
765
|
+
// Real Geist outlines replaced block glyphs: line one's 'A' inks
|
|
766
|
+
// from cap height (row 3) down to the baseline at row 10, and line
|
|
767
|
+
// two's 'B' from row 15 under the 12px line advance; the sampled
|
|
768
|
+
// pixels sit on anti-aliased stem edges.
|
|
769
|
+
try expectPixelRgba8([4]u8{ 225, 225, 225, 255 }, surface, 1, 7);
|
|
770
|
+
try expectPixelRgba8([4]u8{ 0, 0, 0, 255 }, surface, 1, 1);
|
|
771
|
+
try expectPixelRgba8([4]u8{ 241, 241, 241, 255 }, surface, 1, 15);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
test "text layout wraps words into deterministic line boxes" {
|
|
775
|
+
const text = DrawText{
|
|
776
|
+
.font_id = 1,
|
|
777
|
+
.size = 10,
|
|
778
|
+
.origin = geometry.PointF.init(4, 20),
|
|
779
|
+
.color = Color.rgb8(0, 0, 0),
|
|
780
|
+
.text = "Hello world from zero",
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
var lines: [4]TextLine = undefined;
|
|
784
|
+
const plan = try layoutTextRunPlan(text, .{ .max_width = 30, .line_height = 14, .wrap = .word }, &lines);
|
|
785
|
+
const layout = plan.layout;
|
|
786
|
+
try std.testing.expectEqual(@as(FontId, 1), plan.key.font_id);
|
|
787
|
+
try std.testing.expectEqual(@as(f32, 10), plan.key.size);
|
|
788
|
+
try std.testing.expectEqual(@as(f32, 30), plan.key.max_width);
|
|
789
|
+
try std.testing.expectEqual(@as(f32, 14), plan.key.line_height);
|
|
790
|
+
try std.testing.expectEqual(TextWrap.word, plan.key.wrap);
|
|
791
|
+
try std.testing.expectEqual(TextAlign.start, plan.key.alignment);
|
|
792
|
+
try std.testing.expectEqual(text.text.len, plan.key.text_len);
|
|
793
|
+
try std.testing.expectEqual(@as(usize, 0), plan.key.glyph_count);
|
|
794
|
+
try std.testing.expect(plan.key.fingerprint != 0);
|
|
795
|
+
try std.testing.expectEqual(@as(usize, 4), layout.lineCount());
|
|
796
|
+
try std.testing.expectEqual(@as(usize, 0), layout.lines[0].text_start);
|
|
797
|
+
try std.testing.expectEqual(@as(usize, 5), layout.lines[0].text_len);
|
|
798
|
+
try expectRectApprox(geometry.RectF.init(4, 10, 24.25, 14), layout.lines[0].bounds);
|
|
799
|
+
try std.testing.expectEqual(@as(usize, 6), layout.lines[1].text_start);
|
|
800
|
+
try std.testing.expectEqual(@as(usize, 5), layout.lines[1].text_len);
|
|
801
|
+
try std.testing.expectEqual(@as(f32, 34), layout.lines[1].baseline);
|
|
802
|
+
try std.testing.expectEqual(@as(usize, 12), layout.lines[2].text_start);
|
|
803
|
+
try std.testing.expectEqual(@as(usize, 4), layout.lines[2].text_len);
|
|
804
|
+
try std.testing.expectEqual(@as(usize, 17), layout.lines[3].text_start);
|
|
805
|
+
try std.testing.expectEqual(@as(usize, 4), layout.lines[3].text_len);
|
|
806
|
+
try expectRectApprox(geometry.RectF.init(4, 10, 26.61, 56), layout.bounds);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// ------------------------------------------------- single-line elision
|
|
810
|
+
|
|
811
|
+
fn elisionText(content: []const u8) DrawText {
|
|
812
|
+
return .{
|
|
813
|
+
.font_id = 1,
|
|
814
|
+
.size = 10,
|
|
815
|
+
.origin = geometry.PointF.init(0, 10),
|
|
816
|
+
.color = Color.rgb8(0, 0, 0),
|
|
817
|
+
.text = content,
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
test "single-line overflow elides behind a trailing ellipsis on the measurement seam" {
|
|
822
|
+
const content = "Quarterly revenue report";
|
|
823
|
+
const size: f32 = 10;
|
|
824
|
+
const full_width = estimateTextWidth(content, size);
|
|
825
|
+
const ellipsis_advance = support.textEllipsisAdvance(null, 1, size);
|
|
826
|
+
try std.testing.expect(ellipsis_advance > 0);
|
|
827
|
+
|
|
828
|
+
// Fits exactly: not one glyph is touched and no marker is reserved.
|
|
829
|
+
var lines: [2]TextLine = undefined;
|
|
830
|
+
const exact = try layoutTextRun(elisionText(content), .{ .max_width = full_width, .line_height = 14, .wrap = .none }, &lines);
|
|
831
|
+
try std.testing.expectEqual(@as(usize, 1), exact.lineCount());
|
|
832
|
+
try std.testing.expect(!exact.lines[0].isElided());
|
|
833
|
+
try std.testing.expectEqual(content.len, exact.lines[0].paintedTextLen());
|
|
834
|
+
try std.testing.expectApproxEqAbs(full_width, exact.lines[0].bounds.width, 0.001);
|
|
835
|
+
|
|
836
|
+
// One measurement quantum over: the tail elides and the painted
|
|
837
|
+
// extent (kept prefix + ellipsis) never exceeds the box.
|
|
838
|
+
const squeezed = try layoutTextRun(elisionText(content), .{ .max_width = full_width - 0.5, .line_height = 14, .wrap = .none }, &lines);
|
|
839
|
+
const line = squeezed.lines[0];
|
|
840
|
+
try std.testing.expect(line.isElided());
|
|
841
|
+
try std.testing.expect(line.hasEllipsis());
|
|
842
|
+
try std.testing.expect(line.paintedTextLen() < content.len);
|
|
843
|
+
// The logical range still covers every byte (selection/copy).
|
|
844
|
+
try std.testing.expectEqual(content.len, line.text_len);
|
|
845
|
+
try std.testing.expect(line.bounds.width <= full_width - 0.5);
|
|
846
|
+
|
|
847
|
+
// Half the width keeps roughly half the content.
|
|
848
|
+
const half = try layoutTextRun(elisionText(content), .{ .max_width = full_width * 0.5, .line_height = 14, .wrap = .none }, &lines);
|
|
849
|
+
try std.testing.expect(half.lines[0].isElided());
|
|
850
|
+
try std.testing.expect(half.lines[0].paintedTextLen() < content.len / 2 + 4);
|
|
851
|
+
try std.testing.expect(half.lines[0].bounds.width <= full_width * 0.5);
|
|
852
|
+
// A kept prefix never ends in a break byte ("Quarterly …").
|
|
853
|
+
const painted = content[0..half.lines[0].paintedTextLen()];
|
|
854
|
+
try std.testing.expect(painted.len > 0 and painted[painted.len - 1] != ' ');
|
|
855
|
+
|
|
856
|
+
// Exactly the marker's width: an ellipsis-only line.
|
|
857
|
+
const marker_only = try layoutTextRun(elisionText(content), .{ .max_width = ellipsis_advance, .line_height = 14, .wrap = .none }, &lines);
|
|
858
|
+
try std.testing.expectEqual(@as(usize, 0), marker_only.lines[0].paintedTextLen());
|
|
859
|
+
try std.testing.expect(marker_only.lines[0].hasEllipsis());
|
|
860
|
+
try std.testing.expectApproxEqAbs(ellipsis_advance, marker_only.lines[0].bounds.width, 0.001);
|
|
861
|
+
|
|
862
|
+
// Narrower than the marker itself: paint nothing rather than lie.
|
|
863
|
+
const starved = try layoutTextRun(elisionText(content), .{ .max_width = 1, .line_height = 14, .wrap = .none }, &lines);
|
|
864
|
+
try std.testing.expect(starved.lines[0].isElided());
|
|
865
|
+
try std.testing.expect(!starved.lines[0].hasEllipsis());
|
|
866
|
+
try std.testing.expectEqual(@as(usize, 0), starved.lines[0].paintedTextLen());
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
test "elision cuts on UTF-8 cluster boundaries (CJK and emoji)" {
|
|
870
|
+
const content = "\u{4f60}\u{597d}\u{4e16}\u{754c}\u{1F30D} end";
|
|
871
|
+
const size: f32 = 10;
|
|
872
|
+
const full_width = estimateTextWidth(content, size);
|
|
873
|
+
var lines: [2]TextLine = undefined;
|
|
874
|
+
// Sweep every budget from starved to full: the kept prefix must
|
|
875
|
+
// always land on a scalar boundary, never mid-sequence.
|
|
876
|
+
var budget: f32 = 2;
|
|
877
|
+
while (budget < full_width) : (budget += 3) {
|
|
878
|
+
const layout = try layoutTextRun(elisionText(content), .{ .max_width = budget, .line_height = 14, .wrap = .none }, &lines);
|
|
879
|
+
const painted_len = layout.lines[0].paintedTextLen();
|
|
880
|
+
try std.testing.expectEqual(painted_len, canvas.snapTextOffset(content, painted_len));
|
|
881
|
+
// Painted extent stays inside the budget plus the exact-fit
|
|
882
|
+
// slack (sub-pixel by design).
|
|
883
|
+
try std.testing.expect(layout.lines[0].bounds.width <= budget + 0.13);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
test "clip opt-out and wrapping modes never elide" {
|
|
888
|
+
const content = "Quarterly revenue report";
|
|
889
|
+
const full_width = estimateTextWidth(content, 10);
|
|
890
|
+
var lines: [8]TextLine = undefined;
|
|
891
|
+
// Clip: the line keeps every byte; the caller's frame clip truncates.
|
|
892
|
+
const clipped = try layoutTextRun(elisionText(content), .{ .max_width = full_width * 0.5, .line_height = 14, .wrap = .none, .overflow = .clip }, &lines);
|
|
893
|
+
try std.testing.expect(!clipped.lines[0].isElided());
|
|
894
|
+
try std.testing.expectEqual(content.len, clipped.lines[0].paintedTextLen());
|
|
895
|
+
// Word wrap: overflow policy is single-line only.
|
|
896
|
+
const wrapped = try layoutTextRun(elisionText(content), .{ .max_width = full_width * 0.5, .line_height = 14, .wrap = .word }, &lines);
|
|
897
|
+
try std.testing.expect(wrapped.lineCount() > 1);
|
|
898
|
+
for (wrapped.lines) |line| try std.testing.expect(!line.isElided());
|
|
899
|
+
// Unbounded single line: nothing to elide against.
|
|
900
|
+
const unbounded = try layoutTextRun(elisionText(content), .{ .max_width = 0, .line_height = 14, .wrap = .none }, &lines);
|
|
901
|
+
try std.testing.expect(!unbounded.lines[0].isElided());
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
test "shaped glyph runs elide by glyph advance with the same marker" {
|
|
905
|
+
const glyphs = [_]Glyph{
|
|
906
|
+
.{ .id = 1, .x = 0, .y = 0, .advance = 8, .text_start = 0, .text_len = 1 },
|
|
907
|
+
.{ .id = 2, .x = 8, .y = 0, .advance = 8, .text_start = 1, .text_len = 1 },
|
|
908
|
+
.{ .id = 3, .x = 16, .y = 0, .advance = 8, .text_start = 2, .text_len = 1 },
|
|
909
|
+
};
|
|
910
|
+
var lines: [2]TextLine = undefined;
|
|
911
|
+
const layout = try layoutTextRun(.{
|
|
912
|
+
.font_id = 1,
|
|
913
|
+
.size = 10,
|
|
914
|
+
.origin = geometry.PointF.init(0, 10),
|
|
915
|
+
.color = Color.rgb8(0, 0, 0),
|
|
916
|
+
.text = "AVX",
|
|
917
|
+
.glyphs = &glyphs,
|
|
918
|
+
}, .{ .max_width = 20, .line_height = 14, .wrap = .none }, &lines);
|
|
919
|
+
const line = layout.lines[0];
|
|
920
|
+
try std.testing.expect(line.isElided());
|
|
921
|
+
try std.testing.expect(line.hasEllipsis());
|
|
922
|
+
try std.testing.expect(line.paintedGlyphLen() < glyphs.len);
|
|
923
|
+
try std.testing.expectEqual(@as(usize, 3), line.glyph_len);
|
|
924
|
+
try std.testing.expect(line.bounds.width <= 20);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
test "elided lines pin caret and hit mapping at the painted edge" {
|
|
928
|
+
const content = "Quarterly revenue report";
|
|
929
|
+
const full_width = estimateTextWidth(content, 10);
|
|
930
|
+
const options = canvas.TextLayoutOptions{ .max_width = full_width * 0.5, .line_height = 14, .wrap = .none };
|
|
931
|
+
const text = elisionText(content);
|
|
932
|
+
var lines: [2]TextLine = undefined;
|
|
933
|
+
const layout = try layoutTextRun(text, options, &lines);
|
|
934
|
+
const line = layout.lines[0];
|
|
935
|
+
try std.testing.expect(line.isElided());
|
|
936
|
+
// A caret in the hidden tail pins to the painted right edge.
|
|
937
|
+
const caret = canvas.layoutTextCaretRect(text, options, content.len).?;
|
|
938
|
+
try std.testing.expect(caret.x <= line.bounds.maxX() + 0.001);
|
|
939
|
+
// A point past the painted edge selects to the line's true end
|
|
940
|
+
// (rightward sweeps keep selecting the hidden bytes)...
|
|
941
|
+
try std.testing.expectEqual(content.len, canvas.layoutTextOffsetForPoint(text, options, geometry.PointF.init(line.bounds.maxX() + 5, 10)).?);
|
|
942
|
+
// ...while a point on the marker itself maps to the kept prefix.
|
|
943
|
+
const on_marker = canvas.layoutTextOffsetForPoint(text, options, geometry.PointF.init(line.bounds.maxX() - line.ellipsis_advance * 0.5, 10)).?;
|
|
944
|
+
try std.testing.expectEqual(line.paintedTextLen(), on_marker);
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
test "ellipsis advance matches the estimator seam for every font id" {
|
|
948
|
+
// The comptime fast path must be bit-identical to measuring the
|
|
949
|
+
// marker as a run — including registered ids (measured as the sans
|
|
950
|
+
// estimator measures them; a registered face lacking U+2026 takes
|
|
951
|
+
// the documented notdef fallback on both sides of the seam) and the
|
|
952
|
+
// mono pitch.
|
|
953
|
+
for ([_]FontId{ 1, 2, 3, 4, 5, 6, 64, 900 }) |font_id| {
|
|
954
|
+
try std.testing.expectEqual(
|
|
955
|
+
estimateTextWidthForFont(font_id, "\u{2026}", 13),
|
|
956
|
+
support.textEllipsisAdvance(null, font_id, 13),
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
try std.testing.expectEqual(@as(f32, 13 * canvas.mono_advance_em), support.textEllipsisAdvance(null, 2, 13));
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
test "overflow policy salts layout keys and fingerprints only when non-default" {
|
|
963
|
+
const content = "Quarterly revenue report";
|
|
964
|
+
const full_width = estimateTextWidth(content, 10);
|
|
965
|
+
var lines: [2]TextLine = undefined;
|
|
966
|
+
const elided = try layoutTextRunPlan(elisionText(content), .{ .max_width = full_width * 0.5, .line_height = 14, .wrap = .none }, &lines);
|
|
967
|
+
var clip_lines: [2]TextLine = undefined;
|
|
968
|
+
const clipped = try layoutTextRunPlan(elisionText(content), .{ .max_width = full_width * 0.5, .line_height = 14, .wrap = .none, .overflow = .clip }, &clip_lines);
|
|
969
|
+
try std.testing.expectEqual(canvas.TextOverflow.ellipsis, elided.key.overflow);
|
|
970
|
+
try std.testing.expectEqual(canvas.TextOverflow.clip, clipped.key.overflow);
|
|
971
|
+
// The two runs must never share a cache entry or a fingerprint.
|
|
972
|
+
try std.testing.expect(!canvas.textLayoutKeysEqual(elided.key, clipped.key));
|
|
973
|
+
try std.testing.expect(elided.key.fingerprint != clipped.key.fingerprint);
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
test "text layout aligns fallback and shaped line boxes" {
|
|
977
|
+
const text = DrawText{
|
|
978
|
+
.font_id = 1,
|
|
979
|
+
.size = 10,
|
|
980
|
+
.origin = geometry.PointF.init(4, 20),
|
|
981
|
+
.color = Color.rgb8(0, 0, 0),
|
|
982
|
+
.text = "Hi",
|
|
983
|
+
};
|
|
984
|
+
|
|
985
|
+
var center_lines: [1]TextLine = undefined;
|
|
986
|
+
const centered = try layoutTextRunPlan(text, .{ .max_width = 30, .line_height = 14, .alignment = .center }, ¢er_lines);
|
|
987
|
+
try std.testing.expectEqual(TextAlign.center, centered.key.alignment);
|
|
988
|
+
try expectRectApprox(geometry.RectF.init(14.215, 10, 9.57, 14), centered.layout.lines[0].bounds);
|
|
989
|
+
try expectRectApprox(geometry.RectF.init(14.215, 10, 9.57, 14), centered.layout.bounds);
|
|
990
|
+
|
|
991
|
+
var end_lines: [1]TextLine = undefined;
|
|
992
|
+
const end = try layoutTextRun(text, .{ .max_width = 30, .line_height = 14, .alignment = .end }, &end_lines);
|
|
993
|
+
try expectRectApprox(geometry.RectF.init(24.43, 10, 9.57, 14), end.lines[0].bounds);
|
|
994
|
+
|
|
995
|
+
const glyphs = [_]Glyph{
|
|
996
|
+
.{ .id = 1, .x = 0, .y = 0, .advance = 8 },
|
|
997
|
+
.{ .id = 2, .x = 8, .y = 0, .advance = 4 },
|
|
998
|
+
};
|
|
999
|
+
var shaped_lines: [1]TextLine = undefined;
|
|
1000
|
+
const shaped = try layoutTextRun(.{
|
|
1001
|
+
.font_id = 2,
|
|
1002
|
+
.size = 10,
|
|
1003
|
+
.origin = geometry.PointF.init(4, 20),
|
|
1004
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1005
|
+
.text = "AV",
|
|
1006
|
+
.glyphs = &glyphs,
|
|
1007
|
+
}, .{ .max_width = 20, .line_height = 14, .alignment = .center }, &shaped_lines);
|
|
1008
|
+
|
|
1009
|
+
try expectRect(geometry.RectF.init(8, 10, 12, 14), shaped.lines[0].bounds);
|
|
1010
|
+
try expectRect(geometry.RectF.init(8, 10, 12, 14), shaped.bounds);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
test "text layout caret selection and point queries have no line-count cap" {
|
|
1014
|
+
// A document with far more lines than any fixed query-side line
|
|
1015
|
+
// buffer ever held (the caret path once failed a >16-line textarea
|
|
1016
|
+
// with TextLayoutLineListFull and killed the app from a keystroke).
|
|
1017
|
+
// The streaming queries must resolve caret, selection, and hit
|
|
1018
|
+
// offsets for a document of any length.
|
|
1019
|
+
const doc = "word\n" ** 100;
|
|
1020
|
+
const text = DrawText{
|
|
1021
|
+
.font_id = 1,
|
|
1022
|
+
.size = 10,
|
|
1023
|
+
.origin = geometry.PointF.init(4, 20),
|
|
1024
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1025
|
+
.text = doc,
|
|
1026
|
+
};
|
|
1027
|
+
const options = TextLayoutOptions{ .max_width = 200, .line_height = 14, .wrap = .word };
|
|
1028
|
+
|
|
1029
|
+
// Caret at the end of the document: the trailing newline puts it on
|
|
1030
|
+
// line index 100 (the 101st, empty line).
|
|
1031
|
+
const caret = layoutTextCaretRect(text, options, doc.len).?;
|
|
1032
|
+
try std.testing.expectApproxEqAbs(@as(f32, 10 + 100 * 14), caret.y, 0.001);
|
|
1033
|
+
|
|
1034
|
+
// A whole-document selection folds the lines beyond the rect budget
|
|
1035
|
+
// into the last rect instead of erroring.
|
|
1036
|
+
var rects_buffer: [4]TextSelectionRect = undefined;
|
|
1037
|
+
const rects = layoutTextSelectionRects(text, options, TextRange.init(0, doc.len), &rects_buffer);
|
|
1038
|
+
try std.testing.expectEqual(@as(usize, 4), rects.len);
|
|
1039
|
+
try std.testing.expectEqualDeep(TextRange.init(0, 4), rects[0].range);
|
|
1040
|
+
try std.testing.expectEqual(@as(usize, doc.len - 1), rects[3].range.end);
|
|
1041
|
+
try std.testing.expect(rects[3].rect.maxY() > 10 + 99 * 14);
|
|
1042
|
+
|
|
1043
|
+
// Hit testing a point deep in the document resolves to that line.
|
|
1044
|
+
const offset = layoutTextOffsetForPoint(text, options, geometry.PointF.init(5, 10 + 50 * 14 + 7)).?;
|
|
1045
|
+
try std.testing.expectEqual(@as(usize, 50 * 5), offset);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
test "text layout maps caret selection and points across wrapped fallback lines" {
|
|
1049
|
+
const text = DrawText{
|
|
1050
|
+
.font_id = 1,
|
|
1051
|
+
.size = 10,
|
|
1052
|
+
.origin = geometry.PointF.init(4, 20),
|
|
1053
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1054
|
+
.text = "Hello world",
|
|
1055
|
+
};
|
|
1056
|
+
const options = TextLayoutOptions{ .max_width = 30, .line_height = 14, .wrap = .word };
|
|
1057
|
+
|
|
1058
|
+
try expectRectApprox(geometry.RectF.init(28.25, 10, 1, 14), layoutTextCaretRect(text, options, 5));
|
|
1059
|
+
|
|
1060
|
+
var selection_rects: [2]TextSelectionRect = undefined;
|
|
1061
|
+
const rects = layoutTextSelectionRects(text, options, TextRange.init(3, 8), &selection_rects);
|
|
1062
|
+
try std.testing.expectEqual(@as(usize, 2), rects.len);
|
|
1063
|
+
try std.testing.expectEqualDeep(TextRange.init(3, 5), rects[0].range);
|
|
1064
|
+
try expectRectApprox(geometry.RectF.init(19.63, 10, 8.62, 14), rects[0].rect);
|
|
1065
|
+
try std.testing.expectEqualDeep(TextRange.init(6, 8), rects[1].range);
|
|
1066
|
+
try expectRectApprox(geometry.RectF.init(4, 24, 13.98, 14), rects[1].rect);
|
|
1067
|
+
|
|
1068
|
+
const dashboard_value = DrawText{
|
|
1069
|
+
.font_id = default_sans_font_id,
|
|
1070
|
+
.size = 17,
|
|
1071
|
+
.origin = geometry.PointF.init(0, 17),
|
|
1072
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1073
|
+
.text = "$13.4M",
|
|
1074
|
+
};
|
|
1075
|
+
try expectRectApprox(
|
|
1076
|
+
geometry.RectF.init(57.001, 0, 1, 21.25),
|
|
1077
|
+
layoutTextCaretRect(dashboard_value, .{ .line_height = 21.25 }, dashboard_value.text.len),
|
|
1078
|
+
);
|
|
1079
|
+
|
|
1080
|
+
const offset = (layoutTextOffsetForPoint(text, options, geometry.PointF.init(16, 25))).?;
|
|
1081
|
+
try std.testing.expectEqual(@as(usize, 8), offset);
|
|
1082
|
+
|
|
1083
|
+
// A range spanning more lines than the caller's rect budget folds
|
|
1084
|
+
// the overflow into the last rect: a bounding highlight, no error.
|
|
1085
|
+
var one_rect: [1]TextSelectionRect = undefined;
|
|
1086
|
+
const folded = layoutTextSelectionRects(text, options, TextRange.init(3, 8), &one_rect);
|
|
1087
|
+
try std.testing.expectEqual(@as(usize, 1), folded.len);
|
|
1088
|
+
try std.testing.expectEqualDeep(TextRange.init(3, 8), folded[0].range);
|
|
1089
|
+
try expectRectApprox(geometry.RectF.init(4, 10, 24.25, 28), folded[0].rect);
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
test "text layout maps caret selection and points across shaped glyph lines" {
|
|
1093
|
+
const glyphs = [_]Glyph{
|
|
1094
|
+
.{ .id = 1, .x = 2, .y = -3, .advance = 5 },
|
|
1095
|
+
.{ .id = 2, .x = 6, .y = 4, .advance = 4 },
|
|
1096
|
+
};
|
|
1097
|
+
const text = DrawText{
|
|
1098
|
+
.font_id = 2,
|
|
1099
|
+
.size = 10,
|
|
1100
|
+
.origin = geometry.PointF.init(10, 20),
|
|
1101
|
+
.color = Color.rgb8(255, 255, 255),
|
|
1102
|
+
.text = "AV",
|
|
1103
|
+
.glyphs = &glyphs,
|
|
1104
|
+
};
|
|
1105
|
+
const options = TextLayoutOptions{ .line_height = 12 };
|
|
1106
|
+
|
|
1107
|
+
try expectRect(geometry.RectF.init(14, 7, 1, 19.5), layoutTextCaretRect(text, options, 1));
|
|
1108
|
+
|
|
1109
|
+
var selection_rects: [1]TextSelectionRect = undefined;
|
|
1110
|
+
const rects = layoutTextSelectionRects(text, options, TextRange.init(1, 2), &selection_rects);
|
|
1111
|
+
try std.testing.expectEqual(@as(usize, 1), rects.len);
|
|
1112
|
+
try expectRect(geometry.RectF.init(14, 7, 4, 19.5), rects[0].rect);
|
|
1113
|
+
|
|
1114
|
+
const offset = (layoutTextOffsetForPoint(text, options, geometry.PointF.init(13, 12))).?;
|
|
1115
|
+
try std.testing.expectEqual(@as(usize, 1), offset);
|
|
1116
|
+
|
|
1117
|
+
const commands = [_]CanvasCommand{.{ .draw_text = .{
|
|
1118
|
+
.font_id = text.font_id,
|
|
1119
|
+
.size = text.size,
|
|
1120
|
+
.origin = text.origin,
|
|
1121
|
+
.color = text.color,
|
|
1122
|
+
.text = text.text,
|
|
1123
|
+
.glyphs = text.glyphs,
|
|
1124
|
+
.text_layout = options,
|
|
1125
|
+
} }};
|
|
1126
|
+
var render_commands: [1]RenderCommand = undefined;
|
|
1127
|
+
const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
|
|
1128
|
+
var pixels: [24 * 32 * 4]u8 = [_]u8{0} ** (24 * 32 * 4);
|
|
1129
|
+
const surface = try ReferenceRenderSurface.init(24, 32, &pixels);
|
|
1130
|
+
try surface.renderPass(.{
|
|
1131
|
+
.commands = render_plan.commands,
|
|
1132
|
+
.surface_size = geometry.SizeF.init(24, 32),
|
|
1133
|
+
.full_repaint = true,
|
|
1134
|
+
}, Color.rgb8(0, 0, 0));
|
|
1135
|
+
try expectPixelRgba8([4]u8{ 255, 255, 255, 255 }, surface, 10, 8);
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
test "text layout maps caret selection and points through glyph text clusters" {
|
|
1139
|
+
const glyphs = [_]Glyph{
|
|
1140
|
+
.{ .id = 'o', .x = 0, .y = 0, .advance = 6, .text_start = 0, .text_len = 1 },
|
|
1141
|
+
.{ .id = 1001, .x = 6, .y = 0, .advance = 18, .text_start = 1, .text_len = 3 },
|
|
1142
|
+
.{ .id = 'c', .x = 24, .y = 0, .advance = 5, .text_start = 4, .text_len = 1 },
|
|
1143
|
+
.{ .id = 'e', .x = 29, .y = 0, .advance = 7, .text_start = 5, .text_len = 1 },
|
|
1144
|
+
};
|
|
1145
|
+
const text = DrawText{
|
|
1146
|
+
.font_id = 2,
|
|
1147
|
+
.size = 10,
|
|
1148
|
+
.origin = geometry.PointF.init(10, 20),
|
|
1149
|
+
.color = Color.rgb8(255, 255, 255),
|
|
1150
|
+
.text = "office",
|
|
1151
|
+
.glyphs = &glyphs,
|
|
1152
|
+
};
|
|
1153
|
+
const options = TextLayoutOptions{ .line_height = 12 };
|
|
1154
|
+
|
|
1155
|
+
var layout_lines: [1]TextLine = undefined;
|
|
1156
|
+
const layout = try layoutTextRun(text, options, &layout_lines);
|
|
1157
|
+
try std.testing.expectEqualDeep(TextRange.init(0, 6), textLineRange(text, layout.lines[0]));
|
|
1158
|
+
|
|
1159
|
+
try expectRectApprox(geometry.RectF.init(16, 10, 1, 12.5), layoutTextCaretRect(text, options, 1));
|
|
1160
|
+
try expectRectApprox(geometry.RectF.init(22, 10, 1, 12.5), layoutTextCaretRect(text, options, 2));
|
|
1161
|
+
try expectRectApprox(geometry.RectF.init(28, 10, 1, 12.5), layoutTextCaretRect(text, options, 3));
|
|
1162
|
+
try expectRectApprox(geometry.RectF.init(34, 10, 1, 12.5), layoutTextCaretRect(text, options, 4));
|
|
1163
|
+
|
|
1164
|
+
var selection_rects: [1]TextSelectionRect = undefined;
|
|
1165
|
+
const rects = layoutTextSelectionRects(text, options, TextRange.init(1, 4), &selection_rects);
|
|
1166
|
+
try std.testing.expectEqual(@as(usize, 1), rects.len);
|
|
1167
|
+
try std.testing.expectEqualDeep(TextRange.init(1, 4), rects[0].range);
|
|
1168
|
+
try expectRectApprox(geometry.RectF.init(16, 10, 18, 12.5), rects[0].rect);
|
|
1169
|
+
|
|
1170
|
+
try std.testing.expectEqual(@as(usize, 2), (layoutTextOffsetForPoint(text, options, geometry.PointF.init(21, 15))).?);
|
|
1171
|
+
try std.testing.expectEqual(@as(usize, 3), (layoutTextOffsetForPoint(text, options, geometry.PointF.init(27, 15))).?);
|
|
1172
|
+
try std.testing.expectEqual(@as(usize, 4), (layoutTextOffsetForPoint(text, options, geometry.PointF.init(33.5, 15))).?);
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
test "text layout measures utf8 scalars for fallback wrapping" {
|
|
1176
|
+
const text = DrawText{
|
|
1177
|
+
.font_id = 1,
|
|
1178
|
+
.size = 10,
|
|
1179
|
+
.origin = geometry.PointF.init(2, 18),
|
|
1180
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1181
|
+
.text = "éééé éé",
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1184
|
+
// é measures at the face's real 0.567 em advance, so "éééé" splits
|
|
1185
|
+
// after three scalars and the remaining "é éé" fits one line.
|
|
1186
|
+
var lines: [3]TextLine = undefined;
|
|
1187
|
+
const layout = try layoutTextRun(text, .{ .max_width = 20, .line_height = 12, .wrap = .word }, &lines);
|
|
1188
|
+
try std.testing.expectEqual(@as(usize, 2), layout.lineCount());
|
|
1189
|
+
try std.testing.expectEqual(@as(usize, 0), layout.lines[0].text_start);
|
|
1190
|
+
try std.testing.expectEqual(@as(usize, 6), layout.lines[0].text_len);
|
|
1191
|
+
try expectRectApprox(geometry.RectF.init(2, 8, 17.01, 12), layout.lines[0].bounds);
|
|
1192
|
+
try std.testing.expectEqual(@as(usize, 6), layout.lines[1].text_start);
|
|
1193
|
+
try std.testing.expectEqual(@as(usize, 7), layout.lines[1].text_len);
|
|
1194
|
+
try expectRectApprox(geometry.RectF.init(2, 20, 19.51, 12), layout.lines[1].bounds);
|
|
1195
|
+
try expectRectApprox(geometry.RectF.init(2, 8, 19.51, 24), layout.bounds);
|
|
1196
|
+
|
|
1197
|
+
var character_lines: [3]TextLine = undefined;
|
|
1198
|
+
const character_layout = try layoutTextRun(.{
|
|
1199
|
+
.font_id = 1,
|
|
1200
|
+
.size = 10,
|
|
1201
|
+
.origin = geometry.PointF.init(0, 10),
|
|
1202
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1203
|
+
.text = "ééé",
|
|
1204
|
+
}, .{ .max_width = 10, .line_height = 12, .wrap = .character }, &character_lines);
|
|
1205
|
+
try std.testing.expectEqual(@as(usize, 3), character_layout.lineCount());
|
|
1206
|
+
try std.testing.expectEqual(@as(usize, 0), character_layout.lines[0].text_start);
|
|
1207
|
+
try std.testing.expectEqual(@as(usize, 2), character_layout.lines[0].text_len);
|
|
1208
|
+
try std.testing.expectEqual(@as(usize, 2), character_layout.lines[1].text_start);
|
|
1209
|
+
try std.testing.expectEqual(@as(usize, 2), character_layout.lines[1].text_len);
|
|
1210
|
+
try std.testing.expectEqual(@as(usize, 4), character_layout.lines[2].text_start);
|
|
1211
|
+
try std.testing.expectEqual(@as(usize, 2), character_layout.lines[2].text_len);
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
test "text layout cache plans upload retain and evict work" {
|
|
1215
|
+
const text = DrawText{
|
|
1216
|
+
.font_id = 1,
|
|
1217
|
+
.size = 10,
|
|
1218
|
+
.origin = geometry.PointF.init(4, 20),
|
|
1219
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1220
|
+
.text = "Hello world from zero",
|
|
1221
|
+
};
|
|
1222
|
+
|
|
1223
|
+
var lines: [4]TextLine = undefined;
|
|
1224
|
+
const plan = try layoutTextRunPlan(text, .{ .max_width = 30, .line_height = 14, .wrap = .word }, &lines);
|
|
1225
|
+
var entries: [1]TextLayoutCacheEntry = undefined;
|
|
1226
|
+
var actions: [1]TextLayoutCacheAction = undefined;
|
|
1227
|
+
const first = try plan.cachePlan(&.{}, 1, &entries, &actions);
|
|
1228
|
+
try std.testing.expectEqual(@as(usize, 1), first.entryCount());
|
|
1229
|
+
try std.testing.expectEqual(@as(usize, 1), first.uploadCount());
|
|
1230
|
+
try std.testing.expectEqual(@as(usize, 0), first.retainCount());
|
|
1231
|
+
try std.testing.expectEqual(@as(usize, 0), first.evictCount());
|
|
1232
|
+
try std.testing.expectEqual(@as(usize, 4), first.entries[0].line_count);
|
|
1233
|
+
try std.testing.expectEqual(@as(u64, 1), first.entries[0].last_used_frame);
|
|
1234
|
+
try expectRectApprox(geometry.RectF.init(4, 10, 26.61, 56), first.entries[0].bounds);
|
|
1235
|
+
try std.testing.expectEqual(TextLayoutCacheActionKind.upload, first.actions[0].kind);
|
|
1236
|
+
|
|
1237
|
+
var retained_entries: [1]TextLayoutCacheEntry = undefined;
|
|
1238
|
+
var retained_actions: [1]TextLayoutCacheAction = undefined;
|
|
1239
|
+
const retained = try plan.cachePlan(first.entries, 2, &retained_entries, &retained_actions);
|
|
1240
|
+
try std.testing.expectEqual(@as(usize, 1), retained.entryCount());
|
|
1241
|
+
try std.testing.expectEqual(@as(usize, 0), retained.uploadCount());
|
|
1242
|
+
try std.testing.expectEqual(@as(usize, 1), retained.retainCount());
|
|
1243
|
+
try std.testing.expectEqual(@as(usize, 0), retained.evictCount());
|
|
1244
|
+
try std.testing.expectEqual(@as(u64, 2), retained.entries[0].last_used_frame);
|
|
1245
|
+
try std.testing.expectEqual(@as(?usize, 0), retained.actions[0].layout_index);
|
|
1246
|
+
try std.testing.expectEqual(@as(?usize, 0), retained.actions[0].cache_index);
|
|
1247
|
+
|
|
1248
|
+
var changed_lines: [4]TextLine = undefined;
|
|
1249
|
+
const changed_plan = try layoutTextRunPlan(text, .{ .max_width = 30, .line_height = 14, .wrap = .word, .alignment = .center }, &changed_lines);
|
|
1250
|
+
var changed_entries: [1]TextLayoutCacheEntry = undefined;
|
|
1251
|
+
var changed_actions: [2]TextLayoutCacheAction = undefined;
|
|
1252
|
+
const changed = try changed_plan.cachePlan(retained.entries, 3, &changed_entries, &changed_actions);
|
|
1253
|
+
try std.testing.expectEqual(@as(usize, 1), changed.entryCount());
|
|
1254
|
+
try std.testing.expectEqual(@as(usize, 1), changed.uploadCount());
|
|
1255
|
+
try std.testing.expectEqual(@as(usize, 0), changed.retainCount());
|
|
1256
|
+
try std.testing.expectEqual(@as(usize, 1), changed.evictCount());
|
|
1257
|
+
try std.testing.expectEqual(TextAlign.center, changed.entries[0].key.alignment);
|
|
1258
|
+
try std.testing.expectEqual(TextLayoutCacheActionKind.upload, changed.actions[0].kind);
|
|
1259
|
+
try std.testing.expectEqual(@as(?usize, 0), changed.actions[0].layout_index);
|
|
1260
|
+
try std.testing.expectEqual(TextLayoutCacheActionKind.evict, changed.actions[1].kind);
|
|
1261
|
+
try std.testing.expect(changed.actions[1].layout_index == null);
|
|
1262
|
+
try std.testing.expectEqual(@as(?usize, 0), changed.actions[1].cache_index);
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
test "display list text layout plan caches multiple text runs" {
|
|
1266
|
+
const commands = [_]CanvasCommand{
|
|
1267
|
+
.{ .draw_text = .{
|
|
1268
|
+
.id = 1,
|
|
1269
|
+
.font_id = 1,
|
|
1270
|
+
.size = 10,
|
|
1271
|
+
.origin = geometry.PointF.init(0, 10),
|
|
1272
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1273
|
+
.text = "Alpha",
|
|
1274
|
+
} },
|
|
1275
|
+
.{ .draw_text = .{
|
|
1276
|
+
.id = 2,
|
|
1277
|
+
.font_id = 1,
|
|
1278
|
+
.size = 10,
|
|
1279
|
+
.origin = geometry.PointF.init(0, 28),
|
|
1280
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1281
|
+
.text = "Beta",
|
|
1282
|
+
} },
|
|
1283
|
+
};
|
|
1284
|
+
|
|
1285
|
+
var plans: [2]TextLayoutPlan = undefined;
|
|
1286
|
+
var lines: [2]TextLine = undefined;
|
|
1287
|
+
const plan_set = try (DisplayList{ .commands = &commands }).textLayoutPlan(.{}, &plans, &lines);
|
|
1288
|
+
try std.testing.expectEqual(@as(usize, 2), plan_set.planCount());
|
|
1289
|
+
try std.testing.expectEqual(@as(usize, 2), plan_set.lineCount());
|
|
1290
|
+
try std.testing.expect(plan_set.plans[0].key.fingerprint != plan_set.plans[1].key.fingerprint);
|
|
1291
|
+
|
|
1292
|
+
var entries: [2]TextLayoutCacheEntry = undefined;
|
|
1293
|
+
var actions: [2]TextLayoutCacheAction = undefined;
|
|
1294
|
+
const first = try plan_set.cachePlan(&.{}, 1, &entries, &actions);
|
|
1295
|
+
try std.testing.expectEqual(@as(usize, 2), first.uploadCount());
|
|
1296
|
+
try std.testing.expectEqual(@as(?usize, 0), first.actions[0].layout_index);
|
|
1297
|
+
try std.testing.expectEqual(@as(?usize, 1), first.actions[1].layout_index);
|
|
1298
|
+
|
|
1299
|
+
var retained_entries: [2]TextLayoutCacheEntry = undefined;
|
|
1300
|
+
var retained_actions: [2]TextLayoutCacheAction = undefined;
|
|
1301
|
+
const retained = try plan_set.cachePlan(first.entries, 2, &retained_entries, &retained_actions);
|
|
1302
|
+
try std.testing.expectEqual(@as(usize, 2), retained.retainCount());
|
|
1303
|
+
try std.testing.expectEqual(@as(usize, 0), retained.evictCount());
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
test "text layout cache keeps recent unused layouts warm" {
|
|
1307
|
+
const commands = [_]CanvasCommand{
|
|
1308
|
+
.{ .draw_text = .{
|
|
1309
|
+
.id = 1,
|
|
1310
|
+
.font_id = 1,
|
|
1311
|
+
.size = 10,
|
|
1312
|
+
.origin = geometry.PointF.init(0, 10),
|
|
1313
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1314
|
+
.text = "Alpha",
|
|
1315
|
+
} },
|
|
1316
|
+
.{ .draw_text = .{
|
|
1317
|
+
.id = 2,
|
|
1318
|
+
.font_id = 1,
|
|
1319
|
+
.size = 10,
|
|
1320
|
+
.origin = geometry.PointF.init(0, 28),
|
|
1321
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1322
|
+
.text = "Beta",
|
|
1323
|
+
} },
|
|
1324
|
+
};
|
|
1325
|
+
|
|
1326
|
+
var plans: [2]TextLayoutPlan = undefined;
|
|
1327
|
+
var lines: [2]TextLine = undefined;
|
|
1328
|
+
const plan_set = try (DisplayList{ .commands = &commands }).textLayoutPlan(.{}, &plans, &lines);
|
|
1329
|
+
|
|
1330
|
+
var first_entries: [2]TextLayoutCacheEntry = undefined;
|
|
1331
|
+
var first_actions: [2]TextLayoutCacheAction = undefined;
|
|
1332
|
+
const first = try plan_set.cachePlanWithRetention(&.{}, 1, 2, &first_entries, &first_actions);
|
|
1333
|
+
try std.testing.expectEqual(@as(usize, 2), first.uploadCount());
|
|
1334
|
+
|
|
1335
|
+
const visible_plan_set = TextLayoutPlanSet{ .plans = plan_set.plans[0..1] };
|
|
1336
|
+
var warm_entries: [2]TextLayoutCacheEntry = undefined;
|
|
1337
|
+
var warm_actions: [2]TextLayoutCacheAction = undefined;
|
|
1338
|
+
const warm = try visible_plan_set.cachePlanWithRetention(first.entries, 2, 2, &warm_entries, &warm_actions);
|
|
1339
|
+
try std.testing.expectEqual(@as(usize, 2), warm.entryCount());
|
|
1340
|
+
try std.testing.expectEqual(@as(usize, 0), warm.uploadCount());
|
|
1341
|
+
try std.testing.expectEqual(@as(usize, 2), warm.retainCount());
|
|
1342
|
+
try std.testing.expectEqual(@as(usize, 0), warm.evictCount());
|
|
1343
|
+
try std.testing.expectEqual(@as(u64, 2), warm.entries[0].last_used_frame);
|
|
1344
|
+
try std.testing.expectEqual(@as(u64, 1), warm.entries[1].last_used_frame);
|
|
1345
|
+
try std.testing.expectEqual(@as(?usize, 0), warm.actions[0].layout_index);
|
|
1346
|
+
try std.testing.expectEqual(@as(?usize, 0), warm.actions[0].cache_index);
|
|
1347
|
+
try std.testing.expect(warm.actions[1].layout_index == null);
|
|
1348
|
+
try std.testing.expectEqual(@as(?usize, 1), warm.actions[1].cache_index);
|
|
1349
|
+
|
|
1350
|
+
var stale_entries: [2]TextLayoutCacheEntry = undefined;
|
|
1351
|
+
var stale_actions: [2]TextLayoutCacheAction = undefined;
|
|
1352
|
+
const stale = try visible_plan_set.cachePlanWithRetention(first.entries, 4, 2, &stale_entries, &stale_actions);
|
|
1353
|
+
try std.testing.expectEqual(@as(usize, 1), stale.entryCount());
|
|
1354
|
+
try std.testing.expectEqual(@as(usize, 1), stale.retainCount());
|
|
1355
|
+
try std.testing.expectEqual(@as(usize, 1), stale.evictCount());
|
|
1356
|
+
try std.testing.expectEqual(TextLayoutCacheActionKind.evict, stale.actions[1].kind);
|
|
1357
|
+
try std.testing.expect(stale.actions[1].layout_index == null);
|
|
1358
|
+
try std.testing.expectEqual(@as(?usize, 1), stale.actions[1].cache_index);
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
test "display list text layout plan honors per-run options" {
|
|
1362
|
+
const commands = [_]CanvasCommand{
|
|
1363
|
+
.{ .draw_text = .{
|
|
1364
|
+
.id = 1,
|
|
1365
|
+
.font_id = 1,
|
|
1366
|
+
.size = 10,
|
|
1367
|
+
.origin = geometry.PointF.init(2, 18),
|
|
1368
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1369
|
+
.text = "Alpha beta",
|
|
1370
|
+
.text_layout = .{ .max_width = 30, .line_height = 14, .wrap = .word, .alignment = .end },
|
|
1371
|
+
} },
|
|
1372
|
+
.{ .draw_text = .{
|
|
1373
|
+
.id = 2,
|
|
1374
|
+
.font_id = 1,
|
|
1375
|
+
.size = 10,
|
|
1376
|
+
.origin = geometry.PointF.init(2, 42),
|
|
1377
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1378
|
+
.text = "Gamma",
|
|
1379
|
+
} },
|
|
1380
|
+
};
|
|
1381
|
+
|
|
1382
|
+
var plans: [2]TextLayoutPlan = undefined;
|
|
1383
|
+
var lines: [4]TextLine = undefined;
|
|
1384
|
+
const plan_set = try (DisplayList{ .commands = &commands }).textLayoutPlan(.{ .max_width = 80, .line_height = 20, .alignment = .center }, &plans, &lines);
|
|
1385
|
+
try std.testing.expectEqual(@as(usize, 2), plan_set.planCount());
|
|
1386
|
+
try std.testing.expectEqual(@as(f32, 30), plan_set.plans[0].key.max_width);
|
|
1387
|
+
try std.testing.expectEqual(@as(f32, 14), plan_set.plans[0].key.line_height);
|
|
1388
|
+
try std.testing.expectEqual(TextAlign.end, plan_set.plans[0].key.alignment);
|
|
1389
|
+
try std.testing.expectEqual(@as(f32, 80), plan_set.plans[1].key.max_width);
|
|
1390
|
+
try std.testing.expectEqual(@as(f32, 20), plan_set.plans[1].key.line_height);
|
|
1391
|
+
try std.testing.expectEqual(TextAlign.center, plan_set.plans[1].key.alignment);
|
|
1392
|
+
try std.testing.expect(plan_set.plans[0].key.fingerprint != plan_set.plans[1].key.fingerprint);
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
test "text layout cache reports capacity overflow" {
|
|
1396
|
+
const text = DrawText{
|
|
1397
|
+
.font_id = 1,
|
|
1398
|
+
.size = 10,
|
|
1399
|
+
.origin = geometry.PointF.init(0, 10),
|
|
1400
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1401
|
+
.text = "Hello",
|
|
1402
|
+
};
|
|
1403
|
+
var lines: [1]TextLine = undefined;
|
|
1404
|
+
const plan = try layoutTextRunPlan(text, .{}, &lines);
|
|
1405
|
+
|
|
1406
|
+
var no_entries: [0]TextLayoutCacheEntry = .{};
|
|
1407
|
+
var actions: [1]TextLayoutCacheAction = undefined;
|
|
1408
|
+
try std.testing.expectError(error.TextLayoutCacheListFull, plan.cachePlan(&.{}, 1, &no_entries, &actions));
|
|
1409
|
+
|
|
1410
|
+
var entries: [1]TextLayoutCacheEntry = undefined;
|
|
1411
|
+
var no_actions: [0]TextLayoutCacheAction = .{};
|
|
1412
|
+
try std.testing.expectError(error.TextLayoutCacheListFull, plan.cachePlan(&.{}, 1, &entries, &no_actions));
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
test "text layout handles newlines and shaped glyph runs" {
|
|
1416
|
+
const text = DrawText{
|
|
1417
|
+
.font_id = 1,
|
|
1418
|
+
.size = 12,
|
|
1419
|
+
.origin = geometry.PointF.init(0, 12),
|
|
1420
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1421
|
+
.text = "One\nTwo",
|
|
1422
|
+
};
|
|
1423
|
+
var lines: [2]TextLine = undefined;
|
|
1424
|
+
const layout = try layoutTextRun(text, .{ .line_height = 16, .wrap = .none }, &lines);
|
|
1425
|
+
try std.testing.expectEqual(@as(usize, 2), layout.lineCount());
|
|
1426
|
+
try std.testing.expectEqual(@as(usize, 0), layout.lines[0].text_start);
|
|
1427
|
+
try std.testing.expectEqual(@as(usize, 3), layout.lines[0].text_len);
|
|
1428
|
+
try std.testing.expectEqual(@as(usize, 4), layout.lines[1].text_start);
|
|
1429
|
+
try std.testing.expectEqual(@as(usize, 3), layout.lines[1].text_len);
|
|
1430
|
+
try std.testing.expectEqual(@as(f32, 28), layout.lines[1].baseline);
|
|
1431
|
+
|
|
1432
|
+
const trailing = DrawText{
|
|
1433
|
+
.font_id = 1,
|
|
1434
|
+
.size = 12,
|
|
1435
|
+
.origin = geometry.PointF.init(0, 12),
|
|
1436
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1437
|
+
.text = "One\n",
|
|
1438
|
+
};
|
|
1439
|
+
var trailing_lines: [2]TextLine = undefined;
|
|
1440
|
+
const trailing_layout = try layoutTextRun(trailing, .{ .line_height = 16, .wrap = .none }, &trailing_lines);
|
|
1441
|
+
try std.testing.expectEqual(@as(usize, 2), trailing_layout.lineCount());
|
|
1442
|
+
try std.testing.expectEqual(@as(usize, 4), trailing_layout.lines[1].text_start);
|
|
1443
|
+
try std.testing.expectEqual(@as(usize, 0), trailing_layout.lines[1].text_len);
|
|
1444
|
+
try std.testing.expectEqual(@as(f32, 28), trailing_layout.lines[1].baseline);
|
|
1445
|
+
|
|
1446
|
+
const blank = DrawText{
|
|
1447
|
+
.font_id = 1,
|
|
1448
|
+
.size = 12,
|
|
1449
|
+
.origin = geometry.PointF.init(0, 12),
|
|
1450
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1451
|
+
.text = "One\n\nTwo",
|
|
1452
|
+
};
|
|
1453
|
+
var blank_lines: [3]TextLine = undefined;
|
|
1454
|
+
const blank_layout = try layoutTextRun(blank, .{ .line_height = 16, .wrap = .none }, &blank_lines);
|
|
1455
|
+
try std.testing.expectEqual(@as(usize, 3), blank_layout.lineCount());
|
|
1456
|
+
try std.testing.expectEqual(@as(usize, 4), blank_layout.lines[1].text_start);
|
|
1457
|
+
try std.testing.expectEqual(@as(usize, 0), blank_layout.lines[1].text_len);
|
|
1458
|
+
try std.testing.expectEqual(@as(usize, 5), blank_layout.lines[2].text_start);
|
|
1459
|
+
|
|
1460
|
+
const glyphs = [_]Glyph{
|
|
1461
|
+
.{ .id = 1, .x = 0, .y = 0, .advance = 9 },
|
|
1462
|
+
.{ .id = 2, .x = 9, .y = 0, .advance = 10 },
|
|
1463
|
+
};
|
|
1464
|
+
var shaped_lines: [1]TextLine = undefined;
|
|
1465
|
+
const shaped = try layoutTextRun(.{
|
|
1466
|
+
.font_id = 2,
|
|
1467
|
+
.size = 14,
|
|
1468
|
+
.origin = geometry.PointF.init(3, 18),
|
|
1469
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1470
|
+
.text = "AV",
|
|
1471
|
+
.glyphs = &glyphs,
|
|
1472
|
+
}, .{ .line_height = 20 }, &shaped_lines);
|
|
1473
|
+
try std.testing.expectEqual(@as(usize, 1), shaped.lineCount());
|
|
1474
|
+
try std.testing.expectEqual(@as(usize, 2), shaped.lines[0].glyph_len);
|
|
1475
|
+
try expectRect(geometry.RectF.init(3, 4, 19, 20), shaped.lines[0].bounds);
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
test "text layout bounds shaped glyph positions and vertical offsets" {
|
|
1479
|
+
const glyphs = [_]Glyph{
|
|
1480
|
+
.{ .id = 1, .x = 2, .y = -3, .advance = 5 },
|
|
1481
|
+
.{ .id = 2, .x = 6, .y = 4, .advance = 4 },
|
|
1482
|
+
};
|
|
1483
|
+
var lines: [1]TextLine = undefined;
|
|
1484
|
+
const layout = try layoutTextRun(.{
|
|
1485
|
+
.font_id = 2,
|
|
1486
|
+
.size = 10,
|
|
1487
|
+
.origin = geometry.PointF.init(10, 20),
|
|
1488
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1489
|
+
.text = "AV",
|
|
1490
|
+
.glyphs = &glyphs,
|
|
1491
|
+
}, .{ .line_height = 12 }, &lines);
|
|
1492
|
+
|
|
1493
|
+
try std.testing.expectEqual(@as(usize, 1), layout.lineCount());
|
|
1494
|
+
try expectRect(geometry.RectF.init(10, 7, 8, 19.5), layout.lines[0].bounds);
|
|
1495
|
+
try expectRect(geometry.RectF.init(10, 7, 8, 19.5), layout.bounds);
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
test "text layout wraps shaped glyph runs by glyph advances" {
|
|
1499
|
+
const glyphs = [_]Glyph{
|
|
1500
|
+
.{ .id = 1, .x = 0, .y = 0, .advance = 8 },
|
|
1501
|
+
.{ .id = 2, .x = 8, .y = 0, .advance = 7 },
|
|
1502
|
+
.{ .id = 3, .x = 15, .y = 0, .advance = 6 },
|
|
1503
|
+
.{ .id = 4, .x = 21, .y = 0, .advance = 9 },
|
|
1504
|
+
.{ .id = 5, .x = 30, .y = 0, .advance = 5 },
|
|
1505
|
+
};
|
|
1506
|
+
var lines: [3]TextLine = undefined;
|
|
1507
|
+
const layout = try layoutTextRun(.{
|
|
1508
|
+
.font_id = 2,
|
|
1509
|
+
.size = 12,
|
|
1510
|
+
.origin = geometry.PointF.init(4, 20),
|
|
1511
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1512
|
+
.text = "abcde",
|
|
1513
|
+
.glyphs = &glyphs,
|
|
1514
|
+
}, .{ .max_width = 16, .line_height = 18, .wrap = .character }, &lines);
|
|
1515
|
+
|
|
1516
|
+
try std.testing.expectEqual(@as(usize, 3), layout.lineCount());
|
|
1517
|
+
try std.testing.expectEqual(@as(usize, 0), layout.lines[0].glyph_start);
|
|
1518
|
+
try std.testing.expectEqual(@as(usize, 2), layout.lines[0].glyph_len);
|
|
1519
|
+
try std.testing.expectEqual(@as(usize, 0), layout.lines[0].text_start);
|
|
1520
|
+
try std.testing.expectEqual(@as(usize, 2), layout.lines[0].text_len);
|
|
1521
|
+
try expectRect(geometry.RectF.init(4, 8, 15, 18), layout.lines[0].bounds);
|
|
1522
|
+
try std.testing.expectEqual(@as(usize, 2), layout.lines[1].glyph_start);
|
|
1523
|
+
try std.testing.expectEqual(@as(usize, 2), layout.lines[1].glyph_len);
|
|
1524
|
+
try std.testing.expectEqual(@as(usize, 2), layout.lines[1].text_start);
|
|
1525
|
+
try std.testing.expectEqual(@as(usize, 2), layout.lines[1].text_len);
|
|
1526
|
+
try std.testing.expectEqual(@as(f32, 38), layout.lines[1].baseline);
|
|
1527
|
+
try std.testing.expectEqual(@as(usize, 4), layout.lines[2].glyph_start);
|
|
1528
|
+
try std.testing.expectEqual(@as(usize, 1), layout.lines[2].glyph_len);
|
|
1529
|
+
try std.testing.expectEqual(@as(usize, 4), layout.lines[2].text_start);
|
|
1530
|
+
try std.testing.expectEqual(@as(usize, 1), layout.lines[2].text_len);
|
|
1531
|
+
try expectRect(geometry.RectF.init(4, 8, 15, 54), layout.bounds);
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
test "text layout word-wraps shaped glyph runs at mapped spaces" {
|
|
1535
|
+
const glyphs = [_]Glyph{
|
|
1536
|
+
.{ .id = 1, .x = 0, .y = 0, .advance = 5 },
|
|
1537
|
+
.{ .id = 2, .x = 5, .y = 0, .advance = 5 },
|
|
1538
|
+
.{ .id = 3, .x = 10, .y = 0, .advance = 5 },
|
|
1539
|
+
.{ .id = 4, .x = 15, .y = 0, .advance = 5 },
|
|
1540
|
+
.{ .id = 5, .x = 20, .y = 0, .advance = 5 },
|
|
1541
|
+
.{ .id = 6, .x = 25, .y = 0, .advance = 5 },
|
|
1542
|
+
};
|
|
1543
|
+
var lines: [2]TextLine = undefined;
|
|
1544
|
+
const layout = try layoutTextRun(.{
|
|
1545
|
+
.font_id = 2,
|
|
1546
|
+
.size = 10,
|
|
1547
|
+
.origin = geometry.PointF.init(0, 10),
|
|
1548
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1549
|
+
.text = "Hi all",
|
|
1550
|
+
.glyphs = &glyphs,
|
|
1551
|
+
}, .{ .max_width = 16, .line_height = 14, .wrap = .word }, &lines);
|
|
1552
|
+
|
|
1553
|
+
try std.testing.expectEqual(@as(usize, 2), layout.lineCount());
|
|
1554
|
+
try std.testing.expectEqual(@as(usize, 0), layout.lines[0].glyph_start);
|
|
1555
|
+
try std.testing.expectEqual(@as(usize, 2), layout.lines[0].glyph_len);
|
|
1556
|
+
try std.testing.expectEqual(@as(usize, 0), layout.lines[0].text_start);
|
|
1557
|
+
try std.testing.expectEqual(@as(usize, 2), layout.lines[0].text_len);
|
|
1558
|
+
try expectRect(geometry.RectF.init(0, 0, 10, 14), layout.lines[0].bounds);
|
|
1559
|
+
try std.testing.expectEqual(@as(usize, 3), layout.lines[1].glyph_start);
|
|
1560
|
+
try std.testing.expectEqual(@as(usize, 3), layout.lines[1].glyph_len);
|
|
1561
|
+
try std.testing.expectEqual(@as(usize, 3), layout.lines[1].text_start);
|
|
1562
|
+
try std.testing.expectEqual(@as(usize, 3), layout.lines[1].text_len);
|
|
1563
|
+
try expectRect(geometry.RectF.init(0, 14, 15, 14), layout.lines[1].bounds);
|
|
1564
|
+
try expectRect(geometry.RectF.init(0, 0, 15, 28), layout.bounds);
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
test "text layout keeps an empty line for shaped whitespace runs" {
|
|
1568
|
+
const glyphs = [_]Glyph{
|
|
1569
|
+
.{ .id = 1, .x = 0, .y = 0, .advance = 5 },
|
|
1570
|
+
.{ .id = 2, .x = 5, .y = 0, .advance = 5 },
|
|
1571
|
+
};
|
|
1572
|
+
var lines: [1]TextLine = undefined;
|
|
1573
|
+
const layout = try layoutTextRun(.{
|
|
1574
|
+
.font_id = 2,
|
|
1575
|
+
.size = 10,
|
|
1576
|
+
.origin = geometry.PointF.init(0, 10),
|
|
1577
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1578
|
+
.text = " ",
|
|
1579
|
+
.glyphs = &glyphs,
|
|
1580
|
+
}, .{ .max_width = 16, .line_height = 14, .wrap = .word }, &lines);
|
|
1581
|
+
|
|
1582
|
+
try std.testing.expectEqual(@as(usize, 1), layout.lineCount());
|
|
1583
|
+
try std.testing.expectEqual(@as(usize, 0), layout.lines[0].glyph_len);
|
|
1584
|
+
try std.testing.expectEqual(@as(usize, 0), layout.lines[0].text_len);
|
|
1585
|
+
try expectRect(geometry.RectF.init(0, 0, 0, 14), layout.bounds);
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
test "text layout reports output overflow" {
|
|
1589
|
+
var lines: [0]TextLine = .{};
|
|
1590
|
+
try std.testing.expectError(error.TextLayoutLineListFull, layoutTextRun(.{
|
|
1591
|
+
.size = 10,
|
|
1592
|
+
.origin = geometry.PointF.init(0, 10),
|
|
1593
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1594
|
+
.text = "Hello",
|
|
1595
|
+
}, .{}, &lines));
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
test "display list serializes deterministic Phase 2 primitives" {
|
|
1599
|
+
const stops = [_]GradientStop{
|
|
1600
|
+
.{ .offset = 0, .color = Color.rgb8(255, 255, 255) },
|
|
1601
|
+
.{ .offset = 1, .color = Color.rgb8(0, 0, 0) },
|
|
1602
|
+
};
|
|
1603
|
+
const glyphs = [_]Glyph{
|
|
1604
|
+
.{ .id = 42, .x = 12, .y = 28, .advance = 9 },
|
|
1605
|
+
.{ .id = 43, .x = 21, .y = 28, .advance = 8 },
|
|
1606
|
+
};
|
|
1607
|
+
const path = [_]PathElement{
|
|
1608
|
+
.{ .verb = .move_to, .points = .{ geometry.PointF.init(180, 120), geometry.PointF.zero(), geometry.PointF.zero() } },
|
|
1609
|
+
.{ .verb = .line_to, .points = .{ geometry.PointF.init(212, 104), geometry.PointF.zero(), geometry.PointF.zero() } },
|
|
1610
|
+
.{ .verb = .quad_to, .points = .{ geometry.PointF.init(228, 116), geometry.PointF.init(220, 136), geometry.PointF.zero() } },
|
|
1611
|
+
.{ .verb = .cubic_to, .points = .{ geometry.PointF.init(208, 148), geometry.PointF.init(188, 148), geometry.PointF.init(180, 120) } },
|
|
1612
|
+
.{ .verb = .close },
|
|
1613
|
+
};
|
|
1614
|
+
|
|
1615
|
+
var commands: [15]CanvasCommand = undefined;
|
|
1616
|
+
var builder = Builder.init(&commands);
|
|
1617
|
+
try builder.pushClip(.{
|
|
1618
|
+
.id = 9,
|
|
1619
|
+
.rect = geometry.RectF.init(4, 5, 320, 160),
|
|
1620
|
+
.radius = Radius.all(12),
|
|
1621
|
+
});
|
|
1622
|
+
try builder.pushOpacity(0.75);
|
|
1623
|
+
try builder.transform(Affine.translate(8, 6));
|
|
1624
|
+
try builder.fillRect(.{
|
|
1625
|
+
.id = 10,
|
|
1626
|
+
.rect = geometry.RectF.init(0, 0, 360, 180),
|
|
1627
|
+
.fill = .{ .linear_gradient = .{
|
|
1628
|
+
.start = geometry.PointF.init(0, 0),
|
|
1629
|
+
.end = geometry.PointF.init(360, 180),
|
|
1630
|
+
.stops = &stops,
|
|
1631
|
+
} },
|
|
1632
|
+
});
|
|
1633
|
+
try builder.shadow(.{
|
|
1634
|
+
.id = 11,
|
|
1635
|
+
.rect = geometry.RectF.init(24, 24, 220, 96),
|
|
1636
|
+
.radius = Radius.all(16),
|
|
1637
|
+
.offset = .{ .dx = 0, .dy = 18 },
|
|
1638
|
+
.blur = 42,
|
|
1639
|
+
.spread = -8,
|
|
1640
|
+
.color = Color.rgba(0, 0, 0, 0.25),
|
|
1641
|
+
});
|
|
1642
|
+
try builder.fillRoundedRect(.{
|
|
1643
|
+
.id = 13,
|
|
1644
|
+
.rect = geometry.RectF.init(24, 80, 128, 48),
|
|
1645
|
+
.radius = .{ .top_left = 8, .top_right = 10, .bottom_right = 12, .bottom_left = 6 },
|
|
1646
|
+
.fill = .{ .color = Color.rgb8(255, 255, 255) },
|
|
1647
|
+
});
|
|
1648
|
+
try builder.strokeRect(.{
|
|
1649
|
+
.id = 14,
|
|
1650
|
+
.rect = geometry.RectF.init(24, 80, 128, 48),
|
|
1651
|
+
.radius = Radius.all(8),
|
|
1652
|
+
.stroke = .{ .fill = .{ .color = Color.rgb8(0, 0, 0) }, .width = 1.5 },
|
|
1653
|
+
});
|
|
1654
|
+
try builder.drawLine(.{
|
|
1655
|
+
.id = 17,
|
|
1656
|
+
.from = geometry.PointF.init(24, 140),
|
|
1657
|
+
.to = geometry.PointF.init(152, 140),
|
|
1658
|
+
.stroke = .{ .fill = .{ .linear_gradient = .{
|
|
1659
|
+
.start = geometry.PointF.init(0, 0),
|
|
1660
|
+
.end = geometry.PointF.init(360, 180),
|
|
1661
|
+
.stops = &stops,
|
|
1662
|
+
} }, .width = 2 },
|
|
1663
|
+
});
|
|
1664
|
+
try builder.fillPath(.{
|
|
1665
|
+
.id = 18,
|
|
1666
|
+
.elements = &path,
|
|
1667
|
+
.fill = .{ .color = Color.rgb8(15, 23, 42) },
|
|
1668
|
+
});
|
|
1669
|
+
try builder.strokePath(.{
|
|
1670
|
+
.id = 19,
|
|
1671
|
+
.elements = &path,
|
|
1672
|
+
.stroke = .{ .fill = .{ .color = Color.rgb8(0, 0, 0) }, .width = 2 },
|
|
1673
|
+
});
|
|
1674
|
+
try builder.drawImage(.{
|
|
1675
|
+
.id = 15,
|
|
1676
|
+
.image_id = 3,
|
|
1677
|
+
.src = geometry.RectF.init(0, 0, 48, 32),
|
|
1678
|
+
.dst = geometry.RectF.init(180, 40, 96, 64),
|
|
1679
|
+
.opacity = 0.6,
|
|
1680
|
+
.fit = .cover,
|
|
1681
|
+
.sampling = .nearest,
|
|
1682
|
+
});
|
|
1683
|
+
try builder.drawText(.{
|
|
1684
|
+
.id = 12,
|
|
1685
|
+
.font_id = 7,
|
|
1686
|
+
.size = 17,
|
|
1687
|
+
.origin = geometry.PointF.init(32, 52),
|
|
1688
|
+
.color = Color.rgb8(15, 23, 42),
|
|
1689
|
+
.text = "Hi",
|
|
1690
|
+
.glyphs = &glyphs,
|
|
1691
|
+
});
|
|
1692
|
+
try builder.blur(.{
|
|
1693
|
+
.id = 16,
|
|
1694
|
+
.rect = geometry.RectF.init(24, 24, 220, 96),
|
|
1695
|
+
.radius = 18,
|
|
1696
|
+
});
|
|
1697
|
+
try builder.popOpacity();
|
|
1698
|
+
try builder.popClip();
|
|
1699
|
+
|
|
1700
|
+
var buffer: [4096]u8 = undefined;
|
|
1701
|
+
var writer = std.Io.Writer.fixed(&buffer);
|
|
1702
|
+
try builder.displayList().writeJson(&writer);
|
|
1703
|
+
|
|
1704
|
+
const expected =
|
|
1705
|
+
"{\"commands\":[{\"op\":\"push_clip\",\"id\":9,\"rect\":[4,5,320,160],\"radius\":[12,12,12,12]},{\"op\":\"push_opacity\",\"opacity\":0.75},{\"op\":\"transform\",\"matrix\":[1,0,0,1,8,6]},{\"op\":\"fill_rect\",\"id\":10,\"rect\":[0,0,360,180],\"fill\":{\"kind\":\"linear_gradient\",\"start\":[0,0],\"end\":[360,180],\"stops\":[{\"offset\":0,\"color\":[1,1,1,1]},{\"offset\":1,\"color\":[0,0,0,1]}]}},{\"op\":\"shadow\",\"id\":11,\"rect\":[24,24,220,96],\"radius\":[16,16,16,16],\"offset\":[0,18],\"blur\":42,\"spread\":-8,\"color\":[0,0,0,0.25]},{\"op\":\"fill_rounded_rect\",\"id\":13,\"rect\":[24,80,128,48],\"radius\":[8,10,12,6],\"fill\":{\"kind\":\"color\",\"color\":[1,1,1,1]}},{\"op\":\"stroke_rect\",\"id\":14,\"rect\":[24,80,128,48],\"radius\":[8,8,8,8],\"stroke\":{\"width\":1.5,\"fill\":{\"kind\":\"color\",\"color\":[0,0,0,1]}}},{\"op\":\"draw_line\",\"id\":17,\"from\":[24,140],\"to\":[152,140],\"stroke\":{\"width\":2,\"fill\":{\"kind\":\"linear_gradient\",\"start\":[0,0],\"end\":[360,180],\"stops\":[{\"offset\":0,\"color\":[1,1,1,1]},{\"offset\":1,\"color\":[0,0,0,1]}]}}},{\"op\":\"fill_path\",\"id\":18,\"path\":[{\"verb\":\"move_to\",\"points\":[[180,120]]},{\"verb\":\"line_to\",\"points\":[[212,104]]},{\"verb\":\"quad_to\",\"points\":[[228,116],[220,136]]},{\"verb\":\"cubic_to\",\"points\":[[208,148],[188,148],[180,120]]},{\"verb\":\"close\",\"points\":[]}],\"fill\":{\"kind\":\"color\",\"color\":[0.05882353,0.09019608,0.16470589,1]}},{\"op\":\"stroke_path\",\"id\":19,\"path\":[{\"verb\":\"move_to\",\"points\":[[180,120]]},{\"verb\":\"line_to\",\"points\":[[212,104]]},{\"verb\":\"quad_to\",\"points\":[[228,116],[220,136]]},{\"verb\":\"cubic_to\",\"points\":[[208,148],[188,148],[180,120]]},{\"verb\":\"close\",\"points\":[]}],\"stroke\":{\"width\":2,\"fill\":{\"kind\":\"color\",\"color\":[0,0,0,1]}}},{\"op\":\"draw_image\",\"id\":15,\"image\":3,\"dst\":[180,40,96,64],\"src\":[0,0,48,32],\"opacity\":0.6,\"fit\":\"cover\",\"sampling\":\"nearest\"},{\"op\":\"draw_text\",\"id\":12,\"font\":7,\"size\":17,\"origin\":[32,52],\"color\":[0.05882353,0.09019608,0.16470589,1],\"text\":\"Hi\",\"glyphs\":[{\"id\":42,\"x\":12,\"y\":28,\"advance\":9},{\"id\":43,\"x\":21,\"y\":28,\"advance\":8}]},{\"op\":\"blur\",\"id\":16,\"rect\":[24,24,220,96],\"radius\":18},{\"op\":\"pop_opacity\"},{\"op\":\"pop_clip\"}]}";
|
|
1706
|
+
try std.testing.expectEqualStrings(expected, writer.buffered());
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
test "display list serializes per-run text layout options" {
|
|
1710
|
+
const commands = [_]CanvasCommand{.{ .draw_text = .{
|
|
1711
|
+
.id = 3,
|
|
1712
|
+
.font_id = 1,
|
|
1713
|
+
.size = 10,
|
|
1714
|
+
.origin = geometry.PointF.init(4, 20),
|
|
1715
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1716
|
+
.text = "Wrapped",
|
|
1717
|
+
.text_layout = .{ .max_width = 42, .line_height = 14, .wrap = .character, .alignment = .center },
|
|
1718
|
+
} }};
|
|
1719
|
+
|
|
1720
|
+
var buffer: [512]u8 = undefined;
|
|
1721
|
+
var writer = std.Io.Writer.fixed(&buffer);
|
|
1722
|
+
try (DisplayList{ .commands = &commands }).writeJson(&writer);
|
|
1723
|
+
try std.testing.expectEqualStrings(
|
|
1724
|
+
"{\"commands\":[{\"op\":\"draw_text\",\"id\":3,\"font\":1,\"size\":10,\"origin\":[4,20],\"color\":[0,0,0,1],\"text\":\"Wrapped\",\"glyphs\":[],\"layout\":{\"maxWidth\":42,\"lineHeight\":14,\"wrap\":\"character\",\"align\":\"center\",\"overflow\":\"ellipsis\"}}]}",
|
|
1725
|
+
writer.buffered(),
|
|
1726
|
+
);
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
test "display list serializes glyph text clusters" {
|
|
1730
|
+
const glyphs = [_]Glyph{
|
|
1731
|
+
.{ .id = 42, .x = 12, .y = 28, .advance = 9, .text_start = 0, .text_len = 1 },
|
|
1732
|
+
.{ .id = 1001, .x = 21, .y = 28, .advance = 12, .text_start = 1, .text_len = 2 },
|
|
1733
|
+
};
|
|
1734
|
+
const commands = [_]CanvasCommand{.{ .draw_text = .{
|
|
1735
|
+
.id = 3,
|
|
1736
|
+
.font_id = 1,
|
|
1737
|
+
.size = 10,
|
|
1738
|
+
.origin = geometry.PointF.init(4, 20),
|
|
1739
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1740
|
+
.text = "ffi",
|
|
1741
|
+
.glyphs = &glyphs,
|
|
1742
|
+
} }};
|
|
1743
|
+
|
|
1744
|
+
var buffer: [512]u8 = undefined;
|
|
1745
|
+
var writer = std.Io.Writer.fixed(&buffer);
|
|
1746
|
+
try (DisplayList{ .commands = &commands }).writeJson(&writer);
|
|
1747
|
+
try std.testing.expectEqualStrings(
|
|
1748
|
+
"{\"commands\":[{\"op\":\"draw_text\",\"id\":3,\"font\":1,\"size\":10,\"origin\":[4,20],\"color\":[0,0,0,1],\"text\":\"ffi\",\"glyphs\":[{\"id\":42,\"x\":12,\"y\":28,\"advance\":9,\"textStart\":0,\"textLen\":1},{\"id\":1001,\"x\":21,\"y\":28,\"advance\":12,\"textStart\":1,\"textLen\":2}]}]}",
|
|
1749
|
+
writer.buffered(),
|
|
1750
|
+
);
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
fn wideTextMeasureForTests(context: ?*anyopaque, font_id: FontId, size: f32, text: []const u8) f32 {
|
|
1754
|
+
_ = context;
|
|
1755
|
+
_ = font_id;
|
|
1756
|
+
var scalars: f32 = 0;
|
|
1757
|
+
var index: usize = 0;
|
|
1758
|
+
while (index < text.len) : (index += 1) {
|
|
1759
|
+
if (!text_model.isUtf8ContinuationByte(text[index])) scalars += 1;
|
|
1760
|
+
}
|
|
1761
|
+
return size * 2 * scalars;
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
const wide_text_measure = support.TextMeasureProvider{ .measure_fn = wideTextMeasureForTests };
|
|
1765
|
+
|
|
1766
|
+
test "injected measure provider drives line breaking and caret geometry" {
|
|
1767
|
+
const estimator_text = DrawText{
|
|
1768
|
+
.font_id = 1,
|
|
1769
|
+
.size = 10,
|
|
1770
|
+
.origin = geometry.PointF.init(0, 10),
|
|
1771
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1772
|
+
.text = "ab cd",
|
|
1773
|
+
.text_layout = .{ .max_width = 50, .line_height = 12, .wrap = .word },
|
|
1774
|
+
};
|
|
1775
|
+
var estimator_lines: [4]TextLine = undefined;
|
|
1776
|
+
const estimator_layout = try layoutTextRun(estimator_text, estimator_text.text_layout.?, &estimator_lines);
|
|
1777
|
+
try std.testing.expectEqual(@as(usize, 1), estimator_layout.lineCount());
|
|
1778
|
+
|
|
1779
|
+
var measured_text = estimator_text;
|
|
1780
|
+
measured_text.text_layout = .{
|
|
1781
|
+
.max_width = 50,
|
|
1782
|
+
.line_height = 12,
|
|
1783
|
+
.wrap = .word,
|
|
1784
|
+
.measure = &wide_text_measure,
|
|
1785
|
+
};
|
|
1786
|
+
var measured_lines: [4]TextLine = undefined;
|
|
1787
|
+
const measured_layout = try layoutTextRun(measured_text, measured_text.text_layout.?, &measured_lines);
|
|
1788
|
+
try std.testing.expectEqual(@as(usize, 2), measured_layout.lineCount());
|
|
1789
|
+
|
|
1790
|
+
// Caret after "ab" on the first line: 2 scalars x (2 x size) wide.
|
|
1791
|
+
const measured_caret = textLineCaretX(measured_text, measured_layout.lines[0], 2);
|
|
1792
|
+
try std.testing.expectEqual(@as(f32, 40), measured_caret);
|
|
1793
|
+
const estimator_caret = textLineCaretX(estimator_text, estimator_layout.lines[0], 2);
|
|
1794
|
+
try std.testing.expect(estimator_caret != measured_caret);
|
|
1795
|
+
|
|
1796
|
+
// Hit testing agrees with the provider-measured advances.
|
|
1797
|
+
const hit = textOffsetForLayoutPoint(measured_text, measured_layout, geometry.PointF.init(39, 5)).?;
|
|
1798
|
+
try std.testing.expectEqual(@as(usize, 2), hit);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
// ------------------------------------------------------------------
|
|
1802
|
+
// Regression: the reference pen must walk the same measurement seam
|
|
1803
|
+
// layout used. A CoreText-like provider measures multibyte codepoints
|
|
1804
|
+
// narrower than the estimator's flat 0.65em multibyte advance; walking
|
|
1805
|
+
// the raw estimator while the provider measured the line's bounds and
|
|
1806
|
+
// clip dropped one tail glyph per multibyte codepoint — the shape a
|
|
1807
|
+
// live macOS app's automation screenshots exposed.
|
|
1808
|
+
fn coretextLikeMeasureForTests(context: ?*anyopaque, font_id: FontId, size: f32, text: []const u8) f32 {
|
|
1809
|
+
_ = context;
|
|
1810
|
+
var width: f32 = 0;
|
|
1811
|
+
var index: usize = 0;
|
|
1812
|
+
while (index < text.len) {
|
|
1813
|
+
const next = @min(text.len, index + text_model.utf8SequenceLength(text[index]));
|
|
1814
|
+
const cluster = text[index..next];
|
|
1815
|
+
width += if (cluster.len > 1) size * 0.3 else estimateTextAdvanceForBytes(font_id, cluster, size);
|
|
1816
|
+
index = next;
|
|
1817
|
+
}
|
|
1818
|
+
return width;
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
const coretext_like_measure = support.TextMeasureProvider{ .measure_fn = coretextLikeMeasureForTests };
|
|
1822
|
+
|
|
1823
|
+
fn tailInkDroppedByBoundsClip(comptime body: []const u8, text_layout: ?TextLayoutOptions) !usize {
|
|
1824
|
+
const size: f32 = 16;
|
|
1825
|
+
const text = DrawText{
|
|
1826
|
+
.font_id = 1,
|
|
1827
|
+
.size = size,
|
|
1828
|
+
.origin = geometry.PointF.init(4, 20),
|
|
1829
|
+
.color = Color.rgb8(255, 255, 255),
|
|
1830
|
+
.text = body,
|
|
1831
|
+
.text_layout = text_layout,
|
|
1832
|
+
};
|
|
1833
|
+
const commands = [_]CanvasCommand{.{ .draw_text = text }};
|
|
1834
|
+
var render_commands: [1]RenderCommand = undefined;
|
|
1835
|
+
const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
|
|
1836
|
+
|
|
1837
|
+
const width = 360;
|
|
1838
|
+
const height = 40;
|
|
1839
|
+
var clipped_pixels: [width * height * 4]u8 = [_]u8{0} ** (width * height * 4);
|
|
1840
|
+
var unclipped_pixels: [width * height * 4]u8 = [_]u8{0} ** (width * height * 4);
|
|
1841
|
+
|
|
1842
|
+
const clipped = try ReferenceRenderSurface.init(width, height, &clipped_pixels);
|
|
1843
|
+
try clipped.renderPass(.{
|
|
1844
|
+
.commands = render_plan.commands,
|
|
1845
|
+
.surface_size = geometry.SizeF.init(width, height),
|
|
1846
|
+
.full_repaint = true,
|
|
1847
|
+
}, Color.rgb8(0, 0, 0));
|
|
1848
|
+
|
|
1849
|
+
// The same command with surface-wide bounds: every pixel the glyph
|
|
1850
|
+
// outlines would ink with no bounds clip at all.
|
|
1851
|
+
var widened = render_plan.commands[0];
|
|
1852
|
+
widened.bounds = geometry.RectF.init(0, 0, width, height);
|
|
1853
|
+
widened.local_bounds = widened.bounds;
|
|
1854
|
+
const widened_commands = [_]RenderCommand{widened};
|
|
1855
|
+
const unclipped = try ReferenceRenderSurface.init(width, height, &unclipped_pixels);
|
|
1856
|
+
try unclipped.renderPass(.{
|
|
1857
|
+
.commands = &widened_commands,
|
|
1858
|
+
.surface_size = geometry.SizeF.init(width, height),
|
|
1859
|
+
.full_repaint = true,
|
|
1860
|
+
}, Color.rgb8(0, 0, 0));
|
|
1861
|
+
|
|
1862
|
+
var dropped: usize = 0;
|
|
1863
|
+
for (0..height) |y| for (0..width) |x| {
|
|
1864
|
+
const index = (y * width + x) * 4;
|
|
1865
|
+
if (clipped_pixels[index] != unclipped_pixels[index]) dropped += 1;
|
|
1866
|
+
};
|
|
1867
|
+
return dropped;
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
test "provider-measured runs keep their multibyte tails inside command bounds" {
|
|
1871
|
+
const size: f32 = 16;
|
|
1872
|
+
// One exact-fit line per string, measured by the provider — the shape
|
|
1873
|
+
// every tight intrinsic text box produces on a live macOS app.
|
|
1874
|
+
inline for ([_][]const u8{
|
|
1875
|
+
"Live \xc2\xb7 every 2 s",
|
|
1876
|
+
"12 kept \xc2\xb7 2 s \xc2\xb7 ok",
|
|
1877
|
+
"caf\xc3\xa9 r\xc3\xa9sum\xc3\xa9",
|
|
1878
|
+
"go \xe2\x86\x92 done \xe2\x86\x92 end",
|
|
1879
|
+
"\xe4\xb8\xad\xe6\x96\x87 label",
|
|
1880
|
+
}) |body| {
|
|
1881
|
+
const provider_width = coretextLikeMeasureForTests(null, 1, size, body);
|
|
1882
|
+
const options = TextLayoutOptions{
|
|
1883
|
+
.max_width = provider_width,
|
|
1884
|
+
.line_height = size * 1.25,
|
|
1885
|
+
.wrap = .word,
|
|
1886
|
+
.measure = &coretext_like_measure,
|
|
1887
|
+
};
|
|
1888
|
+
// Exact fit stays one line under the provider's own widths.
|
|
1889
|
+
const text = DrawText{
|
|
1890
|
+
.font_id = 1,
|
|
1891
|
+
.size = size,
|
|
1892
|
+
.origin = geometry.PointF.init(4, 20),
|
|
1893
|
+
.color = Color.rgb8(255, 255, 255),
|
|
1894
|
+
.text = body,
|
|
1895
|
+
.text_layout = options,
|
|
1896
|
+
};
|
|
1897
|
+
var lines: [4]TextLine = undefined;
|
|
1898
|
+
const layout = try layoutTextRun(text, options, &lines);
|
|
1899
|
+
try std.testing.expectEqual(@as(usize, 1), layout.lineCount());
|
|
1900
|
+
try std.testing.expectEqual(body.len, layout.lines[0].text_len);
|
|
1901
|
+
|
|
1902
|
+
// And every inked pixel stays inside the command bounds: nothing
|
|
1903
|
+
// the renderer would draw unbounded is lost to the bounds clip.
|
|
1904
|
+
try std.testing.expectEqual(@as(usize, 0), try tailInkDroppedByBoundsClip(body, options));
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1908
|
+
test "estimator-measured exact-fit multibyte strings keep every byte on one line" {
|
|
1909
|
+
const size: f32 = 13;
|
|
1910
|
+
inline for ([_][]const u8{
|
|
1911
|
+
"Live \xc2\xb7 every 2 s",
|
|
1912
|
+
"of 32.0 GB \xc2\xb7 47%",
|
|
1913
|
+
"caf\xc3\xa9 \xc2\xb7 r\xc3\xa9sum\xc3\xa9 \xc2\xb7 na\xc3\xafve",
|
|
1914
|
+
"next \xe2\x86\x92 prev",
|
|
1915
|
+
"\xe4\xb8\xad\xe6\x96\x87\xe6\xb8\xac\xe8\xa9\xa6 row",
|
|
1916
|
+
}) |body| {
|
|
1917
|
+
const options = TextLayoutOptions{
|
|
1918
|
+
.max_width = estimateTextWidth(body, size),
|
|
1919
|
+
.line_height = size * 1.25,
|
|
1920
|
+
.wrap = .word,
|
|
1921
|
+
};
|
|
1922
|
+
const text = DrawText{
|
|
1923
|
+
.font_id = 1,
|
|
1924
|
+
.size = size,
|
|
1925
|
+
.origin = geometry.PointF.init(0, 16),
|
|
1926
|
+
.color = Color.rgb8(0, 0, 0),
|
|
1927
|
+
.text = body,
|
|
1928
|
+
.text_layout = options,
|
|
1929
|
+
};
|
|
1930
|
+
var lines: [4]TextLine = undefined;
|
|
1931
|
+
const layout = try layoutTextRun(text, options, &lines);
|
|
1932
|
+
try std.testing.expectEqual(@as(usize, 1), layout.lineCount());
|
|
1933
|
+
try std.testing.expectEqual(@as(usize, 0), layout.lines[0].text_start);
|
|
1934
|
+
try std.testing.expectEqual(body.len, layout.lines[0].text_len);
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
test "text command bounds cover glyph ink overhang past metric advances" {
|
|
1939
|
+
// Wide real outlines behind narrow metric advances historically
|
|
1940
|
+
// clipped at the bounds edge: the flat 0.65em multibyte estimate
|
|
1941
|
+
// under an \u{2192} arrow, and mono glyphs inking wider than the flat
|
|
1942
|
+
// 0.6em mono advance (the notes-build "tail clip" screenshot
|
|
1943
|
+
// artifact). With the ink allowance on textBounds nothing inks
|
|
1944
|
+
// outside the command bounds.
|
|
1945
|
+
try std.testing.expectEqual(@as(usize, 0), try tailInkDroppedByBoundsClip("go \xe2\x86\x92", null));
|
|
1946
|
+
try std.testing.expectEqual(@as(usize, 0), try tailInkDroppedByBoundsClip("mono tail mm", null));
|
|
1947
|
+
try std.testing.expectEqual(@as(usize, 0), try tailInkDroppedByBoundsClip("gravity plummets", null));
|
|
1948
|
+
try std.testing.expectEqual(@as(usize, 0), try tailInkDroppedByBoundsClip("Grocery run notes\xe2\x80\xa6", null));
|
|
1949
|
+
}
|