WP New style sheet
WP New style sheet ( wpDoc : Object ; styleSheetType : Integer ; styleSheetName : Text {; listLevelCount : Integer} ) : Object
| Parameter | Type | Description | |
|---|---|---|---|
| wpDoc | Object | → | 4D Write Pro document |
| styleSheetType | Integer | → | Type of style sheet |
| styleSheetName | Text | → | Name of style sheet |
| listLevelCount | Integer | → | Total number of levels in the hierarchy |
| Function result | Object | ← | Style sheet object |
History
| Release | Changes |
|---|---|
| 4D 18 | Created |
| 4D 21 R3 | listLevelCount parameter added |
Description
The WP New style sheet command creates a new (empty) style sheet object for the designated wpDoc.
In the wpDoc parameter, pass a 4D Write Pro document.
The styleSheetType parameter lets you designate the type of the style sheet, i.e. the part of the wpDoc that will be affected by the style sheet. Two types are available:
- wk type character: Applies style attributes to characters.
- wk type paragraph: Applies style attributes to paragraphs (required if you want to create hierarchical list style sheets).
Pass a name for the style sheet in the styleSheetName parameter. The style sheet's name is stored with the document and facilitates reusing or modifying the style. It can also be used with the WP Get style sheet and WP DELETE STYLE SHEET commands. The style sheet name must comply with the following rules:
- it must start with a letter
- it can then contain alphanumeric characters, space characters, "-" characters or unicode characters >= 128
- it must be unique in the document regardless of the type
- it must not start with "section", which is reserved
- the "_" is replaced by a space and trailing spaces are removed.
You can specify the attributes of the style sheet using the WP SET ATTRIBUTES command or the object notation (see 4D Write Pro Attributes). For the list of available attributes, see the Style sheet attributes section.
Notes:
- A style sheet only modifies the display of a character or paragraph, not how it is stored in the document. If a style sheet is removed, the text will revert to the default style.
- Any style attributes not defined in the new style sheet will automatically use the Normal style. For more information, see the Style sheets page.
Hierarchical list style sheet
If the styleSheetType parameter is set to wk type paragraph, you can optionally pass the listLevelCount parameter to create a hierarchical list style sheet.
The listLevelCount parameter defines the total number of levels in the hierarchy. When specified (value ≥ 1), the command automatically creates a root-level style sheet and the corresponding sub-level style sheets.
The following predefined values are applied:
wk list style typeis set towk decimalwk list level indexis automatically assigned (1 for the root level, incremented for sub-levels)wk list level countis set to the specified value for all levelswk margin leftis automatically calculated (0.75 cm × level index)
If the parameter is omitted or set to 0, a standard (non-list) paragraph style sheet is created.
Example 1
The following code creates and defines a paragraph style sheet:
var $styleSheet : Object
$styleSheet:=WP New style sheet(wpArea;wk type paragraph;"Main title")
//define style sheet settings
WP SET ATTRIBUTES($styleSheet;wk font family;"Papyrus")
WP SET ATTRIBUTES($styleSheet;wk font size;"48pt")
WP SET ATTRIBUTES($styleSheet;wk text color;"red")
WP SET ATTRIBUTES($styleSheet;wk text align;wk left)
//Apply the style sheet to the first paragraph
var $Paragraphs : Collection
$Paragraphs:=WP Get elements(wpArea;wk type paragraph)
If($Paragraphs.length>0)
WP SET ATTRIBUTES($Paragraphs[0];wk style sheet;$styleSheet)
End if
Example 2
The following code creates a hierarchical list style sheet with 3 levels:
var $mainList : Object
$mainList:=WP New style sheet(wpArea; wk type paragraph; "MainList"; 3)
// The command automatically creates:
// - 1 root-level style sheet ("MainList")
// - 2 sub-level style sheets ("MainList lvl 2" and "MainList lvl 3")
Result:
-
The root style sheet has:
wk list level index= 1wk list level count= 3wk list style type=wk decimal
-
The sub-level style sheets:
- have incremented
wk list level indexvalues (2 and 3) - share the same
wk list level count - are automatically indented (0.75 cm × level index)
- reference the root style sheet through
wk root style
- have incremented
See also
Style sheets
WP DELETE STYLE SHEET
WP Get style sheet
WP Get style sheets
WP IMPORT STYLE SHEETS