Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fabric js fontweight not working

I am using this code to add textbox in canvas using fabric js,

var text = 'Type Text Here';
var textSample = new fabric.Textbox(text, {
    left: getCardLeft() + 100,
    top: getCardTop() + 10,
    width: 200,
    height: 20,
    fontFamily: 'Helvetica',
    fill: getColorPickerForegroundColor(),
    fontWeight: '',
    fontSize: parseInt('25'),
    originX: 'center',
    hasRotatingPoint: true,
    centerTransform: true,
});
canvas.add(textSample);

Which successfully add textbox into canvas. Now, if i try to make it bold using this command

canvas.getActiveObject().set("fontWeight", "bold");
canvas.renderAll();

Working, But when try to change it to normal,

canvas.getActiveObject().set("fontWeight", "");
canvas.getActiveObject().set("fontWeight", "100");
canvas.getActiveObject().set("fontWeight", "normal");
canvas.renderAll();

not working.

I don't know where the issue is. Am i doing anything wrong here?.

Its behaving strange You can see it here.

visit first here Then visit here

like image 459
Himanshu Bhardiya Avatar asked Jan 20 '16 13:01

Himanshu Bhardiya


People also ask

How does fabric js work?

Fabric. js is based on HTML5 canvas, so just put a canvas object into an HTML file, with an id, and that's it. In the controller's AfterContentInit lifecycle hook (so the canvas was rendered inside the nice wrapper): this.

Who uses fabric js?

Who uses Fabric. js? 6 companies reportedly use Fabric. js in their tech stacks, including Ludus, MediaSolution, and Picomto.

Is fabric js open-source?

js is a Javascript HTML5 canvas library. It is a fully open-source project with many contributions over the years.

Why do we use fabric js?

Fabric provides a missing object model for canvas, as well as an SVG parser, layer of interactivity, and a whole suite of other indispensable tools. It is a fully open-source project, licensed under MIT, with many contributions over the years.


1 Answers

I just take fabric.js from here and replaced with mine, and working all.

like image 130
Himanshu Bhardiya Avatar answered Oct 12 '22 22:10

Himanshu Bhardiya