Example #1
0
	public SerializableObject AddReference(ISerializableObjectFieldSerializer serializer, int id, int fieldIndex) {
		var obj = channel.AddObjectReferenceToSerialize(this, id);
		if ((obj != null) || !isLoading) {
			return obj;
		}

		int idHash = id.GetHashCode();

		if (objectReferencedFieldStates == null) {
			objectReferencedFieldStates = new IntHashtable<IntHashtableList<ReplicatedObjectFieldState>>();
		}
		IntHashtableList<ReplicatedObjectFieldState> fields;
		if (!objectReferencedFieldStates.TryGetValue(idHash, out fields)) {
			fields = new IntHashtableList<ReplicatedObjectFieldState>();
			objectReferencedFieldStates[idHash] = fields;
		}
		if (!fields.Contains(curFieldState.fieldSpec.fieldID)) {
			fields.Add(curFieldState.fieldSpec.fieldID, curFieldState);
		}
		curFieldState.AddReference(id, fieldIndex);
		return null;
	}
Example #2
0
        private static IDictionary <String, Object> ReadFontProperties(String name)
        {
            name += ".properties";
            Stream     resource = ResourceUtil.GetResourceStream(FontResources.CMAPS + name);
            Properties p        = new Properties();

            p.Load(resource);
            resource.Dispose();
            IntHashtable W = CreateMetric(p.GetProperty("W"));

            p.Remove("W");
            IntHashtable W2 = CreateMetric(p.GetProperty("W2"));

            p.Remove("W2");
            IDictionary <String, Object> map = new Dictionary <String, Object>();

            foreach (Object obj in p.Keys)
            {
                map.Put((String)obj, p.GetProperty((String)obj));
            }
            map.Put("W", W);
            map.Put("W2", W2);
            return(map);
        }
Example #3
0
        /// <summary>Reads the kerning information from the 'kern' table.</summary>
        /// <param name="unitsPerEm">
        ///
        /// <see cref="HeaderTable.unitsPerEm"/>.
        /// </param>
        protected internal virtual IntHashtable ReadKerning(int unitsPerEm)
        {
            int[] table_location;
            table_location = tables.Get("kern");
            IntHashtable kerning = new IntHashtable();

            if (table_location == null)
            {
                return(kerning);
            }
            raf.Seek(table_location[0] + 2);
            int nTables    = raf.ReadUnsignedShort();
            int checkpoint = table_location[0] + 4;
            int length     = 0;

            for (int k = 0; k < nTables; k++)
            {
                checkpoint += length;
                raf.Seek(checkpoint);
                raf.SkipBytes(2);
                length = raf.ReadUnsignedShort();
                int coverage = raf.ReadUnsignedShort();
                if ((coverage & 0xfff7) == 0x0001)
                {
                    int nPairs = raf.ReadUnsignedShort();
                    raf.SkipBytes(6);
                    for (int j = 0; j < nPairs; ++j)
                    {
                        int pair  = raf.ReadInt();
                        int value = raf.ReadShort() * TrueTypeFont.UNITS_NORMALIZATION / unitsPerEm;
                        kerning.Put(pair, value);
                    }
                }
            }
            return(kerning);
        }
        /// <exception cref="System.IO.IOException"/>
        private static IDictionary <String, Object> ReadFontProperties(String name)
        {
            name += ".properties";
            Stream     resource = ResourceUtil.GetResourceStream(FontConstants.CMAP_RESOURCE_PATH + name);
            Properties p        = new Properties();

            p.Load(resource);
            resource.Close();
            IntHashtable W = CreateMetric(p.GetProperty("W"));

            p.Remove("W");
            IntHashtable W2 = CreateMetric(p.GetProperty("W2"));

            p.Remove("W2");
            IDictionary <String, Object> map = new Dictionary <String, Object>();

            foreach (Object obj in p.Keys)
            {
                map[(String)obj] = p.GetProperty((String)obj);
            }
            map["W"]  = W;
            map["W2"] = W2;
            return(map);
        }
Example #5
0
 public GsubLookupType1(OpenTypeFontTableReader openReader, int lookupFlag, int[] subTableLocations)
     : base(openReader, lookupFlag, subTableLocations)
 {
     substMap = new IntHashtable();
     ReadSubTables();
 }
Example #6
0
        /// <exception cref="System.IO.IOException"/>
        private void InitializeFontProperties()
        {
            // initialize sfnt tables
            OpenTypeParser.HeaderTable      head = fontParser.GetHeadTable();
            OpenTypeParser.HorizontalHeader hhea = fontParser.GetHheaTable();
            OpenTypeParser.WindowsMetrics   os_2 = fontParser.GetOs_2Table();
            OpenTypeParser.PostTable        post = fontParser.GetPostTable();
            isFontSpecific = fontParser.GetCmapTable().fontSpecific;
            kerning        = fontParser.ReadKerning(head.unitsPerEm);
            bBoxes         = fontParser.ReadBbox(head.unitsPerEm);
            // font names group
            fontNames = fontParser.GetFontNames();
            // font metrics group
            fontMetrics.SetUnitsPerEm(head.unitsPerEm);
            fontMetrics.UpdateBbox(head.xMin, head.yMin, head.xMax, head.yMax);
            fontMetrics.SetNumberOfGlyphs(fontParser.ReadNumGlyphs());
            fontMetrics.SetGlyphWidths(fontParser.GetGlyphWidthsByIndex());
            fontMetrics.SetTypoAscender(os_2.sTypoAscender);
            fontMetrics.SetTypoDescender(os_2.sTypoDescender);
            fontMetrics.SetCapHeight(os_2.sCapHeight);
            fontMetrics.SetXHeight(os_2.sxHeight);
            fontMetrics.SetItalicAngle(post.italicAngle);
            fontMetrics.SetAscender(hhea.Ascender);
            fontMetrics.SetDescender(hhea.Descender);
            fontMetrics.SetLineGap(hhea.LineGap);
            fontMetrics.SetWinAscender(os_2.usWinAscent);
            fontMetrics.SetWinDescender(os_2.usWinDescent);
            fontMetrics.SetAdvanceWidthMax(hhea.advanceWidthMax);
            fontMetrics.SetUnderlinePosition((post.underlinePosition - post.underlineThickness) / 2);
            fontMetrics.SetUnderlineThickness(post.underlineThickness);
            fontMetrics.SetStrikeoutPosition(os_2.yStrikeoutPosition);
            fontMetrics.SetStrikeoutSize(os_2.yStrikeoutSize);
            fontMetrics.SetSubscriptOffset(-os_2.ySubscriptYOffset);
            fontMetrics.SetSubscriptSize(os_2.ySubscriptYSize);
            fontMetrics.SetSuperscriptOffset(os_2.ySuperscriptYOffset);
            fontMetrics.SetSuperscriptSize(os_2.ySuperscriptYSize);
            fontMetrics.SetIsFixedPitch(post.isFixedPitch);
            // font identification group
            String[][] ttfVersion = fontNames.GetNames(5);
            if (ttfVersion != null)
            {
                fontIdentification.SetTtfVersion(ttfVersion[0][3]);
            }
            String[][] ttfUniqueId = fontNames.GetNames(3);
            if (ttfUniqueId != null)
            {
                fontIdentification.SetTtfVersion(ttfUniqueId[0][3]);
            }
            byte[] pdfPanose = new byte[12];
            pdfPanose[1] = (byte)(os_2.sFamilyClass);
            pdfPanose[0] = (byte)(os_2.sFamilyClass >> 8);
            Array.Copy(os_2.panose, 0, pdfPanose, 2, 10);
            fontIdentification.SetPanose(pdfPanose);
            IDictionary <int, int[]> cmap = GetActiveCmap();

            int[] glyphWidths = fontParser.GetGlyphWidthsByIndex();
            int   numOfGlyphs = fontMetrics.GetNumberOfGlyphs();

            unicodeToGlyph = new LinkedDictionary <int, Glyph>(cmap.Count);
            codeToGlyph    = new LinkedDictionary <int, Glyph>(numOfGlyphs);
            avgWidth       = 0;
            foreach (int charCode in cmap.Keys)
            {
                int index = cmap.Get(charCode)[0];
                if (index >= numOfGlyphs)
                {
                    ILog LOGGER = LogManager.GetLogger(typeof(iText.IO.Font.TrueTypeFont));
                    LOGGER.Warn(MessageFormatUtil.Format(iText.IO.LogMessageConstant.FONT_HAS_INVALID_GLYPH, GetFontNames().GetFontName
                                                             (), index));
                    continue;
                }
                Glyph glyph = new Glyph(index, glyphWidths[index], charCode, bBoxes != null ? bBoxes[index] : null);
                unicodeToGlyph.Put(charCode, glyph);
                // This is done on purpose to keep the mapping to glyphs with smaller unicode values, in contrast with
                // larger values which often represent different forms of other characters.
                if (!codeToGlyph.ContainsKey(index))
                {
                    codeToGlyph.Put(index, glyph);
                }
                avgWidth += glyph.GetWidth();
            }
            FixSpaceIssue();
            for (int index = 0; index < glyphWidths.Length; index++)
            {
                if (codeToGlyph.ContainsKey(index))
                {
                    continue;
                }
                Glyph glyph = new Glyph(index, glyphWidths[index], -1);
                codeToGlyph.Put(index, glyph);
                avgWidth += glyph.GetWidth();
            }
            if (codeToGlyph.Count != 0)
            {
                avgWidth /= codeToGlyph.Count;
            }
            ReadGdefTable();
            ReadGsubTable();
            ReadGposTable();
            isVertical = false;
        }
Example #7
0
 public void RemoveConnection(IntHashtable <UnityNetDriverConnection> connections, int id)
 {
     connections.Remove(id.GetHashCode());
 }
Example #8
0
    void TickSocket(IntHashtable <UnityNetDriverConnection> connections, INetDriverCallbacks callbacks, int socketID, int reliableChannelID, int unreliableChannelID, byte[] recvBuffer, ref NetIOMetrics reliableChannelMetrics, ref NetIOMetrics unreliableChannelMetrics)
    {
        int  connectionID;
        int  recvSize;
        int  channelID;
        byte error;

        while (true)
        {
            NetworkEventType eventType = NetworkTransport.ReceiveFromHost(socketID, out connectionID, out channelID, recvBuffer, recvBuffer.Length, out recvSize, out error);
            switch (eventType)
            {
            case NetworkEventType.ConnectEvent: {
                var conn = GetConnection(connections, connectionID);
                if (conn == null)
                {
                    conn = CreateConnection(connections, callbacks, socketID, connectionID, reliableChannelID, unreliableChannelID);
                }
                callbacks.OnConnect(conn);
            } break;

            case NetworkEventType.DisconnectEvent: {
                var conn = GetConnection(connections, connectionID);
                if (conn == null)
                {
                    conn = CreateConnection(connections, callbacks, socketID, connectionID, reliableChannelID, unreliableChannelID);
                }
                conn.callbacks = null;
                callbacks.OnDisconnect(conn);
                RemoveConnection(connections, connectionID);
            } break;

            case NetworkEventType.DataEvent: {
                var conn = GetConnection(connections, connectionID);
                if (conn != null)
                {
                    if (channelID == reliableChannelID)
                    {
                        reliableChannelMetrics.bytesRecv += recvSize;
                        ++reliableChannelMetrics.numPacketsRecv;
                    }
                    else
                    {
                        unreliableChannelMetrics.bytesRecv += recvSize;
                        ++unreliableChannelMetrics.numPacketsRecv;
                    }
                    if (error == (byte)NetworkError.MessageToLong)
                    {
                        callbacks.OnInvalidMessageReceived(conn);
                    }
                    else
                    {
                        callbacks.OnMessageReceived(conn, recvBuffer, recvSize);
                    }
                }
            } break;

            default:
                return;
            }
        }
    }
Example #9
0
        /// <summary>
        /// Converts a
        /// <c>String</c>
        /// to a
        /// <c>byte</c>
        /// array according
        /// to the font's encoding.
        /// </summary>
        /// <param name="encoding">the encoding</param>
        /// <param name="text">
        /// the
        /// <c>String</c>
        /// to be converted
        /// </param>
        /// <returns>
        /// an array of
        /// <c>byte</c>
        /// representing the conversion according to the font's encoding
        /// </returns>
        public static byte[] ConvertToBytes(String text, String encoding)
        {
            if (text == null)
            {
                return(new byte[0]);
            }
            if (encoding == null || encoding.Length == 0)
            {
                int    len = text.Length;
                byte[] b   = new byte[len];
                for (int k = 0; k < len; ++k)
                {
                    b[k] = (byte)text[k];
                }
                return(b);
            }
            IExtraEncoding extra = extraEncodings.Get(encoding.ToLower(System.Globalization.CultureInfo.InvariantCulture
                                                                       ));

            if (extra != null)
            {
                byte[] b = extra.CharToByte(text, encoding);
                if (b != null)
                {
                    return(b);
                }
            }
            IntHashtable hash = null;

            if (encoding.Equals(WINANSI))
            {
                hash = winansi;
            }
            else
            {
                if (encoding.Equals(PDF_DOC_ENCODING))
                {
                    hash = pdfEncoding;
                }
            }
            if (hash != null)
            {
                char[] cc  = text.ToCharArray();
                int    len = cc.Length;
                int    ptr = 0;
                byte[] b   = new byte[len];
                int    c;
                for (int k = 0; k < len; ++k)
                {
                    char ch = cc[k];
                    if (ch < 128 || ch > 160 && ch <= 255)
                    {
                        c = ch;
                    }
                    else
                    {
                        c = hash.Get((int)ch);
                    }
                    if (c != 0)
                    {
                        b[ptr++] = (byte)c;
                    }
                }
                if (ptr == len)
                {
                    return(b);
                }
                byte[] b2 = new byte[ptr];
                System.Array.Copy(b, 0, b2, 0, ptr);
                return(b2);
            }
            try {
                return(EncodingUtil.ConvertToBytes(text.ToCharArray(), encoding));
            }
            catch (System.IO.IOException e) {
                throw new iText.IO.IOException(iText.IO.IOException.PdfEncodings, e);
            }
        }
Example #10
0
        /// <exception cref="System.IO.IOException"/>
        private void InitializeFontProperties()
        {
            // initialize sfnt tables
            OpenTypeParser.HeaderTable      head = fontParser.GetHeadTable();
            OpenTypeParser.HorizontalHeader hhea = fontParser.GetHheaTable();
            OpenTypeParser.WindowsMetrics   os_2 = fontParser.GetOs_2Table();
            OpenTypeParser.PostTable        post = fontParser.GetPostTable();
            isFontSpecific = fontParser.GetCmapTable().fontSpecific;
            kerning        = fontParser.ReadKerning(head.unitsPerEm);
            bBoxes         = fontParser.ReadBbox(head.unitsPerEm);
            // font names group
            fontNames.SetAllNames(fontParser.GetAllNameEntries());
            fontNames.SetFontName(fontParser.GetPsFontName());
            fontNames.SetFullName(fontNames.GetNames(4));
            String[][] otfFamilyName = fontNames.GetNames(16);
            if (otfFamilyName != null)
            {
                fontNames.SetFamilyName(otfFamilyName);
            }
            else
            {
                fontNames.SetFamilyName(fontNames.GetNames(1));
            }
            String[][] subfamily = fontNames.GetNames(2);
            if (subfamily != null)
            {
                fontNames.SetStyle(subfamily[0][3]);
            }
            String[][] otfSubFamily = fontNames.GetNames(17);
            if (otfFamilyName != null)
            {
                fontNames.SetSubfamily(otfSubFamily);
            }
            else
            {
                fontNames.SetSubfamily(subfamily);
            }
            String[][] cidName = fontNames.GetNames(20);
            if (cidName != null)
            {
                fontNames.SetCidFontName(cidName[0][3]);
            }
            fontNames.SetWeight(os_2.usWeightClass);
            fontNames.SetWidth(os_2.usWidthClass);
            fontNames.SetMacStyle(head.macStyle);
            fontNames.SetAllowEmbedding(os_2.fsType != 2);
            // font metrics group
            fontMetrics.SetUnitsPerEm(head.unitsPerEm);
            fontMetrics.UpdateBbox(head.xMin, head.yMin, head.xMax, head.yMax);
            fontMetrics.SetMaxGlyphId(fontParser.ReadMaxGlyphId());
            fontMetrics.SetGlyphWidths(fontParser.GetGlyphWidthsByIndex());
            fontMetrics.SetTypoAscender(os_2.sTypoAscender);
            fontMetrics.SetTypoDescender(os_2.sTypoDescender);
            fontMetrics.SetCapHeight(os_2.sCapHeight);
            fontMetrics.SetXHeight(os_2.sxHeight);
            fontMetrics.SetItalicAngle(post.italicAngle);
            fontMetrics.SetAscender(hhea.Ascender);
            fontMetrics.SetDescender(hhea.Descender);
            fontMetrics.SetLineGap(hhea.LineGap);
            fontMetrics.SetWinAscender(os_2.usWinAscent);
            fontMetrics.SetWinDescender(os_2.usWinDescent);
            fontMetrics.SetAdvanceWidthMax(hhea.advanceWidthMax);
            fontMetrics.SetUnderlinePosition((post.underlinePosition - post.underlineThickness) / 2);
            fontMetrics.SetUnderlineThickness(post.underlineThickness);
            fontMetrics.SetStrikeoutPosition(os_2.yStrikeoutPosition);
            fontMetrics.SetStrikeoutSize(os_2.yStrikeoutSize);
            fontMetrics.SetSubscriptOffset(-os_2.ySubscriptYOffset);
            fontMetrics.SetSubscriptSize(os_2.ySubscriptYSize);
            fontMetrics.SetSuperscriptOffset(os_2.ySuperscriptYOffset);
            fontMetrics.SetSuperscriptSize(os_2.ySuperscriptYSize);
            fontMetrics.SetIsFixedPitch(post.isFixedPitch);
            // font identification group
            String[][] ttfVersion = fontNames.GetNames(5);
            if (ttfVersion != null)
            {
                fontIdentification.SetTtfVersion(ttfVersion[0][3]);
            }
            String[][] ttfUniqueId = fontNames.GetNames(3);
            if (ttfUniqueId != null)
            {
                fontIdentification.SetTtfVersion(ttfUniqueId[0][3]);
            }
            fontIdentification.SetPanose(os_2.panose);
            IDictionary <int, int[]> cmap = GetActiveCmap();

            int[] glyphWidths = fontParser.GetGlyphWidthsByIndex();
            unicodeToGlyph = new LinkedDictionary <int, Glyph>(cmap.Count);
            codeToGlyph    = new LinkedDictionary <int, Glyph>(glyphWidths.Length);
            avgWidth       = 0;
            foreach (int charCode in cmap.Keys)
            {
                int index = cmap.Get(charCode)[0];
                if (index >= glyphWidths.Length)
                {
                    ILogger LOGGER = LoggerFactory.GetLogger(typeof(iText.IO.Font.TrueTypeFont));
                    LOGGER.Warn(String.Format(LogMessageConstant.FONT_HAS_INVALID_GLYPH, GetFontNames().GetFontName(), index));
                    continue;
                }
                Glyph glyph = new Glyph(index, glyphWidths[index], charCode, bBoxes != null ? bBoxes[index] : null);
                unicodeToGlyph[charCode] = glyph;
                codeToGlyph[index]       = glyph;
                avgWidth += glyph.GetWidth();
            }
            FixSpaceIssue();
            for (int index_1 = 0; index_1 < glyphWidths.Length; index_1++)
            {
                if (codeToGlyph.ContainsKey(index_1))
                {
                    continue;
                }
                Glyph glyph = new Glyph(index_1, glyphWidths[index_1], -1);
                codeToGlyph[index_1] = glyph;
                avgWidth            += glyph.GetWidth();
            }
            if (codeToGlyph.Count != 0)
            {
                avgWidth /= codeToGlyph.Count;
            }
            ReadGdefTable();
            ReadGsubTable();
            ReadGposTable();
            isVertical = false;
        }
Example #11
0
 /// <summary>
 /// This function is used by RBTableBuilder to fill in all the members of this
 /// object.  (Effectively, the builder class functions as a "friend" of this
 /// class, but to avoid changing too much of the logic, it carries around "shadow"
 /// copies of all these variables until the end of the build process and then
 /// copies them en masse into the actual tables object once all the construction
 /// logic is complete.  This function does that "copying en masse". </summary>
 /// <param name="f2ary"> The value for frenchSec (the French-secondary flag) </param>
 /// <param name="swap"> The value for SE Asian swapping rule </param>
 /// <param name="map"> The collator's character-mapping table (the value for mapping) </param>
 /// <param name="cTbl"> The collator's contracting-character table (the value for contractTable) </param>
 /// <param name="eTbl"> The collator's expanding-character table (the value for expandTable) </param>
 /// <param name="cFlgs"> The hash table of characters that participate in contracting-
 ///              character sequences (the value for contractFlags) </param>
 /// <param name="mso"> The value for maxSecOrder </param>
 /// <param name="mto"> The value for maxTerOrder </param>
 internal void FillInTables(bool f2ary, bool swap, UCompactIntArray map, List <List <EntryPair> > cTbl, List <int[]> eTbl, IntHashtable cFlgs, short mso, short mto)
 {
     outerInstance.FrenchSec_Renamed   = f2ary;
     outerInstance.SeAsianSwapping     = swap;
     outerInstance.Mapping             = map;
     outerInstance.ContractTable       = cTbl;
     outerInstance.ExpandTable         = eTbl;
     outerInstance.ContractFlags       = cFlgs;
     outerInstance.MaxSecOrder_Renamed = mso;
     outerInstance.MaxTerOrder_Renamed = mto;
 }
Example #12
0
 private void SerArray(PdfArray array, int level, ByteBufferOutputStream bb, IntHashtable serialized)
 {
     bb.Append("$A");
     if (level <= 0)
     {
         return;
     }
     for (int k = 0; k < array.Size(); ++k)
     {
         SerObject(array.Get(k, false), level, bb, serialized);
     }
 }
Example #13
0
 private void SerDic(PdfDictionary dic, int level, ByteBufferOutputStream bb, IntHashtable serialized)
 {
     bb.Append("$D");
     if (level <= 0)
     {
         return;
     }
     PdfName[] keys = new PdfName[dic.KeySet().Count];
     dic.KeySet().ToArray(keys);
     iText.IO.Util.JavaUtil.Sort(keys);
     foreach (Object key in keys)
     {
         if (key.Equals(PdfName.P) && (dic.Get((PdfName)key).IsIndirectReference() || dic.Get((PdfName)key).IsDictionary
                                           ()) || key.Equals(PdfName.Parent))
         {
             // ignore recursive call
             continue;
         }
         SerObject((PdfObject)key, level, bb, serialized);
         SerObject(dic.Get((PdfName)key, false), level, bb, serialized);
     }
 }
Example #14
0
            private void SerObject(PdfObject obj, int level, ByteBufferOutputStream bb, IntHashtable serialized)
            {
                if (level <= 0)
                {
                    return;
                }
                if (obj == null)
                {
                    bb.Append("$Lnull");
                    return;
                }
                PdfIndirectReference   reference = null;
                ByteBufferOutputStream savedBb   = null;

                if (obj.IsIndirectReference())
                {
                    reference = (PdfIndirectReference)obj;
                    int key = GetCopyObjectKey(obj);
                    if (serialized.ContainsKey(key))
                    {
                        bb.Append((int)serialized.Get(key));
                        return;
                    }
                    else
                    {
                        savedBb = bb;
                        bb      = new ByteBufferOutputStream();
                    }
                }
                if (obj.IsStream())
                {
                    bb.Append("$B");
                    SerDic((PdfDictionary)obj, level - 1, bb, serialized);
                    if (level > 0)
                    {
                        md5.Reset();
                        bb.Append(md5.Digest(((PdfStream)obj).GetBytes(false)));
                    }
                }
                else
                {
                    if (obj.IsDictionary())
                    {
                        SerDic((PdfDictionary)obj, level - 1, bb, serialized);
                    }
                    else
                    {
                        if (obj.IsArray())
                        {
                            SerArray((PdfArray)obj, level - 1, bb, serialized);
                        }
                        else
                        {
                            if (obj.IsString())
                            {
                                bb.Append("$S").Append(obj.ToString());
                            }
                            else
                            {
                                if (obj.IsName())
                                {
                                    bb.Append("$N").Append(obj.ToString());
                                }
                                else
                                {
                                    bb.Append("$L").Append(obj.ToString());
                                }
                            }
                        }
                    }
                }
                if (savedBb != null)
                {
                    int key = GetCopyObjectKey(reference);
                    if (!serialized.ContainsKey(key))
                    {
                        serialized.Put(key, CalculateHash(bb.GetBuffer()));
                    }
                    savedBb.Append(bb);
                }
            }