Пример #1
0
        /// <summary>
        /// Get the blocks.
        /// </summary>
        /// <param name="words">The words in the page.</param>
        /// <param name="minimumWidth">The minimum width for a block.</param>
        /// <param name="dominantFontWidthFunc">The function that determines the dominant font width.</param>
        /// <param name="dominantFontHeightFunc">The function that determines the dominant font height.</param>
        /// <param name="wordSeparator"></param>
        /// <param name="lineSeparator"></param>
        private IReadOnlyList <TextBlock> GetBlocks(IEnumerable <Word> words, double minimumWidth,
                                                    Func <IEnumerable <Letter>, double> dominantFontWidthFunc,
                                                    Func <IEnumerable <Letter>, double> dominantFontHeightFunc,
                                                    string wordSeparator, string lineSeparator)
        {
            // Filter out white spaces
            words = words.Where(w => !string.IsNullOrWhiteSpace(w.Text));
            if (!words.Any())
            {
                return(EmptyArray <TextBlock> .Instance);
            }

            XYLeaf root = new XYLeaf(words); // Create a root node.
            XYNode node = VerticalCut(root, minimumWidth, dominantFontWidthFunc, dominantFontHeightFunc);

            if (node.IsLeaf)
            {
                return(new List <TextBlock> {
                    new TextBlock((node as XYLeaf).GetLines(wordSeparator), lineSeparator)
                });
            }
            else
            {
                var leaves = node.GetLeaves();

                if (leaves.Count > 0)
                {
                    return(leaves.ConvertAll(l => new TextBlock(l.GetLines(wordSeparator), lineSeparator)));
                }
            }

            return(new List <TextBlock>());
        }
Пример #2
0
        /// <summary>
        /// Get the blocks.
        /// </summary>
        /// <param name="pageWords">The words in the page.</param>
        /// <param name="minimumWidth">The minimum width for a block.</param>
        /// <param name="dominantFontWidthFunc">The function that determines the dominant font width.</param>
        /// <param name="dominantFontHeightFunc">The function that determines the dominant font height.</param>
        public IReadOnlyList <TextBlock> GetBlocks(IEnumerable <Word> pageWords, double minimumWidth,
                                                   Func <IEnumerable <Letter>, double> dominantFontWidthFunc,
                                                   Func <IEnumerable <Letter>, double> dominantFontHeightFunc)
        {
            if (pageWords.Count() == 0)
            {
                return(EmptyArray <TextBlock> .Instance);
            }

            XYLeaf root = new XYLeaf(pageWords); // Create a root node.
            XYNode node = VerticalCut(root, minimumWidth, dominantFontWidthFunc, dominantFontHeightFunc);

            if (node.IsLeaf)
            {
                return(new List <TextBlock> {
                    new TextBlock((node as XYLeaf).GetLines())
                });
            }
            else
            {
                var leaves = node.GetLeaves();

                if (leaves.Count > 0)
                {
                    return(leaves.Select(l => new TextBlock(l.GetLines())).ToList());
                }
            }

            return(new List <TextBlock>());
        }