private void SetFontFamily(FontFamily family) { if (family != null) { FontFamilyInfo fontfamilyInfo = FontManager.GetRegisteredFontFamilyInfo(family); if (this.fontFamilyListBox.Items.Contains(fontfamilyInfo)) { this.fontFamilyListBox.SelectedItem = fontfamilyInfo; this.Dispatcher.BeginInvoke(new Action(() => this.fontFamilyListBox.ScrollIntoView(this.fontFamilyListBox.SelectedItem))); } else { this.fontFamilyListBox.SelectedItem = null; if (fontfamilyInfo != null) { this.fontFamilyTextBox.Text = fontfamilyInfo.DisplayName; } } } else { this.fontFamilyListBox.SelectedItem = family; } }
protected override void OnTextChanged(EventArgs e) { if (!string.IsNullOrEmpty(Text)) { if (!textUpdating) { textUpdating = true; bool found = false; for (int i = 0; i < ComboBox.Items.Count; i++) { FontFamilyInfo item = (FontFamilyInfo)ComboBox.Items[i]; if (item.IsFamilyName(Text)) { ComboBox.SelectedIndex = i; //SelectionStart = 0; SelectionLength = Text.Length; found = true; break; } } if (!found) { ComboBox.SelectedIndex = -1; this.Text = string.Empty; } textUpdating = false; } } }
private void cbFontName_DrawItem(object sender, DrawItemEventArgs e) { // отображение заднего фона элемента e.DrawBackground(); // отображение значка и текста элемента FontFamilyInfo fontFamilyInfo = (FontFamilyInfo)cbFontName.Items[e.Index]; Font font = new Font(fontFamilyInfo.FontFamily, 14, FontStyle.Regular, GraphicsUnit.Pixel); e.Graphics.DrawString(fontFamilyInfo.ToString(), font, textBrush, e.Bounds.X + 2, e.Bounds.Y + 2); // отображение фокуса элемента e.DrawFocusRectangle(); }
public FontSettingsControl() { InitializeComponent(); ShowColorPicker = true; sizeList.Items.AddRange(FontUIToolkit.FontSizeList.Select(f => (object)f).ToArray()); //---------------------------------------------- fontList.SelectedIndexChanged += (s, e) => { if (!updateUI) { updateUI = true; FontFamilyInfo fontFamily = (FontFamilyInfo)fontList.SelectedItem; selectedFont.FontFamilyInfo = fontFamily; UpdateFontStyle(); txtFont.Text = fontFamily.CultureName; labSample.Invalidate(); updateUI = false; RaiseFontNameChanged(); } }; styleList.SelectedIndexChanged += (s, e) => { if (!updateUI) { string style = styleList.SelectedItem as string; if (!string.IsNullOrEmpty(style)) { updateUI = true; selectedFont.Style = FontUIToolkit.GetFontStyleByName(style, "italic", "bold"); if (chkUnderline.Checked) { selectedFont.Style |= FontStyle.Underline; } if (chkStrikeout.Checked) { selectedFont.Style |= FontStyle.Strikeout; } labSample.Invalidate(); updateUI = false; RaiseFontStyleChanged(); } } }; sizeList.SelectedIndexChanged += (s, e) => { if (!updateUI) { updateUI = true; float size = sizeList.SelectedIndex == -1 ? 0 : ((float)sizeList.SelectedItem); txtSize.Text = size == 0 ? string.Empty : size.ToString(); selectedFont.Size = size; labSample.Invalidate(); updateUI = false; RaiseFontSizeChanged(); } }; //---------------------------------------------- txtFont.TextChanged += (s, e) => { string fontName = txtFont.Text; if (!string.IsNullOrEmpty(fontName)) { SetFontNameByString(fontName); } }; txtFont.KeyDown += (s, e) => { switch (e.KeyCode) { case Keys.Up: if (fontList.SelectedIndex > 0) { fontList.SelectedIndex--; } e.Handled = true; break; case Keys.Down: if (fontList.SelectedIndex < fontList.Items.Count - 1) { fontList.SelectedIndex++; } e.Handled = true; break; } }; txtStyle.TextChanged += (s, e) => { if (!updateUI) { updateUI = true; string styleString = txtStyle.Text.Trim(); if (styleString.Length > 0) { foreach (string style in styleList.Items) { if (style.StartsWith(styleString, StringComparison.InvariantCultureIgnoreCase)) { styleList.SelectedItem = style; RaiseFontStyleChanged(); break; } } } updateUI = false; } }; txtStyle.KeyDown += (s, e) => { switch (e.KeyCode) { case Keys.Up: if (styleList.SelectedIndex > 0) { styleList.SelectedIndex--; } e.Handled = true; break; case Keys.Down: if (styleList.SelectedIndex < styleList.Items.Count - 1) { styleList.SelectedIndex++; } e.Handled = true; break; } }; txtSize.TextChanged += (s, e) => { if (!updateUI && txtSize.Text.Trim().Length > 0) { string sizeStr = txtSize.Text; if (sizeStr.StartsWith(" ") || sizeStr.EndsWith(" ")) { sizeStr = sizeStr.Trim(); } float inputSize = SystemFonts.DefaultFont.Size; float.TryParse(txtSize.Text, out inputSize); for (int i = 0; i < sizeList.Items.Count; i++) { if ((float)sizeList.Items[i] == inputSize) { sizeList.SelectedIndex = i; RaiseFontSizeChanged(); break; } } selectedFont.Size = inputSize; labSample.Invalidate(); } }; txtSize.KeyDown += (s, e) => { switch (e.KeyCode) { case Keys.Up: if (sizeList.SelectedIndex > 0) { sizeList.SelectedIndex--; } e.Handled = true; break; case Keys.Down: if (sizeList.SelectedIndex < sizeList.Items.Count - 1) { sizeList.SelectedIndex++; } e.Handled = true; break; } }; labSample.Paint += (s, e) => { Graphics g = e.Graphics; g.Clear(Color.White); if (labSample.ForeColor.A < 255) { GraphicsToolkit.DrawTransparentBlock(g, labSample.ClientRectangle); } using (StringFormat sf = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, FormatFlags = StringFormatFlags.NoWrap, }) { using (Brush b = new SolidBrush(labSample.ForeColor)) { if (selectedFont != null && !string.IsNullOrEmpty(selectedFont.Name) && selectedFont.Size > 0) { try { using (Font font = new Font(SelectedFont.Name, SelectedFont.Size, SelectedFont.Style)) { g.DrawString(labSample.Text, font, b, labSample.ClientRectangle, sf); } } catch { } } } } }; chkUnderline.CheckedChanged += (s, e) => { if (chkUnderline.Checked) { selectedFont.Style |= FontStyle.Underline; } else { selectedFont.Style &= ~FontStyle.Underline; } labSample.Invalidate(); RaiseFontStyleChanged(); }; chkStrikeout.CheckedChanged += (s, e) => { if (chkStrikeout.Checked) { selectedFont.Style |= FontStyle.Strikeout; } else { selectedFont.Style &= ~FontStyle.Strikeout; } labSample.Invalidate(); RaiseFontStyleChanged(); }; fontColor.ColorSelected += (s, e) => { labSample.ForeColor = fontColor.SolidColor; if (SelectedFontColorChanged != null) { SelectedFontColorChanged(this, null); } }; }
private bool DrawBracketed(bool isFence, Node node, string sText, Color color) { int fHeight = 0; string fString = ""; if (isFence) { if (sText.Length == 1) { fString = ((ushort)sText[0]).ToString("X5"); } if (!this.IsParen(fString)) { node.type_.type = ElementType.Mo; try { BoxRect boxRect = this.MeasureTextRect(node, sText, node.scriptLevel_, node.style_); int x = node.box.X + this.RoundFontSize(this.operatorFontSize(node, node.style_)); int y = (node.box.Y + node.box.Baseline) - boxRect.baseline; this.DrawQuote(node, x, y, sText, node.scriptLevel_, node.style_, color); } catch { } } } else if (((node.firstChild != null) && (node.firstChild.type_.type == ElementType.Entity)) && (node.firstChild.glyph != null)) { fString = node.firstChild.glyph.Code; } if (!this.IsParen(fString)) { return(false); } if (isFence) { Node n = null; n = this.CreateChildGlyph(fString, node); if ((n != null) && (n.box != null)) { int normBase = this.MeasureBaseline(node, node.style_, "X"); if (this.IsAboveBaseline(node.box.Height, node.box.Baseline, normBase)) { n.box.X = node.box.X; n.box.Y = (node.box.Y + node.box.Baseline) - n.box.Baseline; this.DrawString(n, node.style_, color); return(true); } } } if (!isFence) { int w = node.firstChild.box.Width; int h = node.firstChild.box.Height; int b = node.firstChild.box.Baseline; int dx = node.firstChild.box.Dx; int dy = node.firstChild.box.Dy; try { this.MeasureBox(node.firstChild, node.style_); fHeight = node.firstChild.box.Height; } catch { } node.firstChild.box.Width = w; node.firstChild.box.Height = h; node.firstChild.box.Baseline = b; node.firstChild.box.Dx = dx; node.firstChild.box.Dy = dy; if (node.box.Height == fHeight) { int oldX = node.firstChild.box.X; try { node.firstChild.box.X = node.firstChild.box.X + this.Fence2Width(false, node, node.firstChild.glyph.Code); this.DrawString(node.firstChild, node.style_, color); } catch { } node.firstChild.box.X = oldX; return(true); } } int x1 = (this.oX + node.box.X) + this.Fence2Width(true, node, fString); int y1 = (this.oY + node.box.Y) + 1; int y2 = node.box.Height - 1; int charVal = 230; int char_extender = 0xe7; int tPart = 0xe8; int bPart = 0xed; bool isRight = false; if (fString != null) { switch (fString) { case "00028": { charVal = 230; char_extender = 0xe7; tPart = 0xe8; break; } case "0007B": { charVal = 0xec; char_extender = 0xef; tPart = 0xee; bPart = 0xed; break; } case "0005B": { charVal = 0xe9; char_extender = 0xea; tPart = 0xeb; break; } case "0230A": { charVal = 0xea; char_extender = 0xea; tPart = 0xeb; break; } case "02308": { charVal = 0xe9; char_extender = 0xea; tPart = 0xea; break; } case "0007C": { charVal = 0xef; char_extender = 0xef; tPart = 0xef; break; } case "02016": { charVal = 0x4c; char_extender = 0x4c; tPart = 0x4c; break; } case "00029": { isRight = true; charVal = 0xf6; char_extender = 0xf7; tPart = 0xf8; break; } case "0007D": { isRight = true; charVal = 0xfc; char_extender = 0xef; tPart = 0xfe; bPart = 0xfd; break; } case "0230B": { isRight = true; charVal = 250; char_extender = 250; tPart = 0xfb; break; } case "02309": { isRight = true; charVal = 0xf9; char_extender = 250; tPart = 250; break; } case "0005D": { isRight = true; charVal = 0xf9; char_extender = 250; tPart = 0xfb; break; } case "0232A": { isRight = true; break; } } } string s = "" + Convert.ToChar(charVal); SizeF sizeF = this.graphics_.MeasureString(s, this.GetBarFont(node)); int ww = (int)Math.Round((double)sizeF.Width); float cor = 0f; float hScale = 0f; int hAmount = 0; try { if (this.GetBarFont(node).Name != "ESSTIXEight") { FontFamilyInfo familyInfo = this.entityManager.GetFontFamilyInfo(this.GetBarFont(node).Name); if ((familyInfo != null) && familyInfo.NeedCorrectY) { cor = ((float)familyInfo.CorrectY) / 100f; hScale = sizeF.Height * cor; hAmount = (int)Math.Round((double)hScale); } } else { cor = -0.02f; hScale = sizeF.Height * cor; hAmount = (int)Math.Round((double)hScale); } } catch { } y1 += hAmount; int char_top = (int)Math.Round((double)(0.05f * sizeF.Height)); int char_bottom = (int)Math.Round((double)(0.78f * sizeF.Height)); double margin = this.operatorFontSize(node, node.style_); if (fString == "00029") { x1 += (int)Math.Round((double)(sizeF.Height * 0.06f)); } else if (((fString == "0005B") || (fString == "0230A")) || (fString == "02308")) { x1 += (int)Math.Round((double)(sizeF.Height * 0.03f)); } else if (fString == "0007C") { x1 -= (int)Math.Round((double)(sizeF.Width * 0.165f)); } else if (fString == "02016") { x1 += this.RoundFontSize(margin); y1 += this.RoundFontSize(0.5 * margin); } if (isRight) { if (fString == "0232A") { try { GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddLine(x1 + (int)Math.Round(0.2 * node.box.Height), this.oY + node.box.Y + node.box.Height / 2, x1 + (2 * this.RoundFontSize(0.5 * margin)), this.oY + node.box.Y); graphicsPath.AddLine(x1 + (2 * this.RoundFontSize(0.5 * margin)), this.oY + node.box.Y, x1 + this.RoundFontSize(0.5 * margin), this.oY + node.box.Y); graphicsPath.AddLine(x1 + this.RoundFontSize(0.5 * margin), this.oY + node.box.Y, (x1 + (int)Math.Round(0.2 * node.box.Height)) - this.RoundFontSize(1.5 * margin), this.oY + node.box.Y + node.box.Height / 2); graphicsPath.AddLine((int)((x1 + (int)Math.Round(0.2 * node.box.Height)) - this.RoundFontSize(1.5 * margin)), (int)(this.oY + node.box.Y + node.box.Height / 2), (int)(x1 + this.RoundFontSize(0.5 * margin)), (int)(this.oY + node.box.Y + node.box.Height)); graphicsPath.AddLine((int)(x1 + this.RoundFontSize(0.5 * margin)), (int)(this.oY + node.box.Y + node.box.Height), (int)(x1 + (2 * this.RoundFontSize(0.5 * margin))), (int)(this.oY + node.box.Y + node.box.Height)); graphicsPath.AddLine((int)(x1 + (2 * this.RoundFontSize(0.5 * margin))), (int)(this.oY + node.box.Y + node.box.Height), (int)(x1 + (int)Math.Round(0.2 * node.box.Height)), (int)(this.oY + node.box.Y + node.box.Height / 2)); this.graphics_.FillPath(new SolidBrush(color), graphicsPath); return(true); } catch { return(true); } } if (fString == "0007D") { int yy = (y1 - (int)Math.Round((double)(0.05f * sizeF.Height))) + (int)Math.Round((double)(0.78f * sizeF.Height)); int xx = ((y1 + (y2 / 2)) - (int)Math.Round((double)(0.05f * sizeF.Height))) - (((int)Math.Round((double)(0.78f * sizeF.Height)) - (int)Math.Round((double)(0.05f * sizeF.Height))) / 2) + (int)Math.Round((double)(0.05f * sizeF.Height)); this.graphics_.SetClip(new RectangleF((float)(x1 - 5), (float)(y1 - 5), (float)(ww + 20), (float)((((((y1 + (y2 / 2)) - (int)Math.Round((double)(0.05f * sizeF.Height))) - (((int)Math.Round((double)(0.78f * sizeF.Height)) - (int)Math.Round((double)(0.05f * sizeF.Height))) / 2) + (int)Math.Round((double)(0.05f * sizeF.Height))) - y1) + 5) + this.Floor(margin * 0.5, 2)))); this.graphics_.DrawString(s, this.GetBarFont(node), new SolidBrush(color), (float)x1, (float)(y1 - (int)Math.Round((double)(0.05f * sizeF.Height))), this.typographicsFormat); this.graphics_.ResetClip(); s = "" + Convert.ToChar(tPart); this.graphics_.SetClip(new RectangleF((float)(x1 - 5), (float)(((y1 + (y2 / 2)) - (int)Math.Round((double)(0.05f * sizeF.Height))) - (((int)Math.Round((double)(0.78f * sizeF.Height)) - (int)Math.Round((double)(0.05f * sizeF.Height))) / 2) + (int)Math.Round((double)(0.78f * sizeF.Height))), (float)(ww + 20), (float)(((y1 + y2) - (((y1 + (y2 / 2)) - (int)Math.Round((double)(0.05f * sizeF.Height))) - (((int)Math.Round((double)(0.78f * sizeF.Height)) - (int)Math.Round((double)(0.05f * sizeF.Height))) / 2) + (int)Math.Round((double)(0.78f * sizeF.Height)))) + 20))); this.graphics_.DrawString(s, this.GetBarFont(node), new SolidBrush(color), (float)x1, (float)((y1 + y2) - (int)Math.Round((double)(0.78f * sizeF.Height))), this.typographicsFormat); this.graphics_.ResetClip(); s = "" + Convert.ToChar(bPart); this.graphics_.DrawString(s, this.GetBarFont(node), new SolidBrush(color), (float)x1, (float)(((y1 + (y2 / 2)) - (int)Math.Round((double)(0.05f * sizeF.Height))) - (((int)Math.Round((double)(0.78f * sizeF.Height)) - (int)Math.Round((double)(0.05f * sizeF.Height))) / 2)), this.typographicsFormat); if (xx > yy) { this.DrawStringClipped(margin, x1, yy, xx + 1, char_extender, ww, char_top, char_bottom, this.GetBarFont(node), color); } yy = ((y1 + (y2 / 2)) - (int)Math.Round((double)(0.05f * sizeF.Height))) - (((int)Math.Round((double)(0.78f * sizeF.Height)) - (int)Math.Round((double)(0.05f * sizeF.Height))) / 2) + (int)Math.Round((double)(0.78f * sizeF.Height)); xx = ((y1 + y2) - (int)Math.Round((double)(0.78f * sizeF.Height))) + (int)Math.Round((double)(0.05f * sizeF.Height)); if (xx > yy) { this.DrawStringClipped(margin, x1, yy, xx, char_extender, ww, char_top, char_bottom, this.GetBarFont(node), color); } } else { this.graphics_.SetClip(new RectangleF((float)(x1 - this.RoundFontSize(margin)), (float)(y1 - 5), (float)(ww + (2 * this.RoundFontSize(margin))), (float)((y2 / 2) + 5))); this.graphics_.DrawString(s, this.GetBarFont(node), new SolidBrush(color), (float)x1, (float)(y1 - (int)Math.Round((double)(0.05f * sizeF.Height))), this.typographicsFormat); this.graphics_.ResetClip(); s = "" + Convert.ToChar(tPart); this.graphics_.SetClip(new RectangleF((float)(x1 - this.RoundFontSize(margin)), (float)(y1 + (y2 / 2)), (float)(ww + (2 * this.RoundFontSize(margin))), (float)((y2 / 2) + 20))); this.graphics_.DrawString(s, this.GetBarFont(node), new SolidBrush(color), (float)x1, (float)((y1 + y2) - (int)Math.Round((double)(0.78f * sizeF.Height))), this.typographicsFormat); this.graphics_.ResetClip(); this.DrawStringClipped(margin, x1, ((y1 - (int)Math.Round((double)(0.05f * sizeF.Height))) + (int)Math.Round((double)(0.78f * sizeF.Height))) - 2, (((y1 + y2) - (int)Math.Round((double)(0.78f * sizeF.Height))) + (int)Math.Round((double)(0.05f * sizeF.Height))) + 1, char_extender, ww, char_top, char_bottom, this.GetBarFont(node), color); } } else { if (fString == "02329") { try { int boxH = node.box.Height; int y = this.oY + node.box.Y; int b = (int)Math.Round(0.2 * boxH); int xx = this.RoundFontSize(0.5 * margin); int xxx = this.RoundFontSize(1.5 * margin); int c = boxH / 2; GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddLine(x1, y + c, (x1 + b) - (2 * xx), y); graphicsPath.AddLine((x1 + b) - (2 * xx), y, (x1 + b) - xx, y); graphicsPath.AddLine((x1 + b) - xx, y, x1 + xxx, y + c); graphicsPath.AddLine((int)(x1 + xxx), (int)(y + c), (int)((x1 + b) - xx), (int)(y + boxH)); graphicsPath.AddLine((int)(x1 + b), (int)(y + boxH), (int)((x1 + b) - (2 * xx)), (int)(y + boxH)); graphicsPath.AddLine((x1 + b) - (2 * xx), y + boxH, x1, y + c); this.graphics_.FillPath(new SolidBrush(color), graphicsPath); return(true); } catch { return(true); } } if (fString == "0007B") // LEFT CURLY BRACKET { int yMarg = ((y1 + (y2 / 2)) - (int)Math.Round((double)(0.05f * sizeF.Height))) - (((int)Math.Round((double)(0.78f * sizeF.Height)) - (int)Math.Round((double)(0.05f * sizeF.Height))) / 2); int yy = (y1 - (int)Math.Round((double)(0.05f * sizeF.Height))) + (int)Math.Round((double)(0.78f * sizeF.Height)); int hh = yMarg + (int)Math.Round((double)(0.05f * sizeF.Height)); this.graphics_.SetClip(new RectangleF((float)(x1 - 5), (float)(y1 - 5), (float)(ww + 10), (float)((((yMarg - y1) + (int)Math.Round((double)(0.05f * sizeF.Height))) + 5) + this.Floor(margin * 0.5, 2)))); this.graphics_.DrawString(s, this.GetBarFont(node), new SolidBrush(color), (float)x1, (float)(y1 - (int)Math.Round((double)(0.05f * sizeF.Height))), this.typographicsFormat); this.graphics_.ResetClip(); s = "" + Convert.ToChar(tPart); this.graphics_.SetClip(new RectangleF((float)(x1 - 5), (float)(yMarg + (int)Math.Round((double)(0.78f * sizeF.Height))), (float)(ww + 10), (float)(((y1 + y2) - (yMarg + (int)Math.Round((double)(0.78f * sizeF.Height)))) + 20))); this.graphics_.DrawString(s, this.GetBarFont(node), new SolidBrush(color), (float)x1, (float)((y1 + y2) - (int)Math.Round((double)(0.78f * sizeF.Height))), this.typographicsFormat); this.graphics_.ResetClip(); s = "" + Convert.ToChar(bPart); this.graphics_.DrawString(s, this.GetBarFont(node), new SolidBrush(color), (float)x1, (float)yMarg, this.typographicsFormat); if (hh > yy) { this.DrawStringClipped(margin, x1, yy, hh + 1, char_extender, ww, char_top, char_bottom, this.GetBarFont(node), color); } yy = yMarg + (int)Math.Round((double)(0.78f * sizeF.Height)); hh = ((y1 + y2) - (int)Math.Round((double)(0.78f * sizeF.Height))) + (int)Math.Round((double)(0.05f * sizeF.Height)); if (hh > yy) { this.DrawStringClipped(margin, x1, yy, hh, char_extender, ww, char_top, char_bottom, this.GetBarFont(node), color); } } else { this.graphics_.SetClip(new RectangleF((float)x1, (float)(y1 - 5), (float)ww, (float)((y2 / 2) + 5))); this.graphics_.DrawString(s, this.GetBarFont(node), new SolidBrush(color), (float)x1, (float)(y1 - (int)Math.Round((double)(0.05f * sizeF.Height))), this.typographicsFormat); this.graphics_.ResetClip(); s = "" + Convert.ToChar(tPart); this.graphics_.SetClip(new RectangleF((float)x1, (float)(y1 + (y2 / 2)), (float)ww, (float)((y2 / 2) + 20))); this.graphics_.DrawString(s, this.GetBarFont(node), new SolidBrush(color), (float)x1, (float)((y1 + y2) - (int)Math.Round((double)(0.78f * sizeF.Height))), this.typographicsFormat); this.graphics_.ResetClip(); this.DrawStringClipped(margin, x1, ((y1 - (int)Math.Round((double)(0.05f * sizeF.Height))) + (int)Math.Round((double)(0.78f * sizeF.Height))) - 2, (((y1 + y2) - (int)Math.Round((double)(0.78f * sizeF.Height))) + (int)Math.Round((double)(0.05f * sizeF.Height))) + 1, char_extender, ww, char_top, char_bottom, this.GetBarFont(node), color); } } return(true); }