コード例 #1
0
 public static void CreateMenu(
     MenuFlyout menu,
     InstalledFont font,
     bool standalone,
     bool showAdvanced = false)
 {
     MainViewModel main = ResourceHelper.Get <ViewModelLocator>("Locator").Main;
コード例 #2
0
        public static FontFace LoadFont(InstalledFont installedFont, string lang, HBDirection direction, int defaultScriptCode = 0)
        {

            NativeFontFace fontFace = LoadFreeTypeFontFace(installedFont);
            SetShapingEngine(fontFace, lang, direction, defaultScriptCode);
            return fontFace;
        }
コード例 #3
0
        public void Test_LettersDontRenderAsRectangles_SerifFont()
        {
            // this test ensures letters don't render as rectangles
            // https://github.com/ScottPlot/ScottPlot/issues/1079

            System.Drawing.Bitmap bmp = new(200, 100);
            using var gfx         = Graphics.FromImage(bmp);
            gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
            gfx.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;

            string[] fontNames = { InstalledFont.Serif(), InstalledFont.Sans(), InstalledFont.Monospace() };

            foreach (string fontName in fontNames)
            {
                gfx.Clear(Color.Navy);
                System.Drawing.Font fnt = new(fontName, 18);

                gfx.DrawString("tttt", fnt, Brushes.Yellow, 10, 10);
                string hash1 = ScottPlot.Tools.BitmapHash(bmp);

                gfx.DrawString("eeee", fnt, Brushes.Yellow, 10, 10);
                string hash2 = ScottPlot.Tools.BitmapHash(bmp);

                Assert.AreNotEqual(hash1, hash2);
            }
        }
コード例 #4
0
 static NativeFontFace LoadFreeTypeFontFace(InstalledFont installedFont)
 {
     //if not found
     //then load it
     byte[] fontFileContent = File.ReadAllBytes(installedFont.FontPath);
     int filelen = fontFileContent.Length;
     IntPtr unmanagedMem = Marshal.AllocHGlobal(filelen);
     Marshal.Copy(fontFileContent, 0, unmanagedMem, filelen);
     //---------------------------------------------------
     //convert font point size to pixel size 
     //---------------------------------------------------
     //load font from memory
     IntPtr faceHandle = NativeMyFontsLib.MyFtNewMemoryFace(unmanagedMem, filelen);
     if (faceHandle == IntPtr.Zero)
     {
         //error
         //load font error
         Marshal.FreeHGlobal(unmanagedMem);
         return null;
     }
     //------------------------------------------------------- 
     NativeFontFace fontFace = new NativeFontFace(unmanagedMem, faceHandle, installedFont.FontName,
         installedFont.FontPath, FontStyle.Regular);
     fontFace.LoadFromFilename = installedFont.FontPath;
     ExportTypeFaceInfo exportTypeInfo = new ExportTypeFaceInfo();
     NativeMyFontsLib.MyFtGetFaceInfo(faceHandle, ref exportTypeInfo);
     fontFace.HasKerning = exportTypeInfo.hasKerning;
     //------------------------------------------------------- 
     return fontFace;
 }
コード例 #5
0
        private void CmbFontFamily_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var font     = (sender as ComboBox).SelectedItem as InstalledFont;
            var fontList = InstalledFont.GetFonts();
            var items    = font.GetCharacters();

            gridView.ItemsSource = items;
        }
コード例 #6
0
 /// <summary>
 /// Creates the context menu for the Font List or the "..." button.
 /// Both of these have a font as their main target.
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="font"></param>
 /// <param name="variant"></param>
 /// <param name="headerContent"></param>
 /// <param name="standalone"></param>
 /// <param name="showAdvanced"></param>
 public static void CreateMenu(
     MenuFlyout menu,
     InstalledFont font,
     CharacterRenderingOptions options,
     FrameworkElement headerContent,
     bool standalone,
     bool showAdvanced = false)
 {
     MainViewModel main = Ioc.Default.GetService <MainViewModel>();
コード例 #7
0
 public static void CreateMenu(
     MenuFlyout menu,
     InstalledFont font,
     FontVariant variant,
     CanvasTextLayoutAnalysis variantAnalysis,
     bool standalone,
     bool showAdvanced = false)
 {
     MainViewModel main = ResourceHelper.Get <ViewModelLocator>("Locator").Main;
コード例 #8
0
ファイル: NativeTextWin32.cs プロジェクト: dhilip89/PixelFarm
        public WinGdiFontFace(RequestFont f)
        {
            this.style = f.Style;
            //resolve
            InstalledFont foundInstalledFont = s_fontLoader.GetFont(f.Name, style.ConvToInstalledFontStyle());

            //TODO: review
            this.nopenTypeFontFace = OpenFontLoader.LoadFont(foundInstalledFont.FontPath);
        }
コード例 #9
0
 /// <summary>
 /// Creates the context menu for the Font List or the "..." button.
 /// Both of these have a font as their main target.
 /// </summary>
 /// <param name="menu"></param>
 /// <param name="font"></param>
 /// <param name="variant"></param>
 /// <param name="headerContent"></param>
 /// <param name="standalone"></param>
 /// <param name="showAdvanced"></param>
 public static void CreateMenu(
     MenuFlyout menu,
     InstalledFont font,
     FontVariant variant,
     FrameworkElement headerContent,
     bool standalone,
     bool showAdvanced = false)
 {
     MainViewModel main = Ioc.Default.GetService <MainViewModel>();
コード例 #10
0
 public static void CreateMenu(
     MenuFlyout menu,
     InstalledFont font,
     FontVariant variant,
     FrameworkElement headerContent,
     bool standalone,
     bool showAdvanced = false)
 {
     MainViewModel main = ResourceHelper.Get <ViewModelLocator>("Locator").Main;
コード例 #11
0
        private void FilterFontList(bool isSymbolFontsOnly)
        {
            var fontList = InstalledFont.GetFonts();

            var newList = fontList.Where(f => f.IsSymbolFont || !isSymbolFontsOnly)
                          .OrderBy(f => f.Name)
                          .ToObservableCollection();

            FontList = newList;
        }
コード例 #12
0
        /// <summary>
        /// Creates the context menu for the Font List or the "..." button.
        /// Both of these have a font as their main target.
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="font"></param>
        /// <param name="variant"></param>
        /// <param name="headerContent"></param>
        /// <param name="standalone"></param>
        /// <param name="showAdvanced"></param>
        public static void CreateMenu(
            MenuFlyout menu,
            InstalledFont font,
            CharacterRenderingOptions options,
            FrameworkElement headerContent,
            FlyoutArgs args)
        {
            MainViewModel main = Ioc.Default.GetService <MainViewModel>();

            bool standalone     = args.Standalone;
            bool showAdvanced   = args.ShowAdvanced;
            bool isExternalFile = args.IsExternalFile;
コード例 #13
0
        void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "Render with PixelFarm";
            this.lstFontSizes.SelectedIndex = 0;// lstFontSizes.Items.Count - 3;

            var installedFont = lstFontList.SelectedItem as InstalledFont;

            if (installedFont != null)
            {
                _selectedInstallFont = installedFont;
            }
        }
コード例 #14
0
            static InstalledFont[] Init()
            {
                var systemFonts = Fonts.SystemFontFamilies;
                var l           = new InstalledFont[systemFonts.Count];
                var i           = 0;

                foreach (var item in systemFonts)
                {
                    l[i++] = new InstalledFont(item);
                }
                Array.Sort(l, (x, y) => x.Name.CompareTo(y.Name));
                return(l);
            }
コード例 #15
0
        private void CmbFontFamily_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (gridView.Visibility == Visibility.Collapsed)
            {
                gridView.Visibility    = Visibility.Visible;
                placeholder.Visibility = Visibility.Collapsed;
            }
            var font     = (sender as ComboBox).SelectedItem as InstalledFont;
            var fontList = InstalledFont.GetFonts();
            var items    = font.GetCharacters();

            gridView.ItemsSource = items;
        }
コード例 #16
0
        public void Test_DrawString_Aligned()
        {
            using System.Drawing.Bitmap bmp = new(400, 300);
            using Graphics gfx = Graphics.FromImage(bmp);
            gfx.Clear(Color.Navy);

            gfx.DrawLine(Pens.Gray, 150, 0, 150, 300);
            gfx.DrawLine(Pens.Gray, 0, 150, 400, 150);
            gfx.DrawEllipse(Pens.White, 145, 145, 10, 10);

            GDI.DrawLabel(
                gfx, "testing", 150, 150, InstalledFont.Sans(), 16, true,
                HorizontalAlignment.Left, VerticalAlignment.Upper,
                Color.Yellow, Color.Magenta);

            TestTools.SaveBitmap(bmp);
        }
コード例 #17
0
        //  PixelFarm.Drawing.Fonts.SvgFontStore svgFontStore = new PixelFarm.Drawing.Fonts.SvgFontStore();
        protected override void OnInitGLProgram(object sender, EventArgs args)
        {
            //temp***
            int max = Math.Max(this.Width, this.Height);

            canvas2d = PixelFarm.Drawing.GLES2.GLES2Platform.CreateCanvasGL2d(max, max);
            painter  = new GLCanvasPainter(canvas2d, max, max);

            //----------------------
            var win32InstallFontProvider       = new PixelFarm.Drawing.InstallFontsProviderWin32();
            InstalledFontCollection collection = new InstalledFontCollection();

            collection.LoadInstalledFont(win32InstallFontProvider.GetInstalledFontIter());
            InstalledFont tahomaFont = collection.GetFont("tahoma", InstalledFontStyle.Regular);
            FontFace      tahomaFace = OpenFontLoader.LoadFont(tahomaFont.FontPath, ScriptLangs.Latin);
            ActualFont    actualFont = tahomaFace.GetFontAtPointsSize(72);
            FontGlyph     glyph      = actualFont.GetGlyph('K');

            //var svgFont = svgFontStore.LoadFont("svg-LiberationSansFont", 300);
            ////PathWriter p01 = new PathWriter();
            ////p01.MoveTo(0, 0);
            ////p01.LineTo(50, 100);
            ////p01.LineTo(100, 0);
            //////-
            ////p01.MoveTo(220, 10);
            ////p01.LineTo(50, 75);
            ////p01.LineTo(25, 15);
            ////p01.CloseFigure();
            ////p01.Stop();
            ////m_pathVxs = p01.Vxs;

            //var m_pathVxs = svgFont.GetGlyph('K').originalVxs;// typeFaceForLargeA.GetGlyphForCharacter('a');
            ////m_pathVxs = MergeFontSubFigures(m_pathVxs);

            //Affine shape_mtx = Affine.NewMatix(AffinePlan.Translate(150, 100));
            //m_pathVxs = shape_mtx.TransformToVxs(m_pathVxs);
            //var curveFlattener = new CurveFlattener();
            //var m_pathVxs2 = curveFlattener.MakeVxs(m_pathVxs);

            glyph_vx = painter.CreateRenderVx(tempSnap1 = new PixelFarm.Agg.VertexStoreSnap(glyph.flattenVxs));

            linearGrBrush2 = new LinearGradientBrush(
                new PointF(0, 0), Color.Red,
                new PointF(100, 100), Color.Black);
            //----------------------
        }
コード例 #18
0
        public InstalledFont GetFont(string fontName, InstalledFontStyle style)
        {
            InstalledFont found = installFontCollection.GetFont(fontName, style);

            if (found == null)
            {
                //not found
                if (fontNotFoundHandler != null)
                {
                    return(fontNotFoundHandler(installFontCollection, fontName, null, style));
                }
                else
                {
                    return(_defaultFontNotFoundHandler(installFontCollection, fontName, null, style));
                }
            }
            return(found);
        }
コード例 #19
0
        public ActualFont LoadFont(string fontName, float fontSizeInPoints)
        {
            //find install font from fontname
            InstalledFont found = PixelFarm.Drawing.GLES2.GLES2Platform.GetInstalledFont(fontName, InstalledFontStyle.Regular);

            if (found == null)
            {
                return(null);
            }

            FontFace fontFace;

            if (!fonts.TryGetValue(found, out fontFace))
            {
                throw new NotSupportedException("revisit freetype impl");
                //convert to freetype data

                //TODO: review here
                //fontFace = FreeTypeFontLoader.LoadFont(found,
                //    GLES2PlatformFontMx.defaultScriptLang
                //    GLES2PlatformFontMx.defaultHbDirection,
                //    GLES2PlatformFontMx.defaultScriptCode);
                //fontFace = FreeTypeFontLoader.LoadFont(found,
                //     "en",
                //     HBDirection.HB_DIRECTION_RTL);

                if (fontFace == null)
                {
                    throw new NotSupportedException();
                }
                fonts.Add(found, fontFace);//register
            }
            //-----------
            //create font at specific size from this fontface
            FontKey    fontKey = new FontKey(fontName, fontSizeInPoints, FontStyle.Regular);
            ActualFont createdFont;

            if (!registerFonts.TryGetValue(fontKey, out createdFont))
            {
                createdFont = fontFace.GetFontAtPointSize(fontSizeInPoints);
            }
            //-----------
            return(createdFont);
        }
コード例 #20
0
        internal static SkiaSharp.SKTypeface GetInstalledFont(string typefaceName)
        {
            InstalledFont installedFont = s_fontLoader.GetFont(typefaceName, InstalledFontStyle.Normal);

            if (installedFont == null)
            {
                return(null);
            }
            else
            {
                SkiaSharp.SKTypeface loadedTypeFace;
                if (!skTypeFaces.TryGetValue(installedFont, out loadedTypeFace))
                {
                    loadedTypeFace = SkiaSharp.SKTypeface.FromFile(installedFont.FontPath);
                    skTypeFaces.Add(installedFont, loadedTypeFace);
                }
                return(loadedTypeFace);
            }
        }
コード例 #21
0
        void SetupFontList()
        {
            InstalledFont selectedFF     = null;
            int           selected_index = 0;
            int           ffcount        = 0;
            bool          found          = false;

            string defaultFont = "Tahoma";

            //string defaultFont = "Alef"; //test hebrew
            //string defaultFont = "Century";
            foreach (InstalledFont ff in _options.GetInstalledFontIter())
            {
                if (!found && ff.FontName == defaultFont)
                {
                    selectedFF             = ff;
                    selected_index         = ffcount;
                    _options.InstalledFont = ff;
                    found = true;
                }
                lstFontList.Items.Add(ff);
                ffcount++;
            }
            //set default font for current text printer
            //


            if (selected_index < 0)
            {
                selected_index = 0;
            }
            lstFontList.SelectedIndex         = selected_index;
            lstFontList.SelectedIndexChanged += (s, e) =>
            {
                InstalledFont ff = lstFontList.SelectedItem as InstalledFont;
                if (ff != null)
                {
                    _options.InstalledFont = ff;
                    _options.InvokeAttachEvents();
                }
            };
        }
コード例 #22
0
        public static void RequestDelete(InstalledFont font)
        {
            MainViewModel main = Ioc.Default.GetService <MainViewModel>();
            var           d    = new ContentDialog
            {
                Title = Localization.Get("DlgDeleteFont/Title"),
                IsPrimaryButtonEnabled   = true,
                IsSecondaryButtonEnabled = true,
                PrimaryButtonText        = Localization.Get("DigDeleteCollection/PrimaryButtonText"),
                SecondaryButtonText      = Localization.Get("DigDeleteCollection/SecondaryButtonText"),
            };

            d.PrimaryButtonClick += (ds, de) =>
            {
                _ = MainPage.MainDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    main.TryRemoveFont(font);
                });
            };
            _ = d.ShowAsync();
        }
コード例 #23
0
        public void Test_DefaultFont_MatchesOsExpectations()
        {
            string defaultFont = InstalledFont.Default();

            Console.WriteLine($">>> Default font: {defaultFont}");

            string defaultFontSans = InstalledFont.Sans();

            Console.WriteLine($">>> Default sans font: {defaultFontSans}");

            string defaultFontSerif = InstalledFont.Serif();

            Console.WriteLine($">>> Default serif font: {defaultFontSerif}");

            string defaultFontMonospace = InstalledFont.Monospace();

            Console.WriteLine($">>> Default monospace font: {defaultFontMonospace}");

            Assert.That(defaultFont == defaultFontSans);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Assert.That(defaultFontSans == "Segoe UI");
                Assert.That(defaultFontSerif == "Times New Roman");
                Assert.That(defaultFontMonospace == "Consolas");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Assert.That(defaultFontSans == "DejaVu Sans");
                Assert.That(defaultFontSerif == "DejaVu Serif");
                Assert.That(defaultFontMonospace == "DejaVu Sans Mono");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                Assert.That(defaultFontSans == "Helvetica");
                Assert.That(defaultFontSerif.StartsWith("Times"));
                Assert.That(defaultFontMonospace == "Courier");
            }
        }
コード例 #24
0
ファイル: Drawing.cs プロジェクト: yongmingxia/ScottPlot
        public void Test_MeasureString_ShowSize()
        {
            string testString = "ScottPlot";

            var   fontName = InstalledFont.Default();
            float fontSize = 14;

            // an active Graphics object is required to measure a string...
            using (var bmp = new System.Drawing.Bitmap(1, 1))
                using (var gfx = System.Drawing.Graphics.FromImage(bmp))
                    using (var font = new System.Drawing.Font(fontName, fontSize))
                    {
                        var stringSize = ScottPlot.Drawing.GDI.MeasureString(gfx, testString, font);

                        var sb = new StringBuilder();
                        sb.AppendLine(System.Environment.OSVersion.ToString());
                        sb.AppendLine($"The string '{testString}' with font '{fontName}' (size {fontSize}) " +
                                      $"measures: {stringSize.Width}px x {stringSize.Height}px");

                        Console.WriteLine(sb);
                    }
        }
コード例 #25
0
        protected override void OnReadyForInitGLShaderProgram()
        {
            InstalledFontCollection collection = new InstalledFontCollection();

            collection.LoadSystemFonts();
            InstalledFont tahomaFont = collection.GetFont("tahoma", InstalledFontStyle.Normal);
            FontFace      tahomaFace = OpenFontLoader.LoadFont(tahomaFont.FontPath);
            ActualFont    actualFont = tahomaFace.GetFontAtPointSize(72);
            FontGlyph     glyph      = (FontGlyph)actualFont.GetGlyph('K');

            //var svgFont = svgFontStore.LoadFont("svg-LiberationSansFont", 300);
            ////PathWriter p01 = new PathWriter();
            ////p01.MoveTo(0, 0);
            ////p01.LineTo(50, 100);
            ////p01.LineTo(100, 0);
            //////-
            ////p01.MoveTo(220, 10);
            ////p01.LineTo(50, 75);
            ////p01.LineTo(25, 15);
            ////p01.CloseFigure();
            ////p01.Stop();
            ////m_pathVxs = p01.Vxs;

            //var m_pathVxs = svgFont.GetGlyph('K').originalVxs;// typeFaceForLargeA.GetGlyphForCharacter('a');
            ////m_pathVxs = MergeFontSubFigures(m_pathVxs);

            //Affine shape_mtx = Affine.NewMatix(AffinePlan.Translate(150, 100));
            //m_pathVxs = shape_mtx.TransformToVxs(m_pathVxs);
            //var curveFlattener = new CurveFlattener();
            //var m_pathVxs2 = curveFlattener.MakeVxs(m_pathVxs);

            glyph_vx = painter.CreateRenderVx(tempSnap1 = new PixelFarm.Drawing.VertexStoreSnap(glyph.flattenVxs));

            linearGrBrush2 = new LinearGradientBrush(
                new PointF(0, 0), Color.Red,
                new PointF(100, 100), Color.Black);
            //----------------------
        }
コード例 #26
0
 public AddToCollectionResult(bool success, InstalledFont font, UserFontCollection collection)
 {
     Success    = success;
     Font       = font;
     Collection = collection;
 }
コード例 #27
0
ファイル: Form2.cs プロジェクト: zwcloud/Typography
        public Form2()
        {
            InitializeComponent();

            //choose Thai script for 'complex script' testing.
            //you can change this to test other script.
            _currentTextPrinter.ScriptLang = Typography.OpenFont.ScriptLangs.Latin;
            //----------
            button1.Click += (s, e) => UpdateRenderOutput();
            //simple load test fonts from local test dir
            //and send it into test list
            chkFillBackground.Checked         = true;
            chkBorder.CheckedChanged         += (s, e) => UpdateRenderOutput();
            chkFillBackground.CheckedChanged += (s, e) => UpdateRenderOutput();
            //----------
            cmbPositionTech.Items.Add(PositionTechnique.OpenFont);
            cmbPositionTech.Items.Add(PositionTechnique.Kerning);
            cmbPositionTech.Items.Add(PositionTechnique.None);
            cmbPositionTech.SelectedIndex         = 0;
            cmbPositionTech.SelectedIndexChanged += (s, e) => UpdateRenderOutput();
            //----------
            lstHintList.Items.Add(HintTechnique.None);
            lstHintList.Items.Add(HintTechnique.TrueTypeInstruction);
            lstHintList.Items.Add(HintTechnique.TrueTypeInstruction_VerticalOnly);
            lstHintList.Items.Add(HintTechnique.CustomAutoFit);
            lstHintList.SelectedIndex         = 0;
            lstHintList.SelectedIndexChanged += (s, e) => UpdateRenderOutput();

            //----------
            //share text printer to our sample textbox
            //but you can create another text printer that specific to text textbox control
            _textBoxControllerForGdi.TextPrinter = _currentTextPrinter;
            _textBoxControllerForGdi.BindHostGraphics(this.sampleTextBox1.CreateGraphics());

            this.sampleTextBox1.SetController(_textBoxControllerForGdi);

            //----------
            txtInputChar.TextChanged += (s, e) => UpdateRenderOutput();
            //1. create font collection
            installedFontCollection = new InstalledFontCollection();
            //set some essential handler
            installedFontCollection.SetFontNameDuplicatedHandler((f1, f2) => FontNameDuplicatedDecision.Skip);
            foreach (string file in Directory.GetFiles("../../../TestFonts", "*.ttf"))
            {
                //eg. this is our custom font folder
                installedFontCollection.AddFont(new FontFileStreamProvider(file));
            }
            //
            _typefaceStore = new TypefaceStore();
            _typefaceStore.FontCollection = installedFontCollection;

            //----------
            //show result
            InstalledFont selectedFF     = null;
            int           selected_index = 0;
            int           ffcount        = 0;
            bool          found          = false;

            foreach (InstalledFont ff in installedFontCollection.GetInstalledFontIter())
            {
                if (!found && ff.FontName == "Source Sans Pro")
                {
                    selectedFF     = ff;
                    selected_index = ffcount;
                    found          = true;
                }
                lstFontList.Items.Add(ff);
                ffcount++;
            }
            //set default font for current text printer
            _currentTextPrinter.Typeface = _typefaceStore.GetTypeface(selectedFF.FontName, selectedFF.FontSubFamily);
            //----------

            if (selected_index < 0)
            {
                selected_index = 0;
            }
            lstFontList.SelectedIndex         = selected_index;
            lstFontList.SelectedIndexChanged += (s, e) =>
            {
                InstalledFont ff = lstFontList.SelectedItem as InstalledFont;
                if (ff != null)
                {
                    //direct set
                    _currentTextPrinter.Typeface = _typefaceStore.GetTypeface(ff);
                    //sample text box
                    UpdateRenderOutput();
                }
            };
            lstFontSizes.Items.AddRange(
                new object[] {
                8, 9,
                10, 11,
                12,
                14,
                16,
                18, 20, 22, 24, 26, 28, 36, 48, 72, 240, 300, 360
            });
            lstFontSizes.SelectedIndexChanged += (s, e) =>
            {
                //new font size
                _currentTextPrinter.FontSizeInPoints = (int)lstFontSizes.SelectedItem;
                UpdateRenderOutput();
            };
            lstFontSizes.SelectedIndex = 0;
            this.Text = "Gdi+ Sample";
            //------
        }
コード例 #28
0
        public Form1()
        {
            InitializeComponent();



            _devGdiTextPrinter          = new DevGdiTextPrinter();
            this.sampleTextBox1.Visible = false;
            _openFontStore = new OpenFontStore();

            //default
            //set script lang,
            //test with Thai for 'complex script'
            _current_script = Typography.OpenFont.ScriptLangs.Latin;
            _devGdiTextPrinter.ScriptLang        = _current_script;
            _devGdiTextPrinter.PositionTechnique = PositionTechnique.OpenFont;


            this.Load += new EventHandler(Form1_Load);

            this.txtGridSize.KeyDown += TxtGridSize_KeyDown;
            //----------
            txtInputChar.TextChanged += (s, e) => UpdateRenderOutput();
            //----------
            cmbRenderChoices.Items.Add(RenderChoice.RenderWithTextPrinterAndMiniAgg);
            cmbRenderChoices.Items.Add(RenderChoice.RenderWithMiniAgg_SingleGlyph);
            cmbRenderChoices.Items.Add(RenderChoice.RenderWithGdiPlusPath);
            cmbRenderChoices.Items.Add(RenderChoice.RenderWithMsdfGen);
            cmbRenderChoices.SelectedIndex         = 0;
            cmbRenderChoices.SelectedIndexChanged += (s, e) => UpdateRenderOutput();
            //----------
            cmbPositionTech.Items.Add(PositionTechnique.OpenFont);
            cmbPositionTech.Items.Add(PositionTechnique.Kerning);
            cmbPositionTech.Items.Add(PositionTechnique.None);
            cmbPositionTech.SelectedIndex         = 0;
            cmbPositionTech.SelectedIndexChanged += (s, e) => UpdateRenderOutput();
            //----------
            lstHintList.Items.Add(HintTechnique.None);
            lstHintList.Items.Add(HintTechnique.TrueTypeInstruction);
            lstHintList.Items.Add(HintTechnique.TrueTypeInstruction_VerticalOnly);
            lstHintList.Items.Add(HintTechnique.CustomAutoFit);
            lstHintList.SelectedIndex         = 0;
            lstHintList.SelectedIndexChanged += (s, e) => UpdateRenderOutput();
            //edge offset
            lstEdgeOffset.Items.Add(0f);
            lstEdgeOffset.Items.Add(-10f);
            lstEdgeOffset.Items.Add(-8f);
            lstEdgeOffset.Items.Add(-6f);
            lstEdgeOffset.Items.Add(-4f);
            lstEdgeOffset.Items.Add(4f);
            lstEdgeOffset.Items.Add(6f);
            lstEdgeOffset.Items.Add(8f);
            lstEdgeOffset.Items.Add(10f);
            lstEdgeOffset.SelectedIndex         = 0;
            lstEdgeOffset.SelectedIndexChanged += (s, e) => UpdateRenderOutput();

            //share text printer to our sample textbox
            //but you can create another text printer that specific to text textbox control
            Graphics gx = this.sampleTextBox1.CreateGraphics();

            _controllerForGdi.BindHostGraphics(gx);
            _controllerForGdi.TextPrinter = _devGdiTextPrinter;
            //----------
            _controllerForPixelFarm.BindHostGraphics(gx);
            _controllerForPixelFarm.TextPrinter = _devVxsTextPrinter;

            //----------
            this.sampleTextBox1.SetController(_controllerForPixelFarm);


            button1.Click += (s, e) => UpdateRenderOutput();
            chkShowGrid.CheckedChanged           += (s, e) => UpdateRenderOutput();
            chkShowTess.CheckedChanged           += (s, e) => UpdateRenderOutput();
            chkXGridFitting.CheckedChanged       += (s, e) => UpdateRenderOutput();
            chkYGridFitting.CheckedChanged       += (s, e) => UpdateRenderOutput();
            chkFillBackground.CheckedChanged     += (s, e) => UpdateRenderOutput();
            chkLcdTechnique.CheckedChanged       += (s, e) => UpdateRenderOutput();
            chkGsubEnableLigature.CheckedChanged += (s, e) => UpdateRenderOutput();
            //----------
            chkShowTess.CheckedChanged                     += (s, e) => UpdateRenderOutput();
            chkDrawCentroidBone.CheckedChanged             += (s, e) => UpdateRenderOutput();
            chkDrawGlyphBone.CheckedChanged                += (s, e) => UpdateRenderOutput();
            chkDynamicOutline.CheckedChanged               += (s, e) => UpdateRenderOutput();
            chkSetPrinterLayoutForLcdSubPix.CheckedChanged += (s, e) => UpdateRenderOutput();
            chkDrawTriangles.CheckedChanged                += (s, e) => UpdateRenderOutput();
            chkDrawRegenerateOutline.CheckedChanged        += (s, e) => UpdateRenderOutput();
            chkBorder.CheckedChanged                  += (s, e) => UpdateRenderOutput();
            chkDrawLineHubConn.CheckedChanged         += (s, e) => UpdateRenderOutput();
            chkDrawPerpendicularLine.CheckedChanged   += (s, e) => UpdateRenderOutput();
            chkDrawGlyphPoint.CheckedChanged          += (s, e) => UpdateRenderOutput();
            chkTestGridFit.CheckedChanged             += (s, e) => UpdateRenderOutput();
            chkUseHorizontalFitAlign.CheckedChanged   += (s, e) => UpdateRenderOutput();
            chkWriteFitOutputToConsole.CheckedChanged += (s, e) => UpdateRenderOutput();

            //----------
            //1. create font collection
            installedFontCollection = new InstalledFontCollection();
            //2. set some essential handler
            installedFontCollection.SetFontNameDuplicatedHandler((f1, f2) => FontNameDuplicatedDecision.Skip);
            foreach (string file in Directory.GetFiles(Path.Combine("..", "..", "..", "TestFonts"), "*.ttf"))
            {
                //eg. this is our custom font folder
                installedFontCollection.AddFont(new FontFileStreamProvider(file));
            }
            //3.
            //installedFontCollection.LoadSystemFonts();
            //----------
            //show result
            InstalledFont selectedFF     = null;
            int           selected_index = 0;
            int           ffcount        = 0;
            bool          found          = false;

            string defaultFont = "Tahoma";

            //string defaultFont = "Alef"; //test hebrew
            //string defaultFont = "Century";
            foreach (InstalledFont ff in installedFontCollection.GetInstalledFontIter())
            {
                if (!found && ff.FontName == defaultFont)
                {
                    selectedFF           = ff;
                    selected_index       = ffcount;
                    _selectedInstallFont = ff;
                    found = true;
                }
                lstFontList.Items.Add(ff);
                ffcount++;
            }
            //set default font for current text printer
            //
            _typefaceStore = new TypefaceStore();
            _typefaceStore.FontCollection = installedFontCollection;


            if (selected_index < 0)
            {
                selected_index = 0;
            }
            lstFontList.SelectedIndex         = selected_index;
            lstFontList.SelectedIndexChanged += (s, e) =>
            {
                InstalledFont ff = lstFontList.SelectedItem as InstalledFont;
                if (ff != null)
                {
                    _selectedInstallFont         = ff;
                    selectedTextPrinter.Typeface = _typefaceStore.GetTypeface(ff);
                    //sample text box
                    UpdateRenderOutput();
                }
            };
            //----------

            lstFontSizes.Items.AddRange(
                new object[] {
                8, 9,
                10, 11,
                12,
                14,
                16,
                18, 20, 22, 24, 26, 28, 36, 48, 72,
                240, 280, 300, 360, 400, 420, 460,
                620, 720, 860, 920, 1024
            });
            lstFontSizes.SelectedIndexChanged += (s, e) =>
            {
                //new font size
                _fontSizeInPts = (int)lstFontSizes.SelectedItem;
                UpdateRenderOutput();
            };

            //----------------
            //string inputstr = "ก้า";
            //string inputstr = "น้ำน้ำ";
            //string inputstr = "example";
            //string inputstr = "lllll";
            //string inputstr = "e";
            //string inputstr = "T";
            //string inputstr = "u";
            //string inputstr = "t";
            //string inputstr = "2";
            //string inputstr = "3";
            //string inputstr = "o";
            //string inputstr = "l";
            //string inputstr = "k";
            //string inputstr = "8";
            //string inputstr = "#";
            //string inputstr = "a";
            //string inputstr = "e";
            //string inputstr = "l";
            //string inputstr = "t";
            //string inputstr = "i";
            string inputstr = "ma";

            //string inputstr = "po";
            //string inputstr = "Å";
            //string inputstr = "fi";
            //string inputstr = "ก่นกิ่น";
            //string inputstr = "ญญู";
            //string inputstr = "ป่า"; //for gpos test
            //string inputstr = "快速上手";
            //string inputstr = "啊";

            //----------------
            this.txtInputChar.Text         = inputstr;
            this.chkFillBackground.Checked = true;
            _readyToRender = true;
        }
コード例 #29
0
        public MainViewModel()
        {
            var fontList = InstalledFont.GetFonts();

            FontList = fontList.OrderBy(f => f.Name).ToObservableCollection();
        }
コード例 #30
0
        private void InitializeList()
        {
            var fontList = InstalledFont.GetFonts();

            CmbFontFamily.ItemsSource = fontList;
        }
コード例 #31
0
 public CollectionUpdatedArgs(InstalledFont font, UserFontCollection collection, bool isAdd)
 {
     Font       = font;
     Collection = collection;
     IsAdd      = isAdd;
 }
コード例 #32
0
ファイル: Form1.cs プロジェクト: luislasonbra/PixelFarm
        public Form1()
        {
            InitializeComponent();

            //choose Thai script for 'complex script' testing.
            //you can change this to test other script.
            _currentTextPrinter.ScriptLang = Typography.OpenFont.ScriptLangs.Thai;
            //----------
            button1.Click += (s, e) => UpdateRenderOutput();
            //simple load test fonts from local test dir
            //and send it into test list
            chkFillBackground.Checked         = true;
            chkBorder.CheckedChanged         += (s, e) => UpdateRenderOutput();
            chkFillBackground.CheckedChanged += (s, e) => UpdateRenderOutput();
            //----------
            cmbPositionTech.Items.Add(PositionTechnique.OpenFont);
            cmbPositionTech.Items.Add(PositionTechnique.Kerning);
            cmbPositionTech.Items.Add(PositionTechnique.None);
            cmbPositionTech.SelectedIndex         = 0;
            cmbPositionTech.SelectedIndexChanged += (s, e) => UpdateRenderOutput();
            //----------
            lstHintList.Items.Add(HintTechnique.None);
            lstHintList.Items.Add(HintTechnique.TrueTypeInstruction);
            lstHintList.Items.Add(HintTechnique.TrueTypeInstruction_VerticalOnly);
            //lstHintList.Items.Add(HintTechnique.CustomAutoFit);
            lstHintList.SelectedIndex         = 0;
            lstHintList.SelectedIndexChanged += (s, e) => UpdateRenderOutput();
            //----------
            txtInputChar.TextChanged += (s, e) => UpdateRenderOutput();
            //

            //1. create font collection
            installedFontCollection = new InstalledFontCollection();
            //2. set some essential handler
            installedFontCollection.SetFontNameDuplicatedHandler((f1, f2) => FontNameDuplicatedDecision.Skip);

            installedFontCollection.LoadFontsFromFolder("../../../TestFonts_Err");
            installedFontCollection.LoadFontsFromFolder("../../../TestFonts");
            //installedFontCollection.LoadSystemFonts();

            //----------
            //show result
            InstalledFont selectedFF     = null;
            int           selected_index = 0;
            int           ffcount        = 0;
            bool          found          = false;

            foreach (InstalledFont ff in installedFontCollection.GetInstalledFontIter())
            {
                if (!found && ff.FontName == "Tahoma")
                {
                    selectedFF     = ff;
                    selected_index = ffcount;
                    found          = true;
                }
                lstFontList.Items.Add(ff);
                ffcount++;
            }
            //set default font for current text printer
            //
            _typefaceStore = new TypefaceStore();
            _typefaceStore.FontCollection = installedFontCollection;
            //set default font for current text printer
            _currentTextPrinter.Typeface = _typefaceStore.GetTypeface(selectedFF);
            //----------


            if (selected_index < 0)
            {
                selected_index = 0;
            }
            lstFontList.SelectedIndex         = selected_index;
            lstFontList.SelectedIndexChanged += (s, e) =>
            {
                InstalledFont ff = lstFontList.SelectedItem as InstalledFont;
                if (ff != null)
                {
                    _currentTextPrinter.Typeface = _typefaceStore.GetTypeface(ff);
                    //sample text box
                    UpdateRenderOutput();
                }
            };
            //----------
            lstFontSizes.Items.AddRange(
                new object[] {
                8, 9,
                10, 11,
                12,
                14,
                16,
                18, 20, 22, 24, 26, 28, 36, 48, 72, 240, 300, 360
            });
            lstFontSizes.SelectedIndexChanged += (s, e) =>
            {
                //new font size
                _currentTextPrinter.FontSizeInPoints = (int)lstFontSizes.SelectedItem;
                UpdateRenderOutput();
            };
            lstFontSizes.SelectedIndex = 0;
            this.Text = "Gdi+ Sample";
            //------
        }