lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I avoid unicode and use Latin1? (Was: Wrong characters with


From: stk
Subject: Re: How can I avoid unicode and use Latin1? (Was: Wrong characters with jEdit)
Date: Sun, 4 Sep 2005 01:45:26 -0400 (EDT)

My original question was

> Or what trick, however laborious, will enable me to use Latin1
> characters in markup?  I only need them occasionally in titles.

I would like to thank Daniel Johnson and Hans de Rijck, who both posted
the algorithm for converting Latin1 to unicode, thus supplying me the
trick I requested.  In fact I used this algorithm to generate a table
(which I printed) indicating the two bytes I have to insert to get any one
of the 64 Latin1 accented letters.  For example, to get an e-acute, I have
to type alt-num-0195 and then alt-num-0169 (I'm running under Windows).
It puts an A-tilde and a copyright-symbol in my Latin1 text editor of
course, but this is the right unicode double byte for an e-acute, and
LilyPond's PDF result is correct.  Obviously this procedure would be
terrible for entering extensive lyrics, but for the occasional accented
character in a song title, it's easy.

Thanks again.

-- Tom

*******************************************************************

Daniel Johnson wrote:

> I offer the following with NO WARRANTY.....

> '==== begin VBScript code ====
>
> Option Explicit
>
> Dim sInFileName, sOutFileName
>
> sInFileName = ""  ' Filename you wish to convert (with full path)
> sOutFileName = "" ' Filename you want for the output
>
> Dim oFSO
> Dim oInFile, sInString
> Dim oOutFile, sOutString
> Dim i, s
> Dim sTransArray(255)
>
> 'Populate the translation table
> For i = 128 To 191
>     sTransArray(i) = chr(&HC2) & chr(i)
> Next
> For i = 192 To 255
>     sTransArray(i) = chr(&HC3) & chr(i - 64)
> Next
>
> 'Read the input file as a single string
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oInFile = oFSO.OpenTextFile(sInFileName, 1, False, 0)
> sInString = oInFile.ReadAll
> oInFile.Close
> Set oInFile = Nothing
>
> 'Perform char-by-char translation
> sOutString = ""
> For i = 0 To Len(sInString)
>     s = Mid(sInString, i, 1)
>     If Asc(s) < 128 Then
>         sOutString = sOutString & s
>     Else
>         sOutString = sOutString & sTransArray(Asc(s))
>     End If
> Next
>
> 'Write the resulting file to the output file
> Set oOutFile = oFSO.OpenTextFile(sOutFileName, 2, True, 0)
> oOutFile.Write(sOutString)
> oOutFile.Close
>
> 'Perform final housekeeping
> Set oOutFile = Nothing
> Set oFSO = Nothing
>
> End
>
> '==== end VBScript code ====

*******************************************************************

Hans de Rijck wrote:

> Or, for someone with a C compiler, the poor-man's algorithm is:

>     for ( unsigned int i = 0; i < length; i++ )
>     {
>         if ( (unsigned char)line1[i] > 127 )
>         {
>             *line2++ = (char)(192 + (((unsigned char)line1[ i ]) / 64));
>             *line2++ = (char)(128 + (((unsigned char)line1[ i ]) % 64));
>         }
>         else
>         {
>             *line2++ = line[ i ];
>         }
>     }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]