CorelDraw & VBA
Back to the Main Menu
VBA Introduction
Artistic Text
Paragraph Text
Finding & Changing Text
Master Layers
Opening Other Applications
User Interface
Event Programming
Storing User Data
Error Handling
Speeding Up CorelDraw
VBA Security
Guide to CorelDraw VBA

The Automatic Creation of Artistic Text

CreateArtisticText creates text of the appropriate font, size, font style and position.
It has poor horizontal positioning and you should apply secondary horizontal positioning.

The full nomenclature to create artistic text is as follows.
CreateArtisticText(Left As Double,
    Bottom As Double,
    Text As String,
    [LanguageID As cdrTextLanguage = cdrLanguageNone],
    [CharSet As cdrTextCharSet = cdrCharSetMixed],
    [Font As String],
    [Size As Single],
    [Bold As cdrTriState = cdrUndefined],
    [Italic As cdrTriState = cdrUndefined],
    [Underline As cdrFontLine = cdrMixedFontLine],
    [Alignment As cdrAlignment = cdrMixedAlignment]) As Shape

Left specifies the horizontal position of the of the text in inches.
The position is either the left end, right end or centre of the text.
The alignment is specified by the cdrAlignment.
However it never horizontally positions the text in perfect position.
You should reposition the text after it is created.

Bottom specifies the position of the characters containing straight lines such as A, H, f and 1 in inches.
The non-straight line characters will be slightly below the correct position. This is dependant on the font.
Rounded lowercase characters and those with tails are a, b, c, d, e, g, j, o, p, q, s, u & y.
Rounded capital characters are C, G, J, O, Q, S, U
Similarly rounded numbers are 0, 3, 5, 6 & 8.
Any underlines are further below the position specified.

LanguageID is not normally changed from the default so leave this blank.

Charset like the language leave this blank.

Font is usually specified unless you want to use the default font in which case you leave blank.

Size is the font size in points. If you leave it blank it will be the default font size.

Bold specifies whether the text is bold or not.
This will accept 1 or 3 options cdrFalse, cdrTrue or cdrUndefined.
It will also accept True or False without the cdr prefix.
If you leave it blank the default is false.
Some fonts such as AvantGarde Md BT cannot be made bold. Attempting to make them bold does not cause an error.

TriState ConstantsValueDescription
cdrFalse0Specifies False
cdrTrue-1Specifies True
cdrUndefined-2Specifies Undefined

Italic like Bold is tristate, it will except cdrFalse, cdrTrue or cdrUndefined.
If you leave it blank the default is false.
Some fonts such as AvantGarde Md BT cannot be made italic. Attempting to make them italic does not cause an error.

Underline can have 1 of 8 values or you can leave blank to accept the default No Under Line.
UnderLine ConstantsValueDescription
cdrNoFontLine0 Specifies no font line
cdrSingleThinFontLine1 Specifies thin font line including under spaces
cdrSingleThinWordFontLine2 Specifies thin font line only under words
cdrSingleThickFontLine3 Specifies thick font line including under spaces
cdrSingleThickWordFontLine4 Specifies thin font line only under words
cdrDoubleThinFontLine5 Specifies double-thin font line including under spaces
cdrDoubleThinWordFontLine6 Specifies double-thin font line only under words
cdrMixedFontLine7 Specifies mixed font line. How does this work?

Alignment can have 1 or 7 positions. Leaving blank means left align in Western countries.
Alignment ConstantsValueDescription
cdrNoAlignment0Specifies no alignment but in effect is the same as cdrLeftAlignment.
cdrLeftAlignment1Specifies the left side of the text plus approximately> 0.1 to 0.3mm to the right depending on the character and font. Why?
cdrRightAlignment2Specifies the right side of the text but is too far to the left. The distance to the left increases with font size.
If the text is italic the last character will be slightly too right.
cdrCenterAlignment3Specifiescentre alignment
cdrFullJustifyAlignment4 Left align text and full justification for mutiple lines of artistic text.
cdrForceJustifyAlignment5 Left align text and forces justification for mutiple lines of artistic text.
cdrMixedAlignment6 Specifies mixed alignment but in effect seems the same as cdrLeftAlignment

Here is a some sample code to create artistic text.

    Dim shText as Shape
    Set shText = CorelDRAW.ActiveDocument.ActivePage.ActiveLayer.CreateArtisticText(30 / 25.4, 50 / 25.4, "Hello" & vbCr & "World", , , "Arial", 12, True, False, , cdrLeftAlignment)
    shText.LeftX = 30 / 25.4
    shText.Fill.UniformColor.CMYKAssign 0, 0, 0, 100
    Set shText = Nothing

The 1st line defines a variable shText as being a shape. The code reserves computer memory to store the properties of a shape.
You can use this variable to refer to the shape.

The 2nd line creates the artistic text, shText, on the active layer of the active page.
If you want page 3 you could substitutePages(3).Layers(2) for .ActivePage.ActiveLayer
Use Layers(2) not Layers(1) as Layers(1) is the Guides layer.
The text is to be 30mm from the left edge of the page & the first line is 50mm from the bottom edge.
CorelDraw works in inches. If you work in millimetres, as I do, you must divide your millimetres by 25.4 to convert to inches for CorelDraw.
The text is Hello World with a carriage return between.
The vbCr represents a carriage return so there will be a second line of text containing the word World.
If the text was to be on one line the text would have been "Hello World".
Leave the LanguageID & CharSet as the default.
The font is Arial and its size is 12 point.
The text is to be Bold, not Italic and not UnderLined.
Alignment is left so that the left end of text will be approximately 30mm from the edge of the page.

The 3rd line is to accurately position the text.
Its a fault of CorelDraw but CreateArtisticText never places the text in the exact horizontal position requested.
Notice that the code requires inches so if using millimetres divide by 25.4 to convert to inches.
The start of line 2 could have been Set shText = CreateArtisticText(0, ....... to position the text at the page edge.
Line 3 would have still positioned the text 30mm from the edge.
If you want to position the right side of the text at 30mm use;
    shText.RightX = 30 / 25.4
If you want to position the centre of the text at 30mm use;
    shText.LeftX = 30 / 25.4 - (shText.SizeWidth)/2
The line above takes the centre of where the text should be and subtracts half of the width of the text.
The answer is where the left edge must be to place the centre in position at 30mm.

The 4th line is to fill the text with black color.
It is not necessary if you are happy with the default fill color.
For CMYK colors use;
Fill.UniformColor.CMYKAssign Cyan, Magenta, Yellow, Black
All 4 CMYK colors can vary from 0 to 100 inclusive.
Alternatively for RGB colors you would use;
Fill.UniformColor.RGBAssign Red, Green, Blue
All 3 RGB colors can vary from 0 to 255 inclusive.
Remember all color printers use CMYK and they should not print more than a total color of 300 for a dry toner printer.
ie Cyan + Magenta + Yellow + Black should not exceed 300.
Exceeding 300 can cause the dry toner to separate from the paper.

The 5th line is to avoid memory problems.
It releases the computer memory that stored the properties of shText so the memory becomes available for other uses.
For repetitive tasks this memory can build up and become a problem.
For every set you need at least one Set ....... = Nothing.
After this line you cannot use shText to refer to the shape again.

If you want to stretch the artistic text you can use;
shText.Stretch Width Enlargement, Height Enlargement
The code on the next line will half the width and double the height.
    shText.Stretch 0.5, 2

Another way to stretch the text is to specify the final width and height.
The 2 lines below alter the width to 20mm and the height to 3mm.
    shText.SizeHeight = 3 / 25.4
    shText.SizeWidth = 20 / 25.4

Altering text height automatically changes the font size.
Therefore, alternatively, you can change the text height by altering the font size and setting only the text width.
shText.Text.Story.Size in the line below is the font size.
    shText.Text.Story.Size = 24
    shText.SizeWidth = 20 / 25.4