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:53 UTC
[03/23] incubator-weex git commit: Merge remote-tracking branch
'upstream/0.12-dev' into iOS-0.12-dev-text-refactor
Merge remote-tracking branch 'upstream/0.12-dev' into iOS-0.12-dev-text-refactor
# Conflicts:
# ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/24f3a30f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/24f3a30f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/24f3a30f
Branch: refs/heads/0.12-dev
Commit: 24f3a30fc633cf37428c2af0198aa1c24e4017ca
Parents: c94e48b b22d7b5
Author: acton393 <zh...@gmail.com>
Authored: Mon Apr 10 15:01:20 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Mon Apr 10 15:01:20 2017 +0800
----------------------------------------------------------------------
.../main/java/com/taobao/weex/WXSDKManager.java | 10 +-
.../weex/appfram/pickers/WXPickersModule.java | 172 +++++-
.../com/taobao/weex/bridge/WXBridgeManager.java | 3 +
.../java/com/taobao/weex/common/Constants.java | 2 +
.../taobao/weex/dom/DOMActionContextImpl.java | 2 +-
.../ui/component/AbstractEditComponent.java | 48 ++
.../taobao/weex/ui/component/WXComponent.java | 23 +-
.../com/taobao/weex/ui/component/WXSlider.java | 81 ++-
.../component/helper/SoftKeyboardDetector.java | 334 +++++++++++
.../taobao/weex/ui/view/WXCircleViewPager.java | 21 +-
.../taobao/weex/ui/view/gesture/WXGesture.java | 14 +
.../java/com/taobao/weex/utils/ATagUtil.java | 8 +-
examples/component/list/list-basic.we | 72 +--
examples/component/scroller-demo.we | 64 +-
examples/vue/index.vue | 10 +-
examples/vue/showcase/compositing.vue | 89 +++
ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 8 +
.../WeexSDK/Sources/Bridge/WXBridgeContext.m | 4 +
ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m | 77 +++
.../Component/Recycler/WXRecyclerComponent.m | 1 +
.../WeexSDK/Sources/Component/WXCellComponent.m | 10 +-
.../Sources/Component/WXComponent_internal.h | 8 +-
.../Sources/Component/WXCycleSliderComponent.h | 18 +
.../Sources/Component/WXCycleSliderComponent.m | 594 +++++++++++++++++++
.../Sources/Component/WXImageComponent.m | 90 ++-
.../Sources/Component/WXIndicatorComponent.h | 8 +
.../Sources/Component/WXIndicatorComponent.m | 16 +-
.../WeexSDK/Sources/Component/WXListComponent.m | 2 +
.../Sources/Component/WXSliderComponent.m | 5 +-
.../Component/WXSliderNeighborComponent.h | 3 +
.../Component/WXSliderNeighborComponent.m | 5 +-
.../WeexSDK/Sources/Component/WXTextComponent.m | 254 ++++----
.../Sources/Display/WXComponent+Display.m | 219 ++++---
ios/sdk/WeexSDK/Sources/Display/WXRoundedRect.h | 4 +
.../WeexSDK/Sources/Display/WXRoundedRect.mm | 10 +
ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m | 1 +
.../Sources/Manager/WXComponentManager.h | 4 +
.../Sources/Manager/WXComponentManager.m | 5 +
ios/sdk/WeexSDK/Sources/Model/WXComponent.h | 74 ++-
ios/sdk/WeexSDK/Sources/Model/WXComponent.m | 12 +-
ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m | 3 +
.../WeexSDK/Sources/Protocol/WXBridgeProtocol.h | 4 +
ios/sdk/WeexSDK/Sources/Utility/WXDefine.h | 11 +
ios/sdk/WeexSDK/Sources/Utility/WXType.h | 5 +
.../Sources/View/WXComponent+ViewManagement.m | 3 +
test/pages/components/recycler.vue | 29 +-
test/pages/slider-infinite.vue | 49 ++
test/scripts/components/recycler.test.js | 162 ++---
test/scripts/components/slider-infinite.test.js | 38 ++
49 files changed, 2178 insertions(+), 511 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/24f3a30f/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
----------------------------------------------------------------------
diff --cc ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
index 9f8315f,42fccfb..b9d4760
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
@@@ -215,16 -99,6 +112,11 @@@
{
self = [super initWithRef:ref type:type styles:styles attributes:attributes events:events weexInstance:weexInstance];
if (self) {
- if (_isUsingTextStorageLock) {
- pthread_mutexattr_init(&_textStorageMutexAttr);
- pthread_mutexattr_settype(&_textStorageMutexAttr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(&_textStorageMutex, &_textStorageMutexAttr);
- }
+ if (attributes[@"coretext"]) {
+ _coretext = [WXConvert BOOL:attributes[@"coretext"]];
+ } else {
+ _coretext = YES;
+ }
[self fillCSSStyles:styles];
[self fillAttributes:attributes];
}
@@@ -323,14 -187,7 +205,8 @@@ do {
- (void)viewDidLoad
{
- if (_isUsingTextStorageLock) {
- pthread_mutex_lock(&_textStorageMutex);
- }
((WXText *)self.view).textStorage = _textStorage;
+ ((WXText *)self.view).attributedString = [self buildCTAttributeString];
- if (_isUsingTextStorageLock) {
- pthread_mutex_unlock(&_textStorageMutex);
- }
[self setNeedsDisplay];
}
@@@ -607,14 -382,8 +474,8 @@@
[self.weexInstance.componentManager _addUITask:^{
if ([self isViewLoaded]) {
- if (_isUsingTextStorageLock) {
- pthread_mutex_lock(&_textStorageMutex);
- }
((WXText *)self.view).textStorage = textStorage;
-
+ ((WXText *)self.view).attributedString = attributedString;
- if (_isUsingTextStorageLock) {
- pthread_mutex_unlock(&_textStorageMutex);
- }
[self readyToRender]; // notify super component
[self setNeedsDisplay];
}
@@@ -645,6 -414,29 +506,89 @@@
[self syncTextStorageForView];
}
+ - (void)drawTextWithContext:(CGContextRef)context bounds:(CGRect)bounds padding:(UIEdgeInsets)padding view:(WXText *)view
+ {
+ if (bounds.size.width <=0 || bounds.size.height <= 0) {
+ return;
+ }
+
+ if ([self _needsDrawBorder]) {
+ [self _drawBorderWithContext:context size:bounds.size];
+ } else {
+ WXPerformBlockOnMainThread(^{
+ [self _resetNativeBorderRadius];
+ });
+ }
- NSLayoutManager *layoutManager = (view ? view.textStorage : _textStorage).layoutManagers.firstObject;
- NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
-
- CGRect textFrame = UIEdgeInsetsInsetRect(bounds, padding);
- NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
-
- [layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:textFrame.origin];
- [layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:textFrame.origin];
++ if (!self.coretext) {
++ NSLayoutManager *layoutManager = _textStorage.layoutManagers.firstObject;
++ NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
++
++ CGRect textFrame = UIEdgeInsetsInsetRect(bounds, padding);
++ NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
++
++ [layoutManager drawBackgroundForGlyphRange:glyphRange atPoint:textFrame.origin];
++ [layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:textFrame.origin];
++ }else {
++ CGRect textFrame = UIEdgeInsetsInsetRect(bounds, padding);
++ // sufficient height for text to draw, or frame lines will be empty
++ textFrame.size.height = bounds.size.height*2;
++
++ //flip the coordinate system
++ CGContextRetain(context);
++ CGContextSetTextMatrix(context, CGAffineTransformIdentity);
++ CGContextTranslateCTM(context, 0, textFrame.size.height);
++ CGContextScaleCTM(context, 1.0, -1.0);
++
++ //add path
++ CGMutablePathRef path = CGPathCreateMutable();
++ CGPathAddRect(path, NULL, textFrame);
++ NSMutableAttributedString * attributedStringCopy = [self buildCTAttributeString];
++ CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)attributedStringCopy);
++ CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL);
++
++ 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;
++ }
++
++ CFRelease(frame);
++ CFRelease(framesetter);
++ CGPathRelease(path);
++ }
+ }
+
#ifdef UITEST
- (NSString *)description
{