コード例 #1
0
ファイル: RespellerDlg.cs プロジェクト: sillsdev/WorldPad
		/// <summary>
		/// Scan the texts for pictures with captions.
		/// </summary>
		/// <param name="texts"></param>
		private void GetCaptionWfics(int[] texts, IWfiWordform wf)
		{
			int flidCaptions = DummyVirtualHandler.InstallDummyHandler(m_cache.VwCacheDaAccessor,
				"WfiWordform", "OccurrencesInCaptions",
				(int)CellarModuleDefns.kcptReferenceSequence).Tag;
			List<int> occurrencesInCaptions = new List<int>();
			string wordform = wf.Form.VernacularDefaultWritingSystem;
			if (string.IsNullOrEmpty(wordform))
				return; // paranoia.
			Set<FwObjDataTypes> desiredType = new Set<FwObjDataTypes>(1);
			desiredType.Add(FwObjDataTypes.kodtGuidMoveableObjDisp);
			int hvoAnnType = CmAnnotationDefn.Twfic(m_cache).Hvo;
			IVwCacheDa cda = m_cache.VwCacheDaAccessor;
			foreach (int hvoText in texts)
			{
				int chvoPara = m_cache.GetVectorSize(hvoText, kflidParagraphs);
				for (int ipara = 0; ipara < chvoPara; ipara++)
				{
					int hvoPara = m_cache.GetVectorItem(hvoText, kflidParagraphs, ipara);
					ITsString tssContents = m_cache.GetTsStringProperty(hvoPara, kflidContents);
					int crun = tssContents.RunCount;
					for (int irun = 0; irun < crun; irun++)
					{
						// See if the run is a picture ORC
						TsRunInfo tri;
						FwObjDataTypes odt;
						ITsTextProps props;
						Guid guid = StringUtils.GetGuidFromRun(tssContents, irun, out odt, out tri, out props, desiredType);
						if (guid == Guid.Empty)
							continue;
						// See if its caption contains our wordform
						int hvoPicture = m_cache.GetIdFromGuid(guid);
						int clsid = m_cache.GetClassOfObject(hvoPicture);
						if (clsid != (int)CmPicture.kclsidCmPicture)
							continue; // bizarre, just for defensiveness.
						ITsString tssCaption = m_cache.GetMultiStringAlt(hvoPicture,
							(int)CmPicture.CmPictureTags.kflidCaption, m_cache.DefaultVernWs);
						WordMaker wordMaker = new WordMaker(tssCaption, m_cache.LanguageWritingSystemFactoryAccessor);
						for (; ; )
						{
							int ichMin;
							int ichLim;
							ITsString tssTxtWord = wordMaker.NextWord(out ichMin, out ichLim);
							if (tssTxtWord == null)
								break;
							if (tssTxtWord.Text != wordform)
								continue;
							int hvoAnn = CmBaseAnnotation.CreateDummyAnnotation(m_cache, hvoPicture,
								hvoAnnType, ichMin, ichLim, wf.Hvo);
							cda.CacheIntProp(hvoAnn, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidFlid,
								(int)CmPicture.CmPictureTags.kflidCaption);
							cda.CacheObjProp(hvoAnn, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidWritingSystem,
								m_cache.DefaultVernWs);
							occurrencesInCaptions.Add(hvoAnn);
						}
					}
				}
			}
			// Make the list the value of the occurrencesInCaptions property.
			cda.CacheVecProp(wf.Hvo, flidCaptions, occurrencesInCaptions.ToArray(), occurrencesInCaptions.Count);
		}
コード例 #2
0
ファイル: ITextUtils.cs プロジェクト: sillsdev/WorldPad
		/// <summary>
		/// Returns the first word in the given tssWordAnn and its lower case form.
		/// </summary>
		/// <param name="tssWordAnn"></param>
		/// <param name="cpe"></param>
		/// <param name="firstFormLowered"></param>
		/// <returns>null if we couldn't find a word in the given tssWordAnn</returns>
		static private ITsString FirstWord(ITsString tssWordAnn, ILgWritingSystemFactory wsf, out string firstFormLowered)
		{
			WordMaker wordScanner = new WordMaker(tssWordAnn, wsf);
			int ichMinFirstWord;
			int ichLimFirstWord;
			ITsString firstWord = wordScanner.NextWord(out ichMinFirstWord, out ichLimFirstWord);
			// Handle null values without crashing.  See LT-6309 for how this can happen.
			if (firstWord != null)
				firstFormLowered = wordScanner.ToLower(firstWord);
			else
				firstFormLowered = null;
			return firstWord;
		}