1
- var textTools = { reverser : function ( tgt ) { //a textRange if ( tgt . typename != "TextRange" ) return false ; var rst = "" ; var st = tgt . contents for ( var i = st . length ; i >= 0 ; i -- ) rst += st . substr ( i , "1" ) ; num = app . activeDocument . selection . characterOffset - 1 ; app . activeDocument . selection . contents = "a" ; app . activeDocument . selection . parent . characters [ num ] . contents = rst ; } , charSplitter : function ( tx ) { //single line textFrame if ( tgt . typename != "TextFrame" ) return false ; if ( tx . lines . length > 1 || tx . characters . length < 2 ) return false ; var chr , y ; for ( var k = tx . characters . length - 1 ; k >= 0 ; k -- ) { chr = tx . duplicate ( ) ; y = tx . position [ 1 ] ; for ( var j = chr . characters . length - 2 ; j >= 0 ; j -- ) chr . characters [ j ] . remove ( ) ; tx . characters [ k ] . remove ( ) ; if ( tx . height > chr . height ) y = y - tx . height + chr . height ; chr . position = [ tx . position [ 0 ] + tx . width , y ] ; } tx . remove ( ) ; } , lineSplitter : function ( tx ) { //textFrame if ( tgt . typename != "TextFrame" ) return false ; var num = tx . paragraphs . length - 1 ; for ( var b , h1 , h2 , j , i = num ; i >= 0 ; i -- ) { b = tx . duplicate ( ) ; h1 = tx . height ; tx . paragraphs [ i ] . remove ( ) ; for ( j = i - 1 ; j >= 0 ; j -- ) b . paragraphs [ j ] . remove ( ) ; h2 = b . height ; b . position = [ tx . position [ 0 ] , tx . position [ 1 ] - h1 + h2 ] ; } } , sortAndConnect : function ( tg ) { //selected textFrames var tf = [ ] ; for ( var i = 0 ; i < tg . length ; i ++ ) tf . push ( tg [ i ] ) ; tf . sort ( function ( a , b ) { return b . position [ 0 ] > a . position [ 0 ] ?- 1 :b . position [ 0 ] == a . position [ 0 ] ?0 :1 } ) ; for ( var chr = tf [ 0 ] . characters . length , i = 1 ; i < tf . length ; i ++ ) { tf [ 0 ] . characters . add ( "#" ) ; tf [ 0 ] . characters [ chr ] . size = tf [ i ] . characters [ 0 ] . size ; tf [ 0 ] . characters [ chr ] . tracking = tf [ i ] . characters [ 0 ] . tracking ; tf [ 0 ] . characters [ chr ] . characterAttributes . textFont = tf [ i ] . characters [ 0 ] . characterAttributes . textFont ; tf [ 0 ] . characters [ chr ] . horizontalScale = tf [ i ] . characters [ 0 ] . horizontalScale ; tf [ 0 ] . characters [ chr ] . verticalScale = tf [ i ] . characters [ 0 ] . verticalScale ; tf [ 0 ] . characters [ chr ] . baselineShift = tf [ i ] . characters [ 0 ] . baselineShift ; tf [ 0 ] . characters [ chr ] . contents = tf [ i ] . contents ; chr += tf [ i ] . characters . length ; tf [ i ] . remove ( ) ; } } , tabSplitter : function ( tg ) { //single line textFrames for ( var i = 0 ; i < app . selection . length ; i ++ ) if ( app . selection [ i ] . typename == "TextFrame" ) while ( this . firstTabSplitter ( app . selection [ i ] ) ) { } } , firstTabSplitter : function ( tf ) { //textFrame if ( tf . characters . length < 2 ) return false ; var wd = tf . width ; var n = tf . contents . indexOf ( "\t" ) ; if ( n < 0 ) return false ; var tf2 = tf . duplicate ( ) ; for ( var i = tf . characters . length - 1 ; i >= n ; i -- ) tf . characters [ i ] . remove ( ) ; for ( i = n ; i >= 0 ; i -- ) tf2 . characters [ i ] . remove ( ) ; tf2 . position = [ tf . position [ 0 ] + wd - tf2 . width , tf . position [ 1 ] ] ; tf . characters [ tf . characters . length - 1 ] . tracking = 0 ; tf2 . characters [ tf2 . characters . length - 1 ] . tracking = 0 ; return true ; } } textTools . reverser ( app . selection ) ;
1
+ var textTools = {
2
+ reverser : function ( tgt ) { //a textRange
3
+ if ( tgt . typename != "TextRange" ) return false ;
4
+ var rst = "" ;
5
+ var st = tgt . contents ;
6
+ for ( var i = st . length ; i >= 0 ; i -- ) rst += st . substr ( i , "1" ) ;
7
+ num = app . activeDocument . selection . characterOffset - 1 ;
8
+ app . activeDocument . selection . contents = "a" ;
9
+ app . activeDocument . selection . parent . characters [ num ] . contents = rst ;
10
+ } ,
11
+ charSplitter : function ( tx ) { //single line textFrame
12
+ if ( tgt . typename != "TextFrame" ) return false ;
13
+ if ( tx . lines . length > 1 || tx . characters . length < 2 ) return false ;
14
+ var chr , y ;
15
+ for ( var k = tx . characters . length - 1 ; k >= 0 ; k -- ) {
16
+ chr = tx . duplicate ( ) ;
17
+ y = tx . position [ 1 ] ;
18
+ for ( var j = chr . characters . length - 2 ; j >= 0 ; j -- ) chr . characters [ j ] . remove ( ) ;
19
+ tx . characters [ k ] . remove ( ) ;
20
+ if ( tx . height > chr . height ) y = y - tx . height + chr . height ;
21
+ chr . position = [ tx . position [ 0 ] + tx . width , y ] ;
22
+ }
23
+ tx . remove ( ) ;
24
+ } ,
25
+ lineSplitter : function ( tx ) { //textFrame
26
+ if ( tgt . typename != "TextFrame" ) return false ;
27
+ var num = tx . paragraphs . length - 1 ;
28
+ for ( var b , h1 , h2 , j , i = num ; i >= 0 ; i -- ) {
29
+ b = tx . duplicate ( ) ;
30
+ h1 = tx . height ;
31
+ tx . paragraphs [ i ] . remove ( ) ;
32
+ for ( j = i - 1 ; j >= 0 ; j -- ) b . paragraphs [ j ] . remove ( ) ;
33
+ h2 = b . height ;
34
+ b . position = [ tx . position [ 0 ] , tx . position [ 1 ] - h1 + h2 ] ;
35
+ }
36
+ } ,
37
+ sortAndConnect : function ( tg ) { //selected textFrames
38
+ var tf = [ ] ;
39
+ for ( var i = 0 ; i < tg . length ; i ++ )
40
+ tf . push ( tg [ i ] ) ;
41
+ tf . sort ( function ( a , b ) { return b . position [ 0 ] > a . position [ 0 ] ?- 1 :b . position [ 0 ] == a . position [ 0 ] ?0 :1 } ) ;
42
+ for ( var chr = tf [ 0 ] . characters . length , i = 1 ; i < tf . length ; i ++ ) {
43
+ tf [ 0 ] . characters . add ( "#" ) ;
44
+ tf [ 0 ] . characters [ chr ] . size = tf [ i ] . characters [ 0 ] . size ;
45
+ tf [ 0 ] . characters [ chr ] . tracking = tf [ i ] . characters [ 0 ] . tracking ;
46
+ tf [ 0 ] . characters [ chr ] . characterAttributes . textFont = tf [ i ] . characters [ 0 ] . characterAttributes . textFont ;
47
+ tf [ 0 ] . characters [ chr ] . horizontalScale = tf [ i ] . characters [ 0 ] . horizontalScale ;
48
+ tf [ 0 ] . characters [ chr ] . verticalScale = tf [ i ] . characters [ 0 ] . verticalScale ;
49
+ tf [ 0 ] . characters [ chr ] . baselineShift = tf [ i ] . characters [ 0 ] . baselineShift ;
50
+ tf [ 0 ] . characters [ chr ] . contents = tf [ i ] . contents ;
51
+ chr += tf [ i ] . characters . length ;
52
+ tf [ i ] . remove ( ) ;
53
+ }
54
+ } ,
55
+ tabSplitter : function ( tg ) { //single line textFrames
56
+ for ( var i = 0 ; i < app . selection . length ; i ++ )
57
+ if ( app . selection [ i ] . typename == "TextFrame" )
58
+ while ( this . firstTabSplitter ( app . selection [ i ] ) ) { }
59
+ } ,
60
+ firstTabSplitter : function ( tf ) { //textFrame
61
+ if ( tf . characters . length < 2 ) return false ;
62
+ var wd = tf . width ;
63
+ var n = tf . contents . indexOf ( "\t" ) ;
64
+ if ( n < 0 ) return false ;
65
+ var tf2 = tf . duplicate ( ) ;
66
+ for ( var i = tf . characters . length - 1 ; i >= n ; i -- ) tf . characters [ i ] . remove ( ) ;
67
+ for ( i = n ; i >= 0 ; i -- ) tf2 . characters [ i ] . remove ( ) ;
68
+ tf2 . position = [ tf . position [ 0 ] + wd - tf2 . width , tf . position [ 1 ] ] ;
69
+ tf . characters [ tf . characters . length - 1 ] . tracking = 0 ;
70
+ tf2 . characters [ tf2 . characters . length - 1 ] . tracking = 0 ;
71
+ return true ;
72
+ }
73
+ }
74
+
75
+
76
+ textTools . reverser ( app . selection ) ;
0 commit comments