tangxu
2024-10-22 6a07c4c846ffbb1e93afdf0260e123e4c145f419
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Drawing;
 
namespace Microsoft.Windows.Forms.Layout
{
    /// <summary>
    /// 布局数据
    /// </summary>
    public sealed class LayoutData : DisposableMini
    {
        /// <summary>
        /// 测试用绘图对象
        /// </summary>
        public Graphics Graphics;
 
        /// <summary>
        /// 区域
        /// </summary>
        public Rectangle ClientRectangle;
        /// <summary>
        /// 边距
        /// </summary>
        public Padding Padding;
        /// <summary>
        /// 文本图片相对位置
        /// </summary>
        public TextImageRelation TextImageRelation;
        /// <summary>
        /// 左右反转样式
        /// </summary>
        public RightToLeft RightToLeft;
 
        /// <summary>
        /// 图片大小
        /// </summary>
        public Size ImageSize;
        /// <summary>
        /// 图片对齐方式
        /// </summary>
        public ContentAlignment ImageAlign;
        /// <summary>
        /// 图片偏移量
        /// </summary>
        public Point ImageOffset;
 
        /// <summary>
        /// 文本
        /// </summary>
        public string Text;
        /// <summary>
        /// 字体
        /// </summary>
        public Font Font;
        /// <summary>
        /// 文本对齐方式
        /// </summary>
        public ContentAlignment TextAlign;
        /// <summary>
        /// 文本偏移量
        /// </summary>
        public Point TextOffset;
 
        /// <summary>
        /// 输出-图片区域(必须先调用Layout()方法)
        /// </summary>
        public Rectangle OutImageBounds;//[OUT]
        /// <summary>
        /// 输出-文本区域(必须先调用Layout()方法)
        /// </summary>
        public Rectangle OutTextBounds;//[OUT]
 
 
        //==================
 
        private bool m_IsLayouted;
        /// <summary>
        /// 是否执行过布局操作
        /// </summary>
        public bool IsLayouted
        {
            get
            {
                return this.m_IsLayouted;
            }
        }
 
 
        private Rectangle? m_CurrentClientRectangle;
        /// <summary>
        /// 当前区域,已减去边距
        /// </summary>
        public Rectangle CurrentClientRectangle
        {
            get
            {
                if (this.m_CurrentClientRectangle == null)
                    this.m_CurrentClientRectangle = RectangleEx.Subtract(this.ClientRectangle, this.Padding);
                return this.m_CurrentClientRectangle.Value;
            }
        }
 
        private TextImageRelation? m_CurrentTextImageRelation;
        /// <summary>
        /// 当前文本图片相对位置,已通过左右反转样式翻译
        /// </summary>
        public TextImageRelation CurrentTextImageRelation
        {
            get
            {
                if (this.m_CurrentTextImageRelation == null)
                    this.m_CurrentTextImageRelation = LayoutOptions.RtlTranslateRelation(this.TextImageRelation, this.RightToLeft);
                return this.m_CurrentTextImageRelation.Value;
            }
        }
 
        private StringFormat m_CurrentStringFormat;
        /// <summary>
        /// 当前文本格式,渲染文本时使用
        /// </summary>
        public StringFormat CurrentStringFormat
        {
            get
            {
                if (this.m_CurrentStringFormat == null)
                    this.m_CurrentStringFormat = LayoutOptions.GetStringFormat(this.TextAlign, this.RightToLeft);
                return this.m_CurrentStringFormat;
            }
        }
 
        private ContentAlignment? m_CurrentImageAlign;
        /// <summary>
        /// 当前图片对齐方式,已通过左右反转样式翻译
        /// </summary>
        public ContentAlignment CurrentImageAlign
        {
            get
            {
                if (this.m_CurrentImageAlign == null)
                    this.m_CurrentImageAlign = LayoutOptions.RtlTranslateAlignment(this.ImageAlign, this.RightToLeft);
                return this.m_CurrentImageAlign.Value;
            }
        }
 
        private ContentAlignment? m_CurrentTextAlign;
        /// <summary>
        /// 当前文本对齐方式,已通过左右反转样式翻译
        /// </summary>
        public ContentAlignment CurrentTextAlign
        {
            get
            {
                if (this.m_CurrentTextAlign == null)
                    this.m_CurrentTextAlign = LayoutOptions.RtlTranslateAlignment(this.TextAlign, this.RightToLeft);
                return this.m_CurrentTextAlign.Value;
            }
        }
 
 
        /// <summary>
        /// 构造函数
        /// </summary>
        public LayoutData()
        {
        }
 
        /// <summary>
        /// 布局文本和图片.该方法可被调用多次,但再生命周期内布局操作只会被执行一次.
        /// </summary>
        public void DoLayout()
        {
            if (this.m_IsLayouted)
                return;
            this.m_IsLayouted = true;
            LayoutOptions.LayoutTextAndImage(this);
        }
 
        /// <summary>
        /// 释放资源
        /// </summary>
        /// <param name="disposing">释放托管资源为true,否则为false</param>
        protected override void Dispose(bool disposing)
        {
            if (this.m_CurrentStringFormat != null)
            {
                this.m_CurrentStringFormat.Dispose();
                this.m_CurrentStringFormat = null;
            }
        }
    }
}