2

Is it possible? html:

   <canvas>  </canvas>

js:

  var ctx = canvas.getContext('2d');
     ctx.font = "10pt  bold Courier";
       var input ="99%" + "More teams partcipated in the contest of asia tournament"
       ctx.fillText(input, 100, 100);

O/p: 99 is dynamic data from service. 99% - should be bold and highlight

More teams Participated in the contest of Asia tournament // normal text

Mohamed Sahir
  • 2,482
  • 8
  • 40
  • 71

1 Answers1

2

Try doing the following:

// get canvas / context
var can = document.getElementById('my-canvas');
var ctx = can.getContext('2d')

// draw first text
var text = '99%';
ctx.font = 'bold 12pt Courier';
ctx.fillText(text, 50, 50);

// measure text
var textWidth = ctx.measureText(text).width;

// draw second text
ctx.font = 'normal 12pt Courier';
ctx.fillText(' invisible', 50 + textWidth, 50);
<canvas id="my-canvas" width="250" height="150"></canvas>
KyleMit
  • 30,350
  • 66
  • 462
  • 664
StackSlave
  • 10,613
  • 2
  • 18
  • 35