Esempio n. 1
0
        public System.Collections.Generic.IReadOnlyList <Block> GetScriptBlocks(bool join)
        {
            if (!join)
            {
                return(GetScriptBlocks());
            }

            EnsureBlockCount();

            if (!join || m_blockCount == 0)
            {
                return(m_blocks);
            }

            var list = new List <Block>(m_blockCount)
            {
                m_blocks[0]
            };

            if (m_styleSheet == null)
            {
                m_styleSheet = SfmLoader.GetUsfmStylesheet();
            }

            for (var i = 1; i < m_blockCount; i++)
            {
                var block     = m_blocks[i];
                var prevBlock = list.Last();
                var style     = (StyleAdapter)m_styleSheet.GetStyle(block.StyleTag);

                if (!block.MatchesReferenceText && !list[list.Count - 1].MatchesReferenceText &&
                    (!block.IsParagraphStart || (style.IsPoetic && !CharacterUtils.EndsWithSentenceFinalPunctuation(prevBlock.GetText(false)))))
                {
                    if (block.CharacterIdInScript == prevBlock.CharacterIdInScript && (block.Delivery ?? string.Empty) == (prevBlock.Delivery ?? string.Empty))
                    {
                        list[list.Count - 1] = CombineBlockWithPreviousBlock(block, prevBlock);
                        continue;
                    }
                }

                list.Add(block);
            }
            return(list);
        }
Esempio n. 2
0
        public System.Collections.Generic.IReadOnlyList <Block> GetScriptBlocks(bool join)
        {
            if (!join)
            {
                return(GetScriptBlocks());
            }

            EnsureBlockCount();

            if (!join || m_blockCount == 0)
            {
                return(m_blocks);
            }

            var list = new List <Block>(m_blockCount);

            if (SingleVoice)
            {
                list.Add(m_blocks[0].Clone());
                var prevBlock = list.Single();
                prevBlock.MatchesReferenceText = false;
                var narrator = CharacterVerseData.GetStandardCharacterId(BookId, CharacterVerseData.StandardCharacter.Narrator);
                for (var i = 1; i < m_blockCount; i++)
                {
                    var clonedBlock = m_blocks[i].Clone();
                    clonedBlock.MatchesReferenceText = false;
                    if (!clonedBlock.CharacterIsStandard)
                    {
                        clonedBlock.CharacterId = narrator;
                    }

                    if (!clonedBlock.IsParagraphStart || (clonedBlock.IsFollowOnParagraphStyle && !CharacterUtils.EndsWithSentenceFinalPunctuation(prevBlock.GetText(false))))                     // && clonedBlock.CharacterId == prevBlock.CharacterId)
                    {
                        prevBlock.CombineWith(clonedBlock);
                    }
                    else
                    {
                        list.Add(clonedBlock);
                        prevBlock = clonedBlock;
                    }
                }
            }
            else
            {
                list.Add(m_blocks[0]);
                if (m_styleSheet == null)
                {
                    m_styleSheet = SfmLoader.GetUsfmStylesheet();
                }

                for (var i = 1; i < m_blockCount; i++)
                {
                    var block     = m_blocks[i];
                    var prevBlock = list.Last();

                    if (block.MatchesReferenceText == prevBlock.MatchesReferenceText &&
                        block.CharacterIdInScript == prevBlock.CharacterIdInScript && (block.Delivery ?? Empty) == (prevBlock.Delivery ?? Empty))
                    {
                        bool combine = false;
                        if (block.MatchesReferenceText)
                        {
                            combine = block.ReferenceBlocks.Single().StartsWithEllipsis ||
                                      ((!block.IsParagraphStart || (block.IsFollowOnParagraphStyle && !CharacterUtils.EndsWithSentenceFinalPunctuation(prevBlock.GetText(false)))) &&
                                       !block.ContainsVerseNumber &&
                                       ((!block.ReferenceBlocks.Single().BlockElements.OfType <Verse>().Any() &&
                                         !CharacterUtils.EndsWithSentenceFinalPunctuation(prevBlock.GetText(false))) ||
                                        block.ReferenceBlocks.Single().BlockElements.OfType <ScriptText>().All(t => t.Content.All(IsWhiteSpace)) ||
                                        prevBlock.ReferenceBlocks.Single().BlockElements.OfType <ScriptText>().All(t => t.Content.All(IsWhiteSpace))));
                        }
                        else if (!block.StartsAtVerseStart)
                        {
                            var style = (StyleAdapter)m_styleSheet.GetStyle(block.StyleTag);
                            combine = !block.IsParagraphStart || (style.IsPoetic && !CharacterUtils.EndsWithSentenceFinalPunctuation(prevBlock.GetText(false)));
                        }
                        if (combine)
                        {
                            list[list.Count - 1] = Block.CombineBlocks(prevBlock, block);
                            continue;
                        }
                    }
                    list.Add(block);
                }
            }
            return(list);
        }