C#でPDF上で使えるフォントを調べようとした

 どんなフォントが使えるのか調べようと思って、こんなのを作ってみた。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using PdfSharp;
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using PdfSharp.Pdf.IO;

namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            PdfDocument doc = new PdfDocument();

            PdfPage page = doc.AddPage();
            XGraphics g = XGraphics.FromPdfPage(page);

            PointF poif = new PointF(0f, 10f);
            XFont f;
            foreach (XFontFamily ff in XFontFamily.Families)
            {
               
                if (ff.IsStyleAvailable(XFontStyle.Bold) == true)
                {
                    f = new XFont(ff.Name, 20.0, XFontStyle.Bold);
                    g.DrawString(ff.Name, f, XBrushes.Black, poif);
                    poif.Y += 10f;
                }
            }

            doc.Save("test.pdf");

            Process.Start("test.pdf");
           
        }
    }
}

実行すると、バグが出る。

f:id:pongeponge:20130414162032p:plain

 Error while parsing an OpenType font.

らしい。

OpenTypeフォントが使えないんだろうか?

 

 ついでにフォントをMS明朝に変えてみてもにたようなもんだった。あれー?