mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Automatic custom fonts registration for iOS.
This commit is contained in:
@ -303,14 +303,18 @@ export var testEnumEntities = function () {
|
||||
// <hide>
|
||||
var file = documents.getFile("Test.txt");
|
||||
var file1 = documents.getFile("Test1.txt");
|
||||
var fileFound,
|
||||
file1Found;
|
||||
var testFolder = documents.getFolder("testFolder");
|
||||
var fileFound = false;
|
||||
var file1Found = false;
|
||||
var testFolderFound = false;
|
||||
var console = {
|
||||
log: function (file) {
|
||||
if (file === "Test.txt") {
|
||||
fileFound = true;
|
||||
} else if (file === "Test1.txt") {
|
||||
file1Found = true;
|
||||
} else if (file === "testFolder") {
|
||||
testFolderFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -323,9 +327,11 @@ export var testEnumEntities = function () {
|
||||
// <hide>
|
||||
TKUnit.assert(fileFound, "Failed to enumerate Test.txt");
|
||||
TKUnit.assert(file1Found, "Failed to enumerate Test1.txt");
|
||||
TKUnit.assert(testFolderFound, "Failed to enumerate testFolder");
|
||||
|
||||
file.remove();
|
||||
file1.remove();
|
||||
testFolder.remove();
|
||||
// </hide>
|
||||
// ```
|
||||
// </snippet>
|
||||
|
@ -333,7 +333,7 @@ export function test_setting_font_properties_sets_native_font() {
|
||||
test_native_font(enums.FontStyle.normal, enums.FontWeight.normal);
|
||||
test_native_font(enums.FontStyle.italic, enums.FontWeight.normal);
|
||||
test_native_font(enums.FontStyle.normal, enums.FontWeight.bold);
|
||||
test_native_font(enums.FontStyle.italic, enums.FontWeight.bold);
|
||||
test_native_font(enums.FontStyle.italic, enums.FontWeight.bold);
|
||||
}
|
||||
|
||||
function test_native_font(style: string, weight: string) {
|
||||
|
@ -323,7 +323,7 @@ export class FileSystemAccess {
|
||||
name: file
|
||||
};
|
||||
|
||||
if (!this.folderExists(file)) {
|
||||
if (!this.folderExists(this.joinPath(path, file))) {
|
||||
info.extension = this.getFileExtension(info.path);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import enums = require("ui/enums");
|
||||
import common = require("./font-common");
|
||||
import fs = require("file-system");
|
||||
import trace = require("trace");
|
||||
|
||||
var DEFAULT_SERIF = "Times New Roman";
|
||||
var DEFAULT_SANS_SERIF = "Helvetica";
|
||||
@ -159,9 +160,25 @@ export module ios {
|
||||
|
||||
var error = new interop.Reference();
|
||||
if (!CTFontManagerRegisterGraphicsFont(font, error)) {
|
||||
throw new Error(CFErrorCopyDescription(<NSError>error.value));
|
||||
trace.write("Error occur while registering font: " + CFErrorCopyDescription(<NSError>error.value), trace.categories.Error, trace.messageType.error);
|
||||
}
|
||||
|
||||
areSystemFontSetsValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
function registerCustomFonts() {
|
||||
var fontsFolderPath = fs.path.join(__dirname.substring(0, __dirname.indexOf("/tns_modules")), "fonts");
|
||||
var fontsFolder = fs.Folder.fromPath(fontsFolderPath);
|
||||
var onEachEntityFunc = function (fileEntity: fs.FileSystemEntity): boolean {
|
||||
if (fs.Folder.exists(fs.path.join(fontsFolderPath, fileEntity.name))) {
|
||||
return true;
|
||||
}
|
||||
ios.registerFont(fileEntity.name);
|
||||
return true;
|
||||
}
|
||||
|
||||
fontsFolder.eachEntity(onEachEntityFunc);
|
||||
}
|
||||
|
||||
registerCustomFonts();
|
Reference in New Issue
Block a user