📄 rich_string.cs
字号:
namespace Imps.Client.Core
{
using Imps.Client.Resource;
using Imps.Utils;
using std;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
using System.Runtime.InteropServices;
public class rich_string
{
private bool _linkSupport;
private string _strUserName;
private SizeF _szPrefered;
private bool _toCalc;
public const int EmoticonSize = 0x10;
private List<pair<object, SizeF>> m_richtext;
private string m_text;
public rich_string()
{
this.m_text = string.Empty;
this._strUserName = "";
this.m_richtext = new List<pair<object, SizeF>>();
this._szPrefered = SizeF.Empty;
}
public rich_string(string strPlaneText)
{
this.m_text = string.Empty;
this._strUserName = "";
this.m_richtext = new List<pair<object, SizeF>>();
this._szPrefered = SizeF.Empty;
this.plane_text = strPlaneText;
}
public rich_string(string strPlaneText, bool bSupportLink)
{
this.m_text = string.Empty;
this._strUserName = "";
this.m_richtext = new List<pair<object, SizeF>>();
this._szPrefered = SizeF.Empty;
this._linkSupport = bSupportLink;
this.plane_text = strPlaneText;
}
public void clear()
{
this.m_richtext.Clear();
}
public void Draw(Graphics g, Font font, Color foreColor, RectangleF rc)
{
this.Draw(g, font, foreColor, rc, null);
}
public void Draw(Graphics g, Font font, Color foreColor, RectangleF rc, StringFormat fmt)
{
int offset = 0;
this.Draw(g, font, foreColor, rc, fmt, ref offset, this._toCalc);
this._toCalc = false;
}
public void Draw(Graphics g, Font font, Color foreColor, RectangleF rc, StringFormat fmt, ref int offset)
{
this.Draw(g, font, foreColor, rc, fmt, ref offset, this._toCalc);
this._toCalc = false;
}
public void Draw(Graphics g, Font font, Color foreColor, RectangleF rc, StringFormat fmt, ref int offset, bool calcMode)
{
using (Font font2 = new Font("Times New Roman", font.Size, font.Style | FontStyle.Bold))
{
using (Font font3 = new Font(font, font.Style | FontStyle.Underline))
{
using (Brush brush = new SolidBrush(Color.White))
{
using (Brush brush2 = new SolidBrush(Color.Purple))
{
float right = rc.Right;
float top = rc.Top;
float num3 = top;
if ((font.Size > 9f) && (font.Size < 11f))
{
num3 += 1f;
}
float bottom = rc.Bottom;
float left = (int) rc.Left;
bool flag = true;
RectangleF ef = rc;
if (fmt == null)
{
fmt = new StringFormat();
fmt.Alignment = StringAlignment.Near;
fmt.LineAlignment = StringAlignment.Center;
fmt.FormatFlags |= StringFormatFlags.NoWrap;
fmt.Trimming = StringTrimming.EllipsisCharacter;
}
SizeF ef2 = g.MeasureString("...", font2, 0x7fffffff, fmt);
fmt.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
bool flag2 = false;
float num6 = right;
if (calcMode)
{
this._szPrefered = (SizeF) Size.Empty;
}
using (Brush brush3 = new SolidBrush(foreColor))
{
int num7 = this.rich_text.get_Count();
for (int i = 0; i < num7; i++)
{
pair<object, SizeF> pair = this.rich_text.get_Item(i);
float num9 = right;
if (left >= right)
{
if (!calcMode)
{
break;
}
flag = false;
}
SizeF empty = SizeF.Empty;
if ((pair.first is string) || (pair.first is rich_string_link))
{
int charactersFitted;
int linesFilled;
string first = string.Empty;
if (pair.first is string)
{
first = (string) pair.first;
}
else
{
first = ((rich_string_link) pair.first).URL;
}
SizeF layoutArea = new SizeF(right - left, 16f);
empty = g.MeasureString(first, font, layoutArea, fmt, out charactersFitted, out linesFilled);
if (charactersFitted >= first.Length)
{
if (calcMode)
{
empty.Width += 1f;
}
if (flag)
{
RectangleF layoutRectangle = RectangleF.FromLTRB(left, num3, right, bottom);
if (!this._linkSupport || (pair.first is string))
{
g.DrawString(first, font, brush3, layoutRectangle, fmt);
}
else
{
if (pair.first is rich_string_link)
{
((rich_string_link) pair.first).PosRect = RectangleF.FromLTRB(left, top, left + empty.Width, bottom);
}
if (((rich_string_link) pair.first).Clicked)
{
g.DrawString(first, font3, brush2, layoutRectangle, fmt);
}
else
{
g.DrawString(first, font3, brush, layoutRectangle, fmt);
}
}
}
left += empty.Width;
if (((first.Length > 1) && font.Bold) && (((i + 1) < num7) && (this.rich_text.get_Item(i + 1).first is AmigoImage)))
{
left += 3f;
}
goto Label_04C3;
}
if (((empty.Width < 28.8) && (num7 != 1)) && (i != (num7 - 1)))
{
num6 = left;
flag2 = true;
flag = false;
}
else
{
RectangleF ef6 = RectangleF.FromLTRB(left, num3, right, bottom);
if (ef6.Width <= (ef2.Width + 5f))
{
num6 = left;
flag2 = true;
flag = false;
}
else
{
if (!this._linkSupport || (pair.first is string))
{
g.DrawString(first, font, brush3, ef6, fmt);
}
else
{
if (pair.first is rich_string_link)
{
((rich_string_link) pair.first).PosRect = ef6;
}
if (((rich_string_link) pair.first).Clicked)
{
g.DrawString(first, font3, brush2, ef6, fmt);
}
else
{
g.DrawString(first, font3, brush, ef6, fmt);
}
}
left = right + 1f;
num6 = left;
flag = false;
}
}
break;
}
if (!(pair.first is AmigoImage))
{
throw new Exception("Unsupport rich_string inner object");
}
if (calcMode)
{
empty = new SizeF(16f, 16f);
}
if (flag)
{
if ((((i + 1) < num7) && (this.rich_text.get_Item(i + 1).first is AmigoImage)) && ((left + 32f) > num9))
{
flag2 = true;
num6 = left;
flag = false;
}
else
{
if ((((left + 28.8) <= num9) || (num7 == 1)) || (i == (num7 - 1)))
{
g.DrawImage(((AmigoImage) pair.first).PreviewImage, (int) left, (int) (top + ((rc.Height - 16f) / 2f)), 0x10, 0x10);
goto Label_04C3;
}
flag2 = true;
num6 = left;
flag = false;
}
break;
}
Label_04C3:
if (calcMode)
{
pair.second = empty;
this._szPrefered.Width += empty.Width;
if (this._szPrefered.Height < empty.Height)
{
this._szPrefered.Height = empty.Height;
}
}
if (pair.first is AmigoImage)
{
left += 16f;
}
}
if (flag2)
{
RectangleF ef7 = RectangleF.FromLTRB(num6, top - 3f, ef.Right, bottom);
g.DrawString("...", font2, brush3, ef7, fmt);
left = right + 1f;
}
}
if (calcMode)
{
this._szPrefered.Width += 1f;
}
if (left > right)
{
left = right;
}
offset = (int) Math.Ceiling((double) left);
}
}
}
}
}
public void DrawEx(Graphics g, Font font, Color foreColor, RectangleF rc, StringFormat fmt, ref int offset, bool calcMode)
{
float right = rc.Right;
float top = rc.Top;
float bottom = rc.Bottom;
float left = (int) rc.Left;
bool flag = true;
if (fmt == null)
{
fmt = new StringFormat();
fmt.Alignment = StringAlignment.Near;
fmt.LineAlignment = StringAlignment.Center;
fmt.FormatFlags |= StringFormatFlags.NoWrap;
fmt.Trimming = StringTrimming.EllipsisCharacter;
}
this._toCalc = true;
SizeF ef = this.MeasureText(g, font);
bool flag2 = false;
this._toCalc = true;
if (ef.Width > rc.Width)
{
flag2 = true;
}
if (calcMode)
{
this._szPrefered = (SizeF) Size.Empty;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -