Exemplo n.º 1
0
 internal static extern uint DrawText(IntPtr hdc, string lpStr, int nCount, ref Win32.RECT lpRect, int wFormat);
Exemplo n.º 2
0
        public static bool ScriptTextOut(string filePathSave, System.Drawing.Font font, List <int> xArray, List <int> yArray, uint fuOptions, Win32.RECT lprc,
                                         List <Uniscribe.SCRIPT_ANALYSIS> psaArray, string pwcReserved, int iReserved,
                                         List <ushort[]> pwGlyphsArray, List <int> cGlyphsArray,
                                         List <int[]> piAdvanceArray, List <int[]> piJustifyArray, List <Uniscribe.GOFFSET[]> pGoffsetArray)
        {
            bool res = false;

            int width  = 500;
            int height = 400;

            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
            lprc = new Win32.RECT(rect);

            Bitmap   bitmap = null;
            Graphics gr     = null;
            IntPtr   HDC    = IntPtr.Zero;

            createBitmap(font, ref bitmap, width, height, ref gr);
            HDC = gr.GetHdc();

            // HFONT hfont = initialize your font;
            IntPtr hfont = font.ToHfont();

            // HFONT old_font = NULL;
            IntPtr old_font = IntPtr.Zero;

            // ... select font into hdc ...
            old_font = Win32.SelectObject(HDC, hfont);

            int old_color = 0;

            old_color = Win32.SetTextColor(HDC, ColorTranslator.ToWin32(System.Drawing.Color.Black));
            System.Drawing.Color color = ColorTranslator.FromWin32(old_color);
            old_color = Win32.SetBkColor(HDC, ColorTranslator.ToWin32(System.Drawing.Color.Yellow));
            color     = ColorTranslator.FromWin32(old_color);

            string text = "It's me!";

            Win32.RECT bounds = new Win32.RECT(rect);
            int        flags  = Win32.DT_CENTER | Win32.DT_VCENTER | Win32.DT_SINGLELINE;
            uint       result = 0;

            result = Win32.DrawText(HDC, text, text.Length, ref bounds, flags);

            IntPtr psc = IntPtr.Zero; // Initialize to NULL, will be filled lazily.

            for (int i = 0; i < psaArray.Count; i++)
            {
                res = callScriptTextOutForItem(HDC, psc, xArray[i], yArray[i], fuOptions, lprc, psaArray[i], pwcReserved,
                                               iReserved, pwGlyphsArray[i], cGlyphsArray[i], piAdvanceArray[i], piJustifyArray[i], pGoffsetArray[i]);

                if (!res)
                {
                }
            }

            if (old_font != IntPtr.Zero)
            {
                Win32.SelectObject(HDC, old_font);  // Put back the previous font.
            }
            gr.ReleaseHdc(HDC);
            saveBitmap(bitmap, gr, filePathSave);

            return(res);
        }
Exemplo n.º 3
0
        private static bool callScriptTextOutForItem(IntPtr HDC, IntPtr psc, int x, int y, uint fuOptions, Win32.RECT lprc,
                                                     Uniscribe.SCRIPT_ANALYSIS psa, string pwcReserved, int iReserved,
                                                     ushort[] pwGlyphs, int cGlyphs,
                                                     int[] piAdvance, int[] piJustify, Uniscribe.GOFFSET[] pGoffset)
        {
            uint res = 0;

            try
            {
                res = 0;

                res = Uniscribe.ScriptTextOut(HDC, ref psc, /*x*/ 0, /*y*/ 0, /*fuOptions*/ 0,
                                              /*lprc*/ null, psa, /*pwcReserved*/ IntPtr.Zero, /*iReserved*/ 0,
                                              pwGlyphs, cGlyphs, piAdvance, piJustify, pGoffset);

                if (res != 0)
                {
                }
            }
            catch (System.Exception)
            {
            }

            return(res == 0);
        }
Exemplo n.º 4
0
        public static bool TestScriptPlaceUniscribeFunction(string filePathSave)
        {
            //string str = "Hello everybody if you hear";

            // Check ScriptJustify (for Kashida)
            string str = "يُساوِي جيد";

            Uniscribe.SCRIPT_ITEM[] items;

            if (!ScriptItemize(str, out items, true))
            {
                return(false);
            }

//             System.Drawing.Font font = new System.Drawing.Font("Arial Unicode MS", 16, FontStyle.Italic);
            System.Drawing.Font font = new System.Drawing.Font("Microsoft Sans Serif", 16, FontStyle.Italic);

            List <ushort[]> pwOutGlyphsArray;
            List <int>      cGlyphsArray;
            List <Uniscribe.SCRIPT_VISATTR[]> psvaArray;

            if (!ScriptShape(str, font, items, out pwOutGlyphsArray, out cGlyphsArray, out psvaArray))
            {
                return(false);
            }

            List <int[]> piAdvanceArray;
            List <Uniscribe.GOFFSET[]> pGoffsetArray;
            List <Uniscribe.ABC>       pABCArray;

            if (!ScriptPlace(font, items, pwOutGlyphsArray, cGlyphsArray, psvaArray, out piAdvanceArray, out pGoffsetArray, out pABCArray))
            {
                return(false);
            }

            Uniscribe.SCRIPT_FONTPROPERTIES sfp;
            if (!ScriptGetFontProperties(font, out sfp))
            {
                return(false);
            }

            List <int> iDxArray         = new List <int>(psvaArray.Count);
            List <int> iMinKashidaArray = new List <int>(psvaArray.Count);

            for (int i = 0; i < psvaArray.Count; i++)
            {
                iDxArray.Add(10);
                iMinKashidaArray.Add(sfp.iKashidaWidth);
            }

            List <int[]> piJustifyArray;

            if (!ScriptJustify(psvaArray, piAdvanceArray, cGlyphsArray, iDxArray, iMinKashidaArray, out piJustifyArray))
            {
                return(false);
            }

            Uniscribe.SCRIPT_LOGATTR[] psla;

            if (!ScriptBreakForItem(str, str.Length, items[0].a, out psla))
            {
                return(false);
            }

            List <int> xArray = new List <int>();
            List <int> yArray = new List <int>();

            int x = 30;
            int y = 30;

            for (int i = 0; i < psvaArray.Count; i++)
            {
                xArray.Add(x);
                yArray.Add(y);
            }

            List <Uniscribe.SCRIPT_ANALYSIS> psaArray = new List <Uniscribe.SCRIPT_ANALYSIS>();

            for (int i = 0; i < items.Length - 1; i++)
            {
                psaArray.Add(items[i].a);
            }

            Win32.RECT lprc = new Win32.RECT();

            if (!ScriptTextOut(filePathSave, font, xArray, yArray, 0, lprc, psaArray, null, 0,
                               pwOutGlyphsArray, cGlyphsArray, piAdvanceArray, piJustifyArray, pGoffsetArray))
            {
                return(false);
            }

            return(true);
        }