private void ProcessRunElements(XmlNodeList runNodes, ITsIncStrBldr tisb)
 {
     foreach (XmlNode runNode in runNodes)
     {
         ProcessRunElement(runNode, tisb);
     }
 }
Exemple #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates the a text run from a string representation.
        /// </summary>
        /// <param name="owner">The owner of the paragraph (book).</param>
        /// <param name="strBldr">The structured string builder.</param>
        /// <param name="textNode">The text node which describes runs to be added to the
        /// paragraph or to the translation for a particular writing system</param>
        /// ------------------------------------------------------------------------------------
        private static void CreateRunFromStringRep(CmObject owner, ITsIncStrBldr strBldr,
                                                   XmlNode textNode)
        {
            XmlNode charStyle = textNode.Attributes.GetNamedItem("CS");

            if (charStyle != null)
            {
                strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                        charStyle.Value);
            }
            else
            {
                strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                        null);
            }

            XmlNode wsICULocale = textNode.Attributes.GetNamedItem("WS");

            if (wsICULocale != null)
            {
                ILgWritingSystemFactory wsf = owner.Cache.LanguageWritingSystemFactoryAccessor;
                int ws = wsf.GetWsFromStr(wsICULocale.Value);
                if (ws <= 0)
                {
                    throw new ArgumentException("Unknown ICU locale encountered: '" + wsICULocale.Value + "'");
                }
                strBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                         (int)FwTextPropVar.ktpvDefault, wsf.GetWsFromStr(wsICULocale.Value));
            }
            else
            {
                throw new ArgumentException("Required attribute WS missing from RUN element.");
            }
        }
Exemple #3
0
        public void GoodMultiUnicodeTest()
        {
            // Start with expected information.
            Assert.AreEqual(0, Cache.LangProject.MainCountry.StringCount, "Wrong number of alternatives for Cache.LangProject.MainCountryAccessor");

            // Create a good string.
            var           english = Cache.LangProject.CurrentAnalysisWritingSystems.First();
            ITsIncStrBldr tisb    = TsStringUtils.MakeIncStrBldr();

            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, english.Handle);
            tisb.Append("Mexico");
            Cache.LangProject.MainCountry.set_String(english.Handle, tisb.GetString());

            // Make sure it is in there now.
            Assert.AreEqual(1, Cache.LangProject.MainCountry.StringCount, "Wrong number of alternatives for Cache.LangProject.MainCountryAccessor");
            int ws;
            var mexico = Cache.LangProject.MainCountry.GetStringFromIndex(0, out ws);

            Assert.AreEqual(english.Handle, ws, "Wrong writing system.");
            Assert.AreEqual("Mexico", mexico.Text, "Wrong text.");

            // Add the same ws string, but with different text.
            tisb = TsStringUtils.MakeIncStrBldr();
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, english.Handle);
            tisb.Append("Guatemala");
            Cache.LangProject.MainCountry.set_String(english.Handle, tisb.GetString());

            // Make sure it is in there now.
            Assert.AreEqual(1, Cache.LangProject.MainCountry.StringCount, "Wrong number of alternatives for Cache.LangProject.MainCountryAccessor");
            var guatemala = Cache.LangProject.MainCountry.GetStringFromIndex(0, out ws);

            Assert.AreEqual(english.Handle, ws, "Wrong writing system.");
            Assert.AreEqual("Guatemala", guatemala.Text, "Wrong text.");
        }
Exemple #4
0
        private void AddNumberingNowOrDelayed(bool fDelayNumber, ITsString tss, out ITsString tssDelayedNumber)
        {
            if (fDelayNumber)
            {
                m_viewConstructor.DelayNumFlag = true;

                ITsIncStrBldr tisb = tss.GetIncBldr();
                tisb.Append("  ");                 // add some padding for separation
                tssDelayedNumber   = tisb.GetString();
                m_hvoDelayedNumber = m_hvo;
            }
            else
            {
                m_viewConstructor.DelayNumFlag = false;

                OutputItemNumber(m_vwEnv, tss);
                tssDelayedNumber = null;
            }
            // This groups senses by placing graminfo before the number, and omitting it if the same as the
            // previous sense in the entry.  This isn't yet supported by the UI, but may well be requested in
            // the future.  (See LT-9663.)
            //if (fGramInfoBeforeNumber)
            //{
            //    tssDelayedNumber = tss;
            //    if (fFirst)
            //        m_hvoGroupedValue = 0;
            //}
            //else if (!m_fDelayNumber)
            //{
            //    m_vwEnv.AddString(tss);
            //    tssDelayedNumber = null;
            //}
        }
Exemple #5
0
        private static void AddVariantTypeGlossInfo(ITsIncStrBldr sb, CoreWritingSystemDefinition wsGloss, IList <IMultiUnicode> multiUnicodeAccessors, CoreWritingSystemDefinition wsUser)
        {
            const string sSeriesSeparator = kDefaultSeriesSeparatorLexEntryTypeReverseAbbr;
            var          fBeginSeparator  = true;

            foreach (var multiUnicodeAccessor in multiUnicodeAccessors)
            {
                int wsActual2;
                var tssVariantTypeInfo = multiUnicodeAccessor.GetAlternativeOrBestTss(wsGloss.Handle, out wsActual2);
                // just concatenate them together separated by comma.
                if (tssVariantTypeInfo == null || tssVariantTypeInfo.Length <= 0)
                {
                    continue;
                }
                if (!fBeginSeparator)
                {
                    sb.AppendTsString(TsStringUtils.MakeString(sSeriesSeparator, wsUser.Handle));
                }
                sb.AppendTsString((tssVariantTypeInfo));
                fBeginSeparator = false;
            }

            // Handle the special case where no reverse abbr was found.
            if (fBeginSeparator && multiUnicodeAccessors.Count > 0)
            {
                sb.AppendTsString(multiUnicodeAccessors.ElementAt(0).NotFoundTss);
            }
        }
Exemple #6
0
 /// <summary>
 /// This method will use the current homograph-number settings to insert the homograph number into the string
 /// </summary>
 public static void InsertHomographNumber(ITsIncStrBldr tisb, int nHomograph, HomographConfiguration hc,
                                          HomographConfiguration.HeadwordVariant hv, LcmCache cache)
 {
     if (nHomograph > 0 && hc.ShowHomographNumber(hv))
     {
         tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, HomographConfiguration.ksHomographNumberStyle);
         if (!string.IsNullOrEmpty(hc.WritingSystem))
         {
             tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, cache.WritingSystemFactory.GetWsFromStr(hc.WritingSystem));
         }
         else
         {
             tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, cache.DefaultVernWs);
         }
         var hnString = nHomograph.ToString();
         if (hc.CustomHomographNumbers.Count == 10)
         {
             for (var i = 0; i < 10; ++i)
             {
                 hnString = hnString.Replace(i.ToString(), hc.CustomHomographNumbers[i]);
             }
         }
         tisb.Append(hnString);
         tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null);
     }
 }
Exemple #7
0
 /// <summary>
 /// Merge two MultiUnicodeAccessor objects.
 /// These cases are handled:
 ///		1. If an alternative exists in both objects, nothing is merged.
 ///		2. If the main object (this) is missing an alternative, and the 'source' has it, then add it to 'this'.
 ///		3. If the main object has an alternative, then do nothing.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="fConcatenateIfBoth"></param>
 /// <param name="sep">separator to use if concatenating</param>
 public void MergeAlternatives(IMultiStringAccessor source, bool fConcatenateIfBoth, string sep)
 {
     if (source == null)
     {
         return;                 // Nothing to do.
     }
     foreach (var lws in m_object.Services.WritingSystemManager.WritingSystems)
     {
         var ws     = lws.Handle;
         var myAlt  = get_String(ws);
         var srcAlt = source.get_String(ws);
         if ((myAlt == null || myAlt.Length == 0) &&
             (srcAlt != null && srcAlt.Length != 0))
         {
             set_String(ws, srcAlt);
         }
         else if (!fConcatenateIfBoth)
         {
             continue;
         }
         else if (myAlt != null && myAlt.Length != 0 &&
                  srcAlt != null && srcAlt.Length != 0 &&
                  !myAlt.Equals(srcAlt))
         {
             ITsIncStrBldr newBldr = TsStringUtils.MakeIncStrBldr();
             newBldr.AppendTsString(get_String(ws));
             newBldr.Append(sep);
             newBldr.AppendTsString(source.get_String(ws));
             set_String(ws, newBldr.GetString());
         }
     }
 }
Exemple #8
0
        private static void AddHeadwordForWsAndHn(ILexEntry entry, int wsVern, int nHomograph, HomographConfiguration.HeadwordVariant hv,
                                                  ITsIncStrBldr tisb, string citationForm, LcmCache cache)
        {
            var ws = cache?.WritingSystemFactory?.get_EngineOrNull(wsVern);

            // Audio writing systems actually store a filename and should not have homograph numbers attached
            if (IsAudioWritingSystem(ws))
            {
                tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsVern);
                tisb.Append(citationForm);
                return;
            }
            var hc = entry.Services.GetInstance <HomographConfiguration>();

            if (hc.HomographNumberBefore)
            {
                InsertHomographNumber(tisb, nHomograph, hc, hv, cache);
            }
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsVern);
            tisb.Append(citationForm);

            if (!hc.HomographNumberBefore)
            {
                InsertHomographNumber(tisb, nHomograph, hc, hv, cache);
            }
        }
Exemple #9
0
        public void UpdateUserPrompt_Vern_Typing()
        {
            // Set up section head with an empty paragraph
            IScrSection section = AddSectionToMockedBook(m_book);
            IStTxtPara  para    = AddSectionHeadParaToSection(section, "",
                                                              ScrStyleNames.SectionHead);

            IVwRootBox   rootb;
            IVwSelection vwsel;
            IVwRootSite  rootsite;

            SetUpResultsForUpdateUserPromptTests(4, "t", out rootb, out vwsel, out rootsite);

            int defVernWs = Cache.DefaultVernWs;

            DummyTeStVc   stVc    = new DummyTeStVc(Cache, defVernWs, rootb);
            ITsIncStrBldr strBdlr = TsIncStrBldrClass.Create();

            strBdlr.SetIntPropValues(SimpleRootSite.ktptUserPrompt, (int)FwTextPropVar.ktpvDefault, 1);
            strBdlr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, Cache.DefaultUserWs);
            strBdlr.Append("t");
            ITsString tssTyped    = strBdlr.GetString();
            ITsString tssExpected = TsStringUtils.MakeTss("t", defVernWs);

            // Now simulate the user typing over the user prompt
            stVc.UpdateProp(vwsel, para.Hvo, SimpleRootSite.kTagUserPrompt, 0, tssTyped);

            // verify that the text is in the paragraph and that there is no longer a user prompt.
            string diff;

            Assert.IsTrue(TsStringHelper.TsStringsAreEqual(tssExpected, para.Contents, out diff), diff);

            m_vwenvMock.VerifyAllExpectations();
            VerifyArgsSentToRequestSelectionAtEndOfUow(rootsite, rootb, 0, 4, StTxtParaTags.kflidContents, "t");
        }
Exemple #10
0
        public void GetTextRepresentation_MultiCharStylePara()
        {
            ITsIncStrBldr strBldr = m_footnotePara.Contents.GetIncBldr();

            // run 1
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    "Emphasis");
            strBldr.Append("Test Text");

            // run 2
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    null);
            strBldr.Append("No char style");

            // run 3
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    "Quoted Text");
            strBldr.Append("Ahh!!!!!!");

            // run 4
            strBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                     (int)FwTextPropVar.ktpvDefault, m_wsDe);
            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    "Untranslated Word");
            strBldr.Append(" untranslated");

            m_footnotePara.Contents = strBldr.GetString();

            string result = m_footnote.TextRepresentation;

            Assert.AreEqual("<FN><M>a</M><P><PS>Note General Paragraph</PS>" +
                            "<RUN WS='fr' CS='Emphasis'>Test Text</RUN><RUN WS='fr'>No char style</RUN>" +
                            "<RUN WS='fr' CS='Quoted Text'>Ahh!!!!!!</RUN>" +
                            "<RUN WS='de' CS='Untranslated Word'> untranslated</RUN></P></FN>", result);
        }
        /// <summary>
        /// Crawls all runs in the specified string. The run modifier is called for each run in the
        /// specified string. If the run modifier returns <c>null</c>, the run is removed from
        /// the string. If all runs are removed, this method returns <c>null</c>.
        /// </summary>
        /// <param name="str">The string.</param>
        /// <param name="runModifier">The run modifier.</param>
        /// <returns></returns>
        public static ITsString CrawlRuns(ITsString str, Func <ITsString, ITsString> runModifier)
        {
            ITsIncStrBldr tisb     = TsIncStrBldrClass.Create();
            bool          modified = false;
            bool          empty    = true;

            for (int i = 0; i < str.RunCount; i++)
            {
                int ichMin, ichLim;
                str.GetBoundsOfRun(i, out ichMin, out ichLim);
                ITsString oldRun = str.GetSubstring(ichMin, ichLim);
                ITsString newRun = runModifier(oldRun);
                if (newRun != null)
                {
                    if (modified || newRun != oldRun)
                    {
                        tisb.AppendTsString(newRun);
                        modified = true;
                    }
                    empty = false;
                }
                else
                {
                    modified = true;
                }
            }

            if (empty)
            {
                return(null);
            }

            return(modified ? tisb.GetString() : str);
        }
Exemple #12
0
        /// <summary>
        /// Returns a TsString with the entry headword and a sense number if there
        /// are more than one senses.
        /// </summary>
        public ITsString OwnerOutlineNameForWs(ILexSense sense, int wsVern, HomographConfiguration.HeadwordVariant hv)
        {
            var entry = sense.Entry;
            int hn;

            if (!m_homographNumbers.TryGetValue(entry.Hvo, out hn))
            {
                hn = entry.HomographNumber;                 // unknown entry, use its own HN instead of our override
            }
            ITsIncStrBldr tisb = TsIncStrBldrClass.Create();

            tisb.AppendTsString(StringServices.HeadWordForWsAndHn(entry, wsVern, hn, "", hv));
            var hc = sense.Services.GetInstance <HomographConfiguration>();

            if (hc.ShowSenseNumber(hv) && HasMoreThanOneSense(entry))
            {
                // These int props may not be needed, but they're safe.
                tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0,
                                      Cache.DefaultAnalWs);
                tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                     HomographConfiguration.ksSenseReferenceNumberStyle);
                tisb.Append(" ");
                tisb.Append(GetSenseNumber(sense));
            }
            return(tisb.GetString());
        }
		/// <summary>
		/// This method will be overridden in common subtypes (like MoStemMsa)
		/// to use the TsIncStrBldr passed to it instead of creating another builder.
		/// (See LT-13728 for performance issues.)
		/// </summary>
		/// <param name="tisb"></param>
		internal virtual void AddChooserNameInItalics(ITsIncStrBldr tisb)
		{
			ITsStrBldr tsb = ChooserNameTS.GetBldr();
			tsb.SetIntPropValues(0, tsb.Length, (int)FwTextPropType.ktptItalic,
									(int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn);
			tisb.AppendTsString(tsb.GetString());
		}
Exemple #14
0
        /// <summary>
        /// Filters LexEntryInflType items from the given variantEntryTypesRs list and joins the GlossPrepend and GlossAppend strings
        /// according to the given wsGloss in a format like ("pl.pst." for GlossPrepend  and ".pl.pst" for GlossAppend).
        /// </summary>
        /// <param name="variantEntryTypesRs"></param>
        /// <param name="wsGloss"></param>
        /// <param name="sbJoinedGlossPrepend"></param>
        /// <param name="sbJoinedGlossAppend"></param>
        public static void JoinGlossAffixesOfInflVariantTypes(IEnumerable <ILexEntryType> variantEntryTypesRs, CoreWritingSystemDefinition wsGloss,
                                                              out ITsIncStrBldr sbJoinedGlossPrepend,
                                                              out ITsIncStrBldr sbJoinedGlossAppend)
        {
            sbJoinedGlossPrepend = TsStringUtils.MakeIncStrBldr();
            sbJoinedGlossAppend  = TsStringUtils.MakeIncStrBldr();

            const string sSeparator = kDefaultSeparatorLexEntryInflTypeGlossAffix;

            foreach (var leit in variantEntryTypesRs.Where(let => (let as ILexEntryInflType) != null)
                     .Select(let => (let as ILexEntryInflType)))
            {
                var       cache  = leit.Cache;
                var       wsUser = cache.ServiceLocator.WritingSystemManager.UserWritingSystem;
                int       wsActual1;
                ITsString tssGlossPrepend =
                    leit.GlossPrepend.GetAlternativeOrBestTss(wsGloss.Handle, out wsActual1);
                if (tssGlossPrepend.Length != 0)
                {
                    AppendGlossAffix(sbJoinedGlossPrepend, tssGlossPrepend, true, sSeparator, wsUser);
                }

                ITsString tssGlossAppend =
                    leit.GlossAppend.GetAlternativeOrBestTss(wsGloss.Handle, out wsActual1);
                if (tssGlossAppend.Length != 0)
                {
                    AppendGlossAffix(sbJoinedGlossAppend, tssGlossAppend, false, sSeparator, wsUser);
                }
            }
        }
Exemple #15
0
        public void AppendAlternativesTest()
        {
            var           english = Cache.LangProject.CurrentAnalysisWritingSystems.ElementAt(0);
            var           spanish = Cache.LangProject.CurrentAnalysisWritingSystems.ElementAt(1);
            ITsIncStrBldr tisb    = TsStringUtils.MakeIncStrBldr();

            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, english.Handle);
            tisb.Append("Mexico");
            Cache.LangProject.MainCountry.set_String(english.Handle, tisb.GetString());

            tisb = TsStringUtils.MakeIncStrBldr();
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, spanish.Handle);
            tisb.Append("Mejico");
            Cache.LangProject.MainCountry.set_String(spanish.Handle, tisb.GetString());

            tisb = TsStringUtils.MakeIncStrBldr();
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, english.Handle);
            tisb.Append("Saltillo");
            Cache.LangProject.FieldWorkLocation.set_String(english.Handle, tisb.GetString());

            Cache.LangProject.FieldWorkLocation.AppendAlternatives(Cache.LangProject.MainCountry);
            Assert.AreEqual("Saltillo Mexico", Cache.LangProject.FieldWorkLocation.get_String(english.Handle).Text);
            Assert.AreEqual("Mejico", Cache.LangProject.FieldWorkLocation.get_String(spanish.Handle).Text);

            tisb = TsStringUtils.MakeIncStrBldr();
            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, spanish.Handle);
            tisb.Append("Saltillo");
            Cache.LangProject.FieldWorkLocation.set_String(spanish.Handle, tisb.GetString());

            ((ITsMultiString)Cache.LangProject.MainCountry).set_String(english.Handle, null);

            Cache.LangProject.FieldWorkLocation.AppendAlternatives(Cache.LangProject.MainCountry);
            Assert.AreEqual("Saltillo Mexico", Cache.LangProject.FieldWorkLocation.get_String(english.Handle).Text);
            Assert.AreEqual("Saltillo Mejico", Cache.LangProject.FieldWorkLocation.get_String(spanish.Handle).Text);
        }
Exemple #16
0
        public ITsString CreateFromStr(XmlNode strNode)
        {
            ITsIncStrBldr tisb = TsStringUtils.MakeIncStrBldr();

            ProcessRunElements(strNode.ChildNodes, tisb);

            return(tisb.GetString());
        }
Exemple #17
0
        ITsString CreateFeatureLine(IFsClosedValue value)
        {
            ITsIncStrBldr featLine = TsStringUtils.MakeIncStrBldr();

            featLine.AppendTsString(value.ValueRA != null ? value.ValueRA.Abbreviation.BestAnalysisAlternative : m_questions);
            featLine.Append(" ");
            featLine.AppendTsString(value.FeatureRA != null ? value.FeatureRA.Abbreviation.BestAnalysisAlternative : m_questions);
            return(featLine.GetString());
        }
Exemple #18
0
        public void SetDlgInfo(CmObjectUi obj, FdoCache cache, XCore.Mediator mediator)
        {
            CheckDisposed();

            StringTable strings = mediator.StringTbl;

            m_cache = cache;
            IVwStylesheet stylesheet = FontHeightAdjuster.StyleSheetFromMediator(mediator);

            Debug.Assert(obj != null);
            Debug.Assert(obj.Object != null);

            Text = String.Format(FdoUiStrings.ksDeleteX, strings.GetString(obj.ClassName, "ClassNames"));

            // Set the s_helpTopic based on the window title and rearrange the buttons if neccesary
            switch (obj.ClassName)
            {
            case "WfiWordform":
                s_helpTopic = "khtpDeleteWordform";
                break;
            }
            if (s_helpTopic != null)
            {
                buttonHelp.Visible = true;
                buttonHelp.Enabled = true;
                this.helpProvider  = new System.Windows.Forms.HelpProvider();
                this.helpProvider.HelpNamespace = FwApp.App.HelpFile;
                this.helpProvider.SetHelpKeyword(this, FwApp.App.GetHelpString(s_helpTopic, 0));
                this.helpProvider.SetHelpNavigator(this, System.Windows.Forms.HelpNavigator.Topic);
            }
            else
            {
                m_deleteButton.Location = m_cancelButton.Location;
                m_cancelButton.Location = buttonHelp.Location;
            }

            //Use an FWTextBox so that strings of different writing systems will
            //be displayed with the correct stylesheet settings.
            m_descriptionBox3.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor;
            m_descriptionBox3.WritingSystemCode    = m_cache.LangProject.DefaultUserWritingSystem;
            m_descriptionBox3.StyleSheet           = stylesheet;
            ITsIncStrBldr tisb3 = TsIncStrBldrClass.Create();

            tisb3.AppendTsString(obj.Object.DeletionTextTSS);
            m_descriptionBox3.Tss = tisb3.GetString();

            m_descriptionBox4.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor;
            m_descriptionBox4.WritingSystemCode    = m_cache.LangProject.DefaultUserWritingSystem;
            m_descriptionBox4.StyleSheet           = stylesheet;
            ITsIncStrBldr tisb4 = TsIncStrBldrClass.Create();

            tisb4.AppendTsString(m_cache.MakeUserTss(" "));             //this is the default for m_descriptionBox4
            m_descriptionBox4.Tss = tisb4.GetString();

            m_deleteButton.Enabled = obj.Object.CanDelete;
            label2.Visible         = m_deleteButton.Enabled;
        }
Exemple #19
0
 public void DontShowMessageBoxForAsserts()
 {
     using (DebugProcs debugProcs = new DebugProcs(false))
     {
         ITsIncStrBldr bldr = TsIncStrBldrClass.Create();
         // asserts - this brings up a message box if ShowAssertMessageBox doesn't work
         bldr.SetIntPropValues(1, 0, 0);
     }
 }
        /// <summary>
        /// This method is called when a user selects Delete Relation on a Lexical Relation slice.
        /// For: Pair relation (eg. Antonym)
        ///     tree relation (parts/whole when deleting a Parts slice)
        /// </summary>
        /// <param name="hvo"></param>
        public void DeleteReference(int hvo)
        {
            CheckDisposed();
            if (hvo <= 0)
            {
                throw new ConfigurationException("Slice:GetObjectHvoForMenusToOperateOn is either messed up or should not have been called, because it could not find the object to be deleted.", m_configurationNode);
            }
            else
            {
                Form mainWindow = (Form)Mediator.PropertyTable.GetValue("window");
                mainWindow.Cursor = Cursors.WaitCursor;
                using (ConfirmDeleteObjectDlg dlg = new ConfirmDeleteObjectDlg())
                {
                    CmObjectUi    ui = CmObjectUi.MakeUi(m_cache, hvo);
                    ILexReference lr = LexReference.CreateFromDBObject(m_cache, hvo);

                    //We need this to determine which kind of relation we are deleting
                    LexRefType lrtOwner =
                        (LexRefType)CmObject.CreateFromDBObject(m_cache, lr.OwnerHVO);

                    int           analWs = m_cache.DefaultAnalWs;
                    int           userWs = m_cache.DefaultUserWs;
                    ITsIncStrBldr tisb   = TsIncStrBldrClass.Create();
                    tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs);

                    switch ((LexRefType.MappingTypes)lrtOwner.MappingType)
                    {
                    case LexRefType.MappingTypes.kmtSenseTree:
                    case LexRefType.MappingTypes.kmtEntryTree:
                    case LexRefType.MappingTypes.kmtEntryOrSenseTree:
                        tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs);
                        tisb.Append(String.Format(LexEdStrings.ksDeleteLexTree, "\x2028"));
                        dlg.SetDlgInfo(ui, m_cache, Mediator, tisb.GetString());
                        break;

                    default:
                        dlg.SetDlgInfo(ui, m_cache, Mediator);
                        break;
                    }

                    if (DialogResult.Yes == dlg.ShowDialog(mainWindow))
                    {
                        lr.DeleteUnderlyingObject();
                        //Update the display because we have removed this slice from the Lexical entry.
                        UpdateForDelete(hvo);

                        mainWindow.Cursor = Cursors.Default;
                    }
                    else                     //If the user selected Cancel in the delete dialog do nothing
                    {
                        mainWindow.Cursor = Cursors.Default;
                        return;
                    }
                }
            }
        }
Exemple #21
0
        public ITsString CreateFromStr(XmlNode strNode)
        {
            CheckDisposed();

            ITsIncStrBldr tisb = m_tsf.GetIncBldr();

            ProcessRunElements(strNode.ChildNodes, tisb);

            return(tisb.GetString());
        }
Exemple #22
0
        public ITsString CreateFromAStr(XmlNode aStrNode, out int wsAStr)
        {
            wsAStr = m_wsCache[aStrNode.Attributes["ws"].Value];
            ITsIncStrBldr tisb = TsStringUtils.MakeIncStrBldr();

            tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsAStr);
            ProcessRunElements(aStrNode.ChildNodes, tisb);

            return(tisb.GetString());
        }
Exemple #23
0
 private static void InsertHomographNumber(ITsIncStrBldr tisb, int nHomograph, HomographConfiguration hc,
                                           HomographConfiguration.HeadwordVariant hv)
 {
     if (nHomograph > 0 && hc.ShowHomographNumber(hv))
     {
         tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, HomographConfiguration.ksHomographNumberStyle);
         tisb.Append(nHomograph.ToString());
         tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null);
     }
 }
Exemple #24
0
        public void ReportHook()
        {
            using (DummyDebugProcs debugProcs = new DummyDebugProcs(false))
            {
                ITsIncStrBldr bldr = TsIncStrBldrClass.Create();
                // next line asserts
                bldr.SetIntPropValues(1, 0, 0);

                Assert.IsTrue(debugProcs.m_fHandlerCalled);
            }
        }
Exemple #25
0
        public void StringServices_CrawlRunsCanDeleteAllRuns()
        {
            var           wsEn  = Cache.WritingSystemFactory.GetWsFromStr("en");
            var           begin = TsStringUtils.MakeString("beginning", wsEn);
            ITsIncStrBldr tisb  = TsStringUtils.MakeIncStrBldr();

            tisb.AppendTsString(begin);
            ITsString result = null;

            Assert.DoesNotThrow(() => result = StringServices.CrawlRuns(tisb.GetString(), run => run.get_WritingSystemAt(0) == wsEn ? null : run));
            Assert.That(result, Is.Null);
        }
Exemple #26
0
        public void GetTextRepresentation_charStylePara()
        {
            ITsIncStrBldr strBldr = m_footnotePara.Contents.GetIncBldr();

            strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle,
                                    "Emphasis");
            strBldr.Append("Test Text");
            m_footnotePara.Contents = strBldr.GetString();
            Assert.AreEqual("<FN><M>a</M><P><PS>Note General Paragraph</PS>" +
                            "<RUN WS='fr' CS='Emphasis'>Test Text</RUN></P></FN>",
                            m_footnote.TextRepresentation);
        }
Exemple #27
0
        /// <summary>
        /// This method should have the same logic as the (above) HeadWordForWsAndHn().
        /// </summary>
        /// <param name="tisb"></param>
        /// <param name="entry"></param>
        /// <param name="wsVern"></param>
        /// <param name="nHomograph"></param>
        /// <param name="defaultCf"></param>
        /// <param name="hv"></param>
        internal static void AddHeadWordForWsAndHn(ITsIncStrBldr tisb, ILexEntry entry, int wsVern, int nHomograph, string defaultCf,
                                                   HomographConfiguration.HeadwordVariant hv)
        {
            var citationForm = CitationFormWithAffixTypeStaticForWs(entry, wsVern, defaultCf);

            if (String.IsNullOrEmpty(citationForm))
            {
                tisb.AppendTsString(entry.Cache.TsStrFactory.EmptyString(wsVern));                 // avoids COM Exception!
                return;
            }
            AddHeadwordForWsAndHn(entry, wsVern, nHomograph, hv, tisb, citationForm);
        }
Exemple #28
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the default value for a cell in the row for new records.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public ITsString GetDefaultNewRowValue(int rowIndex)
        {
            int ws = GetWritingSystemHandle(rowIndex);

            if (ws <= 0)
            {
                ITsIncStrBldr strBldr = TsStringUtils.MakeIncStrBldr();
                strBldr.Append(string.Empty);
                return(strBldr.GetString());
            }

            return(TsStringUtils.EmptyString(ws));
        }
Exemple #29
0
        public void StringServices_CrawlRunsCanSuccessfullyDoNothing()
        {
            var           wsEn       = Cache.WritingSystemFactory.GetWsFromStr("en");
            var           wsFr       = Cache.WritingSystemFactory.GetWsFromStr("fr");
            var           tssFactory = Cache.TsStrFactory;
            var           begin      = tssFactory.MakeString("beginning", wsEn);
            ITsIncStrBldr tisb       = TsIncStrBldrClass.Create();

            tisb.AppendTsString(begin);
            ITsString result = null;

            Assert.DoesNotThrow(() => result = StringServices.CrawlRuns(tisb.GetString(), run => run.get_WritingSystemAt(0) == wsFr ? null : run));
            Assert.That(result.Text, Is.StringMatching("beginning"));
        }
Exemple #30
0
        private ITsString TitleForWs(int ws)
        {
            ITsString tssTitle = null;

            if (ScriptureServices.ScriptureIsResponsibleFor(this))
            {
                Scripture scripture = Cache.LangProject.TranslatedScriptureOA as Scripture;
                if (scripture != null)
                {
                    tssTitle = scripture.BookChapterVerseBridgeAsTss(this, ws);
                    if (OwningFlid == ScrSectionTags.kflidHeading)
                    {
                        string sFmt = Strings.ksSectionHeading;
                        int    iMin = sFmt.IndexOf("{0}");
                        if (iMin < 0)
                        {
                            tssTitle = m_cache.MakeUserTss(sFmt);
                        }
                        else
                        {
                            ITsIncStrBldr tisb = TsIncStrBldrClass.Create();
                            if (iMin > 0)
                            {
                                tisb.AppendTsString(m_cache.MakeUserTss(sFmt.Substring(0, iMin)));
                            }
                            tisb.AppendTsString(tssTitle);
                            if (iMin + 3 < sFmt.Length)
                            {
                                tisb.AppendTsString(m_cache.MakeUserTss(sFmt.Substring(iMin + 3)));
                            }
                            tssTitle = tisb.GetString();
                        }
                    }
                }
            }
            else if (Owner is IText)
            {
                IText text = Owner as IText;
                tssTitle = text.Name.get_String(ws);
            }
            else
            {
                // throw?
            }
            if (tssTitle == null)
            {
                tssTitle = TsStrFactoryClass.Create().EmptyString(Cache.DefaultAnalWs);
            }
            return(tssTitle);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the default value for a cell in the row for new records.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public ITsString GetDefaultNewRowValue(int rowIndex)
        {
            int ws = GetWritingSystemHandle(rowIndex);

            if (ws <= 0)
            {
                ITsIncStrBldr strBldr = TsIncStrBldrClass.Create();
                strBldr.Append(string.Empty);
                return(strBldr.GetString());
            }

            ITsStrFactory tsf = TsStrFactoryClass.Create();

            return(tsf.MakeString(string.Empty, ws));
        }
Exemple #32
0
		/// <summary>
		/// Append to the string builder text equivalent to CitationFormWithAffixTypeStatic, but
		/// with the correct writing systems.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvo"></param>
		/// <param name="tsb"></param>
		public static void CitationFormWithAffixTypeTss(FdoCache cache, int hvo, ITsIncStrBldr tsb)
		{
			ISilDataAccess sda = cache.MainCacheAccessor;
			int hvoType = 0;
			int hvoLexForm = sda.get_ObjectProp(hvo, (int)LexEntry.LexEntryTags.kflidLexemeForm);
			if (hvoLexForm != 0)
			{
				hvoType = sda.get_ObjectProp(hvoLexForm, (int)MoForm.MoFormTags.kflidMorphType);
			}
			else
			{
				// No type info...return simpler version of name.
				ShortName1Static(cache, hvo, tsb);
				return;
			}
			string prefix = string.Empty;
			string postfix = string.Empty;
			if (hvoType > 0) // It may be null.
			{
				prefix = sda.get_UnicodeProp(hvoType, (int)MoMorphType.MoMorphTypeTags.kflidPrefix);
				postfix = sda.get_UnicodeProp(hvoType, (int)MoMorphType.MoMorphTypeTags.kflidPostfix);
			}
			// The following code for setting Ws and FontFamily are to fix LT-6238.
			if (!String.IsNullOrEmpty(prefix))
			{
				tsb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, cache.DefaultVernWs);
				tsb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "Doulos SIL");
				tsb.Append(prefix);
			}
			ShortName1Static(cache, hvo, tsb);
			if (!String.IsNullOrEmpty(postfix))
			{
				tsb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, cache.DefaultVernWs);
				tsb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "Doulos SIL");
				tsb.Append(postfix);
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates the a text run from a string representation.
		/// </summary>
		/// <param name="wsf">The writing system factory.</param>
		/// <param name="strBldr">The structured string builder.</param>
		/// <param name="textNode">The text node which describes runs to be added to the
		/// paragraph or to the translation for a particular writing system</param>
		/// ------------------------------------------------------------------------------------
		private void CreateRunFromStringRep(ILgWritingSystemFactory wsf, ITsIncStrBldr strBldr,
			XmlNode textNode)
		{
			XmlNode charStyle = textNode.Attributes.GetNamedItem("CS");
			if (charStyle != null)
				strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, charStyle.Value);
			else
				strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null);

			XmlNode wsICULocale = textNode.Attributes.GetNamedItem("WS");
			if (wsICULocale != null)
			{
				int ws = wsf.GetWsFromStr(wsICULocale.Value);
				if (ws <= 0)
					throw new ArgumentException("Unknown ICU locale encountered: '" + wsICULocale.Value + "'");
				strBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
					(int)FwTextPropVar.ktpvDefault, wsf.GetWsFromStr(wsICULocale.Value));
			}
			else
				throw new ArgumentException("Required attribute WS missing from RUN element.");
		}
Exemple #34
0
		/// <summary>
		/// Static version for avoiding creating actual object.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvo"></param>
		/// <param name="tsb"></param>
		/// <returns></returns>
		public static void ShortName1Static(FdoCache cache, int hvo, ITsIncStrBldr tsb)
		{
			ISilDataAccess sda = cache.MainCacheAccessor;
			int wsVern = cache.DefaultVernWs;

			// try vernacular citation
			ITsString label = sda.get_MultiStringAlt(hvo,
				(int)LexEntry.LexEntryTags.kflidCitationForm, wsVern);
			if (label.Length != 0)
			{
				tsb.AppendTsString(label);
				return;
			}

			// try lexeme form
			int hvoLf = sda.get_ObjectProp(hvo, (int)LexEntry.LexEntryTags.kflidLexemeForm);
			if (hvoLf != 0)
			{
				label = sda.get_MultiStringAlt(hvoLf, (int)MoForm.MoFormTags.kflidForm,
					wsVern);
				if (label.Length != 0)
				{
					tsb.AppendTsString(label);
					return;
				}
			}

			// Try the first alternate form with the wsVern WS.
			for (int i = 0; i < sda.get_VecSize(hvo, (int)LexEntry.LexEntryTags.kflidAlternateForms); i++)
			{
				int hvoAm = sda.get_VecItem(hvo, (int)LexEntry.LexEntryTags.kflidAlternateForms, i);
				label = sda.get_MultiStringAlt(hvoAm, (int)MoForm.MoFormTags.kflidForm,
					wsVern);
				if (label.Length != 0)
				{
					tsb.AppendTsString(label);
					return;
				}
			}

			// give up
			tsb.AppendTsString(cache.MakeUserTss(Strings.ksQuestions));		// was "??", not "???"
		}
Exemple #35
0
		/// <summary>
		/// This method should have the same logic as the (above) HeadWordForWsAndHn().
		/// </summary>
		/// <param name="tisb"></param>
		/// <param name="entry"></param>
		/// <param name="wsVern"></param>
		/// <param name="nHomograph"></param>
		/// <param name="defaultCf"></param>
		/// <param name="hv"></param>
		internal static void AddHeadWordForWsAndHn(ITsIncStrBldr tisb, ILexEntry entry, int wsVern, int nHomograph, string defaultCf,
	HomographConfiguration.HeadwordVariant hv)
		{
			var citationForm = CitationFormWithAffixTypeStaticForWs(entry, wsVern, defaultCf);
			if (String.IsNullOrEmpty(citationForm))
			{
				tisb.AppendTsString(entry.Cache.TsStrFactory.EmptyString(wsVern)); // avoids COM Exception!
				return;
			}
			AddHeadwordForWsAndHn(entry, wsVern, nHomograph, hv, tisb, citationForm);
		}
Exemple #36
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:TsStringCollectorEnv"/> class.
		/// </summary>
		/// <param name="baseEnv">The base env.</param>
		/// <param name="sda">Date access to get prop values etc.</param>
		/// <param name="hvoRoot">The root object to display, if m_baseEnv is null.
		/// If baseEnv is not null, hvoRoot is ignored.</param>
		/// ------------------------------------------------------------------------------------
		public TsStringCollectorEnv(IVwEnv baseEnv, ISilDataAccess sda, int hvoRoot):
			base(baseEnv, sda, hvoRoot)
		{
			m_builder = TsIncStrBldrClass.Create();
			// In case we add some raw strings, typically numbers, satisfy the constraints of string
			// builders by giving it SOME writing system.
			m_builder.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault,
				sda.WritingSystemFactory.UserWs);
		}
Exemple #37
0
		private static void AddHeadwordForWsAndHn(ILexEntry entry, int wsVern, int nHomograph,
			HomographConfiguration.HeadwordVariant hv, ITsIncStrBldr tisb, string citationForm)
		{
			tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsVern);
			var hc = entry.Services.GetInstance<HomographConfiguration>();
			if (hc.HomographNumberBefore)
				InsertHomographNumber(tisb, nHomograph, hc, hv);
			tisb.Append(citationForm);

			// (EricP) Tried to automatically update the homograph number, but doing that here will
			// steal away manual changes to the HomographNumber column. Also suppressing PropChanged
			// is necessary when HomographNumber column is enabled, otherwise changing the entry index can hang.
			//using (new IgnorePropChanged(cache, PropChangedHandling.SuppressView))
			//{
			//	  ValidateExistingHomographs(CollectHomographs(cache, ShortName1StaticForWs(cache, hvo, wsVern), 0, morphType));
			//}

			if (!hc.HomographNumberBefore)
				InsertHomographNumber(tisb, nHomograph, hc, hv);
		}
Exemple #38
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:TsStringCollectorEnv"/> class.
		/// </summary>
		/// <param name="baseEnv">The base env.</param>
		/// <param name="sda">Date access to get prop values etc.</param>
		/// <param name="hvoRoot">The root object to display, if m_baseEnv is null.
		/// If baseEnv is not null, hvoRoot is ignored.</param>
		/// ------------------------------------------------------------------------------------
		public TsStringCollectorEnv(IVwEnv baseEnv, ISilDataAccess sda, int hvoRoot):
			base(baseEnv, sda, hvoRoot)
		{
			m_builder = TsIncStrBldrClass.Create();
		}
Exemple #39
0
		private void ProcessRunElement(XmlNode runNode, ITsIncStrBldr tisb)
		{
			/*
(From DTD, as of 9/18/2006)
<!ELEMENT Run (#PCDATA)>
<!ATTLIST Run
	type (chars | picture) #IMPLIED
	ownlink CDATA #IMPLIED
	contextString CDATA #IMPLIED
	backcolor CDATA #IMPLIED
	bold (invert | off | on) #IMPLIED
	ws CDATA #REQUIRED
	wsBase CDATA #IMPLIED
	externalLink CDATA #IMPLIED
	fontFamily CDATA #IMPLIED
	fontsize CDATA #IMPLIED
	fontsizeUnit CDATA #IMPLIED
	forecolor CDATA #IMPLIED
	italic (invert | off | on) #IMPLIED
	link CDATA #IMPLIED
	namedStyle CDATA #IMPLIED
	offset CDATA #IMPLIED
	offsetUnit CDATA #IMPLIED
	superscript (sub | super) #IMPLIED
	tabList CDATA #IMPLIED
	tags IDREFS #IMPLIED
	undercolor CDATA #IMPLIED
	underline (dashed | dotted | double | none | single | squiggle | strikethrough) #IMPLIED
>
Stephen McCon...	The relevant source file is FwXmlString.cpp in {FW}/Src/Cellar.  Unfortunately, this area is somewhat of a mess.
Stephen McCon...	The attr list is probably found in FwDatabase.dtd, without explanation.
Randy Regnier		If I understand it right, the various attrs will control some properties for the ts string, such as ws, bold, etc, right?
Stephen McCon...	that's correct.
Stephen McCon...	You could look at FwXmlImportData::ProcessStringStartTag(const XML_Char *, const XML_Char **) in FwXmlString.cpp to see how the attributes are scanned and stored when reading in a string in the various C++ XML parsers.
Stephen McCon...	(Of course, that calls all sorts of other methods to do the work, which you may have to look at as well)
			*/
			// Process all of the properties, before adding the string (says JohnT, personal communication).
			foreach (XmlAttribute attr in runNode.Attributes)
			{
				switch (attr.Name)
				{
					case "ws":
						// ws CDATA #REQUIRED
						tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_wsCache[attr.Value]);
						break;
					case "type":
						// type (chars | picture) #IMPLIED
						// <Run ws=\"en\"
						break;
					case "ownlink":
						// ownlink CDATA #IMPLIED
						// <Run ws=\"xkal\" ownlink=\"993DA544-3B38-4AB0-BFDE-9AF884571A2D\"></Run>
						break;
					case "contextString":
						// contextString CDATA #IMPLIED
						// <Run ws=\"en\" contextString=\"85EE15C6-0799-46C6-8769-F9B3CE313AE2\"></Run>
						break;
					case "backcolor":
						// backcolor CDATA #IMPLIED
						break;
					case "bold":
						// bold (invert | off | on) #IMPLIED
						break;
					case "wsBase":
						// wsBase CDATA #IMPLIED
						break;
					case "externalLink":
						// externalLink CDATA #IMPLIED
						break;
					case "fontFamily":
						// fontFamily CDATA #IMPLIED
						// <Run ws=\"en\" fontsize=\"16000\" forecolor=\"blue\" fontFamily=\"SILDoulos PigLatinDemo\">Welcome to WorldPad!</Run>
						break;
					case "fontsize":
						// fontsize CDATA #IMPLIED
						break;
					case "fontsizeUnit":
						// fontsizeUnit CDATA #IMPLIED
						break;
					case "forecolor":
						// forecolor CDATA #IMPLIED
						// <Run ws=\"en\" fontsize=\"20000\" forecolor=\"red\">French IPA: </Run>
						// <Run ws=\"xsta\" fontsize=\"20000\" forecolor=\"007f00\">We</Run>
						break;
					case "italic":
						// italic (invert | off | on) #IMPLIED
						// <Run ws=\"en\" italic=\"on\">man</Run>
						break;
					case "link":
						// link CDATA #IMPLIED
						// <Run ws=\"en\" link=\"6EBC80F8-9CE0-45D9-BB49-3869591FB1FF\"></Run>
						break;
					case "namedStyle":
						// <Run ws=\"en\" namedStyle=\"Emphasized Text\">pirana</Run>
						break;
					case "offset":
						// offset CDATA #IMPLIED
						break;
					case "offsetUnit":
						// offsetUnit CDATA #IMPLIED
						break;
					case "superscript":
						// superscript (sub | super) #IMPLIED
						break;
					case "tabList":
						// tabList CDATA #IMPLIED
						break;
					case "tags":
						// tags IDREFS #IMPLIED
						// <Run ws=\"en\" tags=\"I2BDD0E8D-F9B2-11D3-977B-00C04F186933\">Tiga</Run>
						break;
					case "undercolor":
						// undercolor CDATA #IMPLIED
						break;
					case "underline":
						// underline (dashed | dotted | double | none | single | squiggle | strikethrough) #IMPLIED
						break;
					default:
						// Unrecognized attr, so do nothing.
						Debug.WriteLine(String.Format("Unrecognized <Run> element attribute: {0}", attr.Name));
						break;
				}
			}
			tisb.Append(runNode.InnerText);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the prop attributes for element and applies them to a string builder
		/// (to take effect on the next string added).
		/// </summary>
		/// <param name="xml">The XML.</param>
		/// <param name="lgwsf">The writing system factory.</param>
		/// <param name="strBldr"></param>
		/// <returns>Rather strangely, it returns a boolean indicating whether an ORC is needed if the
		/// text of the run is empty, that is, whether we set an objdata property</returns>
		/// ------------------------------------------------------------------------------------
		internal static bool GetPropAttributesForElement(XElement xml, ILgWritingSystemFactory lgwsf, ITsIncStrBldr strBldr)
		{
			bool isOrcNeeded = false;
			strBldr.ClearProps();
			foreach (XAttribute attr in xml.Attributes())
			{
				switch (attr.Name.LocalName)
				{
					case "align":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum,
							GetAlignValueForStr(attr.Value));
						break;
					case "backcolor":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, 0,
							GetColorValueForStr(attr.Value));
						break;
					case "bold":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum,
							GetToggleValueForStr(attr.Value));
						break;
					case "borderBottom":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "borderColor":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptBorderColor, 0,
							GetColorValueForStr(attr.Value));
						break;
					case "borderLeading":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptBorderLeading, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "borderTop":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptBorderTop, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "borderTrailing":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptBorderTrailing, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "bulNumScheme":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptBulNumScheme, (int)FwTextPropVar.ktpvEnum,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "bulNumStartAt":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptBulNumStartAt, 0,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "bulNumTxtAft":
						strBldr.SetStrPropValue((int)FwTextPropType.ktptBulNumTxtAft, attr.Value);
						break;
					case "bulNumTxtBef":
						strBldr.SetStrPropValue((int)FwTextPropType.ktptBulNumTxtBef, attr.Value);
						break;
					case "charStyle":
						Debug.Fail("We don't support the old charStyle attribute!");
						break;
					case "contextString":
						AddObjDataToBldr(strBldr, attr, FwObjDataTypes.kodtContextString);
						isOrcNeeded = true;
						break;
					case "embedded":
						strBldr.SetStrPropValue((int)FwTextPropType.ktptObjData,
							(char)FwObjDataTypes.kodtEmbeddedObjectData + attr.Value);
						break;
					case "externalLink":
						strBldr.SetStrPropValue((int)FwTextPropType.ktptObjData,
							(char)FwObjDataTypes.kodtExternalPathName + attr.Value);
						break;
					case "firstIndent":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptFirstIndent, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, true));
						break;
					case "fontFamily":
						strBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily, attr.Value);
						break;
					case "fontsize":
						AddSizePropertyToBldr(strBldr, attr.Value, (int)FwTextPropType.ktptFontSize,
							xml.Attribute("fontsizeUnit"), null);
						break;
					case "fontsizeUnit":
						break; // Ignore. Its handled in the fontsize.
					case "fontVariations":
						strBldr.SetStrPropValue((int)FwTextPropType.ktptFontVariations, attr.Value);
						break;
					case "forecolor":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptForeColor, 0,
							GetColorValueForStr(attr.Value));
						break;
					case "italic":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptItalic, (int)FwTextPropVar.ktpvEnum,
							GetToggleValueForStr(attr.Value));
						break;
					case "keepTogether":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptKeepTogether, (int)FwTextPropVar.ktpvEnum,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "keepWithNext":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptKeepWithNext, (int)FwTextPropVar.ktpvEnum,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "leadingIndent":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptLeadingIndent, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "lineHeight":
						AddSizePropertyToBldr(strBldr, attr.Value, (int)FwTextPropType.ktptLineHeight,
							xml.Attribute("lineHeightUnit"), xml.Attribute("lineHeightType"));
						break;
					case "lineHeightType":
						break; // Ignore. Its handled in the lineHeight
					case "lineHeightUnit":
						break; // Ignore. Its handled in the lineHeight
					case "link":
						AddObjDataToBldr(strBldr, attr, FwObjDataTypes.kodtNameGuidHot);
						isOrcNeeded = true;
						break;
					case "marginBottom":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptMarginBottom, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "marginLeading":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptMarginLeading, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "marginTop":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptMarginTop, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "marginTrailing":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptMarginTrailing, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "moveableObj":
						AddObjDataToBldr(strBldr, attr, FwObjDataTypes.kodtGuidMoveableObjDisp);
						isOrcNeeded = true;
						break;
					case "namedStyle":
						strBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, attr.Value);
						break;
					case "offset":
						AddSizePropertyToBldr(strBldr, attr.Value, (int)FwTextPropType.ktptOffset,
							xml.Attribute("offsetUnit"), null);
						break;
					case "offsetUnit":
						break; // Ignore. Its handled in the offset
					case "ownlink":
						AddObjDataToBldr(strBldr, attr, FwObjDataTypes.kodtOwnNameGuidHot);
						isOrcNeeded = true;
						break;
					case "padBottom":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptPadBottom, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "padLeading":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptPadLeading, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "padTop":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptPadTop, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "padTrailing":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptPadTrailing, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "paracolor":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptParaColor, 0,
							GetColorValueForStr(attr.Value));
						break;
					case "paraStyle":
						Debug.Fail("We don't support the old paraStyle attribute!");
						break;
					case "rightToLeft":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptRightToLeft, (int)FwTextPropVar.ktpvEnum,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "spaceAfter":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptSpaceAfter, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, true));
						break;
					case "spaceBefore":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptSpaceBefore, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, true));
						break;
					case "spellcheck":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptSpellCheck, (int)FwTextPropVar.ktpvEnum,
							GetSpellCheckValueForStr(attr.Value));
						break;
					case "superscript":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptSuperscript, (int)FwTextPropVar.ktpvEnum,
							GetSuperscriptValueForStr(attr.Value));
						break;
					case "tabDef":
						Debug.Fail("We don't support the tabDef property!");
						break;
					case "tabList":
						Debug.Fail("We don't support the tabList property!");
						break;
					case "tags":
						strBldr.SetStrPropValue((int)FwTextPropType.ktptTags,
							GetGuidValuesForStr(attr.Value));
						break;
					case "trailingIndent":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptTrailingIndent, (int)FwTextPropVar.ktpvMilliPoint,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "type":
						Debug.Assert(attr.Value == "chars", "Embedded pictures are not supported!");
						break;
					case "undercolor":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptUnderColor, 0,
							GetColorValueForStr(attr.Value));
						break;
					case "underline":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptUnderline, (int)FwTextPropVar.ktpvEnum,
							GetUnderlineTypeForStr(attr.Value));
						break;
					case "widowOrphan":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptWidowOrphanControl, (int)FwTextPropVar.ktpvEnum,
							GetIntValueFromStr(attr.Value, false));
						break;
					case "ws":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0,
							TsStringSerializer.GetWsForId(attr.Value, lgwsf));
						break;
					case "wsBase":
						strBldr.SetIntPropValues((int)FwTextPropType.ktptBaseWs, 0,
							TsStringSerializer.GetWsForId(attr.Value, lgwsf));
						break;
					case "wsStyle":
						Debug.Fail("We don't support the old wsStyle attribute!");
						break;
					case "space":
					case "editable":
						break;
					default:
						throw new XmlSchemaException("Unknown Prop attribute: " + attr.Name.LocalName);
				}
			}
			return isOrcNeeded;
		}
Exemple #41
0
			private void StoreRemainingClipboardData(ITsIncStrBldr tisbClipBoard)
			{
				// Check whether we actually have any more data remaining, so that
				// we don't add a gratuitous extra newline at the end.
				bool fMoreData = false;
				for (int i = 0; i < m_rgtsbLines.Length; ++i)
				{
					if (!String.IsNullOrEmpty(m_rgtsbLines[i].Text))
					{
						fMoreData = true;
						break;
					}
				}
				if (fMoreData)
					StoreClipboardSegment(tisbClipBoard);
			}
Exemple #42
0
			/// <summary>
			/// Store this segment's worth of data in the overall builder.
			/// </summary>
			private void StoreClipboardSegment(ITsIncStrBldr tisbClipBoard)
			{
				for (int i = 0; i < m_rgtsbLines.Length; ++i)
				{
					// Trim the final trailing tab on the line since it's not needed.
					int cch = m_rgtsbLines[i].Length;
					if (cch > 0 && m_rgtsbLines[i].Text.LastIndexOf('\t') == cch - 1)
						m_rgtsbLines[i].ReplaceTsString(cch - 1, cch, null);
					tisbClipBoard.AppendTsString(m_rgtsbLines[i].GetString());
					m_rgtsbLines[i].Clear();
					tisbClipBoard.Append(Environment.NewLine);
				}
				tisbClipBoard.Append(Environment.NewLine);
			}
Exemple #43
0
		private static void InsertHomographNumber(ITsIncStrBldr tisb, int nHomograph, HomographConfiguration hc,
			HomographConfiguration.HeadwordVariant hv)
		{
			if (nHomograph > 0 && hc.ShowHomographNumber(hv))
			{
				tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, HomographConfiguration.ksHomographNumberStyle);
				tisb.Append(nHomograph.ToString());
				tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null);
			}
		}
Exemple #44
0
		private void JoinGlossAffixesOfInflVariantTypes(ILexEntryRef entryRef1, int wsPreferred, out ITsIncStrBldr sbPrepend1, out ITsIncStrBldr sbAppend1)
		{
			var glossWs1 = Cache.ServiceLocator.WritingSystemManager.Get(wsPreferred);
			MorphServices.JoinGlossAffixesOfInflVariantTypes(entryRef1.VariantEntryTypesRS, glossWs1,
															 out sbPrepend1, out sbAppend1);
		}
Exemple #45
0
		/// <summary>
		/// Static version for avoiding creating actual object.
		/// </summary>
		public static void ShortName1Static(ILexEntry entry, ITsIncStrBldr tsb)
		{
			var ws = entry.Services.WritingSystems.DefaultVernacularWritingSystem;

			// Try vernacular citation
			var tss = entry.CitationForm.get_String(ws.Handle);
			if (tss != null && tss.Length > 0)
			{
				tsb.AppendTsString(tss);
				return;
			}

			// Try lexeme form.
			var form = entry.LexemeFormOA;
			if (form != null)
			{
				tss = form.Form.get_String(ws.Handle);
				if (tss != null && tss.Length > 0)
				{
					tsb.AppendTsString(tss);
					return;
				}
			}

			// Try the first alternate form with the wsVern WS.
			// NB: This may not be the actual first alterantge.
			foreach (var alt in entry.AlternateFormsOS)
			{
				tss = alt.Form.get_String(ws.Handle);
				if (tss != null && tss.Length > 0)
				{
					tsb.AppendTsString(tss);
					return;
				}
			}

			// Give up.
			tsb.AppendTsString(entry.Cache.TsStrFactory.MakeString(
				Strings.ksQuestions,
				entry.Cache.DefaultUserWs));
		}
Exemple #46
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="captionText">The BT caption text (can be null).</param>
		/// <param name="sCopyright">The BT copyright text (can be null).</param>
		/// <param name="ws">The writing system of the BT.</param>
		/// <param name="filename">The name of the file being imported.</param>
		/// <param name="lineNumber">The line number of the first BT segment encountered for
		/// this picture.</param>
		/// <param name="segment">The first BT segment encountered for this picture.</param>
		/// <param name="reference">The Scripture reference.</param>
		/// ------------------------------------------------------------------------------------
		public BTPictureInfo(string captionText, string sCopyright, int ws, string filename,
			int lineNumber, string segment, BCVRef reference)
		{
			m_strbldrCaption = TsIncStrBldrClass.Create();
			m_strbldrCaption.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, ws);
			if (!String.IsNullOrEmpty(captionText))
				m_strbldrCaption.Append(captionText);
			m_copyright = sCopyright;
			m_ws = ws;
			m_filename = filename;
			m_lineNumber = lineNumber;
			m_segment = segment;
			m_ref = new BCVRef(reference);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds object link data to the specified string builder (to affect the next string added)
		/// </summary>
		/// <param name="strBldr">The string builder to be modified.</param>
		/// <param name="attr">The attribute to process.</param>
		/// <param name="type">The type of object data to be added to the text properties.</param>
		/// ------------------------------------------------------------------------------------
		private static void AddObjDataToBldr(ITsIncStrBldr strBldr, XAttribute attr, FwObjDataTypes type)
		{
			byte[] objData = TsStringUtils.GetObjData(new Guid(attr.Value), (byte)type);
			strBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData, objData, objData.Length);
		}
Exemple #48
0
		private void ProcessRunElements(XmlNodeList runNodes, ITsIncStrBldr tisb)
		{
			foreach (XmlNode runNode in runNodes)
				ProcessRunElement(runNode, tisb);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds a size property to the specified props builder with the specified prop type.
		/// </summary>
		/// <param name="propsBldr">The props builder.</param>
		/// <param name="value">The string representation of the size value.</param>
		/// <param name="proptype">The property type.</param>
		/// <param name="unitAttr">The attribute containing the size unit (can be null).</param>
		/// <param name="typeAttr">The attribute containing the size type (can be null).</param>
		/// ------------------------------------------------------------------------------------
		private static void AddSizePropertyToBldr(ITsIncStrBldr propsBldr, string value, int proptype,
			XAttribute unitAttr, XAttribute typeAttr)
		{
			int var;
			int intValue = GetSizeValue(value, unitAttr, typeAttr, false, out var);
			propsBldr.SetIntPropValues(proptype, var, intValue);
		}
		/// <summary>
		/// This method is overridden in order to use the TsIncStrBldr passed
		/// to it instead of creating another builder. (See LT-13728 for performance issues.)
		/// </summary>
		/// <param name="tisb"></param>
		internal override void AddChooserNameInItalics(ITsIncStrBldr tisb)
		{
			tisb.SetIntPropValues((int)FwTextPropType.ktptItalic,
				(int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn);
			AddChooserName(tisb);
		}
		private void AddChooserName(ITsIncStrBldr tisb)
		{
			var analWs = Cache.DefaultAnalWs;
			var pos = PartOfSpeechRA;
			tisb.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, analWs);
			if (pos != null)
				tisb.Append(pos.Abbreviation.AnalysisDefaultWritingSystem.Text);
			else
				tisb.Append(Strings.ksQuestions);
		}