///////////////////////////////////////////////////////////////////// // Test font api class initialization ///////////////////////////////////////////////////////////////////// private void OnLoad ( object sender, EventArgs e ) { // add data grid DataGrid = new CustomDataGridView(this, false); DataGrid.CellFormatting += new DataGridViewCellFormattingEventHandler(OnCellFormatting); DataGrid.CellMouseDoubleClick += new DataGridViewCellMouseEventHandler(OnMouseDoubleClick); // add columns DataGrid.Columns.Add("FontFamilyName", "FontFamilyName"); DataGrid.Columns.Add("Sample", "Sample"); DataGrid.Columns.Add("Type", "Type"); DataGrid.Columns.Add("Style", "Style"); // load available font families array FontFamily[] FamilyArray = FontFamily.Families; foreach (FontFamily FF in FamilyArray) { // look for first available style for current font family Int32 StyleIndex; FontStyle Style = FontStyle.Regular; StringBuilder StyleStr = new StringBuilder(); String[] StyleCode = new String[] { "R,", "B,", "I,", "BI," }; // try regulaar, bold, italic and bold-italic for (StyleIndex = 0; StyleIndex < 4; StyleIndex++) { if (!FF.IsStyleAvailable((FontStyle)StyleIndex)) { continue; } if (StyleStr.Length == 0) { Style = (FontStyle)StyleIndex; } StyleStr.Append(StyleCode[StyleIndex]); } // should not happen if (StyleStr.Length == 0) { continue; } // remove last comma StyleStr.Length--; // add one data grid row Int32 Row = DataGrid.Rows.Add(); DataGridViewRow ViewRow = DataGrid.Rows[Row]; // save font family in row's tag ViewRow.Tag = FF; // design height Int32 DesignHeight = FF.GetEmHeight(Style); // create font Font DesignFont = new Font(FF, DesignHeight, Style, GraphicsUnit.Pixel); // create windows sdk font info object FontApi FontInfo = new FontApi(DesignFont, DesignHeight); WinTextMetric TM = FontInfo.GetTextMetricsApi(); String Type = FamilyType[TM.tmPitchAndFamily >> 4]; if ((TM.tmPitchAndFamily & 1) == 0) { Type += ",Fix"; } if ((TM.tmPitchAndFamily & 2) == 0) { Type += ",Bmap"; } if ((TM.tmPitchAndFamily & 4) != 0) { Type += ",TT"; } if ((TM.tmPitchAndFamily & 8) != 0) { Type += ",Dev"; } // set value of each column ViewRow.Cells[(Int32)FontFamilyColumn.Name].Value = FF.Name; ViewRow.Cells[(Int32)FontFamilyColumn.Sample].Value = "ABCDabcd0123"; ViewRow.Cells[(Int32)FontFamilyColumn.Family].Value = Type; ViewRow.Cells[(Int32)FontFamilyColumn.Style].Value = StyleStr.ToString(); // create a font for the display of the sample ViewRow.Cells[(Int32)FontFamilyColumn.Sample].Tag = new Font(FF, 12, Style); } // select first row if (DataGrid.Rows.Count > 0) { DataGrid.Rows[0].Selected = true; } // force resize OnResize(this, null); // exit return; }