Forum: wxRuby Displaying Asian characters in StyledTextCtrl

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
01a68e65c05c8751d75dbf957ea4fa23?d=identicon&s=25 Zhimin Zhan (zzhan)
on 2009-04-16 01:35
Hi,

I used r18n-desktop (http://r18n.rubyforge.org/) for localization, it
worked well.

But I have trouble displaying Chinese characters in StyledTextCtrl,

  On Mac, the control accepts characters, but failed to save (could be
problems in my application, the file becomes empty)
  on Windows, typed or copied chinese characters showed as blocks,
failed to save as well.

I did a search 'Unicode' in this forum, couldn't find relevant posts.

Thanks,
Zhimin
3396e4a3df8a840faec520af8555a400?d=identicon&s=25 Mario Steele (Guest)
on 2009-04-16 03:57
(Received via mailing list)
The section you need to look at, is here:
http://wxruby.rubyforge.org/doc/styledtextctrl.htm...

Scintilla defaults to the system's encoding, so if you have a different
encoding from your target encoding, it won't work.  Try using thoes
methods,
and see if it makes any difference when your getting text from the
Scintilla
control.

hth,

Mario
01a68e65c05c8751d75dbf957ea4fa23?d=identicon&s=25 Zhimin Zhan (zzhan)
on 2009-04-16 06:47
Thanks Mario

> http://wxruby.rubyforge.org/doc/styledtextctrl.htm...

I did notice this as well, few meaningful examples found on Internet.

 def initialize
   super()
   self.set_code_page(STC_CP_UTF8)
 end

The problem (not being able to save the file) remains.

Regards,
Zhimin
3396e4a3df8a840faec520af8555a400?d=identicon&s=25 Mario Steele (Guest)
on 2009-04-16 07:28
(Received via mailing list)
How exactly are you saving the file?
01a68e65c05c8751d75dbf957ea4fa23?d=identicon&s=25 Zhimin Zhan (zzhan)
on 2009-04-16 07:54
> How exactly are you saving the file?

class EditorSession < Wx::StyledTextCtrl

    def initialize
      super
      # ...
      self.set_code_page(STC_CP_UTF8)
      # ...
    end

    def save_file(name)
      puts "calling save file #{name} "
      begin
        super
        puts "saved Ok"
        # ...
      rescue => e
        puts "error: saving file: #{e}"
        logger.warn "failed to save #{name}: #{e}"
      end
    end

Output:
  calling save file F:/samples/chinese_spec.rb
  saved Ok

Then the file content is cleared.

Zhimin
This topic is locked and can not be replied to.