Font clause - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Specifies a text style. You can use this clause in the MapBasic window in MapInfo Pro.

Syntax

Font font_expr 

font_expr is a Font expression, for example:

MakeFont( fontname, style, size, fgcolor, bgcolor )

Description

The Font clause specifies a text style. Font is a clause, not a complete MapBasic statement. Various object-related statements, such as the Create Text statement, allow you to specify a Font setting; this lets you choose the typeface and point size of the new text object. If you omit the Font expression from a Create Text statement, the new object uses MapInfo Pro's current Font. The keyword Font may be followed by an expression that evaluates to a Font value.

This expression can be a Font variable:

Font font_var

or a call to a function (for example, CurrentFont() function or MakeFont() function) which returns a Font value:

Font MakeFont("Helvetica", 1, 12, BLACK, WHITE)

With some MapBasic statements (for example, the Set Legend statement), the keyword Font can be followed immediately by the five parameters that define a Font style (font name, style, point size, foreground color, and background color) within parentheses:

Font("Helvetica", 1, 12, BLACK, WHITE)

You can also directly assign a string-based style clause into a variable of type Font. For example,

dim fnt as Font 
fnt = "Font (""Arial"",0,9,0)" 
'this assignment will work now, and string-based font clause will convert
 Font variable.

The following table summarizes the components that define a font:

Component Description
font name A string that identifies a font. The set of available fonts depends on the user's system and the hardware platform in use.
style Integer value. Controls text attributes such as bold, italic, and underline. See table below for details.
size Integer value representing a point size. A point size of twelve is one-sixth of an inch tall.
foreground color Integer RGB color value, representing the color of the text. See Rnd() function.
background color Integer RGB color value. If the halo style is used, this is the halo color; otherwise, this is the background fill color.

To specify a transparent background style in a Font clause, omit the background color. For example: Font( "Helvetica", 1, 12, BLACK). To specify a transparent fill when calling the MakeFont() function, specify -1 as the background color.

The following table shows how the style parameter corresponds to font styles.

Style Value Description of text style
0 Plain
1 Bold
2 Italic
4 Underline
8 Strikethrough
32 Shadow
256 Halo
512 All Caps
1024 Expanded

To specify two or more style attributes, add the values from the left column. For example, to specify both the Bold and All Caps attributes, use a style value of 513.

Example

Include "MAPBASIC.DEF"
Dim o_title As Object
Create Text
	Into Variable o_title 
	"Your message could go HERE" 
	(73.5, 42.6) (73.67, 42.9)
	Font MakeFont("Helvetica",1,12,BLACK,WHITE) 

See Also:

Alter Object statement, Chr$() function, Create Text statement, RGB() function