If you know your UTF-8 is correct (no errors) you can find the start of the Nth Unicode code point (not "character!") by finding the Nth byte that is not in the range 0x80-0xBF.
However if you think you need to "print N characters" then you are not using Unicode correctly. That will return the length of UTF-8 that represents N Unicode code points, but those are not "characters". There are combining accents, invisible characters, diretion change indicators, etc. And as others pointed out, even the printing ones in monospace fonts take different widths. On 09/21/2011 08:58 AM, MacArthur, Ian (SELEX GALILEO, UK) wrote: > >> OK. I have string with some length (m = strlen(s);) and I have n - >> quantity of characters which I can print. >> I can calculate k = fl_utf_nb_char(s, m); >> >> If k<= n then no problem : fl_draw(s,x,y); >> >> Otherwise? >> In cycle decrease the source text by one byte and check for >> length, yes? > > It's pretty easy to scan a UTF8 string and determine where each glyph > begins, so you'd want to chop a whole glyph off the end of your string, > not just one byte, I imagine. > > I think there might even be a fltk helper function for finding the glyph > positions in the string - or am I remembering some other toolkit...? > > > > > SELEX Galileo Ltd > Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 > 3EL > A company registered in England& Wales. Company no. 02426132 > ******************************************************************** > This email and any attachments are confidential to the intended > recipient and may also be privileged. If you are not the intended > recipient please delete it from your system and notify the sender. > You should not copy it or use it for any purpose nor disclose or > distribute its contents to any other person. > ******************************************************************** > _______________________________________________ fltk-dev mailing list fltk-dev@easysw.com http://lists.easysw.com/mailman/listinfo/fltk-dev