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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s