示例#1
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;
     }
 }
示例#2
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;
                }
            }
        }