MyScript iink SDK makes it easy to style content. In this part of the guide, you will learn how to set a theme and how you can change the color of the pen at any time.

This page focuses on server-based rendering and styling, so on REST and onscreen Websockets.

With offscreen Websockets, all rendering and styling are performed by the client, refer to OffScreen interactivity page.

Browser styling vs Server styling

As the recognition logic is held by the server, the exact same representation is held on it. It means that the position of strokes and fonts should be the same on the client and the server.

As a consequence of this architecture, size and background of editor can be styled with CSS, but you have to use JavaScript API to configure the inside content of the document.

Browser styling, Loader, boundaries and background

You can use regular CSS to configure the size and the background and your editor.

You can do this with a custom CSS class that overrides the default cssClass in the options that you use to create your editor, as shown below:

Example:

<link rel="stylesheet" href="../assets/my-custom-classes.css" />
      ...
async function loadEditor() {
  const options = {
    configuration: {
          ...
      },
    override: {
      cssClass: "my-custom-class"
    }
  };

  editor = await iink.Editor.load(editorElement, "INTERACTIVEINKSSR", options);
};

loadEditor().catch(error => console.error(error));
Be aware that CSS zoom properties will break the stroke capture and can not be used.

For a full illustration of the editor CSS customization, you can refer to this example:

View demo Get source code

Resizing

As the editor is built with different DOM elements, including canvas and SVG elements, its size does not adapt immediately when the window size changes, plus the server has to be notified of the exact size of the editor. You have to listen to the resize event and call the resize() method of the editor every time the event fires.

window.addEventListener('resize', () => {
    editorElement.editor.resize();
  });

Setting a theme

The next sections are all about server styling

A theme is a style sheet that influences the look & feel of the content rendered by a particular editor object.

The style sheet shall be passed as a string to the theme attribute of the options of the editor object. For example, to set the default ink color to blue for the current editor, you can write:

const options = {
  configuration: {
    theme: {
      ink: {
            color: "#ffffff"
      }
    }
  }
  };

  editor = await iink.Editor.load(editorElement, "INTERACTIVEINKSSR", options);

MyScript iink SDK comes with a built-in default theme. Values defined by the provided style sheet will have a higher priority and override the default style.

See the full styling reference for more information about available styling options.

Changing the style of the pen

It is possible to set the style associated with the pen, for example to change its color or its thickness. This is useful when providing end users with a color palette or when letting them define the characteristics of the pen tool.

There are two possible approaches: via the theme or by setting dynamic styles.

Via the theme

The theming approach consists in specifying classes corresponding to the different pen configurations in the custom theme and in applying a given style to the pen tool by setting the penStyleClasses attribute of the editor.

This approach is the most efficient one, and is better suited when users are provided with a fixed set of choices. It will however be dependent of the theme and thus not stored within the content part.

Example:

editor.theme = {'ink':{'color':'#FFFFFF','-myscript-pen-width':2},'.text':{'font-size':12},'.greenThickPen':{'color':'#00FF00','-myscript-pen-width':3}};
editor.penStyleClasses = 'greenThickPen';

Via dynamic styles

This approach consists in directly setting the style of the pen tool by setting the penStyle attribute of the editor.

It is less optimal in terms of processing time than the theming approach. However, it makes it easy to dynamically create styles (for instance if you let your users build their own color palettes) and will be saved within the content part.

Example:

editor.penStyle = {'color':'#44cec8','-myscript-pen-width':'1'}

Customized styling example

For a full illustration of the styling approaches listed above, you can refer to this example:

View demo Get source code
While it is possible to update the overall look & feel of the content by setting a theme at any time, iink SDK does not currently offer the possibility to specifically modify a posteriori the style of a selection of elements. This is expected to land in a future version.

iink SDK CSS specificities

Cascading Style Sheets (CSS) are a very common way to declaratively style content, for instance on the Web. MyScript iink SDK only relies on a subset of CSS for styling, with a few specificities to keep in mind.

Restrictions

The following restrictions apply:

CSS types

MyScript iink SDK exposes the following type hierarchy:

Built-in classes and properties

The full reference of supported classes and properties can be found here.