// Previewer public IList <Bitmap> GeneratePreviews(TextEntry entry) { var pages = new List <Bitmap>(); if (entry?.EditedText == null) { return(pages); } string kuriimuString = GetKuriimuString(entry.EditedText); int boxes = kuriimuString.Count(c => c == (char)0x17) + 1; Bitmap img = new Bitmap(textBox.Width, textBox.Height * boxes); Encoding unicode = Encoding.GetEncoding("unicode"); Encoding sjis = Encoding.GetEncoding("SJIS"); using (Graphics gfx = Graphics.FromImage(img)) { gfx.SmoothingMode = SmoothingMode.HighQuality; gfx.InterpolationMode = InterpolationMode.Bicubic; gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; for (int i = 0; i < boxes; i++) { gfx.DrawImage(textBox, 0, i * textBox.Height); } RectangleF rectText = new RectangleF(10, 10, 370, 100); Color colorDefault = Color.FromArgb(255, 255, 255, 255); float scaleDefault = 1.0f; //float scaleName = 0.86f; float scaleCurrent = scaleDefault; float x = rectText.X, pX = x; float y = rectText.Y, pY = y; //float yAdjust = 4; //int box = 0; //font.SetTextColor(colorDefault); for (int i = 0; i < kuriimuString.Length; i++) { var info = font.GetWidthInfo(kuriimuString[i]); x += info.left; byte[] tmp = sjis.GetBytes(new char[] { kuriimuString[i] }); if (tmp.Length < 2) { tmp = new byte[] { 0, tmp[0] } } ; font.Draw(unicode.GetString(tmp.Reverse().ToArray())[0], gfx, x, y, scaleDefault, scaleDefault); x += info.glyph_width - info.left; if (kuriimuString[i] == '・') { x = rectText.X; y += 17; } } } pages.Add(img); return(pages); }
// Previewer public IList <Bitmap> GeneratePreviews(TextEntry entry) { var pages = new List <Bitmap>(); if (entry?.EditedText == null) { return(pages); } //string kuriimuString = _previewPairs.Aggregate(GetKuriimuString(entry.EditedText), (s, pair) => s.Replace(pair.Key, pair.Value)); string kuriimuString = _previewPairs.Aggregate(GetKuriimuString(entry.EditedText), (s, pair) => s.Replace(pair.Key, pair.Value)); Bitmap img = new Bitmap(1, 1); switch (Enum.Parse(typeof(BubbleType), Properties.Settings.Default.BubbleType)) { case BubbleType.Type1: img = new Bitmap(bubble001.Width, bubble001.Height); break; case BubbleType.Type2: img = new Bitmap(bubble002.Width, bubble002.Height); break; } using (Graphics gfx = Graphics.FromImage(img)) { gfx.SmoothingMode = SmoothingMode.HighQuality; gfx.InterpolationMode = InterpolationMode.Bicubic; gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; RectangleF rectText = new RectangleF(0, 0, 0, 0); Color colorDefault = Color.FromArgb(255, 0, 0, 0); switch (Enum.Parse(typeof(BubbleType), Properties.Settings.Default.BubbleType)) { case BubbleType.Type1: gfx.DrawImage(bubble001, 0, 0); rectText = new RectangleF(12, 9, 370, 100); break; case BubbleType.Type2: gfx.DrawImage(bubble002, 0, 0); rectText = new RectangleF(20, 11, 370, 100); break; } float scaleDefault = 1.0f; float scaleCurrent = scaleDefault; float x = rectText.X, pX = x; float y = rectText.Y, pY = y; //float fontSize = 3.2f; float fontSize = 1.5f; for (int i = 0; i < kuriimuString.Length; i++) { BCFNT.CharWidthInfo widthInfo = font.GetWidthInfo(kuriimuString[i]); font.SetColor(colorDefault); if (kuriimuString[i] == '\n') { switch (Enum.Parse(typeof(BubbleType), Properties.Settings.Default.BubbleType)) { case BubbleType.Type1: y += 15; x = 12; continue; case BubbleType.Type2: y += 13; x = 18; continue; } } font.Draw(kuriimuString[i], gfx, x, y, scaleCurrent, scaleCurrent); x += widthInfo.char_width - fontSize; } } pages.Add(img); return(pages); }
// Previewer public IList <Bitmap> GeneratePreviews(IEntry entry) { var pages = new List <Bitmap>(); if (entry == null) { return(pages); } string kuriimuString = GetKuriimuString(entry.EditedText); int boxes = kuriimuString.Count(c => c == (char)0x17) + 1; Bitmap img = new Bitmap(textBox.Width, textBox.Height * boxes); using (Graphics gfx = Graphics.FromImage(img)) { gfx.SmoothingMode = SmoothingMode.HighQuality; gfx.InterpolationMode = InterpolationMode.Bicubic; gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; for (int i = 0; i < boxes; i++) { gfx.DrawImage(textBox, 0, i * textBox.Height); } RectangleF rectText = new RectangleF(10, 10, 370, 100); Color colorDefault = Color.FromArgb(255, 255, 255, 255); float scaleDefault = 1.0f; //float scaleName = 0.86f; float scaleCurrent = scaleDefault; float x = rectText.X, pX = x; float y = rectText.Y, pY = y; //float yAdjust = 4; //int box = 0; //font.SetTextColor(colorDefault); for (int i = 0; i < kuriimuString.Length; i++) { if (kuriimuString[i] == ' ') { x += 5; } else if (kuriimuString[i] == '\xa') { x = rectText.X; y += 15; } else { var info = font.GetWidthInfo(kuriimuString[i]); x += info.left; font.Draw(kuriimuString[i], gfx, x, y, scaleDefault, scaleDefault); x += info.glyph_width - info.left; } } } pages.Add(img); return(pages); }
public Bitmap GeneratePreview(string rawString) { Bitmap img = new Bitmap(background.Width, background.Height); using (Graphics gfx = Graphics.FromImage(img)) { gfx.SmoothingMode = SmoothingMode.HighQuality; gfx.InterpolationMode = InterpolationMode.Bicubic; gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; gfx.DrawImage(background, 0, 0); float[][] fadeToFiftyPercentMatrix = { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, 0.45f, 0 }, new float[] { 0, 0, 0, 0, 1 }, }; // Textbox Bitmap textBox = new Bitmap(Resources.top_speaker_bg); ColorMatrix textBoxMatrix = new ColorMatrix(fadeToFiftyPercentMatrix); ImageAttributes textBoxAttributes = new ImageAttributes(); textBoxAttributes.SetColorMatrix(textBoxMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); Rectangle rectTextBox = new Rectangle(0, img.Height - textBox.Height / 2, img.Width, textBox.Height / 2); gfx.InterpolationMode = InterpolationMode.NearestNeighbor; gfx.DrawImage(textBox, rectTextBox, 0, 0, textBox.Width, textBox.Height, GraphicsUnit.Pixel, textBoxAttributes); // Face Bitmap face = Resources.face_icon_pikachu_surprised; Rectangle rectFace = new Rectangle(5, img.Height - face.Height - 4, face.Width, face.Height); gfx.DrawImageUnscaled(face, rectFace); // Text Rectangle rectText = new Rectangle(rectFace.X + rectFace.Width + 9, rectFace.Y + 12, 366, 60); float scale = 1.0f; float x = rectText.X, y = rectText.Y; int line = 0; string str = rawString; font.SetTextColor(Color.White); gfx.InterpolationMode = InterpolationMode.Bicubic; foreach (char c in str) { switch (c) { case '\n': x = rectText.X; y += rectText.Y; if (++line % 3 == 0) { y += 33; } continue; } font.SetTextColor(Color.FromArgb(255, 63, 3, 3)); font.DrawCharacter(c, gfx, x + 2f, y + 2f, scale); font.SetTextColor(Color.White); font.DrawCharacter(c, gfx, x, y, scale); x += font.GetWidthInfo(c).char_width *scale; } // Cursor Bitmap cursor = new Bitmap(Resources.top_speaker); RectangleF rectCursor = new RectangleF(381, 225, 13.9f, 10); gfx.DrawImage(cursor, rectCursor); } return(img); }
public Bitmap GeneratePreview(string rawString) { int boxes = rawString.Count(c => c == '\n') / 3 + 1; const int txtOffsetX = 2; const int txtOffsetY = 2; Bitmap img = new Bitmap(400, Math.Max((txtOffsetY + textBox.Height) * boxes + txtOffsetY, background.Height)); using (Graphics gfx = Graphics.FromImage(img)) { gfx.SmoothingMode = SmoothingMode.HighQuality; gfx.InterpolationMode = InterpolationMode.Bicubic; gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; gfx.DrawImage(background, 0, 0); for (int i = 0; i < boxes; i++) { gfx.DrawImage(textBox, txtOffsetX, (txtOffsetY + textBox.Height) * i + txtOffsetY); } float scale = 0.625f; float x = 10, y = 22; int line = 0; string str = _previewPairs.Aggregate(rawString, (s, pair) => s.Replace(pair.Key, pair.Value)); font.SetTextColor(Color.White); foreach (char c in str) { switch (c) { case '‹': // Player Name font.SetTextColor(Color.FromArgb(255, 254, 254, 149)); continue; case '<': // Orange font.SetTextColor(Color.FromArgb(255, 255, 150, 0)); continue; case '{': // Green font.SetTextColor(Color.FromArgb(255, 131, 237, 63)); continue; case '[': // Purple font.SetTextColor(Color.FromArgb(255, 255, 100, 255)); continue; case '›': // Reset color case '>': case '}': case ']': font.SetTextColor(Color.White); continue; case '\n': x = 10; y += 16; if (++line % 3 == 0) { y += 33; } continue; } // Otherwise it's a regular drawable character font.DrawCharacter(c, gfx, x, y, scale); x += font.GetWidthInfo(c).char_width *scale; } } return(img); }
// Previewer public IList <Bitmap> GeneratePreviews(TextEntry entry) { var pages = new List <Bitmap>(); if (entry == null) { return(pages); } // Paging evety 3rd new line List <string> strings = new List <string>(); string[] lines = entry.EditedText.Split('\n'); string built = string.Empty; int current = 0; for (int i = 0; i < lines.Length; i++) { built += lines[i] + (i != lines.Length - 1 ? "\n" : string.Empty); current++; if (current % 3 == 0) { strings.Add(built); built = string.Empty; } } if ((strings.Count == 0 && built != string.Empty) || (strings.Count > 0 && strings.Last().EndsWith("\n"))) { strings.Add(built); } foreach (string page in strings) { const int txtOffsetX = 2; const int txtOffsetY = 2; Bitmap img = new Bitmap(background.Width, background.Height); using (Graphics gfx = Graphics.FromImage(img)) { gfx.SmoothingMode = SmoothingMode.HighQuality; gfx.InterpolationMode = InterpolationMode.Bicubic; gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; gfx.DrawImage(background, 0, 0); gfx.DrawImage(textBox, txtOffsetX, txtOffsetY); float scale = 0.625f; float x = 10, y = 22; string str = _previewPairs.Aggregate(page, (s, pair) => s.Replace(pair.Key, pair.Value)).Replace("‹PlayerName›", "‹" + Properties.Settings.Default.PlayerName + "›"); font.SetColor(Color.White); foreach (char c in str) { switch (c) { case '‹': // Player Name font.SetColor(Color.FromArgb(255, 254, 254, 149)); continue; case '<': // Orange font.SetColor(Color.FromArgb(255, 255, 150, 0)); continue; case '{': // Green font.SetColor(Color.FromArgb(255, 131, 237, 63)); continue; case '[': // Purple font.SetColor(Color.FromArgb(255, 255, 100, 255)); continue; case '›': // Reset color case '>': case '}': case ']': font.SetColor(Color.White); continue; case '\n': x = 10; y += 16; continue; } // Otherwise it's a regular drawable character font.Draw(c, gfx, x, y, scale, scale); x += font.GetWidthInfo(c).char_width *scale; } } pages.Add(img); } return(pages); }
public Bitmap GeneratePreview(string rawString) { int boxes = rawString.Count(c => c == (char)0x17) + 1; Bitmap img = new Bitmap(textBox.Width, textBox.Height * boxes); using (Graphics gfx = Graphics.FromImage(img)) { gfx.SmoothingMode = SmoothingMode.HighQuality; gfx.InterpolationMode = InterpolationMode.Bicubic; gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; for (int i = 0; i < boxes; i++) { gfx.DrawImage(textBox, 0, i * textBox.Height); } RectangleF rectName = new RectangleF(15, 3, 114, 15); RectangleF rectText = new RectangleF(15, 22, 370, 60); Color colorDefault = Color.FromArgb(255, 37, 66, 167); float scaleDefault = 1.0f; float scaleName = 0.86f; float scaleCurrent = scaleDefault; float x = rectText.X, pX = x; float y = rectText.Y, pY = y; float yAdjust = 4; int box = 0; string str = rawString.Replace("\x1F\x05", "Player"); font.SetTextColor(colorDefault); for (int i = 0; i < str.Length; i++) { bool notEOS = i + 2 < str.Length; char c = str[i]; char c2 = ' '; if (notEOS) { c2 = str[i + 1]; } BCFNT.CharWidthInfo widthInfo = font.GetWidthInfo(c); // Handle control codes if (c == 0x001F && c2 == 0x0002) // Start Name { font.SetTextColor(Color.White); scaleCurrent = scaleName; float width = font.MeasureString(str.Substring(i + 2), (char)0x0002, scaleCurrent); pX = x; pY = y; x = rectName.X + (rectName.Width / 2) - (width / 2); y = rectName.Y; i++; continue; } else if (c == 0x001F && (c2 == 0x0000 || c2 == 0x0100 || c2 == 0x0200 || c2 == 0x0103 || c2 == 0x0020 || c2 == 0x0115)) // Unknown/No Render Effect { i++; continue; } else if (c == 0x0013 && c2 == 0x0000) // Default { font.SetTextColor(colorDefault); i++; continue; } else if (c == 0x0013 && c2 == 0x0001) // Red { font.SetTextColor(Color.Red); i++; continue; } else if (c == 0x0013 && c2 == 0x0003) // Light Blue { font.SetTextColor(Color.FromArgb(255, 54, 129, 216)); i++; continue; } else if (c == 0x001F && c2 == 0x0015) // End Dialog { i++; continue; } else if (c == 0x0017) // Next TextBox { box++; x = rectText.X; pX = x; y = rectText.Y + textBox.Height * box; pY += y; continue; } else if (c == 0x0002) // End Name { font.SetTextColor(colorDefault); scaleCurrent = scaleDefault; x = pX; y = pY; continue; } else if (c == '\n' || x + (widthInfo.char_width * scaleCurrent) - rectText.X > rectText.Width) // New Line/End of Textbox { x = rectText.X; y += (16 * scaleCurrent) + yAdjust; if (c == '\n') { continue; } } // Otherwise it's a regular drawable character font.DrawCharacter(c, gfx, x, y, scaleCurrent); x += widthInfo.char_width * scaleCurrent; } } return(img); }