示例#1
0
        public void SpaceAfterFootnoteMarker()
        {
            IScrBook     book     = m_scr.ScriptureBooksOS[0];
            IScrFootnote footnote = AddFootnote(book, (IStTxtPara)book.TitleOA.ParagraphsOS[0], 0, "This is a footnote");

            footnote.FootnoteMarker = TsStringUtils.MakeString("a", Cache.WritingSystemFactory.GetWsFromStr("en"));
            // Prepare the test by creating a footnote view
            LcmStyleSheet styleSheet = new LcmStyleSheet();

            styleSheet.Init(Cache, Cache.LangProject.Hvo, LangProjectTags.kflidStyles);

            using (DummyFootnoteView footnoteView = new DummyFootnoteView(Cache))
            {
                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, false, false, true);
                SelectionHelper selHelper = SelectionHelper.GetSelectionInfo(null, footnoteView);
                selHelper.IchAnchor = 0;
                selHelper.IchEnd    = 5;
                SelLevInfo[] selLevInfo = new SelLevInfo[3];
                Assert.AreEqual(4, selHelper.GetNumberOfLevels(SelectionHelper.SelLimitType.End));
                Array.Copy(selHelper.GetLevelInfo(SelectionHelper.SelLimitType.End), 1, selLevInfo, 0, 3);
                selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, selLevInfo);
                selHelper.SetTextPropId(SelectionHelper.SelLimitType.End,
                                        StTxtParaTags.kflidContents);
                selHelper.SetSelection(true);

                // Now the real test:
                IVwSelection sel = footnoteView.RootBox.Selection;
                ITsString    tss;
                sel.GetSelectionString(out tss, string.Empty);
                Assert.AreEqual("a ", tss.Text.Substring(0, 2));

                // make sure the marker and the space are read-only (maybe have to select each run
                // separately to make this test truly correct)
                ITsTextProps[]     vttp;
                IVwPropertyStore[] vvps;
                int cttp;
                SelectionHelper.GetSelectionProps(sel, out vttp, out vvps, out cttp);
                Assert.IsTrue(cttp >= 2);
                Assert.IsFalse(SelectionHelper.IsEditable(vttp[0], vvps[0]),
                               "Footnote marker is not read-only");
                Assert.IsFalse(SelectionHelper.IsEditable(vttp[1], vvps[1]),
                               "Space after marker is not read-only");
            }
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// Helper method for FixHyperlinkFolder_linkTextSameAsLink_isUpdated and
        /// FixHyperlinkFolder_linkTextSameAsLinkDespiteChangeOfPlatform_linkTextIsUpdated.
        /// </summary>
        private void FixHyperlinkFolder_linkTextSameAsLink_helper(string origPathSetInDatabase,
                                                                  string lookupPath, string lookupResultToVerify, string pathToRebaseFrom,
                                                                  string pathToRebaseTo, string rebasedPathToVerify)
        {
            var entry = MakeEntry("kick", "hit with foot");

            var       link          = origPathSetInDatabase;
            ITsString paragraph     = TsStringUtils.MakeString("abc" + link + "def", Cache.DefaultAnalWs);
            var       linkBeginning = "abc".Length;
            var       linkEnding    = linkBeginning + link.Length;
            var       bldr          = paragraph.GetBldr();
            var       linkStyle     = MakeStyle("testStyle");

            StringServices.MarkTextInBldrAsHyperlink(bldr, linkBeginning, linkEnding, link, linkStyle);
            entry.LiteralMeaning.AnalysisDefaultWritingSystem = bldr.GetString();

            var hyperlinkInfo = StringServices.GetHyperlinksInFolder(Cache, lookupPath);

            // There should be one hyperlink, and with the proper path.
            Assert.That(hyperlinkInfo, Has.Count.EqualTo(1), "Mistake in unit test");
            var relPath = lookupResultToVerify;

            VerifyHyperlinkInfo(hyperlinkInfo, entry, LexEntryTags.kflidLiteralMeaning,
                                Cache.DefaultAnalWs, linkBeginning, linkEnding, relPath);
            VerifyObjData(entry.LiteralMeaning.AnalysisDefaultWritingSystem, linkBeginning,
                          linkEnding, link);

            // Update links
            StringServices.FixHyperlinkFolder(hyperlinkInfo, pathToRebaseFrom, pathToRebaseTo);
            VerifyHyperlinkInfo(hyperlinkInfo, entry, LexEntryTags.kflidLiteralMeaning,
                                Cache.DefaultAnalWs, linkBeginning, linkEnding, lookupResultToVerify);

            // Check that link text was updated, not just its link

            VerifyObjData(entry.LiteralMeaning.AnalysisDefaultWritingSystem, linkBeginning,
                          linkBeginning + rebasedPathToVerify.Length, rebasedPathToVerify);

            var       linkInfo   = hyperlinkInfo.First();
            var       obj        = linkInfo.Object;
            var       domainData = obj.Cache.DomainDataByFlid;
            ITsString updatedParagraph;

            if (linkInfo.Ws == 0)
            {
                updatedParagraph = domainData.get_StringProp(obj.Hvo, linkInfo.Flid);
            }
            else
            {
                updatedParagraph = domainData.get_MultiStringAlt(obj.Hvo, linkInfo.Flid, linkInfo.Ws);
            }
            Assert.That(updatedParagraph.Text, Is.EqualTo("abc" + rebasedPathToVerify + "def"),
                        "Link text was not updated properly");
        }
示例#4
0
        protected override TreeNode CreateNewNode(XmlNode currentNode, string sType, StringBuilder sbNode, string sTerm)
        {
            TreeNode newNode;

            // we always use a check box
            GlossListTreeView.ImageKind ik = ImageKind.checkBox;
            newNode = new TreeNode(TsStringUtils.NormalizeToNFC(sbNode.ToString()), (int)ik, (int)ik);
            MasterPhonologicalFeature mpf = new MasterPhonologicalFeature(currentNode, ik, sTerm);

            newNode.Tag = mpf;
            return(newNode);
        }
示例#5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="vwenv"></param>
        /// <param name="hvo"></param>
        /// <param name="frag"></param>
        /// ------------------------------------------------------------------------------------
        public override void Display(IVwEnv vwenv, int hvo, int frag)
        {
            switch (frag)
            {
            case kfragRoot:                     // the root; Display the paragraph
                using (new VwConstructorServices.ParagraphBoxHelper(vwenv,
                                                                    () =>
                {
                    if (m_displayOptions.ReadOnlyView)
                    {
                        vwenv.set_IntProperty(
                            (int)FwTextPropType.ktptEditable,
                            (int)FwTextPropVar.ktpvEnum,
                            (int)TptEditable.ktptNotEditable);
                    }
                }))
                {
                    if (m_displayOptions.LiteralStringLabels)
                    {
                        using (new VwConstructorServices.InnerPileHelper(vwenv))
                        {
                            foreach (var ws in WsOrder)
                            {
                                using (new VwConstructorServices.ParagraphBoxHelper(vwenv))
                                {
                                    if (m_displayOptions.LiteralStringLabels)
                                    {
                                        vwenv.AddString(TsStringUtils.MakeString("Label" + ws, ws));
                                    }
                                }
                            }
                        }
                    }
                    using (new VwConstructorServices.InnerPileHelper(vwenv))
                    {
                        foreach (var ws in WsOrder)
                        {
                            using (new VwConstructorServices.ParagraphBoxHelper(vwenv))
                            {
                                //if (m_displayOptions.LiteralStringLabels)
                                //    vwenv.AddString(factory.MakeString("Label" + ws, ws));
                                vwenv.AddStringAltMember(kflidMultiString, ws, null);
                            }
                        }
                    }
                }

                break;

            default:
                throw new ApplicationException("Unexpected frag in SimpleRootSiteDataProviderVc");
            }
        }
        public void DeleteFootnoteMarkerInBt_DelKey()
        {
            IScrBook book = AddBookToMockedScripture(1, "Genesis");

            AddTitleToMockedBook(book, "Genesis");
            m_draftView.BookFilter.Add(book);
            IScrSection section = AddSectionToMockedBook(book);

            AddSectionHeadParaToSection(section, "The first section",
                                        ScrStyleNames.SectionHead);

            // Construct a parent paragraph
            IStTxtPara parentPara = AddParaToMockedSectionContent(section,
                                                                  ScrStyleNames.NormalParagraph);

            AddRunToMockedPara(parentPara, "1", ScrStyleNames.ChapterNumber);
            AddRunToMockedPara(parentPara, "1", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(parentPara, "uno ", null);
            AddRunToMockedPara(parentPara, "2", ScrStyleNames.VerseNumber);
            AddRunToMockedPara(parentPara, "dos ", null);
            IStFootnote footnote1 = AddFootnote(book, parentPara, 5);

            AddParaToMockedText(footnote1, ScrStyleNames.NormalFootnoteParagraph);
            IStFootnote footnote2 = AddFootnote(book, parentPara, 10);

            AddParaToMockedText(footnote2, ScrStyleNames.NormalFootnoteParagraph);
            Assert.AreEqual(2, book.FootnotesOS.Count);

            // Construct the initial back translation
            int            wsBt  = Cache.DefaultAnalWs;
            ICmTranslation trans = AddBtToMockedParagraph(parentPara, wsBt);

            AddRunToMockedTrans(trans, wsBt, "one two", null);
            ITsStrBldr btTssBldr = trans.Translation.get_String(wsBt).GetBldr();

            TsStringUtils.InsertOrcIntoPara(footnote1.Guid, FwObjDataTypes.kodtNameGuidHot, btTssBldr, 3, 3, wsBt);
            TsStringUtils.InsertOrcIntoPara(footnote2.Guid, FwObjDataTypes.kodtNameGuidHot, btTssBldr, 8, 8, wsBt);
            trans.Translation.set_String(wsBt, btTssBldr.GetString());
            m_draftView.RefreshDisplay();

            // Delete text including the first footnote from the first para in Exodus.
            m_draftView.SelectRangeOfChars(0, 0, 0, 0, 5);
            m_draftView.EditingHelper.DeleteSelection();

            // Verify that both original footnotes still exist and that the first BT footnote marker is
            // deleted.
            Assert.AreEqual(2, book.FootnotesOS.Count);
            VerifyFootnote(footnote1, parentPara, 5);
            VerifyFootnote(footnote2, parentPara, 10);
            Assert.AreEqual("two" + StringUtils.kChObject,
                            trans.Translation.get_String(wsBt).Text);
            FdoTestHelper.VerifyBtFootnote(footnote2, parentPara, wsBt, 3);
        }
示例#7
0
        /// <summary>
        /// Determines whether the character at the specified index in the string is wordforming.
        /// </summary>
        public static bool IsCharWordForming(this ITsString tss, int ich, ILgWritingSystemFactory wsf)
        {
            if (ich < 0 || ich >= tss.Length)
            {
                throw new ArgumentOutOfRangeException("ich");
            }

            int wsHandle = tss.get_WritingSystemAt(ich);
            int ch       = char.ConvertToUtf32(tss.Text, ich);

            return(TsStringUtils.IsWordForming(ch, wsf, wsHandle));
        }
示例#8
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initialize the text for the paragraph with the specified builder, or create an
 /// empty paragraph if the builder is null.
 /// </summary>
 /// <param name="bldr">paragraph builder</param>
 /// <param name="text">StText</param>
 /// ------------------------------------------------------------------------------------
 private void InitializeText(StTxtParaBldr bldr, IStText text)
 {
     if (bldr == null)
     {
         IStTxtPara para = text.AddNewTextPara(ScrStyleNames.Remark);
         para.Contents = TsStringUtils.MakeTss(String.Empty, Cache.DefaultAnalWs);
     }
     else
     {
         bldr.CreateParagraph(text);
     }
 }
        /// <summary>
        /// (re)initialize the current list to correspond to the items in m_choices.
        /// This will destroy the selection, and then try to select the indicated line.
        /// </summary>
        void InitCurrentList(int index)
        {
            currentList.SuspendLayout();
            currentList.Items.Clear();
            foreach (InterlinLineSpec ls in m_choices)
            {
                string[] cols = new string[2];

                cols[0] = TsStringUtils.NormalizeToNFC(m_choices.LabelFor(ls.Flid));

                string wsName = "";
                // This tries to find a matching ws from the combo box that would be displayed for this item
                // The reason we use the combo box is because that will give us names like "Default Analysis" instead of
                // the actual analysis ws name.
                foreach (WsComboItem item in WsComboItems(ls.ComboContent))
                {
                    if (getWsFromId(item.Id) == ls.WritingSystem)
                    {
                        wsName = item.ToString();
                        break;
                    }
                }
                // Last ditch effort
                if (wsName == "")
                {
                    ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor;
                    int            wsui         = m_cache.DefaultUserWs;
                    IWritingSystem wsObj        = m_cache.ServiceLocator.WritingSystemManager.Get(ls.WritingSystem);
                    if (wsObj != null)
                    {
                        wsName = wsObj.DisplayLabel;
                    }
                }
                cols[1] = TsStringUtils.NormalizeToNFC(wsName);
                cols[1] = cols[1].Substring(0, Math.Min(cols[1].Length, 42));

                var item1WithToolTip = new ListViewItem(cols);
                item1WithToolTip.ToolTipText = TsStringUtils.NormalizeToNFC(wsName);

                currentList.Items.Add(item1WithToolTip);
            }

            if (index > currentList.Items.Count && index > 0)
            {
                index--;                                       // for when we delete the last item.
            }
            if (index >= 0 && index < currentList.Items.Count) // range check mainly for passing 0 on empty
            {
                currentList.Items[index].Selected = true;
            }

            currentList.ResumeLayout();
        }
        public void GetKeyTermFromTSS_EmbeddedORC()
        {
            ITsStrBldr tsb = TsStrBldrClass.Create();

            tsb.Replace(0, 0, "an", StyleUtils.CharStyleTextProps("Emphasis", Cache.DefaultVernWs));
            tsb.ReplaceTsString(2, 2, TsStringUtils.CreateOrcFromGuid(new Guid(),
                                                                      FwObjDataTypes.kodtOwnNameGuidHot, Cache.DefaultUserWs));
            tsb.Replace(3, 3, "gel", StyleUtils.CharStyleTextProps("Emphasis", Cache.DefaultVernWs));
            // We expect the ORC to be removed from the middle of the input ITsString.
            Assert.AreEqual("angel", TsStringUtils.GetCleanTextFromTsString(tsb.GetString(),
                                                                            m_stylesToRemove, true, Cache.LanguageWritingSystemFactoryAccessor));
        }
示例#11
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Gets the natural type (i.e., not overridden) of the given character code point. This
 /// is essentially based on ICU, but we make one exception to force superscripted
 /// numbers to be considered as word-forming since these are generally used to mark
 /// tone in the vernaculars we work with (see TE-8384).
 /// </summary>
 /// ------------------------------------------------------------------------------------
 protected virtual ValidCharacterType GetNaturalCharType(int codepoint)
 {
     if (TsStringUtils.IsWordForming(codepoint))
     {
         return(ValidCharacterType.WordForming);
     }
     if (DefaultWordformingChars.Any(chr => chr[0] == codepoint))
     {
         return(ValidCharacterType.WordForming);
     }
     return(ValidCharacterType.Other);
 }
示例#12
0
        public void StartsWithMatchSortsFirstAlphabeticalAfter()
        {
            var enWs        = Cache.DefaultAnalWs;
            var matchString = TsStringUtils.MakeString("b", enWs);
            var sorter      = new GenRecordSorter(new StringFinderCompare(new OwnMlPropFinder(Cache.DomainDataByFlid, m_CitationFlid, Cache.DefaultAnalWs),
                                                                          new WritingSystemComparer((CoreWritingSystemDefinition)Cache.WritingSystemFactory.get_EngineOrNull(Cache.DefaultAnalWs))));
            var resultsSorter = new FindResultSorter(matchString, sorter);
            var records       = CreateRecords(new[] { "c", "bob", "a" });

            resultsSorter.Sort(records);
            VerifySortOrder(new[] { "bob", "a", "c" }, records);
        }
示例#13
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Find an allomorph with the specified form, if any. Searches both LexemeForm and
        /// AlternateForms properties.
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="tssform">The tssform.</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public static IMoForm FindMatchingAllomorph(ILexEntry entry, ITsString tssform)
        {
            IMoForm lf     = entry.LexemeFormOA;
            int     wsVern = TsStringUtils.GetWsAtOffset(tssform, 0);
            string  form   = tssform.Text;

            if (lf != null && lf.Form.get_String(wsVern).Text == form)
            {
                return(lf);
            }
            return(entry.AlternateFormsOS.FirstOrDefault(mf => mf.Form.get_String(wsVern).Text == form));
        }
示例#14
0
        public void NullStringDiffersFromTsString()
        {
            ITsStrBldr strBldr = TsStringUtils.MakeStrBldr();

            strBldr.Replace(0, 0, "Test", TsStringUtils.MakeProps(null, 5));
            string s;

            Assert.IsFalse(TsStringHelper.TsStringsAreEqual(strBldr.GetString(), null,
                                                            out s));
            Assert.AreEqual("TsStrings differ." + Environment.NewLine + "\tExpected <Test>, but was <null>.", s,
                            "Got incorrect explanation of difference");
        }
示例#15
0
        public void FixtureSetup()
        {
            m_stylesheet = new TestFwStylesheet();
            m_wsManager  = new WritingSystemManager();

            // English
            CoreWritingSystemDefinition enWs;

            m_wsManager.GetOrSet("en", out enWs);
            m_hvoEnglishWs = enWs.Handle;
            Assert.IsTrue(m_hvoEnglishWs > 0, "Should have gotten an hvo for the English WS");
            // German
            CoreWritingSystemDefinition deWs;

            m_wsManager.GetOrSet("de", out deWs);
            m_hvoGermanWs = deWs.Handle;
            Assert.IsTrue(m_hvoGermanWs > 0, "Should have gotten an hvo for the German WS");
            Assert.IsTrue(m_hvoEnglishWs != m_hvoGermanWs, "Writing systems should have different IDs");

            // Create a couple of styles
            int          hvoStyle  = m_stylesheet.MakeNewStyle();
            ITsPropsBldr propsBldr = TsStringUtils.MakePropsBldr();

            propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Arial");
            m_stylesheet.PutStyle("StyleA", "bla", hvoStyle, 0, hvoStyle, 1, false, false,
                                  propsBldr.GetTextProps());

            hvoStyle = m_stylesheet.MakeNewStyle();
            propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Times New Roman");
            m_stylesheet.PutStyle("StyleB", "bla", hvoStyle, 0, hvoStyle, 1, false, false,
                                  propsBldr.GetTextProps());

            // Override the font size for each writing system and each style.
            List <FontOverride> fontOverrides = new List <FontOverride>(2);
            FontOverride        fo;

            fo.writingSystem = m_hvoEnglishWs;
            fo.fontSize      = 21;
            fontOverrides.Add(fo);
            fo.writingSystem = m_hvoGermanWs;
            fo.fontSize      = 13;
            fontOverrides.Add(fo);
            m_stylesheet.OverrideFontsForWritingSystems("StyleA", fontOverrides);

            fontOverrides.Clear();
            fo.writingSystem = m_hvoEnglishWs;
            fo.fontSize      = 20;
            fontOverrides.Add(fo);
            fo.writingSystem = m_hvoGermanWs;
            fo.fontSize      = 56;
            fontOverrides.Add(fo);
            m_stylesheet.OverrideFontsForWritingSystems("StyleB", fontOverrides);
        }
示例#16
0
        public void SerializeTsStringToXml_WithLink()
        {
            Guid         expectedGuid = Guid.NewGuid();
            ITsPropsBldr tpb          = TsStringUtils.MakePropsBldr();

            tpb.SetIntValue(FwTextPropType.ktptWs, FwTextPropVar.ktpvDefault, EnWS);
            tpb.SetStringValue(FwTextPropType.ktptObjData, CreateObjData(FwObjDataTypes.kodtNameGuidHot, expectedGuid.ToByteArray()));
            ITsString tss = TsStringUtils.MakeString(StringUtils.kChObject.ToString(), tpb.GetTextProps());
            string    xml = TsStringSerializer.SerializeTsStringToXml(tss, WritingSystemManager);

            Assert.That(StripNewLines(xml), Is.EqualTo(string.Format("<Str><Run ws=\"en\" link=\"{0}\"></Run></Str>", expectedGuid)));
        }
示例#17
0
        public void OnAddWordGlossesToFreeTrans_Simple()
        {
            ISegment seg = m_para0_0.SegmentsOS[0];

            SetUpMocksForOnAddWordGlossesToFreeTransTest(seg);
            SetUpGlosses(seg, "hope", "this", "works");

            m_interlinDoc.OnAddWordGlossesToFreeTrans(null);

            AssertEx.AreTsStringsEqual(TsStringUtils.MakeTss("hope this works.", Cache.DefaultAnalWs),
                                       seg.FreeTranslation.AnalysisDefaultWritingSystem);
        }
示例#18
0
        /// <summary>
        /// Creates an ILexEntry object, optionally with specified headword and gloss
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="headword">Optional: defaults to 'Citation'</param>
        /// <param name="gloss">Optional: defaults to 'gloss'</param>
        /// <returns></returns>
        internal static ILexEntry CreateInterestingLexEntry(LcmCache cache, string headword = "Citation", string gloss = "gloss")
        {
            var entryFactory = cache.ServiceLocator.GetInstance <ILexEntryFactory>();
            var entry        = entryFactory.Create();
            var wsEn         = EnsureWritingSystemSetup(cache, "en", false);
            var wsFr         = EnsureWritingSystemSetup(cache, "fr", true);

            AddHeadwordToEntry(entry, headword, wsFr, cache);
            entry.Comment.set_String(wsEn, TsStringUtils.MakeString("Comment", wsEn));
            AddSenseToEntry(entry, gloss, wsEn, cache);
            return(entry);
        }
示例#19
0
        private void UpdateTextBoxWs(ComboBox wsComboBox, FwTextBox textBox)
        {
            var ws = wsComboBox.SelectedItem as CoreWritingSystemDefinition;

            if (ws == null)
            {
                Debug.Assert(wsComboBox.SelectedIndex == -1);
                return;
            }
            textBox.WritingSystemCode = ws.Handle;
            textBox.Tss = TsStringUtils.MakeString(textBox.Text.Trim(), ws.Handle);
        }
示例#20
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles a complex string that contains multiple runs with optional multiple
        /// text props applied.
        /// </summary>
        /// <param name="xml">The XML.</param>
        /// <param name="lgwsf">The writing system factory.</param>
        /// <returns>The created TsString</returns>
        /// ------------------------------------------------------------------------------------
        private static ITsString HandleComplexString(XElement xml, ILgWritingSystemFactory lgwsf)
        {
            var runs = xml.Elements("Run");

            if (runs.Count() == 0)
            {
                if (xml.Name.LocalName == "AStr" && xml.Attributes().Count() == 1)
                {
                    // This duplicates a little bit of code from HandleSimpleRun, but I wanted to keep that really simple
                    // and fast, and this case hardly ever happens...maybe not at all in real life.
                    XAttribute wsAttribute = xml.Attributes().First();
                    if (wsAttribute.Name.LocalName != "ws")
                    {
                        return(null);                        // we handle only single runs with only the ws attribute.
                    }
                    // Make sure the text is in the decomposed form (FWR-148)
                    string runText = Icu.Normalize(xml.Value, Icu.UNormalizationMode.UNORM_NFD);
                    return(TsStringUtils.MakeString(runText, GetWsForId(wsAttribute.Value, lgwsf)));
                }
                return(null);                   // If we don't have any runs, we don't have a string!
            }

            var strBldr = TsStringUtils.MakeIncStrBldr();

            foreach (XElement runElement in runs)
            {
                if (runElement == null)
                {
                    throw new XmlSchemaException("TsString XML must contain a <Run> element contained in a <" + xml.Name.LocalName + "> element");
                }
                string runText = runElement.Value;
                if (runElement.Attribute("ws") == null && (runText.Length == 0 || runText[0] > 13))
                {
                    throw new XmlSchemaException("Run element must contain a ws attribute. Run text: " + runElement.Value);
                }

                // Make sure the text is in the decomposed form (FWR-148)
                runText = Icu.Normalize(runText, Icu.UNormalizationMode.UNORM_NFD);
                bool isOrcNeeded = TsPropsSerializer.GetPropAttributesForElement(runElement, lgwsf, strBldr);

                // Add an ORC character, if needed, for the run
                if (runText.Length == 0 && isOrcNeeded)
                {
                    runText = StringUtils.kszObject;
                }

                // Add the text with the properties to the builder
                strBldr.Append(runText);
            }

            return(strBldr.GetString());
        }
示例#21
0
        public void TryGetObject_PlainPunctString_NotExists_ORCTableNotEmpty()
        {
            IPunctuationForm pf   = Cache.ServiceLocator.GetInstance <IPunctuationFormFactory>().Create();
            ITsStrBldr       bldr = TsStringUtils.MakeStrBldr();

            TsStringUtils.InsertOrcIntoPara(Guid.NewGuid(), FwObjDataTypes.kodtNameGuidHot, bldr, 0, 0, Cache.DefaultVernWs);
            pf.Form = bldr.GetString();

            IPunctuationForm pfDummy;
            ITsString        tssPunc = TsStringUtils.MakeString(".", Cache.DefaultVernWs);

            Assert.IsFalse(m_repo.TryGetObject(tssPunc, out pfDummy));
        }
示例#22
0
        public void TryGetObject_ORCWithSameProps_ObjData()
        {
            IPunctuationForm pf   = Cache.ServiceLocator.GetInstance <IPunctuationFormFactory>().Create();
            ITsStrBldr       bldr = TsStringUtils.MakeStrBldr();

            TsStringUtils.InsertOrcIntoPara(Guid.NewGuid(), FwObjDataTypes.kodtNameGuidHot, bldr, 0, 0, Cache.DefaultVernWs);
            pf.Form = bldr.GetString();
            IPunctuationForm pfExisting;
            ITsString        tssOrcness = bldr.GetString();

            Assert.IsTrue(m_repo.TryGetObject(tssOrcness, out pfExisting));
            Assert.AreEqual(pf, pfExisting);
        }
示例#23
0
        public void TryGetObject_ORC_Twice_WsOnly()
        {
            IPunctuationForm pfDummy;
            ITsString        tssOrcness = TsStringUtils.MakeString(StringUtils.kszObject, Cache.DefaultVernWs);

            Assert.IsFalse(m_repo.TryGetObject(tssOrcness, out pfDummy));

            IPunctuationForm pf = Cache.ServiceLocator.GetInstance <IPunctuationFormFactory>().Create();

            pf.Form    = TsStringUtils.MakeString(StringUtils.kszObject, Cache.DefaultVernWs);
            tssOrcness = TsStringUtils.MakeString(StringUtils.kszObject, Cache.DefaultUserWs);
            Assert.IsFalse(m_repo.TryGetObject(tssOrcness, out pfDummy));
        }
示例#24
0
        protected ITsString MakeSimpleString(String str)
        {
            ITsStrBldr   builder = TsStringUtils.MakeStrBldr();
            ITsPropsBldr bldr    = TsStringUtils.MakePropsBldr();

            bldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                  (int)FwTextPropVar.ktpvDefault, m_cache.DefaultUserWs);
            bldr.SetIntPropValues((int)FwTextPropType.ktptFontSize,
                                  (int)FwTextPropVar.ktpvMilliPoint, s_baseFontSize * 800);
            bldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, MiscUtils.StandardSansSerif);
            builder.Replace(0, 0, str, bldr.GetTextProps());
            return(builder.GetString());
        }
示例#25
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Inserts an ORC pointing to this picture at the specified location.
        /// </summary>
        /// <param name="tsStrBldr">String into which ORC is to be inserted</param>
        /// <param name="ich">character offset where insertion is to occur</param>
        /// ------------------------------------------------------------------------------------
        public void InsertORCAt(ITsStrBldr tsStrBldr, int ich)
        {
            Debug.Assert(tsStrBldr.Length >= ich);

            // Make a TsTextProps with the relevant object data and the same ws as its
            // context.
            int nvar;
            int wsRun = tsStrBldr.get_PropertiesAt(ich).GetIntPropValues((int)FwTextPropType.ktptWs, out nvar);

            // Insert the orc with the resulting properties.
            TsStringUtils.InsertOrcIntoPara(Guid, FwObjDataTypes.kodtGuidMoveableObjDisp,
                                            tsStrBldr, ich, ich, wsRun);
        }
示例#26
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));
        }
示例#27
0
        public void MultiStringNegativeWSTest()
        {
            // Set class first, or it will throw an exception.
            const int hvo  = 1;
            var       clid = SilDataAccess.MetaDataCache.GetClassId("ClassK");

            SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, clid);
            var tag = SilDataAccess.MetaDataCache.GetFieldId("ClassK", "MultiStringProp11", false);

            var tss = TsStringUtils.MakeString("Verb", 1);

            SilDataAccess.SetMultiStringAlt(hvo, tag, -1, tss);
        }
示例#28
0
        public void UnkPropWrongInterfaceTest()
        {
            // First, set up class id.
            const int hvo  = 1;
            var       clid = SilDataAccess.MetaDataCache.GetClassId("ClassG");

            SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, clid);

            var tsPropsBuilder = TsStringUtils.MakePropsBldr();
            var tag            = SilDataAccess.MetaDataCache.GetFieldId("ClassG", "TextPropsProp7", false);

            SilDataAccess.SetUnknown(hvo, tag, tsPropsBuilder);
        }
示例#29
0
        public void UnknownProp()
        {
            object obj = m_ISilDataAccess.get_UnknownProp(1120, 2220);

            Assert.IsNull(obj);

            ITsPropsBldr propsBldr = TsStringUtils.MakePropsBldr();
            ITsTextProps ttp       = propsBldr.GetTextProps();

            m_IVwCacheDa.CacheUnknown(1120, 2220, ttp);
            obj = m_ISilDataAccess.get_UnknownProp(1120, 2220);
            Assert.AreEqual(ttp, obj);
        }
示例#30
0
        /// <summary>
        /// Set the label on the empty node.
        /// </summary>
        /// <param name="label"></param>
        public void SetEmptyLabel(string label)
        {
            CheckDisposed();

            if (m_kEmptyNode != null)
            {
                m_kEmptyNode.Tss = TsStringUtils.MakeString(label, Cache.WritingSystemFactory.UserWs);
            }
            if (m_treeCombo != null && m_treeCombo.SelectedNode == m_kEmptyNode)
            {
                m_treeCombo.Tss = m_kEmptyNode.Tss;
            }
        }