-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Cairo source working on Cairo C source ignore user state reverted to OS X only version working on unit tests wiki example crashes
- Loading branch information
1 parent
cace3d0
commit 90683a4
Showing
29 changed files
with
1,235 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
Xcode/Cairo.xcodeproj/project.xcworkspace/xcuserdata/ | ||
Xcode/Cairo.xcodeproj/xcuserdata | ||
libcairo/autom4te.cache |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// Font.swift | ||
// Cairo | ||
// | ||
// Created by Alsey Coleman Miller on 5/7/16. | ||
// Copyright © 2016 PureSwift. All rights reserved. | ||
// | ||
|
||
import CCairo | ||
|
||
public enum FontSlant: cairo_font_slant_t.RawValue { | ||
|
||
case normal, italic, oblique | ||
} | ||
|
||
public enum FontWeight: cairo_font_weight_t.RawValue { | ||
|
||
case normal, bold | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// CairoTest.h | ||
// Cairo | ||
// | ||
// Created by Alsey Coleman Miller on 5/8/16. | ||
// Copyright © 2016 PureSwift. All rights reserved. | ||
// | ||
|
||
@import Foundation; | ||
|
||
@interface CairoTest : NSObject | ||
|
||
+ (void)helloWikipedia:(NSString *)filename; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// CairoTest.m | ||
// Cairo | ||
// | ||
// Created by Alsey Coleman Miller on 5/8/16. | ||
// Copyright © 2016 PureSwift. All rights reserved. | ||
// | ||
|
||
#import "CairoTest.h" | ||
#import <cairo/cairo.h> | ||
|
||
@implementation CairoTest | ||
|
||
+ (void)helloWikipedia:(NSString *)filename | ||
{ | ||
cairo_t *cr; | ||
cairo_surface_t *surface; | ||
cairo_pattern_t *pattern; | ||
int x,y; | ||
|
||
const char *cString = [filename cStringUsingEncoding: NSUTF8StringEncoding]; | ||
|
||
surface = | ||
(cairo_surface_t *)cairo_svg_surface_create(cString, 100.0, 100.0); | ||
cr = cairo_create(surface); | ||
|
||
/* Draw the squares in the background */ | ||
for (x=0; x<10; x++) | ||
for (y=0; y<10; y++) | ||
cairo_rectangle(cr, x*10.0, y*10.0, 5, 5); | ||
|
||
pattern = cairo_pattern_create_radial(50, 50, 5, 50, 50, 50); | ||
cairo_pattern_add_color_stop_rgb(pattern, 0, 0.75, 0.15, 0.99); | ||
cairo_pattern_add_color_stop_rgb(pattern, 0.9, 1, 1, 1); | ||
|
||
cairo_set_source(cr, pattern); | ||
cairo_fill(cr); | ||
|
||
/* Writing in the foreground */ | ||
cairo_set_font_size (cr, 15); | ||
cairo_select_font_face (cr, "Georgia", | ||
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); | ||
cairo_set_source_rgb (cr, 0, 0, 0); | ||
|
||
cairo_move_to(cr, 10, 25); | ||
cairo_show_text(cr, "Hallo"); | ||
|
||
cairo_move_to(cr, 10, 75); | ||
cairo_show_text(cr, "Wikipedia!"); | ||
|
||
cairo_destroy (cr); | ||
cairo_surface_destroy (surface); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// | ||
// Use this file to import your target's public headers that you would like to expose to Swift. | ||
// | ||
|
||
#import "CairoTest.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// CairoTests.swift | ||
// Cairo | ||
// | ||
// Created by Alsey Coleman Miller on 5/7/16. | ||
// Copyright © 2016 PureSwift. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import Cairo | ||
|
||
final class CairoTests: XCTestCase { | ||
|
||
func testHelloWikipedia() { | ||
|
||
let filename = outputDirectory + "helloWiki.svg" | ||
|
||
print("Writing to \(filename)") | ||
|
||
//let surface = Surface | ||
let surface = Surface(pdf: filename, width: 100, height: 100) | ||
let context = Context(surface: surface) | ||
|
||
/// Draw the squares in the background | ||
for x in 0 ..< 10 { | ||
|
||
for y in 0 ..< 10 { | ||
|
||
context.addRectangle(x: Double(x) * 10.0, y: Double(y) * 10.0, width: 5.0, height: 5.0) | ||
} | ||
} | ||
|
||
let pattern = Cairo.Pattern(radial: (start: (center: (x: 50, y: 50), radius: 5), end: (center: (x: 50, y: 50), radius: 5))) | ||
|
||
pattern.addColorStop(offset: 0.0, red: 0.75, green: 0.15, blue: 0.99) | ||
|
||
pattern.addColorStop(offset: 0.9, red: 1.00, green: 1.00, blue: 1.00) | ||
|
||
context.setSource(pattern: pattern) | ||
|
||
context.fill() | ||
|
||
// Writing in the foreground | ||
|
||
context.setFont(size: 15.0) | ||
|
||
context.setFont(face: (family: "Georgia", slant: .normal, weight: .bold)) | ||
|
||
context.setSource(color: (red: 0, green: 0, blue: 0)) | ||
|
||
context.move(to: (x: 10, y: 25)) | ||
context.show(text: "Hallo!") | ||
|
||
context.move(to: (x: 10, y: 75)) | ||
context.show(text: "Wikipedia!") | ||
|
||
let originalFile = outputDirectory + "helloWiki2.svg" | ||
|
||
CairoTest.helloWikipedia(originalFile) | ||
} | ||
|
||
func testCairoSourceX() { | ||
|
||
|
||
} | ||
} | ||
|
||
#if os(OSX) | ||
let outputDirectory = NSTemporaryDirectory() | ||
#elseif os(Linux) | ||
let outputDirectory = "/tmp/" | ||
#endif |
Oops, something went wrong.