I'm working in ArcGIS 10.0 and Python 2.6.5. I have a string, say
'mMx', that I want to enter into a TextElement (in the data view). The lowercase letters are to be substituted with a graphical symbol through use of the usual html-style formatting tags. We'll assume that the regular font is Arial (specified in the TextSymbol) and that the sybolic font is Wingdings. So, I build a formatted string like so:
<FNT name="Wingdings" size="48">m</FNT>M<FNT name="Wingdings" size="48">x</FNT>
This string is what I set as text for my TextElement. Now, what I want to get is the bounds of the formatted text only, as it would appear on the screen with full symbology. The text appears fine -- with symbology -- on the screen. The problem is that the bounds of the text element include the length of the whole input string, formatting tags and all. In map units, the text is maybe 50' long, but the bounds are 1000'. I have tried QueryBounds and QueryOutline (both of which say they take symbology into account) and also ITextSymbol.GetTextSize. They all return the same crazy dimensions. ArcGIS is processing the formatting tags just fine as far as the text itself is concerned, but the bounds include the tags. I don't get it. This is a big concern, because I absolutely need to know the onscreen-text-only size of the TextElement for use in subsequent calculations.
Does anyone have any insights on this problem? Thank you all for the help ... and I apologize for asking such a specific ArcObjects question here, but I get exactly NO response from ESRI forums anymore.
Well, I just found the problem, and it has to do with the way the format string I show above was made in Python. I have been doing a lot of HTML code block output in Python lately, and I have been used to using triple quoted strings. That is what I did when building the format string. So the following is the actual line of code that builds the format string. (Lesson learned. I should always include a code snippet.)
fmtchar = """<FNT name="Wingdings" size="48">""" + eachChar + """</FNT>"""
It should be:
fmtchar = '<FNT name="Wingdings" size="48">' + eachChar + '</FNT>'
I find it interesing that ArcGIS would process the formatting tags and also count the tag characters as part of the text. Hmmm. BTW, let me know if I should put this solution in an answer to my own question.