Exemplo n.º 1
0
        private void                _ReadAfmFile_ReadCharMetric(AfmReader reader, int charCode)
        {
            string       subKey;
            int          unicode = -1;
            int          height  = 0;
            int          width   = 0;
            AfmRectangle box     = new AfmRectangle(0, 0, 0, 0);

            while ((subKey = reader.ReadKey(true)) != null)
            {
                switch (subKey)
                {
                case "WX":
                case "W0X":
                    width = reader.ReadInteger();
                    break;

                case "WY":
                case "W0Y":
                    height = reader.ReadInteger();
                    break;

                case "B":
                    box = reader.ReadRectangle();
                    break;

                case "L":
                    break;

                case "VV":
                case "W1X":
                case "W1Y":
                    throw new PdfException("Only right to left font are supported.");

                case "N": {
                    string GlyphName = reader.ReadString(false);

                    unicode = AfmReader.GlyphNameToUnicode(GlyphName);

                    if (unicode < 0 && charCode < 0)
                    {
                        throw new PdfException("Unknown GlyphName '" + GlyphName + "'.");
                    }
                }
                break;

                default:
//                  System.Diagnostics.Debug.WriteLine("Warning: Unknown AFM sub-key '"+subKey+"'.");
                    break;
                }
            }

            if (unicode < 0)
            {
                if (charCode < 0)
                {
                    throw new PdfException("Unknown charcode and unicode.");
                }

                if (_charMetric[charCode] == null)
                {
                    unicode = charCode;
                }
            }

            if (unicode > 0)
            {
                _charMetric[unicode] = new AfmCharMetric(height, width, box);
            }
        }
Exemplo n.º 2
0
        protected void                ReadAfmFile(Stream afmStream)
        {
            AfmReader Reader = new AfmReader(afmStream);

            try {
                string Key;
                bool   fCharMetrics = false;

                while ((Key = Reader.ReadKey(false)) != null)
                {
                    switch (Key)
                    {
                    case "Comment":                                                                 break;

                    case "Version":                                                                 break;

                    case "FontName":            _fontName = Reader.ReadString(false);     break;

                    case "FullName":            _fullName = Reader.ReadString(false);     break;

                    case "FamilyName":          _familyName = Reader.ReadString(false);     break;

                    case "Weight":              _weight = Reader.ReadString(false);     break;

                    case "IsCIDFont":           _isCIDFont = Reader.ReadBoolean();         break;

                    case "CharacterSet":        _characterSet = Reader.ReadString(false);     break;

                    case "FontBBox":            _fontBBox = Reader.ReadRectangle();       break;

                    case "ItalicAngle":         _italicAngle = Reader.ReadNumber();          break;

                    case "IsFixedPitch":        _isFixedPitch = Reader.ReadBoolean();         break;

                    case "CapHeight":           _capHeight = Reader.ReadInteger();         break;

                    case "XHeight":             _xheight = Reader.ReadInteger();         break;

                    case "UnderlinePosition":   _underlinePosition = Reader.ReadInteger();         break;

                    case "UnderlineThickness":  _underlineThickness = Reader.ReadInteger();         break;

                    case "Ascender":            _ascender = Reader.ReadInteger();         break;

                    case "Descender":           _descender = Reader.ReadInteger();         break;

                    case "StdHW":               _stdHW = Reader.ReadInteger();         break;

                    case "StdVW":               _stdVW = Reader.ReadInteger();         break;

                    case "VVector":
                    case "StartDirection":
                        if (Reader.ReadInteger() != 0)
                        {
                            throw new PdfException("Only right to left font are supported.");
                        }
                        break;

                    case "StartCharMetrics":
                        fCharMetrics = true;
                        break;

                    case "EndCharMetrics":
                        fCharMetrics = false;
                        break;

                    case "C":
                    case "CH":
                        if (!fCharMetrics)
                        {
                            throw new PdfException("CharMetrics not active.");
                        }

                        _ReadAfmFile_ReadCharMetric(Reader, (Key == "CH") ? (int)Reader.ReadHex() : Reader.ReadInteger());
                        break;

                    case "Notice":
                    case "EncodingScheme":
                    case "StartFontMetrics":
                    case "EndFontMetrics":
                    case "StartKernData":
                    case "EndKernData":
                    case "StartKernPairs":
                    case "EndKernPairs":
                    case "KPX":
                        break;

                    default:
//                      System.Diagnostics.Debug.WriteLine("Warning: Unknown AFM key '"+Key+"'.");
                        break;
                    }
                }
            }
            catch (Exception Err) {
                throw new PdfException("Error parsing Afm file at line " + Reader.LineNo.ToString(CultureInfo.InvariantCulture) + ".", Err);
            }
        }