@ -18,6 +18,7 @@ import {
@@ -18,6 +18,7 @@ import {
createObjectURL , FONT _IDENTITY _MATRIX , IDENTITY _MATRIX , ImageKind , isNodeJS ,
isNum , OPS , Util , warn
} from '../shared/util' ;
import { DOMSVGFactory } from './dom_utils' ;
var SVGGraphics = function ( ) {
throw new Error ( 'Not implemented: SVGGraphics' ) ;
@ -403,6 +404,8 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -403,6 +404,8 @@ SVGGraphics = (function SVGGraphicsClosure() {
}
function SVGGraphics ( commonObjs , objs , forceDataSchema ) {
this . svgFactory = new DOMSVGFactory ( ) ;
this . current = new SVGExtraState ( ) ;
this . transformMatrix = IDENTITY _MATRIX ; // Graphics state matrix
this . transformStack = [ ] ;
@ -418,7 +421,6 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -418,7 +421,6 @@ SVGGraphics = (function SVGGraphicsClosure() {
this . forceDataSchema = ! ! forceDataSchema ;
}
var NS = 'http://www.w3.org/2000/svg' ;
var XML _NS = 'http://www.w3.org/XML/1998/namespace' ;
var XLINK _NS = 'http://www.w3.org/1999/xlink' ;
var LINE _CAP _STYLES = [ 'butt' , 'round' , 'square' ] ;
@ -683,13 +685,13 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -683,13 +685,13 @@ SVGGraphics = (function SVGGraphicsClosure() {
this . current . y = this . current . lineY = 0 ;
current . xcoords = [ ] ;
current . tspan = document . createElementNS ( NS , 'svg:tspan' ) ;
current . tspan = this . svgFactory . createElement ( 'svg:tspan' ) ;
current . tspan . setAttributeNS ( null , 'font-family' , current . fontFamily ) ;
current . tspan . setAttributeNS ( null , 'font-size' ,
pf ( current . fontSize ) + 'px' ) ;
current . tspan . setAttributeNS ( null , 'y' , pf ( - current . y ) ) ;
current . txtElement = document . createElementNS ( NS , 'svg:text' ) ;
current . txtElement = this . svgFactory . createElement ( 'svg:text' ) ;
current . txtElement . appendChild ( current . tspan ) ;
} ,
@ -698,9 +700,9 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -698,9 +700,9 @@ SVGGraphics = (function SVGGraphicsClosure() {
this . current . y = this . current . lineY = 0 ;
this . current . textMatrix = IDENTITY _MATRIX ;
this . current . lineMatrix = IDENTITY _MATRIX ;
this . current . tspan = document . createElementNS ( NS , 'svg:tspan' ) ;
this . current . txtElement = document . createElementNS ( NS , 'svg:text' ) ;
this . current . txtgrp = document . createElementNS ( NS , 'svg:g' ) ;
this . current . tspan = this . svgFactory . createElement ( 'svg:tspan' ) ;
this . current . txtElement = this . svgFactory . createElement ( 'svg:text' ) ;
this . current . txtgrp = this . svgFactory . createElement ( 'svg:g' ) ;
this . current . xcoords = [ ] ;
} ,
@ -710,7 +712,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -710,7 +712,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
this . current . y = this . current . lineY += y ;
current . xcoords = [ ] ;
current . tspan = document . createElementNS ( NS , 'svg:tspan' ) ;
current . tspan = this . svgFactory . createElement ( 'svg:tspan' ) ;
current . tspan . setAttributeNS ( null , 'font-family' , current . fontFamily ) ;
current . tspan . setAttributeNS ( null , 'font-size' ,
pf ( current . fontSize ) + 'px' ) ;
@ -810,7 +812,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -810,7 +812,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
addFontStyle : function SVGGraphics _addFontStyle ( fontObj ) {
if ( ! this . cssStyle ) {
this . cssStyle = document . createElementNS ( NS , 'svg:style' ) ;
this . cssStyle = this . svgFactory . createElement ( 'svg:style' ) ;
this . cssStyle . setAttributeNS ( null , 'type' , 'text/css' ) ;
this . defs . appendChild ( this . cssStyle ) ;
}
@ -852,7 +854,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -852,7 +854,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
current . fontWeight = bold ;
current . fontStyle = italic ;
current . tspan = document . createElementNS ( NS , 'svg:tspan' ) ;
current . tspan = this . svgFactory . createElement ( 'svg:tspan' ) ;
current . tspan . setAttributeNS ( null , 'y' , pf ( - current . y ) ) ;
current . xcoords = [ ] ;
} ,
@ -885,7 +887,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -885,7 +887,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
setFillRGBColor : function SVGGraphics _setFillRGBColor ( r , g , b ) {
var color = Util . makeCssRgb ( r , g , b ) ;
this . current . fillColor = color ;
this . current . tspan = document . createElementNS ( NS , 'svg:tspan' ) ;
this . current . tspan = this . svgFactory . createElement ( 'svg:tspan' ) ;
this . current . xcoords = [ ] ;
} ,
setDash : function SVGGraphics _setDash ( dashArray , dashPhase ) {
@ -896,7 +898,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -896,7 +898,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
constructPath : function SVGGraphics _constructPath ( ops , args ) {
var current = this . current ;
var x = current . x , y = current . y ;
current . path = document . createElementNS ( NS , 'svg:path' ) ;
current . path = this . svgFactory . createElement ( 'svg:path' ) ;
var d = [ ] ;
var opLength = ops . length ;
@ -967,7 +969,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -967,7 +969,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
// Add current path to clipping path
var clipId = 'clippath' + clipCount ;
clipCount ++ ;
var clipPath = document . createElementNS ( NS , 'svg:clipPath' ) ;
var clipPath = this . svgFactory . createElement ( 'svg:clipPath' ) ;
clipPath . setAttributeNS ( null , 'id' , clipId ) ;
clipPath . setAttributeNS ( null , 'transform' , pm ( this . transformMatrix ) ) ;
var clipElement = current . element . cloneNode ( ) ;
@ -1110,7 +1112,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -1110,7 +1112,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
paintSolidColorImageMask :
function SVGGraphics _paintSolidColorImageMask ( ) {
var current = this . current ;
var rect = document . createElementNS ( NS , 'svg:rect' ) ;
var rect = this . svgFactory . createElement ( 'svg:rect' ) ;
rect . setAttributeNS ( null , 'x' , '0' ) ;
rect . setAttributeNS ( null , 'y' , '0' ) ;
rect . setAttributeNS ( null , 'width' , '1px' ) ;
@ -1122,7 +1124,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -1122,7 +1124,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
paintJpegXObject : function SVGGraphics _paintJpegXObject ( objId , w , h ) {
var imgObj = this . objs . get ( objId ) ;
var imgEl = document . createElementNS ( NS , 'svg:image' ) ;
var imgEl = this . svgFactory . createElement ( 'svg:image' ) ;
imgEl . setAttributeNS ( XLINK _NS , 'xlink:href' , imgObj . src ) ;
imgEl . setAttributeNS ( null , 'width' , pf ( w ) ) ;
imgEl . setAttributeNS ( null , 'height' , pf ( h ) ) ;
@ -1149,14 +1151,14 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -1149,14 +1151,14 @@ SVGGraphics = (function SVGGraphicsClosure() {
var height = imgData . height ;
var imgSrc = convertImgDataToPng ( imgData , this . forceDataSchema ) ;
var cliprect = document . createElementNS ( NS , 'svg:rect' ) ;
var cliprect = this . svgFactory . createElement ( 'svg:rect' ) ;
cliprect . setAttributeNS ( null , 'x' , '0' ) ;
cliprect . setAttributeNS ( null , 'y' , '0' ) ;
cliprect . setAttributeNS ( null , 'width' , pf ( width ) ) ;
cliprect . setAttributeNS ( null , 'height' , pf ( height ) ) ;
this . current . element = cliprect ;
this . clip ( 'nonzero' ) ;
var imgEl = document . createElementNS ( NS , 'svg:image' ) ;
var imgEl = this . svgFactory . createElement ( 'svg:image' ) ;
imgEl . setAttributeNS ( XLINK _NS , 'xlink:href' , imgSrc ) ;
imgEl . setAttributeNS ( null , 'x' , '0' ) ;
imgEl . setAttributeNS ( null , 'y' , pf ( - height ) ) ;
@ -1180,10 +1182,10 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -1180,10 +1182,10 @@ SVGGraphics = (function SVGGraphicsClosure() {
var fillColor = current . fillColor ;
current . maskId = 'mask' + maskCount ++ ;
var mask = document . createElementNS ( NS , 'svg:mask' ) ;
var mask = this . svgFactory . createElement ( 'svg:mask' ) ;
mask . setAttributeNS ( null , 'id' , current . maskId ) ;
var rect = document . createElementNS ( NS , 'svg:rect' ) ;
var rect = this . svgFactory . createElement ( 'svg:rect' ) ;
rect . setAttributeNS ( null , 'x' , '0' ) ;
rect . setAttributeNS ( null , 'y' , '0' ) ;
rect . setAttributeNS ( null , 'width' , pf ( width ) ) ;
@ -1208,7 +1210,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -1208,7 +1210,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
var width = bbox [ 2 ] - bbox [ 0 ] ;
var height = bbox [ 3 ] - bbox [ 1 ] ;
var cliprect = document . createElementNS ( NS , 'svg:rect' ) ;
var cliprect = this . svgFactory . createElement ( 'svg:rect' ) ;
cliprect . setAttributeNS ( null , 'x' , bbox [ 0 ] ) ;
cliprect . setAttributeNS ( null , 'y' , bbox [ 1 ] ) ;
cliprect . setAttributeNS ( null , 'width' , pf ( width ) ) ;
@ -1225,24 +1227,17 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -1225,24 +1227,17 @@ SVGGraphics = (function SVGGraphicsClosure() {
/ * *
* @ private
* /
_initialize : function SVGGraphics _initialize ( viewport ) {
// Create the SVG element.
var svg = document . createElementNS ( NS , 'svg:svg' ) ;
svg . setAttributeNS ( null , 'version' , '1.1' ) ;
svg . setAttributeNS ( null , 'width' , viewport . width + 'px' ) ;
svg . setAttributeNS ( null , 'height' , viewport . height + 'px' ) ;
svg . setAttributeNS ( null , 'preserveAspectRatio' , 'none' ) ;
svg . setAttributeNS ( null , 'viewBox' , '0 0 ' + viewport . width +
' ' + viewport . height ) ;
_initialize ( viewport ) {
let svg = this . svgFactory . create ( viewport . width , viewport . height ) ;
// Create the definitions element.
var definitions = document . createElementNS ( NS , 'svg:defs' ) ;
let definitions = this . svgFactory . createElement ( 'svg:defs' ) ;
svg . appendChild ( definitions ) ;
this . defs = definitions ;
// Create the root group element, which acts a container for all other
// groups and applies the viewport transform.
var rootGroup = document . createElementNS ( NS , 'svg:g' ) ;
let rootGroup = this . svgFactory . createElement ( 'svg:g' ) ;
rootGroup . setAttributeNS ( null , 'transform' , pm ( viewport . transform ) ) ;
svg . appendChild ( rootGroup ) ;
@ -1259,7 +1254,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -1259,7 +1254,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
* /
_ensureClipGroup : function SVGGraphics _ensureClipGroup ( ) {
if ( ! this . current . clipGroup ) {
var clipGroup = document . createElementNS ( NS , 'svg:g' ) ;
var clipGroup = this . svgFactory . createElement ( 'svg:g' ) ;
clipGroup . setAttributeNS ( null , 'clip-path' ,
this . current . activeClipUrl ) ;
this . svg . appendChild ( clipGroup ) ;
@ -1273,7 +1268,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
@@ -1273,7 +1268,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
* /
_ensureTransformGroup : function SVGGraphics _ensureTransformGroup ( ) {
if ( ! this . tgrp ) {
this . tgrp = document . createElementNS ( NS , 'svg:g' ) ;
this . tgrp = this . svgFactory . createElement ( 'svg:g' ) ;
this . tgrp . setAttributeNS ( null , 'transform' , pm ( this . transformMatrix ) ) ;
if ( this . current . activeClipUrl ) {
this . _ensureClipGroup ( ) . appendChild ( this . tgrp ) ;