Beispiel #1
0
        internal PdfFont(System.IO.BinaryReader reader)
        {
            _fontName           = reader.ReadString();
            _fullName           = reader.ReadString();
            _familyName         = reader.ReadString();
            _weight             = reader.ReadString();
            _isCIDFont          = reader.ReadBoolean();
            _italicAngle        = reader.ReadDouble();
            _isFixedPitch       = reader.ReadBoolean();
            _characterSet       = reader.ReadString();
            _fontBBox           = new AfmRectangle(reader);
            _underlinePosition  = reader.ReadInt16();
            _underlineThickness = reader.ReadInt16();
            _capHeight          = reader.ReadInt16();
            _xheight            = reader.ReadInt16();
            _ascender           = reader.ReadInt16();
            _descender          = reader.ReadInt16();
            _stdHW = reader.ReadInt16();
            _stdVW = reader.ReadInt16();

            _charMetric = new AfmCharMetric[65536];

            UInt16 pos;

            while ((pos = reader.ReadUInt16()) != 0)
            {
                _charMetric[pos] = new AfmCharMetric(reader);
            }
        }
Beispiel #2
0
 protected PdfFont()
 {
     _fontName           = "";
     _fullName           = "";
     _familyName         = "";
     _weight             = "";
     _isCIDFont          = false;
     _italicAngle        = 0.0;
     _isFixedPitch       = false;
     _characterSet       = "";
     _fontBBox           = new AfmRectangle(0, 0, 0, 0);
     _underlinePosition  = 0;
     _underlineThickness = 0;
     _capHeight          = 0;
     _xheight            = 0;
     _ascender           = 0;
     _descender          = 0;
     _stdHW      = 0;
     _stdVW      = 0;
     _charMetric = new AfmCharMetric[65536];
 }
 internal AfmCharMetric(System.IO.BinaryReader reader)
 {
     _height = reader.ReadInt16();
     _width  = reader.ReadInt16();
     _box    = new AfmRectangle(reader);
 }
 public AfmCharMetric(int Height, int Width, AfmRectangle Box)
 {
     _height = Height;
     _width  = Width;
     _box    = Box;
 }
Beispiel #5
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);
            }
        }
Beispiel #6
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);
            }
        }