示例#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);
        }
示例#2
0
        public static void CreateSampleProjectIfNeeded()
        {
            if (File.Exists(SampleProjectFilePath))
            {
                return;
            }
            var sampleMetadata = new GlyssenDblTextMetadata();

            sampleMetadata.AvailableBooks = new List <Book>();
            var bookOfMark = new Book();

            bookOfMark.Code            = "MRK";
            bookOfMark.IncludeInScript = true;
            bookOfMark.LongName        = "De Good Nyews Bout Jedus Christ Wa Mark Write";
            bookOfMark.ShortName       = "Mark";
            bookOfMark.Abbreviation    = "Mr";
            sampleMetadata.AvailableBooks.Add(bookOfMark);
            sampleMetadata.FontFamily       = "Times New Roman";
            sampleMetadata.FontSizeInPoints = 12;
            sampleMetadata.Id        = kSample;
            sampleMetadata.Copyright = Copyright;
            sampleMetadata.Promotion = Promotion;
            sampleMetadata.Language  = new GlyssenDblMetadataLanguage {
                Iso = kSample
            };
            sampleMetadata.Identification = new DblMetadataIdentification {
                Name = kSampleProjectName, NameLocal = kSampleProjectName
            };
            sampleMetadata.ProjectStatus.ProjectSettingsStatus = ProjectSettingsStatus.Reviewed;
            sampleMetadata.ProjectStatus.QuoteSystemStatus     = QuoteSystemStatus.Obtained;
            sampleMetadata.ProjectStatus.BookSelectionStatus   = BookSelectionStatus.Reviewed;

            var sampleWs = new WritingSystemDefinition();

            sampleWs.QuotationMarks.AddRange(GetSampleQuoteSystem().AllLevels);

            XmlDocument sampleMark = new XmlDocument();

            sampleMark.LoadXml(Resources.SampleMRK);
            UsxDocument mark = new UsxDocument(sampleMark);

            new Project(sampleMetadata, new[] { mark }, SfmLoader.GetUsfmStylesheet(), sampleWs);
        }
示例#3
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);
        }