Example #1
0
        /// <summary>
        /// Fetches the information for the specified run.
        /// </summary>
        public ITsTextProps FetchRunInfo(int irun, out TsRunInfo tri)
        {
            ThrowIfRunIndexOutOfRange("irun", irun);

            TsRun run = Runs[irun];

            tri = new TsRunInfo {
                ichMin = GetRunIchMin(irun), ichLim = run.IchLim, irun = irun
            };
            return(run.TextProps);
        }
Example #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Deletes markers that reference the current footnote in the text and back translations.
        /// This also recalculates the footnote markers of following footnotes.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void DeleteFootnoteMarker()
        {
            // Get paragraph containing footnote and search for run having footnote ref.
            IScrTxtPara para = ParaContainingOrcRA;

            if (para != null && para.IsValidObject)
            {
                para.DeleteAnyBtMarkersForObject(this.Guid);
                ITsString tssContent = para.Contents;
                TsRunInfo runInfo    = new TsRunInfo();
                int       i;
                for (i = 0; i < tssContent.RunCount; i++)
                {
                    ITsTextProps textProps = tssContent.FetchRunInfo(i, out runInfo);
                    string       strGuid   =
                        textProps.GetStrPropValue((int)FwTextPropType.ktptObjData);
                    if (strGuid != null)
                    {
                        Guid guid = MiscUtils.GetGuidFromObjData(strGuid.Substring(1));
                        if (this.Guid == guid)
                        {
                            break;
                        }
                    }
                }

                if (i < tssContent.RunCount)
                {
                    // We found the footnote marker
                    // Remove footnote ref from paragraph - then delete the footnote
                    ITsStrBldr bldr = tssContent.GetBldr();
                    bldr.Replace(runInfo.ichMin, runInfo.ichLim, string.Empty, null);
                    para.Contents = bldr.GetString();
                }
            }
        }
Example #3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// C'tor
 /// </summary>
 /// <param name="badNumber">String with the invalid chapter or verse number</param>
 /// <param name="runInfo">Info about the run</param>
 /// ------------------------------------------------------------------------------------
 protected InvalidScriptureNumberException(string badNumber, TsRunInfo runInfo)
 {
     m_badNumber = badNumber;
     m_runInfo   = runInfo;
 }
Example #4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Deletes a footnote along with its marker in the text. This also recalculates the
		/// footnote markers of following footnotes.
		/// </summary>
		/// <param name="footnote"></param>
		/// ------------------------------------------------------------------------------------
		public static void DeleteFootnoteAndMarker(ScrFootnote footnote)
		{
			// Paragraph changes are not monitored by cache - refresh cache for book before
			// doing deletion
			IScrBook book = new ScrBook(footnote.Cache, footnote.OwnerHVO);
			// REVIEW: Probably not needed now??? ((ScrBook)book).RefreshFootnoteRefs();

			// Get paragraph containing footnote and search for run having footnote ref.
			int hvoPara = footnote.ContainingParagraphHvo;
			if (hvoPara != 0)
			{
				StTxtPara para = new StTxtPara(footnote.Cache, hvoPara);
				para.DeleteAnyBtMarkersForFootnote(footnote.Guid);
				ITsString tssContent = para.Contents.UnderlyingTsString;
				TsRunInfo runInfo = new TsRunInfo();
				int i;
				for (i = 0; i < tssContent.RunCount; i++)
				{
					ITsTextProps textProps = tssContent.FetchRunInfo(i, out runInfo);
					string strGuid =
						textProps.GetStrPropValue((int)FwTextPropType.ktptObjData);
					if (strGuid != null)
					{
						Guid guid = MiscUtils.GetGuidFromObjData(strGuid.Substring(1));
						if (footnote.Guid == guid)
							break;
					}
				}
				System.Diagnostics.Debug.Assert(i < tssContent.RunCount, "Footnote marker not found in text");

				// Remove footnote ref from paragraph - then delete the footnote
				ITsStrBldr bldr = tssContent.GetBldr();
				bldr.Replace(runInfo.ichMin, runInfo.ichLim, string.Empty, null);
				para.Contents.UnderlyingTsString = bldr.GetString();
			}
			DeleteFootnote(footnote);
		}
Example #5
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());
		}
Example #6
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);
		}
Example #7
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;
		}
Example #8
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);
		}
Example #9
0
		private string GetPartialRunData(ITsString tssPara, ref TsRunInfo tri, BTSegment bts)
		{
			ITsStrBldr tsb = tssPara.GetBldr();
			int iMin = Math.Max(tri.ichMin, bts.BeginOffset);
			int iLim = Math.Min(tri.ichLim, bts.EndOffset);
			Debug.Assert(iMin <= iLim);
			tsb.ReplaceTsString(iLim, tssPara.Length, null);
			tsb.ReplaceTsString(0, iMin, null);
			string dataSeg = tsb.Text;
			string dataNFC = String.Empty;
			if (dataSeg != null)
				dataNFC = dataSeg.Normalize();
			return dataNFC;
		}
Example #10
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);
		}
Example #11
0
		private void WritePartialRunWithBTSegment(ITsString tssPara, int irun, ref TsRunInfo tri,
			List<int> rgws, List<OxesInfo> rgInfo,
			int iseg, BTSegment bts)
		{
			string dataNFC = GetPartialRunData(tssPara, ref tri, bts);
			OpenTrGroupIfNeeded();
			OpenTranslationElementIfNeeded();
			WriteRunDataWithEmbeddedStyleInfo(rgInfo, rgws, irun, m_cache.DefaultVernWs, dataNFC);
			if (bts.EndOffset <= tri.ichLim)
				WriteSegmentedBackTrans(bts, iseg);
		}
Example #12
0
		private void CloseTranslationElementIfNeededAndWriteBackTrans(BTSegment bts, TsRunInfo tri,
			Guid guidFootnote)
		{
			CloseTranslationElementIfNeeded();
			WriteSegmentedBackTrans(bts, -1);
			CloseTrGroupIfNeeded();
		}
Example #13
0
        /// <summary>
        /// Fetches the run information at the specified character offset.
        /// </summary>
        public ITsTextProps FetchRunInfoAt(int ich, out TsRunInfo tri)
        {
            ThrowIfCharOffsetOutOfRange("ich", ich, Length);

            return(FetchRunInfo(get_RunAt(ich), out tri));
        }
Example #14
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// C'tor
 /// </summary>
 /// <param name="badChapterNumber">String with the invalid chapter number</param>
 /// <param name="runInfo">Info about the run</param>
 /// ------------------------------------------------------------------------------------
 public InvalidChapterException(string badChapterNumber, TsRunInfo runInfo)
     : base(badChapterNumber, runInfo)
 {
 }
Example #15
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// C'tor
		/// </summary>
		/// <param name="badChapterNumber">String with the invalid chapter number</param>
		/// <param name="runInfo">Info about the run</param>
		/// ------------------------------------------------------------------------------------
		public InvalidChapterException(string badChapterNumber, TsRunInfo runInfo)
			: base(badChapterNumber, runInfo)
		{
		}
Example #16
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// C'tor
 /// </summary>
 /// <param name="badVerseNumber">String with the invalid verse number</param>
 /// <param name="runInfo">Info about the run</param>
 /// ------------------------------------------------------------------------------------
 public InvalidVerseException(string badVerseNumber, TsRunInfo runInfo)
     : base(badVerseNumber, runInfo)
 {
 }
Example #17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// C'tor
		/// </summary>
		/// <param name="badVerseNumber">String with the invalid verse number</param>
		/// <param name="runInfo">Info about the run</param>
		/// ------------------------------------------------------------------------------------
		public InvalidVerseException(string badVerseNumber, TsRunInfo runInfo)
			: base(badVerseNumber, runInfo)
		{
		}
Example #18
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="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 any; otherwise Guid.Empty
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static Guid GetGuidFromRun(ITsString tss, int iRun, out TsRunInfo tri, out ITsTextProps ttp)
		{
			FwObjDataTypes odt;
			return GetGuidFromRun(tss, iRun, out odt, out tri, out ttp, null);
		}
Example #19
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// C'tor
		/// </summary>
		/// <param name="badNumber">String with the invalid chapter or verse number</param>
		/// <param name="runInfo">Info about the run</param>
		/// ------------------------------------------------------------------------------------
		public InvalidScriptureNumberException(string badNumber, TsRunInfo runInfo)
			: base()
		{
			m_badNumber = badNumber;
			m_runInfo = runInfo;
		}
Example #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 (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;
		}
Example #21
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Deletes markers that reference the current footnote in the text and back translations.
		/// This also recalculates the footnote markers of following footnotes.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void DeleteFootnoteMarker()
		{
			// Get paragraph containing footnote and search for run having footnote ref.
			IScrTxtPara para = ParaContainingOrcRA;
			if (para != null && para.IsValidObject)
			{
				para.DeleteAnyBtMarkersForObject(this.Guid);
				ITsString tssContent = para.Contents;
				TsRunInfo runInfo = new TsRunInfo();
				int i;
				for (i = 0; i < tssContent.RunCount; i++)
				{
					ITsTextProps textProps = tssContent.FetchRunInfo(i, out runInfo);
					string strGuid =
						textProps.GetStrPropValue((int)FwTextPropType.ktptObjData);
					if (strGuid != null)
					{
						Guid guid = MiscUtils.GetGuidFromObjData(strGuid.Substring(1));
						if (this.Guid == guid)
							break;
					}
				}

				if (i < tssContent.RunCount)
				{
					// We found the footnote marker
					// Remove footnote ref from paragraph - then delete the footnote
					ITsStrBldr bldr = tssContent.GetBldr();
					bldr.Replace(runInfo.ichMin, runInfo.ichLim, string.Empty, null);
					para.Contents = bldr.GetString();
				}
			}
		}