public static FontIconSet GetAllIcons(FontFamilies fontName) { List <FontIcon> icons = default; switch (fontName) { case FontFamilies.MaterialDesign: icons = GetFontList(typeof(MaterialDesign.Icons)); break; case FontFamilies.FontAwesomeBrands: icons = GetFontList(typeof(FontAwesomeBrands.Icons)); break; case FontFamilies.FontAwesomeRegular: icons = GetFontList(typeof(FontAwesomeRegular.Icons)); break; case FontFamilies.FontAwesomeSolid: icons = GetFontList(typeof(FontAwesomeSolid.Icons)); break; } return(new FontIconSet() { FontName = fontName, Icons = icons }); }
private void MoveToDestination(object sender, RoutedEventArgs e) { try { var path = ((Button)sender).Tag as string; if (string.IsNullOrEmpty(path)) { return; } var selectedItems = ListBox.SelectedItems.OfType <FontElement>().ToList(); foreach (var selectedItem in selectedItems) { foreach (var pathe in selectedItem.Pathes) { var fileName = Path.GetFileName(pathe); if (string.IsNullOrEmpty(fileName)) { continue; } File.Move(pathe, Path.Combine(path, fileName)); } FontFamilies.Remove(selectedItem); } } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private static bool CheckFamily(LOGFONT lf, FontFamilies families) { FontPitchAndFamily v = (FontPitchAndFamily)(lf.lfPitchAndFamily >> 2 << 2); switch (v) { case FontPitchAndFamily.FF_DECORATIVE: { if ((families & FontFamilies.Decorative) == 0) { return(false); } break; } case FontPitchAndFamily.FF_DONTCARE: { return(families == FontFamilies.DontCare ? true : false); } case FontPitchAndFamily.FF_MODERN: { if ((families & FontFamilies.Modern) == 0) { return(false); } break; } case FontPitchAndFamily.FF_ROMAN: { if ((families & FontFamilies.Roman) == 0) { return(false); } break; } case FontPitchAndFamily.FF_SWISS: { if ((families & FontFamilies.Swiss) == 0) { return(false); } break; } case FontPitchAndFamily.FF_SCRIPT: { if ((families & FontFamilies.Script) == 0) { return(false); } break; } } return(true); }
public void Apply() { Setting.Instance.ExperienceProperty.UpdateKind = this._updateKind - 1; if (!fontBroken) { Setting.Instance.ExperienceProperty.FontFamily = FontFamilies.Select(ff => ff.FamilyNames.Select(fn => fn.Value).FirstOrDefault()) .ElementAtOrDefault(_fontFamilyIndex); } Setting.Instance.ExperienceProperty.FontSize = this.FontSize; Setting.Instance.ExperienceProperty.IgnoreTimeoutError = this.IgnoreTimeoutError; }
/// <summary> /// Get the css style fragement /// </summary> /// <returns>The css style attribute</returns> public string GetHtmlStyle() { string style = "style=\""; if (Italic != null) { if (Italic != "normal") { style += "font-style: italic; "; } } if (Bold != null) { style += "font-weight: " + Bold + "; "; } if (Underline != null) { style += "text-decoration: underline; "; } if (TextLineThrough != null) { style += "text-decoration: line-through; "; } if (FontName != null) { style += "font-family: " + FontFamilies.HtmlFont(FontName) + "; "; } if (FontSize != null) { style += "font-size: " + FontFamilies.PtToPx(FontSize) + "; "; } if (FontColor != null) { style += "color: " + FontColor + "; "; } if (BackgroundColor != null) { style += "background-color: " + BackgroundColor + "; "; } if (!style.EndsWith("; ")) { style = ""; } else { style += "\""; } return(style); }
private void ReadBytes(Bytes bytes) { byte[] byteArray = bytes.ByteArray; _height = BitConverter.ToUInt16(byteArray, 0); SetOptionsValue(bytes.Get(2, 2)); _colorIndex = BitConverter.ToUInt16(byteArray, 4); _weight = FontWeightConverter.Convert(BitConverter.ToUInt16(byteArray, 6)); _escapement = (EscapementTypes)BitConverter.ToUInt16(byteArray, 8); _underline = (UnderlineTypes)byteArray[10]; _fontFamily = (FontFamilies)byteArray[11]; _characterSet = (CharacterSets)byteArray[12]; //skip byte index 13 _fontName = UnicodeBytes.Read(bytes.Get(14, bytes.Length - 14), 8); }
private void InitializeComponent() { _container = new VerticalBox(); this.Child = _container; _entry = new Entry(); _entry.TextChanged += (sender, args) => { Console.WriteLine("onChanged()"); }; _container.Children.Add(_entry); _form = new Form(); _entryBase = new PasswordEntry(); _entryBase.TextChanged += (sender, args) => { EntryChanged("password", args.Text); }; _form.Children.Add("Password Entry", _entryBase); _entryBase = new SearchEntry(); _entryBase.TextChanged += (sender, args) => { EntryChanged("search", args.Text); }; _form.Children.Add("Search Box", _entryBase); _container.Children.Add(_form, false); _group = new Group("Font Families"); _container.Children.Add(_group, true); _vBox = new VerticalBox(); _group.Child = _vBox; _multilineEntry = new MultilineEntry(); _vBox.Children.Add(_multilineEntry, true); _button = new Button("List Font Families"); _button.Click += (sender, args) => { _multilineEntry.Text = ""; var fonts = new FontFamilies(); var num = fonts.Count; for (int i = 0; i < num; i++) { var value = fonts[i]; _multilineEntry.Append(value + "\n"); } fonts.Free(); }; _vBox.Children.Add(_button); }
private void SetDefaults() { _height = 200; _italic = false; _underlined = false; _struckOut = false; _colorIndex = 32767; _weight = FontWeight.Normal; _escapement = EscapementTypes.Default; _underline = UnderlineTypes.Default; _fontFamily = FontFamilies.Default; _characterSet = CharacterSets.Default; _notUsed = 0; _fontName = "Arial"; OnChange(); }
public static string GetFontFamily(FontFamilies fontFamily) { switch (fontFamily) { case FontFamilies.FontAwesome5Brands: return(FontAwesome5Brands); case FontFamilies.FontAwesome5Regular: return(FontAwesome5Regular); case FontFamilies.FontAwesome5Solid: return(FontAwesome5Solid); default: return(string.Empty); } }
public PrintForm() { InitializeComponent(); //http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client.Toolkit~ESRI.ArcGIS.Client.Toolkit.Legend.html legend1.Map = MapApplication.Current.Map; legend1.LayerItemsMode = ESRI.ArcGIS.Client.Toolkit.Legend.Mode.Flat; scaleLine1.Map = MapApplication.Current.Map; _fontFamilies = new ObservableCollection <FontFamily>(); FontFamilies.Add(new FontFamily("Portable User Interface")); FontFamilies.Add(new FontFamily("Arial")); FontFamilies.Add(new FontFamily("Arial Black")); FontFamilies.Add(new FontFamily("Arial Unicode MS")); FontFamilies.Add(new FontFamily("Calibri")); FontFamilies.Add(new FontFamily("Cambria")); FontFamilies.Add(new FontFamily("Cambria Math")); FontFamilies.Add(new FontFamily("Comic Sans MS")); FontFamilies.Add(new FontFamily("Candara")); FontFamilies.Add(new FontFamily("Consolas")); FontFamilies.Add(new FontFamily("Constantia")); FontFamilies.Add(new FontFamily("Corbel")); FontFamilies.Add(new FontFamily("Courier New")); FontFamilies.Add(new FontFamily("Georgia")); FontFamilies.Add(new FontFamily("Lucida Grande")); FontFamilies.Add(new FontFamily("Segoe UI")); FontFamilies.Add(new FontFamily("Symbol")); FontFamilies.Add(new FontFamily("Tahoma")); FontFamilies.Add(new FontFamily("Times New Roman")); FontFamilies.Add(new FontFamily("Trebuchet MS")); FontFamilies.Add(new FontFamily("Verdana")); _SelectedPaperX = 290; // 210; _SelectedPaperY = 200; // 297; updatePixelsFromMillimeters(); this.DataContext = this; }
/// <summary> /// Gets the HTML style from global styles. /// This isn't supported by AODL yet. But if /// OpenDocument text documents are loaded, /// this could be. /// </summary> /// <returns>The style from Global Styles</returns> private string GetHtmlStyleFromGlobalStyles() { try { string style = "style=\""; if (this.Document is AODL.Document.TextDocuments.TextDocument) { XmlNode styleNode = ((AODL.Document.TextDocuments.TextDocument) this.Document).DocumentStyles.Styles.SelectSingleNode( "//office:styles/style:style[@style:name='" + this.StyleName + "']", this.Document.NamespaceManager); if (styleNode == null) { styleNode = ((AODL.Document.TextDocuments.TextDocument) this.Document).DocumentStyles.Styles.SelectSingleNode( "//office:styles/style:style[@style:name='" + ((ParagraphStyle)this.Style).ParentStyle + "']", this.Document.NamespaceManager); } if (styleNode != null) { XmlNode paraPropNode = styleNode.SelectSingleNode("style:paragraph-properties", this.Document.NamespaceManager); //Last change via parent style XmlNode parentNode = styleNode.SelectSingleNode("@style:parent-style-name", this.Document.NamespaceManager); XmlNode paraPropNodeP = null; XmlNode parentStyleNode = null; if (parentNode != null) { if (parentNode.InnerText != null) { //Console.WriteLine("Parent-Style-Name: {0}", parentNode.InnerText); parentStyleNode = ((AODL.Document.TextDocuments.TextDocument) this.Document).DocumentStyles.Styles.SelectSingleNode( "//office:styles/style:style[@style:name='" + parentNode.InnerText + "']", this.Document.NamespaceManager); if (parentStyleNode != null) { paraPropNodeP = parentStyleNode.SelectSingleNode("style:paragraph-properties", this.Document.NamespaceManager); } } } //Check first parent style paragraph properties if (paraPropNodeP != null) { //Console.WriteLine("ParentStyleNode: {0}", parentStyleNode.OuterXml); string alignMent = this.GetGlobalStyleElement(paraPropNodeP, "@fo:text-align"); if (alignMent != null) { alignMent = alignMent.ToLower().Replace("end", "right"); if (alignMent.ToLower() == "center" || alignMent.ToLower() == "right") { style += "text-align: " + alignMent + "; "; } } string lineSpace = this.GetGlobalStyleElement(paraPropNodeP, "@fo:line-height"); if (lineSpace != null) { style += "line-height: " + lineSpace + "; "; } string marginTop = this.GetGlobalStyleElement(paraPropNodeP, "@fo:margin-top"); if (marginTop != null) { style += "margin-top: " + marginTop + "; "; } string marginBottom = this.GetGlobalStyleElement(paraPropNodeP, "@fo:margin-bottom"); if (marginBottom != null) { style += "margin-bottom: " + marginBottom + "; "; } string marginLeft = this.GetGlobalStyleElement(paraPropNodeP, "@fo:margin-left"); if (marginLeft != null) { style += "margin-left: " + marginLeft + "; "; } string marginRight = this.GetGlobalStyleElement(paraPropNodeP, "@fo:margin-right"); if (marginRight != null) { style += "margin-right: " + marginRight + "; "; } } //Check paragraph properties, maybe parents style is overwritten or extended if (paraPropNode != null) { string alignMent = this.GetGlobalStyleElement(paraPropNode, "@fo:text-align"); if (alignMent != null) { alignMent = alignMent.ToLower().Replace("end", "right"); if (alignMent.ToLower() == "center" || alignMent.ToLower() == "right") { style += "text-align: " + alignMent + "; "; } } string lineSpace = this.GetGlobalStyleElement(paraPropNode, "@fo:line-height"); if (lineSpace != null) { style += "line-height: " + lineSpace + "; "; } string marginTop = this.GetGlobalStyleElement(paraPropNode, "@fo:margin-top"); if (marginTop != null) { style += "margin-top: " + marginTop + "; "; } string marginBottom = this.GetGlobalStyleElement(paraPropNode, "@fo:margin-bottom"); if (marginBottom != null) { style += "margin-bottom: " + marginBottom + "; "; } string marginLeft = this.GetGlobalStyleElement(paraPropNode, "@fo:margin-left"); if (marginLeft != null) { style += "margin-left: " + marginLeft + "; "; } string marginRight = this.GetGlobalStyleElement(paraPropNode, "@fo:margin-right"); if (marginRight != null) { style += "margin-right: " + marginRight + "; "; } } XmlNode textPropNode = styleNode.SelectSingleNode("style:text-properties", this.Document.NamespaceManager); XmlNode textPropNodeP = null; if (parentStyleNode != null) { textPropNodeP = parentStyleNode.SelectSingleNode("style:text-properties", this.Document.NamespaceManager); } //Check first text properties of parent style if (textPropNodeP != null) { string fontSize = this.GetGlobalStyleElement(textPropNodeP, "@fo:font-size"); if (fontSize != null) { style += "font-size: " + FontFamilies.PtToPx(fontSize) + "; "; } string italic = this.GetGlobalStyleElement(textPropNodeP, "@fo:font-style"); if (italic != null) { style += "font-size: italic; "; } string bold = this.GetGlobalStyleElement(textPropNodeP, "@fo:font-weight"); if (bold != null) { style += "font-weight: bold; "; } string underline = this.GetGlobalStyleElement(textPropNodeP, "@style:text-underline-style"); if (underline != null) { style += "text-decoration: underline; "; } string fontName = this.GetGlobalStyleElement(textPropNodeP, "@style:font-name"); if (fontName != null) { style += "font-family: " + FontFamilies.HtmlFont(fontName) + "; "; } string color = this.GetGlobalStyleElement(textPropNodeP, "@fo:color"); if (color != null) { style += "color: " + color + "; "; } } //Check now text properties of style, maybe some setting are overwritten or extended if (textPropNode != null) { string fontSize = this.GetGlobalStyleElement(textPropNode, "@fo:font-size"); if (fontSize != null) { style += "font-size: " + FontFamilies.PtToPx(fontSize) + "; "; } string italic = this.GetGlobalStyleElement(textPropNode, "@fo:font-style"); if (italic != null) { style += "font-size: italic; "; } string bold = this.GetGlobalStyleElement(textPropNode, "@fo:font-weight"); if (bold != null) { style += "font-weight: bold; "; } string underline = this.GetGlobalStyleElement(textPropNode, "@style:text-underline-style"); if (underline != null) { style += "text-decoration: underline; "; } string fontName = this.GetGlobalStyleElement(textPropNode, "@style:font-name"); if (fontName != null) { style += "font-family: " + FontFamilies.HtmlFont(fontName) + "; "; } string color = this.GetGlobalStyleElement(textPropNode, "@fo:color"); if (color != null) { style += "color: " + color + "; "; } } } } if (!style.EndsWith("; ")) { style = ""; } else { style += "\""; } return(style); } catch (Exception) { //unhandled, only a paragraph style wouldn't be displayed correct //Console.WriteLine("GetHtmlStyleFromGlobalStyles(): {0}", ex.Message); } return(""); }
public override void LoadAsync() { //Task.Factory.StartNew(() => // { lock (UserVMs) { var users = RoomClient.GetRoomUsers(RoomVM.Id); if (users != null && users.Length > 0) { foreach (var user in users) { UserEntered(user, false); } } } var micUsers = RoomClient.GetMicUsers(RoomVM.Id, MicType.Public); if (micUsers != null && micUsers.Count > 0) { if (micUsers.ContainsKey(0) && micUsers[0].MicStatus != MicStatusMessage.MicStatus_Off) { FirstMicUserVM = UserVMs.FirstOrDefault(u => u.Id == micUsers[0].UserId); FirstMicUserVM.OnMic(MicType.Public, 0, micUsers[0].StreamGuid, micUsers[0].MicStatus); if ((FirstMicUserVM.MicStatus & MicStatusMessage.MicStatus_Audio) != MicStatusMessage.MicStatus_Off) { StartAudioPlaying(FirstMicUserVM.Id); } } if (micUsers.ContainsKey(1) && micUsers[1].MicStatus != MicStatusMessage.MicStatus_Off) { SecondMicUserVM = UserVMs.FirstOrDefault(u => u.Id == micUsers[1].UserId); SecondMicUserVM.OnMic(MicType.Public, 1, micUsers[1].StreamGuid, micUsers[1].MicStatus); if ((SecondMicUserVM.MicStatus & MicStatusMessage.MicStatus_Audio) != MicStatusMessage.MicStatus_Off) { StartAudioPlaying(SecondMicUserVM.Id); } } if (micUsers.ContainsKey(2) && micUsers[2].MicStatus != MicStatusMessage.MicStatus_Off) { ThirdMicUserVM = UserVMs.FirstOrDefault(u => u.Id == micUsers[2].UserId); ThirdMicUserVM.OnMic(MicType.Public, 2, micUsers[2].StreamGuid, micUsers[2].MicStatus); if ((ThirdMicUserVM.MicStatus & MicStatusMessage.MicStatus_Audio) != MicStatusMessage.MicStatus_Off) { StartAudioPlaying(ThirdMicUserVM.Id); } } } micUsers = RoomClient.GetMicUsers(RoomVM.Id, MicType.Private); if (micUsers != null && micUsers.Count > 0) { foreach (var mic in micUsers.Values) { if (mic.MicStatus != MicStatusMessage.MicStatus_Off) { var uvm = UserVMs.FirstOrDefault(u => u.Id == mic.UserId); if (uvm != null) { PrivateMicUserVMs.Add(uvm); uvm.OnMic(MicType.Private, mic.MicIndex, mic.StreamGuid, mic.MicStatus); if ((uvm.MicStatus & MicStatusMessage.MicStatus_Audio) != MicStatusMessage.MicStatus_Off) { StartAudioPlaying(uvm.Id); } } } } } micUsers = RoomClient.GetMicUsers(RoomVM.Id, MicType.Secret); if (micUsers != null && micUsers.Count > 0) { foreach (var mic in micUsers.Values) { if (mic.MicStatus != MicStatusMessage.MicStatus_Off) { var uvm = UserVMs.FirstOrDefault(u => u.Id == mic.UserId); if (uvm != null) { SecretMicUserVMs.Add(uvm); uvm.OnMic(MicType.Secret, mic.MicIndex, mic.StreamGuid, mic.MicStatus); if ((uvm.MicStatus & MicStatusMessage.MicStatus_Audio) != MicStatusMessage.MicStatus_Off) { StartAudioPlaying(uvm.Id); } } } } } RoomMessage msg = RoomClient.GetRoomMessage(RoomMessageType.GiftMessage); if (msg != null) { UserViewModel sender = null; UserViewModel receiver = null; lock (UserVMs) { sender = UserVMs.FirstOrDefault(u => u.Id == msg.SenderId); if (sender == null) { sender = ApplicationVM.LocalCache.AllUserVMs[msg.SenderId]; if (sender == null) { var usr = RoomClient.GetUser(msg.SenderId); if (usr != null) { sender = new UserViewModel(usr); sender.Initialize(); ApplicationVM.LocalCache.AllUserVMs[msg.SenderId] = sender; } } else { if (!sender.IsInitialized) { sender.Initialize(); } } } receiver = UserVMs.FirstOrDefault(u => u.Id == msg.ReceiverId); if (receiver == null) { receiver = ApplicationVM.LocalCache.AllUserVMs[msg.ReceiverId]; if (receiver == null) { var usr = RoomClient.GetUser(msg.ReceiverId); if (usr != null) { receiver = new UserViewModel(usr); receiver.Initialize(); ApplicationVM.LocalCache.AllUserVMs[msg.ReceiverId] = receiver; } } else { if (!receiver.IsInitialized) { receiver.Initialize(); } } } } GiftViewModel gift = ApplicationVM.LocalCache.AllGiftVMs.FirstOrDefault(g => g.Id == msg.ItemId); if (sender != null && receiver != null && gift != null) { string header = "<img title='" + sender.RoleVM.Name + "' src='" + sender.ImageVM.StaticImageFile + "'><u style='color:gold;margin-right:10px'><span onclick='window.external.SelectUser(" + sender.Id + ")'" + " oncontextmenu='window.external.SelectUser(" + sender.Id + ")'/>" + sender.NickName + "(" + sender.Id + ")" + "</span></u></img> 送给 " + "<img title='" + receiver.RoleVM.Name + "' src='" + receiver.ImageVM.StaticImageFile + "'><u style='color:purple;margin-left:10px;margin-right:10px'><span onclick='window.external.SelectUser(" + receiver.Id + ")'" + "oncontextmenu='window.external.SelectUser(" + receiver.Id + ")'/>" + receiver.NickName + "(" + receiver.Id + ")" + "</span></u></img>"; string htmlmsg = string.Empty; htmlmsg += "<img style='margin-left:20px;margin-right:20px;' src='" + gift.ImageVM.DynamicImageFile + "'/>"; htmlmsg += header + msg.Count + gift.Unit + gift.Name + "<span style='color:blue'>" + msg.Time + "</span>"; CallJavaScript("ScrollMessage", htmlmsg); } } XmlLanguage enus = XmlLanguage.GetLanguage("en-us"); XmlLanguage zhcn = XmlLanguage.GetLanguage("zh-cn"); string fontname = ""; foreach (FontFamily fontfamily in Fonts.SystemFontFamilies) { if (fontfamily.FamilyNames.ContainsKey(zhcn)) { fontfamily.FamilyNames.TryGetValue(zhcn, out fontname); FontFamilies.Insert(0, fontname); } else if (fontfamily.FamilyNames.ContainsKey(enus)) { fontfamily.FamilyNames.TryGetValue(enus, out fontname); FontFamilies.Add(fontname); } } FontSizes.Add(14); FontSizes.Add(16); FontSizes.Add(18); FontSizes.Add(20); FontSizes.Add(22); FontSizes.Add(24); FontSizes.Add(28); FontSizes.Add(32); FontSizes.Add(36); CallJavaScript("InitUsers", UsersJson); CallJavaScript("InitFonts", FontFamiliesJson, FontSizesJson); CallJavaScript("InitStamp", StampImagesJson); for (int i = 0; i < MotionImagesJson.Count; i++) { CallJavaScript("InitFaceTab", MotionImagesJson[i], i == MotionImagesJson.Count - 1); } CallJavaScript("InitMoneyForHorn", ApplicationVM.LocalCache.HornMsgMoney, ApplicationVM.LocalCache.HallHornMsgMoney, ApplicationVM.LocalCache.GlobalHornMsgMoney); int scoreToMoney = 0; if (ApplicationVM.LocalCache.AllExchangeRateVMs.Count > 0) { try { var exchangeVM = ApplicationVM.LocalCache.AllExchangeRateVMs.OrderBy(r => r).Where(r => Convert.ToDateTime(r.ValidTime) >= (DateTime.Now)).ToList().FirstOrDefault(); if (exchangeVM != null) { scoreToMoney = exchangeVM.ScoreToMoney; } } catch (Exception ex) { } } CallJavaScript("InitExchangeRate", scoreToMoney); //}); }
private void ReadBytes(Bytes bytes) { byte[] byteArray = bytes.ByteArray; _height = BitConverter.ToUInt16(byteArray, 0); SetOptionsValue(bytes.Get(2, 2)); _color = _doc.Workbook.Palette.GetColor(BitConverter.ToUInt16(byteArray, 4)); _weight = FontWeightConverter.Convert(BitConverter.ToUInt16(byteArray, 6)); _escapement = (EscapementTypes) BitConverter.ToUInt16(byteArray, 8); _underline = (UnderlineTypes) byteArray[10]; _fontFamily = (FontFamilies) byteArray[11]; _characterSet = (CharacterSets) byteArray[12]; //skip byte index 13 _fontName = UnicodeBytes.Read(bytes.Get(14, bytes.Length - 14), 8); }
/// <summary> /// Gets the HTML style from global styles. /// This isn't supported by AODL yet. But if /// OpenDocument text documents are loaded, /// this could be. /// </summary> /// <returns>The style from Global Styles</returns> private string GetHtmlStyleFromGlobalStyles() { try { string style = "style=\""; if (Document is TextDocument) { XElement styleNode = ((TextDocument)Document).DocumentStyles.Styles.Descendants(Ns.Office + "styles") .Elements(Ns.Style + "style") .Where(e => string.Equals((string)e.Attribute(Ns.Style + "name"), StyleName)). FirstOrDefault(); if (styleNode == null) { styleNode = ((TextDocument)Document).DocumentStyles.Styles.Descendants(Ns.Office + "styles") .Elements(Ns.Style + "style") .Where( e => string.Equals((string)e.Attribute(Ns.Style + "name"), ((ParagraphStyle)Style).ParentStyle)) .FirstOrDefault(); } if (styleNode != null) { XElement paraPropNode = styleNode.Element(Ns.Style + "paragraph-properties"); //Last change via parent style XAttribute parentNode = styleNode.Attribute(Ns.Style + "parent-style-name"); XElement paraPropNodeP = null; XElement parentStyleNode = null; if (parentNode != null) { if (parentNode.Value != null) { //Console.WriteLine("Parent-Style-Name: {0}", parentNode.InnerText); parentStyleNode = ((TextDocument)Document).DocumentStyles.Styles.Descendants(Ns.Office + "styles") .Elements(Ns.Style + "style") .Where( e => string.Equals((string)e.Attribute(Ns.Style + "name"), parentNode.Value)). FirstOrDefault(); if (parentStyleNode != null) { paraPropNodeP = parentStyleNode.Element(Ns.Style + "paragraph-properties"); } } } //Check first parent style paragraph properties if (paraPropNodeP != null) { //Console.WriteLine("ParentStyleNode: {0}", parentStyleNode.OuterXml); string alignMent = (string)paraPropNodeP.Attribute(Ns.Fo + "text-align"); if (alignMent != null) { alignMent = alignMent.ToLower().Replace("end", "right"); if (alignMent.ToLower() == "center" || alignMent.ToLower() == "right") { style += "text-align: " + alignMent + "; "; } } string lineSpace = (string)paraPropNodeP.Attribute(Ns.Fo + "line-height"); if (lineSpace != null) { style += "line-height: " + lineSpace + "; "; } string marginTop = (string)paraPropNodeP.Attribute(Ns.Fo + "margin-top"); if (marginTop != null) { style += "margin-top: " + marginTop + "; "; } string marginBottom = (string)paraPropNodeP.Attribute(Ns.Fo + "margin-bottom"); if (marginBottom != null) { style += "margin-bottom: " + marginBottom + "; "; } string marginLeft = (string)paraPropNodeP.Attribute(Ns.Fo + "margin-left"); if (marginLeft != null) { style += "margin-left: " + marginLeft + "; "; } string marginRight = (string)paraPropNodeP.Attribute(Ns.Fo + "margin-right"); if (marginRight != null) { style += "margin-right: " + marginRight + "; "; } } //Check paragraph properties, maybe parents style is overwritten or extended if (paraPropNode != null) { string alignMent = (string)paraPropNode.Attribute(Ns.Fo + "text-align"); if (alignMent != null) { alignMent = alignMent.ToLower().Replace("end", "right"); if (alignMent.ToLower() == "center" || alignMent.ToLower() == "right") { style += "text-align: " + alignMent + "; "; } } string lineSpace = (string)paraPropNode.Attribute(Ns.Fo + "line-height"); if (lineSpace != null) { style += "line-height: " + lineSpace + "; "; } string marginTop = (string)paraPropNode.Attribute(Ns.Fo + "margin-top"); if (marginTop != null) { style += "margin-top: " + marginTop + "; "; } string marginBottom = (string)paraPropNode.Attribute(Ns.Fo + "margin-bottom"); if (marginBottom != null) { style += "margin-bottom: " + marginBottom + "; "; } string marginLeft = (string)paraPropNode.Attribute(Ns.Fo + "margin-left"); if (marginLeft != null) { style += "margin-left: " + marginLeft + "; "; } string marginRight = (string)paraPropNode.Attribute(Ns.Fo + "margin-right"); if (marginRight != null) { style += "margin-right: " + marginRight + "; "; } } XElement textPropNode = styleNode.Element(Ns.Style + "text-properties"); XElement textPropNodeP = null; if (parentStyleNode != null) { textPropNodeP = parentStyleNode.Element(Ns.Style + "text-properties"); } //Check first text properties of parent style if (textPropNodeP != null) { string fontSize = (string)textPropNodeP.Attribute(Ns.Fo + "font-size"); if (fontSize != null) { style += "font-size: " + FontFamilies.PtToPx(fontSize) + "; "; } string italic = (string)textPropNodeP.Attribute(Ns.Fo + "font-style"); if (italic != null) { style += "font-size: italic; "; } string bold = (string)textPropNodeP.Attribute(Ns.Fo + "font-weight"); if (bold != null) { style += "font-weight: bold; "; } string underline = (string)textPropNodeP.Attribute(Ns.Style + "text-underline-style"); if (underline != null) { style += "text-decoration: underline; "; } string fontName = (string)textPropNodeP.Attribute(Ns.Style + "font-name"); if (fontName != null) { style += "font-family: " + FontFamilies.HtmlFont(fontName) + "; "; } string color = (string)textPropNodeP.Attribute(Ns.Fo + "color"); if (color != null) { style += "color: " + color + "; "; } } //Check now text properties of style, maybe some setting are overwritten or extended if (textPropNode != null) { string fontSize = (string)textPropNode.Attribute(Ns.Fo + "font-size"); if (fontSize != null) { style += "font-size: " + FontFamilies.PtToPx(fontSize) + "; "; } string italic = (string)textPropNode.Attribute(Ns.Fo + "font-style"); if (italic != null) { style += "font-size: italic; "; } string bold = (string)textPropNode.Attribute(Ns.Fo + "font-weight"); if (bold != null) { style += "font-weight: bold; "; } string underline = (string)textPropNode.Attribute(Ns.Style + "text-underline-style"); if (underline != null) { style += "text-decoration: underline; "; } string fontName = (string)textPropNode.Attribute(Ns.Style + "font-name"); if (fontName != null) { style += "font-family: " + FontFamilies.HtmlFont(fontName) + "; "; } string color = (string)textPropNode.Attribute(Ns.Fo + "color"); if (color != null) { style += "color: " + color + "; "; } } } } if (!style.EndsWith("; ")) { style = ""; } else { style += "\""; } return(style); } catch (Exception) { //unhandled, only a paragraph style wouldn't be displayed correct //Console.WriteLine("GetHtmlStyleFromGlobalStyles(): {0}", ex.Message); } return(""); }
/// <summary> /// Gets the text style as HTML. /// </summary> /// <param name="textStyle">The text style.</param> /// <returns></returns> public string GetTextStyleAsHtml(TextProperties textStyle) { string style = "style=\""; try { if (textStyle != null) { if (textStyle.Italic != null) { if (textStyle.Italic != "normal") { style += "font-style: italic; "; } } if (textStyle.Bold != null) { style += "font-weight: " + textStyle.Bold + "; "; } if (textStyle.Underline != null) { style += "text-decoration: underline; "; } if (textStyle.TextLineThrough != null) { style += "text-decoration: line-through; "; } if (textStyle.FontName != null) { style += "font-family: " + FontFamilies.HtmlFont(textStyle.FontName) + "; "; } if (textStyle.FontSize != null) { style += "font-size: " + FontFamilies.PtToPx(textStyle.FontSize) + "; "; } if (textStyle.FontColor != null) { style += "color: " + textStyle.FontColor + "; "; } if (textStyle.BackgroundColor != null) { style += "background-color: " + textStyle.BackgroundColor + "; "; } } } catch (Exception ex) { throw new AODLException("Exception while trying to build a HTML style string from a TextStyle.", ex); } if (!style.EndsWith("; ")) { style = ""; } else { style += "\""; } return(style); }
/// <summary> /// Gets a collection of fonts based on the specified criteria. /// </summary> /// <param name="families">Bit Field representing which font families to retrieve.</param> /// <param name="pitch">Specify the desired pitch.</param> /// <param name="charset">Specify the desired character set.</param> /// <param name="weight">Specify the desired weight.</param> /// <param name="Script">Specify the desired script(s) (this can be a String or an array of Strings).</param> /// <param name="Style">Specify the desired style(s) (this can be a String or an array of Strings).</param> /// <returns></returns> public static FontCollection GetFonts(FontFamilies families = FontFamilies.DontCare, FontPitch pitch = FontPitch.Default, FontCharSet charset = FontCharSet.Default, FontWeight weight = FontWeight.DontCare, object Script = null, object Style = null) { IntPtr hdc; var fonts = new List <ENUMLOGFONTEX>(); var lf = new LOGFONT(); string s; MemPtr mm = new MemPtr(); string[] wscript; string[] wstyle; if (Script is null) { wscript = new[] { "Western" }; } else if (Script is string) { wscript = new[] { (string)(Script) }; } else if (Script is string[]) { wscript = (string[])Script; } else { throw new ArgumentException("Invalid parameter type for Script"); } if (Style is null) { wstyle = new[] { "", "Normal", "Regular" }; } else if (Style is string) { wstyle = new[] { (string)(Style) }; } else if (Style is string[]) { wstyle = (string[])Style; } else { throw new ArgumentException("Invalid parameter type for Style"); } lf.lfCharSet = (byte)charset; lf.lfFaceName = ""; mm.Alloc(Marshal.SizeOf(lf)); mm.FromStruct(lf); hdc = User32.CreateDC("DISPLAY", null, IntPtr.Zero, IntPtr.Zero); int e; bool bo = false; e = EnumFontFamiliesEx(hdc, mm, (ref ENUMLOGFONTEX lpelfe, IntPtr lpntme, uint FontType, IntPtr lParam) => { int z; if (fonts is null) { z = 0; } else { z = fonts.Count; } // make sure it's the normal, regular version bo = false; foreach (var y in wstyle) { if ((y.ToLower() ?? "") == (lpelfe.elfStyle.ToLower() ?? "")) { bo = true; break; } } if (bo == false) { return(1); } bo = false; foreach (var y in wscript) { if ((y.ToLower() ?? "") == (lpelfe.elfScript.ToLower() ?? "")) { bo = true; break; } } if (bo == false) { return(1); } bo = false; if (weight != FontWeight.DontCare && lpelfe.elfLogFont.lfWeight != (int)weight) { return(1); } // we don't really need two of the same font. if (z > 0) { if ((lpelfe.elfFullName ?? "") == (fonts[z - 1].elfFullName ?? "")) { return(1); } } // the @ indicates a vertical writing font which we definitely do not want. if (lpelfe.elfFullName.Substring(0, 1) == "@") { return(1); } if (!CheckFamily(lpelfe.elfLogFont, families)) { return(1); } // lpelfe.elfLogFont.lfCharSet = charset // If (lpelfe.elfLogFont.lfCharSet <> charset) Then Return 1 if (pitch != FontPitch.Default && (lpelfe.elfLogFont.lfPitchAndFamily & 3) != (int)pitch) { return(1); } fonts.Add(lpelfe); return(1); }, IntPtr.Zero, 0U); User32.DeleteDC(hdc); mm.Free(); if (e == 0) { e = User32.GetLastError(); s = NativeError.Message; } FontInfo nf; var ccol = new FontCollection(); foreach (var f in fonts) { nf = new FontInfo(f); ccol.Add(nf); } ccol.Sort(); return(ccol); }
/// <summary> /// Gets the text style as HTML. /// </summary> /// <param name="textStyle">The text style.</param> /// <returns></returns> public string GetTextStyleAsHtml(TextProperties textStyle) { string style = "style=\""; try { if (textStyle != null) { if (textStyle.Italic != null) { if (textStyle.Italic != "normal") { style += "font-style: italic; "; } } if (textStyle.Bold != null) { style += "font-weight: " + textStyle.Bold + "; "; } if (textStyle.Underline != null) { style += "text-decoration: underline; "; } if (textStyle.TextLineThrough != null) { style += "text-decoration: line-through; "; } if (textStyle.FontName != null) { style += "font-family: " + FontFamilies.HtmlFont(textStyle.FontName) + "; "; } if (textStyle.FontSize != null) { style += "font-size: " + FontFamilies.PtToPx(textStyle.FontSize) + "; "; } if (textStyle.FontColor != null) { style += "color: " + textStyle.FontColor + "; "; } if (textStyle.BackgroundColor != null) { style += "background-color: " + textStyle.BackgroundColor + "; "; } } } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML style string from a TextStyle."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; if (textStyle != null) { if (textStyle.Node != null) { exception.Node = textStyle.Node; } } throw exception; } if (!style.EndsWith("; ")) { style = ""; } else { style += "\""; } return(style); }
private void SetDefaults() { _height = 200; _italic = false; _underlined = false; _struckOut = false; _color = new Color(32767); _weight = FontWeight.Normal; _escapement = EscapementTypes.Default; _underline = UnderlineTypes.Default; _fontFamily = FontFamilies.Default; _characterSet = CharacterSets.Default; _notUsed = 0; _fontName = "Arial"; OnChange(); }
public bool IsFontFamilyValid(string fontFamily) => fontFamily != null && FontFamilies.Contains(fontFamily, StringComparer.OrdinalIgnoreCase);