Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Win32 encoding conversion mystery

by vr (Curate)
on Aug 13, 2018 at 17:38 UTC ( [id://1220300]=note: print w/replies, xml ) Need Help??


in reply to Win32 encoding conversion mystery

What would be the name of this process?

Eh-h... just, 'encoding'?

Good news, decoding from CP932 (~ shiftjis) goes error-free, bad news, online translations (to English) seem to produce gibberish.

use strict; use warnings; use feature 'say'; use Encode qw/ encode decode /; my $a = join '', map chr, qw/ 226 123 226 78 233 9524 196 113 233 9568 196 191 233 8976 233 189 50 /; my $b = join '', map chr, qw/ 131 123 131 78 130 193 142 113 130 204 142 168 130 169 130 171 50 /; ############################ use Test::More; is $a, decode( 'cp437', $b, Encode::FB_CROAK | Encode::LEAVE_SRC ), 'f +rom b to a'; is $b, encode( 'cp437', $a, Encode::FB_CROAK | Encode::LEAVE_SRC ), 'f +rom a to b'; done_testing; ############################ use Win32; say Win32::GetACP; say Win32::GetOEMCP; say Win32::GetConsoleCP; ############################ use Imager; my $text = decode 'cp932', $b, Encode::FB_CROAK | Encode::LEAVE_SRC; my $image = Imager-> new( xsize => 300, ysize => 80 ); Imager::Font-> new( file => 'mona.ttf' ) -> align( string => $text, size => 30, color => 'white', x => $image-> getwidth/2, y => $image-> getheight/2, halign => 'center', valign => 'center', image => $image, ); $image-> write( file => 'jp.png' ); ############################ use Win32::LongPath; mkdirL $text;

Replies are listed 'Best First'.
Re^2: Win32 encoding conversion mystery
by mithaldu (Monk) on Aug 13, 2018 at 17:58 UTC
    Thank you!

    You provided both the correct answer, which is that i needed to encode the UTF8 string i got to code page 437, and provided it in massive detail. This was the exact chain i need to get useful modern UTF8. :D

    my $safe = Encode::FB_CROAK | Encode::LEAVE_SRC; my $text = decode 'cp932', (encode "cp".Win32::GetOEMCP(), $windows_wi +de_filename, $safe), $safe;

      The actual code page you want is probably the one returned by "cp".Win32::GetOEMCP() or "cp".Win32::GetConsoleOutputCP(), not cp437. It's cp850 on my machine, for example. I think it's because I'm using "English (Canada)" instead of "English (US)".

        Thanks for the additional info, that is useful. I amended the post.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1220300]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 05:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found