Skip to content

Commit 6dc1392

Browse files
committed
fix: some font fixes and optimizations
1 parent 859d266 commit 6dc1392

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

src/canvas.android.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,20 @@ export class Paint {
258258
},
259259
});
260260
}
261-
get font() {
261+
setFont(font: Font) {
262+
this.fontInternal = font;
263+
this._native.setTextSize(font.fontSize);
264+
this._needsFontUpdate = true;
265+
}
266+
getFont() {
262267
if (!this.fontInternal) {
263268
this.fontInternal = Font.default;
264269
}
265270
return this.fontInternal;
266271
}
272+
get font() {
273+
return this.getFont();
274+
}
267275
set font(font: Font) {
268276
this.setFont(font);
269277
}
@@ -282,11 +290,6 @@ export class Paint {
282290
this._needsFontUpdate = true;
283291
}
284292
}
285-
setFont(font: Font) {
286-
this.fontInternal = font;
287-
this._needsFontUpdate = true;
288-
// this._native.setTypeface(this.font.getAndroidTypeface());
289-
}
290293
set fontWeight(weight: FontWeight) {
291294
this.setFontWeight(weight);
292295
}

src/canvas.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export class Paint {
3030
fontWeight: FontWeight;
3131
fontStyle: FontStyle;
3232
font: Font;
33+
getFont(): Font
34+
setFont(font: Font)
3335

3436
public getAlpha(): number;
3537
public getStyle(): Style;

src/canvas.ios.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,6 @@ export class Paint implements IPaint {
850850
_color: Color = new Color('black');
851851
style: Style = Style.FILL;
852852
align: Align = Align.LEFT;
853-
// _textSize = 16;
854853
_font: Font;
855854
strokeWidth = 0;
856855
strokeMiter = 0;
@@ -963,13 +962,21 @@ export class Paint implements IPaint {
963962
constructor() {
964963
// this.font = Font.default;
965964
}
966-
967-
get font() {
965+
setFont(font: Font) {
966+
this._font = font;
967+
}
968+
getFont() {
968969
if (!this._font) {
969970
this._font = Font.default;
970971
}
971972
return this._font;
972973
}
974+
get font() {
975+
return this.getFont();
976+
}
977+
set font(font: Font) {
978+
this.setFont(font);
979+
}
973980

974981
setFontFamily(familyName: string) {
975982
this._font = this.font.withFontFamily(familyName);
@@ -1008,23 +1015,26 @@ export class Paint implements IPaint {
10081015
}
10091016

10101017
public getTextSize(): number {
1011-
return this.textSize;
1018+
return this._font ? this._font.fontSize : UIFont.labelFontSize;
10121019
}
10131020

10141021
set textSize(textSize) {
1015-
this._font = this.font.withFontSize(textSize);
1016-
this._textAttribs = null;
1022+
this.setTextSize(textSize);
10171023
}
10181024
get textSize() {
1019-
return this._font ? this._font.fontSize : UIFont.labelFontSize;
1025+
return this.getTextSize();
10201026
}
10211027
setTextSize(textSize) {
1022-
this.textSize = textSize;
1028+
this._font = this.font.withFontSize(textSize);
1029+
this._textAttribs = null;
10231030
}
10241031
get color(): Color | number | string {
10251032
return this._color;
10261033
}
10271034
set color(color: Color | number | string) {
1035+
this.setColor(color);
1036+
}
1037+
setColor(color: Color | number | string) {
10281038
if (color instanceof Color) {
10291039
this._color = color;
10301040
} else if (!!color) {
@@ -1035,6 +1045,7 @@ export class Paint implements IPaint {
10351045
}
10361046
setColor(color: Color | number | string) {
10371047
this.color = color as any;
1048+
10381049
}
10391050
getColor(): Color {
10401051
return this._color;

0 commit comments

Comments
 (0)