MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / RenderTexture

Method RenderTexture

TexturedFontEditor/FontEditor.cs:1109–1182  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1107 }
1108
1109 public void RenderTexture()
1110 {
1111 _MaxLineHeight = 0;
1112
1113 Bitmap tTexture = new Bitmap(_TexWidth, _TexHeight);
1114 using (Graphics tGraph = Graphics.FromImage(tTexture))
1115 {
1116 tGraph.Clear(Color.Transparent);
1117 tGraph.TextRenderingHint = AntiAlias;
1118
1119 // 第一次遍历 计算出字形大小和Location.x以及行索引
1120 Dictionary<CharDef, int> tLineDict = new Dictionary<CharDef, int>();
1121 SortedDictionary<int, int> tLineHeight = new SortedDictionary<int, int>();
1122 int tLeft = 0;
1123 int tLine = 0;
1124 foreach (CharDef x in _CharList)
1125 {
1126 Size tCharSize = x.GetCharSize(tGraph);
1127
1128 // 检查字体能不能容纳到纹理中
1129 if (tLeft + tCharSize.Width >= TexWidth - 1)
1130 {
1131 tLine++;
1132 tLeft = 0;
1133
1134 x.Location = new Point(tLeft, x.Location.Y);
1135 tLineDict.Add(x, tLine);
1136
1137 tLeft += tCharSize.Width;
1138 }
1139 else
1140 {
1141 x.Location = new Point(tLeft, x.Location.Y);
1142 tLineDict.Add(x, tLine);
1143
1144 tLeft += tCharSize.Width;
1145 }
1146
1147 // 处理行高
1148 int tCurLineHeight = tCharSize.Height;
1149 if (!tLineHeight.ContainsKey(tLine))
1150 tLineHeight.Add(tLine, tCurLineHeight);
1151 else
1152 {
1153 if (tCurLineHeight > tLineHeight[tLine])
1154 tLineHeight[tLine] = tCurLineHeight;
1155 }
1156 }
1157
1158 // 计算行基线
1159 int[] tBaseLine = new int[tLineHeight.Count];
1160 foreach (KeyValuePair<int, int> y in tLineHeight)
1161 {
1162 if (y.Key == 0)
1163 tBaseLine[0] = y.Value;
1164 else
1165 tBaseLine[y.Key] = tBaseLine[y.Key - 1] + y.Value;
1166

Callers 3

RefreshAllMethod · 0.45
RepaintMethod · 0.45

Calls 2

GetCharSizeMethod · 0.80
ClearMethod · 0.45

Tested by

no test coverage detected