예제 #1
0
        protected byte[] CreateObjData(FwObjDataTypes objDataType, string data)
        {
            var sb = new StringBuilder();

            sb.Append((char)objDataType);
            sb.Append(data);
            return(Encoding.Unicode.GetBytes(sb.ToString()));
        }
예제 #2
0
        protected byte[] CreateObjData(FwObjDataTypes objDataType, byte[] bytes)
        {
            byte[] typeBytes = BitConverter.GetBytes((char)objDataType);
            var    value     = new byte[bytes.Length + typeBytes.Length];

            Buffer.BlockCopy(typeBytes, 0, value, 0, typeBytes.Length);
            Buffer.BlockCopy(bytes, 0, value, typeBytes.Length, bytes.Length);
            return(value);
        }
예제 #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets all embedded object guids.
		/// </summary>
		/// <param name="tss">The TS String.</param>
		/// <param name="desiredOrcType">Type of the desired ORC.</param>
		/// <returns>Enumeration of GUIDs for all ORC runs of the requested type</returns>
		/// ------------------------------------------------------------------------------------
		public static IEnumerable<Guid> GetAllEmbeddedObjectGuids(this ITsString tss, FwObjDataTypes desiredOrcType)
		{
			for (int iRun = 0; iRun < tss.RunCount; iRun++)
			{
				Guid guid = TsStringUtils.GetGuidFromRun(tss, iRun, desiredOrcType);
				if (guid != Guid.Empty)
					yield return guid;
			}
		}
예제 #4
0
            ///----------------------------------------------------------------------------------
            /// <summary>
            /// Asserts that the footnote is as expected
            /// </summary>
            ///----------------------------------------------------------------------------------
            public void FootnoteEqual(Guid expectedGuid, FwObjDataTypes expectedType, ITsString tss)
            {
                ITsTextProps props = GetProperties(tss, 0);

                Assert.AreEqual(1, props.StrPropCount);
                FwObjDataTypes type;
                Guid           guid = TsStringUtils.GetGuidFromProps(props, null, out type);

                Assert.AreEqual(expectedGuid, guid);
                Assert.AreEqual(expectedType, type);
            }
예제 #5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Insert (or replace) an ORC run in a string builder.
		/// </summary>
		/// <param name="guid">The GUID representing the embedded object</param>
		/// <param name="objDataType">The type of embedding</param>
		/// <param name="tsStrBldr">The TS string builder</param>
		/// <param name="ichMin">The position at which the object is to be inserted</param>
		/// <param name="ichLim">If replacing an existing ORC (or other text), this is the Lim
		/// position (otherwise, should be set equal to ichMin)</param>
		/// <param name="ws">The ID of the writing system to use for the inserted run, or 0
		/// to leave unspecified</param>
		/// ------------------------------------------------------------------------------------
		public static void InsertOrcIntoPara(Guid guid, FwObjDataTypes objDataType,
			ITsStrBldr tsStrBldr, int ichMin, int ichLim, int ws)
		{
			byte[] objData = MiscUtils.GetObjData(guid, (byte)objDataType);
			ITsPropsBldr propsBldr = TsPropsBldrClass.Create();
			propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData,
				objData, objData.Length);
			if (ws != 0)
				propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, ws);
			tsStrBldr.Replace(ichMin, ichLim, new string(kchObject, 1),
				propsBldr.GetTextProps());
		}
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Tests that a footnote marker ORC (Object Replacement Character) has been inserted
        /// as the iRunth run in the given TsString.
        /// </summary>
        /// <param name="tssPara">TsString to check</param>
        /// <param name="iRun">Zero-based index of run to check for the ORC</param>
        /// <param name="ws">Writing system that should be used for the ORC</param>
        /// <param name="fBT">Indicates whether this is checking a back translation.</param>
        /// ------------------------------------------------------------------------------------
        public static void VerifyFootnoteMarkerOrcRun(ITsString tssPara, int iRun, int ws,
                                                      bool fBT)
        {
            Debug.Assert(tssPara.RunCount > iRun, "Trying to access run #" + iRun +
                         " when there are only " + tssPara.RunCount + " run(s).");
            string sOrcRun = tssPara.get_RunText(iRun);

            Assert.AreEqual(1, sOrcRun.Length);
            Assert.AreEqual(StringUtils.kChObject, sOrcRun[0]);
            ITsTextProps ttpOrcRun = tssPara.get_Properties(iRun);
            int          nDummy;
            int          wsActual = ttpOrcRun.GetIntPropValues((int)FwTextPropType.ktptWs,
                                                               out nDummy);

            Assert.AreEqual(ws, wsActual, "Wrong writing system for footnote marker in text");
            string         objData = ttpOrcRun.GetStrPropValue((int)FwTextPropType.ktptObjData);
            FwObjDataTypes orcType = (fBT) ? FwObjDataTypes.kodtNameGuidHot :
                                     FwObjDataTypes.kodtOwnNameGuidHot;

            Assert.AreEqual((char)(int)orcType, objData[0]);
        }
예제 #7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds object link data to the specified string builder (to affect the next string added)
		/// </summary>
		/// <param name="strBldr">The string builder to be modified.</param>
		/// <param name="attr">The attribute to process.</param>
		/// <param name="type">The type of object data to be added to the text properties.</param>
		/// ------------------------------------------------------------------------------------
		private static void AddObjDataToBldr(ITsIncStrBldr strBldr, XAttribute attr, FwObjDataTypes type)
		{
			byte[] objData = TsStringUtils.GetObjData(new Guid(attr.Value), (byte)type);
			strBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData, objData, objData.Length);
		}
예제 #8
0
			///----------------------------------------------------------------------------------
			/// <summary>
			/// Asserts that the footnote is as expected
			/// </summary>
			///----------------------------------------------------------------------------------
			public void FootnoteEqual(Guid expectedGuid, FwObjDataTypes expectedType, ITsString tss)
			{
				ITsTextProps props = GetProperties(tss, 0);
				Assert.AreEqual(1, props.StrPropCount);
				FwObjDataTypes type;
				Guid guid = TsStringUtils.GetGuidFromProps(props, null, out type);
				Assert.AreEqual(expectedGuid, guid);
				Assert.AreEqual(expectedType, type);
			}
예제 #9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get a Guid from the given run in a structured text string.
		/// </summary>
		/// <param name="tss">given structured text string</param>
		/// <param name="iRun">given run</param>
		/// <param name="odt">object data type, 0 if no ORC guid located</param>
		/// <param name="tri">run information</param>
		/// <param name="ttp">text properties of the run (if incoming value is  null and the
		/// run is an object, this will be set to the run props)</param>
		/// <param name="desiredOrcTypes">The desired ORC types, or null to return any type of
		/// ORC</param>
		/// <returns>
		/// The GUID associated with the specified run of the tss, if any; otherwise Guid.Empty
		/// </returns>
		/// ------------------------------------------------------------------------------------
		private static Guid GetGuidFromRun(ITsString tss, int iRun, FwObjDataTypes[] desiredOrcTypes, out FwObjDataTypes odt, out TsRunInfo tri, ref ITsTextProps ttp)
		{
			tss.FetchRunInfo(iRun, out tri);
			if (tri.ichLim - tri.ichMin == 1 && tss.get_RunText(iRun)[0] == StringUtils.kChObject)
			{
				// determine if single-character run contains an ORC
				ttp = ttp ?? tss.get_Properties(iRun);
				return GetGuidFromProps(ttp, desiredOrcTypes, out odt);
			}
			odt = 0;
			return Guid.Empty;
		}
예제 #10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get a Guid from the given run in a structured text string.
		/// </summary>
		/// <param name="tss">given structured text string</param>
		/// <param name="iRun">given run</param>
		/// <param name="desiredOrcType">The desired ORC type</param>
		/// <returns>
		/// The GUID associated with the specified run of the tss, if any; otherwise Guid.Empty
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static Guid GetGuidFromRun(ITsString tss, int iRun, FwObjDataTypes desiredOrcType)
		{
			TsRunInfo tri;
			ITsTextProps ttp;
			FwObjDataTypes odt;
			return GetGuidFromRun(tss, iRun, out odt, out tri, out ttp, new FwObjDataTypes[] { desiredOrcType });
		}
예제 #11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get an owned Guid from the given run in a structured text string.
		/// </summary>
		/// <param name="tss">given structured text string</param>
		/// <param name="iRun">given run</param>
		/// <param name="odt">object data type, 0 if no owned guid located</param>
		/// <returns>
		/// The GUID associated with the specified run of the tss if it is for an owned object;
		/// otherwise Guid.Empty
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static Guid GetOwnedGuidFromRun(ITsString tss, int iRun, out FwObjDataTypes odt)
		{
			TsRunInfo tri;
			ITsTextProps ttp;

			return GetOwnedGuidFromRun(tss, iRun, out odt, out tri, out ttp);
		}
예제 #12
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get a Guid from the given run in a structured text string.
		/// </summary>
		/// <param name="tss">given structured text string</param>
		/// <param name="iRun">given run</param>
		/// <param name="odt">object data type, 0 if no ORC guid located</param>
		/// <param name="tri">run information</param>
		/// <param name="ttp">text properties of the run (if incoming value is  null and the
		/// run is an object, this will be set to the run props)</param>
		/// <param name="desiredOrcTypes">The desired ORC types, or null to return any type of
		/// ORC</param>
		/// <returns>
		/// The GUID associated with the specified run of the tss, if any; otherwise Guid.Empty
		/// </returns>
		/// ------------------------------------------------------------------------------------
		private static Guid GetGuidFromRun(ITsString tss, int iRun,
			Set<FwObjDataTypes> desiredOrcTypes, out FwObjDataTypes odt, out TsRunInfo tri,
			ref ITsTextProps ttp)
		{
			odt = 0;
			tss.FetchRunInfo(iRun, out tri);
			if (tri.ichLim - tri.ichMin == 1 &&
				tss.get_RunText(iRun)[0] == kchObject)
			{
				// determine if single-character run contains an ORC
				ttp = ttp ?? tss.get_Properties(iRun);
				string sObjData = ttp.GetStrPropValue(
					(int)FwTextPropType.ktptObjData);

				if (sObjData != null)
				{
					odt = (FwObjDataTypes)Convert.ToByte(sObjData[0]);
					// See if it's one of the types of objects we want.
					if (desiredOrcTypes == null || desiredOrcTypes.Contains(odt))
					{
						// Get GUID for ORC
						return MiscUtils.GetGuidFromObjData(sObjData.Substring(1));
					}
				}
			}
			return Guid.Empty;
		}
예제 #13
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get a Guid from the given run in a structured text string.
		/// </summary>
		/// <param name="tss">given structured text string</param>
		/// <param name="iRun">given run</param>
		/// <param name="desiredOrcType">The desired ORC type</param>
		/// <returns>
		/// The GUID associated with the specified run of the tss, if any; otherwise Guid.Empty
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static Guid GetGuidFromRun(ITsString tss, int iRun,
			FwObjDataTypes desiredOrcType)
		{
			TsRunInfo tri;
			ITsTextProps ttp;
			FwObjDataTypes odt;
			Set<FwObjDataTypes> desiredType = new Set<FwObjDataTypes>(1);
			desiredType.Add(desiredOrcType);
			return GetGuidFromRun(tss, iRun, out odt, out tri, out ttp, desiredType);
		}
예제 #14
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get an owned Guid from the given run in a structured text string.
		/// </summary>
		/// <param name="tss">given structured text string</param>
		/// <param name="iRun">given run</param>
		/// <param name="odt">object data type, 0 if no owned guid located</param>
		/// <param name="tri">run information</param>
		/// <param name="ttp">text properties of the run</param>
		/// <returns>
		/// The GUID associated with the specified run of the tss if it is for an owned object;
		/// otherwise Guid.Empty
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static Guid GetOwnedGuidFromRun(ITsString tss, int iRun,
			out FwObjDataTypes odt, out TsRunInfo tri,
			out ITsTextProps ttp)
		{
			Set<FwObjDataTypes> desiredTypes = new Set<FwObjDataTypes>(2);
			desiredTypes.Add(FwObjDataTypes.kodtOwnNameGuidHot);
			desiredTypes.Add(FwObjDataTypes.kodtGuidMoveableObjDisp);
			return GetGuidFromRun(tss, iRun, out odt, out tri, out ttp, desiredTypes);
		}
예제 #15
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Appends the specified text to the TS string builder.
		/// </summary>
		/// <param name="bldr">TS string builder.</param>
		/// <param name="guid">The GUID representing the embedded object</param>
		/// <param name="objDataType">The type of embedding</param>
		/// <param name="ws">The ID of the writing system to use for the inserted run, or 0
		/// to leave unspecified</param>
		/// ------------------------------------------------------------------------------------
		public static void AppendOrc(this ITsStrBldr bldr, Guid guid, FwObjDataTypes objDataType, int ws)
		{
			TsStringUtils.InsertOrcIntoPara(guid, objDataType, bldr, bldr.Length, bldr.Length, ws);
		}
예제 #16
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates an object replacement character from a Guid
		/// </summary>
		/// <param name="guid">guid that maps to an ORC</param>
		/// <param name="type">type of ORC to return within the TsString</param>
		/// <param name="ws">The writing system.</param>
		/// <returns>ITsString</returns>
		/// ------------------------------------------------------------------------------------
		public static ITsString CreateOrcFromGuid(Guid guid, FwObjDataTypes type, int ws)
		{
			ITsStrBldr tsStrBldr = TsStrBldrClass.Create();
			byte[] objData = GetObjData(guid, (byte)type);
			ITsPropsBldr propsBldr = TsPropsBldrClass.Create();
			propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData, objData, objData.Length);

			propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, ws);
			tsStrBldr.Replace(0, 0, new string(StringUtils.kChObject, 1), propsBldr.GetTextProps());
			return tsStrBldr.GetString();
		}
예제 #17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// In a string builder, updates the given ORC (Object Replacement Character) run
		/// with new object data.
		/// </summary>
		/// <param name="bldr">tss builder holding the ORC run</param>
		/// <param name="ttp">text properties of the ORC run</param>
		/// <param name="tri">The info for the ORC run, including min/lim character indices.</param>
		/// <param name="odt">object data type indicating to which type of object ORC points</param>
		/// <param name="guidOfNewObj">The GUID of new object, to update the ORC</param>
		/// ------------------------------------------------------------------------------------
		private static void UpdateORCforNewObjData(ITsStrBldr bldr, ITsTextProps ttp,
			TsRunInfo tri, FwObjDataTypes odt, Guid guidOfNewObj)
		{
			// build new ObjData properties of the ORC for the new object
			byte[] objData = MiscUtils.GetObjData(guidOfNewObj, (byte)odt);
			ITsPropsBldr propsBldr = ttp.GetBldr();
			propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData,
				objData, objData.Length);

			// update the run props in the string builder
			bldr.SetProperties(tri.ichMin, tri.ichLim, propsBldr.GetTextProps());
		}
예제 #18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get an owned Guid from the given run in a structured text string.
		/// </summary>
		/// <param name="tss">given structured text string</param>
		/// <param name="iRun">given run</param>
		/// <param name="odt">object data type, 0 if no owned guid located</param>
		/// <param name="tri">run information</param>
		/// <param name="ttp">text properties of the run</param>
		/// <returns>
		/// The GUID associated with the specified run of the tss if it is for an owned object;
		/// otherwise Guid.Empty
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static Guid GetOwnedGuidFromRun(ITsString tss, int iRun, out FwObjDataTypes odt, out TsRunInfo tri, out ITsTextProps ttp)
		{
			return GetGuidFromRun(tss, iRun, out odt, out tri, out ttp, s_ownedObjectTypes);
		}
예제 #19
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Gets all embedded object guids.
 /// </summary>
 /// <param name="tss">The TS String.</param>
 /// <param name="desiredOrcType">Type of the desired ORC.</param>
 /// <returns>Enumeration of GUIDs for all ORC runs of the requested type</returns>
 /// ------------------------------------------------------------------------------------
 public static IEnumerable <Guid> GetAllEmbeddedObjectGuids(this ITsString tss, FwObjDataTypes desiredOrcType)
 {
     for (int iRun = 0; iRun < tss.RunCount; iRun++)
     {
         Guid guid = TsStringUtils.GetGuidFromRun(tss, iRun, desiredOrcType);
         if (guid != Guid.Empty)
         {
             yield return(guid);
         }
     }
 }
예제 #20
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get a Guid from the given run in a structured text string.
		/// </summary>
		/// <param name="tss">given structured text string</param>
		/// <param name="iRun">given run</param>
		/// <param name="odt">object data type, 0 if no ORC guid located</param>
		/// <param name="tri">run information</param>
		/// <param name="ttp">text properties of the run</param>
		/// <param name="desiredOrcTypes">The desired ORC types, or null to return any type of
		/// ORC</param>
		/// <returns>
		/// The GUID associated with the specified run of the tss, if any; otherwise Guid.Empty
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static Guid GetGuidFromRun(ITsString tss, int iRun, out FwObjDataTypes odt, out TsRunInfo tri, out ITsTextProps ttp, FwObjDataTypes[] desiredOrcTypes)
		{
			ttp = null;
			return GetGuidFromRun(tss, iRun, desiredOrcTypes, out odt, out tri, ref ttp);
		}
예제 #21
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Appends the specified text to the TS string builder.
 /// </summary>
 /// <param name="bldr">TS string builder.</param>
 /// <param name="guid">The GUID representing the embedded object</param>
 /// <param name="objDataType">The type of embedding</param>
 /// <param name="ws">The ID of the writing system to use for the inserted run, or 0
 /// to leave unspecified</param>
 /// ------------------------------------------------------------------------------------
 public static void AppendOrc(this ITsStrBldr bldr, Guid guid, FwObjDataTypes objDataType, int ws)
 {
     TsStringUtils.InsertOrcIntoPara(guid, objDataType, bldr, bldr.Length, bldr.Length, ws);
 }
예제 #22
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get a Guid from the given text props.
		/// </summary>
		/// <param name="ttp">The text props</param>
		/// <param name="desiredOrcTypes">Set of ORC types that we're interested in, dude; or
		/// null if it don't make no difference</param>
		/// <param name="odt">Actual object type</param>
		/// <returns>The GUID from the text props or Guid.Empty if the props do not contain
		/// a GUID or have a type of ORC that is not one of the desired kinds</returns>
		/// ------------------------------------------------------------------------------------
		public static Guid GetGuidFromProps(ITsTextProps ttp, FwObjDataTypes[] desiredOrcTypes, out FwObjDataTypes odt)
		{
			odt = 0;
			string sObjData = ttp.ObjData();

			if (sObjData != null)
			{
				odt = (FwObjDataTypes)Convert.ToByte(sObjData[0]);
				// See if it's one of the types of objects we want.
				if (desiredOrcTypes == null || desiredOrcTypes.Contains(odt))
				{
					// Get GUID for ORC
					return MiscUtils.GetGuidFromObjData(sObjData.Substring(1));
				}
			}
			return Guid.Empty;
		}
예제 #23
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Checks an object property stored in the string props.
		/// </summary>
		/// <param name="propName">Name of the property.</param>
		/// <param name="propType">Type of the object property.</param>
		/// <param name="expectedGuid">The expected GUID in the object property.</param>
		/// ------------------------------------------------------------------------------------
		private void CheckStrObjProp(string propName, FwObjDataTypes propType, Guid expectedGuid)
		{
			ITsTextProps ttp = TsPropsSerializer.DeserializePropsFromXml("<Prop " + propName + "='" + expectedGuid + "'></Prop>", m_wsManager);
			Assert.IsNotNull(ttp);
			Assert.AreEqual(0, ttp.IntPropCount);
			Assert.AreEqual(1, ttp.StrPropCount);

			FwObjDataTypes type;
			Guid guid = TsStringUtils.GetGuidFromProps(ttp, null, out type);
			Assert.AreEqual(expectedGuid, guid);
			Assert.AreEqual(propType, type);
		}