1 2from PyObjCTools.TestSupport import * 3from CoreText import * 4from Foundation import NSDictionary 5from Quartz import * 6 7try: 8 long 9except NameError: 10 long = int 11 12class TestCTRun (TestCase): 13 def testTypes(self): 14 self.assertIsCFType(CTRunRef) 15 16 def testConstants(self): 17 self.assertEqual(kCTRunStatusNoStatus, 0) 18 self.assertEqual(kCTRunStatusRightToLeft, (1 << 0)) 19 self.assertEqual(kCTRunStatusNonMonotonic, (1 << 1)) 20 self.assertEqual(kCTRunStatusHasNonIdentityMatrix, (1 << 2)) 21 22 def testFunctions(self): 23 self.assertIsInstance(CTRunGetTypeID(), (int, long)) 24 25 line = CTLineCreateWithAttributedString( 26 CFAttributedStringCreate(None, b"hello world".decode('latin1'), None)) 27 self.assertIsInstance(line, CTLineRef) 28 29 run = CTLineGetGlyphRuns(line)[0] 30 self.assertIsInstance(run, CTRunRef) 31 32 v = CTRunGetGlyphCount(run) 33 self.assertIsInstance(v, (int, long)) 34 35 v = CTRunGetAttributes(run) 36 self.assertIsInstance(v, (dict, NSDictionary)) 37 38 v = CTRunGetStatus(run) 39 self.assertIsInstance(v, (int, long)) 40 41 buf = CTRunGetGlyphsPtr(run) 42 self.assertIsInstance(buf, objc.varlist) 43 self.assertIsInstance(buf[0], (int, long)) 44 45 buf = CTRunGetGlyphs(run, CFRange(0, 5), None) 46 self.assertIsInstance(buf, tuple) 47 self.assertEqual(len(buf), 5) 48 self.assertIsInstance(buf[0], (int, long)) 49 50 buf = CTRunGetPositionsPtr(run) 51 self.assertIsInstance(buf, objc.varlist) 52 self.assertIsInstance(buf[0], CGPoint) 53 54 buf = CTRunGetPositions(run, CFRange(0, 5), None) 55 self.assertIsInstance(buf, tuple) 56 self.assertEqual(len(buf), 5) 57 self.assertIsInstance(buf[0], CGPoint) 58 59 buf = CTRunGetStringIndicesPtr(run) 60 self.assertIsInstance(buf, objc.varlist) 61 self.assertIsInstance(buf[0], (int, long)) 62 63 buf = CTRunGetStringIndices(run, CFRange(0, 5), None) 64 self.assertIsInstance(buf, tuple) 65 self.assertEqual(len(buf), 5) 66 self.assertIsInstance(buf[0], (int, long)) 67 68 v = CTRunGetStringRange(run) 69 self.assertIsInstance(v, CFRange) 70 71 v = CTRunGetTypographicBounds(run, CFRange(0, 5), None, None, None) 72 self.assertIsInstance(v, tuple) 73 self.assertEqual(len(v), 4) 74 self.assertIsInstance(v[0], float) 75 self.assertIsInstance(v[1], float) 76 self.assertIsInstance(v[2], float) 77 self.assertIsInstance(v[3], float) 78 79 url = CFURLCreateWithFileSystemPath(None, 80 "/tmp/pyobjc.test.pdf", kCFURLPOSIXPathStyle, False) 81 self.assertIsInstance(url, CFURLRef) 82 83 ctx = CGPDFContextCreateWithURL(url, CGRect(CGPoint(0, 0), CGSize(1000, 1000)), None) 84 v = CTRunGetImageBounds(run, ctx, CFRange(0, 5)) 85 self.assertIsInstance(v, CGRect) 86 87 v = CTRunGetTextMatrix(run) 88 self.assertIsInstance(v, CGAffineTransform) 89 90 v = CTRunDraw(run, ctx, CFRange(0, 5)) 91 self.assertTrue(v is None) 92 93 @min_os_level('10.5') 94 def testFunctions10_5(self): 95 self.assertArgIsOut(CTRunGetAdvances, 2) 96 self.assertArgSizeInArg(CTRunGetAdvances, 2, 1) 97 98 line = CTLineCreateWithAttributedString( 99 CFAttributedStringCreate(None, b"hello world".decode('latin1'), None)) 100 self.assertIsInstance(line, CTLineRef) 101 102 run = CTLineGetGlyphRuns(line)[0] 103 self.assertIsInstance(run, CTRunRef) 104 105 r = CTRunGetAdvances(run, CFRange(1, 3), None) 106 self.assertIsInstance(r, (list, tuple)) 107 self.assertEquals(len(r), 3) 108 for i in range(3): 109 self.assertIsInstance(r[i], CGSize) 110 111 112 try: 113 CTRunGetAdvancesPtr 114 except NameError: 115 pass 116 else: 117 self.fail("CTRunGetAdvancesPtr is defined") 118 119 120if __name__ == "__main__": 121 main() 122