in src/label/labelStyle.ts [471:608]
function setTokenTextStyle(
textStyle: TextStyleProps['rich'][string],
textStyleModel: Model<LabelOption>,
globalTextStyle: LabelOption,
opt?: Pick<TextCommonParams, 'inheritColor' | 'defaultOpacity' | 'disableBox'>,
isNotNormal?: boolean,
isAttached?: boolean,
isBlock?: boolean,
inRich?: boolean
) {
// In merge mode, default value should not be given.
globalTextStyle = !isNotNormal && globalTextStyle || EMPTY_OBJ;
const inheritColor = opt && opt.inheritColor;
let fillColor = textStyleModel.getShallow('color');
let strokeColor = textStyleModel.getShallow('textBorderColor');
let opacity = retrieve2(textStyleModel.getShallow('opacity'), globalTextStyle.opacity);
if (fillColor === 'inherit' || fillColor === 'auto') {
if (__DEV__) {
if (fillColor === 'auto') {
deprecateReplaceLog('color: \'auto\'', 'color: \'inherit\'');
}
}
if (inheritColor) {
fillColor = inheritColor;
}
else {
fillColor = null;
}
}
if (strokeColor === 'inherit' || (strokeColor === 'auto')) {
if (__DEV__) {
if (strokeColor === 'auto') {
deprecateReplaceLog('color: \'auto\'', 'color: \'inherit\'');
}
}
if (inheritColor) {
strokeColor = inheritColor;
}
else {
strokeColor = null;
}
}
if (!isAttached) {
// Only use default global textStyle.color if text is individual.
// Otherwise it will use the strategy of attached text color because text may be on a path.
fillColor = fillColor || globalTextStyle.color;
strokeColor = strokeColor || globalTextStyle.textBorderColor;
}
if (fillColor != null) {
textStyle.fill = fillColor;
}
if (strokeColor != null) {
textStyle.stroke = strokeColor;
}
const textBorderWidth = retrieve2(textStyleModel.getShallow('textBorderWidth'), globalTextStyle.textBorderWidth);
if (textBorderWidth != null) {
textStyle.lineWidth = textBorderWidth;
}
const textBorderType = retrieve2(textStyleModel.getShallow('textBorderType'), globalTextStyle.textBorderType);
if (textBorderType != null) {
textStyle.lineDash = textBorderType as any;
}
const textBorderDashOffset = retrieve2(
textStyleModel.getShallow('textBorderDashOffset'), globalTextStyle.textBorderDashOffset
);
if (textBorderDashOffset != null) {
textStyle.lineDashOffset = textBorderDashOffset;
}
if (!isNotNormal && (opacity == null) && !inRich) {
opacity = opt && opt.defaultOpacity;
}
if (opacity != null) {
textStyle.opacity = opacity;
}
// TODO
if (!isNotNormal && !isAttached) {
// Set default finally.
if (textStyle.fill == null && opt.inheritColor) {
textStyle.fill = opt.inheritColor;
}
}
// Do not use `getFont` here, because merge should be supported, where
// part of these properties may be changed in emphasis style, and the
// others should remain their original value got from normal style.
for (let i = 0; i < TEXT_PROPS_WITH_GLOBAL.length; i++) {
const key = TEXT_PROPS_WITH_GLOBAL[i];
const val = retrieve2(textStyleModel.getShallow(key), globalTextStyle[key]);
if (val != null) {
(textStyle as any)[key] = val;
}
}
for (let i = 0; i < TEXT_PROPS_SELF.length; i++) {
const key = TEXT_PROPS_SELF[i];
const val = textStyleModel.getShallow(key);
if (val != null) {
(textStyle as any)[key] = val;
}
}
if (textStyle.verticalAlign == null) {
const baseline = textStyleModel.getShallow('baseline');
if (baseline != null) {
textStyle.verticalAlign = baseline;
}
}
if (!isBlock || !opt.disableBox) {
for (let i = 0; i < TEXT_PROPS_BOX.length; i++) {
const key = TEXT_PROPS_BOX[i];
const val = textStyleModel.getShallow(key);
if (val != null) {
(textStyle as any)[key] = val;
}
}
const borderType = textStyleModel.getShallow('borderType');
if (borderType != null) {
textStyle.borderDash = borderType as any;
}
if ((textStyle.backgroundColor === 'auto' || textStyle.backgroundColor === 'inherit') && inheritColor) {
if (__DEV__) {
if (textStyle.backgroundColor === 'auto') {
deprecateReplaceLog('backgroundColor: \'auto\'', 'backgroundColor: \'inherit\'');
}
}
textStyle.backgroundColor = inheritColor;
}
if ((textStyle.borderColor === 'auto' || textStyle.borderColor === 'inherit') && inheritColor) {
if (__DEV__) {
if (textStyle.borderColor === 'auto') {
deprecateReplaceLog('borderColor: \'auto\'', 'borderColor: \'inherit\'');
}
}
textStyle.borderColor = inheritColor;
}
}
}