<commit_before>/**
 * jsPDF Annotations PlugIn
 * Copyright (c) 2014 <NAME> (TwelveTone LLC)  <EMAIL>
 *
 * Licensed under the MIT License.
 * http://opensource.org/licenses/mit-license
 */

/**
 * There are many types of annotations in a PDF document. Annotations are placed
 * on a page at a particular location. They are not 'attached' to an object'
 * <br />
 * This plugin current supports <br />
 * <li> Goto Page (set pageNumber in options)
 * <li> Goto URL (set url in options)
 * 
 * <p>
 * Options In PDF spec Not Implemented Yet
 * <li> link border
 * <li> named target
 * <li> page coordinates
 * <li> destination page scaling and layout
 * <li> actions other than URL and GotoPage
 * <li> background / hover actions
 * </p>
 */

(function(jsPDFAPI) {
	'use strict';

	jsPDFAPI.initAnnotationPlugin = function() {
		this.annotationPlugin = {};

		this.annotationPlugin.annotations = [];
		// TODO remove this after we find a way to subscribe before the
		// first page is created.
		this.annotationPlugin.annotations[1] = [];

		this.annotationPlugin.f2 = function(number) {
			return number.toFixed(2);
		};

		this.internal.events.subscribe('addPage', function(info) {
			this.annotationPlugin.annotations[info.pageNumber] = [];
		});

		this.internal.events.subscribe('render/page', function(info) {
			var pageAnnos = this.annotationPlugin.annotations[info.pageNumber];
			
			var found = false;
			for (var a = 0; a < pageAnnos.length; a++) {
				if (pageAnnos[a].type === 'link'){
					found = true;
					break;
				}
			}
			if (found == false){
				return;
			}

			this.internal.write("/Annots [");
			for (var a = 0; a < pageAnnos.length; a++) {
				var anno = pageAnnos[a];
				var k = this.internal.scaleFactor;
				var pageHeight = this.internal.pageSize.height;
				var rect = "/Rect [" + this.annotationPlugin.f2(anno.x * k) + " " + this.annotationPlugin.f2((pageHeight - anno.y) * k) + " " + this.annotationPlugin.f2(anno.x + anno.w * k) + " " + this.annotationPlugin.f2(pageHeight - (anno.y + anno.h) * k) + "] ";
				if (anno.options.url) {
					this.internal.write('<</Type /Annot /Subtype /Link ' + rect + '/Border [0 0 0] /A <</S /URI /URI (http://www.twelvetone.tv) >> >>')
				} else if (anno.options.pageNumber) {
					// first page is 0
					this.internal.write('<</Type /Annot /Subtype /Link ' + rect + '/Border [0 0 0] /Dest [' + (anno.options.pageNumber-1) + ' /XYZ 0 ' + pageHeight + ' 0] >>')
				} else {
					// TODO error - not supported or not indicated
				}
			}
			this.internal.write("]");
		});
	};

	/**
	 * An array of arrays, indexed by <em>pageNumber</em>.
	 */
	// this.internal.annotations = [];
	/**
	 * valid options
	 * <li> pageNumber or url [required]
	 */
	jsPDFAPI.link = function(x,y,w,h,options) {
		'use strict';
		this.annotationPlugin.annotations[this.internal.getNumberOfPages()].push({
			x : x,
			y : y,
			w : w,
			h : h,
			options : options,
			type : 'link'
		});
	};

	/**<commit_msg>removed hardcoded url added parameter check to link options<commit_after>/**
 * jsPDF Annotations PlugIn
 * Copyright (c) 2014 <NAME> (TwelveTone LLC)  st<EMAIL>
 *
 * Licensed under the MIT License.
 * http://opensource.org/licenses/mit-license
 */

/**
 * There are many types of annotations in a PDF document. Annotations are placed
 * on a page at a particular location. They are not 'attached' to an object'
 * <br />
 * This plugin current supports <br />
 * <li> Goto Page (set pageNumber in options)
 * <li> Goto URL (set url in options)
 * 
 * <p>
 * Options In PDF spec Not Implemented Yet
 * <li> link border
 * <li> named target
 * <li> page coordinates
 * <li> destination page scaling and layout
 * <li> actions other than URL and GotoPage
 * <li> background / hover actions
 * </p>
 */

function notEmpty(obj) {
	if (typeof obj != 'undefined') {
		if (obj != '') {
			return true;
		}
	}
}

(function(jsPDFAPI) {
	'use strict';

	jsPDFAPI.initAnnotationPlugin = function() {
		this.annotationPlugin = {};

		this.annotationPlugin.annotations = [];
		// TODO remove this after we find a way to subscribe before the
		// first page is created.
		this.annotationPlugin.annotations[1] = [];

		this.annotationPlugin.f2 = function(number) {
			return number.toFixed(2);
		};

		this.internal.events.subscribe('addPage', function(info) {
			this.annotationPlugin.annotations[info.pageNumber] = [];
		});

		this.internal.events.subscribe('render/page', function(info) {
			var pageAnnos = this.annotationPlugin.annotations[info.pageNumber];

			var found = false;
			for (var a = 0; a < pageAnnos.length; a++) {
				var anno = pageAnnos[a];
				if (anno.type === 'link') {
					if (notEmpty(anno.options.url) || notEmpty(anno.options.pageNumber)) {
						found = true;
						break;
					}
				}
			}
			if (found == false) {
				return;
			}

			this.internal.write("/Annots [");
			for (var a = 0; a < pageAnnos.length; a++) {
				var anno = pageAnnos[a];
				var k = this.internal.scaleFactor;
				var pageHeight = this.internal.pageSize.height;
				var rect = "/Rect [" + this.annotationPlugin.f2(anno.x * k) + " " + this.annotationPlugin.f2((pageHeight - anno.y) * k) + " " + this.annotationPlugin.f2(anno.x + anno.w * k) + " " + this.annotationPlugin.f2(pageHeight - (anno.y + anno.h) * k) + "] ";
				if (anno.options.url) {
					this.internal.write('<</Type /Annot /Subtype /Link ' + rect + '/Border [0 0 0] /A <</S /URI /URI (' + anno.options.url + ') >> >>')
				} else if (anno.options.pageNumber) {
					// first page is 0
					this.internal.write('<</Type /Annot /Subtype /Link ' + rect + '/Border [0 0 0] /Dest [' + (anno.options.pageNumber - 1) + ' /XYZ 0 ' + pageHeight + ' 0] >>')
				} else {
					// TODO error - should not be here
				}
			}
			this.internal.write("]");
		});
	};

	/**
	 * An array of arrays, indexed by <em>pageNumber</em>.
	 */
	// this.internal.annotations = [];
	/**
	 * valid options
	 * <li> pageNumber or url [required]
	 */
	jsPDFAPI.link = function(x,y,w,h,options) {
		'use strict';
		this.annotationPlugin.annotations[this.internal.getNumberOfPages()].push({
			x : x,
			y : y,
			w : w,
			h : h,
			options : options,
			type : 'link'
		});
	};

	/**
{'fraction_non_alphanumeric': 0.16231977968572817, 'fraction_numerical': 0.007451806253037421, 'mean_word_length': 2.9526248399487836, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '4198341', 'n_tokens_mistral': 2362, 'n_tokens_neox': 2063, 'n_words': 556}