decktape.js
function parseFont(fontObject) {
    const pdfStreamInput = cpyCxtParser.parseNewObject(fontObject.getObjectID());
    const fontDictionary = pdfStreamInput.toJSObject();
    // See "Introduction to Font Data Structures" from PDF specification
    if (fontDictionary.Subtype.value === 'Type0') {
      // TODO: properly support composite fonts with multiple descendants
      const descendant = cpyCxtParser
        .parseNewObject(fontDictionary.DescendantFonts.toJSArray()[0].getObjectID())
        .toJSObject();
      if (descendant.Subtype.value == 'CIDFontType2') {
        const descriptor = cpyCxtParser
          .parseNewObject(descendant.FontDescriptor.getObjectID())
          .toJSObject();
        const id = descriptor.FontFile2.getObjectID();
        const buffer = readStream(cpyCxtParser.parseNewObject(id));
        const font = Font.create(buffer, { type: 'ttf', hinting: true });
        // PDF font name does not contain sub family on Windows 10 so a more robust key
        // is computed from the font metadata
        const name = descriptor.FontName.value + ' - ' + fontMetadataKey(font.data.name);
        if (context.pdfFonts[name]) {
          const f = context.pdfFonts[name].font;
          font.data.glyf.forEach((g, i) => {
            if (g.contours && g.contours.length > 0) {
              if (!f.data.glyf[i].contours || f.data.glyf[i].contours.length === 0) {
                f.data.glyf[i] = g;
              }
            } else if (g.compound) {
              if (typeof f.data.glyf[i].compound === 'undefined'
                  && f.data.glyf[i].contours.length === 0) {
                f.data.glyf[i] = g;
              }
            }
          });
          const replacement = {};
          replacement[id] = context.pdfFonts[name].id;
          cpyCxt.replaceSourceObjects(replacement);
        } else {
          const xObjectId = printer.getObjectsContext().allocateNewObjectID();
          context.pdfFonts[name] = { id: xObjectId, font: font };
          const replacement = {};
          replacement[id] = xObjectId;
          cpyCxt.replaceSourceObjects(replacement);
        }
      }
    }
  }
function parseFont(fontObject) {
    const pdfStreamInput = cpyCxtParser.parseNewObject(fontObject.getObjectID());
    const fontDictionary = pdfStreamInput.toJSObject();
    // See "Introduction to Font Data Structures" from PDF specification
    if (fontDictionary.Subtype.value === 'Type0') {
      // TODO: properly support composite fonts with multiple descendants
      const descendant = cpyCxtParser
        .parseNewObject(fontDictionary.DescendantFonts.toJSArray()[0].getObjectID())
        .toJSObject();
      if (descendant.Subtype.value == 'CIDFontType2') {
        const descriptor = cpyCxtParser
          .parseNewObject(descendant.FontDescriptor.getObjectID())
          .toJSObject();
        const id = descriptor.FontFile2.getObjectID();
        const buffer = readStream(cpyCxtParser.parseNewObject(id));
        const font = Font.create(buffer, { type: 'ttf', hinting: true });
        // PDF font name does not contain sub family on Windows 10 so a more robust key
        // is computed from the font metadata
        const name = descriptor.FontName.value + ' - ' + fontMetadataKey(font.data.name);
        if (context.pdfFonts[name]) {
          const f = context.pdfFonts[name].font;
          font.data.glyf.forEach((g, i) => {
            if (g.contours && g.contours.length > 0) {
              if (!f.data.glyf[i].contours || f.data.glyf[i].contours.length === 0) {
                f.data.glyf[i] = g;
              }
            } else if (g.compound) {
              if (typeof f.data.glyf[i].compound === 'undefined'
                  && f.data.glyf[i].contours.length === 0) {
                f.data.glyf[i] = g;
              }
            }
          });
          const replacement = {};
          replacement[id] = context.pdfFonts[name].id;
          cpyCxt.replaceSourceObjects(replacement);
        } else {
          const xObjectId = printer.getObjectsContext().allocateNewObjectID();
          context.pdfFonts[name] = { id: xObjectId, font: font };
          const replacement = {};
          replacement[id] = xObjectId;
          cpyCxt.replaceSourceObjects(replacement);
        }
      }
    }
  }
function parseFont ( fontObject ) { const pdfStreamInput = cpyCxtParser . parseNewObject ( fontObject . getObjectID ( ) ) ; const fontDictionary = pdfStreamInput . toJSObject ( ) ; // See "Introduction to Font Data Structures" from PDF specification if ( fontDictionary . Subtype . value === 'Type0' ) { // TODO: properly support composite fonts with multiple descendants const descendant = cpyCxtParser . parseNewObject ( fontDictionary . DescendantFonts . toJSArray ( ) [ 0 ] . getObjectID ( ) ) . toJSObject ( ) ; if ( descendant . Subtype . value == 'CIDFontType2' ) { const descriptor = cpyCxtParser . parseNewObject ( descendant . FontDescriptor . getObjectID ( ) ) . toJSObject ( ) ; const id = descriptor . FontFile2 . getObjectID ( ) ; const buffer = readStream ( cpyCxtParser . parseNewObject ( id ) ) ; const font = Font . create ( buffer , { type : 'ttf' , hinting : true } ) ; // PDF font name does not contain sub family on Windows 10 so a more robust key // is computed from the font metadata const name = descriptor . FontName . value + ' - ' + fontMetadataKey ( font . data . name ) ; if ( context . pdfFonts [ name ] ) { const f = context . pdfFonts [ name ] . font ; font . data . glyf . forEach ( ( g , i ) => { if ( g . contours && g . contours . length > 0 ) { if ( ! f . data . glyf [ i ] . contours || f . data . glyf [ i ] . contours . length === 0 ) { f . data . glyf [ i ] = g ; } } else if ( g . compound ) { if ( typeof f . data . glyf [ i ] . compound === 'undefined' && f . data . glyf [ i ] . contours . length === 0 ) { f . data . glyf [ i ] = g ; } } } ) ; const replacement = { } ; replacement [ id ] = context . pdfFonts [ name ] . id ; cpyCxt . replaceSourceObjects ( replacement ) ; } else { const xObjectId = printer . getObjectsContext ( ) . allocateNewObjectID ( ) ; context . pdfFonts [ name ] = { id : xObjectId , font : font } ; const replacement = { } ; replacement [ id ] = xObjectId ; cpyCxt . replaceSourceObjects ( replacement ) ; } } } }
Consolidate duplicate fonts
Consolidate duplicate fonts