Feature Request
Create a font form from file which is really required to load the dynamic font downloaded from our server or at least if the mCustomTypeFaces variable is declared as public.
Android API
Create a new typeface from the specified font file.
http://developer.android.com/reference/android/graphics/Typeface.html#createFromFile(java.lang.String)
Use Case
Our requirement is to download the fonts (TTF) files form server and put them inside app directory, then use it. So if we like to change the fonts tomorrow after app release, we don't have to make a new release.
It is doable on iOS too - http://stackoverflow.com/questions/14048549/how-to-dynamically-load-a-font-under-ios-for-real
I see a much larger issue here. Currently, Titanium only supports loading fonts by "family name". But loading by font family name is not portable between different platforms (ie: Android, iOS, Windows). Even from the same font file. In fact, our sample code on the following guide shows this exact problem and how to deal with it... http://docs.appcelerator.com/platform/latest/#!/guide/Custom_Fonts Also, it's a bit of a guessing game to figure out which name to load per platform, which can cause tech-support issues. Tt can take several builds of guessing at the name to figure it out (very inconvenient and tedious). The following guide indicates this exact problem... http://docs.appcelerator.com/platform/latest/#!/guide/Custom_Fonts-section-src-29004935_safe-id-Q3VzdG9tRm9udHMtRmluZGluZ2Fmb250J3NQb3N0U2NyaXB0bmFtZQ The best and most portable solution is to offer the ability to load fonts by file name (just as easy as loading image files; no guide required). This should be favored over loading them by family name due to the issues mentioned above. So, I recommend that our "font{}" dictionary also support a "fontFilePath" field. Titanium should then select the first font found within the font file, but typically TTF and OTF font files only contain one font within them. If there are multiple fonts contained in the file, then the "fontFamilyName" can be used to select it.
I think a separate JIRA case should be written for the above. [~hknoechel], [~kiguchi], what do you think? (I've done the above in a previous SDK I used to work on and found that this method worked best.) Also, [~kiguchi], we may need to double check if there is a WinRT API for fetching family names within a font file. Back when I worked on Windows Phone 8.0 Silverlight, there was no API to do this and I had to load a font by "
I would think that we might want to use
path
instead offontFilePath
, it may sound a bit redundant.Or, we could follow how Microsoft does it...On Windows, you can use
\[FontFilePath]#\[FontName]
format forfontFamily
property like below. (TIMOB-24299)Maybe we could introduce same format for
fontFamily
on other platforms?[~kiguchi], thanks for your feedback. The advantage of having a separate font "path" field is so that it can also be assigned a file object returned by our Ti.Filesystem API. We currently have a customer who is interested in loading downloaded fonts and this would enable them to do so.