Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CharacterRegion.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using SiliconStudio.Core;
7 using SiliconStudio.Core.Serialization;
8 
9 namespace SiliconStudio.Paradox.Assets.SpriteFont
10 {
11  /// <summary>
12  /// Describes a range of consecutive characters that should be included in the font.
13  /// </summary>
14  [DataContract("CharacterRegion")]
15  public struct CharacterRegion
16  {
17  /// <summary>
18  /// Initializes a new instance of the <see cref="CharacterRegion"/> struct.
19  /// </summary>
20  /// <param name="start">The start.</param>
21  /// <param name="end">The end.</param>
22  /// <exception cref="System.ArgumentException"></exception>
23  public CharacterRegion(char start, char end)
24  {
25  if (start > end)
26  throw new ArgumentException();
27 
28  Start = start;
29  End = end;
30  }
31 
32  /// <summary>
33  /// The first character to include in the region.
34  /// </summary>
35  [DataMember(0)]
36  public char Start;
37 
38  /// <summary>
39  /// The second character to include in the region.
40  /// </summary>
41  [DataMember(1)]
42  public char End;
43 
44  // Flattens a list of character regions into a combined list of individual characters.
46  {
47  if (regions.Any())
48  {
49  // If we have any regions, flatten them and remove duplicates.
50  return regions.SelectMany(region => region.GetCharacters()).Distinct();
51  }
52  else
53  {
54  // If no regions were specified, use the default.
55  return Default.GetCharacters();
56  }
57  }
58 
59  // Default to just the base ASCII character set.
60  public static CharacterRegion Default = new CharacterRegion(' ', '~');
61 
62  // Enumerates all characters within the region.
63  private IEnumerable<Char> GetCharacters()
64  {
65  for (char c = Start; c <= End; c++)
66  {
67  yield return c;
68  }
69  }
70  }
71 }
static IEnumerable< Char > Flatten(IEnumerable< CharacterRegion > regions)
Describes a range of consecutive characters that should be included in the font.
Use the default mode depending on the type of the field/property.
char Start
The first character to include in the region.
char End
The second character to include in the region.
CharacterRegion(char start, char end)
Initializes a new instance of the CharacterRegion struct.