وحدات

تم تقسيم Ink API إلى وحدات، ما يتيح لك استخدام ما تحتاج إليه فقط.

الضربات

يشكّل وحدة الضربات الأساس الذي تستند إليه Ink API. تشمل أنواع البيانات الرئيسية ضمن هذه الوحدة ما يلي:

  • StrokeInputBatch: تمثّل هذه السمة سلسلة من إدخالات المؤشر، بما في ذلك موضعها وطابعها الزمني، ويمكن أن تتضمّن أيضًا الضغط والإمالة والاتجاه.
  • InProgressStroke: تمثّل ضربة يتم رسمها حاليًا. يتم استخدام InProgressStroke لعرض ضربات جزئية بزمن انتقال منخفض ولإنشاء Stroke النهائي بعد اكتمال الإدخال، وبعد ذلك يمكن إعادة استخدام العنصر. InProgressStroke من خلال الدالة البرمجية القابلة للإنشاء InProgressStrokes.
  • Stroke: تمثيل غير قابل للتغيير لضربة نهائية ذات شكل هندسي ثابت. يحتوي كل Stroke على ImmutableStrokeInputBatch (نقاط الإدخال) وBrush (النمط) وPartitionedMesh (الشكل الهندسي). يمكنك تخزين ضربات الفرشاة ومعالجتها وعرضها داخل تطبيقك.

هندسة

يتيح نموذج Geometry إجراء عمليات هندسية على الأشكال الأساسية (باستخدام فئات مخصّصة مثل Box وVec)، بالإضافة إلى الأشكال العشوائية (باستخدام PartitionedMesh)، بما في ذلك رصد التقاطع والتحويل. يمكن أن يحتوي PartitionedMesh أيضًا على بيانات إضافية للمساعدة في العرض.

فرشاة

The brush module defines the style of strokes. It consists of two main parts:

  • Brush: Specifies the style of a stroke including base color, base size, and BrushFamily. BrushFamily is analogous to a font family, it defines a stroke's style. For example, a BrushFamily can represent a specific style of marker or highlighter, allowing strokes with different sizes and colors to share that style.
  • StockBrushes: Provides factory functions for creating ready-to-use BrushFamily instances.

التأليف

The Compose Authoring module lets you capture user touch input and render it as low-latency strokes on the screen in real time. This is achieved through the InProgressStrokes composable, which processes motion events and displays the strokes as they are drawn.

Once a stroke is completed, the composable notifies the client application using an InProgressStrokesFinishedListener callback. This allows the application to retrieve the finished strokes for rendering or storage.

In Compose, InProgressStrokes takes this callback in the onStrokesFinished parameter. Pass the finished strokes to another composable to commit them to the screen using the rendering module.

العرض

تسهّل وحدة "العرض" رسم ضربات الحبر على Canvas يعمل بنظام التشغيل Android. توفّر هذه السمة CanvasStrokeRenderer لـ Compose وViewStrokeRenderer للتنسيقات المستندة إلى العرض. تعمل أدوات العرض هذه على تحسين أداء العرض وتساعد في تقديم صور عالية الجودة، بما في ذلك التنعيم.

لعرض ضربات الفرشاة، استدعِ طريقة create() للحصول على مثيل CanvasStrokeRenderer، ثم استدعِ طريقة draw() لعرض ضربات الفرشاة المكتملة (Stroke) أو الجاري تنفيذها (InProgressStroke) على Canvas.

يمكنك تغيير شكل لوحة العرض عند رسم خط. وتشمل الأمثلة تحريك الكاميرا أفقيًا أو عموديًا وتكبير الصورة وتدويرها. لعرض الضربة بشكل صحيح، يجب أيضًا تمرير عملية التحويل 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.