Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a footnote reference marker (ref orc)
        /// </summary>
        /// <param name="footnote">given footnote</param>
        /// <param name="para">paragraph owning the translation to insert footnote marker into</param>
        /// <param name="ws">given writing system for the back translation</param>
        /// <param name="ichPos">The 0-based character offset into the translation</param>
        /// ------------------------------------------------------------------------------------
        protected void InsertTestBtFootnote(StFootnote footnote, StTxtPara para, int ws, int ichPos)
        {
            ICmTranslation trans = para.GetOrCreateBT();
            ITsStrBldr     bldr  = trans.Translation.GetAlternative(ws).UnderlyingTsString.GetBldr();

            footnote.InsertRefORCIntoTrans(bldr, ichPos, ws);
            trans.Translation.SetAlternative(bldr.GetString(), ws);
        }
Ejemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a back translation from a format string, and attach it to the
        /// given paragraph.
        /// </summary>
        /// <param name="scrInMemoryCache">in-memory cache to use for testing</param>
        /// <param name="book">book to use</param>
        /// <param name="para">the paragraph that will own this back translation</param>
        /// <param name="format">(See CreateText for the definition of the format string)</param>
        /// <param name="ws">writing system of the back translation</param>
        /// ------------------------------------------------------------------------------------
        internal static void AddBackTranslation(ScrInMemoryFdoCache scrInMemoryCache, IScrBook book,
                                                StTxtPara para, string format, int ws)
        {
            ICmTranslation cmTrans = para.GetOrCreateBT();

            // Set the translation string for the given WS
            cmTrans.Translation.GetAlternative(ws).UnderlyingTsString =
                ScrInMemoryFdoCache.CreateFormatText(book, null, format, ws);
        }
Ejemplo n.º 3
0
        public void MakeLabelFromText_AnnotationOnBackTrans()
        {
            CheckDisposed();

            ScrScriptureNote note = new ScrScriptureNote();

            m_scr.BookAnnotationsOS[0].NotesOS.Append(note);
            note.BeginRef = 01001011;
            note.EndRef   = 01001011;
            StTxtPara para = (StTxtPara)m_gen.SectionsOS[1].ContentOA.ParagraphsOS[0];

            note.BeginObjectRA = para.GetOrCreateBT();
            ITsString tss = m_vc.CallMakeLabelFromText("GEN 1:11", "WhoCares", note);

            Assert.AreEqual(2, tss.RunCount);
            Assert.AreEqual("GEN 1:11", tss.get_RunText(0));
            Assert.AreEqual("WhoCares",
                            tss.get_Properties(0).GetStrPropValue((int)FwTextPropType.ktptNamedStyle));
            CheckFinalSpaceInReferenceLabel(tss);
        }
Ejemplo n.º 4
0
        public void FootnoteTranslationTest()
        {
            // get an existing footnote
            IScrBook    book     = m_scr.ScriptureBooksOS[1];      // book of James
            IStFootnote footnote = book.FootnotesOS[0];
            StTxtPara   para     = (StTxtPara)footnote.ParagraphsOS[0];

            // add a translation to the footnote
            ICmTranslation translation = para.GetOrCreateBT();

            translation.Translation.AnalysisDefaultWritingSystem.UnderlyingTsString =
                TsStringHelper.MakeTSS("abcde", m_fdoCache.DefaultAnalWs);

            FwStyleSheet styleSheet = new FwStyleSheet();

            styleSheet.Init(m_fdoCache, m_scr.Hvo,
                            (int)Scripture.ScriptureTags.kflidStyles);

            // Prepare the test by creating a footnote view
            using (DummyFootnoteView footnoteView = new DummyFootnoteView(m_fdoCache, true))
            {
                footnoteView.StyleSheet = styleSheet;
                footnoteView.Visible    = false;

                // We don't actually want to show it, but we need to force the view to create the root
                // box and lay it out so that various test stuff can happen properly.
                footnoteView.MakeRoot();
                footnoteView.CallLayout();

                // Select the footnote marker and some characters of the footnote paragraph
                footnoteView.RootBox.MakeSimpleSel(true, true, false, true);
                SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView);

                // Now the real test:
                IVwSelection sel = footnoteView.RootBox.Selection.GrowToWord();
                ITsString    tss;
                sel.GetSelectionString(out tss, string.Empty);
                Assert.AreEqual("abcde", tss.Text);
            }
        }
Ejemplo n.º 5
0
        public void GetAnnotationLocationInfo_BTLongerThanVern()
        {
            CheckDisposed();

            int wsBt = Cache.DefaultAnalWs;
            // Add a section
            IScrSection   section    = m_scr.ScriptureBooksOS[0].SectionsOS[1];
            StTxtPara     para       = (StTxtPara)section.ContentOA.ParagraphsOS[0];
            CmTranslation transPara1 = (CmTranslation)para.GetOrCreateBT();

            // The text "11BT Verse one" is already added, but we add a couple more verses...
            m_scrInMemoryCache.AddRunToMockedTrans(transPara1, wsBt, ". ", null);
            m_scrInMemoryCache.AddRunToMockedTrans(transPara1, wsBt, "2", ScrStyleNames.VerseNumber);
            m_scrInMemoryCache.AddRunToMockedTrans(transPara1, wsBt, "BT verse two. ", null);
            section.AdjustReferences();

            // Set up a simple selection in the first back translation paragraph.
            m_btDraftView.SelectRangeOfChars(0, 1, 0, 0, 25);

            CmObject  topObj, bottomObj;
            int       wsSelector;
            int       startOffset, endOffset;
            ITsString tssQuote;
            BCVRef    startRef, endRef;

            m_btDraftView.TeEditingHelper.GetAnnotationLocationInfo(out topObj, out bottomObj, out wsSelector,
                                                                    out startOffset, out endOffset, out tssQuote, out startRef, out endRef);

            Assert.AreEqual(transPara1.Hvo, topObj.Hvo);
            Assert.AreEqual(transPara1.Hvo, bottomObj.Hvo);
            Assert.AreEqual(wsBt, wsSelector);
            Assert.AreEqual(0, startOffset);
            Assert.AreEqual(25, endOffset);
            Assert.AreEqual(new BCVRef(2, 1, 1), startRef);
            Assert.AreEqual(new BCVRef(2, 1, 2), endRef);
            Assert.AreEqual("BT Verse one. BT verse", tssQuote.Text);
        }
Ejemplo n.º 6
0
        public static void UpdateMainTransFromSegmented(StTxtPara para, int[] wss)
        {
            if (!para.IsValidObject())
            {
                return;                 // in merge, paragraph may be modified then deleted.
            }
            FdoCache cache = para.Cache;

            BtConverter.EnsureMainParaSegments(para, wss[0]);
            ISilDataAccess sda         = cache.MainCacheAccessor;
            List <int>     segments    = para.Segments;
            int            kflidFT     = StTxtPara.SegmentFreeTranslationFlid(cache);
            ITsString      tssContents = para.Contents.UnderlyingTsString;
            IScripture     scr         = para.Cache.LangProject.TranslatedScriptureOA;
            ICmTranslation originalBT  = para.GetBT();            // Can be null
            string         sUnfinished = BackTranslationStatus.Unfinished.ToString();

            foreach (int ws in wss)
            {
                ITsStrBldr bldr          = TsStrBldrClass.Create();
                bool       wantNextSpace = false;        // suppresses space before the first thing we add.
                bool       haveBtText    = false;        // Text that isn't segment label text
                foreach (int hvoSeg in segments)
                {
                    // If it's a label, insert it directly. Suppress following space.
                    int       beginOffset = sda.get_IntProp(hvoSeg, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset);
                    int       endOffset   = sda.get_IntProp(hvoSeg, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset);
                    ITsString tssFt;
                    // Whether we want to insert a space before the current segment is determined by the previous one.
                    // Save that value so we can set wantSpace appropriately for the following one.
                    bool wantSpace = wantNextSpace;
                    if (SegmentBreaker.HasLabelText(tssContents, beginOffset, endOffset))
                    {
                        tssFt         = (new CmBaseAnnotation(cache, hvoSeg)).TextAnnotated;
                        tssFt         = scr.ConvertCVNumbersInStringForBT(CorrectFootnotes(tssFt), ws);
                        wantNextSpace = false;
                    }
                    else
                    {
                        int hvoFt = sda.get_ObjectProp(hvoSeg, kflidFT);
                        tssFt         = sda.get_MultiStringAlt(hvoFt, (int)CmAnnotation.CmAnnotationTags.kflidComment, ws);
                        haveBtText   |= (tssFt.Length > 0);
                        wantNextSpace = EndsWithNonSpace(tssFt);
                    }
                    if (tssFt.Length > 0)
                    {
                        if (wantSpace)
                        {
                            // The preceding segment should typically be followed by a space.
                            if (!StartsWithSpaceOrOrc(tssFt))
                            {
                                bldr.Replace(bldr.Length, bldr.Length, " ", null);
                            }
                        }
                        bldr.ReplaceTsString(bldr.Length, bldr.Length, tssFt);
                    }
                }

                // If the back translation doesn't have text, we don't want to create verse
                // segment labels. This prevents the problem where the book thinks it has a
                // back translation because of automatically generated verse labels (TE-8283).
                if (!haveBtText)
                {
                    // This check might not be needed, but it shouldn't hurt anything.
                    if (originalBT != null)
                    {
                        if (originalBT.Translation.GetAlternative(ws).Length > 0)
                        {
                            string origStatus = originalBT.Status.GetAlternative(ws);
                            if (!String.IsNullOrEmpty(origStatus) && origStatus != sUnfinished)
                            {
                                originalBT.Status.SetAlternative(sUnfinished, ws);
                            }
                        }
                    }
                    continue;
                }

                ITsString      newFt = bldr.GetString();
                ICmTranslation trans;
                if (newFt.Length == 0)
                {
                    trans = para.GetBT();
                    if (trans == null)
                    {
                        return;                         // don't bother creating one to store an empty translation!
                    }
                }
                else
                {
                    trans = para.GetOrCreateBT();
                }
                // Don't write unless it changed...PropChanged can be expensive.
                if (!trans.Translation.GetAlternative(ws).UnderlyingTsString.Equals(newFt))
                {
                    trans.Translation.SetAlternative(newFt, ws);
                    trans.Status.SetAlternative(sUnfinished, ws);
                }
            }
        }
Ejemplo n.º 7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get the hvo of the (for now, first) translation of a paragraph
        /// </summary>
        /// <param name="hvoPara"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        protected int GetTranslationForPara(int hvoPara)
        {
            StTxtPara para = new StTxtPara(Cache, hvoPara);

            return(para.GetOrCreateBT().Hvo);
        }
Ejemplo n.º 8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new StFootnote owned by the given book created from the given string
        /// representation (Created from GetTextRepresentation())
        /// </summary>
        /// <param name="owner">The object that owns the sequence of footnotes into which the
        /// new footnote is to be inserted</param>
        /// <param name="flid">The field id of the property in which the footnotes are owned
        /// </param>
        /// <param name="sTextRepOfFootnote">The given string representation of a footnote
        /// </param>
        /// <param name="footnoteIndex">0-based index where the footnote will be inserted</param>
        /// <param name="footnoteMarkerStyleName">style name for footnote markers</param>
        /// <returns>An StFootnote with the properties set to the properties in the
        /// given string representation</returns>
        /// ------------------------------------------------------------------------------------
        public static StFootnote CreateFromStringRep(CmObject owner, int flid,
                                                     string sTextRepOfFootnote, int footnoteIndex, string footnoteMarkerStyleName)
        {
            StFootnote createdFootnote = new StFootnote(owner, flid, footnoteIndex);

            // create an XML reader to read in the string representation
            System.IO.StringReader reader = new System.IO.StringReader(sTextRepOfFootnote);
            XmlDocument            doc    = new XmlDocument();

            try
            {
                doc.Load(reader);
            }
            catch (XmlException)
            {
                throw new ArgumentException("Unrecognized XML format for footnote.");
            }

            XmlNodeList tagList = doc.SelectNodes("FN");

            foreach (XmlNode bla in tagList[0].ChildNodes)
            {
                // Footnote marker
                if (bla.Name == "M")
                {
                    ITsPropsBldr propBlr = TsPropsBldrClass.Create();
                    propBlr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                            footnoteMarkerStyleName);
                    ITsStrBldr tss = TsStrBldrClass.Create();
                    tss.Replace(0, 0, bla.InnerText, propBlr.GetTextProps());
                    createdFootnote.FootnoteMarker.UnderlyingTsString = tss.GetString();
                }

                // Display footnote marker
                else if (bla.Name == "ShowMarker")
                {
                    createdFootnote.DisplayFootnoteMarker = true;
                }
                // display footnote scripture reference
                else if (bla.Name == "ShowReference")
                {
                    createdFootnote.DisplayFootnoteReference = true;
                }
                // start of a paragraph
                else if (bla.Name == "P")
                {
                    StTxtPara newPara = new StTxtPara();
                    createdFootnote.ParagraphsOS.Append(newPara);
                    ITsIncStrBldr paraBldr = TsIncStrBldrClass.Create();
                    CmTranslation trans    = null;
                    //ITsStrBldr paraBldr = TsStrBldrClass.Create();
                    foreach (XmlNode paraTextNode in bla.ChildNodes)
                    {
                        if (paraTextNode.Name == "PS")
                        {
                            // paragraph style
                            ITsPropsBldr propBldr =
                                TsPropsBldrClass.Create();
                            if (!String.IsNullOrEmpty(paraTextNode.InnerText))
                            {
                                propBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                                         paraTextNode.InnerText);
                            }
                            else
                            {
                                Debug.Fail("Attempting to create a footnote paragraph with no paragraph style specified!");
                            }
                            newPara.StyleRules = propBldr.GetTextProps();
                        }
                        else if (paraTextNode.Name == "RUN")
                        {
                            CreateRunFromStringRep(owner, paraBldr, paraTextNode);
                            paraBldr.Append(paraTextNode.InnerText);
                        }
                        else if (paraTextNode.Name == "TRANS")
                        {
                            if (trans == null)
                            {
                                trans = (CmTranslation)newPara.GetOrCreateBT();
                            }

                            // Determine which writing system where the string run(s) will be added.
                            string iculocale = paraTextNode.Attributes.GetNamedItem("WS").Value;
                            if (iculocale == null || iculocale == string.Empty)
                            {
                                throw new ArgumentException(
                                          "Unknown ICU locale encountered: " + iculocale);
                            }
                            int transWS = owner.Cache.LanguageEncodings.GetWsFromIcuLocale(iculocale);
                            Debug.Assert(transWS != 0, "Unable to find ws from ICU Locale");

                            // Build a TsString from the run(s) description.
                            ITsIncStrBldr strBldr = TsIncStrBldrClass.Create();
                            foreach (XmlNode transTextNode in paraTextNode.ChildNodes)
                            {
                                if (transTextNode.Name != "RUN")
                                {
                                    throw new ArgumentException("Unexpected translation element '" +
                                                                transTextNode.Name + "' encountered for ws '" + iculocale + "'");
                                }

                                CreateRunFromStringRep(owner, strBldr, transTextNode);
                                strBldr.Append(transTextNode.InnerText);
                            }

                            trans.Translation.SetAlternative(strBldr.GetString(), transWS);
                        }
                    }
                    newPara.Contents.UnderlyingTsString = paraBldr.GetString();
                }
            }
            owner.Cache.PropChanged(null, PropChangeType.kpctNotifyAll, owner.Hvo, flid, footnoteIndex, 1, 0);
            return(createdFootnote);
        }