示例#1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Fill in the back translation dictionaries for the given back translation object.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private Dictionary<int, string> FillBackTransForPara(BackTranslationInfo backtran,
			out Dictionary<int, ITsString> dictBackTrans,
			out Dictionary<int, int> mapWsBackTransRunIndex)
		{
			Dictionary<int, string> mapWsStatus = new Dictionary<int, string>();
			// stores current paragraph's back translations, mapping from ws to string
			dictBackTrans = new Dictionary<int, ITsString>();
			// run index for each back translation, mapping from ws to index
			mapWsBackTransRunIndex = new Dictionary<int, int>();
			if (backtran != null)
			{
				foreach (int ws in m_dictAnalLangs.Keys)
				{
					ITsString tss = backtran.GetBackTransForWs(ws);
					if (tss != null && tss.Length > 0)
					{
						dictBackTrans.Add(ws, tss);
						mapWsBackTransRunIndex.Add(ws, 0);
						string status = backtran.GetStatusForWs(ws);
						if (!String.IsNullOrEmpty(status))
							mapWsStatus.Add(ws, status.Normalize());
					}
				}
			}
			return mapWsStatus;
		}
示例#2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// This is different than other paragraphs because the Title Secondary and Title Tertiary
		/// character styles must generate outer &lt;title&gt; elements instead of being embedded
		/// inside the &lt;tr&gt; element.  We also don't expect chapter and verse numbers in this
		/// context!  However, we may have footnotes.
		/// </summary>
		/// <param name="para">title paragraph</param>
		/// <param name="backtran">back translation of title paragraph</param>
		/// <param name="fExportAnnotation"><c>true</c> to export annotations associated with
		/// the title; <c>false</c> otherwise</param>
		/// <remarks>
		/// This is even trickier, because the back translation should be grouped with the first
		/// "main" type title section.
		/// </remarks>
		/// ------------------------------------------------------------------------------------
		private void ExportTitleParagraph(IStTxtPara para, BackTranslationInfo backtran,
			ref bool fExportAnnotation)
		{
			Dictionary<int, ITsString> dictBackTrans;
			Dictionary<int, int> mapWsBackTransRunIndex;
			Dictionary<int, string> mapWsStatus = FillBackTransForPara(backtran,
				out dictBackTrans, out mapWsBackTransRunIndex);
			ITsString tssPara = para.Contents;
			if (tssPara.Length > 0)
			{
				int runCount = tssPara.RunCount;
				List<int> rgws;
				List<OxesInfo> rgInfo = CollectRunInfo(tssPara, out rgws);
				TitleType ttState = TitleType.kttNone;
				for (int run = 0; run < runCount; ++run)
				{
					string data = tssPara.get_RunText(run);
					if (!String.IsNullOrEmpty(data))
						data = data.Normalize();
					OxesInfo xinfo = rgInfo[run];
					int ws = rgws[run];
					switch (xinfo.StyleName)
					{
						default:
							if (IsObjectReference(data))
							{
								// This is presumably a footnote.
								if (ttState == TitleType.kttNone)
								{
									m_writer.WriteStartElement("title");
									m_writer.WriteAttributeString("type", "main");
									ttState = TitleType.kttMain;
									if (fExportAnnotation)
									{
										ExportAnyRelatedAnnotation();
										fExportAnnotation = false;
									}
								}
								ITsTextProps props = tssPara.get_Properties(run);
								ExportEmbeddedObject(props);
							}
							else
							{
								if (ttState == TitleType.kttSecondary || ttState == TitleType.kttTertiary)
									m_writer.WriteEndElement();		// xinfo.XmlTag (</title>)
								if (ttState != TitleType.kttMain)
								{
									m_writer.WriteStartElement("title");
									m_writer.WriteAttributeString("type", "main");
									ttState = TitleType.kttMain;
									if (fExportAnnotation)
									{
										ExportAnyRelatedAnnotation();
										fExportAnnotation = false;
									}
								}
								OpenTrGroupIfNeeded();
								OpenTranslationElementIfNeeded();
								WriteRunDataWithEmbeddedStyleInfo(rgInfo, rgws, run, m_cache.DefaultVernWs, data);
								CloseTranslationElementIfNeeded();
								WriteTitleBackTrans(mapWsStatus, dictBackTrans, mapWsBackTransRunIndex, ttState);
								CloseTrGroupIfNeeded();
							}
							break;
						case ScrStyleNames.SecondaryBookTitle:
							ttState = WriteSubtitle(dictBackTrans, mapWsBackTransRunIndex, mapWsStatus, ttState, data,
								xinfo, ws, TitleType.kttSecondary, ref fExportAnnotation);
							break;
						case ScrStyleNames.TertiaryBookTitle:
							ttState = WriteSubtitle(dictBackTrans, mapWsBackTransRunIndex, mapWsStatus, ttState, data,
								xinfo, ws, TitleType.kttTertiary, ref fExportAnnotation);
							break;
					}
				}
				if (ttState != TitleType.kttNone)
				{
					WriteTitleBackTrans(mapWsStatus, dictBackTrans, mapWsBackTransRunIndex, ttState);
					m_writer.WriteEndElement();		// </title>
				}
			}
		}
示例#3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Many header paragraphs need special handling.  Some are handled completely by this
		/// method.
		/// </summary>
		/// <param name="para"></param>
		/// <param name="styleName"></param>
		/// <param name="xinfo"></param>
		/// <param name="backtran"></param>
		/// <param name="rgBTSeg">list of segments for a segmented back translation</param>
		/// <returns>true iff the paragraph is completely exported by this method</returns>
		/// ------------------------------------------------------------------------------------
		private bool HandleHeaderParagraph(IStTxtPara para, string styleName, OxesInfo xinfo,
			BackTranslationInfo backtran, List<BTSegment> rgBTSeg)
		{
			if (xinfo.IsHeading)
			{
				if (styleName == ScrStyleNames.MainBookTitle)
				{
					bool fExportAnnotation = false;
					ExportTitleParagraph(para, backtran, ref fExportAnnotation);
					return true;
				}
				else if (styleName == ScrStyleNames.ParallelPassageReference)
				{
					// necessary markup is table driven
					return false;
				}
				else if (m_fInSectionHeader && styleName != ScrStyleNames.SpeechSpeaker)
				{
					// The XML markup for these styles are handled by the caller.
					ExportParagraphData(para.Contents, rgBTSeg);
					return true;
				}
			}
			return false;
		}
示例#4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Write the paragraph using a standard back translation.
		/// </summary>
		/// <param name="tssPara"></param>
		/// <param name="backtran"></param>
		/// ------------------------------------------------------------------------------------
		private void WriteParagraphWithStandardBackTranslation(ITsString tssPara,
			BackTranslationInfo backtran)
		{
			Dictionary<int, ITsString> dictBackTrans;
			Dictionary<int, int> mapWsBackTransRunIndex;
			Dictionary<int, string> mapWsStatus = FillBackTransForPara(backtran,
				out dictBackTrans, out mapWsBackTransRunIndex);

			if (tssPara.Length == 0)
			{
				OpenTrGroupIfNeeded();
				WriteBackTrans(mapWsStatus, dictBackTrans, mapWsBackTransRunIndex, Guid.Empty);
				CloseTrGroupIfNeeded();
			}
			else
			{
				int runCount = tssPara.RunCount;
				List<int> rgws;
				List<OxesInfo> rgInfo = CollectRunInfo(tssPara, out rgws);
				for (int run = 0; run < runCount; ++run)
				{
					string data = tssPara.get_RunText(run);
					if (!String.IsNullOrEmpty(data))
						data = data.Normalize();
					OxesInfo xinfo = rgInfo[run];
					int ws = rgws[run];
					switch (xinfo.StyleName)
					{
						case ScrStyleNames.ChapterNumber:
							ProcessChapterNumber(data, mapWsStatus, dictBackTrans, mapWsBackTransRunIndex);
							break;
						case ScrStyleNames.VerseNumber:
						case ScrStyleNames.VerseNumberInNote:
						case ScrStyleNames.VerseNumberAlternate:
							ProcessVerseNumber(data, mapWsStatus, dictBackTrans, mapWsBackTransRunIndex,
								xinfo.StyleName == ScrStyleNames.VerseNumberAlternate);
							break;
						default:
							if (IsObjectReference(data))
							{
								ITsTextProps props = tssPara.get_Properties(run);
								Guid guidFootnote = GetFootnoteGuidIfAny(props);
								m_sBTsWithFootnote = null;
								if (m_fInTrGroup)
								{
									CloseTranslationElementIfNeededAndWriteBackTrans(mapWsStatus,
										dictBackTrans, mapWsBackTransRunIndex, guidFootnote);
								}

								ExportEmbeddedObject(props);
							}
							else
							{
								// This checks for chapters that do not contain verse one. If that
								// is the case, then we need to make sure annotations associated
								// with the inferred verse one get exported. See TE-7720.
								if (m_iCurrentVerse == 0 && run - 1 >= 0 &&
									rgInfo[run - 1].StyleName == ScrStyleNames.ChapterNumber)
								{
									m_iCurrentVerse = 1;
									ExportAnyRelatedAnnotation();
								}

								OpenTrGroupIfNeeded();
								OpenTranslationElementIfNeeded();
								WriteRunDataWithEmbeddedStyleInfo(rgInfo, rgws, run, m_cache.DefaultVernWs, data);
							}
							break;
					}
				}

				CloseTranslationElementIfNeededAndWriteBackTrans(mapWsStatus,
					dictBackTrans, mapWsBackTransRunIndex, Guid.Empty);
			}
		}
示例#5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Export the data for a single paragraph.
		/// </summary>
		/// <param name="hvoPara"></param>
		/// <param name="tssPara"></param>
		/// <param name="backtran"></param>
		/// <param name="rgBTSeg">list of segments in a segmented back translation</param>
		/// ------------------------------------------------------------------------------------
		private void ExportParagraphData(int hvoPara, ITsString tssPara, BackTranslationInfo backtran,
			List<BTSegment> rgBTSeg)
		{
			if (rgBTSeg != null && rgBTSeg.Count > 0)
			{
				WriteParagraphWithSegmentedBT(tssPara, rgBTSeg);
			}
			else
			{
				WriteParagraphWithStandardBackTranslation(tssPara, backtran);
			}
		}
示例#6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Write out the picture as a &lt;figure&gt; element.
		/// </summary>
		/// <param name="pict"></param>
		/// ------------------------------------------------------------------------------------
		private void ExportPicture(ICmPicture pict)
		{
			ITsString tssCaption = pict.Caption.BestVernacularAlternative;
			string sCaption;
			if (tssCaption.Length > 0 && !tssCaption.Equals(pict.Caption.NotFoundTss))
				sCaption = tssCaption.Text.Normalize();
			else
				sCaption = String.Empty;
			m_writer.WriteStartElement("figure");
			string sPath = pict.PictureFileRA.AbsoluteInternalPath.Normalize();
			string sFile = Path.GetFileName(sPath);
			WriteFigureAttributes(sCaption, sFile);
			m_writer.WriteComment(String.Format("path=\"{0}\"", sPath));
			m_writer.WriteStartElement("caption");
			OpenTrGroupIfNeeded();
			List<BTSegment> rgbts = null;
			BackTranslationInfo trans = null;
			if (Options.UseInterlinearBackTranslation)
			{
				rgbts = new List<BTSegment>();
				BTSegment bts = new BTSegment(0, sCaption.Normalize(NormalizationForm.FormD).Length, pict);
				foreach (int ws in m_dictAnalLangs.Keys)
				{
					ITsString tss = pict.Caption.GetAlternative(ws).UnderlyingTsString;
					if (tss.Length > 0 && tss != pict.Caption.NotFoundTss)
						bts.SetTransForWs(ws, tss.get_NormalizedForm(FwNormalizationMode.knmNFC));
				}
				rgbts.Add(bts);
			}
			else
			{
				trans = new BackTranslationInfo(pict);
			}
			if (tssCaption.Length > 0)
				ExportParagraphData(0, tssCaption, trans, rgbts);
			CloseTrGroupIfNeeded();
			m_writer.WriteEndElement();	//</caption>
			m_writer.WriteEndElement();	//</figure>
		}