public Font Clone() { Font font = new Font(0); font.FirstCodePoint = FirstCodePoint; font.LastCodePoint = LastCodePoint; font.NewlineCodePoint = NewlineCodePoint; font.TabCodePoint = TabCodePoint; font.SpaceCodePoint = SpaceCodePoint; font.variableWidth = variableWidth; font.height = height; font.widthMustBeMultipleOfEight = widthMustBeMultipleOfEight; font.Glyphs = new Char[MaximumCodePoints]; for (int i = 0; i < MaximumCodePoints; i++) font.Glyphs[i] = Glyphs[i].Clone(); font.AboutData = new Dictionary<string, string>(); foreach (KeyValuePair<string, string> s in AboutData) font.AboutData.Add(s.Key, s.Value); return font; }
/// <summary> /// Copies glyphs from this font into a new MFE font, using the /// characters found in the code page file to specify what characters /// to extract. /// </summary> /// <param name="cp"></param> /// <returns></returns> public Mfe.Font MakeMfeFont(CodePageTable cp) { Font font = new Font(); font.Height = this.Height; font.WidthMustBeMultipleOfEight = false; //font["Name"] = this.Name; font["Code Page"] = cp.Name; font.BaseLine = (byte)(Height - (Yoff < 0 ? -Yoff : Yoff)); for (int i = 0; i < cp.CodePoints.Length; i++) { var v = Chars.Where(ch => ch.Codepoint == cp[i]); if (v.FirstOrDefault() != null) font[i] = v.First(); else { Mfe.Char t = new Char(); t.Height = font.Height; font[i] = t; } } return font; }
public static Font DeserializeFrom(byte[] source, ref int i) { if (source[i++] != (int)SerialzationHeaderIds.MasterField) throw new ArgumentException("Invalid font."); i += 4; int p = -1; int temp; if (source[i++] != (int)SerialzationHeaderIds.Version) throw new ArgumentException("Invalid font."); temp = DeserializeInt(source, ref i); if (temp != 2) throw new ArgumentException("Invalid font."); if (source[i++] != CurrentVersionNumber) throw new ArgumentException("Unable to read new font version."); i++; Font font = new Font(0); while (i < source.Length && p != i) { p = i; switch ((SerialzationHeaderIds)source[i++]) { case SerialzationHeaderIds.AboutInformation: i += 4; // Ignore size temp = DeserializeInt(source, ref i); font.AboutData = new Dictionary<string, string>(temp + 4); for (int j = 0; j < temp; j++) font.AboutData.Add(DeserializeString(source, ref i), DeserializeString(source, ref i)); break; case SerialzationHeaderIds.BasicInformation: if (DeserializeInt(source, ref i) != 15) throw new ArgumentException("Invalid BasicInformation"); font.FirstCodePoint = source[i++]; font.LastCodePoint = source[i++]; font.NewlineCodePoint = source[i++]; font.TabCodePoint = source[i++]; font.SpaceCodePoint = source[i++]; font.variableWidth = source[i++] != 0 ? true : false; font.height = source[i++]; font.aspectRatioWidth = (float)DeserializeInt(source, ref i) / 65536; font.aspectRatioHeight = (float)DeserializeInt(source, ref i) / 65536; break; case SerialzationHeaderIds.WidthMustBeMultipleOfEightFlag: if ((temp = DeserializeInt(source, ref i)) != 1) throw new ArgumentException("Invalid WidthMustBeMultipleOfEightFlag (" + temp.ToString() + ")"); //i += 4; temp = source[i++]; font.widthMustBeMultipleOfEight = (temp & 1) != 0; break; case SerialzationHeaderIds.Glyphs: i += 4; // Ignore size if (DeserializeInt(source, ref i) != MaximumCodePoints) throw new ArgumentOutOfRangeException("MaximumCodePoints in font does not match internally expected value."); font.Glyphs = new Char[MaximumCodePoints]; for (int j = 0; j < MaximumCodePoints; j++) font.Glyphs[j] = Char.DeserializeFrom(source, ref i); break; default: throw new ArgumentException("Invalid font."); } } return font; }