Jump to content

Anyone write something for adobe's "Appendix D"? Converting ISO/ANSI


Recommended Posts

Check out the long table at the bottom of this page.

I need to do a stringreplace for every character shown under "CHAR" to convert it to the corresponding 3 digit code under "WIN".

So for example:
 

$string = StringReplace( $string, "É", "\311 ", 0, 1 )

I'm hoping there's a much less tedious way, or that someone's already done the work or there's some library somewhere?

Please please please.  I'm off to bed now.  Thanks.

Edited by LondonNDIB
Link to comment
Share on other sites

  • Moderators

I'll give you a hint... that's the "octal".

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Ugly but it works:

Func ansiencode( $string )
    Local $aFunnyChars[119][2] = [["Æ","306"],["Á","301"],["Â","302"],["Ä","304"],["À","300"],["Å","305"],["Ã","303"],["Ç","307"],["É","311"],["Ê","312"], _
                    ["Ë","313"],["È","310"],["Ð","320"],["€","200"],["Í","315"],["Î","316"],["Ï","317"],["Ì","314"],["Ñ","321"],["Ó","323"], _
                    ["Ô","324"],["Ö","326"],["Ò","322"],["Ø","330"],["Õ","325"],["Š","212"],["Þ","336"],["Ú","332"],["Û","333"],["Ü","334"], _
                    ["Ù","331"],["Ý","335"],["Ÿ","237"],["Ž","216"],["á","341"],["â","342"],["´","264"],["ä","344"],["æ","346"],["à","340"], _
                    ["å","345"],["ã","343"],["¦","246"],["•","225"],["ç","347"],["¸","270"],["¢","242"],["ˆ","210"],["©","251"],["¤","244"], _
                    ["†","206"],["‡","207"],["°","260"],["¨","250"],["÷","367"],["é","351"],["ê","352"],["ë","353"],["è","350"],["…","205"], _
                    ["—","227"],["–","226"],["ð","360"],["¡","241"],["ƒ","203"],["ß","337"],["«","253"],["»","273"],["‹","213"],["›","233"], _
                    ["í","355"],["î","356"],["ï","357"],["ì","354"],["¬","254"],["¯","257"],["µ","265"],["×","327"],["ñ","361"],["ó","363"], _
                    ["ô","364"],["ö","366"],["ò","362"],["½","275"],["¼","274"],["¹","271"],["ª","252"],["º","272"],["ø","370"],["õ","365"], _
                    ["¶","266"],["·","267"],["‰","211"],["±","261"],["¿","277"],["„","204"],["“","223"],["”","224"],["‘","221"],["’","222"], _
                    ["‚","202"],["®","256"],["š","232"],["§","247"],["£","243"],["þ","376"],["¾","276"],["³","263"],["˜","230"],["™","231"], _
                    ["²","262"],["ú","372"],["û","373"],["ü","374"],["ù","371"],["ý","375"],["ÿ","377"],["¥","245"],["ž","236"]]

    For $i = 0 to UBound( $aFunnyChars ) -1
        $string = StringReplace( $string, $aFunnyChars[$i][0], "\" & $aFunnyChars[$i][1] & " ", 0, 1 )
    Next
    Return $string
EndFunc

incidentally, I found that PDF creators seem to want to need that extra space you might notice at the end of my StringReplace.  But I quickly realized it only happens for some characters and not others.  I can't spot any rhyme nor reason, but here is an updated version that accounts for the weird space behavior:

Func ansiencode( $string )
    Local $aFunnyChars[119][2] = [["Æ","306"],["Á","301"],["Â","302"],["Ä","304"],["À","300 "],["Å","305"],["Ã","303"],["Ç","307"],["É","311 "],["Ê","312"], _
                    ["Ë","313"],["È","310"],["Ð","320"],["€","200 "],["Í","315"],["Î","316"],["Ï","317"],["Ì","314 "],["Ñ","321 "],["Ó","323 "], _
                    ["Ô","324 "],["Ö","326 "],["Ò","322 "],["Ø","330 "],["Õ","325 "],["Š","212 "],["Þ","336 "],["Ú","332 "],["Û","333 "],["Ü","334 "], _
                    ["Ù","331 "],["Ý","335 "],["Ÿ","237 "],["Ž","216 "],["á","341"],["â","342 "],["´","264"],["ä","344 "],["æ","346 "],["à","340 "], _
                    ["å","345 "],["ã","343"],["¦","246"],["•","225 "],["ç","347 "],["¸","270"],["¢","242"],["ˆ","210 "],["©","251"],["¤","244"], _
                    ["†","206 "],["‡","207 "],["°","260 "],["¨","250"],["÷","367 "],["é","351"],["ê","352"],["ë","353"],["è","350"],["…","205 "], _
                    ["—","227 "],["–","226 "],["ð","360 "],["¡","241"],["ƒ","203 "],["ß","337 "],["«","253"],["»","273"],["‹","213 "],["›","233 "], _
                    ["í","355 "],["î","356 "],["ï","357 "],["ì","354 "],["¬","254"],["¯","257"],["µ","265 "],["×","327 "],["ñ","361"],["ó","363 "], _
                    ["ô","364 "],["ö","366 "],["ò","362 "],["½","275"],["¼","274"],["¹","271"],["ª","252"],["º","272"],["ø","370"],["õ","365"], _
                    ["¶","266"],["·","267"],["‰","211 "],["±","261"],["¿","277"],["„","204 "],["“","223 "],["”","224 "],["‘","221 "],["’","222 "], _
                    ["‚","202 "],["®","256"],["š","232 "],["§","247"],["£","243"],["þ","376 "],["¾","276 "],["³","263"],["˜","230 "],["™","231 "], _
                    ["²","262"],["ú","372"],["û","373"],["ü","374 "],["ù","371"],["ý","375 "],["ÿ","377 "],["¥","245"],["ž","236 "]]

    For $i = 0 to UBound( $aFunnyChars ) -1
        $string = StringReplace( $string, $aFunnyChars[$i][0], "\" & $aFunnyChars[$i][1], 0, 1 )
    Next
    Return $string
EndFunc
Edited by LondonNDIB
Link to comment
Share on other sites

LOL :D

Read this:

https://en.wikipedia.org/wiki/Octal

I'll make the first part, so converting Text to Octal

ConsoleWrite(_TextToOctal("É") & @CR)

Func _TextToOctal($sChar)
    Local $iASCII = Asc($sChar), $sReturn
    For $i = 1 To 3
        $sReturn = Mod($iASCII, 8) & $sReturn
        $iASCII = Floor($iASCII / 8)
    Next
    Return "/" & $sReturn
EndFunc   ;==>_TextToOctal

How to convert Octal to Text? LondonNDIB will give us the answer :D

Seems never happens so i'll do it for future reference, the guy is too tired...

ConsoleWrite(_TextToOctal("É") & @CR)
ConsoleWrite(_OctalToText("/311") & @CR)

Func _TextToOctal($sChar)
    Local $iASCII = Asc($sChar), $sReturn
    For $i = 1 To 3
        $sReturn = Mod($iASCII, 8) & $sReturn
        $iASCII = Floor($iASCII / 8)
    Next
    Return "/" & $sReturn
EndFunc   ;==>_TextToOctal

Func _OctalToText($sOctal)
    Local $iOctal = StringReplace($sOctal, "/", "")
    Local $aOctal = StringSplit($iOctal, "", 2)
    Local $sOctalToBin, $sHexdecimal
    For $i = 0 To UBound($aOctal) - 1
        $sOctalToBin &= _DecToBin($aOctal[$i])
    Next
    $sHexdecimal = Hex(_BinToDec($sOctalToBin))
    Return _HexToASCII($sHexdecimal)
EndFunc   ;==>_OctalToText

Func _DecToBin($iDecimal)
    Local $sBinary
    Do
        $sBinary = BitAND($iDecimal, 1) & $sBinary
        $iDecimal = BitShift($iDecimal, 1)
    Until $iDecimal = 0
    Return StringFormat('%03i', $sBinary)
EndFunc   ;==>_DecToBin

Func _BinToDec($sBin)
    Local $sBinary = StringSplit($sBin, "")
    Local $iDecimal = 0, $iX = 1, $iNumber = $sBinary[0]
    Do
        If $sBinary[$iNumber] = "1" Then $iDecimal = $iDecimal + $iX
        $iNumber = $iNumber - 1
        $iX = $iX * 2
    Until $iNumber = 0
    Return $iDecimal
EndFunc   ;==>_BinToDec

Func _HexToASCII($sString)
    Return Chr(Dec($sString))
EndFunc   ;==>_HexToASCII
Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

Still confused on what that really does for me.  It seems I'd still have to loops through every single character of my string looking for these mystery chars.

I have really zero experience working with funny characters :(  I'm baffled.  However, it is now 4 in the morning and I have a working solution for my purposes.  Maybe I'll take another look tomorrow.

Link to comment
Share on other sites

Yes, you loop through string but that code replaces your massive array.

$sString = "My String"
$aString = StringSplit($sString, "")
For $x = 1 To $aString[0]
    ConsoleWrite(_TextToOctal($aString[$x]))
Next
ConsoleWrite(@LF)

Func _TextToOctal($sChar)
    Local $iASCII = Asc($sChar), $sReturn
    For $i = 1 To 3
        $sReturn = Mod($iASCII, 8) & $sReturn
        $iASCII = Floor($iASCII / 8)
    Next
    Return "/" & $sReturn
EndFunc   ;==>_TextToOctal
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I guess.  It converts EVERY character though.  99.9999% of them aren't non-English.  So I still need the massive array to know which characters to pass to the function.

Anyway, I tried it and I end up with a very unfortunate PDF consisting of a whole lot of this:

/126/151/141/156/156/145/171/040/114/145/166/

I guess I wasn't clear enough in my initial post.   What I need, for example, would be this:

Fr/340nco

Which would then be valid input to the PDF generator to output as "Frànco"

Oddly enough, that particular one gets malformed where the à and the preceding character are overlapped.  Some characters do this, some don't (about 50/50 it seems with no pattern that I can immediately discern).  So again I'd need an array to tell me which ones require an extra " " and which don't!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...