SIL.FieldWorks.SharpViews.AssembledStyles.ApplyTextProps C# (CSharp) Method

ApplyTextProps() public method

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.
public ApplyTextProps ( ITsTextProps props ) : AssembledStyles
props ITsTextProps
return AssembledStyles
		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;
		}