public static GlyphItem Create(string glyph, Rectangle uv, Vector2d size, Vector2d extents) { GlyphItem temp = new GlyphItem(glyph); temp.Glyph = glyph; temp.UVRect = uv; temp.Size = size; temp.Extents = extents; temp.ReferenceCount = 1; return(temp); }
public void AddGlyph(string glyph) { if (!GlyphItems.ContainsKey(glyph)) { GlyphItem item = new GlyphItem(glyph); GlyphItems[glyph] = item; dirty = true; textureDirty = true; version++; allGlyphs = allGlyphs + glyph.ToString(); } else { GlyphItems[glyph].AddRef(); } }
private void LoadXmlGlyph(XmlDocument xml) { XmlNode nodes = Util.SelectSingleNode(xml, "GlyphItems"); foreach (XmlNode glyphItem in nodes.ChildNodes) { if (glyphItem.Name == "GlyphItem") { GlyphItem item = GlyphItem.FromXML(glyphItem); GlyphItems[item.Glyph] = item; allGlyphs = allGlyphs + item.Glyph; } } Ready = true; }
internal static GlyphItem FromXML(XmlNode node) { string glyph = node.Attributes.GetNamedItem("Glyph").Value; GlyphItem item = new GlyphItem(glyph); item.UVRect = Rectangle.Create( double.Parse(node.Attributes.GetNamedItem("UVLeft").Value), double.Parse(node.Attributes.GetNamedItem("UVTop").Value), double.Parse(node.Attributes.GetNamedItem("UVWidth").Value), double.Parse(node.Attributes.GetNamedItem("UVHeight").Value) ); item.Size = Vector2d.Create( double.Parse(node.Attributes.GetNamedItem("SizeWidth").Value), double.Parse(node.Attributes.GetNamedItem("SizeHeight").Value)); item.Extents = Vector2d.Create( double.Parse(node.Attributes.GetNamedItem("ExtentsWidth").Value), double.Parse(node.Attributes.GetNamedItem("ExtentsHeight").Value)); return(item); }
public void PrepareBatch() { if (glyphCache == null) { glyphCache = GlyphCache.GetCache(Height); } if (glyphCache.Ready == false) { return; } // Add All Glyphs //foreach (Text3d t3d in Items) //{ // foreach (char c in t3d.Text) // { // glyphCache.AddGlyph(c); // } //} //// Calculate Metrics TextObject.Text = ""; TextObject.FontSize = (float)Height * .50f; //System.Drawing.Font font = TextObject.Font; //StringFormat sf = new StringFormat(); //sf.Alignment = StringAlignment.Near; //Bitmap bmp = new Bitmap(20, 20); //Graphics g = Graphics.FromImage(bmp); //// Create Index Buffers List <PositionTexture> verts = new List <PositionTexture>(); foreach (Text3d t3d in Items) { String text = t3d.Text; float left = 0; float top = 0; float fntAdjust = TextObject.FontSize / 128f; float factor = .6666f; float width = 0; float height = 0; for (int i = 0; i < text.Length; i++) { GlyphItem item = glyphCache.GetGlyphItem(text.Substr(i, 1)); if (item != null) { width += (float)(item.Extents.X); height = Math.Max(item.Extents.Y, height); } } Vector2d size = Vector2d.Create(width, height); t3d.width = size.X * (float)t3d.scale * factor * fntAdjust; t3d.height = size.Y * (float)t3d.scale * factor * fntAdjust; int charsLeft = text.Length; for (int i = 0; i < charsLeft; i++) { GlyphItem item = glyphCache.GetGlyphItem(text.Substr(i, 1)); if (item != null) { Rectangle position = Rectangle.Create(left * (float)t3d.scale * factor, 0 * (float)t3d.scale * factor, item.Extents.X * fntAdjust * (float)t3d.scale * factor, item.Extents.Y * fntAdjust * (float)t3d.scale * factor); left += (float)(item.Extents.X * fntAdjust); //System.Diagnostics.Debug.WriteLine((position.Width/position1.Width).ToString() + ", " + (position.Height / position1.Height).ToString()); t3d.AddGlyphPoints(verts, item.Size, position, item.UVRect); } } } vertCount = verts.Count; vertexBuffer = new PositionTextureVertexBuffer(vertCount); PositionTexture[] vertBuf = (PositionTexture[])vertexBuffer.Lock(); // Lock the buffer (which will return our structs) for (int i = 0; i < vertCount; i++) { vertBuf[i] = verts[i]; } vertexBuffer.Unlock(); glyphVersion = glyphCache.Version; }
internal static GlyphItem FromXML(XmlNode node) { string glyph = node.Attributes.GetNamedItem("Glyph").Value; GlyphItem item = new GlyphItem(glyph); item.UVRect = Rectangle.Create( double.Parse(node.Attributes.GetNamedItem("UVLeft").Value), double.Parse(node.Attributes.GetNamedItem("UVTop").Value), double.Parse(node.Attributes.GetNamedItem("UVWidth").Value), double.Parse(node.Attributes.GetNamedItem("UVHeight").Value) ); item.Size = Vector2d.Create( double.Parse(node.Attributes.GetNamedItem("SizeWidth").Value), double.Parse(node.Attributes.GetNamedItem("SizeHeight").Value)); item.Extents = Vector2d.Create( double.Parse(node.Attributes.GetNamedItem("ExtentsWidth").Value), double.Parse(node.Attributes.GetNamedItem("ExtentsHeight").Value)); return item; }
public static GlyphItem Create(string glyph, Rectangle uv, Vector2d size, Vector2d extents) { GlyphItem temp = new GlyphItem(glyph); temp.Glyph = glyph; temp.UVRect = uv; temp.Size = size; temp.Extents = extents; temp.ReferenceCount = 1; return temp; }