/// <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) { _rtfWriter.WriteControl(rtfCtrl, defaultValue); } return; } else { if (val is Unit) { _rtfWriter.WriteControl(rtfCtrl, ToRtfUnit((Unit)val, unit), withStar); } else if (val is bool) { if ((bool)val) { _rtfWriter.WriteControl(rtfCtrl, withStar); } } else if (val is Color) { int idx = _docRenderer.GetColorIndex((Color)val); _rtfWriter.WriteControl(rtfCtrl, idx, withStar); } else if (val is Enum) { _rtfWriter.WriteControl(rtfCtrl, _enumTranslationTable[val].ToString(), withStar); } else if (val is int) { _rtfWriter.WriteControl(rtfCtrl, (int)val, withStar); } else { Debug.Assert(false, "Invalid use of Translate"); } } }
/// <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(); } else if (val is Color) { Color col = (Color)val; col = col.GetMixedTransparencyColor(); valueStr = (col.R + (col.G * 256) + (col.B * 65536)).ToString(); } 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); }
/// <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); }
/// <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) { _rtfWriter.WriteControl(rtfControl, ToRtfUnit(value, rtfUnit), withStar); }
/// <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); }
/// <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(), withStar); }
/// <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); }
/// <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); }
/// <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"); } }
/// <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); }
/// <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; }