/// <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; }
public static int GetWpfValue(XFontFamily family, XFontStyle style, GWV value) { FontDescriptor descriptor = FontDescriptorStock.NewInstance.CreateDescriptor(family, style); XFontMetrics metrics = descriptor.FontMetrics; switch (value) { case GWV.GetCellAscent: return metrics.Ascent; case GWV.GetCellDescent: return Math.Abs(metrics.Descent); case GWV.GetEmHeight: //return (int)metrics.CapHeight; return metrics.UnitsPerEm; case GWV.GetLineSpacing: return metrics.Ascent + Math.Abs(metrics.Descent) + metrics.Leading; default: throw new InvalidOperationException("Unknown GWV value."); // DELETE //case GWV.IsStyleAvailable: // style &= XFontStyle.Regular | XFontStyle.Bold | XFontStyle.Italic | XFontStyle.BoldItalic; // same as XFontStyle.BoldItalic // List<Typeface> s_typefaces = new List<Typeface>(family.wpfFamily.GetTypefaces()); // foreach (Typeface typeface in s_typefaces) // { // } // Debugger.Break(); ////typeface.Style = FontStyles. } }
public static XGlyphTypeface GetOrCreateFromGdi(GdiFont gdiFont) { // $TODO THHO Lock??? string typefaceKey = ComputeKey(gdiFont); XGlyphTypeface glyphTypeface; if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface)) { // We have the glyph typeface already in cache. return(glyphTypeface); } XFontFamily fontFamily = XFontFamily.GetOrCreateFromGdi(gdiFont); XFontSource fontSource = XFontSource.GetOrCreateFromGdi(typefaceKey, gdiFont); // Check if styles must be simulated. XStyleSimulations styleSimulations = XStyleSimulations.None; if (gdiFont.Bold && !fontSource.Fontface.os2.IsBold) { styleSimulations |= XStyleSimulations.BoldSimulation; } if (gdiFont.Italic && !fontSource.Fontface.os2.IsItalic) { styleSimulations |= XStyleSimulations.ItalicSimulation; } glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, styleSimulations, gdiFont); GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface); return(glyphTypeface); }
public static XGlyphTypeface GetOrCreateFrom(string familyName, FontResolvingOptions fontResolvingOptions) { // Check cache for requested type face. string typefaceKey = ComputeKey(familyName, fontResolvingOptions); XGlyphTypeface glyphTypeface; try { // Lock around TryGetGlyphTypeface and AddGlyphTypeface. Lock.EnterFontFactory(); if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface)) { // Just return existing one. return(glyphTypeface); } // Resolve typeface by FontFactory. FontResolverInfo fontResolverInfo = FontFactory.ResolveTypeface(familyName, fontResolvingOptions, typefaceKey); if (fontResolverInfo == null) { // No fallback - just stop. throw new InvalidOperationException("No appropriate font found."); } GdiFont gdiFont = null; // Now create the font family at the first. XFontFamily fontFamily; PlatformFontResolverInfo platformFontResolverInfo = fontResolverInfo as PlatformFontResolverInfo; if (platformFontResolverInfo != null) { // Case: fontResolverInfo was created by platform font resolver // and contains platform specific objects that are reused. // Reuse GDI+ font from platform font resolver. gdiFont = platformFontResolverInfo.GdiFont; fontFamily = XFontFamily.GetOrCreateFromGdi(gdiFont); } else { // Case: fontResolverInfo was created by custom font resolver. // Get or create font family for custom font resolver retrieved font source. fontFamily = XFontFamily.GetOrCreateFontFamily(familyName); } // We have a valid font resolver info. That means we also have an XFontSource object loaded in the cache. XFontSource fontSource = FontFactory.GetFontSourceByFontName(fontResolverInfo.FaceName); Debug.Assert(fontSource != null); // Each font source already contains its OpenTypeFontface. glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations, gdiFont); GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface); } finally { Lock.ExitFontFactory(); } return(glyphTypeface); }
public static XGlyphTypeface GetOrCreateFromWpf(WpfTypeface wpfTypeface) { #if DEBUG if (wpfTypeface.FontFamily.Source == "Segoe UI Semilight") { wpfTypeface.GetType(); } #endif //string typefaceKey = ComputeKey(wpfTypeface); //XGlyphTypeface glyphTypeface; //if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface)) //{ // // We have the glyph typeface already in cache. // return glyphTypeface; //} // Lock around TryGetGlyphTypeface and AddGlyphTypeface. try { Lock.EnterFontFactory(); // Create WPF glyph typeface. WpfGlyphTypeface wpfGlyphTypeface; if (!wpfTypeface.TryGetGlyphTypeface(out wpfGlyphTypeface)) { return(null); } string typefaceKey = ComputeKey(wpfGlyphTypeface); string name1 = wpfGlyphTypeface.DesignerNames[FontHelper.CultureInfoEnUs]; string name2 = wpfGlyphTypeface.FaceNames[FontHelper.CultureInfoEnUs]; string name3 = wpfGlyphTypeface.FamilyNames[FontHelper.CultureInfoEnUs]; string name4 = wpfGlyphTypeface.ManufacturerNames[FontHelper.CultureInfoEnUs]; string name5 = wpfGlyphTypeface.Win32FaceNames[FontHelper.CultureInfoEnUs]; string name6 = wpfGlyphTypeface.Win32FamilyNames[FontHelper.CultureInfoEnUs]; XGlyphTypeface glyphTypeface; if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface)) { // We have the glyph typeface already in cache. return(glyphTypeface); } XFontFamily fontFamily = XFontFamily.GetOrCreateFromWpf(wpfTypeface.FontFamily); XFontSource fontSource = XFontSource.GetOrCreateFromWpf(typefaceKey, wpfGlyphTypeface); glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, (XStyleSimulations)wpfGlyphTypeface.StyleSimulations, wpfTypeface, wpfGlyphTypeface); GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface); return(glyphTypeface); } finally { Lock.ExitFontFactory(); } }
// ----- 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 XFontFamily(GdiFontFamily gdiFontFamily) //{ // FamilyInternal = FontFamilyInternal.GetOrCreateFromGdi(gdiFontFamily); //} internal static XFontFamily CreateFromName_not_used(string name, bool createPlatformFamily) { XFontFamily fontFamily = new XFontFamily(name); if (createPlatformFamily) { #if GDI //fontFamily._gdiFamily = new System.Drawing.FontFamily(name); #endif } return(fontFamily); }
const string KeyPrefix = "tk:"; // "typeface key" #if CORE || GDI XGlyphTypeface(string key, XFontFamily fontFamily, XFontSource fontSource, XStyleSimulations styleSimulations, GdiFont gdiFont) { _key = key; _fontFamily = fontFamily; _fontSource = fontSource; _fontface = OpenTypeFontface.CetOrCreateFrom(fontSource); Debug.Assert(ReferenceEquals(_fontSource.Fontface, _fontface)); _gdiFont = gdiFont; _styleSimulations = styleSimulations; Initialize(); }
/// <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 }
/// <summary> /// Initializes a new instance of the <see cref="XGlyphTypeface"/> class by a font source. /// </summary> public XGlyphTypeface(XFontSource fontSource) { string familyName = fontSource.Fontface.name.Name; _fontFamily = new XFontFamily(familyName, false); _fontface = fontSource.Fontface; _isBold = _fontface.os2.IsBold; _isItalic = _fontface.os2.IsItalic; _key = ComputeKey(familyName, _isBold, _isItalic); //_fontFamily =xfont FontFamilyCache.GetFamilyByName(familyName); _fontSource = fontSource; Initialize(); }
//#if CORE || GDI // //public XFontFamily(GdiFontFamily gdiFontFamily) // //{ // // FamilyInternal = FontFamilyInternal.GetOrCreateFromGdi(gdiFontFamily); // //} //#endif //#if WPF // //public XFontFamily(WpfFontFamily wpfFontFamily) // //{ // // FamilyInternal = FontFamilyInternal.GetOrCreateFromWpf(wpfFontFamily); // // //// HACK // // //int idxHash = _name.LastIndexOf('#'); // // //if (idxHash > 0) // // // _name = _name.Substring(idxHash + 1); // // //_wpfFamily = family; // //} //#endif internal static XFontFamily CreateFromName_not_used(string name, bool createPlatformFamily) { XFontFamily fontFamily = new XFontFamily(name); if (createPlatformFamily) { //#if GDI // //fontFamily._gdiFamily = new System.Drawing.FontFamily(name); //#endif //#if WPF // //fontFamily._wpfFamily = new System.Windows.Media.FontFamily(name); //#endif } return(fontFamily); }
/// <summary> /// Returns an array that contains all the FontFamily objects available for the specified /// graphics context. /// </summary> public static XFontFamily[] GetFamilies(XGraphics graphics) { XFontFamily[] result; #if GDI System.Drawing.FontFamily[] families = null; families = System.Drawing.FontFamily.GetFamilies(graphics.gfx); int count = families.Length; result = new XFontFamily[count]; for (int idx = 0; idx < count; idx++) { result[idx] = new XFontFamily(families[idx]); } #endif #if WPF // TODOWPF: not very important result = null; #endif return(result); }
/// <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, XGdiFontStyle style) { style &= XGdiFontStyle.BoldItalic; #if !SILVERLIGHT // TODOWPF: check for correctness // FontDescriptor descriptor = FontDescriptorCache.GetOrCreateDescriptor(family.Name, style); //XFontMetrics metrics = descriptor.FontMetrics; // style &= XFontStyle.Regular | XFontStyle.Bold | XFontStyle.Italic | XFontStyle.BoldItalic; // same as XFontStyle.BoldItalic List <WpfTypeface> typefaces = new List <WpfTypeface>(family.WpfFamily.GetTypefaces()); foreach (WpfTypeface typeface in typefaces) { bool bold = typeface.Weight == FontWeights.Bold; bool italic = typeface.Style == FontStyles.Italic; switch (style) { case XGdiFontStyle.Regular: if (!bold && !italic) { return(true); } break; case XGdiFontStyle.Bold: if (bold && !italic) { return(true); } break; case XGdiFontStyle.Italic: if (!bold && italic) { return(true); } break; case XGdiFontStyle.BoldItalic: if (bold && italic) { return(true); } break; } ////// typeface.sty ////// bool available = false; ////// GlyphTypeface glyphTypeface; ////// if (typeface.TryGetGlyphTypeface(out glyphTypeface)) ////// { //////#if DEBUG_ ////// glyphTypeface.GetType(); //////#endif ////// available = true; ////// } ////// if (available) ////// return true; } return(false); #else return(true); // AGHACK #endif }
//public XFontFamily(GdiFontFamily gdiFontFamily) //{ // FamilyInternal = FontFamilyInternal.GetOrCreateFromGdi(gdiFontFamily); //} #endif #if WPF //public XFontFamily(WpfFontFamily wpfFontFamily) //{ // FamilyInternal = FontFamilyInternal.GetOrCreateFromWpf(wpfFontFamily); // //// HACK // //int idxHash = _name.LastIndexOf('#'); // //if (idxHash > 0) // // _name = _name.Substring(idxHash + 1); // //_wpfFamily = family; //} #endif internal static XFontFamily CreateFromName_not_used(string name, bool createPlatformFamily) { XFontFamily fontFamily = new XFontFamily(name); if (createPlatformFamily) { #if GDI //fontFamily._gdiFamily = new System.Drawing.FontFamily(name); #endif #if WPF //fontFamily._wpfFamily = new System.Windows.Media.FontFamily(name); #endif } return fontFamily; }
/// <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; if (!this.table.TryGetValue(selector, out descriptor)) { lock (typeof(FontDescriptorStock)) { // may be created by other thread meanwhile if (!this.table.TryGetValue(selector, out descriptor)) { XFont font = new XFont(family.Name, 10, style); descriptor = new OpenTypeDescriptor(font); if (this.table.ContainsKey(selector)) GetType(); else this.table.Add(selector, descriptor); } } } return descriptor; }
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 XTypeface_not_yet_used(XFontFamily family, XFontStyle style) { _family = family; _style = style; }
// ----- AddString ---------------------------------------------------------------------------- #if GDI /// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, System.Drawing.Point origin, XStringFormat format) { //this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, origin, format.RealizeGdiStringFormat()); // TODOWPF AddString(s, family, style, emSize, origin, format); }
public FontSelector(XFontFamily family, XFontStyle style) { this.name = family.Name; this.style = style; }
/// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, SysPoint origin, XStringFormat format) { AddString(s, family, style, emSize, new XPoint(origin), format); }
/// <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 { #if GDI // TODOWPF this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, origin.ToPointF(), format.RealizeGdiStringFormat()); #endif #if WPF Typeface typeface = FontHelper.CreateTypeface(family, style); FormattedText ft = new FormattedText(s, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, emSize, System.Windows.Media.Brushes.Black); Geometry geo = ft.BuildGeometry(origin); this.pathGeometry.AddGeometry(geo); #endif } catch { } }
/// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, RectangleF layoutRect, XStringFormat format) { // TODOWPF this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, layoutRect, format.RealizeGdiStringFormat()); }
public static XGlyphTypeface GetOrCreateFrom(string familyName, FontResolvingOptions fontResolvingOptions) { // Check cache for requested type face. string typefaceKey = ComputeKey(familyName, fontResolvingOptions); XGlyphTypeface glyphTypeface; if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface)) { // Just return existing one. return(glyphTypeface); } // Resolve typeface by FontFactory. FontResolverInfo fontResolverInfo = FontFactory.ResolveTypeface(familyName, fontResolvingOptions, typefaceKey); if (fontResolverInfo == null) { // No fallback - just stop. throw new InvalidOperationException("No appropriate font found."); } #if CORE || GDI GdiFont gdiFont = null; #endif #if WPF WpfFontFamily wpfFontFamily = null; WpfTypeface wpfTypeface = null; WpfGlyphTypeface wpfGlyphTypeface = null; #endif #if UWP // Nothing to do. #endif // Now create the font family at the first. XFontFamily fontFamily; PlatformFontResolverInfo platformFontResolverInfo = fontResolverInfo as PlatformFontResolverInfo; if (platformFontResolverInfo != null) { #if CORE || GDI // $TODO THHO Lock??? // Reuse GDI+ font from platform font resolver. gdiFont = platformFontResolverInfo.GdiFont; fontFamily = XFontFamily.GetOrCreateFromGdi(gdiFont); #endif #if WPF #if !SILVERLIGHT // Reuse WPF font family created from platform font resolver. wpfFontFamily = platformFontResolverInfo.WpfFontFamily; wpfTypeface = platformFontResolverInfo.WpfTypeface; wpfGlyphTypeface = platformFontResolverInfo.WpfGlyphTypeface; fontFamily = XFontFamily.GetOrCreateFromWpf(wpfFontFamily); #else fontFamily = XFontFamily.GetOrCreateFromWpf(new WpfFontFamily(familyName)); #endif #endif #if NETFX_CORE || UWP fontFamily = null; #endif } else { // Create new and exclusively used font family for custom font resolver retrieved font source. fontFamily = XFontFamily.CreateSolitary(fontResolverInfo.FaceName); } // We have a valid font resolver info. That means we also have an XFontSource object loaded in the cache. ////XFontSource fontSource = FontFactory.GetFontSourceByTypefaceKey(fontResolverInfo.FaceName); XFontSource fontSource = FontFactory.GetFontSourceByFontName(fontResolverInfo.FaceName); Debug.Assert(fontSource != null); // Each font source already contains its OpenTypeFontface. #if CORE || GDI glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations, gdiFont); #endif #if WPF glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations, wpfTypeface, wpfGlyphTypeface); #endif #if NETFX_CORE || UWP glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations); #endif GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface); return(glyphTypeface); }
/// <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 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 metrics.Ascent; case GWV.GetCellDescent: return Math.Abs(metrics.Descent); case GWV.GetEmHeight: //return (int)metrics.CapHeight; return metrics.UnitsPerEm; case GWV.GetLineSpacing: return metrics.Ascent + Math.Abs(metrics.Descent) + metrics.Leading; default: throw new InvalidOperationException("Unknown GWV value."); // DELETE //case GWV.IsStyleAvailable: // style &= XFontStyle.Regular | XFontStyle.Bold | XFontStyle.Italic | XFontStyle.BoldItalic; // same as XFontStyle.BoldItalic // List<Typeface> s_typefaces = new List<Typeface>(family.wpfFamily.GetTypefaces()); // foreach (Typeface typeface in s_typefaces) // { // } // Debugger.Break(); ////typeface.Style = FontStyles. } }
/// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, PointF origin, XStringFormat format) { AddString(s, family, style, emSize, new XRect(origin.X, origin.Y, 0, 0), format); }
/// <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> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XPoint origin, XStringFormat format) { try { #if CORE DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddString"); #endif #if GDI if (family.GdiFamily == null) throw new NotFiniteNumberException(PSSR.NotImplementedForFontsRetrievedWithFontResolver(family.Name)); PointF p = origin.ToPointF(); p.Y += SimulateBaselineOffset(family, style, emSize, format); try { Lock.EnterGdiPlus(); _gdipPath.AddString(s, family.GdiFamily, (int)style, (float)emSize, p, format.RealizeGdiStringFormat()); } finally { Lock.ExitGdiPlus(); } #endif #if WPF if (family.WpfFamily == null) throw new NotFiniteNumberException(PSSR.NotImplementedForFontsRetrievedWithFontResolver(family.Name)); #if !SILVERLIGHT XFont font = new XFont(family.Name, emSize, style); double x = origin.X; double y = origin.Y; double lineSpace = font.GetHeight(); double cyAscent = lineSpace * font.CellAscent / font.CellSpace; double cyDescent = lineSpace * font.CellDescent / font.CellSpace; Typeface typeface = FontHelper.CreateTypeface(family.WpfFamily, style); FormattedText formattedText = FontHelper.CreateFormattedText(s, typeface, emSize, WpfBrushes.Black); switch (format.Alignment) { case XStringAlignment.Near: // nothing to do, this is the default //formattedText.TextAlignment = TextAlignment.Left; break; case XStringAlignment.Center: formattedText.TextAlignment = TextAlignment.Center; break; case XStringAlignment.Far: formattedText.TextAlignment = TextAlignment.Right; break; } switch (format.LineAlignment) { case XLineAlignment.Near: //y += cyAscent; break; case XLineAlignment.Center: // TODO use CapHeight. PDFlib also uses 3/4 of ascent y += -lineSpace / 2; //-formattedText.Baseline + (cyAscent * 2 / 4); break; case XLineAlignment.Far: y += -formattedText.Baseline - cyDescent; break; case XLineAlignment.BaseLine: y -= formattedText.Baseline; break; } Geometry geo = formattedText.BuildGeometry(new XPoint(x, y)); _pathGeometry.AddGeometry(geo); #else // AG-HACK throw new InvalidOperationException("Silverlight cannot create geometry of glyphs."); // TODO: Get the outline directly from the font. #endif #endif } catch { throw; } }
/// <summary> /// Returns an array that contains all the FontFamily objects available for the specified /// graphics context. /// </summary> public static XFontFamily[] GetFamilies(XGraphics graphics) { XFontFamily[] result; #if GDI System.Drawing.FontFamily[] families = null; families = System.Drawing.FontFamily.GetFamilies(graphics.gfx); int count = families.Length; result = new XFontFamily[count]; for (int idx = 0; idx < count; idx++) result[idx] = new XFontFamily(families[idx]); #endif #if WPF result = null; #endif return result; }
/// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, PointF origin, XStringFormat format) { //this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, origin, format.RealizeGdiStringFormat()); // TODOWPF AddString(s, family, style, emSize, new XRect(origin.X, origin.Y, 0, 0), format); }
public FontSelector(XFontFamily family, XFontStyle style) { throw new NotImplementedException("PdfFontSelector(XFontFamily family, XFontStyle style)"); }
/// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, System.Windows.Point origin, XStringFormat format) { AddString(s, family, style, emSize, new XPoint(origin), format); //// TODOWPF //Typeface typeface = FontHelper.CreateTypeface(family, style); //FormattedText formattedText = new FormattedText(s, null, FlowDirection.LeftToRight, typeface, emSize, System.Windows.Media.Brushes.Black); //Geometry geo = formattedText.BuildGeometry(origin); //this.pathGeometry.AddGeometry(geo); }
public static XGlyphTypeface GetOrCreateFrom(string familyName, FontResolvingOptions fontResolvingOptions) { // Check cache for requested type face. string typefaceKey = ComputeKey(familyName, fontResolvingOptions); XGlyphTypeface glyphTypeface; try { // Lock around TryGetGlyphTypeface and AddGlyphTypeface. Lock.EnterFontFactory(); if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface)) { // Just return existing one. return(glyphTypeface); } // Resolve typeface by FontFactory. FontResolverInfo fontResolverInfo = FontFactory.ResolveTypeface(familyName, fontResolvingOptions, typefaceKey); if (fontResolverInfo == null) { // No fallback - just stop. throw new InvalidOperationException("No appropriate font found."); } #if CORE && !WITHOUT_DRAWING || GDI GdiFont gdiFont = null; #endif #if WPF WpfFontFamily wpfFontFamily = null; WpfTypeface wpfTypeface = null; WpfGlyphTypeface wpfGlyphTypeface = null; #endif #if UWP // Nothing to do. #endif // Now create the font family at the first. XFontFamily fontFamily; #if !WITHOUT_DRAWING PlatformFontResolverInfo platformFontResolverInfo = fontResolverInfo as PlatformFontResolverInfo; if (platformFontResolverInfo != null) { // Case: fontResolverInfo was created by platform font resolver // and contains platform specific objects that are reused. #if CORE || GDI // Reuse GDI+ font from platform font resolver. gdiFont = platformFontResolverInfo.GdiFont; fontFamily = XFontFamily.GetOrCreateFromGdi(gdiFont); #endif #if WPF #if !SILVERLIGHT // Reuse WPF font family created from platform font resolver. wpfFontFamily = platformFontResolverInfo.WpfFontFamily; wpfTypeface = platformFontResolverInfo.WpfTypeface; wpfGlyphTypeface = platformFontResolverInfo.WpfGlyphTypeface; fontFamily = XFontFamily.GetOrCreateFromWpf(wpfFontFamily); #else fontFamily = XFontFamily.GetOrCreateFromWpf(new WpfFontFamily(familyName)); #endif #endif #if NETFX_CORE || UWP fontFamily = null; #endif } else #endif { // Case: fontResolverInfo was created by custom font resolver. // Get or create font family for custom font resolver retrieved font source. fontFamily = XFontFamily.GetOrCreateFontFamily(familyName); } // We have a valid font resolver info. That means we also have an XFontSource object loaded in the cache. XFontSource fontSource = FontFactory.GetFontSourceByFontName(fontResolverInfo.FaceName); Debug.Assert(fontSource != null); // Each font source already contains its OpenTypeFontface. #if CORE || GDI glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations #if !WITHOUT_DRAWING , gdiFont #endif ); #endif #if WPF glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations, wpfTypeface, wpfGlyphTypeface); #endif #if NETFX_CORE || UWP glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations); #endif GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface); } finally { Lock.ExitFontFactory(); } return(glyphTypeface); }
/// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, Rect rect, XStringFormat format) { //gdip Path.AddString(s, family.gdiFamily, (int)style, (float)emSize, layoutRect, format.RealizeGdiStringFormat()); AddString(s, family, style, emSize, new XRect(rect), format); }
/// <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, XGdiFontStyle style) { style &= XGdiFontStyle.BoldItalic; #if !SILVERLIGHT // TODOWPF: check for correctness // FontDescriptor descriptor = FontDescriptorCache.GetOrCreateDescriptor(family.Name, style); //XFontMetrics metrics = descriptor.FontMetrics; // style &= XFontStyle.Regular | XFontStyle.Bold | XFontStyle.Italic | XFontStyle.BoldItalic; // same as XFontStyle.BoldItalic List<WpfTypeface> typefaces = new List<WpfTypeface>(family.WpfFamily.GetTypefaces()); foreach (WpfTypeface typeface in typefaces) { bool bold = typeface.Weight == FontWeights.Bold; bool italic = typeface.Style == FontStyles.Italic; switch (style) { case XGdiFontStyle.Regular: if (!bold && !italic) return true; break; case XGdiFontStyle.Bold: if (bold && !italic) return true; break; case XGdiFontStyle.Italic: if (!bold && italic) return true; break; case XGdiFontStyle.BoldItalic: if (bold && italic) return true; break; } ////// typeface.sty ////// bool available = false; ////// GlyphTypeface glyphTypeface; ////// if (typeface.TryGetGlyphTypeface(out glyphTypeface)) ////// { //////#if DEBUG_ ////// glyphTypeface.GetType(); //////#endif ////// available = true; ////// } ////// if (available) ////// return true; } return false; #else return true; // AGHACK #endif }
/// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XRect layoutRect, XStringFormat format) { if (s == null) throw new ArgumentNullException("s"); if (family == null) throw new ArgumentNullException("family"); if (format == null) format = XStringFormats.Default; if (format.LineAlignment == XLineAlignment.BaseLine && layoutRect.Height != 0) throw new InvalidOperationException( "DrawString: With XLineAlignment.BaseLine the height of the layout rectangle must be 0."); if (s.Length == 0) return; XFont font = new XFont(family.Name, emSize, style); #if CORE DiagnosticsHelper.HandleNotImplemented("XGraphicsPath.AddString"); #endif #if (GDI || CORE_) && !WPF //Gfx.DrawString(text, font.Realize_GdiFont(), brush.RealizeGdiBrush(), rect, // format != null ? format.RealizeGdiStringFormat() : null); if (family.GdiFamily == null) throw new NotFiniteNumberException(PSSR.NotImplementedForFontsRetrievedWithFontResolver(family.Name)); RectangleF rect = layoutRect.ToRectangleF(); rect.Offset(new PointF(0, SimulateBaselineOffset(family, style, emSize, format))); try { Lock.EnterGdiPlus(); _gdipPath.AddString(s, family.GdiFamily, (int)style, (float)emSize, rect, format.RealizeGdiStringFormat()); } finally { Lock.ExitGdiPlus(); } #endif #if WPF && !GDI if (family.WpfFamily == null) throw new NotFiniteNumberException(PSSR.NotImplementedForFontsRetrievedWithFontResolver(family.Name)); #if !SILVERLIGHT // Just a first sketch, but currently we do not need it and there is enough to do... double x = layoutRect.X; double y = layoutRect.Y; //double lineSpace = font.GetHeight(this); //double cyAscent = lineSpace * font.cellAscent / font.cellSpace; //double cyDescent = lineSpace * font.cellDescent / font.cellSpace; //double cyAscent = family.GetCellAscent(style) * family.GetLineSpacing(style) / family.getl; //fontlineSpace * font.cellAscent / font.cellSpace; //double cyDescent =family.GetCellDescent(style); // lineSpace * font.cellDescent / font.cellSpace; double lineSpace = font.GetHeight(); double cyAscent = lineSpace * font.CellAscent / font.CellSpace; double cyDescent = lineSpace * font.CellDescent / font.CellSpace; bool bold = (style & XFontStyle.Bold) != 0; bool italic = (style & XFontStyle.Italic) != 0; bool strikeout = (style & XFontStyle.Strikeout) != 0; bool underline = (style & XFontStyle.Underline) != 0; Typeface typeface = FontHelper.CreateTypeface(family.WpfFamily, style); //FormattedText formattedText = new FormattedText(s, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, emSize, WpfBrushes.Black); FormattedText formattedText = FontHelper.CreateFormattedText(s, typeface, emSize, WpfBrushes.Black); switch (format.Alignment) { case XStringAlignment.Near: // nothing to do, this is the default //formattedText.TextAlignment = TextAlignment.Left; break; case XStringAlignment.Center: x += layoutRect.Width / 2; formattedText.TextAlignment = TextAlignment.Center; break; case XStringAlignment.Far: x += layoutRect.Width; formattedText.TextAlignment = TextAlignment.Right; break; } //if (PageDirection == XPageDirection.Downwards) //{ switch (format.LineAlignment) { case XLineAlignment.Near: //y += cyAscent; break; case XLineAlignment.Center: // TO/DO use CapHeight. PDFlib also uses 3/4 of ascent //y += -formattedText.Baseline + (cyAscent * 2 / 4) + layoutRect.Height / 2; // GDI seems to make it this simple: // TODO: Check WPF's vertical alignment and make all implementations fit. $MaOs y += layoutRect.Height / 2 - lineSpace / 2; break; case XLineAlignment.Far: y += -formattedText.Baseline - cyDescent + layoutRect.Height; break; case XLineAlignment.BaseLine: y -= formattedText.Baseline; break; } //} //else //{ // // TODOWPF // switch (format.LineAlignment) // { // case XLineAlignment.Near: // //y += cyDescent; // break; // case XLineAlignment.Center: // // TODO use CapHeight. PDFlib also uses 3/4 of ascent // //y += -(cyAscent * 3 / 4) / 2 + rect.Height / 2; // break; // case XLineAlignment.Far: // //y += -cyAscent + rect.Height; // break; // case XLineAlignment.BaseLine: // // nothing to do // break; // } //} //if (bold && !descriptor.IsBoldFace) //{ // // TODO: emulate bold by thicker outline //} //if (italic && !descriptor.IsItalicFace) //{ // // TODO: emulate italic by shearing transformation //} if (underline) { //double underlinePosition = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlinePosition / font.cellSpace; //double underlineThickness = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlineThickness / font.cellSpace; //DrawRectangle(null, brush, x, y - underlinePosition, width, underlineThickness); } if (strikeout) { //double strikeoutPosition = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutPosition / font.cellSpace; //double strikeoutSize = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutSize / font.cellSpace; //DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize); } //dc.DrawText(formattedText, layoutRectangle.Location.ToPoint()); //dc.DrawText(formattedText, new SysPoint(x, y)); Geometry geo = formattedText.BuildGeometry(new Point(x, y)); _pathGeometry.AddGeometry(geo); #else // AG-HACK throw new InvalidOperationException("Silverlight cannot create geometry of glyphs."); // TODO: no, yagni #endif #endif }
/// <summary> /// Init. /// </summary> public FontFamilyAdapter(XFontFamily fontFamily) { _fontFamily = fontFamily; }
/// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XPoint origin, XStringFormat format) { this.gdipPath.AddString(s, family.family, (int)style, (float)emSize, origin.ToPointF(), format.RealizeGdiStringFormat()); }
/// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XRect layoutRect, XStringFormat format) { this.gdipPath.AddString(s, family.family, (int)style, (float)emSize, layoutRect.ToRectangleF(), format.RealizeGdiStringFormat()); }
/// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, RectangleF layoutRect, XStringFormat format) { if (family.GdiFamily == null) throw new NotFiniteNumberException(PSSR.NotImplementedForFontsRetrievedWithFontResolver(family.Name)); RectangleF rect = new RectangleF(layoutRect.X, layoutRect.Y, layoutRect.Width, layoutRect.Height); rect.Offset(new PointF(0, SimulateBaselineOffset(family, style, emSize, format))); try { Lock.EnterGdiPlus(); _gdipPath.AddString(s, family.GdiFamily, (int)style, (float)emSize, layoutRect, format.RealizeGdiStringFormat()); } finally { Lock.ExitGdiPlus(); } }
/// <summary> /// Adds a text string to this path. /// </summary> public void AddString(string s, XFontFamily family, XFontStyle style, double emSize, XRect layoutRect, XStringFormat format) { if (s == null) throw new ArgumentNullException("s"); if (family == null) throw new ArgumentNullException("family"); if (format.LineAlignment == XLineAlignment.BaseLine && layoutRect.Height != 0) throw new InvalidOperationException("DrawString: With XLineAlignment.BaseLine the height of the layout rectangle must be 0."); if (s.Length == 0) return; if (format == null) format = XStringFormats.Default; XFont font = new XFont(family.Name, emSize, style); #if GDI && !WPF RectangleF rc = layoutRect.ToRectangleF(); if (format.LineAlignment == XLineAlignment.BaseLine) { double lineSpace = font.GetHeight(); int cellSpace = font.FontFamily.GetLineSpacing(font.Style); int cellAscent = font.FontFamily.GetCellAscent(font.Style); int cellDescent = font.FontFamily.GetCellDescent(font.Style); double cyAscent = lineSpace * cellAscent / cellSpace; cyAscent = lineSpace * font.cellAscent / font.cellSpace; rc.Offset(0, (float)-cyAscent); } //this.gfx.DrawString(text, font.RealizeGdiFont(), brush.RealizeGdiBrush(), rect, // format != null ? format.RealizeGdiStringFormat() : null); this.gdipPath.AddString(s, family.gdiFamily, (int)style, (float)emSize, rc, format.RealizeGdiStringFormat()); #endif #if WPF && !GDI // Just a first sketch, but currently we do not need it and there is enough to do... double x = layoutRect.X; double y = layoutRect.Y; //double lineSpace = font.GetHeight(this); //double cyAscent = lineSpace * font.cellAscent / font.cellSpace; //double cyDescent = lineSpace * font.cellDescent / font.cellSpace; //double cyAscent = family.GetCellAscent(style) * family.GetLineSpacing(style) / family.getl; //fontlineSpace * font.cellAscent / font.cellSpace; //double cyDescent =family.GetCellDescent(style); // lineSpace * font.cellDescent / font.cellSpace; double lineSpace = font.GetHeight(); double cyAscent = lineSpace * font.cellAscent / font.cellSpace; double cyDescent = lineSpace * font.cellDescent / font.cellSpace; bool bold = (style & XFontStyle.Bold) != 0; bool italic = (style & XFontStyle.Italic) != 0; bool strikeout = (style & XFontStyle.Strikeout) != 0; bool underline = (style & XFontStyle.Underline) != 0; Typeface typeface = FontHelper.CreateTypeface(family, style); FormattedText formattedText = new FormattedText(s, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, emSize, System.Windows.Media.Brushes.Black); switch (format.Alignment) { case XStringAlignment.Near: // nothing to do, this is the default //formattedText.TextAlignment = TextAlignment.Left; break; case XStringAlignment.Center: x += layoutRect.Width / 2; formattedText.TextAlignment = TextAlignment.Center; break; case XStringAlignment.Far: x += layoutRect.Width; formattedText.TextAlignment = TextAlignment.Right; break; } //if (PageDirection == XPageDirection.Downwards) //{ switch (format.LineAlignment) { case XLineAlignment.Near: //y += cyAscent; break; case XLineAlignment.Center: // TODO use CapHeight. PDFlib also uses 3/4 of ascent y += -formattedText.Baseline + (cyAscent * 2 / 4) + layoutRect.Height / 2; break; case XLineAlignment.Far: y += -formattedText.Baseline - cyDescent + layoutRect.Height; break; case XLineAlignment.BaseLine: y -= formattedText.Baseline; break; } //} //else //{ // // TODOWPF // switch (format.LineAlignment) // { // case XLineAlignment.Near: // //y += cyDescent; // break; // case XLineAlignment.Center: // // TODO use CapHeight. PDFlib also uses 3/4 of ascent // //y += -(cyAscent * 3 / 4) / 2 + rect.Height / 2; // break; // case XLineAlignment.Far: // //y += -cyAscent + rect.Height; // break; // case XLineAlignment.BaseLine: // // nothing to do // break; // } //} //if (bold && !descriptor.IsBoldFace) //{ // // TODO: emulate bold by thicker outline //} //if (italic && !descriptor.IsBoldFace) //{ // // TODO: emulate italic by shearing transformation //} if (underline) { //double underlinePosition = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlinePosition / font.cellSpace; //double underlineThickness = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlineThickness / font.cellSpace; //DrawRectangle(null, brush, x, y - underlinePosition, width, underlineThickness); } if (strikeout) { //double strikeoutPosition = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutPosition / font.cellSpace; //double strikeoutSize = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutSize / font.cellSpace; //DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize); } //this.dc.DrawText(formattedText, layoutRectangle.Location.ToPoint()); //this.dc.DrawText(formattedText, new System.Windows.Point(x, y)); Geometry geo = formattedText.BuildGeometry(new Point(x, y)); this.pathGeometry.AddGeometry(geo); #endif }
/// <summary> /// Calculates the offset for BaseLine positioning simulation: /// In GDI we have only Near, Center and Far as LineAlignment and no BaseLine. For XLineAlignment.BaseLine StringAlignment.Near is returned. /// We now return the negative drawed ascender height. /// This has to be added to the LayoutRect/Origin before each _gdipPath.AddString(). /// </summary> /// <param name="family"></param> /// <param name="style"></param> /// <param name="emSize"></param> /// <param name="format"></param> /// <returns></returns> private float SimulateBaselineOffset(XFontFamily family, XFontStyle style, double emSize, XStringFormat format) { XFont font = new XFont(family.Name, emSize, style); if (format.LineAlignment == XLineAlignment.BaseLine) { double lineSpace = font.GetHeight(); int cellSpace = font.FontFamily.GetLineSpacing(font.Style); int cellAscent = font.FontFamily.GetCellAscent(font.Style); int cellDescent = font.FontFamily.GetCellDescent(font.Style); double cyAscent = lineSpace * cellAscent / cellSpace; cyAscent = lineSpace * font.CellAscent / font.CellSpace; return (float)-cyAscent; } return 0; }
/// <summary> /// Returns an array that contains all the FontFamily objects available for the specified /// graphics context. /// </summary> public static XFontFamily[] GetFamilies(XGraphics graphics) { FontFamily[] families = FontFamily.GetFamilies(graphics.gfx); int count = families.Length; XFontFamily[] result = new XFontFamily[count]; for (int idx = 0; idx < count; idx++) result[idx] = new XFontFamily(families[idx]); return result; }