Beispiel #1
0
        // Builds all visual letters of a WordPosition, include them as children TextBlocks
        internal WordCanvas(WordPosition wp)
        {
            // Keep a link to WordPosition, we need it when swapping orientation
            this.wp = wp;

            for (int i = 0; i < wp.Word.Length; i++)
            {
                TextBlock tb = new TextBlock
                {
                    TextAlignment     = TextAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                    Text       = wp.Word.Substring(i, 1),
                    FontFamily = arial,
                    FontSize   = 16,
                    FontWeight = FontWeights.Bold,
                    Padding    = new Thickness(0, 3, 0, 0)
                };

                AdjustTextBlock(i, tb, wp.IsVertical);

                Children.Add(tb);
            }

            SetValue(LeftProperty, UnitSize * wp.StartColumn);
            SetValue(TopProperty, UnitSize * wp.StartRow);
            SetColor(NormalValidForeground, NormalValidBackground);
        }
Beispiel #2
0
        private string recognizeWord(WordPosition word, int rowPixel)
        {
            string wordText = "";


            int tmpWidth  = 3 * letterInformation.CropWidth;
            int tmpHeight = 3 * letterInformation.CropHeight;
            int trashsize = letterInformation.TrashSize;

            OCRExtractLetter extractionLetter = new OCRExtractLetter(tmpWidth, tmpHeight, trashsize);

            int letterSize = letterInformation.LetterSize;

            int start = word.StartPixel;
            int end   = word.EndPixel;

            Color white = Color.WHITE;
            Color color;

            //======================================================================
            for (int j = start; j < end; j++)
            {
                for (int k = -(letterSize / 4); k < (letterSize / 4); k++)
                {
                    int i = rowPixel + k;
                    if (i < 0 || i > image.Height)
                    {
                        continue;
                    }

                    //======================================================================
                    //        gornja vrzija je ispravna ova ne radi kako treba
                    //            for (int k = -(letterSize / 4); k < (letterSize / 4); k++) {
                    //            int i = rowPixel + k;
                    //            if (i < 0 || i > image.getHeight()) {
                    //                continue;
                    //            }
                    //            for (int j = start; j < end; j++) {
                    //======================================================================
                    color = new Color(image.getRGB(j, i));
                    if (color.Equals(white))
                    {
                        visited[i][j] = true;
                    }
                    else if (visited[i][j] == false)
                    {
                        BufferedImage letter = extractionLetter.extraxtLetter(image, visited, i, j);                         //OCRUtilities.extraxtCharacterImage(image, visited, i, j, tmpWidth, tmpHeight, letterInformation.getTrashSize());
                        if (letter != null)
                        {
                            OCRCropLetter crop   = new OCRCropLetter(letter, letterInformation.CropWidth, letterInformation.CropHeight);
                            BufferedImage croped = crop.processImage();
                            wordText += recognizeLetter(croped);
                        }
                    }
                }
            }
            return(wordText);
        }
Beispiel #3
0
        public void TestAddWordPositionAndSquares2()
        {
            WordPosition wp = new WordPosition("PIERRE", "Pierre", new PositionOrientation(0, 0, false));

            Assert.IsTrue(PlaceWordStatus.Valid == g.Layout.AddWordPosition(wp));
            Assert.IsTrue(PlaceWordStatus.Valid == g.Layout.AddWordPosition(new WordPosition("VIOLENT", "Violent", new PositionOrientation(-1, 1, true))));
            // WordPosition already placed, must raise ArgumentException
            g.Layout.AddWordPosition(wp);
        }
 private void Awake()
 {
     player          = GameObject.FindGameObjectWithTag("Player");
     wordPosition    = GetComponent <WordPosition>();
     AM              = FindObjectOfType <Audiomanager>();
     GM              = FindObjectOfType <GameManager>();
     wordManager     = FindObjectOfType <WordManager>();
     preSpawnHandler = FindObjectOfType <PreSpawnHandler>();
 }
    // Spawns word on canvas
    public WordDisplay SpawnWord(GameObject worldObject)
    {
        Vector3      spawnPos     = Camera.main.WorldToScreenPoint(worldObject.transform.position);
        WordPosition wordPosition = worldObject.GetComponent <WordPosition>();

        GameObject  textObj     = Instantiate(wordPrefab, spawnPos, Quaternion.identity, wordCanvas);
        WordDisplay wordDisplay = textObj.GetComponentInChildren <WordDisplay>();

        wordPosition.SetTextObject(textObj);
        wordDisplay.SetWorldObject(worldObject);

        return(wordDisplay);
    }
Beispiel #6
0
        public void TestCoverage()
        {
            g.AddWordsFromFile(@"..\..\Lists\Prénoms.txt");
            WordPosition Pierre = g.Layout.WordPositionList.First(wp => string.Compare(wp.OriginalWord, "Pierre", StringComparison.OrdinalIgnoreCase) == 0);

            g.Layout.RemoveWordPosition(Pierre);
            g.Layout.AddWordPosition(Pierre);
            g.PlaceWordsAgain();
            int          n  = g.Layout.WordsNotConnectedCount();
            WordPosition w1 = g.Layout.WordPositionList.First(wp => string.Compare(wp.OriginalWord, "Barthélémy", StringComparison.OrdinalIgnoreCase) == 0);
            var          l  = g.Layout.GetConnectedWordPositions(w1);

            g.Print(@"C:\temp\Prénoms.Layout.txt");
            g.Layout.SaveLayoutAsCode(@"C:\temp\Prénoms.Layout.cs");
        }
Beispiel #7
0
        private string addSpaces(WordPosition first, WordPosition second)
        {
            if (second == null)
            {
                return("");
            }
            string space = "";
            int    gap   = second.StartPixel - first.EndPixel;
            int    num   = gap / letterInformation.SpaceGap;

            for (int i = 0; i < num; i++)
            {
                space += " ";
            }
            return(space);
        }
Beispiel #8
0
        private string recognizeRow(int row)
        {
            string rowText            = "";
            List <WordPosition> words = textInformation.getWordsAtRow(row);

            for (int i = 0; i < words.Count; i++)
            {
                int          rowPixel = textInformation.getRowAt(row);
                WordPosition word     = words[i];
                rowText += recognizeWord(word, rowPixel);

                if ((i + 1) == words.Count)                 //trenutno smo na poslednjoj reci u redu
                {
                    rowText += addSpaces(word, null);
                }
                else
                {
                    WordPosition next = words[i + 1];
                    rowText += addSpaces(word, next);
                }
            }
            return(rowText);
        }
Beispiel #9
0
        // Builds all visual letters of a WordPosition, include them as children TextBlocks
        internal WordCanvas(WordPosition wp)
        {
            // Keep a link to WordPosition, we need it when swapping orientation
            this.wp = wp;

            for (int i = 0; i < wp.Word.Length; i++)
            {
                TextBlock tb = new TextBlock
                {
                    TextAlignment     = TextAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                    Text       = wp.Word.Substring(i, 1),
                    FontFamily = arial,
                    FontSize   = 16,
                    FontWeight = FontWeights.Bold,
                    Padding    = new Thickness(0, 3, 0, 0)
                };

                double top    = wp.IsVertical ? UnitSize * i : 0;
                double left   = wp.IsVertical ? 0 : UnitSize * i;
                double width  = UnitSize;
                double height = UnitSize;

                if (wp.IsVertical)
                {
                    left  += MarginSize;
                    width -= 2 * MarginSize;
                    if (i == 0)
                    {
                        top    += MarginSize;
                        height -= MarginSize;
                    }
                    else if (i == wp.Word.Length - 1)
                    {
                        height -= MarginSize;
                    }
                }
                else
                {
                    top    += MarginSize;
                    height -= 2 * MarginSize;
                    if (i == 0)
                    {
                        left  += MarginSize;
                        width -= MarginSize;
                    }
                    else if (i == wp.Word.Length - 1)
                    {
                        width -= MarginSize;
                    }
                }


                tb.SetValue(LeftProperty, left);        // Canvas.LeftProperty
                tb.SetValue(TopProperty, top);
                tb.Width  = width;
                tb.Height = height;

                Children.Add(tb);
            }

            SetValue(LeftProperty, UnitSize * wp.StartColumn);
            SetValue(TopProperty, UnitSize * wp.StartRow);
            SetColor(NormalValidForeground, NormalValidBackground);
        }
Beispiel #10
0
 public void Set(Word wrd, int idx)
 {
     word = wrd;
     index = idx;
     position = (idx == 0) ? WordPosition.Beginning : (idx == wrd.length - 1) ? WordPosition.End : WordPosition.Middle;
 }
Beispiel #11
0
 public WordDetails()
 {
     word = null;
     index = 0;
     position = WordPosition.None;
 }
Beispiel #12
0
 internal void AddWordPosition(WordPosition wordPosition)
 {
     model.AddWordPosition(wordPosition);
 }
Beispiel #13
0
 internal void RemoveWordPosition(WordPosition wordPosition)
 {
     model.RemoveWordPosition(wordPosition);
 }
Beispiel #14
0
 internal static PlaceWordStatus CanPlaceWordAtPositionInLayout(WordPositionLayout layout, WordPosition wordPosition, PositionOrientation positionOrientation)
 {
     return(EditorModel.CanPlaceWordAtPositionInLayout(layout, wordPosition, positionOrientation));
 }
Beispiel #15
0
 internal PlaceWordStatus AddWordPosition(WordPosition wordPosition)
 {
     return(Layout.AddWordPosition(wordPosition));
 }
Beispiel #16
0
 internal WordAndCanvas(WordPosition wp, WordCanvas wc)
 {
     WordPosition = wp;
     WordCanvas   = wc;
 }
Beispiel #17
0
        public WordPosition FindWord(string word)
        {
            WordPosition result = new WordPosition();

            Boolean inversed  = false;
            int     wordIndex = StringFromMatrix.IndexOf(word);

            if (wordIndex < 0)
            {
                wordIndex = StringFromMatrix.IndexOf(Reverse(word));
                inversed  = true;
            }

            if (wordIndex > 0)
            {
                result.EndPositionX = result.EndPositionY = 0;

                result.StartPositionX = Positions[wordIndex].X;
                result.StartPositionY = Positions[wordIndex].Y;

                switch (Positions[wordIndex].Direction)
                {
                case Direction.Right:
                    result.EndPositionX = result.StartPositionX + word.Length - 1;
                    result.EndPositionY = result.StartPositionY;
                    break;

                case Direction.Down:
                    result.EndPositionX = result.StartPositionX;
                    result.EndPositionY = result.StartPositionY + word.Length - 1;
                    break;

                case Direction.DownRight:
                    result.EndPositionX = result.StartPositionX + word.Length - 1;
                    result.EndPositionY = result.StartPositionY + word.Length - 1;
                    break;

                case Direction.UpRight:
                    result.EndPositionX = result.StartPositionX + word.Length - 1;
                    result.EndPositionY = result.StartPositionY + word.Length - 1;
                    break;
                }


                if (inversed)
                {
                    int tempX = result.EndPositionX;
                    int tempY = result.EndPositionY;

                    result.EndPositionX = result.StartPositionX;
                    result.EndPositionY = result.StartPositionY;

                    result.StartPositionX = tempX;
                    result.StartPositionY = tempY;
                }

                return(result);
            }

            return(null);
        }
Beispiel #18
0
        internal void MoveWordAndCanvasList(IList <WordAndCanvas> wordAndCanvasList)
        {
            if (wordAndCanvasList == null)
            {
                throw new ArgumentNullException(nameof(wordAndCanvasList));
            }
            if (wordAndCanvasList.Count == 0)
            {
                throw new ArgumentException("Zero words in list", nameof(wordAndCanvasList));
            }

            // If bounding rectangle is updated, need to redraw background grid
            BoundingRectangle r = viewModel.Layout.Bounds;

            if (!r.Equals(gridBounding))
            {
                UpdateBackgroundGrid();
            }

            // Compute distance moved on 1st element to choose animation speed (duration)
            WordPosition wp1      = wordAndCanvasList.First().WordPosition;
            WordCanvas   wc1      = wordAndCanvasList.First().WordCanvas;
            double       deltaX   = (double)wc1.GetValue(Canvas.LeftProperty) - wp1.StartColumn * UnitSize;
            double       deltaY   = (double)wc1.GetValue(Canvas.TopProperty) - wp1.StartRow * UnitSize;
            double       distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);

            // If distance is null, for instance after a selection click, we're done
            if (distance <= 0.0001)
            {
                return;
            }

            // Group animations in a storyboard to simplify premature ending
            var sb       = new Storyboard();
            var duration = new Duration(TimeSpan.FromSeconds(distance >= UnitSize ? 0.35 : 0.1));

            finalMoveWordAnimationData = new List <(Canvas, DependencyProperty, double)>();
            foreach (WordAndCanvas wac in wordAndCanvasList)
            {
                WordCanvas wc = wac.WordCanvas;

                double          finalLeftValue = wac.WordPosition.StartColumn * UnitSize;
                DoubleAnimation daLeft         = new DoubleAnimation
                {
                    Duration = duration,
                    From     = (double)wc.GetValue(Canvas.LeftProperty),
                    To       = finalLeftValue
                };
                Storyboard.SetTarget(daLeft, wc);
                Storyboard.SetTargetProperty(daLeft, new PropertyPath("Left"));
                sb.Children.Add(daLeft);
                finalMoveWordAnimationData.Add((wc, Canvas.LeftProperty, finalLeftValue));

                double          finalTopValue = wac.WordPosition.StartRow * UnitSize;
                DoubleAnimation daTop         = new DoubleAnimation
                {
                    Duration = duration,
                    From     = (double)wc.GetValue(Canvas.TopProperty),
                    To       = finalTopValue
                };
                Storyboard.SetTarget(daTop, wc);
                Storyboard.SetTargetProperty(daTop, new PropertyPath("Top"));
                sb.Children.Add(daTop);
                finalMoveWordAnimationData.Add((wc, Canvas.TopProperty, finalTopValue));
            }
            IsMoveWordAnimationInProgress = true;
            sb.Completed += Sb_Completed;
            sb.Begin();
        }
Beispiel #19
0
        // Check if a WordPosition can be placed at specific location in given layout
        internal static PlaceWordStatus CanPlaceWordAtPositionInLayout(WordPositionLayout layout, WordPosition wordPosition, PositionOrientation position)
        {
            WordPosition testWordPosition = new WordPosition(wordPosition.Word, wordPosition.OriginalWord, position);

            return(layout.CanPlaceWord(testWordPosition, true));
        }
Beispiel #20
0
 private void Awake()
 {
     player       = GameObject.FindGameObjectWithTag("Player");
     wordPosition = GetComponent <WordPosition>();
 }
Beispiel #21
0
 internal WordPositionLayout GetLayoutExcludingWordPosition(WordPosition wordPosition)
 {
     return(model.GetLayoutExcludingWordPositionList(new List <WordPosition> {
         wordPosition
     }));
 }
Beispiel #22
0
 // Removes a word from current Layout
 internal void RemoveWordPosition(WordPosition wordPosition)
 {
     Layout.RemoveWordPosition(wordPosition);
 }