title: CTRunDraw() does implement correct behaviour
body: <p>I am implementing a custom text layout algorithm on MAC OS X using CoreText. I have to partially render a portion of CTRun in different locations inside a custom NSView subclass object. </p>
  
  <p>Here is my implementation of drawRect: method</p>
  
  <pre><code>- (void)drawRect:(NSRect)dirtyRect {
  // Drawing code here.
  CGContextRef context =
  (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
  CGContextSaveGState(context); {
      [[NSColor whiteColor] set];
      NSRectFill(dirtyRect);
  
  
      CTFontRef font = CTFontCreateWithName(CFSTR("Menlo"), 20, &amp;CGAffineTransformIdentity);
  
      CFTypeRef values[] = {font};
      CFStringRef keys[] = {kCTFontAttributeName};
  
      CFDictionaryRef dictionary =
      CFDictionaryCreate(NULL,
                         (const void **)&amp;keys,
                         (const void **)&amp;values,
                         sizeof(keys) / sizeof(keys[0]),
                         &amp;kCFTypeDictionaryKeyCallBacks,
                         &amp;kCFTypeDictionaryValueCallBacks);
  
      CFAttributedStringRef longString =
      CFAttributedStringCreate(kCFAllocatorDefault, CFSTR("this_is_a_very_long_string_that_compromises_many_glyphs,we_wil_see_it:)"), dictionary);
      CTLineRef lineRef = CTLineCreateWithAttributedString(longString);
  
      CFArrayRef runsArray = CTLineGetGlyphRuns(lineRef);
      CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runsArray, 0);
  
      CGAffineTransform textTransform = CGAffineTransformIdentity;
      textTransform = CGAffineTransformScale(textTransform, 1.0, -1.0);
      CGContextSetTextMatrix(context, textTransform);
  
      CGAffineTransform sequenceTransform =
      CGAffineTransformIdentity;
      sequenceTransform = CGAffineTransformTranslate(sequenceTransform, 0, 23.2818);
  
  
      CGPoint firstPoint = CGPointApplyAffineTransform(CGPointMake(0, 0), sequenceTransform);
      CFRange firstRange = CFRangeMake(0, 24);
      CGContextSetTextPosition(context, firstPoint.x, firstPoint.y);
      CTRunDraw(run, context, firstRange);
  
      CGPoint secondPoint = CGPointApplyAffineTransform(CGPointMake(0, 26.2812), sequenceTransform);
      CFRange secondRange = CFRangeMake(24, 24);
      CGContextSetTextPosition(context, secondPoint.x, secondPoint.y);
      CTRunDraw(run, context, secondRange);
  
      CGPoint thirdPoint = CGPointApplyAffineTransform(CGPointMake(0, 52.5625), sequenceTransform);
      CFRange thirdRange = CFRangeMake(48, 23);
      CGContextSetTextPosition(context, thirdPoint.x, thirdPoint.y);
      CTRunDraw(run, context, thirdRange);
  
  }
  CGContextRestoreGState(context);
  </code></pre>
  
  <p>}</p>
  
  <p>Here is the output of this code
  <a href="https://docs.google.com/open?id=0B8df1OdxKw4FYkE5Z1d1VUZQYWs" rel="nofollow">https://docs.google.com/open?id=0B8df1OdxKw4FYkE5Z1d1VUZQYWs</a></p>
  
  <p>The problem is CTRunDraw() method inserts blank spaces on the positions other than the range specified.</p>
  
  <p>What i want is it should render the part of run at its correct position.
  Here is the correct out put which i want.(The correct output is photoshop of original output).
  <a href="https://docs.google.com/open?id=0B8df1OdxKw4FcFRnS0p1cFBfa28" rel="nofollow">https://docs.google.com/open?id=0B8df1OdxKw4FcFRnS0p1cFBfa28</a></p>
  
  <p>Note: I am using flipped coordinate system in my custom NSView subclass.</p>
  
  <pre><code>- (BOOL)isFlipped {
  return YES;
  </code></pre>
  
  <p>}</p>