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

toImage does not honor 'width' when rasterizing a Label. Rasterizing to a window works properly.

    Details

    • Type: Bug
    • Status: Open
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: iOS
    • Environment:

      Description

      function labelHeight2(sOutText, daFont, iWidth, win, doImageView)
      {
      	if (typeof sOutText === undefined || sOutText === null || sOutText == '')
      		return 0;
       
      	var daLabel = Ti.UI.createLabel(
      	{
      		font: daFont,
      		color: 'black',
              backgroundColor:'transparent',
              layout: 'vertical', 
              height: 'auto',
              width: iWidth + 'dp',
              text: sOutText,
              horizontalWrap: true,
              textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
              verticalAlign: Ti.UI.TEXT_VERTICAL_ALIGNMENT_TOP
      	});
      	if (doImageView)
      	{
      	    var blob = daLabel.toImage();
      	    var iWidth = blob.width; // This value return 988 on my machine, it should be 200 or less since I limited the width of the label to 200
      	    Ti.API.info('labelHeight2 width ' + iWidth);
      	    var image = Ti.UI.createImageView({image: blob});
      	    win.add(image);
      	}
      	else
      	    win.add(daLabel);
      	var asize = daLabel.getSize();
      	var iHeight = asize.height; // Return 30 when rasterizing to image and 150 when rasterizing to a window (150 is the correct answer).
      	Ti.API.info('labelHeight2 height ' + iWidth);
       
      	return iHeight;
      }
       
      function doOnOpen()
      {
      	var s = "Now is the time for all good cows to come to the aid of their farmers. Now is the time for all good cows to come to the aid of their farmers. Now is the time for all good cows to come to the aid of their farmers. Now is the time for all good cows to come to the aid of their farmers. Now is the time for all good cows to come to the aid of their farmers.";
      	var iHeight = labelHeight2(s, {fontFamily: 'Helvetice Neue', fontSize: '12dp', fontWeight: 'normal'}, 200, win, false);
      	iHeight = labelHeight2(s, {fontFamily: 'Helvetice Neue', fontSize: '12dp', fontWeight: 'normal'}, 200, win, true);
      	iHeight = labelHeight2('Testing', {fontFamily: 'Helvetice Neue', fontSize: '12dp', fontWeight: 'normal'}, 200, win, false);
      }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              dspells Henry David Spells III
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Backbone Issue Sync

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

                  Git Integration