From 2a2ddb3495e6b6725c4263d2349bf4c80d2aa41a Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Fri, 22 Apr 2016 16:44:17 +0300 Subject: [PATCH] Fix: Bold and italic do not work on Android when no font family is specified Resolves #2018 --- ui/styling/font.android.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ui/styling/font.android.ts b/ui/styling/font.android.ts index 781ca21dd..8b1143082 100644 --- a/ui/styling/font.android.ts +++ b/ui/styling/font.android.ts @@ -64,7 +64,16 @@ export class Font extends common.Font { public getAndroidTypeface(): android.graphics.Typeface { if (!this._typeface) { - this._typeface = createTypeface(this); + var fontStyle = 0; + if (this.isBold) { + fontStyle |= android.graphics.Typeface.BOLD; + } + if (this.isItalic) { + fontStyle |= android.graphics.Typeface.ITALIC; + } + + var typeFace = createTypeface(this); + this._typeface = android.graphics.Typeface.create(typeFace, fontStyle); } return this._typeface; } @@ -116,15 +125,6 @@ function loadFontFromFile(fontFamily: string): android.graphics.Typeface { function createTypeface(font: Font): android.graphics.Typeface { //http://stackoverflow.com/questions/19691530/valid-values-for-androidfontfamily-and-what-they-map-to - - var fontStyle = 0; - if (font.isBold) { - fontStyle |= android.graphics.Typeface.BOLD; - } - if (font.isItalic) { - fontStyle |= android.graphics.Typeface.ITALIC; - } - var fonts = common.parseFontFamily(font.fontFamily); var result = null; if (fonts.length === 0) { @@ -134,16 +134,16 @@ function createTypeface(font: Font): android.graphics.Typeface { for (var i = 0; i < fonts.length; i++) { switch (fonts[i].toLowerCase()) { case common.genericFontFamilies.serif: - result = android.graphics.Typeface.create("serif" + getFontWeightSuffix(font.fontWeight), fontStyle); + result = android.graphics.Typeface.create("serif" + getFontWeightSuffix(font.fontWeight), 0); break; case common.genericFontFamilies.sansSerif: case common.genericFontFamilies.system: - result = android.graphics.Typeface.create("sans-serif" + getFontWeightSuffix(font.fontWeight), fontStyle); + result = android.graphics.Typeface.create("sans-serif" + getFontWeightSuffix(font.fontWeight), 0); break; case common.genericFontFamilies.monospace: - result = android.graphics.Typeface.create("monospace" + getFontWeightSuffix(font.fontWeight), fontStyle); + result = android.graphics.Typeface.create("monospace" + getFontWeightSuffix(font.fontWeight), 0); break; default: