Skip to content

Commit 6e71351

Browse files
author
bastieneichenberger
committed
first commit
1 parent eaa07a3 commit 6e71351

File tree

7 files changed

+108
-3
lines changed

7 files changed

+108
-3
lines changed

lib/helper/config/constants.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/** * Module with constants * @namespace Constants * @memberOf H * @author Bastien Eichenberger */H.Constants = (function (my) { /** * Object with constants * @private * @memberOf PS.Constants * @type {Object} * @property {String} MY_CONST * @property {Number} MY_INTEGER */ var MY_CONSTANTS = { 'MY_CONST': 'hello constante', 'MY_INTEGER': 1 }; /** * Function to get a constant * @function get * @memberOf PS.Constants * @param {string} name * @returns {*} */ my.get = function (name) { return MY_CONSTANTS[name]; } return my;})(H.Constants || {});
1+
/** * Module with constants * @namespace Constants * @memberOf H * @author Bastien Eichenberger */H.Constants = (function (my) { /** * Object with constants * @private * @memberOf PS.Constants * @type {Object} * @property {String} MY_CONST * @property {Number} MY_INTEGER */ var MY_CONSTANTS = { MY_CONST: 'hello constante', MY_INTEGER: 1 }; /** * Function to get a constant * @function get * @memberOf PS.Constants * @param {string} name * @returns {*} */ my.get = function (name) { return MY_CONSTANTS[name]; } return my;})(H.Constants || {});

lib/indesign/document/document.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/** * Module with indesign document functions * @namespace Document * @memberOf IN * @author Bastien Eichenberger */IN.Document = (function (my) { /** * Function to create a new document * @param {number} width the document width * @param {number} height the document height * @returns {number} the document with the specified index */ my.create = function (width, height) { return doc = app.documents.add({ documentPreferences: { pageWidth:width, pageHeight:height } }); } /** * Function to close the active InDesign document or the document passed as parameter * @function close * @memberOf IN.Document * @param {SaveOptions} save_options NO, ASK, YES * @param {InDesign Document} [document] the document to save */ my.close = function (save_options, document) { if (document === undefined) { var document = app.activeDocument; } if (save_options !== SaveOptions.NO && save_options !== SaveOptions.ASK && save_options !== SaveOptions.YES) { throw { name: 'InvalidArgumentError', message: 'you must enter a valid value for the param save_option [NO, ASK, YES]', fileName: $.fileName, lineNumber: $.line }; } document.close(save_options); } /** * Function who return true if one link is out of date * @function out_of_date_link * @memberOf IN.Document * @param {Document} document the indesign document * @return {Boolean} true if a link is out of date */ my.out_of_date_link = function (document) { for (var i = 0; i < document.links.length; i++) { var current_link = document.links[i]; if (current_link.status === LinkStatus.LINK_OUT_OF_DATE) { return true; } } return false; } /** * Function who return true if one link is missing * @function is_missing_link * @memberOf IN.Document * @param {Document} document the indesign document * @return {Boolean} true if a link is missing */ my.is_missing_link = function (document) { for (var i = 0; i < document.links.length; i++) { var current_link = document.links[i]; if (current_link.status === LinkStatus.LINK_MISSING) { return true; } } return false; } /** * Function who package a document and its links * @function save_with_package * @memberOf IN.Document * @param {Document} document the indesign document * @param {String} directories_path_str the path where to store the new document * @returns {String} the path of the new document * @throws {Error} if an error occurred during the package for print */ my.save_with_package = function (document, directories_path_str) { var current_date = new Date(); var folder_package = new Folder(directories_path_str); if (folder_package.exists === false) { folder_package.create(); } var doc_file = document.fullName; var current_folder = new Folder(folder_package + "/" + current_date.year_month_day() + "_" + current_date.hours_minutes_seconds()); current_folder.create(); /** * bool packageForPrint (to: File, copyingFonts: bool, copyingLinkedGraphics: bool, copyingProfiles: bool, updatingGraphics: bool, * includingHiddenLayers: bool, ignorePreflightErrors: bool, creatingReport: bool[, versionComments: string][, forceSave: bool=false]) */ var result_package = document.packageForPrint(current_folder, false, true, false, true, false, true, false); if (!result_package) { throw new Error("il y a eu un problème lors de l'assemblage"); } return current_folder + "/" + document.name; } /** * Function to check if the same file is used many times (image, PDF) * @function is_link_used_many_time * @memberOf IN.Document * @param {Document} document the indesign document * @param {Link} link_item the link item * @return {number} The number of time that the link is used */ my.is_link_used_many_time = function (document, link_item) { var array_all_links = document.links; var counter = 0; for (var i = 0; i < array_all_links.length; i++) { var current_link = array_all_links[i]; if (link_item.filePath === current_link.filePath) { counter++; } } return counter; } /** * Function to export an InDesign document as PDF * @function export_as_PDF * @memberOf IN.Document * @param {Document} document the document to export * @param {string} file_path the file path of the PDF * @param {string } preset_name the name of the PDF export preset * @param {InDesign Document} [document] the document to export * @throws {InvalidArgumentError} */ my.export_as_PDF = function (file_path, preset_name, document) { if (document === undefined) { var document = app.activeDocument; } var my_file = new File(file_path); var export_preset = app.pdfExportPresets.item(preset_name); if (!export_preset.isValid) { throw { name: 'InvalidArgumentError', message: 'The argument preset_name ' + preset_name + ' does not exist', fileName: $.fileName, lineNumber: $.line }; } document.exportFile(ExportFormat.pdfType, my_file, false, export_preset); } /** * Function to export an InDesign document as PDF * @function export_as_JPG * @memberOf IN.Document * @param {string} file_path the file path of the PDF * @param {JPEGOptionsQuality} quality [HIGH, LOW, MEDIUM, MAXIMUM] * @param {number} resolution the resolution of the JPEG * @param {InDesign Document} [document] the document to export */ my.export_as_JPG = function (file_path, quality, resolution, document) { if (document === undefined) { var document = app.activeDocument; } var my_file = new File(file_path); app.jpegExportPreferences.jpegQuality = quality // low medium high maximum app.jpegExportPreferences.exportResolution = resolution; app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.EXPORT_ALL; document.exportFile(ExportFormat.JPG, my_file, false); } return my;})(IN.Document || {});
1+
/** * Module with indesign document functions * @namespace Document * @memberOf IN * @author Bastien Eichenberger */IN.Document = (function (my) { /** * Function to create a new document * @param {number} width the document width * @param {number} height the document height * @returns {number} the document with the specified index */ my.create = function (width, height) { return doc = app.documents.add({ documentPreferences: { pageWidth: width, pageHeight: height } }); } /** * Function to close the active InDesign document or the document passed as parameter * @function close * @memberOf IN.Document * @param {SaveOptions} save_options NO, ASK, YES * @param {InDesign Document} [document] the document to save */ my.close = function (save_options, document) { if (document === undefined) { var document = app.activeDocument; } if (save_options !== SaveOptions.NO && save_options !== SaveOptions.ASK && save_options !== SaveOptions.YES) { throw { name: 'InvalidArgumentError', message: 'you must enter a valid value for the param save_option [NO, ASK, YES]', fileName: $.fileName, lineNumber: $.line }; } document.close(save_options); } /** * @todo */ my.add_page = function () { } /** * Function who return true if one link is out of date * @function out_of_date_link * @memberOf IN.Document * @param {Document} document the indesign document * @return {Boolean} true if a link is out of date */ my.out_of_date_link = function (document) { for (var i = 0; i < document.links.length; i++) { var current_link = document.links[i]; if (current_link.status === LinkStatus.LINK_OUT_OF_DATE) { return true; } } return false; } /** * Function who return true if one link is missing * @function is_missing_link * @memberOf IN.Document * @param {Document} document the indesign document * @return {Boolean} true if a link is missing */ my.is_missing_link = function (document) { for (var i = 0; i < document.links.length; i++) { var current_link = document.links[i]; if (current_link.status === LinkStatus.LINK_MISSING) { return true; } } return false; } /** * Function who package a document and its links * @function save_with_package * @memberOf IN.Document * @param {Document} document the indesign document * @param {String} directories_path_str the path where to store the new document * @returns {String} the path of the new document * @throws {Error} if an error occurred during the package for print */ my.save_with_package = function (document, directories_path_str) { var current_date = new Date(); var folder_package = new Folder(directories_path_str); if (folder_package.exists === false) { folder_package.create(); } var doc_file = document.fullName; var current_folder = new Folder(folder_package + "/" + current_date.year_month_day() + "_" + current_date.hours_minutes_seconds()); current_folder.create(); /** * bool packageForPrint (to: File, copyingFonts: bool, copyingLinkedGraphics: bool, copyingProfiles: bool, updatingGraphics: bool, * includingHiddenLayers: bool, ignorePreflightErrors: bool, creatingReport: bool[, versionComments: string][, forceSave: bool=false]) */ var result_package = document.packageForPrint(current_folder, false, true, false, true, false, true, false); if (!result_package) { throw new Error("il y a eu un problème lors de l'assemblage"); } return current_folder + "/" + document.name; } /** * Function to check if the same file is used many times (image, PDF) * @function is_link_used_many_time * @memberOf IN.Document * @param {Document} document the indesign document * @param {Link} link_item the link item * @return {number} The number of time that the link is used */ my.is_link_used_many_time = function (document, link_item) { var array_all_links = document.links; var counter = 0; for (var i = 0; i < array_all_links.length; i++) { var current_link = array_all_links[i]; if (link_item.filePath === current_link.filePath) { counter++; } } return counter; } /** * Function to export an InDesign document as PDF * @function export_as_PDF * @memberOf IN.Document * @param {Document} document the document to export * @param {string} file_path the file path of the PDF * @param {string } preset_name the name of the PDF export preset * @param {string} [page_range] the page range * @example * export page from 1-10 -> '1-10' * export page from 1-2, 4-6 -> '1-2, 4-6' * export all pages -> PageRange.ALL_PAGES * @param {InDesign Document} [document] the document to export * @throws {InvalidArgumentError} */ my.export_as_PDF = function (file_path, preset_name, page_range, document) { if (page_range === undefined) { var page_range = PageRange.ALL_PAGES; } if (document === undefined) { var document = app.activeDocument; } var my_file = new File(file_path); var export_preset = app.pdfExportPresets.item(preset_name); if (!export_preset.isValid) { throw { name: 'InvalidArgumentError', message: 'The argument preset_name ' + preset_name + ' does not exist', fileName: $.fileName, line: $.line }; } app.pdfExportPreferences.pageRange = page_range; document.exportFile(ExportFormat.pdfType, my_file, false, export_preset); } /** * Function to export an InDesign document as PDF * @function export_as_JPG * @memberOf IN.Document * @param {string} file_path the file path of the PDF * @param {JPEGOptionsQuality} quality [HIGH, LOW, MEDIUM, MAXIMUM] * @param {number} resolution the resolution of the JPEG * @param {InDesign Document} [document] the document to export * @todo add export page range function! */ my.export_as_JPG = function (file_path, quality, resolution, document) { if (document === undefined) { var document = app.activeDocument; } var my_file = new File(file_path); app.jpegExportPreferences.jpegQuality = quality // low medium high maximum app.jpegExportPreferences.exportResolution = resolution; app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.EXPORT_ALL; document.exportFile(ExportFormat.JPG, my_file, false); } return my;})(IN.Document || {});

lib/indesign/document/grep.jsx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Module with indesign grep functions
3+
* @namespace Document.Grep
4+
* @memberOf IN
5+
* @author Bastien Eichenberger
6+
*/
7+
IN.Document.Grep = (function (my) {
8+
9+
var PATTERNS = {
10+
ALL_DOUBLE_SPACES: '\s{2,}' // select all spaces when 2-n spaces detected, do not forget to escape backslash
11+
};
12+
13+
var UNICODE_HEXA = {
14+
NORMAL_SPACE: 0020,
15+
NONBREAKABLE_SPACE: '00A0',
16+
NONBREAKABLE_SPACE_FIXED_WITH: '202F',
17+
PUNCTUATION_SPACE: '2008',
18+
FIGURE_SPACE: '2007',
19+
FLUSH_SPACE: '2001',
20+
HAIR_SPACE: '200A',
21+
THIN_SPACE: '2009',
22+
QUARTER_SPACE: '2005',
23+
SIXTH_SPACE: '2006',
24+
THIRD_SPACE: '2004',
25+
EN_SPACE: '2002',
26+
EM_SPACE: '2003',
27+
};
28+
29+
var NON_PRINTABLE_CHAR = {
30+
TABULATION: '\t',
31+
LINE_BREAK: '\n',
32+
ALL_OTHER_BREAK: '\r'
33+
};
34+
35+
/**
36+
* Function to find a regular expression in a document
37+
* @param {string} regular_expression
38+
* @param {InDesign Document} doc
39+
* @returns {Array} the result that match the pattern
40+
*/
41+
my.find = function (regular_expression, doc) {
42+
43+
if (doc === undefined) {
44+
var doc = app.activeDocument;
45+
}
46+
47+
app.findGrepPreferences = NothingEnum.nothing;
48+
app.findGrepPreferences.findWhat = regular_expression;
49+
50+
return doc.findGrep();
51+
}
52+
53+
my.find_and_change = function (find, replace, find_grep_preferences, doc) {
54+
55+
if (doc === undefined) {
56+
var doc = app.activeDocument;
57+
}
58+
59+
app.findGrepPreferences = NothingEnum.nothing;
60+
app.findGrepPreferences.findWhat = find;
61+
app.changeGrepPreferences.changeTo = replace;
62+
63+
return doc.changeGrep();
64+
}
65+
66+
my.delete_double_standard_spaces = function (string, doc) {
67+
68+
if (doc === undefined) {
69+
var doc = app.activeDocument;
70+
}
71+
var pattern = '\x{' + UNICODE_HEXA.NORMAL_SPACE + '}{2,}';
72+
return my.find_and_change(pattern, UNICODE_HEXA.NORMAL_SPACE, doc);
73+
}
74+
75+
my.get = function (name) {
76+
return REGEX[name];
77+
}
78+
79+
return my;
80+
81+
})(IN.Document.Grep || {});

tests/test/fixtures/helper/log/test_log.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
(function (log_folder) {
22

33
try {
4+
/**
5+
* @todo the result log folder to results/log
6+
*/
47

58
//@include "../../../../../lib/helper/helper-lib.jsx"
69
H.Config.init();
2.1 MB
Binary file not shown.

tests/test/fixtures/indesign/document/test_document.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
IN.Document.create(100, 200);
88

9-
IN.Document.export_as_PDF(results_folder + '/test.pdf', '[PDF/X-4:2008]');
9+
IN.Document.export_as_PDF(results_folder + '/test.pdf', '[PDF/X-4:2008]', '1-1');
1010

1111
IN.Document.export_as_JPG(results_folder + '/test_jpg_indesign.jpg', JPEGOptionsQuality.MEDIUM, 72);
1212

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(function (xml_file_path, results_folder) {
2+
3+
try {
4+
//@include "../../../../../lib/indesign/indesign-lib.jsx"
5+
IN.Config.init();
6+
/**
7+
* @todo test the grep_document.indd file then compare with expectedd file
8+
*/
9+
10+
11+
12+
}
13+
catch (ex) {
14+
alert('file: ' + ex.fileName + '\n message: ' + ex.message + '\n line: ' + ex.line);
15+
}
16+
finally {
17+
IN.Application.restore();
18+
}
19+
20+
21+
}).apply(this, [].slice.apply(this.arguments));

0 commit comments

Comments
 (0)