Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / api / Ext.util.TextMetrics.html
1 <!DOCTYPE html><html><head><title>Ext.util.TextMetrics | Ext JS 4.0 Documentation</title><script type="text/javascript" src="../ext-all.js"></script><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../scrollbars.css" type="text/css"><link rel="stylesheet" href="../docs.css" type="text/css"><link id="styleCss" rel="stylesheet" href="../style.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script><link rel="stylesheet" href="../prettify.css" type="text/css"><!-- link(rel: 'stylesheet', href: req.baseURL + '/css/ext4.css', type: 'text/css')--><link rel="shortcut icon" type="image/ico" href="../favicon.ico"><!--[if IE]>
2 <style type="text/css">.head-band { display: none; }
3 .header { border: 0; top: 0; left: 0px; background: url(../header.gif) repeat-x; }
4 .doc-tab .members .member a.more { background-color: #efefef; }
5 </style><link rel="stylesheet" href="/new/css/ie.css" type="text/css"><![endif]-->
6 </head><body id="ext-body" class="iScroll"><div id="notice" class="notice">For up to date documentation and features, visit 
7 <a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a></div><div class="wrapper"><div class="head-band"></div><div class="header"><h2><a href="../index.html">Sencha Documentation</a></h2></div><div id="search"><form><input type="text" placeholder="Search" id="search-field" autocomplete="off" name="q"></form><div id="search-box"></div></div><div id="treePanel"></div><div id="container"><script type="text/javascript">
8
9     req = {
10         liveURL: '.',
11         standAloneMode: true,
12         origDocClass: 'Ext.util.TextMetrics',
13         docClass: 'Ext.util.TextMetrics',
14         docReq: 'Ext.util.TextMetrics',
15         version: '4.0',
16         baseURL: '.',
17         baseDocURL: '.',
18         baseProdURL: '.'
19     };
20
21     clsInfo = {};
22
23
24
25 </script>
26
27 <script type="text/javascript" src="../search.js"></script>
28 <!--script type="text/javascript" src="/new/javascripts/app/examples.js"></script-->
29 <script type="text/javascript" src="../class_tree.js"></script>
30 <script type="text/javascript" src="../class_doc.js"></script>
31 <script type="text/javascript">
32     req.source = 'TextMetrics.html#Ext-util.TextMetrics';
33     clsInfo = {"methods":["TextMetrics","bind","destroy","getHeight","getSize","getWidth","measure","setFixedWidth"],"cfgs":[],"properties":[],"events":[],"subclasses":[]};
34     Ext.onReady(function() {
35         Ext.create('Docs.classPanel');
36     });
37 </script><div id="top-block" class="top-block"><h1 id="clsTitle" class="cls"><a href="../source/TextMetrics.html#Ext-util.TextMetrics" target="_blank">Ext.util.TextMetrics</a></h1></div><div id="docContent"><div id="doc-overview-content"><div class="lft"><p>
38 Provides precise pixel measurements for blocks of text so that you can determine exactly how high and
39 wide, in pixels, a given block of text will be. Note that when measuring text, it should be plain text and
40 should not contain any HTML, otherwise it may not be measured correctly.</p>
41
42
43 <p></p>
44
45 <p>The measurement works by copying the relevant CSS styles that can affect the font related display, 
46 then checking the size of an element that is auto-sized. Note that if the text is multi-lined, you must 
47 provide a <b>fixed width</b> when doing the measurement.</p>
48
49
50
51
52 <p>
53 If multiple measurements are being done on the same element, you create a new instance to initialize 
54 to avoid the overhead of copying the styles to the element repeatedly.
55 </p>
56
57 <div class="members"><div class="m-methods"><a name="methods"></a><div class="definedBy">Defined By</div><h3 class="mth p">Methods</h3><div id="method-TextMetrics" class="member f ni"><a href="Ext.util.TextMetrics.html#method-TextMetrics" rel="method-TextMetrics" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-constructor" class="viewSource">view source</a></div><a name="TextMetrics"></a><a name="method-TextMetrics"></a><a href="Ext.util.TextMetrics.html#" rel="method-TextMetrics" class="cls expand">TextMetrics</a>(
58 <span class="pre">Mixed bindTo, Number fixedWidth</span>)
59  : void</div><div class="description"><div class="short"><p>&nbsp;</p></div><div class="long">
60 <h3 class="pa">Parameters</h3><ul><li><span class="pre">bindTo</span> : Mixed<div class="sub-desc"><p>The element to bind to.</p>
61 </div></li><li><span class="pre">fixedWidth</span> : Number<div class="sub-desc"><p>A fixed width to apply to the measuring element.</p>
62 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
63 </li></ul></div></div></div><div id="method-bind" class="member ni"><a href="Ext.util.TextMetrics.html#method-bind" rel="method-bind" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-bind" class="viewSource">view source</a></div><a name="bind"></a><a name="method-bind"></a><a href="Ext.util.TextMetrics.html#" rel="method-bind" class="cls expand">bind</a>(
64 <span class="pre">Mixed el</span>)
65  : void</div><div class="description"><div class="short"><p>Binds this TextMetrics instance to a new element</p>
66 </div><div class="long"><p>Binds this TextMetrics instance to a new element</p>
67 <h3 class="pa">Parameters</h3><ul><li><span class="pre">el</span> : Mixed<div class="sub-desc"><p>The element</p>
68 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
69 </li></ul></div></div></div><div id="method-destroy" class="member ni"><a href="Ext.util.TextMetrics.html#method-destroy" rel="method-destroy" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-destroy" class="viewSource">view source</a></div><a name="destroy"></a><a name="method-destroy"></a><a href="Ext.util.TextMetrics.html#" rel="method-destroy" class="cls expand">destroy</a> : void</div><div class="description"><div class="short"><p>Destroy this instance</p>
70 </div><div class="long"><p>Destroy this instance</p>
71 <h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
72 </li></ul></div></div></div><div id="method-getHeight" class="member ni"><a href="Ext.util.TextMetrics.html#method-getHeight" rel="method-getHeight" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-getHeight" class="viewSource">view source</a></div><a name="getHeight"></a><a name="method-getHeight"></a><a href="Ext.util.TextMetrics.html#" rel="method-getHeight" class="cls expand">getHeight</a>(
73 <span class="pre">String text</span>)
74  : Number</div><div class="description"><div class="short"><p>Returns the measured height of the specified text</p>
75 </div><div class="long"><p>Returns the measured height of the specified text</p>
76 <h3 class="pa">Parameters</h3><ul><li><span class="pre">text</span> : String<div class="sub-desc"><p>The text to measure</p>
77 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Number</span>&nbsp; &nbsp;<p>height The height in pixels</p>
78 </li></ul></div></div></div><div id="method-getSize" class="member ni"><a href="Ext.util.TextMetrics.html#method-getSize" rel="method-getSize" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-getSize" class="viewSource">view source</a></div><a name="getSize"></a><a name="method-getSize"></a><a href="Ext.util.TextMetrics.html#" rel="method-getSize" class="cls expand">getSize</a>(
79 <span class="pre">String text</span>)
80  : Object</div><div class="description"><div class="short">Only available on the instance returned from createInstance, not on the singleton.
81
82
83 Returns the size of the specifie...</div><div class="long"><p><b>Only available on the instance returned from <a href="Ext.util.TextMetrics.html#createInstance" rel="Ext.util.TextMetrics#createInstance" class="docClass">createInstance</a>, <u>not</u> on the singleton.</b></p>
84
85
86 <p>Returns the size of the specified text based on the internal element's style and width properties</p>
87 <h3 class="pa">Parameters</h3><ul><li><span class="pre">text</span> : String<div class="sub-desc"><p>The text to measure</p>
88 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Object</span>&nbsp; &nbsp;<p>An object containing the text's size {width: (width), height: (height)}</p>
89 </li></ul></div></div></div><div id="method-getWidth" class="member ni"><a href="Ext.util.TextMetrics.html#method-getWidth" rel="method-getWidth" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-getWidth" class="viewSource">view source</a></div><a name="getWidth"></a><a name="method-getWidth"></a><a href="Ext.util.TextMetrics.html#" rel="method-getWidth" class="cls expand">getWidth</a>(
90 <span class="pre">String text</span>)
91  : Number</div><div class="description"><div class="short"><p>Returns the measured width of the specified text</p>
92 </div><div class="long"><p>Returns the measured width of the specified text</p>
93 <h3 class="pa">Parameters</h3><ul><li><span class="pre">text</span> : String<div class="sub-desc"><p>The text to measure</p>
94 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Number</span>&nbsp; &nbsp;<p>width The width in pixels</p>
95 </li></ul></div></div></div><div id="method-measure" class="member ni"><a href="Ext.util.TextMetrics.html#method-measure" rel="method-measure" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-measure" class="viewSource">view source</a></div><a name="measure"></a><a name="method-measure"></a><a href="Ext.util.TextMetrics.html#" rel="method-measure" class="cls expand">measure</a>(
96 <span class="pre">String/HTMLElement el, String text, [Number fixedWidth]</span>)
97  : Object</div><div class="description"><div class="short"><p>Measures the size of the specified text</p>
98 </div><div class="long"><p>Measures the size of the specified text</p>
99 <h3 class="pa">Parameters</h3><ul><li><span class="pre">el</span> : String/HTMLElement<div class="sub-desc"><p>The element, dom node or id from which to copy existing CSS styles
100 that can affect the size of the rendered text</p>
101 </div></li><li><span class="pre">text</span> : String<div class="sub-desc"><p>The text to measure</p>
102 </div></li><li><span class="pre">fixedWidth</span> : Number<div class="sub-desc"><p>(optional) If the text will be multiline, you have to set a fixed width
103 in order to accurately measure the text height</p>
104 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Object</span>&nbsp; &nbsp;<p>An object containing the text's size {width: (width), height: (height)}</p>
105 </li></ul></div></div></div><div id="method-setFixedWidth" class="member ni"><a href="Ext.util.TextMetrics.html#method-setFixedWidth" rel="method-setFixedWidth" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.TextMetrics.html" class="definedIn docClass">Ext.util.TextMetrics</a><br/><a href="../source/TextMetrics.html#Ext-util.TextMetrics-method-setFixedWidth" class="viewSource">view source</a></div><a name="setFixedWidth"></a><a name="method-setFixedWidth"></a><a href="Ext.util.TextMetrics.html#" rel="method-setFixedWidth" class="cls expand">setFixedWidth</a>(
106 <span class="pre">Number width</span>)
107  : void</div><div class="description"><div class="short">Sets a fixed width on the internal measurement element.  If the text will be multiline, you have
108 to set a fixed width...</div><div class="long"><p>Sets a fixed width on the internal measurement element.  If the text will be multiline, you have
109 to set a fixed width in order to accurately measure the text height.</p>
110 <h3 class="pa">Parameters</h3><ul><li><span class="pre">width</span> : Number<div class="sub-desc"><p>The width to set on the element</p>
111 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
112 </li></ul></div></div></div></div></div></div></div><div id="pageContent"></div></div></div></div></body></html>