Ejemplo n.º 1
0
        private void spyOnTextProps(ITsTextProps ttp)
        {
            int tpt;             // ??

            // look at integer props
            int cintProps = ttp.IntPropCount;

            for (int i = 0; i < cintProps; i++)
            {
                int nVar;
                int intProp = ttp.GetIntProp(i, out tpt, out nVar);
                int Value   = ttp.GetIntPropValues(tpt, out nVar);
                Value = 34;                 // need something so Value can be looked at
            }

            // look at string props
            int cstrProps = ttp.StrPropCount;

            for (int i = 0; i < cstrProps; i++)
            {
                string strProp = ttp.GetStrProp(i, out tpt);
                string Value   = ttp.GetStrPropValue(tpt);
                Value = "why?";                 // need something so Value can be looked at
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the string property at the specified index.
        /// </summary>
        public static string GetStringProperty(this ITsTextProps textProps, int index, out FwTextPropType tpt)
        {
            int    t;
            string value = textProps.GetStrProp(index, out t);

            tpt = (FwTextPropType)t;
            return(value);
        }
Ejemplo n.º 3
0
        public TsTextProps FromITsTextProps(ITsTextProps ttp)
        {
            var bldr          = new TsPropsBldr();
            int countIntProps = ttp.IntPropCount;

            for (int i = 0; i < countIntProps; i++)
            {
                int tpt, ttv;
                var val = ttp.GetIntProp(i, out tpt, out ttv);
                bldr.SetIntPropValues(tpt, ttv, val);
            }

            int countStrProps = ttp.StrPropCount;

            for (int i = 0; i < countStrProps; i++)
            {
                int tpt;
                var val = ttp.GetStrProp(i, out tpt);
                bldr.SetStrPropValue(tpt, val);
            }
            return((TsTextProps)bldr.GetTextProps());
        }
 public static List<string> ClassesFromTsTextProps(ITsTextProps props, int[] intPropsToSkip, int[] strPropsToSkip)
 {
     var classes = new List<string>();
     for (int i = 0, n = props.IntPropCount; i < n; i++)
     {
         int propNum;
         int variation;
         int propValue = props.GetIntProp(i, out propNum, out variation);
         if (intPropsToSkip.Contains(propNum))
             continue;
         string className = String.Format("propi_{0}_{1}_{2}_{3}", propNum, IntPropertyName(propNum), propValue, variation);
         classes.Add(className);
     }
     for (int i = 0, n = props.StrPropCount; i < n; i++)
     {
         int propNum;
         string propValue = props.GetStrProp(i, out propNum).Replace(" ", "_SPACE_");
         string className = String.Format("props_{0}_{1}_{2}", propNum, StringPropertyName(propNum), propValue);
         if (strPropsToSkip.Contains(propNum))
             continue;
         classes.Add(className);
     }
     return classes;
 }
Ejemplo n.º 5
0
        public static List <string> ClassesFromTsTextProps(ITsTextProps props, int[] intPropsToSkip, int[] strPropsToSkip)
        {
            var classes = new List <string>();

            for (int i = 0, n = props.IntPropCount; i < n; i++)
            {
                int propNum;
                int variation;
                int propValue = props.GetIntProp(i, out propNum, out variation);
                if (intPropsToSkip.Contains(propNum))
                {
                    continue;
                }
                string className = String.Format("propi_{0}_{1}_{2}_{3}", propNum, IntPropertyName(propNum), propValue, variation);
                classes.Add(className);
            }
            for (int i = 0, n = props.StrPropCount; i < n; i++)
            {
                int    propNum;
                string propValue = props.GetStrProp(i, out propNum);
                if (propNum == (int)FwTextStringProp.kstpObjData)
                {
                    // Object data can have arbitrary bytes, including null.
                    propValue = HexEncode(propValue);
                }
                // In any other property type, the only problematic value is a space character.
                propValue = propValue.Replace(" ", "_SPACE_");
                string className = String.Format("props_{0}_{1}_{2}", propNum, StringPropertyName(propNum), propValue);
                if (strPropsToSkip.Contains(propNum))
                {
                    continue;
                }
                classes.Add(className);
            }
            return(classes);
        }
Ejemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Compares two TsTextProps
        /// </summary>
        /// <param name="ttp1">expected</param>
        /// <param name="ttp2">actual</param>
        /// <param name="sHowDifferent">Human(geek)-readable string telling how the props are
        /// different, or indicating no difference</param>
        /// <returns>True if they contain the same props, false otherwise</returns>
        /// ------------------------------------------------------------------------------------
        public static bool PropsAreEqual(ITsTextProps ttp1, ITsTextProps ttp2,
                                         out string sHowDifferent)
        {
            // check how intProps compare
            int cProps1 = ttp1.IntPropCount;
            int cProps2 = ttp2.IntPropCount;
            int tpv1, tpv2;      // prop values
            int nVar1, nVar2;    // variation info
            int tpt;             // prop type

            for (int iprop = 0; iprop < cProps1; iprop++)
            {
                tpv1 = ttp1.GetIntProp(iprop, out tpt, out nVar1);
                tpv2 = ttp2.GetIntPropValues(tpt, out nVar2);

                if (tpv1 != tpv2 || nVar1 != nVar2)
                {
                    if (tpt == (int)FwTextPropType.ktptWs)
                    {
                        sHowDifferent = string.Format("Props differ in ktptWs property. "
                                                      + "Expected <{0}>, but was <{1}>.", tpv1, tpv2);
                    }
                    else
                    {
                        sHowDifferent = string.Format("Props differ in intProp type {0}. "
                                                      + "Expected <{1},{2}>, but was <{3},{4}>.", tpt, tpv1, nVar1, tpv2, nVar2);
                    }
                    return(false);
                }
            }
            // if count of intProps differs, it will be difficult to report exact difference
            //  so just issue a simple response for now
            if (cProps1 != cProps2)
            {
                sHowDifferent = string.Format("Props differ in count of intProps. "
                                              + "Expected <{0}>, but was <{1}>.", cProps1, cProps2);
                return(false);
            }

            // check for string properties differences
            int    s1count = ttp1.StrPropCount;
            int    s2count = ttp2.StrPropCount;
            int    strtype;
            string strval1, strval2;             // prop values

            for (int iprop = 0; iprop < s1count; iprop++)
            {
                strval1 = ttp1.GetStrProp(iprop, out strtype);
                strval2 = ttp2.GetStrPropValue(strtype);

                if (strval1 != strval2)
                {
                    if (strtype == (int)FwTextPropType.ktptNamedStyle)
                    {
                        sHowDifferent = string.Format("Props differ in ktptNamedStyle property. "
                                                      + "Expected <{0}>, but was <{1}>.", strval1, strval2);
                    }
                    else if (strtype == (int)FwTextPropType.ktptObjData)
                    {
                        sHowDifferent = string.Format("Props differ in ktptObjData property. "
                                                      + "Expected <{0}>, but was <{1}>.", strval1, strval2);
                    }
                    // we could detail the objectDataType and Guid if needed
                    else
                    {
                        sHowDifferent = string.Format("Props differ in strProp type {0}. "
                                                      + "Expected <{1}>, but was <{2}>.", strtype, strval1, strval2);
                    }
                    return(false);
                }
            }
            // if count of strProps differs, it will be difficult to report exact difference
            //  so just issue a simple response for now
            if (s1count != s2count)
            {
                sHowDifferent = string.Format("Props differ in count of strProps. "
                                              + "Expected <{0}>, but was <{1}>.", s1count, s2count);
                return(false);
            }

            // if we reach this point, no differences were found
            sHowDifferent = "TextProps objects appear to contain the same properties.";
            return(true);
        }
Ejemplo n.º 7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:TextStrPropInfo"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public TextStrPropInfo(ITsTextProps props, int iprop)
		{
			int tpt;
			Value = props.GetStrProp(iprop, out tpt);
			Type = (FwTextPropType)tpt;
		}
Ejemplo n.º 8
0
		private void spyOnTextProps(ITsTextProps ttp)
		{
			int tpt; // ??

			// look at integer props
			int cintProps = ttp.IntPropCount;
			for (int i = 0; i < cintProps; i++)
			{
				int nVar;
				int intProp = ttp.GetIntProp(i, out tpt, out nVar);
				int Value = ttp.GetIntPropValues(tpt, out nVar);
				Value = 34; // need something so Value can be looked at
			}

			// look at string props
			int cstrProps = ttp.StrPropCount;
			for (int i = 0; i < cstrProps; i++)
			{
				string strProp = ttp.GetStrProp(i, out tpt);
				string Value = ttp.GetStrPropValue(tpt);
				Value = "why?"; // need something so Value can be looked at
			}
		}
Ejemplo n.º 9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Compares two TsTextProps
		/// </summary>
		/// <param name="ttp1">expected</param>
		/// <param name="ttp2">actual</param>
		/// <param name="sHowDifferent">Human(geek)-readable string telling how the props are
		/// different, or indicating no difference</param>
		/// <returns>True if they contain the same props, false otherwise</returns>
		/// ------------------------------------------------------------------------------------
		public static bool PropsAreEqual(ITsTextProps ttp1, ITsTextProps ttp2,
			out string sHowDifferent)
		{
			// check how intProps compare
			int cProps1 = ttp1.IntPropCount;
			int cProps2 = ttp2.IntPropCount;
			int tpv1, tpv2; // prop values
			int nVar1, nVar2; // variation info
			int tpt; // prop type
			for (int iprop = 0; iprop < cProps1; iprop++)
			{
				tpv1 = ttp1.GetIntProp(iprop, out tpt, out nVar1);
				tpv2 = ttp2.GetIntPropValues(tpt, out nVar2);

				if (tpv1 != tpv2 || nVar1 != nVar2)
				{
					if (tpt == (int)FwTextPropType.ktptWs)
						sHowDifferent = string.Format("Props differ in ktptWs property. "
							+ "Expected <{0}>, but was <{1}>.", tpv1, tpv2);
					else
						sHowDifferent = string.Format("Props differ in intProp type {0}. "
							+ "Expected <{1},{2}>, but was <{3},{4}>.", tpt, tpv1, nVar1, tpv2, nVar2);
					return false;
				}
			}
			// if count of intProps differs, it will be difficult to report exact difference
			//  so just issue a simple response for now
			if (cProps1 != cProps2)
			{
				sHowDifferent = string.Format("Props differ in count of intProps. "
					+ "Expected <{0}>, but was <{1}>.", cProps1, cProps2);
				return false;
			}

			// check for string properties differences
			int s1count = ttp1.StrPropCount;
			int s2count = ttp2.StrPropCount;
			int strtype;
			string strval1, strval2; // prop values
			for (int iprop = 0; iprop < s1count; iprop++)
			{
				strval1 = ttp1.GetStrProp(iprop, out strtype);
				strval2 = ttp2.GetStrPropValue(strtype);

				if (strval1 != strval2)
				{
					if (strtype == (int)FwTextPropType.ktptNamedStyle)
						sHowDifferent = string.Format("Props differ in ktptNamedStyle property. "
							+ "Expected <{0}>, but was <{1}>.", strval1, strval2);
					else if (strtype == (int)FwTextPropType.ktptObjData)
						sHowDifferent = string.Format("Props differ in ktptObjData property. "
							+ "Expected <{0}>, but was <{1}>.", strval1, strval2);
							// we could detail the objectDataType and Guid if needed
					else
						sHowDifferent = string.Format("Props differ in strProp type {0}. "
							+ "Expected <{1}>, but was <{2}>.", strtype, strval1, strval2);
					return false;
				}
			}
			// if count of strProps differs, it will be difficult to report exact difference
			//  so just issue a simple response for now
			if (s1count != s2count)
			{
				sHowDifferent = string.Format("Props differ in count of strProps. "
					+ "Expected <{0}>, but was <{1}>.", s1count, s2count);
				return false;
			}

			// if we reach this point, no differences were found
			sHowDifferent = "TextProps objects appear to contain the same properties.";
			return true;
		}
Ejemplo n.º 10
0
        /// <summary>
        /// Write the ITsString out.
        /// </summary>
        /// <param name="tssPara"></param>
        /// <param name="cchIndent"></param>
        /// <remarks>TODO: this maybe should go into a generic method somewhere?
        /// Except that part of it is specific to XHTML output...</remarks>
        private void WriteTsStringAsXml(ITsString tssPara, int cchIndent)
        {
            // First, build the indentation.
            StringBuilder bldr = new StringBuilder();

            while (cchIndent > 0)
            {
                bldr.Append(" ");
                --cchIndent;
            }
            string sIndent = bldr.ToString();

            bldr.Append("  ");
            string sIndent2 = bldr.ToString();

            m_writer.WriteLine("{0}<Str>", sIndent);
            int    crun   = tssPara.RunCount;
            string sField = null;

            for (int irun = 0; irun < crun; ++irun)
            {
                TsRunInfo    tri;
                ITsTextProps ttpRun    = tssPara.FetchRunInfo(irun, out tri);
                int          ctip      = ttpRun.IntPropCount;
                int          ctsp      = ttpRun.StrPropCount;
                string       sFieldRun = ttpRun.GetStrPropValue((int)FwTextPropType.ktptFieldName);
                if (sFieldRun != sField)
                {
                    if (!String.IsNullOrEmpty(sField))
                    {
                        m_writer.WriteLine("{0}</Field>", sIndent2);
                    }
                    if (!String.IsNullOrEmpty(sFieldRun))
                    {
                        m_writer.WriteLine("{0}<Field name=\"{1}\">", sIndent2, sFieldRun);
                    }
                    sField    = sFieldRun;
                    sFieldRun = null;
                }
                bool   fMarkItem;
                int    tpt;
                string sVal;
                bool   fSkipText = false;
                int    nVar;
                int    nVal = ttpRun.GetIntPropValues((int)FwTextPropType.ktptMarkItem, out nVar);
                if (nVal == (int)FwTextToggleVal.kttvForceOn && nVar == (int)FwTextPropVar.ktpvEnum)
                {
                    m_writer.Write("{0}<Item><Run", sIndent2);
                    fMarkItem = true;
                }
                else
                {
                    m_writer.Write("{0}<Run", sIndent2);
                    fMarkItem = false;
                }
                for (int itip = 0; itip < ctip; ++itip)
                {
                    nVal = ttpRun.GetIntProp(itip, out tpt, out nVar);
                    if (tpt == (int)FwTextPropType.ktptWs || tpt == (int)FwTextPropType.ktptBaseWs)
                    {
                        if (nVal != 0)
                        {
                            ILgWritingSystem lgws = LgWritingSystem.CreateFromDBObject(m_cache, nVal);
                            m_writer.Write(" {0}=\"{1}\"",
                                           tpt == (int)FwTextPropType.ktptWs ? "ws" : "wsBase", lgws.RFC4646bis);
                        }
                    }
                    else if (tpt != (int)FwTextPropType.ktptMarkItem)
                    {
                        WriteIntTextProp(m_writer, m_cache.LanguageWritingSystemFactoryAccessor, tpt, nVar, nVal);
                    }
                }
                string sRun         = tssPara.get_RunText(irun);
                Guid   guidFootnote = Guid.Empty;
                for (int itsp = 0; itsp < ctsp; ++itsp)
                {
                    sVal = ttpRun.GetStrProp(itsp, out tpt);
                    Debug.Assert(tpt != (int)FwTextPropType.ktptBulNumFontInfo);
                    Debug.Assert(tpt != (int)FwTextPropType.ktptWsStyle);
                    WriteStrTextProp(m_writer, tpt, sVal);
                    if (sRun != null && sRun.Length == 1 && sRun[0] == StringUtils.kchObject)
                    {
                        Debug.Assert(tpt == (int)FwTextPropType.ktptObjData);
                        fSkipText = true;
                        if ((int)sVal[0] == (int)FwObjDataTypes.kodtOwnNameGuidHot)
                        {
                            guidFootnote = MiscUtils.GetGuidFromObjData(sVal.Substring(1));
                        }
                    }
                }
                m_writer.Write(">");
                if (!fSkipText)
                {
                    int cch = tri.ichLim - tri.ichMin;
                    if (cch > 0)
                    {
                        sRun = sRun.Normalize();
                        m_writer.Write(XmlUtils.MakeSafeXml(sRun));
                    }
                }
                if (fMarkItem)
                {
                    m_writer.WriteLine("</Run></Item>");
                }
                else
                {
                    m_writer.WriteLine("</Run>");
                }
                if (guidFootnote != Guid.Empty)
                {
                    int hvoFootnote = m_cache.GetIdFromGuid(guidFootnote);
                    if (hvoFootnote != 0)
                    {
                        ExportFootnote(new ScrFootnote(m_cache, hvoFootnote));
                    }
                }
            }
            if (!String.IsNullOrEmpty(sField))
            {
                m_writer.WriteLine("{0}</Field>", sIndent2);
            }
            m_writer.WriteLine("{0}</Str>", sIndent);
        }