static void ApplyText(XmlReader re, ITextable t) { re.MoveToContent(); for (int i = 0; i < re.AttributeCount; i++) { re.MoveToAttribute(i); if (re.LocalName == FONTNAME_ATTR) t.FontName = re.Value; else if (re.LocalName == FONTSIZE_ATTR) { double sz = 1; double.TryParse(re.Value, out sz); t.FontSize = sz; } else if (re.LocalName == BOLD_ATTR) { bool b = false; bool.TryParse(re.Value, out b); t.Bold = b; } else if (re.LocalName == ITALICS_ATTR) { bool b = false; bool.TryParse(re.Value, out b); t.Italics = b; } else if (re.LocalName == UNDERLINE_ATTR) { bool b = false; bool.TryParse(re.Value, out b); t.Underline = b; } else if (re.LocalName == STRIKETHROUGH_ATTR) { bool b = false; bool.TryParse(re.Value, out b); t.Strikethrough = b; } else if (re.LocalName == WRAPTEXT_ATTR) { bool b = t.WrapText; bool.TryParse(re.Value, out b); t.WrapText = b; } else if (re.LocalName == WRAPTHRESHOLD_ATTR) { double wt = t.WrapThreshold; double.TryParse(re.Value, out wt); t.WrapThreshold = wt; } else if (re.LocalName == WRAPFONTSIZE_ATTR) { double wfs = t.WrapFontSize; double.TryParse(re.Value, out wfs); t.WrapFontSize = wfs; } } t.Text = re.ReadString(); }
public static DPoint MeasureText(string text, ITextable itext) { return GraphicsHelper.MeasureText(text, itext.FontName, itext.FontSize, itext.Bold, itext.Italics, itext.Underline, itext.Strikethrough); }
public static string MakeWrappedText(string text, ITextable itext) { DBitmap bmp = GraphicsHelper.MakeBitmap(10, 10); DGraphics dg = GraphicsHelper.MakeGraphics(bmp); string result = ""; string[] lines = text.Split('\n'); for (int i = 0; i < lines.Length; i++) { string line = lines[i]; // wrap line string remainder = line; string wrappedLine; string wrappedText = null; do { wrappedLine = WrapLine(dg, remainder, itext, out remainder); if (wrappedText == null) wrappedText = wrappedLine; else wrappedText = string.Concat(wrappedText, '\n', wrappedLine); } while (remainder != null); // join lines if (i < lines.Length - 1) result = string.Concat(result, wrappedText, '\n'); else result = string.Concat(result, wrappedText); } dg.Dispose(); bmp.Dispose(); return result; }
static string WrapLine(DGraphics dg, string s, ITextable itext, out string remainder) { string result; remainder = null; if (itext.WrapLength > 0) { result = s; int n = s.Length - 1; DPoint sz = MeasureText(dg, s, itext); while (sz.X > itext.WrapLength) { if (char.IsWhiteSpace(s[n])) { result = s.Substring(0, n); remainder = s.Substring(n); } else { bool foundWord = false; for (int j = n - 1; j >= 0; j--) if (char.IsWhiteSpace(s[j])) { result = s.Substring(0, j + 1); remainder = s.Substring(j + 1); n = j + 1; foundWord = true; break; } if (!foundWord) { result = s.Substring(0, n); remainder = s.Substring(n); } } sz = MeasureText(dg, result, itext); n--; } } else result = ""; if (result.Length == 0) { if (s.Length > 0) result = s.Substring(0, 1); if (s.Length > 1) remainder = s.Substring(1); else remainder = null; } return result; }
public TextEditFigure(DPoint pt, Figure f, ITextable itext) : this(f, itext) { TopLeft = pt; }
public TextEditFigure(Figure f, ITextable itext) { this.f = f; this.itext = itext; SetCursorPos(Text.Length, false); }