मॉड्यूल

Ink API को मॉड्यूलर बनाया गया है, ताकि आप सिर्फ़ उन सुविधाओं का इस्तेमाल कर सकें जिनकी आपको ज़रूरत है.

स्ट्रोक

स्ट्रोक मॉड्यूल, Ink API का आधार है. इस मॉड्यूल में, मुख्य डेटा टाइप ये हैं:

  • StrokeInputBatch: यह पॉइंटर इनपुट की सीरीज़ को दिखाता है. इसमें उनकी पोज़िशन, टाइमस्टैंप, और ज़रूरत के मुताबिक दबाव, झुकाव, और ओरिएंटेशन शामिल होता है.
  • InProgressStroke: इससे ऐसे स्ट्रोक के बारे में पता चलता है जिसे अभी बनाया जा रहा है. InProgressStroke का इस्तेमाल, कम समय में कुछ स्ट्रोक रेंडर करने के लिए किया जाता है. साथ ही, इनपुट पूरा होने के बाद फ़ाइनल Stroke बनाने के लिए किया जाता है. इसके बाद, ऑब्जेक्ट का फिर से इस्तेमाल किया जा सकता है. InProgressStroke का इस्तेमाल InProgressStrokes कंपोज़ेबल करता है.
  • Stroke: यह फ़ाइनल किए गए स्ट्रोक का ऐसा वर्शन होता है जिसे बदला नहीं जा सकता. इसमें तय की गई जियोमेट्री होती है. हर Stroke में ImmutableStrokeInputBatch (इनपुट पॉइंट), Brush (स्टाइल), और PartitionedMesh (ज्यामितीय आकार) होता है. अपने ऐप्लिकेशन में स्ट्रोक सेव किए जा सकते हैं, उनमें बदलाव किया जा सकता है, और उन्हें रेंडर किया जा सकता है.

रेखागणित

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.

ब्रश

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.

रेंडरिंग

रेंडरिंग मॉड्यूल की मदद से, Android Canvas पर इंक स्ट्रोक आसानी से बनाए जा सकते हैं. यह कंपोज़ के लिए CanvasStrokeRenderer और व्यू के आधार पर लेआउट के लिए 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.