Exemple #1
0
        protected unsafe byte *GetSharedMemory(int iSize)
        {
            // Build our name
            String strName = GetMemorySectionName();

            IntPtr mappedFileHandle;

            // This gets shared memory for our map.  If its can't, it gives us clean memory.
            Byte *pMemorySection = EncodingTable.nativeCreateOpenFileMapping(strName, iSize, out mappedFileHandle);

            Contract.Assert(pMemorySection != null,
                            "[BaseCodePageEncoding.GetSharedMemory] Expected non-null memory section to be opened");

            // If that failed, we have to die.
            if (pMemorySection == null)
            {
                throw new OutOfMemoryException(
                          Environment.GetResourceString("Arg_OutOfMemoryException"));
            }

            // if we have null file handle. this means memory was allocated after
            // failing to open the mapped file.

            if (mappedFileHandle != IntPtr.Zero)
            {
                safeMemorySectionHandle = new SafeViewOfFileHandle((IntPtr)pMemorySection, true);
                safeFileMappingHandle   = new SafeFileMappingHandle(mappedFileHandle, true);
            }

            return(pMemorySection);
        }
 // Returns an Encoding object for a given name or a given code page value.
 //
 /// <include file='doc\Encoding.uex' path='docs/doc[@for="Encoding.GetEncoding"]/*' />
 public static Encoding GetEncoding(String name)
 {
     //
     // NOTENOTE: If you add a new encoding that can be get by name, be sure to
     // add the corresponding item in EncodingTable.
     // Otherwise, the code below will throw exception when trying to call
     // EncodingTable.GetCodePageFromName().
     //
     return(GetEncoding(EncodingTable.GetCodePageFromName(name)));
 }
        public override Encoding GetEncoding(string name)
        {
            int codepage = EncodingTable.GetCodePageFromName(name);

            if (codepage == 0)
            {
                return(null);
            }

            return(GetEncoding(codepage));
        }
 private void GetDataItem()
 {
     if (dataItem == null)
     {
         dataItem = EncodingTable.GetCodePageDataItem(m_codePage);
         if (dataItem == null)
         {
             throw new NotSupportedException(String.Format(Environment.GetResourceString("NotSupported_NoCodepageData"), m_codePage));
         }
     }
 }
        protected unsafe byte *GetSharedMemory(int iSize)
        {
            IntPtr ptr;
            byte * numPtr = EncodingTable.nativeCreateOpenFileMapping(this.GetMemorySectionName(), iSize, out ptr);

            if (numPtr == null)
            {
                throw new OutOfMemoryException(Environment.GetResourceString("Arg_OutOfMemoryException"));
            }
            if (ptr != IntPtr.Zero)
            {
                this.safeMemorySectionHandle = new SafeViewOfFileHandle((IntPtr)numPtr, true);
                this.safeFileMappingHandle   = new SafeFileMappingHandle(ptr, true);
            }
            return(numPtr);
        }
        protected unsafe byte *GetSharedMemory(int iSize)
        {
            IntPtr mappedFileHandle;
            byte * openFileMapping = EncodingTable.nativeCreateOpenFileMapping(this.GetMemorySectionName(), iSize, out mappedFileHandle);

            if ((IntPtr)openFileMapping == IntPtr.Zero)
            {
                throw new OutOfMemoryException(Environment.GetResourceString("Arg_OutOfMemoryException"));
            }
            if (mappedFileHandle != IntPtr.Zero)
            {
                this.safeMemorySectionHandle = new SafeViewOfFileHandle((IntPtr)((void *)openFileMapping), true);
                this.safeFileMappingHandle   = new SafeFileMappingHandle(mappedFileHandle, true);
            }
            return(openFileMapping);
        }
Exemple #7
0
        Dictionary<char, int> ParseCmapTable(Stream stream, BinaryReader reader, TableHeader header)
        {
            stream.Position = header.Offset + 2;
            int tableCount = reader.ReadUInt16();

            var tableList = new List<EncodingTable>();
            for (int i = 0; i < tableCount; i++)
            {
                var table = new EncodingTable()
                {
                    PlatformId = reader.ReadUInt16(),
                    EncodingId = reader.ReadUInt16(),
                    Offset = reader.ReadUInt32(),
                };
                tableList.Add(table);
            }

            EncodingTable unicodeTable = tableList.Find(table => table.PlatformId == 3 && table.EncodingId == 1);
            stream.Position = header.Offset + unicodeTable.Offset + 2;

            int length = reader.ReadUInt16();
            stream.Position += 2;

            int segCount = reader.ReadUInt16() / 2;
            stream.Position += 6;

            var endCode = new int[segCount];
            for (int i = 0; i < segCount; i++)
                endCode[i] = reader.ReadUInt16();
            stream.Position += 2;

            var startCode = new int[segCount];
            for (int i = 0; i < segCount; i++)
                startCode[i] = reader.ReadUInt16();

            var idDelta = new int[segCount];
            for (int i = 0; i < segCount; i++)
                idDelta[i] = reader.ReadInt16();

            long offset = stream.Position;
            var idRangeOffset = new int[segCount];
            for (int i = 0; i < segCount; i++)
                idRangeOffset[i] = reader.ReadUInt16();

            var glyphDictionary = new Dictionary<char, int>();
            for (int i = 0; i < segCount - 1; i++)
            {
                if (idRangeOffset[i] == 0)
                {
                    for (int c = startCode[i]; c <= endCode[i]; c++)
                        glyphDictionary.Add((char)c, idDelta[i] + c);
                }
                else
                {
                    for (int c = startCode[i]; c <= endCode[i]; c++)
                    {
                        stream.Position = idRangeOffset[i] + 2 * (c - startCode[i]) + offset + i * 2;
                        glyphDictionary.Add((char)c, idDelta[i] + reader.ReadUInt16());
                    }
                }
            }

            return glyphDictionary;
        }