Fixes image and font embedding
This commit is contained in:
		
							parent
							
								
									0f862e7eb3
								
							
						
					
					
						commit
						de23d3791e
					
				@ -99,7 +99,7 @@ DOMElement.prototype = {
 | 
				
			|||||||
      attrList.push(i + '="' + xmlEncode(this.attributes[i]) + '"');
 | 
					      attrList.push(i + '="' + xmlEncode(this.attributes[i]) + '"');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (this.nodeName === 'svg:tspan') {
 | 
					    if (this.nodeName === 'svg:tspan' || this.nodeName === 'svg:style') {
 | 
				
			||||||
      var encText = xmlEncode(this.textContent);
 | 
					      var encText = xmlEncode(this.textContent);
 | 
				
			||||||
      return '<' + this.nodeName + ' ' + attrList.join(' ') + '>' +
 | 
					      return '<' + this.nodeName + ' ' + attrList.join(' ') + '>' +
 | 
				
			||||||
             encText + '</' + this.nodeName + '>';
 | 
					             encText + '</' + this.nodeName + '>';
 | 
				
			||||||
 | 
				
			|||||||
@ -65,6 +65,7 @@ PDFJS.getDocument(data).then(function (doc) {
 | 
				
			|||||||
      
 | 
					      
 | 
				
			||||||
      return page.getOperatorList().then(function (opList) {
 | 
					      return page.getOperatorList().then(function (opList) {
 | 
				
			||||||
        var svgGfx = new PDFJS.SVGGraphics(page.commonObjs, page.objs);
 | 
					        var svgGfx = new PDFJS.SVGGraphics(page.commonObjs, page.objs);
 | 
				
			||||||
 | 
					        svgGfx.embedFonts = true;
 | 
				
			||||||
        return svgGfx.getSVG(opList, viewport).then(function (svg) {
 | 
					        return svgGfx.getSVG(opList, viewport).then(function (svg) {
 | 
				
			||||||
          var svgDump = svg.toString();
 | 
					          var svgDump = svg.toString();
 | 
				
			||||||
          writeToFile(svgDump, pageNum);
 | 
					          writeToFile(svgDump, pageNum);
 | 
				
			||||||
 | 
				
			|||||||
@ -361,6 +361,10 @@ var SVGGraphics = (function SVGGraphicsClosure() {
 | 
				
			|||||||
    this.commonObjs = commonObjs;
 | 
					    this.commonObjs = commonObjs;
 | 
				
			||||||
    this.objs = objs;
 | 
					    this.objs = objs;
 | 
				
			||||||
    this.pendingEOFill = false;
 | 
					    this.pendingEOFill = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this.embedFonts = false;
 | 
				
			||||||
 | 
					    this.embeddedFonts = {};
 | 
				
			||||||
 | 
					    this.cssStyle = null;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  var NS = 'http://www.w3.org/2000/svg';
 | 
					  var NS = 'http://www.w3.org/2000/svg';
 | 
				
			||||||
@ -728,12 +732,31 @@ var SVGGraphics = (function SVGGraphicsClosure() {
 | 
				
			|||||||
      this.moveText(x, y);
 | 
					      this.moveText(x, y);
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
 | 
				
			||||||
 | 
					      if (!this.cssStyle) {
 | 
				
			||||||
 | 
					        this.cssStyle = document.createElementNS(NS, 'svg:style');
 | 
				
			||||||
 | 
					        this.cssStyle.setAttributeNS(null, 'type', 'text/css');
 | 
				
			||||||
 | 
					        this.defs.appendChild(this.cssStyle);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
 | 
				
			||||||
 | 
					      this.cssStyle.textContent +=
 | 
				
			||||||
 | 
					        '@font-face { font-family: "' + fontObj.loadedName + '";' +
 | 
				
			||||||
 | 
					        ' src: url(' + url + '); }\n';
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    setFont: function SVGGraphics_setFont(details) {
 | 
					    setFont: function SVGGraphics_setFont(details) {
 | 
				
			||||||
      var current = this.current;
 | 
					      var current = this.current;
 | 
				
			||||||
      var fontObj = this.commonObjs.get(details[0]);
 | 
					      var fontObj = this.commonObjs.get(details[0]);
 | 
				
			||||||
      var size = details[1];
 | 
					      var size = details[1];
 | 
				
			||||||
      this.current.font = fontObj;
 | 
					      this.current.font = fontObj;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (this.embedFonts && fontObj.data &&
 | 
				
			||||||
 | 
					          !this.embeddedFonts[fontObj.loadedName]) {
 | 
				
			||||||
 | 
					        this.addFontStyle(fontObj);
 | 
				
			||||||
 | 
					        this.embeddedFonts[fontObj.loadedName] = fontObj;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      current.fontMatrix = (fontObj.fontMatrix ?
 | 
					      current.fontMatrix = (fontObj.fontMatrix ?
 | 
				
			||||||
                            fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
 | 
					                            fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1028,7 +1051,7 @@ var SVGGraphics = (function SVGGraphicsClosure() {
 | 
				
			|||||||
      var current = this.current;
 | 
					      var current = this.current;
 | 
				
			||||||
      var imgObj = this.objs.get(objId);
 | 
					      var imgObj = this.objs.get(objId);
 | 
				
			||||||
      var imgEl = document.createElementNS(NS, 'svg:image');
 | 
					      var imgEl = document.createElementNS(NS, 'svg:image');
 | 
				
			||||||
      imgEl.setAttributeNS(XLINK_NS, 'href', imgObj.src);
 | 
					      imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
 | 
				
			||||||
      imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
 | 
					      imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
 | 
				
			||||||
      imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
 | 
					      imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
 | 
				
			||||||
      imgEl.setAttributeNS(null, 'x', '0');
 | 
					      imgEl.setAttributeNS(null, 'x', '0');
 | 
				
			||||||
@ -1069,7 +1092,7 @@ var SVGGraphics = (function SVGGraphicsClosure() {
 | 
				
			|||||||
      current.element = cliprect;
 | 
					      current.element = cliprect;
 | 
				
			||||||
      this.clip('nonzero');
 | 
					      this.clip('nonzero');
 | 
				
			||||||
      var imgEl = document.createElementNS(NS, 'svg:image');
 | 
					      var imgEl = document.createElementNS(NS, 'svg:image');
 | 
				
			||||||
      imgEl.setAttributeNS(XLINK_NS, 'href', imgSrc);
 | 
					      imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
 | 
				
			||||||
      imgEl.setAttributeNS(null, 'x', '0');
 | 
					      imgEl.setAttributeNS(null, 'x', '0');
 | 
				
			||||||
      imgEl.setAttributeNS(null, 'y', pf(-height));
 | 
					      imgEl.setAttributeNS(null, 'y', pf(-height));
 | 
				
			||||||
      imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
 | 
					      imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user