Ejemplo n.º 1
0
    /// <summary>
    /// Translates a value as a shape's name value pair to RTF.
    /// </summary>
    protected void TranslateAsNameValuePair(string domValueName, string rtfName, RtfUnit unit, string defaultValue)
    {
      object val = GetValueAsIntended(domValueName);
      if (val == null && defaultValue == null)
        return;

      string valueStr = "";
      if (val == null)
        valueStr = defaultValue;
      else
      {
        if (val is Unit)
          valueStr = ToRtfUnit((Unit)val, unit).ToString(CultureInfo.InvariantCulture);
        else if (val is Color)
        {
          Color col = (Color)val;
          col = col.GetMixedTransparencyColor();
          valueStr = (col.R + (col.G * 256) + (col.B * 65536)).ToString(CultureInfo.InvariantCulture);
        }
        else if (val is Enum)
          valueStr = enumTranslationTable[val].ToString();
        else if (val is bool)
          valueStr = (bool)val ? "1" : "0";
        else
          Debug.Assert(false);
      }
      RenderNameValuePair(rtfName, valueStr);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Translates a value named 'valueName' to a Rtf Control word that specifies a unit, enum, bool, int or color.
 /// </summary>
 protected void Translate(string valueName, string rtfCtrl, RtfUnit unit, Unit val, bool withStar)
 {
     Translate(valueName, rtfCtrl, unit, ToRtfUnit(val, RtfUnit.Twips).ToString(CultureInfo.InvariantCulture), withStar);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Translates a value named 'valueName' to a Rtf Control word that specifies a Unit, Enum, Bool, Int or Color.
 /// </summary>
 protected void Translate(string valueName, string rtfCtrl, RtfUnit unit, string defaultValue, bool withStar)
 {
     object val = GetValueAsIntended(valueName);
       if (val == null)
       {
     if (defaultValue != null)
       this.rtfWriter.WriteControl(rtfCtrl, defaultValue);
     return;
       }
       else
       {
     if (val is Unit)
     {
       this.rtfWriter.WriteControl(rtfCtrl, ToRtfUnit((Unit)val, unit), withStar);
     }
     else if (val is bool)
     {
       if ((bool)val)
     this.rtfWriter.WriteControl(rtfCtrl, withStar);
     }
     else if (val is Color)
     {
       int idx = this.docRenderer.GetColorIndex((Color)val);
       this.rtfWriter.WriteControl(rtfCtrl, idx, withStar);
     }
     else if (val is Enum)
     {
       this.rtfWriter.WriteControl(rtfCtrl, enumTranslationTable[val].ToString(), withStar);
     }
     else if (val is int)
     {
       this.rtfWriter.WriteControl(rtfCtrl, (int)val, withStar);
     }
     else
       Debug.Assert(false, "Invalid use of Translate");
       }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Renders the given Unit as control / value pair of the given RTF control in the given RTF unit, optionally with a star.
 /// </summary>
 protected void RenderUnit(string rtfControl, Unit value, RtfUnit rtfUnit, bool withStar)
 {
     this.rtfWriter.WriteControl(rtfControl, ToRtfUnit(value, rtfUnit), withStar);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Renders the given unit as control / value pair in the given RTF unit.
 /// </summary>
 protected void RenderUnit(string rtfControl, Unit value, RtfUnit rtfUnit)
 {
     RenderUnit(rtfControl, value, rtfUnit, false);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Translates the given Unit to an RTF unit.
 /// </summary>
 /// <param name="unit"></param>
 /// <param name="rtfUnit"></param>
 /// <returns></returns>
 internal static int ToRtfUnit(Unit unit, RtfUnit rtfUnit)
 {
     switch (rtfUnit)
       {
     case RtfUnit.HalfPts:
       return (int)(Math.Round(unit.Point * 2));
     case RtfUnit.Twips:
       return (int)(Math.Round(unit.Point * 20));
     case RtfUnit.Lines:
       return (int)(Math.Round(unit.Point * 12 * 20));
     case RtfUnit.EMU:
       return (int)(Math.Round(unit.Point * 12700));
     case RtfUnit.CharUnit100:
       return (int)(Math.Round(unit.Pica * 100));
       }
       return (int)unit.Point;
 }