public void GetOffset(int characterToMeasureStartIndexInclusive, int characterToMeasureEndIndexInclusive, out Vector2 offset) { offset = Vector2.Zero; characterToMeasureEndIndexInclusive = Math.Min(text.Length - 1, characterToMeasureEndIndexInclusive); for (int index = characterToMeasureStartIndexInclusive; index <= characterToMeasureEndIndexInclusive; index++) { if (text[index] == '\n') { offset.x = 0; offset.y -= TypeFaceStyle.EmSizeInPixels; } else { if (index < text.Length - 1) { offset.x += TypeFaceStyle.GetAdvanceForCharacter(text[index], text[index + 1]); } else { offset.x += TypeFaceStyle.GetAdvanceForCharacter(text[index]); } } } }
private void RenderFromCache(Graphics2D graphics2D, Color color) { if (text != null && text.Length > 0) { Vector2 currentOffset = Vector2.Zero; currentOffset = GetBaseline(currentOffset); // remove the decent and 1 pixel that were put into the cache image to give space for descenders currentOffset.Y += (Origin.Y + TypeFaceStyle.DescentInPixels - 1); string[] lines = text.Split('\n'); foreach (string line in lines) { currentOffset = GetXPositionForLineBasedOnJustification(currentOffset, line); currentOffset.X += Origin.X; for (int currentChar = 0; currentChar < line.Length; currentChar++) { ImageBuffer currentGlyphImage = TypeFaceStyle.GetImageForCharacter(line[currentChar], 0, 0, color); if (currentGlyphImage != null) { graphics2D.Render(currentGlyphImage, currentOffset); } // get the advance for the next character currentOffset.X += TypeFaceStyle.GetAdvanceForCharacter(line, currentChar); } // before we go onto the next line we need to move down a line currentOffset.X = 0; currentOffset.Y -= TypeFaceStyle.EmSizeInPixels; } } }
private void RenderFromCache(Graphics2D graphics2D, RGBA_Bytes color) { if (text != null && text.Length > 0) { Vector2 currentOffset = Vector2.Zero; currentOffset = GetBaseline(currentOffset); currentOffset.y += Origin.y; string[] lines = text.Split('\n'); foreach (string line in lines) { currentOffset = GetXPositionForLineBasedOnJustification(currentOffset, line); currentOffset.x += Origin.x; for (int currentChar = 0; currentChar < line.Length; currentChar++) { ImageBuffer currentGlyphImage = TypeFaceStyle.GetImageForCharacter(line[currentChar], 0, 0, color); if (currentGlyphImage != null) { graphics2D.Render(currentGlyphImage, currentOffset); } // get the advance for the next character currentOffset.x += TypeFaceStyle.GetAdvanceForCharacter(line, currentChar); } // before we go onto the next line we need to move down a line currentOffset.x = 0; currentOffset.y -= TypeFaceStyle.EmSizeInPixels; } } }
public void GetSize(int characterToMeasureStartIndexInclusive, int characterToMeasureEndIndexInclusive, out Vector2 offset, string text = null) { if (text == null) { text = this.text; } offset.x = 0; offset.y = TypeFaceStyle.EmSizeInPixels; double currentLineX = 0; for (int i = characterToMeasureStartIndexInclusive; i < characterToMeasureEndIndexInclusive; i++) { if (text[i] == '\n') { if (i + 1 < characterToMeasureEndIndexInclusive && (text[i + 1] == '\n') && text[i] != text[i + 1]) { i++; } currentLineX = 0; offset.y += TypeFaceStyle.EmSizeInPixels; } else { if (i + 1 < text.Length) { currentLineX += TypeFaceStyle.GetAdvanceForCharacter(text[i], text[i + 1]); } else { currentLineX += TypeFaceStyle.GetAdvanceForCharacter(text[i]); } if (currentLineX > offset.x) { offset.x = currentLineX; } } } if (text.Length > characterToMeasureEndIndexInclusive) { if (text[characterToMeasureEndIndexInclusive] == '\n') { currentLineX = 0; offset.y += TypeFaceStyle.EmSizeInPixels; } else { offset.x += TypeFaceStyle.GetAdvanceForCharacter(text[characterToMeasureEndIndexInclusive]); } } }
public IEnumerable <VertexData> Vertices() { if (text != null && text.Length > 0) { Vector2 currentOffset = new Vector2(0, 0); currentOffset = GetBaseline(currentOffset); string[] lines = text.Split('\n'); foreach (string line in lines) { currentOffset = GetXPositionForLineBasedOnJustification(currentOffset, line); for (int currentChar = 0; currentChar < line.Length; currentChar++) { IVertexSource currentGlyph = TypeFaceStyle.GetGlyphForCharacter(line[currentChar]); if (currentGlyph != null) { foreach (VertexData vertexData in currentGlyph.Vertices()) { if (vertexData.command != ShapePath.FlagsAndCommand.CommandStop) { VertexData offsetVertex = new VertexData(vertexData.command, vertexData.position + currentOffset + Origin); yield return(offsetVertex); } } } // get the advance for the next character if (currentChar < line.Length - 1) { // pass the next char so the typeFaceStyle can do kerning if it needs to. currentOffset.x += TypeFaceStyle.GetAdvanceForCharacter(line[currentChar], line[currentChar + 1]); } else { currentOffset.x += TypeFaceStyle.GetAdvanceForCharacter(line[currentChar]); } } // before we go onto the next line we need to move down a line currentOffset.x = 0; currentOffset.y -= TypeFaceStyle.EmSizeInPixels; } } VertexData endVertex = new VertexData(ShapePath.FlagsAndCommand.CommandStop, Vector2.Zero); yield return(endVertex); }
public override IEnumerable <VertexData> Vertices() { if (text != null && text.Length > 0) { var currentOffset = new Vector2(0, 0); currentOffset = GetBaseline(currentOffset); string[] lines = text.Split('\n'); foreach (string line in lines) { currentOffset = GetXPositionForLineBasedOnJustification(currentOffset, line); for (int currentChar = 0; currentChar < line.Length; currentChar++) { IVertexSource currentGlyph = TypeFaceStyle.GetGlyphForCharacter(line[currentChar], ResolutionScale); if (currentGlyph != null) { foreach (VertexData vertexData in currentGlyph.Vertices()) { if (vertexData.command != ShapePath.FlagsAndCommand.Stop) { var offsetVertex = new VertexData(vertexData.command, vertexData.position + currentOffset + Origin); yield return(offsetVertex); } } } // get the advance for the next character currentOffset.X += TypeFaceStyle.GetAdvanceForCharacter(line, currentChar); } // before we go onto the next line we need to move down a line currentOffset.X = 0; currentOffset.Y -= TypeFaceStyle.EmSizeInPixels; } } var endVertex = new VertexData(ShapePath.FlagsAndCommand.Stop, Vector2.Zero); yield return(endVertex); }
public void GetOffset(int characterToMeasureStartIndexInclusive, int characterToMeasureEndIndexInclusive, out Vector2 offset) { offset = Vector2.Zero; characterToMeasureEndIndexInclusive = Math.Min(text.Length - 1, characterToMeasureEndIndexInclusive); var startIndex = characterToMeasureStartIndexInclusive; // find the first '\n' before the characterIndex for (int i = characterToMeasureStartIndexInclusive; i <= characterToMeasureEndIndexInclusive; i++) { if (text[i] == '\n') { startIndex = i + 1; offset.Y -= TypeFaceStyle.EmSizeInPixels; } } characterToMeasureStartIndexInclusive = startIndex; for (int index = characterToMeasureStartIndexInclusive; index <= characterToMeasureEndIndexInclusive; index++) { if (text[index] == '\n') { offset.X = 0; offset.Y -= TypeFaceStyle.EmSizeInPixels; } else { if (!fastAdvance.ContainsKey(text[index])) { fastAdvance[text[index]] = TypeFaceStyle.GetAdvanceForCharacter(text, index); } offset.X += fastAdvance[text[index]]; } } }