示例#1
0
		bool m_fThumbnail; // true to force smaller size.
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public PictureSlice(CmPicture picture)
		{
			m_picBox = new PictureBox();
			m_picBox.Click += new EventHandler(pb_Click);
			m_picBox.Location = new Point(0,0); // not docked, because width may not be whole width
			m_picBox.SizeMode = PictureBoxSizeMode.Zoom;
			m_picture = picture;
			InstallPicture(m_picBox);
			// We need an extra layer of panel because the slice's control is always docked,
			// and we don't want that for the picture box.
			Panel panel = new Panel();
			panel.Controls.Add(m_picBox);
			panel.SizeChanged += new EventHandler(panel_SizeChanged);
			this.Control = panel;
		}
示例#2
0
		public void CmPictureConstructor_FromTextRep()
		{
			CheckDisposed();

			ICmPicture pictNew = new CmPicture(Cache, ((CmPicture)m_pict).TextRepOfPicture,
				StringUtils.LocalPictures);
			Assert.IsTrue(pictNew != m_pict);
			string internalPathNew = pictNew.PictureFileRA.InternalPath;
			Assert.IsNotNull(internalPathNew, "Internal path not set correctly");
			Assert.IsTrue(pictNew.PictureFileRA.AbsoluteInternalPath == internalPathNew, "Files outside LangProject.ExtLinkRootDir are stored as absolute paths");
			m_internalFilesToDelete.Add(pictNew.PictureFileRA.AbsoluteInternalPath);
			Assert.AreEqual(m_internalPath, internalPathNew);
			Assert.IsTrue(internalPathNew.EndsWith(".jpg"));
			AssertEx.AreTsStringsEqual(m_pict.Caption.VernacularDefaultWritingSystem.UnderlyingTsString,
				pictNew.Caption.VernacularDefaultWritingSystem.UnderlyingTsString);
			Assert.AreEqual(m_pict.PictureFileRA.OwnerHVO, pictNew.PictureFileRA.OwnerHVO);
			Assert.IsNull(pictNew.Description.AnalysisDefaultWritingSystem.Text);
			// REVIEW (TE-7745): What should the default PictureLayoutPosition value be?
			Assert.AreEqual(PictureLayoutPosition.CenterInColumn, pictNew.LayoutPos);
			Assert.AreEqual(100, pictNew.ScaleFactor);
			Assert.AreEqual(PictureLocationRangeType.AfterAnchor, pictNew.LocationRangeType);
			Assert.AreEqual(0, pictNew.LocationMin);
			Assert.AreEqual(0, pictNew.LocationMax);
			Assert.IsNull(pictNew.PictureFileRA.Copyright.VernacularDefaultWritingSystem.Text);
		}
示例#3
0
		public void GetTextTokens_WholeBook()
		{
			ScrChecksDataSource dataSource = new ScrChecksDataSource(Cache);
			m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis");
			int iExodus = 2;
			IScrBook exodus = m_scrInMemoryCache.AddBookToMockedScripture(iExodus, "Exodus");
			m_scrInMemoryCache.AddTitleToMockedBook(exodus.Hvo, "Exodus");

			IScrSection section = m_scrInMemoryCache.AddIntroSectionToMockedBook(exodus.Hvo);
			StTxtPara paraIntroSectHead = m_scrInMemoryCache.AddParaToMockedText(section.HeadingOAHvo,
				ScrStyleNames.IntroSectionHead);
			m_scrInMemoryCache.AddRunToMockedPara(paraIntroSectHead, "Everything you wanted to know about Exodus but were afraid to ask", null);
			StTxtPara paraIntroSectContent = m_scrInMemoryCache.AddParaToMockedText(section.ContentOAHvo,
				ScrStyleNames.IntroParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraIntroSectContent, "There's not much to say, really.", null);
			section.AdjustReferences();

			section = m_scrInMemoryCache.AddSectionToMockedBook(exodus.Hvo);
			StTxtPara paraSectHead1 = m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Head1", ScrStyleNames.SectionHead);
			StTxtPara paraSect1Content = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect1Content, "1", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect1Content, "1", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect1Content, "Chapter 1 Verse 1 Text", null);
			section.AdjustReferences();

			section = m_scrInMemoryCache.AddSectionToMockedBook(exodus.Hvo);
			StTxtPara paraSectHead2 = m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "Head2", ScrStyleNames.SectionHead);
			StTxtPara paraSect2Content1 = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "2", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "Chapter 2 Verse 1 Text", null);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "2", ScrStyleNames.VerseNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "Chapter 2 Verse 2 Text ", null);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content1, "Wow!", "Emphasis");
			StTxtPara paraSect2Content2 = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, "Line 1");
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content2, "Selah", ScrStyleNames.Interlude);
			StFootnote footnote = m_scrInMemoryCache.AddFootnote(exodus, paraSect2Content2, 5, "This is the text of the footnote");
			m_scrInMemoryCache.AddRunToMockedPara((StTxtPara)footnote.ParagraphsOS[0], "Favorite", Cache.DefaultUserWs);
			m_scrInMemoryCache.AddRunToMockedPara(paraSect2Content2, " or say, \"la\".", null);
			CmPicture pict;
			using (DummyFileMaker filemaker = new DummyFileMaker("junk.jpg", true))
			{
				ITsStrFactory factory = TsStrFactoryClass.Create();
				pict = new CmPicture(Cache, filemaker.Filename,
					factory.MakeString("Test picture caption", Cache.DefaultVernWs),
					StringUtils.LocalPictures);
				ITsStrBldr bldr = paraSect2Content2.Contents.UnderlyingTsString.GetBldr();
				pict.AppendPicture(Cache.DefaultVernWs, bldr);
				paraSect2Content2.Contents.UnderlyingTsString = bldr.GetString();
			}
			section.AdjustReferences();

			Assert.IsTrue(dataSource.GetText(iExodus, 0));
			IEnumerator<ITextToken> tokens = dataSource.TextTokens().GetEnumerator();
			VerifyToken(tokens, "Exodus", ScrStyleNames.MainBookTitle, string.Empty, exodus.TitleOA.ParagraphsOS[0]);
			VerifyToken(tokens, "Everything you wanted to know about Exodus but were afraid to ask", ScrStyleNames.IntroSectionHead, string.Empty, paraIntroSectHead);
			VerifyToken(tokens, "There's not much to say, really.", ScrStyleNames.IntroParagraph, string.Empty, paraIntroSectContent);
			BCVRef expectedRef = new BCVRef(iExodus, 1, 1);
			VerifyToken(tokens, "Head1", ScrStyleNames.SectionHead, string.Empty, expectedRef, true, TextType.Other, paraSectHead1);
			VerifyToken(tokens, "1", ScrStyleNames.NormalParagraph, ScrStyleNames.ChapterNumber, expectedRef, true, TextType.ChapterNumber, paraSect1Content);
			VerifyToken(tokens, "1", ScrStyleNames.NormalParagraph, ScrStyleNames.VerseNumber, expectedRef, false, TextType.VerseNumber, paraSect1Content);
			VerifyToken(tokens, "Chapter 1 Verse 1 Text", "Paragraph", string.Empty, expectedRef, false, TextType.Verse, paraSect1Content);
			expectedRef.Chapter = 2;
			VerifyToken(tokens, "Head2", ScrStyleNames.SectionHead, string.Empty, expectedRef, true, TextType.Other, paraSectHead2);
			VerifyToken(tokens, "2", ScrStyleNames.NormalParagraph, ScrStyleNames.ChapterNumber, expectedRef, true, TextType.ChapterNumber, paraSect2Content1);
			VerifyToken(tokens, "Chapter 2 Verse 1 Text", ScrStyleNames.NormalParagraph, string.Empty, expectedRef, false, TextType.Verse, paraSect2Content1);
			expectedRef.Verse = 2;
			VerifyToken(tokens, "2", ScrStyleNames.NormalParagraph, ScrStyleNames.VerseNumber, expectedRef, false, TextType.VerseNumber, paraSect2Content1);
			VerifyToken(tokens, "Chapter 2 Verse 2 Text ", ScrStyleNames.NormalParagraph, string.Empty, expectedRef, false, TextType.Verse, paraSect2Content1);
			VerifyToken(tokens, "Wow!", ScrStyleNames.NormalParagraph, ScrStyleNames.Emphasis, expectedRef, false, TextType.Verse, paraSect2Content1);
			VerifyToken(tokens, "Selah", "Line 1", ScrStyleNames.Interlude, expectedRef, true, TextType.Verse, paraSect2Content2);
			VerifyToken(tokens, "This is the text of the footnote", ScrStyleNames.NormalFootnoteParagraph, string.Empty,
				expectedRef, true, TextType.Note, footnote.ParagraphsOS[0]);
			VerifyToken(tokens, "Favorite", ScrStyleNames.NormalFootnoteParagraph, string.Empty, expectedRef,
				expectedRef, false, TextType.Note, "en", footnote.ParagraphsOS[0], (int)StTxtPara.StTxtParaTags.kflidContents);
			VerifyToken(tokens, " or say, \"la\".", "Line 1", string.Empty, expectedRef, false, TextType.Verse, paraSect2Content2);
			VerifyToken(tokens, "Test picture caption", ScrStyleNames.Figure, string.Empty, expectedRef, expectedRef, true, TextType.PictureCaption, null,
				pict, (int)CmPicture.CmPictureTags.kflidCaption);
			Assert.IsFalse(tokens.MoveNext());
		}
示例#4
0
		public void GetParagraphProps_InPictureCaption()
		{
			CheckDisposed();
			ITsStrFactory factory = TsStrFactoryClass.Create();
			CmPicture pict = new CmPicture(Cache, "c:\\junk.jpg",
				factory.MakeString("Test picture", Cache.DefaultVernWs),
				StringUtils.LocalPictures);
			Assert.IsNotNull(pict);
			//CmPicture pic = new CmPicture();
			//ICmFolder folder = new CmFolder();
			//Cache.LangProject.PicturesOC.Add(folder);

			//m_basicView.EditingHelper.MakePictureFromText(Cache,
			ShowForm(Lng.English, DummyBasicViewVc.DisplayType.kNormal);
			DynamicMock mockedSelection = new DynamicMock(typeof(IVwSelection));
			mockedSelection.ExpectAndReturn("IsValid", true);
			mockedSelection.ExpectAndReturn("Commit", true);
			VwChangeInfo changeInfo = new VwChangeInfo();
			changeInfo.hvo = 0;
			mockedSelection.ExpectAndReturn("CompleteEdits", true, new object[] {changeInfo},
				new string[] {typeof(VwChangeInfo).FullName + "&"}, new object[] {changeInfo});
			mockedSelection.ExpectAndReturn("CLevels", 2, false);
			mockedSelection.ExpectAndReturn("CLevels", 2, true);
			string sIntType = typeof(int).FullName;
			string intRef = sIntType + "&";
			mockedSelection.ExpectAndReturn("PropInfo", null,
				new object[] { false, 0, null, null, null, null, null },
				new string[] {typeof(bool).FullName, sIntType, intRef, intRef, intRef,
					intRef, typeof(IVwPropertyStore).FullName + "&"},
				new object[] { false, 0, pict.Hvo, (int)CmPicture.CmPictureTags.kflidCaption, 0, 0, null });
			mockedSelection.ExpectAndReturn("PropInfo", null,
				new object[] { true, 0, null, null, null, null, null },
				new string[] {typeof(bool).FullName, sIntType, intRef, intRef, intRef,
					intRef, typeof(IVwPropertyStore).FullName + "&"},
				new object[] { true, 0, pict.Hvo, (int)CmPicture.CmPictureTags.kflidCaption, 0, 0, null });
			mockedSelection.ExpectAndReturn(2, "EndBeforeAnchor", false);

			DummyBasicView.DummyEditingHelper editingHelper =
				(DummyBasicView.DummyEditingHelper)m_basicView.EditingHelper;
			editingHelper.m_mockedSelection = (IVwSelection)mockedSelection.MockInstance;
			editingHelper.m_fOverrideGetParaPropStores = true;

			IVwRootBox rootBox = m_basicView.RootBox;
			IVwSelection vwsel;
			int hvoText, tagText, ihvoFirst, ihvoLast;
			IVwPropertyStore[] vvps;
			ITsTextProps[] vttp;

			Assert.IsTrue(m_basicView.GetParagraphProps(out vwsel, out hvoText, out tagText,
				out vvps, out ihvoFirst, out ihvoLast, out vttp));

			Assert.AreEqual((int)CmPicture.CmPictureTags.kflidCaption, tagText);
			Assert.AreEqual(1, vttp.Length);
			Assert.AreEqual("Figure caption",
				vttp[0].GetStrPropValue((int)FwTextPropType.ktptNamedStyle));
		}
示例#5
0
		/// <summary>
		/// Override to adjust annotations for the resegmented string.
		/// Enhance JohnT: possibly we don't need to break segments for a picture? But it's nice to have it come
		/// out in the BT window.
		/// </summary>
		protected override void InsertPictureOrc(CmPicture pict, ITsString tss, int ich, int hvoObj, int propTag, int ws)
		{
			m_annotationAdjuster.OnAboutToModify(m_cache, hvoObj);
			base.InsertPictureOrc(pict, tss, ich, hvoObj, propTag, ws);
			m_annotationAdjuster.OnFinishedEdit();
		}
示例#6
0
		public void PressingEnterWithPictureSelected_InSectionHead()
		{
			CheckDisposed();

			int hvoPic = CreateAndInsertPicture();
			CmPicture pic = new CmPicture(Cache, hvoPic);
			pic.Caption.SetVernacularDefaultWritingSystem("My Caption");

			// Get the first paragraph in the first section of the first book.
			IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis");
			IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo);
			StTxtPara para = m_scrInMemoryCache.AddParaToMockedText(section.HeadingOAHvo,
				ScrStyleNames.SectionHead);

			m_scrInMemoryCache.AddRunToMockedPara(para, "This is the heading", null);
			section.AdjustReferences();

			SelectionHelper helper = PutPictureInParagraph(hvoPic, para);
			helper.IchAnchor = 4;
			helper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, (int)CmPicture.CmPictureTags.kflidCaption);
			ReflectionHelper.SetField(m_editingHelper, "m_viewSelection", helper);

			DynamicMock sel = new DynamicMock(typeof(IVwSelection));
			sel.SetupResult("IsRange", false);
			ReflectionHelper.SetField(helper, "m_vwSel", sel.MockInstance);

			DynamicMock rootbox = new DynamicMock(typeof(IVwRootBox));
			ReflectionHelper.SetField(m_RootSite, "m_rootb", rootbox.MockInstance);
			ReflectionHelper.CallMethod(m_editingHelper, "HandleEnterKey", true, string.Empty,
				0, 0, VwShiftStatus.kfssNone, null, Keys.None);
		}
示例#7
0
		public void TestTextRepOfObj_CmPicture()
		{
			CheckDisposed();

			string internalPathOrig = null;
			string internalPathNew = null;
			try
			{
				using (DummyFileMaker filemaker = new DummyFileMaker("junk.jpg", true))
				{
					ITsStrFactory factory = TsStrFactoryClass.Create();
					EditingHelper editHelper = new EditingHelper(null);
					CmPicture pict = new CmPicture(m_fdoCache, filemaker.Filename,
						factory.MakeString("Test picture", m_fdoCache.DefaultVernWs),
						StringUtils.LocalPictures);
					Assert.IsNotNull(pict);
					Assert.IsTrue(pict.PictureFileRA.AbsoluteInternalPath == pict.PictureFileRA.InternalPath);
					Guid guid = Cache.GetGuidFromId(pict.Hvo);
					string sTextRepOfObject = editHelper.TextRepOfObj(m_fdoCache, guid);
					int objectDataType;
					guid = editHelper.MakeObjFromText(m_fdoCache, sTextRepOfObject, null,
						out objectDataType);
					CmPicture pictNew = new CmPicture(Cache, Cache.GetIdFromGuid(guid));
					Assert.IsTrue(pict != pictNew);
					internalPathOrig = pict.PictureFileRA.AbsoluteInternalPath;
					internalPathNew = pictNew.PictureFileRA.AbsoluteInternalPath;
					Assert.AreEqual(internalPathOrig, internalPathNew);
					Assert.AreEqual(internalPathOrig.IndexOf("junk"), internalPathNew.IndexOf("junk"));
					Assert.IsTrue(internalPathNew.EndsWith(".jpg"));
					AssertEx.AreTsStringsEqual(pict.Caption.VernacularDefaultWritingSystem.UnderlyingTsString,
						pictNew.Caption.VernacularDefaultWritingSystem.UnderlyingTsString);
					Assert.AreEqual(pict.PictureFileRA.OwnerHVO, pictNew.PictureFileRA.OwnerHVO);
				}
			}
			finally
			{
				// TODO: When Undo works right, these should get cleaned up automatically
				if (internalPathOrig != null)
					File.Delete(internalPathOrig);
				if (internalPathNew != null)
					File.Delete(internalPathNew);
			}
		}
示例#8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets up current and revision paragraphs, inserting a picture in the specified
		/// paragraph. This returns the position where the picture was inserted.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private int SetupPictureDiffTests(bool putPicInRev, out StTxtPara paraCur,
			out StTxtPara paraRev)
		{
			// create Current section
			IScrSection sectionCur = CreateSection(m_genesis, "My aching head!");
			paraCur = m_scrInMemoryCache.AddParaToMockedSectionContent(sectionCur.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraCur, "1", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraCur, "Hello.", Cache.DefaultVernWs);

			// create Revision section
			IScrSection sectionRev = CreateSection(m_genesisRevision, "My aching head!");
			paraRev = m_scrInMemoryCache.AddParaToMockedSectionContent(sectionRev.Hvo, ScrStyleNames.NormalParagraph);
			m_scrInMemoryCache.AddRunToMockedPara(paraRev, "1", ScrStyleNames.ChapterNumber);
			m_scrInMemoryCache.AddRunToMockedPara(paraRev, "Hello.", Cache.DefaultVernWs);

			int picPos = 7;
			StTxtPara para = (putPicInRev ? paraRev : paraCur);
			ITsString tss = para.Contents.UnderlyingTsString;

			// Add picture to revision.
			ITsStrFactory factory = TsStrFactoryClass.Create();
			using (DummyFileMaker fileMaker = new DummyFileMaker("junk.jpg", true))
			{
				CmPicture pict = new CmPicture(Cache, fileMaker.Filename,
					factory.MakeString("Test picture", Cache.DefaultVernWs),
					StringUtils.LocalPictures);

				pict.InsertORCAt(tss, picPos, para.Hvo,
					(int)StTxtPara.StTxtParaTags.kflidContents, 0);
			}

			m_bookMerger.DetectDifferences(null);
			Assert.AreEqual(1, m_bookMerger.Differences.Count);
			return picPos;
		}
示例#9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adjust the footnotes in the archived book.
		/// </summary>
		/// <param name="hvoBook"></param>
		/// <param name="hvoArchivedBook"></param>
		/// ------------------------------------------------------------------------------------
		protected virtual void AdjustObjectsInArchivedBook(int hvoBook, int hvoArchivedBook)
		{
			if (m_cache.DatabaseAccessor == null)
				return;	// Can happen in tests

			// Now we need to re-hook up the footnotes. Oh, joy!
			bool fIsNull;
			uint cbSpaceTaken;

			// First we need to retrieve the mapping info to be able to go from existing footnote
			// GUIDs in the active book to archived footnote GUIDs.
			string sSql;
			List<Guid> bookFootnotes = new List<Guid>();
			List<Guid> revFootnotes = new List<Guid>();
			IOleDbCommand odc = null;

			try
			{
				m_cache.DatabaseAccessor.CreateCommand(out odc);
				sSql = string.Format("exec GetNewFootnoteGuids {0}, {1}", hvoBook, hvoArchivedBook);
				odc.ExecCommand(sSql, (int)SqlStmtType.knSqlStmtSelectWithOneRowset);
				odc.GetRowset(0);
				bool fMoreRows;
				odc.NextRow(out fMoreRows);

				while (fMoreRows)
				{
					using (ArrayPtr rgGuid = MarshalEx.ArrayToNative(1, typeof(Guid)))
					{
						odc.GetColValue(1, rgGuid, rgGuid.Size, out cbSpaceTaken, out fIsNull, 0);
						if (fIsNull)
							throw new Exception("Unable to archive draft -- Null guid for footnote");
						Guid[] guids = (Guid[])MarshalEx.NativeToArray(rgGuid, 1, typeof(Guid));
						bookFootnotes.Add(guids[0]);
						odc.GetColValue(2, rgGuid, rgGuid.Size, out cbSpaceTaken, out fIsNull, 0);
						if (fIsNull)
							throw new Exception("Unable to archive draft -- Null guid for footnote");
						guids = (Guid[])MarshalEx.NativeToArray(rgGuid, 1, typeof(Guid));
						revFootnotes.Add(guids[0]);
						odc.NextRow(out fMoreRows);
					}
				}
			}
			finally
			{
				DbOps.ShutdownODC(ref odc); // Has to be done, before the call to DbOps.ReadIntsFromCommand;
			}

			// Now we get a list of all the archived paragraphs that have ORCs in them, and
			// hunt for the footnotes and pictures.
			sSql = string.Format("exec GetParasWithORCs {0}", hvoArchivedBook);
			List<int> rghvoRevParas = DbOps.ReadIntsFromCommand(m_cache, sSql, null);

			ITsString tss;
			ITsStrBldr strBldr;
			ITsTextProps ttp;
			ITsPropsBldr propsBldr;
			int iFootnote = 0;
			foreach (int hvoRevPara in rghvoRevParas)
			{
				//TODO: TE- 5082 Duplicate code! The following should call or use common code with
				// StTxtPara.CreateOwnedObjects()
				bool fChanged = false;
				StTxtPara revPara = new StTxtPara(m_cache, hvoRevPara);
				tss = revPara.Contents.UnderlyingTsString;
				strBldr = tss.GetBldr();
				int cRun = tss.RunCount;
				TsRunInfo tri;
				byte[] objData;
				for (int iRun = 0; iRun < cRun; iRun++)
				{
					// Examine this run to see if it is an owned ORC
					FwObjDataTypes odt;
					Guid guid = StringUtils.GetOwnedGuidFromRun(tss, iRun, out odt, out tri, out ttp);
					if (guid != Guid.Empty)
					{
						switch (odt)
						{
							case FwObjDataTypes.kodtOwnNameGuidHot:
								// Probably a footnote. Make sure it's the next one in the
								// original sequence.
								if (guid == bookFootnotes[iFootnote])
								{
									// adjust the owned ORC
									objData = MiscUtils.GetObjData(revFootnotes[iFootnote],
										(byte)FwObjDataTypes.kodtOwnNameGuidHot);
									propsBldr = ttp.GetBldr();
									propsBldr.SetStrPropValueRgch(
										(int)FwTextPropType.ktptObjData,
										objData, objData.Length);
									strBldr.SetProperties(tri.ichMin, tri.ichLim,
										propsBldr.GetTextProps());
									// Look thru back translation and adjust ref ORCs for this footnote there
									AdjustBtFootnoteInArchivedBook(bookFootnotes[iFootnote],
										revFootnotes[iFootnote], revPara);
									fChanged = true;
									iFootnote++;
								}
								else if (bookFootnotes.Contains(guid))
								{
									// This footnote is out of order.
									Debug.Assert(false, "Fix GetParasWithORCs to return the paras in order");
								}
								else
								{
									// This footnote is not in the database
									Debug.Assert(false, "No footnote object owned by this book with guid: " +
										guid.ToString());
								}
								break;
							case FwObjDataTypes.kodtGuidMoveableObjDisp:
								// Get the original picture info
								int picHvo = m_cache.GetIdFromGuid(guid);
								CmPicture picture = new CmPicture(m_cache, picHvo);

								// Copy the picture and the file
								int newPicHvo = m_cache.CopyObject(picHvo, 0, 0);
								int newFileHvo = m_cache.CopyObject(picture.PictureFileRAHvo,
									m_cache.LangProject.Hvo,
									(int)LangProject.LangProjectTags.kflidPictures);

								//update the new picture info
								CmPicture newPicture = new CmPicture(m_cache, newPicHvo);
								newPicture.PictureFileRAHvo = newFileHvo;

								// update the ORC in the revision to point to the new picture
								Guid newPicGuid = m_cache.GetGuidFromId(newPicHvo);
								objData = MiscUtils.GetObjData(newPicGuid,
									(byte)FwObjDataTypes.kodtGuidMoveableObjDisp);
								propsBldr = ttp.GetBldr();
								propsBldr.SetStrPropValueRgch(
									(int)FwTextPropType.ktptObjData,
									objData, objData.Length);
								strBldr.SetProperties(tri.ichMin, tri.ichLim,
									propsBldr.GetTextProps());
								fChanged = true;
								break;
							default:
								throw new Exception("Found an unexpected kind of ORC");
						}
					}
				}
				if (fChanged)
				{
					// Save the new TS string
					// (but prevent side effects from ChangeWatchers)
					using (new IgnorePropChanged(m_cache, PropChangedHandling.SuppressChangeWatcher))
					{
						revPara.Contents.UnderlyingTsString = strBldr.GetString();
					}
				}
			}
		}
示例#10
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Create the CmPicture object for the given data.
		/// </summary>
		/// <param name="src"></param>
		/// <param name="oxesRef"></param>
		/// <param name="alt"></param>
		/// <returns>the guid of the CmPicture object, to use in the object reference property</returns>
		/// <param name="annotationsForPara">List of any annotations added or modified for this
		/// figure</param>
		/// <param name="segmentBTsForPara"></param>
		/// -----------------------------------------------------------------------------------
		private Guid StoreFigureData(string src, string oxesRef, string alt,
			List<IScrScriptureNote> annotationsForPara, List<BTSegment> segmentBTsForPara)
		{
			// TODO (TE-7539): Set Object ref for any annotations in annotationsForPara
			// TODO: figure out a way to use an existing CmPicture if one appears to be pointing
			// to the same file.
			// TODO: Figure out how to use segmented back translation information?

			// First try to find the picture in a standard subdirectory next to the OXES file.
			// If that fails, try to link to a matching picture file already stored in our
			// internal subdirectory.  If these both fail, then the picture will show as an
			// empty box.
			string sPath = Path.Combine(m_sOXESDir,
				String.Format("pictures{0}{1}", Path.DirectorySeparatorChar, src));
			ICmPicture pict;
			if (File.Exists(sPath))
			{
				pict = new CmPicture(m_cache, sPath, m_ParaBldr.StringBuilder.GetString(),
					EditingHelper.DefaultPictureFolder);
			}
			else
			{
				if (Path.IsPathRooted(src))
				{
					sPath = src;
				}
				else
				{
					sPath = String.Format("Pictures{0}{1}", Path.DirectorySeparatorChar, src);
					sPath = Path.Combine(m_cache.LangProject.ExternalLinkRootDir, sPath);
				}
				pict = new CmPicture(m_cache, sPath, m_ParaBldr.StringBuilder.GetString(),
					EditingHelper.DefaultPictureFolder);
				sPath = String.Format("Pictures{0}{1}", Path.DirectorySeparatorChar, src);
				if (File.Exists(Path.Combine(m_cache.LangProject.ExternalLinkRootDir, sPath)))
					pict.PictureFileRA.InternalPath = sPath;
			}
			foreach (int ws in m_BTStrBldrs.Keys)
				pict.Caption.SetAlternative(m_BTStrBldrs[ws].GetString(), ws);
			return pict.Guid;
		}
示例#11
0
		public void ExportPicture_MultipleWS()
		{
			// Create a picture that has a caption with three different writing systems.
			ITsStrBldr tssBldr = TsStrBldrClass.Create();
			ITsPropsBldr propsBldr = TsPropsBldrClass.Create();
			propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, InMemoryFdoCache.s_wsHvos.De);
			tssBldr.ReplaceRgch(0, 0, "photo", 5, propsBldr.GetTextProps());
			propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, InMemoryFdoCache.s_wsHvos.Ur);
			tssBldr.ReplaceRgch(tssBldr.Length, tssBldr.Length, " tasvir", 7, propsBldr.GetTextProps());
			propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, Cache.DefaultVernWs);
			tssBldr.ReplaceRgch(tssBldr.Length, tssBldr.Length, " picture caption", 16, propsBldr.GetTextProps());
			CmPicture picture = new CmPicture(m_inMemoryCache.Cache, @"c:\filename.jpg", tssBldr.GetString(), "folder");

			// Set up for export
			StringWriter stream = new StringWriter();
			XmlTextWriter writer = new XmlTextWriter(stream);
			writer.Formatting = Formatting.None;
			m_exporter = new ExportXml(null, Cache, null, ExportWhat.AllBooks, 0, 0, 0,
				"ExportPicture_MultipleWS");
			ReflectionHelper.SetField(m_exporter, "m_writer", writer);

			// Export the picture to XML
			ReflectionHelper.CallMethod(m_exporter, "ExportPicture", picture);

			// Check the results of the exported picture.
			//   Set up expected results.
			string defaultDir = DirectoryFinder.FWDataDirectory;
			// TODO (TE-7756): Support OXES export and import of new properties that have been
			// added to the CmPicture model
			string strExpected = "<figure src=\"filename.jpg\"><!--path=\"" + defaultDir + "\\filename\"-->" +
				"<caption><trGroup><tr><foreign xml:lang=\"de\">photo</foreign>" +
				"<foreign xml:lang=\"ur\"> tasvir</foreign> picture caption</tr></trGroup></caption></figure>";
			XmlDocument expected = new XmlDocument();
			expected.Load(new StringReader(strExpected));

			//   Get actual results.
			XmlDocument actual = new XmlDocument();
			actual.Load(new StringReader(stream.ToString()));

			string strDifference;
			if (!XmlHelper.CompareXmlNodes(expected.ChildNodes, actual.ChildNodes, out strDifference))
				Assert.Fail(strDifference);
		}
示例#12
0
		public void CreateOwnedObjects_Picture()
		{
			CheckDisposed();

			StTxtPara para = (StTxtPara)m_currentText.ParagraphsOS[0];

			ITsString tss = para.Contents.UnderlyingTsString;
			ITsStrFactory factory = TsStrFactoryClass.Create();
			using (DummyFileMaker fileMaker = new DummyFileMaker("junk.jpg", true))
			{
				CmPicture pict = new CmPicture(Cache, fileMaker.Filename,
					factory.MakeString("Test picture", Cache.DefaultVernWs),
					StringUtils.LocalPictures);
				pict.InsertORCAt(tss, 0, para.Hvo,
					(int)StTxtPara.StTxtParaTags.kflidContents, 0);
				tss = para.Contents.UnderlyingTsString;
				int cchOrigStringLength = tss.Length;

				NMock.DynamicMock mockIObjectMetaInfoProvider =
					new DynamicMock(typeof(IObjectMetaInfoProvider));
				mockIObjectMetaInfoProvider.Strict = true;
				mockIObjectMetaInfoProvider.ExpectAndReturn(1, "PictureFolder", StringUtils.LocalPictures);
				para.CreateOwnedObjects(0, 1,
					(IObjectMetaInfoProvider)mockIObjectMetaInfoProvider.MockInstance);
				mockIObjectMetaInfoProvider.Verify();

				tss = para.Contents.UnderlyingTsString;
				Assert.AreEqual(cchOrigStringLength, tss.Length);
				string sObjData = tss.get_Properties(0).GetStrPropValue((int)FwTextPropType.ktptObjData);
				Guid guid = MiscUtils.GetGuidFromObjData(sObjData.Substring(1));

				byte odt = Convert.ToByte(sObjData[0]);
				Assert.AreEqual((byte)FwObjDataTypes.kodtGuidMoveableObjDisp, odt);
				Assert.IsTrue(Cache.GetGuidFromId(pict.Hvo) != guid, "New guid was not inserted");
			}
		}
示例#13
0
		public void CmPictureConstructor_FromTextRep_MissingFilename()
		{
			CheckDisposed();
			ICmPicture pictNew = new CmPicture(Cache, "CmPicture||||||This is a caption||",
				StringUtils.LocalPictures);
		}
示例#14
0
		public void CmPictureConstructor_FullParamsMultipleDescriptionVariants()
		{
			CheckDisposed();
			Dictionary<int, string> descriptions = new Dictionary<int,string>();
			descriptions[Cache.DefaultAnalWs] = "My picture.";
			descriptions[Cache.DefaultVernWs] = "Mi foto.";
			ICmPicture pictNew = new CmPicture(Cache, StringUtils.LocalPictures, 0, null, descriptions,
				m_pict.PictureFileRA.AbsoluteInternalPath, "left", "1-2",
				"Don't use this picture in your book!",
				m_pict.Caption.VernacularDefaultWritingSystem.UnderlyingTsString,
				PictureLocationRangeType.ParagraphRange, "62");
			Assert.IsTrue(pictNew != m_pict);
			string internalPathNew = pictNew.PictureFileRA.InternalPath;
			Assert.AreEqual(pictNew.PictureFileRA.AbsoluteInternalPath, internalPathNew, "Files outside LangProject.ExtLinkRootDir are stored as absolute paths");
			m_internalFilesToDelete.Add(pictNew.PictureFileRA.AbsoluteInternalPath);
			Assert.AreEqual(m_internalPath, internalPathNew);
			AssertEx.AreTsStringsEqual(m_pict.Caption.VernacularDefaultWritingSystem.UnderlyingTsString,
				pictNew.Caption.VernacularDefaultWritingSystem.UnderlyingTsString);
			Assert.AreEqual(m_pict.PictureFileRA.OwnerHVO, pictNew.PictureFileRA.OwnerHVO);
			Assert.AreEqual("My picture.", pictNew.Description.AnalysisDefaultWritingSystem.Text);
			Assert.AreEqual("Mi foto.", pictNew.Description.VernacularDefaultWritingSystem.Text);
			Assert.AreEqual(PictureLayoutPosition.LeftAlignInColumn, pictNew.LayoutPos);
			Assert.AreEqual(62, pictNew.ScaleFactor);
			Assert.AreEqual(PictureLocationRangeType.ParagraphRange, pictNew.LocationRangeType);
			Assert.AreEqual(1, pictNew.LocationMin);
			Assert.AreEqual(2, pictNew.LocationMax);
			Assert.AreEqual("Don't use this picture in your book!",
				pictNew.PictureFileRA.Copyright.VernacularDefaultWritingSystem.Text);
		}
示例#15
0
		public void FixOrcsWithoutProps_OrphanedFootnoteAndValidPicture()
		{
			CheckDisposed();

			IScrBook exodus = CreateExodusData();
			StTxtPara para = AddPara(exodus.SectionsOS[2]);
			AddVerse(para, 2, 3, "ORC is here, you see, my friend.");

			// Update the paragraph contents to include the picture
			ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr();
			ITsStrFactory factory = TsStrFactoryClass.Create();
			CmPicture pict = new CmPicture(Cache, "c:\\junk.jpg",
				factory.MakeString("Test picture", Cache.DefaultVernWs),
				StringUtils.LocalPictures);
			Assert.IsNotNull(pict);
			pict.InsertOwningORCIntoPara(tsStrBldr, 11, 0);
			para.Contents.UnderlyingTsString = tsStrBldr.GetString();

			// Update the paragraph contents to include the (orphaned) footnote marker
			CreateFootnote(exodus, 1, 0, 1, 19, ScrStyleNames.CrossRefFootnoteParagraph, true);

			TeScrInitializer scrInit = new TestTeScrInitializer(Cache);
			List<string> report = (List<string>)ReflectionHelper.GetResult(scrInit, "FixOrcsWithoutProps");

			VerifyNoOrphanedFootnotes();
			VerifyResourceForFixedOrphans();

			Assert.AreEqual(1, report.Count);
			Assert.AreEqual("EXO 1:2 - Deleted corrupted footnote marker or picture anchor", report[0]);

			Assert.AreEqual(0, exodus.FootnotesOS.Count);
		}
示例#16
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates a picture object and inserts it into the cache's picture collection.
		/// </summary>
		/// <returns>The hvo of the picture.</returns>
		/// ------------------------------------------------------------------------------------
		private int CreateAndInsertPicture(int index, out string fileNameString)
		{
			// Load larger picture from resources and save it to file.
			Image resImage = TeResourceHelper.ImageNotFoundX;
			fileNameString = Guid.NewGuid() + ".bmp";
			resImage.Save(fileNameString);

			ITsStrFactory factory = TsStrFactoryClass.Create();
			CmPicture realPicture = new CmPicture(Cache, fileNameString,
				factory.MakeString(String.Empty, Cache.DefaultVernWs),
				EditingHelper.DefaultPictureFolder);

			return realPicture.Hvo;
		}
示例#17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create copies of any objects whose guids are owned by the given portion of the
		/// paragraph Contents. Use this when part of a string has just been replaced with a
		/// previous revision that may have object references.
		/// </summary>
		/// <param name="ichMin">The 0-based index of the first character to search for ORCs
		/// </param>
		/// <param name="ichLim">The 0-based index of the character following the last character
		/// to be searched</param>
		/// <param name="objInfoProvider">Object that can provide the correct footnote index or
		/// picture folder to use for copied objects
		/// </param>
		/// ------------------------------------------------------------------------------------
		public void CreateOwnedObjects(int ichMin, int ichLim,
			IObjectMetaInfoProvider objInfoProvider)
		{
			if (ichLim <= ichMin)
				return; // nothing to do

			ITsString paraContents = Contents.UnderlyingTsString;
			ITsTextProps ttp;
			TsRunInfo tri;
			int firstRun = paraContents.get_RunAt(ichMin);
			int lastRun = paraContents.get_RunAt(ichLim - 1);

			// these variables are initialized if needed as we process the runs
			ITsStrBldr paraBldr = null;
			int hvoFollowingFootnote = 0;
			int iFirstFootnote = -1;
			int footnoteCount = 0; // number of footnotes we have encountered in the given range
			ICmObject footnoteOwner = null;
			int footnoteFlid = 0;

			// Check each run, and create copies of the owned objects
			for (int iRun = firstRun; iRun <= lastRun; iRun++)
			{
				FwObjDataTypes odt;
				Guid guidOfObjToCopy = StringUtils.GetOwnedGuidFromRun(paraContents, iRun, out odt,
					out tri, out ttp);

				// if this run is an owning ORC...
				if (guidOfObjToCopy != Guid.Empty)
				{
					Guid guidOfNewObj = Guid.Empty;

					if (odt == FwObjDataTypes.kodtOwnNameGuidHot)
					{
						// If this is the first footnote created, get the correct starting index to use
						// TODO (TimS): if there are two footnotes together, we noticed some problems with getting the
						// correct footnote index
						if (iFirstFootnote == -1)
						{
							iFirstFootnote = objInfoProvider.NextFootnoteIndex(this, ichMin);
							GetFootnoteOwnerAndFlid(out footnoteOwner, out footnoteFlid);
							if (Cache.GetVectorSize(footnoteOwner.Hvo, footnoteFlid) > iFirstFootnote)
								hvoFollowingFootnote = Cache.GetVectorItem(footnoteOwner.Hvo, footnoteFlid, iFirstFootnote);
							else
								hvoFollowingFootnote = -1;
						}
						Debug.Assert(hvoFollowingFootnote != 0);
						Debug.Assert(iFirstFootnote > -1);
						// Create the new copy of the footnote.
						int hvoNewFootnote;
						int hvoFootnote = m_cache.GetIdFromGuid(guidOfObjToCopy);
						if (m_cache.IsValidObject(hvoFootnote))
						{
							hvoNewFootnote = m_cache.CopyObject(hvoFootnote, footnoteOwner.Hvo,
								footnoteFlid, hvoFollowingFootnote);
						}
						else
						{
							int iFootnote = iFirstFootnote + footnoteCount;
							// Unable to find footnote with this guid, so create a blank footnote.
							hvoNewFootnote = CreateBlankDummyFootnote(footnoteOwner, iFootnote,
								paraContents, iRun).Hvo;
						}
						guidOfNewObj = m_cache.GetGuidFromId(hvoNewFootnote);
						Debug.Assert(guidOfNewObj != guidOfObjToCopy);
						footnoteCount++;
					}
					else if (odt == FwObjDataTypes.kodtGuidMoveableObjDisp)
					{
						// Create the new copy of the picture.
						string textRep = m_cache.TextRepOfObj(guidOfObjToCopy);
						//REVIEW: when we support BT of a caption, be sure we copy it!
						CmPicture pict = new CmPicture(m_cache, textRep,
							objInfoProvider.PictureFolder);
						guidOfNewObj = m_cache.GetGuidFromId(pict.Hvo);
					}

					// If a new object was created, update all the ORCs for it
					if (guidOfNewObj != Guid.Empty)
					{
						// We re-use the same string builder for the paragraph contents.
						//  Just get it if this is the first time thru.
						if (paraBldr == null)
							paraBldr = paraContents.GetBldr();

						UpdateORCforNewObjData(paraBldr, ttp, tri, odt, guidOfNewObj);

						// In each translation, update any ORC from the old object, to the new
						UpdateOrcsInTranslations(guidOfObjToCopy, guidOfNewObj);
					}
				}
			}
			// save the updated paragraph string
			if (paraBldr != null)
			{
				// Finally, set the paragraph Contents to the new value
				// (but prevent side effects from ChangeWatchers)
				using (new IgnorePropChanged(m_cache, PropChangedHandling.SuppressChangeWatcher))
				{
					Contents.UnderlyingTsString = paraBldr.GetString();
				}
			}

			// if we inserted footnotes, do a PropChanged now that the footnotes and ORCs are in the db
			if (iFirstFootnote > -1)
			{
				m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, footnoteOwner.Hvo,
					footnoteFlid, iFirstFootnote, footnoteCount, 0);
			}
		}
示例#18
0
		public void DeletePictureInPara()
		{
			CheckDisposed();

			// Create pictures.
			string fileName1;
			CmPicture picture1 = new CmPicture();
			string folder = String.Empty;
			int hvoPic1 = CreateAndInsertPicture(0, out fileName1);
			try
			{
				// Create a book with one section and one paragraph with text.
				IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus");
				IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo);
				StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo,
					ScrStyleNames.NormalParagraph);
				m_scrInMemoryCache.AddRunToMockedPara(para, "This is the paragraph", null);
				section.AdjustReferences();

				// Insert picture ORC into paragraph at the beginning.
				int paraRunCountWithNoPict = para.Contents.UnderlyingTsString.RunCount;
				picture1 = new CmPicture(Cache, hvoPic1);
				picture1.InsertORCAt(para.Contents.UnderlyingTsString, 0, para.Hvo,
					(int)StTxtPara.StTxtParaTags.kflidContents, 0);
				string pic1Text1 = picture1.TextRepOfPicture;
				int startIndex = pic1Text1.IndexOf(@":") - 1;
				int stringLength = pic1Text1.LastIndexOf(@"\") - startIndex;
				folder = pic1Text1.Substring(startIndex, stringLength);
				m_draftView.RefreshDisplay();

				// select the  picture
				// 1/3 worked on the overnight build machine while 1/2 fails, so it can't be chosen programmatically reliably.
				// we click where we expect the picture is in the DummyDraftView form; 1/2 from top seems to work
				m_draftView.ScrollToEnd();
				m_draftView.CallMouseDown(new Point(m_draftView.ClientRectangle.Width / 2,
					m_draftView.ClientRectangle.Height / 2));
				//Application.DoEvents();

				// delete the  picture
				m_draftView.TeEditingHelper.DeletePicture();
				m_draftView.RefreshDisplay();

				// We expect that picture 1 will be deleted.
				Assert.AreEqual(0, Cache.GetClassOfObject(hvoPic1),
					"Picture object 1 is still in cache");

				Assert.AreEqual(paraRunCountWithNoPict, para.Contents.UnderlyingTsString.RunCount,
					"Paragraph's run count is invalid. Picture might not have been deleted.");

				Assert.AreEqual(null,
					para.Contents.UnderlyingTsString.get_Properties(0).GetStrPropValue(
					(int)FwTextPropType.ktptObjData),
					"The picture's ORC is still in the paragraph.");
			}
			finally
			{
				m_draftView.Dispose();
				// Remove picture files that were created for this test in StringUtils.LocalPictures
				if (File.Exists(fileName1))
					File.Delete(fileName1);
				if (File.Exists(folder + @"\" + fileName1))
					File.Delete(folder + @"\" + fileName1);
			}
		}
示例#19
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create a picture (no caption set).
		/// </summary>
		/// <param name="para">Paragraph to insert picture into</param>
		/// <param name="ichPos">The 0-based character offset into the paragraph</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		protected ICmPicture InsertTestPicture(StTxtPara para, int ichPos)
		{
			// Create the picture
			ICmFolder folder = m_fdoCache.LangProject.PicturesOC.Add(new CmFolder());
			ICmFile file = folder.FilesOC.Add(new CmFile());
			file.InternalPath = "there";
			int newHvo = m_fdoCache.CreateObject(CmPicture.kClassId);
			ICmPicture picture = new CmPicture(m_fdoCache, newHvo);
			picture.PictureFileRA = file;

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

			return picture;
		}
示例#20
0
		public void DeletePictureTwoInPara()
		{
			CheckDisposed();

			// Create pictures.
			string fileName1, fileName2;
			CmPicture picture1;
			CmPicture picture2;
			string folder = String.Empty;
			int hvoPic1 = CreateAndInsertPicture(0, out fileName1);
			int hvoPic2 = CreateAndInsertPicture(1, out fileName2);
			try
			{
				// Create a book with one section and one paragraph with text.
				IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(3, "Leviticus");
				IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo);
				StTxtPara para = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo,
					ScrStyleNames.NormalParagraph);
				m_scrInMemoryCache.AddRunToMockedPara(para, "This is the paragraph", null);
				section.AdjustReferences();

				// Insert picture ORCs into paragraph, at the beginning.
				picture1 = new CmPicture(Cache, hvoPic1);
				picture1.InsertORCAt(para.Contents.UnderlyingTsString, 0, para.Hvo,
					(int)StTxtPara.StTxtParaTags.kflidContents, 0);
				int paraRunCountWithOnePict = para.Contents.UnderlyingTsString.RunCount;

				picture2 = new CmPicture(Cache, hvoPic2);
				picture2.InsertORCAt(para.Contents.UnderlyingTsString, 1, para.Hvo,
					(int)StTxtPara.StTxtParaTags.kflidContents, 0);

				string pic1Text1 = picture1.TextRepOfPicture;
				int startIndex = pic1Text1.IndexOf(@":") - 1;
				int stringLength = pic1Text1.LastIndexOf(@"\") - startIndex;
				folder = pic1Text1.Substring(startIndex, stringLength);
				m_draftView.RefreshDisplay();

				// Select the second picture. We click where we expect the picture is in the
				// DummyDraftView form; half the picture height above the bottom seems to work
				// NOTE: It would be better to select the picture programmatically. However,
				// MakeSelInObj doesn't work; we probably need a new method to allow this.
				// Currently there seems to be no way to programmatically (or with the keyboard)
				// select a picture.
				m_draftView.ScrollToEnd();
				m_draftView.CallMouseDown(new Point(m_draftView.ClientRectangle.Width / 2,
					m_draftView.ClientRectangle.Height -
					(TeResourceHelper.ImageNotFoundX.Height / 2)));

				// delete the second picture
				m_draftView.TeEditingHelper.DeletePicture();
				m_draftView.RefreshDisplay();

				// We expect that picture 1 will still be in the cache, but picture 2 will be deleted.
				Assert.AreNotEqual(0, Cache.GetClassOfObject(hvoPic1),
					"Picture object 1 is not in cache");
				Assert.AreEqual(0, Cache.GetClassOfObject(hvoPic2),
					"Picture object 2 is still in cache");

				Assert.AreEqual(paraRunCountWithOnePict, para.Contents.UnderlyingTsString.RunCount,
					"Paragraph's run count is invalid. Second picture might not have been deleted.");

				Assert.AreEqual(null,
					para.Contents.UnderlyingTsString.get_Properties(1).GetStrPropValue(
					(int)FwTextPropType.ktptObjData),
					"The second picture's ORC is still in the paragraph.");
			}
			finally
			{
				m_draftView.Dispose();
				// Remove picture files that were created for this test in StringUtils.LocalPictures
				if (File.Exists(fileName1))
					File.Delete(fileName1);
				if (File.Exists(fileName2))
					File.Delete(fileName2);
				if (File.Exists(folder + @"\" + fileName1))
						File.Delete(folder + @"\" + fileName1);
				if (File.Exists(folder + @"\" + fileName2))
					File.Delete(folder + @"\" + fileName2);
			}
		}
示例#21
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates a picture object and inserts it into the cache's picture collection.
		/// </summary>
		/// <returns>The hvo of the picture.</returns>
		/// ------------------------------------------------------------------------------------
		private int CreateAndInsertPicture()
		{
			int pictureCount = Cache.LangProject.PicturesOC.Count;

			int hvoFolder = Cache.CreateObject(CmFolder.kClassId,
				Cache.LangProject.Hvo,
				(int)LangProject.LangProjectTags.kflidPictures, 0);
			CmFolder folder = new CmFolder(Cache, hvoFolder, true, true);
			CmFile file = new CmFile();
			folder.FilesOC.Add(file);

			int hvoPict = Cache.CreateObject(CmPicture.kclsidCmPicture);
			CmPicture picture = new CmPicture(Cache, hvoPict, true, true);
			picture.PictureFileRA = file;

			// Make sure the picture got added to the cache's picture collection.
			Assert.AreEqual(pictureCount + 1, Cache.LangProject.PicturesOC.Count);

			return picture.Hvo;
		}
示例#22
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Insert a picture at the current selection of the active rootsite.
		/// </summary>
		/// <param name="initialPicture">The existing CmPicture being modified, if any</param>
		/// <param name="srcFilename">The path to the original filename (an internal copy will
		/// be made in this method)</param>
		/// <param name="captionTss">The caption</param>
		/// <param name="sFolder">The name of the CmFolder where picture should be stored</param>
		/// ------------------------------------------------------------------------------------
		public void UpdatePicture(CmPicture initialPicture, string srcFilename,
			ITsString captionTss, string sFolder)
		{
			CheckDisposed();

			initialPicture.UpdatePicture(srcFilename, captionTss, sFolder);
		}
示例#23
0
		public void FindPictureInVerse_Found()
		{
			CheckDisposed();
			CreateExodusData();
			StTxtPara paraS1P0 = (StTxtPara)m_scr.ScriptureBooksOS[0].SectionsOS[1].ContentOA.ParagraphsOS[0];
			ITsString tss = paraS1P0.Contents.UnderlyingTsString;
			ITsStrFactory factory = TsStrFactoryClass.Create();
			using (DummyFileMaker fileMaker = new DummyFileMaker("junk.jpg", true))
			{
				CmPicture pict = new CmPicture(Cache, fileMaker.Filename,
					factory.MakeString("Test picture picture", Cache.DefaultVernWs),
					StringUtils.LocalPictures);
				int positionToInsertOrc = tss.Length;
				pict.InsertORCAt(tss, positionToInsertOrc, paraS1P0.Hvo,
					(int)StTxtPara.StTxtParaTags.kflidContents, 0);
				int iSection, iPara, ichOrcPos;
				Assert.IsTrue(m_editingHelper.FindPictureInVerse(new ScrReference(02001002, m_scr.Versification), pict.Hvo,
					out iSection, out iPara, out ichOrcPos));
				Assert.AreEqual(1, iSection);
				Assert.AreEqual(0, iPara);
				Assert.AreEqual(positionToInsertOrc, ichOrcPos);
			}
		}
示例#24
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Insert a picture at the current selection of the active rootsite.
		/// </summary>
		/// <param name="srcFilename">The path to the original filename (an internal copy will
		/// be made in this method)</param>
		/// <param name="captionTss">The caption</param>
		/// <param name="sFolder">The name of the CmFolder where picture should be stored</param>
		/// ------------------------------------------------------------------------------------
		public CmPicture InsertPicture(string srcFilename, ITsString captionTss, string sFolder)
		{
			CheckDisposed();

			CmPicture pict = new CmPicture(m_cache, srcFilename, captionTss, sFolder);
			// Add the ORC to the text at the insertion point.
			InsertPicture(pict);
			return pict;
		}
示例#25
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Selects the given note's cited text in a picture caption.
		/// </summary>
		/// <param name="iBook">The index of the book in the filter (this is passed as a
		/// convenience -- it could be recalculated).</param>
		/// <param name="note">The note.</param>
		/// ------------------------------------------------------------------------------------
		private void SelectCitedTextInPictureCaption(int iBook, IScrScriptureNote note)
		{
			try
			{
				CmPicture picture = new CmPicture(Cache, note.BeginObjectRAHvo);
				int iSection, iPara, ichOrcPos;
				ITsString citedText = note.CitedTextTss;
				if (!FindPictureInVerse(new ScrReference(note.BeginRef, m_scr.Versification),
					picture.Hvo, out iSection, out iPara, out ichOrcPos))
				{
					throw new Exception("Picture ORC not found in verse"); // See catch
				}
				int ichStart, ichEnd;
				ITsString sCaptionText = picture.Caption.VernacularDefaultWritingSystem.UnderlyingTsString;
				if (sCaptionText.Length >= note.EndOffset &&
					StringUtils.Substring(sCaptionText, note.BeginOffset,
					note.EndOffset - note.BeginOffset) == citedText)
				{
					ichStart = note.BeginOffset;
					ichEnd = note.EndOffset;
				}
				else
				{
					// Search for word form in caption
					if (!StringUtils.FindWordFormInString(citedText, sCaptionText,
						m_cache.LanguageWritingSystemFactoryAccessor, out ichStart, out ichEnd))
					{
						ichStart = ichEnd = 0;
					}
				}
				MakeSelectionInPictureCaption(iBook, iSection,
					(int)ScrSection.ScrSectionTags.kflidContent, iPara,
					ichOrcPos, ichStart, ichEnd);
			}
			catch
			{
				// Picture or caption no longer exists. Go to the start of the specified verse.
				GotoVerse(new ScrReference(note.BeginRef, m_scr.Versification));
				return;
			}
		}
示例#26
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Inserts a ORC pointing to hvoObjToInsert at the current selection location.
		/// Enhance JohnT: should move this to RootSite or similar location where all clients
		/// can readily use it.
		/// </summary>
		/// <param name="pict">The picture to insert</param>
		/// ------------------------------------------------------------------------------------
		private void InsertPicture(CmPicture pict)
		{
			// get selection information
			ITsString tss;
			int ich;
			bool fAssocPrev;
			int hvoObj;
			int ws;
			int propTag;
			CurrentSelection.Selection.TextSelInfo(true, out tss, out ich, out fAssocPrev,
				out hvoObj, out propTag, out ws);
			SelectionHelper oldSelection = CurrentSelection;

			// If inserting a picture over a user prompt, need to set up info for a proper insertion
			// in the empty paragraph.
			if (propTag == SimpleRootSite.kTagUserPrompt)
			{
				ich = 0;
				ITsStrFactory factory = TsStrFactoryClass.Create();
				tss = factory.MakeString(string.Empty, m_cache.DefaultVernWs);
				propTag = (int)StTxtPara.StTxtParaTags.kflidContents;
			}

			InsertPictureOrc(pict, tss, ich, hvoObj, propTag, ws);
			SelectionHelper helper = CurrentSelection;
			if (helper == null)
			{
				oldSelection.SetTextPropId(SelectionHelper.SelLimitType.Anchor, (int)StTxtPara.StTxtParaTags.kflidContents);
				oldSelection.SetTextPropId(SelectionHelper.SelLimitType.End, (int)StTxtPara.StTxtParaTags.kflidContents);
				oldSelection.IchAnchor = 0;
				oldSelection.IchEnd = 0;
				oldSelection.SetSelection(true);
				Debug.Assert(CurrentSelection != null);
			}
			else
			{
				helper.IchAnchor = helper.IchEnd = ich + 1;
				helper.SetSelection(true);
			}
		}
示例#27
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Inserts a picture, either using the current segment (USFM-style) or the pending
		/// picture in m_currPictureInfo.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected void InsertPicture()
		{
			CmPicture picture;
			if (m_currPictureInfo == null)
			{
				string[] tokens = m_sSegmentText.Split(new char[] {'|'});
				if (tokens.Length < 6)
					throw new ArgumentException("The USFM format for a Picture was invalid");
				string sDescription = tokens[0];
				string srcFilename = tokens[1];
				if (String.IsNullOrEmpty(srcFilename))
					srcFilename = Path.Combine(DirectoryFinder.FWCodeDirectory, "MissingPictureInImport.bmp");
				string sLayoutPos = tokens[2];
				string sLocationRange = tokens[3];
				string sCopyright = tokens[4];
				string sCaption = tokens[5];
				picture = new CmPicture(m_cache, EditingHelper.DefaultPictureFolder,
					m_currentRef.BBCCCVVV, m_scr as IPictureLocationBridge, sDescription,
					srcFilename, sLayoutPos, sLocationRange, sCopyright, sCaption,
					PictureLocationRangeType.ReferenceRange, "100");
			}
			else
			{
				string srcFilename = m_currPictureInfo.PictureFilename;
				if (String.IsNullOrEmpty(srcFilename))
					srcFilename = Path.Combine(DirectoryFinder.FWCodeDirectory, "MissingPictureInImport.bmp");
				picture = new CmPicture(m_cache, EditingHelper.DefaultPictureFolder,
					m_currentRef.BBCCCVVV, m_scr as IPictureLocationBridge,
					m_currPictureInfo.Description, srcFilename,
					m_currPictureInfo.LayoutPos, m_currPictureInfo.LocationRange,
					m_currPictureInfo.Copyright, m_currPictureInfo.TssCaption,
					PictureLocationRangeType.ReferenceRange, m_currPictureInfo.ScaleFactor);
				m_currPictureInfo = null;
			}
			picture.AppendPicture(GetWsForContext(m_ParaBldr.StringBuilder),
				m_ParaBldr.StringBuilder);
			m_CurrParaPictures.Add(picture);
		}
示例#28
0
		/// <summary>
		/// This method is broken out so TeEditingHelper can override and adjust annotations.
		/// Probably anything else that does it will need to adjust annotations, too, but nothing
		/// else yet uses this kind of picture in an StText.
		/// </summary>
		protected virtual void InsertPictureOrc(CmPicture pict, ITsString tss, int ich, int hvoObj, int propTag, int ws)
		{
			pict.InsertORCAt(tss, ich, hvoObj, propTag, ws);
		}
示例#29
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Make sure picture exists and is referred to properly in the paragraph contents
		/// </summary>
		/// <param name="pictureOrig">The original picture</param>
		/// <param name="para"></param>
		/// <param name="ich">Character position where ORC should be</param>
		/// ------------------------------------------------------------------------------------
		private void VerifyPicture(ICmPicture pictureOrig, IStTxtPara para, int ich)
		{
			ITsString tss = para.Contents.UnderlyingTsString;
			int iRun = tss.get_RunAt(ich);
			ITsTextProps orcPropsParaFootnote = tss.get_Properties(iRun);
			string objData = orcPropsParaFootnote.GetStrPropValue(
				(int)FwTextPropType.ktptObjData);
			Assert.AreEqual((char)(int)FwObjDataTypes.kodtGuidMoveableObjDisp, objData[0]);

			// Send the objData string without the first character because the first character
			// is the object replacement character and the rest of the string is the GUID.
			Guid newPicGuid = MiscUtils.GetGuidFromObjData(objData.Substring(1));
			int newPicHvo = m_fdoCache.GetIdFromGuid(newPicGuid);
			Assert.IsTrue(pictureOrig.Guid != newPicGuid);
			Assert.IsTrue(pictureOrig.Hvo != newPicHvo);
			string sOrc = tss.get_RunText(iRun);
			Assert.AreEqual(StringUtils.kchObject, sOrc[0]);

			CmPicture pictureNew = new CmPicture(m_fdoCache, newPicHvo);
			Assert.IsTrue(pictureOrig.PictureFileRAHvo != pictureNew.PictureFileRAHvo);
			Assert.AreEqual(pictureOrig.PictureFileRA.InternalPath,
				pictureNew.PictureFileRA.InternalPath);
		}
示例#30
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();
		}