public override unsafe int GetHashCode() { fixed(VertexPositionNormalDiffuseTexture *self = &this) { return(FNV1A.Hash((IntPtr)self, sizeof(float) * 8)); } }
public override Point MeasureString(string fontName, float size, string text) { if (string.IsNullOrEmpty(text)) { return(Point.Zero); } if (string.IsNullOrEmpty(fontName)) { throw new InvalidOperationException("fontName null"); } int fontHash = FNV1A.Hash(fontName); for (int i = 0; i < measures.Count; i++) { if (measures[i].IsEqual(text, fontHash, size)) { return(measures[i].Measured); } } using var textConv = new UTF8ZHelper(stackalloc byte[256], text); using var fontConv = new UTF8ZHelper(stackalloc byte[256], fontName); fixed(byte *tC = &textConv.ToUTF8Z().GetPinnableReference(), tF = &fontConv.ToUTF8Z().GetPinnableReference()) { pg_measurestring(ctx, (IntPtr)tC, (IntPtr)tF, size * (96.0f / 72.0f), out var width, out var height); var p = new Point((int)width, (int)height); measures.Enqueue(new MeasureResults() { Text = text, Font = fontHash, Size = size, Measured = p }); return(p); } }
public override float LineHeight(string fontName, float size) { if (string.IsNullOrEmpty(fontName)) { throw new InvalidOperationException("LineHeight fontName cannot be null"); } int fontHash = FNV1A.Hash(fontName); for (int i = 0; i < lineHeights.Count; i++) { if (lineHeights[i].Hash == fontHash && Math.Abs(lineHeights[i].Size - size) < 0.001f) { return(lineHeights[i].LineHeight); } } using var fontConv = new UTF8ZHelper(stackalloc byte[256], fontName); fixed(byte *tF = &fontConv.ToUTF8Z().GetPinnableReference()) { var retval = pg_lineheight(ctx, (IntPtr)tF, size * (96.0f / 72.0f)); lineHeights.Enqueue(new HeightResult() { Hash = fontHash, Size = size, LineHeight = retval }); return(retval); } }
public unsafe int MakeHash(string fontName, string text) { fixed(StringInfo *si = &this) { return(FNV1A.Hash((IntPtr)si, sizeof(StringInfo), FNV1A.Hash(text, FNV1A.Hash(fontName)))); } }