Forum Xamarin Xamarin.Forms

SKPaint.IsVerticalText is obsolete?

lescperlescper Member ✭✭✭✭

how to use it to verticaltext now?

SKPaint.IsVerticalText is obsolete?

Tagged:

Answers

  • lescperlescper Member ✭✭✭✭

    :):):):):)

  • jezhjezh Member, Xamarin Team Xamurai
    edited September 14

    As a test, there is no such property now:

    For this question, you can follow up this issue here: https://github.com/mono/SkiaSharp/issues/1496

  • lescperlescper Member ✭✭✭✭

    @jezh then how to draw a vertical text?

  • jezhjezh Member, Xamarin Team Xamurai
  • lescperlescper Member ✭✭✭✭

    @jezh nothing about vertical text. and I do not want to transform.

    there will be many text and many lines.

  • jezhjezh Member, Xamarin Team Xamurai

    there will be many text and many lines.

    When we rotate the text for only one degree, there will be one line text.

    For example ,when I replaced the sample code RotatedTextPage.cs with the following code :

        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info = args.Info;
            SKSurface surface = args.Surface;
            SKCanvas canvas = surface.Canvas;
    
            canvas.Clear();
    
            using (SKPaint textPaint = new SKPaint
            {
                Color = SKColors.Black,
                TextSize = 72
            })
            {
                float xCenter = info.Width / 2;
                float yCenter = info.Height / 2;
    
                SKRect textBounds = new SKRect();
                textPaint.MeasureText(text, ref textBounds);
                float yText = yCenter - textBounds.Height / 2 - textBounds.Top;
    
                //for (int degrees = 0; degrees <=90; degrees += 90)
                //{
                //    canvas.Save();
                //    canvas.RotateDegrees(degrees, xCenter, yCenter);
                //    canvas.DrawText(text, xCenter, yText, textPaint);
                //    canvas.Restore();
                //}
    
    
                canvas.Save();
                canvas.RotateDegrees(90, xCenter, yCenter);
                canvas.DrawText(text, xCenter, yText, textPaint);
                canvas.Restore();
            }
        }
    

    The result will as follows:

  • lescperlescper Member ✭✭✭✭

    If there is a lot of words?

  • lescperlescper Member ✭✭✭✭

    It is not work

  • lescperlescper Member ✭✭✭✭
  • jezhjezh Member, Xamarin Team Xamurai
    edited September 16

    If there is a lot of words?

    I did a test with a long words, the result is like this:

    I just changed the value of yCenter:

      float yCenter = 10;
    
  • lescperlescper Member ✭✭✭✭

    @jezh If there is mutiple lines?

  • jezhjezh Member, Xamarin Team Xamurai

    If there is mutiple lines?

    You can draw other texts with the same canvas.
    When I modified the sample code as follows:

           void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
            {
                SKImageInfo info = args.Info;
                SKSurface surface = args.Surface;
                SKCanvas canvas = surface.Canvas;
    
                canvas.Clear();
    
                using (SKPaint textPaint = new SKPaint
                {
                    Color = SKColors.Black,
                    TextSize = 50
                })
                {
                    float xCenter = info.Width / 2;
                    float yCenter = 10;
    
                    SKRect textBounds = new SKRect();
                    textPaint.MeasureText(text, ref textBounds);
                    float yText = yCenter - textBounds.Height / 2 - textBounds.Top;
    
                    canvas.Save();
                    canvas.RotateDegrees(90, xCenter, yCenter);
                    canvas.DrawText(text, xCenter, yText, textPaint);
                    canvas.Restore();
    
                    //***********************
                    float xCenter2 = info.Width / 2+50;
                    float yCenter2 = 10;
    
    
                    SKRect textBounds2 = new SKRect();
                    textPaint.MeasureText(text2, ref textBounds2);
                    float yText2 = yCenter2 - textBounds2.Height / 2 - textBounds2.Top;
    
    
                    canvas.Save();
                    canvas.RotateDegrees(90, xCenter2, yCenter2);
                    canvas.DrawText(text2, xCenter2, yText2, textPaint);
                    canvas.Restore();
    
                }
            }
        }
    

    The text2 is the second string:

      static readonly string text2 = "rotated text2 assssssssssssssssssssssssssssssssssss ";
    

    The result

  • lescperlescper Member ✭✭✭✭

    @jezh I mean I do not know how many texts is there.

    and do not wan tto separate it to mutiple.

  • jezhjezh Member, Xamarin Team Xamurai

    For this, you can refer to the following thread: https://forums.xamarin.com/discussion/105582/drawtext-multiline

Sign In or Register to comment.