(hostStyle: ZRStyleProps, elType: string, isNormal: boolean)
| 69 | * retried from the `hostStyle`. |
| 70 | */ |
| 71 | export function convertFromEC4CompatibleStyle(hostStyle: ZRStyleProps, elType: string, isNormal: boolean): { |
| 72 | textContent: TextProps & {type: string}, |
| 73 | textConfig: ElementTextConfig |
| 74 | } { |
| 75 | const srcStyle = hostStyle as Dictionary<any>; |
| 76 | let textConfig: ElementTextConfig; |
| 77 | let textContent: TextProps & {type: string}; |
| 78 | |
| 79 | let textContentStyle: TextStyleProps; |
| 80 | if (elType === 'text') { |
| 81 | textContentStyle = srcStyle; |
| 82 | } |
| 83 | else { |
| 84 | textContentStyle = {}; |
| 85 | hasOwn(srcStyle, 'text') && (textContentStyle.text = srcStyle.text); |
| 86 | hasOwn(srcStyle, 'rich') && (textContentStyle.rich = srcStyle.rich); |
| 87 | hasOwn(srcStyle, 'textFill') && (textContentStyle.fill = srcStyle.textFill); |
| 88 | hasOwn(srcStyle, 'textStroke') && (textContentStyle.stroke = srcStyle.textStroke); |
| 89 | hasOwn(srcStyle, 'fontFamily') && (textContentStyle.fontFamily = srcStyle.fontFamily); |
| 90 | hasOwn(srcStyle, 'fontSize') && (textContentStyle.fontSize = srcStyle.fontSize); |
| 91 | hasOwn(srcStyle, 'fontStyle') && (textContentStyle.fontStyle = srcStyle.fontStyle); |
| 92 | hasOwn(srcStyle, 'fontWeight') && (textContentStyle.fontWeight = srcStyle.fontWeight); |
| 93 | |
| 94 | textContent = { |
| 95 | type: 'text', |
| 96 | style: textContentStyle, |
| 97 | // ec4 does not support rectText trigger. |
| 98 | // And when text position is different in normal and emphasis |
| 99 | // => hover text trigger emphasis; |
| 100 | // => text position changed, leave mouse pointer immediately; |
| 101 | // That might cause incorrect state. |
| 102 | silent: true |
| 103 | }; |
| 104 | textConfig = {}; |
| 105 | const hasOwnPos = hasOwn(srcStyle, 'textPosition'); |
| 106 | if (isNormal) { |
| 107 | textConfig.position = hasOwnPos ? srcStyle.textPosition : 'inside'; |
| 108 | } |
| 109 | else { |
| 110 | hasOwnPos && (textConfig.position = srcStyle.textPosition); |
| 111 | } |
| 112 | hasOwn(srcStyle, 'textPosition') && (textConfig.position = srcStyle.textPosition); |
| 113 | hasOwn(srcStyle, 'textOffset') && (textConfig.offset = srcStyle.textOffset); |
| 114 | hasOwn(srcStyle, 'textRotation') && (textConfig.rotation = srcStyle.textRotation); |
| 115 | hasOwn(srcStyle, 'textDistance') && (textConfig.distance = srcStyle.textDistance); |
| 116 | } |
| 117 | |
| 118 | convertEC4CompatibleRichItem(textContentStyle, hostStyle); |
| 119 | |
| 120 | each(textContentStyle.rich, function (richItem) { |
| 121 | convertEC4CompatibleRichItem(richItem as TextStyleProps, richItem); |
| 122 | }); |
| 123 | |
| 124 | return { |
| 125 | textConfig: textConfig, |
| 126 | textContent: textContent |
| 127 | }; |
| 128 | } |
no test coverage detected
searching dependent graphs…