diff --git a/Polyfill/prototypes.js b/Polyfill/prototypes.js index 129eaf6..786a832 100644 --- a/Polyfill/prototypes.js +++ b/Polyfill/prototypes.js @@ -1,28 +1,28 @@ -/* +/* false */ - String.prototype.trim = function () { - return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); + return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""); }; String.prototype.startsWith = function (sub) { - if (typeof sub !== "string") throwError("Parameter in startsWith is not a string", sub) - return !sub.length || this.indexOf(sub) === 0 + if (typeof sub !== "string") + throwError("Parameter in startsWith is not a string", sub); + return !sub.length || this.indexOf(sub) === 0; }; String.prototype.endsWith = function (sub) { - if (typeof sub !== "string") throwError("Parameter in endsWith is not a string", sub) - return !sub.length || this.slice(this.length - sub.length).indexOf(sub) === 0 + if (typeof sub !== "string") + throwError("Parameter in endsWith is not a string", sub); + return !sub.length || this.slice(this.length - sub.length).indexOf(sub) === 0; }; String.prototype.endsWithArray = function (subArray) { for (i in subArray) { - if (this.endsWith(subArray[i])) - return true; + if (this.endsWith(subArray[i])) return true; } return false; }; @@ -36,21 +36,21 @@ String.prototype.endsWithArray = function (subArray) { // } Array.isArray = function (arg) { - return Object.prototype.toString.call(arg) === '[object Array]'; + return Object.prototype.toString.call(arg) === "[object Array]"; }; -Object.prototype.keys = function () { - const arr = [] - for (k in this) - if (this.hasOwnProperty(k)) - arr.push(k) - return arr -} - -Object.prototype.copy = function () { - const copy = Array.isArray(this) ? [] : {} - for (k in this) - if (this.hasOwnProperty(k)) - copy[k] = this[k] - return copy -} \ No newline at end of file +// Object.prototype.keys = function () { +// const arr = [] +// for (k in this) +// if (this.hasOwnProperty(k)) +// arr.push(k) +// return arr +// } + +// Object.prototype.copy = function () { +// const copy = Array.isArray(this) ? [] : {} +// for (k in this) +// if (this.hasOwnProperty(k)) +// copy[k] = this[k] +// return copy +// } diff --git a/README.md b/README.md index 3a140df..96558e7 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,75 @@ # Layer Format Object + This can be used in `defaultTextFormat`, `customTextFormats`, `starterLayerFormats` and `groupLayer` properties from the configuration file. ### Common Properties + Can be used in any properties from the configuration file. -| Property | Type | Description | +| Property | Type | Description | | :------------ |:---------------:| :-----| | name | string | The layer name. | -| visible | boolean | If the layer will be visible or not. | -| allLocked | boolean | Completely block settings and contents of the layer. Will deactivate all 3 below. | -| transparentPixelsLocked | boolean | Edit only opaque portions of the layer. | -| pixelsLocked | boolean | Pixels can't be edited (with a Paint Brush for example). | -| positionLocked | boolean | Layer can't be moved. | -| border | string | Not yet implemented | +| visible | boolean | If the layer will be visible or not. | +| allLocked | boolean | Completely block settings and contents of the layer. Will deactivate all 3 below. | +| transparentPixelsLocked | boolean | Edit only opaque portions of the layer. | +| pixelsLocked | boolean | Pixels can't be edited (with a Paint Brush for example). | +| positionLocked | boolean | Layer can't be moved. | +| border | string | Not yet implemented | ### Text Properties + Can only be used in `defaultTextFormat` and `customTextFormats` from the configuration file. -| Property | Type | Description | +| Property | Type | Description | | :------------ |:---------------:| :-----| -| identifierStart | string | Can only be used in `customTextFormats` and is **Obrigatory**. Identifies the type of formatting to use in a line of text. Will be ignored if `ignoreCustomWith` identifier was found before this. | +| identifierStart | string | Can only be used in `customTextFormats` and is **Obligatory**. Identifies the type of formatting to use in a line of text. Will be ignored if `ignoreCustomWith` identifier was found before this. | | size | integer | Font size. | -| font | string | Font name. | -| justification | string | Text justification. See [Documentation](#Documentation) for options. | -| language | string | Text language, useful for auto-wrapping. See [Documentation](#Documentation) for options. | -| boxText | boolean | If true, a TextBox will be used instead of a PointText. | - +| font | string | Font name. | +| justification | string | Text justification. See [Documentation](#Documentation) for options. | +| language | string | Text language, useful for auto-wrapping. See [Documentation](#Documentation) for options. | +| boxText | boolean | If true, a TextBox will be used instead of a PointText. | ### Starter Layer Properties + Can only be used in `starterLayerFormats` from the configuration file. -| Property | Type | Description | +| Property | Type | Description | | :------------ |:---------------:| :-----| | duplicate | boolean | Is a duplicate from layer below. Can only be used from the 2 layer. | -| isBackgroundLayer | boolean | Turn this layer the background layer. Will override a lot of configurations. | - - - - +| isBackgroundLayer | boolean | Turn this layer the background layer. Will override a lot of configurations. | # Configuration File + This is a commented configuration file as example. **But remember, `.JSON` files CAN'T have comments.** ```javascript { // These 3 Configurations determine how we will identify // a new 'page' in your .txt file: - - identifierStart: "[", + + identifierStart: "[", identifierEnd: "]", - ignorePageNumber: false, // This will ignore the number inside indentifiers + ignorePageNumber: false, // This will ignore the number inside identifiers // This example will identify lines like: // [1] - // [02] + // [02] // [ 30 ] // And will try to find files like // "01.png", "2.psd", "30.jpeg" to insert this text into - - + + "prioritizePSD": false, // Prioritize '.psd' and '.psb' over the other files // If have ambiguous files selected like "01.png" and "1.psd" // There is a order of priorities, that is: // '.psd', '.psb', '.png', '.jpg', '.jpeg' OR // '.png', '.jpg', '.jpeg', '.psd', '.psb' - - + + selectAllFiles: false, // With this, you select every file manually, rather than a folder alwaysCreateGroup: false, // With this, it will always create a folder named by 'groupLayer.name' below - + groupLayer: { name: "Types", // Folder name visible: false, // Visibility of the layer }, - + defaultTextFormat: { size: 16, // Font size font: "CCWildWordsInt Regular", // Font name @@ -78,16 +78,16 @@ This is a commented configuration file as example. **But remember, `.JSON` files visible: true, // Visibility of the layer language: "BRAZILLIANPORTUGUESE", // Language }, - - - + + + ignoreCustomWith: ".", // Lines starting with this, will always be formatted as default - + customTextFormats: [ // You can Add as much 'Layer Format Object's as you want { // Necessary: identifier_Start: "#", // Lines starting with this, will be formatted as following - + // Optional: // Everything not included will be formatted as in default size: 12, @@ -98,15 +98,12 @@ This is a commented configuration file as example. **But remember, `.JSON` files } ``` - - # Documentation - - This program was made using [Adobe Photoshop 2020 Scripting](https://www.adobe.com/devnet/photoshop/scripting.html) and the javascript documentation can be found there. Justification Options: + - CENTER - CENTERJUSTIFIED - FULLYJUSTIFIED @@ -116,6 +113,7 @@ Justification Options: - RIGHTJUSTIFIED Language Options: + - BRAZILLIANPORTUGUESE - CANADIANFRENCH - DANISH diff --git a/textToLayers.js b/textToLayers.js index 5531de4..5613d4f 100644 --- a/textToLayers.js +++ b/textToLayers.js @@ -1,4 +1,4 @@ -/* +/* AutoTypeSetting A program that automatically inputs text from files @@ -145,7 +145,7 @@ function processText(arrayFiles) { applyStarterLayerFormats() //? Getting the first valid key of 'content' - insertPageTexts(content[content.keys()[0]]) + insertPageTexts(content[getKeys(content)[0]]) } } @@ -244,14 +244,6 @@ function applyStarterLayerFormats() { - - - - - - - - function isNaN(p) { return p !== p } @@ -274,8 +266,8 @@ function isEqualObjects(obj, sec) { typeof (obj) != 'object' || typeof (sec) != 'object')) throwError("\nTypeError: equalObjects received non-objects") - const objKeys = obj.keys() - const secKeys = sec.keys() + const objKeys = getKeys(obj) + const secKeys = getKeys(sec) // alert("Objects:\n" + objKeys + "\n" + secKeys) @@ -328,7 +320,22 @@ function isEqualObjects(obj, sec) { +function getKeys(obj){ + const arr = [] + for (k in obj) + if (obj.hasOwnProperty(k)) + arr.push(k) + return arr +} + +function getCopy(obj){ + const copy = Array.isArray(obj) ? [] : {} + for (k in obj) + if (obj.hasOwnProperty(k)) + copy[k] = obj[k] + return copy +} function getFileFromScriptPath(filename) { return new File((new File($.fileName)).path + "/" + encodeURI(filename)) @@ -360,7 +367,7 @@ function getIndexOf(arr, item) { function getFont(fontName) { //? Loop through every font for (i = 0; i < app.fonts.length; i++) - //? search a font with the name including 'fontName' + //? search a font with the name including 'fontName' if (app.fonts[i].name.indexOf(fontName) > -1) return app.fonts[i] //? else return "Arial" by default @@ -401,8 +408,10 @@ function getConfig() { //* Setting 'config' if (defaultConfig === undefined) { throwError("Default Configuration Missing.\nYou can get another one for free on https://github.com/krevlinmen/PhotoshopScanlatingScripts") - } else { - config = (savedConfig === undefined ? defaultConfig : savedConfig).copy() + + } + else { + config = getCopy(savedConfig === undefined ? defaultConfig : savedConfig) } //* Asserting Integrity @@ -423,7 +432,7 @@ function getConfig() { if (configBuffer[i] === undefined) throwError("Necessary configuration missing: " + i) if (isNotUndef(necConfigs[i])) { - var newArrayI = arrayI.copy() + var newArrayI = getCopy(arrayI) newArrayI.push(i) assertIntegrity(necConfigs[i], newArrayI) } @@ -669,9 +678,9 @@ function calculatePositions(textArray) { for (i in textArray) { layerPosition.height = (config.defaultTextFormat.size * 1.1) * Math.ceil(textArray[i].length / (layerPosition.width / (6 * config.defaultTextFormat.size / 7))) //! Attention - positionData.push(layerPosition.copy()) + positionData.push(getCopy(layerPosition)) - layerPosition.yPosition += yBorder + layerPosition.height //*yPosition += The size of the text Box + border + layerPosition.yPosition += yBorder + layerPosition.height //*yPosition += The size of the text Box + border if (layerPosition.yPosition >= activeDocument.height) { //*if the bottom of the file is reached layerPosition.yPosition = yBorder //*Reset yPosition @@ -715,7 +724,7 @@ function calculatePositions(textArray) { function createProgressBarObj() { /* - Code for Import https://scriptui.joon as.me — (Triple click to select): + Code for Import https://scriptui.joon as.me — (Triple click to select): {"activeId":0,"items":{"item-0":{"id":0,"type":"Dialog","parentId":false,"style":{"enabled":true,"varName":null,"windowType":"Window","creationProps":{"su1PanelCoordinates":false,"maximizeButton":false,"minimizeButton":false,"independent":false,"closeButton":true,"borderless":false,"resizeable":false},"text":"Processing files","preferredSize":[0,0],"margins":16,"orientation":"column","spacing":10,"alignChildren":["center","top"]}},"item-1":{"id":1,"type":"Progressbar","parentId":0,"style":{"enabled":true,"varName":"","preferredSize":[50,4],"alignment":"fill","helpTip":null}},"item-2":{"id":2,"type":"Divider","parentId":0,"style":{"enabled":true,"varName":null}},"item-3":{"id":3,"type":"Button","parentId":0,"style":{"enabled":true,"varName":"cancelButton","text":"Cancel","justify":"center","preferredSize":[0,0],"alignment":"right","helpTip":null}}},"order":[0,1,2,3],"settings":{"importJSON":true,"indentSize":false,"cepExport":false,"includeCSSJS":true,"showDialog":true,"functionWrapper":false,"afterEffectsDockable":false,"itemReferenceList":"None"}} */ @@ -778,7 +787,7 @@ function formatProgressBarObj(progressBar,imgDir){ function createUserInterface() { /* - Code for Import https://scriptui.joonas.me — (Triple click to select): + Code for Import https://scriptui.joonas.me — (Triple click to select): {"activeId":50,"items":{"item-0":{"id":0,"type":"Dialog","parentId":false,"style":{"text":"Auto TypeSetter","preferredSize":[0,0],"margins":16,"orientation":"row","spacing":10,"alignChildren":["left","top"],"varName":"win","windowType":"Dialog","creationProps":{"su1PanelCoordinates":false,"maximizeButton":false,"minimizeButton":false,"independent":false,"closeButton":true,"borderless":false,"resizeable":false},"enabled":true}},"item-1":{"id":1,"type":"Panel","parentId":20,"style":{"text":"Page Indentifiers","preferredSize":[0,0],"margins":10,"orientation":"column","spacing":10,"alignChildren":["left","top"],"alignment":null,"varName":null,"creationProps":{"borderStyle":"etched","su1PanelCoordinates":false},"enabled":true}},"item-4":{"id":4,"type":"StaticText","parentId":6,"style":{"text":"Start","justify":"left","preferredSize":[0,0],"alignment":null,"varName":null,"helpTip":null,"softWrap":true,"creationProps":{"truncate":"none","multiline":false,"scrolling":false},"enabled":true}},"item-5":{"id":5,"type":"EditText","parentId":6,"style":{"text":"[","preferredSize":[60,0],"alignment":null,"varName":"identifierStartBox","helpTip":null,"softWrap":false,"creationProps":{"noecho":false,"readonly":false,"multiline":false,"scrollable":false,"borderless":false,"enterKeySignalsOnChange":false},"enabled":true,"justify":"left"}},"item-6":{"id":6,"type":"Group","parentId":1,"style":{"preferredSize":[0,0],"margins":0,"orientation":"row","spacing":10,"alignChildren":["right","center"],"alignment":"center","varName":null,"enabled":true}},"item-9":{"id":9,"type":"Panel","parentId":20,"style":{"text":"Configuration","preferredSize":[0,0],"margins":10,"orientation":"column","spacing":10,"alignChildren":["left","top"],"alignment":null,"varName":null,"creationProps":{"borderStyle":"etched","su1PanelCoordinates":false},"enabled":true}},"item-19":{"id":19,"type":"Group","parentId":0,"style":{"preferredSize":[0,0],"margins":0,"orientation":"column","spacing":10,"alignChildren":["fill","top"],"alignment":null,"varName":null,"enabled":true}},"item-20":{"id":20,"type":"Group","parentId":0,"style":{"preferredSize":[0,0],"margins":0,"orientation":"column","spacing":10,"alignChildren":["fill","top"],"alignment":null,"varName":null,"enabled":true}},"item-21":{"id":21,"type":"Panel","parentId":19,"style":{"text":"Files","preferredSize":[0,0],"margins":10,"orientation":"column","spacing":10,"alignChildren":["fill","top"],"alignment":null,"varName":null,"creationProps":{"borderStyle":"etched","su1PanelCoordinates":false},"enabled":true}},"item-22":{"id":22,"type":"StaticText","parentId":21,"style":{"text":"Select a Folder including:\n- A '.txt' file containing the text\n- Image Files ('1.png', '2.jpg')\n\n(if you don't select images, \nthe script will run on a open\ndocument)","justify":"left","preferredSize":[0,0],"alignment":null,"varName":null,"helpTip":null,"softWrap":true,"creationProps":{"truncate":"none","multiline":false,"scrolling":false},"enabled":true}},"item-36":{"id":36,"type":"Group","parentId":0,"style":{"preferredSize":[0,0],"margins":0,"orientation":"column","spacing":10,"alignChildren":["fill","top"],"alignment":null,"varName":null,"enabled":true}},"item-37":{"id":37,"type":"Button","parentId":36,"style":{"text":"OK","justify":"center","preferredSize":[0,0],"alignment":null,"varName":"confirmBtn","helpTip":null,"enabled":false}},"item-38":{"id":38,"type":"Button","parentId":36,"style":{"text":"Cancel","justify":"center","preferredSize":[0,0],"alignment":null,"varName":"cancelBtn","helpTip":null,"enabled":true}},"item-40":{"id":40,"type":"Checkbox","parentId":1,"style":{"text":"Ignore Page Number","preferredSize":[0,0],"alignment":null,"varName":"ignorePageNumberCB","helpTip":"This will ignore or not numbers between both identifiers","enabled":true,"checked":false}},"item-45":{"id":45,"type":"Group","parentId":1,"style":{"preferredSize":[0,0],"margins":0,"orientation":"row","spacing":10,"alignChildren":["right","center"],"alignment":"center","varName":null,"enabled":true}},"item-46":{"id":46,"type":"StaticText","parentId":45,"style":{"text":"End","justify":"left","preferredSize":[0,0],"alignment":null,"varName":"","helpTip":null,"softWrap":true,"creationProps":{"truncate":"none","multiline":false,"scrolling":false},"enabled":true}},"item-47":{"id":47,"type":"EditText","parentId":45,"style":{"text":"]","preferredSize":[60,0],"alignment":null,"varName":"identifierEndBox","helpTip":null,"softWrap":false,"creationProps":{"noecho":false,"readonly":false,"multiline":false,"scrollable":false,"borderless":false,"enterKeySignalsOnChange":false},"enabled":true,"justify":"left"}},"item-48":{"id":48,"type":"Button","parentId":9,"style":{"enabled":true,"varName":"registerConfigBtn","text":"Register Config.","justify":"center","preferredSize":[0,0],"alignment":"fill","helpTip":"Select a JSON with your custom configuration to use! :D"}},"item-49":{"id":49,"type":"Button","parentId":9,"style":{"enabled":false,"varName":"resetConfigBtn","text":"Reset Config.","justify":"center","preferredSize":[0,0],"alignment":"fill","helpTip":"This will delete the JSON you registered"}},"item-50":{"id":50,"type":"Button","parentId":9,"style":{"enabled":true,"varName":"openFolderBtn","text":"Open Folder","justify":"center","preferredSize":[0,0],"alignment":"fill","helpTip":""}},"item-52":{"id":52,"type":"Checkbox","parentId":21,"style":{"enabled":true,"varName":"selectAllFilesCB","text":"Select All Files Instead","preferredSize":[0,0],"alignment":null,"helpTip":"You need to select all files, not a folder containing these files","checked":false}},"item-53":{"id":53,"type":"StaticText","parentId":21,"style":{"enabled":true,"varName":null,"creationProps":{"truncate":"none","multiline":false,"scrolling":false},"softWrap":true,"text":"Formats Supported","justify":"center","preferredSize":[0,0],"alignment":null,"helpTip":"'.png', '.jpeg', '.jpg', '.psd', '.psb'"}},"item-55":{"id":55,"type":"Button","parentId":21,"style":{"enabled":true,"varName":"selectFilesBtn","text":"Select","justify":"center","preferredSize":[0,0],"alignment":"center","helpTip":null}},"item-56":{"id":56,"type":"StaticText","parentId":19,"style":{"enabled":true,"varName":null,"creationProps":{"truncate":"none","multiline":false,"scrolling":false},"softWrap":true,"text":"Created By \nKrevlinMen and ImSamuka","justify":"left","preferredSize":[0,0],"alignment":null,"helpTip":null}},"item-57":{"id":57,"type":"Panel","parentId":20,"style":{"text":"Text Group","preferredSize":[0,0],"margins":10,"orientation":"column","spacing":10,"alignChildren":["left","top"],"alignment":null,"varName":null,"creationProps":{"borderStyle":"etched","su1PanelCoordinates":false},"enabled":true}},"item-58":{"id":58,"type":"Group","parentId":57,"style":{"preferredSize":[0,0],"margins":0,"orientation":"row","spacing":10,"alignChildren":["right","center"],"alignment":"fill","varName":null,"enabled":true}},"item-59":{"id":59,"type":"StaticText","parentId":58,"style":{"text":"Name","justify":"left","preferredSize":[0,0],"alignment":null,"varName":null,"helpTip":null,"softWrap":true,"creationProps":{"truncate":"none","multiline":false,"scrolling":false},"enabled":true}},"item-60":{"id":60,"type":"EditText","parentId":58,"style":{"text":"Type","preferredSize":[80,0],"alignment":null,"varName":"groupNameBox","helpTip":null,"softWrap":false,"creationProps":{"noecho":false,"readonly":false,"multiline":false,"scrollable":false,"borderless":false,"enterKeySignalsOnChange":false},"enabled":true,"justify":"left"}},"item-64":{"id":64,"type":"Checkbox","parentId":57,"style":{"text":"Visible","preferredSize":[0,0],"alignment":null,"varName":"visibleGroupCB","helpTip":"Set Layer to Visible","enabled":true}},"item-65":{"id":65,"type":"Checkbox","parentId":57,"style":{"text":"Always Create Group","preferredSize":[0,0],"alignment":null,"varName":"alwaysCreateGroupCB","helpTip":"Always create a new group, otherwise add text layers to an existing group","enabled":true}},"item-66":{"id":66,"type":"Button","parentId":9,"style":{"enabled":true,"varName":"saveConfigBtn","text":"Save Config.","justify":"center","preferredSize":[0,0],"alignment":"fill","helpTip":"Quick Save Current Configuration"}}},"order":[0,20,1,6,4,5,45,46,47,40,57,58,59,60,64,65,9,66,48,50,49,19,21,22,53,52,55,56,36,37,38],"settings":{"importJSON":true,"indentSize":false,"cepExport":false,"includeCSSJS":true,"functionWrapper":false,"compactCode":false,"showDialog":true,"afterEffectsDockable":false,"itemReferenceList":"var"}} */