Skip to content

Commit 95eb8ac

Browse files
committed
fix: ios prevent native font from being “reset” when not necessary
1 parent 5be905c commit 95eb8ac

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/canvas.ios.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,9 @@ export class Paint implements IPaint {
830830
}
831831
public setFilterBitmap(param0: boolean) {}
832832
public setTypeface(font: Font | UIFont): Font {
833+
if (this.font === font) {
834+
return this._font;
835+
}
833836
if (font instanceof Font) {
834837
this._font = font;
835838
} else if (font) {
@@ -963,7 +966,11 @@ export class Paint implements IPaint {
963966
// this.font = Font.default;
964967
}
965968
setFont(font: Font) {
969+
if (font === this._font) {
970+
return;
971+
}
966972
this._font = font;
973+
this._textAttribs = null;
967974
}
968975
getFont() {
969976
if (!this._font) {
@@ -979,6 +986,9 @@ export class Paint implements IPaint {
979986
}
980987

981988
setFontFamily(familyName: string) {
989+
if (this._font && this._font.fontFamily === familyName) {
990+
return;
991+
}
982992
this._font = this.font.withFontFamily(familyName);
983993
this._textAttribs = null;
984994
}
@@ -993,6 +1003,9 @@ export class Paint implements IPaint {
9931003
}
9941004

9951005
set fontWeight(weight: FontWeight) {
1006+
if (this._font && this._font.fontWeight === weight) {
1007+
return;
1008+
}
9961009
this.setFontWeight(weight);
9971010
}
9981011
setFontWeight(weight: FontWeight) {
@@ -1003,6 +1016,9 @@ export class Paint implements IPaint {
10031016
this.setFontStyle(style);
10041017
}
10051018
setFontStyle(style: FontStyle) {
1019+
if (this._font && this._font.fontStyle === style) {
1020+
return;
1021+
}
10061022
this._font = this.font.withFontStyle(style);
10071023
this._textAttribs = null;
10081024
}
@@ -1025,6 +1041,9 @@ export class Paint implements IPaint {
10251041
return this.getTextSize();
10261042
}
10271043
setTextSize(textSize) {
1044+
if (this._font && this._font.fontSize === textSize) {
1045+
return;
1046+
}
10281047
this._font = this.font.withFontSize(textSize);
10291048
this._textAttribs = null;
10301049
}

0 commit comments

Comments
 (0)