4Q-s-r-o / signature

Flutter plugin that creates a canvas for writing down a signature
MIT License
255 stars 85 forks source link

Auto-generate signature #53

Closed salihagic closed 1 year ago

salihagic commented 2 years ago

I would like to propose a feature for auto-generating the signature or prepopulating the SignaturePad's canvas by supplying an initial text.

Something like:

TextPainter _buildTextPainter(Size canvasSize) {
  //Determins the scale of the generated text so it
  //fits the most appropriatelly basen on it's length
  final defaultScaleCharWidth = 9.0;
  final maxCharacters = canvasSize.width / defaultScaleCharWidth;
  final initialTextScaleFactor = maxCharacters / text.length;
  final textScaleFactor = (initialTextScaleFactor == 0 ? 1 : initialTextScaleFactor) * 0.8;

  //Define text style, maybe later add custom font that's more appropriate for a signature...
  final span = TextSpan(
    text: text,
    style: const TextStyle(color: Colors.black, fontStyle: FontStyle.italic),
  );

  //Build the text painter to compute all the
  //points that are required to render the text on canvas
  final textPainter = TextPainter(
    text: span,
    textAlign: TextAlign.left,
    textDirection: painting.TextDirection.ltr,
    textScaleFactor: textScaleFactor,
  );

  textPainter.layout();

  return textPainter;
}

// ...

final textPainter = _buildTextPainter(size);

textPainter.paint(
  canvas,
  Offset(
    _horizontalOffset(size, textPainter),
    _verticalOffset(size, textPainter),
  ),
);
MartinHlavna commented 2 years ago

Hello,

what is the use case for this?

salihagic commented 2 years ago

Hi,

The use case would be to allow users to autogenerate signature based on their first name and last name that we have saved in our database so the user would have this shortcut for auto-generating the signature. Some custom font could be inserted so it would look more signature-like.

I know it goes against the very basic logic of having the signature(eg. it should come from manually writting it by the user) but that's debatable if you consider that in a heavy use of this feature some users would prefer to not need to manually write it every time. Something like a stamp that companies use or politicians when they write a letter.

MartinHlavna commented 2 years ago

We will think about ways to implement this.

Be aware of legislative challenges thought. I would personally double check (maybe even consult with lawyer) if something like this is okay in terms of law if you need to use signature for some legal signatures.

Maybe instead of initialText, there could be method in controller for this. If you would really want to pre-fill signature you could call this method in initState, but it would also open possibility for having button that user needs to click in order to auto-fill signature.

madsane29 commented 2 years ago

I mean, if something like this get implemented, might just rename the package to something like "paint_on_canvas" :-] Feels like something like this would go against everything what a "signature" does stand for. But obviously it is your package.

ethael commented 1 year ago

this idea is going beyond the scope of this plugin. it would start to move towards something like a simple drawing canvas. we would like to keep the KISS principle in place here and do only one thing and do it well.

vagadiyainfotech commented 1 year ago

Hello @salihagic Can you please explain more or share some part of missing code.