LoginSignup
3
3

More than 5 years have passed since last update.

WinForms+Win8/8.1で縦書き&斜体の描画がバグっている

Last updated at Posted at 2014-06-02

概要

Win8または8.1の環境下において、Windowsフォームで縦書き&斜体(MS Pゴシック)を描画すると、フォントサイズによっては傾き方がWin7以前と比べておかしくなります。

※(ついでに)縦書きとは関係ありませんが、絵文字も描画されません。

スクリーンショット

Win7 (左から順にGraphics.DrawString120px, Graphics.DrawString48px, GraphicsPath.AddString48px)
win7winforms.png

Win8.1
win8winforms.png

  • 小さいフォント(真ん中)は問題無いが、大きなフォント(左)になると、傾き方が変わる
  • パス生成(右)はフォントサイズに関係無くおかしい
  • 顔文字はとにかく出ない(豆腐になる)

再現コード

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    var g = e.Graphics;
    var text = "「縦。」?";
    var fontFace = "MS Pゴシック";
    var sf = new StringFormat(StringFormat.GenericTypographic);
    sf.FormatFlags |= (StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.DirectionVertical);


    // DrawString フォント大 おかしい
    {
        var font = new Font(fontFace, 120, FontStyle.Italic, GraphicsUnit.Pixel);
        g.DrawString(text, font, Brushes.Black, 10, 10, sf);
    }

    // DrawString フォント小 問題なし
    {
        var font = new Font(fontFace, 48, FontStyle.Italic, GraphicsUnit.Pixel);
        g.DrawString(text, font, Brushes.Black, 190, 10, sf);
    }

    // GraphicsPath + AddString おかしい
    {
        var font = new Font(fontFace, 48, FontStyle.Italic, GraphicsUnit.Pixel);
        var path = new GraphicsPath();
        path.AddString(text, font.FontFamily, (int)font.Style, font.Size, new Point(300, 10), sf);
        g.DrawPath(Pens.Black, path);
    }
}

回避方法

今のところありません。何か判ったら追記します。

3
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3