> >> If we keep MK's wcwidth.c in its vanilla state, we can swap in an
> >> update or replacement if it is ever needed without much fuss.
> >
> > Agree.
>
> Me, too. Maybe #include it, or at least copy it in fl_wcwidth.c(xx)
> and leave it as its own function (if possible).
Actually, I'm not sure MK's code will really fly as-is on win32 hosts...
He uses wchar_t as his passed parameter type, but it is apparent from
the way that he uses it that he assumes this is at least a 32-bit type.
E.g. at or near line 202 / 203 of wcwidth.c he compares it to 0x2fffd
and other values larger than 16-bits...
However, on win32 systems, wchar_t is only a 16-bit type, and this part
of the code will not work.
I don't have a Mac or Unix box to hand, but I assume most have a 32-bit
wchar_t (e.g. I assume they are using some UCS-4 (or UTF-32) type
encoding...)
> > Yes - that might be the smart thing to do: then (for example) if we
> > decide to use platform specific functions at a later date,
> all that will
> > be hidden inside fl_wcwidth() or whatever... This function could of
> > course handle the "errors to cp1252" mapping and so forth too, if
> > required.
>
> +1: yes, please, I like fl_wcwidth()
Problems with mk_wcwidth aside, here's a possible implementation then:
--------------------------------------------------------
/* include Markus Kuhn's wcidth.c here. I guess that ideally we'd want
* to inline these functions, as they may get called frequently! */
#include "wcwidth.c"
/* According to information on Microsoft's and the Unicode Consortium's
* websites, positions 0x81, 0x8D, 0x8F, 0x90, and 0x9D are unused.
* However it appears that in practice the Windows API call to convert
* from the CP1252 to Unicode maps these to the corresponding C1
* control codes. */
/* Note: ERRORS_TO_CP1252 is currently defined local to fl_utf.c only,
* so would need to be made "more public" e.g. in config.h or similar */
#ifdef ERRORS_TO_CP1252
/* Map the CP1252 chars to their respective widths. The only valid
values
* here are +1 (for a printable glyph) and -1 (for a C1 ctrl char) */
static const int cp1252_width[32] = {
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF
*/
/* 8x */ 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1,
-1,
/* 9x */ -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1
};
#endif
/* we need at least a 32-bit unsigned type for this... */
int fl_wcwidth(unsigned int ucs) {
#ifdef ERRORS_TO_CP1252
if ((ucs >= 0x80) && (ucs < 0xa0))
return cp1252_width[ucs - 0x80];
else
#endif
return mk_wcwidth(ucs); /* ideally we want this inlined */
} /* fl_wcwidth */
/* end of file */
--
Ian
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
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev