private void SelectObject(object obj) { if (obj == null) { throw(new ArgumentNullException("obj")); } if (obj is GdiPen) { GdiPen pen = (GdiPen)obj; _currentPen = pen; Win32.SelectObject(_hdc, pen.NativePen); } else if (obj is GdiBrush) { GdiBrush brush = (GdiBrush)obj; _currentBrush = brush; Win32.SelectObject(_hdc, brush.NativeBrush); } else if (obj is GdiFont) { GdiFont font = (GdiFont)obj; _currentFont = font; Win32.SelectObject(_hdc, font.NativeFont); } else { throw(new Exception("Unknow gdi object")); } }
public void PaintNavigationMap(MindMap map, float zoom, PaintEventArgs e) { if (map == null) { throw new ArgumentNullException(); } var graphics = new GdiGraphics(e.Graphics); ResetObjects(graphics, map); if (!map.BackColor.IsEmpty) { e.Graphics.Clear(map.BackColor); } if (map.Root != null) { Liner = LayoutManage.GetLiner(map.LayoutType); Font font = ChartBox.DefaultChartFont; var font2 = new GdiFont(font.FontFamily, font.Size * zoom); //GenerateFoldingButtonImage(map, zoom); PaintNavigationMap(graphics, map.Root, zoom, font2); PaintNavigationMapLinkLines(graphics, map.Root, zoom, font2); } }
cmdFanBlade_Click(object sender, EventArgs e) { int cIncrement = degRotate; if (cIncrement == 0) { cIncrement = 45; } IntPtr hdc = GdiGraphics.GetDC(m_hwndForm); for (int i = 0; i < 360; i += cIncrement) { IntPtr hfont = GdiFont.Create(hdc, "Tahoma", 12, i); IntPtr hfontOld = GdiGraphics.SelectObject(hdc, hfont); GdiGraphics.ExtTextOut(hdc, m_xText, m_yText, 0, IntPtr.Zero, "Rotated Text", 12, IntPtr.Zero); GdiGraphics.SelectObject(hdc, hfontOld); GdiGraphics.DeleteObject(hfont); } GdiGraphics.ReleaseDC(m_hwndForm, hdc); }
} // SetHorizontalAlignment // // Calculate font baseline for baseline alignment. // private int GetFontBaseline(string strFont, int cptHeight) { int cyReturn; // Fetch a Win32 DC. IntPtr hdc = GdiGraphics.GetDC(m_hwndForm); // Create a Win32 font. IntPtr hfont = GdiFont.Create(hdc, strFont, cptHeight, 0); // Select font into DC. IntPtr hfontOld = GdiGraphics.SelectObject(hdc, hfont); // Allocate font metric structure. GdiFont.TEXTMETRIC tm = new GdiFont.TEXTMETRIC(); // Fetch font metrics. GdiFont.GetTextMetrics(hdc, ref tm); // Fetch return value. cyReturn = tm.tmAscent; // Disconnect font from DC -- *Critical* because.... GdiGraphics.SelectObject(hdc, hfontOld); // ... clean up of Win32 font object requires font to // be disconnected from any and all DCs. GdiGraphics.DeleteObject(hfont); // Disconnect from Win32 DC. GdiGraphics.ReleaseDC(m_hwndForm, hdc); return(cyReturn); } // GetFontBaseline
FormMain_Paint(object sender, PaintEventArgs e) { // Fetch a Win32 DC. IntPtr hdc = GdiGraphics.GetDC(m_hwndForm); // Create a Win32 font. IntPtr hfont = GdiFont.Create(hdc, "Tahoma", 12, m_degRotate); // Select font into DC. IntPtr hfontOld = GdiGraphics.SelectObject(hdc, hfont); // Draw using Win32 text drawing function. GdiGraphics.ExtTextOut(hdc, m_xText, m_yText, 0, IntPtr.Zero, "Rotated Text", 12, IntPtr.Zero); // Disconnect font from DC -- *Critical* because.... GdiGraphics.SelectObject(hdc, hfontOld); // ... clean up of Win32 font object requires font to // be disconnected from any and all DCs. GdiGraphics.DeleteObject(hfont); // Disconnect from Win32 DC. GdiGraphics.ReleaseDC(m_hwndForm, hdc); }
mitemFilePrint_Click(object sender, EventArgs e) { // Display dialog to select printer & port. PAGESETUPDLGSTRUCT psd; psd = new PAGESETUPDLGSTRUCT(); PrintSetupDlg.InitDlgStruct(ref psd, hwndForm); int iErr = PrintSetupDlg.ShowDialog(ref psd); if (iErr == 0) { // Either error... string strErr = PrintSetupDlg.GetErrorString(); if (strErr != "Ok") { MessageBox.Show(strErr, "PrintGdi"); } // ...Or user clicked <Cancel> return; } IntPtr hdcPrinter = IntPtr.Zero; IntPtr hfont = IntPtr.Zero; IntPtr hfontOld = IntPtr.Zero; try { // Connect to printer by creating a DC. hdcPrinter = Printing.CreatePrinterDC(ref psd); if (hdcPrinter != IntPtr.Zero) { // Select font. hfont = GdiFont.Create(tboxInput.Font.Name, (int)tboxInput.Font.Size, 0, hdcPrinter); hfontOld = GdiGraphics.SelectObject(hdcPrinter, hfont); // Print PrintJob_Gdi.PrintText(tboxInput, hdcPrinter); } else { throw new System.Exception(); } } catch { MessageBox.Show("Error connecting to printer.", "PrintGdi"); } finally { // Cleanup GdiGraphics.SelectObject(hdcPrinter, hfontOld); GdiGraphics.DeleteObject(hfont); Printing.DeleteDC(hdcPrinter); // Clean up resources associated with print dialog. PrintSetupDlg.Close(ref psd); } }
/// <summary> /// Creates a <see cref="GdiFontMetrics"/> object from <b>baseFontName</b> /// </summary> private void ObtainFontMetrics() { dc = new GdiDeviceContent(); GdiFont font = GdiFont.CreateDesignFont( properties.FaceName, properties.IsBold, properties.IsItalic, dc); metrics = font.GetMetrics(dc); }
public RenderArgs(RenderMode mode, Graphics graphics, MindMap chart, Font font) : this() { Mode = mode; Graphics = new GdiGraphics(graphics); Chart = chart; Font = new GdiFont(font); }
public GdiFont SelectFont(GdiFont gdiFont) { if (gdiFont == null) { throw (new ArgumentNullException("gdiFont")); } this.SelectObject(gdiFont); return(gdiFont); }
public RenderArgs(RenderMode mode, Graphics graphics, MindMapView view, Font font) : this() { Mode = mode; Graphics = new GdiGraphics(graphics); View = view; Font = new GdiFont(font); if (view != null) { Chart = view.Map; } }
protected override void OnPaint(ChartGraphics g) { g.SelectBrush(this.Owner.BackColor); GdiFont gdiFont = g.SelectFont(this.Owner.ScaleFont); int fh = (int)gdiFont.Font.GetHeight(); this.Owner.Area.SelectGridPen(g); g.SetTextColor(this.Owner.ForeColor); for (int i = 0; i < _gridLines.Count; i++) { GridLine gl = _gridLines[i]; g.DrawLine(0, gl.Y, 2, gl.Y); g.TextOut(gl.Desc, 7, gl.Y - fh / 2); } }
public GdiFont SelectFont(Font font) { if (font == null) { throw (new ArgumentNullException("font")); } GdiFont.FontKey key = new GdiFont.FontKey(font); GdiFont gdiFont = null; _fontTable.TryGetValue(key, out gdiFont); if (gdiFont == null) { gdiFont = new GdiFont(font); _fontTable.Add(gdiFont.Key, gdiFont); } this.SelectObject(gdiFont); return(gdiFont); }
mitemFilePrint_Click(object sender, EventArgs e) { IntPtr hdcPrinter = IntPtr.Zero; IntPtr hfont = IntPtr.Zero; IntPtr hfontOld = IntPtr.Zero; try { // Connect to printer by creating a DC. hdcPrinter = mPrint.mPrintRenderWrapper.CreatePrinterContext(); if (hdcPrinter != IntPtr.Zero) { // Select font. hfont = GdiFont.Create(tboxInput.Font.Name, (int)tboxInput.Font.Size, 0, hdcPrinter); hfontOld = GdiGraphics.SelectObject(hdcPrinter, hfont); // Print PrintJob_Gdi.PrintText(tboxInput, hdcPrinter); } else { throw new System.Exception(); } } catch { MessageBox.Show("Error connecting to printer.", "PrintHPMobile"); } finally { // Cleanup GdiGraphics.SelectObject(hdcPrinter, hfontOld); GdiGraphics.DeleteObject(hfont); mPrint.mPrintRenderWrapper.DeletePrinterContext(hdcPrinter); } }
protected override void OnPaint(ChartGraphics g) { g.SelectBrush(this.Owner.BackColor); GdiFont gdiFont = g.SelectFont(this.Owner.ScaleFont); this.Owner.Area.SelectGridPen(g); g.SetTextColor(this.Owner.ForeColor); for (int i = 0; i < _gridLines.Count; i++) { GridLine gl = _gridLines[i]; g.DrawLine(gl.X, 0, gl.X, 2); g.TextOut(gl.Desc, gl.X, 3); } //for (int i = 0; i < _viewCountBar; i++) { // int x = i * this.DeltaX; // int barindex = i + this.Position; // if (Multiple(x, 32)) { // //if (this.HorizontalScaleVisible && this.ChartManager.Bars != null && barindex < barcount) { // // string sc = ""; // // DateTime dtm = this.ChartManager.Bars[barindex].Time; // // if (l) { // // sc = dtm.ToString("d MMM yyyy"); // // l = false; // // } else // // sc = dtm.ToString("d MMM ") + dtm.ToShortTimeString(); // // ghscale.DrawLine(_borderPen, _map[i], 0, _map[i], 2); // // ghscale.DrawString(sc, Manager.Style.ScaleFont, _scaleForeBrush, _map[i], 2); // //} // } //} }
//-------------------------------------------------------- public static void PrintText(TextBox textIn, IntPtr hdc) { // Split input data into separate lines of text. char [] achNewLine = new char[] { '\n' }; String [] astrSplit; astrSplit = textIn.Text.Split(achNewLine); // Calculate longest string in the document int cchMax = 0; int cstr = astrSplit.Length; for (int i = 0; i < cstr; i++) { if (astrSplit[i].Length > cchMax) { cchMax = astrSplit[i].Length; } } // Allocate conversion buffers. byte[] byteData = new Byte[cchMax]; char[] chData = new Char[cchMax]; System.Text.Encoder d; d = System.Text.Encoding.UTF8.GetEncoder(); // Get device resolution int cxyInch = GdiGraphics.GetDeviceCaps(hdc, CAPS.LOGPIXELSY); // In draft mode, the PCL driver returns wrong value. if (cxyInch == 0) { cxyInch = 150; } // Calculate page size. int cxPhysPage = GdiGraphics.GetDeviceCaps(hdc, CAPS.PHYSICALWIDTH); int cyPhysPage = GdiGraphics.GetDeviceCaps(hdc, CAPS.PHYSICALHEIGHT); int cxOff = GdiGraphics.GetDeviceCaps(hdc, CAPS.PHYSICALOFFSETX); int cyOff = GdiGraphics.GetDeviceCaps(hdc, CAPS.PHYSICALOFFSETY); // Calculate line height. TEXTMETRIC tm = new TEXTMETRIC(); GdiFont.GetTextMetrics(hdc, ref tm); int cyLineHeight = tm.tmHeight + tm.tmExternalLeading; // Init text drawing coordinates; int xText = cxyInch - cxOff; int yText = cxyInch - cyOff; // Calculate page boundaries int yFirst = yText; int yLast = cyPhysPage - cxyInch; // Notify GDI of document and page start. DOCINFO di = new DOCINFO(); di.cbSize = Marshal.SizeOf(di); Printing.StartDoc(hdc, ref di); Printing.StartPage(hdc); try { // Set iEnd -- trim extra carriage-return from text int iEnd = 0; int cchString = astrSplit[0].Length; char ch = astrSplit[0][cchString - 1]; if (ch == '\r') { iEnd = -1; } // Loop through list of strings. for (int i = 0; i < cstr; i++) { cchString = astrSplit[i].Length; if (cchString > 0) { // Draw line of text. GdiGraphics.ExtTextOut(hdc, xText, yText, 0, IntPtr.Zero, astrSplit[i], cchString + iEnd, IntPtr.Zero); } // Advance to next line. yText += cyLineHeight; // Skip to next page (if not at document end) if (yText >= yLast && (i + 1) < cstr) { Printing.EndPage(hdc); Printing.StartPage(hdc); yText = yFirst; } } } finally { // End of page & end of document. Printing.EndPage(hdc); Printing.EndDoc(hdc); } } // PrintText()