Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set XX to 1
  2.  
  3. tell application "Adobe InDesign CC 2017"
  4.     tell active document
  5.         tell page XX
  6.            
  7.             set overlownFrames_List to (get id of every text frame whose overflows of properties is true) as list
  8.            
  9.         end tell
  10.        
  11.        
  12.         repeat with i from 1 to count of overlownFrames_List
  13.            
  14.             -- Get side of document to assign correct geometric bounds for text frame resize
  15.             set pageSide to get side of parent page of text frame id (item i of overlownFrames_List)
  16.            
  17.             -- Get document offset to assign correct geometric bounds for text frame resize
  18.             set documentOffset to get document offset of parent page of text frame id (item i of overlownFrames_List) as number
  19.            
  20.             -- Page bounds are needed so that text frame resize does not exceed page bounds!
  21.             set overflow_GeometricBounds_Page to get bounds of parent page of text frame id (item i of overlownFrames_List)
  22.            
  23.            
  24.            
  25.             -- Define geometric bounds of text frame with overflow text
  26.             set overflow_GeometricBounds_Frame to get geometric bounds of text frame id (item i of overlownFrames_List)
  27.            
  28.             -- Get widt of text frame
  29.             set overflow_TextFrame_WIDTH to (item 4 of overflow_GeometricBounds_Frame) - (item 2 of overflow_GeometricBounds_Frame)
  30.            
  31.             -- Get height of text frame
  32.             set overflow_TextFrame_HEIGHT to (item 3 of overflow_GeometricBounds_Frame) - (item 1 of overflow_GeometricBounds_Frame)
  33.            
  34.             set overflow_ParagaraphCount to get count of paragraphs of parent story of text frame id (item i of overlownFrames_List)
  35.            
  36.             -- Get first paragraph justification and save it as string. This is to avoid calling paragraph/story properties for each instance
  37.             set overflow_Justification to get justification of paragraph 1 of parent story of text frame id (item i of overlownFrames_List) as string
  38.            
  39.            
  40.            
  41.            
  42.            
  43.             -- First expand rotated text frames
  44.             -- Rotated text frames with oferflow have a special expansion procedure not related to 0º rotated frames
  45.             set textFrame_rotationAngle to get absolute rotation angle of text frame id (item i of overlownFrames_List)
  46.            
  47.             if textFrame_rotationAngle ≠ 0 then
  48.                
  49.                
  50.                 -- Set variable of transform reference point for rotation, depending on:
  51.                 -- rotation angle of text frame
  52.                 -- justification of text frame content
  53.                
  54.                 if overflow_Justification = "left" or overflow_Justification = "left justified" or overflow_Justification = "to binding side" or overflow_Justification = "full" then
  55.                    
  56.                     if textFrame_rotationAngle ≥ 0 and textFrame_rotationAngle ≤ 90 then
  57.                        
  58.                         tell layout window 1
  59.                             set transform reference point to bottom left anchor
  60.                         end tell
  61.                        
  62.                         -- Set transform reference point for rotating texxt frame to its original coordinates
  63.                         set rotationAnchor to top left anchor
  64.                        
  65.                        
  66.                        
  67.                        
  68.                        
  69.                     else if textFrame_rotationAngle ≥ 0 and textFrame_rotationAngle > 90 then
  70.                        
  71.                         tell layout window 1
  72.                             set transform reference point to bottom left anchor
  73.                         end tell
  74.                        
  75.                         -- Set transform reference point for rotating texxt frame to its original coordinates
  76.                         set rotationAnchor to bottom left anchor
  77.                        
  78.                     end if
  79.                 end if
  80.                
  81.                 set rotation angle of text frame id (item i of overlownFrames_List) to 0
  82.                
  83.                 -- Use system "fit content to frame" before changing geometric bounds
  84.                 -- In some cases system "fit content to frame" solves the problem
  85.                 tell text frame id (item i of overlownFrames_List) to fit given frame to content
  86.                
  87.                 -- Check if text overflow still exists
  88.                 set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
  89.                
  90.                 -- If overflow still exists apply new geometric bounds => expand text frame
  91.                 if ReCheck_Overflow = true then
  92.                    
  93.                     -- Set initial variable state
  94.                     set textOverflow to true
  95.                    
  96.                     -- Text width expansion unit in mm
  97.                     set addWidth to 2
  98.                    
  99.                    
  100.                     -- For text frames that system fitting does not work expansion neds to be applied accorning to content justification!
  101.                     -- Resize text frame gradually, until overflow is false
  102.                     repeat until textOverflow = false
  103.                        
  104.                         -- Expansion rules for justification: left, left justified, to binding side (left), center justified, full
  105.                         if overflow_Justification = "left" or overflow_Justification = "left justified" or overflow_Justification = "to binding side" or overflow_Justification = "full" then
  106.                            
  107.                             set properties of text frame id (item i of overlownFrames_List) to ¬
  108.                                 {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
  109.                                     (item 2 of overflow_GeometricBounds_Frame), ¬
  110.                                     (item 3 of overflow_GeometricBounds_Frame), ¬
  111.                                     ((item 4 of overflow_GeometricBounds_Frame) + addWidth)}}
  112.                            
  113.                             -- Expansion rules for justification: right, away from binding side (right)    
  114.                         else if overflow_Justification = "right" or overflow_Justification = "away from binding side" then
  115.                            
  116.                             set properties of text frame id (item i of overlownFrames_List) to ¬
  117.                                 {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
  118.                                     ((item 2 of overflow_GeometricBounds_Frame) + addWidth), ¬
  119.                                     (item 3 of overflow_GeometricBounds_Frame), ¬
  120.                                     (item 4 of overflow_GeometricBounds_Frame)}}
  121.                            
  122.                             -- Expansion rules for justification: center, center justified             
  123.                         else if overflow_Justification = "center" or overflow_Justification = "center justified" then
  124.                            
  125.                             set properties of text frame id (item i of overlownFrames_List) to ¬
  126.                                 {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
  127.                                     (item 2 of overflow_GeometricBounds_Frame), ¬
  128.                                     (item 3 of overflow_GeometricBounds_Frame), ¬
  129.                                     ((item 4 of overflow_GeometricBounds_Frame) + (addWidth / 2))}}
  130.                         end if
  131.                        
  132.                         -- Check if text overflow still exists
  133.                         set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
  134.                        
  135.                         -- If overflow still exists try to expand text frame vertically
  136.                         if ReCheck_Overflow = true then
  137.                             tell text frame id (item i of overlownFrames_List) to fit given frame to content
  138.                         end if
  139.                        
  140.                         -- Check if text overflow still exists
  141.                         set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
  142.                        
  143.                         -- If overflow still exists then repeat text frame width resize
  144.                         if ReCheck_Overflow = true then
  145.                             tell text frame id (item i of overlownFrames_List) to fit given frame to content
  146.                         else if ReCheck_Overflow = false then
  147.                             set textOverflow to false
  148.                         end if
  149.                        
  150.                         -- Redefine text expansion unit after each loop
  151.                         set addWidth to addWidth + 2
  152.                     end repeat
  153.                 end if -- ReCheck_Overflow = true
  154.                
  155.                 -- Rotate text frame back to its original absolute rortation angle
  156.                 set rotation angle of text frame id (item i of overlownFrames_List) to textFrame_rotationAngle
  157.                
  158.                
  159.             else if textFrame_rotationAngle = 0 then
  160.                
  161.                
  162.                
  163.                
  164.                
  165.                
  166.                
  167.                
  168.                
  169.                
  170.                
  171.                
  172.                
  173.                 -- Define 2/3 of page width. This widt is used to establish if text frame should be expanded by width or height.
  174.                 -- If text frame width ≥ 2/3 page width => expand by width
  175.                 -- If text frame width ≤ 2/3 page width => expand by height
  176.                
  177.                 if item 2 of overflow_GeometricBounds_Page = 0 then -- left or first (right!) page
  178.                     set maxFrame_WIDTH to (item 4 of overflow_GeometricBounds_Page) / 3 * 2
  179.                     set pageSide_GeometricBounds to "left"
  180.                 else if item 2 of overflow_GeometricBounds_Page ≠ 0 then -- right page
  181.                     set maxFrame_WIDTH to (item 2 of overflow_GeometricBounds_Page) / 3 * 2
  182.                     set pageSide_GeometricBounds to "right"
  183.                 end if
  184.                
  185.                
  186.                
  187.                
  188.                
  189.                
  190.                 -- Apply overset transformation rules for firts RIGTH HAND page only!!!!
  191.                 if pageSide_GeometricBounds = "left" and documentOffset = 1 then
  192.                    
  193.                     (*========================================================
  194.                 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  195.                 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  196.                 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  197.                 ========================================================*)
  198.                    
  199.                     -- Text frame width is larger than its width => expand text frame horizontally
  200.                     --if overflow_TextFrame_WIDTH > overflow_TextFrame_HEIGHT then
  201.                    
  202.                     -- Text frame width is more than 2/3 of page width => expand text frame horizontally
  203.                     if overflow_TextFrame_WIDTH ≥ maxFrame_WIDTH then
  204.                        
  205.                         (*========================================================
  206.                         #########################################################
  207.                         ========================================================*)
  208.                        
  209.                         -- Expansion rules for justification: left, left justified, to binding side (left), center justified, full
  210.                         if overflow_Justification = "left" or overflow_Justification = "left justified" or overflow_Justification = "to binding side" or overflow_Justification = "full" then
  211.                            
  212.                            
  213.                             set properties of text frame id (item i of overlownFrames_List) to ¬
  214.                                 {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
  215.                                     (item 2 of overflow_GeometricBounds_Frame), ¬
  216.                                     (item 3 of overflow_GeometricBounds_Frame), ¬
  217.                                     (item 4 of overflow_GeometricBounds_Page)}}
  218.                            
  219.                             -- Check if maximum allowed frame width (right page bound) has cleared text overflow
  220.                             set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
  221.                            
  222.                             -- If overflow still exists then expand text frame vertically
  223.                             if ReCheck_Overflow = true then
  224.                                 tell text frame id (item i of overlownFrames_List) to fit given frame to content
  225.                             end if
  226.                            
  227.                             -- Re-fit width of expanded text frame "remove unnecessary width and height"
  228.                             tell text frame id (item i of overlownFrames_List) to fit given frame to content
  229.                            
  230.                             (*========================================================
  231.                             #########################################################
  232.                             ========================================================*)
  233.                            
  234.                             -- Expansion rules for justification: right, away from binding side (right)    
  235.                         else if overflow_Justification = "right" or overflow_Justification = "away from binding side" then
  236.                            
  237.                             set properties of text frame id (item i of overlownFrames_List) to ¬
  238.                                 {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
  239.                                     (item 2 of overflow_GeometricBounds_Page), ¬
  240.                                     (item 3 of overflow_GeometricBounds_Frame), ¬
  241.                                     (item 4 of overflow_GeometricBounds_Frame)}}
  242.                            
  243.                             -- Check if maximum allowed frame width (right page bound) has cleared text overflow
  244.                             set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
  245.                            
  246.                             -- If overflow still exists then expand text frame vertically
  247.                             if ReCheck_Overflow = true then
  248.                                 tell text frame id (item i of overlownFrames_List) to fit given frame to content
  249.                             end if
  250.                            
  251.                             -- Re-fit width of expanded text frame "remove unnecessary width and height"
  252.                             tell text frame id (item i of overlownFrames_List) to fit given frame to content
  253.                            
  254.                             (*========================================================
  255.                             #########################################################
  256.                             ========================================================*)
  257.                            
  258.                             -- Expansion rules for justification: center, center justified     
  259.                         else if overflow_Justification = "center" or overflow_Justification = "center justified" then
  260.                            
  261.                             set properties of text frame id (item i of overlownFrames_List) to ¬
  262.                                 {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
  263.                                     (item 2 of overflow_GeometricBounds_Page), ¬
  264.                                     (item 3 of overflow_GeometricBounds_Frame), ¬
  265.                                     (item 4 of overflow_GeometricBounds_Page)}}
  266.                            
  267.                             -- Check if maximum allowed frame width (right page bound) has cleared text overflow
  268.                             set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
  269.                            
  270.                             -- If overflow still exists then expand text frame vertically
  271.                             if ReCheck_Overflow = true then
  272.                                 tell text frame id (item i of overlownFrames_List) to fit given frame to content
  273.                             end if
  274.                            
  275.                             -- Re-fit width of expanded text frame "remove unnecessary width and height"
  276.                             tell text frame id (item i of overlownFrames_List) to fit given frame to content
  277.                            
  278.                         end if -- Justification properties
  279.                        
  280.                        
  281.                         (*========================================================
  282.                         +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  283.                         +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  284.                         +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  285.                         ========================================================*)
  286.                        
  287.                         -- Text frame width is less than 2/3 of page width => expand text frame vertically 
  288.                         -- Applies to all justification rules, except center and center justified  
  289.                     else if overflow_TextFrame_WIDTH < maxFrame_WIDTH then
  290.                        
  291.                         -- Expansion rules for justification: left, left justified, to binding side (left), full
  292.                         -- Expansion rules for justification: left, left justified, to binding side (left), center justified, full
  293.                         if overflow_Justification = "left" or overflow_Justification = "left justified" or overflow_Justification = "to binding side" or overflow_Justification = "center justified" or overflow_Justification = "full" then
  294.                            
  295.                            
  296.                             set properties of text frame id (item i of overlownFrames_List) to ¬
  297.                                 {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
  298.                                     (item 2 of overflow_GeometricBounds_Frame), ¬
  299.                                     (item 3 of overflow_GeometricBounds_Frame), ¬
  300.                                     (0)}}
  301.                            
  302.                             -- Check if maximum allowed frame width (right page bound) has cleared text overflow
  303.                             set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
  304.                            
  305.                             -- If overflow still exists then expand text frame vertically
  306.                             if ReCheck_Overflow = true then
  307.                                 tell text frame id (item i of overlownFrames_List) to fit given frame to content
  308.                             end if
  309.                            
  310.                             -- Re-fit width of expanded text frame "remove unnecessary width and height"
  311.                             tell text frame id (item i of overlownFrames_List) to fit given frame to content
  312.                            
  313.                             (*========================================================
  314.                             #########################################################
  315.                             ========================================================*)
  316.                            
  317.                             -- Expansion rules for justification: right, away from binding side (right)    
  318.                         else if overflow_Justification = "right" or overflow_Justification = "away from binding side" then
  319.                            
  320.                             set properties of text frame id (item i of overlownFrames_List) to ¬
  321.                                 {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
  322.                                     ((item 4 of overflow_GeometricBounds_Page) - (2 * (item 4 of overflow_GeometricBounds_Page))), ¬
  323.                                     (item 3 of overflow_GeometricBounds_Frame), ¬
  324.                                     (item 4 of overflow_GeometricBounds_Frame)}}
  325.                            
  326.                             -- Check if maximum allowed frame width (right page bound) has cleared text overflow
  327.                             set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
  328.                            
  329.                             -- If overflow still exists then expand text frame vertically
  330.                             if ReCheck_Overflow = true then
  331.                                 tell text frame id (item i of overlownFrames_List) to fit given frame to content
  332.                             end if
  333.                            
  334.                             -- Re-fit width of expanded text frame "remove unnecessary width and height"
  335.                             tell text frame id (item i of overlownFrames_List) to fit given frame to content
  336.                            
  337.                             (*========================================================
  338.                             #########################################################
  339.                             ========================================================*)
  340.                            
  341.                            
  342.                             -- Expansion rules for justification: center, center justified     
  343.                         else if overflow_Justification = "center" or overflow_Justification = "center justified" then
  344.                            
  345.                             -- Use system "fit content to frame" before changing geometric bounds
  346.                             -- In some cases system "fit content to frame" solves the problem
  347.                             tell text frame id (item i of overlownFrames_List) to fit given frame to content
  348.                            
  349.                             -- Check if text overflow still exists
  350.                             set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
  351.                            
  352.                             -- If overflow still exists apply new geometric bounds => expand text frame
  353.                             if ReCheck_Overflow = true then
  354.                                
  355.                                 -- Set initial variable state
  356.                                 set textOverflow to true
  357.                                
  358.                                 -- Text width expansion unit in mm
  359.                                 set addWidth to 2
  360.                                
  361.                                 -- Resize text frame gradually, until overflow is false
  362.                                 repeat until textOverflow = false
  363.                                     set properties of text frame id (item i of overlownFrames_List) to ¬
  364.                                         {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
  365.                                             ((item 2 of overflow_GeometricBounds_Frame) - addWidth), ¬
  366.                                             (item 3 of overflow_GeometricBounds_Frame), ¬
  367.                                             ((item 4 of overflow_GeometricBounds_Frame) + addWidth)}}
  368.                                    
  369.                                     -- Check if text overflow still exists
  370.                                     set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
  371.                                    
  372.                                     -- If overflow still exists try to expand text frame vertically
  373.                                     if ReCheck_Overflow = true then
  374.                                         tell text frame id (item i of overlownFrames_List) to fit given frame to content
  375.                                     end if
  376.                                    
  377.                                     -- Check if text overflow still exists
  378.                                     set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
  379.                                    
  380.                                     -- If overflow still exists then repeat text frame width resize
  381.                                     if ReCheck_Overflow = true then
  382.                                         tell text frame id (item i of overlownFrames_List) to fit given frame to content
  383.                                     else if ReCheck_Overflow = false then
  384.                                         set textOverflow to false
  385.                                     end if
  386.                                    
  387.                                     -- Redefine text expansion unit after each loop
  388.                                     set addWidth to addWidth + 2
  389.                                 end repeat
  390.                             end if -- ReCheck_Overflow = true
  391.                         end if -- Justification properties
  392.                     end if -- overflow_TextFrame_WIDTH ≥ maxFrame_WIDTH
  393.                     --end if -- overflow_TextFrame_WIDTH > overflow_TextFrame_HEIGHT
  394.                    
  395.                    
  396.                    
  397.                    
  398.                    
  399.                    
  400.                    
  401.                    
  402.                    
  403.                    
  404.                    
  405.                    
  406.                    
  407.                    
  408.                    
  409.                 else if pageSide_GeometricBounds = "left" and documentOffset ≠ 1 then
  410.                    
  411.                    
  412.                 end if -- First or left page
  413.                
  414.                
  415.                
  416.             end if
  417.            
  418.             set absolute rotation angle of text frame id (item i of overlownFrames_List) to textFrame_rotationAngle
  419.            
  420.         end repeat
  421.        
  422.        
  423.        
  424.        
  425.     end tell
  426. end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement