/// <summary> /// scale_x,scale_y、offset_x,offset_yを用いてアフィン変換してから文字列を描画する。 /// </summary> /// <param name="g"></param> /// <param name="dstPoint"></param> /// <param name="mes"></param> private void DrawString(Point dstPoint, string mes, int font_size, DrawStringOption option = null) { // 文字フォントサイズは、scaleの影響を受ける。 var scale = ViewModel.AffineMatrix.Scale.X; var size = (float)(font_size * scale); // こんな小さいものは視認できないので描画しなくて良い。 if (size <= 2) { return; } using (var font = new Font("MSPゴシック", size, GraphicsUnit.Pixel)) { var brush = option != null ? option.brush : Brushes.Black; var sf = new StringFormat(); sf.LineAlignment = StringAlignment.Near; var align = option != null ? option.align : 0; switch (align) { // 左寄せ case 0: sf.Alignment = StringAlignment.Near; break; // センタリング case 1: sf.Alignment = StringAlignment.Center; break; // 右寄せ case 2: sf.Alignment = StringAlignment.Far; break; } graphics.DrawString(mes, font, brush, Affine(dstPoint), sf); } }
/// <summary> /// scale_x,scale_y、offset_x,offset_yを用いてアフィン変換してから文字列を描画する。 /// </summary> /// <param name="g"></param> /// <param name="dstPoint"></param> /// <param name="mes"></param> private void DrawString(Point dstPoint, string mes, int font_size, DrawStringOption option = null) { // 文字フォントサイズは、scaleの影響を受ける。 var scale = AffineMatrix.Scale.X; var size = (float)(font_size * scale); // こんな小さいものは視認できないので描画しなくて良い。 if (size <= 2) { return; } var config = TheApp.app.Config; var fd = config.FontManager.MainWindow; var fontname = fd.FontName; var fontstyle = fd.FontStyle; var fontsize = fd.FontSize; // これを9ptからの相対的な大きさをフォントに反映させる。 using (var font = new Font(fontname, size * fontsize / 9f, fontstyle, GraphicsUnit.Pixel)) { var brush = option == null ? Brushes.Black : option.brush; var brush2 = option == null ? null : option.brush2; var sf = new StringFormat(); sf.LineAlignment = StringAlignment.Near; var align = option != null ? option.align : 0; switch (align) { // 左寄せ case 0: sf.Alignment = StringAlignment.Near; break; // センタリング case 1: sf.Alignment = StringAlignment.Center; break; // 右寄せ case 2: sf.Alignment = StringAlignment.Far; break; } // brush2が指定されているのでこれを先に描画 if (brush2 != null) { var dstPoint2 = new Point(dstPoint.X + 1, dstPoint.Y + 1); graphics.DrawString(mes, font, brush2, Affine(dstPoint2), sf); } graphics.DrawString(mes, font, brush, Affine(dstPoint), sf); } }