[Mwinapi-commits] SF.net SVN: mwinapi: [68] trunk/ManagedWinapi/CodepointRange.cs
Status: Beta
Brought to you by:
schierlm
From: <sch...@us...> - 2008-04-28 18:42:26
|
Revision: 68 http://mwinapi.svn.sourceforge.net/mwinapi/?rev=68&view=rev Author: schierlm Date: 2008-04-28 11:41:39 -0700 (Mon, 28 Apr 2008) Log Message: ----------- CodepointRange.cs: Add helper method to get codepoint ranges of all fonts, while ignoring identical font styles within a font family. Modified Paths: -------------- trunk/ManagedWinapi/CodepointRange.cs Modified: trunk/ManagedWinapi/CodepointRange.cs =================================================================== --- trunk/ManagedWinapi/CodepointRange.cs 2008-04-27 17:52:10 UTC (rev 67) +++ trunk/ManagedWinapi/CodepointRange.cs 2008-04-28 18:41:39 UTC (rev 68) @@ -48,6 +48,57 @@ } /// <summary> + /// Returns a dictionary containing codepoint ranges of all fonts. + /// If multiple fonts of one family (bold, italic, etc.) share their + /// codepoint range, only their base font is included in this list, + /// otherwise all different variants are included. + /// </summary> + public static Dictionary<Font, CodepointRange> GetRangesForAllFonts() + { + Dictionary<Font, CodepointRange> result = new Dictionary<Font, CodepointRange>(); + foreach (FontFamily ff in FontFamily.Families) + { + Font[] fonts = new Font[16]; + CodepointRange[] range = new CodepointRange[fonts.Length]; + for (int i = 0; i < fonts.Length; i++) + { + if (ff.IsStyleAvailable((FontStyle)i)) + { + fonts[i] = new Font(ff, 10, (FontStyle)i); + range[i] = new CodepointRange(fonts[i]); + } + } + int importantBits = 0; + for (int bit = 1; bit < fonts.Length; bit <<= 1) + { + for (int i = 0; i < fonts.Length; i++) + { + if ((i & bit) != 0) continue; + if (range[i] != null && range[i | bit] != null) + { + if (!range[i].Equals(range[i | bit])) + { + importantBits |= bit; + break; + } + } + else if (range[i] != null || range[i | bit] != null) + { + importantBits |= bit; + break; + } + } + } + for (int i = 0; i < fonts.Length; i++) + { + if ((i & importantBits) != i || fonts[i] == null) continue; + result.Add(fonts[i], range[i]); + } + } + return result; + } + + /// <summary> /// The number of codepoints supported by this font. /// </summary> public int SupportedCodepointCount { get { return codepointCount; } } @@ -111,6 +162,30 @@ return sb.Append("]").ToString(); } + #region Equals and HashCode + public override bool Equals(object obj) + { + CodepointRange cr = obj as CodepointRange; + if (cr == null) + return false; + if (codepointCount != cr.codepointCount || ranges.Length != cr.ranges.Length) + return false; + for (int i = 0; i < ranges.Length; i++) + { + if (ranges[i] != cr.ranges[i]) + { + return false; + } + } + return true; + } + + public override int GetHashCode() + { + return 3 * codepointCount + 7 * ranges.Length + 9 * FirstCodepoint + 11 * LastCodepoint; + } + #endregion + #region PInvoke Declarations [DllImport("gdi32.dll")] private static extern uint GetFontUnicodeRanges(IntPtr hdc, IntPtr lpgs); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |