Skip to content

Commit 9370c3b

Browse files
authored
Merge pull request #28 from edgar79/windows-utf8-codepage65001
Windows batch encoded in UTF-8 (using chcp 65001)
2 parents 2d67d7c + b4e4f1a commit 9370c3b

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

extension/OOoLilyPond/LilyPond.xba

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Function CallLilyPond() As Boolean
8282

8383
ElseIf sOSType = "Windows" Then
8484

85-
sCommand = "cd /d " & Chr(34) & ConvertFromURL(sTmpPath) & Chr(34) & Chr(10) _
85+
sCommand = "cd /d " & Chr(34) & ConvertFromURL(sTmpPath) & Chr(34) & Chr(10) & Chr(13) _
8686
& Chr(34) & sLilyPondExecutable & Chr(34) & " -dno-point-and-click"
8787
If Len(sIncludeStatement) > 0 Then
8888
sCommand = sCommand & " " & sIncludeStatement
@@ -91,21 +91,21 @@ Function CallLilyPond() As Boolean
9191
If bTransparentBackground Then
9292
sCommand = sCommand & " -dno-delete-intermediate-files -dpixmap-format=pngalpha --png " & sBackendOpt & " -dresolution=" _
9393
& iGraphicDPI & " "& Chr(34) & ConvertFromURL(sTmpPath) & constOLyFileName & ".ly" & Chr (34) _
94-
& " >" & constOLyFileName & ".out 2>&1" &Chr(10)
94+
& " >" & constOLyFileName & ".out 2>&1" & Chr(10) & Chr(13)
9595
Else
9696
sCommand = sCommand & " -dno-delete-intermediate-files --png " & sBackendOpt & " -dresolution=" _
9797
& iGraphicDPI & " " & Chr(34) & ConvertFromURL(sTmpPath) & constOLyFileName & ".ly" & Chr (34) _
98-
& " >" & constOLyFileName & ".out 2>&1" &Chr(10)
98+
& " >" & constOLyFileName & ".out 2>&1" & Chr(10) & Chr(13)
9999
End If
100100
ElseIf sFormat="eps" Then
101101
sCommand = sCommand & " " & sBackendOpt & " -f eps " & Chr(34) & ConvertFromURL(sTmpPath) & constOLyFileName & ".ly" & Chr (34) _
102-
& " >" & constOLyFileName & ".out 2>&1" & Chr(10)
102+
& " >" & constOLyFileName & ".out 2>&1" & Chr(10) & Chr(13)
103103
ElseIf sFormat="svg" Then
104104
sCommand = sCommand & " " & sBackendOpt & " " & Chr(34) & ConvertFromURL(sTmpPath) & constOLyFileName & ".ly" & Chr (34) _
105-
& " >" & constOLyFileName & ".out 2>&1" & Chr(10)
105+
& " >" & constOLyFileName & ".out 2>&1" & Chr(10) & Chr(13)
106106
End If
107-
sCommand=sCommand & "if %ERRORLEVEL% equ 9009 echo cannot execute >LilyPond-cannot_execute" & Chr(10) _
108-
& "if %ERRORLEVEL% equ 3 echo cannot execute >LilyPond-cannot_execute" & Chr(10)
107+
sCommand=sCommand & "if %ERRORLEVEL% equ 9009 echo cannot execute >LilyPond-cannot_execute" & Chr(10) & Chr(13) _
108+
& "if %ERRORLEVEL% equ 3 echo cannot execute >LilyPond-cannot_execute" & Chr(10) & Chr(13)
109109
'ToDo: 9009 and 3 OK? Other errors? Wrong Permissions?
110110
WindowsCommand(sCommand)
111111

extension/OOoLilyPond/Tools.xba

100644100755
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ End Function
335335

336336

337337
Sub WindowsCommand(sCommand as String)
338+
338339
' I did not achieve to run lilypond directly with the Shell command and the
339340
' Output redirected to files.
340341
' I tried: Shell("cmd /c lilypond >file1 2>file2")
@@ -344,15 +345,24 @@ Sub WindowsCommand(sCommand as String)
344345

345346
Dim sBatFile As String
346347
Dim iNumber As Integer
348+
Dim oTextStream As Object
347349

348350
sBatFile=TmpFileName(ConvertFromURL(sTmpPath) & "CommandCallFromOOo_",".bat")
351+
352+
' Open output stream
353+
oTextStream = createUnoService("com.sun.star.io.TextOutputStream")
354+
If oFileAccess.exists( sBatFile ) Then oFileAccess.kill( sBatFile )
355+
oTextStream.setOutputStream(oFileAccess.openFileWrite(sBatFile))
356+
357+
'Set CodePage to 65001 - which is UTF-8 (Supports any except bidirectional and scripted languages)
358+
oTextStream.setEncoding("utf-8")
359+
oTextStream.writeString( Chr(10) & Chr(13) )
360+
oTextStream.writeString("chcp 65001" & Chr(10) & Chr(13) & sCommand)
361+
oTextStream.closeOutput()
349362

350-
iNumber = Freefile
351-
Open sBatFile For Output As #iNumber
352-
Print #iNumber, "chcp 1252" & Chr (10) & sCommand
353-
Close #iNumber
354-
Shell (sBatFile, 1, "", True)
363+
Shell (sBatFile, 6, "", True) ' Window-code 6 : only show symbol and leave focus on the current window
355364
Kill(sBatFile)
365+
356366
End Sub
357367

358368

0 commit comments

Comments
 (0)