Determining the Width of a Text String
QUESTION: How can I determine the width of a text string, using the Text function?
ANSWER: Chris Torrence provides the answer to this function graphics question.
You can use the undocumented "GetTextDimensions" method. For example, like this.IDL> p = Plot(/test) IDL> t = Text(0, 1, 'Data Layer Text', /DATA, CLIP=0) ; in the data layer IDL> Print, t.GetTextDimensions() 14.931223 0.072726995 0.00000000 IDL> t1 = Text(0,0, 'Annotation Layer Text') ; in the annotation layer IDL> Print, t1.GetTextDimensions() 0.30468721 0.054687291 0.00000000For text in the "data" layer, the units will be in "data" units. For text in the "annotation" layer, the units will be normalized 0-1. You can use the ConvertCoord() method to convert between different coordinates.
Version of IDL used to prepare this article: IDL 8.2.3.
Copyright ©
1996–2018 Fanning Software Consulting, Inc.
Written: 12 Oct 2014