OSDN Git Service

Update Help Document. Basically clean up SVN context.
[tortoisegit/TortoiseGitJp.git] / doc / images / adjustimages.bat
1 @echo off & setlocal enableextensions enabledelayedexpansion\r
2 :: ============================================================ \r
3 :: $Id: adjustimages.bat 15164 2009-01-22 22:22:30Z simonlarge $\r
4 :: ============================================================ \r
5 :: This script verifies all .png images to see if they fit\r
6 :: in the PDF version of the documentation. The FOP version we\r
7 :: use doesn't scale images automatically when they are too\r
8 :: wide or high.\r
9 :: We want images to be at most 5.75 inches wide and 9 inches\r
10 :: high.\r
11 :: The script retrieves the DPI setting in the image and\r
12 :: and calculates the actual size of the image. If it exceeds\r
13 :: the limits, the DPI setting of the image is increased to\r
14 :: fit the limits.\r
15 ::\r
16 :: By default all images in all languages will be checked.\r
17 :: You can specify a group of files to check using the first\r
18 :: parameter, e.g.\r
19 ::     adjustimages en\Rev*.png\r
20 ::\r
21 :: The image manipulation is done using NConvert.exe from\r
22 :: http://www.xnview.com\r
23 :: ============================================================ \r
24 :: Set image size limits in 1000ths of an inch\r
25 set /a w_limit = 5750\r
26 set /a h_limit = 9000\r
27 ::\r
28 ::\r
29 if '%1' == '' goto :DoDefault\r
30 for %%? in (%1) do Call :ProcAdjustFile %%?\r
31 endlocal & goto:EOF\r
32 ::\r
33 :DoDefault\r
34 for %%? in (de\*.png) do Call :ProcAdjustFile %%?\r
35 for %%? in (en\*.png) do Call :ProcAdjustFile %%?\r
36 for %%? in (es\*.png) do Call :ProcAdjustFile %%?\r
37 for %%? in (fi\*.png) do Call :ProcAdjustFile %%?\r
38 for %%? in (fr\*.png) do Call :ProcAdjustFile %%?\r
39 for %%? in (id\*.png) do Call :ProcAdjustFile %%?\r
40 for %%? in (ja\*.png) do Call :ProcAdjustFile %%?\r
41 for %%? in (ru\*.png) do Call :ProcAdjustFile %%?\r
42 :: Cleanup\r
43 for %%? in (f_info.txt) do if exist %%? del %%?\r
44 endlocal & goto :EOF\r
45 ::===============================================================\r
46 :ProcAdjustFile FileName\r
47 :: Extract resolution info from file\r
48 setlocal enableextensions enabledelayedexpansion\r
49 nconvert.exe -info %1>f_info.txt\r
50 ::\r
51 :: Extract image width, height and dpi\r
52 :: Width   = 3rd word on 10th line\r
53 :: Height  = 3rd word on 11th line\r
54 :: XDPI    = 3rd word on 19th line\r
55 :: YDPI    = 3rd word on 20th line\r
56 :: Do the test. Get the third word of the tenth line.\r
57 call :ProcGetLine f_info.txt 10 getLine\r
58 for /f "tokens=3" %%? in ("%getLine%") do set /a w_image = %%?\r
59 call :ProcGetLine f_info.txt 11 getLine\r
60 for /f "tokens=3" %%? in ("%getLine%") do set /a h_image = %%?\r
61 call :ProcGetLine f_info.txt 19 getLine\r
62 for /f "tokens=3" %%? in ("%getLine%") do set /a xdpi = %%?\r
63 call :ProcGetLine f_info.txt 20 getLine\r
64 for /f "tokens=3" %%? in ("%getLine%") do set /a ydpi = %%?\r
65 :: Set default dpi if no dpi was found\r
66 set /a must_convert = 0\r
67 if %xdpi% equ 0 (\r
68    set /a xdpi = 96\r
69    set /a must_convert = 1\r
70 )\r
71 if %ydpi% equ 0 (\r
72    set /a ydpi = 96\r
73    set /a must_convert = 1\r
74 )\r
75 ::\r
76 :: Calculate image width and height (factor 1000 is used because\r
77 :: of the integer math.\r
78 set /a w_image_inch = w_image * 1000 / xdpi\r
79 set /a h_image_inch = h_image * 1000 / ydpi\r
80 rem echo Image (w - h): %w_image% - %h_image%\r
81 rem echo DPI (x - y)  : %xdpi% - %ydpi%\r
82 rem echo Size (w - h) : %w_image_inch% - %h_image_inch%\r
83 set /a w_delta = w_limit - w_image_inch\r
84 set /a h_delta = h_limit - h_image_inch\r
85 rem echo Delta (w - h): %w_delta% - %h_delta%\r
86 :: If height and width are within limits, we're done\r
87 :: If not, determine direction with largest overdraw and\r
88 ::   calculate a dpi setting that will fit the image into the\r
89 ::   available space\r
90 ::   Calculation method: new_dpi = (pixels * 1000) / limit\r
91 if %w_delta% geq 0 (\r
92    if %h_delta% geq 0 (\r
93       if %must_convert% equ 1 (\r
94          echo %1: image fits with default dpi\r
95          set /a new_dpi = 95\r
96       ) else (\r
97          echo %1: image is ok\r
98          goto :Done\r
99       )\r
100    ) else (\r
101       echo %1: image too high\r
102       set /a new_dpi = h_image * 1000 / h_limit\r
103    )\r
104 ) else (\r
105    if %h_delta% geq 0 (\r
106       echo %1: image too wide\r
107       set /a new_dpi = w_image * 1000 / w_limit\r
108    ) else (\r
109       echo %1: image too wide and too high\r
110       set /a new_xdpi = w_image * 1000 / w_limit\r
111       set /a new_ydpi = h_image * 1000 / h_limit\r
112       if !new_xdpi! leq !new_ydpi! (\r
113          set /a new_dpi = !new_ydpi!\r
114       ) else (\r
115          set /a new_dpi = !new_xdpi!\r
116       )\r
117       rem echo dpi required for width !new_xdpi!\r
118       rem echo dpi required for height !new_ydpi!\r
119    )\r
120 )\r
121 :: Make sure the dpi is large enough (integer arithmetic truncates)\r
122 set /a new_dpi = new_dpi + 1\r
123 echo adjust dpi to %new_dpi%\r
124 nconvert.exe -dpi %new_dpi% %1 >nul\r
125 :Done\r
126 endlocal & goto :EOF\r
127 ::===============================================================\r
128 :ProcGetLine FileName LineNro returnText\r
129 setlocal enableextensions\r
130 set lineNro_=%2\r
131 set /a lineNro_-=1\r
132 set return_=\r
133 for /f "tokens=* skip=%lineNro_% delims=" %%r in ('type %1') do (\r
134   if not defined return_ set return_=%%r)\r
135 endlocal & set %3=%return_% & goto :EOF\r