iPDFdev Tips & Tricks for PDF development

IFXPDFFactory – part 5 – Pens and brushes

January 10th, 2013

In the previous post I showed the color support in IFXPDFFactory. How are these colors actually used? Pens and brushes enter the scene here.

Pens are used for stroking operations while brushes are used for filling operations.

IFXPDFPen class defines a PDF pen. The following properties are available:
- IFXPDFColor* color - the color of the pen
- double width - the width of the pen
- IFXPDFLineCap lineCap - line end style, flat, square or round
- IFXPDFLineJoin lineJoin - line join style, miter, bevel or round
- double dashOffset - offset for dash pattern
- NSString* dashPattern - dash pattern style

2 initializers are available for the IFXPDFPen class:
- init - creates a black pen with a width of 1 point
- initWithColor:andWidth: - creates a pen with the specified color and width

// Create a default RGB black pen
IFXPDFPen* blackPen = [[IFXPDFPen alloc] init];
// use the pen and then release it
// ...
[blackPen release];
// or create a 5 points yellow pen
IFXPDFPen* yellowPen = [[IFXPDFPen alloc] initWithColor: [IFXPDFRgbColor yellowColor] andWidth: 5];
// ...
[yellowPen release];
// or create an autoreleased pen
IFXPDFPen* redPen = [IFXPDFPen penWithColor: [IFXPDFRgbColor redColor] andWidth: 2.5];

Any PDF color, RGB, CMYK, Gray, separation, etc, can be used with a PDF pen.

Pen properties can be changed during stroking operations, there is no need to create separate pens for each stroke.

IFXPDFPen* pen = [[IFXPDFPen alloc] init];
pen.color = [IFXPDFRgbColor redColor];
pen.width = 3;
// use the pen
// ...
pen.width = 1;
// ...
pen.color = [IFXPDFRgbColor blueColor];
// ...
pen.lineCap = IFXPDFLineCapRound;
pen.lineJoin = IFXPDFLineJoinRound;
// ...
[pen release];

IFXPDFBrush class defines a PDF brush. The brush has a single color property which sets the color for filling operations:
- IFXPDFColor* color - fill color.

2 initializers are available for the IFXPDFBrush class:
- init - creates a RGB black brush
- initWithColor: - creates a brush with the specified color

// Create a default RGB black brush
IFXPDFBrush* blackBrush = [[IFXPDFBrush alloc] init];
// ...
[blackBrush release];
// or create a yellow brush
IFXPDFBrush* yellowBrush = [IFXPDFBrush alloc] initWithColor: [IFXPDFRgbColor yellowColor]];
// ...
[yellowBrush release];
// or use an autoreleased brush
IFXPDFBrush* redBrush = [IFXPDFBrush brushWithColor: [IFXPDFRgbColor redColor]];

The brush color can also be changed between filling operations.

IFXPDFBrush* brush = [[IFXPDFBrush alloc] init];
// ...
brush.color = [IFXPDFRgbColor redColor];
// ...
brush.color = [IFXPDFRgbColor greenColor];
// ...
[brush release];
Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.