/// <summary> /// Performs a deep copy. /// </summary> /// <returns></returns> public GlyphMetrics Clone() { GlyphMetrics retval = new GlyphMetrics(); retval.SourceRect = SourceRect; retval.LeftOverhang = LeftOverhang; retval.RightOverhang = RightOverhang; foreach (KeyValuePair <char, int> kvp in KerningPairs) { retval.KerningPairs.Add(kvp.Key, kvp.Value); } return(retval); }
private void GetRects(string text, RectangleF[] srcRects, RectangleF[] destRects, out int rectCount) { double destX = 0; double destY = 0; int height = mCharHeight; rectCount = 0; for (int i = 0; i < text.Length; i++) { switch (text[i]) { case '\r': // ignore '\r' characters that are followed by '\n', because // the line break on Windows is these two characters in succession. if (i + 1 < text.Length && text[i + 1] == '\n') { break; } // this '\r' is not followed by a '\n', so treat it like any other character. goto default; case '\n': destX = 0; destY += height * this.ScaleHeight; break; default: GlyphMetrics glyph = mFontMetrics[text[i]]; destX = Math.Max(0, destX - glyph.LeftOverhang * ScaleWidth); srcRects[rectCount] = new RectangleF( glyph.SourceRect.X, glyph.SourceRect.Y, glyph.SourceRect.Width, glyph.SourceRect.Height); destRects[rectCount] = new RectangleF((float)destX, (float)destY, (float)(srcRects[rectCount].Width * ScaleWidth), (float)(srcRects[rectCount].Height * ScaleHeight)); destX += destRects[rectCount].Width - glyph.RightOverhang * ScaleWidth; rectCount++; break; } } }
private void ExtractMonoSpaceAsciiFont(Size characterSize) { int x = 0; int y = 0; char val = '\0'; while (y + characterSize.Height <= mSurface.SurfaceHeight) { Rectangle src = new Rectangle(x, y, characterSize.Width, characterSize.Height); mFontMetrics[val] = new GlyphMetrics(src); val++; x += characterSize.Width; if (x + characterSize.Width > mSurface.SurfaceWidth) { y += characterSize.Height; x = 0; } } CalcAverageCharWidth(); }