コード例 #1
0
 private void WriteUsageElement(IMultiUnicode styleUsage, XmlWriter writer)
 {
     foreach (var wsId in styleUsage.AvailableWritingSystemIds)
     {
         writer.WriteStartElement("usage");
         writer.WriteAttributeString("wsId", Cache.WritingSystemFactory.GetStrFromWs(wsId));
         writer.WriteString(styleUsage.get_String(wsId).Text);
         writer.WriteEndElement();                 // usage
     }
 }
コード例 #2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Adds the glosses in all available writing systems to the specified sense.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private void AddDbGlossesToSense(LexSense sense, IMultiUnicode glosses)
 {
     for (int i = 0; i < glosses.StringCount; i++)
     {
         int       ws;
         ITsString tssGloss  = glosses.GetStringFromIndex(i, out ws);
         string    icuLocale = m_cache.WritingSystemFactory.GetStrFromWs(ws);
         sense.Glosses.Add(new LexGloss(icuLocale, tssGloss.Text));
     }
 }
コード例 #3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Set string values for the given property for each writing system represented in the
 /// nodelist
 /// </summary>
 /// <param name="multiUnicodeproperty">A MultiUnicodeAccessor representing the property
 /// whose value is to be set</param>
 /// <param name="nodes">An XmlNodeList with the strings in one or more writing systems
 /// </param>
 /// ------------------------------------------------------------------------------------
 private void SetMultiUnicodeAlternatives(IMultiUnicode multiUnicodeproperty,
                                          XmlNodeList nodes)
 {
     foreach (XmlNode node in nodes)
     {
         int    ws          = GetWs(node.Attributes);
         string alternative = node.InnerText;
         if (ws > 0 && alternative != null && alternative != string.Empty)
         {
             multiUnicodeproperty.set_String(ws, m_strFactory.MakeString(alternative, ws));
         }
         // REVIEW: What should we do when the writing system is not defined in the database?
     }
 }
コード例 #4
0
ファイル: ReadWriteServices.cs プロジェクト: sillsdev/liblcm
        /// <summary>
        /// Common code for loading a MultiUnicodeAccessor.
        /// </summary>
        internal static void LoadMultiUnicodeAccessor(ICmObject obj, int flid, XElement reader,
                                                      ref IMultiUnicode multiUnicodeProperty, ILgWritingSystemFactory wsf)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            // Deal with MultiUnicode data type.
            multiUnicodeProperty = new MultiUnicodeAccessor(obj, flid);
            ((MultiAccessor)multiUnicodeProperty).LoadFromDataStoreInternal(reader, wsf);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="glossAffixAccessor">GlossPrepend or GlossAppend</param>
        /// <param name="wsGloss"></param>
        /// <param name="wsUser"></param>
        /// <returns></returns>
        public static ITsString AddTssGlossAffix(ITsIncStrBldr sb, IMultiUnicode glossAffixAccessor,
                                                 CoreWritingSystemDefinition wsGloss, CoreWritingSystemDefinition wsUser)
        {
            if (sb == null)
            {
                sb = TsStringUtils.MakeIncStrBldr();
            }
            int       wsActual1;
            ITsString tssGlossPrepend = glossAffixAccessor.GetAlternativeOrBestTss(wsGloss.Handle, out wsActual1);

            if (tssGlossPrepend != null && tssGlossPrepend.Length != 0)
            {
                bool isPrepend = (glossAffixAccessor.Flid == LexEntryInflTypeTags.kflidGlossPrepend);
                AppendGlossAffix(sb, tssGlossPrepend, isPrepend, kDefaultSeparatorLexEntryInflTypeGlossAffix, wsUser);
            }
            return(tssGlossPrepend);
        }
コード例 #6
0
 /// <summary>
 /// Read multilingual Unicode data from XML fragments like
 /// &lt;Name&gt;
 ///		&lt;AUni ws="en"&gt;FRAME and OCM Categories&lt;/AUni&gt;
 ///	&lt;/Name&gt;
 /// </summary>
 private void SetMultiUnicodeFromXml(XmlReader xrdr, IMultiUnicode mu)
 {
     if (xrdr.IsEmptyElement)
     {
         xrdr.Read();
         return;
     }
     if (xrdr.ReadToDescendant("AUni"))
     {
         do
         {
             string sWs  = xrdr.GetAttribute("ws");
             string sVal = xrdr.ReadString();
             int    ws   = m_wsf.GetWsFromStr(sWs);
             if (ws != 0)
             {
                 mu.set_String(ws, sVal);
             }
         } while (xrdr.ReadToNextSibling("AUni"));
     }
     xrdr.Read();                // read the end tag.
 }
コード例 #7
0
 private void SetMultiUnicodeFromXml(XmlReader xrdr, IMultiUnicode mu)
 {
     if (xrdr.IsEmptyElement)
     {
         xrdr.Read();
         return;
     }
     if (xrdr.ReadToDescendant("AUni"))
     {
         do
         {
             string sWs  = xrdr.GetAttribute("ws");
             string sVal = xrdr.ReadString();
             if (sWs == "en")
             {
                 continue;                                       // don't overwrite the English string
             }
             int ws = GetWsFromStr(sWs);
             mu.set_String(ws, sVal);
         } while (xrdr.ReadToNextSibling("AUni"));
     }
     xrdr.Read();                // read the end tag.
 }
コード例 #8
0
		void SetVernAlternative(IMultiUnicode mu, string content)
		{
			mu.VernacularDefaultWritingSystem = MakeVernTss(content);
		}
コード例 #9
0
ファイル: XmlList.cs プロジェクト: bbriggs/FieldWorks
		/// <summary>
		/// Read multilingual Unicode data from XML fragments like
		/// &lt;Name&gt;
		///		&lt;AUni ws="en"&gt;FRAME and OCM Categories&lt;/AUni&gt;
		///	&lt;/Name&gt;
		/// </summary>
		private void SetMultiUnicodeFromXml(XmlReader xrdr, IMultiUnicode mu)
		{
			if (xrdr.IsEmptyElement)
			{
				xrdr.Read();
				return;
			}
			if (xrdr.ReadToDescendant("AUni"))
			{
				do
				{
					string sWs = xrdr.GetAttribute("ws");
					string sVal = xrdr.ReadString();
					int ws = m_wsf.GetWsFromStr(sWs);
					if (ws != 0)
						mu.set_String(ws, sVal);
				} while (xrdr.ReadToNextSibling("AUni"));
			}
			xrdr.Read();	// read the end tag.
		}
コード例 #10
0
		private void SetMultiUnicodeFromXml(XmlReader xrdr, IMultiUnicode mu)
		{
			if (xrdr.IsEmptyElement)
			{
				xrdr.Read();
				return;
			}
			if (xrdr.ReadToDescendant("AUni"))
			{
				do
				{
					string sWs = xrdr.GetAttribute("ws");
					string sVal = xrdr.ReadString();
					if (sWs == "en")
						continue;		// don't overwrite the English string
					int ws = GetWsFromStr(sWs);
					mu.set_String(ws, sVal);
				} while (xrdr.ReadToNextSibling("AUni"));
			}
			xrdr.Read();	// read the end tag.
		}
コード例 #11
0
		void SetString(IMultiUnicode target, int ws, string text)
		{
			target.set_String(ws, Cache.TsStrFactory.MakeString(text, ws));
		}
コード例 #12
0
		private void AddAbbrAndNameInfo(IMultiUnicode abbr, IMultiUnicode name, IMultiUnicode reverseAbbr, IMultiUnicode reverseName)
		{
			int wsActual;
			ITsString tssAnal;

			if (name != null)
			{
				string sname, snameWS, sabbr, sabbrWS;
				tssAnal = name.GetAlternativeOrBestTss(m_cache.DefaultAnalWs, out wsActual);
				sname = tssAnal.Text;
				snameWS = m_cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(wsActual);

				cbFunction.Items.Add(sname);

				if (!m_htNameToAbbr.ContainsKey(sname))
				{
					if (abbr == null)
					{
						sabbr = sname;	// use both for the map key
						sabbrWS = snameWS;
					}
					else
					{
						tssAnal = abbr.GetAlternativeOrBestTss(m_cache.DefaultAnalWs, out wsActual);
						sabbr = tssAnal.Text;
						sabbrWS = m_cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(wsActual);
					}
					NameWSandAbbr nwsa = new NameWSandAbbr();
					nwsa.name = sname;
					nwsa.nameWS = snameWS;
					nwsa.abbr = sabbr;
					nwsa.abbrWS = sabbrWS;
					m_htNameToAbbr.Add(sname, nwsa);
				}
			}
			if (reverseName != null)
			{
				string srname, srnameWS, srabbr, srabbrWS;
				tssAnal = reverseName.GetAlternativeOrBestTss(m_cache.DefaultAnalWs, out wsActual);
				srname = tssAnal.Text;
				srnameWS = m_cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(wsActual);

				cbFunction.Items.Add(srname);

				if (!m_htNameToAbbr.ContainsKey(srname))
				{
					if (reverseAbbr == null)
					{
						srabbr = srname;	// use both for the map key
						srabbrWS = srnameWS;
					}
					else
					{
						tssAnal = reverseAbbr.GetAlternativeOrBestTss(m_cache.DefaultAnalWs, out wsActual);
						srabbr = tssAnal.Text;
						srabbrWS = m_cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(wsActual);
					}
					NameWSandAbbr nwsa = new NameWSandAbbr();
					nwsa.name = srname;
					nwsa.nameWS = srnameWS;
					nwsa.abbr = srabbr;
					nwsa.abbrWS = srabbrWS;
					m_htNameToAbbr.Add(srname, nwsa);
				}
			}
		}
コード例 #13
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds the glosses in all available writing systems to the specified sense.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void AddDbGlossesToSense(LexSense sense, IMultiUnicode glosses)
		{
			for (int i = 0; i < glosses.StringCount; i++)
			{
				int ws;
				ITsString tssGloss = glosses.GetStringFromIndex(i, out ws);
				string icuLocale = m_cache.WritingSystemFactory.GetStrFromWs(ws);
				sense.Glosses.Add(new LexGloss(icuLocale, tssGloss.Text));
			}
		}
コード例 #14
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Set string values for the given property for each writing system represented in the
		/// nodelist
		/// </summary>
		/// <param name="multiUnicodeproperty">A MultiUnicodeAccessor representing the property
		/// whose value is to be set</param>
		/// <param name="nodes">An XmlNodeList with the strings in one or more writing systems
		/// </param>
		/// ------------------------------------------------------------------------------------
		private void SetMultiUnicodeAlternatives(IMultiUnicode multiUnicodeproperty,
			XmlNodeList nodes)
		{
			foreach (XmlNode node in nodes)
			{
				int ws = GetWs(node.Attributes);
				string alternative = node.InnerText;
				if (ws > 0 && alternative != null && alternative != string.Empty)
					multiUnicodeproperty.set_String(ws, m_strFactory.MakeString(alternative, ws));
				// REVIEW: What should we do when the writing system is not defined in the database?
			}
		}
コード例 #15
0
 void SetVernAlternative(IMultiUnicode mu, string content)
 {
     mu.VernacularDefaultWritingSystem = MakeVernTss(content);
 }
コード例 #16
0
 void SetString(IMultiUnicode target, int ws, string text)
 {
     target.set_String(ws, Cache.TsStrFactory.MakeString(text, ws));
 }
コード例 #17
0
ファイル: LiftExporter.cs プロジェクト: bbriggs/FieldWorks
		private void WriteAllForms(TextWriter w, string wrappingElementName, string attrs,
			string elementName, IMultiUnicode multi)
		{
			if (multi == null || multi.StringCount == 0)
				return;
			if (!String.IsNullOrEmpty(wrappingElementName))
			{
				if (String.IsNullOrEmpty(attrs))
					w.WriteLine("<{0}>", wrappingElementName);
				else
					w.WriteLine("<{0} {1}>", wrappingElementName, attrs);
			}
			for (var i = 0; i < multi.StringCount; ++i)
			{
				int ws;
				var sForm = multi.GetStringFromIndex(i, out ws).Text;
				if (String.IsNullOrEmpty(sForm))
					continue;

				var sLang = m_cache.WritingSystemFactory.GetStrFromWs(ws);
				if (IsVoiceWritingSystem(ws))
				{
					// The alternative contains a file path. We need to adjust and export and copy the file.
					var internalPath = sForm;
					// usually this will be unchanged, but it is pathologically possible that the file name conflicts.
					sForm = ExportFile(internalPath,
						Path.Combine(FdoFileHelper.GetMediaDir(m_cache.LangProject.LinkedFilesRootDir), internalPath),
						"audio");
				}
				w.WriteLine("<{0} lang=\"{1}\"><text>{2}</text></{0}>", elementName,
					MakeSafeAndNormalizedAttribute(sLang),
					sForm != null ? MakeSafeAndNormalizedXml(sForm.Replace("\x2028", Environment.NewLine)) : string.Empty);
			}
			if (!String.IsNullOrEmpty(wrappingElementName))
				w.WriteLine("</{0}>", wrappingElementName);
		}
コード例 #18
0
ファイル: ExportDialog.cs プロジェクト: bbriggs/FieldWorks
 private void ExportMultiUnicode(TextWriter w, IMultiUnicode mu)
 {
     string sEnglish = mu.get_String(m_wsEn).Text;
     if (String.IsNullOrEmpty(sEnglish))
         return;
     string sField = m_cache.MetaDataCacheAccessor.GetFieldName(mu.Flid);
     w.WriteLine(String.Format("<{0}>", sField));
     w.WriteLine(String.Format("<AUni ws=\"en\">{0}</AUni>",
         XmlUtils.MakeSafeXml(sEnglish)));
     foreach (int ws in m_mapWsCode.Keys)
     {
         string sValue = mu.get_String(ws).Text;
         if (sValue == null)
             sValue = String.Empty;
         else
             sValue = Icu.Normalize(sValue, Icu.UNormalizationMode.UNORM_NFC);
         w.WriteLine(String.Format("<AUni ws=\"{0}\">{1}</AUni>",
             m_mapWsCode[ws], XmlUtils.MakeSafeXml(sValue)));
     }
     w.WriteLine(String.Format("</{0}>", sField));
 }