private void RenderUV3Line(FillHelper verts, Rect uv, int idx) { // After render... uhh it's done... except if there's autoFill per line in there... which need to be done right now ... switch (autoFill) { case Filling.PerLine: for (int j = idx; j < verts.vertexcount; j++) { verts.SetUV2(InverseLerp(uv, verts.m_Positions[j]), j); } break; /*case 5: * //Toughest filling method: Per word - Not yet available * var boxes = box.Box.Children; * r = new Rect(offset, box.RenderSize); * for (int j = lastVerts; j < verts.currentVertCount; j++) { * verts.m_Uv2S[j] = InverseLerp(r, verts.m_Positions[j]); * } * break;*/ } }
private void RenderUV3(FillHelper verts) { var count = verts.vertexcount; switch (autoFill) { case Filling.Rectangle: Rect r; if (hasRect) { r = rectArea; } else { r = new Rect(-VecScale(size, alignment), size); } for (int i = 0; i < count; i++) { verts.SetUV2(InverseLerp(r, verts.m_Positions[i]), i); } break; case Filling.WholeText: if (hasRect) { r = new Rect(-( VecScale(size, (alignment)) + VecScale(rectArea.size, VecNormal(alignment)) + -(rectArea.center)), size); } else { r = new Rect(-VecScale(size, alignment), size); } for (int i = 0; i < count; i++) { verts.SetUV2(InverseLerp(r, verts.m_Positions[i]), i); } break; case Filling.WholeTextSquared: if (hasRect) { r = new Rect(-( VecScale(size, (alignment)) + VecScale(rectArea.size, VecNormal(alignment)) + -(rectArea.center)), size); } else { r = new Rect(-VecScale(size, alignment), size); } var max = Mathf.Max(r.width, r.height); var center = r.center; r.size = Vector2.one * max; r.center = center; for (int i = 0; i < count; i++) { verts.SetUV2(InverseLerp(r, verts.m_Positions[i]), i); } break; case Filling.PerCharacter: for (int i = 0; i < count; i++) { int l = i % 4; verts.SetUV2(new Vector2(l == 0 | l == 3 ? 0 : 1, l < 2 ? 0 : 1), i); } break; case Filling.PerCharacterSquared: for (int i = 0; i < count; i += 4) { Vector2 sz = verts.m_Positions[i + 2] - verts.m_Positions[i]; if (sz.x <= 0 || sz.y <= 0) { for (int l = 0; l < 4; l++) { verts.SetUV2(new Vector2(l == 0 | l == 3 ? 0 : 1, l < 2 ? 0 : 1), i); } continue; } float xMin, xMax, yMin, yMax; if (sz.x > sz.y) { var h = sz.y / sz.x; xMin = 0; xMax = 1; yMin = (1 - h) / 2; yMax = 1 - yMin; } else { var v = sz.x / sz.y; yMin = 0; yMax = 1; xMin = (1 - v) / 2; xMax = 1 - xMin; } for (int l = 0; l < 4; l++) { verts.SetUV2(new Vector2(l == 0 | l == 3 ? xMin : xMax, l < 2 ? yMin : yMax), i + l); } } break; case Filling.LocalContinous: var ratio = 1 / (factor * scale); for (int i = 0; i < count; i++) { verts.SetUV2(verts.m_Positions[i] * ratio, i); } break; case Filling.WorldContinous: ratio = 1 / (factor * scale); var transform = context.monoContainer.transform; for (int i = 0; i < count; i++) { verts.SetUV2(transform.TransformPoint(verts.m_Positions[i]) * ratio, i); } break; } }
public void Render() { if (hasRect && autoFit > 0 && (rectArea.size.x <= 0 || rectArea.size.y <= 0)) { return; } // At first, calculate starting offset CalculateRenderedArea(size, alignment, rectArea); var lastIsCustomAlign = false; //Layout bug fix. float shift; float lastOffsetX = offset.x; float postYOffset = 0f, postYParagraph = 0f; // // We'll start from top (line-per-line). This means offset will subtracted decrementally.. offset.y += size.y; TexRenderer box; var scaleFactor = scale * factor; FillHelper verts = context.vertex; for (int i = 0; i < formulas.Count; i++) { int lastVerts = verts.currentVertCount; box = formulas[i]; // Recalculate offsets var alignX = alignment.x; var sizeX = size.x; offset.y -= (box.Box.totalHeight + (i > 0 && formulas[i - 1].Box.totalHeight > 0 ? spaceSize + postYOffset : 0) + (box.partOfPreviousLine == 0 ? postYParagraph : 0)) * scaleFactor; box.Scale *= factor; shift = (box.Box.height - box.Box.depth) * box.Scale; // Recalculate again if something defined in box's meta if (box.usingMetaRules) { float lastY = offset.y; var meta = box.metaRules; alignX = meta.GetAlignment(alignment.x); sizeX = (box.Box.width) * scaleFactor; var rectModify = rectArea; rectModify.width -= (meta.right + meta.left + box.partOfPreviousLine > 0 ? 0 : meta.leading) * scaleFactor; // We only need to adjust horizontal offset CalculateRenderedArea(new Vector2(sizeX, 0), new Vector2(alignX, alignment.y), rectModify); offset.x += ((1 - alignX) * meta.left - (alignX) * meta.right + (box.partOfPreviousLine > 0 ? 0 : (-(alignX * 2 - 1)) * meta.leading) ) * scaleFactor; sizeX -= rectArea.xMax - rectModify.xMax; offset.y = lastY; // Don't want thing messed. postYOffset = (meta.spacing); // Additional spacing postYParagraph = box.Box.totalHeight > 0 ? meta.paragraph : 0; lastIsCustomAlign = true; } else if (lastIsCustomAlign) { // This is just for restoring things from beginning (if necessary) postYOffset = 0; postYParagraph = 0; offset.x = lastOffsetX; lastIsCustomAlign = false; } // Get ready to render float x = offset.x + /*box.Box.shift * box.Scale +*/ alignX * (sizeX - box.Scale * box.Box.width); float y = offset.y - shift; box.Render(context, x, y); // After render... uhh it's done... except if there's autoFill per line in there... which need to be done right now ... switch (autoFill) { case Filling.PerLine: Rect r = new Rect(new Vector2(x, offset.y), box.RenderSize); for (int j = lastVerts; j < verts.currentVertCount; j++) { verts.SetUV2(inverseLerp(r, verts.m_Positions[j]), j); } break; /*case 5: * //Toughest filling method: Per word - Not yet available * var boxes = box.Box.Children; * r = new Rect(offset, box.RenderSize); * for (int j = lastVerts; j < verts.currentVertCount; j++) { * verts.m_Uv2S[j] = inverseLerp(r, verts.m_Positions[j]); * } * break;*/ } } if (autoFill > 0) { RenderUV3(verts); } }