LUALoriotPro WEB site

LoriotPro scripting documentation
Extensions for LUA language

Table of contents Search function

Print the current page Mail this  link UTUBE Channel version française

lpav.SetOption - Using the LPAV_TEXTSTYLE option

The text can be set in the rectangle in different format.

It can be aligned on the top, center of bottom of the rectangle, on the left, center or right side of the rectangle.

Mulitline text can be activated and ellipsis use when text is longer than the text box.

To change the setting add the keyword with + sign between

Exemple:

lpav.SetOption(LPAV_TEXTSTYLE,DT_SINGLELINE + DT_VCENTER + DT_CENTER )

To works the following defines should be used:

Lua Defines to add to the script

DT_BOTTOM = 0x00000008 -- Justifies the text to the bottom of the rectangle.

DT_CENTER = 0x00000001 -- Centers text horizontally in the rectangle.

DT_VCENTER = 0x00000004 -- Centers text vertically

DT_LEFT = 0x00000000 -- Aligns text to the left.

DT_RIGHT = 0x00000002 -- Aligns text to the right.

DT_TOP = 0x00000000 -- Justifies the text to the top of the rectangle.

DT_CALCRECT = 0x00000400 -- Determines the width and height of the rectangle.

DT_EDITCONTROL = 0x00002000 -- Duplicates the text-displaying characteristics of a multiline edit control.

DT_END_ELLIPSIS = 0x00008000 -- if the end of a string does not fit in the rectangle, it is truncated and ellipses are added.

DT_EXPANDTABS = 0x00000040 -- Expands tab characters.

DT_EXTERNALLEADING = 0x00000200 -- Includes the font external leading in line height.

DT_HIDEPREFIX = 0x00100000 -- Ignores the ampersand (&) prefix character in the text.

DT_INTERNAL = 0x00001000 -- Uses the system font to calculate text metrics.

DT_MODIFYSTRING = 0x00010000 -- Modifies the specified string to match the displayed text.

DT_NOCLIP = 0x00000100 -- Draws without clipping.

DT_NOFULLWIDTHCHARBREAK = 0x00080000 -- Prevents a line break at a DBCS (double-wide character string),

DT_NOPREFIX = 0x00000800

DT_PATH_ELLIPSIS = 0x00004000 -- replaces characters in the middle of the string with ellipses

DT_PREFIXONLY = 0x00200000

DT_RTLREADING = 0x00020000 -- Layout in right-to-left reading order for bidirectional text when the font selected into the hdc is a Hebrew or Arabic font.

DT_SINGLELINE = 0x00000020

DT_TABSTOP = 0x00000080 -- Change the default number (8) of characters per tab

DT_WORDBREAK = 0x00000010

DT_WORD_ELLIPSIS = 0x00040000 --Truncates any word that does not fit in the rectangle and adds ellipses.

 

Keyword detailed explanation

Value

Meaning

DT_BOTTOM

0x00000008

Justifies the text to the bottom of the rectangle. This value is used only with the DT_SINGLELINE value.

DT_CALCRECT

0x00000400

Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the lpRect parameter and extends the base of the rectangle to bound the last line of text. If the largest word is wider than the rectangle, the width is expanded. If the text is less than the width of the rectangle, the width is reduced. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.

DT_CENTER

0x00000001

Centers text horizontally in the rectangle.

DT_EDITCONTROL

0x00002000

Duplicates the text-displaying characteristics of a multiline edit control. Specifically, the average character width is calculated in the same manner as for an edit control, and the function does not display a partially visible last line.

DT_END_ELLIPSIS

0x00008000

For displayed text, if the end of a string does not fit in the rectangle, it is truncated and ellipses are added. If a word that is not at the end of the string goes beyond the limits of the rectangle, it is truncated without ellipses.

The string is not modified unless the DT_MODIFYSTRING flag is specified.

Compare with DT_PATH_ELLIPSIS and DT_WORD_ELLIPSIS.

DT_EXPANDTABS

0x00000040

Expands tab characters. The default number of characters per tab is eight. The DT_WORD_ELLIPSIS, DT_PATH_ELLIPSIS, and DT_END_ELLIPSIS values cannot be used with the DT_EXPANDTABS value.

DT_EXTERNALLEADING

0x00000200

Includes the font external leading in line height. Normally, external leading is not included in the height of a line of text.

DT_HIDEPREFIX

0x00100000

Ignores the ampersand (&) prefix character in the text. The letter that follows will not be underlined, but other mnemonic-prefix characters are still processed.

Example:

input string: "A&bc&&d"

normal: "Abc&d"

DT_HIDEPREFIX: "Abc&d"

Compare with DT_NOPREFIX and DT_PREFIXONLY.

DT_INTERNAL

0x00001000

Uses the system font to calculate text metrics.

DT_LEFT

0x00000000

Aligns text to the left.

DT_MODIFYSTRING

0x00010000

Modifies the specified string to match the displayed text. This value has no effect unless DT_END_ELLIPSIS or DT_PATH_ELLIPSIS is specified.

DT_NOCLIP

0x00000100

Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.

DT_NOFULLWIDTHCHARBREAK

0x00080000

Prevents a line break at a DBCS (double-wide character string), so that the line breaking rule is equivalent to SBCS strings. For example, this can be used in Korean windows, for more readability of icon labels. This value has no effect unless DT_WORDBREAK is specified.

DT_NOPREFIX

0x00000800

Turns off processing of prefix characters. Normally, DrawText interprets the mnemonic-prefix character & as a directive to underscore the character that follows, and the mnemonic-prefix characters && as a directive to print a single &. By specifying DT_NOPREFIX, this processing is turned off. For example,

Example:

input string: "A&bc&&d"

normal: "Abc&d"

DT_NOPREFIX: "A&bc&&d"

Compare with DT_HIDEPREFIX and DT_PREFIXONLY.

DT_PATH_ELLIPSIS

0x00004000

For displayed text, replaces characters in the middle of the string with ellipses so that the result fits in the specified rectangle. If the string contains backslash (\) characters, DT_PATH_ELLIPSIS preserves as much as possible of the text after the last backslash.

The string is not modified unless the DT_MODIFYSTRING flag is specified.

Compare with DT_END_ELLIPSIS and DT_WORD_ELLIPSIS.

DT_PREFIXONLY

0x00200000

Draws only an underline at the position of the character following the ampersand (&) prefix character. Does not draw any other characters in the string. For example,

Example:

input string: "A&bc&&d"n

normal: "Abc&d"

DT_PREFIXONLY: " _ "

Compare with DT_HIDEPREFIX and DT_NOPREFIX.

DT_RIGHT

0x00000002

Aligns text to the right.

DT_RTLREADING

0x00020000

Layout in right-to-left reading order for bidirectional text when the font selected into the hdc is a Hebrew or Arabic font. The default reading order for all text is left-to-right.

DT_SINGLELINE

0x00000020

Displays text on a single line only. Carriage returns and line feeds do not break the line.

DT_TABSTOP

0x00000080

Sets tab stops. Bits 15-8 (high-order byte of the low-order word) of the uFormat parameter specify the number of characters for each tab. The default number of characters per tab is eight. The DT_CALCRECT, DT_EXTERNALLEADING, DT_INTERNAL, DT_NOCLIP, and DT_NOPREFIX values cannot be used with the DT_TABSTOP value.

DT_TOP

0x00000000

Justifies the text to the top of the rectangle.

DT_VCENTER

0x00000004

Centers text vertically. This value is used only with the DT_SINGLELINE value.

DT_WORDBREAK

0x00000010

Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the lpRect parameter. A carriage return-line feed sequence also breaks the line.

If this is not specified, output is on one line.

DT_WORD_ELLIPSIS

0x00040000

Truncates any word that does not fit in the rectangle and adds ellipses.

Compare with DT_END_ELLIPSIS and DT_PATH_ELLIPSIS.

 

Script example

The following Script show example of usage of the lpav.SetOption(LPAV_TEXTSTYLE,keyword)

 

-- LoriotPro V6.00

-- To run correctly this file is located to bin/config/script

-- Input values

-- lp_index index for this script ".1"

-- lp_oid SNMP OID for this script "ifnumber"

-- lp_host default ip address for this script "127.0.0.1"

-- Output Values

   lp_value = 0;

   lp_buffer ="error";

dofile(lp.GetPath().."/config/script/loriotinit.lua"); -- to support define

-- lp.InitLuaPath(); -- to support luaforwindows librairies and hook print function

 

dofile(lp.GetPath().."/config/script/text_format.lua"); -- to support define

 

objType=LPAV_OBJ_FILL_TEXT

x=5 y=5 l=200 h=10

lpav.Insert(x,y,l,h,objType);

lpav.SetName("format par défaut\n = DT_CENTER");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,10)

lpav.SetLineColor(0,0,0);

 

x=5 y=y+11 l=200 h=10

lpav.Insert(x,y,l,h,objType);

lpav.SetName("format par défaut");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,10)

lpav.SetOption(LPAV_TEXTSTYLE,DT_SINGLELINE + DT_VCENTER + DT_CENTER )

 

--Text on top left

x=5 y=y+21 l=200 h=20

lpav.Insert(x,y,l,h,objType);

lpav.SetName("Text on top left");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,8)

lpav.SetOption(LPAV_TEXTSTYLE,DT_TOP + DT_LEFT)

 

--Text on top center

x=l+6 y=y l=200 h=20

lpav.Insert(x,y,l,h,objType);

lpav.SetName("Text on top center");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,8)

lpav.SetOption(LPAV_TEXTSTYLE,DT_TOP + DT_CENTER)

 

--Text on top right

x=2*l+6 y=y l=200 h=20

lpav.Insert(x,y,l,h,objType);

lpav.SetName("Text on top right");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,8)

lpav.SetOption(LPAV_TEXTSTYLE,DT_TOP + DT_RIGHT)

 

--Text on vertical center left

--beware that DT_SINGLELINE is required

x=5 y=y+21 l=200 h=20

lpav.Insert(x,y,l,h,objType);

lpav.SetName("Text on vertical center left");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,8)

lpav.SetOption(LPAV_TEXTSTYLE,DT_SINGLELINE + DT_VCENTER + DT_LEFT)

 

--Text on vertical center center

--beware that DT_SINGLELINE is required

x=l+6 y=y l=200 h=20

lpav.Insert(x,y,l,h,objType);

lpav.SetName("Text on vertical center center");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,8)

lpav.SetOption(LPAV_TEXTSTYLE,DT_SINGLELINE + DT_VCENTER + DT_CENTER)

 

--Text on vertical center right

--beware that DT_SINGLELINE is required

x=2*l+6 y=y l=200 h=20

lpav.Insert(x,y,l,h,objType);

lpav.SetName("Text on vertical center right");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,8)

lpav.SetOption(LPAV_TEXTSTYLE,DT_SINGLELINE + DT_VCENTER + DT_RIGHT)

 

 

--Text on bottom left

--beware that DT_SINGLELINE is required

x=5 y=y+21 l=200 h=20

lpav.Insert(x,y,l,h,objType);

lpav.SetName("Text on bottom left");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,8)

lpav.SetOption(LPAV_TEXTSTYLE,DT_SINGLELINE + DT_LEFT + DT_BOTTOM)

 

--Text on bottom center

x=l+6 y=y l=200 h=20

lpav.Insert(x,y,l,h,objType);

lpav.SetName("Text on bottom center");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,8)

lpav.SetOption(LPAV_TEXTSTYLE,DT_SINGLELINE + DT_BOTTOM + DT_CENTER)

 

--Text on bottom right

--beware that DT_SINGLELINE is required

x=2*l+6 y=y l=200 h=20

lpav.Insert(x,y,l,h,objType);

lpav.SetName("Text on bottom right");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,8)

lpav.SetOption(LPAV_TEXTSTYLE,DT_SINGLELINE + DT_RIGHT + DT_BOTTOM)

 

--Add leading point when size of rectangle to small

-- Option  DT_WORD_ELLIPSIS

x=5 y=y+22 l=100 h=10

lpav.Insert(x,y,l,h,objType);

lpav.SetName("Add leading point when size of rectangle to small");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,10)

lpav.SetOption(LPAV_TEXTSTYLE,DT_SINGLELINE + DT_VCENTER + DT_CENTER + DT_WORD_ELLIPSIS)

 

--Multiline example

-- Option 

x=5 y=y+11 l=100 h=10

lpav.Insert(x,y,l,h,objType);

lpav.SetName("This is a multi line example\rThis is a multi line example\rThis is a multi line example\rThis is a multi line example\r");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,10)

lpav.SetOption(LPAV_TEXTSTYLE,DT_CENTER)

 

--Multiline example with word breaking

-- Option  DT_CENTER + DT_WORDBREAK

x=l+6 y=y l=100 h=10

lpav.Insert(x,y,l,h,objType);

lpav.SetName("This is a multi line example with word breaking\rThis is a multi line example with word breaking\rThis is a multi line example with word breaking\rThis is a multi line example with word breaking\r");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,10)

lpav.SetOption(LPAV_TEXTSTYLE,DT_CENTER + DT_WORDBREAK)

 

--Multiline example with word breaking and ellipsis

-- Option

x=2*l+6 y=y l=100 h=10

lpav.Insert(x,y,l,h,objType);

lpav.SetName("This is a multi line example with word \rbreaking this is a multi line example with word breaking");

lpav.SetOption(LPAV_FONTNAME,"Arial")

lpav.SetOption(LPAV_FONTSIZE,6)

lpav.SetOption(LPAV_TEXTSTYLE,DT_MODIFYSTRING  +DT_END_ELLIPSIS)

 

 

 

lpav.RefreshMap();

 

A s a result of the execution of the above script different text format option are displayed

Text Format



www.loriotpro.com