D
D
denisss122016-01-26 18:59:37
JavaScript
denisss12, 2016-01-26 18:59:37

How to reset the canvas transformation?

Hello.
There is a task:
66d3b2a3e25c41fcb1be0945b4b38edc.png
Adjust the width of the input text to the size of the Canvas. Not the font size, but the width. The first thing that came to mind was to use ctx.scale:

$('#edit-line-item-fields-field-case-name-und-0-value').keyup(function(){ 
   var case_text=$(this).val().toUpperCase();
   var main = $(this).val().length;
   var scale_number = (6/main);
//По-умолчанию, в тексте 6 букв. Делим 6 на кол-во символов. Получаем коэффициент трансформации.
   ctx.clearRect(0, 0, canvas.width, canvas.height);
   ctx.scale(scale_number,1);
   ctx.fillText(case_text,10, 78);
});

The first letter is great. But, when we continue to enter and apply the coefficient, the value only increases.
Is it possible to somehow reset the value of ctx.scale?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question