コード例 #1
0
ファイル: InMemoryFdoCache.cs プロジェクト: sillsdev/WorldPad
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add a mindless footnote (i.e., it's marker, paragraph style, etc. won't be set)
		/// to a paragraph.
		/// </summary>
		/// <param name="footnoteSequence">Sequence of footnotes into which to insert</param>
		/// <param name="para">the paragraph into which to insert the footnote ORC</param>
		/// <param name="ichPos">the zero-based character offset at which to insert the footnote
		/// ORC into the paragraph</param>
		/// <param name="footnoteText">text for the footnote (no footnote paragraph created if
		/// null)</param>
		/// <returns>the new footnote</returns>
		/// ------------------------------------------------------------------------------------
		public StFootnote AddFootnote(FdoOwningSequence<IStFootnote> footnoteSequence,
			IStTxtPara para, int ichPos, string footnoteText)
		{
			CheckDisposed();
			// Create the footnote
			StFootnote footnote = new StFootnote();
			footnoteSequence.Append(footnote);

			// Update the paragraph contents to include the footnote marker ORC
			ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr();
			footnote.InsertOwningORCIntoPara(tsStrBldr, ichPos, m_fdoCache.DefaultVernWs);
			para.Contents.UnderlyingTsString = tsStrBldr.GetString();

			if (footnoteText != null)
			{
				// Create the footnote paragraph with the given footnoteText
				StTxtParaBldr paraBldr = new StTxtParaBldr(m_fdoCache);
				paraBldr.ParaProps = StyleUtils.ParaStyleTextProps("Note General Paragraph");
				paraBldr.AppendRun(footnoteText, StyleUtils.CharStyleTextProps(null, m_fdoCache.DefaultVernWs));
				paraBldr.CreateParagraph(footnote.Hvo);
			}

			return footnote;
		}
コード例 #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create a mindless footnote (i.e., it's marker, paragraph style, etc. won't be set).
		/// </summary>
		/// <param name="book">Book to insert footnote into</param>
		/// <param name="para">Paragraph to insert footnote into</param>
		/// <param name="iFootnotePos">The 0-based index of the new footnote in the collection
		/// of footnotes owned by the book</param>
		/// <param name="ichPos">The 0-based character offset into the paragraph</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		protected StFootnote InsertTestFootnote(IScrBook book, IStTxtPara para,
			int iFootnotePos, int ichPos)
		{
			// Create the footnote
			StFootnote footnote = new StFootnote();
			book.FootnotesOS.InsertAt(footnote, iFootnotePos);

			// Update the paragraph contents to include the footnote marker
			ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr();
			footnote.InsertOwningORCIntoPara(tsStrBldr, ichPos, 0); // Don't care about ws
			para.Contents.UnderlyingTsString = tsStrBldr.GetString();

			return footnote;
		}
コード例 #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create an ITsString from a format string.
		/// </summary>
		/// <param name="book">The book for inserting footnotes into (can be null if there are
		/// no footnotes)</param>
		/// <param name="strBldr">The ITsStrBldr to add the text to (if null a new one will be
		/// created)</param>
		/// <param name="format">format string, which may include these special "commands":
		/// \c - insert a chapter number run
		/// \v - insert a verse number run
		/// \* - insert a simple text run
		/// \*(char style name) - insert a text run with a character style.
		/// \i - insert a picture (text must be the text rep of the picture (see pic code))
		/// \f - insert a footnote</param>
		/// \^ - end of the current footnote (required for every footnote)
		/// <param name="ws">writing system for each run of text</param>
		/// <returns>the completed ITsString</returns>
		/// ------------------------------------------------------------------------------------
		public static ITsString CreateFormatText(IScrBook book, ITsStrBldr strBldr,
			string format, int ws)
		{
			if (strBldr == null)
				strBldr = TsStrBldrClass.Create();

			int nChapter = 1, nVerse = 1;

			for (int i = 0; i < format.Length; )
			{
				// skip the backslash (verify that it is there first)
				if (format[i] != '\\')
					Debug.Assert(false, @"Format string must start every text run with \*: {0}" +
						format.Substring(i));
				if (++i >= format.Length)
					break;

				// save the field type character
				char field = format[i];
				if (++i >= format.Length)
					break;

				// determine the endmarker we'll look for
				string endMarker = (field == 'f' || field == 'i') ? @"\^" : @"\";

				// extract the data for the field
				int lim = format.IndexOf(endMarker, i);
				if (lim == -1 && field == 'f')
					Debug.Assert(false, @"Format string must have a \^ to end footnote!");
				else if (lim == -1)
					lim = format.Length;
				string fieldData = format.Substring(i, lim - i);

				// remember pos of next backslash, or the end of the format string
				i = lim;
				//skip empty commands, such as \^
				if (fieldData.Length == 0)
					continue;

				// what kind of command is this?
				switch (field)
				{
					case 'c':
						Int32.TryParse(fieldData, out nChapter);
						AddRunToStrBldr(strBldr, fieldData, ws, "Chapter Number");
						break;
					case 'v':
						FdoCache cache = book.Cache;
						LgWritingSystem vernWs = new LgWritingSystem(cache, cache.DefaultVernWs);
						string sBridge = cache.LangProject.TranslatedScriptureOA.Bridge;
						string [] pieces = fieldData.Split(new string[] {sBridge}, 2, StringSplitOptions.RemoveEmptyEntries);
						StringBuilder strb = new StringBuilder();
						string sLastVerse = pieces[pieces.Length - 1];
						Int32.TryParse(fieldData, out nVerse);
						if (vernWs.RightToLeft && pieces.Length == 2)
						{
							// The verse number run has a bridge and is in a right-to-left
							// writing system. Construct a verse bridge with right-to-left
							// characters adjacent to the bridge character.
							strb.Append(pieces[0] + '\u200f' + sBridge + '\u200f' + pieces[1]);
						}
						else
							strb.Append(fieldData);

						AddRunToStrBldr(strBldr, strb.ToString(), ws, "Verse Number");
						break;
					case 'f':
						StFootnote footnote = new StFootnote();
						book.FootnotesOS.Append(footnote);
						footnote.InsertOwningORCIntoPara(strBldr, strBldr.Length, ws);
						footnote.FootnoteMarker.UnderlyingTsString = TsStringHelper.MakeTSS("a", ws); // auto-generate
						if (fieldData.IndexOf(@"\f") != -1)
							Debug.Assert(false, @"Format string must not nest \f within another \f..\^");
						StTxtPara para = AppendParagraph(footnote, fieldData, ws); //recursively calls CreateText to process any char styles
						para.StyleRules = StyleUtils.ParaStyleTextProps("Note General Paragraph");
						//TODO: add multiple paragraphs for a footnote
						break;
					case 'i':
						CmPicture picture = new CmPicture(book.Cache, fieldData, StringUtils.LocalPictures,
							new BCVRef(book.CanonicalNum, nChapter, nVerse),
							book.Cache.LangProject.TranslatedScriptureOA as IPictureLocationBridge);
						picture.AppendPicture(ws, strBldr);
						break;
					case '*':
						{
							int wsRun = ws;
							string charStyleName = null;
							// if we have an optional character style in parens, process it
							if (fieldData[0] == '(')
							{
								int endParen = fieldData.IndexOf(")", 0);
								Debug.Assert(endParen > 1); // caller must provide something within parens
								if (endParen != -1)
								{
									charStyleName = fieldData.Substring(1, endParen - 1);
									fieldData = fieldData.Substring(endParen + 1);
								}
							}
							// if we have an optional writing system specifier, process it
							if (fieldData[0] == '|' && fieldData.Length > 3 && fieldData[3] == '|')
							{
								wsRun = book.Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(fieldData.Substring(1, 2));
								if (wsRun > 0)
									fieldData = fieldData.Substring(4);
								else
									wsRun = ws;
							}
							AddRunToStrBldr(strBldr, fieldData, wsRun, charStyleName);
							break;
						}
				}
			}
			return strBldr.GetString();
		}