fabricjs

How to apply custom font in fabric text object?

梦想与她 提交于 2019-12-03 10:05:43
问题 I would like to use custom font in fabric text object, I followed the link below: http://fabricjs.com/fabric-intro-part-4/ But it seems that it's only supported in node.js. Is there any way to support it on simple fabric text object on canvas? 回答1: Use CSS: @font-face { font-family: myFirstFont; src: url('Sansation_Light.ttf'), url('Sansation_Light.eot'); /* IE9 */ } Create fabric text object instance : var object = new fabric.Text("NEW TEXT", { fontFamily: "myFirstFont", left: 150, top: 100,

FabricJs - How do I Add properties to each object

两盒软妹~` 提交于 2019-12-03 08:53:54
I need to introduce few additional properties to existing object properties set. like: ID Geo Location etc Whenever I draw a shape, I need to add additional properties to the shape and need to get from toDataLessJSON() As of version 1.7.0 levon's code stopped working. All you need to do is to fix as follows: // Save additional attributes in Serialization fabric.Object.prototype.toObject = (function (toObject) { return function (properties) { return fabric.util.object.extend(toObject.call(this, properties), { textID: this.textID }); }; })(fabric.Object.prototype.toObject); You have to receive

How to manage memory in case of multiple fabric js canvas?

纵然是瞬间 提交于 2019-12-03 08:38:04
In my application, I have multiple Fabric.js canvases, There is no limit on the number of canvases. I'll render heavy JSON via loadFromJson method of Fabric.js. So I want to release the fabric object memory if the canvas is not in use. How can I do that? At a time only one canvas will be visible. But I have to render all the canvases as the page loads. Canvas is actually a page and user can switch between pages via clicking on page number or something else. Remember user can come back to any canvas any time and try to doodle or use any other Fabric.js functionality. Here is my HTML structure:

Free drawing on canvas using fabric.js

元气小坏坏 提交于 2019-12-03 08:32:18
I am trying to draw a free drawing on canvas using fabric.js but i am not able to free draw a like spray, circle, texture mode on my side i use this code only the pencil mode drawing is working but when i select spray and other mode that mode drawing as pencil. Here is my HTML Here is fiddle ink <label for="drawing-mode-selector">Mode:</label> <select id="drawing-mode-selector"> <option>Pencil</option> <option>Circle</option> <option>Spray</option> <option>Pattern</option> <option>hline</option> <option>vline</option> <option>square</option> <option>diamond</option> <option>texture</option> <

Select All the objects on canvas using Fabric.js

China☆狼群 提交于 2019-12-03 08:31:44
问题 Is there a way to explicitly select all the objects present at a particular instance of time. This can be easily done using mouse to select all. Is there a code-solution like a button named Select All so that clicking it would make all the fabric type objects being selected and then I could apply the changes to whole of that ActiveGroup using canvas.getActiveGroup(); and iterate over. 回答1: Good question. There's no built-in method for this, but you would need to do something along these lines

How to make friends Fabric.js and Redux?

十年热恋 提交于 2019-12-03 07:55:04
问题 Is there any approach to use Fabric.js and Redux together? Fabric.js state should be used as part of store, but it isn't immutable and can mutate itself by user canvas interaction. Any idea? Thanks. 回答1: I have extracted small example from my implementation of React-Redux and Fabric.js. It works by simply getting whole fabric object by fabric.toObject(), saving it into state and revoking by fabric.loadFromJSON(). You can play around by using Redux DevTools and traveling through the state. For

Init loaded text with remote web font in Fabric.js

风格不统一 提交于 2019-12-03 07:18:50
I'm working on a big custom application with Fabric JS and I already did a great job. But I have a problem with init loaded text object that uses a webfont. As long as that font is local on the client's computer, I works fine, ELSE the webfont is NOT loaded and the text object on the canvas is rendered in a default sans-serif font-family. Here is, in short, what I do (in this example I use "allstar" as my webfont) : CSS: The css is loaded inside fonts.css in the head before fabric.js @font-face{ font-family:'allstar'; src: url('/path-to-fonts/all_star-webfont.eot'); src: url('/path-to-fonts

How to drag and drop between canvases in Fabric.js

守給你的承諾、 提交于 2019-12-03 06:26:02
问题 I understand Fabric.js have built-in support on drag-n-drop within the same canvas. How can we make it work for multiple canvas? Or from an non-canvas html element e.g. an image from a table? 回答1: Use canvas.observe("object:moving", function (event) {}); If event.e.clientY and event.e.clientX are outside the canvas, then: var activeObject = canvas.getActiveObject(); Store in global dragImage var activeObject.clone(function (c) { dragImage = c; }); canvas.remove(activeObject); Then in window

Add Delete button on element in Canvas Fabric JS

时光怂恿深爱的人放手 提交于 2019-12-03 06:25:34
问题 Hi I want to add delete button in element using FabricJS. I Have an example: I try adding this part of code but when I resize image the delete button don't stay on place. http://jsfiddle.net/wxao1on8/13/ function addDeleteBtn(x, y, w){ $(".deleteBtn").remove(); var btnLeft = x; var btnTop = y - 30; var widthadjust=w/2; btnLeft=widthadjust+btnLeft-1 var deleteBtn = '<img src="https://www.funagain.com/images/old/common/delete-icon.png" class="deleteBtn" ' + 'style="position:absolute;top:'

Right way to rotate things with a mouse in Fabric.js

社会主义新天地 提交于 2019-12-03 06:14:04
This is the example: http://jsbin.com/UHENoKi/11/ Here I use simple formula to find the angle between two points (vectors): But as you could see at JSBin - something is broken. Where did I make a mistake? UPDATE Working example: http://jsbin.com/UHENoKi/13/edit?js,output Douglas The angle to rotate by is being calculated based on the 0,0 origin, but the square is rotating around its own center at 100, 100, so they don't match. If you move the square to 0,0, it feels OK: var rect = new fabric.Rect({ fill: '#00FFAB', top: 0, left: 0, width: 100, height: 100, selectable: false }); Rather than