fonts.js 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2017 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. 'use strict';
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.getFontType = exports.ProblematicCharRanges = exports.IdentityToUnicodeMap = exports.ToUnicodeMap = exports.FontFlags = exports.Font = exports.ErrorFont = exports.PRIVATE_USE_OFFSET_END = exports.PRIVATE_USE_OFFSET_START = exports.SEAC_ANALYSIS_ENABLED = undefined;
  27. var _util = require('../shared/util');
  28. var _cff_parser = require('./cff_parser');
  29. var _glyphlist = require('./glyphlist');
  30. var _encodings = require('./encodings');
  31. var _standard_fonts = require('./standard_fonts');
  32. var _unicode = require('./unicode');
  33. var _font_renderer = require('./font_renderer');
  34. var _stream = require('./stream');
  35. var _type1_parser = require('./type1_parser');
  36. var PRIVATE_USE_OFFSET_START = 0xE000;
  37. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  38. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  39. var PDF_GLYPH_SPACE_UNITS = 1000;
  40. var SEAC_ANALYSIS_ENABLED = false;
  41. var FontFlags = {
  42. FixedPitch: 1,
  43. Serif: 2,
  44. Symbolic: 4,
  45. Script: 8,
  46. Nonsymbolic: 32,
  47. Italic: 64,
  48. AllCap: 65536,
  49. SmallCap: 131072,
  50. ForceBold: 262144
  51. };
  52. var MacStandardGlyphOrdering = ['.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis', 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis', 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar', 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply', 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter', 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla', 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  53. function adjustWidths(properties) {
  54. if (!properties.fontMatrix) {
  55. return;
  56. }
  57. if (properties.fontMatrix[0] === _util.FONT_IDENTITY_MATRIX[0]) {
  58. return;
  59. }
  60. var scale = 0.001 / properties.fontMatrix[0];
  61. var glyphsWidths = properties.widths;
  62. for (var glyph in glyphsWidths) {
  63. glyphsWidths[glyph] *= scale;
  64. }
  65. properties.defaultWidth *= scale;
  66. }
  67. function adjustToUnicode(properties, builtInEncoding) {
  68. if (properties.hasIncludedToUnicodeMap) {
  69. return;
  70. }
  71. if (properties.hasEncoding) {
  72. return;
  73. }
  74. if (builtInEncoding === properties.defaultEncoding) {
  75. return;
  76. }
  77. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  78. return;
  79. }
  80. var toUnicode = [],
  81. glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
  82. for (var charCode in builtInEncoding) {
  83. var glyphName = builtInEncoding[charCode];
  84. var unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
  85. if (unicode !== -1) {
  86. toUnicode[charCode] = String.fromCharCode(unicode);
  87. }
  88. }
  89. properties.toUnicode.amend(toUnicode);
  90. }
  91. function getFontType(type, subtype) {
  92. switch (type) {
  93. case 'Type1':
  94. return subtype === 'Type1C' ? _util.FontType.TYPE1C : _util.FontType.TYPE1;
  95. case 'CIDFontType0':
  96. return subtype === 'CIDFontType0C' ? _util.FontType.CIDFONTTYPE0C : _util.FontType.CIDFONTTYPE0;
  97. case 'OpenType':
  98. return _util.FontType.OPENTYPE;
  99. case 'TrueType':
  100. return _util.FontType.TRUETYPE;
  101. case 'CIDFontType2':
  102. return _util.FontType.CIDFONTTYPE2;
  103. case 'MMType1':
  104. return _util.FontType.MMTYPE1;
  105. case 'Type0':
  106. return _util.FontType.TYPE0;
  107. default:
  108. return _util.FontType.UNKNOWN;
  109. }
  110. }
  111. function recoverGlyphName(name, glyphsUnicodeMap) {
  112. if (glyphsUnicodeMap[name] !== undefined) {
  113. return name;
  114. }
  115. var unicode = (0, _unicode.getUnicodeForGlyph)(name, glyphsUnicodeMap);
  116. if (unicode !== -1) {
  117. for (var key in glyphsUnicodeMap) {
  118. if (glyphsUnicodeMap[key] === unicode) {
  119. return key;
  120. }
  121. }
  122. }
  123. (0, _util.info)('Unable to recover a standard glyph name for: ' + name);
  124. return name;
  125. }
  126. var Glyph = function GlyphClosure() {
  127. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  128. this.fontChar = fontChar;
  129. this.unicode = unicode;
  130. this.accent = accent;
  131. this.width = width;
  132. this.vmetric = vmetric;
  133. this.operatorListId = operatorListId;
  134. this.isSpace = isSpace;
  135. this.isInFont = isInFont;
  136. }
  137. Glyph.prototype.matchesForCache = function (fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  138. return this.fontChar === fontChar && this.unicode === unicode && this.accent === accent && this.width === width && this.vmetric === vmetric && this.operatorListId === operatorListId && this.isSpace === isSpace && this.isInFont === isInFont;
  139. };
  140. return Glyph;
  141. }();
  142. var ToUnicodeMap = function ToUnicodeMapClosure() {
  143. function ToUnicodeMap() {
  144. var cmap = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  145. this._map = cmap;
  146. }
  147. ToUnicodeMap.prototype = {
  148. get length() {
  149. return this._map.length;
  150. },
  151. forEach: function forEach(callback) {
  152. for (var charCode in this._map) {
  153. callback(charCode, this._map[charCode].charCodeAt(0));
  154. }
  155. },
  156. has: function has(i) {
  157. return this._map[i] !== undefined;
  158. },
  159. get: function get(i) {
  160. return this._map[i];
  161. },
  162. charCodeOf: function charCodeOf(value) {
  163. var map = this._map;
  164. if (map.length <= 0x10000) {
  165. return map.indexOf(value);
  166. }
  167. for (var charCode in map) {
  168. if (map[charCode] === value) {
  169. return charCode | 0;
  170. }
  171. }
  172. return -1;
  173. },
  174. amend: function amend(map) {
  175. for (var charCode in map) {
  176. this._map[charCode] = map[charCode];
  177. }
  178. }
  179. };
  180. return ToUnicodeMap;
  181. }();
  182. var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
  183. function IdentityToUnicodeMap(firstChar, lastChar) {
  184. this.firstChar = firstChar;
  185. this.lastChar = lastChar;
  186. }
  187. IdentityToUnicodeMap.prototype = {
  188. get length() {
  189. return this.lastChar + 1 - this.firstChar;
  190. },
  191. forEach: function forEach(callback) {
  192. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  193. callback(i, i);
  194. }
  195. },
  196. has: function has(i) {
  197. return this.firstChar <= i && i <= this.lastChar;
  198. },
  199. get: function get(i) {
  200. if (this.firstChar <= i && i <= this.lastChar) {
  201. return String.fromCharCode(i);
  202. }
  203. return undefined;
  204. },
  205. charCodeOf: function charCodeOf(v) {
  206. return Number.isInteger(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
  207. },
  208. amend: function amend(map) {
  209. (0, _util.unreachable)('Should not call amend()');
  210. }
  211. };
  212. return IdentityToUnicodeMap;
  213. }();
  214. var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
  215. function writeInt16(dest, offset, num) {
  216. dest[offset] = num >> 8 & 0xFF;
  217. dest[offset + 1] = num & 0xFF;
  218. }
  219. function writeInt32(dest, offset, num) {
  220. dest[offset] = num >> 24 & 0xFF;
  221. dest[offset + 1] = num >> 16 & 0xFF;
  222. dest[offset + 2] = num >> 8 & 0xFF;
  223. dest[offset + 3] = num & 0xFF;
  224. }
  225. function writeData(dest, offset, data) {
  226. var i, ii;
  227. if (data instanceof Uint8Array) {
  228. dest.set(data, offset);
  229. } else if (typeof data === 'string') {
  230. for (i = 0, ii = data.length; i < ii; i++) {
  231. dest[offset++] = data.charCodeAt(i) & 0xFF;
  232. }
  233. } else {
  234. for (i = 0, ii = data.length; i < ii; i++) {
  235. dest[offset++] = data[i] & 0xFF;
  236. }
  237. }
  238. }
  239. function OpenTypeFileBuilder(sfnt) {
  240. this.sfnt = sfnt;
  241. this.tables = Object.create(null);
  242. }
  243. OpenTypeFileBuilder.getSearchParams = function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  244. var maxPower2 = 1,
  245. log2 = 0;
  246. while ((maxPower2 ^ entriesCount) > maxPower2) {
  247. maxPower2 <<= 1;
  248. log2++;
  249. }
  250. var searchRange = maxPower2 * entrySize;
  251. return {
  252. range: searchRange,
  253. entry: log2,
  254. rangeShift: entrySize * entriesCount - searchRange
  255. };
  256. };
  257. var OTF_HEADER_SIZE = 12;
  258. var OTF_TABLE_ENTRY_SIZE = 16;
  259. OpenTypeFileBuilder.prototype = {
  260. toArray: function OpenTypeFileBuilder_toArray() {
  261. var sfnt = this.sfnt;
  262. var tables = this.tables;
  263. var tablesNames = Object.keys(tables);
  264. tablesNames.sort();
  265. var numTables = tablesNames.length;
  266. var i, j, jj, table, tableName;
  267. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  268. var tableOffsets = [offset];
  269. for (i = 0; i < numTables; i++) {
  270. table = tables[tablesNames[i]];
  271. var paddedLength = (table.length + 3 & ~3) >>> 0;
  272. offset += paddedLength;
  273. tableOffsets.push(offset);
  274. }
  275. var file = new Uint8Array(offset);
  276. for (i = 0; i < numTables; i++) {
  277. table = tables[tablesNames[i]];
  278. writeData(file, tableOffsets[i], table);
  279. }
  280. if (sfnt === 'true') {
  281. sfnt = (0, _util.string32)(0x00010000);
  282. }
  283. file[0] = sfnt.charCodeAt(0) & 0xFF;
  284. file[1] = sfnt.charCodeAt(1) & 0xFF;
  285. file[2] = sfnt.charCodeAt(2) & 0xFF;
  286. file[3] = sfnt.charCodeAt(3) & 0xFF;
  287. writeInt16(file, 4, numTables);
  288. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  289. writeInt16(file, 6, searchParams.range);
  290. writeInt16(file, 8, searchParams.entry);
  291. writeInt16(file, 10, searchParams.rangeShift);
  292. offset = OTF_HEADER_SIZE;
  293. for (i = 0; i < numTables; i++) {
  294. tableName = tablesNames[i];
  295. file[offset] = tableName.charCodeAt(0) & 0xFF;
  296. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  297. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  298. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  299. var checksum = 0;
  300. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  301. var quad = (0, _util.readUint32)(file, j);
  302. checksum = checksum + quad >>> 0;
  303. }
  304. writeInt32(file, offset + 4, checksum);
  305. writeInt32(file, offset + 8, tableOffsets[i]);
  306. writeInt32(file, offset + 12, tables[tableName].length);
  307. offset += OTF_TABLE_ENTRY_SIZE;
  308. }
  309. return file;
  310. },
  311. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  312. if (tag in this.tables) {
  313. throw new Error('Table ' + tag + ' already exists');
  314. }
  315. this.tables[tag] = data;
  316. }
  317. };
  318. return OpenTypeFileBuilder;
  319. }();
  320. var ProblematicCharRanges = new Int32Array([0x0000, 0x0020, 0x007F, 0x00A1, 0x00AD, 0x00AE, 0x0600, 0x0780, 0x08A0, 0x10A0, 0x1780, 0x1800, 0x1C00, 0x1C50, 0x2000, 0x2010, 0x2011, 0x2012, 0x2028, 0x2030, 0x205F, 0x2070, 0x25CC, 0x25CD, 0x3000, 0x3001, 0x3164, 0x3165, 0xAA60, 0xAA80, 0xD800, 0xE000, 0xFFF0, 0x10000]);
  321. var Font = function FontClosure() {
  322. function Font(name, file, properties) {
  323. var charCode;
  324. this.name = name;
  325. this.loadedName = properties.loadedName;
  326. this.isType3Font = properties.isType3Font;
  327. this.sizes = [];
  328. this.missingFile = false;
  329. this.glyphCache = Object.create(null);
  330. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  331. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  332. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  333. var type = properties.type;
  334. var subtype = properties.subtype;
  335. this.type = type;
  336. this.subtype = subtype;
  337. this.fallbackName = this.isMonospace ? 'monospace' : this.isSerifFont ? 'serif' : 'sans-serif';
  338. this.differences = properties.differences;
  339. this.widths = properties.widths;
  340. this.defaultWidth = properties.defaultWidth;
  341. this.composite = properties.composite;
  342. this.wideChars = properties.wideChars;
  343. this.cMap = properties.cMap;
  344. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  345. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  346. this.fontMatrix = properties.fontMatrix;
  347. this.bbox = properties.bbox;
  348. this.defaultEncoding = properties.defaultEncoding;
  349. this.toUnicode = properties.toUnicode;
  350. this.fallbackToUnicode = properties.fallbackToUnicode || new ToUnicodeMap();
  351. this.toFontChar = [];
  352. if (properties.type === 'Type3') {
  353. for (charCode = 0; charCode < 256; charCode++) {
  354. this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
  355. }
  356. this.fontType = _util.FontType.TYPE3;
  357. return;
  358. }
  359. this.cidEncoding = properties.cidEncoding;
  360. this.vertical = properties.vertical;
  361. if (this.vertical) {
  362. this.vmetrics = properties.vmetrics;
  363. this.defaultVMetrics = properties.defaultVMetrics;
  364. }
  365. if (!file || file.isEmpty) {
  366. if (file) {
  367. (0, _util.warn)('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  368. }
  369. this.fallbackToSystemFont();
  370. return;
  371. }
  372. if (subtype === 'Type1C') {
  373. if (type !== 'Type1' && type !== 'MMType1') {
  374. if (isTrueTypeFile(file)) {
  375. subtype = 'TrueType';
  376. } else {
  377. type = 'Type1';
  378. }
  379. } else if (isOpenTypeFile(file)) {
  380. subtype = 'OpenType';
  381. }
  382. }
  383. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  384. type = 'CIDFontType0';
  385. }
  386. if (type === 'CIDFontType0') {
  387. if (isType1File(file)) {
  388. subtype = 'CIDFontType0';
  389. } else if (isOpenTypeFile(file)) {
  390. subtype = 'OpenType';
  391. } else {
  392. subtype = 'CIDFontType0C';
  393. }
  394. }
  395. if (subtype === 'OpenType' && type !== 'OpenType') {
  396. type = 'OpenType';
  397. }
  398. try {
  399. var data;
  400. switch (type) {
  401. case 'MMType1':
  402. (0, _util.info)('MMType1 font (' + name + '), falling back to Type1.');
  403. case 'Type1':
  404. case 'CIDFontType0':
  405. this.mimetype = 'font/opentype';
  406. var cff = subtype === 'Type1C' || subtype === 'CIDFontType0C' ? new CFFFont(file, properties) : new Type1Font(name, file, properties);
  407. adjustWidths(properties);
  408. data = this.convert(name, cff, properties);
  409. break;
  410. case 'OpenType':
  411. case 'TrueType':
  412. case 'CIDFontType2':
  413. this.mimetype = 'font/opentype';
  414. data = this.checkAndRepair(name, file, properties);
  415. if (this.isOpenType) {
  416. adjustWidths(properties);
  417. type = 'OpenType';
  418. }
  419. break;
  420. default:
  421. throw new _util.FormatError('Font ' + type + ' is not supported');
  422. }
  423. } catch (e) {
  424. if (!(e instanceof _util.FormatError)) {
  425. throw e;
  426. }
  427. (0, _util.warn)(e);
  428. this.fallbackToSystemFont();
  429. return;
  430. }
  431. this.data = data;
  432. this.fontType = getFontType(type, subtype);
  433. this.fontMatrix = properties.fontMatrix;
  434. this.widths = properties.widths;
  435. this.defaultWidth = properties.defaultWidth;
  436. this.toUnicode = properties.toUnicode;
  437. this.encoding = properties.baseEncoding;
  438. this.seacMap = properties.seacMap;
  439. this.loading = true;
  440. }
  441. Font.getFontID = function () {
  442. var ID = 1;
  443. return function Font_getFontID() {
  444. return String(ID++);
  445. };
  446. }();
  447. function int16(b0, b1) {
  448. return (b0 << 8) + b1;
  449. }
  450. function writeSignedInt16(bytes, index, value) {
  451. bytes[index + 1] = value;
  452. bytes[index] = value >>> 8;
  453. }
  454. function signedInt16(b0, b1) {
  455. var value = (b0 << 8) + b1;
  456. return value & 1 << 15 ? value - 0x10000 : value;
  457. }
  458. function int32(b0, b1, b2, b3) {
  459. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  460. }
  461. function string16(value) {
  462. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  463. }
  464. function safeString16(value) {
  465. value = value > 0x7FFF ? 0x7FFF : value < -0x8000 ? -0x8000 : value;
  466. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  467. }
  468. function isTrueTypeFile(file) {
  469. var header = file.peekBytes(4);
  470. return (0, _util.readUint32)(header, 0) === 0x00010000;
  471. }
  472. function isOpenTypeFile(file) {
  473. var header = file.peekBytes(4);
  474. return (0, _util.bytesToString)(header) === 'OTTO';
  475. }
  476. function isType1File(file) {
  477. var header = file.peekBytes(2);
  478. if (header[0] === 0x25 && header[1] === 0x21) {
  479. return true;
  480. }
  481. if (header[0] === 0x80 && header[1] === 0x01) {
  482. return true;
  483. }
  484. return false;
  485. }
  486. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  487. var toFontChar = [],
  488. unicode;
  489. for (var i = 0, ii = encoding.length; i < ii; i++) {
  490. unicode = (0, _unicode.getUnicodeForGlyph)(encoding[i], glyphsUnicodeMap);
  491. if (unicode !== -1) {
  492. toFontChar[i] = unicode;
  493. }
  494. }
  495. for (var charCode in differences) {
  496. unicode = (0, _unicode.getUnicodeForGlyph)(differences[charCode], glyphsUnicodeMap);
  497. if (unicode !== -1) {
  498. toFontChar[+charCode] = unicode;
  499. }
  500. }
  501. return toFontChar;
  502. }
  503. function isProblematicUnicodeLocation(code) {
  504. var i = 0,
  505. j = ProblematicCharRanges.length - 1;
  506. while (i < j) {
  507. var c = i + j + 1 >> 1;
  508. if (code < ProblematicCharRanges[c]) {
  509. j = c - 1;
  510. } else {
  511. i = c;
  512. }
  513. }
  514. return !(i & 1);
  515. }
  516. function adjustMapping(charCodeToGlyphId, properties, missingGlyphs) {
  517. var toUnicode = properties.toUnicode;
  518. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  519. var isIdentityUnicode = properties.toUnicode instanceof IdentityToUnicodeMap;
  520. var newMap = Object.create(null);
  521. var toFontChar = [];
  522. var usedFontCharCodes = [];
  523. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  524. for (var originalCharCode in charCodeToGlyphId) {
  525. originalCharCode |= 0;
  526. var glyphId = charCodeToGlyphId[originalCharCode];
  527. if (missingGlyphs[glyphId]) {
  528. continue;
  529. }
  530. var fontCharCode = originalCharCode;
  531. var hasUnicodeValue = false;
  532. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  533. hasUnicodeValue = true;
  534. var unicode = toUnicode.get(fontCharCode);
  535. if (unicode.length === 1) {
  536. fontCharCode = unicode.charCodeAt(0);
  537. }
  538. }
  539. if (usedFontCharCodes[fontCharCode] !== undefined || isProblematicUnicodeLocation(fontCharCode) || isSymbolic && !hasUnicodeValue) {
  540. do {
  541. if (nextAvailableFontCharCode > PRIVATE_USE_OFFSET_END) {
  542. (0, _util.warn)('Ran out of space in font private use area.');
  543. break;
  544. }
  545. fontCharCode = nextAvailableFontCharCode++;
  546. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  547. fontCharCode = 0xF020;
  548. nextAvailableFontCharCode = fontCharCode + 1;
  549. }
  550. } while (usedFontCharCodes[fontCharCode] !== undefined);
  551. }
  552. newMap[fontCharCode] = glyphId;
  553. toFontChar[originalCharCode] = fontCharCode;
  554. usedFontCharCodes[fontCharCode] = true;
  555. }
  556. return {
  557. toFontChar: toFontChar,
  558. charCodeToGlyphId: newMap,
  559. nextAvailableFontCharCode: nextAvailableFontCharCode
  560. };
  561. }
  562. function getRanges(glyphs, numGlyphs) {
  563. var codes = [];
  564. for (var charCode in glyphs) {
  565. if (glyphs[charCode] >= numGlyphs) {
  566. continue;
  567. }
  568. codes.push({
  569. fontCharCode: charCode | 0,
  570. glyphId: glyphs[charCode]
  571. });
  572. }
  573. if (codes.length === 0) {
  574. codes.push({
  575. fontCharCode: 0,
  576. glyphId: 0
  577. });
  578. }
  579. codes.sort(function fontGetRangesSort(a, b) {
  580. return a.fontCharCode - b.fontCharCode;
  581. });
  582. var ranges = [];
  583. var length = codes.length;
  584. for (var n = 0; n < length;) {
  585. var start = codes[n].fontCharCode;
  586. var codeIndices = [codes[n].glyphId];
  587. ++n;
  588. var end = start;
  589. while (n < length && end + 1 === codes[n].fontCharCode) {
  590. codeIndices.push(codes[n].glyphId);
  591. ++end;
  592. ++n;
  593. if (end === 0xFFFF) {
  594. break;
  595. }
  596. }
  597. ranges.push([start, end, codeIndices]);
  598. }
  599. return ranges;
  600. }
  601. function createCmapTable(glyphs, numGlyphs) {
  602. var ranges = getRanges(glyphs, numGlyphs);
  603. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  604. var cmap = '\x00\x00' + string16(numTables) + '\x00\x03' + '\x00\x01' + (0, _util.string32)(4 + numTables * 8);
  605. var i, ii, j, jj;
  606. for (i = ranges.length - 1; i >= 0; --i) {
  607. if (ranges[i][0] <= 0xFFFF) {
  608. break;
  609. }
  610. }
  611. var bmpLength = i + 1;
  612. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  613. ranges[i][1] = 0xFFFE;
  614. }
  615. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  616. var segCount = bmpLength + trailingRangesCount;
  617. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  618. var startCount = '';
  619. var endCount = '';
  620. var idDeltas = '';
  621. var idRangeOffsets = '';
  622. var glyphsIds = '';
  623. var bias = 0;
  624. var range, start, end, codes;
  625. for (i = 0, ii = bmpLength; i < ii; i++) {
  626. range = ranges[i];
  627. start = range[0];
  628. end = range[1];
  629. startCount += string16(start);
  630. endCount += string16(end);
  631. codes = range[2];
  632. var contiguous = true;
  633. for (j = 1, jj = codes.length; j < jj; ++j) {
  634. if (codes[j] !== codes[j - 1] + 1) {
  635. contiguous = false;
  636. break;
  637. }
  638. }
  639. if (!contiguous) {
  640. var offset = (segCount - i) * 2 + bias * 2;
  641. bias += end - start + 1;
  642. idDeltas += string16(0);
  643. idRangeOffsets += string16(offset);
  644. for (j = 0, jj = codes.length; j < jj; ++j) {
  645. glyphsIds += string16(codes[j]);
  646. }
  647. } else {
  648. var startCode = codes[0];
  649. idDeltas += string16(startCode - start & 0xFFFF);
  650. idRangeOffsets += string16(0);
  651. }
  652. }
  653. if (trailingRangesCount > 0) {
  654. endCount += '\xFF\xFF';
  655. startCount += '\xFF\xFF';
  656. idDeltas += '\x00\x01';
  657. idRangeOffsets += '\x00\x00';
  658. }
  659. var format314 = '\x00\x00' + string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + '\x00\x00' + startCount + idDeltas + idRangeOffsets + glyphsIds;
  660. var format31012 = '';
  661. var header31012 = '';
  662. if (numTables > 1) {
  663. cmap += '\x00\x03' + '\x00\x0A' + (0, _util.string32)(4 + numTables * 8 + 4 + format314.length);
  664. format31012 = '';
  665. for (i = 0, ii = ranges.length; i < ii; i++) {
  666. range = ranges[i];
  667. start = range[0];
  668. codes = range[2];
  669. var code = codes[0];
  670. for (j = 1, jj = codes.length; j < jj; ++j) {
  671. if (codes[j] !== codes[j - 1] + 1) {
  672. end = range[0] + j - 1;
  673. format31012 += (0, _util.string32)(start) + (0, _util.string32)(end) + (0, _util.string32)(code);
  674. start = end + 1;
  675. code = codes[j];
  676. }
  677. }
  678. format31012 += (0, _util.string32)(start) + (0, _util.string32)(range[1]) + (0, _util.string32)(code);
  679. }
  680. header31012 = '\x00\x0C' + '\x00\x00' + (0, _util.string32)(format31012.length + 16) + '\x00\x00\x00\x00' + (0, _util.string32)(format31012.length / 12);
  681. }
  682. return cmap + '\x00\x04' + string16(format314.length + 4) + format314 + header31012 + format31012;
  683. }
  684. function validateOS2Table(os2) {
  685. var stream = new _stream.Stream(os2.data);
  686. var version = stream.getUint16();
  687. stream.getBytes(60);
  688. var selection = stream.getUint16();
  689. if (version < 4 && selection & 0x0300) {
  690. return false;
  691. }
  692. var firstChar = stream.getUint16();
  693. var lastChar = stream.getUint16();
  694. if (firstChar > lastChar) {
  695. return false;
  696. }
  697. stream.getBytes(6);
  698. var usWinAscent = stream.getUint16();
  699. if (usWinAscent === 0) {
  700. return false;
  701. }
  702. os2.data[8] = os2.data[9] = 0;
  703. return true;
  704. }
  705. function createOS2Table(properties, charstrings, override) {
  706. override = override || {
  707. unitsPerEm: 0,
  708. yMax: 0,
  709. yMin: 0,
  710. ascent: 0,
  711. descent: 0
  712. };
  713. var ulUnicodeRange1 = 0;
  714. var ulUnicodeRange2 = 0;
  715. var ulUnicodeRange3 = 0;
  716. var ulUnicodeRange4 = 0;
  717. var firstCharIndex = null;
  718. var lastCharIndex = 0;
  719. if (charstrings) {
  720. for (var code in charstrings) {
  721. code |= 0;
  722. if (firstCharIndex > code || !firstCharIndex) {
  723. firstCharIndex = code;
  724. }
  725. if (lastCharIndex < code) {
  726. lastCharIndex = code;
  727. }
  728. var position = (0, _unicode.getUnicodeRangeFor)(code);
  729. if (position < 32) {
  730. ulUnicodeRange1 |= 1 << position;
  731. } else if (position < 64) {
  732. ulUnicodeRange2 |= 1 << position - 32;
  733. } else if (position < 96) {
  734. ulUnicodeRange3 |= 1 << position - 64;
  735. } else if (position < 123) {
  736. ulUnicodeRange4 |= 1 << position - 96;
  737. } else {
  738. throw new _util.FormatError('Unicode ranges Bits > 123 are reserved for internal usage');
  739. }
  740. }
  741. } else {
  742. firstCharIndex = 0;
  743. lastCharIndex = 255;
  744. }
  745. var bbox = properties.bbox || [0, 0, 0, 0];
  746. var unitsPerEm = override.unitsPerEm || 1 / (properties.fontMatrix || _util.FONT_IDENTITY_MATRIX)[0];
  747. var scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;
  748. var typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));
  749. var typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));
  750. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  751. typoDescent = -typoDescent;
  752. }
  753. var winAscent = override.yMax || typoAscent;
  754. var winDescent = -override.yMin || -typoDescent;
  755. return '\x00\x03' + '\x02\x24' + '\x01\xF4' + '\x00\x05' + '\x00\x00' + '\x02\x8A' + '\x02\xBB' + '\x00\x00' + '\x00\x8C' + '\x02\x8A' + '\x02\xBB' + '\x00\x00' + '\x01\xDF' + '\x00\x31' + '\x01\x02' + '\x00\x00' + '\x00\x00\x06' + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + '\x00\x00\x00\x00\x00\x00' + (0, _util.string32)(ulUnicodeRange1) + (0, _util.string32)(ulUnicodeRange2) + (0, _util.string32)(ulUnicodeRange3) + (0, _util.string32)(ulUnicodeRange4) + '\x2A\x32\x31\x2A' + string16(properties.italicAngle ? 1 : 0) + string16(firstCharIndex || properties.firstChar) + string16(lastCharIndex || properties.lastChar) + string16(typoAscent) + string16(typoDescent) + '\x00\x64' + string16(winAscent) + string16(winDescent) + '\x00\x00\x00\x00' + '\x00\x00\x00\x00' + string16(properties.xHeight) + string16(properties.capHeight) + string16(0) + string16(firstCharIndex || properties.firstChar) + '\x00\x03';
  756. }
  757. function createPostTable(properties) {
  758. var angle = Math.floor(properties.italicAngle * Math.pow(2, 16));
  759. return '\x00\x03\x00\x00' + (0, _util.string32)(angle) + '\x00\x00' + '\x00\x00' + (0, _util.string32)(properties.fixedPitch) + '\x00\x00\x00\x00' + '\x00\x00\x00\x00' + '\x00\x00\x00\x00' + '\x00\x00\x00\x00';
  760. }
  761. function createNameTable(name, proto) {
  762. if (!proto) {
  763. proto = [[], []];
  764. }
  765. var strings = [proto[0][0] || 'Original licence', proto[0][1] || name, proto[0][2] || 'Unknown', proto[0][3] || 'uniqueID', proto[0][4] || name, proto[0][5] || 'Version 0.11', proto[0][6] || '', proto[0][7] || 'Unknown', proto[0][8] || 'Unknown', proto[0][9] || 'Unknown'];
  766. var stringsUnicode = [];
  767. var i, ii, j, jj, str;
  768. for (i = 0, ii = strings.length; i < ii; i++) {
  769. str = proto[1][i] || strings[i];
  770. var strBufUnicode = [];
  771. for (j = 0, jj = str.length; j < jj; j++) {
  772. strBufUnicode.push(string16(str.charCodeAt(j)));
  773. }
  774. stringsUnicode.push(strBufUnicode.join(''));
  775. }
  776. var names = [strings, stringsUnicode];
  777. var platforms = ['\x00\x01', '\x00\x03'];
  778. var encodings = ['\x00\x00', '\x00\x01'];
  779. var languages = ['\x00\x00', '\x04\x09'];
  780. var namesRecordCount = strings.length * platforms.length;
  781. var nameTable = '\x00\x00' + string16(namesRecordCount) + string16(namesRecordCount * 12 + 6);
  782. var strOffset = 0;
  783. for (i = 0, ii = platforms.length; i < ii; i++) {
  784. var strs = names[i];
  785. for (j = 0, jj = strs.length; j < jj; j++) {
  786. str = strs[j];
  787. var nameRecord = platforms[i] + encodings[i] + languages[i] + string16(j) + string16(str.length) + string16(strOffset);
  788. nameTable += nameRecord;
  789. strOffset += str.length;
  790. }
  791. }
  792. nameTable += strings.join('') + stringsUnicode.join('');
  793. return nameTable;
  794. }
  795. Font.prototype = {
  796. name: null,
  797. font: null,
  798. mimetype: null,
  799. encoding: null,
  800. get renderer() {
  801. var renderer = _font_renderer.FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  802. return (0, _util.shadow)(this, 'renderer', renderer);
  803. },
  804. exportData: function Font_exportData() {
  805. var data = {};
  806. for (var i in this) {
  807. if (this.hasOwnProperty(i)) {
  808. data[i] = this[i];
  809. }
  810. }
  811. return data;
  812. },
  813. fallbackToSystemFont: function Font_fallbackToSystemFont() {
  814. var _this = this;
  815. this.missingFile = true;
  816. var charCode, unicode;
  817. var name = this.name;
  818. var type = this.type;
  819. var subtype = this.subtype;
  820. var fontName = name.replace(/[,_]/g, '-');
  821. var stdFontMap = (0, _standard_fonts.getStdFontMap)(),
  822. nonStdFontMap = (0, _standard_fonts.getNonStdFontMap)();
  823. var isStandardFont = !!stdFontMap[fontName] || !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  824. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  825. this.bold = fontName.search(/bold/gi) !== -1;
  826. this.italic = fontName.search(/oblique/gi) !== -1 || fontName.search(/italic/gi) !== -1;
  827. this.black = name.search(/Black/g) !== -1;
  828. this.remeasure = Object.keys(this.widths).length > 0;
  829. if (isStandardFont && type === 'CIDFontType2' && this.cidEncoding.indexOf('Identity-') === 0) {
  830. var GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)();
  831. var map = [];
  832. for (charCode in GlyphMapForStandardFonts) {
  833. map[+charCode] = GlyphMapForStandardFonts[charCode];
  834. }
  835. if (/Arial-?Black/i.test(name)) {
  836. var SupplementalGlyphMapForArialBlack = (0, _standard_fonts.getSupplementalGlyphMapForArialBlack)();
  837. for (charCode in SupplementalGlyphMapForArialBlack) {
  838. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  839. }
  840. } else if (/Calibri/i.test(name)) {
  841. var SupplementalGlyphMapForCalibri = (0, _standard_fonts.getSupplementalGlyphMapForCalibri)();
  842. for (charCode in SupplementalGlyphMapForCalibri) {
  843. map[+charCode] = SupplementalGlyphMapForCalibri[charCode];
  844. }
  845. }
  846. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  847. if (!isIdentityUnicode) {
  848. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  849. map[+charCode] = unicodeCharCode;
  850. });
  851. }
  852. this.toFontChar = map;
  853. this.toUnicode = new ToUnicodeMap(map);
  854. } else if (/Symbol/i.test(fontName)) {
  855. this.toFontChar = buildToFontChar(_encodings.SymbolSetEncoding, (0, _glyphlist.getGlyphsUnicode)(), this.differences);
  856. } else if (/Dingbats/i.test(fontName)) {
  857. if (/Wingdings/i.test(name)) {
  858. (0, _util.warn)('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  859. }
  860. this.toFontChar = buildToFontChar(_encodings.ZapfDingbatsEncoding, (0, _glyphlist.getDingbatsGlyphsUnicode)(), this.differences);
  861. } else if (isStandardFont) {
  862. this.toFontChar = buildToFontChar(this.defaultEncoding, (0, _glyphlist.getGlyphsUnicode)(), this.differences);
  863. } else {
  864. var glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
  865. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  866. if (!_this.composite) {
  867. var glyphName = _this.differences[charCode] || _this.defaultEncoding[charCode];
  868. unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
  869. if (unicode !== -1) {
  870. unicodeCharCode = unicode;
  871. }
  872. }
  873. _this.toFontChar[charCode] = unicodeCharCode;
  874. });
  875. }
  876. this.loadedName = fontName.split('-')[0];
  877. this.loading = false;
  878. this.fontType = getFontType(type, subtype);
  879. },
  880. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  881. function readTableEntry(file) {
  882. var tag = (0, _util.bytesToString)(file.getBytes(4));
  883. var checksum = file.getInt32() >>> 0;
  884. var offset = file.getInt32() >>> 0;
  885. var length = file.getInt32() >>> 0;
  886. var previousPosition = file.pos;
  887. file.pos = file.start ? file.start : 0;
  888. file.skip(offset);
  889. var data = file.getBytes(length);
  890. file.pos = previousPosition;
  891. if (tag === 'head') {
  892. data[8] = data[9] = data[10] = data[11] = 0;
  893. data[17] |= 0x20;
  894. }
  895. return {
  896. tag: tag,
  897. checksum: checksum,
  898. length: length,
  899. offset: offset,
  900. data: data
  901. };
  902. }
  903. function readOpenTypeHeader(ttf) {
  904. return {
  905. version: (0, _util.bytesToString)(ttf.getBytes(4)),
  906. numTables: ttf.getUint16(),
  907. searchRange: ttf.getUint16(),
  908. entrySelector: ttf.getUint16(),
  909. rangeShift: ttf.getUint16()
  910. };
  911. }
  912. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  913. if (!cmap) {
  914. (0, _util.warn)('No cmap table available.');
  915. return {
  916. platformId: -1,
  917. encodingId: -1,
  918. mappings: [],
  919. hasShortCmap: false
  920. };
  921. }
  922. var segment;
  923. var start = (font.start ? font.start : 0) + cmap.offset;
  924. font.pos = start;
  925. font.getUint16();
  926. var numTables = font.getUint16();
  927. var potentialTable;
  928. var canBreak = false;
  929. for (var i = 0; i < numTables; i++) {
  930. var platformId = font.getUint16();
  931. var encodingId = font.getUint16();
  932. var offset = font.getInt32() >>> 0;
  933. var useTable = false;
  934. if (potentialTable && potentialTable.platformId === platformId && potentialTable.encodingId === encodingId) {
  935. continue;
  936. }
  937. if (platformId === 0 && encodingId === 0) {
  938. useTable = true;
  939. } else if (platformId === 1 && encodingId === 0) {
  940. useTable = true;
  941. } else if (platformId === 3 && encodingId === 1 && (hasEncoding || !potentialTable)) {
  942. useTable = true;
  943. if (!isSymbolicFont) {
  944. canBreak = true;
  945. }
  946. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  947. useTable = true;
  948. canBreak = true;
  949. }
  950. if (useTable) {
  951. potentialTable = {
  952. platformId: platformId,
  953. encodingId: encodingId,
  954. offset: offset
  955. };
  956. }
  957. if (canBreak) {
  958. break;
  959. }
  960. }
  961. if (potentialTable) {
  962. font.pos = start + potentialTable.offset;
  963. }
  964. if (!potentialTable || font.peekByte() === -1) {
  965. (0, _util.warn)('Could not find a preferred cmap table.');
  966. return {
  967. platformId: -1,
  968. encodingId: -1,
  969. mappings: [],
  970. hasShortCmap: false
  971. };
  972. }
  973. var format = font.getUint16();
  974. font.getUint16();
  975. font.getUint16();
  976. var hasShortCmap = false;
  977. var mappings = [];
  978. var j, glyphId;
  979. if (format === 0) {
  980. for (j = 0; j < 256; j++) {
  981. var index = font.getByte();
  982. if (!index) {
  983. continue;
  984. }
  985. mappings.push({
  986. charCode: j,
  987. glyphId: index
  988. });
  989. }
  990. hasShortCmap = true;
  991. } else if (format === 4) {
  992. var segCount = font.getUint16() >> 1;
  993. font.getBytes(6);
  994. var segIndex,
  995. segments = [];
  996. for (segIndex = 0; segIndex < segCount; segIndex++) {
  997. segments.push({ end: font.getUint16() });
  998. }
  999. font.getUint16();
  1000. for (segIndex = 0; segIndex < segCount; segIndex++) {
  1001. segments[segIndex].start = font.getUint16();
  1002. }
  1003. for (segIndex = 0; segIndex < segCount; segIndex++) {
  1004. segments[segIndex].delta = font.getUint16();
  1005. }
  1006. var offsetsCount = 0;
  1007. for (segIndex = 0; segIndex < segCount; segIndex++) {
  1008. segment = segments[segIndex];
  1009. var rangeOffset = font.getUint16();
  1010. if (!rangeOffset) {
  1011. segment.offsetIndex = -1;
  1012. continue;
  1013. }
  1014. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  1015. segment.offsetIndex = offsetIndex;
  1016. offsetsCount = Math.max(offsetsCount, offsetIndex + segment.end - segment.start + 1);
  1017. }
  1018. var offsets = [];
  1019. for (j = 0; j < offsetsCount; j++) {
  1020. offsets.push(font.getUint16());
  1021. }
  1022. for (segIndex = 0; segIndex < segCount; segIndex++) {
  1023. segment = segments[segIndex];
  1024. start = segment.start;
  1025. var end = segment.end;
  1026. var delta = segment.delta;
  1027. offsetIndex = segment.offsetIndex;
  1028. for (j = start; j <= end; j++) {
  1029. if (j === 0xFFFF) {
  1030. continue;
  1031. }
  1032. glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
  1033. glyphId = glyphId + delta & 0xFFFF;
  1034. mappings.push({
  1035. charCode: j,
  1036. glyphId: glyphId
  1037. });
  1038. }
  1039. }
  1040. } else if (format === 6) {
  1041. var firstCode = font.getUint16();
  1042. var entryCount = font.getUint16();
  1043. for (j = 0; j < entryCount; j++) {
  1044. glyphId = font.getUint16();
  1045. var charCode = firstCode + j;
  1046. mappings.push({
  1047. charCode: charCode,
  1048. glyphId: glyphId
  1049. });
  1050. }
  1051. } else {
  1052. (0, _util.warn)('cmap table has unsupported format: ' + format);
  1053. return {
  1054. platformId: -1,
  1055. encodingId: -1,
  1056. mappings: [],
  1057. hasShortCmap: false
  1058. };
  1059. }
  1060. mappings.sort(function (a, b) {
  1061. return a.charCode - b.charCode;
  1062. });
  1063. for (i = 1; i < mappings.length; i++) {
  1064. if (mappings[i - 1].charCode === mappings[i].charCode) {
  1065. mappings.splice(i, 1);
  1066. i--;
  1067. }
  1068. }
  1069. return {
  1070. platformId: potentialTable.platformId,
  1071. encodingId: potentialTable.encodingId,
  1072. mappings: mappings,
  1073. hasShortCmap: hasShortCmap
  1074. };
  1075. }
  1076. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  1077. if (!header) {
  1078. if (metrics) {
  1079. metrics.data = null;
  1080. }
  1081. return;
  1082. }
  1083. font.pos = (font.start ? font.start : 0) + header.offset;
  1084. font.pos += header.length - 2;
  1085. var numOfMetrics = font.getUint16();
  1086. if (numOfMetrics > numGlyphs) {
  1087. (0, _util.info)('The numOfMetrics (' + numOfMetrics + ') should not be ' + 'greater than the numGlyphs (' + numGlyphs + ')');
  1088. numOfMetrics = numGlyphs;
  1089. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  1090. header.data[35] = numOfMetrics & 0x00ff;
  1091. }
  1092. var numOfSidebearings = numGlyphs - numOfMetrics;
  1093. var numMissing = numOfSidebearings - (metrics.length - numOfMetrics * 4 >> 1);
  1094. if (numMissing > 0) {
  1095. var entries = new Uint8Array(metrics.length + numMissing * 2);
  1096. entries.set(metrics.data);
  1097. metrics.data = entries;
  1098. }
  1099. }
  1100. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart, hintsValid) {
  1101. var glyphProfile = {
  1102. length: 0,
  1103. sizeOfInstructions: 0
  1104. };
  1105. if (sourceEnd - sourceStart <= 12) {
  1106. return glyphProfile;
  1107. }
  1108. var glyf = source.subarray(sourceStart, sourceEnd);
  1109. var contoursCount = signedInt16(glyf[0], glyf[1]);
  1110. if (contoursCount < 0) {
  1111. contoursCount = -1;
  1112. writeSignedInt16(glyf, 0, contoursCount);
  1113. dest.set(glyf, destStart);
  1114. glyphProfile.length = glyf.length;
  1115. return glyphProfile;
  1116. }
  1117. var i,
  1118. j = 10,
  1119. flagsCount = 0;
  1120. for (i = 0; i < contoursCount; i++) {
  1121. var endPoint = glyf[j] << 8 | glyf[j + 1];
  1122. flagsCount = endPoint + 1;
  1123. j += 2;
  1124. }
  1125. var instructionsStart = j;
  1126. var instructionsLength = glyf[j] << 8 | glyf[j + 1];
  1127. glyphProfile.sizeOfInstructions = instructionsLength;
  1128. j += 2 + instructionsLength;
  1129. var instructionsEnd = j;
  1130. var coordinatesLength = 0;
  1131. for (i = 0; i < flagsCount; i++) {
  1132. var flag = glyf[j++];
  1133. if (flag & 0xC0) {
  1134. glyf[j - 1] = flag & 0x3F;
  1135. }
  1136. var xyLength = (flag & 2 ? 1 : flag & 16 ? 0 : 2) + (flag & 4 ? 1 : flag & 32 ? 0 : 2);
  1137. coordinatesLength += xyLength;
  1138. if (flag & 8) {
  1139. var repeat = glyf[j++];
  1140. i += repeat;
  1141. coordinatesLength += repeat * xyLength;
  1142. }
  1143. }
  1144. if (coordinatesLength === 0) {
  1145. return glyphProfile;
  1146. }
  1147. var glyphDataLength = j + coordinatesLength;
  1148. if (glyphDataLength > glyf.length) {
  1149. return glyphProfile;
  1150. }
  1151. if (!hintsValid && instructionsLength > 0) {
  1152. dest.set(glyf.subarray(0, instructionsStart), destStart);
  1153. dest.set([0, 0], destStart + instructionsStart);
  1154. dest.set(glyf.subarray(instructionsEnd, glyphDataLength), destStart + instructionsStart + 2);
  1155. glyphDataLength -= instructionsLength;
  1156. if (glyf.length - glyphDataLength > 3) {
  1157. glyphDataLength = glyphDataLength + 3 & ~3;
  1158. }
  1159. glyphProfile.length = glyphDataLength;
  1160. return glyphProfile;
  1161. }
  1162. if (glyf.length - glyphDataLength > 3) {
  1163. glyphDataLength = glyphDataLength + 3 & ~3;
  1164. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  1165. glyphProfile.length = glyphDataLength;
  1166. return glyphProfile;
  1167. }
  1168. dest.set(glyf, destStart);
  1169. glyphProfile.length = glyf.length;
  1170. return glyphProfile;
  1171. }
  1172. function sanitizeHead(head, numGlyphs, locaLength) {
  1173. var data = head.data;
  1174. var version = int32(data[0], data[1], data[2], data[3]);
  1175. if (version >> 16 !== 1) {
  1176. (0, _util.info)('Attempting to fix invalid version in head table: ' + version);
  1177. data[0] = 0;
  1178. data[1] = 1;
  1179. data[2] = 0;
  1180. data[3] = 0;
  1181. }
  1182. var indexToLocFormat = int16(data[50], data[51]);
  1183. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  1184. (0, _util.info)('Attempting to fix invalid indexToLocFormat in head table: ' + indexToLocFormat);
  1185. var numGlyphsPlusOne = numGlyphs + 1;
  1186. if (locaLength === numGlyphsPlusOne << 1) {
  1187. data[50] = 0;
  1188. data[51] = 0;
  1189. } else if (locaLength === numGlyphsPlusOne << 2) {
  1190. data[50] = 0;
  1191. data[51] = 1;
  1192. } else {
  1193. throw new _util.FormatError('Could not fix indexToLocFormat: ' + indexToLocFormat);
  1194. }
  1195. }
  1196. }
  1197. function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions) {
  1198. var itemSize, itemDecode, itemEncode;
  1199. if (isGlyphLocationsLong) {
  1200. itemSize = 4;
  1201. itemDecode = function fontItemDecodeLong(data, offset) {
  1202. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  1203. };
  1204. itemEncode = function fontItemEncodeLong(data, offset, value) {
  1205. data[offset] = value >>> 24 & 0xFF;
  1206. data[offset + 1] = value >> 16 & 0xFF;
  1207. data[offset + 2] = value >> 8 & 0xFF;
  1208. data[offset + 3] = value & 0xFF;
  1209. };
  1210. } else {
  1211. itemSize = 2;
  1212. itemDecode = function fontItemDecode(data, offset) {
  1213. return data[offset] << 9 | data[offset + 1] << 1;
  1214. };
  1215. itemEncode = function fontItemEncode(data, offset, value) {
  1216. data[offset] = value >> 9 & 0xFF;
  1217. data[offset + 1] = value >> 1 & 0xFF;
  1218. };
  1219. }
  1220. var locaData = loca.data;
  1221. var locaDataSize = itemSize * (1 + numGlyphs);
  1222. if (locaData.length !== locaDataSize) {
  1223. locaData = new Uint8Array(locaDataSize);
  1224. locaData.set(loca.data.subarray(0, locaDataSize));
  1225. loca.data = locaData;
  1226. }
  1227. var oldGlyfData = glyf.data;
  1228. var oldGlyfDataLength = oldGlyfData.length;
  1229. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  1230. var startOffset = itemDecode(locaData, 0);
  1231. var writeOffset = 0;
  1232. var missingGlyphs = Object.create(null);
  1233. itemEncode(locaData, 0, writeOffset);
  1234. var i, j;
  1235. var locaCount = dupFirstEntry ? numGlyphs - 1 : numGlyphs;
  1236. for (i = 0, j = itemSize; i < locaCount; i++, j += itemSize) {
  1237. var endOffset = itemDecode(locaData, j);
  1238. if (endOffset === 0) {
  1239. endOffset = startOffset;
  1240. }
  1241. if (endOffset > oldGlyfDataLength && (oldGlyfDataLength + 3 & ~3) === endOffset) {
  1242. endOffset = oldGlyfDataLength;
  1243. }
  1244. if (endOffset > oldGlyfDataLength) {
  1245. startOffset = endOffset;
  1246. }
  1247. var glyphProfile = sanitizeGlyph(oldGlyfData, startOffset, endOffset, newGlyfData, writeOffset, hintsValid);
  1248. var newLength = glyphProfile.length;
  1249. if (newLength === 0) {
  1250. missingGlyphs[i] = true;
  1251. }
  1252. if (glyphProfile.sizeOfInstructions > maxSizeOfInstructions) {
  1253. maxSizeOfInstructions = glyphProfile.sizeOfInstructions;
  1254. }
  1255. writeOffset += newLength;
  1256. itemEncode(locaData, j, writeOffset);
  1257. startOffset = endOffset;
  1258. }
  1259. if (writeOffset === 0) {
  1260. var simpleGlyph = new Uint8Array([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  1261. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  1262. itemEncode(locaData, j, simpleGlyph.length);
  1263. }
  1264. glyf.data = simpleGlyph;
  1265. } else if (dupFirstEntry) {
  1266. var firstEntryLength = itemDecode(locaData, itemSize);
  1267. if (newGlyfData.length > firstEntryLength + writeOffset) {
  1268. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  1269. } else {
  1270. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  1271. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  1272. }
  1273. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  1274. itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength);
  1275. } else {
  1276. glyf.data = newGlyfData.subarray(0, writeOffset);
  1277. }
  1278. return {
  1279. missingGlyphs: missingGlyphs,
  1280. maxSizeOfInstructions: maxSizeOfInstructions
  1281. };
  1282. }
  1283. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  1284. var start = (font.start ? font.start : 0) + post.offset;
  1285. font.pos = start;
  1286. var length = post.length,
  1287. end = start + length;
  1288. var version = font.getInt32();
  1289. font.getBytes(28);
  1290. var glyphNames;
  1291. var valid = true;
  1292. var i;
  1293. switch (version) {
  1294. case 0x00010000:
  1295. glyphNames = MacStandardGlyphOrdering;
  1296. break;
  1297. case 0x00020000:
  1298. var numGlyphs = font.getUint16();
  1299. if (numGlyphs !== maxpNumGlyphs) {
  1300. valid = false;
  1301. break;
  1302. }
  1303. var glyphNameIndexes = [];
  1304. for (i = 0; i < numGlyphs; ++i) {
  1305. var index = font.getUint16();
  1306. if (index >= 32768) {
  1307. valid = false;
  1308. break;
  1309. }
  1310. glyphNameIndexes.push(index);
  1311. }
  1312. if (!valid) {
  1313. break;
  1314. }
  1315. var customNames = [];
  1316. var strBuf = [];
  1317. while (font.pos < end) {
  1318. var stringLength = font.getByte();
  1319. strBuf.length = stringLength;
  1320. for (i = 0; i < stringLength; ++i) {
  1321. strBuf[i] = String.fromCharCode(font.getByte());
  1322. }
  1323. customNames.push(strBuf.join(''));
  1324. }
  1325. glyphNames = [];
  1326. for (i = 0; i < numGlyphs; ++i) {
  1327. var j = glyphNameIndexes[i];
  1328. if (j < 258) {
  1329. glyphNames.push(MacStandardGlyphOrdering[j]);
  1330. continue;
  1331. }
  1332. glyphNames.push(customNames[j - 258]);
  1333. }
  1334. break;
  1335. case 0x00030000:
  1336. break;
  1337. default:
  1338. (0, _util.warn)('Unknown/unsupported post table version ' + version);
  1339. valid = false;
  1340. if (properties.defaultEncoding) {
  1341. glyphNames = properties.defaultEncoding;
  1342. }
  1343. break;
  1344. }
  1345. properties.glyphNames = glyphNames;
  1346. return valid;
  1347. }
  1348. function readNameTable(nameTable) {
  1349. var start = (font.start ? font.start : 0) + nameTable.offset;
  1350. font.pos = start;
  1351. var names = [[], []];
  1352. var length = nameTable.length,
  1353. end = start + length;
  1354. var format = font.getUint16();
  1355. var FORMAT_0_HEADER_LENGTH = 6;
  1356. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  1357. return names;
  1358. }
  1359. var numRecords = font.getUint16();
  1360. var stringsStart = font.getUint16();
  1361. var records = [];
  1362. var NAME_RECORD_LENGTH = 12;
  1363. var i, ii;
  1364. for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
  1365. var r = {
  1366. platform: font.getUint16(),
  1367. encoding: font.getUint16(),
  1368. language: font.getUint16(),
  1369. name: font.getUint16(),
  1370. length: font.getUint16(),
  1371. offset: font.getUint16()
  1372. };
  1373. if (r.platform === 1 && r.encoding === 0 && r.language === 0 || r.platform === 3 && r.encoding === 1 && r.language === 0x409) {
  1374. records.push(r);
  1375. }
  1376. }
  1377. for (i = 0, ii = records.length; i < ii; i++) {
  1378. var record = records[i];
  1379. if (record.length <= 0) {
  1380. continue;
  1381. }
  1382. var pos = start + stringsStart + record.offset;
  1383. if (pos + record.length > end) {
  1384. continue;
  1385. }
  1386. font.pos = pos;
  1387. var nameIndex = record.name;
  1388. if (record.encoding) {
  1389. var str = '';
  1390. for (var j = 0, jj = record.length; j < jj; j += 2) {
  1391. str += String.fromCharCode(font.getUint16());
  1392. }
  1393. names[1][nameIndex] = str;
  1394. } else {
  1395. names[0][nameIndex] = (0, _util.bytesToString)(font.getBytes(record.length));
  1396. }
  1397. }
  1398. return names;
  1399. }
  1400. var TTOpsStackDeltas = [0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1, 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1, 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2, 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1, -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  1401. function sanitizeTTProgram(table, ttContext) {
  1402. var data = table.data;
  1403. var i = 0,
  1404. j,
  1405. n,
  1406. b,
  1407. funcId,
  1408. pc,
  1409. lastEndf = 0,
  1410. lastDeff = 0;
  1411. var stack = [];
  1412. var callstack = [];
  1413. var functionsCalled = [];
  1414. var tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions;
  1415. var inFDEF = false,
  1416. ifLevel = 0,
  1417. inELSE = 0;
  1418. for (var ii = data.length; i < ii;) {
  1419. var op = data[i++];
  1420. if (op === 0x40) {
  1421. n = data[i++];
  1422. if (inFDEF || inELSE) {
  1423. i += n;
  1424. } else {
  1425. for (j = 0; j < n; j++) {
  1426. stack.push(data[i++]);
  1427. }
  1428. }
  1429. } else if (op === 0x41) {
  1430. n = data[i++];
  1431. if (inFDEF || inELSE) {
  1432. i += n * 2;
  1433. } else {
  1434. for (j = 0; j < n; j++) {
  1435. b = data[i++];
  1436. stack.push(b << 8 | data[i++]);
  1437. }
  1438. }
  1439. } else if ((op & 0xF8) === 0xB0) {
  1440. n = op - 0xB0 + 1;
  1441. if (inFDEF || inELSE) {
  1442. i += n;
  1443. } else {
  1444. for (j = 0; j < n; j++) {
  1445. stack.push(data[i++]);
  1446. }
  1447. }
  1448. } else if ((op & 0xF8) === 0xB8) {
  1449. n = op - 0xB8 + 1;
  1450. if (inFDEF || inELSE) {
  1451. i += n * 2;
  1452. } else {
  1453. for (j = 0; j < n; j++) {
  1454. b = data[i++];
  1455. stack.push(b << 8 | data[i++]);
  1456. }
  1457. }
  1458. } else if (op === 0x2B && !tooComplexToFollowFunctions) {
  1459. if (!inFDEF && !inELSE) {
  1460. funcId = stack[stack.length - 1];
  1461. ttContext.functionsUsed[funcId] = true;
  1462. if (funcId in ttContext.functionsStackDeltas) {
  1463. stack.length += ttContext.functionsStackDeltas[funcId];
  1464. } else if (funcId in ttContext.functionsDefined && functionsCalled.indexOf(funcId) < 0) {
  1465. callstack.push({
  1466. data: data,
  1467. i: i,
  1468. stackTop: stack.length - 1
  1469. });
  1470. functionsCalled.push(funcId);
  1471. pc = ttContext.functionsDefined[funcId];
  1472. if (!pc) {
  1473. (0, _util.warn)('TT: CALL non-existent function');
  1474. ttContext.hintsValid = false;
  1475. return;
  1476. }
  1477. data = pc.data;
  1478. i = pc.i;
  1479. }
  1480. }
  1481. } else if (op === 0x2C && !tooComplexToFollowFunctions) {
  1482. if (inFDEF || inELSE) {
  1483. (0, _util.warn)('TT: nested FDEFs not allowed');
  1484. tooComplexToFollowFunctions = true;
  1485. }
  1486. inFDEF = true;
  1487. lastDeff = i;
  1488. funcId = stack.pop();
  1489. ttContext.functionsDefined[funcId] = {
  1490. data: data,
  1491. i: i
  1492. };
  1493. } else if (op === 0x2D) {
  1494. if (inFDEF) {
  1495. inFDEF = false;
  1496. lastEndf = i;
  1497. } else {
  1498. pc = callstack.pop();
  1499. if (!pc) {
  1500. (0, _util.warn)('TT: ENDF bad stack');
  1501. ttContext.hintsValid = false;
  1502. return;
  1503. }
  1504. funcId = functionsCalled.pop();
  1505. data = pc.data;
  1506. i = pc.i;
  1507. ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop;
  1508. }
  1509. } else if (op === 0x89) {
  1510. if (inFDEF || inELSE) {
  1511. (0, _util.warn)('TT: nested IDEFs not allowed');
  1512. tooComplexToFollowFunctions = true;
  1513. }
  1514. inFDEF = true;
  1515. lastDeff = i;
  1516. } else if (op === 0x58) {
  1517. ++ifLevel;
  1518. } else if (op === 0x1B) {
  1519. inELSE = ifLevel;
  1520. } else if (op === 0x59) {
  1521. if (inELSE === ifLevel) {
  1522. inELSE = 0;
  1523. }
  1524. --ifLevel;
  1525. } else if (op === 0x1C) {
  1526. if (!inFDEF && !inELSE) {
  1527. var offset = stack[stack.length - 1];
  1528. if (offset > 0) {
  1529. i += offset - 1;
  1530. }
  1531. }
  1532. }
  1533. if (!inFDEF && !inELSE) {
  1534. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] : op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  1535. if (op >= 0x71 && op <= 0x75) {
  1536. n = stack.pop();
  1537. if (!isNaN(n)) {
  1538. stackDelta = -n * 2;
  1539. }
  1540. }
  1541. while (stackDelta < 0 && stack.length > 0) {
  1542. stack.pop();
  1543. stackDelta++;
  1544. }
  1545. while (stackDelta > 0) {
  1546. stack.push(NaN);
  1547. stackDelta--;
  1548. }
  1549. }
  1550. }
  1551. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  1552. var content = [data];
  1553. if (i > data.length) {
  1554. content.push(new Uint8Array(i - data.length));
  1555. }
  1556. if (lastDeff > lastEndf) {
  1557. (0, _util.warn)('TT: complementing a missing function tail');
  1558. content.push(new Uint8Array([0x22, 0x2D]));
  1559. }
  1560. foldTTTable(table, content);
  1561. }
  1562. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  1563. if (ttContext.tooComplexToFollowFunctions) {
  1564. return;
  1565. }
  1566. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  1567. (0, _util.warn)('TT: more functions defined than expected');
  1568. ttContext.hintsValid = false;
  1569. return;
  1570. }
  1571. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  1572. if (j > maxFunctionDefs) {
  1573. (0, _util.warn)('TT: invalid function id: ' + j);
  1574. ttContext.hintsValid = false;
  1575. return;
  1576. }
  1577. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  1578. (0, _util.warn)('TT: undefined function: ' + j);
  1579. ttContext.hintsValid = false;
  1580. return;
  1581. }
  1582. }
  1583. }
  1584. function foldTTTable(table, content) {
  1585. if (content.length > 1) {
  1586. var newLength = 0;
  1587. var j, jj;
  1588. for (j = 0, jj = content.length; j < jj; j++) {
  1589. newLength += content[j].length;
  1590. }
  1591. newLength = newLength + 3 & ~3;
  1592. var result = new Uint8Array(newLength);
  1593. var pos = 0;
  1594. for (j = 0, jj = content.length; j < jj; j++) {
  1595. result.set(content[j], pos);
  1596. pos += content[j].length;
  1597. }
  1598. table.data = result;
  1599. table.length = newLength;
  1600. }
  1601. }
  1602. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  1603. var ttContext = {
  1604. functionsDefined: [],
  1605. functionsUsed: [],
  1606. functionsStackDeltas: [],
  1607. tooComplexToFollowFunctions: false,
  1608. hintsValid: true
  1609. };
  1610. if (fpgm) {
  1611. sanitizeTTProgram(fpgm, ttContext);
  1612. }
  1613. if (prep) {
  1614. sanitizeTTProgram(prep, ttContext);
  1615. }
  1616. if (fpgm) {
  1617. checkInvalidFunctions(ttContext, maxFunctionDefs);
  1618. }
  1619. if (cvt && cvt.length & 1) {
  1620. var cvtData = new Uint8Array(cvt.length + 1);
  1621. cvtData.set(cvt.data);
  1622. cvt.data = cvtData;
  1623. }
  1624. return ttContext.hintsValid;
  1625. }
  1626. font = new _stream.Stream(new Uint8Array(font.getBytes()));
  1627. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp', 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  1628. var header = readOpenTypeHeader(font);
  1629. var numTables = header.numTables;
  1630. var cff, cffFile;
  1631. var tables = Object.create(null);
  1632. tables['OS/2'] = null;
  1633. tables['cmap'] = null;
  1634. tables['head'] = null;
  1635. tables['hhea'] = null;
  1636. tables['hmtx'] = null;
  1637. tables['maxp'] = null;
  1638. tables['name'] = null;
  1639. tables['post'] = null;
  1640. var table;
  1641. for (var i = 0; i < numTables; i++) {
  1642. table = readTableEntry(font);
  1643. if (VALID_TABLES.indexOf(table.tag) < 0) {
  1644. continue;
  1645. }
  1646. if (table.length === 0) {
  1647. continue;
  1648. }
  1649. tables[table.tag] = table;
  1650. }
  1651. var isTrueType = !tables['CFF '];
  1652. if (!isTrueType) {
  1653. if (header.version === 'OTTO' && !(properties.composite && properties.cidToGidMap) || !tables['head'] || !tables['hhea'] || !tables['maxp'] || !tables['post']) {
  1654. cffFile = new _stream.Stream(tables['CFF '].data);
  1655. cff = new CFFFont(cffFile, properties);
  1656. adjustWidths(properties);
  1657. return this.convert(name, cff, properties);
  1658. }
  1659. delete tables['glyf'];
  1660. delete tables['loca'];
  1661. delete tables['fpgm'];
  1662. delete tables['prep'];
  1663. delete tables['cvt '];
  1664. this.isOpenType = true;
  1665. } else {
  1666. if (!tables['loca']) {
  1667. throw new _util.FormatError('Required "loca" table is not found');
  1668. }
  1669. if (!tables['glyf']) {
  1670. (0, _util.warn)('Required "glyf" table is not found -- trying to recover.');
  1671. tables['glyf'] = {
  1672. tag: 'glyf',
  1673. data: new Uint8Array(0)
  1674. };
  1675. }
  1676. this.isOpenType = false;
  1677. }
  1678. if (!tables['maxp']) {
  1679. throw new _util.FormatError('Required "maxp" table is not found');
  1680. }
  1681. font.pos = (font.start || 0) + tables['maxp'].offset;
  1682. var version = font.getInt32();
  1683. var numGlyphs = font.getUint16();
  1684. var maxFunctionDefs = 0;
  1685. var maxSizeOfInstructions = 0;
  1686. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  1687. font.pos += 8;
  1688. var maxZones = font.getUint16();
  1689. if (maxZones > 2) {
  1690. tables['maxp'].data[14] = 0;
  1691. tables['maxp'].data[15] = 2;
  1692. }
  1693. font.pos += 4;
  1694. maxFunctionDefs = font.getUint16();
  1695. font.pos += 6;
  1696. maxSizeOfInstructions = font.getUint16();
  1697. }
  1698. var dupFirstEntry = false;
  1699. if (properties.type === 'CIDFontType2' && properties.toUnicode && properties.toUnicode.get(0) > '\0') {
  1700. dupFirstEntry = true;
  1701. numGlyphs++;
  1702. tables['maxp'].data[4] = numGlyphs >> 8;
  1703. tables['maxp'].data[5] = numGlyphs & 255;
  1704. }
  1705. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'], tables['cvt '], maxFunctionDefs);
  1706. if (!hintsValid) {
  1707. delete tables['fpgm'];
  1708. delete tables['prep'];
  1709. delete tables['cvt '];
  1710. }
  1711. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  1712. if (!tables['head']) {
  1713. throw new _util.FormatError('Required "head" table is not found');
  1714. }
  1715. sanitizeHead(tables['head'], numGlyphs, isTrueType ? tables['loca'].length : 0);
  1716. var missingGlyphs = Object.create(null);
  1717. if (isTrueType) {
  1718. var isGlyphLocationsLong = int16(tables['head'].data[50], tables['head'].data[51]);
  1719. var glyphsInfo = sanitizeGlyphLocations(tables['loca'], tables['glyf'], numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions);
  1720. missingGlyphs = glyphsInfo.missingGlyphs;
  1721. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  1722. tables['maxp'].data[26] = glyphsInfo.maxSizeOfInstructions >> 8;
  1723. tables['maxp'].data[27] = glyphsInfo.maxSizeOfInstructions & 255;
  1724. }
  1725. }
  1726. if (!tables['hhea']) {
  1727. throw new _util.FormatError('Required "hhea" table is not found');
  1728. }
  1729. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  1730. tables['hhea'].data[10] = 0xFF;
  1731. tables['hhea'].data[11] = 0xFF;
  1732. }
  1733. var metricsOverride = {
  1734. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  1735. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  1736. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  1737. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  1738. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  1739. };
  1740. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  1741. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  1742. if (tables['post']) {
  1743. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  1744. if (!valid) {
  1745. tables['post'] = null;
  1746. }
  1747. }
  1748. var charCodeToGlyphId = [],
  1749. charCode;
  1750. function hasGlyph(glyphId) {
  1751. return !missingGlyphs[glyphId];
  1752. }
  1753. if (properties.composite) {
  1754. var cidToGidMap = properties.cidToGidMap || [];
  1755. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  1756. properties.cMap.forEach(function (charCode, cid) {
  1757. if (cid > 0xffff) {
  1758. throw new _util.FormatError('Max size of CID is 65,535');
  1759. }
  1760. var glyphId = -1;
  1761. if (isCidToGidMapEmpty) {
  1762. glyphId = cid;
  1763. } else if (cidToGidMap[cid] !== undefined) {
  1764. glyphId = cidToGidMap[cid];
  1765. }
  1766. if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId)) {
  1767. charCodeToGlyphId[charCode] = glyphId;
  1768. }
  1769. });
  1770. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  1771. charCodeToGlyphId[0] = numGlyphs - 1;
  1772. }
  1773. } else {
  1774. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont, properties.hasEncoding);
  1775. var cmapPlatformId = cmapTable.platformId;
  1776. var cmapEncodingId = cmapTable.encodingId;
  1777. var cmapMappings = cmapTable.mappings;
  1778. var cmapMappingsLength = cmapMappings.length;
  1779. if (properties.hasEncoding && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === -1 && cmapEncodingId === -1 && !!(0, _encodings.getEncoding)(properties.baseEncodingName)) {
  1780. var baseEncoding = [];
  1781. if (properties.baseEncodingName === 'MacRomanEncoding' || properties.baseEncodingName === 'WinAnsiEncoding') {
  1782. baseEncoding = (0, _encodings.getEncoding)(properties.baseEncodingName);
  1783. }
  1784. var glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
  1785. for (charCode = 0; charCode < 256; charCode++) {
  1786. var glyphName, standardGlyphName;
  1787. if (this.differences && charCode in this.differences) {
  1788. glyphName = this.differences[charCode];
  1789. } else if (charCode in baseEncoding && baseEncoding[charCode] !== '') {
  1790. glyphName = baseEncoding[charCode];
  1791. } else {
  1792. glyphName = _encodings.StandardEncoding[charCode];
  1793. }
  1794. if (!glyphName) {
  1795. continue;
  1796. }
  1797. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  1798. var unicodeOrCharCode;
  1799. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  1800. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  1801. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  1802. unicodeOrCharCode = _encodings.MacRomanEncoding.indexOf(standardGlyphName);
  1803. }
  1804. var found = false;
  1805. for (i = 0; i < cmapMappingsLength; ++i) {
  1806. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  1807. continue;
  1808. }
  1809. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  1810. found = true;
  1811. break;
  1812. }
  1813. if (!found && properties.glyphNames) {
  1814. var glyphId = properties.glyphNames.indexOf(glyphName);
  1815. if (glyphId === -1 && standardGlyphName !== glyphName) {
  1816. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  1817. }
  1818. if (glyphId > 0 && hasGlyph(glyphId)) {
  1819. charCodeToGlyphId[charCode] = glyphId;
  1820. }
  1821. }
  1822. }
  1823. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  1824. for (i = 0; i < cmapMappingsLength; ++i) {
  1825. charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
  1826. }
  1827. } else {
  1828. for (i = 0; i < cmapMappingsLength; ++i) {
  1829. charCode = cmapMappings[i].charCode;
  1830. if (cmapPlatformId === 3 && charCode >= 0xF000 && charCode <= 0xF0FF) {
  1831. charCode &= 0xFF;
  1832. }
  1833. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  1834. }
  1835. }
  1836. }
  1837. if (charCodeToGlyphId.length === 0) {
  1838. charCodeToGlyphId[0] = 0;
  1839. }
  1840. var newMapping = adjustMapping(charCodeToGlyphId, properties, missingGlyphs);
  1841. this.toFontChar = newMapping.toFontChar;
  1842. tables['cmap'] = {
  1843. tag: 'cmap',
  1844. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  1845. };
  1846. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  1847. tables['OS/2'] = {
  1848. tag: 'OS/2',
  1849. data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
  1850. };
  1851. }
  1852. if (!tables['post']) {
  1853. tables['post'] = {
  1854. tag: 'post',
  1855. data: createPostTable(properties)
  1856. };
  1857. }
  1858. if (!isTrueType) {
  1859. try {
  1860. cffFile = new _stream.Stream(tables['CFF '].data);
  1861. var parser = new _cff_parser.CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
  1862. cff = parser.parse();
  1863. var compiler = new _cff_parser.CFFCompiler(cff);
  1864. tables['CFF '].data = compiler.compile();
  1865. } catch (e) {
  1866. (0, _util.warn)('Failed to compile font ' + properties.loadedName);
  1867. }
  1868. }
  1869. if (!tables['name']) {
  1870. tables['name'] = {
  1871. tag: 'name',
  1872. data: createNameTable(this.name)
  1873. };
  1874. } else {
  1875. var namePrototype = readNameTable(tables['name']);
  1876. tables['name'].data = createNameTable(name, namePrototype);
  1877. }
  1878. var builder = new OpenTypeFileBuilder(header.version);
  1879. for (var tableTag in tables) {
  1880. builder.addTable(tableTag, tables[tableTag].data);
  1881. }
  1882. return builder.toArray();
  1883. },
  1884. convert: function Font_convert(fontName, font, properties) {
  1885. properties.fixedPitch = false;
  1886. if (properties.builtInEncoding) {
  1887. adjustToUnicode(properties, properties.builtInEncoding);
  1888. }
  1889. var mapping = font.getGlyphMapping(properties);
  1890. var newMapping = adjustMapping(mapping, properties, Object.create(null));
  1891. this.toFontChar = newMapping.toFontChar;
  1892. var numGlyphs = font.numGlyphs;
  1893. function getCharCodes(charCodeToGlyphId, glyphId) {
  1894. var charCodes = null;
  1895. for (var charCode in charCodeToGlyphId) {
  1896. if (glyphId === charCodeToGlyphId[charCode]) {
  1897. if (!charCodes) {
  1898. charCodes = [];
  1899. }
  1900. charCodes.push(charCode | 0);
  1901. }
  1902. }
  1903. return charCodes;
  1904. }
  1905. function createCharCode(charCodeToGlyphId, glyphId) {
  1906. for (var charCode in charCodeToGlyphId) {
  1907. if (glyphId === charCodeToGlyphId[charCode]) {
  1908. return charCode | 0;
  1909. }
  1910. }
  1911. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = glyphId;
  1912. return newMapping.nextAvailableFontCharCode++;
  1913. }
  1914. var seacs = font.seacs;
  1915. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  1916. var matrix = properties.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  1917. var charset = font.getCharset();
  1918. var seacMap = Object.create(null);
  1919. for (var glyphId in seacs) {
  1920. glyphId |= 0;
  1921. var seac = seacs[glyphId];
  1922. var baseGlyphName = _encodings.StandardEncoding[seac[2]];
  1923. var accentGlyphName = _encodings.StandardEncoding[seac[3]];
  1924. var baseGlyphId = charset.indexOf(baseGlyphName);
  1925. var accentGlyphId = charset.indexOf(accentGlyphName);
  1926. if (baseGlyphId < 0 || accentGlyphId < 0) {
  1927. continue;
  1928. }
  1929. var accentOffset = {
  1930. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  1931. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  1932. };
  1933. var charCodes = getCharCodes(mapping, glyphId);
  1934. if (!charCodes) {
  1935. continue;
  1936. }
  1937. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  1938. var charCode = charCodes[i];
  1939. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  1940. var baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
  1941. var accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
  1942. seacMap[charCode] = {
  1943. baseFontCharCode: baseFontCharCode,
  1944. accentFontCharCode: accentFontCharCode,
  1945. accentOffset: accentOffset
  1946. };
  1947. }
  1948. }
  1949. properties.seacMap = seacMap;
  1950. }
  1951. var unitsPerEm = 1 / (properties.fontMatrix || _util.FONT_IDENTITY_MATRIX)[0];
  1952. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  1953. builder.addTable('CFF ', font.data);
  1954. builder.addTable('OS/2', createOS2Table(properties, newMapping.charCodeToGlyphId));
  1955. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId, numGlyphs));
  1956. builder.addTable('head', '\x00\x01\x00\x00' + '\x00\x00\x10\x00' + '\x00\x00\x00\x00' + '\x5F\x0F\x3C\xF5' + '\x00\x00' + safeString16(unitsPerEm) + '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + '\x00\x00' + safeString16(properties.descent) + '\x0F\xFF' + safeString16(properties.ascent) + string16(properties.italicAngle ? 2 : 0) + '\x00\x11' + '\x00\x00' + '\x00\x00' + '\x00\x00');
  1957. builder.addTable('hhea', '\x00\x01\x00\x00' + safeString16(properties.ascent) + safeString16(properties.descent) + '\x00\x00' + '\xFF\xFF' + '\x00\x00' + '\x00\x00' + '\x00\x00' + safeString16(properties.capHeight) + safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + '\x00\x00' + '\x00\x00' + '\x00\x00' + '\x00\x00' + '\x00\x00' + '\x00\x00' + string16(numGlyphs));
  1958. builder.addTable('hmtx', function fontFieldsHmtx() {
  1959. var charstrings = font.charstrings;
  1960. var cffWidths = font.cff ? font.cff.widths : null;
  1961. var hmtx = '\x00\x00\x00\x00';
  1962. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  1963. var width = 0;
  1964. if (charstrings) {
  1965. var charstring = charstrings[i - 1];
  1966. width = 'width' in charstring ? charstring.width : 0;
  1967. } else if (cffWidths) {
  1968. width = Math.ceil(cffWidths[i] || 0);
  1969. }
  1970. hmtx += string16(width) + string16(0);
  1971. }
  1972. return hmtx;
  1973. }());
  1974. builder.addTable('maxp', '\x00\x00\x50\x00' + string16(numGlyphs));
  1975. builder.addTable('name', createNameTable(fontName));
  1976. builder.addTable('post', createPostTable(properties));
  1977. return builder.toArray();
  1978. },
  1979. get spaceWidth() {
  1980. if ('_shadowWidth' in this) {
  1981. return this._shadowWidth;
  1982. }
  1983. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i', 'I'];
  1984. var width;
  1985. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  1986. var glyphName = possibleSpaceReplacements[i];
  1987. if (glyphName in this.widths) {
  1988. width = this.widths[glyphName];
  1989. break;
  1990. }
  1991. var glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
  1992. var glyphUnicode = glyphsUnicodeMap[glyphName];
  1993. var charcode = 0;
  1994. if (this.composite) {
  1995. if (this.cMap.contains(glyphUnicode)) {
  1996. charcode = this.cMap.lookup(glyphUnicode);
  1997. }
  1998. }
  1999. if (!charcode && this.toUnicode) {
  2000. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  2001. }
  2002. if (charcode <= 0) {
  2003. charcode = glyphUnicode;
  2004. }
  2005. width = this.widths[charcode];
  2006. if (width) {
  2007. break;
  2008. }
  2009. }
  2010. width = width || this.defaultWidth;
  2011. this._shadowWidth = width;
  2012. return width;
  2013. },
  2014. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  2015. var fontCharCode, width, operatorListId;
  2016. var widthCode = charcode;
  2017. if (this.cMap && this.cMap.contains(charcode)) {
  2018. widthCode = this.cMap.lookup(charcode);
  2019. }
  2020. width = this.widths[widthCode];
  2021. width = (0, _util.isNum)(width) ? width : this.defaultWidth;
  2022. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  2023. var unicode = this.toUnicode.get(charcode) || this.fallbackToUnicode.get(charcode) || charcode;
  2024. if (typeof unicode === 'number') {
  2025. unicode = String.fromCharCode(unicode);
  2026. }
  2027. var isInFont = charcode in this.toFontChar;
  2028. fontCharCode = this.toFontChar[charcode] || charcode;
  2029. if (this.missingFile) {
  2030. fontCharCode = (0, _unicode.mapSpecialUnicodeValues)(fontCharCode);
  2031. }
  2032. if (this.isType3Font) {
  2033. operatorListId = fontCharCode;
  2034. }
  2035. var accent = null;
  2036. if (this.seacMap && this.seacMap[charcode]) {
  2037. isInFont = true;
  2038. var seac = this.seacMap[charcode];
  2039. fontCharCode = seac.baseFontCharCode;
  2040. accent = {
  2041. fontChar: String.fromCharCode(seac.accentFontCharCode),
  2042. offset: seac.accentOffset
  2043. };
  2044. }
  2045. var fontChar = String.fromCharCode(fontCharCode);
  2046. var glyph = this.glyphCache[charcode];
  2047. if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
  2048. glyph = new Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
  2049. this.glyphCache[charcode] = glyph;
  2050. }
  2051. return glyph;
  2052. },
  2053. charsToGlyphs: function Font_charsToGlyphs(chars) {
  2054. var charsCache = this.charsCache;
  2055. var glyphs, glyph, charcode;
  2056. if (charsCache) {
  2057. glyphs = charsCache[chars];
  2058. if (glyphs) {
  2059. return glyphs;
  2060. }
  2061. }
  2062. if (!charsCache) {
  2063. charsCache = this.charsCache = Object.create(null);
  2064. }
  2065. glyphs = [];
  2066. var charsCacheKey = chars;
  2067. var i = 0,
  2068. ii;
  2069. if (this.cMap) {
  2070. var c = Object.create(null);
  2071. while (i < chars.length) {
  2072. this.cMap.readCharCode(chars, i, c);
  2073. charcode = c.charcode;
  2074. var length = c.length;
  2075. i += length;
  2076. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  2077. glyph = this.charToGlyph(charcode, isSpace);
  2078. glyphs.push(glyph);
  2079. }
  2080. } else {
  2081. for (i = 0, ii = chars.length; i < ii; ++i) {
  2082. charcode = chars.charCodeAt(i);
  2083. glyph = this.charToGlyph(charcode, charcode === 0x20);
  2084. glyphs.push(glyph);
  2085. }
  2086. }
  2087. return charsCache[charsCacheKey] = glyphs;
  2088. }
  2089. };
  2090. return Font;
  2091. }();
  2092. var ErrorFont = function ErrorFontClosure() {
  2093. function ErrorFont(error) {
  2094. this.error = error;
  2095. this.loadedName = 'g_font_error';
  2096. this.loading = false;
  2097. }
  2098. ErrorFont.prototype = {
  2099. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  2100. return [];
  2101. },
  2102. exportData: function ErrorFont_exportData() {
  2103. return { error: this.error };
  2104. }
  2105. };
  2106. return ErrorFont;
  2107. }();
  2108. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  2109. var charCodeToGlyphId = Object.create(null);
  2110. var glyphId, charCode, baseEncoding;
  2111. var isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  2112. if (properties.baseEncodingName) {
  2113. baseEncoding = (0, _encodings.getEncoding)(properties.baseEncodingName);
  2114. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  2115. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  2116. if (glyphId >= 0) {
  2117. charCodeToGlyphId[charCode] = glyphId;
  2118. } else {
  2119. charCodeToGlyphId[charCode] = 0;
  2120. }
  2121. }
  2122. } else if (isSymbolicFont) {
  2123. for (charCode in builtInEncoding) {
  2124. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  2125. }
  2126. } else {
  2127. baseEncoding = _encodings.StandardEncoding;
  2128. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  2129. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  2130. if (glyphId >= 0) {
  2131. charCodeToGlyphId[charCode] = glyphId;
  2132. } else {
  2133. charCodeToGlyphId[charCode] = 0;
  2134. }
  2135. }
  2136. }
  2137. var differences = properties.differences,
  2138. glyphsUnicodeMap;
  2139. if (differences) {
  2140. for (charCode in differences) {
  2141. var glyphName = differences[charCode];
  2142. glyphId = glyphNames.indexOf(glyphName);
  2143. if (glyphId === -1) {
  2144. if (!glyphsUnicodeMap) {
  2145. glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
  2146. }
  2147. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  2148. if (standardGlyphName !== glyphName) {
  2149. glyphId = glyphNames.indexOf(standardGlyphName);
  2150. }
  2151. }
  2152. if (glyphId >= 0) {
  2153. charCodeToGlyphId[charCode] = glyphId;
  2154. } else {
  2155. charCodeToGlyphId[charCode] = 0;
  2156. }
  2157. }
  2158. }
  2159. return charCodeToGlyphId;
  2160. }
  2161. var Type1Font = function Type1FontClosure() {
  2162. function findBlock(streamBytes, signature, startIndex) {
  2163. var streamBytesLength = streamBytes.length;
  2164. var signatureLength = signature.length;
  2165. var scanLength = streamBytesLength - signatureLength;
  2166. var i = startIndex,
  2167. j,
  2168. found = false;
  2169. while (i < scanLength) {
  2170. j = 0;
  2171. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  2172. j++;
  2173. }
  2174. if (j >= signatureLength) {
  2175. i += j;
  2176. while (i < streamBytesLength && (0, _util.isSpace)(streamBytes[i])) {
  2177. i++;
  2178. }
  2179. found = true;
  2180. break;
  2181. }
  2182. i++;
  2183. }
  2184. return {
  2185. found: found,
  2186. length: i
  2187. };
  2188. }
  2189. function getHeaderBlock(stream, suggestedLength) {
  2190. var EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
  2191. var streamStartPos = stream.pos;
  2192. var headerBytes, headerBytesLength, block;
  2193. try {
  2194. headerBytes = stream.getBytes(suggestedLength);
  2195. headerBytesLength = headerBytes.length;
  2196. } catch (ex) {
  2197. if (ex instanceof _util.MissingDataException) {
  2198. throw ex;
  2199. }
  2200. }
  2201. if (headerBytesLength === suggestedLength) {
  2202. block = findBlock(headerBytes, EEXEC_SIGNATURE, suggestedLength - 2 * EEXEC_SIGNATURE.length);
  2203. if (block.found && block.length === suggestedLength) {
  2204. return {
  2205. stream: new _stream.Stream(headerBytes),
  2206. length: suggestedLength
  2207. };
  2208. }
  2209. }
  2210. (0, _util.warn)('Invalid "Length1" property in Type1 font -- trying to recover.');
  2211. stream.pos = streamStartPos;
  2212. var SCAN_BLOCK_LENGTH = 2048;
  2213. var actualLength;
  2214. while (true) {
  2215. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  2216. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  2217. if (block.length === 0) {
  2218. break;
  2219. }
  2220. stream.pos += block.length;
  2221. if (block.found) {
  2222. actualLength = stream.pos - streamStartPos;
  2223. break;
  2224. }
  2225. }
  2226. stream.pos = streamStartPos;
  2227. if (actualLength) {
  2228. return {
  2229. stream: new _stream.Stream(stream.getBytes(actualLength)),
  2230. length: actualLength
  2231. };
  2232. }
  2233. (0, _util.warn)('Unable to recover "Length1" property in Type1 font -- using as is.');
  2234. return {
  2235. stream: new _stream.Stream(stream.getBytes(suggestedLength)),
  2236. length: suggestedLength
  2237. };
  2238. }
  2239. function getEexecBlock(stream, suggestedLength) {
  2240. var eexecBytes = stream.getBytes();
  2241. return {
  2242. stream: new _stream.Stream(eexecBytes),
  2243. length: eexecBytes.length
  2244. };
  2245. }
  2246. function Type1Font(name, file, properties) {
  2247. var PFB_HEADER_SIZE = 6;
  2248. var headerBlockLength = properties.length1;
  2249. var eexecBlockLength = properties.length2;
  2250. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  2251. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  2252. if (pfbHeaderPresent) {
  2253. file.skip(PFB_HEADER_SIZE);
  2254. headerBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  2255. }
  2256. var headerBlock = getHeaderBlock(file, headerBlockLength);
  2257. var headerBlockParser = new _type1_parser.Type1Parser(headerBlock.stream, false, SEAC_ANALYSIS_ENABLED);
  2258. headerBlockParser.extractFontHeader(properties);
  2259. if (pfbHeaderPresent) {
  2260. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  2261. eexecBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  2262. }
  2263. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  2264. var eexecBlockParser = new _type1_parser.Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
  2265. var data = eexecBlockParser.extractFontProgram();
  2266. for (var info in data.properties) {
  2267. properties[info] = data.properties[info];
  2268. }
  2269. var charstrings = data.charstrings;
  2270. var type2Charstrings = this.getType2Charstrings(charstrings);
  2271. var subrs = this.getType2Subrs(data.subrs);
  2272. this.charstrings = charstrings;
  2273. this.data = this.wrap(name, type2Charstrings, this.charstrings, subrs, properties);
  2274. this.seacs = this.getSeacs(data.charstrings);
  2275. }
  2276. Type1Font.prototype = {
  2277. get numGlyphs() {
  2278. return this.charstrings.length + 1;
  2279. },
  2280. getCharset: function Type1Font_getCharset() {
  2281. var charset = ['.notdef'];
  2282. var charstrings = this.charstrings;
  2283. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  2284. charset.push(charstrings[glyphId].glyphName);
  2285. }
  2286. return charset;
  2287. },
  2288. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  2289. var charstrings = this.charstrings;
  2290. var glyphNames = ['.notdef'],
  2291. glyphId;
  2292. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  2293. glyphNames.push(charstrings[glyphId].glyphName);
  2294. }
  2295. var encoding = properties.builtInEncoding;
  2296. if (encoding) {
  2297. var builtInEncoding = Object.create(null);
  2298. for (var charCode in encoding) {
  2299. glyphId = glyphNames.indexOf(encoding[charCode]);
  2300. if (glyphId >= 0) {
  2301. builtInEncoding[charCode] = glyphId;
  2302. }
  2303. }
  2304. }
  2305. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  2306. },
  2307. getSeacs: function Type1Font_getSeacs(charstrings) {
  2308. var i, ii;
  2309. var seacMap = [];
  2310. for (i = 0, ii = charstrings.length; i < ii; i++) {
  2311. var charstring = charstrings[i];
  2312. if (charstring.seac) {
  2313. seacMap[i + 1] = charstring.seac;
  2314. }
  2315. }
  2316. return seacMap;
  2317. },
  2318. getType2Charstrings: function Type1Font_getType2Charstrings(type1Charstrings) {
  2319. var type2Charstrings = [];
  2320. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  2321. type2Charstrings.push(type1Charstrings[i].charstring);
  2322. }
  2323. return type2Charstrings;
  2324. },
  2325. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  2326. var bias = 0;
  2327. var count = type1Subrs.length;
  2328. if (count < 1133) {
  2329. bias = 107;
  2330. } else if (count < 33769) {
  2331. bias = 1131;
  2332. } else {
  2333. bias = 32768;
  2334. }
  2335. var type2Subrs = [];
  2336. var i;
  2337. for (i = 0; i < bias; i++) {
  2338. type2Subrs.push([0x0B]);
  2339. }
  2340. for (i = 0; i < count; i++) {
  2341. type2Subrs.push(type1Subrs[i]);
  2342. }
  2343. return type2Subrs;
  2344. },
  2345. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  2346. var cff = new _cff_parser.CFF();
  2347. cff.header = new _cff_parser.CFFHeader(1, 0, 4, 4);
  2348. cff.names = [name];
  2349. var topDict = new _cff_parser.CFFTopDict();
  2350. topDict.setByName('version', 391);
  2351. topDict.setByName('Notice', 392);
  2352. topDict.setByName('FullName', 393);
  2353. topDict.setByName('FamilyName', 394);
  2354. topDict.setByName('Weight', 395);
  2355. topDict.setByName('Encoding', null);
  2356. topDict.setByName('FontMatrix', properties.fontMatrix);
  2357. topDict.setByName('FontBBox', properties.bbox);
  2358. topDict.setByName('charset', null);
  2359. topDict.setByName('CharStrings', null);
  2360. topDict.setByName('Private', null);
  2361. cff.topDict = topDict;
  2362. var strings = new _cff_parser.CFFStrings();
  2363. strings.add('Version 0.11');
  2364. strings.add('See original notice');
  2365. strings.add(name);
  2366. strings.add(name);
  2367. strings.add('Medium');
  2368. cff.strings = strings;
  2369. cff.globalSubrIndex = new _cff_parser.CFFIndex();
  2370. var count = glyphs.length;
  2371. var charsetArray = [0];
  2372. var i, ii;
  2373. for (i = 0; i < count; i++) {
  2374. var index = _cff_parser.CFFStandardStrings.indexOf(charstrings[i].glyphName);
  2375. if (index === -1) {
  2376. index = 0;
  2377. }
  2378. charsetArray.push(index >> 8 & 0xff, index & 0xff);
  2379. }
  2380. cff.charset = new _cff_parser.CFFCharset(false, 0, [], charsetArray);
  2381. var charStringsIndex = new _cff_parser.CFFIndex();
  2382. charStringsIndex.add([0x8B, 0x0E]);
  2383. for (i = 0; i < count; i++) {
  2384. var glyph = glyphs[i];
  2385. if (glyph.length === 0) {
  2386. charStringsIndex.add([0x8B, 0x0E]);
  2387. continue;
  2388. }
  2389. charStringsIndex.add(glyph);
  2390. }
  2391. cff.charStrings = charStringsIndex;
  2392. var privateDict = new _cff_parser.CFFPrivateDict();
  2393. privateDict.setByName('Subrs', null);
  2394. var fields = ['BlueValues', 'OtherBlues', 'FamilyBlues', 'FamilyOtherBlues', 'StemSnapH', 'StemSnapV', 'BlueShift', 'BlueFuzz', 'BlueScale', 'LanguageGroup', 'ExpansionFactor', 'ForceBold', 'StdHW', 'StdVW'];
  2395. for (i = 0, ii = fields.length; i < ii; i++) {
  2396. var field = fields[i];
  2397. if (!(field in properties.privateData)) {
  2398. continue;
  2399. }
  2400. var value = properties.privateData[field];
  2401. if (Array.isArray(value)) {
  2402. for (var j = value.length - 1; j > 0; j--) {
  2403. value[j] -= value[j - 1];
  2404. }
  2405. }
  2406. privateDict.setByName(field, value);
  2407. }
  2408. cff.topDict.privateDict = privateDict;
  2409. var subrIndex = new _cff_parser.CFFIndex();
  2410. for (i = 0, ii = subrs.length; i < ii; i++) {
  2411. subrIndex.add(subrs[i]);
  2412. }
  2413. privateDict.subrsIndex = subrIndex;
  2414. var compiler = new _cff_parser.CFFCompiler(cff);
  2415. return compiler.compile();
  2416. }
  2417. };
  2418. return Type1Font;
  2419. }();
  2420. var CFFFont = function CFFFontClosure() {
  2421. function CFFFont(file, properties) {
  2422. this.properties = properties;
  2423. var parser = new _cff_parser.CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  2424. this.cff = parser.parse();
  2425. var compiler = new _cff_parser.CFFCompiler(this.cff);
  2426. this.seacs = this.cff.seacs;
  2427. try {
  2428. this.data = compiler.compile();
  2429. } catch (e) {
  2430. (0, _util.warn)('Failed to compile font ' + properties.loadedName);
  2431. this.data = file;
  2432. }
  2433. }
  2434. CFFFont.prototype = {
  2435. get numGlyphs() {
  2436. return this.cff.charStrings.count;
  2437. },
  2438. getCharset: function CFFFont_getCharset() {
  2439. return this.cff.charset.charset;
  2440. },
  2441. getGlyphMapping: function CFFFont_getGlyphMapping() {
  2442. var cff = this.cff;
  2443. var properties = this.properties;
  2444. var charsets = cff.charset.charset;
  2445. var charCodeToGlyphId;
  2446. var glyphId;
  2447. if (properties.composite) {
  2448. charCodeToGlyphId = Object.create(null);
  2449. if (cff.isCIDFont) {
  2450. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  2451. var cid = charsets[glyphId];
  2452. var charCode = properties.cMap.charCodeOf(cid);
  2453. charCodeToGlyphId[charCode] = glyphId;
  2454. }
  2455. } else {
  2456. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  2457. charCodeToGlyphId[glyphId] = glyphId;
  2458. }
  2459. }
  2460. return charCodeToGlyphId;
  2461. }
  2462. var encoding = cff.encoding ? cff.encoding.encoding : null;
  2463. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  2464. return charCodeToGlyphId;
  2465. }
  2466. };
  2467. return CFFFont;
  2468. }();
  2469. (function checkSeacSupport() {
  2470. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  2471. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = true;
  2472. }
  2473. })();
  2474. (function checkChromeWindows() {
  2475. if (typeof navigator !== 'undefined' && /Windows.*Chrome/.test(navigator.userAgent)) {
  2476. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  2477. }
  2478. })();
  2479. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  2480. exports.PRIVATE_USE_OFFSET_START = PRIVATE_USE_OFFSET_START;
  2481. exports.PRIVATE_USE_OFFSET_END = PRIVATE_USE_OFFSET_END;
  2482. exports.ErrorFont = ErrorFont;
  2483. exports.Font = Font;
  2484. exports.FontFlags = FontFlags;
  2485. exports.ToUnicodeMap = ToUnicodeMap;
  2486. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  2487. exports.ProblematicCharRanges = ProblematicCharRanges;
  2488. exports.getFontType = getFontType;