private bool RegisterFont(string fontName) { if (!m_FontMappings.HasFontName(fontName)) { return(false); } if (!FontFactory.Contains(fontName)) { FontFactory.Register(m_FontMappings.GetFontFileName(fontName), fontName); } return(true); }
/// <summary> /// Loads the default text font. /// </summary> private void LoadDefaultTextFont() { try { if (this._styleDocument != null && this._styleDocument.Styles != null) { XmlNode defaultParagraphStyle = this._styleDocument.Styles.SelectSingleNode( "//style:default-style[@style:family='paragraph']", this._document.NamespaceManager); if (defaultParagraphStyle != null) { XmlNode defaultTextProperties = defaultParagraphStyle.SelectSingleNode("style:text-properties", this._document.NamespaceManager); if (defaultTextProperties != null) { XmlNode fontName = defaultTextProperties.SelectSingleNode("@style:font-name", this._document.NamespaceManager); if (fontName != null && fontName.InnerText != null) { if (FontFactory.Contains(fontName.InnerText)) { this._defaultTextFont = FontFactory.GetFont(fontName.InnerText); } else { // todo: do it better! this._defaultTextFont = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12.0f); } } } } } } catch (Exception) { throw; } }
/// <summary> /// Loads the default text font. /// </summary> private void LoadDefaultTextFont() { try { XNamespace styleNs = "urn:oasis:names:tc:opendocument:xmlns:style:1.0"; if (this._styleDocument != null && this._styleDocument.Styles != null) { XElement defaultParagraphStyle = this._styleDocument.Styles.Descendants(styleNs + "default-style") .Where(e => string.Equals((string)e.Attribute(styleNs + "family"), "paragraph")).FirstOrDefault(); if (defaultParagraphStyle != null) { XElement defaultTextProperties = defaultParagraphStyle.Element(styleNs + "text-properties"); if (defaultTextProperties != null) { XAttribute fontName = defaultTextProperties.Attribute(styleNs + "font-name"); if (fontName != null && fontName.Value != null) { if (FontFactory.Contains(fontName.Value)) { this._defaultTextFont = FontFactory.GetFont(fontName.Value); } else { // todo: do it better! this._defaultTextFont = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12.0f); } } } } } } catch (Exception) { throw; } }
/// <summary> /// Gets the font object. /// </summary> /// <param name="textProperties">The text properties.</param> /// <returns>The font object</returns> public static Font GetFont(TextProperties textProperties) { try { Font font = new Font(); if (textProperties != null) { string fontName = ""; if (textProperties.FontName != null) { fontName = textProperties.FontName; } else { fontName = DefaultDocumentStyles.Instance().DefaultTextFont.Familyname; } if (FontFactory.Contains(fontName)) { string colorStr = "#000000"; int iTextFontStyle = 0; //normal int bold = (textProperties.Bold != null && textProperties.Bold.ToLower() == "bold") ? 1 : 0; int italic = (textProperties.Italic != null && textProperties.Bold.ToLower() == "italic") ? 1 : 0; int textLineThrough = (textProperties.TextLineThrough != null) ? 1 : 0; int underline = (textProperties.Underline != null) ? 1 : 0; float size = 12.0f; // up to now, standard todo: do it better if (textProperties.FontSize != null) { if (textProperties.FontSize.ToLower().EndsWith("pt")) { try { size = (float)Convert.ToDouble(textProperties.FontSize.ToLower().Replace("pt", "")); } catch (Exception) { throw; } } } if (textProperties.FontColor != null) { colorStr = textProperties.FontColor; } if (bold == 1 && italic == 1) { iTextFontStyle = Font.BOLDITALIC; } if (bold == 1 && italic == 0) { iTextFontStyle = Font.BOLD; } if (bold == 0 && italic == 1) { iTextFontStyle = Font.ITALIC; } // TODO: underline strike through iTextSharp.text.Color color = RGBColorConverter.GetColorFromHex(colorStr); font = FontFactory.GetFont(fontName, size, iTextFontStyle, color); } } return(font); } catch (Exception) { throw; } }