FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix: Bold and italic do not work on Android when no font family by hamorphis · Pull Request #2019 · NativeScript/NativeScript · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
26 changes: 13 additions & 13 deletions ui/styling/font.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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:
Expand Down

Back | FazBrowse Home | New Git URL