1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/// <reference path='./import.ts' /> 17class SymbolFontColorModifier extends ModifierWithKey<object> { 18 constructor(value: object) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('symbolGlyphFontColor'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().symbolGlyph.resetFontColor(node); 25 } else { 26 getUINativeModule().symbolGlyph.setFontColor(node, this.value); 27 } 28 } 29 30 checkObjectDiff(): boolean { 31 if (isResource(this.stageValue) && isResource(this.value)) { 32 let ret: boolean = !isResourceEqual(this.stageValue, this.value); 33 return ret; 34 } else { 35 return true; 36 } 37 } 38 } 39 40 class SymbolFontSizeModifier extends ModifierWithKey<number | string | Resource> { 41 constructor(value: number | string | Resource) { 42 super(value); 43 } 44 static identity: Symbol = Symbol('symbolGlyphFontSize'); 45 applyPeer(node: KNode, reset: boolean): void { 46 if (reset) { 47 getUINativeModule().symbolGlyph.resetFontSize(node); 48 } else { 49 getUINativeModule().symbolGlyph.setFontSize(node, this.value); 50 } 51 } 52 53 checkObjectDiff(): boolean { 54 if (isResource(this.stageValue) && isResource(this.value)) { 55 return !isResourceEqual(this.stageValue, this.value); 56 } else { 57 return true; 58 } 59 } 60 } 61 62 class SymbolFontWeightModifier extends ModifierWithKey<number | FontWeight | string> { 63 constructor(value: number | FontWeight | string) { 64 super(value); 65 } 66 static identity: Symbol = Symbol('symbolGlyphFontWeight'); 67 applyPeer(node: KNode, reset: boolean): void { 68 if (reset) { 69 getUINativeModule().symbolGlyph.resetFontWeight(node); 70 } else { 71 getUINativeModule().symbolGlyph.setFontWeight(node, this.value); 72 } 73 } 74 75 checkObjectDiff(): boolean { 76 if (isResource(this.stageValue) && isResource(this.value)) { 77 return !isResourceEqual(this.stageValue, this.value); 78 } else { 79 return true; 80 } 81 } 82 } 83 84 class RenderingStrategyModifier extends ModifierWithKey<SymbolRenderingStrategy> { 85 constructor(value: SymbolRenderingStrategy) { 86 super(value); 87 } 88 static identity: Symbol = Symbol('symbolGlyphRenderingStrategy'); 89 applyPeer(node: KNode, reset: boolean): void { 90 if (reset) { 91 getUINativeModule().symbolGlyph.resetRenderingStrategy(node); 92 } else { 93 getUINativeModule().symbolGlyph.setRenderingStrategy(node, this.value); 94 } 95 } 96 97 checkObjectDiff(): boolean { 98 if (isResource(this.stageValue) && isResource(this.value)) { 99 return !isResourceEqual(this.stageValue, this.value); 100 } else { 101 return true; 102 } 103 } 104 } 105 106 class EffectStrategyModifier extends ModifierWithKey<SymbolEffectStrategy> { 107 constructor(value: SymbolEffectStrategy) { 108 super(value); 109 } 110 static identity: Symbol = Symbol('symbolGlyphEffectStrategy'); 111 applyPeer(node: KNode, reset: boolean): void { 112 if (reset) { 113 getUINativeModule().symbolGlyph.resetEffectStrategy(node); 114 } else { 115 getUINativeModule().symbolGlyph.setEffectStrategy(node, this.value); 116 } 117 } 118 119 checkObjectDiff(): boolean { 120 if (isResource(this.stageValue) && isResource(this.value)) { 121 return !isResourceEqual(this.stageValue, this.value); 122 } else { 123 return true; 124 } 125 } 126 } 127 128 class SymbolEffectModifier extends ModifierWithKey<ArkSymbolEffect> { 129 constructor(value: ArkSymbolEffect) { 130 super(value); 131 } 132 static identity: Symbol = Symbol('symbolGlyphSymbolEffect'); 133 applyPeer(node: KNode, reset: boolean): void { 134 if (reset) { 135 getUINativeModule().symbolGlyph.resetSymbolEffectOptions(node); 136 } else { 137 getUINativeModule().symbolGlyph.setSymbolEffectOptions(node, this.value.symbolEffect, this.value.action); 138 } 139 } 140 } 141 142 class SymbolMinFontScaleModifier extends ModifierWithKey<Optional<number | Resource>> { 143 constructor(value: Optional<number | Resource>) { 144 super(value); 145 } 146 static identity: Symbol = Symbol('symbolGlyphMinFontScale'); 147 applyPeer(node: KNode, reset: boolean): void { 148 if (reset) { 149 getUINativeModule().symbolGlyph.resetMinFontScale(node); 150 } else { 151 getUINativeModule().symbolGlyph.setMinFontScale(node, this.value); 152 } 153 } 154 155 checkObjectDiff(): boolean { 156 if (isResource(this.stageValue) && isResource(this.value)) { 157 return !isResourceEqual(this.stageValue, this.value); 158 } else { 159 return true; 160 } 161 } 162 } 163 164 class SymbolMaxFontScaleModifier extends ModifierWithKey<Optional<number | Resource>> { 165 constructor(value: Optional<number | Resource>) { 166 super(value); 167 } 168 static identity: Symbol = Symbol('symbolGlyphMaxFontScale'); 169 applyPeer(node: KNode, reset: boolean): void { 170 if (reset) { 171 getUINativeModule().symbolGlyph.resetMaxFontScale(node); 172 } else { 173 getUINativeModule().symbolGlyph.setMaxFontScale(node, this.value); 174 } 175 } 176 177 checkObjectDiff(): boolean { 178 if (isResource(this.stageValue) && isResource(this.value)) { 179 return !isResourceEqual(this.stageValue, this.value); 180 } else { 181 return true; 182 } 183 } 184 } 185 186 class SymbolContentModifier extends ModifierWithKey<Resource> { 187 constructor(value: Resource) { 188 super(value); 189 } 190 static identity: Symbol = Symbol('symbolContent'); 191 applyPeer(node: KNode, reset: boolean): void { 192 if (reset) { 193 getUINativeModule().symbolGlyph.resetSymbolGlyphInitialize(node); 194 } else { 195 getUINativeModule().symbolGlyph.setSymbolGlyphInitialize(node, this.value); 196 } 197 } 198 } 199 200 class ArkSymbolGlyphComponent extends ArkComponent implements SymbolGlyphAttribute { 201 constructor(nativePtr: KNode, classType?: ModifierType) { 202 super(nativePtr, classType); 203 } 204 initialize(value: Object[]): this { 205 if (value[0] !== undefined) { 206 modifierWithKey(this._modifiersWithKeys, SymbolContentModifier.identity, SymbolContentModifier, value[0]); 207 } else { 208 modifierWithKey(this._modifiersWithKeys, SymbolContentModifier.identity, SymbolContentModifier, undefined); 209 } 210 return this; 211 } 212 fontColor(value: object): SymbolGlyphAttribute { 213 modifierWithKey(this._modifiersWithKeys, SymbolFontColorModifier.identity, SymbolFontColorModifier, value); 214 return this; 215 } 216 fontSize(value: number | string | Resource): SymbolGlyphAttribute { 217 modifierWithKey(this._modifiersWithKeys, SymbolFontSizeModifier.identity, SymbolFontSizeModifier, value); 218 return this; 219 } 220 fontWeight(value: number | FontWeight | string): SymbolGlyphAttribute { 221 let fontWeightStr: string = '400'; 222 if (isNumber(value)) { 223 fontWeightStr = value.toString(); 224 } else if (isString(value)) { 225 fontWeightStr = String(value); 226 } 227 modifierWithKey(this._modifiersWithKeys, SymbolFontWeightModifier.identity, SymbolFontWeightModifier, fontWeightStr); 228 return this; 229 } 230 renderingStrategy(value: SymbolRenderingStrategy): SymbolGlyphAttribute { 231 modifierWithKey(this._modifiersWithKeys, RenderingStrategyModifier.identity, RenderingStrategyModifier, value); 232 return this; 233 } 234 effectStrategy(value: SymbolEffectStrategy): SymbolGlyphAttribute { 235 modifierWithKey(this._modifiersWithKeys, EffectStrategyModifier.identity, EffectStrategyModifier, value); 236 return this; 237 } 238 symbolEffect(effect: SymbolEffect, action?: boolean | number): SymbolGlyphAttribute { 239 let symbolEffect = new ArkSymbolEffect(); 240 symbolEffect.symbolEffect = effect; 241 symbolEffect.action = action; 242 modifierWithKey(this._modifiersWithKeys, SymbolEffectModifier.identity, SymbolEffectModifier, symbolEffect); 243 return this; 244 } 245 } 246 247 // @ts-ignore 248 globalThis.SymbolGlyph.attributeModifier = function (modifier: ArkComponent): void { 249 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 250 return new ArkSymbolGlyphComponent(nativePtr); 251 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 252 return new modifierJS.SymbolGlyphModifier(undefined, nativePtr, classType); 253 }); 254 };