4D Write Pro: Style sheets are here

Automatically translated from English

For 4D Write Pro, 4D v18 brings good news: the arrival of style sheets! We’re thrilled to announce that you can now manage your own style sheets for paragraphs or characters.

HDI 4D Write Pro style sheets

Before going any further, you may be wondering “What about the style sheets I created with 4D Write?” We’ve got you covered, because not only are they imported, they can be applied!

A quick reminder

A couple of new commands have been added to create, delete, and import style sheets. But before diving into details, let’s refresh your memory. What are style sheets and what can be done with them?

   character style sheet

A character style sheet allows you to define how a character (or a word) is displayed and printed. You can define the font family, style, color, and other attributes such as underlining or line through, or text modification such as upper and lower case, upper case, etc.

   paragraph style sheet

A paragraph style sheet provides even more. You can use it to define margin colors, padding, tabs, borders, and much more.

How does it work

First, the style sheet must be created with the new command: WP New style sheet. Once created, the style sheet’s content must be defined using the well-known WP Set attributes command. You can add as many attributes as you want as long as the style sheet type is appropriate for the attributes. For example, you can set the wk text color attribute for a character or a paragraph style sheet, but you can only set wk margin or wk border attributes for a character style sheet.

Once all that’s done, the last thing to do is to apply the newly created style sheet to a target (paragraphs or specific texts).

What difference does it make?

Why waste time applying the same attributes individually to multiple paragraphs when you could do it all in one shot? Moreover, if you want to change anything afterward, you’ll have to do it for each paragraph (e.g. change the font family, the font size, the color.)

Now, if you apply a single style sheet to multiple paragraphs and want to make a change, you only need to change the attributes in the style sheet itself. Once updating the style sheet is done, all the modifications will be reapplied to each paragraph referring to that style sheet! A huge time savings! It’s also safer since you’re sure not to forget any paragraphs.

Example

A style sheet is an object belonging to a document. It’s created using the WP New style sheet command. Once created, you can use this object as a parameter for WP Set attributes.

Let’s create a “Blue Helvetica” paragraph style sheet where we want to display the font for the paragrah in the “Blue Helvetica” font family, 24pt, aligned on left:

styleSheet:=WP New style sheet(WParea1;wk type paragraph;"Blue Helvetica Neue")
WP SET ATTRIBUTES(styleSheet;wk font;"Helvetica Neue Condensed Black")
WP SET ATTRIBUTES(styleSheet;wk font size;"24pt")
WP SET ATTRIBUTES(styleSheet;wk text color;"blue")
WP SET ATTRIBUTES(styleSheet;wk text align;wk left)

Now let’s apply it to the first two paragraphs:

colParagraphs:=WP Get elements(WParea1;wk type paragraph)
For ($i;0;1)
WP SET ATTRIBUTES(colParagraphs[$i];wk style sheet;"Blue Helvetica Neue")
End for 

Your paragraphs should look something like this: 

 

You may change your mind and decide that you prefer green instead of blue and justified alignment instead of left aligned … simply modify two attributes and you’re done!

more commands

Five new commands have been created:

  • WP New style sheet: allows creating a style sheet
  • WP DELETE STYLE SHEET: allows deleting a style sheet
  • WP Get style sheet: allows retrieving a single style sheet by its name,
  • WP Get style sheets: fills a collection of style sheets of a given type, and finally,
  • WP IMPORT STYLE SHEETS: allows importing existing stylesheets created in another 4D Write Pro document (as a template, for example).

A note about the UI

The user interface has been improved too. Both the side panel widget (in a new tab) and the toolbar widget (in the first tab) now include stylesheet tools.

Note: The source code for both widgets is available for 4D Partners. This is also an interesting learning tool: you can use the source code to learn about 4D Write Pro commands and see how we’re using them.

Stylesheets in action

 

Roland Lannuzel

• Product Owner & 4D Expert •

After studying electronics, Roland went into industrial IT as a developer and consultant, building solutions for customers with a variety of databases and technologies. In the late 80’s he fell in love with 4D and has used it in writing business applications that include accounting, billing and email systems.

Eventually joining the company in 1997, Roland’s valuable contributions include designing specifications, testing tools, demos as well as training and speaking to the 4D community at many conferences. He continues to actively shape the future of 4D by defining new features and database development tools.