倍角文字を出力できますか?

文書番号 : 27318     文書種別 : 使用方法     最終更新日 : 2009/08/03
文書を印刷する
対象製品
ActiveReports for .NET 6.0J Professional
詳細
ActiveReports には、文字を横倍角や縦倍角で出力するための直接的な機能は用意されておりませんが、Graphicsクラスの DrawStringメソッドを用いることで、それに近い動作は可能です。

◆サンプルコード (VB.NET)
Private Sub Detail_Format(...) Handles Detail.Format
  Picture1.Size = New SizeF(4.0F, 2.0F)
  Dim bm As New Bitmap(400, 200)
  Picture1.Image = bm

  ' Graphicsオブジェクトを作成します。
  Dim g As Graphics = Graphics.FromImage(Picture1.Image)

  ' 出力するフォントを設定します。
  Dim f As New Font("MS ゴシック", 12)

  ' 表示位置の単位を mm に設定します。
  g.PageUnit = GraphicsUnit.Millimeter

  ' テキストレンダリングの品質を指定します。
  ' (アンチエイリアス処理されたグリフ ビットマップを使用)
  g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias

  ' ------ アンチエイリアス処理した通常のサイズの文字を表示 ------
  g.TranslateTransform(10, 0)       '表示位置の設定
  g.ScaleTransform(1.0, 1.0)       '横・縦の表示比率の設定
  g.DrawString("通常サイズの文字", f, Brushes.Black, 0, 0)
  g.ResetTransform()           '単位行列にリセット

  ' ---------------------- 横倍角文字を表示 ----------------------
  g.TranslateTransform(10, 10)      '表示位置の設定
  g.ScaleTransform(2.0, 1.0)       '横・縦の表示比率を設定
  g.DrawString("横倍角文字", f, Brushes.Red, 0, 0)
  g.ResetTransform()           '単位行列にリセット

  ' ---------------------- 縦倍角文字を表示 ----------------------
  g.TranslateTransform(10, 20)      '表示位置の設定
  g.ScaleTransform(1.0, 2.0)       '横・縦の表示比率を設定
  g.DrawString("縦倍角文字", f, Brushes.Blue, 0, 0)
  g.ResetTransform()           '単位行列にリセット

  f.Dispose()
  g.Dispose()
End Sub



◆サンプルコード (C#)
private void detail_Format(object sender, EventArgs e)
{
  this.picture1.Size = new SizeF(4.0F, 2.0F);
  Bitmap bm = new Bitmap(400, 200);
  this.picture1.Image = bm;

  // Graphicsオブジェクトを作成します。
  Graphics g = Graphics.FromImage(this.picture1.Image);

  // 出力するフォントを設定します。
  Font f =new Font("MS ゴシック", 12);

  // 表示位置の単位を mm に設定します。
  g.PageUnit = GraphicsUnit.Millimeter;

  // テキストレンダリングの品質を指定します。
  // (アンチエイリアス処理されたグリフ ビットマップを使用)
  g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

  // ------ アンチエイリアス処理した通常のサイズの文字を表示 ------
  g.TranslateTransform(5, 5);       // 表示位置の設定
  g.ScaleTransform(1.0f, 1.0f);      // 横・縦の表示比率の設定
  g.DrawString("通常サイズの文字", f, Brushes.Black, 0, 0);
  g.ResetTransform();           // 単位行列にリセット

  // ---------------------- 横倍角文字を表示 ----------------------
  g.TranslateTransform(5, 15);      // 表示位置の設定
  g.ScaleTransform(2.0f, 1.0f);      // 横・縦の表示比率を設定
  g.DrawString("横倍角文字", f, Brushes.Red, 0, 0);
  g.ResetTransform();           // 単位行列にリセット

  // ---------------------- 縦倍角文字を表示 ----------------------
  g.TranslateTransform(5, 25);      // 表示位置の設定
  g.ScaleTransform(1.0f, 2.0f);      // 横・縦の表示比率を設定
  g.DrawString("縦倍角文字", f, Brushes.Blue, 0, 0);
  g.ResetTransform();           // 単位行列にリセット

  f.Dispose();
  g.Dispose();
}


なお、上記の方法によって描画された文字列は、Graphicsオブジェクト(メタ形式)上にレンダリングされているため、レポート上では全て画像データとなります。
キーワード
HowTo デザイン・レイアウト

この文書は、以前は次のFAQ IDで公開されていました : 11995