//
//  IFXPDFAffineTransformsSample.m
//  IFXPDFFactory-iOS-SamplesBrowser
//
//  Created by Sorin Nistor on 11/11/13.
//  Copyright (c) 2013 IFXFactory. All rights reserved.
//

#import "IFXPDFAffineTransformsSample.h"

@implementation IFXPDFAffineTransformsSample

+ (IFXPDFDocument*) run
{
    IFXPDFDocument* pdfDocument = [[IFXPDFDocument alloc] init];
    IFXPDFPage* page = [IFXPDFPage emptyPage];
    [pdfDocument.pages addPage:page];
    
    IFXPDFBrush* blackBrush = [IFXPDFBrush brushWithColor:[IFXPDFRgbColor blackColor]];
    
    IFXPDFFont* titleFont = [[IFXPDFFont alloc] init];
    titleFont.fontFace = IFXPDFHelveticaBoldFontFace;
    titleFont.size = 16;
    IFXPDFFont* sectionFont = [[IFXPDFFont alloc] init];
    sectionFont.fontFace = IFXPDFHelveticaFontFace;
    sectionFont.size = 10;
    
    [page.graphics drawText:@"Affine transforms" withFont:titleFont brush:blackBrush atX:20 y:50];
    [page.graphics drawText:@"Translate, rotate and scale" withFont:sectionFont brush:blackBrush atX:20 y:70];
    
    IFXPDFPen* pen = [IFXPDFPen penWithColor:[IFXPDFRgbColor blackColor] andWidth:1];
    [page.graphics drawLineWithPen:pen fromX1:0 y1:page.height/2 toX2:page.width y2:page.height/2];
    [page.graphics drawLineWithPen:pen fromX1:page.width/2 y1:0 toX2:page.width/2 y2:page.height];
    
    // Translate the origin of the coordinate system to the center of the page.
    [page.graphics translateTransformWithTx:page.width/2 andTy:page.height/2];
    // Draw a rectangle with its center at (0, 0)
    pen.color = [IFXPDFRgbColor redColor];
    [page.graphics drawRectangleWithPen:pen atX:-150 y:-100 withWidth:300 height:200];
    
    // Rotate the coordinate system with 30 degrees.
    [page.graphics rotateTransformWithAngle:30];
    // Draw a rectangle with its center at (0, 0)
    pen.color = [IFXPDFRgbColor greenColor];
    [page.graphics drawRectangleWithPen:pen atX:-150 y:-100 withWidth:300 height:200];
    
    // Scale the coordinate system by 1.5.
    [page.graphics scaleTransformWithSx:1.5 andSy:1.5];
    // Draw a rectangle with its center at (0, 0)
    pen.color = [IFXPDFRgbColor blueColor];
    [page.graphics drawRectangleWithPen:pen atX:-150 y:-100 withWidth:300 height:200];
    
    return pdfDocument;
}

@end