コード例 #1
0
ファイル: AssertEx.cs プロジェクト: sillsdev/WorldPad
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Verifies that the given run of the given ITsString contains the specified text and
		/// properties.
		/// </summary>
		/// <param name="tss">The ITsString to test</param>
		/// <param name="iRun">Zero-based run index to check</param>
		/// <param name="expectedText">Expected contents of run</param>
		/// <param name="expectedCharStyle">Expected character style name, or null if expecting
		/// default paragraph character props</param>
		/// <param name="expectedWs">Expected writing system for the run</param>
		/// <param name="fExpectNFD">Pass <c>true</c> to make sure that TSS is in normal
		/// form decomposed (which it probably should be if it has been saved to the DB); pass
		/// <c>false</c> if the string is not expected to be decomposed.</param>
		/// ------------------------------------------------------------------------------------
		public static void RunIsCorrect(ITsString tss, int iRun, string expectedText,
			string expectedCharStyle, int expectedWs, bool fExpectNFD)
		{
			Assert.AreEqual(fExpectNFD,
				tss.get_IsNormalizedForm(FwNormalizationMode.knmNFD));

			// If both strings are null then they're equal and there's nothing else to compare.
			if (expectedText == null)
			{
				Assert.IsNull(tss.Text);
				return;
			}

			// If both strings are 0-length, then they're equal; otherwise compare them.
			if (expectedText.Length == 0)
				Assert.AreEqual(0, tss.Length);
			else
			{
				// compare strings
				// apparently IndexOf performs Unicode normalization.
				if (expectedText.IndexOf(tss.get_RunText(iRun), StringComparison.Ordinal) != 0)
				{
					Assert.Fail("Run " + iRun + " text differs. Expected <" +
						expectedText + "> but was <" + tss.get_RunText(iRun) + ">");
				}
			}

			ITsTextProps ttp1 = StyleUtils.CharStyleTextProps(expectedCharStyle, expectedWs);
			ITsTextProps ttp2 = tss.get_Properties(iRun);
			string sWhy;
			if (!TsTextPropsHelper.PropsAreEqual(ttp1, ttp2, out sWhy))
				Assert.Fail(sWhy);
		}
コード例 #2
0
		public override void SetString(int hvo, int tag, ITsString tss)
		{
			if (!ShowSpaces || tag != StTxtParaTags.kflidContents || tss.Text == null)
			{
				base.SetString(hvo, tag, tss);
				return;
			}
			var text = tss.Text;
			var bldr = tss.GetBldr();
			int index = text.IndexOf(' ');
			while (index >= 0)
			{
				int nVar;
				if (bldr.get_PropertiesAt(index).GetIntPropValues((int) FwTextPropType.ktptBackColor, out nVar) == KzwsBackColor)
					bldr.Replace(index, index + 1, AnalysisOccurrence.KstrZws, null);
				index = text.IndexOf(' ', index + 1);
			}
			for (int irun = bldr.RunCount - 1; irun >= 0;  irun--)
			{
				int nVar;
				if (bldr.get_Properties(irun).GetIntPropValues((int) FwTextPropType.ktptBackColor, out nVar) == KzwsBackColor)
				{
					int ichMin, ichLim;
					bldr.GetBoundsOfRun(irun, out ichMin, out ichLim);
					bldr.SetIntPropValues(ichMin, ichLim, (int)FwTextPropType.ktptBackColor, -1, -1);
				}
			}

			base.SetString(hvo, tag, bldr.GetString());
		}
コード例 #3
0
ファイル: CmPicture.cs プロジェクト: bbriggs/FieldWorks
		///// ------------------------------------------------------------------------------------
		///// <summary>
		///// Append a picture to the end of the paragraph using the given writing system.
		///// </summary>
		///// <param name="ws">given writing system</param>
		///// <param name="strBldr">The string builder for the paragraph being composed</param>
		///// ------------------------------------------------------------------------------------
		//public void AppendPicture(int ws, ITsStrBldr strBldr)
		//{
		//    // Make a TsTextProps with the relevant object data and the same ws as its
		//    // context.
		//    byte[] objData = MiscUtils.GetObjData(this.Guid,
		//        (byte)FwObjDataTypes.kodtGuidMoveableObjDisp);
		//    ITsPropsBldr propsBldr = TsPropsBldrClass.Create();
		//    propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData,
		//        objData, objData.Length);
		//    propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, ws);

		//    // Insert the orc with the resulting properties.
		//    strBldr.Replace(strBldr.Length, strBldr.Length,
		//        new string(TsStringUtils.kChObject, 1), propsBldr.GetTextProps());
		//}

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Update the properties of a CmPicture with the given file, caption, and folder.
		/// </summary>
		/// <param name="srcFilename">The full path to the filename (this might be an "internal"
		/// copy of the original the user chose)</param>
		/// <param name="captionTss">The caption</param>
		/// <param name="sFolder">The name of the CmFolder where picture should be stored</param>
		/// <param name="ws">The WS for the location in the caption MultiUnicode to put the
		/// caption</param>
		/// ------------------------------------------------------------------------------------
		public void UpdatePicture(string srcFilename, ITsString captionTss, string sFolder, int ws)
		{
			// Set the caption first since creating the CmFile will throw if srcFilename is empty.
			if (ws != 0)
				Caption.set_String(ws, captionTss);

			ICmFile file = PictureFileRA;
			if (file == null)
			{
				ICmFolder folder = DomainObjectServices.FindOrCreateFolder(m_cache, LangProjectTags.kflidPictures, sFolder);
				PictureFileRA = DomainObjectServices.FindOrCreateFile(folder, srcFilename);
			}
			else
			{
				Debug.Assert(sFolder == CmFolderTags.LocalPictures,
					"TODO: If we ever actually support use of different folders, we need to handle folder changes.");
				if (srcFilename != null && !FileUtils.PathsAreEqual(srcFilename, file.AbsoluteInternalPath))
					file.InternalPath = srcFilename;
			}
			// We shouldn't need to this in the new FDO.
			//m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, Hvo,
			//    (int)CmPicture.CmPictureTags.kflidCaption, ws, 0 , 0);
			//m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, file.Hvo,
			//    (int)CmFile.CmFileTags.kflidInternalPath, 0, 1, 1);
		}
コード例 #4
0
			public SandboxVc(CachePair caches, InterlinLineChoices choices, bool fIconsForAnalysisChoices, SandboxBase sandbox)
			{
				m_caches = caches;
				m_cache = caches.MainCache; //prior to 9-20-2011 this was not set, if we find there was a reason get rid of this.
				m_choices = choices;
				m_sandbox = sandbox;
				m_fIconsForAnalysisChoices = fIconsForAnalysisChoices;
				m_wsAnalysis = caches.MainCache.DefaultAnalWs;
				m_wsUi = caches.MainCache.LanguageWritingSystemFactoryAccessor.UserWs;
				m_tssMissingMorphs = m_tsf.MakeString(ITextStrings.ksStars, m_sandbox.RawWordformWs);
				m_tssEmptyAnalysis = m_tsf.MakeString("", m_wsAnalysis);
				m_tssEmptyVern = m_tsf.MakeString("", m_sandbox.RawWordformWs);
				m_tssMissingEntry = m_tssMissingMorphs;
				// It's tempting to re-use m_tssMissingMorphs, but the analysis and vernacular default
				// fonts may have different sizes, requiring differnt line heights to align things well.
				m_tssMissingMorphGloss = m_tsf.MakeString(ITextStrings.ksStars, m_wsAnalysis);
				m_tssMissingMorphPos = m_tsf.MakeString(ITextStrings.ksStars, m_wsAnalysis);
				m_tssMissingWordPos = m_tssMissingMorphPos;
				m_PulldownArrowPic = VwConstructorServices.ConvertImageToComPicture(ResourceHelper.InterlinPopupArrow);
				m_dxmpArrowPicWidth = ConvertPictureWidthToMillipoints(m_PulldownArrowPic.Picture);
				IWritingSystem wsObj = caches.MainCache.ServiceLocator.WritingSystemManager.Get(m_sandbox.RawWordformWs);
				if (wsObj != null)
					m_fRtl = wsObj.RightToLeftScript;

			}
コード例 #5
0
ファイル: ClusterTests.cs プロジェクト: bbriggs/FieldWorks
		private ITsString m_tssVerse; // text to include in a verse

		#region Setup

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Overridden to only create a book with no content, heading, title, etc.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void CreateTestData()
		{
			m_genesis = AddBookToMockedScripture(1, "Genesis");
			m_genesisRevision = AddArchiveBookToMockedScripture(1, "Genesis");

			m_tssVerse = TsStringUtils.MakeTss("verse text", Cache.DefaultVernWs);
		}
コード例 #6
0
		public RegRuleFormulaVc(FdoCache cache, Mediator mediator)
			: base(cache, mediator)
		{
			ITsPropsBldr tpb = TsPropsBldrClass.Create();
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, 1000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
			m_ctxtProps = tpb.GetTextProps();

			tpb = TsPropsBldrClass.Create();
			tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 20000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
			tpb.SetIntPropValues((int)FwTextPropType.ktptPadLeading, (int)FwTextPropVar.ktpvMilliPoint, 2000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptPadTrailing, (int)FwTextPropVar.ktpvMilliPoint, 2000);
			tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, MiscUtils.StandardSansSerif);
			tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable);
			m_charProps = tpb.GetTextProps();

			ITsStrFactory tsf = m_cache.TsStrFactory;
			int userWs = m_cache.DefaultUserWs;
			m_arrow = tsf.MakeString("\u2192", userWs);
			m_slash = tsf.MakeString("/", userWs);
			m_underscore = tsf.MakeString("__", userWs);
		}
コード例 #7
0
		/// <summary>
		/// Helper
		/// </summary>
		private LexEntryComponents SetupComponentsForEntryCreation(out int germanWsId,
			out ILexEntryFactory lexFactory, out ITsString tssGermanGloss)
		{
			germanWsId = Cache.WritingSystemFactory.GetWsFromStr("de");
			Cache.LangProject.AnalysisWritingSystems.Add(
				Cache.WritingSystemFactory.get_EngineOrNull(germanWsId) as IWritingSystem);
			lexFactory = Cache.ServiceLocator.GetInstance<ILexEntryFactory>();
			tssGermanGloss = Cache.TsStrFactory.MakeString("da", germanWsId);
			var tssVernacForm = Cache.TsStrFactory.MakeString("bunk",
				Cache.WritingSystemFactory.GetWsFromStr(Cache.LangProject.DefaultVernacularWritingSystem.Id));
			var msa = new SandboxGenericMSA
			{
				MainPOS = Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS.Where(
					pos => pos.Name.AnalysisDefaultWritingSystem.Text == "noun")
					.Cast<IPartOfSpeech>()
					.FirstOrDefault(),
				MsaType = MsaType.kStem
			};

			var lexEntryComponents = new LexEntryComponents()
			{
				GlossAlternatives = new List<ITsString>() { tssGermanGloss },
				LexemeFormAlternatives = new List<ITsString>() { tssVernacForm },
				MSA = msa,
				MorphType = Cache.LangProject.LexDbOA.MorphTypesOA.PossibilitiesOS.Where(
					mt => mt.Name.AnalysisDefaultWritingSystem.Text == "stem")
					.Cast<IMoMorphType>()
					.FirstOrDefault()
			};
			return lexEntryComponents;
		}
コード例 #8
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// -----------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			base.Dispose(disposing);

			if (disposing)
			{
				//RightMouseClickedEvent -= new FwRightMouseClickEventHandler(InterlinDocChild_RightMouseClickedEvent);
				if (m_tryAWordSandbox != null)
				{
					if (!Controls.Contains(m_tryAWordSandbox))
						m_tryAWordSandbox.Dispose();
				}
				if (m_vc != null)
					m_vc.Dispose();
			}
			m_tryAWordSandbox = null;
			m_vc = null;
			m_wordform = null;
			m_msaHvoList = null;
			m_sWordForm = null;
		}
コード例 #9
0
		/// <summary>
		/// Find (create, if needed) a wordform for the given ITsString.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="tssContents">The form to find.</param>
		/// <returns>A wordform with the given form.</returns>
		public static IWfiWordform FindOrCreateWordform(FdoCache cache, ITsString tssContents)
		{
			IWfiWordform wf;
			if (!cache.ServiceLocator.GetInstance<IWfiWordformRepository>().TryGetObject(tssContents, out wf))
				wf = cache.ServiceLocator.GetInstance<IWfiWordformFactory>().Create(tssContents);
			return wf;
		}
コード例 #10
0
		protected InterlinearExporter(FdoCache cache, XmlWriter writer, int hvoRoot, InterlinLineChoices lineChoices, InterlinVc vc, ITsString tssTextName, ITsString tssTextAbbreviation)
			: base(null, cache.MainCacheAccessor, hvoRoot)
		{
			m_cache = cache;
			m_writer = writer;
			ktagParaSegments = InterlinVc.ParaSegmentTag(cache);
			ktagSegmentForms = InterlinVc.SegmentFormsTag(cache);
			m_flidStringValue = CmBaseAnnotation.StringValuePropId(cache);
			m_lineChoices = lineChoices;
			m_defaultGlossVirtFlid = BaseVirtualHandler.GetInstalledHandlerTag(m_cache, "WfiMorphBundle", "DefaultSense");
			m_vc = vc;
			m_tssPendingTitle = tssTextName;
			m_tssTitleAbbreviation = tssTextAbbreviation;

			// Get morphtype information that we need later.  (plus stuff we don't...)  See LT-8288.
			IMoMorphType mmtStem;
			IMoMorphType mmtPrefix;
			IMoMorphType mmtSuffix;
			IMoMorphType mmtInfix;
			IMoMorphType mmtBoundStem;
			IMoMorphType mmtSimulfix;
			IMoMorphType mmtSuprafix;
			MoMorphType.GetMajorMorphTypes(cache, out mmtStem, out mmtPrefix, out mmtSuffix, out mmtInfix,
				out mmtBoundStem, out m_mmtProclitic, out m_mmtEnclitic, out mmtSimulfix, out mmtSuprafix);
		}
コード例 #11
0
ファイル: WordMaker.cs プロジェクト: bbriggs/FieldWorks
		/// <summary>
		/// Start it off analyzing a string.
		/// </summary>
		/// <param name="tss"></param>
		/// <param name="cpe">engine to use.</param>
		public WordMaker(ITsString tss, ILgCharacterPropertyEngine cpe)
		{
			m_tss = tss;
			m_ich = 0;
			m_st = tss.get_Text();
			m_cch = m_st.Length;
			m_cpe = cpe;
		}
コード例 #12
0
		protected RuleFormulaVcBase(FdoCache cache, XCore.Mediator mediator)
			: base(cache, mediator)
		{
			ITsStrFactory tsf = m_cache.TsStrFactory;
			int userWs = m_cache.DefaultUserWs;
			m_infinity = tsf.MakeString("\u221e", userWs);
			m_x = tsf.MakeString("X", userWs);
		}
コード例 #13
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Replaces the specified portion of the original string with the new string.
		/// </summary>
		/// <param name="tss">The original string.</param>
		/// <param name="startIndex">The start index.</param>
		/// <param name="length">The length.</param>
		/// <param name="tssReplace">The new string.</param>
		/// <returns>The new string with the requested replacements made</returns>
		/// ------------------------------------------------------------------------------------
		public static ITsString Replace(this ITsString tss, int startIndex, int length, ITsString tssReplace)
		{
			int cch = tss.Length;
			Debug.Assert(startIndex >= 0 && startIndex + length <= cch);
			ITsStrBldr bldr = tss.GetBldr();
			bldr.ReplaceTsString(startIndex, startIndex + length, tssReplace);
			return bldr.GetString();
		}
コード例 #14
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Make sure that all runs of the given ts string will fit within the given height.
		/// </summary>
		/// <param name="tss">(Potentially) unadjusted TsString -- may have some pre-existing
		/// adjustments, but if it does, we (probably) ignore those and recheck every run</param>
		/// <param name="dympMaxHeight">The maximum height (in millipoints) of the Ts String.</param>
		/// <param name="styleSheet"></param>
		/// <param name="writingSystemFactory"></param>
		/// -------------------------------------------------------------------------------------
		public static ITsString GetAdjustedTsString(ITsString tss, int dympMaxHeight,
			IVwStylesheet styleSheet, ILgWritingSystemFactory writingSystemFactory)
		{
			if (dympMaxHeight == 0)
				return tss;

			ITsStrBldr bldr = null;

			int runCount = tss.RunCount;
			for (int irun = 0; irun < runCount; irun++)
			{
				ITsTextProps props = tss.get_Properties(irun);
				int var;
				int wsTmp = props.GetIntPropValues((int)FwTextPropType.ktptWs,
					out var);
				string styleName =
					props.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle);

				int height;
				string name;
				float sizeInPoints;
				using (Font f = GetFontForStyle(styleName, styleSheet, wsTmp, writingSystemFactory))
				{
					height = GetFontHeight(f);
					name = f.Name;
					sizeInPoints = f.SizeInPoints;
				}
				int curHeight = height;
				// incrementally reduce the size of the font until the text can fit
				while (curHeight > dympMaxHeight)
				{
					using (var f = new Font(name, sizeInPoints - 0.25f))
					{
						curHeight = GetFontHeight(f);
						name = f.Name;
						sizeInPoints = f.SizeInPoints;
					}
				}

				if (curHeight != height)
				{
					// apply formatting to the problem run
					if (bldr == null)
						bldr = tss.GetBldr();

					int iStart = tss.get_MinOfRun(irun);
					int iEnd = tss.get_LimOfRun(irun);
					bldr.SetIntPropValues(iStart, iEnd,
						(int)FwTextPropType.ktptFontSize,
						(int)FwTextPropVar.ktpvMilliPoint, (int)(sizeInPoints * 1000.0f));
				}
			}

			if (bldr != null)
				return bldr.GetString();
			else
				return tss;
		}
コード例 #15
0
		public ComplexConcPatternVc(FdoCache cache, Mediator mediator)
			: base(cache, mediator)
		{
			ITsStrFactory tsf = m_cache.TsStrFactory;
			int userWs = m_cache.DefaultUserWs;
			m_infinity = tsf.MakeString("\u221e", userWs);
			m_or = tsf.MakeString("OR", userWs);
			m_hash = tsf.MakeString("#", userWs);
		}
コード例 #16
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Insert the specified string into the first argument/recipient at the specified position.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public static ITsString Insert(this ITsString tss, int startIndex, ITsString tssInsert)
		{
			int cch = tss.Length;
			Debug.Assert(startIndex >= 0 && startIndex <= cch);
			if (tssInsert.Length == 0)
				return tss;
			ITsStrBldr bldr = tss.GetBldr();
			bldr.ReplaceTsString(startIndex, startIndex, tssInsert);
			return bldr.GetString();
		}
コード例 #17
0
		private bool m_fShouldLink; // set true by btnLexicon_Click, caller should call LinkToLexicon after dialog closes.
		#endregion

		#region Constructor/destructor
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor for a single LexEntry object.
		/// </summary>
		/// <param name="leui"></param>
		/// <param name="wf"></param>
		/// <param name="helpProvider"></param>
		/// <param name="helpFileKey">string key to get the help file name</param>
		/// ------------------------------------------------------------------------------------
		public SummaryDialogForm(LexEntryUi leui, ITsString tssForm, IHelpTopicProvider helpProvider,
			string helpFileKey, IVwStylesheet styleSheet)
		{
			InitializeComponent();

			m_rghvo = new List<int>(1);
			m_rghvo.Add(leui.Object.Hvo);
			m_cache = leui.Object.Cache;
			m_mediator = leui.Mediator;
			Initialize(tssForm, helpProvider, helpFileKey, styleSheet);
		}
コード例 #18
0
ファイル: WordMaker.cs プロジェクト: bbriggs/FieldWorks
		public WordMaker(ITsString tss, ILgWritingSystemFactory encf)
		{
			m_tss = tss;
			m_ich = 0;
			m_st = tss.get_Text();
			if (m_st == null)
				m_st = "";
			m_cch = m_st.Length;
			// Get a character property engine from the wsf.
			m_cpe = encf.get_UnicodeCharProps();
			Debug.Assert(m_cpe != null, "encf.get_UnicodeCharProps() returned null");
		}
コード例 #19
0
		/// <summary>
		/// Create a new sense and add it to the given entry.
		/// </summary>
		/// <param name="entry"></param>
		/// <param name="sandboxMSA"></param>
		/// <param name="gloss"></param>
		/// <returns></returns>
		public ILexSense Create(ILexEntry entry, SandboxGenericMSA sandboxMSA, ITsString gloss)
		{
			var sense = new LexSense();
			entry.SensesOS.Add(sense);
			sense.SandboxMSA = sandboxMSA;

			if (gloss != null)
			{
				sense.Gloss.set_String(gloss.get_WritingSystemAt(0), gloss);
			}
			return sense;
		}
コード例 #20
0
		public static InterlinearExporter Create(string mode, FdoCache cache, XmlWriter writer, int hvoRoot,
			InterlinLineChoices lineChoices, InterlinVc vc, ITsString tssTextName, ITsString tssTextAbbreviation)
		{
			if (mode != null && mode.ToLowerInvariant() == "elan")
			{
				return new InterlinearExporterForElan(cache, writer, hvoRoot, lineChoices, vc, tssTextName,
													  tssTextAbbreviation);
			}
			else
			{
				return new InterlinearExporter(cache, writer, hvoRoot, lineChoices, vc, tssTextName, tssTextAbbreviation);
			}
		}
コード例 #21
0
ファイル: StFootnote.cs プロジェクト: bbriggs/FieldWorks
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the text representation of a TsString.
		/// </summary>
		/// <param name="tss">The TsString.</param>
		/// <returns>text representation of the TsString</returns>
		/// ------------------------------------------------------------------------------------
		private string GetTextRepresentationOfTsString(ITsString tss)
		{
			string tssRepresentation = string.Empty;
			for (int iRun = 0; iRun < tss.RunCount; iRun++)
			{
				tssRepresentation += "<RUN";

				// writing system of run
				int nVar;
				int ws = tss.get_Properties(iRun).GetIntPropValues(
					(int)FwTextPropType.ktptWs, out nVar);
				if (ws != -1)
				{
					IWritingSystem wsObj = Services.WritingSystemManager.Get(ws);
					tssRepresentation += " WS='" + wsObj.Id + "'";
				}

				// character style of run
				string charStyle = tss.get_Properties(iRun).GetStrPropValue(
					(int)FwTextPropType.ktptNamedStyle);
				string runText = tss.get_RunText(iRun);
				// add the style tags
				if (charStyle != null)
					tssRepresentation += " CS='" + charStyle + @"'";

				tssRepresentation += ">";

				// add the text for the tag
				if (runText != null && runText != string.Empty)
				{
					var newString = new StringBuilder(runText.Length * 2);
					for (var i = 0; i < runText.Length; i++)
					{
						// remove '<' and '>' from the text
						if (runText[i] == '<')
							newString.Append("&lt;");
						else if (runText[i] == '>')
							newString.Append("&gt;");
						else
							newString.Append(runText[i]);
					}
					tssRepresentation += newString.ToString();
				}

				// add the run end tag
				tssRepresentation += "</RUN>";
			}
			return tssRepresentation;
		}
コード例 #22
0
		public bool Accept(ITsString tssKey)
		{
			// Fail fast if text doesn't match exactly.
			if (!MatchText(tssKey.Length == 0 ? "" : tssKey.Text))
				return false;
			// Writing system must also match.
			int crun = tssKey.RunCount;
			for (int irun = 0; irun < crun; irun++)
			{
				int nVar;
				if (tssKey.get_Properties(irun).GetIntPropValues((int)FwTextPropType.ktptWs, out nVar) != m_ws)
					return false;
			}
			return true;
		}
コード例 #23
0
		public MetaRuleFormulaVc(FdoCache cache, XCore.Mediator mediator)
			: base(cache, mediator)
		{
			ITsPropsBldr tpb = TsPropsBldrClass.Create();
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
			m_inputCtxtProps = tpb.GetTextProps();

			tpb = TsPropsBldrClass.Create();
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
			tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable);
			tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			m_resultCtxtProps = tpb.GetTextProps();

			tpb = TsPropsBldrClass.Create();
			tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, MiscUtils.StandardSansSerif);
			tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 10000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
			tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable);
			m_colHeaderProps = tpb.GetTextProps();

			tpb = TsPropsBldrClass.Create();
			tpb.SetStrPropValue((int)FwTextPropType.ktptFontFamily, MiscUtils.StandardSansSerif);
			tpb.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 10000);
			tpb.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault,
				(int)ColorUtil.ConvertColorToBGR(Color.Gray));
			tpb.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalLeft);
			tpb.SetIntPropValues((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable);
			m_rowHeaderProps = tpb.GetTextProps();

			var tsf = m_cache.TsStrFactory;
			var userWs = m_cache.DefaultUserWs;
			m_inputStr = tsf.MakeString(MEStrings.ksMetaRuleInput, userWs);
			m_resultStr = tsf.MakeString(MEStrings.ksMetaRuleResult, userWs);
			m_leftEnvStr = tsf.MakeString(MEStrings.ksMetaRuleLeftEnv, userWs);
			m_rightEnvStr = tsf.MakeString(MEStrings.ksMetaRuleRightEnv, userWs);
			m_switchStr = tsf.MakeString(MEStrings.ksMetaRuleSwitch, userWs);
		}
コード例 #24
0
		private void GetTextProps()
		{
			IStText txt = CmObject.CreateFromDBObject(m_cache, m_hvoRoot) as IStText;
			if (txt != null)
			{
				int hvoOwner = txt.OwnerHVO;
				m_text = CmObject.CreateFromDBObject(m_cache, hvoOwner) as FDO.IText;
				if (m_text != null)
				{
					m_tssTextName = m_text.Name.BestVernacularAnalysisAlternative;
					m_tssTextAbbreviation = m_text.Abbreviation.BestVernacularAnalysisAlternative;
				}
				else if (SIL.FieldWorks.FDO.Scripture.Scripture.IsResponsibleFor(txt as SIL.FieldWorks.FDO.Cellar.StText))
				{
					m_tssTextName = txt.ShortNameTSS;
					// sorry, no abbreviation...
				}
			}
		}
コード例 #25
0
ファイル: CmTranslation.cs プロジェクト: bbriggs/FieldWorks
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Subclasses should override this, if they need to have side effects.
		/// </summary>
		/// <param name="multiAltFlid"></param>
		/// <param name="alternativeWs"></param>
		/// <param name="originalValue"></param>
		/// <param name="newValue"></param>
		/// ------------------------------------------------------------------------------------
		protected override void ITsStringAltChangedSideEffectsInternal(int multiAltFlid,
			IWritingSystem alternativeWs, ITsString originalValue, ITsString newValue)
		{
			base.ITsStringAltChangedSideEffectsInternal(multiAltFlid, alternativeWs, originalValue, newValue);

			// Make sure the translation belongs to Scripture.
			ScrTxtPara para = Owner as ScrTxtPara;
			if (para == null || TypeRA == null)
				return;

			if (multiAltFlid == CmTranslationTags.kflidTranslation &&
				TypeRA.Guid == CmPossibilityTags.kguidTranBackTranslation &&
				((originalValue == null && newValue != null) ||
				(originalValue != null && newValue == null) ||
				(originalValue != null && originalValue.Text != newValue.Text)))
			{
				BtConverter.ConvertCmTransToInterlin(para, alternativeWs.Handle);
				MarkAsUnfinished(alternativeWs.Handle);
			}
		}
コード例 #26
0
		private void SetupForLexSenseFactoryCreate(out int germanWsId, out ITsString tssGermanGloss,
			out ILexEntry entry, out ILexSenseFactory lexSenseFactory, out SandboxGenericMSA msa)
		{
			germanWsId = Cache.WritingSystemFactory.GetWsFromStr("de");
			Cache.LangProject.AnalysisWritingSystems.Add(
				Cache.WritingSystemFactory.get_EngineOrNull(germanWsId) as IWritingSystem);
			var lexFactory = Cache.ServiceLocator.GetInstance<ILexEntryFactory>();
			tssGermanGloss = Cache.TsStrFactory.MakeString("da", germanWsId);
			entry = lexFactory.Create();
			lexSenseFactory = Cache.ServiceLocator.GetInstance<ILexSenseFactory>();
			msa = new SandboxGenericMSA
			{
				MainPOS =
					Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS.Where(
						pos => pos.Name.AnalysisDefaultWritingSystem.Text == "noun")
						.Cast<IPartOfSpeech>()
						.FirstOrDefault(),
				MsaType = MsaType.kStem
			};
		}
コード例 #27
0
			public GetRealAnalysisMethod(IHelpTopicProvider helpTopicProvider, SandboxBase owner,
				CachePair caches, int hvoSbWord, AnalysisTree oldAnalysis, IWfiAnalysis wa,
				IWfiGloss gloss, InterlinLineChoices choices, ITsString tssForm,
				bool fWantOnlyWfiAnalysis) : this()
			{
				m_helpTopicProvider = helpTopicProvider;
				m_sandbox = owner;
				m_caches = caches;
				m_hvoSbWord = hvoSbWord;
				m_oldAnalysis = oldAnalysis;
				m_wf = oldAnalysis.Wordform;
				m_wa = wa;
				m_wg = gloss;
				m_sda = m_caches.DataAccess;
				m_sdaMain = m_caches.MainCache.MainCacheAccessor;
				m_cmorphs = m_sda.get_VecSize(m_hvoSbWord, ktagSbWordMorphs);
				m_choices = choices;
				m_tssForm = tssForm;
				m_fWantOnlyWfiAnalysis = fWantOnlyWfiAnalysis;
			}
コード例 #28
0
		public override bool Matches(ITsString arg)
		{
			string text = arg.Text;
			if (String.IsNullOrEmpty(text))
				return false;
			DateTime time;
			GenDate gen;
			if (!HandleGenDate && DateTime.TryParse(text, out time))
			{
				switch (m_type)
				{
					case DateMatchType.After:
						return time >= m_start;
					case DateMatchType.Before:
						return time <= m_end;
					case DateMatchType.Range:
					case DateMatchType.On:
						return time >= m_start && time <= m_end;
					case DateMatchType.NotRange:
						return time < m_start || time > m_end;
				}
			}
			else if (HandleGenDate && GenDate.TryParse(text, out gen))
			{
				switch (m_type)
				{
					case DateMatchType.After:
						return GenDateIsAfterDate(gen, m_start, IsStartAD);
					case DateMatchType.Before:
						return GenDateIsBeforeDate(gen, m_end, IsEndAD);
					case DateMatchType.Range:
					case DateMatchType.On:
						return GenDateIsInRange(gen);
					case DateMatchType.NotRange:
						return !GenDateIsInRange(gen);
				}
			}
			return false;
		}
コード例 #29
0
ファイル: FdoTestHelper.cs プロジェクト: bbriggs/FieldWorks
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates analyses for the words and punctuation forms of the specified segment. Words
		/// will have WfiWordforms created if they don't already exist.
		/// </summary>
		/// <param name="segment">The segment.</param>
		/// <param name="paraContents">The para contents.</param>
		/// <param name="ichBeginOffset">The beginning character offset.</param>
		/// <param name="ichLimOffset">The character offset limit.</param>
		/// <param name="fCreateGlosses">if set to <c>true</c> create glosses in addition to the
		/// WfiWordforms for each surface form.</param>
		/// ------------------------------------------------------------------------------------
		public static void CreateAnalyses(ISegment segment, ITsString paraContents,
			int ichBeginOffset, int ichLimOffset, bool fCreateGlosses)
		{
			FdoCache cache = segment.Cache;
			IFdoServiceLocator servloc = cache.ServiceLocator;
			if (SegmentBreaker.HasLabelText(paraContents, ichBeginOffset, ichLimOffset))
			{
				IPunctuationForm labelPunc = servloc.GetInstance<IPunctuationFormFactory>().Create();
				segment.AnalysesRS.Add(labelPunc);
				labelPunc.Form = paraContents.GetSubstring(ichBeginOffset, ichLimOffset);
			}
			else
			{
				ParseSegBaseline(segment, ichBeginOffset, ichLimOffset, (iForm, word, iAnalysis) =>
					{
						CreateAnalysisForWord(word, segment, cache.DefaultAnalWs, fCreateGlosses);
						return true;
					},
					(sPunc, iAnalysis) => CreatePuncForm(segment, cache.TsStrFactory.MakeString(sPunc, cache.DefaultVernWs)),
					(ichOrc, iAnalysis) => CreatePuncForm(segment, paraContents.Substring(segment.BeginOffset + ichOrc, 1)));
			}
		}
コード例 #30
0
ファイル: TextExtensions.cs プロジェクト: regnrand/liblcm
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Replaces the specified portion of the original string with the new string.
        /// </summary>
        /// <param name="tss">The original string.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="length">The length.</param>
        /// <param name="tssReplace">The new string.</param>
        /// <returns>The new string with the requested replacements made</returns>
        /// ------------------------------------------------------------------------------------
        public static ITsString Replace(this ITsString tss, int startIndex, int length, ITsString tssReplace)
        {
            int cch = tss.Length;

            Debug.Assert(startIndex >= 0 && startIndex + length <= cch);
            ITsStrBldr bldr = tss.GetBldr();

            bldr.ReplaceTsString(startIndex, startIndex + length, tssReplace);
            return(bldr.GetString());
        }
コード例 #31
0
ファイル: ParaBox.cs プロジェクト: vkarthim/FieldWorks
        public void StringChanged(int clientRunIndex, ITsString newValue)
        {
            var oldRun = (TssClientRun)Source.ClientRuns[clientRunIndex];

            Relayout(Source.ClientRunChanged(clientRunIndex, oldRun.CopyWithNewContents(newValue)));
        }
コード例 #32
0
 public void GetFirstParaString(out ITsString _ptss, string bstrSep, out bool _fGotItAll)
 {
     throw new NotImplementedException();
 }
コード例 #33
0
 public void ReplaceWithTsString(ITsString _tss)
 {
     throw new NotImplementedException();
 }
コード例 #34
0
ファイル: TsStringHelper.cs プロジェクト: vkarthim/liblcm
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Compares two TsStrings
 /// </summary>
 /// <param name="tssExpected">expected</param>
 /// <param name="tssActual">actual</param>
 /// <param name="sHowDifferent">Human(geek)-readable string telling how the TsStrings are different, or null if they are the same</param>
 /// <returns>True if TsStrings match, false otherwise</returns>
 /// ------------------------------------------------------------------------------------
 public static bool TsStringsAreEqual(ITsString tssExpected, ITsString tssActual, out string sHowDifferent)
 {
     return(TsStringsAreEqual(tssExpected, tssActual, new Dictionary <int, int>(), out sHowDifferent));
 }
コード例 #35
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Set the text in the "Name of List" text box for a particular ws.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 protected void SetListName(ITsString listName, int ws)
 {
     m_lmscListName.SetValue(ws, listName);
 }
コード例 #36
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Check the given text props to see if they specify the given style
 /// </summary>
 /// <param name="tss">The string containing the run.</param>
 /// <param name="iRun">The run from the string.</param>
 /// <param name="sStyle">Style</param>
 /// <returns>
 /// true if the given text at the specified run uses the given named style
 /// </returns>
 /// ------------------------------------------------------------------------------------
 public static bool IsStyle(this ITsString tss, int iRun, string sStyle)
 {
     return(tss.Style(iRun) == sStyle);
 }
コード例 #37
0
ファイル: PatternVcBase.cs プロジェクト: vkarthim/FieldWorks
        public override ITsString DisplayVariant(IVwEnv vwenv, int tag, int frag)
        {
            // we use display variant to display literal strings that are editable
            ITsString tss = null;

            switch (frag)
            {
            case kfragEmpty:
                tss = m_empty;
                break;

            case kfragLeftBracketUpHook:
                tss = m_leftBracketUpHook;
                break;

            case kfragLeftBracketExt:
                tss = m_leftBracketExt;
                break;

            case kfragLeftBracketLowHook:
                tss = m_leftBracketLowHook;
                break;

            case kfragRightBracketUpHook:
                tss = m_rightBracketUpHook;
                break;

            case kfragRightBracketExt:
                tss = m_rightBracketExt;
                break;

            case kfragRightBracketLowHook:
                tss = m_rightBracketLowHook;
                break;

            case kfragLeftBracket:
                tss = m_leftBracket;
                break;

            case kfragRightBracket:
                tss = m_rightBracket;
                break;

            case kfragLeftParenUpHook:
                tss = m_leftParenUpHook;
                break;

            case kfragLeftParenExt:
                tss = m_leftParenExt;
                break;

            case kfragLeftParenLowHook:
                tss = m_leftParenLowHook;
                break;

            case kfragRightParenUpHook:
                tss = m_rightParenUpHook;
                break;

            case kfragRightParenExt:
                tss = m_rightParenExt;
                break;

            case kfragRightParenLowHook:
                tss = m_rightParenLowHook;
                break;

            case kfragLeftParen:
                tss = m_leftParen;
                break;

            case kfragRightParen:
                tss = m_rightParen;
                break;

            case kfragQuestions:
                tss = m_questions;
                break;

            case kfragZeroWidthSpace:
                tss = m_zwSpace;
                break;
            }
            return(tss);
        }
コード例 #38
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Given a TS string and an index, find the closest start of a word before that
        /// position (or after that position if at a word boundary already or in the last word
        /// of the string. If in a run marked using one of the special styles, always returns
        /// the position at the end of that run. Runs having these special styles are also
        /// always regarded as word boundaries.
        /// </summary>
        /// <param name="tss">the structured string of the paragraph or translation</param>
        /// <param name="ich">the given index</param>
        /// <param name="specialStyles">The special styles.</param>
        /// <returns>adjusted character index</returns>
        /// ------------------------------------------------------------------------------------
        public static int FindWordBoundary(this ITsString tss, int ich, params string[] specialStyles)
        {
            if (ich < 0 || ich > tss.Length)
            {
                throw new ArgumentOutOfRangeException("ich");
            }

            if (ich == 0 || ich == tss.Length)
            {
                return(ich);
            }

            string text          = tss.Text;
            string startingStyle = tss.StyleAt(ich);
            string prevStyle     = ich > 0 ? tss.StyleAt(ich - 1) : startingStyle;

            if (!specialStyles.Contains(startingStyle) || prevStyle == null)
            {
                startingStyle = null;
            }
            else if (startingStyle != null)
            {
                startingStyle = prevStyle;
            }

            // Advance to the next word boundary if appropriate)
            while (ich < text.Length)
            {
                // if the current character is space...
                if (Character.IsSeparator(text[ich]))
                {
                    ich++;
                }
                else if (Character.IsPunct(text[ich]) && ich > 0 && !Character.IsSeparator(text[ich - 1]))
                {
                    // if word-final punctuation advance
                    ich++;
                }
                else if (startingStyle != null && tss.StyleAt(ich) == startingStyle)
                {
                    ich++;
                }
                else
                {
                    break;
                }
            }

            // NEVER move backward if at the end of the paragraph.
            if (ich < text.Length)
            {
                // While the insertion point is in the middle of a word then back up to the
                // start of the word or the start of a paragraph.
                while (ich > 0 && !Character.IsSeparator(text[ich - 1]) && !specialStyles.Contains(tss.StyleAt(ich - 1)))
                {
                    ich--;
                }
            }

            return(ich);
        }
コード例 #39
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Breaks a TsString into words where a word is defined as separated by whitespace or
 /// by run breaks, whichever is shorter.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public static IEnumerable <TsRunPart> Words(this ITsString tss)
 {
     return(tss.Runs().SelectMany(run => run.Words()));
 }
コード例 #40
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Extract the specified substring from the ITsString, from ichMin on.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public static ITsString Substring(this ITsString tss, int ichMin)
 {
     return(tss == null ? null : tss.GetSubstring(ichMin, tss.Length));
 }
コード例 #41
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Extract the specified substring from the ITsString. (Returns null if input is null.)
 /// If length is too large, return all of the string from ichMin on.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public static ITsString Substring(this ITsString tss, int ichMin, int length1)
 {
     return(tss == null ? null : tss.GetSubstring(ichMin, ichMin + length1));
 }
コード例 #42
0
        private static void AddGloss(TsIncStrBldr sb, IMultiStringAccessor gloss, IWritingSystem wsGloss)
        {
            ITsString tssGloss = GetTssGloss(gloss, wsGloss);

            sb.AppendTsString(tssGloss);
        }
コード例 #43
0
        /// <summary>
        /// Given the GUI control or view ah, find and highlight the text indicated
        /// via the location (level) path.
        /// </summary>
        /// <param name="lpath">Level path array.</param>
        /// <param name="ah">Accessibility helper from the GUI control or view</param>
        /// <returns>true if the selected string was retrieved.</returns>
        private bool selectText(GuiPath lpath, AccessibilityHelper ah)
        {
            IVwRootBox rbox = ah.RootBox();

            isNotNull(rbox, "view rootbox not found");

            IVwSelection sel = null;             // returned selection

            // create a SelLevInfo[] array to the content using the model view levels.
            int clevels = 0;

            SelLevInfo[] rgvsli;
            if (DrillToContent(lpath, out rgvsli, out clevels))
            {
                int          ihvoRoot      = 0;            // first rootbox
                int          tagTextProp   = 16002;        // kflidStTxtPara_Contents
                int          cpropPrevious = 0;
                int          ichAnchor     = m_at;         // starting character number
                int          ichEnd        = m_at + m_run; // ending character number in rgvsli[0].ihvo or ihvoEnd if it is not -1
                int          ws            = 0;
                bool         fAssocPrev    = false;
                int          ihvoEnd       = -1;   // paragraph # to end at, if it doesn't exist, get unspecified interop error
                ITsTextProps ttpIns        = null;
                bool         fInstall      = true; // make it the view's default selection

                //int iHeight = rbox.get_Height();
                int iHeight = rbox.Height;

                sel = rbox.MakeTextSelection
                          (ihvoRoot, clevels, rgvsli, tagTextProp, cpropPrevious, ichAnchor, ichEnd,
                          ws, fAssocPrev, ihvoEnd, ttpIns, fInstall);
                isNotNull(sel, "failed to select text");
                //areEqual(true, sel.get_IsValid(), "selection is not valid");
                areEqual(true, sel.IsValid, "selection is not valid");
                ITsTextProps ttp = spyOnSelection(sel);
                if (ttp != null)
                {
                    spyOnTextProps(ttp);
                }
            }
            string    strSeparator = "|";
            ITsString tssFromApp;

            sel.GetSelectionString(out tssFromApp, strSeparator);
            ITsStreamWrapper tsw = TsStreamWrapperClass.Create();

            //UCOMIStream strm = tsw.get_Stream();
            System.Runtime.InteropServices.ComTypes.IStream strm = tsw.Stream;
            // Copy the string to our address space.
            ITsStrBldr bldr = TsStrBldrClass.Create();

            bldr.ReplaceTsString(0, 0, tssFromApp);
            ITsString tss           = bldr.GetString();
            int       icchIndent    = 2;
            int       iws           = 0;
            bool      fWriteObjData = true;
            //tsw.WriteTssAsXml(tss2, icchIndent, iws, fWriteObjData);
            //ISilDataAccess da = rbox.get_DataAccess();
            ISilDataAccess da = rbox.DataAccess;
            //ILgWritingSystemFactory wsf = da.get_WritingSystemFactory();
            ILgWritingSystemFactory wsf = da.WritingSystemFactory;

            tss.WriteAsXml(strm, wsf, icchIndent, iws, fWriteObjData);
            //m_text = tsw.get_Contents(); // XML formatted string
            m_text = tsw.Contents;             // XML formatted string
            return(m_text != null);
        }
コード例 #44
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Get the named style from the specified run of the given TS String.
 /// </summary>
 /// <param name="tss">The string</param>
 /// <param name="iRun">The run index.</param>
 /// <returns>the named style or <c>null</c> if the run doesn't have a style</returns>
 /// ------------------------------------------------------------------------------------
 public static string Style(this ITsString tss, int iRun)
 {
     return(tss.get_StringProperty(iRun, (int)FwTextPropType.ktptNamedStyle));
 }
コード例 #45
0
        /// <summary>
        /// Called when the IBus UpdatePreeditText event is raised to update the composition.
        /// </summary>
        /// <param name="obj">New composition string that will replace the existing
        /// composition (sub-)string.</param>
        /// <param name="cursorPos">0-based position where the cursor should be put after
        /// updating the composition (pre-edit window). This position is relative to the
        /// composition/preedit text.</param>
        public void OnUpdatePreeditText(object obj, int cursorPos)
        {
            if (AssociatedSimpleRootSite.InvokeRequired)
            {
                AssociatedSimpleRootSite.InvokeAsync(() => OnUpdatePreeditText(obj, cursorPos));
                return;
            }

            var selHelper = SetupForTypingEventHandler(true, false);

            if (selHelper == null)
            {
                return;
            }

            if (m_InitialSelection == null)
            {
                // Create a new, independent selection helper for m_InitialSelHelper - we want
                // to remember the current selection
                m_InitialSelection = new SelectionWrapper(AssociatedSimpleRootSite);
                OnPreeditOpened();
            }

            var ibusText        = obj as IBusText;
            var compositionText = ibusText.Text;

            CheckAttributesForCommittingKeyboard(ibusText);

            // Make the correct selection
            if (m_EndOfPreedit != null)
            {
                selHelper = m_EndOfPreedit;
            }

            var selectionProps = GetSelectionProps(selHelper);

            // Replace any previous pre-edit text.
            if (m_InitialSelection.SelectionHelper.Selection.EndBeforeAnchor)
            {
                // If we have a backwards selection we insert the pre-edit before the selected
                // text. selHelper points to the originally selected text (which got moved because
                // we inserted the pre-edit before it). The top of m_InitialSelection is the
                // start of the pre-edit, the top of selHelper is the position before the
                // originally selected text
                Debug.Assert(m_InitialSelection.SelectionHelper.IsRange);
                selHelper.IchEnd    = selHelper.GetIch(SelectionHelper.SelLimitType.End);
                selHelper.IchAnchor = m_InitialSelection.SelectionHelper.GetIch(SelectionHelper.SelLimitType.Top);
            }
            else
            {
                // selHelper points to the position after inserting the previous pre-edit text,
                // so it will be the end of our range selection. The bottom of m_InitialSelection
                // is the position at the end of the initial range selection, so it will be part
                // of the anchor.
                selHelper.IchEnd    = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom);
                selHelper.IchAnchor = m_InitialSelection.SelectionHelper.GetIch(SelectionHelper.SelLimitType.Bottom);
            }
            selHelper.SetSelection(true);

            // Update the pre-edit text
            ITsString str = CreateTsStringUsingSelectionProps(compositionText, selectionProps, true);

            selHelper.Selection.ReplaceWithTsString(str);

            m_EndOfPreedit = new SelectionHelper(
                AssociatedSimpleRootSite.EditingHelper.CurrentSelection);

            if (m_InitialSelection.SelectionHelper.IsRange)
            {
                // keep the range selection
                if (m_InitialSelection.SelectionHelper.Selection.EndBeforeAnchor)
                {
                    // we inserted before the original selection but we want to keep the original
                    // text selected, so we have to adjust
                    selHelper            = new SelectionHelper(m_InitialSelection.SelectionHelper);
                    selHelper.IchAnchor += str.Length;
                    selHelper.IchEnd    += str.Length;
                }
                else
                {
                    selHelper = m_InitialSelection.SelectionHelper;
                }
            }
            else
            {
                // Set the IP to the position IBus told us. This is tricky because compositionText
                // might be in NFC but we have converted it to NFD, so the position needs to
                // change. To simplify this we expect for now that IBus sets the cursor always
                // either at the start or the end of the composition string.
                selHelper           = new SelectionHelper(AssociatedSimpleRootSite.EditingHelper.CurrentSelection);
                selHelper.IchAnchor = m_InitialSelection.SelectionHelper.GetIch(SelectionHelper.SelLimitType.Bottom);
                if (compositionText.Length == cursorPos)
                {
                    selHelper.IchAnchor += str.Length;
                }
                else
                {
                    Debug.Assert(cursorPos == 0,
                                 "IBus told us a cursor position that changed because of nfc->nfd normalization");
                    selHelper.IchAnchor += cursorPos;
                }
                selHelper.IchEnd = selHelper.IchAnchor;
            }

            // make the selection visible
            selHelper.SetSelection(true);
        }
コード例 #46
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Get the named style from the specified character position of the given TS String. If
 /// the position is right between two runs, this gets the style of the following run.
 /// </summary>
 /// <param name="tss">The string</param>
 /// <param name="ich">The character index.</param>
 /// <returns>the named style or <c>null</c> if the run at ich doesn't have a style</returns>
 /// ------------------------------------------------------------------------------------
 public static string StyleAt(this ITsString tss, int ich)
 {
     return(tss.get_StringPropertyAt(ich, (int)FwTextPropType.ktptNamedStyle));
 }
コード例 #47
0
ファイル: TsStringHelper.cs プロジェクト: vkarthim/liblcm
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Compares two TsStrings
        /// </summary>
        /// <param name="tssExpected">expected</param>
        /// <param name="tssActual">actual</param>
        /// <param name="propsWithWiggleRoom">dictionary of format properties that needn't be exact, along with their acceptable errors</param>
        /// <param name="sHowDifferent">Human(geek)-readable string telling how the TsStrings are different, or null if they are the same</param>
        /// <returns>True if TsStrings match, false otherwise</returns>
        /// ------------------------------------------------------------------------------------
        public static bool TsStringsAreEqual(ITsString tssExpected, ITsString tssActual, IDictionary <int, int> propsWithWiggleRoom,
                                             out string sHowDifferent)
        {
            sHowDifferent = null;

            // Deal with cases where one or both of the passed values is null
            if (tssExpected == null)
            {
                if (tssActual != null)
                {
                    sHowDifferent = string.Format("TsStrings differ.{0}\tExpected <null>, but was <{1}>.",
                                                  Environment.NewLine, tssActual.Text);
                    return(false);
                }
                return(true);
            }
            if (tssActual == null)
            {
                sHowDifferent = string.Format("TsStrings differ.{0}\tExpected <{1}>, but was <null>.",
                                              Environment.NewLine, tssExpected.Text);
                return(false);
            }

            // If the lengths differ then the TS Strings are different
            if (tssExpected.Length != tssActual.Length)
            {
                sHowDifferent = string.Format("TsString lengths differ.{0}\tExpected <{1}>, but was <{2}>.",
                                              Environment.NewLine, tssExpected.Text, tssActual.Text);
                return(false);
            }

            if (tssExpected.Text != tssActual.Text)
            {
                sHowDifferent = string.Format("TsString text differs.{0}\tExpected <{1}>, but was <{2}>.",
                                              Environment.NewLine, tssExpected.Text, tssActual.Text);
                return(false);
            }

            var bldr   = new StringBuilder();
            int cRuns1 = tssExpected.RunCount;
            int cRuns2 = tssActual.RunCount;

            if (cRuns1 != cRuns2)
            {
                bldr.AppendFormat("TsStrings have different number of runs.{0}\tExpected {1} runs, but was {2} runs.",
                                  Environment.NewLine, cRuns1, cRuns2);
                for (int iRun = 0; iRun < cRuns1 || iRun < cRuns2; iRun++)
                {
                    bldr.AppendFormat("{0}\tExpected run {1}:<", Environment.NewLine, iRun + 1);
                    if (iRun < cRuns1)
                    {
                        bldr.Append(tssExpected.get_RunText(iRun));
                    }
                    bldr.Append(">, but was:<");
                    if (iRun < cRuns2)
                    {
                        bldr.Append(tssActual.get_RunText(iRun));
                    }
                    bldr.Append(">");
                }
                sHowDifferent = bldr.ToString();
                return(false);
            }

            for (int iRun = 0; iRun < cRuns1; iRun++)
            {
                string sRun1 = tssExpected.get_RunText(iRun);
                string sRun2 = tssActual.get_RunText(iRun);
                if (sRun1 != null && sRun1.Length != sRun2.Length)
                {
                    sHowDifferent = string.Format("TsStrings differ in length of run {1}.{0}" +
                                                  "\tExpected length={2}, but was length={3}.{0}" +
                                                  "\texpected run:<{4}>{0}" +
                                                  "\t     but was:<{5}>", Environment.NewLine, iRun + 1, sRun1.Length, sRun2.Length,
                                                  sRun1, sRun2);
                    return(false);
                }

                string sDetails;
                if (!TsTextPropsHelper.PropsAreEqual(tssExpected.get_Properties(iRun), tssActual.get_Properties(iRun), propsWithWiggleRoom, out sDetails))
                {
                    sHowDifferent = string.Format("TsStrings differ in format of run {1}.{0}\t{2}",
                                                  Environment.NewLine, iRun + 1, sDetails);
                    return(false);
                }
            }

            // if we reach this point, no differences were found
            return(true);
        }
コード例 #48
0
 /// <summary>
 /// Gets the string property value.
 /// </summary>
 public static string get_StringProperty(this ITsString tss, int iRun, int tpt)
 {
     return(tss.get_Properties(iRun).GetStrPropValue(tpt));
 }
コード例 #49
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Set the text in the "Description" text box for a particular ws.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 protected void SetDescription(ITsString description, int ws)
 {
     m_lmscDescription.SetValue(ws, description);
 }
コード例 #50
0
 /// <summary>
 /// Gets the string property value at the specified character offset.
 /// </summary>
 public static string get_StringPropertyAt(this ITsString tss, int ich, int tpt)
 {
     return(tss.get_StringProperty(tss.get_RunAt(ich), tpt));
 }
コード例 #51
0
        /// <summary>
        /// Helper method to edit a TsString in the dummy cache at a given position.
        /// </summary>
        /// <param name="hvoIndex"></param>
        /// <param name="index"></param>
        /// <param name="tss"></param>
        public void EditRevIndexEntryInCache(int hvoIndex, int index, int ws, ITsString tss)
        {
            int hvoEntry = m_sdaRev.get_VecItem(hvoIndex, kFlidEntries, index);

            m_sdaRev.SetMultiStringAlt(hvoEntry, ReversalIndexEntryTags.kflidReversalForm, ws, tss);
        }
コード例 #52
0
        /// <summary>
        /// Gets the writing system.
        /// </summary>
        public static int get_WritingSystem(this ITsString tss, int irun)
        {
            int var;

            return(tss.get_Properties(irun).GetIntPropValues((int)FwTextPropType.ktptWs, out var));
        }
コード例 #53
0
 public void GetSelectionString(out ITsString _ptss, string bstrSep)
 {
     throw new NotImplementedException();
 }
コード例 #54
0
 /// <summary>
 /// Gets the writing system at the specified character offset.
 /// </summary>
 public static int get_WritingSystemAt(this ITsString tss, int ich)
 {
     return(tss.get_WritingSystem(tss.get_RunAt(ich)));
 }
コード例 #55
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="wp"></param>
 /// <param name="mediator"></param>
 /// <param name="propertyTable"></param>
 /// <param name="tssform">establishes the ws of the dialog.</param>
 public void SetDlgInfo(LcmCache cache, WindowParams wp, Mediator mediator, XCore.PropertyTable propertyTable, ITsString tssform)
 {
     CheckDisposed();
     SetDlgInfo(cache, wp, mediator, propertyTable, tssform.Text, TsStringUtils.GetWsAtOffset(tssform, 0));
 }
コード例 #56
0
 /// <summary>
 /// Determines if the specified run is an ORC character.
 /// </summary>
 public static bool get_IsRunOrc(this ITsString tss, int iRun)
 {
     return(tss.get_RunText(iRun) == "\ufffc");
 }
コード例 #57
0
        /// <summary>
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="sPrefixMarker"></param>
        /// <param name="tssMorphForm"></param>
        /// <param name="sPostfixMarker"></param>
        /// <returns></returns>
        public static IEnumerable <TMoForm> GetMatchingMorphs <TMoForm, TMoFormRepository>(FdoCache cache,
                                                                                           string sPrefixMarker, ITsString tssMorphForm, string sPostfixMarker)
            where TMoForm : IMoForm
            where TMoFormRepository : IRepository <TMoForm>
        {
            var allMorphs =
                cache.ServiceLocator.GetInstance <TMoFormRepository>().AllInstances();
            // If the morph is either a proclitic or an enclitic, then it can stand alone; it does not have to have any
            // prefix or postfix even when such is defined for proclitic and/or enclitc.  So we augment the query to allow
            // these two types to be found without the appropriate prefix or postfix.  See LT-8124.
            // Restrict by Morph Type as well as Morph Form.
            int wsForm = TsStringUtils.GetWsAtOffset(tssMorphForm, 0);

            return(from mf in allMorphs
                   where mf.Owner != null && mf.Owner.IsValidObject /* check for orphans See UndoAllIssueTest */ &&
                   // computing OwningFlid is relatively slow, especially twice times 46000...
                   //(mf.OwningFlid == LexEntryTags.kflidAlternateForms ||
                   // mf.OwningFlid == LexEntryTags.kflidLexemeForm) &&
                   mf.Owner.ClassID == LexEntryTags.kClassId &&
                   tssMorphForm.Equals(mf.Form.get_String(wsForm)) &&
                   mf.MorphTypeRA != null &&
                   (mf.MorphTypeRA.Prefix == sPrefixMarker ||
                    sPrefixMarker == "" && (mf.MorphTypeRA.Prefix == null ||
                                            mf.MorphTypeRA.Guid == MoMorphTypeTags.kguidMorphEnclitic ||
                                            mf.MorphTypeRA.Guid == MoMorphTypeTags.kguidMorphProclitic)) &&
                   (mf.MorphTypeRA.Postfix == sPostfixMarker ||
                    sPostfixMarker == "" && (mf.MorphTypeRA.Postfix == null ||
                                             mf.MorphTypeRA.Guid == MoMorphTypeTags.kguidMorphEnclitic ||
                                             mf.MorphTypeRA.Guid == MoMorphTypeTags.kguidMorphProclitic))
                   select mf);
        }
コード例 #58
0
        protected override void Dispose(bool disposing)
        {
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
            }

            m_rule = null;

            if (m_inputCtxtProps != null)
            {
                Marshal.ReleaseComObject(m_inputCtxtProps);
                m_inputCtxtProps = null;
            }
            if (m_resultCtxtProps != null)
            {
                Marshal.ReleaseComObject(m_resultCtxtProps);
                m_resultCtxtProps = null;
            }
            if (m_colHeaderProps != null)
            {
                Marshal.ReleaseComObject(m_colHeaderProps);
                m_colHeaderProps = null;
            }
            if (m_rowHeaderProps != null)
            {
                Marshal.ReleaseComObject(m_rowHeaderProps);
                m_rowHeaderProps = null;
            }
            if (m_inputStr != null)
            {
                Marshal.ReleaseComObject(m_inputStr);
                m_inputStr = null;
            }
            if (m_resultStr != null)
            {
                Marshal.ReleaseComObject(m_resultStr);
                m_resultStr = null;
            }
            if (m_leftEnvStr != null)
            {
                Marshal.ReleaseComObject(m_leftEnvStr);
                m_leftEnvStr = null;
            }
            if (m_rightEnvStr != null)
            {
                Marshal.ReleaseComObject(m_rightEnvStr);
                m_rightEnvStr = null;
            }
            if (m_switchStr != null)
            {
                Marshal.ReleaseComObject(m_switchStr);
                m_switchStr = null;
            }

            base.Dispose(disposing);
        }
コード例 #59
0
ファイル: FwTextBoxColumn.cs プロジェクト: bbriggs/FieldWorks
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes the text box control.
		/// </summary>
		/// <param name="fwTxtBox">The FwTextBox control to initialize. When this is null, then
		/// the column's internal FwTextBox (i.e. m_textBoxControl) is initialized.</param>
		/// <param name="tss">The TsString fwTxtBox is initialized to.</param>
		/// <param name="rowIndex">Row whose writing system is used (and whose default value
		/// is used when necessary).</param>
		/// ------------------------------------------------------------------------------------
		public void InitializeTextBoxControl(FwTextBox fwTxtBox, ITsString tss, int rowIndex)
		{
			if (rowIndex < 0 || (TextBoxControl == null && fwTxtBox == null))
				return;

			if (fwTxtBox == null)
				fwTxtBox = m_textBoxControl;

			if (m_cache != null)
				fwTxtBox.WritingSystemFactory =	m_cache.WritingSystemFactory;

			fwTxtBox.Size = new Size(Width, DataGridView.Rows[rowIndex].Height);
			fwTxtBox.StyleSheet = m_styleSheet;
			fwTxtBox.WritingSystemCode = GetWritingSystemHandle(rowIndex);
			fwTxtBox.Tss = tss ?? GetDefaultNewRowValue(rowIndex);
		}
コード例 #60
0
 /// <summary>
 /// Looks through all morphs to find a match. Use the generic interface GetMatchingMorphs(TMoForm, TMoFormRepository)
 /// for better performance.
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="sPrefixMarker"></param>
 /// <param name="tssMorphForm"></param>
 /// <param name="sPostfixMarker"></param>
 /// <returns></returns>
 public static IEnumerable <IMoForm> GetMatchingMorphs(FdoCache cache,
                                                       string sPrefixMarker, ITsString tssMorphForm, string sPostfixMarker)
 {
     return(GetMatchingMorphs <IMoForm, IMoFormRepository>(cache, sPrefixMarker, tssMorphForm, sPostfixMarker));
 }