Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3418] Custom Font support on Android

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-05-16T10:54:39.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.7.0, Sprint 2011-13, Release 1.6.2
ComponentsAndroid
Labelsandroid, custom, enterprise, feature, font, fontfamily, klist, release-1.6.2, release-1.7.0, reported-1.6.1, rplist
ReporterAlan Leard
AssigneeDon Thorp
Created2011-04-15T03:44:50.000+0000
Updated2011-05-16T10:54:39.000+0000

Description

Feature Request

Support for Custom Fonts on Android Devices.

Attachments

FileDateSize
chantelli-antiqua.zip2011-04-15T03:44:50.000+000012903
screenshot.png2011-04-15T03:44:50.000+000030788

Comments

  1. Don Thorp 2011-04-15

    Needs to go on 1.6.2 as well.

  2. Bill Dawson 2011-04-15

    (from [d06a815b13625e60d5f43f717420af9ab2308db6]) Support custom fonts loaded in assets/fonts. [#3418] https://github.com/appcelerator/titanium_mobile/commit/d06a815b13625e60d5f43f717420af9ab2308db6"> https://github.com/appcelerator/titanium_mobile/commit/d06a815b1362...

  3. Bill Dawson 2011-04-15

    (from [89670092e070d0c67f04300becd3b18285b3753a]) Move the default font file location to Resources/fonts so as to take advantage of our built-in builder.py file delta/deletion/addition checking. [#3418] https://github.com/appcelerator/titanium_mobile/commit/89670092e070d0c67f04300becd3b18285b3753a"> https://github.com/appcelerator/titanium_mobile/commit/89670092e070...

  4. Bill Dawson 2011-04-15

    To use this, put your custom (third-party) font files in Resources/fonts (or Resources/android/fonts if you prefer ... both will be handled). Then when setting the font property of the view (Label, TextField, etc.), set the fontFamily member to the base filename of the font file (i.e., the file name without the extension).

    EXAMPLE (to be used for QE testing as well):

    • Create a new project.

    • Create the Resources/fonts folder in that project.

    • Download and unzip the attached Chantelli-Antiqua.zip file, and copy Chantelli-Antiqua.ttf into your Resources/fonts folder.

    • Use this as your app.js:

       Titanium.UI.setBackgroundColor('#000');
       var win = Titanium.UI.createWindow({  
           title:'Test',
           backgroundColor:'#000',
           exitOnClose: true,
           layout: 'vertical'
       });
       
       var lbl = Ti.UI.createLabel({
           text: "Now is the time for all good men to come to the aid of their country",
           font: {fontFamily: 'chantelli_antiqua', fontSize: '15dp'},
           height: 'auto',
           width: 'auto',
           top:10,
           backgroundColor: 'red',
           color: 'white'
       });
       win.add(lbl);
       
       var tf = Ti.UI.createTextField({
           hintText: "Type here",
           font: {fontFamily: 'Chantelli_antiqua', fontSize: '15dp'},
           height: 'auto', width: '100%',
           top: 10
       });
       win.add(tf);
       
       var ta = Ti.UI.createTextArea({
           hintText: "Type here, mein Freund",
           font: {fontFamily: 'Chantelli_antiqua', fontSize: '15dp'},
           height: '80dp', width: '100%', borderRadius: '5',
           top: 10
       });
       win.add(ta);
       
       var btn = Ti.UI.createButton({
           font: {fontFamily: 'Chantelli_antiqua', fontSize: '15dp'},
           title: 'I am a button',
           height: 'auto', width: 'auto',
           top: 10
       });
       win.add(btn);
       
       var btn2 = Ti.UI.createButton({
           font: {fontFamily: 'Chantelli_antiqua', fontSize: '15dp', fontWeight: 'bold'},
           title: 'I am also a button',
           height: 'auto', width: 'auto',
           top: 10
       });
       win.add(btn2);
       
       var btn3 = Ti.UI.createButton({
           font: {fontFamily: 'Chantelli_antiqua', fontSize: '25dp', fontWeight: 'bold'},
           title: 'Ah, but so am I a button',
           height: 'auto', width: 'auto',
           top: 10
       });
       win.add(btn3);
       
       win.open();
       

    Notice in several places we're setting font: {fontFamily: 'Chantelli_antiqua' ... }. (Case doesn't matter.)

    When you run it, you will (or should) notice that the font is not a standard font. See attached screenshot.png.

  5. Bill Dawson 2011-04-15

    (from [0243d42c591e2ec96defa95302597f27fb21af19]) Move the default font file location to Resources/fonts so as to take advantage of our built-in builder.py file delta/deletion/addition checking. [#3418] https://github.com/appcelerator/titanium_mobile/commit/0243d42c591e2ec96defa95302597f27fb21af19"> https://github.com/appcelerator/titanium_mobile/commit/0243d42c591e...

  6. Bill Dawson 2011-04-15

    (from [9a03aba397daa01ca562a7f82192bf82791cd0c1]) Support custom fonts loaded in assets/fonts. [#3418] https://github.com/appcelerator/titanium_mobile/commit/9a03aba397daa01ca562a7f82192bf82791cd0c1"> https://github.com/appcelerator/titanium_mobile/commit/9a03aba397da...

  7. Bill Dawson 2011-04-15

    QE: please test both in master and 1_6_X, as it was specifically requested that this feature be added to 1_6_X

  8. Natalie Huynh 2011-04-18

    Tested with [INFO] Titanium SDK version: 1.6.2 (04/18/11 17:16 878906d) on Nexus S 2.3.2 Emulator 2.1

JSON Source