Hi all. I just started experimenting with the FOX drawing functions. After having a little problem with text positioning, I know stumbled into an encoding problem (at least, I think so). Whenever I want to draw something like "foo\nbar" or "foo\r\nbar" I get those ugly squares (which likely symbolize a char the font (?) is not able to display). Screenshot is attached. My system''s encoding is UTF-8, by the way. Any ideas? Regards, Jannis -------------- next part -------------- A non-text attachment was scrubbed... Name: Bildschirmfoto-TodoListEditor: Zeichentests.png Type: image/png Size: 4363 bytes Desc: not available Url : http://rubyforge.org/pipermail/fxruby-users/attachments/20050323/77abf591/Zeichentests.png
On Wednesday 23 March 2005 09:20 am, Jannis Pohlmann wrote:> Hi all. > > I just started experimenting with the FOX drawing functions. After > having a little problem with > text positioning, I know stumbled into an encoding problem (at least, I > think so). > > Whenever I want to draw something like "foo\nbar" or "foo\r\nbar" I get > those ugly squares (which > likely symbolize a char the font (?) is not able to display). > > Screenshot is attached. My system''s encoding is UTF-8, by the way. > > Any ideas?Please note that dc.drawText() does not do any formatting, it just draws the visible characters and draws "replacement" characters for the formatting characters like \n and \t. If you want interpretation of the formatting, just place a text widget and it will do a lot of formatting for you; alternatively you can write a loop; here is what FXLabel uses: beg=0; do{ end=beg; while(end<text.length() && text[end]!=''\n'') end++; dc.drawText(xx,yy,&text[beg],end-beg); yy+=font->getFontHeight(); beg=end+1; } while(end<text.length()); I know you''re working in Ruby, and this is C++. But I hope you get the idea:- hunt for the \n, then draw up to that, move to the next line and hunt for the next \n. Repeat until the whole string is done.... - Jeroen P.S. As for utf-8, this capability will be in FOX in the 1.6 version; the plan is to have unicode drawing support for all widgets, and have some stuff in place for localization.
Jeroen van der Zijp schrieb:>On Wednesday 23 March 2005 09:20 am, Jannis Pohlmann wrote: > > >>Hi all. >> >>I just started experimenting with the FOX drawing functions. After >>having a little problem with >>text positioning, I know stumbled into an encoding problem (at least, I >>think so). >> >>Whenever I want to draw something like "foo\nbar" or "foo\r\nbar" I get >>those ugly squares (which >>likely symbolize a char the font (?) is not able to display). >> >>Screenshot is attached. My system''s encoding is UTF-8, by the way. >> >>Any ideas? >> >> > >Please note that dc.drawText() does not do any formatting, it just draws >the visible characters and draws "replacement" characters for the formatting >characters like \n and \t. > >If you want interpretation of the formatting, just place a text widget and >it will do a lot of formatting for you; alternatively you can write a loop; >here is what FXLabel uses: > > beg=0; > do{ > end=beg; > while(end<text.length() && text[end]!=''\n'') end++; > dc.drawText(xx,yy,&text[beg],end-beg); > yy+=font->getFontHeight(); > beg=end+1; > } > while(end<text.length()); > >I know you''re working in Ruby, and this is C++. But I hope you get the >idea:- hunt for the \n, then draw up to that, move to the next line and >hunt for the next \n. Repeat until the whole string is done.... > >Thanks very much, Jeroen. Wrapping this into correct Ruby code won''t be much of a problem.>P.S. As for utf-8, this capability will be in FOX in the 1.6 version; >the plan is to have unicode drawing support for all widgets, and have >some stuff in place for localization. > >Yeah, I''m really looking forward to it. Regards, Jannis
BTW, this should be most typical for Ruby (assuming you already know the coordinates where you want to draw): str = "foo\nbar" # or "foo\r\nbar" lines = str.split(/[\r]?\n/) nr = 0 lines.each do |line| dc.drawText(x, y + dc.font.fontAscent + nr * dc.font.fontHeight, line) nr += 1 end Hails, Jannis