BigBadaboom / androidsvg

SVG rendering library for Android
http://bigbadaboom.github.io/androidsvg/
Apache License 2.0
1.2k stars 231 forks source link

Support multi-value text geometry attributes #248

Open zhang-hai opened 2 years ago

zhang-hai commented 2 years ago

Issue

I find this question when load svg file.

normal image23

But lost the '<' when useing this library to load the svg: image

Solution

SVGAndroidRenderer.java

   private void enumerateTextSpans(TextContainer obj, TextProcessor textprocessor)
   {
      if (!display())
         return;

      Iterator<SvgObject>  iter = obj.children.iterator();
      boolean              isFirstChild = true;

      // get the array of x info
      List<Length> xList = null;
      int size = 0;
      if (obj instanceof Text){
         xList = ((Text) obj).x;
         size = xList.size();
      }

      while (iter.hasNext())
      {
         SvgObject  child = iter.next();

         if (child instanceof TextSequence) {
            final String text = ((TextSequence) child).text;
            //When the length of the string is greater than 1 and consistent with the length of the X coordinate array, each character needs to be drawn separately
            if (text.length() > 1 && text.length() == size){
               for (int i = 0;i < text.length();i++){
                  String s = text.substring(i,i+1);
                  if (textprocessor instanceof PlainTextDrawer){
                     ((PlainTextDrawer) textprocessor).x = xList.get(i).value;
                  }
                  textprocessor.processText(s);
               }
            }else {
               textprocessor.processText(textXMLSpaceTransform(text, isFirstChild, !iter.hasNext() /*isLastChild*/));
            }
         } else {
            processTextChild(child, textprocessor);
         }
         isFirstChild = false;
      }
   }
BigBadaboom commented 2 years ago

Hi. Thanks for your report.

This is failing because AndroidSVG doesn't currently support multivalue x attributes in text. For example:

x="706 1612"

This is a rarely used feature of the SVG spec. And is complicated to implement properly. So it didn't seem high on the priority list.

I'm curious... What software generated this SVG?

PL