//KerningVersuch1.jsx
var myObject;
var myCheckSelection = false;
if(app.documents.length != 0){
if(app.activeDocument.stories.length != 0){
if(app.selection.length != 0){
switch(app.selection[0].constructor.name){
case "InsertionPoint":
case "Character":
case "Word":
case "TextStyleRange":
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
case "TextFrame":
var myArray = myDisplayDialog();
myObject = myArray[0];
myCheckSelection = myArray[1];
break;
default:
myObject = app.activeDocument;
break;
}
}
else{
myObject = app.activeDocument;
}
if(myObject != "None"){
myTextCleanup(myObject, myCheckSelection);
}
}
else{
alert("The current document contains no text. Please open a document containing text and try again.");
}
}
else{
alert("No documents are open. Please open a document and try again.");
}
function myDisplayDialog(){
var myCheckSelection = false;
var myDialog = app.dialogs.add({name:"TextCleanup"});
with(myDialog.dialogColumns.add()){
with(dialogRows.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Search Range"});
}
var myRangeButtons = radiobuttonGroups.add();
with(myRangeButtons){
radiobuttonControls.add({staticLabel:"Selected Story", checkedState:true});
radiobuttonControls.add({staticLabel:"Document"});
if(app.selection[0].contents != ""){
radiobuttonControls.add({staticLabel:"Selection"});
}
}
}
}
var myResult = myDialog.show();
if(myResult == true){
switch(myRangeButtons.selectedButton){
case 0:
switch(app.selection[0].constructor.name){
case "InsertionPoint":
case "Character":
case "Word":
case "TextStyleRange":
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
case "TextFrame":
myObject = app.selection[0].parentStory;
break;
default:
myObject = "None";
break;
}
break;
case 1:
myObject = app.activeDocument;
break;
case 2:
switch(app.selection[0].constructor.name){
case "Word":
case "TextStyleRange":
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
case "TextFrame":
if(app.selection[0].contents != ""){
myObject = app.selection[0].texts.item(0);
myCheckSelection = true;
}
else{
myObject = "None";
}
break;
default:
myObject = "None";
break;
}
break;
}
}
else{
myObject = "None";
}
myDialog.destroy();
return [myObject, myCheckSelection];
}
app.findPreferences = app.changePreferences = null;
app.findPreferences.appliedFont = 'Times';
app.findPreferences.fontStyle = 'Regular';
Times( '10', -75 );
Times( '01', -25 );
Times( '11', -75 );
Times( '12', -75 );
Times( '13', -75 );
Times( '14', -75 );
Times( '15', -75 );
Times( '16', -75 );
Times( '17', -75 );
Times( '18', -75 );
Times( '19', -75 );
Times( '1.', -150 );
Times( '1,', -100 );
Times( ',7', -50 );
Times( '7+', -50 );
Times( '1)', -100 );
Times( '+8', +75 );
Times( '-7', -100 );
Times( '1-', -100 );
Times( '-3', +25 );
Times( '1+', -100 );
Times( '+2', +25 );
Times( '6+', +25 );
Times( '2/', +100 );
Times( '/3', +100 );
Times( '6/', +100 );
Times( '/7', +100 );
Times( '0/', +100 );
Times( '/1', +100 );
Times( '(1', -50 );
Times( '31', -50 );
Times( '1°', -50 );
Times( '6:', +75 );
Times( ':9', +75 );
Times( '21', -25 );
Times( '75', -25 );
Times( '37', -25 );
Times( '7,', -100 );
Times( '87', -25 );
Times( '0-', +100 );
Times( '6-', +100 );
Times( '-1', -75 );
Times( '1:', -50 );
Times( ':1', -75 );
Times( '.B', +100 );
Times( '*B', +100 );
Times( '7-', -50 );
Times( '+1', -50 );
Times( '+9', +25 );
Times( ' 1', -100 );
Times( ' 7', -50 );
Times( '7 ', -100 );
Times( ' x', +100 );
function Times( kPair, kValue )
{
//All Paar-Vorkommen finden
var myPairs = myObject.search( kPair, false, true );
//Einfügen der Kerningwerte zwischen erstem und zweitem Buchstaben
for( var i = 0; i < myPairs.length; i++ )
myPairs[i].insertionPoints[1].kerningValue = kValue;
}
function myTextCleanup(myObject, myCheckSelection){
var myScriptFileName, myFindChangeFile, myFindChangeFileName, myScriptFile, myResult;
var myFindChangeFile = myFindFile("TextCleanup.txt")
if(myFindChangeFile != null){
var myResult = myFindChangeFile.open("r", undefined, undefined);
if(myResult == true){
//Clear any existing find/change settings.
app.changePreferences = NothingEnum.nothing;
app.findPreferences = NothingEnum.nothing;
//Loop through the find/change operations.
do{
myLine = myFindChangeFile.readln();
//Ignore comment lines and blank lines.
if((myLine.substring(0,2)!="//")&&(myLine != "")){
myFindChangeArray = myLine.split("\t");
//The first field in the line is the FindWhat string.
eval("app.findPreferences.properties = " + myFindChangeArray[0]);
//The second field in the line is the ChangeTo string.
eval ("app.changePreferences.properties = " + myFindChangeArray[1]);
//The third field in the line can be either "once" or "all".
//If it's "all", keep on searching until no instances of the
//search text are found, if it's "once," search just once.
myFindLimit = myFindChangeArray[2];
if(myFindLimit == "once"){
myFoundItems = myObject.search(app.findPreferences.findText, undefined, undefined, app.changePreferences.changeText);
}
else{
var myLoopLimit = 0;
outsideloop:
do{
//Because it's easy to end up in an endless loop when you set myFindLimit to "all", we need
//to provide a way to get out of the loop.
myFoundItems = myObject.search(app.findPreferences.findText, undefined, undefined, app.changePreferences.changeText);
myLoopLimit ++;
if(myLoopLimit > 100){
var myResult = confirm("Your find/change operation has been run 100 times. Do you want to continue?");
if(myResult == false){
break outsideloop;
}
else{
myLoopLimit = 0;
}
}
if(myCheckSelection == true){
//If myCheckSelection is true, reacquire a reference to the selection each time through the loop.
//You need to do this because deleting/adding characters has the potential to invalidate the
//text reference you're using.
myObject = app.selection[0];
}
}while(myFoundItems.length > 0);
}
//Reset the find/change preferences after each search.
app.changePreferences = NothingEnum.nothing;
app.findPreferences = NothingEnum.nothing;
if(myCheckSelection == true){
//If myCheckSelection is true, reacquire a reference to the selection each time through the loop.
//You need to do this because deleting/adding characters has the potential to invalidate the
//text reference you're using.
myObject = app.selection[0];
}
}
} while(myFindChangeFile.eof == false);
myFindChangeFile.close();
}
}
}
function myFindFile(myFileName){
var myFile;
try{
var myScriptFileName = app.activeScript;
//Get a file reference to the script.
var myScriptFile = File(myScriptFileName);
//Get a reference to the folder containing the script.
var myFolder = myScriptFile.parent;
//Look for the file name in the folder.
if(myFolder.getFiles(myFileName).length != 0){
var myFile = myFolder.getFiles(myFileName)[0];
}
else{
throw "error"
}
}
catch (myError){
myFile = File.openDialog("Choose the file containing your find/change list");
}
return myFile;
}