<!DOCTYPE HTML>
<html>
<body>
<canvas id="canvas" width="300px" height="300px" style="border:1px solid #c3c3c3;"></canvas>

<script type="text/javascript">
  var ctx = document.getElementById('canvas').getContext("2d");
  ctx.font = '15px Arial';

  var rtl = '\u202e';
  var ltr = '\u202d';
  var stop = '\u202c';

  ctx.fillText(ltr + 'foo' + stop + ltr + 'bar' + stop, 10, 20);
  ctx.fillText(ltr + 'foo' + stop + rtl + 'bar' + stop, 10, 40);
  ctx.fillText(rtl + 'foo' + stop + ltr + 'bar' + stop, 10, 60);
  ctx.fillText(rtl + 'foo' + stop + rtl + 'bar' + stop, 10, 80);

</script>
</body>
