Пример #1
0
        private void FontChenge()
        {
            //PrivateFontCollectionオブジェクトを作成する
            System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
            //PrivateFontCollectionにフォントを追加する
            pfc.AddFontFile(@"./FONT/A-OTF-UDShinMGoPr6-Regular.otf");
            //同様にして、複数のフォントを追加できる
            //pfc.AddFontFile(@"FONT/AdobeFnt19.lst");

            //PrivateFontCollectionに追加されているフォントの名前を列挙する
            foreach (System.Drawing.FontFamily ff in pfc.Families)
            {
                Console.WriteLine(ff.Name);
            }

            //PrivateFontCollectionの先頭のフォントのFontオブジェクトを作成する
            System.Drawing.Font f =
                new System.Drawing.Font(pfc.Families[0], 12);

            //Labelコントロールのフォントに設定する
            infobox.Font = f;

            //後始末
            pfc.Dispose();
        }
Пример #2
0
        /// <summary>
        /// Find the font family name of an specified TTF font file. Only available for Net Framework 4.5 builds.
        /// </summary>
        /// <param name="ttfFont">TTF font file.</param>
        /// <returns>The font family name of the specified TTF font file.</returns>
        /// <remarks>This method will return an empty string if the specified font is not found in its path or the system font folder or if it is not a valid TTF font.</remarks>
        public static string TrueTypeFontFamilyName(string ttfFont)
        {
            if (string.IsNullOrEmpty(ttfFont))
            {
                throw new ArgumentNullException(nameof(ttfFont));
            }

            // the following information is only applied to TTF not SHX fonts
            if (!Path.GetExtension(ttfFont).Equals(".TTF", StringComparison.InvariantCultureIgnoreCase))
            {
                return(string.Empty);
            }

            // try to find the file in the specified directory, if not try it in the fonts system folder
            string fontFile = File.Exists(ttfFont) ?
                              Path.GetFullPath(ttfFont) :
                              string.Format("{0}{1}{2}", Environment.GetFolderPath(Environment.SpecialFolder.Fonts), Path.DirectorySeparatorChar, Path.GetFileName(ttfFont));

            System.Drawing.Text.PrivateFontCollection fontCollection = new System.Drawing.Text.PrivateFontCollection();
            try
            {
                fontCollection.AddFontFile(fontFile);
                return(fontCollection.Families[0].Name);
            }
            catch (FileNotFoundException)
            {
                return(string.Empty);
            }
            finally
            {
                fontCollection.Dispose();
            }
        }
Пример #3
0
        private void OnDragDrophandler(object sender, DragEventArgs e)
        {
            object o = e.Data.GetData(DataFormats.Text);

            if (o != null)
            {
                this.fontListBox.NewItem(o.ToString());
            }
            else
            {
                System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
                try
                {
                    string[] FontName = (string[])e.Data.GetData(DataFormats.FileDrop, true);
                    for (int f = 0; f < FontName.Length; f++)
                    {
                        pfc.AddFontFile(FontName[f]);
                    }
                    if (pfc.Families.Length > 0)
                    {
                        for (int i = 0; i < pfc.Families.Length; i++)
                        {
                            this.fontListBox.NewItem(((FontFamily)pfc.Families[i]).Name);
                        }
                    }
                }
                finally
                {
                    pfc.Dispose();
                }
            }
        }
Пример #4
0
        /// <summary>
        /// フォントの設定
        /// </summary>
        private void SetFont()
        {
            //PrivateFontCollectionオブジェクトを作成する
            System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();

            //PrivateFontCollectionにフォントを追加する
            pfc.AddFontFile(FONT_7SEG);
            pfc.AddFontFile(FONT_14SEG);
            pfc.AddFontFile(FONT_DETAIL);

            //PrivateFontCollectionの先頭のフォントのFontオブジェクトを作成する
            System.Drawing.Font fontDetail = new System.Drawing.Font(pfc.Families[2], 24);
            System.Drawing.Font font7seg   = new System.Drawing.Font(pfc.Families[1], 45);
            System.Drawing.Font font14seg  = new System.Drawing.Font(pfc.Families[0], 45);

            //textBoxコントロールのフォントに設定する
            //  "PRESENT TIME"
            this.textBoxPresentYear.Font   = font7seg;
            this.textBoxPresentMonth.Font  = font14seg;
            this.textBoxPresentDay.Font    = font7seg;
            this.textBoxPresentHour.Font   = font7seg;
            this.textBoxPresentMinute.Font = font7seg;
            this.textBoxPresentSecond.Font = font7seg;
            //  "TODO TIME"
            this.textBoxToDoDay.Font    = font7seg;
            this.textBoxToDoMonth.Font  = font14seg;
            this.textBoxToDoYear.Font   = font7seg;
            this.textBoxToDoHour.Font   = font7seg;
            this.textBoxToDoMinute.Font = font7seg;
            // "TODO DETAIL"
            this.textBoxToDoDetail.Font = fontDetail;
            // "NOTIFIED TODO"
            this.textBoxNotifiedToDo.Font = fontDetail;

            // 始末
            pfc.Dispose();

            return;
        }
        public ScoreboardCompetitiveTeamRenderer(XAML.TeamScoreboard parent, List<playersData> TeamData, string TeamName)
        {
            m_parent = parent;
            m_parent.image.Source = null;

            //set the current directory and filename for the template
            string scoreboardTemplate = Directory.GetCurrentDirectory() + "\\images\\background\\team_bg.png";
            string teamLogoDirectory = Directory.GetCurrentDirectory() + "\\images\\team_logos\\";
            string fontLocation = Directory.GetCurrentDirectory() + "\\fonts\\orbitron-black.ttf";
            // 'PrivateFontCollection' is in the 'System.Drawing.Text' namespace
            var foo = new Gdi.Text.PrivateFontCollection();
            // Provide the path to the font on the filesystem
            foo.AddFontFile(fontLocation);
            //Make variable for the custom font
            var myCustomFont = new Gdi.Font((Gdi.FontFamily)foo.Families[0], 24f);
            Gdi.Bitmap bitmap = null;
            //try and load the background as a bitmap
            try
            {
                bitmap = new Gdi.Bitmap(scoreboardTemplate);
            }
            catch (Exception)
            {
                bitmap = Properties.Resources.bg;
            }
            //Clone the bitmap for nicer transparancy
            Gdi.Bitmap clone = new Gdi.Bitmap(bitmap.Width, bitmap.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

            //convert the bitmap to a graphic
            Gdi.Graphics gr = Gdi.Graphics.FromImage(clone);
            //draw the bitmap the the graphic
            gr.DrawImage(bitmap, new Gdi.Rectangle(0, 0, clone.Width, clone.Height));

            //Load the bitmap to a gdi graphic and add some nice antialisasing to it
            Gdi.Graphics g = Gdi.Graphics.FromImage(bitmap);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.TextRenderingHint = Gdi.Text.TextRenderingHint.AntiAliasGridFit;

            g.DrawString("Team Stats", myCustomFont, Gdi.Brushes.White, 230, 350);
            g.DrawString(TeamName, myCustomFont, Gdi.Brushes.White,  1500, 350);

            //Start drawing graphics for team members
            int rightOffset = 320;
            int heightOffset = 330;
            Gdi.StringFormat format = new Gdi.StringFormat();
            format.LineAlignment = Gdi.StringAlignment.Center;
            format.Alignment = Gdi.StringAlignment.Center;

            foreach (var player in TeamData)
            {
                bool renderOrNot = true;
                foreach( var team in MainWindow.CompetitiveTeamData)
                {
                    if(TeamName == team.TeamName)
                    {
                        foreach(var players in team.TeamMembers)
                        {
                            if (player.name == players.MemberName && players.MemberIsCoreOrSub == Structs.TeamMember.CoreOrSub.substitute)
                            {
                                renderOrNot = false;
                            }

                        }
                    }
                }
                if (renderOrNot == false)
                    continue;
                //Draw player name
                g.DrawString(player.name, myCustomFont, Gdi.Brushes.White, rightOffset, 150f + heightOffset, format);
                heightOffset += 72;
                //Draw player kills
                g.DrawString(player.kills.ToString(), myCustomFont, Gdi.Brushes.White, rightOffset, 150f + heightOffset, format);
                heightOffset += 72;
                //Draw player deaths
                g.DrawString(player.deaths.ToString(), myCustomFont, Gdi.Brushes.White, rightOffset, 150f + heightOffset, format);
                heightOffset += 72;
                //Draw player kdr
                g.DrawString((Math.Round((decimal)player.kills / (decimal)player.deaths, 2)).ToString(), myCustomFont, Gdi.Brushes.White, rightOffset, 150f + heightOffset, format);
                heightOffset += 72;
                //draw bombs detonated
                g.DrawString(player.score.ToString(), myCustomFont, Gdi.Brushes.White, rightOffset, 150f + heightOffset, format);

                heightOffset += 72;
                //draw score
                g.DrawString(player.bombsDetonated.ToString(), myCustomFont, Gdi.Brushes.White, rightOffset, 150f + heightOffset, format);

                rightOffset += 320;
                heightOffset = 330;
            }

            //Convert to ui readable image
            ImageSource bitmapSource = loadBitmap(bitmap);
            m_parent.image.Source = bitmapSource;
            clone.Dispose();
            g.Dispose();
            bitmap.Dispose();
            foo.Dispose();
            gr.Dispose();
        }
        public ScoreboardCompetitiveTeamRenderer(XAML.TeamScoreboard parent, List <playersData> TeamData, string TeamName)
        {
            m_parent = parent;
            m_parent.image.Source = null;

            //set the current directory and filename for the template
            string scoreboardTemplate = Directory.GetCurrentDirectory() + "\\images\\background\\team_bg.png";
            string teamLogoDirectory  = Directory.GetCurrentDirectory() + "\\images\\team_logos\\";
            string fontLocation       = Directory.GetCurrentDirectory() + "\\fonts\\orbitron-black.ttf";
            // 'PrivateFontCollection' is in the 'System.Drawing.Text' namespace
            var foo = new Gdi.Text.PrivateFontCollection();

            // Provide the path to the font on the filesystem
            foo.AddFontFile(fontLocation);
            //Make variable for the custom font
            var myCustomFont = new Gdi.Font((Gdi.FontFamily)foo.Families[0], 24f);

            Gdi.Bitmap bitmap = null;
            //try and load the background as a bitmap
            try
            {
                bitmap = new Gdi.Bitmap(scoreboardTemplate);
            }
            catch (Exception)
            {
                bitmap = Properties.Resources.bg;
            }
            //Clone the bitmap for nicer transparancy
            Gdi.Bitmap clone = new Gdi.Bitmap(bitmap.Width, bitmap.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

            //convert the bitmap to a graphic
            Gdi.Graphics gr = Gdi.Graphics.FromImage(clone);
            //draw the bitmap the the graphic
            gr.DrawImage(bitmap, new Gdi.Rectangle(0, 0, clone.Width, clone.Height));

            //Load the bitmap to a gdi graphic and add some nice antialisasing to it
            Gdi.Graphics g = Gdi.Graphics.FromImage(bitmap);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.TextRenderingHint = Gdi.Text.TextRenderingHint.AntiAliasGridFit;

            g.DrawString("Team Stats", myCustomFont, Gdi.Brushes.White, 230, 350);
            g.DrawString(TeamName, myCustomFont, Gdi.Brushes.White, 1500, 350);

            //Start drawing graphics for team members
            int rightOffset  = 320;
            int heightOffset = 330;

            Gdi.StringFormat format = new Gdi.StringFormat();
            format.LineAlignment = Gdi.StringAlignment.Center;
            format.Alignment     = Gdi.StringAlignment.Center;

            foreach (var player in TeamData)
            {
                bool renderOrNot = true;
                foreach (var team in MainWindow.CompetitiveTeamData)
                {
                    if (TeamName == team.TeamName)
                    {
                        foreach (var players in team.TeamMembers)
                        {
                            if (player.name == players.MemberName && players.MemberIsCoreOrSub == Structs.TeamMember.CoreOrSub.substitute)
                            {
                                renderOrNot = false;
                            }
                        }
                    }
                }
                if (renderOrNot == false)
                {
                    continue;
                }
                //Draw player name
                g.DrawString(player.name, myCustomFont, Gdi.Brushes.White, rightOffset, 150f + heightOffset, format);
                heightOffset += 72;
                //Draw player kills
                g.DrawString(player.kills.ToString(), myCustomFont, Gdi.Brushes.White, rightOffset, 150f + heightOffset, format);
                heightOffset += 72;
                //Draw player deaths
                g.DrawString(player.deaths.ToString(), myCustomFont, Gdi.Brushes.White, rightOffset, 150f + heightOffset, format);
                heightOffset += 72;
                //Draw player kdr
                g.DrawString((Math.Round((decimal)player.kills / (decimal)player.deaths, 2)).ToString(), myCustomFont, Gdi.Brushes.White, rightOffset, 150f + heightOffset, format);
                heightOffset += 72;
                //draw bombs detonated
                g.DrawString(player.score.ToString(), myCustomFont, Gdi.Brushes.White, rightOffset, 150f + heightOffset, format);

                heightOffset += 72;
                //draw score
                g.DrawString(player.bombsDetonated.ToString(), myCustomFont, Gdi.Brushes.White, rightOffset, 150f + heightOffset, format);

                rightOffset += 320;
                heightOffset = 330;
            }



            //Convert to ui readable image
            ImageSource bitmapSource = loadBitmap(bitmap);

            m_parent.image.Source = bitmapSource;
            clone.Dispose();
            g.Dispose();
            bitmap.Dispose();
            foo.Dispose();
            gr.Dispose();
        }
Пример #7
0
        private void cmdFontSearchFolder_Click(object sender, System.EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) {
                int index = 0;
                bool stopnow = false;

                System.Drawing.Text.PrivateFontCollection pfc;
                System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(folderBrowserDialog1.SelectedPath);
                System.IO.FileInfo[] FileArray = dir.GetFiles("*.ttf");
                for (int outerindex = 0; outerindex != 2; outerindex+=1) {
                    foreach (System.IO.FileInfo f in FileArray) {
                        try {
                            stopnow = true;
                            index+=1;
                            labelFontNum.Text = index.ToString(Util.cfi);
                            Application.DoEvents();
                            pfc = new System.Drawing.Text.PrivateFontCollection();
                            pfc.AddFontFile(f.FullName);

                            if (pfc.Families.Length != 0) {
                                foreach (ListViewItem lvi in lstFonts.Items) {
                                    stopnow = false;
                                    try {
                                        string familyName = lvi.Text.TrimStart("@".ToCharArray());

                                        foreach (System.Drawing.FontFamily pFamily in pfc.Families) {
                                            if (String.Equals(pFamily.Name, familyName, StringComparison.OrdinalIgnoreCase)) {
                                                lvi.SubItems[1].Text = "Found In Folder";
                                                lvi.SubItems[2].Text = f.FullName;
                                            }
                                        }
                                    } catch { }
                                }
                            }
                            pfc.Dispose();
                        } catch {
                            stopnow = false;
                            MessageBox.Show("Couldn't add font " + f.FullName);
                        }
                        if (stopnow) break;
                    }
                    FileArray = dir.GetFiles("*.ttc");
                }

                System.GC.Collect();
            }
            labelFontNum.Text = "done";
        }