Пример #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);
            }
        }
Пример #2
0
        public PdfDistance         TextWidth(PdfDistance fontSize, string text)
        {
            int width = 0;

            if (text != null)
            {
                for (int i = 0; i < text.Length; ++i)
                {
                    char c = text[i];

                    if (Encode(c) == '?')
                    {
                        c = '?';
                    }

                    AfmCharMetric Metric = _charMetric[c];

                    width += (Metric != null) ? Metric.Width : _fontBBox.urX;
                }
            }

            return(new PdfDistance(fontSize.pnts * (double)width / 1000.0));
        }
Пример #3
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);
            }
        }