Skip to content

Instantly share code, notes, and snippets.

@erikhazzard
Created February 13, 2012 23:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save erikhazzard/1821595 to your computer and use it in GitHub Desktop.
Save erikhazzard/1821595 to your computer and use it in GitHub Desktop.
getbbox cs getcomputedlength
<html>
<meta charset='utf-8' />
<head>
</head>
<body>
<svg>
<text id='text_node' y="20px" text-anchor="start" opacity="1">
<tspan>You</tspan>
<tspan dx='.5em'>shall</tspan>
<tspan dx='.5em' dy='.9em'>not</tspan>
<tspan dx='.4em' dy='.9em'>pass</tspan>
<tspan dx='.5em'>Fly</tspan>
<tspan dx='.4em' dy='.9em'>you</tspan>
<tspan dx='.4em' dy='.9em'>fools</tspan>
</text>
</svg>
<script>
var bbox = document.getElementById('text_node').getBBox();
var computed_text_length = document.getElementById('text_node').getComputedTextLength();
console.log('BBOX width: ', bbox.width);
console.log('Computed text length: ', computed_text_length);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment