예제 #1
0
        internal override void InsertText(InsertionPoint ip, string input)
        {
            MultiAccessor.set_String(m_ws, ((MlsClientRun)ParaBox.Source.ClientRuns[ClientRunIndex]).Tss);
            var bldr = MultiAccessor.get_String(m_ws).GetBldr();
            // Where there is a choice, we want the new text to have the properties of the neighbor
            // character that the IP is most closely associated with.
            ITsTextProps props;

            if (ip.StringPosition > 0 && ip.AssociatePrevious)
            {
                props = bldr.get_PropertiesAt(ip.StringPosition - 1);
            }
            else
            {
                props = bldr.get_PropertiesAt(ip.StringPosition);                 // might be the lim, but that's OK.
            }
            if (ip.StyleToBeApplied != null)
            {
                var propsBldr = props.GetBldr();
                propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, ip.StyleToBeApplied.Name);
                props = propsBldr.GetTextProps();
            }

            // Enhance JohnT: there may possibly be some special caes, e.g., where the indicated character
            // is an ORC linked to certain kinds of data or a verse number, where we don't want to copy all
            // the properties.
            bldr.Replace(ip.StringPosition, ip.StringPosition, input, props);
            MultiAccessor.set_String(m_ws, bldr.GetString());
        }
예제 #2
0
        internal override void InsertText(InsertionPoint ip, ITsString input)
        {
            var bldr = ((TssClientRun)ParaBox.Source.ClientRuns[ClientRunIndex]).Tss.GetBldr();

            bldr.ReplaceTsString(ip.StringPosition, ip.StringPosition, input);
            MultiAccessor.set_String(m_ws, bldr.GetString());
        }
예제 #3
0
        /// <summary>
        /// Get the actual ws of the WritingSystem based on the given hvo.
        /// If the WritingSystem is not magic, it'll just return WritingSystem.
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="hvo"></param>
        /// <param name="wsPreferred">the ws to prefer over the standard sequence in current writing systems list. also used as a default
        /// if no alternative ws can be found.</param>
        /// <returns></returns>
        public int GetActualWs(FdoCache cache, int hvo, int wsPreferred)
        {
            int wsActual = 0;

            if (this.StringFlid == -1)
            {
                // we depend upon someone else to determine the ws.
                return(0);
            }
            if (this.WritingSystem == LangProject.kwsFirstVern && wsPreferred != 0)
            {
                // first try the preferred hvo before looking for one in the standard sequence of the writing systems list.
                MultiAccessor ma = MultiAccessor.CreateMultiAccessor(cache, hvo, this.StringFlid, "");
                ma.GetAlternativeOrBestTss(wsPreferred, out wsActual);
            }
            if (wsActual == 0)
            {
                wsActual = cache.LangProject.ActualWs(this.WritingSystem, hvo, this.StringFlid);
            }
            if (wsActual == 0)
            {
                wsActual = wsPreferred;
            }
            return(wsActual);
        }
예제 #4
0
        protected static ITsString GetTssLabel(FdoCache cache, int hvoItem, int flidName, int wsName)
        {
            MultiAccessor ma = MultiAccessor.CreateMultiAccessor(cache, hvoItem, flidName);
            int           wsActual;
            ITsString     tssLabel = ma.GetAlternativeOrBestTss(wsName, out wsActual);

            return(tssLabel);
        }
예제 #5
0
 internal override void Delete(InsertionPoint start, InsertionPoint end)
 {
     if (CanDelete(start, end))
     {
         MultiAccessor.set_String(m_ws, ((MlsClientRun)ParaBox.Source.ClientRuns[ClientRunIndex]).Tss);
         var bldr   = MultiAccessor.get_String(m_ws).GetBldr();
         int newPos = start.StringPosition;
         bldr.Replace(newPos, end.StringPosition, "", null);
         MultiAccessor.set_String(m_ws, bldr.GetString());
     }
 }
예제 #6
0
        internal override void ApplyStyle(InsertionPoint start, InsertionPoint end, string style)
        {
            if (!CanApplyStyle(start, end, style))
            {
                return;
            }

            MultiAccessor.set_String(m_ws, ((MlsClientRun)ParaBox.Source.ClientRuns[ClientRunIndex]).Tss);
            var bldr   = MultiAccessor.get_String(m_ws).GetBldr();
            int newPos = start.StringPosition;

            bldr.SetStrPropValue(newPos, end.StringPosition, (int)FwTextPropType.ktptNamedStyle, style);
            MultiAccessor.set_String(m_ws, bldr.GetString());
        }
예제 #7
0
        public void MlsRuns()
        {
            string           part1 = "abc def";
            IViewMultiString mls   = new MultiAccessor(wsEn, wsEn);

            mls.set_String(wsEn, tsf.MakeString(part1, wsEn));
            AssembledStyles styles    = new AssembledStyles();
            MlsClientRun    clientRun = new MlsClientRun(mls, styles.WithWs(wsEn));

            Assert.AreEqual(1, clientRun.UniformRunCount);
            Assert.AreEqual(part1, clientRun.UniformRunText(0));
            AssembledStyles style1 = clientRun.UniformRunStyles(0);

            Assert.AreEqual(wsEn, style1.Ws);
            Assert.AreEqual(0, clientRun.UniformRunStart(0));
            Assert.AreEqual(part1.Length, clientRun.UniformRunLength(0));

            string     part2 = " ghi";
            ITsStrBldr bldr  = mls.get_String(wsEn).GetBldr();

            bldr.Replace(part1.Length, part1.Length, part2, ttpFrn);
            IViewMultiString multibldr = new MultiAccessor(wsEn, wsEn);

            multibldr.set_String(wsFrn, bldr.GetString());
            MlsClientRun clientRun2 = new MlsClientRun(multibldr, styles.WithWs(wsFrn));

            Assert.AreEqual(2, clientRun2.UniformRunCount);
            Assert.AreEqual(part1, clientRun2.UniformRunText(0));
            Assert.AreEqual(part2, clientRun2.UniformRunText(1));
            style1 = clientRun2.UniformRunStyles(0);
            Assert.AreEqual(wsEn, style1.Ws);
            AssembledStyles style2 = clientRun2.UniformRunStyles(1);

            Assert.AreEqual(wsFrn, style2.Ws);
            Assert.AreEqual(0, clientRun2.UniformRunStart(0));
            Assert.AreEqual(part1.Length, clientRun2.UniformRunLength(0));
            Assert.AreEqual(part1.Length, clientRun2.UniformRunStart(1));
            Assert.AreEqual(part2.Length, clientRun2.UniformRunLength(1));
        }
예제 #8
0
            private void SetContentFromNode(FdoCache cache, string sNodeName, bool fFixName, MultiAccessor item)
            {
                ILgWritingSystemFactory wsf = cache.LanguageWritingSystemFactoryAccessor;
                ITsStrFactory           tsf = TsStrFactoryClass.Create();
                int     iWS;
                XmlNode nd;
                bool    fContentFound = false;              // be pessimistic

                foreach (ILgWritingSystem ws in cache.LangProject.CurAnalysisWssRS)
                {
                    string sWS = ws.ICULocale;
                    nd = m_node.SelectSingleNode(sNodeName + "[@ws='" + sWS + "']");
                    if (nd == null || nd.InnerText.Length == 0)
                    {
                        continue;
                    }
                    fContentFound = true;
                    string sNodeContent;
                    if (fFixName)
                    {
                        sNodeContent = NameFixer(nd.InnerText);
                    }
                    else
                    {
                        sNodeContent = nd.InnerText;
                    }
                    iWS = wsf.GetWsFromStr(sWS);
                    item.SetAlternative(tsf.MakeString(sNodeContent, iWS), iWS);
                }
                if (!fContentFound)
                {
                    iWS = cache.LangProject.DefaultAnalysisWritingSystem;
                    item.SetAlternative(tsf.MakeString("", iWS), iWS);
                }
            }