Пример #1
0
        internal static IntHashtable ConvertCompositeWidthsArray(PdfArray widthsArray)
        {
            IntHashtable res = new IntHashtable();

            if (widthsArray == null)
            {
                return(res);
            }
            for (int k = 0; k < widthsArray.Size(); ++k)
            {
                int       c1  = widthsArray.GetAsNumber(k).IntValue();
                PdfObject obj = widthsArray.Get(++k);
                if (obj.IsArray())
                {
                    PdfArray subWidths = (PdfArray)obj;
                    for (int j = 0; j < subWidths.Size(); ++j)
                    {
                        int c2 = subWidths.GetAsNumber(j).IntValue();
                        res.Put(c1++, c2);
                    }
                }
                else
                {
                    int c2 = ((PdfNumber)obj).IntValue();
                    int w  = widthsArray.GetAsNumber(++k).IntValue();
                    for (; c1 <= c2; ++c1)
                    {
                        res.Put(c1, w);
                    }
                }
            }
            return(res);
        }
Пример #2
0
 protected internal override void ReadSubTable(int subTableLocation) {
     openReader.rf.Seek(subTableLocation);
     int substFormat = openReader.rf.ReadShort();
     if (substFormat == 1) {
         int coverage = openReader.rf.ReadUnsignedShort();
         int deltaGlyphID = openReader.rf.ReadShort();
         IList<int> coverageGlyphIds = openReader.ReadCoverageFormat(subTableLocation + coverage);
         foreach (int coverageGlyphId in coverageGlyphIds) {
             int substituteGlyphId = coverageGlyphId + deltaGlyphID;
             substMap.Put(coverageGlyphId, substituteGlyphId);
         }
     }
     else {
         if (substFormat == 2) {
             int coverage = openReader.rf.ReadUnsignedShort();
             int glyphCount = openReader.rf.ReadUnsignedShort();
             int[] substitute = new int[glyphCount];
             for (int k = 0; k < glyphCount; ++k) {
                 substitute[k] = openReader.rf.ReadUnsignedShort();
             }
             IList<int> coverageGlyphIds = openReader.ReadCoverageFormat(subTableLocation + coverage);
             for (int k = 0; k < glyphCount; ++k) {
                 substMap.Put(coverageGlyphIds[k], substitute[k]);
             }
         }
         else {
             throw new ArgumentException("Bad substFormat: " + substFormat);
         }
     }
 }
Пример #3
0
 static Cp437Conversion()
 {
     for (int k = 0; k < table.Length; ++k)
     {
         c2b.Put(table[k], k + 128);
     }
 }
Пример #4
0
 public virtual bool AddSymbol(int code, int unicode) {
     if (code < 0 || code > 255) {
         return false;
     }
     String glyphName = AdobeGlyphList.UnicodeToName(unicode);
     if (glyphName != null) {
         unicodeToCode.Put(unicode, code);
         codeToUnicode[code] = unicode;
         differences[code] = glyphName;
         unicodeDifferences.Put(unicode, unicode);
         return true;
     }
     else {
         return false;
     }
 }
Пример #5
0
 public virtual IntHashtable CreateDirectMapping() {
     IntHashtable result = new IntHashtable();
     foreach (KeyValuePair<int, char[]> entry in byteMappings) {
         if (entry.Value.Length <= 2) {
             result.Put((int)entry.Key, ConvertToInt(entry.Value));
         }
     }
     return result;
 }
Пример #6
0
        private static IntHashtable CreateMetric(String s)
        {
            IntHashtable    h  = new IntHashtable();
            StringTokenizer tk = new StringTokenizer(s);

            while (tk.HasMoreTokens())
            {
                int n1 = Convert.ToInt32(tk.NextToken());
                h.Put(n1, Convert.ToInt32(tk.NextToken()));
            }
            return(h);
        }
        private static IntHashtable CreateMetric(String s)
        {
            IntHashtable    h  = new IntHashtable();
            StringTokenizer tk = new StringTokenizer(s);

            while (tk.HasMoreTokens())
            {
                int n1 = Convert.ToInt32(tk.NextToken(), System.Globalization.CultureInfo.InvariantCulture);
                h.Put(n1, Convert.ToInt32(tk.NextToken(), System.Globalization.CultureInfo.InvariantCulture));
            }
            return(h);
        }
Пример #8
0
        /// <exception cref="System.IO.IOException"/>
        public OtfClass(RandomAccessFileOrArray rf, int classLocation)
        {
            //key is glyph, value is class inside all 2
            rf.Seek(classLocation);
            int classFormat = rf.ReadUnsignedShort();

            if (classFormat == 1)
            {
                int startGlyph = rf.ReadUnsignedShort();
                int glyphCount = rf.ReadUnsignedShort();
                int endGlyph   = startGlyph + glyphCount;
                for (int k = startGlyph; k < endGlyph; ++k)
                {
                    int cl = rf.ReadUnsignedShort();
                    mapClass.Put(k, cl);
                }
            }
            else
            {
                if (classFormat == 2)
                {
                    int classRangeCount = rf.ReadUnsignedShort();
                    for (int k = 0; k < classRangeCount; ++k)
                    {
                        int glyphStart = rf.ReadUnsignedShort();
                        int glyphEnd   = rf.ReadUnsignedShort();
                        int cl         = rf.ReadUnsignedShort();
                        for (; glyphStart <= glyphEnd; ++glyphStart)
                        {
                            mapClass.Put(glyphStart, cl);
                        }
                    }
                }
                else
                {
                    throw new System.IO.IOException("Invalid class format " + classFormat);
                }
            }
        }
Пример #9
0
 internal override void AddChar(String mark, CMapObject code)
 {
     if (code.IsNumber())
     {
         int    codePoint;
         String s = ToUnicodeString(mark, true);
         if (iText.IO.Util.TextUtil.IsSurrogatePair(s, 0))
         {
             codePoint = iText.IO.Util.TextUtil.ConvertToUtf32(s, 0);
         }
         else
         {
             codePoint = (int)s[0];
         }
         map.Put(codePoint, (int)code.GetValue());
     }
 }
Пример #10
0
        public virtual IntHashtable GetReversMap()
        {
            IntHashtable code2cid = new IntHashtable(map.Count);

            foreach (int cid in map.Keys)
            {
                byte[] bytes    = map.Get(cid);
                int    byteCode = 0;
                foreach (byte b in bytes)
                {
                    byteCode <<= 8;
                    byteCode  += b & 0xff;
                }
                code2cid.Put(byteCode, cid);
            }
            return(code2cid);
        }
Пример #11
0
        public virtual IList <OpenTableLookup> GetLookups(FeatureRecord[] features)
        {
            IntHashtable hash = new IntHashtable();

            foreach (FeatureRecord rec in features)
            {
                foreach (int idx in rec.lookups)
                {
                    hash.Put(idx, 1);
                }
            }
            IList <OpenTableLookup> ret = new List <OpenTableLookup>();

            foreach (int idx in hash.ToOrderedKeys())
            {
                ret.Add(lookupList[idx]);
            }
            return(ret);
        }
Пример #12
0
 static SymbolConversion()
 {
     for (int k = 0; k < 256; ++k)
     {
         int v = table1[k];
         if (v != 0)
         {
             t1.Put(v, k);
         }
     }
     for (int k_1 = 0; k_1 < 256; ++k_1)
     {
         int v = table2[k_1];
         if (v != 0)
         {
             t2.Put(v, k_1);
         }
     }
 }
Пример #13
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);
        }
Пример #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);
                }
            }