2009-12-23 11 views
8

मैं अपने ऐप में एंबेडेड रिसोर्स के रूप में एक फ़ॉन्ट एम्बेड कर रहा हूं और इसे टेक्स्टबॉक्स में उपयोग करना चाहता हूं। AddMemoryFont मदद कहता है कि मुझे जीडीआई + का उपयोग करने के लिए संगत पाठ प्रतिपादन को सही पर सेट करना है, इसलिए मेरा फ़ॉन्ट इस्तेमाल किया जा सकता है, लेकिन किसी भी तरह से यह सही फ़ॉन्ट प्रदर्शित नहीं करेगा।सी #: टेक्स्टबॉक्स पर एक एम्बेडेड फ़ॉन्ट का उपयोग

प्रोग्राम.c में मैं स्पष्ट रूप से बताता हूं: एप्लिकेशन .etCompatibleTextRenderingDefault (सत्य);

तो यह क्यों काम नहीं कर रहा है? किसी को भी एक सुराग मिला?

उत्तर

19

ठीक है, मैंने इसे इंटरवेब्स और Google के लिए धन्यवाद दिया।

भविष्य में संदर्भ के लिए, यदि किसी को भी यह समस्या है, ठीक है: एक धारा के रूप में अपने एम्बेडेड फ़ॉन्ट प्राप्त करने के बाद, और AddMemoryFont, आप AddFontMemResourceEx कॉल करनी होगी कॉल करने से पहले! (सी # में उपलब्ध नहीं है, तो आप इसे आयात करने के लिए है:

[DllImport("gdi32.dll")] 
    private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts); 

और उसके बाद:।

  //create an unsafe memory block for the data 
     System.IntPtr data = Marshal.AllocCoTaskMem((int)fontStream.Length); 
     //create a buffer to read in to 
     Byte[] fontData = new Byte[fontStream.Length]; 
     //fetch the font program 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); 

     // We HAVE to do this to register the font to the system (Weird .NET bug !) 
     uint cFonts = 0; 
     AddFontMemResourceEx(data, (uint)fontData.Length, IntPtr.Zero, ref cFonts); 

     //pass the font to the font collection 
     mFontCollection.AddMemoryFont(data, (int)fontStream.Length); 
     //close the resource stream 
     fontStream.Close(); 
     //free the unsafe memory 
     Marshal.FreeCoTaskMem(data); 

और Presto, आप फ़ॉन्ट उपयोग करने के लिए सक्षम हो जाएगा AddFontMemResourceEx के बिना यह अभ्यस्त काम ।

+0

+1 पता चला है कि, धन्यवाद, नेतृत्व – BillW

+0

पवित्र केकड़ा मैं घंटे धन्यवाद के लिए दीवार के खिलाफ मेरे सिर पीटने दिया !! – Mike

+0

कहां है "fontStream" यहाँ से आ रहा है? –

संबंधित मुद्दे