Search code examples
svgfontsfabricjsarabic

Fabric js text component with arabic letters gets generated in wrong way


Problem When you use fabric js for generating text components and convert then to SVG.

problem is here

I want to see the problem and try reproduce and/or resolve ----->Please check first comment <-----

How to use demo to reproduce

  1. Open Url of demo
  2. Run it
  3. Click on add text component it will add English test text component.
  4. Now change the text by double click and paste this for example arabic word شريف
  5. Open your browser inspector.
  6. click on print to console button .

Expected result To look like this

Expected correct result


Solution

  • This is fixed in newer version. Update to v2.3.3 (latest) , your fabricjs version v1.5 is too old and its not maintained any more.

    find latest here fabric.js website

    DEMO

    var canvas = this.__canvas = new fabric.Canvas('c');
    canvas.setDimensions({
     width:400,height:400
    })
    text = new fabric.IText('شريف', { 
      left: 50,
      top: 100,
      fontFamily: 'arial black',
      fill: '#333',
      fontSize: 50
    })
    
    canvas.add(text);
    console.log(text.toSVG());
    function printtest(){
      console.log(text.toSVG());
    }
    #c{
      border:1px solid red;
    }
    <script src="https://rawgit.com/kangax/fabric.js/master/dist/fabric.js"></script>
    <button onclick="printtest()">print console</button><br>
    <canvas id="c"></canvas>