CMap format 4: Segment mapping to delta values. The Windows standard format.
Inheritance: PdfSharp.Fonts.OpenType.OpenTypeFontTable
        /// <summary>
        /// Maps a unicode to the index of the corresponding glyph.
        /// See OpenType spec "cmap - Character To Glyph Index Mapping Table / Format 4: Segment mapping to delta values"
        /// for details about this a little bit strange looking algorithm.
        /// </summary>
        public int CharCodeToGlyphIndex(char value)
        {
            try
            {
                CMap4 cmap     = FontFace.cmap.cmap4;
                int   segCount = cmap.segCountX2 / 2;
                int   seg;
                for (seg = 0; seg < segCount; seg++)
                {
                    if (value <= cmap.endCount[seg])
                    {
                        break;
                    }
                }
                Debug.Assert(seg < segCount);

                if (value < cmap.startCount[seg])
                {
                    return(0);
                }

                if (cmap.idRangeOffs[seg] == 0)
                {
                    return((value + cmap.idDelta[seg]) & 0xFFFF);
                }

                int idx = cmap.idRangeOffs[seg] / 2 + (value - cmap.startCount[seg]) - (segCount - seg);
                Debug.Assert(idx >= 0 && idx < cmap.glyphCount);

                if (cmap.glyphIdArray[idx] == 0)
                {
                    return(0);
                }

                return((cmap.glyphIdArray[idx] + cmap.idDelta[seg]) & 0xFFFF);
            }
            catch
            {
                GetType();
                throw;
            }
        }
示例#2
0
        internal void Read()
        {
            try
            {
                int tableOffset = this.fontData.Position;

                this.version   = this.fontData.ReadUShort();
                this.numTables = this.fontData.ReadUShort();

                bool success = false;
                for (int idx = 0; idx < this.numTables; idx++)
                {
                    PlatformId    platformId = (PlatformId)this.fontData.ReadUShort();
                    WinEncodingId encodingId = (WinEncodingId)this.fontData.ReadUShort();
                    int           offset     = this.fontData.ReadLong();

                    int currentPosition = this.fontData.Position;

                    // Just read Windows stuff
                    if (platformId == PlatformId.Win && (encodingId == WinEncodingId.Symbol || encodingId == WinEncodingId.Unicode))
                    {
                        this.symbol = encodingId == WinEncodingId.Symbol;

                        this.fontData.Position = tableOffset + offset;
                        this.cmap4             = new CMap4(this.fontData, encodingId);
                        this.fontData.Position = currentPosition;
                        // We have found what we are looking for, so break.
                        success = true;
                        break;
                    }
                }
                if (!success)
                {
                    throw new InvalidOperationException("Font has no usable platform or encoding ID. It cannot be used with PDFsharp.");
                }
            }
            catch (Exception ex)
            {
                throw new PdfSharpException(PSSR.ErrorReadingFontData, ex);
            }
        }
示例#3
0
        internal void Read()
        {
            try
            {
                int tableOffset = _fontData.Position;

                version = _fontData.ReadUShort();
                numTables = _fontData.ReadUShort();
#if DEBUG_
                if (_fontData.Name == "Cambria")
                    Debug-Break.Break();
#endif

                bool success = false;
                for (int idx = 0; idx < numTables; idx++)
                {
                    PlatformId platformId = (PlatformId)_fontData.ReadUShort();
                    WinEncodingId encodingId = (WinEncodingId)_fontData.ReadUShort();
                    int offset = _fontData.ReadLong();

                    int currentPosition = _fontData.Position;

                    // Just read Windows stuff.
                    if (platformId == PlatformId.Win && (encodingId == WinEncodingId.Symbol || encodingId == WinEncodingId.Unicode))
                    {
                        symbol = encodingId == WinEncodingId.Symbol;

                        _fontData.Position = tableOffset + offset;
                        cmap4 = new CMap4(_fontData, encodingId);
                        _fontData.Position = currentPosition;
                        // We have found what we are looking for, so break.
                        success = true;
                        break;
                    }
                }
                if (!success)
                    throw new InvalidOperationException("Font has no usable platform or encoding ID. It cannot be used with PDFsharp.");
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(PSSR.ErrorReadingFontData, ex);
            }
        }
示例#4
0
    internal void Read()
    {
      try
      {
        int tableOffset = this.fontData.Position;

        this.version = this.fontData.ReadUShort();
        this.numTables = this.fontData.ReadUShort();

        bool success = false;
        for (int idx = 0; idx < this.numTables; idx++)
        {
          PlatformId platformId = (PlatformId)this.fontData.ReadUShort();
          WinEncodingId encodingId = (WinEncodingId)this.fontData.ReadUShort();
          int offset = this.fontData.ReadLong();

          int currentPosition = this.fontData.Position;

          // Just read Windows stuff
          if (platformId == PlatformId.Win && (encodingId == WinEncodingId.Symbol || encodingId == WinEncodingId.Unicode))
          {
            this.symbol = encodingId == WinEncodingId.Symbol;

            this.fontData.Position = tableOffset + offset;
            this.cmap4 = new CMap4(this.fontData, encodingId);
            this.fontData.Position = currentPosition;
            // We have found what we are looking for, so break.
            success = true;
            break;
          }
        }
        if (!success)
          throw new InvalidOperationException("Font has no usable platform or encoding ID. It cannot be used with PDFsharp.");
      }
      catch (Exception ex)
      {
        throw new PdfSharpException(PSSR.ErrorReadingFontData, ex);
      }
    }