/// <summary> /// Initializes a new Position struct pointing to specified position /// of given parent SDUFormattedString object. /// </summary> /// <param name="parent"></param> /// <param name="piece"></param> /// <param name="index"></param> public Position(SDUFormattedString parent, int piece, int index) { m_parent=parent; m_piece=piece; m_index=index; }
/// <summary> /// Returns interval containing full parent SDUFormattedString. /// </summary> /// <param name="parent"></param> /// <returns></returns> public static Interval Full(SDUFormattedString parent) { return new Interval(parent.Begin, parent.End); }
/// <summary> /// Initializes a new Position struct pointing to the first character /// of given parent SDUFormattedString object. /// </summary> /// <param name="parent"></param> public Position(SDUFormattedString parent) { m_parent=parent; m_piece=0; m_index=0; }
/// <summary> /// Returns a new Position struct pointing behind the last character /// of given parent SDUFormattedString object. /// </summary> /// <param name="parent"></param> /// <returns></returns> public static Position End(SDUFormattedString parent) { Position res=new Position(parent); res.m_piece=parent.Count; res.m_index=0; return res; }
/// <summary> /// Returns a new Position struct pointing to the first character /// of given parent SDUFormattedString object. /// </summary> /// <param name="parent"></param> /// <returns></returns> public static Position Begin(SDUFormattedString parent) { Position res=new Position(parent); res.m_piece=0; res.m_index=0; return res; }
/// <summary> /// Draws string with given character format and alignment at given <see cref="Point"/>. /// </summary> /// <param name="gr"><see cref="Graphics"/> object to draw into.</param> /// <param name="str"><see cref="string"/> to be drawn.</param> /// <param name="pnt"><see cref="Point"/> where the string will be drawn.</param> /// <param name="fmt"><see cref="CharacterFormat"/> used to draw the <see cref="string"/>. </param> /// <param name="align">Specifies whether the <paramref name="pnt"/> is at left, right /// or in the center of the string. (<see cref="ParagraphAlignment.Full"/> means the same /// as <see cref="ParagraphAlignment.Left"/>.)</param> public void DrawString(Graphics gr, string str, PointF pnt, CharacterFormat fmt, ParagraphAlignment align) { StringFormat sf = (StringFormat) StringFormat.GenericDefault.Clone(); sf.Alignment = ParAl2StrAl(align); sf.HotkeyPrefix = fmt.HotkeyPrefix; Matrix trOld = null; if (fmt.Angle != 0) { trOld = gr.Transform.Clone(); gr.TranslateTransform(pnt.X, pnt.Y); gr.RotateTransform(fmt.Angle); gr.TranslateTransform(-pnt.X, -pnt.Y); } if (fmt.Formatted) { CharacterFormat cf = fmt.ShallowCopy(); cf.Angle = 0; SDUFormattedString fs = new SDUFormattedString(str, cf); SizeF sz = fs.Measure(gr, true); sz.Height += GetMeasureStringVerticalGap(gr, cf.Font); PointF ofs = pnt; switch (align) { case ParagraphAlignment.Right: ofs.X -= sz.Width; break; case ParagraphAlignment.Center: ofs.X -= sz.Width/2; break; } ParagraphFormat pf = new ParagraphFormat(); pf.MultiLine = false; pf.Alignment = align; fs.DrawStringInRectangle(gr, new RectangleF(ofs, sz), pf); } else if (fmt.FilledBounds) { ParagraphFormat pf = new ParagraphFormat(); //pf.Alignment=align; SizeF sz = MeasureStringExactly(gr, str, fmt, pf, false); sz.Width += GetMeasureStringHorizontalGap(gr, fmt.Font); pnt.X += GetMeasureStringHorizontalGap(gr, fmt.Font)/2; pnt.Y += GetMeasureStringVerticalGap(gr, fmt.Font); gr.FillRectangle(fmt.Brush, new RectangleF(pnt, sz)); } else gr.DrawString(str, fmt.Font, fmt.Brush, pnt, sf); if (trOld != null) gr.Transform = trOld; }
/// <summary> /// Draws string with given formating into given <paramref name="rectangle"/>. /// </summary> /// <param name="gr"><see cref="Graphics"/> object to draw into.</param> /// <param name="str"><see cref="string"/> to be drawn.</param> /// <param name="rectangle"><see cref="Rectangle"/> that string is drawn into.</param> /// <param name="fmtCharacter"><see cref="CharacterFormat"/> used to draw the <see cref="string"/>. </param> /// <param name="fmtParagraph"><see cref="ParagraphFormat"/> used to draw the <see cref="string"/>. </param> public void DrawStringInRectangle(Graphics gr, string str, RectangleF rectangle, CharacterFormat fmtCharacter, ParagraphFormat fmtParagraph) { Matrix trOld = gr.Transform.Clone(); gr.TranslateTransform(rectangle.X, rectangle.Y); gr.RotateTransform(fmtCharacter.Angle); gr.TranslateTransform(-rectangle.X, -rectangle.Y); if (fmtParagraph.BackgroundBrush != null) gr.FillRectangle(fmtParagraph.BackgroundBrush, rectangle); CharacterFormat cf = fmtCharacter.ShallowCopy(); cf.Angle = 0; ParagraphFormat pf = fmtParagraph.ShallowCopy(); pf.BackgroundBrush = null; if (fmtCharacter.Formatted) { SDUFormattedString fmts = new SDUFormattedString(str, cf); if (pf.MultiLine) fmts.WrapLines(gr, rectangle.Width); fmts.DrawStringInRectangle(gr, rectangle, pf); } else if (fmtCharacter.FilledBounds) gr.FillRectangle(fmtCharacter.Brush, rectangle); else { if (fmtParagraph.Alignment == ParagraphAlignment.Full && fmtParagraph.MultiLine && rectangle.Width > 0) { DrawFullAlignedStringInRectangle(gr, str, rectangle, cf, fmtParagraph); } else { StringFormat sf = GetStringFormat(fmtCharacter, fmtParagraph); gr.DrawString(str, fmtCharacter.Font, fmtCharacter.Brush, rectangle, sf); } } gr.Transform = trOld; }
/// <summary> /// Returns height of the text when wrapping to given <paramref name="width"/> is performed. /// </summary> /// <param name="gr">Graphics object used for measurement.</param> /// <param name="str">String to be measured.</param> /// <param name="cf"><see cref="CharacterFormat"/> of given string.</param> /// <param name="width">Maximum width of resulting text.</param> /// <returns>Returns height of the text when wrapping to given <paramref name="width"/> /// is performed.</returns> public float GetWrappedHeight(Graphics gr, string str, CharacterFormat cf, float width) { CharacterFormat cf2=cf.ShallowCopy(); cf2.Angle=0; SDUFormattedString fmts = new SDUFormattedString(str, cf); fmts.WrapLines(gr, width); return fmts.GetTotalHeight(gr); }