Canvas Test Js

Canvas Test Js

by fulviocanducci

HTML

<script src="https://unpkg.com/smooth-signature/dist/index.umd.min.js"></script>
<canvas id="ca"></canvas>
<button type="button" onClick="verificar()">
Verificar se tem assinatura
</button>
<button type="button" onClick="limpar()">Limpar</button>
<button type="button" onClick="rotativa()">rotativa</button>

JavaScript

////signature.getPNG()
////signature.getJPG()
////signature.clear()
////signature.undo()
////signature.isEmpty()
////signature.getRotateCanvas(90)
function optionsSignature() {
  this.options = {
    width: 1000,
    height: 600,
    scale: 2,
    minWidth: 4,
    maxWidth: 10,
    color: '#333333',
    bgColor: '#C3C3C3'
  };
  this.setWidth = function (value) {
    this.options.width = value;
    return this;
  };
  this.setHeight = function (value) {
    this.options.height = value;
    return this;
  };
  this.setScale = function (value) {
    this.options.scale = value;
    return this;
  };
  this.setMinWidth = function (value) {
    this.options.minWidth = value;
    return this;
  };
  this.setMaxWidth = function (value) {
    this.options.maxWidth = value;
    return this;
  };
  this.setColor = function (value) {
    this.options.color = value;
    return this;
  };
  this.setBgColor = function (value) {
    this.options.bgColor = value;
    return this;
  };
  this.getOptions = function () {
    return this.options;
  };
}
function createSignature(id, options = {
  width: 1000,
  height: 600,
  scale: 2,
  minWidth: 4,
  maxWidth: 10,
  color: '#1890ff',
  bgColor: '#efefef'
})
{
  this.options = options;
  this.signature = null;
  this.getOptions = function () {
    return this.options;
  }
  this.clear = function() {
  	if (this.signature) {
  		return this.signature.clear();
    }
    throw new Error("No signature");
  }
  this.getSignature = function () {
    if (this.signature === null) {
      this.render();
    }
    return this.signature;
  }
  this.getBase64PNG = function () {
    let data = this.getSignature().getPNG();
    return data.substring(data.indexOf(",") + 1, data.length)
  }
  this.getBase64JPG = function (quality) {
    let data = this.getSignature().getJPG(quality);
    return data.substring(data.indexOf(",") + 1, data.length)
  }
  this.render = function () {
    try {
      this.signature = new...