private void xxcbDrawItem(object sender, DrawItemEventArgs e) { //drawItems here if (sender == null) return; if (e.Index < 0) return; //Get the Combo from the sender object ComboBox cbo = (ComboBox)sender; //Get the FontFamily from put in constructor FontFamily ff = new FontFamily(cbo.Items[e.Index].ToString()); //Set font style FontStyle fs = FontStyle.Regular; if (!ff.IsStyleAvailable(fs)) fs = FontStyle.Italic; if (!ff.IsStyleAvailable(fs)) fs = FontStyle.Bold; //Set font for drawing with (wich is the font itself) Font font = new Font(ff, 8, fs); //draw the background and focus rectangle e.DrawBackground(); e.DrawFocusRectangle(); //get graphics Graphics g = e.Graphics; //And draw with whatever font and brush we wish g.DrawString(font.Name, font, Brushes.ForestGreen, e.Bounds.X, e.Bounds.Y); }
/// <summary> /// Occurs during the drawing of an item /// </summary> /// <param name="e"></param> protected override void OnDrawItem(DrawItemEventArgs e) { Rectangle outer = e.Bounds; outer.Inflate(1, 1); e.Graphics.FillRectangle(Brushes.White, outer); Brush fontBrush = Brushes.Black; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { Rectangle r = e.Bounds; r.Inflate(-1, -1); e.Graphics.FillRectangle(Global.HighlightBrush(r, Color.FromArgb(215, 238, 252)), r); Pen p = new Pen(Color.FromArgb(215, 238, 252)); Global.DrawRoundedRectangle(e.Graphics, p, e.Bounds); p.Dispose(); } string name = Items[e.Index].ToString(); FontFamily ff = new FontFamily(name); Font fnt = new Font("Arial", 10, FontStyle.Regular); if (ff.IsStyleAvailable(FontStyle.Regular)) { fnt = new Font(name, 10, FontStyle.Regular); } else if (ff.IsStyleAvailable(FontStyle.Italic)) { fnt = new Font(name, 10, FontStyle.Italic); } SizeF box = e.Graphics.MeasureString(name, Font); e.Graphics.DrawString(name, Font, fontBrush, e.Bounds.X, e.Bounds.Y); e.Graphics.DrawString("ABC", fnt, fontBrush, e.Bounds.X + box.Width, e.Bounds.Y); }
internal System.Drawing.Font get_drawing_font() { if (internal_font == null || check_font_dirty()) { System.Drawing.FontFamily ff; try { ff = new System.Drawing.FontFamily(name, private_fonts); } catch (Exception e) { ff = new System.Drawing.FontFamily(name); } System.Drawing.FontStyle style = System.Drawing.FontStyle.Regular; if (bold && ff.IsStyleAvailable(System.Drawing.FontStyle.Bold)) { style = System.Drawing.FontStyle.Bold; } if (italic && ff.IsStyleAvailable(System.Drawing.FontStyle.Italic)) { style = System.Drawing.FontStyle.Italic; } if (bold && italic && ff.IsStyleAvailable(System.Drawing.FontStyle.Bold) && ff.IsStyleAvailable(System.Drawing.FontStyle.Italic)) { style = System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic; } if (internal_font != null) { internal_font.Dispose(); } internal_font = new System.Drawing.Font(ff, size - 10, style, System.Drawing.GraphicsUnit.Pixel); } return(internal_font); }
protected override void OnDrawItem(DrawItemEventArgs e) { if (!this.Enabled) { e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds); } else { e.DrawBackground(); string fontName = null; if (e.Index == -1) { // Text shown in the combobox itself fontName = this.Text; } else { fontName = (string)this.Items[e.Index]; } Font font = null; if ((fontName != null) && (fontName.Length != 0)) { try { FontFamily fontFamily = new FontFamily(fontName); FontStyle fontStyle = FontStyle.Regular; if (!fontFamily.IsStyleAvailable(fontStyle)) { fontStyle = FontStyle.Italic; if (!fontFamily.IsStyleAvailable(fontStyle)) { fontStyle = FontStyle.Bold; if (!fontFamily.IsStyleAvailable(fontStyle)) { throw new NotSupportedException(); } } } font = new Font(fontName, (float)((e.Bounds.Height - 2) / 1.2), fontStyle, GraphicsUnit.Pixel); } catch (Exception) { } } Rectangle textBounds = new Rectangle(e.Bounds.Left + 2, e.Bounds.Top, e.Bounds.Width - 2, e.Bounds.Height); using (TextGraphics textGraphics = new TextGraphics(e.Graphics)) { textGraphics.DrawText(fontName, textBounds.Location, (font != null) ? font : e.Font, e.ForeColor); } if (font != null) { font.Dispose(); } } }
private Font GetFont(FontFamily family, FontStyle style, float size) { if (family.IsStyleAvailable(style)) { return new Font(family, size, style); } var styleWithDefault = style |= GetDefaultStyle(family); if (family.IsStyleAvailable(styleWithDefault)) { return new Font(family, size, style); } return new Font(family, size, SelectionFont.Style); }
public static FontStyle GetDefaultStyle(FontFamily fontFamily) { if (fontFamily.IsStyleAvailable(FontStyle.Regular)) return FontStyle.Regular; if (fontFamily.IsStyleAvailable(FontStyle.Bold)) return FontStyle.Bold; if (fontFamily.IsStyleAvailable(FontStyle.Italic)) return FontStyle.Italic; if (fontFamily.IsStyleAvailable(FontStyle.Underline)) return FontStyle.Underline; if (fontFamily.IsStyleAvailable(FontStyle.Strikeout)) return FontStyle.Strikeout; return FontStyle.Regular; }
public static FontStyle GetFittingStyle(FontFamily ff) { var style = FontStyle.Regular; if (!ff.IsStyleAvailable(style)) { style = ff.IsStyleAvailable(FontStyle.Bold) ? FontStyle.Bold : ff.IsStyleAvailable(FontStyle.Italic) ? FontStyle.Italic : ff.IsStyleAvailable(FontStyle.Strikeout) ? FontStyle.Strikeout : FontStyle.Underline; } return style; }
///<summary> /// Convert a UI Dialog Font to a System.Drawing.Font /// </summary> public static Font FontFromUiDialogFont(UIDLGLOGFONT logFont) { var conversion = new char[logFont.lfFaceName.Length]; for(int i = 0; i < logFont.lfFaceName.Length; i++) { conversion[i] = (char)logFont.lfFaceName[i]; } var familyName = new String(conversion); var emSize = Math.Abs(logFont.lfHeight); var style = FontStyle.Regular; int FW_NORMAL = 400; if (logFont.lfItalic > 0) { style |= FontStyle.Italic; } if (logFont.lfUnderline > 0) { style |= FontStyle.Underline; } if (logFont.lfStrikeOut > 0) { style |= FontStyle.Strikeout; } if (logFont.lfWeight > FW_NORMAL) { style |= FontStyle.Bold; } var unit = GraphicsUnit.Pixel; var gdiCharSet = logFont.lfCharSet; var ff = new FontFamily(familyName); var teststyles = new FontStyle[5]; teststyles[0] = style; teststyles[1] = FontStyle.Regular; teststyles[2] = FontStyle.Bold; teststyles[3] = FontStyle.Italic; teststyles[4] = FontStyle.Bold | FontStyle.Italic; for (int i = 0; i < teststyles.Length; i++) { if (ff.IsStyleAvailable(teststyles[i])) { style = teststyles[i]; return new Font(familyName, emSize, style, unit, gdiCharSet); } } // We can't find a valid style for this font - fallback to just size and unit return new Font(familyName, emSize, unit); }
public static Font GetLegacyFont(TextBlock element) { System.Drawing.FontStyle style = 0; FontStyle[] s = new System.Drawing.FontStyle[] { FontStyle.Regular, FontStyle.Bold, FontStyle.Italic, FontStyle.Strikeout, FontStyle.Underline }; // Find the first default style that will work with this font... var family = new System.Drawing.FontFamily(element.FontFamily.Source); foreach (FontStyle fs in s) { if (family.IsStyleAvailable(fs)) { style = fs; break; } } // Scale the font from 96 DPI to 72 DPI double size = PixelsToPoints(element, element.FontSize); if (element.FontWeight == System.Windows.FontWeights.Bold) { style |= System.Drawing.FontStyle.Bold; } if (element.FontStyle == System.Windows.FontStyles.Italic || element.FontStyle == System.Windows.FontStyles.Oblique) { style |= System.Drawing.FontStyle.Italic; } if (element.TextDecorations.Contains(System.Windows.TextDecorations.Underline[0])) { style |= System.Drawing.FontStyle.Underline; } if (element.TextDecorations.Contains(System.Windows.TextDecorations.Strikethrough[0])) { style |= System.Drawing.FontStyle.Strikeout; } var font = new Font(family, (float)size, style); return(font); }
private void UpdateFontStyle() { chkStrikeout.Checked = (selectedFont.Style & FontStyle.Strikeout) == FontStyle.Strikeout; chkUnderline.Checked = (selectedFont.Style & FontStyle.Underline) == FontStyle.Underline; styleList.Items.Clear(); if (string.IsNullOrEmpty(selectedFont.Name)) { styleList.Enabled = false; } else { styleList.Enabled = true; using (FontFamily ff = new FontFamily(selectedFont.Name)) { if (ff.IsStyleAvailable(FontStyle.Regular)) styleList.Items.Add("Regular"); if (ff.IsStyleAvailable(FontStyle.Italic)) styleList.Items.Add("Italic"); if (ff.IsStyleAvailable(FontStyle.Bold)) styleList.Items.Add("Bold"); if (ff.IsStyleAvailable(FontStyle.Bold | FontStyle.Italic)) styleList.Items.Add("Bold Italic"); chkStrikeout.Enabled = ff.IsStyleAvailable(FontStyle.Strikeout); if (!chkStrikeout.Enabled) chkStrikeout.Checked = false; chkUnderline.Enabled = ff.IsStyleAvailable(FontStyle.Underline); if (!chkUnderline.Enabled) chkUnderline.Checked = false; int foundOldStyle = -1; for (int i = 0; i < styleList.Items.Count; i++) { string text = Convert.ToString(styleList.Items[i]); FontStyle fs = FontToolkit.GetFontStyleByName(text, "italic", "bold"); if (fs == SelectedFont.Style) { styleList.SelectedIndex = foundOldStyle = i; break; } } if (foundOldStyle == -1 && styleList.Items.Count > 0) { styleList.SelectedIndex = 0; selectedFont.Style = FontToolkit.GetFontStyleByName(Convert.ToString(styleList.Items[0]), "italic", "bold"); if (chkUnderline.Checked) selectedFont.Style |= FontStyle.Underline; if (chkStrikeout.Checked) selectedFont.Style |= FontStyle.Strikeout; } } } txtStyle.Text = FontToolkit.GetFontStyleName(selectedFont.Style, "Regular", "Italic", "Bold"); labSample.Invalidate(); }
private void lbDrawItem(object sender, DrawItemEventArgs e) { Brush brush1; Brush brush2; Font font1; Rectangle rectangle1 = e.Bounds; int num1 = rectangle1.X; rectangle1 = e.Bounds; int num2 = rectangle1.Y; if (this.lb.SelectedIndex == e.Index) { brush1 = SystemBrushes.ActiveCaption; brush2 = SystemBrushes.HighlightText; } else { brush1 = SystemBrushes.Window; brush2 = SystemBrushes.ControlText; } e.Graphics.FillRectangle(brush1, e.Bounds); if (this.m_ShowName) { e.Graphics.DrawString(this.lb.Items[e.Index].ToString(), base.Font, brush2, ((float)num1), ((float)num2)); num1 += 160; } if (!this.m_ShowSample) { return; } FontFamily family1 = new FontFamily(this.lb.Items[e.Index].ToString()); if (family1.IsStyleAvailable(FontStyle.Regular)) { font1 = new Font(this.lb.Items[e.Index].ToString(), 10f, FontStyle.Regular); } else { if (family1.IsStyleAvailable(FontStyle.Bold)) { font1 = new Font(this.lb.Items[e.Index].ToString(), 10f, FontStyle.Bold); goto Label_0194; } if (family1.IsStyleAvailable(FontStyle.Italic)) { font1 = new Font(this.lb.Items[e.Index].ToString(), 10f, FontStyle.Italic); goto Label_0194; } font1 = new Font(this.lb.Items[e.Index].ToString(), 10f, (FontStyle.Italic | FontStyle.Bold)); } Label_0194: e.Graphics.DrawString(this.m_SampleText, font1, brush2, ((float)num1), ((float)num2)); font1.Dispose(); }
/// <summary> /// Returns the valid FontStyle which are compatible with specified FontName. /// </summary> /// <param name="fontName">font Name</param> /// <returns>DataTable having 2 Columns (StyleName, StyleID). dataRow sample-: Bold, 1</returns> public static DataTable GetFontStyle(string fontName) { DataTable RetVal = new DataTable(); RetVal.Columns.Add("StyleName"); RetVal.Columns.Add("StyleID"); try { FontFamily oFontFamily = new FontFamily(fontName); if (oFontFamily.IsStyleAvailable(FontStyle.Regular)) { RetVal.Rows.Add(new object[] { "Regular", 0 }); } if (oFontFamily.IsStyleAvailable(FontStyle.Bold)) { RetVal.Rows.Add(new object[] { "Bold", 1 }); } if (oFontFamily.IsStyleAvailable(FontStyle.Italic)) { RetVal.Rows.Add(new object[] { "Italic", 2 }); } if (oFontFamily.IsStyleAvailable(FontStyle.Underline)) { RetVal.Rows.Add(new object[] { "Underline", 4 }); } if (oFontFamily.IsStyleAvailable(FontStyle.Strikeout)) { RetVal.Rows.Add(new object[] { "Strikeout", 8 }); } } catch { } return RetVal; }
private void cbxFamily_SelectedIndexChanged(object sender, System.EventArgs e) { if (this.inModelToView) return; int idx = this.cbxFamily.SelectedIndex; if (idx >= 0) { this.fontProperty.FamilyName = this.cbxFamily.SelectedItem.ToString(); FontFamily family = new FontFamily(this.fontProperty.FamilyName); string supportedSyles = ""; if (family.IsStyleAvailable(FontStyle.Regular)) supportedSyles += "Regualr, "; if (family.IsStyleAvailable(FontStyle.Bold)) supportedSyles += "Bold, "; if (family.IsStyleAvailable(FontStyle.Italic)) supportedSyles += "Italic, "; if (family.IsStyleAvailable(FontStyle.Bold | FontStyle.Italic)) supportedSyles += "BoldItalic, "; if (family.IsStyleAvailable(FontStyle.Strikeout)) supportedSyles += "Strikeout, "; if (family.IsStyleAvailable(FontStyle.Underline)) supportedSyles += "Underline, "; this.lblSupportedStyles.Text = supportedSyles; OnUpdateDrawing(); } }
private void rtxShow_SelectionChanged(object sender, EventArgs e) { try { #region Aglin if (rtxShow.SelectionAlignment == ExtendedRichTextBox.RichTextAlign.Left) { btnAlignLeft.Checked = true; btnAlignCenter.Checked = false; btnAlignRight.Checked = false; } else if (rtxShow.SelectionAlignment == ExtendedRichTextBox.RichTextAlign.Center) { btnAlignLeft.Checked = false; btnAlignCenter.Checked = true; btnAlignRight.Checked = false; } else if (rtxShow.SelectionAlignment == ExtendedRichTextBox.RichTextAlign.Right) { btnAlignLeft.Checked = false; btnAlignCenter.Checked = false; btnAlignRight.Checked = true; } else { btnAlignLeft.Checked = true; btnAlignCenter.Checked = false; btnAlignRight.Checked = false; } #endregion #region Font FontFamily ff = new FontFamily("Tahoma"); if (ff.IsStyleAvailable(FontStyle.Bold) == true) { btnBold.Enabled = true; btnBold.Checked = rtxShow.SelectionCharStyle.Bold; } else { btnBold.Enabled = false; btnBold.Checked = false; } if (ff.IsStyleAvailable(FontStyle.Italic) == true) { btnItalic.Enabled = true; btnItalic.Checked = rtxShow.SelectionCharStyle.Italic; } else { btnItalic.Enabled = false; btnItalic.Checked = false; } if (ff.IsStyleAvailable(FontStyle.Underline) == true) { btnUnderline.Enabled = true; btnUnderline.Checked = rtxShow.SelectionCharStyle.Underline; } else { btnUnderline.Enabled = false; btnUnderline.Checked = false; } ff.Dispose(); #endregion rtxShow.UpdateObjects(); } catch (Exception) { } }
private static void SetAttributeValue(Control control, string propertyName, string value) { if (control is EIBColumn) { if (propertyName == XMLServicesConstants.XmlNodeSortableAtt) { if (value.Equals("auto")) { ((EIBColumn) control).Sortable = true; } else { ((EIBColumn)control).Sortable = false; } } } if (propertyName == XMLServicesConstants.XmlNodeTextAtt) { control.Text = value; } if (propertyName == XMLServicesConstants.XmlNodeTabIndexAtt) { control.TabIndex = int.Parse(value); } if (propertyName == XMLServicesConstants.XmlNodeIdAtt) { control.Name = value; } // Check for the layout of the basewindow going negative. if (control.Parent is BaseWindow) { control.Location = new System.Drawing.Point(0,0); } else { if (propertyName == XMLServicesConstants.XmlNodeXAtt) { control.Location = new System.Drawing.Point(Int32.Parse(value), control.Location.Y); } if (propertyName == XMLServicesConstants.XmlNodeYAtt) { control.Location = new System.Drawing.Point(control.Location.X, Int32.Parse(value)); } } if (propertyName == XMLServicesConstants.XmlNodeWidthTypeAtt) { if (control is ICustomSizableControl) { if (value == WidthMeasurement.Auto.ToString()) { ((ICustomSizableControl)control).WidthType = WidthMeasurement.Auto; } else if (value == WidthMeasurement.Pixel.ToString()) { ((ICustomSizableControl)control).WidthType = WidthMeasurement.Pixel; } else if (value == WidthMeasurement.Percent.ToString()) { ((ICustomSizableControl)control).WidthType = WidthMeasurement.Percent; } } } if (propertyName == XMLServicesConstants.XmlNodeWidthAtt) { if (control is ICustomSizableControl) { ((ICustomSizableControl)control)._Width = Int32.Parse(value); /*if (((ICustomSizableControl)control).WidthType == WidthMeasurement.Percent) { ((ICustomSizableControl)control).WidthType = WidthMeasurement.Percent; ((ICustomSizableControl)control)._Width = Int32.Parse(value.Replace("%", "")); } else if (value.Contains("px")) { ((ICustomSizableControl)control).WidthType = WidthMeasurement.Pixel; ((ICustomSizableControl)control)._Width = Int32.Parse(value.Replace("px", "")); } else { int wdth = 0; if (Int32.TryParse(value, out wdth)) { ((ICustomSizableControl)control).WidthType = WidthMeasurement.Auto; ((ICustomSizableControl)control)._Width = Int32.Parse(value); } }*/ } else { control.Width = Int32.Parse(value); } if (control is EIBColumn) { EIBColumn column = (EIBColumn)control; if (column.WidthType == WidthMeasurement.Pixel) { column.WidthPixel = Int32.Parse(value); control.Width = Int32.Parse(value); } } } if (propertyName == XMLServicesConstants.XmlNodeHeightAtt) { control.Height = Int32.Parse(value); if (control is EIBRow) { EIBRow row = (EIBRow)control; if (row.HeightTyp == EIBRow.HeightMeasurement.Pixel) { row.HeightPixel = Int32.Parse(value); } } } #region Cursor propreties if (propertyName == XMLServicesConstants.XmlNodeCursorAtt) { control.Cursor = getCursorFromValue(value); } #endregion #region Padding and Margin Properties if (propertyName == XMLServicesConstants.XmlNodePaddingLeftAtt) { control.Padding = new Padding(int.Parse(value), control.Padding.Top, control.Padding.Right, control.Padding.Bottom) ; } if (propertyName == XMLServicesConstants.XmlNodePaddingRightAtt) { control.Padding = new Padding(control.Padding.Left, control.Padding.Top, int.Parse(value), control.Padding.Bottom) ; } if (propertyName == XMLServicesConstants.XmlNodePaddingBottomAtt) { control.Padding = new Padding(control.Padding.Left, control.Padding.Top, control.Padding.Right, int.Parse(value)) ; } if (propertyName == XMLServicesConstants.XmlNodePaddingTopAtt) { control.Padding = new Padding(control.Padding.Left, int.Parse(value), control.Padding.Right,control.Padding.Bottom ) ; } if (!(control is IEIBControl)) { if (propertyName == XMLServicesConstants.XmlNodeMarginLeftAtt) { control.Margin = new Padding(int.Parse(value), control.Margin.Top, control.Margin.Right, control.Margin.Bottom); } if (propertyName == XMLServicesConstants.XmlNodeMarginRightAtt) { control.Margin = new Padding(control.Margin.Left, control.Margin.Top, int.Parse(value), control.Margin.Bottom); } if (propertyName == XMLServicesConstants.XmlNodeMarginBottomAtt) { control.Margin = new Padding(control.Margin.Left, control.Margin.Top, control.Margin.Right, int.Parse(value)); } if (propertyName == XMLServicesConstants.XmlNodeMarginTopAtt) { control.Margin = new Padding(control.Margin.Left, int.Parse(value), control.Margin.Right, control.Margin.Bottom); } } else { IEIBControl control1 = (IEIBControl)control; if (propertyName == XMLServicesConstants.XmlNodeMarginLeftAtt) { control1.ControlMargin = new Padding(int.Parse(value), control1.ControlMargin.Top, control1.ControlMargin.Right, control1.ControlMargin.Bottom); } if (propertyName == XMLServicesConstants.XmlNodeMarginRightAtt) { control1.ControlMargin = new Padding(control1.ControlMargin.Left, control1.ControlMargin.Top, int.Parse(value), control1.ControlMargin.Bottom); } if (propertyName == XMLServicesConstants.XmlNodeMarginBottomAtt) { control1.ControlMargin = new Padding(control1.ControlMargin.Left, control1.ControlMargin.Top, control1.ControlMargin.Right, int.Parse(value)); } if (propertyName == XMLServicesConstants.XmlNodeMarginTopAtt) { control1.ControlMargin = new Padding(control1.ControlMargin.Left, int.Parse(value), control1.ControlMargin.Right, control1.ControlMargin.Bottom); } } #endregion if (propertyName == XMLServicesConstants.XmlNodeBoxAlignmentAtt) { if (value == "horizontal") { ((EIBPanel)control).BoxAlignment = BoxAlignment.Horizontal; } else if (value == "vertical") { ((EIBPanel)control).BoxAlignment = BoxAlignment.Vertical; } else { ((EIBPanel)control).BoxAlignment = BoxAlignment.None; } } if (propertyName == XMLServicesConstants.XmlNodeDateFormatAtt) { if (control is EIBDatePicker) { EIBDatePicker datetimepicker = (EIBDatePicker)control; datetimepicker.CustomFormatType = value; } } if (propertyName == XMLServicesConstants.XmlNodeVisibleAtt) { if (control is ICustomVisible) { ICustomVisible ctrlVisible = (ICustomVisible)control; if ((value.Equals(true.ToString().ToLower()))) { ctrlVisible.Visible = true; } else { ctrlVisible.Visible = false; } } else { if ((value.Equals(true.ToString().ToLower()))) control.Visible = true; else control.Visible = false; } } if (propertyName == XMLServicesConstants.XmlNodeEnableAtt) { if ((value.Equals(true.ToString().ToLower()))) control.Enabled = true; else control.Enabled = false; } if (propertyName == XMLServicesConstants.XmlNodeAlignAtt) { if (control is IContainerControl) { ((IContainerControl)control).Align = getContainerAlignment(value); //(value == ContainerAlignment.Center.ToString().ToLower())?ContainerAlignment.Center:(value == ContainerAlignment.Left.ToString().ToLower())?ContainerAlignment.Left:ContainerAlignment.Right; } } if (propertyName == XMLServicesConstants.XmlNodePositionAtt) { ((IEIBControl)control).Position = (value == ControlPosition.Absolute.ToString().ToLower()) ? ControlPosition.Absolute : ControlPosition.Relative; } if (propertyName == XMLServicesConstants.XmlNodeFontSizeAtt) { control.Font = new Font(control.Font.FontFamily, float.Parse(value),control.Font.Style); } if (propertyName == XMLServicesConstants.XmlNodeFontStyleAtt) { FontStyle fs=GetFontStyle(value); control.Font = new Font(control.Font,fs ); } if (propertyName == XMLServicesConstants.XmlNodeFontAtt) { FontFamily f = new FontFamily(value); if (f.IsStyleAvailable(control.Font.Style)) { control.Font = new Font(value, control.Font.Size, control.Font.Style); } else { MessageBox.Show("Font style not supported for " +(value.ToString().Trim()) + " for control " +(control.Text.ToString()) ); } } if (propertyName == XMLServicesConstants.XmlNodeNetBackColorAtt) { if (!value.Contains("#")) { control.BackColor = Color.FromName(value); } else { control.BackColor = ColorTranslator.FromHtml(value); } } if (propertyName == XMLServicesConstants.XmlNodeNetForeColorAtt) { if (!value.Contains("#")) { control.ForeColor = Color.FromName(value); } else { control.ForeColor = ColorTranslator.FromHtml(value); } } if (propertyName == XMLServicesConstants.XmlNodeTimeAtt) { ((EIBTime)control).setTime(value); } if (propertyName == XMLServicesConstants.XmlNodeFirstDayOfWeekAtt) { if(control is EIBSchedular) ((EIBSchedular)control).FirstDayOfWeek = value; } //Applet if (propertyName == XMLServicesConstants.XmlNodeArchiveAtt) { if (control is EIBApplet) ((EIBApplet)control).Archive = value.Split('/')[1]; } if (propertyName == XMLServicesConstants.XmlNodeCodeAtt) { if (control is EIBApplet) ((EIBApplet)control).Code = value; } if (propertyName == XMLServicesConstants.XmlNodeAppNameAtt) { if (control is EIBApplet) ((EIBApplet)control).AppName = value; } if (propertyName == XMLServicesConstants.XmlNodeMultiSelectAtt) { bool val; if (value.Equals(true.ToString(),StringComparison.OrdinalIgnoreCase)) val = true; else val = false; if(control is EIBGrid) ((EIBGrid)control).MultiSelect = val; if(control is EIBLattice) ((EIBLattice)control).MultiSelect = val; if (control is EIBListbox) ((EIBListbox)control).MultiSelect = val; } if (propertyName == XMLServicesConstants.XmlNodeMenuIconAtt) { string fileNameValue = Path.GetFileNameWithoutExtension(value); fileNameValue = fileNameValue.Insert(fileNameValue.Length, DateTime.Now.Ticks.ToString()); fileNameValue = Path.GetTempPath() + @"\" + fileNameValue + ".jpg"; File.Copy(EIBXMLUtilities.folderName + @"\" + value, fileNameValue, true); Bitmap imgInFile = new Bitmap(fileNameValue); if(control is EIBMenuBar) ((EIBMenuBar) control).MenuIcon = imgInFile; if (control is EIBVMenuBar) ((EIBVMenuBar)control).MenuIcon = imgInFile; } if (propertyName == XMLServicesConstants.XmlNodeMoldAtt) { if (control is EIBSchedular) ((EIBSchedular)control).Mold = value; } if (propertyName == XMLServicesConstants.XmlNodeTimeZoneAtt) { if (control is EIBSchedular) ((EIBSchedular)control).TimeZone = value; } if (propertyName == XMLServicesConstants.XmlNodePasswordCharAtt) { if (control is EIBTextBox) { EIBTextBox textBox = (EIBTextBox)control; if (value.Length == 1) { textBox.PasswordChar = value[0]; } } } if (propertyName == XMLServicesConstants.XmlNodeReadOnlyAtt) { if (control is EIBTextBox) { EIBTextBox textBox = (EIBTextBox)control; textBox.ReadOnly = (value.Equals(true.ToString().ToLower())); } if (control is EIBCombobox) { EIBCombobox comboBox = (EIBCombobox)control; comboBox.ReadOnly = (value.Equals(true.ToString().ToLower())); } } if (propertyName == XMLServicesConstants.XmlNodeMaxLengthAtt) { if (control is EIBTextBox) { EIBTextBox textBox = (EIBTextBox)control; textBox.MaxLength = Int32.Parse(value); ; } } if (propertyName == XMLServicesConstants.XmlNodeValueTypeAtt) { if (control is EIBTextBox) { EIBTextBox textBox = (EIBTextBox)control; textBox.ValueType = value; } } if (propertyName == XMLServicesConstants.XmlNodePageSizeAtt) { if (control is EIBPaging) { ((EIBPaging)control).PageSize = Int32.Parse(value); } } if (propertyName == XMLServicesConstants.XmlNodePaginalAtt) { if (control is EIBListbox) { ((EIBListbox)control).paginal = value; } if (control is EIBGrid) { ((EIBGrid)control).paginal = value; } if (control is EIBLattice) { ((EIBLattice)control).paginal = value; } } if (propertyName == XMLServicesConstants.XmlNodeSourceAtt) { if (control is EIBPicture) { EIBPicture picture = (EIBPicture)control; MemoryStream ms = new MemoryStream(File.ReadAllBytes(EIBXMLUtilities.folderName + "/" + value)); Image imgInFile = Image.FromStream(ms); //Image imgInFile = Image.FromFile(EIBXMLUtilities.folderName + "/" + value); picture.Image = imgInFile; ms.Close(); ms.Dispose(); } if (control is EIBImageBrowse) { EIBImageBrowse imageBrowse = (EIBImageBrowse)control; MemoryStream ms = new MemoryStream(File.ReadAllBytes(EIBXMLUtilities.folderName + "/" + value)); Image imgInFile = Image.FromStream(ms); //Image imgInFile = Image.FromFile(EIBXMLUtilities.folderName + "/" + value); imageBrowse.Image = imgInFile; ms.Close(); ms.Dispose(); } if (control is EIBButton) { EIBButton button = (EIBButton)control; string fileNameValue = Path.GetFileNameWithoutExtension(value); fileNameValue = fileNameValue.Insert(fileNameValue.Length, DateTime.Now.Ticks.ToString()); fileNameValue = Path.GetTempPath() + @"\" + fileNameValue + ".jpg"; File.Copy(EIBXMLUtilities.folderName + @"\" + value, fileNameValue, true); Bitmap imgInFile = new Bitmap(fileNameValue); button.Image = imgInFile; //MemoryStream ms = new MemoryStream(File.ReadAllBytes(EIBXMLUtilities.folderName + "/" + value)); //Image imgInFile = Image.FromStream(ms); //button.Image = imgInFile; //ms.Close(); //ms.Dispose(); } GC.Collect(); GC.WaitForPendingFinalizers(); } if (propertyName == XMLServicesConstants.XmlNodeBackgroundImageAtt) { string fileNameValue = Path.GetFileNameWithoutExtension(value); fileNameValue = fileNameValue.Insert(fileNameValue.Length, DateTime.Now.Ticks.ToString()); fileNameValue = Path.GetTempPath() + @"\" + fileNameValue + ".jpg"; File.Copy(EIBXMLUtilities.folderName + @"\" + value, fileNameValue , true); Bitmap imgInFile = new Bitmap(fileNameValue); control.BackgroundImage = imgInFile; } if (propertyName == XMLServicesConstants.XmlNodeBackgroundImageLayoutAtt) { control.BackgroundImageLayout = getBackGroundImageLayout(value); //if (control is EIBPicture) //{ // EIBPicture picture = (EIBPicture)control; // Image imgInFile = Image.FromFile(EIBXMLUtilities.folderName + "/" + value); // picture.Image = imgInFile; //} //if (control is EIBButton) //{ // EIBButton button = (EIBButton)control; // Image imgInFile = Image.FromFile(EIBXMLUtilities.folderName + "/" + value); // button.Image = imgInFile; //} } if (propertyName == XMLServicesConstants.XmlNodeMultiLineAtt) { if (control is EIBTextBox) { EIBTextBox textBox = (EIBTextBox)control; textBox.Multiline = (value == true.ToString().ToLower()); } } if (propertyName == XMLServicesConstants.XmlNodeSizeTypeAtt) { if (control is EIBRow) { EIBRow row = (EIBRow)control; if (value.Trim().Equals("Pixel")) { row.HeightTyp = EIBRow.HeightMeasurement.Pixel; row.HeightPixel = row.Height; } if (value.Trim().Equals("Percent")) { row.HeightTyp = EIBRow.HeightMeasurement.Percent; } if (value.Trim().Equals("Auto")) { row.HeightTyp = EIBRow.HeightMeasurement.Auto; } } if (control is EIBColumn) { EIBColumn column = (EIBColumn)control; if (value.Trim().Equals("Pixel")) { column.WidthType = WidthMeasurement.Pixel; column.WidthPixel = column.Width; } if (value.Trim().Equals("Percent")) { column.WidthType = WidthMeasurement.Percent; } if (value.Trim().Equals("Auto")) { column.WidthType = WidthMeasurement.Auto; } } } if (propertyName == XMLServicesConstants.XmlNodeDefaultAtt) { if (control is EIBPanel) { EIBPanel panel = (EIBPanel)control; panel.DefaultScreen = (value.Equals(true.ToString().ToLower())); } //if (control is EIBPlaceHolder) //{ // EIBPlaceHolder placeholder = (EIBPlaceHolder)control; // placeholder.DefaultScreen = (value.Equals(true.ToString().ToLower())); //} } //if (propertyName == XMLServicesConstants.XmlNodeBackgroundImageAtt) //{ // if (control is EIBPanel) // { // EIBPanel panel = (EIBPanel)control; // Image imgInFile = Image.FromFile(EIBXMLUtilities.folderName + "/" + value); // panel.BackgroundImage = imgInFile; // } //} if (propertyName == XMLServicesConstants.XmlNodeItemreferenceAtt) { if (control is EIBItem) { control.Text = value; } } if (propertyName == XMLServicesConstants.XmlNodeTextAlignAtt) { EIBLabel label = (EIBLabel)control; if (control is EIBLabel) label.TextAlign = TextAlignment(value); } if (propertyName == XMLServicesConstants.XmlNodeBorderAtt) { if (control is EIBPanel) { EIBPanel panel = (EIBPanel)control; panel.BorderStyle = BorderStyleValue(value); //if (value == System.Windows.Forms.BorderStyle.FixedSingle.ToString().ToLower()) //{ // panel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; //} //if (value == System.Windows.Forms.BorderStyle.None.ToString().ToLower()) //{ // panel.BorderStyle = System.Windows.Forms.BorderStyle.None; //} //if (value == System.Windows.Forms.BorderStyle.Fixed3D.ToString().ToLower()) //{ // panel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; //} } if (control is EIBPlaceHolder) { EIBPlaceHolder placeholder = (EIBPlaceHolder)control; placeholder.BorderStyle = BorderStyleValue(value); } if (control is EIBLabel) { EIBLabel label = (EIBLabel)control; if(propertyName == XMLServicesConstants.XmlNodeBorderAtt) label.BorderStyle = BorderStyleValue(value); } if (control is EIBRadioGroup) { EIBRadioGroup radiogroup = (EIBRadioGroup)control; radiogroup.BorderStyle = BorderStyleValue(value); } if (control is EIBGrid) { EIBGrid gridcontrol = (EIBGrid)control; gridcontrol.BorderStyle = BorderStyleValue(value); } if (control is EIBLattice) { EIBLattice latticecontrol = (EIBLattice)control; latticecontrol.BorderStyle = BorderStyleValue(value); } if (control is EIBTextBox) { EIBTextBox textBoxControl = (EIBTextBox)control; textBoxControl.BorderStyle = BorderStyleValue(value); } if (control is EIBRow) { EIBRow row = (EIBRow)control; row.BorderStyle = BorderStyleValue(value); } } if (propertyName == XMLServicesConstants.XmlNodeFlatStyleAtt) { ((EIBButton)control).FlatStyle = getFlatStyle(value); } if (propertyName == XMLServicesConstants.XmlNodeBorderSizeAtt) { ((EIBButton)control).FlatAppearance.BorderSize = int.Parse(value); } if (propertyName == XMLServicesConstants.XmlNodeOrientAtt) { ((EIBVMenuBar)control).Orient = (value == Controls.Common.MenuOrient.horizontal.ToString().ToLower()) ? Controls.Common.MenuOrient.horizontal : Controls.Common.MenuOrient.vertical; } if (propertyName == XMLServicesConstants.XmlNodeUseAtt) { ((IEIBControl)control).Use = value; } if (propertyName == XMLServicesConstants.XmlNodeTitleAtt) { if ((control is EIBPanel) && control.Parent is BaseWindow) { ((EIBPanel)control).Title = value; } } if (propertyName == XMLServicesConstants.XmlNodePopupAtt) { if ((control is EIBPanel) && control.Parent is BaseWindow) { ((EIBPanel)control).Popup = (value == "true") ? true : false; } } if (propertyName == XMLServicesConstants.XmlNodeSearchFieldAtt) { if (control is EIBTextBox) { ((EIBTextBox)control).SearchField = (value == "true") ? true : false; } } if (propertyName == XMLServicesConstants.XmlNodeVisibleToAtt) { string[] visibleToValues = value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); List<string> visibleToList = new List<string>(visibleToValues); ((IEIBControl)control).VisibleTo = visibleToList; } if (propertyName == XMLServicesConstants.XmlNodeAutoSizeAtt) { if (control is EIBVMenuBar) { ((EIBVMenuBar)control).AutoSize = value.Equals(true.ToString().ToLower()); } } }
//Refresh the ListView private void refreshListView(int listIndex, int slotNumber) { //Temporary FontFamily FontFamily tempFontFamily = null; //Place cardName on the tab mainTabControl.TabPages[listIndex].Text = PScard[listIndex].cardName; //Remove all icons from the list iconList[listIndex].Images.Clear(); //Remove all items from the list cardList[listIndex].Items.Clear(); //Add linked slot icons to iconList iconList[listIndex].Images.Add(Properties.Resources.linked); iconList[listIndex].Images.Add(Properties.Resources.linked_disabled); //Add 15 List items along with icons for (int i = 0; i < 15; i++) { //Add save icons to the list iconList[listIndex].Images.Add(prepareIcons(listIndex,i)); switch (PScard[listIndex].saveType[i]) { default: //Corrupted cardList[listIndex].Items.Add("Corrupted slot"); break; case 0: //Formatted save cardList[listIndex].Items.Add("Free slot"); break; case 1: //Initial save case 4: //Deleted initial save cardList[listIndex].Items.Add(PScard[listIndex].saveName[i, mainSettings.titleEncoding]); cardList[listIndex].Items[i].SubItems.Add(PScard[listIndex].saveProdCode[i]); cardList[listIndex].Items[i].SubItems.Add(PScard[listIndex].saveIdentifier[i]); cardList[listIndex].Items[i].ImageIndex = i + 2; //Skip two linked slot icons break; case 2: //Middle link cardList[listIndex].Items.Add("Linked slot (middle link)"); cardList[listIndex].Items[i].ImageIndex = 0; break; case 5: //Middle link deleted cardList[listIndex].Items.Add("Linked slot (middle link)"); cardList[listIndex].Items[i].ImageIndex = 1; break; case 3: //End link cardList[listIndex].Items.Add("Linked slot (end link)"); cardList[listIndex].Items[i].ImageIndex = 0; break; case 6: //End link deleted cardList[listIndex].Items.Add("Linked slot (end link)"); cardList[listIndex].Items[i].ImageIndex = 1; break; } } //Select the active item in the list cardList[listIndex].Items[slotNumber].Selected = true; //Set font for the list if (mainSettings.listFont != null) { //Create FontFamily from font name tempFontFamily = new FontFamily(mainSettings.listFont); //Check if regular style is supported if (tempFontFamily.IsStyleAvailable(FontStyle.Regular)) { //Use custom font cardList[listIndex].Font = new Font(mainSettings.listFont, 8.25f); } else { //Use default font mainSettings.listFont = FontFamily.GenericSansSerif.Name; cardList[listIndex].Font = new Font(mainSettings.listFont, 8.25f); } } //Set showListGrid option if (mainSettings.showListGrid == 0) cardList[listIndex].GridLines = false; else cardList[listIndex].GridLines = true; refreshPluginBindings(); //Enable certain list items enableSelectiveEditItems(); }
private bool IsFontFamilyFixedPitch (FontFamily family) { FontStyle fs; if (family.IsStyleAvailable (FontStyle.Regular)) fs = FontStyle.Regular; else if (family.IsStyleAvailable (FontStyle.Bold)) fs = FontStyle.Bold; else if (family.IsStyleAvailable (FontStyle.Italic)) fs = FontStyle.Italic; else if (family.IsStyleAvailable (FontStyle.Strikeout)) fs = FontStyle.Strikeout; else if (family.IsStyleAvailable (FontStyle.Underline)) fs = FontStyle.Underline; else return false; Font f = new Font (family.Name, 10, fs); if (TextRenderer.MeasureString ("i", f).Width == TextRenderer.MeasureString ("w", f).Width) return true; return false; }
public static void DrawFontItem(Graphics g, FontFamilyInfo fontFamily, Rectangle rect, bool isSelected) { using (StringFormat sf = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, }) { sf.FormatFlags |= StringFormatFlags.NoWrap; using (FontFamily ff = new FontFamily(fontFamily.CultureName)) { Font font = null; // some fonts are not support Regular style, we need find // a style which is supported by current font if (ff.IsStyleAvailable(FontStyle.Regular)) font = new Font(fontFamily.CultureName, FixedDrawFontSize, FontStyle.Regular); else if (ff.IsStyleAvailable(FontStyle.Bold)) font = new Font(fontFamily.CultureName, FixedDrawFontSize, FontStyle.Bold); else if (ff.IsStyleAvailable(FontStyle.Italic)) font = new Font(fontFamily.CultureName, FixedDrawFontSize, FontStyle.Italic); else if (ff.IsStyleAvailable(FontStyle.Strikeout)) font = new Font(fontFamily.CultureName, FixedDrawFontSize, FontStyle.Strikeout); else if (ff.IsStyleAvailable(FontStyle.Underline)) font = new Font(fontFamily.CultureName, FixedDrawFontSize, FontStyle.Underline); if (font != null) { g.DrawString(font.Name, font, isSelected ? SystemBrushes.HighlightText : Brushes.Black, rect, sf); font.Dispose(); } } } }
public static GraphicsPath GetTextPath(BlockDefinition section, string text, Graphics graphics) { GraphicsPath myPath = new GraphicsPath(); FontFamily family = new FontFamily("Arial"); FontStyle fontStyle = FontStyle.Regular; if (section.text.font != null && File.Exists(Path.Combine(section.Manager.RootPath, section.text.font))) { PrivateFontCollection col = new PrivateFontCollection(); col.AddFontFile(Path.Combine(section.Manager.RootPath, section.text.font)); family = col.Families[0]; bool fontStyleFound = false; foreach (var fontstyleEnum in Enum.GetValues(typeof(FontStyle))) { if (family.IsStyleAvailable(((FontStyle)fontstyleEnum))) { fontStyle = (FontStyle)fontstyleEnum; fontStyleFound = true; break; } foreach (var secondStyle in Enum.GetValues(typeof(FontStyle))) { var combinedStyle = ((FontStyle)fontstyleEnum) | ((FontStyle)secondStyle); if (family.IsStyleAvailable(combinedStyle)) { fontStyle = combinedStyle; fontStyleFound = true; break; } } } if (!fontStyleFound) { family = new FontFamily("Arial"); } } int size = section.text.size; int minsize = 6; Point location = section.location.ToPoint(); StringFormat format = StringFormat.GenericDefault; if (section.wordwrap.height > 0) { format = new StringFormat(); format.Alignment = GetAlignment(section.wordwrap.align); format.LineAlignment = GetAlignment(section.wordwrap.valign); Size block = section.wordwrap.ToSize(); Rectangle rect = new Rectangle(location, block); if (section.wordwrap.shrinkToFit) { GraphicsUnit original = graphics.PageUnit; graphics.PageUnit = GraphicsUnit.Point; // Convert the PageUnit to Point just long enough to get an accurate measurement. Font tempfont = new Font(family, size, fontStyle); // Create the font for the measurement. SizeF unwrappedSize = graphics.MeasureString(text, tempfont); if (unwrappedSize.Height > section.wordwrap.height) { if (unwrappedSize.Width > section.wordwrap.width) { int sizePerIncrement = (int)Math.Round((double)(unwrappedSize.Width / size), MidpointRounding.ToEven); size = (int)Math.Round((double)(rect.Width / sizePerIncrement), MidpointRounding.ToEven); size = (size < minsize) ? minsize : size; tempfont = new Font(family, size, fontStyle); } } else { float measuredHeight = graphics.MeasureString(text, tempfont, rect.Width, format).Height; if (rect.Height < measuredHeight) { int sizePerIncrement = (int)Math.Round((double)(measuredHeight / unwrappedSize.Height), MidpointRounding.ToEven); //unwrappedSize.Height seems to be a better method of getting sizePerIncrement. size = (int)Math.Round((double)(rect.Height / sizePerIncrement), MidpointRounding.ToEven); size = (size < minsize) ? minsize : size; tempfont = new Font(family, size, fontStyle); } } while (size > minsize && rect.Height < graphics.MeasureString(text, tempfont, rect.Width, format).Height) // Compare the height of the rendered text to the bounding box. If it's larger { size -= 1; // Reduce the size, test again. tempfont = new Font(family, size, fontStyle); // REcreate the font in the new size } // end addition graphics.PageUnit = original; // Change the PageUnit back to display. } myPath.AddString(text, family, (int)fontStyle, size, rect, format); } else { myPath.AddString(text, family, (int)fontStyle, size, location, format); } return myPath; }
public static Font GetFont(String familyName, float size, FontStyle style) { Font result = null; FontFamily family = null; try { family = new FontFamily(familyName); if (family.IsStyleAvailable(style)) result = new Font(familyName, size, style); else { // On some systems even the regular style throws an exception (which actually should not happen // as Windows should automatically pick an alternative font if the one requested does not exist, but // there are cases...). result = new Font(familyName, size, FontStyle.Regular); } } catch { result = new Font(FontFamily.GenericSansSerif, size, style); } if (family != null) family.Dispose(); return result; }
internal static Font GetUsableNormalFont(string FontName, double FontSize, FontStyle DrawStyle) { Font usablefont = new Font(FontFamily.GenericSansSerif, (float)FontSize); // there's this elaborate dance of try-catch-if-else because apparently certain typefaces // don't have a "normal" version but say the bold version works just fine. // For example, the typeface Aharoni will choke with FontStyle.Regular but FontStyle.Bold is fine. try { usablefont = new Font(FontName, (float)FontSize, DrawStyle); } catch { FontFamily ff = new FontFamily(FontName); FontStyle fsLastDitch = FontStyle.Regular; if ((DrawStyle & FontStyle.Bold) > 0) { if (ff.IsStyleAvailable(FontStyle.Bold)) fsLastDitch |= FontStyle.Bold; } if ((DrawStyle & FontStyle.Italic) > 0) { if (ff.IsStyleAvailable(FontStyle.Italic)) fsLastDitch |= FontStyle.Italic; } if ((DrawStyle & FontStyle.Strikeout) > 0) { if (ff.IsStyleAvailable(FontStyle.Strikeout)) fsLastDitch |= FontStyle.Strikeout; } if ((DrawStyle & FontStyle.Underline) > 0) { if (ff.IsStyleAvailable(FontStyle.Underline)) fsLastDitch |= FontStyle.Underline; } // do I need to check for combinations? Say bold and italic combo exists, but // just bold or just italic doesn't. What kind of typeface does this?!?! // If I didn't know better, I'd point my finger at Verdana, but that's because // I've a verdant vendetta against it... if (ff.IsStyleAvailable(fsLastDitch)) { usablefont = new Font(FontName, (float)FontSize, fsLastDitch); // else I-don't-care-anymore } else if (ff.IsStyleAvailable(FontStyle.Regular)) { usablefont = new Font(FontName, (float)FontSize, FontStyle.Regular); } else if (ff.IsStyleAvailable(FontStyle.Bold)) { usablefont = new Font(FontName, (float)FontSize, FontStyle.Bold); } else if (ff.IsStyleAvailable(FontStyle.Italic)) { usablefont = new Font(FontName, (float)FontSize, FontStyle.Italic); } else if (ff.IsStyleAvailable(FontStyle.Bold | FontStyle.Italic)) { usablefont = new Font(FontName, (float)FontSize, FontStyle.Bold | FontStyle.Italic); } else { // the font name or typeface might not be installed (say on a web server), // so we'll use a generic sans serif font as a fallback. What if this fails? // I don't know... *can* it fail? usablefont = new Font(FontFamily.GenericSansSerif, (float)FontSize); } } return usablefont; }
private Font CreateDefaultFont(FontFamily fontFamily, float size) { Font font = null; if (fontFamily.IsStyleAvailable(FontStyle.Regular)) font = new Font(fontFamily, size, FontStyle.Regular); else if (fontFamily.IsStyleAvailable(FontStyle.Bold)) font = new Font(fontFamily, size, FontStyle.Bold); else if (fontFamily.IsStyleAvailable(FontStyle.Italic)) font = new Font(fontFamily, size, FontStyle.Italic); return font; }
private void cbDrawItem(object sender, DrawItemEventArgs e) { Font font1; Rectangle rectangle1 = e.Bounds; int num1 = rectangle1.X; rectangle1 = e.Bounds; int num2 = rectangle1.Y; if (e.Index < 0) { e.DrawBackground(); e.DrawFocusRectangle(); return; } e.DrawBackground(); e.DrawFocusRectangle(); Brush colorbrush = SystemBrushes.ControlText; if ((e.State & System.Windows.Forms.DrawItemState.Selected) == System.Windows.Forms.DrawItemState.Selected) colorbrush = SystemBrushes.HighlightText; if (this.m_ShowName) { e.Graphics.DrawString(this.cb.Items[e.Index].ToString(), base.Font, colorbrush, ((float)num1), ((float)num2)); num1 += 160; } if (!this.m_ShowSample) { return; } FontFamily family1 = new FontFamily(this.cb.Items[e.Index].ToString()); if (family1.IsStyleAvailable(FontStyle.Regular)) { font1 = new Font(this.cb.Items[e.Index].ToString(), 10f, FontStyle.Regular); } else { if (family1.IsStyleAvailable(FontStyle.Bold)) { font1 = new Font(this.cb.Items[e.Index].ToString(), 10f, FontStyle.Bold); } else if (family1.IsStyleAvailable(FontStyle.Italic)) { font1 = new Font(this.cb.Items[e.Index].ToString(), 10f, FontStyle.Italic); } else font1 = new Font(this.cb.Items[e.Index].ToString(), 10f, (FontStyle.Italic | FontStyle.Bold)); } e.Graphics.DrawString(this.cb.Items[e.Index].ToString(), font1, colorbrush, ((float)num1), ((float)num2)); font1.Dispose(); }
private void ConfigureFontStyleControl(FontFamily zFamily, FontStyle eStyle, CheckBox checkBox) { checkBox.Enabled = zFamily.IsStyleAvailable(eStyle); if (!checkBox.Enabled) { checkBox.Checked = false; } }
/// <exception cref="ArgumentException">Invalid font style</exception> private static SD.Bitmap CreateFontBitmap(SD.FontFamily fontFamily, SD.FontStyle fontStyle, int fontSize, int resolution, ref int leading, IEnumerable <Range> codePoints, IDictionary <char, RectangleF> glyphs) { if (!fontFamily.IsStyleAvailable(fontStyle)) { throw new ArgumentException("Invalid font style", "fontStyle"); } using (var font = new SD.Font(fontFamily, fontSize, fontStyle, SD.GraphicsUnit.Point)) { if (leading == 0) { leading = (int)Math.Ceiling(font.GetHeight()); } using (var sf = new StringFormat(StringFormat.GenericTypographic)) { sf.FormatFlags ^= StringFormatFlags.NoClip; IEnumerable <int> codePointList = GetCodePointList(codePoints); float x = 0, y = 0; // get texture dimensions var texSize = GetTexSize(codePointList, resolution, font, sf, leading); // draw font texture var fontBitmap = new SD.Bitmap(texSize.Width, texSize.Height); fontBitmap.SetResolution(resolution, resolution); float italicPadding = 0f; //pkubat added if (font.Italic) { italicPadding = fontSize / 7f; } using (var g = SD.Graphics.FromImage(fontBitmap)) { using (var brush = new SD.SolidBrush(SD.Color.White)) { g.Clear(SD.Color.Transparent); //g.InterpolationMode = InterpolationMode.Low; //g.CompositingQuality = CompositingQuality.HighSpeed; //g.SmoothingMode = SmoothingMode.HighSpeed; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.TextRenderingHint = TextRenderingHint.AntiAlias; g.PageUnit = SD.GraphicsUnit.Pixel; foreach (int i in codePointList) { string c = char.ConvertFromUtf32(i); var size = g.MeasureString(c, font, texSize.Width, sf); size.Width += italicPadding; if (x + size.Width >= texSize.Width) { x = 0; y += leading + 2; } g.DrawString(c, font, brush, new SD.RectangleF(x, y, size.Width, leading), sf); // fill glyphdict glyphs[(char)i] = new RectangleF( x / texSize.Width, y / texSize.Height, size.Width / texSize.Width, (float)leading / texSize.Height); x += size.Width + 2; } // get space width var spaceSize = g.MeasureString(" ", font); glyphs[' '] = new RectangleF(0, 0, spaceSize.Width / texSize.Width, (float)leading / texSize.Height); } return(fontBitmap); } } } }
internal System.Drawing.Font get_drawing_font() { if (internal_font == null || check_font_dirty()) { System.Drawing.FontFamily ff; try { ff = new System.Drawing.FontFamily(name, private_fonts); } catch (Exception e) { ff = new System.Drawing.FontFamily(name); } System.Drawing.FontStyle style = System.Drawing.FontStyle.Regular; if (bold && ff.IsStyleAvailable(System.Drawing.FontStyle.Bold)) style = System.Drawing.FontStyle.Bold; if (italic && ff.IsStyleAvailable(System.Drawing.FontStyle.Italic)) style = System.Drawing.FontStyle.Italic; if (bold && italic && ff.IsStyleAvailable(System.Drawing.FontStyle.Bold) && ff.IsStyleAvailable(System.Drawing.FontStyle.Italic)) style = System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic; if (internal_font != null) internal_font.Dispose(); internal_font = new System.Drawing.Font(ff, size - 10, style, System.Drawing.GraphicsUnit.Pixel); } return internal_font; }
private static void SetMenuValue(ToolStripItem control, XmlNode xmlNode) { int attributeCount = xmlNode.Attributes.Count; if (attributeCount > 0) { for (int counter = 0; counter < attributeCount; counter++) { if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeTextAtt) { control.Text = xmlNode.Attributes[counter].Value; } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeMenuIconAtt) { string fileNameValue = Path.GetFileNameWithoutExtension(xmlNode.Attributes[counter].Value); fileNameValue = fileNameValue.Insert(fileNameValue.Length, DateTime.Now.Ticks.ToString()); fileNameValue = Path.GetTempPath() + @"\" + fileNameValue + ".jpg"; File.Copy(EIBXMLUtilities.folderName + @"\" + xmlNode.Attributes[counter].Value, fileNameValue, true); Bitmap imgInFile = new Bitmap(fileNameValue); if(control is EIBMenu) ((EIBMenu)control).MenuIcon = imgInFile; if (control is EIBMenuItem) ((EIBMenuItem)control).MenuIcon = imgInFile; } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeWidthAtt) { control.Width = Int32.Parse(xmlNode.Attributes[counter].Value); } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeHeightAtt) { control.Height = Int32.Parse(xmlNode.Attributes[counter].Value); } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeIdAtt) { control.Name = xmlNode.Attributes[counter].Value; } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeNetBackColorAtt) { control.BackColor = Color.FromName(xmlNode.Attributes[counter].Value); } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeNameAtt) { control.Name = xmlNode.Attributes[counter].Value; } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeFontSizeAtt) { control.Font = new Font(control.Font.FontFamily, float.Parse(xmlNode.Attributes[counter].Value), control.Font.Style); } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeFontStyleAtt) { FontStyle fs = GetFontStyle(xmlNode.Attributes[counter].Value); control.Font = new Font(control.Font, fs); } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeFontAtt) { FontFamily f = new FontFamily(xmlNode.Attributes[counter].Value); if (f.IsStyleAvailable(control.Font.Style)) { control.Font = new Font(xmlNode.Attributes[counter].Value, control.Font.Size, control.Font.Style); } else { MessageBox.Show("Font style not supported for " + (xmlNode.Attributes[counter].Value.ToString().Trim()) + " for control " + (control.Text.ToString())); } } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeNetBackColorAtt) { if (!xmlNode.Attributes[counter].Value.Contains("#")) { control.BackColor = Color.FromName(xmlNode.Attributes[counter].Value); } else { control.BackColor = ColorTranslator.FromHtml(xmlNode.Attributes[counter].Value); } } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeNetForeColorAtt) { if (!xmlNode.Attributes[counter].Value.Contains("#")) { control.ForeColor = Color.FromName(xmlNode.Attributes[counter].Value); } else { control.ForeColor = ColorTranslator.FromHtml(xmlNode.Attributes[counter].Value); } } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeTextAlignAtt) { control.TextAlign = getTextAlign(xmlNode.Attributes[counter].Value); } if (xmlNode.Attributes[counter].Name == XMLServicesConstants.XmlNodeVisibleToAtt) { string[] visibleToValues = xmlNode.Attributes[counter].Value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); List<string> visibleToList = new List<string>(visibleToValues); ((IEIBControl)control).VisibleTo = visibleToList; } } } }
/// <summary> /// Finds out which font styles are available for the given Gdi font family. /// </summary> /// <param name="fontFamily">The Gdi font family.</param> /// <returns>Value that indicate which styles are available for the fontFamily.</returns> protected static FontStylePresence GetFontStylePresence(FontFamily fontFamily) { FontStylePresence pres = FontStylePresence.NoStyleAvailable; if (fontFamily.IsStyleAvailable(FontStyle.Regular)) pres |= FontStylePresence.RegularStyleAvailable; if (fontFamily.IsStyleAvailable(FontStyle.Bold)) pres |= FontStylePresence.BoldStyleAvailable; if (fontFamily.IsStyleAvailable(FontStyle.Italic)) pres |= FontStylePresence.ItalicStyleAvailable; if (fontFamily.IsStyleAvailable(FontStyle.Bold | FontStyle.Italic)) pres |= FontStylePresence.BoldAndItalicStyleAvailable; return pres; }
/// <summary> /// Generate the Font-Formal so we can draw correctly /// </summary> protected void UpdateFormat() { string fontFamily = GetFieldValueAsString(FieldType.FONT_FAMILY); bool fontBold = GetFieldValueAsBool(FieldType.FONT_BOLD); bool fontItalic = GetFieldValueAsBool(FieldType.FONT_ITALIC); float fontSize = GetFieldValueAsFloat(FieldType.FONT_SIZE); try { FontStyle fs = FontStyle.Regular; bool hasStyle = false; using (FontFamily fam = new FontFamily(fontFamily)) { bool boldAvailable = fam.IsStyleAvailable(FontStyle.Bold); if (fontBold && boldAvailable) { fs |= FontStyle.Bold; hasStyle = true; } bool italicAvailable = fam.IsStyleAvailable(FontStyle.Italic); if (fontItalic && italicAvailable) { fs |= FontStyle.Italic; hasStyle = true; } if (!hasStyle) { bool regularAvailable = fam.IsStyleAvailable(FontStyle.Regular); if (regularAvailable) { fs = FontStyle.Regular; } else { if (boldAvailable) { fs = FontStyle.Bold; } else if (italicAvailable) { fs = FontStyle.Italic; } } } _font = new Font(fam, fontSize, fs, GraphicsUnit.Pixel); _textBox.Font = _font; } } catch (Exception ex) { ex.Data.Add("fontFamily", fontFamily); ex.Data.Add("fontBold", fontBold); ex.Data.Add("fontItalic", fontItalic); ex.Data.Add("fontSize", fontSize); throw; } _stringFormat.Alignment = (StringAlignment)GetFieldValue(FieldType.TEXT_HORIZONTAL_ALIGNMENT); _stringFormat.LineAlignment = (StringAlignment)GetFieldValue(FieldType.TEXT_VERTICAL_ALIGNMENT); }
public static Font GetFontIfExisted(string name, float size, FontStyle style) { Font f = null; try { FontFamily ff = new FontFamily(name); if (!ff.IsStyleAvailable(style)) style = FontStyle.Regular; f = new Font(ff, size, style); } catch (Exception ex) { Logger.Log("font toolkit", "info: " + ex.Message); f = SystemFonts.DefaultFont; } return f; }
private void DrawFontItem(DrawItemEventArgs e) { FontStyle[] styles = new FontStyle[4] { FontStyle.Regular, FontStyle.Bold, FontStyle.Italic, FontStyle.Bold | FontStyle.Italic }; if (!BarFunctions.IsOffice2007Style(m_Style)) e.DrawBackground(); string fontname = this.Items[e.Index].ToString(); FontFamily family = new FontFamily(fontname); int iWidth = this.DropDownWidth / 2 - 4; if (iWidth <= 0) iWidth = this.Width; foreach (FontStyle style in styles) { if (family.IsStyleAvailable(style)) { eTextFormat format = eTextFormat.Default | eTextFormat.NoPrefix; Color textColor = (e.State & DrawItemState.Selected) != 0 ? SystemColors.HighlightText : SystemColors.ControlText; Office2007ButtonItemStateColorTable ct = null; if (BarFunctions.IsOffice2007Style(m_Style)) { Office2007ButtonItemColorTable bct = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.ButtonItemColors[0]; if ((e.State & DrawItemState.Selected) != 0 || (e.State & DrawItemState.HotLight) != 0) ct = bct.MouseOver; else if ((e.State & DrawItemState.Disabled) != 0 || !this.Enabled) ct = bct.Disabled; else ct = bct.Default; //if (ct == null) if (!this.Enabled) textColor = _DisabledForeColor.IsEmpty ? SystemColors.ControlDark : _DisabledForeColor; else textColor = SystemColors.ControlText; if ((e.State & DrawItemState.Selected) != 0 || (e.State & DrawItemState.HotLight) != 0) Office2007ButtonItemPainter.PaintBackground(e.Graphics, ct, e.Bounds, RoundRectangleShapeDescriptor.RoundCorner2); else { e.DrawBackground(); } } if ((e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit) { Rectangle rt = e.Bounds; rt.Height = 0; // Prevents clipping based on height format |= eTextFormat.NoClipping | eTextFormat.NoPadding; TextDrawing.DrawString(e.Graphics, fontname, this.Font, textColor, rt, format); } else { Size szFont = TextDrawing.MeasureString(e.Graphics, fontname, this.Font); int iDiff = (int)((e.Bounds.Height - szFont.Height) / 2); Rectangle rFontName = new Rectangle(e.Bounds.X, e.Bounds.Y + iDiff, ((e.State & DrawItemState.Disabled) == DrawItemState.Disabled ? e.Bounds.Width : Math.Max(e.Bounds.Width - 100, 32)), e.Bounds.Height - iDiff); TextDrawing.DrawString(e.Graphics, fontname, this.Font, textColor, rFontName, format); Rectangle rRemainder = new Rectangle(e.Bounds.X + iWidth + 4, e.Bounds.Y, e.Bounds.Width + 100, e.Bounds.Height); //using(Font f = new Font(family, (float)e.Bounds.Height - 8, style)) using (Font f = new Font(family, this.Font.Size, style)) TextDrawing.DrawString(e.Graphics, fontname, f, textColor, rRemainder, format); } break; } } if (family != null) family.Dispose(); }
private void UpdateFont() { string fontFamily = GetFieldValueAsString(FieldType.FONT_FAMILY); bool fontBold = GetFieldValueAsBool(FieldType.FONT_BOLD); bool fontItalic = GetFieldValueAsBool(FieldType.FONT_ITALIC); float fontSize = GetFieldValueAsFloat(FieldType.FONT_SIZE); if (fontInvalidated && fontFamily != null && fontSize != 0) { FontStyle fs = FontStyle.Regular; bool hasStyle = false; using(FontFamily fam = new FontFamily(fontFamily)) { bool boldAvailable = fam.IsStyleAvailable(FontStyle.Bold); if (fontBold && boldAvailable) { fs |= FontStyle.Bold; hasStyle = true; } bool italicAvailable = fam.IsStyleAvailable(FontStyle.Italic); if (fontItalic && italicAvailable) { fs |= FontStyle.Italic; hasStyle = true; } if (!hasStyle) { bool regularAvailable = fam.IsStyleAvailable(FontStyle.Regular); if (regularAvailable) { fs = FontStyle.Regular; } else { if (boldAvailable) { fs = FontStyle.Bold; } else if(italicAvailable) { fs = FontStyle.Italic; } } } font = new Font(fam, fontSize, fs, GraphicsUnit.Pixel); } fontInvalidated = false; } }
/// <summary> /// Initializes the main UI components. /// </summary> /// <remarks> /// If the metrics of the various UI components have been saved, they are loaded. Otherwise, /// the default layout is applied. /// </remarks> protected void InitializeDocuments() { string strTab = null; if (ViewModel.EnvironmentInfo.Settings.DockPanelLayouts.ContainsKey("mainForm") && !String.IsNullOrEmpty(ViewModel.EnvironmentInfo.Settings.DockPanelLayouts["mainForm"])) { dockPanel1.LoadFromXmlString(ViewModel.EnvironmentInfo.Settings.DockPanelLayouts["mainForm"], LoadDockedContent); try { if (m_dblDefaultActivityManagerAutoHidePortion == 0) m_dblDefaultActivityManagerAutoHidePortion = dmcDownloadMonitor.AutoHidePortion; } catch { } if (!ViewModel.UsesPlugins) pmcPluginManager.Hide(); } else { if (ViewModel.UsesPlugins) pmcPluginManager.DockState = DockState.Unknown; mmgModManager.DockState = DockState.Unknown; dmcDownloadMonitor.DockState = DockState.Unknown; dmcDownloadMonitor.ShowHint = DockState.DockBottom; dmcDownloadMonitor.Show(dockPanel1, DockState.DockBottom); if (m_dblDefaultActivityManagerAutoHidePortion == 0) m_dblDefaultActivityManagerAutoHidePortion = dmcDownloadMonitor.Height; try { dmcDownloadMonitor.AutoHidePortion = m_dblDefaultActivityManagerAutoHidePortion; } catch { } amcActivateModsMonitor.DockState = DockState.Unknown; amcActivateModsMonitor.ShowHint = DockState.DockBottom; amcActivateModsMonitor.Show(dockPanel1, DockState.DockBottom); if (m_dblDefaultActivationMonitorAutoHidePortion == 0) m_dblDefaultActivationMonitorAutoHidePortion = amcActivateModsMonitor.Height; try { amcActivateModsMonitor.AutoHidePortion = m_dblDefaultActivationMonitorAutoHidePortion; } catch { } if (ViewModel.UsesPlugins) pmcPluginManager.Show(dockPanel1); mmgModManager.Show(dockPanel1); } strTab = dockPanel1.ActiveDocument.DockHandler.TabText; if (ViewModel.PluginManagerVM != null) pmcPluginManager.Show(dockPanel1); if ((ViewModel.UsesPlugins) && (strTab == "Plugins")) pmcPluginManager.Show(dockPanel1); else mmgModManager.Show(dockPanel1); if ((dmcDownloadMonitor == null) || ((dmcDownloadMonitor.VisibleState == DockState.Unknown) || (dmcDownloadMonitor.VisibleState == DockState.Hidden))) { dmcDownloadMonitor.Show(dockPanel1, DockState.DockBottom); if (m_dblDefaultActivityManagerAutoHidePortion == 0) m_dblDefaultActivityManagerAutoHidePortion = dmcDownloadMonitor.Height; try { dmcDownloadMonitor.AutoHidePortion = m_dblDefaultActivityManagerAutoHidePortion; } catch { } } if ((amcActivateModsMonitor == null) || ((amcActivateModsMonitor.VisibleState == DockState.Unknown) || (amcActivateModsMonitor.VisibleState == DockState.Hidden))) { amcActivateModsMonitor.Show(dockPanel1, DockState.DockBottom); if (m_dblDefaultActivationMonitorAutoHidePortion == 0) m_dblDefaultActivationMonitorAutoHidePortion = amcActivateModsMonitor.Height; try { amcActivateModsMonitor.AutoHidePortion = m_dblDefaultActivationMonitorAutoHidePortion; } catch { } } amcActivateModsMonitor.DockTo(dmcDownloadMonitor.Pane, DockStyle.Right, 1); if (ViewModel.UsesPlugins) { tlbPluginsCounter.Text = " Total plugins: " + ViewModel.PluginManagerVM.ManagedPlugins.Count + " | Active plugins: "; FontFamily myFontFamily = new FontFamily(tlbActivePluginsCounter.Font.Name); if (ViewModel.PluginManagerVM.ActivePlugins.Count > ViewModel.PluginManagerVM.MaxAllowedActivePluginsCount) { Icon icoIcon = new Icon(SystemIcons.Warning, 16, 16); tlbActivePluginsCounter.Image = icoIcon.ToBitmap(); tlbActivePluginsCounter.ForeColor = Color.Red; if (myFontFamily.IsStyleAvailable(FontStyle.Bold)) tlbActivePluginsCounter.Font = new Font(tlbActivePluginsCounter.Font, FontStyle.Bold); else if (myFontFamily.IsStyleAvailable(FontStyle.Regular)) tlbActivePluginsCounter.Font = new Font(tlbActivePluginsCounter.Font, FontStyle.Regular); tlbActivePluginsCounter.Text = ViewModel.PluginManagerVM.ActivePlugins.Count.ToString(); tlbActivePluginsCounter.ToolTipText = String.Format("Too many active plugins! {0} won't start!", ViewModel.CurrentGameModeName); } else { tlbActivePluginsCounter.Image = null; tlbActivePluginsCounter.ForeColor = Color.Black; if (myFontFamily.IsStyleAvailable(FontStyle.Regular)) tlbActivePluginsCounter.Font = new Font(tlbActivePluginsCounter.Font, FontStyle.Regular); else if (myFontFamily.IsStyleAvailable(FontStyle.Bold)) tlbActivePluginsCounter.Font = new Font(tlbActivePluginsCounter.Font, FontStyle.Bold); tlbActivePluginsCounter.Text = ViewModel.PluginManagerVM.ActivePlugins.Count.ToString(); } } else { tlbPluginSeparator.Visible = false; tlbPluginsCounter.Visible = false; } tlbModsCounter.Text = " Total mods: " + ViewModel.ModManagerVM.ManagedMods.Count + " | Active mods: " + ViewModel.ModManager.ActiveMods.Count; UserStatusFeedback(); }