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