当前位置: 首页>>代码示例>>C#>>正文


C# PrivateFontCollection.AddFontFile方法代码示例

本文整理汇总了C#中System.Drawing.Text.PrivateFontCollection.AddFontFile方法的典型用法代码示例。如果您正苦于以下问题:C# PrivateFontCollection.AddFontFile方法的具体用法?C# PrivateFontCollection.AddFontFile怎么用?C# PrivateFontCollection.AddFontFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Text.PrivateFontCollection的用法示例。


在下文中一共展示了PrivateFontCollection.AddFontFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RegisterFont

        /// <summary>
        /// Installs font on the user's system and adds it to the registry so it's available on the next session
        /// Your font must be included in your project with its build path set to 'Content' and its Copy property
        /// set to 'Copy Always'
        /// </summary>
        /// <param name="contentFontName">Your font to be passed as a resource (i.e. "myfont.tff")</param>
        private static void RegisterFont(string contentFontName)
        {
            DirectoryInfo dirWindowsFolder = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System));

            // Concatenate Fonts folder onto Windows folder.
            string strFontsFolder = Path.Combine(dirWindowsFolder.FullName, "Fonts");

            // Creates the full path where your font will be installed
            var fontDestination = Path.Combine(strFontsFolder, contentFontName);

            if (!File.Exists(fontDestination))
            {
                // Copies font to destination
                System.IO.File.Copy(Path.Combine(System.IO.Directory.GetCurrentDirectory(), contentFontName), fontDestination);

                // Retrieves font name
                // Makes sure you reference System.Drawing
                PrivateFontCollection fontCol = new PrivateFontCollection();
                fontCol.AddFontFile(fontDestination);
                var actualFontName = fontCol.Families[0].Name;

                //Add font
                AddFontResource(fontDestination);
                //Add registry entry   
                Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts",
        actualFontName, contentFontName, RegistryValueKind.String);
            }
        }
开发者ID:sanlinnaing,项目名称:MyInput,代码行数:34,代码来源:FontInstaller.cs

示例2: CustomFonts

 static CustomFonts()
 {
     Fonts = new PrivateFontCollection();
     Fonts.AddFontFile(Path.Combine(Environment.CurrentDirectory, "Fonts", "FontAwesome.ttf"));
     Fonts.AddFontFile(Path.Combine(Environment.CurrentDirectory, "Fonts", "Lato-Bol.ttf"));
     Fonts.AddFontFile(Path.Combine(Environment.CurrentDirectory, "Fonts", "Lato-Reg.ttf"));
     Fonts.AddFontFile(Path.Combine(Environment.CurrentDirectory, "Fonts", "Lato-RegIta.ttf"));
 }
开发者ID:seanfuture,项目名称:Slack,代码行数:8,代码来源:CustomFonts.cs

示例3: init

        public static void init()
        {
            var a = new PrivateFontCollection();

            a.AddFontFile(@"res/FONT/mplantin.ttf");
            a.AddFontFile(@"res/FONT/MatrixBold.ttf");
            a.AddFontFile(@"res/FONT/Maiandra GD.ttf");

            fontFamilies[MPLATIN] = a.Families[0];
            fontFamilies[MANGALB] = a.Families[1];
            fontFamilies[MAIANDRA] = a.Families[2];
        }
开发者ID:shtonki,项目名称:cardstone,代码行数:12,代码来源:FontLoader.cs

示例4: LoadFonts

        private static void LoadFonts(PrivateFontCollection fonts, string folderPath, bool recursive = true)
        {
            if (!Directory.Exists(folderPath))
                return;

            foreach (var item in Directory.GetFiles(folderPath, "*.*tf"))
            {
                string ext = Path.GetExtension(item);

                if (string.IsNullOrEmpty(ext) || ext.Length != 4)
                    continue;

                try
                {
                    fonts.AddFontFile(item);
                }
                catch(Exception ex)
                {
                    Logging.LogManagerProvider.Instance.WriteError(ex, string.Format("Font '{0}' can not be loaded", item));
                }
            }

            if (!recursive)
                return;

            foreach (var subdir in Directory.GetDirectories(folderPath))
                LoadFonts(fonts, subdir, recursive);
        }
开发者ID:spbuksh,项目名称:CuratedGalleries,代码行数:28,代码来源:FontLoader.cs

示例5: Form1

        public Form1()
        {
            InitializeComponent();
            rand = new Random();
            dataGrid = new Grid("TileMap.csv");
            Controls.Add(dataGrid);
            sound = new System.Windows.Media.MediaPlayer();
            sound.Open(new Uri("pacmanDubHeavy.mp3", UriKind.Relative));
            sound.Play();

            gameEngine = new GameEngine(dataGrid, rand, timer1.Interval);

            //pacman font
            PrivateFontCollection fontCollection = new PrivateFontCollection();
            fontCollection.AddFontFile("crackman.ttf");

            FontFamily ff = fontCollection.Families[0];
            int fontsize = 12;
            Font pacmanFont = new Font(ff, fontsize, FontStyle.Bold);

            label2.Font = pacmanFont;
            label3.Font = pacmanFont;
            label4.Font = pacmanFont;

            lifeCounter = new PictureBox[3];
            lifeCounter[0] = pictureBox1;
            lifeCounter[1] = pictureBox2;
            lifeCounter[2] = pictureBox3;
        }
开发者ID:StephGarland,项目名称:PacMan,代码行数:29,代码来源:Form1.cs

示例6: LoadCustomFont

 private void LoadCustomFont()
 {
     m_privateFontCollection = new PrivateFontCollection();
     m_privateFontCollection.AddFontFile(Directory.GetCurrentDirectory() + "\\content\\Capture_it.ttf");
 
     m_labelFont = new Font(m_privateFontCollection.Families[0], 10.0f, FontStyle.Regular);
 }
开发者ID:craiglonsdale,项目名称:TDLAlphaServer,代码行数:7,代码来源:Form1.Designer.cs

示例7: Intro

 public Intro()
 {
     InitializeComponent();
     PrivateFontCollection pfc = new PrivateFontCollection();
     pfc.AddFontFile("..\\..\\TrajanPro-Regular.ttf");
     label1.Font = new Font(pfc.Families[0], 10, FontStyle.Bold);
 }
开发者ID:OminusRumors,项目名称:Titanic-interactive-infographic,代码行数:7,代码来源:Intro.cs

示例8: Intitial

        /// <summary>
        /// 初始化
        /// </summary>
        public void Intitial( FontMgr.FontLoadInfo fontLoadInfo )
        {
            try
            {
                privateFontCollection = new PrivateFontCollection();

                foreach (FontMgr.FontInfo info in fontLoadInfo.UnitCodeFontInfos)
                {
                    privateFontCollection.AddFontFile( info.path );
                }

                fontFamilys = privateFontCollection.Families;

                if (fontFamilys.Length != fontLoadInfo.UnitCodeFontInfos.Count)
                    throw new Exception( "导入的各个字体必须属于不同类别" );

                for (int i = 0; i < fontFamilys.Length; i++)
                {
                    fonts.Add( fontLoadInfo.UnitCodeFontInfos[i].name, new System.Drawing.Font( fontFamilys[i], fontLoadInfo.DefualtEmSize ) );
                }

                System.Drawing.Bitmap tempBitMap = new System.Drawing.Bitmap( 1, 1 );
                mesureGraphics = System.Drawing.Graphics.FromImage( tempBitMap );
            }
            catch (Exception)
            {
                throw new Exception( "读取字体文件出错" );
            }

        }
开发者ID:ingex0,项目名称:smarttank,代码行数:33,代码来源:ChineseWriter.cs

示例9: QFont

        public QFont(string fileName, float size, FontStyle style, QFontBuilderConfiguration config)
        {
            PrivateFontCollection pfc = new PrivateFontCollection();
            pfc.AddFontFile(fileName);
            var fontFamily = pfc.Families[0];

            if (!fontFamily.IsStyleAvailable(style))
                throw new ArgumentException("Font file: " + fileName + " does not support style: " +  style );

            if (config == null)
                config = new QFontBuilderConfiguration();

            TransformViewport? transToVp = null;
            float fontScale = 1f;
            if (config.TransformToCurrentOrthogProjection)
                transToVp = OrthogonalTransform(out fontScale);

            using(var font = new Font(fontFamily, size * fontScale * config.SuperSampleLevels, style)){
                fontData = BuildFont(font, config, null);
            }

            if (config.ShadowConfig != null)
                Options.DropShadowActive = true;
            if (transToVp != null)
                Options.TransformToViewport = transToVp;

            if(config.UseVertexBuffer)
                InitVBOs();
        }
开发者ID:swax,项目名称:QuickFont,代码行数:29,代码来源:QFont.cs

示例10: Form1_Paint

        // Draw Faked Beveled effect
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            Bitmap canvas = Canvas.GenImage(ClientSize.Width, ClientSize.Height);

            // Text context to store string and font info to be sent as parameter to Canvas methods
            TextContext context = new TextContext();

            // Load a font from its file into private collection,
            // instead of from system font collection
            //=============================================================
            PrivateFontCollection fontcollection = new PrivateFontCollection();

            string szFontFile = "..\\..\\..\\CommonFonts\\Segoe Print.TTF";

            fontcollection.AddFontFile(szFontFile);
            if (fontcollection.Families.Count() > 0)
                context.fontFamily = fontcollection.Families[0];

            context.fontStyle = FontStyle.Regular;
            context.nfontSize = 38;

            context.pszText = "Love Like Magic";
            context.ptDraw = new Point(0, 0);

            // Draw the main outline
            //==========================================================
            ITextStrategy mainOutline = Canvas.TextOutline(Color.FromArgb(235, 10, 230), Color.FromArgb(235, 10, 230), 4);
            Canvas.DrawTextImage(mainOutline, canvas, new Point(4, 4), context);

            // Draw the small bright outline shifted (-2, -2)
            //==========================================================
            ITextStrategy mainBright = Canvas.TextOutline(Color.FromArgb(252, 173, 250), Color.FromArgb(252, 173, 250), 2);
            Canvas.DrawTextImage(mainBright, canvas, new Point(2, 2), context);

            // Draw the small dark outline shifted (+2, +2)
            //==========================================================
            ITextStrategy mainDark = Canvas.TextOutline(Color.FromArgb(126, 5, 123), Color.FromArgb(126, 5, 123), 2);
            Canvas.DrawTextImage(mainDark, canvas, new Point(6, 6), context);

            // Draw the smallest outline (color same as main outline)
            //==========================================================
            ITextStrategy mainInner = Canvas.TextOutline(Color.FromArgb(235, 10, 230), Color.FromArgb(235, 10, 230), 2);
            Canvas.DrawTextImage(mainInner, canvas, new Point(4, 4), context);

            // Finally blit the rendered canvas onto the window
            e.Graphics.DrawImage(canvas, 0, 0, ClientSize.Width, ClientSize.Height);

            // Release all the resources
            //============================
            canvas.Dispose();

            mainOutline.Dispose();
            mainBright.Dispose();
            mainDark.Dispose();
            mainInner.Dispose();
        }
开发者ID:shaovoon,项目名称:outline-text,代码行数:60,代码来源:Form1.cs

示例11: OutlineTextProcessor

        ///<summary>
        /// Creates a new instance of the OutlineTextProcessor class.
        ///</summary>
        public OutlineTextProcessor(ModelItem modelItemParam, TemplateBase templateParam, string fontPathParam)
        {
            modelItem = modelItemParam;
            template = templateParam;

            PrivateFontCollection fontcollection = new PrivateFontCollection();
            fontcollection.AddFontFile(fontPathParam + template.Font.FileName);
            fontFamily = fontcollection.Families[0];
        }
开发者ID:akhtn7,项目名称:AddTextToImage,代码行数:12,代码来源:OutlineTextProcessor.cs

示例12: RenderText

		public static Graphic RenderText(string filename, int size, string text, Color color)
		{
			PrivateFontCollection pfc = new PrivateFontCollection();
			pfc.AddFontFile(filename);
			FontFamily fontfam=pfc.Families[0];

			Font font=new Font(fontfam, size);

			return RenderText(font, text, color);
		}
开发者ID:seeseekey,项目名称:CSCL,代码行数:10,代码来源:Text.cs

示例13: LoadFont

 public static PrivateFontCollection LoadFont(string file, int fontSize)
 {
     PrivateFontCollection fontCollection = new PrivateFontCollection();
     fontCollection.AddFontFile(file);
     if (fontCollection.Families.Length < 0)
     {
         throw new InvalidOperationException("No font familiy found when loading font");
     }
     return fontCollection;
 }
开发者ID:Dybuk,项目名称:ME3Explorer,代码行数:10,代码来源:InterpEditor.cs

示例14: FontManager

        private FontManager()
        {
            PrivateFontCollection fontCollection = new PrivateFontCollection();

            // Add fonts
            String path = (Path.Combine(Application.ExecutablePath, "..", "Resources", "Courgette-Regular.ttf"));

            fontCollection.AddFontFile(path);
            courgette = fontCollection.Families[0];

            courgetteWpf = new System.Windows.Media.FontFamily(new Uri("pack://application:,,,/"), "./Resources/#Courgette");
        }
开发者ID:EusthEnoptEron,项目名称:Sketchball,代码行数:12,代码来源:FontManager.cs

示例15: LoadFonts

 public void LoadFonts(string fontsFolderPath)
 {
     if (string.IsNullOrEmpty(fontsFolderPath)) Die("Null Fonts Path");
     var files = Directory.GetFiles(fontsFolderPath);
     var fontFiles = (from file in files
                      where file.EndsWith(".ttf")
                      select file).ToList();
     if (!fontFiles.Any()) Die("No Fonts Found");
     fonts = new PrivateFontCollection();
     fontFiles.ForEach(f => fonts.AddFontFile(f));
     AvailableFonts = fonts.Families.ToDictionary(x => x.Name);
 }
开发者ID:chandru9279,项目名称:zasz.me,代码行数:12,代码来源:FontsService.cs


注:本文中的System.Drawing.Text.PrivateFontCollection.AddFontFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。