private void LoadState() { Log.Information("Loading State"); var regAccessor = new RegistryAccessor(); var fontFamConverter = new Media.FontFamilyConverter(); var fontFamily = regAccessor.Read("FONTFAMILY"); var fontWeightToBeConverted = regAccessor.Read("FONTWEIGHT"); var fontSize = regAccessor.Read("FONTSIZE"); var fontStyle = regAccessor.Read("FONTSYLE"); if (fontFamily != null) { _formatModel.Family = fontFamConverter.ConvertFromString(fontFamily) as Media.FontFamily; } if (fontWeightToBeConverted != null) { _formatModel.Weight = FontWeight.FromOpenTypeWeight(Convert.ToInt32(regAccessor.Read("FONTWEIGHT"))); } if (fontSize != null && fontSize != "0") { _formatModel.Size = Convert.ToDouble(fontSize); } if (fontStyle != null) { _formatModel.Style = ConvertFontSytleFromString(fontStyle); } }
public override IResult Execute(IResult previousResults) { try { var font = new FontFamilyConverter().ConvertFromInvariantString(FontFamily) as FontFamily; if (font == null) { Log.WarnFormat("Cannot convert {0} to a valid font family", FontFamily); return new NextResult(); } AppearanceManager.DefaultFontFamily = font; return new NextResult(); } catch (Exception e) { return new ExceptionOccurred(e); } }
// Initialize known object types internal static TypeConverter CreateKnownTypeConverter(Int16 converterId) { TypeConverter o = null; switch (converterId) { case -42: o = new System.Windows.Media.Converters.BoolIListConverter(); break; case -46: o = new System.ComponentModel.BooleanConverter(); break; case -53: o = new System.Windows.Media.BrushConverter(); break; case -61: o = new System.ComponentModel.ByteConverter(); break; case -70: o = new System.ComponentModel.CharConverter(); break; case -71: o = new System.Windows.Media.Converters.CharIListConverter(); break; case -87: o = new System.Windows.Media.ColorConverter(); break; case -94: o = new System.Windows.Input.CommandConverter(); break; case -96: o = new System.Windows.Markup.ComponentResourceKeyConverter(); break; case -111: o = new System.Windows.CornerRadiusConverter(); break; case -114: o = new System.ComponentModel.CultureInfoConverter(); break; case -115: o = new System.Windows.CultureInfoIetfLanguageTagConverter(); break; case -117: o = new System.Windows.Input.CursorConverter(); break; case -124: o = new System.ComponentModel.DateTimeConverter(); break; case -125: o = new System.Windows.Markup.DateTimeConverter2(); break; case -130: o = new System.ComponentModel.DecimalConverter(); break; case -137: o = new System.Windows.Markup.DependencyPropertyConverter(); break; case -138: o = new System.Windows.DialogResultConverter(); break; case -174: o = new System.Windows.Media.DoubleCollectionConverter(); break; case -175: o = new System.ComponentModel.DoubleConverter(); break; case -176: o = new System.Windows.Media.Converters.DoubleIListConverter(); break; case -188: o = new System.Windows.DurationConverter(); break; case -190: o = new System.Windows.DynamicResourceExtensionConverter(); break; case -201: o = new System.Windows.ExpressionConverter(); break; case -204: o = new System.Windows.FigureLengthConverter(); break; case -215: o = new System.Windows.Media.FontFamilyConverter(); break; case -216: o = new System.Windows.FontSizeConverter(); break; case -218: o = new System.Windows.FontStretchConverter(); break; case -220: o = new System.Windows.FontStyleConverter(); break; case -222: o = new System.Windows.FontWeightConverter(); break; case -240: o = new System.Windows.Media.GeometryConverter(); break; case -256: o = new System.Windows.GridLengthConverter(); break; case -267: o = new System.ComponentModel.GuidConverter(); break; case -286: o = new System.Windows.Media.ImageSourceConverter(); break; case -299: o = new System.Windows.Input.InputScopeConverter(); break; case -301: o = new System.Windows.Input.InputScopeNameConverter(); break; case -306: o = new System.ComponentModel.Int16Converter(); break; case -314: o = new System.Windows.Media.Int32CollectionConverter(); break; case -315: o = new System.ComponentModel.Int32Converter(); break; case -319: o = new System.Windows.Int32RectConverter(); break; case -324: o = new System.ComponentModel.Int64Converter(); break; case -338: o = new System.Windows.Input.KeyConverter(); break; case -340: o = new System.Windows.Input.KeyGestureConverter(); break; case -342: o = new System.Windows.KeySplineConverter(); break; case -344: o = new System.Windows.KeyTimeConverter(); break; case -348: o = new System.Windows.LengthConverter(); break; case -387: o = new System.Windows.Media.Media3D.Matrix3DConverter(); break; case -392: o = new System.Windows.Media.MatrixConverter(); break; case -410: o = new System.Windows.Input.ModifierKeysConverter(); break; case -411: o = new System.Windows.Input.MouseActionConverter(); break; case -415: o = new System.Windows.Input.MouseGestureConverter(); break; case -423: o = new System.Windows.NullableBoolConverter(); break; case -445: o = new System.Windows.Media.PathFigureCollectionConverter(); break; case -453: o = new System.Windows.Media.PixelFormatConverter(); break; case -462: o = new System.Windows.Media.Media3D.Point3DCollectionConverter(); break; case -463: o = new System.Windows.Media.Media3D.Point3DConverter(); break; case -467: o = new System.Windows.Media.Media3D.Point4DConverter(); break; case -473: o = new System.Windows.Media.PointCollectionConverter(); break; case -474: o = new System.Windows.PointConverter(); break; case -475: o = new System.Windows.Media.Converters.PointIListConverter(); break; case -492: o = new System.Windows.PropertyPathConverter(); break; case -498: o = new System.Windows.Media.Media3D.QuaternionConverter(); break; case -507: o = new System.Windows.Media.Media3D.Rect3DConverter(); break; case -511: o = new System.Windows.RectConverter(); break; case -521: o = new System.Windows.Media.Animation.RepeatBehaviorConverter(); break; case -538: o = new System.Windows.Markup.RoutedEventConverter(); break; case -545: o = new System.ComponentModel.SByteConverter(); break; case -563: o = new System.ComponentModel.SingleConverter(); break; case -568: o = new System.Windows.Media.Media3D.Size3DConverter(); break; case -572: o = new System.Windows.SizeConverter(); break; case -615: o = new System.ComponentModel.StringConverter(); break; case -619: o = new System.Windows.StrokeCollectionConverter(); break; case -633: o = new System.Windows.TemplateBindingExpressionConverter(); break; case -635: o = new System.Windows.TemplateBindingExtensionConverter(); break; case -637: o = new System.Windows.Markup.TemplateKeyConverter(); break; case -645: o = new System.Windows.TextDecorationCollectionConverter(); break; case -655: o = new System.Windows.ThicknessConverter(); break; case -664: o = new System.ComponentModel.TimeSpanConverter(); break; case -681: o = new System.Windows.Media.TransformConverter(); break; case -692: o = new System.Windows.Markup.TypeTypeConverter(); break; case -696: o = new System.ComponentModel.UInt16Converter(); break; case -698: o = new System.ComponentModel.UInt32Converter(); break; case -700: o = new System.ComponentModel.UInt64Converter(); break; case -701: o = new System.Windows.Media.Converters.UShortIListConverter(); break; case -705: o = new System.UriTypeConverter(); break; case -714: o = new System.Windows.Media.Media3D.Vector3DCollectionConverter(); break; case -715: o = new System.Windows.Media.Media3D.Vector3DConverter(); break; case -722: o = new System.Windows.Media.VectorCollectionConverter(); break; case -723: o = new System.Windows.VectorConverter(); break; case -757: o = new System.Windows.Markup.XmlLanguageConverter(); break; } return o; }
private void UpdateSampleTicker(DAL.Content sticker) { try { tbTickerSample.Text = sticker.Metadata8; FontFamilyConverter ffc = new FontFamilyConverter(); FontFamily ff = new FontFamily(); ff = (FontFamily)ffc.ConvertFromString(sticker.Metadata2); tbTickerSample.FontFamily = ff; tbTickerSample.FontSize = Convert.ToDouble(sticker.Metadata3); //Brush b = new //Color c = new Color(); BrushConverter bc = new BrushConverter(); tbTickerSample.Foreground = (Brush)bc.ConvertFromString(sticker.Metadata4); gridTickerBackground.Background = (Brush)bc.ConvertFromString(sticker.Metadata6); gridTickerBackground.Opacity = Convert.ToDouble(sticker.Metadata7); } catch (Exception ex) { } }
public void OpenDocxFile(string fileName) { XElement wordDoc = null; try { Package package = Package.Open(fileName); Uri documentUri = new Uri("/word/document.xml", UriKind.Relative); PackagePart documentPart = package.GetPart(documentUri); wordDoc = XElement.Load(new StreamReader(documentPart.GetStream())); } catch (Exception) { this.rtbDocument.Document.Blocks.Add(new Paragraph(new Run("Cannot open file!"))); return; } XNamespace w = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"; var paragraphs = from p in wordDoc.Descendants(w + "p") select p; foreach (var p in paragraphs) { var style = from s in p.Descendants(w + "rPr") select s; var parStyle = from s in p.Descendants(w + "pPr") select s; var font = (from f in style.Descendants(w + "rFonts") select f.FirstAttribute).FirstOrDefault(); var size = (from s in style.Descendants(w + "sz") select s.FirstAttribute).FirstOrDefault(); var rgbColor = (from c in style.Descendants(w + "color") select c.FirstAttribute).FirstOrDefault(); var bold = (from b in style.Descendants(w + "b") select b).FirstOrDefault(); var italic = (from i in style.Descendants(w + "i") select i).FirstOrDefault(); var underline = (from u in style.Descendants(w + "u") select u).FirstOrDefault(); var alignment = (from a in parStyle.Descendants(w + "jc") select a).FirstOrDefault(); var textElements = from t in p.Descendants(w + "t") select t; var list = (from l in parStyle.Descendants(w + "numPr") select l).FirstOrDefault(); StringBuilder text = new StringBuilder(); foreach (var element in textElements) { text.Append(element.Value); } Paragraph par = new Paragraph(); Run run = new Run(text.ToString()); List items = new List(); if (list != null) { //List items = new List(); items.ListItems.Add(new ListItem(par)); var markerStyleElement = (from l in list.Descendants(w + "numId") select l).FirstOrDefault(); TextMarkerStyle markerStyle = new TextMarkerStyle(); if(markerStyleElement != null) { int value = int.Parse(markerStyleElement.Attribute(w + "val").Value); switch (value) { case 1: markerStyle = TextMarkerStyle.Disc; break; case 2: markerStyle = TextMarkerStyle.Decimal; break; } } items.MarkerStyle = markerStyle; } if(font != null) { FontFamilyConverter converter = new FontFamilyConverter(); run.FontFamily = (FontFamily) converter.ConvertFrom(font.Value); } if(size != null) { run.FontSize = double.Parse(size.Value); } if(rgbColor != null) { Color color = ConvertRgbToColor(rgbColor.Value); run.Foreground = new SolidColorBrush(color); } if(bold != null) { if (bold.Attribute(w + "val") != null) { if (bold.Attribute(w + "val").Value == "off") { run.FontWeight = FontWeights.Normal; } else { run.FontWeight = FontWeights.Bold; } } else { run.FontWeight = FontWeights.Bold; } } if(italic != null) { if (italic.Attribute(w + "val") != null) { if (italic.Attribute(w + "val").Value == "off") { run.FontStyle = FontStyles.Normal; } else { run.FontStyle = FontStyles.Italic; } } else { run.FontStyle = FontStyles.Italic; } } if(underline != null) { run.TextDecorations.Add(TextDecorations.Underline); } if(alignment != null) { TextAlignment textAlignment = new TextAlignment(); string value = alignment.Attribute(w + "val").Value; switch (value) { case "left": textAlignment = TextAlignment.Left; break; case "center": textAlignment = TextAlignment.Center; break; case "right": textAlignment = TextAlignment.Right; break; case "justify": textAlignment = TextAlignment.Justify; break; } par.TextAlignment = textAlignment; } else { par.TextAlignment = TextAlignment.Left; } par.Inlines.Add(run); if(list != null) { this.rtbDocument.Document.Blocks.Add(items); } else { this.rtbDocument.Document.Blocks.Add(par); } } }
private void CreateTimeWindow () { if (WMB.Basics.GetUserConfigurationSettingsValue ("WPMediaShowTimeBackground") != "On") return; BrushConverter BRConverter = new BrushConverter (); System.Windows.FontWeightConverter FWConverter = new FontWeightConverter (); System.Windows.Media.FontFamilyConverter FFConverter = new FontFamilyConverter (); m_TimeWindow = new System.Windows.Window (); m_TimeWindow.Width = ((double) m_CVM.VideoWidth) * 0.8; m_TimeWindow.Height = ((double) m_CVM.VideoHeight) * 0.2; m_TimeWindow.MaxWidth = ((double) m_CVM.VideoWidth) * 0.8; m_TimeWindow.MaxHeight = ((double) m_CVM.VideoHeight) * 0.2; m_TimeWindow.MinWidth = ((double) m_CVM.VideoWidth) * 0.8; m_TimeWindow.MinHeight = ((double) m_CVM.VideoHeight) * 0.2; m_TimeWindow.Top = ((double) m_CVM.VideoRectangle.Top) + ((double) m_CVM.VideoHeight) * 0.75; ; m_TimeWindow.Left = ((double) m_CVM.VideoRectangle.Left) + ((double) m_CVM.VideoWidth) * 0.1; m_TimeWindow.AllowsTransparency = true; m_TimeWindow.Topmost = false; Brush TransparentBrush = (Brush) BRConverter.ConvertFromString ("Transparent"); m_TimeWindow.Background = TransparentBrush; m_TimeWindow.BorderBrush = TransparentBrush; m_TimeWindow.WindowStyle = System.Windows.WindowStyle.None; Grid RootGrid = m_XAMLHandling.CreateGrid (new int [] {1}, new int [] {1}); RootGrid.Background = TransparentBrush; m_TimeWindow.Content = RootGrid; Viewbox ViewBoxControl = new Viewbox (); RootGrid.Children.Add (ViewBoxControl); m_BackGroundTimeTextBlock = new TextBlock(); ViewBoxControl.Child = m_BackGroundTimeTextBlock; m_BackGroundTimeTextBlock.Text = "WPMedia"; m_BackGroundTimeTextBlock.HorizontalAlignment = HorizontalAlignment.Center; m_BackGroundTimeTextBlock.VerticalAlignment = VerticalAlignment.Center; m_BackGroundTimeTextBlock.Foreground = (Brush) BRConverter.ConvertFromString("AntiqueWhite"); m_BackGroundTimeTextBlock.Background = TransparentBrush; m_BackGroundTimeTextBlock.FontFamily = (FontFamily) FFConverter.ConvertFromString ("Verdana"); m_BackGroundTimeTextBlock.FontWeight = (FontWeight) FWConverter.ConvertFromString ("Bold"); m_TimeWindow.Cursor = Cursors.None; m_TimeWindow.Show (); }
private void MenuItemFontChange_Clicked(object sender, RoutedEventArgs e) { System.Windows.Forms.FontDialog fontDialog = new System.Windows.Forms.FontDialog(); fontDialog.Font = new System.Drawing.Font(EditText1.FontFamily.ToString(), (float)EditText1.FontSize); if (fontDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FontFamilyConverter ffc = new FontFamilyConverter(); EditText1.FontSize = (double)fontDialog.Font.Size; EditText1.FontFamily = (FontFamily)ffc.ConvertFromString(fontDialog.Font.Name); /* if (fontDialog.Font.Bold) textAnnotation.FontWeight = FontWeights.Bold; else textAnnotation.FontWeight = FontWeights.Normal; if (fontDialog.Font.Italic) textAnnotation.FontStyle = FontStyles.Italic; else textAnnotation.FontStyle = FontStyles.Normal; */ } }
private void button8_Click(object sender, RoutedEventArgs e) { if (selTB != null) { selTB.Foreground = ChooseColor(); using (System.Windows.Forms.FontDialog fd = new System.Windows.Forms.FontDialog()) { try { fd.AllowScriptChange = false; fd.AllowSimulations = false; if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FontFamilyConverter ffc = new FontFamilyConverter(); selTB.FontSize = fd.Font.Size; selTB.FontFamily = (FontFamily)ffc.ConvertFromString(fd.Font.Name); } } catch { //Not a truetype font MessageBox.Show("Шрифт не изменен"); } } } }
private void btnReset_Click(object sender, RoutedEventArgs e) { try { FontFamilyConverter converter = new FontFamilyConverter(); FontFamily consolas = (FontFamily)converter.ConvertFromString("Consolas"); Properties.Settings.Default.EditorFontFace = consolas; this.fontSizeSlider.Value = 13d; Properties.Settings.Default.EditorForeground = Colors.Black; Properties.Settings.Default.EditorBackground = Colors.White; Properties.Settings.Default.Save(); } catch { //Can't reset settings } //Show settings this.ShowSettings(); }
public FontNameToFontFamilyConverter() { InternalConverter = new FontFamilyConverter(); }
public async Task TestAttachedPropertyButtonFontFamily() { await TestHost.SwitchToAppThread(); var window = await WindowHelpers.CreateInvisibleWindowAsync<TextBoxHelperTestWindow>().ConfigureAwait(false); window.Invoke(() => { var fontFamily = new FontFamilyConverter().ConvertFromString("Arial"); window.TestTextBox.SetValue(TextBoxHelper.ButtonFontFamilyProperty, fontFamily); Assert.Equal(fontFamily, window.TestTextBox.FindChild<Button>("PART_ClearText").FontFamily); window.TestButtonTextBox.SetValue(TextBoxHelper.ButtonFontFamilyProperty, fontFamily); Assert.Equal(fontFamily, window.TestButtonTextBox.FindChild<Button>("PART_ClearText").FontFamily); window.TestPasswordBox.SetValue(TextBoxHelper.ButtonFontFamilyProperty, fontFamily); Assert.Equal(fontFamily, window.TestPasswordBox.FindChild<Button>("PART_ClearText").FontFamily); window.TestButtonPasswordBox.SetValue(TextBoxHelper.ButtonFontFamilyProperty, fontFamily); Assert.Equal(fontFamily, window.TestButtonPasswordBox.FindChild<Button>("PART_ClearText").FontFamily); window.TestButtonRevealedPasswordBox.SetValue(TextBoxHelper.ButtonFontFamilyProperty, fontFamily); Assert.Equal(fontFamily, window.TestButtonRevealedPasswordBox.FindChild<Button>("PART_ClearText").FontFamily); window.TestComboBox.SetValue(TextBoxHelper.ButtonFontFamilyProperty, fontFamily); var toggleButton = window.TestComboBox.FindChild<ToggleButton>("PART_DropDownToggle"); Assert.Equal(fontFamily, toggleButton.FindChild<Button>("PART_ClearText").FontFamily); window.TestEditableComboBox.SetValue(TextBoxHelper.ButtonFontFamilyProperty, fontFamily); var edTextBox = window.TestEditableComboBox.FindChild<TextBox>("PART_EditableTextBox"); Assert.Equal(fontFamily, edTextBox.FindChild<Button>("PART_ClearText").FontFamily); window.TestNumericUpDown.SetValue(TextBoxHelper.ButtonFontFamilyProperty, fontFamily); Assert.Equal(fontFamily, window.TestNumericUpDown.FindChild<Button>("PART_ClearText").FontFamily); window.TestHotKeyBox.SetValue(TextBoxHelper.ButtonFontFamilyProperty, fontFamily); Assert.Equal(fontFamily, window.TestHotKeyBox.FindChild<Button>("PART_ClearText").FontFamily); }); }
public void addPhoto(string path) { StackPanel sp = new StackPanel(); Label label = new Label(); label.HorizontalContentAlignment = HorizontalAlignment.Center; label.FontStyle = FontStyles.Italic; FontFamilyConverter ffc = new FontFamilyConverter(); FontFamily f = ffc.ConvertFromString("Calibri") as FontFamily; label.FontFamily = f; Image img = new Image(); sp.Children.Add(img); sp.Children.Add(label); BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(path); bitmap.EndInit(); img.ToolTip = "Press space to preview photo"; img.Source = bitmap; label.Content = System.IO.Path.GetFileName(img.Source.ToString()); img.Height = 128; img.Width = 135; selectListBox.Items.Add(sp); }
private void fontComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBoxItem fontItem = (ComboBoxItem)fontComboBox.SelectedItem; string font = fontItem.Content.ToString(); var fontFamilyConvertor = new FontFamilyConverter(); send.FontFamily = fontFamilyConvertor.ConvertFromString(font) as FontFamily; myFont = font; }
private Paragraph CreateParagraph(string message) { Paragraph para = new Paragraph(); para.BorderBrush = Brushes.Red; var emoticons = emoticonMap.Keys.Cast<string>(); var color = Brushes.Red; para.Padding = new Thickness(0); var fontFamilyConvertor = new FontFamilyConverter(); var font = fontFamilyConvertor.ConvertFromString("Segoe UI") as FontFamily; if (message.Contains("[col]")) { var colorCode = message.Substring(message.IndexOf("[col]") + 5, message.IndexOf("[/col]") - (message.IndexOf("[col]") + 5)); message = message.Replace("[col]" + colorCode + "[/col]", ""); color = GetColor(colorCode); var fontCode = message.Substring(message.IndexOf("[fon]") + 5, message.IndexOf("[/fon]") - (message.IndexOf("[fon]") + 5)); message = message.Replace("[fon]" + fontCode + "[/fon]", ""); font = fontFamilyConvertor.ConvertFromString(fontCode) as FontFamily; para.BorderBrush = color; para.FontFamily = font; var name = message.TakeWhile(elem => !(elem.Equals(':'))); var parsedStringName = new string(name.ToArray()); var regex = new Regex(parsedStringName); message = regex.Replace(message, "", 1); parsedStringName += message[0]; message = message.Substring(1); para.AddText(parsedStringName, Brushes.Black); } var emoteExists = emoticons.Any(emote => message.Contains(emote)); while (emoteExists || message.ToLower().Contains("https") || message.ToLower().Contains("http") || message.ToLower().Contains("www")) { message = message.Trim(); if ("".Equals(message)) break; if (message.ToLower().StartsWith("https") || message.ToLower().StartsWith("http") || message.ToLower().StartsWith("www")) { Hyperlink link = new Hyperlink(); link.IsEnabled = true; link.Inlines.Add(" (Click) "); var startIndex = message.IndexOf("https:"); if (startIndex == -1) startIndex = message.IndexOf("http:"); if (startIndex == -1) startIndex = message.IndexOf("www."); if (startIndex != -1) { var endIndex = message.IndexOf(" ", startIndex); if (endIndex == -1) endIndex = message.Count(); var prefix = message.Substring(startIndex, endIndex - startIndex).StartsWith("www.") ? "http://" : ""; link.NavigateUri = new Uri(prefix + message.Substring(startIndex, endIndex - startIndex)); para.Inlines.Add(link); link.RequestNavigate += new RequestNavigateEventHandler(link_RequestNavigate); message = message.Replace(message.Substring(startIndex, endIndex - startIndex), ""); } } else if (emoticons.Any(emote => message.Substring(0, message.IndexOf(" ") == -1 ? message.Count() : message.IndexOf(" ")).Contains(emote))) { var parsedMessage = message.TakeWhile(elem => !emoteStart.Contains(elem)); var parsedStringMessage = new string(parsedMessage.ToArray()); if (!parsedStringMessage.Equals("")) { var regex = new Regex(parsedStringMessage); message = regex.Replace(message, "", 1); para.AddText(parsedStringMessage, color); } if (message.Count() == 0) break; var emotes = emoticons.Where(emote => message.Substring(0, message.Count() < MAX_EMOTE_LENGTH ? message.Count() : MAX_EMOTE_LENGTH).Contains(emote)); if (emotes.Count() > 0) { para.Inlines.Add(GetImageBySymbol(emotes.Last())); message = message.Substring(emotes.Last().Count()); } else { para.AddText("" + message[0], color); message = message.Substring(1); } } else { para.AddText(message.Substring(0, message.IndexOf(" ") == -1 ? message.Count() : message.IndexOf(" ")) + " ", color); var regex = new Regex(message.Substring(0, message.IndexOf(" ") == -1 ? message.Count() : message.IndexOf(" "))); message = regex.Replace(message, "", 1); } } if (!"".Equals(message)) { para.AddText(message, color); } return para; }