Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-18853

Android: Custom Fonts not working in Attributed Strings

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Release 4.1.0
    • Component/s: Android
    • Environment:

      Appc Studio: 4.0.0.201504021909
      Ti SDK: 4.0.0.Beta2 and 4.0.0.Beta3
      CLI: 4.0.0-beta3
      MAC: 10.9.5
      Device: Nexus 6 - android 5.1

    • Story Points:
      5
    • Sprint:
      2015 Sprint 09 SDK

      Description

      Problem

      The Ti.UI.ATTRIBUTE_FONT part of TIMOB-15998 doesn't appear to be working with custom fonts. TIMOB-15998 didn't demonstrate custom fonts working. The built-in font Roboto and its variants are working, as well as the built-in families monospace and serif. However, custom fonts placed in app/assets/android/fonts as well as app/assets/fonts are not working.

      Below, I'm expecting to see the first line of text, "Chantelli Antiqua," to be displayed in the custom font, which is more of a serif font than the sans-serif shown. Instead, however, we see the text displayed in the default font.

      Test case

      app.js

      var win = Titanium.UI.createWindow({
      	backgroundColor : "#ffffff"
      });
       
      var scrollView = Ti.UI.createScrollView({
      	height : Ti.UI.FILL,
      	width : Ti.UI.FILL,
      	layout : "vertical"
      });
       
      win.add(scrollView);
       
      win.open();
       
      var fonts = ["Chantelli_Antiqua", "serif", "monospace", "sans-serif", "sans-serif-light", "sans-serif-condensed"];
       
      _.each(fonts, function(font) {
      	var text = font;
       
      	var attr = Titanium.UI.createAttributedString({
      		text : text,
      		attributes : [
      		{
      			type : Ti.UI.ATTRIBUTE_FONT,
      			value : {
      				font : {
      					fontSize : 20,
      					fontFamily : font
      				}
      			},
      			range : [0, text.length]
      		},
      		{
      			type : Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
      			value : "#000000",
      			range : [0, text.length]
      		}]
      	});
       
      	var label = Titanium.UI.createLabel({
      		top : 10,
      		left : 10,
      		right : 10,
      		height : Titanium.UI.SIZE,
      		attributedString : attr
      	});
       
      	scrollView.add(label);
      });
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                msamah Ashraf Abu (Inactive)
                Reporter:
                athorne Alex Bernier
                Reviewer:
                Hieu Pham
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-19880
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Source Code