<commit_before>/*global underscore, $, ko, N*/


'use strict';


var _ = underscore;


////////////////////////////////////////////////////////////////////////////////


var
embedded_fonts    = require('^/lib/embedded_fonts/configs'),
glyphs_map        = require('^/lib/embedded_fonts/glyphs_map'),
trackNameChanges  = require('./_namesTracker'),
trackCodeChanges  = require('./_codesTracker');


// Int to char, with fix for big numbers
// see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/fromCharCode
function fixedFromCharCode(code) {
  /*jshint bitwise: false*/
  if (code > 0xffff) {
    code -= 0x10000;
    var surrogate1 = 0xd800 + (code >> 10),
        surrogate2 = 0xdc00 + (code & 0x3ff);
    return String.fromCharCode(surrogate1, surrogate2);
  } else {
    return String.fromCharCode(code);
  }
}


// Char to Int, with fix for big numbers
function fixedCharCodeAt(char) {
  /*jshint bitwise: false*/
  var char1 = char.charCodeAt(0),
      char2 = char.charCodeAt(1);

  if ((char.length >= 2) &&
      ((char1 & 0xfc00) === 0xd800) &&
      ((char2 & 0xfc00) === 0xdc00)) {
    return 0x10000 + ((char1 - 0xd800) << 10) + (char2 - 0xdc00);
  } else {
    return char1;
  }
}


////////////////////////////////////////////////////////////////////////////////


function GlyphModel(font, data, options) {

  //
  // Essential properties
  //

  this.uid              = data.uid;
  this.originalName     = data.css;
  this.originalCode     = data.code;

  //
  // Helper properties
  //

  this.font             = font;
  
  // we search by name AND aliases
  this.keywords         = [this.originalName].concat(data.search || []).join(',');
  this.charRef          = fixedFromCharCode(glyphs_map[font.fontname][data.uid]);
  this.cssExt           = data['css-ext'];
  this.tooltip          = "name: '" + this.originalName + "'" +
                          (this.keywords ? ', tags: ' + this.keywords : '');

  //
  // Actual properties state
  //

  this.selected         = ko.observable(false);
  this.name             = ko.observable(this.originalName);
  this.code             = ko.observable(this.originalCode);

  //
  // Serialization. Make sure to update this method to have
  // desired fields sent to the server (by font builder).
  //

  this.serialize        = function () {
    return {
      uid:        this.uid,

      orig_css:   this.originalName,
      orig_code:  this.originalCode,

      css:        this.name(),
      code:       this.code(),

      src:        this.font.fontname<commit_msg>fixed back tooltip texts & imptover identation<commit_after>/*global underscore, $, ko, N*/


'use strict';


var _ = underscore;


////////////////////////////////////////////////////////////////////////////////


var
embedded_fonts    = require('^/lib/embedded_fonts/configs'),
glyphs_map        = require('^/lib/embedded_fonts/glyphs_map'),
trackNameChanges  = require('./_namesTracker'),
trackCodeChanges  = require('./_codesTracker');


// Int to char, with fix for big numbers
// see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/fromCharCode
function fixedFromCharCode(code) {
  /*jshint bitwise: false*/
  if (code > 0xffff) {
    code -= 0x10000;
    var surrogate1 = 0xd800 + (code >> 10),
        surrogate2 = 0xdc00 + (code & 0x3ff);
    return String.fromCharCode(surrogate1, surrogate2);
  } else {
    return String.fromCharCode(code);
  }
}


// Char to Int, with fix for big numbers
function fixedCharCodeAt(char) {
  /*jshint bitwise: false*/
  var char1 = char.charCodeAt(0),
      char2 = char.charCodeAt(1);

  if ((char.length >= 2) &&
      ((char1 & 0xfc00) === 0xd800) &&
      ((char2 & 0xfc00) === 0xdc00)) {
    return 0x10000 + ((char1 - 0xd800) << 10) + (char2 - 0xdc00);
  } else {
    return char1;
  }
}


////////////////////////////////////////////////////////////////////////////////


function GlyphModel(font, data, options) {

  //
  // Essential properties
  //

  this.uid              = data.uid;
  this.originalName     = data.css;
  this.originalCode     = data.code;

  //
  // Helper properties
  //

  this.font             = font;
  
  // we search by name AND aliases
  this.keywords         = [this.originalName].concat(data.search || []).join(',');


  this.charRef          = fixedFromCharCode(glyphs_map[font.fontname][data.uid]);
  this.cssExt           = data['css-ext'];
  this.tooltip          = "name: '" + this.originalName + "'" +
                          (data.search ? ',   tags: ' + data.search.join(', ') : '');

  //
  // Actual properties state
  //

  this.selected         = ko.observable(false);
  this.name             = ko.observable(this.originalName);
  this.code             = ko.observable(this.originalCode);

  //
  // Serialization. Make sure to update this method to have
  // desired fields sent to the server (by font builder).
  //

  this.serialize        = function () {
    return {
      uid:        this.uid,

      orig_css:   this.originalName,
      orig_code:  this.originalCode,

      css:        this.name(),
      code:       this.code(),

      src:        this.font.fontname
{'fraction_non_alphanumeric': 0.19593023255813954, 'fraction_numerical': 0.023255813953488372, 'mean_word_length': 1.8880805819809736, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5144254', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1560, 'n_words': 336}