public final class CmsTextMetrics
extends java.lang.Object
Normal usage would be:
for(Element e: elements) { CmsTextMetrics tm = CmsTextMetrics.get(e, "TextMetricsKey"); // measure text if (r.getWidth(text) > 500) { // do something } // release tm.release(); }Based on my-gwt TextMetrics.
限定符和类型 | 方法和说明 |
---|---|
protected void |
bind(com.google.gwt.dom.client.Element element)
Binds this text metrics instance to an element from which to copy existing
CSS styles that can affect the size of the rendered text.
|
protected void |
bind(com.google.gwt.dom.client.Element element,
CmsDomUtil.Style... attributes)
Binds this text metrics instance to an element from which to copy existing
CSS styles that can affect the size of the rendered text.
|
static CmsTextMetrics |
get(com.google.gwt.dom.client.Element element,
java.lang.String key)
Gets the text metrics object for a given DOM element and key.
|
int |
getHeight(java.lang.String text)
Returns the measured height of the specified text.
|
int |
getWidth(java.lang.String text)
Returns the measured width of the specified text.
|
void |
release()
Should be called, when finished measuring, to release the playground.
|
void |
setFixedWidth(int width)
Sets a fixed width on the internal measurement element.
|
public static CmsTextMetrics get(com.google.gwt.dom.client.Element element, java.lang.String key)
If the key is null, or the method has been never called with the same key before, a new text metrics object will be created, with its style taken from the element parameter. Otherwise, the text metrics object for the given key will be returned, and the element parameter will be ignored.
element
- the element from which to take the stylekey
- the text metrics keypublic int getHeight(java.lang.String text)
setFixedWidth(int)
if necessary.text
- the text to be measuredpublic int getWidth(java.lang.String text)
text
- the text to measurepublic void release()
public void setFixedWidth(int width)
width
- the width to set on the elementprotected void bind(com.google.gwt.dom.client.Element element)
element
- the elementprotected void bind(com.google.gwt.dom.client.Element element, CmsDomUtil.Style... attributes)
element
- the elementattributes
- the attributes to bind