void BuildGrid() { int glyphCount = mImporterString.Length; mFont.glyphs = new GiraffeFontGlyph[glyphCount]; GiraffeSprite sprite = mFont.atlas.GetSprite(mFont.spriteName); int charsPerLine = sprite.width / mImporterCharWidth; for (int i = 0; i < glyphCount; i++) { int cx = i % charsPerLine; int cy = i / charsPerLine; GiraffeFontGlyph glyph = new GiraffeFontGlyph() { character = mImporterString[i], width = mImporterCharWidth, height = mImporterCharHeight, x = cx * mImporterCharWidth, y = sprite.height - ((cy + 1) * mImporterCharHeight), xAdvance = mImporterCharWidth, xOffset = 0, yOffset = 0 }; mFont.glyphs[i] = glyph; } mFont.lineHeight = mImporterCharHeight; mFont.spaceAdvance = mImporterCharWidth; EditorUtility.SetDirty(mFont); mImporterType = ImporterType.None; }
public void AddTo(GiraffeLayer layer, int x, int y, String text) { int length = text.Length; int p = x; for (int i = 0; i < length; i++) { char c = text[i]; if (c >= characterRangeMin && c <= characterRangeMax && characters.ContainsKey(c)) { GiraffeFontGlyph glyph = characters[c]; layer.Add(p + glyph.xOffset, y + glyph.yOffset, glyph.sprite); p += glyph.xAdvance; } else if (c == ' ') { p += spaceAdvance; } } }
public int Size(String text) { int length = text.Length; int p = 0; for (int i = 0; i < length; i++) { char c = text[i]; if (c >= characterRangeMin && c <= characterRangeMax && characters.ContainsKey(c)) { GiraffeFontGlyph glyph = characters[c]; p += glyph.xAdvance; } else if (c == ' ') { p += spaceAdvance; } } return(p); }
void Initialise() { sprite = atlas.GetSprite(spriteName); float invTexWidth = 1.0f / atlas.texture.width; float invTexHeight = 1.0f / atlas.texture.height; characters = new Dictionary <char, GiraffeFontGlyph>(glyphs.Length); characterRangeMin = char.MaxValue; characterRangeMax = char.MinValue; for (int i = 0; i < glyphs.Length; i++) { GiraffeFontGlyph glyph = glyphs[i]; char c = (char)glyph.character; characters.Add(c, glyph); if (c < characterRangeMin) { characterRangeMin = c; } if (c > characterRangeMax) { characterRangeMax = c; } GiraffeSprite glyphSprite = new GiraffeSprite(); glyph.sprite = glyphSprite; glyphSprite.left = glyph.x + sprite.left; glyphSprite.top = glyph.y + sprite.top; glyphSprite.width = glyph.width; glyphSprite.height = glyph.height; glyphSprite.Refresh(invTexWidth, invTexHeight); } }