How to use the signature_pad.prototype function in signature_pad

To help you get started, we’ve selected a few signature_pad examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enketo / enketo-core / src / widget / draw / draw-widget.js View on Github external
import dialog from 'enketo/dialog';
import { updateDownloadLink, dataUriToBlobSync, getFilename } from '../../js/utils';
const DELAY = 1500;

/**
 * SignaturePad.prototype.fromDataURL is asynchronous and does not return
 * a Promise. This is a rewrite returning a promise and the objectUrl.
 * In addition it also fixes a bug where a loaded image is stretched to fit
 * the canvas.
 *
 * @function external:SignaturePad#fromObjectURL
 * @param {*} objectUrl
 * @param {*} options
 * @return {Promise}
 */
SignaturePad.prototype.fromObjectURL = function( objectUrl, options ) {
    const image = new Image();
    options = options || {};
    const deviceRatio = options.ratio || window.devicePixelRatio || 1;
    const width = options.width || ( this._canvas.width / deviceRatio );
    const height = options.height || ( this._canvas.height / deviceRatio );
    const that = this;

    this._reset();

    return new Promise( resolve => {
        image.src = objectUrl;
        image.onload = () => {
            const imgWidth = image.width;
            const imgHeight = image.height;
            const hRatio = width / imgWidth;
            const vRatio = height / imgHeight;
github enketo / enketo-core / src / widget / draw / draw-widget.js View on Github external
that._ctx.drawImage( image, left, top, imgWidth, imgHeight );
            }
            resolve( objectUrl );
        };
        that._isEmpty = false;
    } );
};

/**
 * Similar to SignaturePad.prototype.fromData except that it doesn't clear the canvas.
 * This is to facilitate undoing a drawing stroke over a background (bitmap) image.
 *
 * @function external:SignaturePad#updateData
 * @param {*} pointGroups
 */
SignaturePad.prototype.updateData = function( pointGroups ) {
    const that = this;
    this._fromData(
        pointGroups,
        ( curve, widths ) => { that._drawCurve( curve, widths.start, widths.end ); },
        rawPoint => { that._drawDot( rawPoint ); }
    );

    this._data = pointGroups;
};

/**
 * Widget to obtain user-provided drawings or signature.
 *
 * @extends Widget
 */
class DrawWidget extends Widget {

signature_pad

Library for drawing smooth signatures.

MIT
Latest version published 1 month ago

Package Health Score

83 / 100
Full package analysis

Similar packages