<commit_before>'use strict'

var PDFObject  = require('./object/object')
var PDFXObject = require('./object/xobject')
var Pages      = require('./object/pages')
var Page       = require('./object/page')
var uuid       = require('node-uuid')
var debug      = require('debug')('pdfjs')

var version = require('../../package.json').version

var PDF = module.exports = function PDF(doc) {
  this.doc = doc

  this.version = 1.3

  this.info = {
    id:           uuid.v4(),
    producer:     'pdfjs v' + version + ' (github.com/rkusa/pdfjs)',
    creationDate: null
  }

  this.offset = 0
}

PDF.prototype.addObject = function(object) {
  this.objects.push(object)
}

PDF.prototype.createObject = function(type) {
  var object = new PDFObject()
  if (type) object.addProperty('Type', type)
  this.addObject(object)
  return object
}

PDF.prototype.createXObject = function(subtype) {
  var xobject = new PDFXObject()
  if (subtype) xobject.addProperty('Subtype', subtype)
  this.addObject(xobject)
  return xobject
}

// PDF.prototype.createImage = function(data) {
//   var image = new Image('Im' + (this.images.length + 1), data)
//   this.images.push(image)
//   this.addObject(image.xobject)
//   return image
// }

PDF.prototype.createPage = function() {
  var pages = this.pages.pages
  var index = pages.indexOf(this.currentPage)

  if (index + 1 < pages.length) {
    return this.currentPage = pages[index + 1]
  } else {
    var page = this.currentPage = new Page(this.pages)

    this.pages.add(page)

    return page
  }
}

PDF.prototype.Tm = function(a, b, c, d, e, f) {
  this.write(a, b, c, d, e, f + this.offset, 'Tm')
}

PDF.prototype.Tj = function(str) {
  this.write(str, 'Tj')
}

PDF.prototype.Td = function(x, y) {
  this.write(x, y, 'Td')
}

PDF.prototype.Tf = function(font, size) {
  this.write(font, size, 'Tf')
}

PDF.prototype.rg = function(r, g, b) {
  this.write(r, g, b, 'rg')
}

PDF.prototype.RG = function(r, g, b) {
  this.write(r, g, b, 'RG')
}

PDF.prototype.BT = function() {
  this.write('BT')
}

PDF.prototype.ET = function() {
  this.write('ET')
}

PDF.prototype.re = function(x, y, width, height) {
  this.write(x, y + this.offset, width, height, 're')
}

PDF.prototype.rectangle = function(x, y, width, height) {
  y += this.offset

  var top = this.doc.style.height - this.doc.style.paddingTop

  if (y < this.doc.style.paddingBottom) {
    var delta = this.doc.style.paddingBottom - y
    y = this.doc.style.paddingBottom
    height -= delta
  } else if (y + height > top) {
    height -= (y + height) - top
  }

  if (height > this.doc.style.innerHeight) {
    height = this.doc.style.innerHeight
  }

  this.re(x, y - this.offset, width, height, 're')
}

PDF.prototype.f = function() {
  this.write('f')
}

PDF.prototype.w = function(lineWidth) {
  this.write(lineWidth, 'w')
}

PDF.prototype.S = function() {
  var path = Array.prototype.slice.call(arguments)<commit_msg>do not repeat unnecessary w, rg and RG operations<commit_after>'use strict'

var PDFObject  = require('./object/object')
var PDFXObject = require('./object/xobject')
var Pages      = require('./object/pages')
var Page       = require('./object/page')
var uuid       = require('node-uuid')
var debug      = require('debug')('pdfjs')

var version = require('../../package.json').version

var PDF = module.exports = function PDF(doc) {
  this.doc = doc

  this.version = 1.3

  this.info = {
    id:           uuid.v4(),
    producer:     'pdfjs v' + version + ' (github.com/rkusa/pdfjs)',
    creationDate: null
  }

  this.offset = 0
  this.state = {}
}

PDF.prototype.addObject = function(object) {
  this.objects.push(object)
}

PDF.prototype.createObject = function(type) {
  var object = new PDFObject()
  if (type) object.addProperty('Type', type)
  this.addObject(object)
  return object
}

PDF.prototype.createXObject = function(subtype) {
  var xobject = new PDFXObject()
  if (subtype) xobject.addProperty('Subtype', subtype)
  this.addObject(xobject)
  return xobject
}

// PDF.prototype.createImage = function(data) {
//   var image = new Image('Im' + (this.images.length + 1), data)
//   this.images.push(image)
//   this.addObject(image.xobject)
//   return image
// }

PDF.prototype.createPage = function() {
  var pages = this.pages.pages
  var index = pages.indexOf(this.currentPage)

  // reset state (line widht, etc.) for each page
  this.state = {}

  if (index + 1 < pages.length) {
    return this.currentPage = pages[index + 1]
  } else {
    var page = this.currentPage = new Page(this.pages)

    this.pages.add(page)

    return page
  }
}

PDF.prototype.Tm = function(a, b, c, d, e, f) {
  this.write(a, b, c, d, e, f + this.offset, 'Tm')
}

PDF.prototype.Tj = function(str) {
  this.write(str, 'Tj')
}

PDF.prototype.Td = function(x, y) {
  this.write(x, y, 'Td')
}

PDF.prototype.Tf = function(font, size) {
  this.write(font, size, 'Tf')
}

PDF.prototype.rg = function(r, g, b) {
  var curr = this.state.rg
  if (curr && curr[0] === r && curr[1] === g && curr[2] === b) {
    return
  }
  this.state.rg = [r, g, b]
  this.write(r, g, b, 'rg')
}

PDF.prototype.RG = function(r, g, b) {
  var curr = this.state.RG
  if (curr && curr[0] === r && curr[1] === g && curr[2] === b) {
    return
  }
  this.state.RG = [r, g, b]
  this.write(r, g, b, 'RG')
}

PDF.prototype.BT = function() {
  this.write('BT')
}

PDF.prototype.ET = function() {
  this.write('ET')
}

PDF.prototype.re = function(x, y, width, height) {
  this.write(x, y + this.offset, width, height, 're')
}

PDF.prototype.rectangle = function(x, y, width, height) {
  y += this.offset

  var top = this.doc.style.height - this.doc.style.paddingTop

  if (y < this.doc.style.paddingBottom) {
    var delta = this.doc.style.paddingBottom - y
    y = this.doc.style.paddingBottom
    height -= delta
  } else if (y + height > top) {
    height -= (y + height) - top
  }

  if (height > this.doc.style.innerHeight) {
    height = this.doc.style.innerHeight
  }

  this.re(x, y - this.offset, width, height, 're')
}

PDF.prototype.f = function() {
  this.write('f')
}

PDF.prototype.w = function(lineWidth) {
  if (this.state.w === lineWidth) {
    return
  }
  this.state.w = lineWidth
  this.write(lineWidth, 'w')
}

PDF.prototype.S = function() {
  var path = Array.prototype.slice.call(arguments)
{'fraction_non_alphanumeric': 0.17172359015091343, 'fraction_numerical': 0.003177124702144559, 'mean_word_length': 3.088311688311688, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6839297', 'n_tokens_mistral': 2326, 'n_tokens_neox': 2297, 'n_words': 513}