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


C# PrivateFontCollection.Dispose方法代码示例

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


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

示例1: Dispose_Family

		public void Dispose_Family ()
		{
			PrivateFontCollection pfc = new PrivateFontCollection ();
			pfc.Dispose ();
			Assert.IsNotNull (pfc.Families);
			// no it's not a ObjectDisposedException
		}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:PrivateFontCollectionTest.cs

示例2: comboBoxTPFont_SelectedIndexChanged

        private void comboBoxTPFont_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxTPFont.SelectedIndex == -1) return;

            switch (comboBoxTPFont.SelectedIndex)
            {
                case 0:
                    if (pfc != null)
                    {
                        pfc.Dispose();
                        pfc = null;
                    }

                    //PrivateFontCollectionオブジェクトを作成する
                    pfc = new System.Drawing.Text.PrivateFontCollection();
                    byte[] fontBuf = null;
                    if (comboBoxTPFont.SelectedIndex == 0)
                    {
                        fontBuf = Properties.Resources.pirulen_rg;
                    }

                    IntPtr fontBufPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontBuf.Length);
                    System.Runtime.InteropServices.Marshal.Copy(fontBuf, 0, fontBufPtr, fontBuf.Length);

                    pfc.AddMemoryFont(fontBufPtr, fontBuf.Length);
                    System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontBufPtr);

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

                    selectedFont = f;
                    break;
                default:
                    if (pfc != null) 
                    {
                        pfc.Dispose();
                        pfc = null; 
                    }

                    selectedFont = new Font(comboBoxTPFont.Text, (int)numericUpDownFontSize.Value);
                    break;
            }
            controller.TPFont = selectedFont;
        }
开发者ID:alterf,项目名称:ACT.TPMonitor,代码行数:44,代码来源:ACTTabpageControl.cs

示例3: imagettftext

        public static PhpArray imagettftext(PhpResource im, double size, double angle, int x, int y, int col, string font_file, string text)
        {
            PhpGdImageResource img = PhpGdImageResource.ValidImage(im);
            if (img == null)
                return null;
            
            if (string.IsNullOrEmpty(font_file))
            {
                PhpException.Throw(PhpError.Warning, Utils.Resources.GetString("filename_cannot_be_empty"));
                return null;
            }

            font_file = Path.Combine(ScriptContext.CurrentContext.WorkingDirectory, font_file);

            if (!File.Exists(font_file))
            {
                PhpException.Throw(PhpError.Warning, String.Format(Utils.Resources.GetString("invalid_font_filename"), font_file));
                return null;
            }

            // Font preparation
            PrivateFontCollection pfc;

            try
            {
                pfc = new PrivateFontCollection();
                pfc.AddFontFile(font_file);
            }
            catch
            {
                PhpException.Throw(PhpError.Warning, String.Format(Utils.Resources.GetString("invalid_font_filename"), font_file));
                return null;
            }

            FontStyle style = FontStyle.Regular;

            if (!pfc.Families[0].IsStyleAvailable(FontStyle.Regular))
            {
                if (pfc.Families[0].IsStyleAvailable(FontStyle.Bold))
                {
                    style = FontStyle.Bold;
                }
                else if (pfc.Families[0].IsStyleAvailable(FontStyle.Italic))
                {
                    style = FontStyle.Italic;
                }
                else if (pfc.Families[0].IsStyleAvailable(FontStyle.Underline))
                {
                    style = FontStyle.Underline;
                }
                else if (pfc.Families[0].IsStyleAvailable(FontStyle.Strikeout))
                {
                    style = FontStyle.Strikeout;
                }
            }

            Font font = new Font(pfc.Families[0], (float)size, style, GraphicsUnit.Point);
            float descent = font.Size * font.FontFamily.GetCellDescent(style) / font.FontFamily.GetEmHeight(style);
            float ascent = font.Size * font.FontFamily.GetCellAscent(style) / font.FontFamily.GetEmHeight(style);
            Point origin = new Point(x, (int)(y - (ascent + descent)));

            StringFormat sf = new StringFormat(StringFormat.GenericTypographic);

            Graphics g = Graphics.FromImage(img.Image);
            //graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            SizeF sizef = g.MeasureString(text, font, origin, sf);


            System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
            matrix.RotateAt(-(float)angle, new PointF(x + (sizef.Width / 2), y - ((ascent + descent) / 2)));
            Point[] points = { origin };
            matrix.TransformPoints(points);

            int difX = (origin.X - points[0].X);
            int difY = (origin.Y - points[0].Y);

            origin.X = origin.X - difX;
            origin.Y = origin.Y + difY;

            g.Transform = matrix;
            //g.TranslateTransform(origin.X - points[0].X, origin.Y - points[0].Y);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            Color color = GetAlphaColor(img, col);

            SolidBrush brush = new SolidBrush(color);

            g.DrawString(text, font, brush, origin, sf);
            brush.Dispose();

            sf.Dispose();
            font.Dispose();
            pfc.Dispose();

            g.Dispose();

            Point[] points2 = new Point[4];

            if (angle != 0)
            {
//.........这里部分代码省略.........
开发者ID:proff,项目名称:Phalanger,代码行数:101,代码来源:PhpGd.cs

示例4: AddText

        protected static void AddText(int x, int y, string text, Graphics graphics, TextStyle cls, StringFormat format)
        {
            if (cls == null)
                throw new ArgumentNullException("cls");

            lock (FontLock)
            {
                Font verFont;
                PrivateFontCollection pfc = new PrivateFontCollection();

                try
                {
                    if (cls.FontFileName != null && cls.FontFileName != string.Empty)
                    {
                        try
                        {
                            pfc.AddFontFile(cls.FontFileName);
                        }
                        catch (ArgumentNullException ex)
                        {
                            throw new Exception(string.Format("Font with filename '{0}' not found", cls.FontFileName), ex);
                        }

                        verFont = new Font(pfc.Families[0], cls.Size, cls.Style, GraphicsUnit.Pixel);
                    }
                    else
                        verFont = new Font(cls.Family, cls.Size, cls.Style, GraphicsUnit.Pixel);

                    using (verFont)
                    {
                        graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                        graphics.DrawString(text, verFont, cls.Brush, x, y, format);
                    }

                }
                finally
                {
                    // due to a bug in the BCL, each fontfamily object in the private font collection has to
                    // be explicitly disposed.  See:
                    // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=202970
                    // http://support.microsoft.com/kb/901026
                    // http://blog.loseyourmind.com/?m=200710
                    if (pfc.Families.Length > 0)
                    {
                        for (int i = pfc.Families.Length - 1; i >= 0; i--)
                            pfc.Families[i].Dispose();
                        pfc.Dispose();
                    }
                }
            }
        }
开发者ID:robgray,项目名称:Tucana,代码行数:51,代码来源:TextImage.cs

示例5: changeToBrailleFont

        private void changeToBrailleFont()
        {
            //define a private font collection
            System.Drawing.Text.PrivateFontCollection pfc2 = new System.Drawing.Text.PrivateFontCollection();
            //read your resource font into a byte array
            byte[] Bytes = Properties.Resources.SimBraille;
            //allocate some memory and get a pointer to it
            IntPtr ptr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(Bytes.Length);
            //copy the font data byte array to memory
            System.Runtime.InteropServices.Marshal.Copy(Bytes, 0, ptr, Bytes.Length);
            //Add the font to the private font collection
            pfc2.AddMemoryFont(ptr, Bytes.Length);
            //free up the previously allocated memory
            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(ptr);
            //define a font from the private font collection
            System.Drawing.Font fnt2 = new System.Drawing.Font(pfc2.Families[0], 16);
            //dispose of the private font collection
            pfc2.Dispose();

            System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
            string path = Path.GetDirectoryName(Application.ExecutablePath) + "\\Resources\\";
            string font = "SimBraille.ttf";

            try
            {
                pfc.AddFontFile(path + font);
                System.Drawing.Font fnt = new System.Drawing.Font(pfc.Families[0], 16);

                richTextBoxEditor.Font = fnt;
                richTextBoxEditor.SelectionStart = 0;
                richTextBoxEditor.SelectionLength = richTextBoxEditor.TextLength;
                richTextBoxEditor.SelectionFont = fnt;
                richTextBoxEditor.SelectionStart = 0;
                richTextBoxEditor.SelectionLength = 0;

                int rightMargin = setRightMargin(fnt2);
                richTextBoxEditor.RightMargin = rightMargin;

                fnt.Dispose();
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }

            //return the font created from your font resource

            textToolStripMenuItem.Checked = false;
            punktToolStripMenuItem.Checked = true;
        }
开发者ID:joelowe,项目名称:BrailleConverter,代码行数:50,代码来源:Form1.cs

示例6: addFonts

        public void addFonts(string[] filePaths, bool copy=true)
        {
            foreach (string fileName in filePaths)
            {
                //Console.WriteLine(fileName);
                //Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
                FileInfo info = new FileInfo(fileName);

                // If the font list already contains this font, just skip it
                // TODO: This will only check file name. It would be nice if we
                //  could either open the font file and check font name, or exclude
                //  extension from the check, so that you can't add an OTF and TTF of
                //  the same font, for example.
                // TODO: If we *do* detect a duplicate? Perhaps show a dialog asking the
                //  user what we should do?
                if (listFonts.FindItemWithText(info.Name) != null) continue;

                if (copy)
                {
                    try
                    {
                        File.Copy(fileName,
                            Path.Combine(APP_DATA, info.Name),
                            true);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Exception occured: " + ex.ToString());
                        MessageBox.Show(String.Format("Error copying {0} into fonts directory.", fileName), "Error copying file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                PrivateFontCollection tempCollection = new PrivateFontCollection();
                tempCollection.AddFontFile(Path.Combine(APP_DATA, info.Name));
                fonts.AddFontFile(Path.Combine(APP_DATA, info.Name));

                // Create the new item to add to the list
                string[] data = {tempCollection.Families[0].Name, info.Name};
                ListViewItem newItem = new ListViewItem(data);
                newItem.Checked = true;
                // TODO: User configurable font size.
                // TODO: It seems that the font goes away if you select the item before
                //   the font is installed. Should I just automatically install fonts?
                newItem.Font = new Font(tempCollection.Families[0], 12);
                listFonts.Items.Add(newItem);

                tempCollection.Dispose();
            }
        }
开发者ID:TrueJournals,项目名称:temp-font-installer,代码行数:50,代码来源:Form1.cs


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