public static CharacterAtom DeSerialize(string FilePath) { CharacterAtom ret = new CharacterAtom(); if (System.IO.File.Exists(FilePath)) { Encoding FileEnc = FileEncodingUtils.GetEncodingJIS(FilePath); string[] Datas = System.IO.File.ReadAllLines(FilePath, FileEnc); for (int i = 0; i < Datas.Length; i++) { if (Datas[i].Length > 6 && Datas[i].Substring(0, 6).ToLower() == "image=") { string filename = Datas[i].Substring(6); string Dir = (new System.IO.DirectoryInfo(FilePath)).Parent.FullName; if (System.IO.File.Exists(Dir + "\\" + filename)) { ret.Avatar = filename;// Dir + "\\" + filename; } } if (Datas[i].Length > 5 && Datas[i].Substring(0, 5).ToLower() == "name=") { ret.Dbname = Datas[i].Substring(5); } if (Datas[i].Length > 7 && Datas[i].Substring(0, 7).ToLower() == "author=") { ret.Author = Datas[i].Substring(7); } } } return(ret); }
void addCharacter(char inText, List <AAtom> outHTML, List <string> openTags, Color currentColor, List <HREF_Attributes> openHREFs) { CharacterAtom c = new CharacterAtom(inText); c.Style_IsBold = hasTag(openTags, "b"); c.Style_IsItalic = hasTag(openTags, "i"); c.Style_IsUnderlined = hasTag(openTags, "u"); c.Style_IsOutlined = hasTag(openTags, "outline"); string fontTag = lastTag(openTags, new string[] { "big", "small", "medium", "basefont" }); switch (fontTag) { case "big": c.Font = Fonts.Big; break; case "medium": c.Font = Fonts.Default; break; case "small": c.Font = Fonts.Small; break; } c.Alignment = getAlignmentFromOpenTags(openTags); c.Color = currentColor; if (openHREFs.Count > 0) { c.HREFAttributes = openHREFs[openHREFs.Count - 1]; } outHTML.Add(c); }
private void txt_Dir_TextChanged(object sender, EventArgs e) { if (System.IO.File.Exists(txt_Dir.Text + "\\character.txt")) { try { CharacterAtom charatom = VocalUtau.Formats.Model.USTs.Otos.CharacterSerializer.DeSerialize(txt_Dir.Text + "\\character.txt"); if (this.txt_Name.Text.Trim() == "") { this.txt_Name.Text = charatom.Dbname; } UtauPic.Image = Image.FromFile(PathUtils.AbsolutePath(PathUtils.AbsolutePath(txt_Dir.Text), charatom.Avatar)); } catch {; } } else { UtauPic.Image = null; } }
// pass bool = false to get the width of the line to be drawn without actually drawing anything. Useful for aligning text. unsafe void writeTexture_Line(List <AAtom> atoms, uint *rPtr, ref int x, int y, int linewidth, int maxHeight, ref int lineheight, bool draw) { for (int i = 0; i < atoms.Count; i++) { AFont font = TextUni.GetFont((int)atoms[i].Font); if (lineheight < font.Height) { lineheight = font.Height; } if (draw) { if (atoms[i] is CharacterAtom) { CharacterAtom atom = (CharacterAtom)atoms[i]; ACharacter character = font.GetCharacter(atom.Character); // HREF links should be colored white, because we will hue them at runtime. uint color = atom.IsHREF ? 0xFFFFFFFF : Utility.UintFromColor(atom.Color); character.WriteToBuffer(rPtr, x, y, linewidth, maxHeight, font.Baseline, atom.Style_IsBold, atom.Style_IsItalic, atom.Style_IsUnderlined, atom.Style_IsOutlined, color, 0xFF000008); } else if (atoms[i] is ImageAtom) { ImageAtom atom = (ImageAtom)atoms[i]; if (lineheight < atom.Height) { lineheight = atom.Height; } Images.AddImage(new Rectangle(x, y + (lineheight - atom.Height) / 2, atom.Width, atom.Height), atom.Texture, GumpData.GetGumpXNA(atom.ValueOver), GumpData.GetGumpXNA(atom.ValueDown)); atom.AssociatedImage = Images[Images.Count - 1]; } } x += atoms[i].Width; } }
void getTextDimensions(Reader reader, int maxwidth, int maxheight, out int width, out int height, out int ascender) { width = 0; height = 0; ascender = 0; int lineheight = 0; int widestline = 0; int descenderheight = 0; int linecount = 0; List <AAtom> word = new List <AAtom>(); int additionalwidth = 0; // for italic + outlined characters, which need a little more room for their slant/outline. int word_width = 0; for (int i = 0; i < reader.Length; ++i) { word_width += reader.Atoms[i].Width; additionalwidth -= reader.Atoms[i].Width; if (additionalwidth < 0) { additionalwidth = 0; } if (lineheight < reader.Atoms[i].Height) { lineheight = reader.Atoms[i].Height; } if (reader.Atoms[i].IsThisAtomALineBreak) { if (width + additionalwidth > widestline) { widestline = width + additionalwidth; } height += lineheight; linecount += 1; descenderheight = 0; lineheight = 0; width = 0; } else { word.Add(reader.Atoms[i]); // we may need to add additional width for special style characters. if (reader.Atoms[i] is CharacterAtom) { CharacterAtom atom = (CharacterAtom)reader.Atoms[i]; AFont font = TextUni.GetFont((int)atom.Font); ACharacter ch = font.GetCharacter(atom.Character); // italic characters need a little extra width if they are at the end of the line. if (atom.Style_IsItalic) { additionalwidth = font.Height / 2; } if (atom.Style_IsOutlined) { additionalwidth += 2; } if (ch.YOffset + ch.Height - lineheight > descenderheight) { descenderheight = ch.YOffset + ch.Height - lineheight; } if (ch.YOffset < 0 && linecount == 0 && ascender > ch.YOffset) { ascender = ch.YOffset; } } if (reader.Atoms[i].Alignment != Alignments.Left) { widestline = maxwidth; } if (i == reader.Length - 1 || reader.Atoms[i + 1].CanBreakAtThisAtom) { // Now make sure this line can fit the word. if (width + word_width + additionalwidth <= maxwidth) { // it can fit! width += word_width + additionalwidth; word_width = 0; word.Clear(); // if this word is followed by a space, does it fit? If not, drop it entirely and insert \n after the word. if (!(i == reader.Length - 1) && reader.Atoms[i + 1].IsThisAtomABreakingSpace) { int charwidth = reader.Atoms[i + 1].Width; if (width + charwidth <= maxwidth) { // we can fit an extra space here. width += charwidth; i++; } else { // can't fit an extra space on the end of the line. replace the space with a \n. ((CharacterAtom)reader.Atoms[i + 1]).Character = '\n'; } } } else { // this word cannot fit in the current line. if ((width > 0) && (i - word.Count >= 0)) { // if this is the last word in a line. Replace the last space character with a line break // and back up to the beginning of this word. if (reader.Atoms[i - word.Count].IsThisAtomABreakingSpace) { ((CharacterAtom)reader.Atoms[i - word.Count]).Character = '\n'; i = i - word.Count - 1; } else { reader.Atoms.Insert(i - word.Count, new CharacterAtom('\n')); i = i - word.Count; } word.Clear(); word_width = 0; } else { // this is the only word on the line and we will need to split it. // first back up until we've reached the reduced the size of the word // so that it fits on one line, and split it there. int iWordWidth = word_width; for (int j = word.Count - 1; j >= 1; j--) { int iDashWidth = TextUni.GetFont((int)word[j].Font).GetCharacter('-').Width; if (iWordWidth + iDashWidth <= maxwidth) { reader.Atoms.Insert(i - (word.Count - j) + 1, new CharacterAtom('\n')); reader.Atoms.Insert(i - (word.Count - j) + 1, new CharacterAtom('-')); break; } iWordWidth -= word[j].Width; } i -= word.Count + 2; if (i < 0) { i = -1; } word.Clear(); width = 0; word_width = 0; } } } } } width += additionalwidth; height += lineheight + descenderheight; linecount += 1; if (widestline > width) { width = widestline; } }