示例#1
0
        public void CreateFontFile(string pFontName, string pFileName)
        {
            E     rc = 0;
            EMBED ulPrivStatus;
            float siz = 32f;

            if (!File.Exists(pFileName))
            {
                // Create the font and put it where we can use it
                IntPtr hDC = CreateDC("DISPLAY", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                if (hDC != IntPtr.Zero)
                {
                    IntPtr hFont = CreateFont(MulDiv(Convert.ToInt16(siz), GetDeviceCaps(hDC, LOGPIXELSY), 72),
                                              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, pFontName);
                    if (hFont != IntPtr.Zero)
                    {
                        IntPtr hFontOld = SelectObject(hDC, hFont);
                        if (hFontOld != IntPtr.Zero)
                        {
                            // We are writing out the embed file info for the font if the file doesn't exist.
                            uint           ulStatus = 0;
                            FileStream     fsWrite  = new FileStream(pFileName, FileMode.CreateNew);
                            WRITEEMBEDPROC wep      = new WRITEEMBEDPROC(this.WriteEmbedProc);
                            TTEMBEDINFO    ttie     = new TTEMBEDINFO();

                            ttie.usStructSize  = Convert.ToUInt16(Marshal.SizeOf(ttie));
                            ttie.usRootStrSize = 0;
                            ttie.pusRootStr    = IntPtr.Zero;
                            ulPrivStatus       = 0;
                            ulStatus           = 0;
                            rc = TTEmbedFont(hDC,
                                             TTEMBED.RAW | TTEMBED.TTCOMPRESSED,
                                             CHARSET.UNICODE,
                                             out ulPrivStatus,
                                             out ulStatus,
                                             wep,
                                             fsWrite,
                                             IntPtr.Zero,
                                             0,
                                             0,
                                             ttie);
                            fsWrite.Flush();
                            fsWrite.Close();
                            if (rc != E.NONE)
                            {
                                // Since creation of the file ultimately failed, delete whatever
                                // interim bits might have been written.
                                File.Delete(pFileName);
                            }
                            SelectObject(hDC, hFontOld);
                        }
                        DeleteObject(hFont);
                    }
                    DeleteDC(hDC);
                }
            }
        }
示例#2
0
 internal static extern E TTEmbedFont(IntPtr hDC,
                                      TTEMBED ulFlags,
                                      CHARSET ulCharSet,
                                      out EMBED pulPrivStatus,
                                      out uint pulStatus,
                                      WRITEEMBEDPROC lpfnWriteToStream,
                                      FileStream lpvWriteStream,
                                      ref ushort pusCharCodeSet,
                                      ushort usCharCodeCount,
                                      ushort usLanguage,
                                      TTEMBEDINFO pTTEmbedInfo);
 internal static extern E TTEmbedFont(IntPtr hDC,
     TTEMBED ulFlags,
     CHARSET ulCharSet,
     out EMBED pulPrivStatus,
     out uint pulStatus,
     WRITEEMBEDPROC lpfnWriteToStream,
     FileStream lpvWriteStream,
     ref ushort pusCharCodeSet,
     ushort usCharCodeCount,
     ushort usLanguage,
     TTEMBEDINFO pTTEmbedInfo);
        public void CreateFontFile(string pFontName,string pFileName)
        {
            E rc = 0;
                EMBED ulPrivStatus;
                float siz = 32f;

                if (!File.Exists(pFileName))
                {
                    // Create the font and put it where we can use it
                    IntPtr hDC = CreateDC("DISPLAY", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                    if (hDC != IntPtr.Zero)
                    {
                        IntPtr hFont = CreateFont(MulDiv(Convert.ToInt16(siz), GetDeviceCaps(hDC, LOGPIXELSY), 72),
                                                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, pFontName);
                        if (hFont != IntPtr.Zero)
                        {
                            IntPtr hFontOld = SelectObject(hDC, hFont);
                            if (hFontOld != IntPtr.Zero)
                            {
                                // We are writing out the embed file info for the font if the file doesn't exist.
                                uint ulStatus = 0;
                                FileStream fsWrite = new FileStream(pFileName, FileMode.CreateNew);
                                WRITEEMBEDPROC wep = new WRITEEMBEDPROC(this.WriteEmbedProc);
                                TTEMBEDINFO ttie = new TTEMBEDINFO();

                                ttie.usStructSize = Convert.ToUInt16(Marshal.SizeOf(ttie));
                                ttie.usRootStrSize = 0;
                                ttie.pusRootStr = IntPtr.Zero;
                                ulPrivStatus = 0;
                                ulStatus = 0;
                                rc = TTEmbedFont(hDC,
                                                 TTEMBED.RAW | TTEMBED.TTCOMPRESSED,
                                                 CHARSET.UNICODE,
                                                 out ulPrivStatus,
                                                 out ulStatus,
                                                 wep,
                                                 fsWrite,
                                                 IntPtr.Zero,
                                                 0,
                                                 0,
                                                 ttie);
                                fsWrite.Flush();
                                fsWrite.Close();
                                if (rc != E.NONE)
                                {
                                    // Since creation of the file ultimately failed, delete whatever
                                    // interim bits might have been written.
                                    File.Delete(pFileName);
                                }
                                SelectObject(hDC, hFontOld);
                            }
                            DeleteObject(hFont);
                        }
                        DeleteDC(hDC);
                    }
                }
        }