예제 #1
0
        public void AddTask(string s, Font font, Brush brush, PointF point)
        {
            if (!(brush is SolidBrush))
            {
                throw new NotSupportedException("brush");
            }
            _colors.Add((brush as SolidBrush).Color);
            MyFont myFont = FontManager.GetFont(FontManager.FindClosestFont(font));

            string[] lines = s.Split('\n');
            float    k     = (font.SizeInPoints / myFont.FontInfo.Pt);
            //k = 1;
            int glyphHeight = (int)(k * myFont.FontInfo.Height);
            int realStrLen  = 0;

            foreach (string str in lines)
            {
                int strLen = str.Length;
                realStrLen += strLen;
                float x = point.X;
                for (int j = 0; j < strLen; j++)
                {
                    if (!myFont.Symbols.ContainsKey(str[j]))
                    {
                        realStrLen--;
                        continue;
                    }
                    GlyphData symbol = myFont.Symbols[str[j]];
                    AddVertex(x + symbol.XOffset * k,
                              point.Y + symbol.YOffset * k,
                              symbol.TextureXPos,
                              symbol.TextureYPos);
                    AddVertex(x + (symbol.XOffset + symbol.Width) * k,
                              point.Y + symbol.YOffset * k,
                              symbol.TextureWidth,
                              symbol.TextureYPos);
                    AddVertex(x + symbol.XOffset * k,
                              point.Y + (symbol.YOffset + symbol.Height) * k,
                              symbol.TextureXPos,
                              symbol.TextureHeight);

                    AddVertex(x + (symbol.XOffset + symbol.Width) * k,
                              point.Y + symbol.YOffset * k,
                              symbol.TextureWidth,
                              symbol.TextureYPos);
                    AddVertex(x + (symbol.XOffset + symbol.Width) * k,
                              point.Y + (symbol.YOffset + symbol.Height) * k,
                              symbol.TextureWidth,
                              symbol.TextureHeight);
                    AddVertex(x + symbol.XOffset * k,
                              point.Y + (symbol.YOffset + symbol.Height) * k,
                              symbol.TextureXPos,
                              symbol.TextureHeight);
                    x += (myFont.Symbols[str[j]].OrigW + (j != strLen - 1 ? myFont.GetKerningDelta(str[j], str[j + 1]) : 0.0f)) * k;
                }
                point.Y += glyphHeight;
            }
            _stringLens.Add(realStrLen);
            _fontTextures.Add(myFont.FontTexture);
        }