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.
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.
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));
For a full illustration of the editor CSS customization, you can refer to this example:
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();
});
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.
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.
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';
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'}
For a full illustration of the styling approaches listed above, you can refer to this example:
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.
The following restrictions apply:
h1
, p
or div
are not supported).mm
and properties provided with an explicit unit will be ignored.inherit
, initial
or unset
are not supported.*
) is not supported, neither are combinators.MyScript iink SDK exposes the following type hierarchy:
ink
- Groups all the types described below:stroke
- Handwritten strokes onlyglyph
- Converted text glyphsline
- Converted lines, obtained for instance when converting a diagramarc
- Converted elliptical arcs, ellipses and circlesguide
- The text guidesThe full reference of supported classes and properties can be found here.