public override void Flush() { base.Flush(); if (character != null) { character.Flush(); character = null; } ObjPool <RotatedCharBox> .Release(this); }
public TexCharMetric[] GetExtentMetrics(TexStyle style) { var metric = new TexCharMetric[4]; var main = TEXPreference.main; metric[0] = main.GetCharMetric(extentTop, style); metric[1] = main.GetCharMetric(extentMiddle, style); metric[2] = main.GetCharMetric(extentBottom, style); metric[3] = main.GetCharMetric(extentRepeat, style); return(metric); }
public override Box CreateBox(TexStyle style) { // Create box for base atom. var baseBox = BaseAtom == null ? StrutBox.Empty : BaseAtom.CreateBox(TexUtility.GetCrampedStyle(style)); // Find character of best scale for accent symbol. TexCharMetric accentChar = TEXPreference.main.GetCharMetric(AccentAtom.Name, style); while (accentChar.ch.nextLargerExist) { var nextLargerChar = TEXPreference.main.GetCharMetric(accentChar.ch.nextLarger, style); if (nextLargerChar.width > baseBox.width) { break; } accentChar = nextLargerChar; } var resultBox = VerticalBox.Get(); // Create and add box for accent symbol. var accentBox = CharBox.Get(style, accentChar); var accentWidth = (accentBox.bearing + accentBox.italic) * .5f; accentBox.italic = accentWidth + (accentBox.width * .5f); accentBox.bearing = accentWidth - (accentBox.width * .5f); //accentBox. = accentBox.width + accentBox.italic - accentBox.bearing; resultBox.Add((accentBox)); //var delta = Mathf.Min(-accentChar.depth, baseBox.height); resultBox.Add(StrutBox.Get(0, TEXConfiguration.main.AccentMargin * TexUtility.SizeFactor(style), 0, 0)); // Centre and add box for base atom. Centre base box and accent box with respect to each other. var boxWidthsDiff = (baseBox.width - accentBox.width) / 2f; accentBox.shift = Mathf.Max(boxWidthsDiff, 0); if (boxWidthsDiff < 0) { baseBox = HorizontalBox.Get(baseBox, accentBox.width, TexAlignment.Center); } resultBox.Add(baseBox); // Adjust height and depth of result box. var depth = baseBox.depth; var totalHeight = resultBox.height + resultBox.depth; resultBox.depth = depth; resultBox.height = totalHeight - depth; return(resultBox); }
public static UnicodeBox Get(TexCharMetric metric, int fontIdx, CharacterInfo c) { var box = ObjPool <UnicodeBox> .Get(); // float ratio = TEXPreference.main.fontData[fontIdx].Font_Asset.fontSize / Scale; box.character = c; box.fontIndex = fontIdx; box.depth = metric.depth; box.height = metric.height; box.bearing = metric.bearing; box.italic = metric.italic; box.width = metric.width; box.scaleApplied = metric.appliedScale; // We are not keeping this ... metric.Flush(); return(box); }
public TexCharMetric CreateCharacterDataOnTheFly(char c, float scale, out CharacterInfo info) { if (type == TexFontType.Font) { CharacterInfo f; Font_Asset.RequestCharactersInTexture(new string(c, 1), TexUtility.RenderTextureSize, TexUtility.RenderFontStyle); Font_Asset.GetCharacterInfo(c, out f, TexUtility.RenderTextureSize, TexUtility.RenderFontStyle); info = f; var factor = 1f / (info.size == 0 ? Font_Asset.fontSize : info.size); return(TexCharMetric.Get(null, info.maxY * factor, -info.minY * factor, -info.minX * factor, info.maxX * factor, info.advance * factor, scale)); } else { // Nothing we can do for sprites ... info = new CharacterInfo(); return(TexCharMetric.Get(null, 0, 0, 0, 0, 0, 0)); } }
public static RotatedCharBox Get(TexStyle style, TexCharMetric Char, FontStyle fontStyle) { var box = ObjPool <RotatedCharBox> .Get(); if (Char == null) { throw new NullReferenceException(); } box.character = Char; //I can't say more but our cached glyph is slightly incorrect because //the usage of int in character Info, so we need to... var font = Char.ch.font; if (font.type == TexFontType.Font && Char.ch.supported) { CharacterInfo c; if (DrawingContext.GetCharInfo(font.Font_Asset, Char.ch.characterIndex, (int)(TexUtility.RenderTextureSize * Char.appliedScale) + 1, TexUtility.TexStyle2FontStyle(fontStyle), out c)) { float ratio = (c.size == 0 ? (float)TexUtility.RenderTextureSize : c.size) / Char.appliedScale; //Swap XY box.bearing = 0; box.italic = (c.maxY - c.minY) / ratio; box.depth = c.maxX / ratio; box.height = (-c.minX) / ratio; //No kerning applied? box.width = box.italic; box.c = c; return(box); } } box.bearing = 0; box.italic = Char.height + Char.depth; box.depth = 0; box.height = Char.italic + Char.bearing; box.width = box.italic; return(box); }
public static CharBox Get(TexStyle style, TexCharMetric Char, FontStyle fontStyle) { if (Char == null) { throw new NullReferenceException(); } var box = ObjPool <CharBox> .Get(); var ch = Char.ch; var font = ch.font; box.character = Char; //I can't say more but our cached glyph is slightly incorrect because //the usage of int in character Info, so we need to... if (box.isFont = (font.type == TexFontType.Font) && ch.supported) { CharacterInfo c; if (DrawingContext.GetCharInfo(font.Font_Asset, ch.characterIndex, (int)(TexUtility.RenderTextureSize * Char.appliedScale) + 1, fontStyle, out c)) { float ratio = Char.appliedScale / (float)(c.size); box.depth = -c.minY * ratio; box.height = c.maxY * ratio; box.bearing = -c.minX * ratio; box.italic = c.maxX * ratio; box.width = c.advance * ratio; box.c = c; return(box); } } box.depth = Char.depth; box.height = Char.height; box.bearing = Char.bearing; box.italic = Char.italic; box.width = Char.width; return(box); }
public TexCharMetric GetMetric(float scale) { return(TexCharMetric.Get(this, height, depth, bearing, italic, width, scale)); }
public static RotatedCharBox Get(TexStyle style, TexCharMetric Char) { return(Get(style, Char, TexUtility.RenderFontStyle)); }
public static CharBox Get(TexStyle style, TexCharMetric Char) { return(Get(style, Char, TexUtility.RenderFontStyle == TexUtility.FontStyleDefault ? FontStyle.Normal : TexUtility.RenderFontStyle)); }