diff --git a/run_time/src/gae_server/www/js/tachyfont/incrementalfontutils.js b/run_time/src/gae_server/www/js/tachyfont/incrementalfontutils.js index f1674fa3..c0d2fffa 100644 --- a/run_time/src/gae_server/www/js/tachyfont/incrementalfontutils.js +++ b/run_time/src/gae_server/www/js/tachyfont/incrementalfontutils.js @@ -58,88 +58,6 @@ tachyfont.IncrementalFontUtils.STYLESHEET_ID = 'Incremental\u00A0Font\u00A0Utils'; -/** - * Get the character to glyphId mapping. - * @param {DataView} baseFont Base font. - * @param {Object} headerInfo Header information. - * @return {Object.} Map of chars to glyphId, - * format4Seg, format12Seg. - */ -tachyfont.IncrementalFontUtils.getCmapMapping = function(headerInfo) { - var cmapMapping = {}; - var charCmapInfo; - // Parse format 4. - if (headerInfo.compact_gos.cmap4) { - var segments = headerInfo.compact_gos.cmap4.segments; - var glyphIdArray = headerInfo.compact_gos.cmap4.glyphIdArray; - var glyphIdIndex = 0; - for (var i = 0; i < segments.length; i++) { - var startCode = segments[i][0]; - var endCode = segments[i][1]; - var idDelta = segments[i][2]; - var idRangeOffset = segments[i][3]; - var length = endCode - startCode + 1; - for (var j = 0; j < length; j++) { - var code = startCode + j; - var glyphId = null; - if (idRangeOffset == 0) { - glyphId = (code + idDelta) % 65536; - } else { - if (goog.DEBUG) { - // TODO(bstell): verify this code. - debugger; - } - glyphId = glyphIdArray[glyphIdIndex++]; - if (glyphId == 0) { - // This code is not mapped in the font. - if (goog.DEBUG) { - // TODO(bstell): verify this code. - debugger; - } - continue; - } - } - charCmapInfo = new tachyfont.CharCmapInfo(glyphId, i, null); - cmapMapping[code] = charCmapInfo; - } - } - } - - - if (!headerInfo.compact_gos.cmap12) { - if (goog.Debug) { - debugger; // TODO(bstell): need to handle this. - } - return cmapMapping; - } - var n12Groups = headerInfo.cmap12.nGroups; - var segments = headerInfo.compact_gos.cmap12.segments; - for (var i = 0; i < n12Groups; i++) { - var startCode = segments[i][0]; - var length = segments[i][1]; - var startGlyphId = segments[i][2]; - for (var j = 0; j < length; j++) { - var code = startCode + j; - charCmapInfo = cmapMapping[code]; - var glyphId = startGlyphId + j; - if (goog.DEBUG) { - if (charCmapInfo) { - goog.asserts.assert(charCmapInfo.glyphId == glyphId, - 'format 4/12 glyphId mismatch'); - } - } - if (!charCmapInfo) { - charCmapInfo = new tachyfont.CharCmapInfo(glyphId, null, null); - cmapMapping[code] = charCmapInfo; - } - charCmapInfo.format12Seg = i; - } - } - return cmapMapping; -}; - - - /** * Parses base font header, set properties. * @param {DataView} baseFont Base font with header. @@ -170,7 +88,8 @@ tachyfont.IncrementalFontUtils.writeCharsetFormat2 = * @param {DataView} baseFont Base font as DataView * @return {DataView} Sanitized base font */ -tachyfont.IncrementalFontUtils.sanitizeBaseFont = function(headerInfo, baseFont) { +tachyfont.IncrementalFontUtils.sanitizeBaseFont = + function(headerInfo, baseFont) { if (headerInfo.isTtf) { headerInfo.dirty = true; @@ -399,3 +318,85 @@ tachyfont.IncrementalFontUtils.setCssFontRule = tachyfont.IncrementalFontUtils.deleteCssRule(ruleToDelete, sheet); sheet.insertRule(rule_str, sheet.cssRules.length); }; + + +/** + * Get the character to glyphId mapping. + * @param {Object} headerInfo Header information. + * @return {Object.} Map of chars to glyphId, + * format4Seg, format12Seg. + */ +tachyfont.IncrementalFontUtils.getCmapMapping = function(headerInfo) { + var cmapMapping = {}; + var charCmapInfo; + // Parse format 4. + if (headerInfo.compact_gos.cmap4) { + var segments = headerInfo.compact_gos.cmap4.segments; + var glyphIdArray = headerInfo.compact_gos.cmap4.glyphIdArray; + var glyphIdIndex = 0; + for (var i = 0; i < segments.length; i++) { + var startCode = segments[i][0]; + var endCode = segments[i][1]; + var idDelta = segments[i][2]; + var idRangeOffset = segments[i][3]; + var length = endCode - startCode + 1; + for (var j = 0; j < length; j++) { + var code = startCode + j; + var glyphId = null; + if (idRangeOffset == 0) { + glyphId = (code + idDelta) % 65536; + } else { + if (goog.DEBUG) { + // TODO(bstell): verify this code. + debugger; + } + glyphId = glyphIdArray[glyphIdIndex++]; + if (glyphId == 0) { + // This code is not mapped in the font. + if (goog.DEBUG) { + // TODO(bstell): verify this code. + debugger; + } + continue; + } + } + charCmapInfo = new tachyfont.CharCmapInfo(glyphId, i, null); + cmapMapping[code] = charCmapInfo; + } + } + } + + + if (!headerInfo.compact_gos.cmap12) { + if (goog.Debug) { + debugger; // TODO(bstell): need to handle this. + } + return cmapMapping; + } + var n12Groups = headerInfo.cmap12.nGroups; + var segments = headerInfo.compact_gos.cmap12.segments; + for (var i = 0; i < n12Groups; i++) { + var startCode = segments[i][0]; + var length = segments[i][1]; + var startGlyphId = segments[i][2]; + for (var j = 0; j < length; j++) { + var code = startCode + j; + charCmapInfo = cmapMapping[code]; + var glyphId = startGlyphId + j; + if (goog.DEBUG) { + if (charCmapInfo) { + goog.asserts.assert(charCmapInfo.glyphId == glyphId, + 'format 4/12 glyphId mismatch'); + } + } + if (!charCmapInfo) { + charCmapInfo = new tachyfont.CharCmapInfo(glyphId, null, null); + cmapMapping[code] = charCmapInfo; + } + charCmapInfo.format12Seg = i; + } + } + return cmapMapping; +}; + +