@native-sdk/cli 0.10.0 → 0.11.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/README.md +8 -6
- package/bin/native.js +2 -1
- package/build/app.zig +320 -60
- package/build/corewire.zig +53 -0
- package/build/test_shards.zig +49 -0
- package/build/ts_run.mjs +3 -3
- package/build.zig +1818 -87
- package/package.json +19 -14
- package/packages/core/compile-surface/core.ts +134 -72
- package/packages/core/package-lock.json +75 -357
- package/packages/core/package.json +25 -4
- package/packages/core/scripts/compiler_command.mjs +17 -12
- package/packages/core/scripts/compiler_typecheck.mjs +1 -0
- package/packages/core/scripts/gen_declarations.mjs +3 -2
- package/packages/core/scripts/gen_service_surface.mjs +22 -10
- package/packages/core/scripts/install_scriptc.mjs +182 -0
- package/packages/core/scripts/invoke_scriptc.mjs +18 -0
- package/packages/core/scripts/merge_static_archives.mjs +6 -1
- package/packages/core/scripts/npm_static_spike.mjs +2 -2
- package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
- package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
- package/packages/core/scripts/run_library_compiler.mjs +51 -0
- package/packages/core/scripts/run_native_tests.mjs +22 -0
- package/packages/core/scripts/scriptc-toolchain.json +101 -0
- package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
- package/packages/core/scripts/stage_external_core.mjs +57 -1
- package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
- package/packages/core/sdk/bytes.d.ts +2 -0
- package/packages/core/sdk/bytes.ts +86 -0
- package/packages/core/sdk/core.d.ts +308 -4
- package/packages/core/sdk/core.ts +320 -84
- package/packages/core/sdk/events.d.ts +247 -0
- package/packages/core/sdk/events.ts +230 -2
- package/packages/core/sdk/internal/image_identity.d.ts +7 -0
- package/packages/core/sdk/internal/image_identity.ts +71 -0
- package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
- package/packages/core/sdk/internal/markdown_policy.ts +878 -0
- package/packages/core/sdk/text.d.ts +27 -0
- package/packages/core/sdk/text.ts +206 -15
- package/packages/core/sdk/theme.d.ts +251 -0
- package/packages/core/sdk/theme.ts +267 -0
- package/packages/core/src/authorization.ts +137 -0
- package/packages/core/src/automation_commands.ts +201 -0
- package/packages/core/src/automation_interactions.ts +92 -0
- package/packages/core/src/bridge_descriptors.ts +104 -0
- package/packages/core/src/builtin_coordination.ts +172 -0
- package/packages/core/src/canvas_frame_coordination.ts +81 -0
- package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
- package/packages/core/src/canvas_scene_observation.ts +145 -0
- package/packages/core/src/chart_content.ts +161 -0
- package/packages/core/src/chart_plans.ts +432 -0
- package/packages/core/src/checker.ts +166 -19
- package/packages/core/src/code_content.ts +580 -0
- package/packages/core/src/command_coordination.ts +140 -0
- package/packages/core/src/component_composition.ts +94 -0
- package/packages/core/src/component_construction.ts +149 -0
- package/packages/core/src/contract.ts +25 -7
- package/packages/core/src/control_appearance.ts +232 -0
- package/packages/core/src/control_commands.ts +115 -0
- package/packages/core/src/control_content.ts +105 -0
- package/packages/core/src/control_geometry.ts +107 -0
- package/packages/core/src/control_payloads.ts +119 -0
- package/packages/core/src/control_primitives.ts +134 -0
- package/packages/core/src/devhost.ts +82 -7
- package/packages/core/src/devhost_journal.mjs +30 -7
- package/packages/core/src/effect_plans.ts +71 -0
- package/packages/core/src/flow_measurement.ts +121 -0
- package/packages/core/src/font_registry.ts +37 -0
- package/packages/core/src/glyph_atlas.ts +86 -0
- package/packages/core/src/gpu_packet_preparation.ts +130 -0
- package/packages/core/src/gpu_planning.ts +123 -0
- package/packages/core/src/gpu_presentation.ts +55 -0
- package/packages/core/src/host_flow.ts +89 -0
- package/packages/core/src/host_input_regions.ts +165 -0
- package/packages/core/src/image_registry.ts +66 -0
- package/packages/core/src/indicator_plans.ts +132 -0
- package/packages/core/src/infer.ts +150 -8
- package/packages/core/src/input_composition.ts +116 -0
- package/packages/core/src/intrinsic_measure.ts +100 -0
- package/packages/core/src/layout_coordination.ts +207 -0
- package/packages/core/src/leaf_plans.ts +134 -0
- package/packages/core/src/markup_development.ts +160 -0
- package/packages/core/src/measurement_coordination.ts +185 -0
- package/packages/core/src/modules.ts +1 -1
- package/packages/core/src/motion_sampling.ts +100 -0
- package/packages/core/src/paragraph_layout.ts +192 -0
- package/packages/core/src/portable_sources.json +74 -0
- package/packages/core/src/portable_sources.ts +17 -0
- package/packages/core/src/registered_font.ts +93 -0
- package/packages/core/src/render_animation_lifecycle.ts +128 -0
- package/packages/core/src/render_coordination.ts +170 -0
- package/packages/core/src/render_resources.ts +234 -0
- package/packages/core/src/runtime_policy.ts +3930 -0
- package/packages/core/src/scalar_text.ts +84 -0
- package/packages/core/src/service_contract.ts +2 -1
- package/packages/core/src/session_codecs.ts +309 -0
- package/packages/core/src/shell_admission.ts +126 -0
- package/packages/core/src/shell_coordination.ts +93 -0
- package/packages/core/src/sqlite_cli.ts +11 -0
- package/packages/core/src/status_validation.ts +232 -0
- package/packages/core/src/stream_policy.ts +63 -0
- package/packages/core/src/surface_recipes.ts +136 -0
- package/packages/core/src/system_admission.ts +60 -0
- package/packages/core/src/terminal_paint.ts +436 -0
- package/packages/core/src/text_document_width.ts +81 -0
- package/packages/core/src/text_measurement_cache.ts +69 -0
- package/packages/core/src/text_query_layout.ts +179 -0
- package/packages/core/src/text_run_layout.ts +410 -0
- package/packages/core/src/text_span_queries.ts +355 -0
- package/packages/core/src/typed_ast.ts +18 -1
- package/packages/core/src/types.ts +7 -5
- package/packages/core/src/vector_effects.ts +98 -0
- package/packages/core/src/vector_raster.ts +243 -0
- package/packages/core/src/view_components.ts +2415 -0
- package/packages/core/src/view_coordination.ts +198 -0
- package/packages/core/src/view_frontend.ts +980 -0
- package/packages/core/src/widget_audits.ts +202 -0
- package/packages/core/src/widget_changes.ts +258 -0
- package/packages/core/src/widget_metrics.ts +139 -0
- package/packages/core/src/widget_motion.ts +171 -0
- package/packages/core/src/widget_paint.ts +272 -0
- package/packages/core/src/widget_paint_walk.ts +203 -0
- package/packages/core/src/widget_presentation.ts +141 -0
- package/packages/core/src/widget_routing.ts +262 -0
- package/packages/core/src/window_lifecycle.ts +92 -0
- package/packages/core/testing/index.ts +430 -0
- package/schemas/app.schema.json +13 -0
- package/skill-data/core/SKILL.md +2 -2
- package/skill-data/core/references/web-engines-packaging-debugging.md +2 -1
- package/skill-data/native-ui/SKILL.md +76 -17
- package/skill-data/ts-core/SKILL.md +113 -9
- package/skill-data/ts-services/SKILL.md +1 -1
- package/skill-data/ts-services/references/service-surface.md +264 -144
- package/src/app_runner/root.zig +25 -12
- package/src/app_runner/ts_compiled_view.zig +1631 -0
- package/src/app_runner/ts_core_main.zig +143 -10
- package/src/app_runner/ts_core_mobile.zig +24 -12
- package/src/automation/server.zig +1 -3
- package/src/automation/snapshot.zig +9 -637
- package/src/automation/snapshot_reference.zig +656 -0
- package/src/automation/snapshot_serialization.zig +566 -0
- package/src/platform/linux/gtk_host.c +36 -24
- package/src/platform/linux/gtk_pixels.h +118 -0
- package/src/platform/linux/gtk_pixels_test.c +241 -0
- package/src/platform/linux/root.zig +2 -0
- package/src/platform/macos/appkit_host.m +188 -30
- package/src/platform/macos/pointer_motion_test.m +96 -0
- package/src/platform/macos/scroll_driver_test.m +105 -0
- package/src/platform/macos/spectrum_bins.h +34 -0
- package/src/platform/macos/spectrum_bins_test.c +56 -0
- package/src/platform/macos/text_keyboard_test.m +80 -0
- package/src/platform/macos/widget_focus_test.m +66 -0
- package/src/platform/null_platform.zig +26 -2
- package/src/platform/null_platform_tests.zig +13 -0
- package/src/platform/root.zig +1 -0
- package/src/platform/types.zig +13 -0
- package/src/platform/windows/root.zig +2 -0
- package/src/platform/windows/webview2_host.cpp +7 -2
- package/src/primitives/app_manifest/comptime_scene.zig +1 -1
- package/src/primitives/app_manifest/root.zig +2 -0
- package/src/primitives/app_manifest/tests.zig +4 -1
- package/src/primitives/app_manifest/validation.zig +2 -0
- package/src/primitives/canvas/a11y_audit.zig +3 -1
- package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
- package/src/primitives/canvas/chart_content_policy.zig +75 -0
- package/src/primitives/canvas/chart_plan_policy.zig +196 -0
- package/src/primitives/canvas/code_content_policy.zig +162 -0
- package/src/primitives/canvas/commands.zig +29 -1
- package/src/primitives/canvas/component_composition.zig +125 -0
- package/src/primitives/canvas/component_composition_policy.zig +44 -0
- package/src/primitives/canvas/component_construction_policy.zig +187 -0
- package/src/primitives/canvas/container_layout_policy.zig +87 -0
- package/src/primitives/canvas/control_appearance_policy.zig +142 -0
- package/src/primitives/canvas/control_command_policy.zig +75 -0
- package/src/primitives/canvas/control_content_policy.zig +90 -0
- package/src/primitives/canvas/control_geometry_policy.zig +165 -0
- package/src/primitives/canvas/control_payload_policy.zig +48 -0
- package/src/primitives/canvas/control_primitive_policy.zig +129 -0
- package/src/primitives/canvas/effect_plan_policy.zig +96 -0
- package/src/primitives/canvas/events.zig +1027 -1
- package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
- package/src/primitives/canvas/frame.zig +92 -23
- package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
- package/src/primitives/canvas/gpu.zig +10 -0
- package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
- package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
- package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
- package/src/primitives/canvas/grid_layout_policy.zig +51 -0
- package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
- package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
- package/src/primitives/canvas/intrinsic_measure_policy.zig +128 -0
- package/src/primitives/canvas/layout_audit.zig +5 -2
- package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
- package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
- package/src/primitives/canvas/markdown.zig +13 -3
- package/src/primitives/canvas/markdown_content_policy.zig +227 -0
- package/src/primitives/canvas/markdown_image_binding.zig +81 -0
- package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
- package/src/primitives/canvas/numeric_capabilities.zig +14 -0
- package/src/primitives/canvas/reference.zig +12 -6
- package/src/primitives/canvas/registered_font_policy.zig +152 -0
- package/src/primitives/canvas/render.zig +48 -0
- package/src/primitives/canvas/render_cache_policy.zig +184 -0
- package/src/primitives/canvas/render_coordination_policy.zig +163 -0
- package/src/primitives/canvas/render_damage_policy.zig +160 -0
- package/src/primitives/canvas/render_effects.zig +14 -0
- package/src/primitives/canvas/render_generic_resources.zig +14 -0
- package/src/primitives/canvas/render_images.zig +14 -0
- package/src/primitives/canvas/render_layers.zig +14 -0
- package/src/primitives/canvas/render_override_policy.zig +119 -0
- package/src/primitives/canvas/render_paths.zig +14 -0
- package/src/primitives/canvas/render_plan_policy.zig +199 -0
- package/src/primitives/canvas/render_resource_policy.zig +476 -0
- package/src/primitives/canvas/root.zig +100 -0
- package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
- package/src/primitives/canvas/serialization.zig +8 -1
- package/src/primitives/canvas/surface_layout_policy.zig +36 -0
- package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
- package/src/primitives/canvas/terminal_grid.zig +10 -696
- package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
- package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
- package/src/primitives/canvas/text.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +113 -0
- package/src/primitives/canvas/text_cache_policy.zig +94 -0
- package/src/primitives/canvas/text_document_policy.zig +120 -0
- package/src/primitives/canvas/text_layout.zig +51 -2
- package/src/primitives/canvas/text_layout_cache.zig +29 -0
- package/src/primitives/canvas/text_layout_hash.zig +1 -0
- package/src/primitives/canvas/text_layout_types.zig +3 -0
- package/src/primitives/canvas/text_measure_cache.zig +46 -0
- package/src/primitives/canvas/text_measurement_policy.zig +124 -0
- package/src/primitives/canvas/text_metrics.zig +23 -0
- package/src/primitives/canvas/text_query_policy.zig +156 -0
- package/src/primitives/canvas/text_run_policy.zig +252 -0
- package/src/primitives/canvas/text_scalar_policy.zig +156 -0
- package/src/primitives/canvas/text_span_query_policy.zig +232 -0
- package/src/primitives/canvas/text_spans.zig +280 -8
- package/src/primitives/canvas/text_tests.zig +10 -0
- package/src/primitives/canvas/tokens.zig +38 -0
- package/src/primitives/canvas/ui.zig +250 -83
- package/src/primitives/canvas/ui_markup.zig +139 -33
- package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
- package/src/primitives/canvas/ui_markup_contract.zig +146 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
- package/src/primitives/canvas/ui_markup_tests.zig +116 -0
- package/src/primitives/canvas/ui_markup_view.zig +258 -32
- package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
- package/src/primitives/canvas/ui_schema.zig +13 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -7
- package/src/primitives/canvas/ui_tests.zig +1 -0
- package/src/primitives/canvas/vector.zig +36 -2
- package/src/primitives/canvas/vector_effect_policy.zig +236 -0
- package/src/primitives/canvas/vector_raster_policy.zig +190 -0
- package/src/primitives/canvas/virtual_extent_policy.zig +292 -0
- package/src/primitives/canvas/virtual_extents.zig +99 -3
- package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
- package/src/primitives/canvas/widget_audit_policy.zig +293 -0
- package/src/primitives/canvas/widget_change_policy.zig +298 -0
- package/src/primitives/canvas/widget_invalidation.zig +113 -2
- package/src/primitives/canvas/widget_layout.zig +673 -128
- package/src/primitives/canvas/widget_layout_tests.zig +4 -0
- package/src/primitives/canvas/widget_metric_policy.zig +126 -0
- package/src/primitives/canvas/widget_metrics.zig +45 -6
- package/src/primitives/canvas/widget_paint_policy.zig +166 -0
- package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
- package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
- package/src/primitives/canvas/widget_render.zig +744 -74
- package/src/primitives/canvas/widget_render_controls.zig +1217 -133
- package/src/primitives/canvas/widget_render_scroll.zig +11 -3
- package/src/primitives/canvas/widget_render_style.zig +94 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
- package/src/primitives/canvas/widget_routing.zig +75 -0
- package/src/primitives/canvas/widget_routing_policy.zig +135 -0
- package/src/primitives/canvas/widget_runtime.zig +20 -1
- package/src/primitives/canvas/widget_semantics.zig +25 -0
- package/src/primitives/canvas/widget_text_input.zig +86 -23
- package/src/primitives/canvas/widget_text_select.zig +1 -0
- package/src/primitives/canvas/widget_tree.zig +8 -1
- package/src/primitives/canvas/widgets.zig +42 -12
- package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
- package/src/root.zig +21 -0
- package/src/runtime/accessibility_policy.zig +122 -0
- package/src/runtime/api.zig +28 -0
- package/src/runtime/app_dispatch_policy.zig +68 -0
- package/src/runtime/authorization_policy.zig +150 -0
- package/src/runtime/automation_command_policy.zig +241 -0
- package/src/runtime/automation_interaction_policy.zig +107 -0
- package/src/runtime/automation_snapshot.zig +52 -22
- package/src/runtime/automation_snapshot_reference.zig +290 -0
- package/src/runtime/automation_widget_dispatch.zig +267 -355
- package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
- package/src/runtime/blob_policy.zig +58 -0
- package/src/runtime/blob_reference.zig +64 -0
- package/src/runtime/bridge_descriptor_policy.zig +206 -0
- package/src/runtime/builtin_bridge.zig +180 -44
- package/src/runtime/builtin_coordination_policy.zig +121 -0
- package/src/runtime/callback_policy_test_reference.zig +97 -0
- package/src/runtime/canvas_drag_policy.zig +94 -0
- package/src/runtime/canvas_fonts.zig +38 -10
- package/src/runtime/canvas_frame.zig +590 -134
- package/src/runtime/canvas_frame_helpers.zig +1 -0
- package/src/runtime/canvas_hover_policy.zig +131 -0
- package/src/runtime/canvas_images.zig +59 -30
- package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
- package/src/runtime/canvas_limits.zig +1 -1
- package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
- package/src/runtime/canvas_scene_observation_policy.zig +181 -0
- package/src/runtime/canvas_widget_context_menu.zig +4 -4
- package/src/runtime/canvas_widget_display.zig +110 -9
- package/src/runtime/canvas_widget_events.zig +718 -328
- package/src/runtime/canvas_widget_runtime.zig +437 -81
- package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
- package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
- package/src/runtime/canvas_widget_state.zig +93 -56
- package/src/runtime/channel_sources.zig +80 -0
- package/src/runtime/command_policy.zig +161 -0
- package/src/runtime/component_policy.zig +83 -0
- package/src/runtime/core.zig +156 -6
- package/src/runtime/desktop_files.zig +189 -0
- package/src/runtime/effects.zig +466 -29
- package/src/runtime/effects_tests.zig +28 -0
- package/src/runtime/file_policy_test_reference.zig +113 -0
- package/src/runtime/flow.zig +418 -341
- package/src/runtime/flow_reference.zig +1426 -0
- package/src/runtime/font_registry_policy.zig +72 -0
- package/src/runtime/frame_profile.zig +24 -33
- package/src/runtime/gpu_surface_events.zig +97 -35
- package/src/runtime/host_event_pump.zig +303 -0
- package/src/runtime/host_event_pump_reference.zig +268 -0
- package/src/runtime/host_flow_policy.zig +155 -0
- package/src/runtime/host_input_regions_policy.zig +156 -0
- package/src/runtime/image_registry_policy.zig +94 -0
- package/src/runtime/input_composition_policy.zig +138 -0
- package/src/runtime/journal_policy.zig +66 -0
- package/src/runtime/journal_reference.zig +53 -0
- package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
- package/src/runtime/markup_development_policy.zig +91 -0
- package/src/runtime/media_surface.zig +40 -1
- package/src/runtime/motion_sampling_policy.zig +159 -0
- package/src/runtime/recording_policy.zig +42 -0
- package/src/runtime/render_animation_policy.zig +206 -0
- package/src/runtime/replay_policy.zig +66 -0
- package/src/runtime/replay_policy_reference.zig +326 -0
- package/src/runtime/replay_progress_policy.zig +64 -0
- package/src/runtime/replay_progress_reference.zig +34 -0
- package/src/runtime/request_policy_test_reference.zig +188 -0
- package/src/runtime/root.zig +13 -0
- package/src/runtime/session_blobs.zig +157 -58
- package/src/runtime/session_blobs_reference.zig +692 -0
- package/src/runtime/session_codec.zig +361 -0
- package/src/runtime/session_codec_reference.zig +1027 -0
- package/src/runtime/session_journal.zig +246 -983
- package/src/runtime/session_record.zig +224 -45
- package/src/runtime/session_replay.zig +157 -415
- package/src/runtime/session_tests.zig +552 -0
- package/src/runtime/shell_admission_policy.zig +225 -0
- package/src/runtime/shell_coordination_policy.zig +138 -0
- package/src/runtime/shell_layout.zig +126 -1
- package/src/runtime/snapshot_policy.zig +60 -0
- package/src/runtime/snapshot_reference.zig +64 -0
- package/src/runtime/state.zig +16 -0
- package/src/runtime/status_validation.zig +190 -0
- package/src/runtime/system_admission_policy.zig +140 -0
- package/src/runtime/system_services.zig +46 -36
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_canvas_hooks.zig +261 -0
- package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
- package/src/runtime/ts_canvas_icons.zig +234 -0
- package/src/runtime/ts_core_host.zig +2325 -411
- package/src/runtime/ts_core_host_tests.zig +1982 -0
- package/src/runtime/ts_test_host.zig +699 -0
- package/src/runtime/ts_ui_app.zig +1087 -45
- package/src/runtime/ui_app.zig +1117 -629
- package/src/runtime/ui_app_provenance.zig +147 -5
- package/src/runtime/ui_app_provenance_reference.zig +370 -0
- package/src/runtime/ui_app_tests.zig +619 -9
- package/src/runtime/ui_app_window_tests.zig +89 -0
- package/src/runtime/view.zig +25 -0
- package/src/runtime/view_canvas.zig +30 -6
- package/src/runtime/view_coordination_policy.zig +147 -0
- package/src/runtime/view_widget_control.zig +51 -14
- package/src/runtime/view_widget_scroll.zig +16 -5
- package/src/runtime/view_widget_text.zig +153 -68
- package/src/runtime/view_widget_tree.zig +460 -56
- package/src/runtime/webview_view_bridge_tests.zig +2 -0
- package/src/runtime/widget_motion_policy.zig +238 -0
- package/src/runtime/window_command_bridge_tests.zig +63 -0
- package/src/runtime/window_lifecycle_policy.zig +127 -0
- package/src/runtime/window_storage.zig +74 -8
- package/src/runtime/window_view_runtime.zig +148 -33
- package/src/runtime/window_views.zig +163 -10
- package/src/tooling/codesign.zig +125 -74
- package/src/tooling/components/identity_tests.zig +62 -36
- package/src/tooling/components/stepper.native +24 -0
- package/src/tooling/components/stepper.zig +0 -19
- package/src/tooling/components/timeline-item.native +22 -0
- package/src/tooling/components/timeline.native +5 -3
- package/src/tooling/components/timeline_item.zig +0 -32
- package/src/tooling/eject_components.zig +76 -8
- package/src/tooling/ios.zig +66 -12
- package/src/tooling/manifest.zig +35 -0
- package/src/tooling/package.zig +85 -1
- package/src/tooling/raw_manifest.zig +6 -0
- package/src/tooling/templates.zig +15 -3
- package/src/tooling/ts_core.zig +13 -3
- package/src/tooling/verbs.zig +22 -0
- package/tools/corewire/build_profile.mjs +54 -0
- package/tools/corewire/contract_intake.ts +303 -0
- package/tools/corewire/contract_intake.zig +82 -0
- package/tools/corewire/core.test.ts +166 -0
- package/tools/corewire/core_abi.zig +51 -0
- package/tools/corewire/core_cases.ts +233 -0
- package/tools/corewire/core_contract.ts +407 -0
- package/tools/corewire/core_emission.ts +136 -0
- package/tools/corewire/core_emission.zig +69 -0
- package/tools/corewire/core_goldens.json +3110 -0
- package/tools/corewire/core_policy.ts +14 -0
- package/tools/corewire/core_policy.zig +48 -0
- package/tools/corewire/core_projection.ts +360 -0
- package/tools/corewire/core_vocabulary.ts +6 -0
- package/tools/corewire/emit.zig +19 -1590
- package/tools/corewire/emit_facade.ts +714 -0
- package/tools/corewire/emit_facade.zig +10 -3752
- package/tools/corewire/emit_mirror.ts +290 -0
- package/tools/corewire/emit_profile.ts +50 -0
- package/tools/corewire/emit_service.ts +331 -0
- package/tools/corewire/emit_service.zig +23 -842
- package/tools/corewire/entry.test.ts +95 -0
- package/tools/corewire/entry_coordination.ts +127 -0
- package/tools/corewire/entry_coordination.zig +190 -0
- package/tools/corewire/facade_templates.ts +85 -0
- package/tools/corewire/filesystem.test.ts +166 -0
- package/tools/corewire/filesystem_coordination.ts +213 -0
- package/tools/corewire/filesystem_coordination.zig +245 -0
- package/tools/corewire/intake.test.ts +35 -0
- package/tools/corewire/intake_cases.ts +55 -0
- package/tools/corewire/intake_goldens.json +12237 -0
- package/tools/corewire/invocation.test.ts +24 -0
- package/tools/corewire/invocation.ts +175 -0
- package/tools/corewire/invocation.zig +136 -0
- package/tools/corewire/invocation_cases.ts +60 -0
- package/tools/corewire/invocation_fixture.ts +33 -0
- package/tools/corewire/invocation_goldens.json +1143 -0
- package/tools/corewire/invocation_tests.zig +111 -0
- package/tools/corewire/invocation_usage.ts +2 -0
- package/tools/corewire/lossless_projection.ts +96 -0
- package/tools/corewire/main.zig +7 -680
- package/tools/corewire/main_reference.zig +415 -0
- package/tools/corewire/mirror_templates.ts +55 -0
- package/tools/corewire/profile.test.ts +248 -0
- package/tools/corewire/profile.zig +56 -0
- package/tools/corewire/profile_emission.ts +202 -0
- package/tools/corewire/profile_library.json +29 -0
- package/tools/corewire/profile_tests.zig +136 -0
- package/tools/corewire/service.test.ts +75 -0
- package/tools/corewire/service_cases.ts +61 -0
- package/tools/corewire/service_contract.zig +40 -146
- package/tools/corewire/service_goldens.json +650 -0
- package/tools/corewire/service_projection.zig +52 -0
- package/tools/corewire/service_templates.ts +14 -0
- package/tools/corewire/shim_rt.zig +9 -0
- package/tools/corewire/sidecar.zig +267 -1438
- package/tools/corewire/emit_profile.zig +0 -521
|
@@ -7,6 +7,8 @@ const text_layout_cache = @import("text_layout_cache.zig");
|
|
|
7
7
|
const text_layout_hash = @import("text_layout_hash.zig");
|
|
8
8
|
const text_measure_cache = @import("text_measure_cache.zig");
|
|
9
9
|
const text_metrics = @import("text_metrics.zig");
|
|
10
|
+
const compiled_run = @import("text_run_policy.zig");
|
|
11
|
+
const compiled_query = @import("text_query_policy.zig");
|
|
10
12
|
|
|
11
13
|
const Error = canvas.Error;
|
|
12
14
|
const FontId = canvas.FontId;
|
|
@@ -38,6 +40,7 @@ pub const estimatedGlyphAdvance = text_metrics.estimatedGlyphAdvance;
|
|
|
38
40
|
pub const TextMeasureProvider = text_metrics.TextMeasureProvider;
|
|
39
41
|
pub const TextInkMetrics = text_metrics.TextInkMetrics;
|
|
40
42
|
pub const measureTextWidthForFont = text_metrics.measureTextWidthForFont;
|
|
43
|
+
pub const measureTextWidthForFontWithPolicy = text_metrics.measureTextWidthForFontWithPolicy;
|
|
41
44
|
pub const measureTextAdvance = text_metrics.measureTextAdvance;
|
|
42
45
|
|
|
43
46
|
/// The measurement provider a DrawText carries via its layout options, if
|
|
@@ -322,6 +325,11 @@ pub fn layoutTextRun(text: DrawText, options: TextLayoutOptions, output: []TextL
|
|
|
322
325
|
|
|
323
326
|
pub fn layoutTextRunPlan(text: DrawText, options: TextLayoutOptions, output: []TextLine) Error!TextLayoutPlan {
|
|
324
327
|
const effective_options = textLayoutOptionsForDrawText(options, text);
|
|
328
|
+
if (effective_options.text_run_policy) |policy| {
|
|
329
|
+
const result = compiled_query.execute(policy, text, effective_options, .{ .mode = 0, .lines = output });
|
|
330
|
+
if (result.line_capacity_failed) return error.TextLayoutLineListFull;
|
|
331
|
+
return .{ .key = textLayoutKey(text, effective_options), .layout = .{ .lines = output[0..result.len], .bounds = result.bounds } };
|
|
332
|
+
}
|
|
325
333
|
var len: usize = 0;
|
|
326
334
|
var bounds: ?geometry.RectF = null;
|
|
327
335
|
var lines = TextLineIterator.init(text, effective_options);
|
|
@@ -359,6 +367,13 @@ pub const TextLineIterator = struct {
|
|
|
359
367
|
|
|
360
368
|
pub fn next(self: *TextLineIterator) ?TextLine {
|
|
361
369
|
if (self.finished) return null;
|
|
370
|
+
if (self.options.text_run_policy orelse self.text.text_run_policy) |policy| {
|
|
371
|
+
const result = compiled_run.execute(policy, 0, self.text, self.options, self.cursor, self.index, self.finished, .{}, 0, 0);
|
|
372
|
+
self.cursor = result.cursor;
|
|
373
|
+
self.index = result.index;
|
|
374
|
+
self.finished = result.finished;
|
|
375
|
+
return result.line;
|
|
376
|
+
}
|
|
362
377
|
if (self.text.glyphs.len > 0) return self.nextGlyphLine();
|
|
363
378
|
return self.nextPlainLine();
|
|
364
379
|
}
|
|
@@ -430,6 +445,8 @@ fn textInkInsets(size: f32) geometry.InsetsF {
|
|
|
430
445
|
}
|
|
431
446
|
|
|
432
447
|
pub fn textBounds(value: DrawText) ?geometry.RectF {
|
|
448
|
+
const run_options = textLayoutOptionsForDrawText(.{}, value);
|
|
449
|
+
if (run_options.text_run_policy) |policy| return compiled_query.execute(policy, value, run_options, .{ .mode = 1 }).bounds;
|
|
433
450
|
if (value.text_layout) |options| {
|
|
434
451
|
var lines: [max_text_bounds_layout_lines]TextLine = undefined;
|
|
435
452
|
if (layoutTextRun(value, options, &lines)) |layout| {
|
|
@@ -446,7 +463,7 @@ pub fn textBounds(value: DrawText) ?geometry.RectF {
|
|
|
446
463
|
while (iterator.next()) |line| {
|
|
447
464
|
bounds = unionOptionalBounds(bounds, textLineInkBounds(value, line));
|
|
448
465
|
}
|
|
449
|
-
if (bounds) |value_bounds| return
|
|
466
|
+
if (bounds) |value_bounds| return inflateTextBounds(value, value_bounds);
|
|
450
467
|
}
|
|
451
468
|
|
|
452
469
|
const metric = metricTextBounds(value) orelse return null;
|
|
@@ -471,10 +488,17 @@ fn textBoundsForLines(value: DrawText, lines: []const TextLine) ?geometry.RectF
|
|
|
471
488
|
for (lines) |line| {
|
|
472
489
|
bounds = unionOptionalBounds(bounds, textLineInkBounds(value, line));
|
|
473
490
|
}
|
|
474
|
-
return if (bounds) |value_bounds|
|
|
491
|
+
return if (bounds) |value_bounds| inflateTextBounds(value, value_bounds) else null;
|
|
492
|
+
}
|
|
493
|
+
fn inflateTextBounds(text: DrawText, bounds: geometry.RectF) geometry.RectF {
|
|
494
|
+
const options = textLayoutOptionsForDrawText(.{}, text);
|
|
495
|
+
if (options.text_run_policy) |policy| return compiled_run.execute(policy, 7, text, options, 0, 0, false, .{ .bounds = bounds }, 0, 0).line.?.bounds;
|
|
496
|
+
return bounds.inflate(textInkInsets(text.size));
|
|
475
497
|
}
|
|
476
498
|
|
|
477
499
|
fn textLineInkBounds(value: DrawText, line: TextLine) geometry.RectF {
|
|
500
|
+
const options = textLayoutOptionsForDrawText(.{}, value);
|
|
501
|
+
if (options.text_run_policy) |policy| return compiled_run.execute(policy, 6, value, options, 0, 0, false, line, 0, 0).line.?.bounds;
|
|
478
502
|
var bounds = line.bounds;
|
|
479
503
|
if (value.glyphs.len > 0) return bounds;
|
|
480
504
|
if (drawTextMeasure(value)) |provider| {
|
|
@@ -505,6 +529,8 @@ fn textLineInkBounds(value: DrawText, line: TextLine) geometry.RectF {
|
|
|
505
529
|
}
|
|
506
530
|
|
|
507
531
|
fn metricTextBounds(value: DrawText) ?geometry.RectF {
|
|
532
|
+
const options = textLayoutOptionsForDrawText(.{}, value);
|
|
533
|
+
if (options.text_run_policy) |policy| return if (compiled_run.execute(policy, 5, value, options, 0, 0, false, .{}, 0, 0).line) |line| line.bounds else null;
|
|
508
534
|
if (value.glyphs.len == 0 and value.text.len == 0) return null;
|
|
509
535
|
|
|
510
536
|
var min_x = value.origin.x;
|
|
@@ -549,6 +575,7 @@ pub fn layoutTextCaretRectWithAffinity(
|
|
|
549
575
|
offset: usize,
|
|
550
576
|
affinity: canvas.TextCaretAffinity,
|
|
551
577
|
) ?geometry.RectF {
|
|
578
|
+
if (options.text_run_policy orelse text.text_run_policy) |policy| return compiled_query.execute(policy, text, options, .{ .mode = 2, .offset = offset, .affinity = affinity }).bounds;
|
|
552
579
|
const line = streamTextLineForOffset(text, options, snapTextOffset(text.text, offset), affinity) orelse return null;
|
|
553
580
|
return textCaretRectForLine(text, line, offset);
|
|
554
581
|
}
|
|
@@ -563,6 +590,7 @@ pub fn textCaretRectForLayoutWithAffinity(
|
|
|
563
590
|
offset: usize,
|
|
564
591
|
affinity: canvas.TextCaretAffinity,
|
|
565
592
|
) ?geometry.RectF {
|
|
593
|
+
if (textLayoutOptionsForDrawText(.{}, text).text_run_policy) |policy| return compiled_query.execute(policy, text, textLayoutOptionsForDrawText(.{}, text), .{ .mode = 5, .offset = offset, .affinity = affinity, .prepared = layout.lines }).bounds;
|
|
566
594
|
const line = textLineForOffset(layout, text.text.len, snapTextOffset(text.text, offset), affinity) orelse return null;
|
|
567
595
|
return textCaretRectForLine(text, line, offset);
|
|
568
596
|
}
|
|
@@ -583,6 +611,11 @@ pub fn layoutTextSelectionRects(
|
|
|
583
611
|
range: TextRange,
|
|
584
612
|
output: []TextSelectionRect,
|
|
585
613
|
) []const TextSelectionRect {
|
|
614
|
+
if (options.text_run_policy orelse text.text_run_policy) |policy| {
|
|
615
|
+
const result = compiled_query.execute(policy, text, options, .{ .mode = 3, .range = range, .selections = output });
|
|
616
|
+
return output[0..result.len];
|
|
617
|
+
}
|
|
618
|
+
|
|
586
619
|
const normalized = snapTextRange(text.text, range);
|
|
587
620
|
if (normalized.isCollapsed(text.text.len)) return output[0..0];
|
|
588
621
|
|
|
@@ -595,6 +628,11 @@ pub fn layoutTextSelectionRects(
|
|
|
595
628
|
}
|
|
596
629
|
|
|
597
630
|
pub fn textSelectionRectsForLayout(text: DrawText, layout: TextLayout, range: TextRange, output: []TextSelectionRect) []const TextSelectionRect {
|
|
631
|
+
if (textLayoutOptionsForDrawText(.{}, text).text_run_policy) |policy| {
|
|
632
|
+
const result = compiled_query.execute(policy, text, textLayoutOptionsForDrawText(.{}, text), .{ .mode = 6, .range = range, .prepared = layout.lines, .selections = output });
|
|
633
|
+
return output[0..result.len];
|
|
634
|
+
}
|
|
635
|
+
|
|
598
636
|
const normalized = snapTextRange(text.text, range);
|
|
599
637
|
if (normalized.isCollapsed(text.text.len)) return output[0..0];
|
|
600
638
|
|
|
@@ -657,6 +695,8 @@ pub fn layoutTextCaretPositionForPoint(
|
|
|
657
695
|
options: TextLayoutOptions,
|
|
658
696
|
point: geometry.PointF,
|
|
659
697
|
) ?canvas.TextCaretPosition {
|
|
698
|
+
if (options.text_run_policy orelse text.text_run_policy) |policy| return compiled_query.execute(policy, text, options, .{ .mode = 4, .point = point }).position;
|
|
699
|
+
|
|
660
700
|
var lines = TextLineIterator.init(text, options);
|
|
661
701
|
var candidate: ?TextLine = null;
|
|
662
702
|
var previous: ?TextLine = null;
|
|
@@ -681,6 +721,8 @@ pub fn textCaretPositionForLayoutPoint(
|
|
|
681
721
|
layout: TextLayout,
|
|
682
722
|
point: geometry.PointF,
|
|
683
723
|
) ?canvas.TextCaretPosition {
|
|
724
|
+
if (textLayoutOptionsForDrawText(.{}, text).text_run_policy) |policy| return compiled_query.execute(policy, text, textLayoutOptionsForDrawText(.{}, text), .{ .mode = 7, .point = point, .prepared = layout.lines }).position;
|
|
725
|
+
|
|
684
726
|
var previous: ?TextLine = null;
|
|
685
727
|
for (layout.lines) |line| {
|
|
686
728
|
if (point.y < line.bounds.y + line.bounds.height) {
|
|
@@ -738,6 +780,7 @@ fn streamTextLineForOffset(
|
|
|
738
780
|
}
|
|
739
781
|
|
|
740
782
|
pub fn nextTextLineEnd(text: []const u8, start: usize, font_id: FontId, size: f32, options: TextLayoutOptions) usize {
|
|
783
|
+
if (options.text_run_policy) |policy| return compiled_run.execute(policy, 1, .{ .font_id = font_id, .size = size, .origin = .{}, .color = .{}, .text = text, .measure = options.measure }, options, start, 0, false, .{}, 0, 0).offset;
|
|
741
784
|
const max_width = if (options.max_width > 0) options.max_width else std.math.inf(f32);
|
|
742
785
|
if (options.wrap == .none or max_width == std.math.inf(f32)) {
|
|
743
786
|
return nextExplicitLineEnd(text, start);
|
|
@@ -936,6 +979,8 @@ fn textLineRangeForLength(text_len: usize, line: TextLine) TextRange {
|
|
|
936
979
|
}
|
|
937
980
|
|
|
938
981
|
pub fn textLineCaretX(text: DrawText, line: TextLine, offset: usize) f32 {
|
|
982
|
+
const options = textLayoutOptionsForDrawText(.{}, text);
|
|
983
|
+
if (options.text_run_policy) |policy| return compiled_run.execute(policy, 2, text, options, 0, 0, false, line, offset, 0).scalar;
|
|
939
984
|
const range = textLineRange(text, line);
|
|
940
985
|
const snapped = clampTextOffsetToRange(text.text, range, offset);
|
|
941
986
|
const x = if (line.glyph_len > 0 and line.glyph_start < text.glyphs.len)
|
|
@@ -972,6 +1017,8 @@ fn textLineGlyphCaretX(text: DrawText, line: TextLine, range: TextRange, offset:
|
|
|
972
1017
|
}
|
|
973
1018
|
|
|
974
1019
|
fn textLineOffsetForX(text: DrawText, line: TextLine, x: f32) usize {
|
|
1020
|
+
const options = textLayoutOptionsForDrawText(.{}, text);
|
|
1021
|
+
if (options.text_run_policy) |policy| return compiled_run.execute(policy, 3, text, options, 0, 0, false, line, 0, x).offset;
|
|
975
1022
|
const range = textLineRange(text, line);
|
|
976
1023
|
if (x <= line.bounds.x) return range.start;
|
|
977
1024
|
// Elided lines: the hidden tail has no painted geometry, so a point
|
|
@@ -1042,6 +1089,8 @@ fn lineHeight(text: DrawText, options: TextLayoutOptions) f32 {
|
|
|
1042
1089
|
}
|
|
1043
1090
|
|
|
1044
1091
|
pub fn textLineBounds(text: DrawText, text_start: usize, text_len: usize, glyph_start: usize, glyph_len: usize, baseline: f32, line_height_value: f32) geometry.RectF {
|
|
1092
|
+
const options = textLayoutOptionsForDrawText(.{}, text);
|
|
1093
|
+
if (options.text_run_policy) |policy| return compiled_run.execute(policy, 4, text, options, 0, 0, false, .{ .text_start = text_start, .text_len = text_len, .glyph_start = glyph_start, .glyph_len = glyph_len, .baseline = baseline, .bounds = .{ .height = line_height_value } }, 0, 0).line.?.bounds;
|
|
1045
1094
|
if (glyph_len > 0 and glyph_start < text.glyphs.len) {
|
|
1046
1095
|
const glyphs = text.glyphs[glyph_start..@min(text.glyphs.len, glyph_start + glyph_len)];
|
|
1047
1096
|
const origin_x = glyphs[0].x;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const compiled_cache = @import("text_cache_policy.zig");
|
|
1
2
|
const geometry = @import("geometry");
|
|
2
3
|
const canvas = @import("root.zig");
|
|
3
4
|
const text_layout_types = @import("text_layout_types.zig");
|
|
@@ -49,6 +50,11 @@ pub const TextLayoutPlanSet = struct {
|
|
|
49
50
|
var planner = TextLayoutCachePlanner.init(entries, actions);
|
|
50
51
|
return planner.buildMany(self.plans, previous, frame_index, retention_frames);
|
|
51
52
|
}
|
|
53
|
+
pub fn cachePlanWithPolicy(self: TextLayoutPlanSet, policy: ?compiled_cache.Policy, previous: []const TextLayoutCacheEntry, frame_index: u64, retention_frames: u64, entries: []TextLayoutCacheEntry, actions: []TextLayoutCacheAction) Error!TextLayoutCachePlan {
|
|
54
|
+
var planner = TextLayoutCachePlanner.init(entries, actions);
|
|
55
|
+
if (policy) |owner| return planner.buildCompiled(self, previous, frame_index, retention_frames, owner);
|
|
56
|
+
return planner.buildMany(self.plans, previous, frame_index, retention_frames);
|
|
57
|
+
}
|
|
52
58
|
};
|
|
53
59
|
|
|
54
60
|
pub const TextLayoutCacheEntry = struct {
|
|
@@ -200,6 +206,29 @@ pub const TextLayoutCachePlanner = struct {
|
|
|
200
206
|
};
|
|
201
207
|
}
|
|
202
208
|
|
|
209
|
+
pub fn buildCompiled(self: *TextLayoutCachePlanner, plan: TextLayoutPlanSet, previous: []const TextLayoutCacheEntry, frame_index: u64, retention_frames: u64, policy: compiled_cache.Policy) Error!TextLayoutCachePlan {
|
|
210
|
+
self.reset();
|
|
211
|
+
const current = plan.plans;
|
|
212
|
+
var decision = compiled_cache.Plan.init(false, current.len, previous.len, self.entries.len, self.actions.len, frame_index, retention_frames);
|
|
213
|
+
defer decision.deinit();
|
|
214
|
+
for (current, 0..) |entry, i| decision.fact(i, entry.key, textLayoutKeyHash(entry.key), 0);
|
|
215
|
+
for (previous, 0..) |entry, i| decision.fact(current.len + i, entry.key, textLayoutKeyHash(entry.key), entry.last_used_frame);
|
|
216
|
+
decision.run(policy);
|
|
217
|
+
for (0..decision.entry_count) |i| {
|
|
218
|
+
const source = decision.source(i);
|
|
219
|
+
self.entries[i] = if (source < current.len) .{ .key = current[source].key, .line_count = current[source].lineCount(), .bounds = current[source].layout.bounds, .last_used_frame = frame_index } else previous[source - current.len];
|
|
220
|
+
}
|
|
221
|
+
self.entry_len = decision.entry_count;
|
|
222
|
+
for (0..decision.action_count) |i| {
|
|
223
|
+
const action = decision.action(i);
|
|
224
|
+
const source = action.source;
|
|
225
|
+
self.actions[i] = .{ .kind = @enumFromInt(action.kind), .key = if (source < current.len) current[source].key else previous[source - current.len].key, .layout_index = if (source < current.len) source else null, .cache_index = action.cache };
|
|
226
|
+
}
|
|
227
|
+
self.action_len = decision.action_count;
|
|
228
|
+
if (decision.failed) return error.TextLayoutCacheListFull;
|
|
229
|
+
return .{ .entries = self.entries[0..self.entry_len], .actions = self.actions[0..self.action_len] };
|
|
230
|
+
}
|
|
231
|
+
|
|
203
232
|
/// First appended entry equal to `key`, walking the entry index's
|
|
204
233
|
/// probe chain — the indexed equivalent of scanning
|
|
205
234
|
/// `self.entries[0..self.entry_len]`.
|
|
@@ -23,6 +23,7 @@ const resourceHashPoint = hash_model.resourceHashPoint;
|
|
|
23
23
|
pub fn textLayoutOptionsForDrawText(frame_options: TextLayoutOptions, text: DrawText) TextLayoutOptions {
|
|
24
24
|
var options = text.text_layout orelse frame_options;
|
|
25
25
|
if (options.measure == null) options.measure = text.measure;
|
|
26
|
+
if (options.text_run_policy == null) options.text_run_policy = text.text_run_policy;
|
|
26
27
|
return options;
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -20,6 +20,8 @@ pub const DrawText = struct {
|
|
|
20
20
|
/// Process-local measurement context used for host-aware ink bounds.
|
|
21
21
|
/// Excluded from equality, hashing, and serialization.
|
|
22
22
|
measure: ?*const text_metrics.TextMeasureProvider = null,
|
|
23
|
+
/// Process-local portable planner, excluded from content identity.
|
|
24
|
+
text_run_policy: ?*const fn ([]const u8, []u8) usize = null,
|
|
23
25
|
text_layout: ?TextLayoutOptions = null,
|
|
24
26
|
};
|
|
25
27
|
|
|
@@ -63,6 +65,7 @@ pub const TextLayoutOptions = struct {
|
|
|
63
65
|
/// Deliberately excluded from equality, hashing, and serialization:
|
|
64
66
|
/// it is process-local layout context, not drawn content.
|
|
65
67
|
measure: ?*const text_metrics.TextMeasureProvider = null,
|
|
68
|
+
text_run_policy: ?*const fn ([]const u8, []u8) usize = null,
|
|
66
69
|
};
|
|
67
70
|
|
|
68
71
|
pub const TextLine = struct {
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
const std = @import("std");
|
|
52
52
|
const builtin = @import("builtin");
|
|
53
53
|
const canvas = @import("root.zig");
|
|
54
|
+
const compiled = @import("text_measurement_policy.zig");
|
|
54
55
|
const text_metrics = @import("text_metrics.zig");
|
|
55
56
|
|
|
56
57
|
const FontId = canvas.FontId;
|
|
@@ -249,6 +250,51 @@ pub fn textRunAdvances(provider: *const TextMeasureProvider, font_id: FontId, si
|
|
|
249
250
|
return cache.storage[victim][0..text.len];
|
|
250
251
|
}
|
|
251
252
|
|
|
253
|
+
/// The compiled owner decides admission, exact lookup, LRU, fetch accounting
|
|
254
|
+
/// and batch acceptance. This adapter applies those decisions to native storage.
|
|
255
|
+
pub fn textRunAdvancesWithPolicy(provider: *const TextMeasureProvider, policy: ?compiled.Policy, font_id: FontId, size: f32, text: []const u8) ?[]const f32 {
|
|
256
|
+
const owner = policy orelse return textRunAdvances(provider, font_id, size, text);
|
|
257
|
+
return compiledAdvances(provider, owner, font_id, size, text, true);
|
|
258
|
+
}
|
|
259
|
+
pub fn cachedTextRunAdvancesWithPolicy(provider: *const TextMeasureProvider, policy: ?compiled.Policy, font_id: FontId, size: f32, text: []const u8) ?[]const f32 {
|
|
260
|
+
const owner = policy orelse return cachedTextRunAdvances(provider, font_id, size, text);
|
|
261
|
+
return compiledAdvances(provider, owner, font_id, size, text, false);
|
|
262
|
+
}
|
|
263
|
+
fn compiledAdvances(provider: *const TextMeasureProvider, policy: compiled.Policy, font_id: FontId, size: f32, text: []const u8, fetch: bool) ?[]const f32 {
|
|
264
|
+
const flags: u8 = @as(u8, @intFromBool(provider.measure_advances_fn != null)) | (if (advance_cache.peek() != null) @as(u8, 2) else 0) | (if (fetch) @as(u8, 4) else 0);
|
|
265
|
+
const admitted = compiled.admission(policy, 0, flags, text.len, 0);
|
|
266
|
+
if (admitted.kind == 1) return &.{};
|
|
267
|
+
if (admitted.kind != 6) return null;
|
|
268
|
+
// Structural safety guards protect buffers independently of the policy.
|
|
269
|
+
if (provider.measure_advances_fn == null or text.len == 0 or text.len > max_batched_advance_run_bytes) @panic("invalid measured text admission");
|
|
270
|
+
const cache = if (fetch) advance_cache.get() else advance_cache.peek() orelse @panic("invalid measured text peek admission");
|
|
271
|
+
const current = advanceKeyFor(provider, font_id, size, text);
|
|
272
|
+
const oversize = text.len > max_cached_advance_run_bytes;
|
|
273
|
+
const count: usize = if (oversize) advance_cache_capacity + 1 else advance_cache_capacity;
|
|
274
|
+
var storage: [compiled.fact_packet_bytes]u8 = undefined;
|
|
275
|
+
const request = storage[0 .. compiled.facts_at + count * compiled.fact_bytes];
|
|
276
|
+
compiled.header(request, if (fetch) 1 else 2, 0, count, text.len, 0);
|
|
277
|
+
compiled.key(request[32..], current);
|
|
278
|
+
for (cache.entries, 0..) |entry, i| compiled.fact(request[compiled.facts_at + i * compiled.fact_bytes ..], entry.key, entry.last_used);
|
|
279
|
+
if (oversize) compiled.fact(request[compiled.facts_at + advance_cache_capacity * compiled.fact_bytes ..], cache.oversize_key, 0);
|
|
280
|
+
const decision = compiled.execute(policy, request);
|
|
281
|
+
if (decision.flags & 1 != 0) cache.use_tick += 1;
|
|
282
|
+
if (decision.flags & 2 != 0) cache.hit_count += 1;
|
|
283
|
+
if (decision.flags & 4 != 0) cache.fetch_count += 1;
|
|
284
|
+
const slot = decision.slot orelse return null;
|
|
285
|
+
if ((oversize and slot != advance_cache_capacity) or (!oversize and slot >= advance_cache_capacity)) @panic("invalid measured text storage family");
|
|
286
|
+
const values = if (oversize) cache.oversize_storage[0..text.len] else cache.storage[slot][0..text.len];
|
|
287
|
+
if (decision.kind == 2) {
|
|
288
|
+
if (!oversize) cache.entries[slot].last_used = cache.use_tick;
|
|
289
|
+
return values;
|
|
290
|
+
}
|
|
291
|
+
if (oversize) cache.oversize_key = .{} else cache.entries[slot].key = .{};
|
|
292
|
+
if (!provider.measureAdvances(font_id, size, text, values)) return null;
|
|
293
|
+
if (!compiled.batchValid(policy, values)) return null;
|
|
294
|
+
if (oversize) cache.oversize_key = current else cache.entries[slot] = .{ .key = current, .last_used = cache.use_tick };
|
|
295
|
+
return values;
|
|
296
|
+
}
|
|
297
|
+
|
|
252
298
|
/// Peek: the run's advances IF already retained (or sitting in the
|
|
253
299
|
/// oversize slot), never fetching. Per-frame consumers that would
|
|
254
300
|
/// otherwise fetch hundreds of retained single-line runs (line-bounds
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
//! Copied measured-text decisions. Native owns hashes, opaque provider
|
|
2
|
+
//! identities, generation atomics, font calls, buffers and pointer proofs.
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
pub const Policy = *const fn ([]const u8, []u8) usize;
|
|
5
|
+
pub const key_bytes = 96;
|
|
6
|
+
pub const fact_bytes = 104;
|
|
7
|
+
pub const max_facts = 257;
|
|
8
|
+
pub const facts_at = 128;
|
|
9
|
+
pub const fact_packet_bytes = facts_at + max_facts * fact_bytes;
|
|
10
|
+
pub const Decision = struct { kind: u32, slot: ?usize, flags: u32 };
|
|
11
|
+
|
|
12
|
+
pub fn header(bytes: []u8, mode: u8, flags: u8, count: usize, length: usize, capacity: usize) void {
|
|
13
|
+
@memset(bytes, 0);
|
|
14
|
+
bytes[0..4].* = .{ 58, 1, mode, flags };
|
|
15
|
+
put(bytes, 4, count);
|
|
16
|
+
put(bytes, 8, length);
|
|
17
|
+
put(bytes, 12, capacity);
|
|
18
|
+
}
|
|
19
|
+
pub fn resultValid(request: []const u8, result: []const u8) bool {
|
|
20
|
+
if (request.len < 32 or result.len != 16 or word(result, 0) > 6 or word(result, 8) > 15 or word(result, 12) != 0) return false;
|
|
21
|
+
const kind = word(result, 0);
|
|
22
|
+
const slot = word(result, 4);
|
|
23
|
+
const flags = word(result, 8);
|
|
24
|
+
const mode = request[2];
|
|
25
|
+
const indexed = kind == 2 or kind == 3 or kind == 4;
|
|
26
|
+
if (indexed) {
|
|
27
|
+
if (slot >= word(request, 4)) return false;
|
|
28
|
+
} else if (slot != 0xffffffff) return false;
|
|
29
|
+
return switch (mode) {
|
|
30
|
+
0 => (kind == 0 or kind == 1 or kind == 6) and flags == 0,
|
|
31
|
+
3 => (kind == 0 or kind == 6) and flags == 0,
|
|
32
|
+
1 => (kind == 2 and flags == 3) or (kind == 3 and flags == 5),
|
|
33
|
+
2 => (kind == 0 and flags == 0) or (kind == 2 and flags == (if (word(request, 8) > 2048) @as(u32, 2) else 3)),
|
|
34
|
+
4 => (kind == 0 and flags == 8) or (kind == 2 and flags == 3),
|
|
35
|
+
5 => (kind == 0 and flags == 0) or (kind == 4 and flags == 1),
|
|
36
|
+
6, 7 => (kind == 0 or kind == 5) and flags == 0,
|
|
37
|
+
else => false,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
pub fn execute(policy: Policy, request: []const u8) Decision {
|
|
41
|
+
var result: [16]u8 = undefined;
|
|
42
|
+
if (policy(request, &result) != result.len or !resultValid(request, &result)) @panic("invalid measured text decision");
|
|
43
|
+
const kind = word(&result, 0);
|
|
44
|
+
const slot = word(&result, 4);
|
|
45
|
+
return .{ .kind = kind, .slot = if (kind == 2 or kind == 3 or kind == 4) slot else null, .flags = word(&result, 8) };
|
|
46
|
+
}
|
|
47
|
+
pub fn key(bytes: []u8, value: anytype) void {
|
|
48
|
+
@memset(bytes[0..key_bytes], 0);
|
|
49
|
+
const T = @TypeOf(value);
|
|
50
|
+
if (comptime @hasField(T, "hash")) {
|
|
51
|
+
integer(bytes, 0, value.hash);
|
|
52
|
+
integer(bytes, 8, value.text_len);
|
|
53
|
+
integer(bytes, 16, value.font_id);
|
|
54
|
+
put(bytes, 24, value.size_bits);
|
|
55
|
+
integer(bytes, 32, value.provider_context);
|
|
56
|
+
integer(bytes, 40, value.provider_fn);
|
|
57
|
+
integer(bytes, 48, value.generation);
|
|
58
|
+
} else {
|
|
59
|
+
integer(bytes, 0, value.fingerprint);
|
|
60
|
+
integer(bytes, 8, value.span_count);
|
|
61
|
+
put(bytes, 16, value.size_bits);
|
|
62
|
+
put(bytes, 20, value.line_height_bits);
|
|
63
|
+
put(bytes, 24, value.max_width_bits);
|
|
64
|
+
put(bytes, 28, @intFromEnum(value.wrap));
|
|
65
|
+
put(bytes, 32, @intFromEnum(value.alignment));
|
|
66
|
+
integer(bytes, 40, value.font_id);
|
|
67
|
+
integer(bytes, 48, value.mono_font_id);
|
|
68
|
+
integer(bytes, 56, value.provider_context);
|
|
69
|
+
integer(bytes, 64, value.provider_fn);
|
|
70
|
+
integer(bytes, 72, value.paragraph_policy);
|
|
71
|
+
integer(bytes, 80, value.generation);
|
|
72
|
+
}
|
|
73
|
+
put(bytes, 88, @intFromBool(value.used));
|
|
74
|
+
}
|
|
75
|
+
pub fn fact(bytes: []u8, value: anytype, tick: u64) void {
|
|
76
|
+
key(bytes, value);
|
|
77
|
+
integer(bytes, 96, tick);
|
|
78
|
+
}
|
|
79
|
+
pub fn admission(policy: Policy, mode: u8, flags: u8, length: usize, capacity: usize) Decision {
|
|
80
|
+
var bytes: [32]u8 = undefined;
|
|
81
|
+
header(&bytes, mode, flags, 0, length, capacity);
|
|
82
|
+
return execute(policy, &bytes);
|
|
83
|
+
}
|
|
84
|
+
const BatchScratch = struct { bytes: [32 + 65536 * 4]u8 };
|
|
85
|
+
const batch_scratch = @import("lazy_tls.zig").LazyTls(BatchScratch);
|
|
86
|
+
pub fn batchValid(policy: Policy, advances: []const f32) bool {
|
|
87
|
+
if (advances.len > 65536) @panic("measured text batch outside owner storage");
|
|
88
|
+
const bytes = batch_scratch.get().bytes[0 .. 32 + advances.len * 4];
|
|
89
|
+
header(bytes, 6, 1, 0, advances.len, 0);
|
|
90
|
+
for (advances, 0..) |value, i| put(bytes, 32 + i * 4, @as(u32, @bitCast(value)));
|
|
91
|
+
return execute(policy, bytes).kind == 5;
|
|
92
|
+
}
|
|
93
|
+
pub fn put(bytes: []u8, at: usize, value: usize) void {
|
|
94
|
+
std.mem.writeInt(u32, bytes[at..][0..4], std.math.cast(u32, value) orelse @panic("measured text wire overflow"), .little);
|
|
95
|
+
}
|
|
96
|
+
pub fn integer(bytes: []u8, at: usize, value: u64) void {
|
|
97
|
+
std.mem.writeInt(u64, bytes[at..][0..8], value, .little);
|
|
98
|
+
}
|
|
99
|
+
fn word(bytes: []const u8, at: usize) u32 {
|
|
100
|
+
return std.mem.readInt(u32, bytes[at..][0..4], .little);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
test "measured text copied transport rejects foreign shapes before native state changes" {
|
|
104
|
+
var request: [32]u8 = undefined;
|
|
105
|
+
header(&request, 1, 0, 256, 1, 0);
|
|
106
|
+
var result: [16]u8 = @splat(0);
|
|
107
|
+
put(&result, 0, 3);
|
|
108
|
+
put(&result, 4, 255);
|
|
109
|
+
put(&result, 8, 5);
|
|
110
|
+
try std.testing.expect(resultValid(&request, &result));
|
|
111
|
+
for (0..16) |length| try std.testing.expect(!resultValid(&request, result[0..length]));
|
|
112
|
+
for ([_]usize{ 0, 4, 8, 12 }) |at| {
|
|
113
|
+
var bad = result;
|
|
114
|
+
put(&bad, at, 0xffffffff);
|
|
115
|
+
try std.testing.expect(!resultValid(&request, &bad));
|
|
116
|
+
}
|
|
117
|
+
put(&result, 4, 256);
|
|
118
|
+
try std.testing.expect(!resultValid(&request, &result));
|
|
119
|
+
put(&result, 4, 0);
|
|
120
|
+
for ([_]u8{ 0, 2, 3, 4, 5, 6, 7, 255 }) |mode| {
|
|
121
|
+
request[2] = mode;
|
|
122
|
+
try std.testing.expect(!resultValid(&request, &result));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -175,6 +175,16 @@ fn faceAdvanceEm(face: *const font_ttf.Face, glyph: u16) f32 {
|
|
|
175
175
|
return face.advance(glyph) / face.units_per_em;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
/// Immutable bundled-font primitive for copied scalar requests. Printable
|
|
179
|
+
/// ASCII uses the same comptime hmtx facts as the native reference, avoiding
|
|
180
|
+
/// repeated cmap walks when an editor measures long numeric drafts.
|
|
181
|
+
pub fn bundledGlyphAdvanceEm(codepoint: u21) ?f32 {
|
|
182
|
+
if (codepoint >= 0x20 and codepoint < 0x7f) return ascii_advance_em[codepoint - 0x20];
|
|
183
|
+
const face = &font_ttf.geist_regular;
|
|
184
|
+
const glyph = face.glyphIndex(codepoint);
|
|
185
|
+
return if (glyph == 0) null else faceAdvanceEm(face, glyph);
|
|
186
|
+
}
|
|
187
|
+
|
|
178
188
|
pub fn estimateTextAdvanceForBytes(font_id: FontId, bytes: []const u8, size: f32) f32 {
|
|
179
189
|
if (bytes.len == 0) return 0;
|
|
180
190
|
if (font_id == default_mono_font_id) return size * mono_advance_em;
|
|
@@ -334,3 +344,16 @@ fn sansVariantWidthFactor(font_id: FontId) f32 {
|
|
|
334
344
|
pub fn estimatedGlyphAdvance(glyph: Glyph, size: f32) f32 {
|
|
335
345
|
return @max(size * 0.25, glyph.advance);
|
|
336
346
|
}
|
|
347
|
+
|
|
348
|
+
pub fn measureTextWidthForFontWithPolicy(provider: ?*const TextMeasureProvider, policy: ?@import("text_scalar_policy.zig").Policy, font_id: FontId, text: []const u8, size: f32) f32 {
|
|
349
|
+
const owner = policy orelse return measureTextWidthForFont(provider, font_id, text, size);
|
|
350
|
+
return @import("text_scalar_policy.zig").width(owner, provider, font_id, text, size);
|
|
351
|
+
}
|
|
352
|
+
pub fn estimateTextAdvanceForBytesWithPolicy(policy: ?@import("text_scalar_policy.zig").Policy, font_id: FontId, bytes: []const u8, size: f32) f32 {
|
|
353
|
+
const owner = policy orelse return estimateTextAdvanceForBytes(font_id, bytes, size);
|
|
354
|
+
return @import("text_scalar_policy.zig").estimate(owner, font_id, bytes, size, true);
|
|
355
|
+
}
|
|
356
|
+
pub fn measureTextInkWithPolicy(provider: *const TextMeasureProvider, policy: ?@import("text_scalar_policy.zig").Policy, font_id: FontId, size: f32, text: []const u8) ?TextInkMetrics {
|
|
357
|
+
const owner = policy orelse return provider.measureInk(font_id, size, text);
|
|
358
|
+
return @import("text_scalar_policy.zig").ink(owner, provider, font_id, text, size);
|
|
359
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
//! Caller-owned storage and explicit font capabilities for whole-run queries.
|
|
2
|
+
//! Traversal, output admission, accumulation and neighboring-line decisions
|
|
3
|
+
//! belong to the portable query and line planners.
|
|
4
|
+
const std = @import("std");
|
|
5
|
+
const geometry = @import("geometry");
|
|
6
|
+
const types = @import("text_layout_types.zig");
|
|
7
|
+
const interaction = @import("text_interaction.zig");
|
|
8
|
+
const run = @import("text_run_policy.zig");
|
|
9
|
+
pub const Result = struct {
|
|
10
|
+
bounds: ?geometry.RectF,
|
|
11
|
+
position: ?interaction.TextCaretPosition,
|
|
12
|
+
len: usize,
|
|
13
|
+
line_capacity_failed: bool,
|
|
14
|
+
};
|
|
15
|
+
pub const Query = struct {
|
|
16
|
+
mode: u8,
|
|
17
|
+
offset: usize = 0,
|
|
18
|
+
affinity: interaction.TextCaretAffinity = .upstream,
|
|
19
|
+
point: geometry.PointF = .{},
|
|
20
|
+
range: interaction.TextRange = .{},
|
|
21
|
+
prepared: []const types.TextLine = &.{},
|
|
22
|
+
lines: []types.TextLine = &.{},
|
|
23
|
+
selections: []interaction.TextSelectionRect = &.{},
|
|
24
|
+
};
|
|
25
|
+
inline fn word(bytes: []const u8, at: usize) u32 {
|
|
26
|
+
return std.mem.readInt(u32, bytes[at..][0..4], .little);
|
|
27
|
+
}
|
|
28
|
+
inline fn float(bytes: []const u8, at: usize) f32 {
|
|
29
|
+
return @bitCast(word(bytes, at));
|
|
30
|
+
}
|
|
31
|
+
inline fn put(bytes: []u8, at: usize, value: usize) void {
|
|
32
|
+
std.mem.writeInt(u32, bytes[at..][0..4], std.math.cast(u32, value) orelse @panic("text query integer range"), .little);
|
|
33
|
+
}
|
|
34
|
+
inline fn setFloat(bytes: []u8, at: usize, value: f32) void {
|
|
35
|
+
std.mem.writeInt(u32, bytes[at..][0..4], @bitCast(value), .little);
|
|
36
|
+
}
|
|
37
|
+
fn readRect(bytes: []const u8, at: usize) geometry.RectF {
|
|
38
|
+
return .{ .x = float(bytes, at), .y = float(bytes, at + 4), .width = float(bytes, at + 8), .height = float(bytes, at + 12) };
|
|
39
|
+
}
|
|
40
|
+
fn lineValid(bytes: []const u8, at: usize, text_len: u32, glyph_count: u32) bool {
|
|
41
|
+
return @as(u64, word(bytes, at)) + word(bytes, at + 4) <= text_len and
|
|
42
|
+
(glyph_count == 0 or @as(u64, word(bytes, at + 8)) + word(bytes, at + 12) <= glyph_count) and
|
|
43
|
+
word(bytes, at + 36) <= 1 and word(bytes, at + 44) <= 1 and
|
|
44
|
+
(word(bytes, at + 36) == 0 or word(bytes, at + 40) <= word(bytes, at + 4)) and
|
|
45
|
+
(word(bytes, at + 44) == 0 or word(bytes, at + 48) <= word(bytes, at + 12));
|
|
46
|
+
}
|
|
47
|
+
/// Validate every write index and capability before invoking host code.
|
|
48
|
+
pub fn resultValid(request: []const u8, result: []const u8) bool {
|
|
49
|
+
if (request.len < 1024 or result.len != 1024 or result[3] < 1 or result[3] > 2 or
|
|
50
|
+
!std.mem.eql(u8, request[0..3], result[0..3]) or !std.mem.eql(u8, request[4..80], result[4..80])) return false;
|
|
51
|
+
if (word(result, 12) != request.len or word(result, 40) > request.len or
|
|
52
|
+
@as(u64, word(result, 40)) + @as(u64, word(result, 44)) * 64 != request.len) return false;
|
|
53
|
+
const source_len = word(request, 40);
|
|
54
|
+
const text_len = word(request, 548);
|
|
55
|
+
const glyph_count = word(request, 552);
|
|
56
|
+
if (source_len != 1024 + @as(u64, glyph_count) * 32 + @as(u64, text_len) * 5 or
|
|
57
|
+
word(request, 520) + @as(u64, text_len) != source_len or word(request, 524) != source_len or
|
|
58
|
+
!std.mem.eql(u8, request[512..514], result[512..514]) or
|
|
59
|
+
!std.mem.eql(u8, request[516..556], result[516..556]) or
|
|
60
|
+
!std.mem.eql(u8, request[576..592], result[576..592])) return false;
|
|
61
|
+
for ([_]usize{ 92, 100, 116, 184, 188, 248, 272, 308, 312 }) |at| if (word(result, at) > 1) return false;
|
|
62
|
+
if (word(result, 124) > word(request, 8) or word(result, 96) > 14 or word(result, 104) > 14 or
|
|
63
|
+
word(result, 316) > 64 or result[514] > 8 or result[515] > 2 or
|
|
64
|
+
word(result, 556) > (if (result[514] == 0 and glyph_count > 0) glyph_count else text_len) or
|
|
65
|
+
word(result, 564) > 1) return false;
|
|
66
|
+
const reserved_zero = [_]u8{0} ** 72;
|
|
67
|
+
if (!std.mem.eql(u8, result[440..512], &reserved_zero)) return false;
|
|
68
|
+
if (result[3] == 2) return word(result, 80) == 0 and word(result, 84) == 0 and word(result, 92) == 0 and word(result, 100) == 0 and word(result, 304) <= text_len;
|
|
69
|
+
if (word(result, 92) != 0) return false;
|
|
70
|
+
return switch (word(result, 80)) {
|
|
71
|
+
1 => blk: {
|
|
72
|
+
if (word(result, 100) != 1) break :blk false;
|
|
73
|
+
// A new portable subquery can replace the previous completed
|
|
74
|
+
// line state. Immutable facts still match the caller's source.
|
|
75
|
+
var expected: [512]u8 = undefined;
|
|
76
|
+
@memcpy(&expected, result[512..1024]);
|
|
77
|
+
expected[3] = 0;
|
|
78
|
+
if (word(request, 100) != 0 and request[515] == 1 and word(request, 368) == word(result, 368)) @memcpy(&expected, request[512..1024]);
|
|
79
|
+
break :blk run.resultValidFacts(&expected, source_len, 1024, result[512..1024]);
|
|
80
|
+
},
|
|
81
|
+
2 => request[2] == 0 and word(result, 100) == 0 and word(result, 84) < word(request, 8) and word(result, 124) == word(result, 84) + 1 and lineValid(result, 128, text_len, glyph_count),
|
|
82
|
+
3 => request[2] == 1 and word(result, 100) == 0 and word(result, 84) < 64 and word(result, 124) == word(result, 84) + 1 and lineValid(result, 128, text_len, glyph_count),
|
|
83
|
+
4 => (request[2] == 3 or request[2] == 6) and word(result, 100) == 0 and word(result, 84) < word(request, 8) and word(result, 124) == word(result, 84) + 1 and word(result, 320) <= word(result, 324) and word(result, 324) <= text_len,
|
|
84
|
+
else => false,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
pub fn execute(policy: run.Policy, text: types.DrawText, options: types.TextLayoutOptions, query: Query) Result {
|
|
88
|
+
const glyph_bytes = std.math.mul(usize, text.glyphs.len, 32) catch @panic("text query glyph capacity");
|
|
89
|
+
const text_bytes = std.math.mul(usize, text.text.len, 5) catch @panic("text query byte capacity");
|
|
90
|
+
const source_len = std.math.add(usize, std.math.add(usize, 1024, glyph_bytes) catch @panic("text query source capacity"), text_bytes) catch @panic("text query source capacity");
|
|
91
|
+
const prepared_count = if (query.mode == 1) 64 else query.prepared.len;
|
|
92
|
+
const total = std.math.add(usize, source_len, std.math.mul(usize, prepared_count, 64) catch @panic("text query line capacity")) catch @panic("text query packet capacity");
|
|
93
|
+
if (total > std.math.maxInt(u32)) @panic("text query packet range");
|
|
94
|
+
if (total <= 8192) {
|
|
95
|
+
var small: [8192]u8 = undefined;
|
|
96
|
+
return executeInStorage(policy, text, options, query, source_len, prepared_count, small[0..total]);
|
|
97
|
+
}
|
|
98
|
+
const allocator = std.heap.page_allocator;
|
|
99
|
+
const packet = allocator.alloc(u8, total) catch @panic("text query allocation");
|
|
100
|
+
defer allocator.free(packet);
|
|
101
|
+
return executeInStorage(policy, text, options, query, source_len, prepared_count, packet);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fn executeInStorage(policy: run.Policy, text: types.DrawText, options: types.TextLayoutOptions, query: Query, source_len: usize, prepared_count: usize, packet: []u8) Result {
|
|
105
|
+
const total = packet.len;
|
|
106
|
+
@memset(packet, 0);
|
|
107
|
+
run.initialize(packet[512..source_len], 512, 0, text, options, 0, 0, false, .{}, 0, 0);
|
|
108
|
+
put(packet, 520, source_len - text.text.len);
|
|
109
|
+
put(packet, 524, source_len);
|
|
110
|
+
packet[0..6].* = .{ 55, 1, query.mode, 0, @intFromBool(text.text_layout != null), @intFromBool(query.mode >= 5) };
|
|
111
|
+
put(packet, 8, if (query.mode == 0) query.lines.len else if (query.mode == 1) 64 else query.selections.len);
|
|
112
|
+
put(packet, 12, total);
|
|
113
|
+
put(packet, 16, @min(if (query.mode == 3 or query.mode == 6) query.range.start else query.offset, std.math.maxInt(u32)));
|
|
114
|
+
put(packet, 20, @min(query.range.end, std.math.maxInt(u32)));
|
|
115
|
+
put(packet, 24, @intFromEnum(query.affinity));
|
|
116
|
+
setFloat(packet, 28, query.point.x);
|
|
117
|
+
setFloat(packet, 32, query.point.y);
|
|
118
|
+
put(packet, 40, source_len);
|
|
119
|
+
put(packet, 44, prepared_count);
|
|
120
|
+
var line_header: [512]u8 = @splat(0);
|
|
121
|
+
for (query.prepared, 0..) |line, i| {
|
|
122
|
+
run.writeLine(&line_header, line);
|
|
123
|
+
@memcpy(packet[source_len + i * 64 ..][0..56], line_header[320..376]);
|
|
124
|
+
}
|
|
125
|
+
var result: [1024]u8 = undefined;
|
|
126
|
+
var calls: usize = 0;
|
|
127
|
+
const quota = std.math.mul(usize, total, 32) catch @panic("text query continuation range");
|
|
128
|
+
while (true) {
|
|
129
|
+
calls += 1;
|
|
130
|
+
if (calls > quota) @panic("text query did not finish");
|
|
131
|
+
@memset(&result, 0xa5);
|
|
132
|
+
if (policy(packet, &result) != result.len or !resultValid(packet, &result)) @panic("invalid text query continuation");
|
|
133
|
+
if (result[3] == 2) break;
|
|
134
|
+
const action = word(&result, 80);
|
|
135
|
+
const slot = word(&result, 84);
|
|
136
|
+
@memcpy(packet[0..1024], &result);
|
|
137
|
+
switch (action) {
|
|
138
|
+
1 => run.supplyCapability(packet, packet[512..1024], 1024, text, options),
|
|
139
|
+
2 => {
|
|
140
|
+
@memcpy(line_header[320..376], packet[128..184]);
|
|
141
|
+
query.lines[slot] = run.readLine(&line_header);
|
|
142
|
+
},
|
|
143
|
+
3 => @memcpy(packet[source_len + slot * 64 ..][0..56], packet[128..184]),
|
|
144
|
+
4 => query.selections[slot] = .{ .range = .{ .start = word(packet, 320), .end = word(packet, 324) }, .rect = readRect(packet, 328) },
|
|
145
|
+
else => unreachable,
|
|
146
|
+
}
|
|
147
|
+
put(packet, 92, 1);
|
|
148
|
+
}
|
|
149
|
+
const present = word(&result, 272) != 0;
|
|
150
|
+
return .{
|
|
151
|
+
.bounds = if (present) readRect(&result, 256) else null,
|
|
152
|
+
.position = if (present and (query.mode == 4 or query.mode == 7)) .{ .offset = word(&result, 304), .affinity = @enumFromInt(word(&result, 308)) } else null,
|
|
153
|
+
.len = word(&result, 124),
|
|
154
|
+
.line_capacity_failed = word(&result, 312) != 0,
|
|
155
|
+
};
|
|
156
|
+
}
|