Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG text is poor quality?

Tags:

svg

d3.js

I've constructed some SVG text using D3, but for some reason it's quite low quality. This is in Chrome on OSX.

This is the code:

.hover-text { 
   stroke: black;
}
var tipHeadText = hoverLineGroup.append('text')
   .attr("class", "hover-text")
   .attr("text-anchor", "middle")
   .attr('font-size', '10px')
   .attr('y', -45).text("Last data point:")

This is how it renders, looking quite fuzzy:

enter image description here

Is there anything I can do to make it crisper? Or would I be better off using HTML?

like image 261
Richard Avatar asked Sep 19 '13 16:09

Richard


People also ask

How do I scale SVG text?

You can use the scale(x,y) transform command to scale an element. A scale of 1 is normal size, 0.5 is half normal size, and 2 is double normal size. For example, add transform="scale(1, 2)" to your tag to scale it normally horizontally and twice the size vertically.

Does SVG change font?

SVG isn't just a vector image format. It can contain numerous other stuff like bitmap images, and text as text (not vector). The text has a font property but the font isn't included. So if the system the SVG is viewed doesn't have the font installed, it'(s rendered with another default font.

How do I make SVG text?

To create text SVG's in Inkscape you need to turn your text into a path. To do this just select your text and then go to “path” in the top menu bar and then choose “object to path”. This will turn your text into a path. From here you can click into each individual letter of your text and edit however you'd like.


1 Answers

It looks like you're setting the stroke to black? Stroke represents the outer border of the text where fill sets the inner color. Consider using fill instead and setting stroke to none:

.fuzzy {
    stroke: black;
}
.crisp {
    fill: black;
    font-weight: bold;
}

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <text class="fuzzy" font-size="10px" x="0" y="15" fill="red">I love SVG</text>
</svg> 
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <text class="crisp" font-size="10px" x="0" y="15" fill="red">I love SVG</text>
</svg> 

jsFiddle: http://jsfiddle.net/reblace/RGEXc/1/ Here's a nice reference on svg text: http://www.hongkiat.com/blog/scalable-vector-graphics-text/

If this is off the mark, then perhaps a jsFiddle of your own demonstrating the problem would help narrow in on the issue?

like image 93
reblace Avatar answered Sep 25 '22 12:09

reblace