Text Search Error in Firefox 4

I ran into a bug with my application that I was looking for before inconsistent text rendering between Chrome and Firefox 4.

Chrome tells me that a certain line of text has a width of 215 pixels, while Firefox 4 tells me a width of 218 pixels:

Chrome vs Firefox Text Rendering

A little search indicates that the problem is with Firefox 4 and not with Chrome.

The following code displays the text in the canvas element, as well as through HTML and displays the width:

<html>
  <head>
    <title>Firefox 4 Text Rendering Bug</title>
    <script type="text/javascript">
      function draw(){
        var canvas = document.getElementById('tutorial');
        if (canvas.getContext){
          var ctx = canvas.getContext('2d');
          ctx.font = "bold 16pt Helvetica"
          ctx.fillText("MORE INFORMATION", 0, 16)
          alert(ctx.measureText("MORE INFORMATION").width); 
        }
      }
    </script>
    <style type="text/css">
      canvas { border: 1px solid black; }
      h2 {font-size: 16pt; font-family: Helvetica; font-weight: bold }
    </style>
  </head>
  <body onload="draw();">
    <canvas id="tutorial" width="220" height="20"></canvas>
    <h2>MORE INFORMATION</h2>
  </body>
</html>

Is there a way to visually convert text between browsers?

+3
source share
2 answers

Is there a way to render text between browsers?

Short answer: No Not with fillText.

: , . Firefox, . , FF4 .

Chrome 13.0.782.1, Safari 5 Opera 11 211

IE9 220

FF4 218

Helvetica, . Windows Arial, .. ..

. , fillText. , fillText, - - , , , , .

, : , . PNG . , , -, .

+4

: - , .

, , , 5%, .

0

All Articles