Skip to content

API / geotoolkit / renderer / TextMetrics / TextMetrics

Class: TextMetrics

renderer.TextMetrics.TextMetrics

Defines text metrics

Table of contents

Constructors
[new TextMetrics(width)](/solutions/geotoolkit/GeoToolkit_JS/apis/classes/geotoolkit.renderer.textmetrics.textmetrics.md#new textmetrics(width))[new TextMetrics(width, height, fontMetrics)](/solutions/geotoolkit/GeoToolkit_JS/apis/classes/geotoolkit.renderer.textmetrics.textmetrics.md#new textmetrics(width, height, fontmetrics))
Methods
Css Properties
Name Type Description
fontmetricsFontMetricsFont metrics
fontmetrics-ascentnumber
fontmetrics-descentnumber
fontmetrics-heightnumber
heightnumberSet the height
widthnumberSet the width

Contents

Constructors

new TextMetrics(width)

• new TextMetrics(width?)

Parameters

Name Type
Optional widthOptions

new TextMetrics(width, height, fontMetrics)

• new TextMetrics(width, height, fontMetrics?)

Parameters

Name Type Description
widthnumberwidth or properties object
heightnumberheight
Optional fontMetricsFontMetricsfont metrics
Methods

clone

▸ clone(): TextMetrics

Return clone object.

Returns

TextMetrics

clone a copy of this object


getClassName

▸ getClassName(): string

Returns

string


getFontMetrics

▸ getFontMetrics(): FontMetrics

Return font metrics

Returns

FontMetrics

font metrics


getHeight

▸ getHeight(): number

return height

Returns

number


getProperties

▸ getProperties(): Options

Gets all the properties pertaining to this object

Returns

Options

properties


getWidth

▸ getWidth(): number

return width

Returns

number


setMetrics

▸ setMetrics(width, height, fontMetrics?): TextMetrics

setMetrics

Parameters

Name Type Description
widthnumberwidth
heightnumberheight
Optional fontMetricsFontMetricsfont metrics

Returns

TextMetrics

this


setProperties

▸ setProperties(properties?): TextMetrics

Sets all the properties pertaining to this object

Parameters

Name Type Description
Optional propertiesOptionsAn object containing the properties to set

Returns

TextMetrics


toRect

▸ toRect(): Rect

Convert current instance TextMetrics to Rect

Returns

Rect


clearCache

▸ Static clearCache(): void

clears the current cache

Returns

void


getClassName

▸ Static getClassName(): string

Returns

string


getMeasureTextStrategy

▸ Static getMeasureTextStrategy(): TextMetricsMeasureStrategy

Returns the current text measure strategy

Returns

TextMetricsMeasureStrategy


measureText

▸ Static measureText(text, textStyle?, useFontMetrics?): TextMetrics

Measure text size in device coordinates

Parameters

Name Type Description
textstringcurrent text string
Optional textStyleTextStylethe text style
Optional useFontMetricsbooleanflag to calculate font metrics

Returns

TextMetrics

text metrics


parseFont

▸ Static parseFont(font): Font

Parse font weight, size and family based on font string follow w3 recommendation see http://www.w3.org/TR/css3-fonts/ if the font cannot be parsed it will return default font : 12px arial.

Parameters

Name Type Description
fontstring | TextStylecurrent font for the text

Returns

Font


setCacheLimit

▸ Static setCacheLimit(val): void

Sets the maximum cache limit

Parameters

Name Type Description
valnumbernumber of different font metrics that can be implemented

Returns

void


setMeasureTextStrategy

▸ Static setMeasureTextStrategy(val): void

Sets the strategy to use when measuring text size This function sets the 'MeasureText' function according to the strategy

Parameters

Name Type Description
valTextMetricsMeasureStrategy | customMeasureTextStrategystrategy to measure text

Returns

void