As the tutorial says (not as clear as it should), you need to convert the font to the cufon format if you want to treat individual letters as unique SVG paths. If you do, the paper.print function works as expected. Without this, the print function returns an empty array (and the "letter [4]" fails).
Experimentally, I grabbed two missing font files from html5rocks:
<script src="Vegur.font.js"></script> <script src="cufon.js"></script>
and added them to a sample HTML page:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Raphaël—JavaScript Library</title> </head> <body> <div id="demo-1"></div> <script src="raphael.js" type="text/javascript"></script> <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script> <script src="Scripts/Vegur.font.js" type="text/javascript"></script> <script src="Scripts/cufon.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { var paper = Raphael("demo-1", 320, 200); var t = paper.text(50, 10, "HTML5ROCKS"); var letters = paper.print(50, 50, "HTML5ROCKS", paper.getFont("Vegur"), 40); letters[4].attr({ fill: "orange" }); for (var i = 5; i < letters.length; i++) { letters[i].attr({ fill: "#3D5C9D", "stroke-width": "2", stroke: "#3D5C9D" }); } }); </script> </body> </html>
The second HTML5ROCKS text is marked as expected (as shown on the tutorial's original page).
source share