static WinGdiFont SetFont(RequestFont font) { WinGdiFont winFont = WinGdiFontSystem.GetWinGdiFont(font); MyWin32.SelectObject(win32MemDc.DC, winFont.CachedHFont()); return(winFont); }
internal static void MeasureCharWidths(IntPtr hFont, out int[] charWidths, out NativeTextWin32.FontABC[] abcSizes) { //only in ascii range //current version charWidths = new int[MAX_CODEPOINT_NO + 1]; // MyWin32.SelectObject(win32MemDc.DC, hFont); unsafe { //see: https://msdn.microsoft.com/en-us/library/ms404377(v=vs.110).aspx //A code page contains 256 code points and is zero-based. //In most code pages, code points 0 through 127 represent the ASCII character set, //and code points 128 through 255 differ significantly between code pages abcSizes = new NativeTextWin32.FontABC[MAX_CODEPOINT_NO + 1]; fixed(NativeTextWin32.FontABC *abc = abcSizes) { NativeTextWin32.GetCharABCWidths(win32MemDc.DC, (uint)0, (uint)MAX_CODEPOINT_NO, abc); } for (int i = 0; i < (MAX_CODEPOINT_NO + 1); ++i) { charWidths[i] = abcSizes[i].Sum; } } }
public void Reset(int hPageNum, int vPageNum, int newWidth, int newHeight) { this.pageNumFlags = (hPageNum << 8) | vPageNum; this.ReleaseUnManagedResource(); this.ClearPreviousStoredValues(); var orgHdc = MyWin32.CreateCompatibleDC(IntPtr.Zero); System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(newWidth, newHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); hbmp = bmp.GetHbitmap(); MyWin32.SelectObject(orgHdc, hbmp); MyWin32.PatBlt(orgHdc, 0, 0, newWidth, newHeight, MyWin32.WHITENESS); MyWin32.SetBkMode(orgHdc, MyWin32._SetBkMode_TRANSPARENT); hFont = defaultHFont; MyWin32.SelectObject(orgHdc, hFont); currentClipRect = new System.Drawing.Rectangle(0, 0, newWidth, newHeight); MyWin32.SelectObject(orgHdc, hRgn); gx = System.Drawing.Graphics.FromHdc(orgHdc); this.originalHdc = orgHdc; gx.Clear(System.Drawing.Color.White); MyWin32.SetRectRgn(hRgn, 0, 0, newWidth, newHeight); left = hPageNum * newWidth; top = vPageNum * newHeight; right = left + newWidth; bottom = top + newHeight; #if DEBUG debug_resetCount++; #endif }
public void MeasureCharWidths(IntPtr hFont, out int[] charWidths, out NativeTextWin32.FontABC[] abcSizes) { if (!isInit) { Init(); } //only in ascii range //current version charWidths = new int[256]; MyWin32.SelectObject(hdc, hFont); unsafe { abcSizes = new NativeTextWin32.FontABC[256]; fixed(NativeTextWin32.FontABC *abc = abcSizes) { NativeTextWin32.GetCharABCWidths(hdc, (uint)0, (uint)255, abc); } for (int i = 0; i < 161; i++) { charWidths[i] = abcSizes[i].Sum; } for (int i = 161; i < 255; i++) { charWidths[i] = abcSizes[i].Sum; } } }
void PrepareCharacterMapWhiteOnBlack(char[] buffer) { //----------------------------------------------------------------------- IntPtr gxdc = gx.GetHdc(); int len = buffer.Length; //draw each character int curX = 0; int curY = 0; //1. clear with white color, MyWin32.PatBlt(gxdc, 0, 0, width, height, MyWin32.BLACKNESS); //2. transparent background MyWin32.SetBkMode(gxdc, MyWin32._SetBkMode_TRANSPARENT); //3. white brush //set user font to dc MyWin32.SelectObject(gxdc, this.hFont); int rgb = ((255 & 0xFF) << 16 | (255 & 0xFF) << 8 | 255); MyWin32.SetTextColor(gxdc, rgb); //TODO:correct white text on black bg for subpixel rendering //when draw with subpixel rendering //on white bg -> red come first from left ,end with blue //on black bg -> blue come first from left, end with red int fontHeight = fontInfo.FontHeight; int maxLineHeight = fontHeight; for (int i = 0; i < len; ++i) { //----------------------------------------------------------------------- //measure string //and make simple character map //----------------------------------------------------------------------- //measure each character *** //not adjust kerning*** char c = buffer[i]; FontABC abcWidth = fontInfo.GetCharABCWidth(c); int glyphBoxWidth = Math.Abs(abcWidth.a) + (int)abcWidth.b + abcWidth.c; if (abcWidth.Sum + curX > this.width) { //start newline curX = 0; curY += maxLineHeight; maxLineHeight = fontHeight; } NativeTextWin32.TextOut(gxdc, curX, curY, new char[] { c }, 1); charMap.Add(c, new PixelFarm.Drawing.RectangleF(curX, curY, glyphBoxWidth, fontHeight)); curX += glyphBoxWidth; //move next } gx.ReleaseHdc(gxdc); //myTextBoardBmp = new Bitmap(width, height, new LazyGdiBitmapBufferProvider(this.textBoardBmp)); //myTextBoardBmp.InnerImage = GLBitmapTextureHelper.CreateBitmapTexture(this.textBoardBmp); }
public int MeasureStringWidth(IntPtr hFont, char[] buffer, int length) { if (!isInit) { Init(); } MyWin32.SelectObject(this.hdc, hFont); NativeTextWin32.WIN32SIZE size; NativeTextWin32.GetTextExtentPoint32(hdc, buffer, length, out size); return(size.Width); }
void PrepareCharacterMapBlackOnWhite(char[] buffer) { //----------------------------------------------------------------------- IntPtr gxdc = gx.GetHdc(); int len = buffer.Length; //draw each character int curX = 0; int curY = 0; //1. clear with white color, MyWin32.PatBlt(gxdc, 0, 0, width, height, MyWin32.WHITENESS); //2. transparent background MyWin32.SetBkMode(gxdc, MyWin32._SetBkMode_TRANSPARENT); //set user font to dc MyWin32.SelectObject(gxdc, this.hFont); int fontHeight = fontInfo.FontHeight; int maxLineHeight = fontHeight; for (int i = 0; i < len; ++i) { //----------------------------------------------------------------------- //measure string //and make simple character map //----------------------------------------------------------------------- //measure each character *** //not adjust kerning*** char c = buffer[i]; FontABC abcWidth = fontInfo.GetCharABCWidth(c); int glyphBoxWidth = Math.Abs(abcWidth.a) + (int)abcWidth.b + abcWidth.c; if (abcWidth.Sum + curX > this.width) { //start newline curX = 0; curY += maxLineHeight; maxLineHeight = fontHeight; } NativeTextWin32.TextOut(gxdc, curX, curY, new char[] { c }, 1); charMap.Add(c, new PixelFarm.Drawing.RectangleF(curX, curY, glyphBoxWidth, fontHeight)); curX += glyphBoxWidth; //move next } gx.ReleaseHdc(gxdc); //myTextBoardBmp = new Bitmap(width, height, new LazyGdiBitmapBufferProvider(this.textBoardBmp)); //myTextBoardBmp.InnerImage = GLBitmapTextureHelper.CreateBitmapTexture(this.textBoardBmp); }
void CreateGraphicsFromNativeHdc(int width, int height) { //3. create original dc from memory dc and prepare background var orgHdc = MyWin32.CreateCompatibleDC(IntPtr.Zero); bgBmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); hbmp = bgBmp.GetHbitmap(); MyWin32.SelectObject(orgHdc, hbmp); MyWin32.PatBlt(orgHdc, 0, 0, width, height, MyWin32.WHITENESS); MyWin32.SetBkMode(orgHdc, MyWin32._SetBkMode_TRANSPARENT); //4. font hFont = MyWin32.SelectObject(orgHdc, hFont); //5. region hRgn = MyWin32.CreateRectRgn(0, 0, width, height); MyWin32.SelectObject(orgHdc, hRgn); //6. create graphics from hdc*** gx = System.Drawing.Graphics.FromHdc(orgHdc); this.originalHdc = orgHdc; }