void ReadGlyphList(BinaryReader reader) { ushort glyphCount = reader.ReadUInt16(); for (int i = 0; i < glyphCount; ++i) { //read each glyph map info //1. codepoint var glyphMap = new TextureGlyphMapData(); ushort glyphIndex = reader.ReadUInt16(); //2. area, left,top,width,height glyphMap.Left = reader.ReadUInt16(); glyphMap.Top = reader.ReadUInt16(); glyphMap.Width = reader.ReadUInt16(); glyphMap.Height = reader.ReadUInt16(); //3. border x,y int borderXY = reader.ReadUInt16(); glyphMap.BorderX = borderXY & 0xff; glyphMap.BorderY = borderXY >> 8; //--------------------------------------- //4. texture offset glyphMap.TextureXOffset = reader.ReadSingle(); glyphMap.TextureYOffset = reader.ReadSingle(); //--------------------------------------- _atlas.AddGlyph(glyphIndex, glyphMap); } }
//-------------------- internal void WriteGlyphList(Dictionary <ushort, TextureGlyphMapData> glyphs) { _writer.Write((ushort)FontTextureObjectKind.GlyphList); //total number int totalNum = glyphs.Count; #if DEBUG if (totalNum >= ushort.MaxValue) { throw new NotSupportedException(); } #endif _writer.Write((ushort)totalNum); // foreach (var kp in glyphs) { ushort glyphIndex = kp.Key; TextureGlyphMapData g = kp.Value; //1. code point _writer.Write((ushort)glyphIndex); //2. area, left,top,width,height _writer.Write((ushort)g.Left); _writer.Write((ushort)g.Top); _writer.Write((ushort)g.Width); _writer.Write((ushort)g.Height); //3. texture offset _writer.Write((short)g.TextureXOffset); //short _writer.Write((short)g.TextureYOffset); //short } }
public bool TryGetGlyphMapData(ushort glyphIndex, out TextureGlyphMapData glyphdata) { if (!_glyphLocations.TryGetValue(glyphIndex, out glyphdata)) { glyphdata = null; return(false); } return(true); }
public static Dictionary <ushort, TextureGlyphMapData> CloneLocationWithOffset(SimpleFontAtlas org, int dx, int dy) { Dictionary <ushort, TextureGlyphMapData> cloneDic = new Dictionary <ushort, TextureGlyphMapData>(); foreach (var kp in org._glyphLocations) { TextureGlyphMapData orgMapData = kp.Value; cloneDic.Add(kp.Key, new TextureGlyphMapData() { Left = orgMapData.Left + dx, Top = orgMapData.Top + dy, // Width = orgMapData.Width, Height = orgMapData.Height, TextureXOffset = orgMapData.TextureXOffset, TextureYOffset = orgMapData.TextureYOffset }); } return(cloneDic); }
public void AddGlyph(ushort glyphIndex, TextureGlyphMapData glyphData) { _glyphLocations.Add(glyphIndex, glyphData); }