Skip to content

Commit ccec4dc

Browse files
committed
feat: ios StaticLayout supports shadows….
get Width fix
1 parent 75a7a26 commit ccec4dc

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/canvas.ios.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,30 +2113,20 @@ export class StaticLayout {
21132113
}
21142114
const fullRange = { location: 0, length: nsAttributedString.length };
21152115
nsAttributedString.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, fullRange);
2116+
this.toDraw = nsAttributedString;
21162117
this.nsAttributedString.enumerateAttributesInRangeOptionsUsingBlock(fullRange, 0, (attributes: NSDictionary<string, any>, range: NSRange, p3: any) => {
21172118
nsAttributedString.addAttributesRange(attributes, range);
21182119
});
2119-
2120-
this.toDraw = nsAttributedString;
2121-
let height;
2122-
this.toDraw.enumerateAttributeInRangeOptionsUsingBlock('verticalTextAligment', fullRange, 0, (value, range) => {
2123-
if (value) {
2124-
if (!height) {
2125-
height = this.getHeight();
2126-
}
2127-
const font: UIFont = this.toDraw.attributeAtIndexEffectiveRange(NSFontAttributeName, range.location, null);
2128-
const fontHeight = font.lineHeight;
2129-
this.toDraw.addAttributeValueRange(NSBaselineOffsetAttributeName, Math.round(height / 2 - fontHeight / 2), range);
2130-
}
2131-
});
21322120
}
21332121
draw(canvas: Canvas) {
2122+
canvas.startApplyPaint(this.paint);
21342123
const ctx = canvas.ctx;
21352124
this.createAttributedStringToDraw();
21362125

21372126
UIGraphicsPushContext(ctx);
21382127
this.toDraw.drawWithRectOptionsContext(CGRectMake(0, 0, this.width, Number.MAX_VALUE), NSStringDrawingOptions.UsesLineFragmentOrigin, null);
21392128
UIGraphicsPopContext();
2129+
canvas.finishApplyPaint(this.paint);
21402130
}
21412131
getPaint() {
21422132
return this.paint;
@@ -2149,11 +2139,19 @@ export class StaticLayout {
21492139
return this.rect;
21502140
}
21512141
getWidth() {
2152-
const result = this.getBounds().size.width;
2153-
return Math.round(isNaN(result) ? this.width : result);
2142+
if (this.width) {
2143+
return this.width;
2144+
}
2145+
let result = this.getBounds().size.width;
2146+
if (isNaN(result)) {
2147+
result = this.width;
2148+
} else {
2149+
result = Math.max(result, this.width);
2150+
}
2151+
return result;
21542152
}
21552153
getHeight() {
21562154
const result = this.getBounds().size.height;
2157-
return Math.round(result);
2155+
return result;
21582156
}
21592157
}

0 commit comments

Comments
 (0)