1 /**
2  * Copyright:       Copyright (C) 2018 Gabriel Gheorghe, All Rights Reserved
3  * Authors:         $(Gabriel Gheorghe)
4  * License:         $(LINK2 https://www.gnu.org/licenses/gpl-3.0.txt, GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007)
5  * Source:          $(LINK2 https://github.com/GabyForceQ/LibertyEngine/blob/master/source/liberty/text/word.d)
6  * Documentation:
7  * Coverage:
8 **/
9 module liberty.text.word;
10 
11 import liberty.text.character;
12 
13 /**
14  * Represents one word in the text.
15 **/
16 final class Word {
17   private {
18     Character[] characters;
19     float width = 0.0f;
20     float fontSize;
21   }
22 
23   /**
24    * Create a new empty word.
25    * $(D_PARAM fontSize):
26    *    - the font size of the text which this word is in.
27   **/
28   this(float fontSize)   {
29     this.fontSize = fontSize;
30   }
31 
32   /**
33    * Add a new character to the end of the current word.
34    * It increases the width of the word.
35    * $(D_PARAM character):
36    *    - the character to be added.
37    * Returns reference to this so it can be used in a stream.
38   **/
39   typeof(this) addCharacter(Character character)   {
40     characters ~= character;
41     width += character.getAdvance().x * fontSize;
42     return this;
43   }
44 
45   /**
46    * Returns the list of characters in the word.
47   **/
48   Character[] getCharacters()   {
49     return characters;
50   }
51 
52   /**
53    * Returns the width of the word relative to screen size.
54   **/
55   float getWidth()   const {
56     return width;
57   }
58 }