圆弧调整文字大小

时间:2018-11-12 06:12:35

标签: c# winforms text automatic-ref-counting scaling

我打算调整文本的宽度或高度,但是我不知道要使用哪种图形转换。

这是我的代码(“文本到弧”方法):

    private void DrawTextOnCircle(Graphics gr, Font font,Brush brush, float radius, float cx, float cy, string top_text,  RectangleF _rect, float spacing)
    {
        float x = 0f;
        float y = 0f;
        x = Shape.center.X - (_rect.Width / 2f);
        y = (Shape.center.Y - (_rect.Height / 2f));
        float TransformX = Shape.center.X;
        float TransformY = Shape.center.Y;

        gr.TranslateTransform(TransformX, TransformY);

        StringFormat string_format = new StringFormat();
        List<RectangleF> r = MeasureCharacters2(gr, font, _rect, top_text);
        float num = ((IEnumerable<float>)(from CharacterRectangle in r.Cast<RectangleF>() select CharacterRectangle.Width)).Sum();
        GraphicsContainer gc = gr.BeginContainer();
        gr.SmoothingMode = SmoothingMode.AntiAlias;
        gr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

        for(int i=0; i< top_text.Length; i++)
        {
            float dx = 0f;
            RectangleF ef = r[i];
            float dy = (ef.Height / 2f) - (radius * 3.779528f);
            float angle = spacing * i;
            float startAngle = 0;
            gr.RotateTransform((float)-90 + startAngle);
            if (i != 0)
                gr.RotateTransform(angle);

            gr.TranslateTransform(dx, dy);
            //gr.ScaleTransform()

            char ch = top_text[i];
            if(!isOutlined)
                gr.DrawString(ch.ToString(), font, Brushes.Red, 0, 0, string_format);
            else
            {
                GraphicsPath path = new GraphicsPath();
                path.AddString(top_text[i].ToString(), font.FontFamily, Convert.ToInt32(font.Style), gr.DpiY * font.Size/72f, new PointF(0f, 0f), string_format);
                gr.DrawPath(new Pen(Brushes.Red, 0.05f), path);
            }
            gr.ResetTransform();
        }
        gr.EndContainer(gc);
    }

我的输出:

enter image description here

  

我想做的是,如果我缩放trackBar并带有宽度或高度选项,则文本也将缩放其宽度或高度。

0 个答案:

没有答案