//
// IFXPDFBezierCurvesSample.m
// IFXPDFFactory-iOS-SamplesBrowser
//
// Created by Sorin Nistor on 10/8/13.
// Copyright (c) 2013 IFXFactory. All rights reserved.
//
#import "IFXPDFBezierCurvesSample.h"
@implementation IFXPDFBezierCurvesSample
+ (IFXPDFDocument*) run
{
IFXPDFDocument* pdfDocument = [[IFXPDFDocument alloc] init];
IFXPDFPage* page = [IFXPDFPage emptyPage];
[pdfDocument.pages addPage:page];
IFXPDFBrush* blackBrush = [IFXPDFBrush brushWithColor:[IFXPDFRgbColor blackColor]];
IFXPDFPen* blackPen = [IFXPDFPen penWithColor:[IFXPDFRgbColor blackColor] andWidth:1];
IFXPDFPen* lightGreenPen = [IFXPDFPen penWithColor:[IFXPDFRgbColor lightGreenColor] andWidth:8];
IFXPDFBrush* darkRedBrush = [IFXPDFBrush brushWithColor:[IFXPDFRgbColor darkRedColor]];
IFXPDFFont* titleFont = [[IFXPDFFont alloc] init];
titleFont.fontFace = IFXPDFHelveticaFontFace;
titleFont.size = 16;
IFXPDFFont* sectionFont = [[IFXPDFFont alloc] init];
sectionFont.fontFace = IFXPDFHelveticaFontFace;
sectionFont.size = 10;
[page.graphics drawText:@"Bezier curves" withFont:titleFont brush:blackBrush atX:20 y:50];
[page.graphics drawLineWithPen:blackPen fromX1:20 y1:210 toX2:600 y2:210];
[page.graphics drawLineWithPen:blackPen fromX1:306 y1:70 toX2:306 y2:350];
[page.graphics drawRectangleWithBrush:darkRedBrush atX:39 y:339 withWidth:2 height:2];
[page.graphics drawRectangleWithBrush:darkRedBrush atX:279 y:79 withWidth:2 height:2];
[page.graphics drawRectangleWithBrush:darkRedBrush atX:499 y:299 withWidth:2 height:2];
[page.graphics drawRectangleWithBrush:darkRedBrush atX:589 y:69 withWidth:2 height:2];
[page.graphics drawBezierWithPen:lightGreenPen atX1:40 y1:340 x2:280 y2:80 x3:500 y3:300 x4:590 y4:70];
[page.graphics drawText:@"Random bezier curves" withFont:sectionFont brush:blackBrush atX:20 y:380];
IFXPDFPath* clipPath = [[IFXPDFPath alloc] init];
[clipPath rectangleAtX:20 y:400 withWidth:570 height:350 rotation:0];
[page.graphics saveGraphicsState];
[page.graphics setClippingPath:clipPath];
IFXPDFRgbColor* randomColor = [[IFXPDFRgbColor alloc] init];
IFXPDFPen* randomPen = [IFXPDFPen penWithColor:randomColor andWidth:1];
int w = page.width;
srand(time(NULL));
for (int i = 0; i < 50; i++) {
randomColor.red = (rand() % 256) / 255.0;
randomColor.green = (rand() % 256) / 255.0;
randomColor.blue = (rand() % 256) / 255.0;
double x1 = rand() % w;
double y1 = 380 + rand() % 350;
double x2 = rand() % w;
double y2 = 380 + rand() % 350;
double x3 = rand() % w;
double y3 = 380 + rand() % 350;
double x4 = rand() % w;
double y4 = 380 + rand() % 350;
[page.graphics drawBezierWithPen:randomPen atX1:x1 y1:y1 x2:x2 y2:y2 x3:x3 y3:y3 x4:x4 y4:y4];
}
[page.graphics restoreGraphicsState];
return pdfDocument;
}
@end