Esempio n. 1
0
 internal override byte[] ConvertToBytes(String text)
 {
     if (cjkMirror != null)
     {
         return(PdfEncodings.ConvertToBytes(text, CJKFont.CJK_ENCODING));
     }
     else if (isType0)
     {
         char[] chars = text.ToCharArray();
         int    len   = chars.Length;
         byte[] b     = new byte[len * 2];
         int    bptr  = 0;
         for (int k = 0; k < len; ++k)
         {
             int[] ws = (int[])metrics[(int)chars[k]];
             if (ws != null)
             {
                 int g = ws[0];
                 b[bptr++] = (byte)(g / 256);
                 b[bptr++] = (byte)(g);
             }
         }
         if (bptr == b.Length)
         {
             return(b);
         }
         else
         {
             byte[] nb = new byte[bptr];
             Array.Copy(b, 0, nb, 0, bptr);
             return(nb);
         }
     }
     else
     {
         char[] cc  = text.ToCharArray();
         byte[] b   = new byte[cc.Length];
         int    ptr = 0;
         for (int k = 0; k < cc.Length; ++k)
         {
             if (uni2byte.ContainsKey(cc[k]))
             {
                 b[ptr++] = (byte)uni2byte[cc[k]];
             }
         }
         if (ptr == b.Length)
         {
             return(b);
         }
         else
         {
             byte[] b2 = new byte[ptr];
             Array.Copy(b, 0, b2, 0, ptr);
             return(b2);
         }
     }
 }
Esempio n. 2
0
 public override int GetWidth(int char1)
 {
     if (!widths3.ContainsKey(char1))
     {
         throw new ArgumentException("The char " + (int)char1 + " is not defined in a Type3 font");
     }
     return(widths3[char1]);
 }
Esempio n. 3
0
        /**
         * Checks if a reference refers to a page object.
         * @param   ref the reference that needs to be checked
         * @return  true is the reference refers to a page object.
         */
        protected internal bool IsPage(PRIndirectReference refi)
        {
            IntHashtable refs = (IntHashtable)pages2intrefs[refi.Reader];

            if (refs != null)
            {
                return(refs.ContainsKey(refi.Number));
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
        protected internal bool IsVisited(PdfReader reader, int number, int generation)
        {
            IntHashtable refs = (IntHashtable)readers2intrefs[reader];

            return(refs.ContainsKey(number));
        }
Esempio n. 5
0
 internal static void FindAllObjects(PdfReader reader, PdfObject obj, IntHashtable hits)
 {
     if (obj == null)
         return;
     switch (obj.Type) {
         case PdfObject.INDIRECT:
             PRIndirectReference iref = (PRIndirectReference)obj;
             if (reader != iref.Reader)
                 return;
             if (hits.ContainsKey(iref.Number))
                 return;
             hits[iref.Number] = 1;
             FindAllObjects(reader, PdfReader.GetPdfObject(obj), hits);
             return;
         case PdfObject.ARRAY:
             PdfArray a = (PdfArray)obj;
             for (int k = 0; k < a.Size; ++k) {
                 FindAllObjects(reader, a[k], hits);
             }
             return;
         case PdfObject.DICTIONARY:
         case PdfObject.STREAM:
             PdfDictionary dic = (PdfDictionary)obj;
             foreach (PdfName name in dic.Keys) {
                 FindAllObjects(reader, dic.Get(name), hits);
             }
             return;
     }
 }
Esempio n. 6
0
 private void FillMetrics(byte[] touni, IntHashtable widths, int dw)
 {
     PdfContentParser ps = new PdfContentParser(new PRTokeniser(touni));
     PdfObject ob = null;
     PdfObject last = null;
     while ((ob = ps.ReadPRObject()) != null) {
         if (ob.Type == PdfContentParser.COMMAND_TYPE) {
             if (ob.ToString().Equals("beginbfchar")) {
                 int n = ((PdfNumber)last).IntValue;
                 for (int k = 0; k < n; ++k) {
                     String cid = DecodeString((PdfString)ps.ReadPRObject());
                     String uni = DecodeString((PdfString)ps.ReadPRObject());
                     if (uni.Length == 1) {
                         int cidc = (int)cid[0];
                         int unic = (int)uni[uni.Length - 1];
                         int w = dw;
                         if (widths.ContainsKey(cidc))
                             w = widths[cidc];
                         metrics[unic] = new int[]{cidc, w};
                     }
                 }
             }
             else if (ob.ToString().Equals("beginbfrange")) {
                 int n = ((PdfNumber)last).IntValue;
                 for (int k = 0; k < n; ++k) {
                     String cid1 = DecodeString((PdfString)ps.ReadPRObject());
                     String cid2 = DecodeString((PdfString)ps.ReadPRObject());
                     int cid1c = (int)cid1[0];
                     int cid2c = (int)cid2[0];
                     PdfObject ob2 = ps.ReadPRObject();
                     if (ob2.IsString()) {
                         String uni = DecodeString((PdfString)ob2);
                         if (uni.Length == 1) {
                             int unic = (int)uni[uni.Length - 1];
                             for (; cid1c <= cid2c; cid1c++, unic++) {
                                 int w = dw;
                                 if (widths.ContainsKey(cid1c))
                                     w = widths[cid1c];
                                 metrics[unic] = new int[]{cid1c, w};
                             }
                         }
                     }
                     else {
                         PdfArray a = (PdfArray)ob2;
                         for (int j = 0; j < a.Size; ++j, ++cid1c) {
                             String uni = DecodeString(a.GetAsString(j));
                             if (uni.Length == 1) {
                                 int unic = (int)uni[uni.Length - 1];
                                 int w = dw;
                                 if (widths.ContainsKey(cid1c))
                                     w = widths[cid1c];
                                 metrics[unic] = new int[]{cid1c, w};
                             }
                         }
                     }
                 }
             }
         }
         else
             last = ob;
     }
 }
Esempio n. 7
0
        private void FillMetrics(byte[] touni, IntHashtable widths, int dw)
        {
            PdfContentParser ps   = new PdfContentParser(new PRTokeniser(touni));
            PdfObject        ob   = null;
            PdfObject        last = null;

            while ((ob = ps.ReadPRObject()) != null)
            {
                if (ob.Type == PdfContentParser.COMMAND_TYPE)
                {
                    if (ob.ToString().Equals("beginbfchar"))
                    {
                        int n = ((PdfNumber)last).IntValue;
                        for (int k = 0; k < n; ++k)
                        {
                            String cid = DecodeString((PdfString)ps.ReadPRObject());
                            String uni = DecodeString((PdfString)ps.ReadPRObject());
                            if (uni.Length == 1)
                            {
                                int cidc = (int)cid[0];
                                int unic = (int)uni[uni.Length - 1];
                                int w    = dw;
                                if (widths.ContainsKey(cidc))
                                {
                                    w = widths[cidc];
                                }
                                metrics[unic] = new int[] { cidc, w };
                            }
                        }
                    }
                    else if (ob.ToString().Equals("beginbfrange"))
                    {
                        int n = ((PdfNumber)last).IntValue;
                        for (int k = 0; k < n; ++k)
                        {
                            String    cid1  = DecodeString((PdfString)ps.ReadPRObject());
                            String    cid2  = DecodeString((PdfString)ps.ReadPRObject());
                            int       cid1c = (int)cid1[0];
                            int       cid2c = (int)cid2[0];
                            PdfObject ob2   = ps.ReadPRObject();
                            if (ob2.IsString())
                            {
                                String uni = DecodeString((PdfString)ob2);
                                if (uni.Length == 1)
                                {
                                    int unic = (int)uni[uni.Length - 1];
                                    for (; cid1c <= cid2c; cid1c++, unic++)
                                    {
                                        int w = dw;
                                        if (widths.ContainsKey(cid1c))
                                        {
                                            w = widths[cid1c];
                                        }
                                        metrics[unic] = new int[] { cid1c, w };
                                    }
                                }
                            }
                            else
                            {
                                PdfArray a = (PdfArray)ob2;
                                for (int j = 0; j < a.Size; ++j, ++cid1c)
                                {
                                    String uni = DecodeString(a.GetAsString(j));
                                    if (uni.Length == 1)
                                    {
                                        int unic = (int)uni[uni.Length - 1];
                                        int w    = dw;
                                        if (widths.ContainsKey(cid1c))
                                        {
                                            w = widths[cid1c];
                                        }
                                        metrics[unic] = new int[] { cid1c, w };
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    last = ob;
                }
            }
        }