ماژول ها

Ink API ماژولار است، بنابراین می‌توانید فقط از آنچه نیاز دارید استفاده کنید.

سکته مغزی

The strokes module serves as the foundation of the Ink API. Key data types within this module are:

  • StrokeInputBatch: Represents a series of pointer inputs, including their position, timestamp, and optionally pressure, tilt, and orientation.
  • InProgressStroke: Represents a stroke that is actively being drawn. InProgressStroke is used to render partial strokes with low latency and to build the final Stroke once input is complete, after which the object can be reused. InProgressStroke is used by the InProgressStrokes composable.
  • Stroke: An immutable representation of a finalized stroke with fixed geometry. Each Stroke has an ImmutableStrokeInputBatch (input points), a Brush (style), and a PartitionedMesh (geometric shape). You can store, manipulate, and render strokes within your application.

هندسه

The Geometry module supports geometric operations on primitive shapes (using dedicated classes like Box and Vec), as well as arbitrary shapes (using PartitionedMesh), including intersection detection and transformation. PartitionedMesh can also hold additional data to support rendering.

برس

ماژول brush سبک خطوط را تعریف می‌کند و از دو بخش اصلی تشکیل شده است:

  • Brush : سبک یک خط شامل رنگ پایه، اندازه پایه و BrushFamily را مشخص می‌کند. BrushFamily مشابه خانواده فونت است و سبک یک خط را تعریف می‌کند. برای مثال، یک BrushFamily می‌تواند یک سبک خاص از ماژیک یا هایلایتر را نشان دهد و به خطوط با اندازه‌ها و رنگ‌های مختلف اجازه می‌دهد تا آن سبک را به اشتراک بگذارند.
  • StockBrushes : توابع کارخانه‌ای برای ایجاد نمونه‌های آماده برای استفاده BrushFamily را فراهم می‌کند.

تألیف

ماژول Compose Authoring به شما امکان می‌دهد ورودی لمسی کاربر را ضبط کرده و آن را به صورت حرکات لمسی با تأخیر کم روی صفحه نمایش به صورت بلادرنگ رندر کنید. این امر از طریق Composable InProgressStrokes محقق می‌شود که رویدادهای حرکتی را پردازش کرده و حرکات لمسی را هنگام ترسیم نمایش می‌دهد.

پس از تکمیل یک stroke، composable با استفاده از فراخوانی InProgressStrokesFinishedListener به برنامه کلاینت اطلاع می‌دهد. این به برنامه اجازه می‌دهد تا stroke های تکمیل شده را برای رندر یا ذخیره سازی بازیابی کند.

در Compose، InProgressStrokes این فراخوانی را در پارامتر onStrokesFinished دریافت می‌کند. stroke های تکمیل شده را به یک composable دیگر منتقل کنید تا با استفاده از ماژول رندر ، آنها را به صفحه نمایش اعمال کند.

رندرینگ

ماژول Rendering، ترسیم خطوط جوهر روی Canvas اندروید را ساده می‌کند. این CanvasStrokeRenderer را برای Compose و ViewStrokeRenderer را برای طرح‌بندی‌های مبتنی بر نما فراهم می‌کند. این رندرکننده‌ها عملکرد رندر را بهینه کرده و به ارائه تصاویر با کیفیت بالا، از جمله ضد لبه‌سازی، کمک می‌کنند.

برای رندر کردن strokeها، متد create() را برای دریافت یک نمونه CanvasStrokeRenderer فراخوانی کنید، و سپس متد draw() را برای رندر strokeهای تکمیل‌شده ( Stroke ) یا در حال انجام ( InProgressStroke ) روی یک Canvas فراخوانی کنید.

شما می‌توانید هنگام رسم یک stroke، بوم را تغییر شکل دهید. مثال‌ها شامل panning، zooming و rotation می‌شود. برای رندر صحیح stroke، باید transform canvas را به CanvasStrokeRenderer.draw نیز ارسال کنید.

برای جلوگیری از ردیابی جداگانه‌ی تبدیل canvas ، به جای آن ViewStrokeRenderer استفاده کنید.

ذخیره‌سازی

The storage module provides utilities for efficiently serializing and deserializing stroke data, primarily focusing on StrokeInputBatch.

The module uses protocol buffers and optimized delta compression techniques, resulting in significant storage savings compared to naive methods.

The storage module simplifies saving, loading, and sharing strokes.