Example #1
0
        /// <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);
        }
Example #2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Sets a string property.
 /// </summary>
 /// <param name="binaryProps">The binary properties.</param>
 /// <param name="fIsExplicit"><c>true</c> if the value is explicitly set and should be
 /// added to the props list.</param>
 /// <param name="tpt">The property type.</param>
 /// <param name="value">The property value.</param>
 /// ------------------------------------------------------------------------------------
 private static void SetStrProp(List <char> binaryProps, bool fIsExplicit, FwTextPropType tpt,
                                string value)
 {
     if (fIsExplicit)
     {
         binaryProps.Add((char)tpt);
         binaryProps.AddRange(value.ToCharArray());
         binaryProps.Add((char)0);
     }
 }
Example #3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Sets an integer property.
 /// </summary>
 /// <param name="binaryProps">The binary properties.</param>
 /// <param name="fIsExplicit"><c>true</c> if the value is explicitly set and should be
 /// added to the props list.</param>
 /// <param name="tpt">The property type.</param>
 /// <param name="value">The property value.</param>
 /// ------------------------------------------------------------------------------------
 private static void SetIntProp(List <char> binaryProps, bool fIsExplicit, FwTextPropType tpt,
                                uint value)
 {
     if (fIsExplicit)
     {
         binaryProps.Add((char)tpt);
         binaryProps.Add(Convert.ToChar(value & 0xFFFF));
         binaryProps.Add(Convert.ToChar(value >> 16));
     }
 }
Example #4
0
        /// <summary>
        /// Attempts to get the value of the specified int property.
        /// </summary>
        public static bool TryGetIntValue(this ITsTextProps textProps, FwTextPropType tpt, out FwTextPropVar var, out int value)
        {
            int v;

            value = textProps.GetIntPropValues((int)tpt, out v);
            if (v == -1 && value == -1)
            {
                var = FwTextPropVar.ktpvDefault;
                return(false);
            }

            var = (FwTextPropVar)v;
            return(true);
        }
Example #5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Scales the given property based on the scaling factor and sets it in the in-memory
		/// stylesheet.
		/// </summary>
		/// <param name="stylesheet">The in-memory stylesheet used for overriding properties.
		/// </param>
		/// <param name="scalingFactor">The scaling factor.</param>
		/// <param name="styleName">Name of the style.</param>
		/// <param name="styleProps">The style props.</param>
		/// <param name="prop">The type of property to be scaled.</param>
		/// ------------------------------------------------------------------------------------
		private static void ScaleProperty(InMemoryStyleSheet stylesheet,
			decimal scalingFactor, string styleName, ITsTextProps styleProps,
			FwTextPropType prop)
		{
			int var;
			int propValue = styleProps.GetIntPropValues((int)prop, out var);
			if (propValue != -1 && var == (int)FwTextPropVar.ktpvMilliPoint)
			{
				if (prop == FwTextPropType.ktptFontSize)
				{
					Debug.Assert(propValue >= 4);
					// Calculate new value for this style, rounding to reasonable value.
					propValue = ScaleAndRoundProp(scalingFactor, propValue, 1000);
					// Adjusted font size must be at least 4 pts
					propValue = Math.Max(propValue, 4000);
				}
				else
					propValue = ScaleAndRoundProp(scalingFactor, propValue, 1);

				stylesheet.AddIntPropOverride(styleName, prop,
					FwTextPropVar.ktpvMilliPoint, propValue);
			}
		}
Example #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Decodes the font info.
        /// </summary>
        /// <param name="blob">The BLOB.</param>
        /// <returns>The font information represented in the BLOB.</returns>
        /// ------------------------------------------------------------------------------------
        private static FontInfo DecodeFontInfo(string blob)
        {
            FontInfo fontInfo = new FontInfo();

            fontInfo.SetAllDefaults();

            if (blob != null)
            {
                for (int i = 0; i < blob.Length;)
                {
                    int iPropLim = blob.IndexOf('\0', i);
                    if (iPropLim < 0)
                    {
                        iPropLim = blob.Length;
                    }

                    FwTextPropType tpt = (FwTextPropType)blob[i++];
                    if (tpt == FwTextPropType.ktptFontFamily)
                    {
                        fontInfo.m_fontName.ExplicitValue = blob.Substring(i, iPropLim - i);
                        i += (iPropLim - i + 1);
                        break;
                    }
                    else if (tpt == FwTextPropType.ktptFontVariations)
                    {
                        fontInfo.m_features.ExplicitValue = blob.Substring(i, iPropLim - i);
                        i += (iPropLim - i + 1);
                        break;
                    }

                    int nVal = (int)blob[i] + (int)(blob[i + 1] << 16);
                    i += 2;

                    switch (tpt)
                    {
                    case FwTextPropType.ktptBold:
                        fontInfo.m_bold.ExplicitValue = nVal == 1;
                        break;

                    case FwTextPropType.ktptItalic:
                        fontInfo.m_italic.ExplicitValue = nVal == 1;
                        break;

                    case FwTextPropType.ktptSuperscript:
                        fontInfo.m_superSub.ExplicitValue = (FwSuperscriptVal)nVal;
                        break;

                    case FwTextPropType.ktptUnderline:
                        fontInfo.m_underline.ExplicitValue = (FwUnderlineType)nVal;
                        break;

                    case FwTextPropType.ktptFontSize:
                        fontInfo.m_fontSize.ExplicitValue = nVal;
                        break;

                    case FwTextPropType.ktptOffset:
                        fontInfo.m_offset.ExplicitValue = nVal;
                        break;

                    case FwTextPropType.ktptBackColor:
                        fontInfo.m_backColor.ExplicitValue = ColorUtil.ConvertBGRtoColor((uint)nVal);
                        break;

                    case FwTextPropType.ktptForeColor:
                        fontInfo.m_fontColor.ExplicitValue = ColorUtil.ConvertBGRtoColor((uint)nVal);
                        break;

                    case FwTextPropType.ktptUnderColor:
                        fontInfo.m_underlineColor.ExplicitValue = ColorUtil.ConvertBGRtoColor((uint)nVal);
                        break;
                    }
                }
            }

            return(fontInfo);
        }
Example #7
0
 /// <summary>
 /// Sets the specified property to the string value represented by the specified byte array.
 /// </summary>
 public static void SetStringValue(this ITsIncStrBldr tisb, FwTextPropType tpt, byte[] value)
 {
     tisb.SetStrPropValueRgch((int)tpt, value, value == null ? 0 : value.Length);
 }
Example #8
0
 /// <summary>
 /// Sets the specified property to the specified string value.
 /// </summary>
 public static void SetStringValue(this ITsIncStrBldr tisb, FwTextPropType tpt, string value)
 {
     tisb.SetStrPropValue((int)tpt, value);
 }
Example #9
0
 /// <summary>
 /// Sets the specified property to the specified int value.
 /// </summary>
 public static void SetIntValue(this ITsIncStrBldr tisb, FwTextPropType tpt, FwTextPropVar var, int value)
 {
     tisb.SetIntPropValues((int)tpt, (int)var, value);
 }
Example #10
0
 /// <summary>
 /// Sets the specified property to the specified string value.
 /// </summary>
 public static void SetStringValue(this ITsPropsBldr tpb, FwTextPropType tpt, string value)
 {
     tpb.SetStrPropValue((int)tpt, value);
 }
Example #11
0
 /// <summary>
 /// Sets the specified property to the specified int value.
 /// </summary>
 public static void SetIntValue(this ITsPropsBldr tpb, FwTextPropType tpt, FwTextPropVar var, int value)
 {
     tpb.SetIntPropValues((int)tpt, (int)var, value);
 }
Example #12
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);
        }
Example #13
0
 /// <summary>
 /// Attempts to get the value of the specified string property.
 /// </summary>
 public static bool TryGetStringValue(this ITsTextProps textProps, FwTextPropType tpt, out string value)
 {
     value = textProps.GetStrPropValue((int)tpt);
     return(value != null);
 }
Example #14
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets a string property.
		/// </summary>
		/// <param name="binaryProps">The binary properties.</param>
		/// <param name="fIsExplicit"><c>true</c> if the value is explicitly set and should be
		/// added to the props list.</param>
		/// <param name="tpt">The property type.</param>
		/// <param name="value">The property value.</param>
		/// ------------------------------------------------------------------------------------
		private static void SetStrProp(List<char> binaryProps, bool fIsExplicit, FwTextPropType tpt,
			string value)
		{
			if (fIsExplicit)
			{
				binaryProps.Add((char)tpt);
				binaryProps.AddRange(value.ToCharArray());
				binaryProps.Add((char)0);
			}
		}
Example #15
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets an integer property.
		/// </summary>
		/// <param name="binaryProps">The binary properties.</param>
		/// <param name="fIsExplicit"><c>true</c> if the value is explicitly set and should be
		/// added to the props list.</param>
		/// <param name="tpt">The property type.</param>
		/// <param name="value">The property value.</param>
		/// ------------------------------------------------------------------------------------
		private static void SetIntProp(List<char> binaryProps, bool fIsExplicit, FwTextPropType tpt,
			uint value)
		{
			if (fIsExplicit)
			{
				binaryProps.Add((char)tpt);
				binaryProps.Add(Convert.ToChar(value & 0xFFFF));
				binaryProps.Add(Convert.ToChar(value >> 16));
			}
		}