From b51d94ed97a5ff5f4d1289332ea8f94dbc44207c Mon Sep 17 00:00:00 2001 From: eb1 Date: Mon, 12 Jan 2015 20:55:31 -0600 Subject: [PATCH] Code cleanup --- doc/index.md | 50 ++++++++++++++++++++++++++++++++++-- plugin.xml | 23 +---------------- src/wp/Fonts.cs | 68 ------------------------------------------------- 3 files changed, 49 insertions(+), 92 deletions(-) delete mode 100644 src/wp/Fonts.cs diff --git a/doc/index.md b/doc/index.md index f3ebdc8..e0b92c9 100755 --- a/doc/index.md +++ b/doc/index.md @@ -19,15 +19,61 @@ # org.adapt-it.cordova.fonts -This plugin defines a global `fonts` object, which provides access to the fonts installed on the device. +This plugin defines a global `Fonts` object, which provides access to the fonts installed on the device. The `Fonts` object is available from the `navigator` object after the `deviceready` event fires. + + document.addEventListener("deviceready", onDeviceReady, false); + function onDeviceReady() { + console.log(navigator.Fonts); + } ## Installation cordova plugin add https://github.com/adapt-it/cordova-fonts.git +## Supported Platforms + +- Android +- iOS + +# Fonts + +The `Fonts` object provides a way to enumerate through the list of fonts installed on the device. + +## Methods + +Currently this plugin only provides a single method, **getFontList**. + +### GetFontList + +**Parameters:** + +- **successCallback**: Callback that returns the list of fonts as an array of string values. +- **errorCallback: Callback that executes if an error occurs while retrieving the list of fonts on the local device. + +### Example + + if (navigator.Fonts) { + console.log("Fonts object in navigator"); + navigator.Fonts.getFontList( + function (fontList) { + if (fontlist) { + for (var i = 0; i < fontlist.length; i++) { + console.log("Font: " + fontlist[i]); + } + } + }, + function (error) { + console.log("FontList error: " + error); + } + ); + } else { + console.log("Plugin error: Fonts plugin not found (is it installed?)"); + } + + ## Internal Development / Unit Testing -(This is only for devs who are debugging the plugin itself) +(This is only for devs who are developing / debugging the plugin itself) The cordova-fonts plugin uses the cordova-plugin-test-framework to run unit tests. Complete the following to run through the plugin unit tests: diff --git a/plugin.xml b/plugin.xml index 79b9d8c..882273f 100644 --- a/plugin.xml +++ b/plugin.xml @@ -34,26 +34,5 @@ - - - - + diff --git a/src/wp/Fonts.cs b/src/wp/Fonts.cs deleted file mode 100644 index 61734cd..0000000 --- a/src/wp/Fonts.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Windows.Media; -using System.Runtime.Serialization; - -namespace WPCordovaClassLib.Cordova.Commands -{ - /// - /// Provides information about system locale, culture settings, number formats, ect. - /// - public class Fonts : BaseCommand - { - /// - /// Gets the string identifier for the client's current language. - /// - /// - public void getPreferredLanguage(string options) - { - try - { - string fontFamilies = ""; - //TODO: System.Windows.Media.SystmTypefaces? -// Typefase[] typefaces = -// FontFamily[] fontFamilies; -// InstalledFontCollection installedFontCollection = new InstalledFontCollection(); -// // Get the array of FontFamily objects. -// fontFamilies = installedFontCollection.Families; - PluginResult result = new PluginResult(PluginResult.Status.OK, this.WrapIntoJSON(fontFamilies)); - this.DispatchCommandResult(result); - } - catch (Exception e) - { - this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, e)); - } - } - - /// - /// Wraps data into JSON format - /// - /// data - /// data formatted as JSON object - private string WrapIntoJSON(T data, string keyName = "value") - { - string param = "{0}"; - string stringifiedData = data.ToString(); - - if (data.GetType() == typeof(string)) - { - param = "\"" + param + "\""; - } - - if (data.GetType() == typeof(bool)) - { - stringifiedData = stringifiedData.ToLower(); - } - - if (data.GetType() == typeof(string[])) - { - stringifiedData = JSON.JsonHelper.Serialize(data); - } - - var formattedData = string.Format("\"" + keyName + "\":" + param, stringifiedData); - formattedData = "{" + formattedData + "}"; - - return formattedData; - } - - } -} \ No newline at end of file