You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by cx...@apache.org on 2017/04/13 11:20:52 UTC

[02/23] incubator-weex git commit: * [ios] line by line to draw

* [ios] line  by line to draw


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/c94e48b6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/c94e48b6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/c94e48b6

Branch: refs/heads/0.12-dev
Commit: c94e48b6d1ed5bbe1f9b42bd93c5c226b5008be2
Parents: be4eb0e
Author: acton393 <zh...@gmail.com>
Authored: Mon Apr 10 12:17:03 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Mon Apr 10 12:17:03 2017 +0800

----------------------------------------------------------------------
 .../WeexSDK/Sources/Component/WXTextComponent.m | 50 ++++++++++++++++++--
 1 file changed, 47 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c94e48b6/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
index d226b9a..9f8315f 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
@@ -88,7 +88,44 @@
         NSMutableAttributedString * attributedStringCopy = [_attributedString mutableCopy];
         CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge  CFAttributedStringRef)attributedStringCopy);
         CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL);
-        CTFrameDraw(frame, context);
+        
+        CFArrayRef lines = CTFrameGetLines(frame);
+        CFIndex lineCount = CFArrayGetCount(lines);
+        CGPoint lineOrigins[lineCount];
+        CTFrameGetLineOrigins(frame, CFRangeMake(0, 0), lineOrigins);
+        
+        CGFloat frameY = 0;
+        for (CFIndex index = 0; index < lineCount; index ++) {
+            CTLineRef lineRef = CFArrayGetValueAtIndex(lines, index);
+            CGFloat lineAscent;
+            CGFloat lineDescent;
+            CGFloat lineLeading;
+            
+            CTLineGetTypographicBounds(lineRef, &lineAscent, &lineDescent, &lineLeading);
+            CGPoint lineOrigin = lineOrigins[index];
+            
+            NSLog(@"lineAscent = %f",lineAscent);
+            NSLog(@"lineDescent = %f",lineDescent);
+            NSLog(@"lineLeading = %f",lineLeading);
+            
+            if (index > 0) {
+                frameY = frameY - lineAscent;
+            }else {
+                frameY = lineOrigin.y;
+            }
+            lineOrigin.x += padding.left;
+            lineOrigin.y -= padding.top;
+            NSLog(@"lines: %ld origin: %@",index, NSStringFromCGPoint(lineOrigin));
+            CGContextSetTextPosition(context, lineOrigin.x, lineOrigin.y);
+//            CTLineDraw(lineRef, context);
+            CFArrayRef runs = CTLineGetGlyphRuns(lineRef);
+            for (CFIndex runIndex = 0; runIndex < CFArrayGetCount(runs); runIndex ++) {
+                CTRunRef run = CFArrayGetValueAtIndex(runs, runIndex);
+                CTRunDraw(run, context, CFRangeMake(0, 0));
+            }
+            frameY = frameY - lineDescent;
+        }
+        
         UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
         UIGraphicsEndImageContext();
         
@@ -425,11 +462,18 @@ do {\
         paragraphStyle.alignment = _textAlign;
     }
     
+    // set default lineBreakMode
+    paragraphStyle.lineBreakMode = NSLineBreakByClipping;
+    if (_textOverflow && [_textOverflow length] > 0) {
+        if ([_textOverflow isEqualToString:@"ellipsis"])
+            paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
+    }
+    
     if (_lineHeight) {
         paragraphStyle.maximumLineHeight = _lineHeight;
         paragraphStyle.minimumLineHeight = _lineHeight;
     }
-    if (_lineHeight || _textAlign) {
+    if (_lineHeight || _textAlign || [_textOverflow length] > 0) {
         [attributedString addAttribute:(id)kCTParagraphStyleAttributeName
                                  value:paragraphStyle
                                  range:(NSRange){0, attributedString.length}];
@@ -511,7 +555,7 @@ do {\
 
 - (BOOL)adjustLineHeight
 {
-    return YES;
+    return !_coretext;
 }
 
 - (NSTextStorage *)textStorageWithWidth:(CGFloat)width