private void _DrawText(Graphics g, Size bmpSize, CFont font, List <CTextElement> elements) { Font fo = CFonts.GetSystemFont(font); float maxHeight = elements.Select(el => el.Height).Max(); int lineCount = elements.Last().Line + 1; //Have to use size in em not pixels! float emSize = fo.Size * fo.FontFamily.GetCellAscent(fo.Style) / fo.FontFamily.GetEmHeight(fo.Style); float outlineSize = CFonts.GetOutlineSize(font) * font.Height; SColorF outlineColorF = CFonts.GetOutlineColor(font); outlineColorF.A = outlineColorF.A * _TextColor.A; using (var path = new GraphicsPath()) using (var pen = new Pen(outlineColorF.AsColor(), outlineSize / 2)) { pen.LineJoin = LineJoin.Round; pen.Alignment = PenAlignment.Outset; float top = (bmpSize.Height - _MarginBottom - _MarginTop - maxHeight * lineCount) / 2 + _MarginTop; int nextLineEl = 0; for (int i = 0; i < lineCount; i++) { int firstEl = nextLineEl; for (; nextLineEl < elements.Count; nextLineEl++) { if (elements[nextLineEl].Line > i) { break; } } string line = elements.GetRange(firstEl, nextLineEl - firstEl).Aggregate("", (current, element) => current + element.Text); float left; if (lineCount == 1 || (i == 1 && lineCount == 3)) { //Center Text if this is the only line or the middle line float width = _GetWidth(elements, firstEl, nextLineEl - 1); left = (bmpSize.Width - _MarginLeft - _MarginRight - width) / 2 + _MarginLeft; } else if (i == lineCount - 1) { //Place last line at right float width = _GetWidth(elements, firstEl, nextLineEl - 1); left = bmpSize.Width - width - _MarginRight; } else { left = _MarginLeft; } //g.DrawString(line, fo, new SolidBrush(_TextColor.AsColor()), left, top, StringFormat.GenericTypographic); path.AddString(line, fo.FontFamily, (int)fo.Style, emSize, new PointF(left, top), StringFormat.GenericTypographic); top += maxHeight + _LineSpace; } g.DrawPath(pen, path); g.FillPath(new SolidBrush(_TextColor.AsColor()), path); } }
private void _DrawBackground(Graphics g, Bitmap bmpBackground, String firstCoverPath) { g.Clear(_BGColor.AsColor()); ImageAttributes ia = null; if (_Theme.ShowFirstCover && !String.IsNullOrEmpty(firstCoverPath) && File.Exists(firstCoverPath)) { using (Bitmap bmp2 = new Bitmap(firstCoverPath)) g.DrawImage(bmp2, bmpBackground.GetRect(), 0, 0, bmp2.Width, bmp2.Height, GraphicsUnit.Pixel); ColorMatrix cm = new ColorMatrix { Matrix33 = _Theme.ImageAlpha }; ia = new ImageAttributes(); ia.SetColorMatrix(cm); } g.DrawImage(bmpBackground, bmpBackground.GetRect(), 0, 0, bmpBackground.Width, bmpBackground.Height, GraphicsUnit.Pixel, ia); }