モジュール

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.

ジオメトリ

Geometry モジュールは、プリミティブ シェイプ(BoxVec などの専用クラスを使用)と任意のシェイプ(PartitionedMesh を使用)に対する幾何学的演算をサポートしています。これには、交差検出と変換が含まれます。PartitionedMesh は、レンダリングをサポートするための追加データを保持することもできます。

ブラシ

brush モジュールはストロークのスタイルを定義します。主に次の 2 つの部分で構成されています。

  • Brush: ベースカラー、ベースサイズ、BrushFamily など、ストロークのスタイルを指定します。BrushFamily はフォント ファミリーに似ており、ストロークのスタイルを定義します。たとえば、BrushFamily は特定のスタイルのマーカーやハイライトを表すことができ、サイズや色の異なるストロークがそのスタイルを共有できます。
  • StockBrushes: すぐに使用できる BrushFamily インスタンスを作成するためのファクトリ関数を提供します。

オーサリング

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 にインク ストロークを簡単に描画できます。Compose 用の 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.