Skip to content

JS library for creating text in SVG, Canvas and possibly other formats in the future.

License

Notifications You must be signed in to change notification settings

ariutta/cross-platform-text

Repository files navigation

cross-platform-text

JS library for creating text in SVG, Canvas and possibly other formats in the future. Handles both single- and multi-line text.

Usage

  1. Create Instance
var myInstance1 = crossPlatformText.getInstance({
  targetSelector:'#my-svg1', // (CSS selector) required
  format: 'svg' // ('svg' or 'canvas') required if 'targetSelector' does not reference an SVG or Canvas element
});

targetSelector references an SVG, Canvas or HTML element (such as a div). If it references an HTML element, the library will create a new SVG or Canvas element inside the HTML element, as specified by format.

For an existing SVG, the library will look for a g element with the class viewport. If it does not exist, the library will create it.

  1. Render text
var myText1 = myInstance1.render({
    x:50, // (px) required
    y:200, // (px) required
    width:100, // (px) required
    height:20, // (px) required
    textContent:'My text\nhas two lines' // (string) required
  });

API

Supported arguments for render(arguments):

About

JS library for creating text in SVG, Canvas and possibly other formats in the future.

Resources

License

Stars

Watchers

Forks

Packages

No packages published