Pure SVG way to fit text to a box

后端 未结 4 692
小鲜肉
小鲜肉 2020-12-07 13:21

Box size known. Text string length unknown. Fit text to box without ruining its aspect ratio.

\"enter

4条回答
  •  渐次进展
    2020-12-07 13:28

    first of all: just saw that the answer doesn't precisely address your need - it might still be an option, so here we go:

    you are rightly observing that svg doesn't support word-wrapping directly. however, you might benefit from foreignObject elements serving as a wrapper for xhtml fragments where word-wrapping is available.

    have a look at this self-contained demo (available online):

    
    
    
    
      simulated wrapping in svg
      A foreignObject container
    
       
       
          
             
                Demo test that is supposed to be word-wrapped somewhere along the line to show that it is indeed possible to simulate ordinary text containers in svg.
             
          
       
    
      
    

提交回复
热议问题