src/components/text.js
function () {
    var data = this.data;
    var el = this.el;
    var fontSrc;
    var geometry = this.geometry;
    var self = this;

    if (!data.font) { warn('No font specified. Using the default font.'); }

    // Make invisible during font swap.
    this.mesh.visible = false;

    // Look up font URL to use, and perform cached load.
    fontSrc = this.lookupFont(data.font || DEFAULT_FONT) || data.font;
    cache.get(fontSrc, function doLoadFont () {
      return loadFont(fontSrc, data.yOffset);
    }).then(function setFont (font) {
      var fontImgSrc;

      if (font.pages.length !== 1) {
        throw new Error('Currently only single-page bitmap fonts are supported.');
      }

      if (!fontWidthFactors[fontSrc]) {
        font.widthFactor = fontWidthFactors[font] = computeFontWidthFactor(font);
      }

      // Update geometry given font metrics.
      self.updateGeometry(geometry, font);

      // Set font and update layout.
      self.currentFont = font;
      self.updateLayout();

      // Look up font image URL to use, and perform cached load.
      fontImgSrc = self.getFontImageSrc();
      cache.get(fontImgSrc, function () {
        return loadTexture(fontImgSrc);
      }).then(function (image) {
        // Make mesh visible and apply font image as texture.
        var texture = self.texture;
        texture.image = image;
        texture.needsUpdate = true;
        textures[data.font] = texture;
        self.texture = texture;
        self.mesh.visible = true;
        el.emit('textfontset', {font: data.font, fontObj: font});
      }).catch(function (err) {
        error(err.message);
        error(err.stack);
      });
    }).catch(function (err) {
      error(err.message);
      error(err.stack);
    });
  }
function () {
    var data = this.data;
    var el = this.el;
    var fontSrc;
    var geometry = this.geometry;
    var self = this;

    if (!data.font) { warn('No font specified. Using the default font.'); }

    // Make invisible during font swap.
    this.mesh.visible = false;

    // Look up font URL to use, and perform cached load.
    fontSrc = this.lookupFont(data.font || DEFAULT_FONT) || data.font;
    cache.get(fontSrc, function doLoadFont () {
      return loadFont(fontSrc, data.yOffset);
    }).then(function setFont (font) {
      var fontImgSrc;

      if (font.pages.length !== 1) {
        throw new Error('Currently only single-page bitmap fonts are supported.');
      }

      if (!fontWidthFactors[fontSrc]) {
        font.widthFactor = fontWidthFactors[font] = computeFontWidthFactor(font);
      }

      // Update geometry given font metrics.
      self.updateGeometry(geometry, font);

      // Set font and update layout.
      self.currentFont = font;
      self.updateLayout();

      // Look up font image URL to use, and perform cached load.
      fontImgSrc = self.getFontImageSrc();
      cache.get(fontImgSrc, function () {
        return loadTexture(fontImgSrc);
      }).then(function (image) {
        // Make mesh visible and apply font image as texture.
        var texture = self.texture;
        texture.image = image;
        texture.needsUpdate = true;
        textures[data.font] = texture;
        self.texture = texture;
        self.mesh.visible = true;
        el.emit('textfontset', {font: data.font, fontObj: font});
      }).catch(function (err) {
        error(err.message);
        error(err.stack);
      });
    }).catch(function (err) {
      error(err.message);
      error(err.stack);
    });
  }
function ( ) { var data = this . data ; var el = this . el ; var fontSrc ; var geometry = this . geometry ; var self = this ; if ( ! data . font ) { warn ( 'No font specified. Using the default font.' ) ; } // Make invisible during font swap. this . mesh . visible = false ; // Look up font URL to use, and perform cached load. fontSrc = this . lookupFont ( data . font || DEFAULT_FONT ) || data . font ; cache . get ( fontSrc , function doLoadFont ( ) { return loadFont ( fontSrc , data . yOffset ) ; } ) . then ( function setFont ( font ) { var fontImgSrc ; if ( font . pages . length !== 1 ) { throw new Error ( 'Currently only single-page bitmap fonts are supported.' ) ; } if ( ! fontWidthFactors [ fontSrc ] ) { font . widthFactor = fontWidthFactors [ font ] = computeFontWidthFactor ( font ) ; } // Update geometry given font metrics. self . updateGeometry ( geometry , font ) ; // Set font and update layout. self . currentFont = font ; self . updateLayout ( ) ; // Look up font image URL to use, and perform cached load. fontImgSrc = self . getFontImageSrc ( ) ; cache . get ( fontImgSrc , function ( ) { return loadTexture ( fontImgSrc ) ; } ) . then ( function ( image ) { // Make mesh visible and apply font image as texture. var texture = self . texture ; texture . image = image ; texture . needsUpdate = true ; textures [ data . font ] = texture ; self . texture = texture ; self . mesh . visible = true ; el . emit ( 'textfontset' , { font : data . font , fontObj : font } ) ; } ) . catch ( function ( err ) { error ( err . message ) ; error ( err . stack ) ; } ) ; } ) . catch ( function ( err ) { error ( err . message ) ; error ( err . stack ) ; } ) ; }
Load font for geometry, load font image for material, and apply.
Load font for geometry load font image for material and apply .