Exemple #1
0
        public int ScriptShape(string inChars, int charPos, int length, SCRIPT_ITEM[] items, OPENTYPE_TAG[] scriptTags, int itemsCount, IntPtr hWnd, string faceName, int fontHeight, out ushort[] logClust, out SCRIPT_CHARPROP[] charProps, out ushort[] glyphs, out SCRIPT_GLYPHPROP[] glyphProps)
        {
            if (string.IsNullOrEmpty(inChars))
            {
                throw new ArgumentException("inChars");
            }
            if (items == null || items.Length <= 0)
            {
                throw new ArgumentException("items");
            }
            if (itemsCount >= items.Length)
            {
                throw new ArgumentException("itemsCount");
            }
            if (charPos < 0)
            {
                throw new ArgumentException("charPos");
            }
            if (charPos >= inChars.Length)
            {
                throw new ArgumentException("charPos");
            }
            if (length <= 0)
            {
                throw new ArgumentException("length");
            }
            if (charPos + length > inChars.Length)
            {
                throw new ArgumentOutOfRangeException("length");
            }
            if (string.IsNullOrEmpty(faceName))
            {
                throw new ArgumentException("faceName");
            }
            if (fontHeight <= 0)
            {
                throw new ArgumentException("fontHeight");
            }
            int itemIndex;

            for (itemIndex = 0; itemIndex < itemsCount - 1; itemIndex++)
            {
                if (items[itemIndex].iCharPos <= charPos)
                {
                    if (items[itemIndex + 1].iCharPos >= charPos + length)
                    {
                        break;
                    }
                }
            }
            if (itemIndex == itemsCount - 1)
            {
                if (items[itemIndex].iCharPos > charPos)
                {
                    throw new ArgumentOutOfRangeException("length");
                }
            }
            SCRIPT_ANALYSIS psa        = items[itemIndex].a;
            string          shapeChars = inChars.Substring(charPos, length);
            OPENTYPE_TAG    tagScript  = scriptTags[itemIndex];
            OPENTYPE_TAG    tagLangSys = new OPENTYPE_TAG('\0', '\0', '\0', '\0');

            int[] rangeChars = new int[]
            {
                length
            };
            logClust   = new ushort[length];
            charProps  = new SCRIPT_CHARPROP[length];
            glyphs     = new ushort[length];
            glyphProps = new SCRIPT_GLYPHPROP[length];
            for (int index = 0; index < length; index++)
            {
                glyphProps[index] = default(SCRIPT_GLYPHPROP);
                logClust[index]   = 0;
                charProps[index]  = default(SCRIPT_CHARPROP);
                glyphs[index]     = 0;
            }
            int pcGlyphs = 0;

            OPENTYPE_FEATURE_RECORD[] arRecord   = new OPENTYPE_FEATURE_RECORD[1];
            OPENTYPE_FEATURE_RECORD   potfRecord = default(OPENTYPE_FEATURE_RECORD);

            arRecord[0]           = potfRecord;
            potfRecord.tagFeature = new OPENTYPE_TAG('v', 'e', 'r', 't');
            potfRecord.lParameter = 1u;
            TEXTRANGE_PROPERTIES[] arRangeProperty = new TEXTRANGE_PROPERTIES[1];
            TEXTRANGE_PROPERTIES   rpRangeProperty = default(TEXTRANGE_PROPERTIES);

            arRangeProperty[0]          = rpRangeProperty;
            rpRangeProperty.cotfRecords = 1;
            int    cRanges     = 1;
            IntPtr arRecordPtr = Marshal.AllocHGlobal(Marshal.SizeOf(potfRecord));

            Marshal.StructureToPtr(potfRecord, arRecordPtr, false);
            IntPtr arRangePtr = Marshal.AllocHGlobal(Marshal.SizeOf(rpRangeProperty));

            rpRangeProperty.potfRecords = arRecordPtr;
            Marshal.StructureToPtr(rpRangeProperty, arRangePtr, false);
            IntPtr hDC  = User32.GetDC(hWnd);
            IntPtr font = Gdi32.CreateFontIndirect(new LOGFONT
            {
                lfCharSet  = FontCharSet.DEFAULT_CHARSET,
                lfHeight   = fontHeight,
                lfFaceName = faceName
            });
            IntPtr oldFont = Gdi32.SelectObject(hDC, font);
            int    hresult = Usp10.ScriptShapeOpenType(hDC, ref this._psc, ref psa, tagScript, tagLangSys, rangeChars, ref arRangePtr, cRanges, shapeChars, length, length, logClust, charProps, glyphs, glyphProps, ref pcGlyphs);

            Gdi32.SelectObject(hDC, oldFont);
            Gdi32.DeleteObject(font);
            User32.ReleaseDC(hWnd, hDC);
            Marshal.FreeHGlobal(arRecordPtr);
            Marshal.FreeHGlobal(arRangePtr);
            Marshal.ThrowExceptionForHR(hresult);
            return(pcGlyphs);
        }