private unsafe static int SetTextAntialiasModeImpl(IntPtr thisPtr, SharpDX.Direct2D1.TextAntialiasMode textAntialiasMode) { try { var shadow = ToShadow <CommandSinkShadow>(thisPtr); var callback = (CommandSink)shadow.Callback; callback.TextAntialiasMode = textAntialiasMode; } catch (Exception exception) { return((int)SharpDX.Result.GetResultFromException(exception)); } return(Result.Ok.Code); }
public FontFamilyFontProvider(string fontFamily, string fontFile, Size charSize, string unicodeGlyphTextFile, Color[] bgPalette, Color[] fgPalette, float scale, Size shift, float?aspectTolerance, string fontName, bool tryToFit, string charListTextFile, bool strictGlyphCheck, System.Windows.FontWeight fontWeight, System.Windows.FontStyle fontStyle, System.Windows.FontStretch fontStretch, SharpDX.Direct2D1.TextAntialiasMode textAAMode) { this.CharSizeNoPadding = charSize; this.FontFamily = fontFamily; this.FontFile = fontFile; this.UnicodeGlyphTextFile = unicodeGlyphTextFile; this.BackgroundPalette = bgPalette; this.ForegroundPalette = fgPalette; this.Scale = scale; this.Shift = shift; this.AspectTolerance = aspectTolerance; this.FontName = fontName; this.TryToFit = tryToFit; this.CharListTextFile = charListTextFile; this.StrictGlyphCheck = strictGlyphCheck; this.FontWeight = fontWeight; this.FontStyle = fontStyle; this.FontStretch = fontStretch; //this.RenderingMode = renderingMode; this.TextAAMode = textAAMode; IEnumerable <EmojiTest.Utils.EmojiInfo> cps = null; if (!string.IsNullOrEmpty(UnicodeGlyphTextFile)) { cps = EmojiTest.Utils.AllEmojiCodepoints(UnicodeGlyphTextFile); } if (!string.IsNullOrEmpty(CharListTextFile)) { string s = System.IO.File.ReadAllText(charListTextFile); List <EmojiTest.Utils.EmojiInfo> cps2 = new List <EmojiTest.Utils.EmojiInfo>(); foreach (char c in s.Distinct()) { EmojiTest.Utils.EmojiInfo o; o.attribute = null; o.cps = new int[] { c }; o.forceInclude = false; o.str = c.ToString(); cps2.Add(o); } cps = cps2; } PetsciiMapgen.Log.WriteLine("Total fontfamily codepoint sequences to process: {0:N0}", cps.Count()); if (!string.IsNullOrEmpty(FontFile)) { _fontCollection = new PrivateFontCollection(); _fontCollection.AddFontFile(FontFile); Log.WriteLine("Loaded font {0}", FontFile); foreach (var f in _fontCollection.Families) { Log.WriteLine(" -> font family: {0}", f.Name); } if (string.IsNullOrEmpty(this.FontFamily)) { this.FontFamily = _fontCollection.Families[0].Name; Log.WriteLine("AUTO-SELECTING font family {0}", this.FontFamily); } } this.charMap = EmojiTest.Utils.GenerateEmojiBitmap(FontFamily, this.CharSizeNoPadding.Width, this.CharSizeNoPadding.Height, Scale, Shift.Width, Shift.Height, cps, BackgroundPalette, ForegroundPalette, AspectTolerance, tryToFit, this.FontStyle, this.FontWeight, this.FontStretch, this.StrictGlyphCheck, this.TextAAMode); }
public static FontFamilyFontProvider ProcessArgs(string[] args) { // -fonttype fontfamily // -fontfamily "Segoe UI emoji" // -fontfile "blah.wtf" // -charsize 8x8 // -UnicodeGlyphTextFile emoji-data-v12.txt // -bgcolor #000000 // -fgcolor #ffffff // -scale 1.2 // -shift 2x2 // -fontname "Segoe" <-- just to help name dirs/files string fontFamily = ""; string fontFile = ""; Size charSize = new Size(8, 8); string unicodeGlyphTextFile = ""; Color[] bgPalette = new Color[] { Color.White }; Color[] fgPalette = new Color[] { Color.Black }; float scale = 1.0f; Size shift = new Size(0, 0); string fontName = ""; float? aspectTolerance = null; bool tryToFit = false; string charListTextFile = ""; bool strictGlyphCheck = true; System.Windows.FontWeight fontWeight = System.Windows.FontWeights.Normal; System.Windows.FontStyle fontStyle = System.Windows.FontStyles.Normal; System.Windows.FontStretch fontStretch = System.Windows.FontStretches.Normal; //SharpDX.DirectWrite.RenderingMode renderingMode = SharpDX.DirectWrite.RenderingMode.Outline; SharpDX.Direct2D1.TextAntialiasMode textAAMode = SharpDX.Direct2D1.TextAntialiasMode.Grayscale; args.ProcessArg("-fontfamily", s => { fontFamily = s; }); args.ProcessArg("-charListTextFile", s => { charListTextFile = s; }); args.ProcessArg("-tryToFit", s => { tryToFit = Utils.ToBool(s); }); args.ProcessArg("-fontFile", s => { fontFile = s; }); args.ProcessArg("-charsize", s => { charSize = new Size(int.Parse(s.Split('x')[0]), int.Parse(s.Split('x')[1])); }); args.ProcessArg("-UnicodeGlyphTextFile", s => { unicodeGlyphTextFile = s; }); args.ProcessArg("-bgcolor", s => { bgPalette = new Color[] { System.Drawing.ColorTranslator.FromHtml(s) }; }); args.ProcessArg("-fgcolor", s => { fgPalette = new Color[] { System.Drawing.ColorTranslator.FromHtml(s) }; }); args.ProcessArg("-bgpalette", s => { bgPalette = Utils.GetNamedPalette(s); }); args.ProcessArg("-fgpalette", s => { fgPalette = Utils.GetNamedPalette(s); }); args.ProcessArg("-scale", s => { scale = float.Parse(s); }); args.ProcessArg("-shift", s => { shift = new Size(int.Parse(s.Split('x')[0]), int.Parse(s.Split('x')[1])); }); args.ProcessArg("-aspectTolerance", s => { if (float.TryParse(s, out float f)) { aspectTolerance = f; } }); args.ProcessArg("-fontname", s => { fontName = s; }); args.ProcessArg("-strictGlyphCheck", s => { strictGlyphCheck = Utils.ToBool(s); }); args.ProcessArg("-fontWeight", s => { fontWeight = System.Windows.FontWeight.FromOpenTypeWeight(int.Parse(s)); }); args.ProcessArg("-fontStyle", s => { fontStyle = (s.ToLowerInvariant() == "italic") ? System.Windows.FontStyles.Italic : System.Windows.FontStyles.Normal; }); args.ProcessArg("-fontStretch", s => { fontStretch = System.Windows.FontStretch.FromOpenTypeStretch(int.Parse(s)); }); args.ProcessArg("-fontsmoothing", s => { switch (s.ToLowerInvariant()) { case "aliased": textAAMode = SharpDX.Direct2D1.TextAntialiasMode.Aliased; break; case "cleartype": textAAMode = SharpDX.Direct2D1.TextAntialiasMode.Cleartype; break; case "grayscale": textAAMode = SharpDX.Direct2D1.TextAntialiasMode.Grayscale; break; } }); if (string.IsNullOrEmpty(fontName)) { fontName = fontFamily; } return(new FontFamilyFontProvider(fontFamily, fontFile, charSize, unicodeGlyphTextFile, bgPalette, fgPalette, scale, shift, aspectTolerance, fontName, tryToFit, charListTextFile, strictGlyphCheck, fontWeight, fontStyle, fontStretch, textAAMode)); }