Example #1
0
        public void GetFootnoteMarkerFromGuid()
        {
            StFootnote footnote = new StFootnote();

            m_scr.ScriptureBooksOS[0].FootnotesOS.Append(footnote);
            footnote.FootnoteMarker.Text = "a";

            Guid guid = m_fdoCache.GetGuidFromId(footnote.Hvo);

            // Add the guid property so we can get it out as a string.
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            byte[] objData = MiscUtils.GetObjData(guid, 1);
            propsBldr.SetStrPropValueRgch(1, objData, objData.Length);

            // Get the guid property as a string.
            string sObjData;

            propsBldr.GetStrPropValue(1, out sObjData);

            using (StVc vc = new StVc())
            {
                vc.Cache     = m_fdoCache;
                vc.DefaultWs = m_fdoCache.LanguageWritingSystemFactoryAccessor.UserWs;
                ITsString footnoteMarker = vc.GetStrForGuid(sObjData.Substring(1));

                Assert.AreEqual("2", footnoteMarker.Text);
            }
        }
Example #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Append a picture to the end of the paragraph using the given writing system.
        /// </summary>
        /// <param name="ws">given writing system</param>
        /// <param name="strBldr">The string builder for the paragraph being composed</param>
        /// ------------------------------------------------------------------------------------
        public void AppendPicture(int ws, ITsStrBldr strBldr)
        {
            // Make a TsTextProps with the relevant object data and the same ws as its
            // context.
            byte[] objData = MiscUtils.GetObjData(m_cache.GetGuidFromId(this.Hvo),
                                                  (byte)FwObjDataTypes.kodtGuidMoveableObjDisp);
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData,
                                          objData, objData.Length);
            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, ws);

            // Insert the orc with the resulting properties.
            strBldr.Replace(strBldr.Length, strBldr.Length,
                            new string(StringUtils.kchObject, 1), propsBldr.GetTextProps());
        }
Example #3
0
        public void GetFootnoteMarkerFromGuid()
        {
            IScrFootnote footnote = Cache.ServiceLocator.GetInstance <IScrFootnoteFactory>().Create();

            m_scr.ScriptureBooksOS[0].FootnotesOS.Add(footnote);
            footnote.FootnoteMarker = Cache.TsStrFactory.MakeString("a", Cache.WritingSystemFactory.GetWsFromStr("en"));

            // Add the guid property so we can get it out as a string.
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            byte[] objData = TsStringUtils.GetObjData(footnote.Guid, 1);
            propsBldr.SetStrPropValueRgch(1, objData, objData.Length);

            // Get the guid property as a string.
            string sObjData;

            propsBldr.GetStrPropValue(1, out sObjData);

            StVc vc = new StVc(Cache.WritingSystemFactory.UserWs)
            {
                Cache = Cache
            };
            ITsString footnoteMarker = vc.GetStrForGuid(sObjData.Substring(1));

            // Call to GetStrForGuid doesn't generate a footnote marker based on the
            // Scripture Footnote properties since the method to do that is in TeStVc.
            int dummy;

            Assert.AreEqual(StringUtils.kszObject, footnoteMarker.Text);
            ITsTextProps props = footnoteMarker.get_Properties(0);

            Assert.AreEqual(2, props.IntPropCount);
            Assert.AreEqual(Cache.DefaultUserWs, props.GetIntPropValues((int)FwTextPropType.ktptWs, out dummy));
            Assert.AreEqual(0, props.GetIntPropValues((int)FwTextPropType.ktptEditable, out dummy));
            Assert.AreEqual(1, props.StrPropCount);

            FwObjDataTypes odt;
            Guid           footnoteGuid = TsStringUtils.GetGuidFromProps(props, null, out odt);

            Assert.IsTrue(odt == FwObjDataTypes.kodtPictEvenHot || odt == FwObjDataTypes.kodtPictOddHot);
            Assert.AreEqual(footnote.Guid, footnoteGuid);
        }
Example #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Inserts an ORC pointing to this picture at the specified location.
        /// </summary>
        /// <param name="tss">String into which ORC is to be inserted</param>
        /// <param name="ich">character offset where insertion is to occur</param>
        /// <param name="hvoObj">The object that owns the given tss</param>
        /// <param name="flid">The owning flid of the tss</param>
        /// <param name="ws">The writing system alternative (used only for multi's)</param>
        /// ------------------------------------------------------------------------------------
        public void InsertORCAt(ITsString tss, int ich, int hvoObj, int flid, int ws)
        {
            // REVIEW: Why do we have InsertORCAt when InsertOwningORCIntoPara probably does much
            // the same thing? InsertORCAt is used in production code. InsertOwningORCIntoPara is
            // used in some tests.
            System.Diagnostics.Debug.Assert(tss.Length >= ich);

            // Make a TsTextProps with the relevant object data and the same ws as its
            // context.
            byte[] objData = MiscUtils.GetObjData(m_cache.GetGuidFromId(Hvo),
                                                  (byte)FwObjDataTypes.kodtGuidMoveableObjDisp);
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData,
                                          objData, objData.Length);
            int nvar;
            int wsRun = tss.get_PropertiesAt(ich).
                        GetIntPropValues((int)FwTextPropType.ktptWs, out nvar);

            propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsRun);

            // Insert the orc with the resulting properties.
            ITsStrBldr tsStrBldr = tss.GetBldr();

            tsStrBldr.Replace(ich, ich, new string(StringUtils.kchObject, 1),
                              propsBldr.GetTextProps());

            if (ws == 0)
            {
                m_cache.SetTsStringProperty(hvoObj, flid, tsStrBldr.GetString());
            }
            else
            {
                // This branch has probably not been tested, not currently used.
                m_cache.SetMultiStringAlt(hvoObj, flid, ws, tsStrBldr.GetString());
            }
        }
Example #5
0
 /// <summary>
 /// Sets a string property by passing a byte array and length.
 /// This method is only used by Views.
 /// </summary>
 public void SetStrPropValueRgch(int tpt, byte[] rgchVal, int nValLength)
 {
     m_propsBldr.SetStrPropValueRgch(tpt, rgchVal, nValLength);
 }
Example #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Fixes all orphaned footnotes or pictures in the given list.
        /// </summary>
        /// <param name="book">The book being fixed (needed in case we have to re-order
        /// footnotes.</param>
        /// <param name="orcLocations">List of locations of ORCs.</param>
        /// <param name="footnotes">List of footnotes and their associated ORC locations if
        /// they were found.</param>
        /// <param name="issuesToReport">List of descriptions of any problems fix or any
        /// remaining problems that the user might still need to fix</param>
        /// ------------------------------------------------------------------------------------
        private void FixOrcsWithoutProps(IScrBook book, List <OrcLocation> orcLocations,
                                         List <FootnoteOrcLocation> footnotes, List <string> issuesToReport)
        {
            int         iFootnote = 0;
            OrcLocation orc;

            for (int i = 0; i < orcLocations.Count; i++)
            {
                orc = orcLocations[i];
                if (orc.Footnote != null)
                {
                    while (iFootnote < footnotes.Count && footnotes[iFootnote++].footnote != orc.Footnote)
                    {
                        issuesToReport.Add(String.Format("{0} - Footnote {1} has no corresponding marker",
                                                         book.BookId, iFootnote));
                    }
                    continue;
                }

                IStTxtPara para = orc.para;
                ITsStrBldr bldr = para.Contents.GetBldr();

                ITsPropsBldr        propsBldr       = bldr.get_PropertiesAt(orc.ich).GetBldr();
                FootnoteOrcLocation currentFootnote = iFootnote < footnotes.Count ? footnotes[iFootnote] : null;

                if (currentFootnote == null || currentFootnote.location != null)
                {
                    // Remove the ORC and report it.
                    bldr.Replace(orc.ich, orc.ich + 1, null, null);
                    issuesToReport.Add(String.Format(Properties.Resources.kstidCorruptedOrcRemoved,
                                                     orc.ToString(m_scr)));

                    // Adjust ORC offsets for any other ORCs in this same para.
                    OrcLocation adjOrc;
                    for (int j = i + 1; j < orcLocations.Count; j++)
                    {
                        adjOrc = orcLocations[j];
                        if (adjOrc.para == orc.para)
                        {
                            adjOrc.ich--;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    IStFootnote footnote = currentFootnote.footnote;

                    byte[] footnoteObjData = TsStringUtils.GetObjData(footnote.Guid, (byte)FwObjDataTypes.kodtNameGuidHot);
                    propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData, footnoteObjData, footnoteObjData.Length);

                    bldr.SetProperties(orc.ich, orc.ich + 1, propsBldr.GetTextProps());
                    currentFootnote.location = orc;  // No longer an orphan :-)
                    iFootnote++;                     // We're now using this one

                    issuesToReport.Add(String.Format(Properties.Resources.kstidConnectedFootnoteToMarker, orc.ToString(m_scr)));
                }

                para.Contents = bldr.GetString();
            }

            while (iFootnote < footnotes.Count)
            {
                Debug.Assert(footnotes[iFootnote].location == null);
                issuesToReport.Add(String.Format(Properties.Resources.kstidNoMarkerForFootnote,
                                                 book.BookId, ++iFootnote));
            }
        }
Example #7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds object link data to the specified text property builder
		/// </summary>
		/// <param name="propsBldr">The props builder.</param>
		/// <param name="attr">The attribute to process.</param>
		/// <param name="type">The type of object data to be added to the text properties.</param>
		/// ------------------------------------------------------------------------------------
		private static void AddObjDataToBldr(ITsPropsBldr propsBldr, XAttribute attr, FwObjDataTypes type)
		{
			byte[] objData = TsStringUtils.GetObjData(new Guid(attr.Value), (byte)type);
			propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData, objData, objData.Length);
		}
Example #8
0
 /// <summary>
 /// Sets the specified property to the string value represented by the specified byte array.
 /// </summary>
 public static void SetStringValue(this ITsPropsBldr tpb, FwTextPropType tpt, byte[] value)
 {
     tpb.SetStrPropValueRgch((int)tpt, value, value == null ? 0 : value.Length);
 }