/// <summary> /// Creates a typeface. /// </summary> public static Typeface CreateTypeface(XFontFamily family, XFontStyle style) { FontStyle fontStyle = FontStyleFromStyle(style); FontWeight fontWeight = FontWeightFromStyle(style); Typeface typeface = new Typeface(family.wpfFamily, fontStyle, fontWeight, FontStretches.Normal); return typeface; }
/// <summary> /// New... /// </summary> public OpenTypeDescriptor(string fontDescriptorKey, string name, XFontStyle stlye, OpenTypeFontface fontface, XPdfFontOptions options) : base(fontDescriptorKey) { FontFace = fontface; FontName = name; Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class. /// </summary> /// <param name="familyName">Name of the font family.</param> /// <param name="emSize">The em size.</param> /// <param name="style">The font style.</param> public XFont(string familyName, double emSize, XFontStyle style) { this.familyName = familyName; this.size = emSize; this.style = style; this.pdfOptions = new XPdfFontOptions(); Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class from a System.DrawingCore.FontFamily. /// </summary> /// <param name="fontFamily">The System.DrawingCore.FontFamily.</param> /// <param name="emSize">The em size.</param> /// <param name="style">The font style.</param> /// <param name="pdfOptions">Additional PDF options.</param> public XFont(UwpFontFamily fontFamily, double emSize, XFontStyle style, XPDFFontOptions pdfOptions) { _familyName = fontFamily.Source; _gdiFontFamily = fontFamily; _emSize = emSize; _style = style; _pdfOptions = pdfOptions; InitializeFromGdi(); }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class from a System.DrawingCore.FontFamily. /// </summary> /// <param name="fontFamily">The System.DrawingCore.FontFamily.</param> /// <param name="emSize">The em size.</param> /// <param name="style">The font style.</param> /// <param name="pdfOptions">Additional PDF options.</param> public XFont(GdiFontFamily fontFamily, double emSize, XFontStyle style, XPDFFontOptions pdfOptions) { FamilyName = fontFamily.Name; GdiFontFamily = fontFamily; Size = emSize; Style = style; _pdfOptions = pdfOptions; InitializeFromGdi(); }
internal static WpfTypeface TryCreateTypeface(string name, XFontStyle style, out WpfFontFamily fontFamily) { if (Singleton._fontFamilies.TryGetValue(name, out fontFamily)) { WpfTypeface typeface = FontHelper.CreateTypeface(fontFamily, style); return(typeface); } return(null); }
internal static Typeface TryFindTypeface(string name, XFontStyle style, out FontFamily fontFamily) { if (s_global.fontFamilies.TryGetValue(name, out fontFamily)) { Typeface typeface = FontHelper.CreateTypeface(fontFamily, style); return(typeface); } return(null); }
/// <summary> /// Create a WPF GlyphTypeface and retrieve font data from it. /// </summary> internal static XFontSource CreateFontSource(string familyName, FontResolvingOptions fontResolvingOptions, out WpfFontFamily wpfFontFamily, out WpfTypeface wpfTypeface, out WpfGlyphTypeface wpfGlyphTypeface, string typefaceKey) { if (string.IsNullOrEmpty(typefaceKey)) { typefaceKey = XGlyphTypeface.ComputeKey(familyName, fontResolvingOptions); } XFontStyle style = fontResolvingOptions.FontStyle; #if DEBUG if (StringComparer.OrdinalIgnoreCase.Compare(familyName, "Segoe UI Semilight") == 0 && (style & XFontStyle.BoldItalic) == XFontStyle.Italic) { familyName.GetType(); } #endif // Use WPF technique to create font data. wpfTypeface = XPrivateFontCollection.TryCreateTypeface(familyName, style, out wpfFontFamily); #if DEBUG__ if (wpfTypeface != null) { WpfGlyphTypeface glyphTypeface; ICollection <WpfTypeface> list = wpfFontFamily.GetTypefaces(); foreach (WpfTypeface tf in list) { if (!tf.TryGetGlyphTypeface(out glyphTypeface)) { Debug - Break.Break(); } } //if (!WpfTypeface.TryGetGlyphTypeface(out glyphTypeface)) // throw new InvalidOperationException(PSSR.CannotGetGlyphTypeface(familyName)); } #endif if (wpfFontFamily == null) { wpfFontFamily = new WpfFontFamily(familyName); } if (wpfTypeface == null) { wpfTypeface = FontHelper.CreateTypeface(wpfFontFamily, style); } // Let WPF choose the right glyph typeface. if (!wpfTypeface.TryGetGlyphTypeface(out wpfGlyphTypeface)) { throw new InvalidOperationException(PSSR.CannotGetGlyphTypeface(familyName)); } // Get or create the font source and cache it unter the specified typeface key. XFontSource fontSource = XFontSource.GetOrCreateFromWpf(typefaceKey, wpfGlyphTypeface); return(fontSource); }
private static void SetText(XGraphics gfx, string text, XFontStyle style, double x, double y) { const string facename = "Calibri"; XStringFormat format = new XStringFormat(); XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode); XFont font = new XFont(facename, 8, style, options); gfx.DrawString(text, font, XBrushes.Black, x, y, format); }
public XTypefaceHack(string fontFamilyName, XFontStyle style, XFontWeight weight, XFontStretch stretch) { if (String.IsNullOrEmpty(fontFamilyName)) throw new ArgumentNullException("fontFamilyName"); this.fontFamilyName = fontFamilyName; this.style = style; this.weight = weight; this.stretch = stretch; }
internal XFont(string familyName, double emSize, XFontStyle style, XPdfFontOptions pdfOptions, XStyleSimulations styleSimulations) { _familyName = familyName; _emSize = emSize; _style = style; _pdfOptions = pdfOptions; OverrideStyleSimulations = true; StyleSimulations = styleSimulations; Initialize(); }
/// <summary> /// Gets the height, in font design units, of the em square for the specified style. /// </summary> public int GetEmHeight(XFontStyle style) { OpenTypeDescriptor descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(Name, style); int result = descriptor.UnitsPerEm; #if DEBUG_ int headValue = descriptor.FontFace.head.unitsPerEm; Debug.Assert(headValue == result); #endif return(result); }
public void AddFont(string familyName, XFontStyle style, string filename, bool simulateBold = false, bool simulateItalic = false) { using (var fileStream = new FileStream($"{fontsPath}{filename}", FileMode.Open, FileAccess.Read, FileShare.Read)) { int length = (int)fileStream.Length; byte[] data = new byte[length]; int read = fileStream.Read(data, 0, length); AddFont(familyName, style, data, simulateBold, simulateItalic); } }
/// <summary> /// Returns the cell descent, in design units, of the XFontFamily object of the specified style. /// </summary> public int GetCellDescent(XFontStyle style) { OpenTypeDescriptor descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(Name, style); int result = descriptor.Descender; #if DEBUG_ && GDI int gdiValue = _gdiFamily.GetCellDescent((FontStyle)style); Debug.Assert(gdiValue == result); #endif return(result); }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class. /// </summary> /// <param name="family">The font family.</param> /// <param name="emSize">The em size.</param> /// <param name="style">The font style.</param> /// <param name="pdfOptions">Additional PDF options.</param> public XFont(System.Drawing.FontFamily family, double emSize, XFontStyle style, XPdfFontOptions pdfOptions /*, * XPrivateFontCollection privateFontCollection*/ ) { this.familyName = null; this.gdifamily = family; this.emSize = emSize; this.style = style; this.pdfOptions = pdfOptions; Initialize(); }
// ----- AddString ---------------------------------------------------------------------------- /// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XPoint origin, XStringFormat format) { try { DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddString"); } catch { throw; } }
public XTypefaceHack(string fontFamilyName, XFontStyle style, XFontWeight weight, XFontStretch stretch) { if (String.IsNullOrEmpty(fontFamilyName)) { throw new ArgumentNullException("fontFamilyName"); } this.fontFamilyName = fontFamilyName; this.style = style; this.weight = weight; this.stretch = stretch; }
/// <summary> /// Creates a typeface. /// </summary> public static Typeface CreateTypeface(WpfFontFamily family, XFontStyle style) { // BUG: does not work with fonts that have others than the four default styles WpfFontStyle fontStyle = FontStyleFromStyle(style); WpfFontWeight fontWeight = FontWeightFromStyle(style); #if !SILVERLIGHT WpfTypeface typeface = new WpfTypeface(family, fontStyle, fontWeight, FontStretches.Normal); #else WpfTypeface typeface = null; #endif return(typeface); }
protected XFont CreateFont(string familyName, double emSize, XFontStyle style, XPdfFontOptions options) { XFont font; try { font = new XFont(familyName, emSize, style, options); } catch { font = new XFont("Courier", emSize, style, options); } return font; }
static XFont XFontFromCache(Font font, bool unicode, PdfFontEmbedding fontEmbedding) { XFont xFont = null; XPdfFontOptions options = null; options = new XPdfFontOptions(fontEmbedding, unicode); XFontStyle style = GetXStyle(font); xFont = new XFont(font.Name, font.Size, style, options); return(xFont); }
//private const string testFontName = "Times New Roman"; //const string testFontName = "Segoe Condensed"; //const string testFontName = "Frutiger LT 45 Light"; //static FontHelper() //{ // FontFamily fontFamily = new FontFamily(testFontName); // s_typefaces = new List<Typeface>(fontFamily.GetTypefaces()); //} //private static List<Typeface> s_typefaces; /// <summary> /// Creates a typeface. /// </summary> public static Typeface CreateTypeface(FontFamily family, XFontStyle style) { // BUG: does not work with fonts that have others than the four default styles FontStyle fontStyle = FontStyleFromStyle(style); FontWeight fontWeight = FontWeightFromStyle(style); Typeface typeface = new Typeface(family, fontStyle, fontWeight, FontStretches.Normal); //List<Typeface> typefaces = new List<Typeface>(fontFamily.GetTypefaces()); //typefaces.GetType(); //Typeface typeface = typefaces[3]; return(typeface); }
void DrawCodePage(XGraphics gfx, XPoint origin) { const double dx = 25; const double dy = 25; XFont labelFont = new XFont("Verdana", 10, XFontStyle.Bold); //XFont font = new XFont("Bauhaus", 16); XFont font = this.properties.Font1.Font; //XFont labelFont = font; //font = new XFont("Symbol", 16); Encoding encoding = Encoding.GetEncoding(1252); double asdf = XColors.LightGray.GS; //XBrush lighter = new XSolidBrush(XColor.FromGrayScale(XColor.LightGray.GS * 1.1)); XBrush lighter = new XSolidBrush(XColor.FromGrayScale(0.9)); XFontStyle style = font.Style; double lineSpace = font.GetHeight(gfx); int cellSpace = font.FontFamily.GetLineSpacing(style); int cellAscent = font.FontFamily.GetCellAscent(style); int cellDescent = font.FontFamily.GetCellDescent(style); int cellLeading = cellSpace - cellAscent - cellDescent; double ascent = lineSpace * cellAscent / cellSpace; double descent = lineSpace * cellDescent / cellSpace; double leading = lineSpace * cellLeading / cellSpace; double x = origin.X + dx; double y = origin.Y; //for (int idx = 0; idx < 16; idx++) // gfx.DrawString("x" + idx.ToString("X"), labelFont, XBrushes.DarkGray, x + idx * dx, y); for (int row = 0; row < 16; row++) { x = origin.X; y += dy; //gfx.DrawString(row.ToString("X") + "x", labelFont, XBrushes.DarkGray, x, y); for (int clm = 0; clm < 16; clm++) { x += dx; string glyph = encoding.GetString(new byte[1] { Convert.ToByte(row * 16 + clm) }); glyph += "!"; XSize size = gfx.MeasureString(glyph, font); gfx.DrawRectangle(XBrushes.LightGray, x, y - size.Height + descent, size.Width, size.Height); gfx.DrawRectangle(lighter, x, y - size.Height + descent, size.Width, leading); gfx.DrawRectangle(lighter, x, y, size.Width, descent); gfx.DrawString(glyph, font, XBrushes.Black, x, y); } } }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class from a System.Drawing.FontFamily. /// </summary> /// <param name="fontFamily">The System.Windows.Media.FontFamily.</param> /// <param name="emSize">The em size.</param> /// <param name="style">The font style.</param> /// <param name="pdfOptions">Additional PDF options.</param> public XFont(WpfFontFamily fontFamily, double emSize, XFontStyle style, XPdfFontOptions pdfOptions) { #if !SILVERLIGHT _familyName = fontFamily.FamilyNames[XmlLanguage.GetLanguage("en-US")]; #else // Best we can do in Silverlight. _familyName = fontFamily.Source; #endif _wpfFontFamily = fontFamily; _emSize = emSize; _style = style; _pdfOptions = pdfOptions; InitializeFromWpf(); }
protected XFont CreateFont(string familyName, double emSize, XFontStyle style, XPdfFontOptions options) { XFont font; try { font = new XFont(familyName, emSize, style, options); } catch { font = new XFont("Courier", emSize, style, options); } return(font); }
/// <summary> /// Determines whether the style is available as a glyph type face in the specified font family, i.e. the specified style is not simulated. /// </summary> public static bool IsStyleAvailable(XFontFamily family, XFontStyle style) { #if !SILVERLIGHT // TODOWPF: check for correctness FontDescriptor descriptor = FontDescriptorStock.Global.CreateDescriptor(family, style); XFontMetrics metrics = descriptor.FontMetrics; style &= XFontStyle.Regular | XFontStyle.Bold | XFontStyle.Italic | XFontStyle.BoldItalic; // same as XFontStyle.BoldItalic List <Typeface> typefaces = new List <Typeface>(family.wpfFamily.GetTypefaces()); foreach (Typeface typeface in typefaces) { bool available = false; GlyphTypeface glyphTypeface; if (typeface.TryGetGlyphTypeface(out glyphTypeface)) { #if DEBUG glyphTypeface.GetType(); #endif available = true; } #if DEBUG_ // int weightClass = typeface.Weight.ToOpenTypeWeight(); switch (style) { case XFontStyle.Regular: //if (typeface.TryGetGlyphTypeface(.Style == FontStyles.Normal && typeface.Weight== FontWeights.Normal.) break; case XFontStyle.Bold: break; case XFontStyle.Italic: break; case XFontStyle.BoldItalic: break; } #endif if (available) { return(true); } } return(false); #else return(true); // AGHACK #endif }
//public string GetName(int language); /// <summary> /// Indicates whether the specified FontStyle enumeration is available. /// </summary> public bool IsStyleAvailable(XFontStyle style) { XGdiFontStyle xStyle = ((XGdiFontStyle)style) & XGdiFontStyle.BoldItalic; #if CORE throw new InvalidOperationException("In CORE build it is the responsibility of the developer to provide all required font faces."); #endif #if GDI && !WPF if (GdiFamily != null) { return(GdiFamily.IsStyleAvailable((GdiFontStyle)xStyle)); } return(false); #endif }
/// <summary> /// Gets the height, in font design units, of the em square for the specified style. /// </summary> public int GetEmHeight(XFontStyle style) { OpenTypeDescriptor descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(Name, style); int result = descriptor.UnitsPerEm; //#if DEBUG_ && GDI //int gdiValue = _gdiFamily.GetEmHeight((FontStyle)style); //Debug.Assert(gdiValue == result); //#endif //#if DEBUG_ // int headValue = descriptor.FontFace.head.unitsPerEm; // Debug.Assert(headValue == result); //#endif return(result); }
internal static XFontStyle GetXStyle(Font font) { XFontStyle style = XFontStyle.Regular; if (font.Bold) { style = font.Italic ? XFontStyle.BoldItalic : XFontStyle.Bold; } else if (font.Italic) { style = XFontStyle.Italic; } return(style); }
/// <summary> /// Returns the line spacing, in design units, of the FontFamily object of the specified style. /// The line spacing is the vertical distance between the base lines of two consecutive lines of text. /// </summary> public int GetLineSpacing(XFontStyle style) { OpenTypeDescriptor descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(Name, style); int result = descriptor.LineSpacing; #if DEBUG_ && GDI int gdiValue = _gdiFamily.GetLineSpacing((FontStyle)style); Debug.Assert(gdiValue == result); #endif #if DEBUG_ && WPF && !SILVERLIGHT int wpfValue = (int)Math.Round(_wpfFamily.LineSpacing * GetEmHeight(style)); Debug.Assert(wpfValue == result); #endif return(result); }
//public override int GetHashCode(); /// <summary> /// Returns the line spacing, in design units, of the FontFamily object of the specified style. /// The line spacing is the vertical distance between the base lines of two consecutive lines of text. /// </summary> public int GetLineSpacing(XFontStyle style) { #if GDI && !WPF return(this.gdiFamily.GetLineSpacing((FontStyle)style)); #endif #if WPF && !GDI return(FontHelper.GetWpfValue(this, style, GWV.GetLineSpacing)); #endif #if WPF && GDI #if DEBUG int gdiResult = this.gdiFamily.GetLineSpacing((FontStyle)style); int wpfResult = FontHelper.GetWpfValue(this, style, GWV.GetLineSpacing); //Debug.Assert(gdiResult == wpfResult, "GDI+ and WPF provides different values."); #endif return(FontHelper.GetWpfValue(this, style, GWV.GetLineSpacing)); #endif }
public void HelloWorld(string familyName, double fontSize, XFontStyle style) { string filename = "HelloWorld"; // Create a new PDF document. var document = new PdfDocument(); document.Info.Title = "Created with PDFsharp"; // Create an empty page in this document. var page = document.AddPage(); // Get an XGraphics object for drawing on this page. var gfx = XGraphics.FromPdfPage(page); // Draw two lines with a red default pen. var width = page.Width; var height = page.Height; gfx.DrawLine(XPens.Red, 0, 0, width, height); gfx.DrawLine(XPens.Red, width, 0, 0, height); // Draw a circle with a red pen which is 1.5 point thick. var r = width / 5; gfx.DrawEllipse(new XPen(XColors.Red, 1.5), XBrushes.White, new XRect(width / 2 - r, height / 2 - r, 2 * r, 2 * r)); // Create a font var font = new XFont(familyName, fontSize, style); // Draw the text. gfx.DrawString("Hello, PDFsharp!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center); string fileNameOut = string.Format("{0}_{1}_{2}_{3}{4}", filename, familyName, fontSize, style, _extOuput); string fullOutputPath = System.IO.Path.Combine(_outputFolder.LocalPath, fileNameOut); // Save the document... document.Save(fullOutputPath); }
/// <summary> /// Simple hack to make it work... /// </summary> public static FontStyle FontStyleFromStyle(XFontStyle style) { switch (style & XFontStyle.BoldItalic) // mask out Underline and Strikeout { case XFontStyle.Regular: return FontStyles.Normal; case XFontStyle.Bold: return FontStyles.Normal; case XFontStyle.Italic: return FontStyles.Italic; case XFontStyle.BoldItalic: return FontStyles.Italic; } return FontStyles.Normal; }
/// <summary> /// Simple hack to make it work... /// </summary> public static FontStyle FontStyleFromStyle(XFontStyle style) { switch (style & XFontStyle.BoldItalic) // mask out Underline and Strikeout { case XFontStyle.Regular: return(FontStyles.Normal); case XFontStyle.Bold: return(FontStyles.Normal); case XFontStyle.Italic: return(FontStyles.Italic); case XFontStyle.BoldItalic: return(FontStyles.Italic); } return(FontStyles.Normal); }
/// <summary> /// Converts a DOM Font to an XFont. /// </summary> internal static XFont FontToXFont(Font font, PdfFontEncoding encoding) { XPdfFontOptions options = new XPdfFontOptions(encoding); XFontStyle style = GetXStyle(font); #if DEBUG if (StringComparer.OrdinalIgnoreCase.Compare(font.Name, "Segoe UI Semilight") == 0 && (style & XFontStyle.BoldItalic) == XFontStyle.Italic) { font.GetType(); } #endif XFont xFont = new XFont(font.Name, font.Size, style, options); #if DEBUG CreateFontCounter++; #endif return(xFont); }
/// <summary> /// Simple hack to make it work... /// </summary> public static FontWeight FontWeightFromStyle(XFontStyle style) { switch (style & XFontStyle.BoldItalic) // Mask out Underline, Strikeout, etc. { case XFontStyle.Regular: return(FontWeights.Normal); case XFontStyle.Bold: return(FontWeights.Bold); case XFontStyle.Italic: return(FontWeights.Normal); case XFontStyle.BoldItalic: return(FontWeights.Bold); } return(FontWeights.Normal); }
/// <summary> /// Simple hack to make it work... /// </summary> public static FontWeight FontWeightFromStyle(XFontStyle style) { switch (style) { case XFontStyle.Regular: return(FontWeights.Normal); case XFontStyle.Bold: return(FontWeights.Bold); case XFontStyle.Italic: return(FontWeights.Normal); case XFontStyle.BoldItalic: return(FontWeights.Bold); } return(FontWeights.Normal); }
/// <summary> /// Creates font and enforces bold/italic simulation. /// </summary> public static XFont CreateSpecialFont(string familyName, double emSize, XFontStyle style, XPdfFontOptions pdfOptions, XStyleSimulations styleSimulations) { return new XFont(familyName, emSize, style, pdfOptions, styleSimulations); }
public FontResolvingOptions(XFontStyle fontStyle, XStyleSimulations styleSimulations) { FontStyle = fontStyle; OverrideStyleSimulations = true; StyleSimulations = styleSimulations; }
public FontResolvingOptions(XFontStyle fontStyle) { FontStyle = fontStyle; }
//public string GetName(int language); /// <summary> /// Indicates whether the specified FontStyle enumeration is available. /// </summary> public bool IsStyleAvailable(XFontStyle style) { XGdiFontStyle xStyle = ((XGdiFontStyle)style) & XGdiFontStyle.BoldItalic; #if CORE throw new InvalidOperationException("In CORE build it is the responsibility of the developer to provide all required font faces."); #endif #if GDI && !WPF if (GdiFamily != null) return GdiFamily.IsStyleAvailable((GdiFontStyle)xStyle); return false; #endif #if WPF && !GDI if (WpfFamily != null) return FontHelper.IsStyleAvailable(this, xStyle); return false; #endif #if WPF && GDI #if DEBUG //bool gdiResult = _gdiFamily.IsStyle Available((FontStyle)style); //bool wpfResult = FontHelper.IsStyle Available(this, style); //// TODOWPF: check when fails //Debug.Assert(gdiResult == wpfResult, "GDI+ and WPF provide different values."); #endif return FontHelper.IsStyleAvailable(this, xStyle); #endif #if NETFX_CORE || UWP throw new InvalidOperationException("In NETFX_CORE build it is the responsibility of the developer to provide all required font faces."); #endif }
//public string GetName(int language); /// <summary> /// Indicates whether the specified FontStyle enumeration is available. /// </summary> public bool IsStyleAvailable(XFontStyle style) { #if GDI && !WPF return this.gdiFamily.IsStyleAvailable((FontStyle)style); #endif #if WPF && !GDI return FontHelper.GetWpfValue(this, style, GWV.IsStyleAvailable) == 1; #endif #if WPF && GDI #if DEBUG bool gdiResult = this.gdiFamily.IsStyleAvailable((FontStyle)style); bool wpfResult = FontHelper.GetWpfValue(this, style, GWV.IsStyleAvailable) == 1; // TODOWPF //Debug.Assert(gdiResult == wpfResult, "GDI+ and WPF provides different values."); #endif return FontHelper.GetWpfValue(this, style, GWV.IsStyleAvailable) == 1; #endif }
static string MakeKey(string familyName, XFontStyle style) { return MakeKey(familyName, (style & XFontStyle.Bold) != 0, (style & XFontStyle.Italic) != 0); }
public FontSelector(XFontFamily family, XFontStyle style) { throw new NotImplementedException("PdfFontSelector(XFontFamily family, XFontStyle style)"); }
/// <summary> /// Simple hack to make it work... /// </summary> public static FontWeight FontWeightFromStyle(XFontStyle style) { switch (style) { case XFontStyle.Regular: return FontWeights.Normal; case XFontStyle.Bold: return FontWeights.Bold; case XFontStyle.Italic: return FontWeights.Normal; case XFontStyle.BoldItalic: return FontWeights.Bold; } return FontWeights.Normal; }
public static int GetWpfValue(XFontFamily family, XFontStyle style, GWV value) { FontDescriptor descriptor = FontDescriptorStock.Global.CreateDescriptor(family, style); XFontMetrics metrics = descriptor.FontMetrics; switch (value) { case GWV.GetCellAscent: return (int)metrics.Ascent; case GWV.GetCellDescent: return (int)Math.Abs(metrics.Descent); case GWV.GetEmHeight: return (int)metrics.CapHeight; case GWV.GetLineSpacing: return (int)(metrics.Ascent + Math.Abs(metrics.Descent) + metrics.Leading); case GWV.IsStyleAvailable: // TODOWPF: System.Collections.Generic.List<Typeface> typefaces = new System.Collections.Generic.List<Typeface>(family.wpfFamily.GetTypefaces()); foreach (Typeface typeface in typefaces) { Debugger.Break(); //typeface.Style = FontStyles. } // TODOWPF return 1; } return 0; }
public FontSelector(XFontFamily family, XFontStyle style) { this.name = family.Name; this.style = style; }
public void IssueCommand(string command) { switch (command) { case ".large": _fontSize = 20; break; case ".normal": _fontSize = 14; break; case ".paragraph": row += (GetCharHeight() * 2); _rowWidth = indentWidth; break; case ".fill": _fill = true; break; case ".nofill": _fill = false; break; case ".regular": _style = XFontStyle.Regular; break; case ".italics": if (_style == XFontStyle.Bold) _style = XFontStyle.BoldItalic; else _style = XFontStyle.Italic; break; case ".bold": if (_style == XFontStyle.Italic) _style = XFontStyle.BoldItalic; else _style = XFontStyle.Bold; break; default: // If it starts with "." it must be a parameterized command like indent if (command.StartsWith(".")) { if (command.Contains (".indent")) { if (_rowWidth > indentWidth) row += (GetCharHeight() * 2); _indent += int.Parse (command.Replace (".indent ", "")); _rowWidth = indentWidth; } } else { // It's just text, so write it out WriteText (command); } break; } }
/// <summary> /// Gets the FontDescriptor identified by the specified FontSelector. If no such objects /// exists, a new FontDescriptor is created and added to the stock. /// </summary> public FontDescriptor CreateDescriptor(XFontFamily family, XFontStyle style) { if (family == null) throw new ArgumentNullException("family"); FontSelector selector = new FontSelector(family, style); FontDescriptor descriptor = this.table[selector] as FontDescriptor; if (descriptor == null) { lock (typeof(FontDescriptorStock)) { // may be created by other thread meanwhile descriptor = this.table[selector] as FontDescriptor; if (descriptor == null) { XFont font = new XFont(family.Name, 10, style); descriptor = new TrueTypeDescriptor(font, font.privateFontCollection); if (this.table.ContainsKey(selector)) GetType(); else this.table.Add(selector, descriptor); } } } return descriptor; }
/// <summary> /// Returns the cell descent, in design units, of the XFontFamily object of the specified style. /// </summary> public int GetCellDescent(XFontStyle style) { OpenTypeDescriptor descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(Name, style); int result = descriptor.Descender; #if DEBUG_ && GDI int gdiValue = _gdiFamily.GetCellDescent((FontStyle)style); Debug.Assert(gdiValue == result); #endif return result; }
public XTypefaceHack(string typefaceName, XFontStyle style, XFontWeight weight) : this(typefaceName, style, weight, new XFontStretch()) { }
public FontInfo(string name, float size, XFontStyle style = XFontStyle.Regular) { this.family = null; this.name = name; this.size = size; this.style = style; }
internal static WpfTypeface TryCreateTypeface(string name, XFontStyle style, out WpfFontFamily fontFamily) { if (Singleton._fontFamilies.TryGetValue(name, out fontFamily)) { WpfTypeface typeface = FontHelper.CreateTypeface(fontFamily, style); return typeface; } return null; }
internal static string ComputeKey(string name, XFontStyle style) { return ComputeKey(name, (style & XFontStyle.Bold) == XFontStyle.Bold, (style & XFontStyle.Italic) == XFontStyle.Italic); }
private static void DrawText(XGraphics gfx, double x, double y, double width, double height, XFontStyle fontStyle, int size, string text) { DrawText(gfx, x, y, width, height, fontStyle, size, text, XBrushes.Black, XStringFormats.TopLeft); }
public FontInfo(FontFamily family, float size, XFontStyle style = XFontStyle.Regular) { this.family = family; this.name = null; this.size = size; this.style = style; }
/// <summary> /// Gets the height, in font design units, of the em square for the specified style. /// </summary> public int GetEmHeight(XFontStyle style) { OpenTypeDescriptor descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(Name, style); int result = descriptor.UnitsPerEm; #if DEBUG_ && GDI int gdiValue = _gdiFamily.GetEmHeight((FontStyle)style); Debug.Assert(gdiValue == result); #endif #if DEBUG_ int headValue = descriptor.FontFace.head.unitsPerEm; Debug.Assert(headValue == result); #endif return result; }
private static void DrawText(XGraphics gfx, double x, double y, double width, double height, XFontStyle fontStyle, int size, string text, XBrush brush, XStringFormat stringformat) { XFont font = new XFont("Calibri", size, fontStyle); XTextFormatter tf = new XTextFormatter(gfx); XRect rect = new XRect(x, y, width, height); tf.DrawString(text, font, brush, rect, stringformat); }
internal static Typeface TryFindTypeface(string name, XFontStyle style, out System.Windows.Media.FontFamily fontFamily) { if (s_global.fontFamilies.TryGetValue(name, out fontFamily)) { Typeface typeface = FontHelper.CreateTypeface(fontFamily, style); return typeface; } return null; }
//public override int GetHashCode(); /// <summary> /// Returns the line spacing, in design units, of the FontFamily object of the specified style. /// The line spacing is the vertical distance between the base lines of two consecutive lines of text. /// </summary> public int GetLineSpacing(XFontStyle style) { #if GDI && !WPF return this.gdiFamily.GetLineSpacing((FontStyle)style); #endif #if WPF && !GDI return FontHelper.GetWpfValue(this, style, GWV.GetLineSpacing); #endif #if WPF && GDI #if DEBUG int gdiResult = this.gdiFamily.GetLineSpacing((FontStyle)style); int wpfResult = FontHelper.GetWpfValue(this, style, GWV.GetLineSpacing); //Debug.Assert(gdiResult == wpfResult, "GDI+ and WPF provides different values."); #endif return FontHelper.GetWpfValue(this, style, GWV.GetLineSpacing); #endif }
/// <summary> /// Returns the line spacing, in design units, of the FontFamily object of the specified style. /// The line spacing is the vertical distance between the base lines of two consecutive lines of text. /// </summary> public int GetLineSpacing(XFontStyle style) { OpenTypeDescriptor descriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptor(Name, style); int result = descriptor.LineSpacing; #if DEBUG_ && GDI int gdiValue = _gdiFamily.GetLineSpacing((FontStyle)style); Debug.Assert(gdiValue == result); #endif #if DEBUG_ && WPF && !SILVERLIGHT int wpfValue = (int)Math.Round(_wpfFamily.LineSpacing * GetEmHeight(style)); Debug.Assert(wpfValue == result); #endif return result; }