| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | #!/bin/bash
 | 
					
						
							|  |  |  | shopt -s nullglob extglob | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #---------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2023-03-14 03:19:43 +03:00
										 |  |  | # | 
					
						
							|  |  |  | # For docs see README.md | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2023-03-08 04:30:17 +03:00
										 |  |  | # | 
					
						
							|  |  |  | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
					
						
							| 
									
										
										
										
											2023-03-14 03:19:43 +03:00
										 |  |  | # | 
					
						
							|  |  |  | # XXX DOC: | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | #		$spread/ | 
					
						
							| 
									
										
										
										
											2023-03-14 03:19:43 +03:00
										 |  |  | #			... | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | #			imagepage.tex | 
					
						
							|  |  |  | #				image page template. | 
					
						
							|  |  |  | #				fields: | 
					
						
							|  |  |  | #					${IMAGE} | 
					
						
							|  |  |  | #					${CAPTION} | 
					
						
							| 
									
										
										
										
											2023-03-08 02:49:40 +03:00
										 |  |  | #					${TEXT0} | 
					
						
							|  |  |  | #					... | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | #			textpage.tex | 
					
						
							|  |  |  | #				text page template. | 
					
						
							|  |  |  | #				fields: | 
					
						
							|  |  |  | #					${TEXT} | 
					
						
							| 
									
										
										
										
											2023-03-08 02:49:40 +03:00
										 |  |  | #					... | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | #			<spread-template-name>-imagepage.tpl | 
					
						
							|  |  |  | #			<spread-template-name>-textpage.tpl | 
					
						
							|  |  |  | #				indicates the image/text page template to use. | 
					
						
							|  |  |  | #				ignored if explicit templates are given. | 
					
						
							|  |  |  | #			... | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #---------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2023-03-08 04:30:17 +03:00
										 |  |  | # load config... | 
					
						
							| 
									
										
										
										
											2023-03-12 00:38:04 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 04:30:17 +03:00
										 |  |  | CONFIG=${CONFIG:=$(basename ${0%.*}).cfg} | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | # prepend CFG_ to settings in config... | 
					
						
							|  |  |  | # NOTE: this is done to prevent them overriding the environment... | 
					
						
							| 
									
										
										
										
											2023-03-08 04:30:17 +03:00
										 |  |  | [ -e $CONFIG ] \
 | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | 	&& eval $(cat "$CONFIG" \
 | 
					
						
							| 
									
										
										
										
											2023-03-12 00:38:04 +03:00
										 |  |  | 		| sed -e 's/^\(\s*\)\([A-Z_]\+=\)/\1CFG_\2/') | 
					
						
							| 
									
										
										
										
											2023-03-08 04:30:17 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | # defaults... | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2023-03-08 04:30:17 +03:00
										 |  |  | # NOTE: all of these options can be either set in the $CONFIG file or  | 
					
						
							|  |  |  | #		set in the script env. | 
					
						
							|  |  |  | # NOTE: env takes priority over $CONFIG | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | # if set add pdf annotations of paths to each image... | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | ANOTATE_IMAGE_PATHS=${ANOTATE_IMAGE_PATHS:=$CFG_ANOTATE_IMAGE_PATHS} | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | ANOTATE_IMAGE_PATHS=${ANOTATE_IMAGE_PATHS:=} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # supported formats/extensions... | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | TEXT_FORMATS=${TEXT_FORMATS:=$CFG_TEXT_FORMATS} | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | TEXT_FORMATS=${TEXT_FORMATS:=txt} | 
					
						
							| 
									
										
										
										
											2023-06-26 14:47:10 +03:00
										 |  |  | TEXT_FORMATS=${TEXT_FORMATS,,} | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | IMAGE_FORMATS=${IMAGE_FORMATS:=$CFG_IMAGE_FORMATS} | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | IMAGE_FORMATS=${IMAGE_FORMATS:=jpeg|jpg|png|pdf|svg|eps} | 
					
						
							| 
									
										
										
										
											2023-06-26 14:47:10 +03:00
										 |  |  | IMAGE_FORMATS=${IMAGE_FORMATS,,} | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | SPREADS_DIR=${SPREADS_DIR:=$CFG_SPREADS_DIR} | 
					
						
							| 
									
										
										
										
											2023-03-11 00:39:38 +03:00
										 |  |  | SPREADS_DIR=${SPREADS_DIR:=spreads/} | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | IMAGE_HIRES_DIR=${IMAGE_HIRES_DIR:=$CFG_IMAGE_HIRES_DIR} | 
					
						
							| 
									
										
										
										
											2023-03-08 04:00:02 +03:00
										 |  |  | IMAGE_HIRES_DIR=${IMAGE_HIRES_DIR:=} | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | CAPTION_DIR=${CAPTION_DIR:=$CFG_CAPTION_DIR} | 
					
						
							| 
									
										
										
										
											2023-03-08 04:00:02 +03:00
										 |  |  | CAPTION_DIR=${CAPTION_DIR:=captions/} | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | TEMPLATE_DIR=${TEMPLATE_DIR:=$CFG_TEMPLATE_DIR} | 
					
						
							| 
									
										
										
										
											2023-03-08 04:00:02 +03:00
										 |  |  | TEMPLATE_DIR=${TEMPLATE_DIR:=templates/} | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 12:07:15 +03:00
										 |  |  | # Default templates | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | # NOTE: if a template is not found we will try and build a spread from  | 
					
						
							|  |  |  | #		page components... | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # page templates... | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | EMPTY_PAGE=${EMPTY_PAGE:=$CFG_EMPTY_PAGE} | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | EMPTY_PAGE=${EMPTY_PAGE:=emptypage} | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | TEXT_PAGE=${TEXT_PAGE:=$CFG_TEXT_PAGE} | 
					
						
							| 
									
										
										
										
											2023-03-08 04:30:17 +03:00
										 |  |  | TEXT_PAGE=${TEXT_PAGE:=textpage} | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | IMAGE_PAGE=${IMAGE_PAGE:=$CFG_IMAGE_PAGE} | 
					
						
							| 
									
										
										
										
											2023-03-08 04:30:17 +03:00
										 |  |  | IMAGE_PAGE=${IMAGE_PAGE:=imagepage} | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | # dynamic spread templates... | 
					
						
							| 
									
										
										
										
											2023-03-08 04:30:17 +03:00
										 |  |  | # NOTE: the index here corresponds to the number of images found in a  | 
					
						
							|  |  |  | #		spread directory... | 
					
						
							| 
									
										
										
										
											2023-03-09 02:29:00 +03:00
										 |  |  | if [ ${#IMAGE_SPREAD[@]} = 0 ] ; then | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 	if [ ${#CFG_IMAGE_SPREAD[@]} != 0 ] ; then | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | 		IMAGE_SPREAD=() | 
					
						
							|  |  |  | 		for i in ${!CFG_IMAGE_SPREAD[@]} ; do | 
					
						
							|  |  |  | 			IMAGE_SPREAD[$i]=${CFG_IMAGE_SPREAD[$i]} | 
					
						
							|  |  |  | 		done | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		IMAGE_SPREAD=( | 
					
						
							|  |  |  | 			[0]=text-spread | 
					
						
							|  |  |  | 			[2]=image-image | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2023-03-09 02:29:00 +03:00
										 |  |  | fi | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #---------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | printhelp(){ | 
					
						
							|  |  |  | 	echo "Usage: `basename $0` [ARGUMENTS] [PATH]" | 
					
						
							| 
									
										
										
										
											2023-03-08 05:40:04 +03:00
										 |  |  | 	echo "       `basename $0` [ARGUMENTS] PATH INDEX" | 
					
						
							|  |  |  | 	echo "       `basename $0` [ARGUMENTS] PATH FROM COUNT" | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 	echo | 
					
						
							| 
									
										
										
										
											2021-09-08 00:07:23 +03:00
										 |  |  | 	echo "Generate LaTeX layout from directory structure." | 
					
						
							|  |  |  | 	echo | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 	echo "Arguments:" | 
					
						
							|  |  |  | 	echo "  -h --help   - print this help and exit." | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 	echo "  -c PATH     - load configuration from PATH." | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | 	echo "  -a --annotate" | 
					
						
							|  |  |  | 	echo "              - add annotations with image paths to pages." | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 	echo "  --templates PATH" | 
					
						
							| 
									
										
										
										
											2023-03-08 04:00:02 +03:00
										 |  |  | 	echo "              - path to search for templates (default: $TEMPLATE_DIR)." | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 	echo "  --single-image-tpl NAME" | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | 	echo "              - single image default template (default: ${IMAGE_SPREAD[1]})." | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 	echo "  --double-image-tpl NAME" | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | 	echo "              - double image default template (default: ${IMAGE_SPREAD[2]})." | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 	echo "  --text-spread-tpl NAME" | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | 	echo "              - text spread default template (default: ${IMAGE_SPREAD[0]})." | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 	echo "  --captions PATH" | 
					
						
							| 
									
										
										
										
											2023-03-08 04:00:02 +03:00
										 |  |  | 	echo "              - path to search for captions (default: $CAPTION_DIR)." | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 	echo | 
					
						
							|  |  |  | 	echo "Parameters:" | 
					
						
							| 
									
										
										
										
											2023-03-11 00:39:38 +03:00
										 |  |  | 	echo "  PATH        - path to root pages directory (default: $SPREADS_DIR)" | 
					
						
							| 
									
										
										
										
											2023-03-08 05:40:04 +03:00
										 |  |  | 	echo "  INDEX       - index of spread to generate" | 
					
						
							|  |  |  | 	echo "  FROM        - spread to start from" | 
					
						
							|  |  |  | 	echo "  COUNT       - number of spreads to generate" | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 	echo | 
					
						
							|  |  |  | 	echo "Environment:" | 
					
						
							|  |  |  | 	echo "  \$IMAGE_HIRES_DIR " | 
					
						
							|  |  |  | 	echo "              - source directory for replacement hi-res images." | 
					
						
							| 
									
										
										
										
											2021-09-08 04:37:44 +03:00
										 |  |  | 	echo "  \$ANOTATE_IMAGE_PATHS " | 
					
						
							|  |  |  | 	echo "              - if true add image paths in anotations." | 
					
						
							| 
									
										
										
										
											2023-03-08 05:20:25 +03:00
										 |  |  | 	echo "  \$CONFIG     - sets the config file name (default: $CONFIG)" | 
					
						
							|  |  |  | 	echo "  \$TEXT_FORMATS " | 
					
						
							|  |  |  | 	echo "              - list of file extensions treated as text (default: $TEXT_FORMATS)." | 
					
						
							|  |  |  | 	echo "  \$IMAGE_FORMATS " | 
					
						
							|  |  |  | 	echo "              - list of file extensions treated as images" | 
					
						
							|  |  |  | 	echo "                (default: $IMAGE_FORMATS)." | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 	echo | 
					
						
							| 
									
										
										
										
											2023-03-08 04:30:17 +03:00
										 |  |  | 	echo "Configuration defaults can be stored in a config file: $CONFIG" | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 	echo | 
					
						
							|  |  |  | 	echo "NOTE: COUNT is relevant iff FROM is given, otherwise all available " | 
					
						
							|  |  |  | 	echo "        spreads are generated." | 
					
						
							|  |  |  | 	echo | 
					
						
							| 
									
										
										
										
											2021-09-08 00:07:23 +03:00
										 |  |  | 	echo "Examples:" | 
					
						
							|  |  |  | 	echo "  $ `basename $0` ./pages > pages.tex" | 
					
						
							|  |  |  | 	echo "              - generate a layout fron the contents of ./pages" | 
					
						
							|  |  |  | 	echo | 
					
						
							|  |  |  | 	echo "  $ IMAGE_HIRES_DIR=images/hi-res `basename $0` ./pages" | 
					
						
							|  |  |  | 	echo "              - generate a layout fron the contents of ./pages and " | 
					
						
							|  |  |  | 	echo "                replaceing local images with images in ./images/hi-res" | 
					
						
							|  |  |  | 	echo | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
					
						
							|  |  |  | # handle arguments... | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | while true ; do | 
					
						
							|  |  |  | 	case $1 in | 
					
						
							|  |  |  | 		-h|--help) | 
					
						
							|  |  |  | 			printhelp | 
					
						
							|  |  |  | 			exit | 
					
						
							|  |  |  | 			;; | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | 		-a|--annotate) | 
					
						
							|  |  |  | 			ANOTATE_IMAGE_PATHS=1 | 
					
						
							|  |  |  | 			shift | 
					
						
							| 
									
										
										
										
											2023-04-13 11:37:45 +03:00
										 |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | 			;; | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 		-c) | 
					
						
							|  |  |  | 			$CONFIG="$2" | 
					
						
							|  |  |  | 			[ -e "$CONFIG" ] \
 | 
					
						
							|  |  |  | 				&& source "$CONFIG" | 
					
						
							|  |  |  | 			shift 2 | 
					
						
							| 
									
										
										
										
											2023-04-13 11:37:45 +03:00
										 |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 			;; | 
					
						
							| 
									
										
										
										
											2021-09-08 00:07:23 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 		--templates) | 
					
						
							| 
									
										
										
										
											2023-03-08 04:00:02 +03:00
										 |  |  | 			TEMPLATE_DIR=$2 | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 			shift 2 | 
					
						
							| 
									
										
										
										
											2023-04-13 11:37:45 +03:00
										 |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 			;; | 
					
						
							|  |  |  | 		--single-image-tpl) | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | 			IMAGE_SPREAD[1]=$2 | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 			shift 2 | 
					
						
							| 
									
										
										
										
											2023-04-13 11:37:45 +03:00
										 |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 			;; | 
					
						
							|  |  |  | 		--double-image-tpl) | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | 			IMAGE_SPREAD[2]=$2 | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 			shift 2 | 
					
						
							| 
									
										
										
										
											2023-04-13 11:37:45 +03:00
										 |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 			;; | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 		--text-spread-tpl) | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | 			IMAGE_SPREAD[0]=$2 | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 			shift 2 | 
					
						
							| 
									
										
										
										
											2023-04-13 11:37:45 +03:00
										 |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 			;; | 
					
						
							| 
									
										
										
										
											2023-03-08 04:00:02 +03:00
										 |  |  | 		--captions) | 
					
						
							|  |  |  | 			CAPTION_DIR=$2 | 
					
						
							| 
									
										
										
										
											2023-03-12 00:45:46 +03:00
										 |  |  | 			shift 2 | 
					
						
							| 
									
										
										
										
											2023-04-13 11:37:45 +03:00
										 |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2023-03-08 04:00:02 +03:00
										 |  |  | 			;; | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-20 00:26:26 +03:00
										 |  |  | 		# handle unknown options... | 
					
						
							|  |  |  | 		-*|--*) | 
					
						
							| 
									
										
										
										
											2023-04-13 11:37:45 +03:00
										 |  |  | 			echo "Error: unknown option \"$1\"" >&2 | 
					
						
							| 
									
										
										
										
											2021-11-20 00:26:26 +03:00
										 |  |  | 			exit | 
					
						
							|  |  |  | 			;; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 		*) | 
					
						
							|  |  |  | 			break | 
					
						
							|  |  |  | 			;; | 
					
						
							|  |  |  | 	esac | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ -z $1 ] ; then | 
					
						
							| 
									
										
										
										
											2023-03-11 11:51:25 +03:00
										 |  |  | 	SPREADS_DIR=spreads/ | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | else | 
					
						
							| 
									
										
										
										
											2023-03-11 00:39:38 +03:00
										 |  |  | 	SPREADS_DIR=$1/ | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 04:37:44 +03:00
										 |  |  | # calculate spread index range... | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | # XXX add support for negative indexing... | 
					
						
							|  |  |  | FROM=$2 | 
					
						
							|  |  |  | COUNT=$( [ -z $3 ] && echo 1 || echo $3 ) | 
					
						
							|  |  |  | STOP=$(( FROM + COUNT )) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 05:20:25 +03:00
										 |  |  | # prep format regexps... | 
					
						
							|  |  |  | TEXT_FORMATS='.*\.('$TEXT_FORMATS')$' | 
					
						
							|  |  |  | IMAGE_FORMATS='.*\.('$IMAGE_FORMATS')$' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #---------------------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 04:06:27 +03:00
										 |  |  | # Get image caption... | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | # usage: | 
					
						
							|  |  |  | #	getCaption SPREAD IMAGE | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | getCaption(){ | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 	local spread=$1 | 
					
						
							|  |  |  | 	local name=`basename "${2%.*}"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	local captions=( | 
					
						
							| 
									
										
										
										
											2023-03-08 04:00:02 +03:00
										 |  |  | 		"$CAPTION_DIR/${name}.txt" | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 		"${spread}/${name}.txt" | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	local caption | 
					
						
							|  |  |  | 	for caption in "${captions[@]}" ; do | 
					
						
							|  |  |  | 		if [ -e "${caption}" ] ; then | 
					
						
							|  |  |  | 			echo ${caption} | 
					
						
							|  |  |  | 			return | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 	done | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 04:06:27 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Read/print caption text... | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | # usage: | 
					
						
							|  |  |  | #	readCaption PATH | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | readCaption(){ | 
					
						
							|  |  |  | 	[ -z "$1" ] \
 | 
					
						
							|  |  |  | 		&& return 1 | 
					
						
							|  |  |  | 	cat "$1" \
 | 
					
						
							|  |  |  | 		| sed -e 's/\\/\\\\\\/g' | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 04:06:27 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Get template... | 
					
						
							|  |  |  | # usage: | 
					
						
							|  |  |  | #	getTemplate SPREAD TYPE | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | getTemplate(){ | 
					
						
							| 
									
										
										
										
											2023-03-17 18:38:25 +03:00
										 |  |  | 	local spread=$1 | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 	local name=$2 | 
					
						
							| 
									
										
										
										
											2023-03-17 18:38:25 +03:00
										 |  |  | 	local template | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 	if [[ $name =~ .*\.tex ]] ; then  | 
					
						
							|  |  |  | 		# already an existing template... | 
					
						
							|  |  |  | 		if [ -e "$name" ] ; then | 
					
						
							|  |  |  | 			echo $name | 
					
						
							|  |  |  | 			return | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 		# normalize... | 
					
						
							|  |  |  | 		name=${name%.tex} | 
					
						
							| 
									
										
										
										
											2023-03-17 18:38:25 +03:00
										 |  |  | 	# normalize template name... | 
					
						
							| 
									
										
										
										
											2023-03-18 02:50:16 +03:00
										 |  |  | 	elif [[ $name =~ .*\.tpl ]] ; then | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 		name=$( echo $name \
 | 
					
						
							| 
									
										
										
										
											2023-03-17 18:38:25 +03:00
										 |  |  | 			| sed \
 | 
					
						
							|  |  |  | 				-e 's/.tpl$//' \
 | 
					
						
							|  |  |  | 				-e "s%$spread/%%" \
 | 
					
						
							|  |  |  | 				-e 's/^[0-9]\+-//' ) | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# local template... | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 	template=($spread/*-$name.tex) | 
					
						
							| 
									
										
										
										
											2023-03-17 18:38:25 +03:00
										 |  |  | 	if [ ${#template[@]} != 0 ] ; then | 
					
						
							|  |  |  | 		template=${template[0]} | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 		template=($spread/$name.tex) | 
					
						
							| 
									
										
										
										
											2023-03-08 04:06:27 +03:00
										 |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2023-03-17 18:38:25 +03:00
										 |  |  | 	# global template... | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 	if [ -z $template ] \
 | 
					
						
							|  |  |  | 			|| ! [ -e "$template" ] ; then | 
					
						
							|  |  |  | 		 template="$TEMPLATE_DIR/${name}.tex" | 
					
						
							| 
									
										
										
										
											2023-03-08 04:06:27 +03:00
										 |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2023-03-17 18:38:25 +03:00
										 |  |  | 	# check if the thing exists... | 
					
						
							|  |  |  | 	if ! [ -e $template ] ; then | 
					
						
							|  |  |  | 		return 1 | 
					
						
							| 
									
										
										
										
											2023-03-08 04:06:27 +03:00
										 |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2023-03-17 18:38:25 +03:00
										 |  |  | 	echo $template | 
					
						
							| 
									
										
										
										
											2023-03-08 04:06:27 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Get template slots (cached)... | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | # usage: | 
					
						
							|  |  |  | #	templateSlots TEMPLATE | 
					
						
							| 
									
										
										
										
											2023-03-04 22:50:08 +03:00
										 |  |  | declare -A TEMPLATE_INDEX | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | templateSlots(){ | 
					
						
							| 
									
										
										
										
											2023-03-05 22:29:54 +03:00
										 |  |  | 	# cache the vars... | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | 	#if [ ${TEMPLATE_INDEX[$1]+_} ] ; then | 
					
						
							|  |  |  | 	if [ -z ${TEMPLATE_INDEX[$1]} ] ; then | 
					
						
							| 
									
										
										
										
											2023-03-05 01:50:13 +03:00
										 |  |  | 		TEMPLATE_INDEX[$1]=$(cat "$1" \
 | 
					
						
							| 
									
										
										
										
											2023-03-06 02:08:47 +03:00
										 |  |  | 			| grep -o '\${[A-Z0-9_]\+}' \
 | 
					
						
							| 
									
										
										
										
											2023-03-05 01:50:13 +03:00
										 |  |  | 			| sed 's/\${\(.*\)}/\1/g' \
 | 
					
						
							| 
									
										
										
										
											2023-03-08 02:49:40 +03:00
										 |  |  | 			| sort -V) | 
					
						
							| 
									
										
										
										
											2023-03-05 01:50:13 +03:00
										 |  |  | 	fi | 
					
						
							|  |  |  | 	echo ${TEMPLATE_INDEX[$1]} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 04:06:27 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | # Populate template image/text slots | 
					
						
							|  |  |  | # usage: | 
					
						
							|  |  |  | #	populateTemplate SPREAD TEMPLATE ITEMS... | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2023-03-06 02:08:47 +03:00
										 |  |  | populateTemplate(){ | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 	local spread="$1" | 
					
						
							|  |  |  | 	local tpl="$2" | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 	[ -e "$tpl" ] \
 | 
					
						
							|  |  |  | 		|| return 1 | 
					
						
							| 
									
										
										
										
											2023-03-06 02:08:47 +03:00
										 |  |  | 	local slots=( $(templateSlots "${tpl}") ) | 
					
						
							|  |  |  | 	local text=$(cat "${tpl}") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 	# items/img/txt... | 
					
						
							|  |  |  | 	shift 2 | 
					
						
							|  |  |  | 	local items=("$@") | 
					
						
							|  |  |  | 	if [ ${#items[@]} = 0 ] ; then | 
					
						
							|  |  |  | 		items=( $spread/* ) | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	local img=() | 
					
						
							|  |  |  | 	local txt=() | 
					
						
							|  |  |  | 	local elem | 
					
						
							|  |  |  | 	for elem in "${items[@]}" ; do | 
					
						
							| 
									
										
										
										
											2023-06-26 14:47:10 +03:00
										 |  |  | 		if [[ "${elem,,}" =~ $IMAGE_FORMATS ]] ; then | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 			img+=("$elem") | 
					
						
							| 
									
										
										
										
											2023-06-26 14:47:10 +03:00
										 |  |  | 		elif [[ "${elem,,}" =~ $TEXT_FORMATS ]] ; then | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 			txt+=("$elem") | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 	done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 02:08:47 +03:00
										 |  |  | 	local var | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 	local val | 
					
						
							|  |  |  | 	local index=() | 
					
						
							|  |  |  | 	local captions=() | 
					
						
							|  |  |  | 	local name | 
					
						
							|  |  |  | 	# pass 1: images... | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 	# NOTE: we are doing this in three passes as caption and image slots | 
					
						
							|  |  |  | 	#		can be included in the template in any order but the captions | 
					
						
							|  |  |  | 	#		need all the images to be fully populated/indexed (passes 1  | 
					
						
							|  |  |  | 	#		and 2), and text is done as a separate pass to prevent it  | 
					
						
							|  |  |  | 	#		from competing with captions. | 
					
						
							| 
									
										
										
										
											2023-03-06 02:08:47 +03:00
										 |  |  | 	local i=0 | 
					
						
							|  |  |  | 	for var in ${slots[@]} ; do | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 		name=${var//[0-9]/} | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 		if [ ${name} != "IMAGE" ] ; then | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 			continue | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		val=${img[$i]} | 
					
						
							|  |  |  | 		# index images for caption retrieval... | 
					
						
							|  |  |  | 		index[${var/$name/}]="$val" | 
					
						
							|  |  |  | 		# warn if no image found for slot... | 
					
						
							|  |  |  | 		if [ -z ${val} ] ; then | 
					
						
							|  |  |  | 			echo % | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				echo "% WARNING: image #${i} requested but not found" | 
					
						
							|  |  |  | 				echo "%     in: ${tpl}" | 
					
						
							|  |  |  | 				echo "%     by: ${spread}" | 
					
						
							|  |  |  | 			} | tee >(cat >&2) | 
					
						
							|  |  |  | 			echo % | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 		i=$(( i + 1 )) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | 		val=${val//\//\\/} | 
					
						
							| 
									
										
										
										
											2023-03-13 20:12:15 +03:00
										 |  |  | 		text=$(echo "${text}" | \
 | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | 			sed "s/\${${var}}/${val%.*}/g") | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 	done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# pass 2: captions... | 
					
						
							|  |  |  | 	for var in ${slots[@]} ; do | 
					
						
							|  |  |  | 		name=${var//[0-9]/} | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 		if [ ${name} != "CAPTION" ] ; then | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 			continue | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		# get global caption... | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 		val=$(getCaption "$spread" "${index[${var/$name/}]}" "${txt[@]}") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if [ -n "${val}" ] ; then | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | 			# clear the used texts... (XXX test) | 
					
						
							|  |  |  | 			for i in "${!txt[@]}" ; do | 
					
						
							|  |  |  | 				[ "$val" = "${txt[$i]}" ] \
 | 
					
						
							|  |  |  | 					&& unset "txt[$i]" | 
					
						
							|  |  |  | 			done | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 			val=$(readCaption "${val}") | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 		fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-13 20:12:15 +03:00
										 |  |  | 		text=$(echo "${text}" | \
 | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 			sed "s/\${${var}}/${val}/g") | 
					
						
							|  |  |  | 	done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# pass 3: texts... | 
					
						
							|  |  |  | 	for var in ${slots[@]} ; do | 
					
						
							|  |  |  | 		name=${var//[0-9]/} | 
					
						
							|  |  |  | 		if [ ${name} = "CAPTION" ] || [ ${name} = "IMAGE" ] ; then | 
					
						
							|  |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2023-03-06 02:08:47 +03:00
										 |  |  | 		fi | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		val= | 
					
						
							|  |  |  | 		for i in ${!txt[@]} ; do | 
					
						
							|  |  |  | 			# NOTE: we do not care as much if not text is found... | 
					
						
							|  |  |  | 			val=${txt[$i]} | 
					
						
							|  |  |  | 			unset "txt[$i]" | 
					
						
							|  |  |  | 			# we only need the first text... | 
					
						
							|  |  |  | 			break | 
					
						
							|  |  |  | 		done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | 		val=${val//\//\\/} | 
					
						
							| 
									
										
										
										
											2023-03-13 20:12:15 +03:00
										 |  |  | 		text=$(echo "${text}" | \
 | 
					
						
							| 
									
										
										
										
											2023-03-06 02:08:47 +03:00
										 |  |  | 			sed "s/\${${var}}/${val}/g") | 
					
						
							|  |  |  | 	done | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 	# print out the filled template... | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | 	echo % template: $tpl | 
					
						
							| 
									
										
										
										
											2023-03-13 20:12:15 +03:00
										 |  |  | 	echo "${text}" | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 	return | 
					
						
							| 
									
										
										
										
											2023-03-06 02:08:47 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-03-04 22:50:08 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 04:06:27 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Handle/print spread... | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | # usage: | 
					
						
							|  |  |  | #	handleSpread SPREAD | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | # closure: $IMAGE_HIRES_DIR, $IMAGE_SPREAD | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | handleSpread(){ | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 	local spread="$1" | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 	# skip non-spreads... | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 	[ -d "$spread" ] \
 | 
					
						
							|  |  |  | 		|| return 1 | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	# auto layout / templates... | 
					
						
							|  |  |  | 	# NOTE: to use a specific template just `touch <template-name>.tpl` | 
					
						
							|  |  |  | 	#	in the spread directory... | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# layout tweaks... | 
					
						
							|  |  |  | 	local tweaks=($spread/*tweak.tex) | 
					
						
							|  |  |  | 	if ! [ -z ${tweaks} ] ; then | 
					
						
							|  |  |  | 		echo "% tweaks: ${tweaks[0]}" | 
					
						
							|  |  |  | 		cat ${tweaks[0]} | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# collect images and text... | 
					
						
							|  |  |  | 	# NOTE: we are filling these manually to support configurable  | 
					
						
							|  |  |  | 	#		image/text patterns... | 
					
						
							|  |  |  | 	local img=() | 
					
						
							|  |  |  | 	local txt=() | 
					
						
							|  |  |  | 	local items=() | 
					
						
							|  |  |  | 	for elem in "$spread"/* ; do | 
					
						
							| 
									
										
										
										
											2023-06-26 14:47:10 +03:00
										 |  |  | 		if [[ "${elem,,}" =~ $IMAGE_FORMATS ]] ; then | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 			img+=("$elem") | 
					
						
							|  |  |  | 			items+=("$elem") | 
					
						
							| 
									
										
										
										
											2023-06-26 14:47:10 +03:00
										 |  |  | 		elif [[ "${elem,,}" =~ $TEXT_FORMATS ]] ; then | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 			txt+=("$elem") | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 			items+=("$elem") | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 	done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# get hi-res image paths... | 
					
						
							|  |  |  | 	if ! [ -z $IMAGE_HIRES_DIR ] ; then | 
					
						
							|  |  |  | 		local C=0 | 
					
						
							|  |  |  | 		for image in "${img[@]}" ; do | 
					
						
							|  |  |  | 			# skip non-images... | 
					
						
							|  |  |  | 			local new="$IMAGE_HIRES_DIR/`basename ${image/[0-9]-/}`" | 
					
						
							|  |  |  | 			# ignore file ext for availability test... | 
					
						
							|  |  |  | 			# NOTE: the first match may be an unsupported format... | 
					
						
							|  |  |  | 			new="${new%.*}" | 
					
						
							|  |  |  | 			new=($new.*) | 
					
						
							|  |  |  | 			if [ -e "${new[0]}" ] ; then | 
					
						
							|  |  |  | 				img[$C]=${new[0]} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				echo % | 
					
						
							|  |  |  | 				echo "% WARNING: hi-res image not found for: \"${image}\" -> \"${new}\"" \
 | 
					
						
							|  |  |  | 					| tee >(cat >&2) | 
					
						
							|  |  |  | 				echo % | 
					
						
							|  |  |  | 			fi | 
					
						
							|  |  |  | 			C=$(( C + 1 )) | 
					
						
							|  |  |  | 		done | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# manual layout... | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 	local template | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 	local layout=( $spread/*layout.tex ) | 
					
						
							|  |  |  | 	if ! [ -z $layout ] ; then | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 		template=${layout[0]} | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	# templates and partial templates... | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		local template=( $spread/*.tpl ) | 
					
						
							|  |  |  | 		# skip page template refs: *-imagepage.tpl / *-textpage.tpl | 
					
						
							|  |  |  | 		# XXX this will also eat 0-imagepage.tpl / 20-textpage.tpl -- do a better pattern... | 
					
						
							|  |  |  | 		if ! [ -z $template ] ; then | 
					
						
							|  |  |  | 			template=(`ls "$spread/"*.tpl \
 | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | 				| egrep -v '.*-('${IMAGE_PAGE}'|'${TEXT_PAGE}')\.tpl'`) | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 		fi | 
					
						
							|  |  |  | 		# no template explicitly defined -> match auto-template... | 
					
						
							|  |  |  | 		if [ -z $layout ] && [ -z $template ] ; then | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | 			# N images... | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | 			if [ -z $template ] && [ -n "${IMAGE_SPREAD[${#img[@]}]}" ] ; then | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | 				template=$(getTemplate "$spread" "${IMAGE_SPREAD[${#img[@]}]}") | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 			fi | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 			# build spread from pages... | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 			if [ -z $template ] ; then | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 				local C=0 | 
					
						
							|  |  |  | 				local P | 
					
						
							|  |  |  | 				local elem | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | 				# only one page in spread... | 
					
						
							|  |  |  | 				# NOTE since the right page is more important we prioritize  | 
					
						
							|  |  |  | 				#		it over the left page, placing the blank left... | 
					
						
							|  |  |  | 				if [ ${#items[@]} = 1 ] ; then | 
					
						
							|  |  |  | 					C=1 | 
					
						
							|  |  |  | 					echo "%" | 
					
						
							|  |  |  | 					echo "% empty page..." | 
					
						
							|  |  |  | 					template=$(getTemplate "$spread" "$EMPTY_PAGE") | 
					
						
							|  |  |  | 					if [ -z "$teplate" ] ; then | 
					
						
							|  |  |  | 						echo "\\null" | 
					
						
							|  |  |  | 						echo "\\newpage" | 
					
						
							|  |  |  | 					else | 
					
						
							|  |  |  | 						cat "${template}" | 
					
						
							|  |  |  | 					fi | 
					
						
							|  |  |  | 				fi | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 				for elem in "${items[@]}" ; do | 
					
						
							|  |  |  | 					C=$(( C + 1 )) | 
					
						
							|  |  |  | 					P=$([ $C == 1 ] \
 | 
					
						
							|  |  |  | 						&& echo "left" \
 | 
					
						
							|  |  |  | 						|| echo "right") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 					# XXX need to use populateTemplate here... | 
					
						
							|  |  |  | 					#		...to do this need to somehow remove the used | 
					
						
							|  |  |  | 					#		slots/files from list... | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 					# image... | 
					
						
							| 
									
										
										
										
											2023-06-26 14:47:10 +03:00
										 |  |  | 					if [[ "${elem,,}" =~ $IMAGE_FORMATS ]] ; then | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 						echo % | 
					
						
							|  |  |  | 						echo "% $P page (image)..." | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | 						template=`getTemplate "$spread" "$IMAGE_PAGE"` | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | 						echo % template: $template | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 						anotatePath "${elem}" | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 						local caption=$(getCaption "$spread" "${elem}") | 
					
						
							|  |  |  | 						caption=$(readCaption "$caption") | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 						cat "${template}" \
 | 
					
						
							|  |  |  | 							| sed -e "s%\${IMAGE0\?}%${elem%.*}%" \
 | 
					
						
							|  |  |  | 								-e "s%\${CAPTION0\?}%${caption}%" | 
					
						
							|  |  |  | 					# text... | 
					
						
							|  |  |  | 					else | 
					
						
							|  |  |  | 						echo % | 
					
						
							|  |  |  | 						echo "% $P page (text)..." | 
					
						
							| 
									
										
										
										
											2023-03-08 03:30:51 +03:00
										 |  |  | 						template=$(getTemplate "$spread" "$TEXT_PAGE") | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | 						echo % template: $template | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 						cat "${template}" \
 | 
					
						
							|  |  |  | 							| sed "s%\${TEXT}%${elem}%" | 
					
						
							|  |  |  | 					fi | 
					
						
							|  |  |  | 					# reset for next page... | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 					template= | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 					# ignore the rest of the items when we are done  | 
					
						
							|  |  |  | 					# creating two pages... | 
					
						
							|  |  |  | 					[ $C == 2 ] \
 | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 						&& return | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 				done | 
					
						
							|  |  |  | 			fi | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 		# formatting done... | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 		[ -z $template ] \
 | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 			&& return | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 		# resolve the template path... | 
					
						
							|  |  |  | 		local p=$template | 
					
						
							| 
									
										
										
										
											2023-03-17 18:38:25 +03:00
										 |  |  | 		template=$(getTemplate "$spread" "$template") | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		# not found... | 
					
						
							|  |  |  | 		if [ -z $template ] ; then | 
					
						
							|  |  |  | 			echo "%" | 
					
						
							|  |  |  | 			echo "% ERROR: could not resolve template: $p" | tee >(cat >&2) | 
					
						
							|  |  |  | 			echo "%" | 
					
						
							|  |  |  | 		fi | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | 	fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	populateTemplate "$spread" "$template" "${img[@]}" "${txt[@]}" | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-17 19:30:27 +03:00
										 |  |  | 	return $? | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 20:40:41 +03:00
										 |  |  | # Add pdf notes with image path used in template | 
					
						
							|  |  |  | # usage: | 
					
						
							|  |  |  | #	anotatePath PATH | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | anotatePath(){ | 
					
						
							|  |  |  | 	if [ -z "$1" ] || [ -z "$ANOTATE_IMAGE_PATHS" ] ; then | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	path=$(basename ${1%.*}) | 
					
						
							|  |  |  | 	# NOTE: did not figure out how to make a verbatim comment in latex  | 
					
						
							|  |  |  | 	#		so here we are, doing it in shell... | 
					
						
							|  |  |  | 	path=${path//_/\\_} | 
					
						
							| 
									
										
										
										
											2021-09-08 18:52:23 +03:00
										 |  |  | 	#echo "\\pdfmargincomment{Image: $path}%" | 
					
						
							|  |  |  | 	echo "\\pdfcommentcell{Image: $path}%" | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-05 01:50:13 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | #---------------------------------------------------------------------- | 
					
						
							|  |  |  | # generate the template... | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | echo %---------------------------------------------------------------------- | 
					
						
							|  |  |  | echo % | 
					
						
							| 
									
										
										
										
											2023-03-11 02:24:31 +03:00
										 |  |  | echo % WARNING: This file is auto-generated by make-spreads.sh and will be  | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | echo "%          overwritten on next run..." | 
					
						
							|  |  |  | echo % | 
					
						
							| 
									
										
										
										
											2023-03-11 00:39:38 +03:00
										 |  |  | echo "% Image source (preview): \"$SPREADS_DIR\"" | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | echo "% Image source (hi-res): \"$IMAGE_HIRES_DIR\"" | 
					
						
							|  |  |  | echo % | 
					
						
							|  |  |  | echo %---------------------------------------------------------------------- | 
					
						
							|  |  |  | echo % | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-11 00:39:38 +03:00
										 |  |  | l=$(ls "$SPREADS_DIR/" | wc -l) | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | c=0 | 
					
						
							|  |  |  | d=0 | 
					
						
							| 
									
										
										
										
											2023-03-11 00:39:38 +03:00
										 |  |  | SPREADS=("$(ls "${SPREADS_DIR}" | sort -n)") | 
					
						
							| 
									
										
										
										
											2023-03-08 04:00:02 +03:00
										 |  |  | for spread in ${SPREADS[@]} ; do | 
					
						
							| 
									
										
										
										
											2023-03-11 00:39:38 +03:00
										 |  |  | 	spread="${SPREADS_DIR}/${spread}" | 
					
						
							| 
									
										
										
										
											2023-03-08 04:00:02 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 	# skip non-spreads... | 
					
						
							|  |  |  | 	if ! [ -d "$spread" ] ; then | 
					
						
							| 
									
										
										
										
											2023-03-08 05:22:52 +03:00
										 |  |  | 		l=$(( l - 1 )) | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 		continue | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | 	# skip temporarily disabled... | 
					
						
							| 
									
										
										
										
											2023-03-08 20:08:57 +03:00
										 |  |  | 	elif [[ "${spread}" =~ [\\\/]-.*$ ]] ; then | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | 		SKIP_FIRST=1 | 
					
						
							| 
									
										
										
										
											2023-03-08 20:08:57 +03:00
										 |  |  | 		echo "% spread: ${spread}: skipped..." | tee >(cat >&2) | 
					
						
							| 
									
										
										
										
											2023-03-08 05:12:58 +03:00
										 |  |  | 		continue | 
					
						
							|  |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	c=$(( c + 1 )) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# if $FROM is given print only stuff in range... | 
					
						
							|  |  |  | 	[ -z $FROM ] \
 | 
					
						
							|  |  |  | 		|| if (( $(( c - 1 )) < $FROM )) || (( $c > $STOP )) ; then | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# if we are building only a specific spread... | 
					
						
							| 
									
										
										
										
											2023-03-11 00:39:38 +03:00
										 |  |  | 	##if ! [ -z $SPREAD ] && [[ "$spread" != "$SPREADS_DIR/$SPREAD" ]]; then | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 	##	continue | 
					
						
							|  |  |  | 	##fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ! [ -z $SKIP_FIRST ] ; then | 
					
						
							|  |  |  | 		echo % | 
					
						
							|  |  |  | 		echo % | 
					
						
							|  |  |  | 		echo % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	SKIP_FIRST=1 | 
					
						
							| 
									
										
										
										
											2023-03-08 04:00:02 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 20:08:57 +03:00
										 |  |  | 	printf "Spread ($c/$l): ${spread}                         \r" >&2 | 
					
						
							|  |  |  | 	echo "% spread: ${spread}" | 
					
						
							| 
									
										
										
										
											2023-03-07 23:00:16 +03:00
										 |  |  | 	handleSpread "$spread" | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	d=$(( d + 1 )) | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo % | 
					
						
							|  |  |  | echo % | 
					
						
							|  |  |  | echo % | 
					
						
							|  |  |  | echo %---------------------------------------------------------------------- | 
					
						
							|  |  |  | echo | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-07 23:29:23 +03:00
										 |  |  | echo "Spread created: $d of $l                                         " >&2 | 
					
						
							| 
									
										
										
										
											2021-09-07 01:29:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #---------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2023-03-08 05:35:33 +03:00
										 |  |  | #                                            vim:set ts=4 sw=4 nowrap : |