Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/support
esri/workers
Class: Font

require(["esri/symbols/Font"], function(Font) { /* code goes here */ });

Description

(Added at v1.0)
Font used for text symbols added to the graphics layer.

Note that variant is deprecated, and will not available in version 4.

Samples

Search for samples that use this class.

Constructors

NameSummary
new Font()Creates a new Font object.
new Font(size?, style?, variant?, weight?, family?)Creates a new Font object.
new Font(json)Creates a new Font object using a JSON object.

Constants

NameDescription
STYLE_ITALICText is in italics.
STYLE_NORMALText style is normal.
STYLE_OBLIQUEText is slanted.
VARIANT_NORMALText variant is normal. Deprecated
VARIANT_SMALLCAPSText is in all small caps. Deprecated
WEIGHT_BOLDText weight is bold.
WEIGHT_BOLDERText weight is extra bold.
WEIGHT_LIGHTERText weight is lighter than normal.
WEIGHT_NORMALText weight is normal.

Properties

NameTypeSummary
decorationStringText decoration.
familyStringFont family.
sizeNumberFont size.
styleStringText style.
variantStringText variant (deprecated).
weightStringText weight.

Methods

NameReturn typeSummary
setDecoration(decoration)FontUpdates the font with the given decoration.
setFamily(family)FontSets the font family.
setSize(size)FontSets the font size.
setStyle(style)FontSets the font style.
setVariant(variant)FontSets the font variant (deprecated).
setWeight(weight)FontSets the font weight.
Constructor Details

new Font()

Creates a new Font object. This constructor takes no parameters.
Sample:
require([
  "esri/symbols/Font", ... 
], function(Font, ... ) {
  var font = new Font();
  ...
});

new Font(size?, style?, variant?, weight?, family?)

Creates a new Font object.
Parameters:
<Number | String> size Optional Font size. Values can be in "pt", "px", "em", and "%". For example: "12pt", "12px", ".8em", "80%". If no unit is specified with number, defaults to "px".
<String> style Optional Font style. See Constants table for values.
<String> variant Optional Font variant. See Constants table for values.
<String> weight Optional Font weight. See Constants table for values.
<String> family Optional Font family.
Sample:
require([
  "esri/symbols/Font", ... 
], function(Font, ... ) {
  var font = new Font("20pt", Font.STYLE_ITALIC,
    Font.VARIANT_NORMAL, Font.WEIGHT_BOLD,"Courier");
  ...
});

new Font(json)

Creates a new Font object using a JSON object.
Parameters:
<Object> json Required JSON object representing the font.
Property Details

<String> decoration

Text decoration. (Added at v3.8)
Known values: "underline" | "line-through" | "none"
Default value: "none"

<String> family

Font family.
Default value: Serif
See also: setFamily()

<Number> size

Font size.
Default value: 10
See also: setSize()

<String> style

Text style. See the Constants table for valid values.
Default value: STYLE_NORMAL
See also: setStyle()

<String> variant

Text variant (deprecated). See the Constants table for valid values.
Default value: VARIANT_NORMAL
See also: setVariant()

<String> weight

Text weight. See the Constants table for valid values.
Default value: WEIGHT_NORMAL
See also: setWeight()
Method Details

setDecoration(decoration)

Updates the font with the given decoration. (Added at v3.8)
Return type: Font
Parameters:
<String> decoration Required Text decoration. See decoration property for the list of supported decorations.

setFamily(family)

Sets the font family. The font family property does not work in Internet Explorer 7; Arial is always used.
Return type: Font
Parameters:
<String> family Required Font family.
See also: family

setSize(size)

Sets the font size. If no unit is specified with number, defaults to pixels, "px."
Return type: Font
Parameters:
<Number | String> size Required Font size. Values can be in "pt", "px", "em", and "%". For example: "12pt", "12px", ".8em", "80%". If no unit is specified with number, defaults to "px".
Sample:
font.setSize("12pt");
See also: size

setStyle(style)

Sets the font style.
Return type: Font
Parameters:
<String> style Required Font style. See Constants table for values.
See also: style

setVariant(variant)

Sets the font variant (deprecated).
Return type: Font
Parameters:
<String> variant Required Font variant. See Constants table for values.
See also: variant

setWeight(weight)

Sets the font weight.
Return type: Font
Parameters:
<String> weight Required Font weight. See Constants table for values.
Sample:
require([
  "esri/symbols/Font", ... 
], function(Font, ... ) {
  var font = new Font( ... );
  font.setWeight(Font.WEIGHT_BOLD);  
  ...
});    
See also: weight
Show Modal