-
Notifications
You must be signed in to change notification settings - Fork 6
Styles
fabiantheblind edited this page Sep 29, 2012
·
1 revision
###Styles
Style your text. This scriptfile needs to be saved to work.
/**
* With styles you can controll your text
*/
// a function
// this script has to be saved somewhere
// or this wont work
main();
function main(){
// make a doc
var pw = 210;
var ph = 500;
var doc = app.documents.add({
documentPreferences:{
pageWidth:pw,pageHeight:ph
}
});
// build a style with nested grep styles
var code = build_code_paragraphStyle (doc);
// get the page
var page = doc.pages[0];
// make a frame
var tf = page.textFrames.add({geometricBounds:[10,10,ph-10,pw-10]});
// load the content of the script
var scriptfile = File($.fileName);
alert(scriptfile);
var content;
if(scriptfile != false){
scriptfile.open('r');
content = scriptfile.read();
}else{
alert("Bah!");
}
// add the content to the frame
tf.contents = content;
scriptfile.close(); // always close files after reading
// apply the style
tf.paragraphs.everyItem().appliedParagraphStyle = code;
}
// build a lot of styles
function build_code_paragraphStyle(d){
var charStyles = new Array();
var keywords = d.characterStyles.add({name:"keywords",fillColor:d.swatches.item(5)});
var comments = d.characterStyles.add({name:"comments",fillColor:d.swatches.item(3),fillTint: 70});
var operators = d.characterStyles.add({name:"operators",fillColor:d.swatches.item(7)});
var separators = d.characterStyles.add({name:"separators",fillColor:d.swatches.item(8)});
var numbers = d.characterStyles.add({name:"numbers",fillColor:d.swatches.item(9)});
var comment = d.characterStyles.add({name:"comment",fillColor:d.swatches.item(9)});
var string = d.characterStyles.add({name:"strings",fillColor:d.swatches.item(5)});
var code = d.paragraphStyles.add({name:"code",appliedFont:"Andale Mono",pointSize:10});
//change language (only in the paragraphStyle) to get the right "" for the code
code.appliedLanguage = app.languagesWithVendors.item("English: USA");
// do some nested grep styles
var grp = code.nestedGrepStyles.add();
grp.appliedCharacterStyle = keywords;
grp.grepExpression = "abstract|boolean|break|byte|case|catch|char\ |class|const|continue|debugger|default|delete|do\ |double|else|enum|export|extends|false|final|finally|float|for|function|goto|if|implements|import|in\ |instanceof|int\ |interface|long|native|new|n ull|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|var|void|volatile|wh ile|with";
grp = code.nestedGrepStyles.add();
grp.appliedCharacterStyle = operators;
grp.grepExpression = "is|new|sizeof|typeof";
grp = code.nestedGrepStyles.add();
grp.appliedCharacterStyle = operators;
grp.grepExpression = "[-~\\[\\]!$%&*+/:<=>?^|]+";
grp = code.nestedGrepStyles.add();
grp.appliedCharacterStyle = separators;
grp.grepExpression = "[(){},;\\s]+";
grp = code.nestedGrepStyles.add();
grp.appliedCharacterStyle = numbers;
grp.grepExpression = "\\<[0-9]+(\\.[0-9]+)?([eE][-+]?[0-9]+)?";
grp = code.nestedGrepStyles.add();
grp.appliedCharacterStyle = comments;
grp.grepExpression = "/\\*+[^*]*\\*+([^/*][^*]*\\*+)*/";
grp = code.nestedGrepStyles.add();
grp.appliedCharacterStyle = comment;
grp.grepExpression = "//.*";
grp = code.nestedGrepStyles.add();
grp.appliedCharacterStyle = string;
grp.grepExpression = "\".*?\"";
return code;
}
This wiki is maintained by:
fabiantheblind
Collaborators:
- How To Install And Run Scripts
- References And Links
- Tools
- First Session
- Comments
- Extended JavaScript Guide
- Variables And Operations
- Conditionals
- Arrays
- Output And Interaction
- Objects
- Classes
- Loops
- Functions
- Recursive Functions
- The ID Scripting DOM
- ExtendScript
- Inspect Properties
- app
- Documents
- Pages And Margins
- Masterspreads
- Layers
- GeometricBounds and Coordinates
- Text
- Line Feeds And Carrige Returns
- Simple Find And Change Grep
- Simple Find And Change Text
- Text Analysis
- Text Analysis ID FC
- Text Find Locations
- InsertionPoints
- Styles
- Objectstyles
- Rectangles Ovals Polygons
- Matrix
- Outlines Groups Alignment
- Graphic Lines
- Spiro
- Colors And Swatches
- HSL Color Wheel
- Pathfinder
- Fonts
- Transformation Matricies
- Duplicate And Transform
- Includes
- Storing Data In A Target Engine
- Create And Read Files
- Read In JSON From File And Eval
- Delay And View
- ScriptUI Resource Strings