From 050835320d3165ddb42e98432d7e4208298129c6 Mon Sep 17 00:00:00 2001 From: plainheart Date: Tue, 3 Oct 2023 12:41:11 +0800 Subject: [PATCH] fix(toolbox): fix toolbox text can't apply the specified or inherited font style --- src/component/toolbox/ToolboxView.ts | 10 +- src/component/toolbox/featureManager.ts | 4 + test/toolbox-textStyle.html | 122 ++++++++++++++++++++---- 3 files changed, 114 insertions(+), 22 deletions(-) diff --git a/src/component/toolbox/ToolboxView.ts b/src/component/toolbox/ToolboxView.ts index e24be3cd96..071c009bd5 100644 --- a/src/component/toolbox/ToolboxView.ts +++ b/src/component/toolbox/ToolboxView.ts @@ -39,6 +39,7 @@ import { import { getUID } from '../../util/component'; import Displayable from 'zrender/src/graphic/Displayable'; import ZRText from 'zrender/src/graphic/Text'; +import { getFont } from '../../label/labelStyle'; type IconPath = ToolboxFeatureModel['iconPaths'][string]; @@ -217,13 +218,20 @@ class ToolboxView extends ComponentView { pathEmphasisState.style = iconStyleEmphasisModel.getItemStyle(); // Text position calculation + // TODO: extract `textStyle` from `iconStyle` and use `createTextStyle` const textContent = new ZRText({ style: { text: titlesMap[iconName], align: iconStyleEmphasisModel.get('textAlign'), borderRadius: iconStyleEmphasisModel.get('textBorderRadius'), padding: iconStyleEmphasisModel.get('textPadding'), - fill: null + fill: null, + font: getFont({ + fontStyle: iconStyleEmphasisModel.get('textFontStyle'), + fontFamily: iconStyleEmphasisModel.get('textFontFamily'), + fontSize: iconStyleEmphasisModel.get('textFontSize'), + fontWeight: iconStyleEmphasisModel.get('textFontWeight') + }, ecModel) }, ignore: true }); diff --git a/src/component/toolbox/featureManager.ts b/src/component/toolbox/featureManager.ts index 49553ebe59..5b16acf618 100644 --- a/src/component/toolbox/featureManager.ts +++ b/src/component/toolbox/featureManager.ts @@ -33,6 +33,10 @@ type IconStyle = ItemStyleOption & { textAlign?: LabelOption['align'] textBorderRadius?: LabelOption['borderRadius'] textPadding?: LabelOption['padding'] + textFontFamily?: LabelOption['fontFamily'] + textFontSize?: LabelOption['fontSize'] + textFontWeight?: LabelOption['fontWeight'] + textFontStyle?: LabelOption['fontStyle'] }; export interface ToolboxFeatureOption { diff --git a/test/toolbox-textStyle.html b/test/toolbox-textStyle.html index d80a175e6b..1776f05c38 100644 --- a/test/toolbox-textStyle.html +++ b/test/toolbox-textStyle.html @@ -23,32 +23,19 @@ + + - -
+ + - \ No newline at end of file +