This page introduces the role of the Editor
object, the central point to interact with content.
An Editor
is the main entry point to act on interactive content.
It is responsible for building and updating a content model from users’ input events and/or edition commands.
It is instantiated from an Engine
:
// Create an editor
var editor = engine.CreateEditor(renderer, toolController);
The ToolController argument is optional. If you omit it, the editor will instantiate a ToolController with the default settings.
EditorUserControl
will create the editor automatically for you.
While iink SDK can be globally configured at engine level, it is possible to override this configuration at editor level. This is particularly useful in form-like use cases, where you need to manipulate fields with different configurations.
You can access the configuration of a specific editor via the Configuration
property and set the values of the keys that should override the global
configuration, in a cascade-like manner. Values of the keys you do not explicitly set at editor-level still follow engine-level configuration.
For example:
var globalConfig = engine.Configuration;
var editorConfig = editor.Configuration;
// Global configuration values apply ...
var globalUnit = globalConfig.GetString("math.solver.angle-unit"); // -> "deg"
var editorUnit = editorConfig.GetString("math.solver.angle-unit"); // -> "deg"
globalConfig.SetString("math.solver.angle-unit", "rad");
globalUnit = globalConfig.GetString("math.solver.angle-unit"); // -> "rad"
editorUnit = editorConfig.GetString("math.solver.angle-unit"); // -> "rad"
// ... except if overridden at editor level
editorConfig.SetNumber("math.solver.fractional-part-digits", 4);
globalConfig.SetNumber("math.solver.fractional-part-digits", 2);
var editorDigits = editorConfig.GetNumber("math.solver.fractional-part-digits"); // -> 4
var globalDigits = globalConfig.GetNumber("math.solver.fractional-part-digits"); // -> 2
text.configuration.bundle
and text.configuration.name
behave in a particular way, in that they are only
considered the very first time a given part is set to an editor and cannot be changed afterwards.
An Editor
works on a ContentPart
.
To setup the link between them, call the editor’s Part
property and pass it the part you opened or created:
// Create a new package
var package = engine.CreatePackage("newPackage.iink");
// Create a new part
var part = package.CreatePart("Text");
// Associate editor with the new part
editor.Part = part;
SetViewSize()
on the editor and attached to it a font metrics provider
before setting the part. If you use the reference implementation, the EditorUserControl
will do it automatically for you.
Text Document and Text parts have guides set by default. Guides provide useful hints for end users to know where to write and at what size. They also improve the recognition accuracy, provided that handwriting uses them as baselines.
You can enable or disable the guides of a Text part via the text.guides.enable
key of the engine or
editor configuration. The vertical spacing between guides can be tuned via the text styling options.
You are in charge of capturing the input events. This section gives you some hints on how to transmit the captured inputs to the editor.
MyScript iink SDK typically processes user input in real time. You thus have to tell how pointers are interacting with the capture surface (typically a screen or a graphical tablet).
This can be done by calling the following methods of the Editor
object:
PointerDown()
- When the pointer first touches the surface.PointerMove()
- When the pointer moves while staying in contact with the surface.PointerUp()
- When the pointer is lifted from the surface.Each of these methods requires you to provide:
x
and y
- The coordinates in pixels of the pointer on the surface.t
- The timestamp of the pointer eventf
- The pressure information associated to the event (normalized between 0 and 1)
pointerType
- The type of pointer: see the PointerType
pointerId
- An identifier for this pointer.Example:
editor.PointerDown(0.0f, 0.0f, CurrentTime(), .7f, PointerType.PEN, 1);
editor.PointerMove(2.0f, 2.0f, CurrentTime(), .6f, PointerType.PEN, 1);
editor.PointerUp(2.0f, 4.0f, CurrentTime(), .5f, PointerType.PEN, 1);
PointerCancel()
to have the editor drop and ignore an ongoing event sequence.
Remarks:
PEN
tool, iink SDK triggers the recognition, with the SELECTOR
tool iink SDK determines a selection, etc.In the most simple case, you can write something like:
const long NO_TIMESTAMP = -1;
const float NO_PRESSURE = 0.0f;
const int NO_POINTER_ID = -1;
editor.PointerDown(0.0f, 0.0f, NO_TIMESTAMP, NO_PRESSURE, PointerType.PEN, NO_POINTER_ID);
editor.PointerMove(2.0f, 2.0f, NO_TIMESTAMP, NO_PRESSURE, PointerType.PEN, NO_POINTER_ID);
editor.PointerUp(2.0f, 4.0f, NO_TIMESTAMP, NO_PRESSURE, PointerType.PEN, NO_POINTER_ID);
In some cases, you may want to send a set of strokes to the engine in a single pass, for instance if you import ink from outside of the iink model that you want to process as a single batch.
For all types of parts but “Text Document”, iink SDK provides a method to input in a single pass a series of pointer events, PointerEvents()
,
that take in parameter an array of PointerEvent
objects.
Here is an example:
// Build the pointer events array
PointerEvent[] events = new PointerEvent[]
{
// Stroke 1
new PointerEvent().Down(184, 124),
new PointerEvent().Move(184, 125),
new PointerEvent().Move(184, 128),
new PointerEvent().Move(184, 133),
new PointerEvent().Move(184, 152),
new PointerEvent().Move(184, 158),
new PointerEvent().Move(184, 163),
new PointerEvent().Move(183, 167),
new PointerEvent().Move(183, 174),
new PointerEvent().Move(183, 183),
new PointerEvent().Up(183, 184),
// Stroke 2
new PointerEvent().Down(150, 126),
new PointerEvent().Move(151, 126),
new PointerEvent().Move(152, 126),
new PointerEvent().Move(158, 126),
new PointerEvent().Move(166, 126),
new PointerEvent().Move(184, 126),
new PointerEvent().Move(190, 128),
new PointerEvent().Move(196, 128),
new PointerEvent().Move(200, 128),
new PointerEvent().Move(207, 128),
new PointerEvent().Move(208, 128),
new PointerEvent().Up(209, 128)
};
// Feed the editor
editor.PointerEvents(events, false);
PointerEvents()
to process a large quantity of strokes, you should set the processGestures
parameter to false
to
explicitly prevent gesture detection and allow better performances.
For the particular case of “Text Document” parts, you should:
waitForIdle()
to ensure that the recognition is complete.MyScript iink SDK supports all the standard gestures defined as part of Interactive Ink.
There is nothing particular to do to benefit from gestures when using the PEN
tool. The SDK will take care of detecting and applying the effect of the gestures from the provided input
without any plumbing needed.
Decorations can be styled and will be taken into account when generating some of the export formats (ex: text underlining will be
ignored for a simple text export, will turn bold in the case of a docx
export and be semantically tagged in a jiix
export).
The following operations can be directly made on the content of a part via an Editor
object:
Most operations, however, are to be done on content blocks.
The UI Reference Implementation comes with a “smart guide” component that lets you provide real-time text recognition feedback to your end users and allows them to select alternative interpretations from the engine.
Refer to the page describing how to work with text recognition candidates for more information.
Sometimes, the block extraction or segmentation does not work properly, leading to a frustrating user experience with some ink recognized as text instead of shape, or shape as drawing, etc.
In order to cope with such a situation, the lasso selector can be used to select some content, and then force
the selected content to be recognized as a specific type and/or grouped with the editor SetSelectionType()
.
The list of possible types is provided by the GetAvailableSelectionTypes()
method.
There are cases where it makes sense to be notified of what occurs in the model. For instance, you may want to update the states of the undo/redo buttons of your interface or only permit an export when there is something to export.
You can call AddListener()
and RemoveListener()
to respectively attach and remove an object of your choice that implements the IEditorListener
interface:
the interface has several methods that let you know when any change occurs within the model.
IEditorListener
also provides an OnError()
method that you can implement to be notified when anything goes wrong. It
is strongly recommended to implement it, as it allows detecting some frequently seen issues such as recognition assets or configurations not
found by the engine.
In addition, the Editor
class provides other useful methods/properties, such as:
IsIdle()
- Returns true
if any ongoing processing by the engine is overWaitForIdle()
- Blocks your thread until the engine is idle. It allows waiting for recognition to be complete before exporting, converting or
manipulating the content.IsIdle()
will always return false
in a ContentChanged()
notification.
WaitForIdle()
from inside an IEditorListener
notification.
You previously created an Editor
object.
As you rely on the reference rendering implementation provided by MyScript, ink input will be transparently managed by the
EditorUserControl
. All you have to do is to load the part into the editor at the end of the OpenContent()
method you previously wrote:
public void OpenContent()
{
// Select the package and part to use
...
// Associate the part with the editor
editor.Part = part;
}
If you launch the app, you can now write in it and see actual ink being rendered!
Next, you will plug the undo, redo and clear buttons.
This can be conveniently done by calling the appropriate Editor
methods in reaction to user actions:
public void Undo()
{
editor.Undo();
}
public void Redo()
{
editor.Redo();
}
public void Clear()
{
editor.Clear();
}
As a “Math” part consists of a single root block, you will be able to convert it very easily. This will be the topic of the next step of this guide!