#!/usr/bin/perl # # screenplayformatpro.pl 2.0 # Copyright (C) 2003 by Fletcher T. Penney. # # http://fletcher.freeshell.org/ # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License # as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # Or visit http://gnu.org # # This is a complete re-write of my original # screenplayformat.pl script # # There are numerous new settings, and the parser # is much improved. # # The margins and options are set by the gui and # prefixed to the script automatically. # As far as the script is concerned, it all arrives at once. # # First, set defaults # Page Margins (in inches) $left = 1.5; $right = 1; $top = 1; $bottom = 0.5; $offset = 0.5; # Used for scene numbers $pagebuffer = 0; # Used for scene numbers # Transitions $transleft = 4; # Alternate 0 # Character Names $charleft = 2; $charright = 0.2; # Parentheticals $parleft = 1.7; $parright = 2; # = 5.2 from left # Dialogue $dialleft = 1; $dialright = 1.5; # = 6 from left # Default options $keepfade = 1; $keeptransitions = 1; $doublebeforeslugs = 1; # Defaults $VO = " (V.O.)"; $OS = " (O.S.)"; $NIGHT = " - NIGHT"; $DAY = " - DAY"; $CONT = " (CONT'D)"; $INT = "INT."; $EXT = "EXT."; $IE = "INT./EXT."; $newpage= "\\page\n"; # Default Transitions to recognize $MatchTransitions = "(((MATCH |JUMP )?CUT|DISSOLVE|BACK) TO:)|(FADE (IN:|OUT\.|TO BLACK\.))"; # Next, read headers and options and override defaults as appropriate $line = <>; if ($line =~ /^#\s*BEGIN-HEADERS/i) { while (($line = <>) && ($line !~ /# END-HEADERS/i)) { if ($line =~ /^\s*LEFT MARGIN\s*([0-9\.]+)/i) { $left = $1; } if ($line =~ /^\s*RIGHT MARGIN\s*([0-9\.]+)/i) { $right = $1; } if ($line =~ /^\s*TOP MARGIN\s*([0-9\.]+)/i) { $top = $1; } if ($line =~ /^\s*BOTTOM MARGIN\s*([0-9\.]+)/i) { $bottom = $1; } if ($line =~ /^\s*TRANSITIONS\s*([0-9\.]+)/i) { $transleft = $1; } if ($line =~ /^\s*LEFT CHARACTER NAME\s*([0-9\.]+)/i) { $charleft = $1; } if ($line =~ /^\s*RIGHT CHARACTER NAME\s*([0-9\.]+)/i) { $charright = $1; } if ($line =~ /^\s*LEFT PARENTHETICAL\s*([0-9\.]+)/i) { $parleft = $1; } if ($line =~ /^\s*RIGHT PARENTHETICAL\s*([0-9\.]+)/i) { $parright = $1; } if ($line =~ /^\s*LEFT DIALOGUE\s*([0-9\.]+)/i) { $dialleft = $1; } if ($line =~ /^\s*RIGHT DIALOGUE\s*([0-9\.]+)/i) { $dialright = $1; } if ($line =~ /^\s*SCENE OFFSET\s*([0-9\.]+)/i) { $offset = $1; } if ($line =~ /^\s*USE\s*FORMFEED/i) { $newpage = "\f\n"; } if ($line =~ /^\s*HIDE\s*FADES/i) { $keepfade = 0; } if ($line =~/^\s*HIDE\s*TRANSITIONS/i) { $keeptransitions=0; } if ($line =~/^\s*SINGLESPACE\s*SLUG/i) { $doublebeforeslugs = 0; } if ($line =~ /^\s*DEFINE VO:(.*)/i) { $VO = $1; } if ($line =~ /^\s*DEFINE OS:(.*)/i) { $OS = $1; } if ($line =~ /^\s*DEFINE NIGHT:(.*)/i) { $NIGHT = $1; } if ($line =~ /^\s*DEFINE DAY:(.*)/i) { $DAY = $1; } if ($line =~ /^\s*DEFINE CONTINUE:(.*)/i) { $CONT = $1; } if ($line =~ /^\s*DEFINE INT:(.*)/i) { $INT = $1; } if ($line =~ /^\s*DEFINE EXT:(.*)/i) { $EXT = $1; } if ($line =~ /^\s*DEFINE IE:(.*)/i) { $IE = $1; } if ($line =~ /^\s*DEFINE TRANS.*:(.*)/i) { $temp = $1; $temp =~ s/(\.|\(|\))/\\$1/g; $MatchTransitions.="|$temp"; } if ($line =~ /^\s*NUMBER\s*SCENES/i) { $numberscene = 1; } if ($line =~ /^\s*\\t(itle)?\s*(.*)/i) { $title = $2; $title =~ s/\\n\s*/\\\n/g; } if ($line =~ /^\s*\\w(riter)?\s*(.*)/i) { $writer = $2; $writer =~ s/\\n\s*/\\\n/g; } if ($line =~ /^\s*\\c(ompany)?\s*(.*)/i) { $company = $2; $company =~ s/\\n\s*/\\\n/g; } if ($line =~ /^\s*\\a(ddress)?\s*(.*)/i) { $address = $2; $address =~ s/\\n\s*/\\\n/g; } if ($line =~ /^\s*\\p(hone)?\s*(.*)/i) { $phone = $2; $phone =~ s/\\n\s*/\\\n/g; } if ($line =~ /^\s*CHARACTER\s*ALIAS\s*([\w\s]*)\=\s*([\w\|]*)/i) { push(@CharAliases,$2); $Char = $1; $Char =~ s/\s*$//; push(@CharName,$Char); } if ($line =~ /^\s*LOCATION\s*ALIAS\s*([\w\s]*)\=\s*([\w\|]*)/i) { push(@LocAliases,$2); $Char = $1; $Char =~ s/\s*$//; push(@LocName,$Char); } } } # Now, if scenes are numbered, fix the left margins... if ($numberscene eq 1) { $left = $left - $offset; $transleft = $transleft + $offset; $charleft = $charleft + $offset; $parleft = $parleft + $offset; $dialleft = $dialleft + $offset; $pagebuffer = $offset * 1440; } # Now convert from inches to picas $left = $left * 1440; $right = $right * 1440; $bottom = $bottom * 1440; $top = $top * 1440; $transleft = $transleft * 1440; $charleft = $charleft * 1440; $charright = $charright * 1440; $parleft = $parleft * 1440; $parright = $parright * 1440; $dialleft = $dialleft * 1440; $dialright = $dialright * 1440; $pagewidth = 12240 - $left - $right; # Now set rtf strings $Header = "{\\rtf1\\mac\\ansicpg10000\\cocoartf100 {\\fonttbl\\f0\\qfmodern\\fcharset77 Courier;} {\\colortbl;\\red255\\green255\\blue255;} \\margl$left\\margr$right\\margb$bottom\\margt$top\\vieww12600\\viewh12120\\viewkind1\\viewscale100 \\pard\\ql\\qnatural \\f0\\fs24 \\cf0 "; $FullWidth = "\\pard\\tqr\\tx$pagewidth\\ql\\qnatural \\cf0 "; $Slugline = "\\pard\\tqr\\tx$pagewidth\\ql\\qnatural \\cf0 "; $Center = "\\pard\\qc \\cf0 "; if ($numberscene eq 1) { $Slugline = "\\pard\\tx$pagebuffer\\tqr\\tx$pagewidth\\ql\\qnatural \\cf0 "; $FullWidth = "\\pard\\tqr\\tx$pagewidth\\li$pagebuffer\\ql\\qnatural \\cf0 "; $Center = "\\pard\\li$pagebuffer\\qc \\cf0 "; } $Character = "\\pard\\li$charleft\\ri$charright\\ql\\qnatural \\cf0 "; $Parenthetical = "\\pard\\li$parleft\\ri$parright\\ql\\qnatural \\cf0 "; $Dialogue = "\\pard\\li$dialleft\\ri$dialright\\ql\\qnatural \\cf0 "; $Transition = "\\pard\\li$transleft\\ql \\cf0 "; # Now set variables $Scene = 0; $Act = 1; $blank = 0; $oldtype = "none"; $type = "none"; print $Header; # Print Title Page if appropriate if ($title ne "") { print "\\\n\\\n\\\n\\\n\\\n\\\n\\\n\\\n"; print "\\\n\\\n\\\n\\\n\\\n\\\n\\\n\\\n"; print "\\\n\\\n\\\n\\\n\\\n\\\n\\\n\\\n"; print $Center; print "$title\\\n\\\n"; if ($writer ne "") { print "by\\\n$writer" ; } else { print "\\\n"; } print "\\\n\\\n\\\n\\\n\\\n\\\n\\\n"; print "\\\n\\\n\\\n\\\n\\\n\\\n\\\n"; print $FullWidth; print "$company\\\n$address\\\n$phone$newpage"; } # Main Loop while ($line = <>) { # Strip newlines. These will placed at beginning of lines when needed chomp $line; # Strip formfeeds. These appear when pdf is converted to text $line =~ s/\f//g; # Skip Comments next if ($line =~ /^\s*#/); # Handle Fade lines if ($line =~ /^F(A|AD|ADE)\s*(IN|OUT)/i) { if ($keepfade ne 1) { next; } else { $line = uc($line); $line = "$Transition$line"; $type = "trans"; } } # Handle Transitions if ($line =~ /^$MatchTransitions$/i) { if ($keeptransitions ne 1) { next; } else { $line = uc($line); $line = "$Transition$line"; $type = "trans"; } } # Skip empty lines if ($line =~ /^$/) { $blank = 1; $type="none"; next; } # Handle Sluglines if (($line =~ s/^I(NT)?\.?(\s+)/$INT /i)|| ($line =~ s/^E(X|XT)?\.?(\s+)/$EXT /i)|| ($line =~ s/^I(NT)?\.?\/E(X|XT)?\.?(\s+)/$IE /i)) { $line =~ s/[\s-]+D(AY)?$/$DAY/i; $line =~ s/[\s-]+N(IGHT)?$/$NIGHT/i; $line.=" "; for ($i=0;$i