Unable to clone curved text in fabric.js version 5.3.0

I am currently using fabric.js version 5.3.0 and I have a requirement to clone curved text and add it to the canvas.

Description: The issue I am facing is that the cloning functionality does not work properly with curved text. The cloned object does not return the same as the original one. You can check the problem by visiting the following fiddle: https://jsfiddle.net/Niketa_patel/snw9yx21/7/

Below is the code snippet:

(function (fabric) {
  /*
   * CurvedText object for fabric.js
   * @author Arjan Haverkamp (av01d)
   * @date January 2018
   */
  
  // Rest of the JavaScript code...
  
})(typeof fabric !== "undefined" ? fabric : fabric);
var fcanvas = new fabric.Canvas('canv');

// Creating a curved text object
const curvedText = new fabric.CurvedText('It feels so nice to be able to draw', {
    diameter: 360,
    fontSize: 32,
    fontFamily: 'Arial',
    left: 50,
    top: 50,
    fill: 'red'
});

let democopy = {};

// Adding the curved text to the canvas
fcanvas.add(curvedText);

// Cloning the curved text
curvedText.clone(cloned=>{
console.log(cloned,'curvedText');
democopy = cloned;
})

// Cloning the cloned text
democopy.clone(cloned=>{
console.log(cloned,'cloned');
console.log(curvedText,'curvedText')
fcanvas.add(cloned);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.1/fabric.min.js"></script>
<canvas id="canv" width="500" height="300" style="border: 1px solid rgb(204, 204, 204); width: 400px; height: 400px; -webkit-user-select: none;"></canvas>

Thank you :)

Answer №1

Organize your styles in an object and reapply them using the set() method.

const styledText = {
    font: 'Helvetica',
    size: 24,
    color: 'blue',
    alignment: 'center'
};
const customText = new fabric.CustomText('Creating unique designs is amazing', styledText);
let copiedText = {};

canvas.add(customText);
customText.clone(cloned=>{
  cloned.set(styledText);
  copiedText = cloned;
  canvas.add(copiedText);
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Combining elements from a string array to create a hierarchical object in JavaScript

I need assistance with merging values from an array into a predefined nested object. Here is an example of the array with values, ['name=ABC XYZ', 'hobbies=[M,N,O,P]', 'profession=S', 'age=27'] The object that needs ...

5 Simple Steps for Adding a Value to a Popup Textbox Automatically

I want to send a value to another php page and then display the values. How can I achieve this? Here is the PHP code snippet: if(!empty($_POST["mytext"])) { for ($x=1; $x<=$a; $x++) { echo $txtLine[$x] = $_POST['mytext'.$x]; } } B ...

The bootstrap switch button remains in a neutral grey color

Ordinary: Initially clicked: Click again: After the second click, it remains grey and only reverts on a different action like mouse click or selection. Is there a way to make it go back to its original state when unselected? ...

Angular app sends a JSON request and receives no data in response

It seems like Angular may be loading the page before fully receiving all the information from JSONP. There are times when refreshing the page multiple times eventually displays the information, but it's not consistent. Interestingly, the code used on ...

Will the useEffect hook re-run whenever the component renders if it includes props in its dependency array?

According to the React documentation on useEffect, it is recommended to include props in the dependency array of useEffect: import { useEffect } from 'react'; import { createConnection } from './chat.js'; function ChatRoom({ roomId }) ...

Exploring the Bookmarking Capabilities of Firefox

Is there a way to access the users' bookmarks using Firefox API and javascript? Appreciate any help, Bruno ...

Encountering a problem with AngularJS when trying to pass a controller through ng-include in HTML

I'm currently developing a portal-style application that will dynamically inject HTML from other URLs (within the domain) into different sections of the page, which I like to refer to as widgets. Each widget needs to be loaded with an ng-include and h ...

A JavaScript function to separate a URL and eliminate the final segment

http://www.google.com/site!#656126.72367 Is there a way to split and remove the part after the exclamation mark in this URL using JavaScript when the page is loaded? I am looking to achieve http://www.google.com/site ...

Zod: ensure at least one field meets the necessary criteria

Currently, I am in the process of developing a form that allows users to input either their email address or phone number. While they have the option to provide both, they are required to enter both before proceeding. For this project, I am utilizing Zod a ...

Rendering with node.js express inside nested JS files

Imagine I have a basic view <html> <head> <title>something</title> </head> <body> <%= param %> </body> <script type="text/javascript" src="myscript.js"></script> </html> Be ...

Preserving color output while executing commands in NodeJS

My Grunt task involves shelling out via node to run "composer install". var done = this.async(); var exec = require('child_process').exec; var composer = exec( 'php bin/composer.phar install', function(error, stdout, stderr) { ...

Tips for efficiently handling navigation re-rendering on a Single Page Application using Vue.js

I am currently in the process of developing a Single Page Application using Vue.js. The structure involves having a template in App.vue which includes a navigation bar followed by a router-view component. When a user attempts to log in, a modal window appe ...

Convert the easeInExpo function from jQuery easing to vanilla JavaScript and CSS

Currently, I am in the process of converting a piece of code from jQuery to plain JavaScript and CSS. The specific code snippet I am focusing on involves creating easing functions without relying on jQuery. const customEasing = { easeInExpo: function ( ...

Handling invalid JSON data using JavaScript

Looking to extract data from this URL using Javascript. Here is a sample of the JSON content: {"ss":[["Thu","7:00","Final",,"BAL","19","ATL","20",,,"56808",,"PRE4","2015"],["Thu","7:00","Final",,"NO","10","GB","38",,,"56809",,"PRE4","2015"]]} Most tutori ...

What is the correct way to update an array of objects using setState in React?

I am facing an issue where I have an array of objects that generates Close buttons based on the number of items in it. When I click a Close button, my expectation is that the array should be updated (removed) and the corresponding button element should dis ...

Dynamically linking tabbable tabs is a useful technique that allows for

I have been working on an app that organizes websites into groups displayed as tabs in a tabbable navigator using Twitter Bootstrap. The idea is that each time a new group is added, a new tab should appear. Currently, this is how it looks: The functionali ...

AngularJS relies heavily on the concept of internationalization, commonly referred

I18n key: "step1.download":"{{n0}} Get {{n1}} More content." Within my website: <span translate=step1.download translate-values="{ n0: '{{info0}}', n1: '{{info1}}'}"></span> Within my application logic: $scope.download ...

Resolve the route expression before the API request is fully processed

As a hobby coder, I have some gaps in my knowledge and despite trying various solutions, I have not been able to solve this issue. Idea Outcome My goal is to call my Express server, retrieve data from an external API, and render the data once it's f ...

Issue with Express.js res.append function: Headers cannot be set after they have already been sent

I encountered an issue in my express project where I tried to set multiple cookies using "res.append" in the same request, but I kept getting an error saying "Error: Can't set headers after they are sent.". Can someone help me identify the problem and ...

Assistance with changing styles

Hey there, I could really use some assistance. I've created a style switcher, but I'm struggling to figure out how to replace the stylesheet properly. Currently, my code empties the <head> element when what I really need is for it to simply ...