void Process() { //need a clean buffer //when drawing if (buffer != null) { buffer.Release(); buffer = null; } if (processor == null || lines == null) { return; } CreateBufferIfNeeded(); processor.Prepare(width, height, character, buffer); float px = 1.0f / width; float py = 1.0f / height; MVector pivot = new MVector(-1, 0); if (map != null && map.Count > 0 && transforms.Count > 0) { int tindex = 0; for (int i = 0; i < lines.Length; i++) { string line = lines[i]; float left = 0; float alignmentAdjustment = adjustments[i]; for (int j = 0; j < line.Length; j++) { if (tindex >= transforms.Count) { continue; } string ch = line.Substring(j, 1); FontManager.CharData data = null; if (map.TryGetValue(ch, out data)) { if (data.texture == null) { tindex++; continue; } CharacterTransform ct = transforms[tindex]; MVector finalPos = new MVector((ct.position.X + left * ct.scale.X) * width - alignmentAdjustment, (ct.position.Y + (i * data.bearing) * py * ct.scale.Y) * height); left += (data.size.X + pspacing) * px; character.Bind(); character.SetData(data.texture.Image, GLInterfaces.PixelFormat.Bgra, (int)Math.Ceiling(data.size.X), (int)Math.Ceiling(data.size.Y)); GLTextuer2D.Unbind(); processor.Translation = finalPos; processor.Angle = ct.angle; processor.Pivot = pivot; processor.Scale = ct.scale * (new MVector(data.size.X, data.size.Y) * 0.5f); processor.ProcessCharacter(width, height, character, buffer); } tindex++; } } } processor.Complete(); Updated(); Output.Data = buffer; Output.Changed(); }
private void GetTransforms() { transforms.Clear(); if (map == null || map.Count == 0) { return; } adjustments.Clear(); for (int i = 0; i < lines.Length; i++) { string line = lines[i]; float alignmentAdjustment = 0; for (int j = 0; j < line.Length; j++) { string ch = line.Substring(j, 1); FontManager.CharData data = null; MVector pPos = position; float pcharRotation = rotation; MVector pScale = scale; if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "Rotation")) { if (ParentGraph.IsParameterValueFunction(Id, "Rotation")) { FunctionGraph func = ParentGraph.GetParameterRaw(Id, "Rotation").Value as FunctionGraph; func.SetVar("character", j, NodeType.Float); func.SetVar("maxCharacters", line.Length, NodeType.Float); func.SetVar("line", i, NodeType.Float); func.SetVar("maxLines", lines.Length, NodeType.Float); } pcharRotation = Convert.ToSingle(ParentGraph.GetParameterValue(Id, "Rotation")); } if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "Scale")) { if (ParentGraph.IsParameterValueFunction(Id, "Scale")) { FunctionGraph func = ParentGraph.GetParameterRaw(Id, "Scale").Value as FunctionGraph; func.SetVar("character", j, NodeType.Float); func.SetVar("maxCharacters", line.Length, NodeType.Float); func.SetVar("line", i, NodeType.Float); func.SetVar("maxLines", lines.Length, NodeType.Float); } pScale = ParentGraph.GetParameterValue <MVector>(Id, "Position"); } if (ParentGraph != null && ParentGraph.HasParameterValue(Id, "Position")) { if (ParentGraph.IsParameterValueFunction(Id, "Position")) { FunctionGraph func = ParentGraph.GetParameterRaw(Id, "Position").Value as FunctionGraph; func.SetVar("character", j, NodeType.Float); func.SetVar("maxCharacters", line.Length, NodeType.Float); func.SetVar("line", i, NodeType.Float); func.SetVar("maxLines", lines.Length, NodeType.Float); } pPos = ParentGraph.GetParameterValue <MVector>(Id, "Position"); } CharacterTransform ct = new CharacterTransform(pcharRotation * (float)(Math.PI / 180.0f), pPos, pScale); transforms.Add(ct); //for these two alignments we need to calculate the //actual full line width first before we do final //positing and rendering //to apply the proper adjustment //for right alignment all we need is the total //for center we need the halfway point if (palignment == TextAlignment.Center || palignment == TextAlignment.Right) { if (map.TryGetValue(ch, out data)) { alignmentAdjustment += data.size.X + pspacing; } } } if (palignment == TextAlignment.Center) { alignmentAdjustment *= 0.5f; } adjustments.Add(alignmentAdjustment); } }