Skip to content

Commit 3c55729

Browse files
committed
fix some bugs
1 parent c73da53 commit 3c55729

File tree

3 files changed

+85
-48
lines changed

3 files changed

+85
-48
lines changed

1.0/inkporter.bat

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set dpi=%5
1111

1212
if [%1]==[] goto main
1313

14-
REM pushd %4 2>nul
14+
:: pushd %4 2>nul
1515

1616
:main
1717
echo "|| Welcome to : ||"
@@ -36,7 +36,6 @@ pushd %4
3636

3737
if %target%== png goto PNGBATCHPPROCESS
3838
if %target%== pdf goto PDFBATCHPPROCESS
39-
if %target%== pdf_cmyk goto PDFCMYKBATCHPPROCESS
4039
if %target%== eps goto EPSBATCHPPROCESS
4140
if %target%== svg goto SVGPLAINBATCHPROCESS
4241
if %target%== jpeg goto JPEGBATCHPPROCESS
@@ -45,12 +44,13 @@ if %target%== webp goto WEBPBATCHPPROCESS
4544
if %target%== booklet goto BOOKLETPPROCESS
4645
if %target%== booklet_cmyk goto BOOKLETCMYKPROCESS
4746
if %target%== bundle goto BUNDLEBATCHPROCESS
47+
if %target%== pdf_cmyk goto PDFCMYKBATCHPPROCESS
4848

4949
goto pilihtarget
5050

5151
:mainpilih
52-
REM set exdir="%cd%"
53-
REM echo exdir=%exdir%
52+
:: set exdir="%cd%"
53+
:: echo exdir=%exdir%
5454
echo.
5555
echo Available SVG files on %cd% :
5656
echo.
@@ -63,8 +63,8 @@ echo.
6363
goto pilihtarget
6464

6565
:pilihtarget
66-
REM set exdir ="%cd%"
67-
REM echo exdir=%exdir%
66+
:: set exdir ="%cd%"
67+
:: echo exdir=%exdir%
6868
set svgin=%1
6969
if [%1]==[] set svgin="%svg%"
7070
echo Selected file = %svgin%
@@ -112,7 +112,7 @@ echo libwebp : https://developers.google.com/speed/webp/
112112
goto void
113113

114114
:help
115-
echo Inkporter-win 1.6 For Inkscape 0.92.x
115+
echo Inkporter-win 1.6 For Inkscape 1.0
116116
echo.
117117
echo Usage :
118118
echo inkporter runs inkporter and inkporter will prompts you to choose .svg file
@@ -145,6 +145,8 @@ for /f "delims=," %%d in ('inkscape --query-all %svgin% ^| findstr %objID%') do
145145
)
146146
goto end
147147

148+
149+
148150
:PDF
149151
echo Selected Format : PDF
150152

@@ -165,8 +167,11 @@ for /f "delims=," %%d in ('inkscape --query-all %svgin% ^| findstr %objID%') do
165167
echo.
166168
echo %%d.pdf has been created
167169
)
170+
168171
goto end
169172

173+
174+
170175
:EPS
171176
echo Selected Format : EPS
172177

@@ -313,7 +318,7 @@ goto end
313318
:BOOKLET
314319
echo Selected Format : Booklet (PDF)
315320
set /p objID="Object ID pattern : "
316-
REM set /p namaberkas="Output filename (put .pdf in the end, unless you want something else) : "
321+
:: set /p namaberkas="Output filename (put .pdf in the end, unless you want something else) : "
317322
set exdir="%cd%"
318323
echo your objects will be saved in %exdir%
319324
echo.
@@ -322,23 +327,33 @@ echo.
322327
set namaberkas=booklet_%objID%.pdf
323328
for /f "delims=," %%d in ('inkscape --query-all %svgin% ^| findstr %objID%') do (
324329
echo Now processing %%d
325-
inkscape --export-id=%%d --export-id-only --export-plain-svg --export-filename=%exdir%\%%d-temp.svg %svgin%
326-
inkscape --export-area-page --export-type=pdf --export-filename=%exdir%\pdftemp-%%d.pdf %exdir%\%%d-temp.svg
330+
inkscape --export-id=%%d --export-id-only --export-plain-svg --export-filename=%exdir%\%%d-pdf-temp.svg %svgin%
331+
inkscape %exdir%\%%d-pdf-temp.svg --export-area-page --export-type=pdf --export-filename=%exdir%\pdftemp-%%d.pdf
327332
move %exdir%\pdftemp-%%d.pdf %exdir%\pdftemp-%%d.pdfx >nul
328-
del %exdir%\%%d-temp.svg
333+
del %exdir%\%%d-pdf-temp.svg
329334
)
335+
:: change the directory to exdir
330336
pushd %exdir%
331-
dir /b | findstr pdftemp >> list.txt
337+
:: based on answer on stackoverflow : https://stackoverflow.com/questions/19297935/naturally-sort-files-in-batch
338+
(
339+
setlocal enabledelayedexpansion
340+
for %%f in (*.pdfx) do (
341+
set numbr=00000000000000000000000000000000%%f
342+
set numbr=!numbr:~-36!
343+
set $!numbr!=%%f
344+
)
345+
for /f "tokens=1,* delims==" %%f in ('set $0') do echo %%g
346+
) >>inkporter-pagelist.txt
332347
echo.
333-
gswin32c -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -sOutputFile=%namaberkas% @list.txt
348+
gswin32c -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -sOutputFile=%namaberkas% @inkporter-pagelist.txt
334349
del *.pdfx
335-
del list.txt
350+
del inkporter-pagelist.txt
336351
goto end
337352

338353
:BOOKLETCMYK
339354
echo Selected Format : Booklet (PDF-CMYK)
340355
set /p objID="Object ID pattern : "
341-
REM set /p namaberkas="Output filename (put .pdf in the end, unless you want something else) : "
356+
:: set /p namaberkas="Output filename (put .pdf in the end, unless you want something else) : "
342357
set exdir="%cd%"
343358
echo your objects will be saved in %cd%\%fold%
344359

@@ -355,12 +370,21 @@ for /f "delims=," %%d in ('inkscape --query-all %svgin% ^| findstr %objID%') do
355370
del %exdir%\%%d-rgb.pdf
356371
del %exdir%\%%d-temp.svg
357372
)
373+
358374
pushd %exdir%
359-
dir /b | findstr pdftemp >> list.txt
375+
(
376+
setlocal enabledelayedexpansion
377+
for %%f in (*.pdfx) do (
378+
set numbr=00000000000000000000000000000000%%f
379+
set numbr=!numbr:~-36!
380+
set $!numbr!=%%f
381+
)
382+
for /f "tokens=1,* delims==" %%f in ('set $0') do echo %%g
383+
) >>inkporter-pagelist.txt
360384
echo.
361-
gswin32c -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -sOutputFile=%namaberkas% @list.txt
385+
gswin32c -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -sOutputFile=%namaberkas% @inkporter-pagelist.txt
362386
del *.pdfx
363-
del list.txt
387+
del inkporter-pagelist.txt
364388
goto end
365389

366390
:BUNDLE
@@ -388,13 +412,14 @@ for /f "delims=," %%d in ('inkscape --query-all %svgin% ^| findstr %objID%') do
388412
rmdir /s /q %exdir%\temp-inkporter
389413
goto end
390414

415+
:endline
391416
:end
392417
echo COMPLETE
393-
del %2_inkporter-temp.svg >nul 2>nul
418+
:: del %2_inkporter-temp.svg >nul 2>nul
394419
if not [%2]==[] exit
395420

396421
:langsung_end
397422
echo See you
398423

399424
:void
400-
endlocal
425+
endlocal

1.0/inkporter.py

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
import inkex
1010
from time import sleep
1111
import warnings
12+
import io
1213

13-
__version__ = '1.1.0'
14+
__version__ = '1.6.1'
1415

1516
def atoi(text):
1617
return int(text) if text.isdigit() else text
@@ -60,6 +61,9 @@ def do_png(self):
6061
os.system(command)
6162

6263
def do_bundle(self):
64+
if not self.has_7zip():
65+
inkex.utils.errormsg("Please install and add 7-Zip directory to Environment Variable")
66+
return
6367
file_export = '"' + self.options.output_dir + '"'
6468
command = "start inkporter bundle {0} {1} {2} {3} {4}".format(
6569
self.myfile, self.options.id_pattern, file_export, self.options.dpi, self.options.bg_color)
@@ -68,7 +72,7 @@ def do_bundle(self):
6872
def do_jpg(self):
6973
file_export = '"' + self.options.output_dir + '"'
7074
if not self.has_imagemagick():
71-
inkex.utils.errormsg("Please install and add ImageMagick directory to Environment Variable")
75+
inkex.utils.errormsg("Please install and add ImageMagick directory to PATH Environment Variable")
7276
return
7377
if self.options.with_cmyk:
7478
options = "CMYK"
@@ -84,10 +88,13 @@ def do_jpg(self):
8488
def do_pdf(self):
8589
file_export = '"' + self.options.output_dir + '"'
8690
if self.options.with_cmyk:
91+
if not self.has_gs32():
92+
inkex.utils.errormsg("Please Install and add Ghostscript 32 bit directory to PATH environment variable to export PDF-CMYK")
93+
return
8794
command = "start inkporter pdf_cmyk {0} {1} {2}".format(
8895
self.myfile, self.options.id_pattern, file_export)
8996
os.system(command)
90-
else:
97+
else:
9198
command = "start inkporter pdf {0} {1} {2}".format(
9299
self.myfile, self.options.id_pattern, file_export)
93100
os.system(command)
@@ -108,6 +115,10 @@ def do_eps(self):
108115
os.close(self.tmplog_fd)
109116

110117
def do_booklet(self):
118+
if not self.has_gs32():
119+
inkex.utils.errormsg("Please Install and add Ghostscript 32 bit directory to PATH environment variable to export Booklet (PDF)")
120+
return
121+
111122
if self.options.with_cmyk:
112123
file_export = '"' + self.options.output_dir + '"'
113124
command = "start inkporter booklet_cmyk {0} {1} {2}".format(
@@ -123,6 +134,9 @@ def do_booklet(self):
123134

124135
def do_webp(self):
125136
file_export = '"' + self.options.output_dir + '"'
137+
if not self.has_webp():
138+
inkex.utils.errormsg("Please Download and add libwebp directory to PATH environment variable to export WEBP")
139+
return
126140
command = "start inkporter webp {0} {1} {2} {3}".format(
127141
self.myfile, self.options.id_pattern, file_export, self.options.dpi)
128142
os.system(command)
@@ -131,10 +145,22 @@ def do_webp(self):
131145
def has_imagemagick(self):
132146
status, output = self.get_cmd_output('magick --version')
133147
return status == 0 and 'ImageMagick' in output
148+
149+
def has_gs32(self):
150+
status, output = self.get_cmd_output('gswin32c --help')
151+
return status == 0 and 'Ghostscript' in output
152+
153+
def has_webp(self):
154+
status, output = self.get_cmd_output('cwebp')
155+
return status == 0 and 'cwebp' in output
156+
157+
def has_7zip(self):
158+
status, output = self.get_cmd_output('7z')
159+
return status == 0 and '7-Zip' in output
134160

135161
def make_tmp_file(self, file_format):
136162
handler, self.myfile = tempfile.mkstemp(suffix=".svg",prefix="inkporter-%s-"%file_format)
137-
with open(handler, "w") as f:
163+
with io.open(handler, "w", encoding="utf-8") as f:
138164
f.write(etree.tostring(self.document, encoding="utf-8",xml_declaration=True).decode("utf-8"))
139165
self.tmpout.append(self.myfile)
140166

@@ -151,28 +177,16 @@ def get_cmd_output(self, cmd):
151177
text = text[:-1]
152178
return sts, text
153179

154-
def do_cleanup(self):
155-
# for item in self.tmpout:
156-
# if os.path.exists(os.path.abspath(item)):
157-
# os.remove(os.path.abspath(item))
158-
# if os.path.isdir(self.tmpdir):
159-
# os.rmdir(self.tmpdir)
160-
print("hai")
180+
def quit_inkporter(self):
181+
warnings.filterwarnings("ignore")
182+
exit()
161183

162184
# called when extension is running
163185
def effect(self):
164-
if len(self.options.id_pattern) > 0:
165-
new_nss = inkex.utils.NSS
166-
new_nss[u're'] = u'http://exslt.org/regular-expressions'
167-
path_to_compile = "//*[re:match(@id,'(%s)','g')]" % self.options.id_pattern
168-
self.id_to_process = self.document.xpath(path_to_compile, namespaces=new_nss)
169-
self.svg.selected = {}
170-
for item in self.id_to_process:
171-
self.svg.selected[item.attrib['id']] = item
172-
if len(self.svg.selected) < 1:
186+
if not self.options.id_pattern:
173187
inkex.utils.errormsg(
174-
"Please select at least 1 object or fill ID Pattern to use this extension!")
175-
exit()
188+
"Please fill ID Pattern to use this extension!")
189+
self.quit_inkporter()
176190
try:
177191
if not os.path.isdir(os.path.expandvars(self.options.output_dir)):
178192
os.mkdir(os.path.expandvars(self.options.output_dir))
@@ -193,14 +207,12 @@ def effect(self):
193207
self.do_webp()
194208
elif self.options.format == "bundle":
195209
self.do_bundle()
196-
self.do_cleanup()
197210
except Exception as e:
198211
inkex.utils.errormsg(e)
199212
import traceback
200213
inkex.utils.errormsg(traceback.print_exc())
201-
print("hai")
202214

203-
warnings.filterwarnings("ignore")
215+
self.quit_inkporter()
204216

205217

206218
if __name__ == '__main__':

inkporter_installer_for_1.0.nsi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
; HM NIS Edit Wizard helper defines
44
!define PRODUCT_NAME "Inkporter For Inkscape 1.0"
5-
!define PRODUCT_VERSION "1.6"
5+
!define PRODUCT_VERSION "1.6.2"
66
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
77
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
88
; !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\AppMainExe.exe"
@@ -105,12 +105,12 @@ SectionEnd
105105
SectionEnd
106106

107107
Section -Post
108-
WriteRegExpandStr HKCR "Directory\Background\shell\Inkporter" "" "Buka Inkporter di sini"
108+
WriteRegExpandStr HKCR "Directory\Background\shell\Inkporter" "" "Open Inkporter here"
109109
WriteRegExpandStr HKCR "Directory\Background\shell\Inkporter" "Icon" "$INSTDIR\inkporter_data\inkporter.ico"
110110
WriteRegExpandStr HKCR "Directory\Background\shell\Inkporter\command" "" "$INSTDIR\inkporter_data\inkporter.bat"
111111
WriteRegExpandStr HKCR "inkscape.svg\shell\Inkporter\command" "" '$INSTDIR\inkporter_data\inkporter.bat "%1"'
112112
WriteRegExpandStr HKCR "inkscape.svg\shell\Inkporter" "Icon" "$INSTDIR\inkporter_data\inkporter.ico"
113-
WriteRegExpandStr HKCR "inkscape.svg\shell\Inkporter" "" "Ekspor dengan Inkporter"
113+
WriteRegExpandStr HKCR "inkscape.svg\shell\Inkporter" "" "Export with Inkporter"
114114
WriteUninstaller "$INSTDIR\uninstall_inkporter.exe"
115115
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "${PRODUCT_NAME}"
116116
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninstall_inkporter.exe"

0 commit comments

Comments
 (0)