[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: fabric.js свой шрифт
Kusss
Нажимаю кнопку "Добавить" - текст добавляется но с каким-то дефолтовым шрифтом, при повторном добавлении шрифт принимается.
Кода много конечно, но помогите разобраться
<style>
@font-face
{
font-family: gillsans;
src: url('/overlay/font/gillsans.ttf');
url('/overlay/font/gillsans.eot');
}
</style>
<input
type="hidden" class="fontSize" name="fontSize" value="256">
<input
type="hidden" class="fontFamily" name="fontFamily" value="gillsans">
<input
type="hidden" class="heightText" name="heightText" value="1500">
<input
type="hidden" class="toUpperCase" name="toUpperCase" value="0">

<div
class="main_view" style="position:absolute; left:127.572px; top:131.132px;">
<canvas
id="paint1" width="267px" height="399px"></canvas>
</div>
<div
class="main_view" style="position:absolute; left:127.572px; top:131.132px;">
<canvas
id="paint2" width="267px" height="399px"></canvas>
</div>


<input
type="text" class="b-input__field input_text" placeholder="Надпись" maxlength="12">
<br>
<input
type="button" class="main_str_add" value="Добавить">

var $canvas = []
i = 0;
$('.main_view canvas').each( function(i){
var id = $(this).attr('id')
$id = new fabric.Canvas(id);
$canvas[i] = $id;
i++;
});

$(document).ready(function(){
$('.main_str_add').on('click', function(){
var canvasMaxWidth = $('.main_view canvas').first().width(),
scale = canvasMaxWidth/2000,
center_left = (canvasMaxWidth)/2,
text_obj = [],
center_top = $('.heightText').val()*scale;


text_obj['text'] = $('.input_text').val();
text_obj['fontFamily'] = $('.fontFamily').val();
text_obj['fontSize'] = $('.fontSize').val()*scale;

addText(text_obj, center_left, center_top);
});
});

// Добавляем текст
function addText(text_obj, center_left, center_top) {
var textSample = new fabric.Text(text_obj['text'], {
left: center_left,
top: center_top,
fontFamily: text_obj['fontFamily'],
fontSize: text_obj['fontSize'],
lineHeight: 1,
textAlign: 'center',
scale: 1,
angle: '',
fill: 'black',
fontWeight: '',
originX: 'center',
hasRotatingPoint: true,
centerTransform: true,
lockMovementX: 'false',
lockMovementY: 'false',
lockRotation: 'false',
hasControls: 0,
});

$.each( $canvas , function(key, value){
value.clear();
value.add(textSample);
value.renderAll();
});
}
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.