ThinkGeo.com    |     Documentation    |     Premium Support

GeoCanvas.MeasureText returns anomalous rectangle dimensions

I am trying to implement the word-wrapping sample in RotatingTextStyle. One problem I have is that GeoCanvas.MeasureText returns bad measurements. For example, I am trying to wrap the following text:


 123456879 123456879 123456879 123456879 123456879 123456879 123456879 123456879 123456879 123456879 123456879 123456879 123456879 123456879 123456879 123456879 123456879 123456879


The bounding box screen width is 354. However, the GeoCanvas.MeasureText returns 1132x14 with a Tahoma 9 font.


Does the MeasureText method try to wrap the words inside the rectangle, or just treat the text as a single string without line breaks? I've seen it return rectangles that indicate 3 lines of wrapped text, so it seems like it would take into account the dimensions of the containing rectangle...


I am trying to implement the word wrap logic, but am struggling with the best way to calclulate the maximum string size, and the MeasureText isn't helping!


 



Gregory, 
  
   The MeasureText method just passes through to the GDI+ MeasureText method.  To GDI+ when you draw text you can easily draw off the screen region.  For this reason i think what it returns is correct as the string you have above is very long and would easily go off the screen.  I think you need to insert your own carriage returns and then see what the rectangle looks like.  Below are two projects on our Code Community that shows some word wrapping.  I think after looking at the projects below you will be inspired.  I think another things we could do if you are interested is to write method where you pass in a string and an rectangle and we would try and fit the text in it.  We could have options for wrapping or adjusting the font etc. 
  
 code.thinkgeo.com/projects/show/wordwrapped 
 code.thinkgeo.com/projects/show/hybridtextstyle 
  
 David

Thanks, David. That is good to know I will try some alternate measures…

David, Thanks for your help on this. 
  
 Gregory, any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale