Skip to content

Commit

Permalink
Fix richtext using outline to generate warnings (#17329)
Browse files Browse the repository at this point in the history
Co-authored-by: qiuguohua <[email protected]>
  • Loading branch information
qiuguohua and qiuguohua authored Jul 8, 2024
1 parent 590c3c6 commit 46e8a20
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions cocos/2d/components/rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { assert, warnID, Color, Vec2, CCObject, cclegacy, js, Size } from '../..
import { HtmlTextParser, IHtmlTextParserResultObj, IHtmlTextParserStack } from '../utils/html-text-parser';
import { Node } from '../../scene-graph';
import { CacheMode, HorizontalTextAlignment, Label, VerticalTextAlignment } from './label';
import { LabelOutline } from './label-outline';
import { Sprite } from './sprite';
import { UITransform } from '../framework';
import { Component } from '../../scene-graph/component';
Expand Down Expand Up @@ -63,9 +62,9 @@ const labelPool = new js.Pool((seg: ISegment) => {
if (!cclegacy.isValid(seg.node)) {
return false;
} else {
const outline = seg.node.getComponent(LabelOutline);
if (outline) {
outline.width = 0;
const label = seg.node.getComponent(Label);
if (label) {
label.outlineWidth = 0;
}
}
return true;
Expand Down Expand Up @@ -1257,10 +1256,10 @@ this._measureText(styleIndex) as unknown as (s: string) => number,
}

// adjust y for label with outline
const outline = segment.node.getComponent(LabelOutline);
if (outline) {
const label = segment.node.getComponent(Label);
if (label) {
const position = segment.node.position.clone();
position.y -= outline.width;
position.y -= label.outlineWidth;
segment.node.position = position;
}
}
Expand Down Expand Up @@ -1306,13 +1305,13 @@ this._measureText(styleIndex) as unknown as (s: string) => number,

label.isUnderline = !!textStyle.underline;
if (textStyle.outline) {
let labelOutline = labelSeg.node.getComponent(LabelOutline);
if (!labelOutline) {
labelOutline = labelSeg.node.addComponent(LabelOutline);
let label = labelSeg.node.getComponent(Label);
if (!label) {
label = labelSeg.node.addComponent(Label);
}

labelOutline.color = this._convertLiteralColorValue(textStyle.outline.color);
labelOutline.width = textStyle.outline.width;
label.enableOutline = true;
label.outlineColor = this._convertLiteralColorValue(textStyle.outline.color);
label.outlineWidth = textStyle.outline.width;
}

label.fontSize = textStyle.size || this._fontSize;
Expand Down

0 comments on commit 46e8a20

Please sign in to comment.