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 } }
/// <summary> /// Gets the int property at the specified index. /// </summary> public static int GetIntProperty(this ITsTextProps textProps, int index, out FwTextPropType tpt, out FwTextPropVar var) { int t, v; int value = textProps.GetIntProp(index, out t, out v); tpt = (FwTextPropType)t; var = (FwTextPropVar)v; return(value); }
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; }
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); }
/// ------------------------------------------------------------------------------------ /// <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); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:TextIntPropInfo"/> class. /// </summary> /// ------------------------------------------------------------------------------------ public TextIntPropInfo(ITsTextProps props, int iprop, FdoCache cache) { int nvar; int tpt; Value = props.GetIntProp(iprop, out tpt, out nvar); Type = (FwTextPropType)tpt; Variant = (FwTextPropVar)nvar; m_toStringValue = Value + " (" + Type + ")"; if (tpt == (int)FwTextPropType.ktptWs) { IWritingSystem ws = cache.ServiceLocator.WritingSystemManager.Get(Value); m_toStringValue += " {" + ws + "}"; } }
/// ------------------------------------------------------------------------------------ /// <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; }
/// <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); }
/// <summary> /// Compute the assembled styles that results from applying the properties specified in the text props to this. /// We might start with a root assembled styles that says to use a 10-point font, /// then apply a paragraph style which says to use a 12-point font, except for French use 14-point. /// Then in another text props we may tell it the writing system is French, and must get 14-point as the /// result. Or, in a single TsTextProps, we may tell it the WS is French and to apply a character /// style which says to use 16-point, except for French 18-point; the result needs to be 18-point. /// It's also theoretically possible that the same text props again says directly to use 20-point; that /// should win over all the others. /// We achieve most of this by simply looking for the ws, then the named style, then everything else /// (and when we process a style, if we already know a ws we include the overrides for that ws). /// However, when we process the paragraph style, we don't know what ws a run in that paragraph will have. /// </summary> /// <param name="props"></param> /// <returns></returns> public AssembledStyles ApplyTextProps(ITsTextProps props) { AssembledStyles result = this; // Apply writing system, if present, first, so that it can be used to select // a named style effect. int ttv; int ws = props.GetIntPropValues((int) FwTextPropType.ktptWs, out ttv); if (ttv != -1) result = result.WithWs(ws); // Apply named style next, if present, so that style effects can be overridden by explicit ones. var namedStyle = props.GetStrPropValue((int) FwTextPropType.ktptNamedStyle); if (namedStyle != null) result = result.WithNamedStyle(namedStyle); int count = props.IntPropCount; for (int i = 0; i < count; i++) { int tpt; int val = props.GetIntProp(i, out tpt, out ttv); switch (tpt) { case (int) FwTextPropType.ktptWs: // handled first break; case (int) FwTextPropType.ktptBold: int weight; Debug.Assert(ttv == (int) FwTextPropVar.ktpvEnum); switch (val) { case (int) FwTextToggleVal.kttvForceOn: weight = (int) VwFontWeight.kvfwBold; break; // todo JohnT: several others. default: weight = (int)VwFontWeight.kvfwNormal; break; } result = result.WithFontWeight(weight); break; } } return result; }