private void CreateText(double x, double y, double maxWidth) { _bitmapText.Clear(); double currentX = 0; double currentY = 0; string[] words = _text.Split(' '); foreach (string word in words) { Vector nextWordLength = _font.MeasureFont(word); if (maxWidth != -1 && (currentX + nextWordLength.X) > maxWidth) { currentX = 0; currentY += nextWordLength.Y; } string wordWithSpace = word + " "; // add the space character that was removed. foreach (char c in wordWithSpace) { CharacterSprite sprite = _font.CreateSprite(c); float xOffset = ((float)sprite.Data.XOffset) / 2; float yOffset = (((float)sprite.Data.Height) * 0.5f) + ((float)sprite.Data.YOffset); sprite.Sprite.SetPosition(x + currentX + xOffset, y - currentY - yOffset); currentX += sprite.Data.XAdvance; _bitmapText.Add(sprite); } } _dimensions = _font.MeasureFont(_text, _maxWidth); _dimensions.Y = currentY; SetColor(_color); }
private void CreateText(double x, double y, double maxWidth) { _bitmapText.Clear(); double currentX = 0; double currentY = 0; string[] words = _text.Split(' '); foreach (string word in words) { Vector nextWordLength = _font.MeasureFont(word); if (maxWidth != -1 && (currentX + nextWordLength.X) > maxWidth) { currentX = 0; currentY += nextWordLength.Y; } string wordWithSpace = word + " "; // add the space character that was removed. char lastChar = ' '; foreach (char c in wordWithSpace) { int kernAmount = _font.GetKerning(lastChar, c); CharacterSprite sprite = _font.CreateSprite(c); var w = sprite.Sprite.GetWidth(); float yOffset = (((float)sprite.Data.Height) * 0.5f) + ((float)sprite.Data.YOffset); float xOffset = ((float)sprite.Data.XOffset) + kernAmount; sprite.Sprite.SetPosition(x + currentX + (sprite.Sprite.GetWidth() / 2) + xOffset, y - currentY - yOffset); currentX += sprite.Data.XAdvance; System.Diagnostics.Debug.Assert((int)sprite.Sprite.GetWidth() == sprite.Data.Width); _bitmapText.Add(sprite); lastChar = c; } } _dimensions = _font.MeasureFont(_text, _maxWidth); _dimensions.Y = currentY; SetColor(_color); }