Labels being truncated in V1.1

Editor
Feb 12, 2014 at 2:08 PM
Hi,

Great work on V1.1. The rendering seems smoother and the labels look great (looks like you managed to get the justification fixed too!) :)

I have created a function that wraps text (see below). it basically justs adds a newline when the text in the current line gets too long.

However, now as I increase the size of the label, last few lines of text gradually disapear until I'm only left with half a label!

Thanks,

Rob Smart
   private string WrapText(string originalText)
   {
       var myStringArray = originalText.Split(' ');

       var maxCount = 10;
       var curCount = 0;
       var outString = "";

       List<string> stringList =new List<string>();

       for (var myStringArrayIndex = 0; myStringArrayIndex < myStringArray.Length; myStringArrayIndex++)
       {
           if (curCount <= maxCount)
           {
               var myWordLength = myStringArray[myStringArrayIndex].Length;

               if ((curCount + myWordLength) > maxCount)
               {
                   //new word will push me over the limit so give it a new line
                   outString = outString + System.Environment.NewLine + myStringArray[myStringArrayIndex];
                   curCount = myStringArray[myStringArrayIndex].Length;
               }
               else
               {
                   //Add word to line
                   outString = outString + " " + myStringArray[myStringArrayIndex];
                   curCount = curCount + myStringArray[myStringArrayIndex].Length + 1;
               }
           }
           else
           {
               //Start new line
               //new word will push me over the limit so give it a new line
               outString = outString + System.Environment.NewLine + myStringArray[myStringArrayIndex];
               curCount = myStringArray[myStringArrayIndex].Length;
           }
       }

       return outString;
   }
Coordinator
Feb 12, 2014 at 3:06 PM
You need to play with VectorRenderer.SizeOfStringDelegate.

The currently used implementation cuts off 26% of the size returned by Graphics.MeasureString function. While this seems to be valid for 1-2 line labels it might be wrong for multi line labels.
Editor
Feb 12, 2014 at 3:58 PM
Felix, Thanks for the feedback. I fixed it thanks.

For anyone else interested this is how to do this.

add a delegate method using this code.

VectorRenderer.SizeOfString = SizeOfString;



then add this method

private SizeF SizeOfString(Graphics graphics, string text, Font font)
    {
        var s = graphics.MeasureString(text, font);
        return new SizeF(s.Width + 1f, s.Height);
    }
Coordinator
Feb 12, 2014 at 4:48 PM
This might be worth a try, too. (http://stackoverflow.com/questions/6704923/textrenderer-measuretext-and-graphics-measurestring-mismatch-in-size)
private SizeF SizeOfString(Graphics graphics, string text, Font font)
    {
        var s = TextRenderer.MeasureString(text, font);
        return new SizeF(s.Width + 1f, s.Height);
    }
You can only assign it if you have System.Windows.Forms referenced.