public List <UnicodeRangeInfo> GetUnicodeRanges(string cultureName) { //'//Get the culture info for the given locale System.Globalization.CultureInfo CI = new System.Globalization.CultureInfo(cultureName); //'//Create and init our structure that will get passed LOCALESIGNATURE FI = new LOCALESIGNATURE(); FI.Initialize(); //'//Determine the size of our structure object SI = Marshal.SizeOf(FI); //'//Call the unmanaged function int Result = GetLocaleInfoW(CI.LCID, LOCALE_FONTSIGNATURE, ref FI, SI); if (Result == 0) { //'//If we get a zero then there's an error. This should call GetLastError ideally return(null); } else { //'//The lsUsb field represents a 128 bit value but we pass it into the unmanaged function as an array of 4 integers. //'//The code below converts the array of integers to a giant binary string. //'//There are of course better ways to do this that will save 5ms but I will leave that to you object Usb = Strings.StrReverse(string.Format("{0}{1}{2}{3}", Convert.ToString(FI.lsUsb(3), 2).PadLeft(32, '0'), Convert.ToString(FI.lsUsb(2), 2).PadLeft(32, '0'), Convert.ToString(FI.lsUsb(1), 2).PadLeft(32, '0'), Convert.ToString(FI.lsUsb(0), 2).PadLeft(32, '0'))); //'//This will be our return ranges List <UnicodeRangeInfo> LocaleRanges = new List <UnicodeRangeInfo>(); int loopI = 0; //'//Loop through the bits //'//Technically the last couple of bits aren't supposed to be used but there is no value in UnicodeRangeInfo for them anyway so it does not matter for (I = 0; I <= (Usb.Length - 1); I++) { //'//This is to stop the compiler complaining about lambda expressions loopI = I; //'//If the bit is set if (Usb(I) == '1') { //'//Find all ranges in the master range list with that bit set LocaleRanges.AddRange(AllRanges.FindAll(n => n.Bit == loopI)); } } return(LocaleRanges); } }
private static extern int GetLocaleInfoW(int locale, int LCType, ref LOCALESIGNATURE lpLCData, int cchData);