npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

canvas-text-wrapper-new

v0.11.0

Published

Split canvas text into lines on specified rule with optional alignment, padding, and more. Supports HDPI screens.

Downloads

26

Readme

canvas-text-wrapper

Syntax

CanvasTextWrapper(HTMLCanvasElement, String [, options]);

Options

| Option | Value | Description | | ------------- | ------------- | ------------- | | font | String | Text style that includes font size (in px), font weight, font family, etc. | | lineHeight | String or Number | Number - 'n' times font size where 1 is equivalent to '100%'. Also the property can be set in '%' or 'px'. | | textAlign | "left" "center" "right" | Horizontal alignment of each line. | | verticalAlign | "top" "middle" "bottom" | Vertical alignment of the whole text block. | | paddingX | Number | Horizontal padding (in px) that is equally set on left and right sides. | | paddingY | Number | Vertical padding (in px) that is equally set on top and bottoms. | | offsetX | Number | Horizontal offset (in px) that is set on left side. | | offsetY | Number | Vertical offset (in px) that is set on top. | | maxWidth | Number | Limit the width (in px) of the text box. 0 means no limit | | fitParent | Boolean | Fit canvas' container size instead of its own size. | | lineBreak | "auto" "word" | "auto" - text goes to the next line on a whole word when there's no room "word" - each next word is placed on a new line | | sizeToFill | Boolean | Ignore given font size and line height and resize text to fill its padded container. | | maxFontSizeToFill | Number | If above option is true text won't be bigger than set. | | strokeText | Boolean | Allow text outline based on canvas context configuration. | | justifyLines | Boolean | All lines will try to match the same width with flexed spaces between the words. | | allowNewLine | Boolean | Text breaks on a new line character "\n". Supports multiple consecutive new lines. | | renderHDPI | Boolean | Text is rendered based on device pixel ratio. | | textDecoration | "none" "underline" | Text is underlined according to context.strokeStyle and context.lineWidth |

NOTE: if a single word is too long to fit the width with specified font size, it will break on any letter unless sizeToFill option is enabled.

Default options

   {
        font: '18px Arial, sans-serif',
        lineHeight: 1,
        textAlign: 'left',
        verticalAlign: 'top',
        paddingX: 0,
        paddingY: 0,
        offsetX: 0,
        offsetY: 0,
        maxWidth: 0,
        fitParent: false,
        lineBreak: 'auto',
        strokeText: false
        sizeToFill: false,
        maxFontSizeToFill: false,
        allowNewLine: true,
        justifyLines: false,
        renderHDPI: true,
        textDecoration: 'none'
    }

Usage

Configure context properties such as fillStyle, lineWidth, strokeStyle etc. before passing it to CanvasTextWrapper like so:

var CanvasTextWrapper = require('canvas-text-wrapper').CanvasTextWrapper;

var canvas = document.getElementById('#canvasText');
canvas.width = 200;
canvas.height = 200;
context = canvas.getContext('2d');
context.lineWidth = 2;
context.strokeStyle = '#ff0000';

CanvasTextWrapper(canvas, 'Hello', {strokeText: true});

Test

Run npm t NOTE: Test requires beefy to be installed globally

Examples

see here

Install

npm i canvas-text-wrapper --save
bower install canvas-text-wrapper