public override RSize MeasureString(string str, RFont font) { if (_useGdiPlusTextRendering) { ReleaseHdc(); var fontAdapter = (FontAdapter)font; var realFont = fontAdapter.Font; _characterRanges[0] = new CharacterRange(0, str.Length); _stringFormat.SetMeasurableCharacterRanges(_characterRanges); var size = _g.MeasureCharacterRanges(str, realFont, RectangleF.Empty, _stringFormat)[0].GetBounds(_g).Size; if (font.Height < 0) { var height = realFont.Height; var descent = realFont.Size * realFont.FontFamily.GetCellDescent(realFont.Style) / realFont.FontFamily.GetEmHeight(realFont.Style); #if !MONO fontAdapter.SetMetrics(height, (int)Math.Round((height - descent + .5f))); #else fontAdapter.SetMetrics(height, (int)Math.Round((height - descent + 1f))); #endif } return(Utils.Convert(size)); } else { #if !MONO SetFont(font); var size = new Size(); Win32Utils.GetTextExtentPoint32(_hdc, str, str.Length, ref size); if (font.Height < 0) { TextMetric lptm; Win32Utils.GetTextMetrics(_hdc, out lptm); ((FontAdapter)font).SetMetrics(size.Height, lptm.tmHeight - lptm.tmDescent + lptm.tmUnderlined + 1); } return(Utils.Convert(size)); #else throw new InvalidProgramException("Invalid Mono code"); #endif } }