Determining the size of a string in inches using Python and the Windows APIs

Using the source provided in this Python script, one can determine the bounding box, in inches, of a string as it would be rendered in a specific typeface and size on Windows. This, in turn, is useful in determining the estimated size of a text element in a text element exported using arcpy.mapping from an MXD given a custom string.

This serves as an example of the power of the CTypes module in integrating non-Python libraries in a workflow, and how it is relatively painless to interface with a native binary library without writing any C.