Represents an Open Type Font font in memory.
コード例 #1
0
 public void Read(FontData fontData)
 {
     this.Tag      = fontData.ReadTag();
     this.CheckSum = fontData.ReadULong();
     this.Offset   = fontData.ReadLong();
     this.Length   = (int)fontData.ReadULong();
 }
コード例 #2
0
 internal FontData[] GetFontDataList()
 {
   int count = fontDataTable.Values.Count;
   FontData[] fontDataArray = new FontData[count];
   fontDataTable.Values.CopyTo(fontDataArray, 0);
   return fontDataArray;
 }
コード例 #3
0
        public static void Test()
        {
            Font     font  = new Font("Times New Roman", 10);
            FontData image = new FontData(font);

//      Font font = new Font("Isabelle", 12);
//      LOGFONT logFont = new LOGFONT();
//      font.ToLogFont(logFont);
//
//      IntPtr hfont = CreateFontIndirect(logFont);
////      IntPtr hfont2 = font.ToHfont();
////      System.Windows.Forms.MessageBox.Show(hfont2.ToString());
//
//      Graphics gfx = Graphics.FromHwnd(IntPtr.Zero);
//      IntPtr hdc = gfx.GetHdc();
//      IntPtr oldFont =  SelectObject(hdc, hfont);
//      int size = GetFontData(hdc, 0, 0, null, 0);
//
//      byte[] fontbits = new byte[size];
//      int xx = GetFontData(hdc, 0, 0, fontbits, size);
//      SelectObject(hdc, oldFont);
//      DeleteObject(hfont);
//      gfx.ReleaseHdc(hdc);
//
//      FontData image = new FontData(fontbits);
//      //image.Read();
//
//
//      //HandleRef
//
//      font.GetType();
        }
コード例 #4
0
        internal FontData[] GetFontDataList()
        {
            int count = fontDataTable.Values.Count;

            FontData[] fontDataArray = new FontData[count];
            fontDataTable.Values.CopyTo(fontDataArray, 0);
            return(fontDataArray);
        }
コード例 #5
0
 public OpenTypeFontTable(FontData fontData, string tag)
 {
   this.fontData = fontData;
   if (fontData != null && fontData.tableDictionary.ContainsKey(tag))
     this.DirectoryEntry = fontData.tableDictionary[tag];
   else
     this.DirectoryEntry = new TableDirectoryEntry(tag);
   this.DirectoryEntry.FontTable = this;
 }
コード例 #6
0
        /// <summary>
        /// Creates and reads a TableDirectoryEntry from the font image.
        /// </summary>
        public static TableDirectoryEntry ReadFrom(FontData fontData)
        {
            TableDirectoryEntry entry = new TableDirectoryEntry();

            entry.Tag      = fontData.ReadTag();
            entry.CheckSum = fontData.ReadULong();
            entry.Offset   = fontData.ReadLong();
            entry.Length   = (int)fontData.ReadULong();
            return(entry);
        }
コード例 #7
0
 public OpenTypeDescriptor(XFont font, XPdfFontOptions options)
 {
     try
     {
         fontData = new FontData(font, options);
         fontName = font.Name;
         Initialize();
     }
     catch
     {
         throw;
     }
 }
コード例 #8
0
 public OpenTypeFontTable(FontData fontData, string tag)
 {
     this.fontData = fontData;
     if (fontData != null && fontData.tableDictionary.ContainsKey(tag))
     {
         DirectoryEntry = fontData.tableDictionary[tag];
     }
     else
     {
         DirectoryEntry = new TableDirectoryEntry(tag);
     }
     DirectoryEntry.FontTable = this;
 }
コード例 #9
0
 /// <summary>
 /// This is an external helper function.
 /// </summary>
 public static byte[] F74167FFE4044F53B28A4AF049E9EF25(XFont font, XPdfFontOptions options, bool subset)
 {
   byte[] data = null;
   if (subset)
   {
     OpenTypeDescriptor descriptor = new OpenTypeDescriptor(font, options);
     FontData image = descriptor.fontData;
     CMapInfo cmapInfo = new CMapInfo(descriptor);
     cmapInfo.AddAnsiChars();
     image = image.CreateFontSubSet(cmapInfo.GlyphIndices, false);
     data = image.Data;
   }
   else
   {
     FontData fontData = new FontData(font, options);
     data = fontData.Data;
   }
   return data;
 }
コード例 #10
0
 /// <summary>
 /// This is an external helper function.
 /// </summary>
 public static byte[] F74167FFE4044F53B28A4AF049E9EF25(XFont font, XPdfFontOptions options, bool subset)
 {
     byte[] data = null;
     if (subset)
     {
         OpenTypeDescriptor descriptor = new OpenTypeDescriptor(font, options);
         FontData           image      = descriptor.fontData;
         CMapInfo           cmapInfo   = new CMapInfo(descriptor);
         cmapInfo.AddAnsiChars();
         image = image.CreateFontSubSet(cmapInfo.GlyphIndices, false);
         data  = image.Data;
     }
     else
     {
         FontData fontData = new FontData(font, options);
         data = fontData.Data;
     }
     return(data);
 }
コード例 #11
0
    public FontData RegisterFontData(byte[] data)
    {
      uint checksum = CalcChecksum(data);
      string key = String.Format("??{0:X}", checksum);

      FontData fontData;
      if (!this.fontDataTable.TryGetValue(key, out fontData))
      {
        lock (typeof(FontDataStock))
        {
          // may be created by other thread meanwhile
          if (!this.fontDataTable.TryGetValue(key, out fontData))
          {
            fontData = new FontData(data);
            this.fontDataTable.Add(key, fontData);
            this.lastEntry = fontData;
          }
        }
      }
      return fontData;
    }
コード例 #12
0
        public FontData RegisterFontData(byte[] data)
        {
            uint   checksum = CalcChecksum(data);
            string key      = String.Format("??{0:X}", checksum);

            FontData fontData;

            if (!fontDataTable.TryGetValue(key, out fontData))
            {
                lock (typeof(FontDataStock))
                {
                    // may be created by other thread meanwhile
                    if (!fontDataTable.TryGetValue(key, out fontData))
                    {
                        fontData = new FontData(data);
                        fontDataTable.Add(key, fontData);
                        lastEntry = fontData;
                    }
                }
            }
            return(fontData);
        }
コード例 #13
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
 public HorizontalHeaderTable(FontData fontData)
   : base(fontData, Tag)
 {
   Read();
 }
コード例 #14
0
 public GenericFontTable(FontData fontData, string tag)
     : base(fontData, tag)
 {
     this.fontData = fontData;
 }
コード例 #15
0
 public void Read(FontData fontData)
 {
   this.Tag = fontData.ReadTag();
   this.CheckSum = fontData.ReadULong();
   this.Offset = fontData.ReadLong();
   this.Length = (int)fontData.ReadULong();
 }
コード例 #16
0
 public MaximumProfileTable(FontData fontData)
     : base(fontData, Tag)
 {
     Read();
 }
コード例 #17
0
 public HorizontalMetricsTable(FontData fontData)
     : base(fontData, Tag)
 {
     Read();
 }
コード例 #18
0
ファイル: GlyphDataTable.cs プロジェクト: INSA-GEI/insa-gei
 public GlyphDataTable(FontData fontData)
     : base(fontData, Tag)
 {
     DirectoryEntry.Tag = TableTagNames.Glyf;
     Read();
 }
コード例 #19
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
 public GlyphSubstitutionTable(FontData fontData)
   : base(fontData, Tag)
 {
   DirectoryEntry.Tag = TableTagNames.GSUB;
   DirectoryEntry = fontData.tableDictionary[TableTagNames.GSUB];
   Read();
 }
コード例 #20
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
    byte[] bytes; // Set of instructions executed whenever point size or font or transformation change. n is the number of BYTE items that fit in the size of the table.

    public ControlValueProgram(FontData fontData)
      : base(fontData, Tag)
    {
      DirectoryEntry.Tag = TableTagNames.Prep;
      DirectoryEntry = fontData.tableDictionary[TableTagNames.Prep];
      Read();
    }
コード例 #21
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
    byte[] bytes; // Instructions. n is the number of BYTE items that fit in the size of the table.

    public FontProgram(FontData fontData)
      : base(fontData, Tag)
    {
      DirectoryEntry.Tag = TableTagNames.Fpgm;
      DirectoryEntry = fontData.tableDictionary[TableTagNames.Fpgm];
      Read();
    }
コード例 #22
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
    FWord[] array; // List of n values referenceable by instructions. n is the number of FWORD items that fit in the size of the table.

    public ControlValueTable(FontData fontData)
      : base(fontData, Tag)
    {
      DirectoryEntry.Tag = TableTagNames.Cvt;
      DirectoryEntry = fontData.tableDictionary[TableTagNames.Cvt];
      Read();
    }
コード例 #23
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
 public PostScriptTable(FontData fontData)
   : base(fontData, Tag)
 {
   Read();
 }
コード例 #24
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
    public ushort[] glyphIdArray;     // Glyph index array (arbitrary length)

    public CMap4(FontData fontData, WinEncodingId encodingId)
      : base(fontData, "----")
    {
      this.encodingId = encodingId;
      Read();
    }
コード例 #25
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
 public OS2Table(FontData fontData)
   : base(fontData, Tag)
 {
   Read();
 }
コード例 #26
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
    public short glyphDataFormat; // 0 for current format

    public FontHeaderTable(FontData fontData)
      : base(fontData, Tag)
    {
      Read();
    }
コード例 #27
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
 public VerticalMetricsTable(FontData fontData)
   : base(fontData, Tag)
 {
   Read();
   throw new NotImplementedException("VerticalMetricsTable");
 }
コード例 #28
0
        public short glyphDataFormat;  // 0 for current format

        public FontHeaderTable(FontData fontData)
            : base(fontData, Tag)
        {
            Read();
        }
コード例 #29
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
 public VerticalMetrics(FontData fontData)
   : base(fontData, Tag)
 {
   Read();
 }
コード例 #30
0
 public VerticalMetrics(FontData fontData)
     : base(fontData, Tag)
 {
     Read();
 }
コード例 #31
0
 /// <summary>
 /// Shallow copy for font subset.
 /// </summary>
 FontData(FontData fontData)
 {
     offsetTable = fontData.offsetTable;
 }
コード例 #32
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
 public NameTable(FontData fontData)
   : base(fontData, Tag)
 {
   Read();
 }
コード例 #33
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
 public VerticalHeaderTable(FontData fontData)
   : base(fontData, Tag)
 {
   Read();
 }
コード例 #34
0
 public IRefFontTable(FontData fontData, OpenTypeFontTable fontTable)
     : base(null, fontTable.DirectoryEntry.Tag)
 {
     this.fontData           = fontData;
     this.irefDirectoryEntry = fontTable.DirectoryEntry;
 }
コード例 #35
0
 public GenericFontTable(FontData fontData, string tag)
   : base(fontData, tag)
 {
   this.fontData = fontData;
 }
コード例 #36
0
ファイル: OpenTypeDescriptor.cs プロジェクト: DavidS/MigraDoc
    public static void Test()
    {
      Font font = new Font("Times New Roman", 10);
      FontData image = new FontData(font);

//      Font font = new Font("Isabelle", 12);
//      LOGFONT logFont = new LOGFONT();
//      font.ToLogFont(logFont);
//
//      IntPtr hfont = CreateFontIndirect(logFont);
////      IntPtr hfont2 = font.ToHfont();
////      System.Windows.Forms.MessageBox.Show(hfont2.ToString());
//
//      Graphics gfx = Graphics.FromImage(new Bitmap(100, 100));
//      IntPtr hdc = gfx.GetHdc();
//      IntPtr oldFont =  SelectObject(hdc, hfont);
//      int size = GetFontData(hdc, 0, 0, null, 0);
//
//      byte[] fontbits = new byte[size];
//      int xx = GetFontData(hdc, 0, 0, fontbits, size);
//      SelectObject(hdc, oldFont);
//      DeleteObject(hfont);
//      gfx.ReleaseHdc(hdc);
//
//      FontData image = new FontData(fontbits);
//      //image.Read();
//
//
//      //HandleRef
//
//      font.GetType();
    }
コード例 #37
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
 public HorizontalMetricsTable(FontData fontData)
   : base(fontData, Tag)
 {
   Read();
 }
コード例 #38
0
 public bool UnregisterFontData(FontData fontData)
 {
     Debug.Assert(false);
     return(false);
 }
コード例 #39
0
ファイル: FontData.cs プロジェクト: jsuen123/openpetragit
        /// <summary>
        /// Create the font image using GDI+ functionality.
        /// </summary>
        void CreateGdiFontImage(XFont font, XPdfFontOptions options /*, XPrivateFontCollection privateFontCollection*/)
        {
            System.Drawing.Font   gdiFont = font.RealizeGdiFont();
            NativeMethods.LOGFONT logFont;
#if DEBUG_
            logFont = new NativeMethods.LOGFONT();
            gdiFont.ToLogFont(logFont);
            Debug.WriteLine("FontData: " + logFont.lfFaceName);
#endif
            this.data = null;

            // PFC
            //if (privateFontCollection != null)
            //{
            //  //XPrivateFont privateFont = privateFontCollection.FindFont(logFont.lfFaceName, logFont.lfWeight >= 700, logFont.lfItalic > 0);
            //  XGlyphTypeface privateFont = privateFontCollection.FindFont(font.Name, font.Bold, font.Italic);
            //  if (privateFont != null)
            //  {
            //    //////int size = privateFont.GetData(ref this.data);
            //    //////if (size > 0)
            //    //////{
            //    //////  this.data = new byte[size];
            //    //////  privateFont.GetData(ref this.data, size);
            //    //////}
            //  }
            //}

            // Console.WriteLine("looking for " + gdiFont.Name);
            foreach (string fontFile in NativeMethods._FontFiles)
            {
                try
                {
                    BinaryReader br     = new BinaryReader(File.OpenRead(fontFile));
                    byte[]       buffer = br.ReadBytes((int)br.BaseStream.Length);
                    br.Close();

                    FontData fd = new FontData(buffer);

                    //System.Console.WriteLine(fd.name.Name);

                    if (fd.name.Name.Trim().ToLower() == gdiFont.Name.Trim().ToLower())
                    {
                        this.data = buffer;
                        break;
                    }
                }
                catch
                {
                    //System.Console.WriteLine(exc.ToString());
                }
            }

            if (this.data == null)
            {
                int    error;
                IntPtr hfont = gdiFont.ToHfont();
                IntPtr hdc   = NativeMethods.GetDC(IntPtr.Zero);
                error = Marshal.GetLastWin32Error();
                IntPtr oldFont = NativeMethods.SelectObject(hdc, hfont);
                error = Marshal.GetLastWin32Error();
                // size is exactly the size of the font file.
                int size = NativeMethods.GetFontData(hdc, 0, 0, null, 0);
                error = Marshal.GetLastWin32Error();
                if (size > 0)
                {
                    this.data = new byte[size];
                    int effectiveSize = NativeMethods.GetFontData(hdc, 0, 0, this.data, this.data.Length);
                    Debug.Assert(size == effectiveSize);
                    NativeMethods.SelectObject(hdc, oldFont);
                    NativeMethods.ReleaseDC(IntPtr.Zero, hdc);
                    error.GetType();
                }
                else
                {
                    // Sometimes size is -1 (GDI_ERROR), but I cannot determine why. It happens only with the font 'Symbol'.
                    // The issue occurs the first time in early 2005, when I start writing PDFsharp. I could not fix it and after
                    // some code refactoring the problem disappears.
                    // There was never a report from anyone about this issue.
                    // Now I get it again (while debugging QBX 2006). Maybe it is a problem with my PC at my home office.
                    // As a work-around I create a new font handle with a different height value. This works. Maybe the
                    // font file gets locked somewhere. Very very strange.

                    // IF SOMEONE ELSE COMES HERE PLEASE LET ME KNOW!

                    // Clean up old handles
                    NativeMethods.SelectObject(hdc, oldFont);
                    NativeMethods.ReleaseDC(IntPtr.Zero, hdc);

                    // Try again with new font handle
                    logFont = new NativeMethods.LOGFONT();
                    gdiFont.ToLogFont(logFont);
                    logFont.lfHeight += 1; // force new handle
                    IntPtr hfont2 = NativeMethods.CreateFontIndirect(logFont);
                    hdc     = NativeMethods.GetDC(IntPtr.Zero);
                    error   = Marshal.GetLastWin32Error();
                    oldFont = NativeMethods.SelectObject(hdc, hfont2);
                    error   = Marshal.GetLastWin32Error();
                    // size is exactly the size of the font file.
                    size  = NativeMethods.GetFontData(hdc, 0, 0, null, 0);
                    error = Marshal.GetLastWin32Error();
                    if (size > 0)
                    {
                        this.data = new byte[size];
                        int effectiveSize = NativeMethods.GetFontData(hdc, 0, 0, this.data, this.data.Length);
                        Debug.Assert(size == effectiveSize);
                    }
                    NativeMethods.SelectObject(hdc, oldFont);
                    NativeMethods.ReleaseDC(IntPtr.Zero, hdc);
                    NativeMethods.DeleteObject(hfont2);
                    error.GetType();
                }
            }
            if (this.data == null)
            {
                throw new InvalidOperationException("Internal error. Font data could not retrieved.");
            }
        }
コード例 #40
0
 public IRefFontTable(FontData fontData, OpenTypeFontTable fontTable)
   : base(null, fontTable.DirectoryEntry.Tag)
 {
   this.fontData = fontData;
   this.irefDirectoryEntry = fontTable.DirectoryEntry;
 }
コード例 #41
0
ファイル: GlyphDataTable.cs プロジェクト: DavidS/MigraDoc
 public GlyphDataTable(FontData fontData)
   : base(fontData, Tag)
 {
   DirectoryEntry.Tag = TableTagNames.Glyf;
   Read();
 }
コード例 #42
0
 public bool UnregisterFontData(FontData fontData)
 {
   Debug.Assert(false);
   return false;
 }
コード例 #43
0
 public IndexToLocationTable(FontData fontData)
   : base(fontData, Tag)
 {
   DirectoryEntry = this.fontData.tableDictionary[TableTagNames.Loca];
   Read();
 }
コード例 #44
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
 /// <summary>
 /// Initializes a new instance of the <see cref="CMapTable"/> class.
 /// </summary>
 public CMapTable(FontData fontData)
   : base(fontData, Tag)
 {
   Read();
 }
コード例 #45
0
 public OS2Table(FontData fontData)
     : base(fontData, Tag)
 {
     Read();
 }
コード例 #46
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CMapTable"/> class.
 /// </summary>
 public CMapTable(FontData fontData)
     : base(fontData, Tag)
 {
     Read();
 }
コード例 #47
0
 public PostScriptTable(FontData fontData)
     : base(fontData, Tag)
 {
     Read();
 }
コード例 #48
0
 public HorizontalHeaderTable(FontData fontData)
     : base(fontData, Tag)
 {
     Read();
 }
コード例 #49
0
ファイル: FontData.cs プロジェクト: DavidS/MigraDoc
 /// <summary>
 /// Shallow copy for font subset.
 /// </summary>
 FontData(FontData fontData)
 {
   this.offsetTable = fontData.offsetTable;
 }
コード例 #50
0
 public VerticalHeaderTable(FontData fontData)
     : base(fontData, Tag)
 {
     Read();
 }
コード例 #51
0
 public IndexToLocationTable(FontData fontData)
     : base(fontData, Tag)
 {
     DirectoryEntry = this.fontData.tableDictionary[TableTagNames.Loca];
     Read();
 }
コード例 #52
0
 public VerticalMetricsTable(FontData fontData)
     : base(fontData, Tag)
 {
     Read();
     throw new NotImplementedException("VerticalMetricsTable");
 }
コード例 #53
0
 /// <summary>
 /// Creates and reads a TableDirectoryEntry from the font image.
 /// </summary>
 public static TableDirectoryEntry ReadFrom(FontData fontData)
 {
   TableDirectoryEntry entry = new TableDirectoryEntry();
   entry.Tag = fontData.ReadTag();
   entry.CheckSum = fontData.ReadULong();
   entry.Offset = fontData.ReadLong();
   entry.Length = (int)fontData.ReadULong();
   return entry;
 }
コード例 #54
0
 public NameTable(FontData fontData)
     : base(fontData, Tag)
 {
     Read();
 }
コード例 #55
0
ファイル: OpenTypeStructures.cs プロジェクト: DavidS/MigraDoc
 public MaximumProfileTable(FontData fontData)
   : base(fontData, Tag)
 {
   Read();
 }
コード例 #56
0
        public ushort[] glyphIdArray;    // Glyph index array (arbitrary length)

        public CMap4(FontData fontData, WinEncodingId encodingId)
            : base(fontData, "----")
        {
            this.encodingId = encodingId;
            Read();
        }
コード例 #57
0
        /// <summary>
        /// Creates a new font image that is a subset of this font image containing only the specified glyphs.
        /// </summary>
        public FontData CreateFontSubSet(Dictionary <int, object> glyphs, bool cidFont)
        {
            // Create new font image
            FontData fontData = new FontData(this);

            // Create new loca and glyf table
            IndexToLocationTable loca = new IndexToLocationTable();

            loca.ShortIndex = this.loca.ShortIndex;
            GlyphDataTable glyf = new GlyphDataTable();

            // Add all required tables
            //fontData.AddTable(this.os2);
            if (!cidFont)
            {
                fontData.AddTable(this.cmap);
            }
            if (this.cvt != null)
            {
                fontData.AddTable(this.cvt);
            }
            if (this.fpgm != null)
            {
                fontData.AddTable(this.fpgm);
            }
            fontData.AddTable(glyf);
            fontData.AddTable(this.head);
            fontData.AddTable(this.hhea);
            fontData.AddTable(this.hmtx);
            fontData.AddTable(loca);
            if (this.maxp != null)
            {
                fontData.AddTable(this.maxp);
            }
            //fontData.AddTable(this.name);
            if (this.prep != null)
            {
                fontData.AddTable(this.prep);
            }

            // Get closure of used glyphs
            this.glyf.CompleteGlyphClosure(glyphs);

            // Create a sorted array of all used glyphs
            int glyphCount = glyphs.Count;

            int[] glyphArray = new int[glyphCount];
            glyphs.Keys.CopyTo(glyphArray, 0);
            Array.Sort <int>(glyphArray);

            // Calculate new size of glyph table.
            int size = 0;

            for (int idx = 0; idx < glyphCount; idx++)
            {
                size += this.glyf.GetGlyphSize(glyphArray[idx]);
            }
            glyf.DirectoryEntry.Length = size;

            // Create new loca table
            int numGlyphs = this.maxp.numGlyphs;

            loca.locaTable = new int[numGlyphs + 1];

            // Create new glyf table
            glyf.glyphTable = new byte[glyf.DirectoryEntry.PaddedLength];

            // Fill new glyf and loca table
            int glyphOffset = 0;
            int glyphIndex  = 0;

            for (int idx = 0; idx < numGlyphs; idx++)
            {
                loca.locaTable[idx] = glyphOffset;
                if (glyphIndex < glyphCount && glyphArray[glyphIndex] == idx)
                {
                    glyphIndex++;
                    byte[] bytes  = this.glyf.GetGlyphData(idx);
                    int    length = bytes.Length;
                    if (length > 0)
                    {
                        Buffer.BlockCopy(bytes, 0, glyf.glyphTable, glyphOffset, length);
                        glyphOffset += length;
                    }
                }
            }
            loca.locaTable[numGlyphs] = glyphOffset;

            // Compile font tables into byte array
            fontData.Compile();

            return(fontData);
        }
コード例 #58
0
 /// <summary>
 /// Shallow copy for font subset.
 /// </summary>
 FontData(FontData fontData)
 {
     this.offsetTable = fontData.offsetTable;
 }
コード例 #59
0
ファイル: FontData.cs プロジェクト: DavidS/MigraDoc
    /// <summary>
    /// Creates a new font image that is a subset of this font image containing only the specified glyphs.
    /// </summary>
    public FontData CreateFontSubSet(Dictionary<int, object> glyphs, bool cidFont)
    {
      // Create new font image
      FontData fontData = new FontData(this);

      // Create new loca and glyf table
      IndexToLocationTable loca = new IndexToLocationTable();
      loca.ShortIndex = this.loca.ShortIndex;
      GlyphDataTable glyf = new GlyphDataTable();

      // Add all required tables
      //fontData.AddTable(this.os2);
      if (!cidFont)
        fontData.AddTable(this.cmap);
      if (this.cvt != null)
        fontData.AddTable(this.cvt);
      if (this.fpgm != null)
        fontData.AddTable(this.fpgm);
      fontData.AddTable(glyf);
      fontData.AddTable(this.head);
      fontData.AddTable(this.hhea);
      fontData.AddTable(this.hmtx);
      fontData.AddTable(loca);
      if (this.maxp != null)
        fontData.AddTable(this.maxp);
      //fontData.AddTable(this.name);
      if (this.prep != null)
        fontData.AddTable(this.prep);

      // Get closure of used glyphs
      this.glyf.CompleteGlyphClosure(glyphs);

      // Create a sorted array of all used glyphs
      int glyphCount = glyphs.Count;
      int[] glyphArray = new int[glyphCount];
      glyphs.Keys.CopyTo(glyphArray, 0);
      Array.Sort<int>(glyphArray);

      // Calculate new size of glyph table.
      int size = 0;
      for (int idx = 0; idx < glyphCount; idx++)
        size += this.glyf.GetGlyphSize(glyphArray[idx]);
      glyf.DirectoryEntry.Length = size;

      // Create new loca table
      int numGlyphs = this.maxp.numGlyphs;
      loca.locaTable = new int[numGlyphs + 1];

      // Create new glyf table
      glyf.glyphTable = new byte[glyf.DirectoryEntry.PaddedLength];

      // Fill new glyf and loca table
      int glyphOffset = 0;
      int glyphIndex = 0;
      for (int idx = 0; idx < numGlyphs; idx++)
      {
        loca.locaTable[idx] = glyphOffset;
        if (glyphIndex < glyphCount && glyphArray[glyphIndex] == idx)
        {
          glyphIndex++;
          byte[] bytes = this.glyf.GetGlyphData(idx);
          int length = bytes.Length;
          if (length > 0)
          {
            Buffer.BlockCopy(bytes, 0, glyf.glyphTable, glyphOffset, length);
            glyphOffset += length;
          }
        }
      }
      loca.locaTable[numGlyphs] = glyphOffset;

      // Compile font tables into byte array
      fontData.Compile();

      return fontData;
    }