public override void Load(ExtendedBinaryReader reader, bool keepOpen = false) { // Height of the character in pixels CharacterHeight = reader.ReadInt32(); // The amount of characters defined int characterCount = reader.ReadInt32(); // Unknown WidthScale = reader.ReadSingle(); HeightScale = reader.ReadSingle(); for (int i = 0; i < characterCount; ++i) { var fontEntry = new FontEntry { Character = ReadReversedUTF8Char(reader), // The read UTF8 character XScale = reader.ReadSingle(), // X position on the texture (Multiply by the textures width to get pixels) YScale = reader.ReadSingle(), // Y position on the texture (Multiply by the textures height to get pixels) }; if (!MonospaceOnly) { fontEntry.Kerning = reader.ReadInt32(); // -X offset for positioning when rendering fontEntry.Width = reader.ReadInt32(); // The width of the character in pixels } else { fontEntry.Width = CharacterHeight; // Force square character } Characters.Add(fontEntry); } }
public RichTextBuilder Font([NotNull] string fontName, string family = null) { int i = 0; for (; i < _fontTable.Count; i++) { if (string.Equals(fontName, _fontTable[i].Name)) { break; } } if (i < _fontTable.Count) { _fontTable[i] = new FontEntry(i, fontName, family); } else { _fontTable.Add(new FontEntry(i, fontName, family)); } _body.AppendFormat(CultureInfo.InvariantCulture, @"\f{0}", i); _needDelimiter = true; return(this); }
public static void WriteFont(BBData data, FontInfo fi, StringsChunkBuilder strings, int[] texPagOffsets) { var fe = new FontEntry { CodeName = fi.CodeName == null ? 0 : strings.GetOffset(fi.CodeName), SystemName = strings.GetOffset(fi.SystemName), EmSize = fi.EmSize, Bold = fi.IsBold ? DwordBool.True : DwordBool.False, Italic = fi.IsItalic ? DwordBool.True : DwordBool.False, _ignore0 = fi.Characters[0].Character, Charset = fi.Charset, AntiAliasing = fi.AntiAliasing, TPagOffset = (uint)texPagOffsets[fi.TexPagId], Scale = fi.Scale }; foreach (var character in fi.Characters) { if (character.Character > fe._ignore1) { fe._ignore1 = character.Character; } } data.Buffer.Write(fe); data.Buffer.Position -= 8; WriteList(data, fi.Characters, WriteFontCharEntry); }
/// <remarks> /// The <paramref name="family"/>, if present, should be one of: /// nil, roman, swiss, modern, script, decor, tech, bidi. /// It is supposed to help with font substitution, but appears /// to be of limited use in practice and therefore may best be /// omitted. /// </remarks> public void SetDefaultFont([NotNull] string name, string family = null) { if (_fontTable.Count < 1) { _fontTable.Add(new FontEntry(0, name, family)); } else { _fontTable[0] = new FontEntry(0, name, family); } }
View CreateTwitterEntry() { var twitter = new FontEntry { Font = Font.OfSize(Fonts.OpenSansLight, 14), HeightRequest = 30 }; twitter.Keyboard = Keyboard.Text; twitter.SetBinding(Entry.TextProperty, "Twitter"); return(twitter); }
View CreatePhoneEntry() { var phone = new FontEntry { Font = Font.OfSize(Fonts.OpenSansLight, 14), HeightRequest = 30 }; phone.Keyboard = Keyboard.Telephone; phone.SetBinding(Entry.TextProperty, "Phone"); return(phone); }
View CreateEmailEntry() { var email = new FontEntry { Font = Font.OfSize(Fonts.OpenSansLight, 14), HeightRequest = 30 }; email.Keyboard = Keyboard.Email; email.SetBinding(Entry.TextProperty, "Email"); return(email); }
View CreateCompanyEntry() { var company = new FontEntry { Font = Font.OfSize(Fonts.OpenSansLight, 14), Placeholder = "required", HeightRequest = 30 }; company.Keyboard = Keyboard.Text; company.SetBinding(Entry.TextProperty, "Company"); return(company); }
View CreateTitleEntry() { var title = new FontEntry { Font = Font.OfSize(Fonts.OpenSansLight, 14), Placeholder = "required", HeightRequest = 30 }; title.Keyboard = Keyboard.Text; title.SetBinding(Entry.TextProperty, "Title"); return(title); }
View CreateLastNameEntry() { var last = new FontEntry { Font = Font.OfSize(Fonts.OpenSansLight, 14), Placeholder = "required", HeightRequest = 30 }; last.Keyboard = Keyboard.Text; last.SetBinding(Entry.TextProperty, "LastName"); return(last); }
private void SetFont(FontEntry view) { UIFont uiFont; if (view.Font != Font.Default && (uiFont = view.Font.ToUIFont()) != null) { Control.Font = uiFont; } else if (view.Font == Font.Default) { Control.Font = UIFont.SystemFontOfSize(17f); } }
// private void SetBorder(FontEntry view) // { // Control.BorderStyle = view.HasBorder ? UITextBorderStyle.RoundedRect : UITextBorderStyle.None; // } private void SetTextAlignment(FontEntry view) { switch (view.XAlign) { case TextAlignment.Center: Control.TextAlignment = UITextAlignment.Center; break; case TextAlignment.End: Control.TextAlignment = UITextAlignment.Right; break; case TextAlignment.Start: Control.TextAlignment = UITextAlignment.Left; break; } }
void UpdateText(FontEntry mEntry) { //FormattedString formattedString = base.Element.FormattedText ?? base.Element.Text; FormattedString formattedString = base.Element.Text; this.view.TextFormatted = formattedString.ToAttributed(Font.Default, base.Element.TextColor, this.view); if (mEntry.Font.FontFamily != null) { this.view.Typeface = Typeface.CreateFromAsset(Forms.Context.Assets, string.Format("{0}.ttf", GetFontFamily(mEntry.Font))); } if (mEntry.Font.FontSize > 0) { this.view.TextSize = (float)mEntry.Font.FontSize; } }
public static FontWrapper LoadFile(string pathToFont, FontKind kind = FontKind.Texture) { if (!File.Exists(pathToFont)) { throw new FileNotFoundException(pathToFont + " could not be found!"); } var hash = CalculateHashCode(pathToFont, kind); FontEntry fe; if (fontCache.TryGetValue(hash, out fe)) { fe.ReferenceCount++; return(new FontWrapper(hash, fe.Handle, kind)); } IntPtr font; switch (kind) { case FontKind.Pixmap: font = Fonts.CreatePixmapFont(pathToFont); break; default: case FontKind.Texture: font = Fonts.CreateTextureFont(pathToFont); break; } if (font == IntPtr.Zero) { throw new FTGLException(IntPtr.Zero); } fontCache [hash] = new FontEntry(font); return(new FontWrapper(hash, font, kind)); }
public void generateStuff(int size = 24, bool _2x = false) { Library font = new Library(); Face face = font.NewFace(file, 0); //Stroker stroke = new Stroker(font); int height = 0; char averageCh = 'A'; double fontScale = 1; string[] characters = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" }; if (isScore) characters = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ".", ",", "%", "x" }; var entries = new List<FontEntry>(); face.SetCharSize(0, size << 6, 0, 96); face.SetTransform(new FTMatrix(3 << 16, 0, 0, 3 << 16), FTVector.Unit(0)); // thicknesssss //stroke.Set(1, StrokerLineCap.Round, StrokerLineJoin.Round, 0); face.LoadGlyph(face.GetCharIndex(averageCh), LoadFlags.Default, LoadTarget.Normal); height = (int)face.Glyph.Metrics.HorizontalBearingY >> 6; // then fill the fontentry array foreach (var ch in characters) { face.LoadGlyph(face.GetCharIndex(ch[0]), LoadFlags.Default, LoadTarget.Normal); face.Glyph.RenderGlyph(RenderMode.Normal); Bitmap bitmap; if (face.Glyph.Bitmap.Width == 0) { bitmap = new Bitmap(1, 1); } else { bitmap = new Bitmap(face.Glyph.Bitmap.Width + 4, face.Glyph.Bitmap.Rows + 4); var gg = Graphics.FromImage(bitmap); gg.Clear(Color.Transparent); var data = bitmap.LockBits(new Rectangle(2, 2, bitmap.Width - 4, bitmap.Height - 4), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); byte[] pixelAlphas = new byte[face.Glyph.Bitmap.Width * face.Glyph.Bitmap.Rows]; Marshal.Copy(face.Glyph.Bitmap.Buffer, pixelAlphas, 0, pixelAlphas.Length); for (int j = 0; j < pixelAlphas.Length; j++) { int pixelOffset = (j / data.Width) * data.Stride + (j % data.Width * 4); Marshal.WriteByte(data.Scan0, pixelOffset + 0, colorDialog1.Color.R); Marshal.WriteByte(data.Scan0, pixelOffset + 1, colorDialog1.Color.G); Marshal.WriteByte(data.Scan0, pixelOffset + 2, colorDialog1.Color.B); Marshal.WriteByte(data.Scan0, pixelOffset + 3, pixelAlphas[j]); } bitmap.UnlockBits(data); } var entry = new FontEntry(); entry.Character = ch[0]; entry.Bitmap = bitmap; entry.AdvanceX = (int)(((face.Glyph.Metrics.HorizontalAdvance >> 6)) * fontScale); entry.PreX = (int)(((face.Glyph.Metrics.HorizontalBearingX >> 6)) * fontScale); entry.Width = (int)((face.Glyph.Metrics.Width >> 6) * fontScale); entry.Height = (int)((face.Glyph.Metrics.Height >> 6) * fontScale); entry.PreY = (int)((face.Glyph.Metrics.HorizontalBearingY >> 6) * -fontScale); if (entry.Width < 2) { entry.Width = 2; } entries.Add(entry); } foreach (var entry in entries) { Bitmap bitmap = entry.Bitmap; var fontpath = file.Split('\\').Last().Replace(".ttf", ""); if (!Directory.Exists(Path.Combine(Directory.GetCurrentDirectory(), "generated\\" + fontpath))) Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "generated\\" + fontpath)); string name = ""; switch (entry.Character.ToString()) { case ".": name = "dot"; break; case ",": name = "comma"; break; case "%": name = "percent"; break; default: name = entry.Character.ToString(); break; } bitmap.Save(@"generated\\" + fontpath + "\\" + ((isScore) ? "score-" : "default-") + name + ((_2x) ? "@2x" : "") + ".png", ImageFormat.Png); } }