Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set XX to 1
- tell application "Adobe InDesign CC 2017"
- tell active document
- tell page XX
- set overlownFrames_List to (get id of every text frame whose overflows of properties is true) as list
- end tell
- repeat with i from 1 to count of overlownFrames_List
- -- Get side of document to assign correct geometric bounds for text frame resize
- set pageSide to get side of parent page of text frame id (item i of overlownFrames_List)
- -- Get document offset to assign correct geometric bounds for text frame resize
- set documentOffset to get document offset of parent page of text frame id (item i of overlownFrames_List) as number
- -- Page bounds are needed so that text frame resize does not exceed page bounds!
- set overflow_GeometricBounds_Page to get bounds of parent page of text frame id (item i of overlownFrames_List)
- -- Define geometric bounds of text frame with overflow text
- set overflow_GeometricBounds_Frame to get geometric bounds of text frame id (item i of overlownFrames_List)
- -- Get widt of text frame
- set overflow_TextFrame_WIDTH to (item 4 of overflow_GeometricBounds_Frame) - (item 2 of overflow_GeometricBounds_Frame)
- -- Get height of text frame
- set overflow_TextFrame_HEIGHT to (item 3 of overflow_GeometricBounds_Frame) - (item 1 of overflow_GeometricBounds_Frame)
- set overflow_ParagaraphCount to get count of paragraphs of parent story of text frame id (item i of overlownFrames_List)
- -- Get first paragraph justification and save it as string. This is to avoid calling paragraph/story properties for each instance
- set overflow_Justification to get justification of paragraph 1 of parent story of text frame id (item i of overlownFrames_List) as string
- -- First expand rotated text frames
- -- Rotated text frames with oferflow have a special expansion procedure not related to 0º rotated frames
- set textFrame_rotationAngle to get absolute rotation angle of text frame id (item i of overlownFrames_List)
- if textFrame_rotationAngle ≠ 0 then
- -- Set variable of transform reference point for rotation, depending on:
- -- rotation angle of text frame
- -- justification of text frame content
- if overflow_Justification = "left" or overflow_Justification = "left justified" or overflow_Justification = "to binding side" or overflow_Justification = "full" then
- if textFrame_rotationAngle ≥ 0 and textFrame_rotationAngle ≤ 90 then
- tell layout window 1
- set transform reference point to bottom left anchor
- end tell
- -- Set transform reference point for rotating texxt frame to its original coordinates
- set rotationAnchor to top left anchor
- else if textFrame_rotationAngle ≥ 0 and textFrame_rotationAngle > 90 then
- tell layout window 1
- set transform reference point to bottom left anchor
- end tell
- -- Set transform reference point for rotating texxt frame to its original coordinates
- set rotationAnchor to bottom left anchor
- end if
- end if
- set rotation angle of text frame id (item i of overlownFrames_List) to 0
- -- Use system "fit content to frame" before changing geometric bounds
- -- In some cases system "fit content to frame" solves the problem
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- -- Check if text overflow still exists
- set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
- -- If overflow still exists apply new geometric bounds => expand text frame
- if ReCheck_Overflow = true then
- -- Set initial variable state
- set textOverflow to true
- -- Text width expansion unit in mm
- set addWidth to 2
- -- For text frames that system fitting does not work expansion neds to be applied accorning to content justification!
- -- Resize text frame gradually, until overflow is false
- repeat until textOverflow = false
- -- Expansion rules for justification: left, left justified, to binding side (left), center justified, full
- if overflow_Justification = "left" or overflow_Justification = "left justified" or overflow_Justification = "to binding side" or overflow_Justification = "full" then
- set properties of text frame id (item i of overlownFrames_List) to ¬
- {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
- (item 2 of overflow_GeometricBounds_Frame), ¬
- (item 3 of overflow_GeometricBounds_Frame), ¬
- ((item 4 of overflow_GeometricBounds_Frame) + addWidth)}}
- -- Expansion rules for justification: right, away from binding side (right)
- else if overflow_Justification = "right" or overflow_Justification = "away from binding side" then
- set properties of text frame id (item i of overlownFrames_List) to ¬
- {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
- ((item 2 of overflow_GeometricBounds_Frame) + addWidth), ¬
- (item 3 of overflow_GeometricBounds_Frame), ¬
- (item 4 of overflow_GeometricBounds_Frame)}}
- -- Expansion rules for justification: center, center justified
- else if overflow_Justification = "center" or overflow_Justification = "center justified" then
- set properties of text frame id (item i of overlownFrames_List) to ¬
- {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
- (item 2 of overflow_GeometricBounds_Frame), ¬
- (item 3 of overflow_GeometricBounds_Frame), ¬
- ((item 4 of overflow_GeometricBounds_Frame) + (addWidth / 2))}}
- end if
- -- Check if text overflow still exists
- set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
- -- If overflow still exists try to expand text frame vertically
- if ReCheck_Overflow = true then
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- end if
- -- Check if text overflow still exists
- set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
- -- If overflow still exists then repeat text frame width resize
- if ReCheck_Overflow = true then
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- else if ReCheck_Overflow = false then
- set textOverflow to false
- end if
- -- Redefine text expansion unit after each loop
- set addWidth to addWidth + 2
- end repeat
- end if -- ReCheck_Overflow = true
- -- Rotate text frame back to its original absolute rortation angle
- set rotation angle of text frame id (item i of overlownFrames_List) to textFrame_rotationAngle
- else if textFrame_rotationAngle = 0 then
- -- Define 2/3 of page width. This widt is used to establish if text frame should be expanded by width or height.
- -- If text frame width ≥ 2/3 page width => expand by width
- -- If text frame width ≤ 2/3 page width => expand by height
- if item 2 of overflow_GeometricBounds_Page = 0 then -- left or first (right!) page
- set maxFrame_WIDTH to (item 4 of overflow_GeometricBounds_Page) / 3 * 2
- set pageSide_GeometricBounds to "left"
- else if item 2 of overflow_GeometricBounds_Page ≠ 0 then -- right page
- set maxFrame_WIDTH to (item 2 of overflow_GeometricBounds_Page) / 3 * 2
- set pageSide_GeometricBounds to "right"
- end if
- -- Apply overset transformation rules for firts RIGTH HAND page only!!!!
- if pageSide_GeometricBounds = "left" and documentOffset = 1 then
- (*========================================================
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- ========================================================*)
- -- Text frame width is larger than its width => expand text frame horizontally
- --if overflow_TextFrame_WIDTH > overflow_TextFrame_HEIGHT then
- -- Text frame width is more than 2/3 of page width => expand text frame horizontally
- if overflow_TextFrame_WIDTH ≥ maxFrame_WIDTH then
- (*========================================================
- #########################################################
- ========================================================*)
- -- Expansion rules for justification: left, left justified, to binding side (left), center justified, full
- if overflow_Justification = "left" or overflow_Justification = "left justified" or overflow_Justification = "to binding side" or overflow_Justification = "full" then
- set properties of text frame id (item i of overlownFrames_List) to ¬
- {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
- (item 2 of overflow_GeometricBounds_Frame), ¬
- (item 3 of overflow_GeometricBounds_Frame), ¬
- (item 4 of overflow_GeometricBounds_Page)}}
- -- Check if maximum allowed frame width (right page bound) has cleared text overflow
- set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
- -- If overflow still exists then expand text frame vertically
- if ReCheck_Overflow = true then
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- end if
- -- Re-fit width of expanded text frame "remove unnecessary width and height"
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- (*========================================================
- #########################################################
- ========================================================*)
- -- Expansion rules for justification: right, away from binding side (right)
- else if overflow_Justification = "right" or overflow_Justification = "away from binding side" then
- set properties of text frame id (item i of overlownFrames_List) to ¬
- {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
- (item 2 of overflow_GeometricBounds_Page), ¬
- (item 3 of overflow_GeometricBounds_Frame), ¬
- (item 4 of overflow_GeometricBounds_Frame)}}
- -- Check if maximum allowed frame width (right page bound) has cleared text overflow
- set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
- -- If overflow still exists then expand text frame vertically
- if ReCheck_Overflow = true then
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- end if
- -- Re-fit width of expanded text frame "remove unnecessary width and height"
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- (*========================================================
- #########################################################
- ========================================================*)
- -- Expansion rules for justification: center, center justified
- else if overflow_Justification = "center" or overflow_Justification = "center justified" then
- set properties of text frame id (item i of overlownFrames_List) to ¬
- {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
- (item 2 of overflow_GeometricBounds_Page), ¬
- (item 3 of overflow_GeometricBounds_Frame), ¬
- (item 4 of overflow_GeometricBounds_Page)}}
- -- Check if maximum allowed frame width (right page bound) has cleared text overflow
- set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
- -- If overflow still exists then expand text frame vertically
- if ReCheck_Overflow = true then
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- end if
- -- Re-fit width of expanded text frame "remove unnecessary width and height"
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- end if -- Justification properties
- (*========================================================
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- ========================================================*)
- -- Text frame width is less than 2/3 of page width => expand text frame vertically
- -- Applies to all justification rules, except center and center justified
- else if overflow_TextFrame_WIDTH < maxFrame_WIDTH then
- -- Expansion rules for justification: left, left justified, to binding side (left), full
- -- Expansion rules for justification: left, left justified, to binding side (left), center justified, full
- 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
- set properties of text frame id (item i of overlownFrames_List) to ¬
- {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
- (item 2 of overflow_GeometricBounds_Frame), ¬
- (item 3 of overflow_GeometricBounds_Frame), ¬
- (0)}}
- -- Check if maximum allowed frame width (right page bound) has cleared text overflow
- set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
- -- If overflow still exists then expand text frame vertically
- if ReCheck_Overflow = true then
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- end if
- -- Re-fit width of expanded text frame "remove unnecessary width and height"
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- (*========================================================
- #########################################################
- ========================================================*)
- -- Expansion rules for justification: right, away from binding side (right)
- else if overflow_Justification = "right" or overflow_Justification = "away from binding side" then
- set properties of text frame id (item i of overlownFrames_List) to ¬
- {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
- ((item 4 of overflow_GeometricBounds_Page) - (2 * (item 4 of overflow_GeometricBounds_Page))), ¬
- (item 3 of overflow_GeometricBounds_Frame), ¬
- (item 4 of overflow_GeometricBounds_Frame)}}
- -- Check if maximum allowed frame width (right page bound) has cleared text overflow
- set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
- -- If overflow still exists then expand text frame vertically
- if ReCheck_Overflow = true then
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- end if
- -- Re-fit width of expanded text frame "remove unnecessary width and height"
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- (*========================================================
- #########################################################
- ========================================================*)
- -- Expansion rules for justification: center, center justified
- else if overflow_Justification = "center" or overflow_Justification = "center justified" then
- -- Use system "fit content to frame" before changing geometric bounds
- -- In some cases system "fit content to frame" solves the problem
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- -- Check if text overflow still exists
- set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
- -- If overflow still exists apply new geometric bounds => expand text frame
- if ReCheck_Overflow = true then
- -- Set initial variable state
- set textOverflow to true
- -- Text width expansion unit in mm
- set addWidth to 2
- -- Resize text frame gradually, until overflow is false
- repeat until textOverflow = false
- set properties of text frame id (item i of overlownFrames_List) to ¬
- {geometric bounds:{(item 1 of overflow_GeometricBounds_Frame), ¬
- ((item 2 of overflow_GeometricBounds_Frame) - addWidth), ¬
- (item 3 of overflow_GeometricBounds_Frame), ¬
- ((item 4 of overflow_GeometricBounds_Frame) + addWidth)}}
- -- Check if text overflow still exists
- set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
- -- If overflow still exists try to expand text frame vertically
- if ReCheck_Overflow = true then
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- end if
- -- Check if text overflow still exists
- set ReCheck_Overflow to get overflows of properties of text frame id (item i of overlownFrames_List)
- -- If overflow still exists then repeat text frame width resize
- if ReCheck_Overflow = true then
- tell text frame id (item i of overlownFrames_List) to fit given frame to content
- else if ReCheck_Overflow = false then
- set textOverflow to false
- end if
- -- Redefine text expansion unit after each loop
- set addWidth to addWidth + 2
- end repeat
- end if -- ReCheck_Overflow = true
- end if -- Justification properties
- end if -- overflow_TextFrame_WIDTH ≥ maxFrame_WIDTH
- --end if -- overflow_TextFrame_WIDTH > overflow_TextFrame_HEIGHT
- else if pageSide_GeometricBounds = "left" and documentOffset ≠ 1 then
- end if -- First or left page
- end if
- set absolute rotation angle of text frame id (item i of overlownFrames_List) to textFrame_rotationAngle
- end repeat
- end tell
- end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement