//====================================== public Size MeasureString(char[] buff, int startAt, int len, Font font) { //if (_useGdiPlusTextRendering) //{ // ReleaseHdc(); // _characterRanges[0] = new System.Drawing.CharacterRange(0, len); // _stringFormat.SetMeasurableCharacterRanges(_characterRanges); // System.Drawing.Font font2 = (System.Drawing.Font)font.InnerFont; // var size = gx.MeasureCharacterRanges( // new string(buff, startAt, len), // font2, // System.Drawing.RectangleF.Empty, // _stringFormat)[0].GetBounds(gx).Size; // return new PixelFarm.Drawing.Size((int)Math.Round(size.Width), (int)Math.Round(size.Height)); //} //else //{ SetFont(font); PixelFarm.Drawing.Size size = new Size(); unsafe { fixed(char *startAddr = &buff[0]) { NativeTextWin32.UnsafeGetTextExtentPoint32(tempDc, startAddr + startAt, len, ref size); } } return(size); //} }
public static PixelFarm.Drawing.Size MeasureString(char[] buff, int startAt, int len, RequestFont font) { SetFont(font); Win32.Size win32_size = new Size(); if (buff.Length > 0) { unsafe { fixed(char *startAddr = &buff[0]) { NativeTextWin32.UnsafeGetTextExtentPoint32(win32MemDc.DC, startAddr + startAt, len, ref win32_size); } } } return(new PixelFarm.Drawing.Size(win32_size.W, win32_size.H)); }