File: CoreGraphics-verifyOnly.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (126 lines) | stat: -rw-r--r-- 4,335 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// RUN: %target-typecheck-verify-swift
// REQUIRES: objc_interop

import CoreGraphics

//===----------------------------------------------------------------------===//
// CGColorSpace
//===----------------------------------------------------------------------===//

// CGColorSpace.colorTable
// TODO: has memory issues as a runtime test, so make it verify-only for now
let table: [UInt8] = [0,0,0, 255,0,0, 0,0,255, 0,255,0,
 255,255,0, 255,0,255, 0,255,255, 255,255,255]
let space = CGColorSpace(indexedBaseSpace: CGColorSpaceCreateDeviceRGB(),
 last: table.count - 1, colorTable: table)!
// expectEqual(table, space.colorTable)

//===----------------------------------------------------------------------===//
// CGContext
//===----------------------------------------------------------------------===//

func testCGContext(context: CGContext, image: CGImage, glyph: CGGlyph) {
  
  context.setLineDash(phase: 0.5, lengths: [0.1, 0.2]) 

  context.move(to: CGPoint.zero) 

  context.addLine(to: CGPoint(x: 0.5, y: 0.5)) 

  context.addCurve(to: CGPoint(x: 1, y: 1), control1: CGPoint(x: 1, y: 0), control2: CGPoint(x: 0, y: 1)) 

  context.addQuadCurve(to: CGPoint(x: 0.5, y: 0.5), control: CGPoint(x: 0.5, y: 0)) 

  context.addRects([CGRect(x: 0, y: 0, width: 100, height: 100)]) 

  context.addLines(between: [CGPoint(x: 0.5, y: 0.5)]) 

  context.addArc(center: CGPoint(x: 0.5, y: 0.5), radius: 1, startAngle: 0, endAngle: .pi, clockwise: false) 

  context.addArc(tangent1End: CGPoint(x: 1, y: 1), tangent2End: CGPoint(x: 0.5, y: 0.5), radius: 0.5) 

  context.fill([CGRect(x: 0, y: 0, width: 100, height: 100)])
  
  context.fillPath()
  context.fillPath(using: .evenOdd)

  context.strokeLineSegments(between: [CGPoint(x: 0.5, y: 0.5), CGPoint(x: 0, y: 0.5)]) 

  context.clip(to: [CGRect(x: 0, y: 0, width: 100, height: 100)]) 
  
  context.clip()
  context.clip(using: .evenOdd)

  context.draw(image, in: CGRect(x: 0, y: 0, width: 100, height: 100), byTiling: true) 

  print(context.textPosition) 

  context.showGlyphs([glyph], at: [CGPoint(x: 0.5, y: 0.5)]) 

}

//===----------------------------------------------------------------------===//
// CGDirectDisplay
//===----------------------------------------------------------------------===//

#if os(macOS)
let (dx, dy) = CGGetLastMouseDelta()
#endif

//===----------------------------------------------------------------------===//
// CGImage
//===----------------------------------------------------------------------===//

func testCGImage(image: CGImage) -> CGImage? {
  return image.copy(maskingColorComponents: [1, 0, 0])
}

//===----------------------------------------------------------------------===//
// CGLayer
//===----------------------------------------------------------------------===//

func testDrawLayer(in context: CGContext) {
  let layer = CGLayer(context, size: CGSize(width: 512, height: 384),
   auxiliaryInfo: nil)!
    context.draw(layer, in: CGRect(origin: .zero, size: layer.size))
    context.draw(layer, at: CGPoint(x: 20, y: 20))
}

func testCGPath(path: CGPath) {
  
  let dashed = path.copy(dashingWithPhase: 1, lengths: [0.2, 0.3, 0.5])
  
  let stroked = path.copy(strokingWithWidth: 1, lineCap: .butt,
   lineJoin: .miter, miterLimit: 0.1)

  let mutable = stroked.mutableCopy()!
  
  // test inferred transform parameter for all below
  print(path.contains(CGPoint(x: 0.5, y: 0.5)))
  print(path.contains(CGPoint(x: 0.5, y: 0.5), using: .evenOdd))

  mutable.move(to: .zero) 

  mutable.addLine(to: CGPoint(x: 0.5, y: 0.5)) 

  mutable.addCurve(to: CGPoint(x: 1, y: 1), control1: CGPoint(x: 1, y: 0), control2: CGPoint(x: 0, y: 1)) 

  mutable.addQuadCurve(to: CGPoint(x: 0.5, y: 0.5), control: CGPoint(x: 0.5, y: 0)) 

  mutable.addRect(CGRect(x: 0, y: 0, width: 10, height: 10)) 
  mutable.addRects([CGRect(x: 0, y: 0, width: 100, height: 100)]) 

  mutable.addLines(between: [CGPoint(x: 0.5, y: 0.5)]) 

  mutable.addEllipse(in: CGRect(x: 0, y: 0, width: 50, height: 70))
  
  mutable.addArc(center: CGPoint(x: 0.5, y: 0.5), radius: 1, startAngle: 0, endAngle: .pi, clockwise: false) 

  mutable.addArc(tangent1End: CGPoint(x: 1, y: 1), tangent2End: CGPoint(x: 0.5, y: 0.5), radius: 0.5) 

  mutable.addRelativeArc(center: CGPoint(x: 1, y: 1), radius: 0.5,
   startAngle: .pi, delta: .pi/2)
  
  mutable.addPath(dashed)
  
}