Summary description for PrivateFontCollection.
Inheritance: FontCollection
Beispiel #1
1
        /// <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);
            }
        }
Beispiel #2
1
        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;
        }
 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);
 }
Beispiel #4
0
        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);
        }
Beispiel #5
0
    public Game()
    {
        I = new NotifyIcon()
        {
            ContextMenu = new ContextMenu(new MenuItem[]
                                          { new MenuItem("Exit", (s, e) => Application.Exit()) }),
            Visible = true
        };
        //register global hotkeys for controls
        Action <int, Keys> E = (k, K) => RegisterHotKey((IntPtr)0, k, 0, (int)K);

        E(left, Keys.Left);
        E(right, Keys.Right);
        E(up, Keys.Up);
        E(down, Keys.Down);
        E(_, Keys.Space);
        Application.AddMessageFilter(this);
        mode = MENU;
        //read the custom font for legible text at 16x16 pixels
        var c = new SD.Text.PrivateFontCollection();

        c.AddFontFile("f.ttf");
        font = new Font(c.Families[0], 5, GraphicsUnit.Pixel);
        Q    = new Timer()
        {
            Interval = width
        };
        Q.Tick += (e, a) => T();
        Q.Start();
    }
Beispiel #6
0
        private static void EnsureFontLoaded()
        {
            if (_FontAwesome == null)
            {
                _PrivateFontCollection = new PrivateFontCollection();

                byte[] fontAwesomeBuffer = BarFunctions.LoadFont("SystemImages.FontAwesome.ttf");
                _FontAwesomeHandle = GCHandle.Alloc(fontAwesomeBuffer, GCHandleType.Pinned);
                _PrivateFontCollection.AddMemoryFont(_FontAwesomeHandle.AddrOfPinnedObject(), fontAwesomeBuffer.Length);
                uint rsxCnt = 1;
                _FontAwesomePointer = AddFontMemResourceEx(_FontAwesomeHandle.AddrOfPinnedObject(),
                                                     (uint)fontAwesomeBuffer.Length, IntPtr.Zero, ref rsxCnt);
                using (FontFamily ff = _PrivateFontCollection.Families[0])
                {
                    if (ff.IsStyleAvailable(FontStyle.Regular))
                    {
                        _FontAwesome = new Font(ff, _FontAwesomeDefaultSize, FontStyle.Regular, GraphicsUnit.Point);
                        _FontAwesomeCache.Add(_FontAwesomeDefaultSize, _FontAwesome);
                    }
                    else
                    {
                        // Error use default font...
                        _FontAwesome = SystemInformation.MenuFont;
                    }
                }
            }
        }
		public void Dispose_Family ()
		{
			PrivateFontCollection pfc = new PrivateFontCollection ();
			pfc.Dispose ();
			Assert.IsNotNull (pfc.Families);
			// no it's not a ObjectDisposedException
		}
Beispiel #8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            byte[] fontArray = Properties.Resources.OpenSans_ExtraBold;
            int dataLength = Properties.Resources.OpenSans_ExtraBold.Length;

            // ASSIGN MEMORY AND COPY  BYTE[] ON THAT MEMORY ADDRESS
            IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength);
            Marshal.Copy(fontArray, 0, ptrData, dataLength);

            uint cFonts = 0;
            AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts);

            PrivateFontCollection pfc = new PrivateFontCollection();
            //PASS THE FONT TO THE  PRIVATEFONTCOLLECTION OBJECT
            pfc.AddMemoryFont(ptrData, dataLength);

            //FREE THE  "UNSAFE" MEMORY
            Marshal.FreeCoTaskMem(ptrData);

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

            Font font = new Font(pfc.Families[0], Font.Size, FontStyle.Regular);
            e.Graphics.DrawString(Text, font, new SolidBrush(this.ForeColor), new PointF(20, 17), format);
        }
 public Intro()
 {
     InitializeComponent();
     PrivateFontCollection pfc = new PrivateFontCollection();
     pfc.AddFontFile("..\\..\\TrajanPro-Regular.ttf");
     label1.Font = new Font(pfc.Families[0], 10, FontStyle.Bold);
 }
 void Initialize()
 {
   if (privateFontCollection == null)
     privateFontCollection = new PrivateFontCollection();
   if (privateFonts == null)
     privateFonts = new List<XPrivateFont>();
 }
        internal static void LoadFont()
        {
            Fonts = new PrivateFontCollection();

            // specify embedded resource name
            Stream fontStream = new MemoryStream(Properties.Resources.futura_extrabold);

            // create an unsafe memory block for the font data
            System.IntPtr data = Marshal.AllocCoTaskMem((int)fontStream.Length);

            // create a buffer to read in to
            byte[] fontdata = new byte[fontStream.Length];

            //byte[] fontdata = InstagramScreenSaver.Properties.Resources.futura_extrabold;

            // read the font data from the resource
            fontStream.Read(fontdata, 0, (int)fontStream.Length);

            // copy the bytes to the unsafe memory block
            Marshal.Copy(fontdata, 0, data, (int)fontStream.Length);

            // pass the font to the font collection
            Fonts.AddMemoryFont(data, (int)fontStream.Length);

            // close the resource stream
            fontStream.Close();

            // free up the unsafe memory
            Marshal.FreeCoTaskMem(data);
        }
Beispiel #12
0
        /// <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( "读取字体文件出错" );
            }

        }
Beispiel #13
0
        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();
        }
Beispiel #14
0
        private void FontCollection()
        {
            // Create the byte array and get its length

            byte[] fontArray = Resources.gill_sans_ultra_bold_condensed;
            int dataLength = Resources.gill_sans_ultra_bold_condensed.Length;

            // ASSIGN MEMORY AND COPY  BYTE[] ON THAT MEMORY ADDRESS
            IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength);
            Marshal.Copy(fontArray, 0, ptrData, dataLength);

            uint cFonts = 0;
            AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts);

            PrivateFontCollection pfc = new PrivateFontCollection();
            //PASS THE FONT TO THE  PRIVATEFONTCOLLECTION OBJECT
            pfc.AddMemoryFont(ptrData, dataLength);

            //FREE THE  "UNSAFE" MEMORY
            Marshal.FreeCoTaskMem(ptrData);

            ff = pfc.Families[0];
            font = new Font(ff, 15f, FontStyle.Bold);
            fontButtonRegular = new Font(ff, 25f, FontStyle.Bold);
            fontButtonSelected = new Font(ff, 30f, FontStyle.Bold);
            fontRankings = new Font(ff, 25f, FontStyle.Bold);

            MyButton._normalFont = fontButtonRegular;
            MyButton._hoverFont = fontButtonSelected;
        }
Beispiel #15
0
        private void InitCustomFont()
        {
            PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection();

            privateFonts.AddFontFile(@"..\..\fonts\04B_03__.TTF");
            PixelFont = new Font(privateFonts.Families[0], 12);
        }
Beispiel #16
0
    //フォントファイルの読み込み これに登録することで、以降、名前呼び出しするだけで引用可能
    private void SetPrivateFont()
    {
        fontCollection = new System.Drawing.Text.PrivateFontCollection();

        for (int t = 0; t <= 2; t++)
        {
            string fontPath = "";
            //    if (t == 0) fontPath="system/mika.ttf";
            //if (t == 1) fontPath = s.gamedata_directry() + "font/" + "azuki.ttf";

            //    if (t == 1) fontPath = s1.gamedata_directry() + "font/" + "mplus-1c-black.ttf";
            if (t == 2)
            {
                fontPath = s1.gamedata_directry() + "font/" + "mplus-1c-bold.ttf";
            }

            if (m1.strlength(fontPath) >= 1)
            {
                IntPtr fontResourceHandle;

                byte[] fileImage = System.IO.File.ReadAllBytes(fontPath);
                unsafe
                {
                    fixed(byte *fileImageP = fileImage)
                    {
                        int  fonts  = 0;
                        int *fontsP = &fonts;

                        fontResourceHandle = AddFontMemResourceEx((IntPtr)fileImageP, (uint)fileImage.Length, (IntPtr)0, (IntPtr)fontsP);
                    }
                }
            }
        }
    }
Beispiel #17
0
        static unsafe ChatPreview()
        {
            Fonts = new PrivateFontCollection();
            fixed( byte* fontPointer = Resources.MinecraftFont ) {
                Fonts.AddMemoryFont( (IntPtr)fontPointer, Resources.MinecraftFont.Length );
            }
            MinecraftFont = new Font( Fonts.Families[0], 12, FontStyle.Regular );
            ColorPairs = new[]{
                new ColorPair(0,0,0,0,0,0),
                new ColorPair(0,0,191,0,0,47),
                new ColorPair(0,191,0,0,47,0),
                new ColorPair(0,191,191,0,47,47),
                new ColorPair(191,0,0,47,0,0),
                new ColorPair(191,0,191,47,0,47),
                new ColorPair(191,191,0,47,47,0),
                new ColorPair(191,191,191,47,47,47),

                new ColorPair(64,64,64,16,16,16),
                new ColorPair(64,64,255,16,16,63),
                new ColorPair(64,255,64,16,63,16),
                new ColorPair(64,255,255,16,63,63),
                new ColorPair(255,64,64,63,16,16),
                new ColorPair(255,64,255,63,16,63),
                new ColorPair(255,255,64,63,63,16),
                new ColorPair(255,255,255,63,63,63)
            };
        }
Beispiel #18
0
        // 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();
        }
Beispiel #19
0
 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"));
 }
Beispiel #20
0
 private void AddFontFromResource(PrivateFontCollection privateFontCollection, string fullFontResourceString)
 {
     var fontBytes = GetResourceBytes(fullFontResourceString);
     var fontData = Marshal.AllocCoTaskMem(fontBytes.Length);
     Marshal.Copy(fontBytes, 0, fontData, fontBytes.Length);
     privateFontCollection.AddMemoryFont(fontData, fontBytes.Length); // Add font to collection.
     Marshal.FreeCoTaskMem(fontData); // Do not forget to frees the memory block.
 }
Beispiel #21
0
    //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //                                                                                                                        LoadFontFile()
    //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    private Font LoadFontFile(string path, int size)
    {
        PrivateFontCollection fontCollection = new System.Drawing.Text.PrivateFontCollection();

        fontCollection.AddFontFile(path);

        return(new System.Drawing.Font(fontCollection.Families[0], size));
    }
 public TollPrinter()
     : base()
 {
     if (pfc == null) {
         pfc = new PrivateFontCollection();
         AddPrivateFont(pfc, "LabelPrintingSystem_Manifest.code128.ttf");
     }
 }
Beispiel #23
0
        /// <summary>
        /// 読み込むファイルを指定して新しい FontLoader クラスのインスタンスを初期化します。
        /// </summary>
        /// <param name="filename">読み込まれるフォントファイル。</param>
        public FontLoader(string filename)
        {
            if (string.IsNullOrWhiteSpace(filename))
                throw new ArgumentNullException("filename");

            this.fontCollection = new PrivateFontCollection();
            this.fontCollection.AddFontFile(filename);
            this.families = Array.AsReadOnly(this.fontCollection.Families);
        }
Beispiel #24
0
        /// <summary>
        /// 设置字体
        /// </summary>
        /// <param name="name"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static Font ShowFont(string name, float size)
        {
            Font font = null;

            System.Drawing.Text.PrivateFontCollection privateFonts = new System.Drawing.Text.PrivateFontCollection();
            privateFonts.AddFontFile(Application.StartupPath + @"\Font\" + name + ".otf");
            font = new Font(privateFonts.Families[0], size);
            return(font);
        }
Beispiel #25
0
 /// <summary>
 /// Načte font ze zdrojů.
 /// </summary>
 /// <param name="fontResourceData">Dara fontu ze zdrojů.</param>
 /// <param name="fontCollection">Výstupní kolekce fontů s novým fontem.</param>
 /// <returns>Vrací FontFamily.</returns>
 public static unsafe FontFamily LoadFontFamily(byte[] fontResourceData, out PrivateFontCollection fontCollection)
 {
     fixed (byte* ptr = fontResourceData)
     {
         fontCollection = new PrivateFontCollection();
         fontCollection.AddMemoryFont(new IntPtr(ptr), fontResourceData.Length);
         return fontCollection.Families[0];
     }
 }
        ///<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];
        }
Beispiel #27
0
 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;
 }
Beispiel #28
0
        unsafe static Fonts() {
            fonts = new PrivateFontCollection();

            fixed (byte* data = Resources.Ubuntu)
                fonts.AddMemoryFont((IntPtr)data, Resources.Ubuntu.Length);

            fixed (byte* data = Resources.minecraft)
                fonts.AddMemoryFont((IntPtr)data, Resources.minecraft.Length);

        }
Beispiel #29
0
		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);
		}
Beispiel #30
0
 public Theme(uint width, uint height)
 {
     ScreenWidth = width;
     ScreenHeight = height;
     PrivateFontCollection pfc = new PrivateFontCollection();
     //String path = Theme.AdaptRelativePathToPlatform("../../../../media/"); 
     //pfc.AddFontFile(path + "arial.ttf");
     //Font f = new Font(pfc.Families[0], 12);
     //defaultTextFont = new TextFontTexture(f); //FontStyle.Bold | FontStyle.Italic));
     defaultTextFont = new TextFontTexture(new Font("Arial", 10, FontStyle.Regular)); //FontStyle.Bold | FontStyle.Italic));
 }
    private void LoadFontFile(string path)
    {
        fontCollection = new System.Drawing.Text.PrivateFontCollection();
        fontCollection.AddFontFile(path);
        font = new System.Drawing.Font(fontCollection.Families[0], fontRenderSize);
        Texture2D texture = new Texture2D((int)previewImage.rectTransform.rect.width, (int)previewImage.rectTransform.rect.height);

        byte[] data = RenderFontTextToBitmapArray(texture.width, texture.height, font, renderTextString, System.Drawing.Brushes.GhostWhite);
        texture.LoadImage(data);
        previewImage.texture = texture;
    }
        public void ProcessRequest(HttpContext context)
        {
            PrivateFontCollection pfc = new PrivateFontCollection();

            string code = context.Request.QueryString["Code"];
            if (String.IsNullOrEmpty(code)) throw new ArgumentNullException("Code");

            // Get embedded font resource stream
            Assembly aa = Assembly.GetExecutingAssembly();
            string[] resourceNames = aa.GetManifestResourceNames();
            Stream fontStream = aa.GetManifestResourceStream(resourceNames[0]);
            if (fontStream == null) throw new ArgumentNullException("fontStream");

            // Read font stream
            byte[] fontData = new Byte[fontStream.Length];
            fontStream.Read(fontData, 0, fontData.Length);
            fontStream.Close();

            // Pin array to get address
            GCHandle handle = GCHandle.Alloc(fontData, GCHandleType.Pinned);

            try {
                IntPtr memIntPtr = Marshal.UnsafeAddrOfPinnedArrayElement(fontData, 0);
                if (memIntPtr == null) throw new ArgumentNullException("memIntPtr");

                // Add font to private collection and set font for use
                pfc.AddMemoryFont(memIntPtr, fontData.Length);
                Font barcode = new Font(pfc.Families[0], 44f);

                // Determine width
                Graphics gf = Graphics.FromImage(new Bitmap(100, 100));
                SizeF size = gf.MeasureString(String.Format("*{0}*", code), barcode);
                int width = (int)size.Width + 2;
                const int height = 70;

                using (Bitmap bm = new Bitmap(width, height))
                using (Graphics g = Graphics.FromImage(bm))
                using (MemoryStream ms = new MemoryStream()) {
                    Font text = new Font("Consolas", 12f);
                    PointF barcodeStart = new PointF(2f, 2f);
                    SolidBrush black = new SolidBrush(Color.Black);
                    SolidBrush white = new SolidBrush(Color.White);
                    g.FillRectangle(white, 0, 0, width, height);
                    g.DrawString(String.Format("*{0}*", code), barcode, black, barcodeStart);
                    g.DrawString(code, text, black, new Rectangle(0, 46, width, 20), new StringFormat() { Alignment = StringAlignment.Center });
                    context.Response.ContentType = "image/png";
                    bm.Save(ms, ImageFormat.Png);
                    ms.WriteTo(context.Response.OutputStream);
                }
            } finally {
                // Don't forget to unpin the array!
                handle.Free();
            }
        }
Beispiel #33
0
        public Menu()
            : base()
        {
            //make a fontcollection and store the font from file in here
            PrivateFontCollection pfc = new PrivateFontCollection ();
            pfc.AddFontFile ("Fonts/Dolce Vita.ttf");
            _font = new Font (pfc.Families [0], 25, FontStyle.Regular);

            //default text color
            _defaultColor = new SolidBrush (Color.White);
            _paused = true;
        }
        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");
        }
Beispiel #35
0
 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);
 }
 public ResourceFont(byte[] rawFont)
 {
     _font = new PrivateFontCollection();
     using (var stream = new MemoryStream(rawFont))
     {
         _handle = GCHandle.Alloc(rawFont, GCHandleType.Pinned);
         _fontPointer = _handle.AddrOfPinnedObject();
         _font.AddMemoryFont(_fontPointer, (int)stream.Length);
         uint dummy = 0;
         AddFontMemResourceEx(_fontPointer, (uint)stream.Length, IntPtr.Zero, ref dummy);                
     }
 }
Beispiel #37
0
        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;
        }
Beispiel #38
0
    public static void load_fonts()
    {
        private_fonts = new System.Drawing.Text.PrivateFontCollection();

        List <string> list = new List <string>();

        if (Directory.Exists(@"Fonts\"))
        {
            list.AddRange(Directory.GetFiles(@"Fonts\"));
        }
        foreach (string path in OpenGame.Runtime.Runtime.ResourcePaths)
        {
            if (Directory.Exists(path + @"Fonts\"))
            {
                list.AddRange(Directory.GetFiles(path + @"Fonts\"));
            }
        }
        if (list.Count > 0)
        {
            string[] found = list.ToArray();
            int      id    = 0;
            foreach (string file in found)
            {
                if (Path.GetExtension(file) == ".ttf")
                {
                    private_fonts.AddFontFile(file);
                    //Console.WriteLine("Installed font: " + private_fonts.Families[id].Name);
                    id++;
                }
            }
        }
        default_name = "VL Gothic";
        if (OpenGame.Runtime.Runtime.RGSSVersion == 1)
        {
            default_name = "Arial";
            default_size = 22;
            default_bold = true;
        }
        if (OpenGame.Runtime.Runtime.RGSSVersion == 2)
        {
            default_name = "Verdana";
            default_size = 20;
        }
        default_font = new Font(default_name);
        if (OpenGame.Runtime.Runtime.RGSSVersion == 1)
        {
            default_font.outline = false;
        }
        //Console.WriteLine("Set default font to: " + default_font.name);
    }
Beispiel #39
0
    public A()
    {
        I = new NotifyIcon()
        {
            Visible = true
        };
        Action <int, Keys> E = (k, K) => RegisterHotKey((IntPtr)0, k, 0, (int)K);

        E(L, Keys.Left); E(R, Keys.Right); E(U, Keys.Up); E(D, Keys.Down); E(_, Keys.Space);
        Application.AddMessageFilter(this);
        m = 9;
        var c = new SD.Text.PrivateFontCollection();

        c.AddFontFile("f.ttf");
        F = new Font(c.Families[0], 5, GraphicsUnit.Pixel);
        Q = new Timer()
        {
            Interval = W
        };
        Q.Tick += (e, a) => T();
        Q.Start();
    }
Beispiel #40
0
    static FontEx()
    {
        fontDict = new Dictionary <string, FontFamily>();


        //这些字体win 自带
        try
        {
            fontDict["simsun.ttf"] = new FontFamily("宋体");
            fontDict["simkai.ttf"] = new FontFamily("楷体");
            fontDict["simhei.ttf"] = new FontFamily("黑体");
        }
        catch (Exception)
        {
            fontDict["simkai.ttf"] = new FontFamily("宋体");
            fontDict["simhei.ttf"] = new FontFamily("宋体");
        }

        // 这些字体 win不自带
        string[] fn = { "msyh.ttf", "pingfang.ttf" }; // "simkai.ttf", "simsun.ttf", "simhei.ttf",
        privateFonts = new System.Drawing.Text.PrivateFontCollection[fn.Length];
        for (int i = 0; i < fn.Length; i++)
        {
            string ttf = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fn[i]);
            privateFonts[i] = new System.Drawing.Text.PrivateFontCollection();
            privateFonts[i].AddFontFile(ttf);

            fontDict[fn[i]] = privateFonts[i].Families[0];
        }

        //字体名称 => ttf 文件名称
        ttfDict = new Dictionary <string, string>();
        ttfDict.Add("楷体", "simkai.ttf");
        ttfDict.Add("雅黑", "msyh.ttf");
        ttfDict.Add("宋体", "simsun.ttf");
        ttfDict.Add("黑体", "simhei.ttf");
        ttfDict.Add("苹方", "pingfang.ttf");
    }
        static public void AddFontResource(this PrivateFontCollection outFontCollection, System.IO.FileInfo ttfFontFile, uint count = 0)
        {
            if (outFontCollection == null)
            {
                throw new ArgumentException();
            }

            byte[] fontData = System.IO.File.ReadAllBytes(ttfFontFile.FullName);
            IntPtr fontPtr  = Marshal.AllocCoTaskMem(fontData.Length);

            Marshal.Copy(fontData, 0, fontPtr, fontData.Length);

            outFontCollection.AddMemoryFont(fontPtr, fontData.Length);
            IntPtr ptr = AddFontMemResourceEx(fontPtr, (uint)fontData.Length, IntPtr.Zero, ref count);

            if (ptr == IntPtr.Zero)
            {
                throw new NullReferenceException();
            }

            Marshal.FreeCoTaskMem(fontPtr);
            fontData = null;
        }
Beispiel #42
0
        public FontIndex()
        {
            LocalFontCollection = new PrivateFontCollection();
            KeyIndex            = new System.Collections.Generic.List <string>();
//			KeyIndex.Add("Nothing");
        }
        static public Font GetFontResource(this PrivateFontCollection outFontCollection, System.IO.FileInfo ttfFontFile, float fontSize, uint count = 0)
        {
            AddFontResource(outFontCollection, ttfFontFile, count);

            return(new Font(outFontCollection.Families[outFontCollection.Families.Length - 1], fontSize));
        }
Beispiel #44
0
 public static System.Drawing.Font CreateFont(string fontFile, float fontSize, System.Drawing.FontStyle fontStyle, System.Drawing.GraphicsUnit graphicsUnit, byte gdiCharSet)
 {
     System.Drawing.Text.PrivateFontCollection privateFontCollection = new System.Drawing.Text.PrivateFontCollection();
     privateFontCollection.AddFontFile(fontFile);
     return(new System.Drawing.Font(privateFontCollection.Families[0], fontSize, fontStyle, graphicsUnit, gdiCharSet));
 }