Пример #1
0
        private List <BrailleSymbolSlotPosition> GetNewSymbolSlots(List <BrailleCharacter> characters)
        {
            List <BrailleSymbolSlotPosition> symbols = new List <BrailleSymbolSlotPosition>();
            int i      = 0;
            int length = characters.Count;
            BrailleCharacter before       = BlankCharacter;
            BrailleCharacter beforebefore = BlankCharacter;
            BrailleCharacter after;

            foreach (BrailleCharacter character in characters)
            {
                if (i < length - 1)
                {
                    after = characters[i + 1];
                }
                else
                {
                    after = BlankCharacter;
                }

                foreach (BrailleSymbolSlot slot in character.GetSymbols(beforebefore, before, after))
                {
                    BrailleSymbolSlotPosition s = new BrailleSymbolSlotPosition(slot, 0, i);
                    symbols.Add(s);
                }

                //Next
                beforebefore = before;
                before       = character;
                i++;
            }
            return(symbols);
        }
Пример #2
0
        public void AttemptWriteChar(char c)
        {
            int row    = Cursor.Row;
            int column = Cursor.Column;

            BrailleCharacter newChar = GetBrailleCharacter(c);

            if (newChar != null)
            {
                int symbolCount = Symbols[row].Count;
                //Primary check if room available
                if (symbolCount < CHARACTER_COLUMNS)
                {
                    //Find current character index or select last one
                    List <BrailleCharacter> characters = Characters[row];
                    if (characters.Count == 0)
                    {
                        characters.Add(newChar);
                        RecalculateSymbolSlots(row);
                        AttemptCursorPositionOffset(0, newChar.GetSymbols(BlankCharacter, BlankCharacter, BlankCharacter).Count);
                        DataChanged();
                        return;
                    }
                    else
                    {
                        BrailleSymbolSlotPosition previous = GetSymbolSlotPositionBefore();

                        //Calculate new list of symbol slot position and check if it fits
                        List <BrailleCharacter> newCharacters = characters.ToList();
                        int index = previous != null ? previous.i + 1 : 0;
                        newCharacters.Insert(index, newChar);

                        int newSymbolsCount = GetNewSymbolSlots(newCharacters).Count;
                        if (newSymbolsCount <= CHARACTER_COLUMNS)
                        {
                            Characters[row] = newCharacters;
                            RecalculateSymbolSlots(row);
                            AttemptCursorPositionChange(row, GetLastSymbolFromCharacterColumn(index, row));
                            DataChanged();
                            return;
                        }
                    }
                }
            }
        }
Пример #3
0
 private bool IsIndependantCharacter(BrailleCharacter c)
 {
     return(c.Type == BrailleCharacterType.WHITESPACE || c.Type == BrailleCharacterType.LOWERCASE || c.Type == BrailleCharacterType.SYMBOL || c.Type == BrailleCharacterType.CURRENCY);
 }
Пример #4
0
            public List <BrailleSymbolSlot> GetSymbols(BrailleCharacter beforebefore, BrailleCharacter before, BrailleCharacter after)
            {
                this.symbolSlots = new List <BrailleSymbolSlot>();

                if (Type == BrailleCharacterType.WHITESPACE)
                {
                    AddSymbolSlotSpecial(WHITESPACE, false);
                }
                else if (Type == BrailleCharacterType.LOWERCASE)
                {
                    if (before.Type == BrailleCharacterType.NUMBER || (beforebefore.Type == BrailleCharacterType.UPPERCASE && before.Type == BrailleCharacterType.UPPERCASE))
                    {
                        AddSymbolSlotSpecial(WHITESPACE);
                    }
                    AddSymbolSlot(Letter);
                }
                else if (Type == BrailleCharacterType.UPPERCASE)
                {
                    if (before.Type != BrailleCharacterType.UPPERCASE)
                    {
                        if (!IsIndependantCharacter(before))
                        {
                            AddSymbolSlotSpecial(WHITESPACE);
                        }

                        //If the previous char is not uppercase, then add uppercase mark. If the character after it is also uppercase, then add a second mark.
                        AddSymbolSlotSpecial(UPPERCASE);
                        if (after.Type == BrailleCharacterType.UPPERCASE)
                        {
                            AddSymbolSlotSpecial(UPPERCASE);
                        }
                    }
                    AddSymbolSlot(Letter);
                }
                else if (Type == BrailleCharacterType.NUMBER)
                {
                    //Add number mark if character before is not number
                    if (before.Type != BrailleCharacterType.NUMBER)
                    {
                        AddSymbolSlotSpecial(NUMBER);
                    }
                    AddSymbolSlot(Letter);
                }
                else
                {
                    //Handles both money and special symbols
                    if (!IsIndependantCharacter(before))
                    {
                        AddSymbolSlotSpecial(WHITESPACE);
                    }
                    if (Type == BrailleCharacterType.CURRENCY)
                    {
                        AddSymbolSlotSpecial(CURRENCY);
                        AddSymbolSlot(Letter);
                    }
                    else if (Type == BrailleCharacterType.SYMBOL)
                    {
                        AddSymbolSlotSpecial(SYMBOL);
                        AddSymbolSlot(Letter);
                    }
                }

                return(symbolSlots);
            }