5

Possible Duplicate:
SVG Scaling Text to fit container

I have an text of unknown length (say the caption of an element) and I have a container with fixed dimensions that should display the text without clipping. Instead the text should be scaled to fit the container completely.

Example:

<svg>
    <rect width="100px" height="100px" fill="none" stroke="blue" />
    <svg width="100px" height="100px" style="border:black">
        <text dx="1ex" dy="1.5em" >Some Unknown Caption</text>
    </svg>
</svg>

I thought this should be easy with svg but I cannot find out how to do it. I know I can do it with Javascript by calculating the scaling factor but I believe that for this common case some kind of autoscaling must exist. I have experimented with the viewbox attribute but it seems that you must know the dimensions of the content which I don't.

Community
  • 1
  • 1
Christian Rodemeyer
  • 2,001
  • 1
  • 19
  • 22
  • 6
    If casperOne had read the answer to the possible duplicate he had seen that this question doesn't answer my question. The viewbox solution only works if you know how wide your text is. Please read and understand my question and the possible duplicate before closing it. Thank you. – Christian Rodemeyer May 07 '12 at 18:04
  • any updates on this? I'm sure there's a jQuery hack out there, but I was hoping to find the quick and easy that works in IE.. – whyoz Jan 24 '15 at 20:37

0 Answers0