Automatic custom fonts registration for iOS.

This commit is contained in:
Nedyalko Nikolov
2015-10-07 13:04:21 +03:00
parent 4059b35408
commit f25e2bf757
4 changed files with 28 additions and 5 deletions

View File

@ -303,14 +303,18 @@ export var testEnumEntities = function () {
// <hide> // <hide>
var file = documents.getFile("Test.txt"); var file = documents.getFile("Test.txt");
var file1 = documents.getFile("Test1.txt"); var file1 = documents.getFile("Test1.txt");
var fileFound, var testFolder = documents.getFolder("testFolder");
file1Found; var fileFound = false;
var file1Found = false;
var testFolderFound = false;
var console = { var console = {
log: function (file) { log: function (file) {
if (file === "Test.txt") { if (file === "Test.txt") {
fileFound = true; fileFound = true;
} else if (file === "Test1.txt") { } else if (file === "Test1.txt") {
file1Found = true; file1Found = true;
} else if (file === "testFolder") {
testFolderFound = true;
} }
} }
} }
@ -323,9 +327,11 @@ export var testEnumEntities = function () {
// <hide> // <hide>
TKUnit.assert(fileFound, "Failed to enumerate Test.txt"); TKUnit.assert(fileFound, "Failed to enumerate Test.txt");
TKUnit.assert(file1Found, "Failed to enumerate Test1.txt"); TKUnit.assert(file1Found, "Failed to enumerate Test1.txt");
TKUnit.assert(testFolderFound, "Failed to enumerate testFolder");
file.remove(); file.remove();
file1.remove(); file1.remove();
testFolder.remove();
// </hide> // </hide>
// ``` // ```
// </snippet> // </snippet>

View File

@ -323,7 +323,7 @@ export class FileSystemAccess {
name: file name: file
}; };
if (!this.folderExists(file)) { if (!this.folderExists(this.joinPath(path, file))) {
info.extension = this.getFileExtension(info.path); info.extension = this.getFileExtension(info.path);
} }

View File

@ -1,6 +1,7 @@
import enums = require("ui/enums"); import enums = require("ui/enums");
import common = require("./font-common"); import common = require("./font-common");
import fs = require("file-system"); import fs = require("file-system");
import trace = require("trace");
var DEFAULT_SERIF = "Times New Roman"; var DEFAULT_SERIF = "Times New Roman";
var DEFAULT_SANS_SERIF = "Helvetica"; var DEFAULT_SANS_SERIF = "Helvetica";
@ -159,9 +160,25 @@ export module ios {
var error = new interop.Reference(); var error = new interop.Reference();
if (!CTFontManagerRegisterGraphicsFont(font, error)) { 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; 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();