/// <summary> /// 异步给文本设置宽度 /// </summary> /// <param name="ls"></param> private void SetWordWidthEvent(LineString ls) { if (ls.PWord == null) { return; } foreach (var w in ls.PWord) { w.Width = CharCommand.GetWrodWidth(w, this.pIEdit.GetGraphics, this.pLanguageMode.TabSpaceCount); ls.Width += w.Width; } }
/// <summary> /// 获取LineString 的宽度 /// </summary> /// <param name="ls"></param> /// <param name="g"></param> /// <param name="tapSpaceCount"></param> /// <returns></returns> public static int GetLineStringWidth(LineString ls, Graphics g, int tapSpaceCount) { if (ls.Width > 0) { return(ls.Width); } foreach (var w in ls.PWord) { w.Width = CharCommand.GetWrodWidth(w, g, tapSpaceCount); ls.Width += w.Width; } return(ls.Width); }
/// <summary> /// 获取文本的宽度 /// </summary> /// <param name="w"></param> /// <param name="g"></param> /// <param name="f"></param> /// <param name="tagSpaceCount"></param> /// <returns></returns> public static int GetWrodWidth(Word w, Graphics g, Font f, int tabSpaceCount) { switch (w.PEWordType) { case EWordType.Tab: return(FontContainer.GetSpaceWidth(g) * tabSpaceCount); case EWordType.Space: return(FontContainer.GetSpaceWidth(g)); default: return(CharCommand.GetCharWidth(g, w.Text, f ?? FontContainer.DefaultFont)); } }