• No results found

Single Color Fills

In document OpenOffice.org BASIC Guide (Page 156-162)

The main property for single-color fills is:

FillColor (Long)

fill color of area

To use the fill mode, you must the FillStyle property to the SOLID fill mode.

The following example creates a rectangle shape and fills it with red (RGB value 255, 0, 0):

Dim Doc As Object Dim Page As Object

Dim RectangleShape As Object

Dim Point As New com.sun.star.awt.Point Dim Size As New com.sun.star.awt.Size

The Structure of Drawings 157 Point.x = 1000 Point.y = 1000 Size.Width = 10000 Size.Height = 10000 Doc = StarDesktop.CurrentComponent Page = Doc.drawPages(0) RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape") RectangleShape.Size = Size RectangleShape.Position = Point RectangleShape.FillStyle = com.sun.star.drawing.FillStyle.SOLID RectangleShape.FillColor = RGB(255,0,0) Page.add(RectangleShape)

Color Gradient

If you set the FillStyle property to GRADIENT, you can apply a color gradient to any fill area of a OpenOffice.org document.

If you want to apply a predefined color gradient, you can assign the associated name of the FillTransparenceGradientName property. To define your own color gradient, you need to complete a

com.sun.star.awt.Gradient

structure to assign the FillGradient property. This property provides the following options:

Style (Enum)

type of gradient, for example, linear or radial (default values in accordance with com.sun.star.awt.GradientStyle

)

StartColor (Long)

start color of color gradient

EndColor (Long)

end color of color gradient

Angle (Short)

angle of color gradient in tenths of a degree

XOffset (Short)

X-coordinate at which the color gradient starts, specified in hundredths of a millimeter

The Structure of Drawings 158 Y-coordinate at which the color gradient begins, specified in hundredths of a

millimeter

StartIntensity (Short)

intensity of StartColor as a percentage (in OpenOffice.org Basic, you can also specify values higher than 100 percent)

EndIntensity (Short)

intensity of EndColor as a percentage (in OpenOffice.org Basic, you can also specify values higher than 100 percent)

StepCount (Short)

number of color graduations which OpenOffice.org is to calculate for the gradients The following example demonstrates the use of color gradients with the aid of the

com.sun.star.awt.Gradient structure:

Dim Doc As Object Dim Page As Object

Dim RectangleShape As Object

Dim Point As New com.sun.star.awt.Point Dim Size As New com.sun.star.awt.Size

Dim Gradient As New com.sun.star.awt.Gradient Point.x = 1000 Point.y = 1000 Size.Width = 10000 Size.Height = 10000 Doc = StarDesktop.CurrentComponent Page = Doc.drawPages(0) RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape") RectangleShape.Size = Size RectangleShape.Position = Point Gradient.Style = com.sun.star.awt.GradientStyle.LINEAR Gradient.StartColor = RGB(255,0,0) Gradient.EndColor = RGB(0,255,0) Gradient.StartIntensity = 150 Gradient.EndIntensity = 150 Gradient.Angle = 450 Gradient.StepCount = 100 RectangleShape.FillStyle = com.sun.star.drawing.FillStyle.GRADIENT RectangleShape.FillGradient = Gradient

The Structure of Drawings 159 Page.add(RectangleShape)

This example creates a linear color gradient (Style = LINEAR). The gradient starts with red (StartColor) in the top left corner, and extends at a 45 degree angle (Angle) to green

(EndColor) in the bottom right corner. The color intensity of the start and end colors is 150 percent (StartIntensity and EndIntensity) which results in the colors seeming brighter than the values specified in the StartColor and EndColor properties. The color gradient is

depicted using a hundred graduated individual colors (StepCount).

Hatches

To create a hatch fill, the FillStyle property must be set to HATCH. The program code for defining the hatch is very similar to the code for color gradients. Again an auxiliary structure, in this case

com.sun.star.drawing.Hatch

, is used to define the appearance of hatches. The structure for hatches has the following properties:

Style (Enum)

type of hatch: simple, squared, or squared with diagonals (default values in accordance with com.sun.star.awt.HatchStyle)

Color (Long)

color of lines

Distance (Long)

distance between lines in hundredths of a millimeter

Angle (Short)

angle of hatch in tenths of a degree

The following example demonstrates the use of a hatch structure:

Dim Doc As Object Dim Page As Object

Dim RectangleShape As Object

Dim Point As New com.sun.star.awt.Point Dim Size As New com.sun.star.awt.Size

Dim Hatch As New com.sun.star.drawing.Hatch Point.x = 1000 Point.y = 1000 Size.Width = 10000 Size.Height = 10000 Doc = StarDesktop.CurrentComponent Page = Doc.drawPages(0)

The Structure of Drawings 160 RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape") RectangleShape.Size = Size RectangleShape.Position = Point RectangleShape.FillStyle = com.sun.star.drawing.FillStyle.HATCH Hatch.Style = com.sun.star.drawing.HatchStyle.SINGLE Hatch.Color = RGB(64,64,64) Hatch.Distance = 20 Hatch.Angle = 450 RectangleShape.FillHatch = Hatch Page.add(RectangleShape)

This code creates a simple hatch structure (HatchStyle = SINGLE) whose lines are rotated 45 degrees (Angle). The lines are dark gray (Color) and are spaced is 0.2 millimeters (Distance) apart.

Bitmaps

To use bitmap projection as a fill, you must set the FillStyle property to BITMAP. If the bitmap is already available in OpenOffice.org, you just need to specify its name in the FillBitMapName property and its display style (simple, tiled, or elongated) in the FillBitmapMode property (default values in accordance with

com.sun.star.drawing.BitmapMode ).

If you want to use an external bitmap file, you can specify its URL in the FillBitmapURL property.

The following example creates a rectangle and tiles the Sky bitmap that is available in OpenOffice.org to fill the area of the rectangle:

Dim Doc As Object Dim Page As Object

Dim RectangleShape As Object

Dim Point As New com.sun.star.awt.Point Dim Size As New com.sun.star.awt.Size Point.x = 1000

Point.y = 1000 Size.Width = 10000 Size.Height = 10000

The Structure of Drawings 161 Page = Doc.drawPages(0) RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape") RectangleShape.Size = Size RectangleShape.Position = Point RectangleShape.FillStyle = com.sun.star.drawing.FillStyle.BITMAP RectangleShape.FillBitmapName = "Sky" RectangleShape.FillBitmapMode = com.sun.star.drawing.BitmapMode.REPEAT Page.add(RectangleShape)

Transparency

You can adjust the transparency of any fill that you apply. The simplest way to change the transparency of a drawing element is to use the FillTransparence property.

The following example creates a red rectangle with a transparency of 50 percent.

Dim Doc As Object Dim Page As Object

Dim RectangleShape As Object

Dim Point As New com.sun.star.awt.Point Dim Size As New com.sun.star.awt.Size Point.x = 1000 Point.y = 1000 Size.Width = 10000 Size.Height = 10000 Doc = StarDesktop.CurrentComponent Page = Doc.drawPages(0) RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape") RectangleShape.Size = Size RectangleShape.Position = Point RectangleShape.FillStyle = com.sun.star.drawing.FillStyle.SOLID RectangleShape.FillTransparence = 50 RectangleShape.FillColor = RGB(255,0,0) Page.add(RectangleShape)

The Structure of Drawings 162 In addition to the FillTransparence property, the

com.sun.star.drawing.FillProperties

service also provides the FillTransparenceGradient property. This is used to define a gradient that specifies the transparency of a fill area.

In document OpenOffice.org BASIC Guide (Page 156-162)

Related documents