title: Line spacing in multi-language layout with Core Text
body: <p>The attributed string has only one attribute - 17 point Helvetica NeueUI font - covering the whole string. Line 1~3 are purely English, line 4~6 are mixtures of English and Chinese, line 7~8 are purely Chinese.</p>
  <p>It is then layouted with CTFramesetter and resultant frame is drawn with CTFrameDraw.</p>
  <pre><code>// UIView subclass
  - (id)initWithFrame:(CGRect)frame
  {
      self = [super initWithFrame:frame];
      if (self) {
          self.backgroundColor = [UIColor whiteColor];
          CTFontRef font = CTFontCreateWithName(CFSTR(&quot;Helvetica NeueUI&quot;), 17.f, NULL);
          _text = [[NSAttributedString alloc] initWithString:string attributes:
                   [NSDictionary dictionaryWithObject:(id)font forKey:(id)kCTFontAttributeName]];
          CFRelease(font);
          _framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)_text);
          CGMutablePathRef path = CGPathCreateMutable();
          CGPathAddRect(path, NULL, self.bounds);
          _frame = CTFramesetterCreateFrame(_framesetter, CFRangeMake(0, 0), path, NULL);
          CGPathRelease(path);
      }
      return self;
  }
  
  - (void)drawRect:(CGRect)rect
  {
      CGContextRef context = UIGraphicsGetCurrentContext();
      CGContextSaveGState(context);
      // Flip the coordinate system.
      CGContextTranslateCTM(context, 0.f, self.bounds.size.height);
      CGContextScaleCTM(context, 1.f, -1.f);
      
      CGContextSetTextMatrix(context, CGAffineTransformIdentity);
      
      CTFrameDraw(_frame, context);
      CGContextRestoreGState(context);
  }
  </code></pre>
  <p>The problem is that the space between line 7 and 8 (purely Chinese lines) is much smaller than others.</p>
  <p>For contrast, I put a <code>UILabel</code> below it, with the same font and text. Ignoring the rendering difference of single characters, you can see the line spaces in <code>UILabel</code> are uniform including the last one between two Chinese lines.</p>
  <p><a href="https://i.stack.imgur.com/Zu7WE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Zu7WE.png" alt="Screenshot" /></a><br />
  <sub>(source: <a href="https://img.skitch.com/20120226-tjxb4siwht2sa988j5r8h42wbt.png" rel="noreferrer">skitch.com</a>)</sub></p>
  <p><strong>Notice</strong>: this results above is got on a real device. If you run the same code on the simulator, you'll get very different result for the Core Text view — spaces between lines containing Chinese are much larger than others.</p>
  <ol>
  <li>Why is the space between Chinese lines smaller(larger)?</li>
  <li>How can I layout multi-language text with uniform line height using Core Text?</li>
  </ol>
  <p>PS: here is the <a href="https://d.pr/gZgi" rel="noreferrer">sample project</a> you can try yourself.</p>