2 # -------------------------------------
5 # -------------------------------------
6 # -------------------------------------
8 # -------------------------------------
9 c_Usage="Usage: utf82ps.sh [-p A4|A3|B5|B4|15i] [-L] [-m margin-left,right,top,bottom] [-f fontsize ] [ -l line-space% ] [ -w font-width% ] [ -g ] file"
13 d_FontSize="12" # point
14 d_LineSpace="10" # % d_FontSize / 100 * d_LineSpace
15 d_FontWidth="100" # % d_FontSize / 100 * d_FontWidth
17 c_MincyoFont="/Ryumin-Light-UniJIS-UTF8-H"
18 c_GothicFont="/GothicBBB-Medium-UniJIS-UTF8-H"
19 c_DefaultFont=$c_MincyoFont
20 #c_DefaultFont=$c_GothicFont
21 # -------------------------------------
23 # -------------------------------------
24 # 15iはおそらく使わないと思いますがサンプルとして。15iは用紙方向を変えたくないので二つともPortになってます。
25 # paper margi paper size orientation
26 # left right top bottom x y default swich
28 A4 25.4 12.7 25.4 12.7 210 297 Port Land
29 A3 25.4 12.7 25.4 12.7 297 420 Port Land
30 B5 25.4 12.7 25.4 12.7 182 257 Port Land
31 B4 25.4 12.7 25.4 12.7 257 364 Port Land
32 15i 0 0 0 0 381 279.4 Port Port
34 # -------------------------------------
36 # -------------------------------------
37 while getopts "p:Lm:f:l:w:gh" OPT
40 p) c_PaperSize=${OPTARG} ;;
41 L) c_Landscape="yes" ;;
42 m) c_PaperMargin=${OPTARG} ;;
43 f) d_FontSize=${OPTARG} ;;
44 l) d_LineSpace=${OPTARG} ;;
45 w) d_FontWidth=${OPTARG} ;;
46 g) c_DefaultFont=$c_GothicFont ;;
47 h|\?) echo "$c_Usage"; exit 1;;
50 shift `expr ${OPTIND} - 1`
51 # -------------------------------------
53 # -------------------------------------
54 if [ "${1}" != "" ]; then
57 # -------------------------------------
59 # -------------------------------------
60 if [ "${c_PaperMargin}" = "" ]; then
61 c_Table=`echo "${c_PaperTable}" | grep "${c_PaperSize}"`
64 c_Temp=`echo "${c_PaperMargin}" | sed -e s/,/"${c_tab}"/g`
65 c_Table="${c_PaperSize}$c_tab${c_Temp}"
70 d_Temp=`echo "${c_Table}" | cut -f${i}`
73 2) d_MarginLeft=${d_Temp} ;;
74 3) d_MarginRight=${d_Temp} ;;
75 4) d_MarginTop=${d_Temp} ;;
76 5) d_MarginBottom=${d_Temp} ;;
79 # -------------------------------------
81 # -------------------------------------
82 c_Table=`echo "${c_PaperTable}" | grep "${c_PaperSize}"`
86 d_Temp=`echo "${c_Table}" | cut -f${i}`
89 6) d_PaperSizeX=${d_Temp} ;;
90 7) d_PaperSizeY=${d_Temp} ;;
93 # -------------------------------------
95 # -------------------------------------
96 c_Table=`echo "${c_PaperTable}" | grep "${c_PaperSize}"`
100 d_Temp=`echo "${c_Table}" | cut -f${i}`
103 8) c_PaperOrientation=${d_Temp} ;;
104 9) if [ "${c_Landscape}" = "yes" ]; then
105 c_PaperOrientation=${d_Temp}
111 if [ "${c_PaperOrientation}" = "Land" ]; then
112 d_Temp=${d_PaperSizeX}
113 d_PaperSizeX=${d_PaperSizeY}
114 d_PaperSizeY=${d_Temp}
116 # -------------------------------------
118 # -------------------------------------
119 echo "%!PS-Adobe-3.0"
120 echo "/mm {2.834645669 mul} def"
121 echo "/d_MarginLeft ${d_MarginLeft} mm def"
122 echo "/d_MarginRight ${d_PaperSizeX} mm ${d_MarginRight} mm sub def"
123 echo "/d_MarginTop ${d_PaperSizeY} mm ${d_MarginTop} mm sub def"
124 echo "/d_MarginBottom ${d_MarginBottom} mm def"
125 echo "/d_FontSize ${d_FontSize} def"
126 echo "/d_LineSpace d_FontSize 100 div ${d_LineSpace} mul def"
127 echo "/d_FontWidth d_FontSize 100 div ${d_FontWidth} mul def"
128 echo "/c_DefaltFont ${c_DefaultFont} findfont [ d_FontWidth 0 0 d_FontSize 0 0 ] makefont def"
130 echo "/d_1ByteCh { 16#7f le } def"
131 echo "/d_2ByteCh { dup 16#cf ge exch 16#df le and } def"
132 echo "/d_3ByteCh { 16#ef le } def"
133 echo "/d_4ByteCh { dup 16#f0 ge exch 16#f7 le and } def"
134 echo "/d_5ByteCh { dup 16#f8 ge exch 16#fb le and } def"
135 echo "/d_6ByteCh { dup 16#fc ge exch 16#fd le and } def"
137 echo "/c_BeforSt { 0 exch getinterval } def"
138 echo "/d_AfterStDic 1 dict def"
143 /d_Length c_PrintSt length d_Start sub def
144 c_PrintSt d_Start d_Length getinterval
147 echo "/d_StringCutDic 1 dict def"
152 c_PrintSt 0 get d_1ByteCh { 1 /d_Byte exch def exit } if
153 c_PrintSt 0 get d_2ByteCh { 2 /d_Byte exch def exit } if
154 c_PrintSt 0 get d_3ByteCh { 3 /d_Byte exch def exit } if
155 c_PrintSt 0 get d_4ByteCh { 4 /d_Byte exch def exit } if
156 c_PrintSt 0 get d_5ByteCh { 5 /d_Byte exch def exit } if
157 c_PrintSt 0 get d_6ByteCh { 6 /d_Byte exch def exit } if
159 c_PrintSt d_Byte c_AfterSt c_PrintSt d_Byte c_BeforSt
164 echo -n "/f_NewPage { "
165 if [ "${c_PaperOrientation}" = "Land" ]; then
166 echo -n "90 rotate 0 ${d_PaperSizeY} mm -1 mul translate "
168 echo "d_MarginLeft d_MarginTop d_FontSize sub moveto } def"
169 echo "/f_NewLine { d_MarginLeft currentpoint exch pop d_FontSize sub d_LineSpace sub moveto } def"
170 echo "/f_NextString { dup length 0 gt { f_ShowStrings } { pop } ifelse } def"
171 echo "/f_ShowStrings {
173 dup stringwidth pop currentpoint pop add
174 d_MarginRight gt { f_NewLine } if
175 currentpoint exch pop d_FontSize sub
176 d_MarginBottom lt { showpage f_NewPage } if
179 echo "c_DefaltFont setfont"
181 # -------------------------------------
183 # -------------------------------------
184 c_x0a=`printf "\x0a"` # 改行
185 c_x0c=`printf "\x0c"` # 改ページ
186 c_x09=`printf "\x09"` # タブ
187 c_Tab=`printf " "` # 置換後タブ 空白8文字
188 while IFS= read -r c_Line
190 if [ "${c_Line}" = "${c_x0a}" ]; then
192 elif [ "${c_Line}" = "${c_x0c}" ]; then
193 echo "showpage f_NewPage"
196 echo -n "${c_Line}" | sed -e "s/\\\/\\\\\\\/g" -e "s/(/\\\(/g" -e "s/)/\\\)/g" -e "s/${c_x09}/${c_Tab}/g"
197 echo " ) f_ShowStrings f_NewLine"
200 # -------------------------------------
202 # -------------------------------------