mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-07 00:42:31 +00:00
fix: Text color doesn't work with inlineSize #1225
This commit is contained in:
@@ -421,7 +421,7 @@ abstract public class RenderableView extends VirtualView {
|
|||||||
* Sets up paint according to the props set on a view. Returns {@code true}
|
* Sets up paint according to the props set on a view. Returns {@code true}
|
||||||
* if the fill should be drawn, {@code false} if not.
|
* if the fill should be drawn, {@code false} if not.
|
||||||
*/
|
*/
|
||||||
private boolean setupFillPaint(Paint paint, float opacity) {
|
boolean setupFillPaint(Paint paint, float opacity) {
|
||||||
if (fill != null && fill.size() > 0) {
|
if (fill != null && fill.size() > 0) {
|
||||||
paint.reset();
|
paint.reset();
|
||||||
paint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
|
paint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
|
||||||
@@ -436,7 +436,7 @@ abstract public class RenderableView extends VirtualView {
|
|||||||
* Sets up paint according to the props set on a view. Returns {@code true}
|
* Sets up paint according to the props set on a view. Returns {@code true}
|
||||||
* if the stroke should be drawn, {@code false} if not.
|
* if the stroke should be drawn, {@code false} if not.
|
||||||
*/
|
*/
|
||||||
private boolean setupStrokePaint(Paint paint, float opacity) {
|
boolean setupStrokePaint(Paint paint, float opacity) {
|
||||||
paint.reset();
|
paint.reset();
|
||||||
double strokeWidth = relativeOnOther(this.strokeWidth);
|
double strokeWidth = relativeOnOther(this.strokeWidth);
|
||||||
if (strokeWidth == 0 || stroke == null || stroke.size() == 0) {
|
if (strokeWidth == 0 || stroke == null || stroke.size() == 0) {
|
||||||
|
|||||||
@@ -93,7 +93,12 @@ class TSpanView extends TextView {
|
|||||||
void draw(Canvas canvas, Paint paint, float opacity) {
|
void draw(Canvas canvas, Paint paint, float opacity) {
|
||||||
if (mContent != null) {
|
if (mContent != null) {
|
||||||
if (mInlineSize != null && mInlineSize.value != 0) {
|
if (mInlineSize != null && mInlineSize.value != 0) {
|
||||||
drawWrappedText(canvas, paint);
|
if (setupFillPaint(paint, opacity * fillOpacity)) {
|
||||||
|
drawWrappedText(canvas, paint);
|
||||||
|
}
|
||||||
|
if (setupStrokePaint(paint, opacity * strokeOpacity)) {
|
||||||
|
drawWrappedText(canvas, paint);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
int numEmoji = emoji.size();
|
int numEmoji = emoji.size();
|
||||||
if (numEmoji > 0) {
|
if (numEmoji > 0) {
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
- (BOOL)applyStrokeColor:(CGContextRef)context opacity:(CGFloat)opacity;
|
- (BOOL)applyStrokeColor:(CGContextRef)context opacity:(CGFloat)opacity;
|
||||||
|
|
||||||
|
- (CGColorRef)getColorWithOpacity:(CGFloat)opacity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @abstract
|
* @abstract
|
||||||
* paint fills the context with a brush. The context is assumed to
|
* paint fills the context with a brush. The context is assumed to
|
||||||
|
|||||||
@@ -29,6 +29,11 @@
|
|||||||
CGColorRelease(_color);
|
CGColorRelease(_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (CGColorRef)getColorWithOpacity:(CGFloat)opacity
|
||||||
|
{
|
||||||
|
return CGColorCreateCopyWithAlpha(_color, opacity * CGColorGetAlpha(_color));
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)applyFillColor:(CGContextRef)context opacity:(CGFloat)opacity
|
- (BOOL)applyFillColor:(CGContextRef)context opacity:(CGFloat)opacity
|
||||||
{
|
{
|
||||||
CGColorRef color = CGColorCreateCopyWithAlpha(_color, opacity * CGColorGetAlpha(_color));
|
CGColorRef color = CGColorCreateCopyWithAlpha(_color, opacity * CGColorGetAlpha(_color));
|
||||||
|
|||||||
+29
-2
@@ -84,7 +84,33 @@ static CGFloat RNSVGTSpan_radToDeg = 180 / (CGFloat)M_PI;
|
|||||||
if (self.content) {
|
if (self.content) {
|
||||||
RNSVGGlyphContext* gc = [self.textRoot getGlyphContext];
|
RNSVGGlyphContext* gc = [self.textRoot getGlyphContext];
|
||||||
if (self.inlineSize != nil && self.inlineSize.value != 0) {
|
if (self.inlineSize != nil && self.inlineSize.value != 0) {
|
||||||
[self drawWrappedText:context gc:gc rect:rect];
|
CGColorRef color;
|
||||||
|
if (self.fill) {
|
||||||
|
if (self.fill.class == RNSVGBrush.class) {
|
||||||
|
color = [self.tintColor CGColor];
|
||||||
|
[self drawWrappedText:context gc:gc rect:rect color:color];
|
||||||
|
} else {
|
||||||
|
color = [self.fill getColorWithOpacity:self.fillOpacity];
|
||||||
|
[self drawWrappedText:context gc:gc rect:rect color:color];
|
||||||
|
}
|
||||||
|
if (color) {
|
||||||
|
CGColorRelease(color);
|
||||||
|
color = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (self.stroke) {
|
||||||
|
if (self.stroke.class == RNSVGBrush.class) {
|
||||||
|
color = [self.tintColor CGColor];
|
||||||
|
[self drawWrappedText:context gc:gc rect:rect color:color];
|
||||||
|
} else {
|
||||||
|
color = [self.stroke getColorWithOpacity:self.strokeOpacity];
|
||||||
|
[self drawWrappedText:context gc:gc rect:rect color:color];
|
||||||
|
}
|
||||||
|
if (color) {
|
||||||
|
CGColorRelease(color);
|
||||||
|
color = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (self.path) {
|
if (self.path) {
|
||||||
NSUInteger count = [emoji count];
|
NSUInteger count = [emoji count];
|
||||||
@@ -138,7 +164,7 @@ static CGFloat RNSVGTSpan_radToDeg = 180 / (CGFloat)M_PI;
|
|||||||
}
|
}
|
||||||
|
|
||||||
TopAlignedLabel *label;
|
TopAlignedLabel *label;
|
||||||
- (void)drawWrappedText:(CGContextRef)context gc:(RNSVGGlyphContext *)gc rect:(CGRect)rect {
|
- (void)drawWrappedText:(CGContextRef)context gc:(RNSVGGlyphContext *)gc rect:(CGRect)rect color:(CGColorRef)color {
|
||||||
[self pushGlyphContext];
|
[self pushGlyphContext];
|
||||||
if (fontRef != nil) {
|
if (fontRef != nil) {
|
||||||
CFRelease(fontRef);
|
CFRelease(fontRef);
|
||||||
@@ -182,6 +208,7 @@ TopAlignedLabel *label;
|
|||||||
label.numberOfLines = 0;
|
label.numberOfLines = 0;
|
||||||
label.opaque = NO;
|
label.opaque = NO;
|
||||||
label.font = font;
|
label.font = font;
|
||||||
|
label.textColor = [UIColor colorWithCGColor:color];
|
||||||
|
|
||||||
CGFloat fontSize = [gc getFontSize];
|
CGFloat fontSize = [gc getFontSize];
|
||||||
CGFloat height = CGRectGetHeight(rect);
|
CGFloat height = CGRectGetHeight(rect);
|
||||||
|
|||||||
Reference in New Issue
Block a user