TextStyle.ets 698 B

123456789101112131415161718192021222324
  1. export class CustomTextStyle implements AttributeModifier<TextAttribute> {
  2. fontSize: number | string | Resource = 16;
  3. fontWeight: number | FontWeight | string = 400;
  4. fontColor: ResourceColor = '#000000';
  5. constructor(font: CustomFont) {
  6. this.fontSize = font.size ?? this.fontSize
  7. this.fontWeight = font.weight ?? this.fontWeight
  8. this.fontColor = font.color ?? this.fontColor
  9. }
  10. applyNormalAttribute(instance: TextAttribute): void {
  11. instance
  12. .fontSize(this.fontSize)
  13. .fontWeight(this.fontWeight)
  14. .fontColor(this.fontColor)
  15. }
  16. }
  17. interface CustomFont{
  18. size?: number | string | Resource
  19. weight?: number | FontWeight | string
  20. color?: ResourceColor
  21. }