Skip to content

Text issue #9

@nfskis

Description

@nfskis

Hi Chris,
first, thank you for the great job. I love to play with your great virtual canvas. It is wonderful. by the way, I have a struggling to display text but It was not successful. I made a method as like this. but It disappear texts on the canvas. Could you please advice for me? thank you in advance.

private void DrawText(DrawingContext dc, Pen pen, Pen selectionPen, Rect bounds)
{
double minFontSize = 150.0;
double adjustedFontSize = Math.Min(100 / scale, minFontSize); // 조정된 폰트 크기 적용
var dpi = VisualTreeHelper.GetDpi(this);

 FormattedText text = new FormattedText(
     "TEST",
     CultureInfo.InvariantCulture,
     FlowDirection.LeftToRight,
     new Typeface("Arial"),
     adjustedFontSize, 
     pen.Brush,
     dpi.PixelsPerDip);

 //Debug.WriteLine(@$"bounds {bounds.Width} X {bounds.Height}, FontSize: {adjustedFontSize}");
 dc.DrawText(text, new Point(bounds.X, bounds.Y));

 if (Selected)
 {
     dc.DrawRectangle(null, selectionPen, bounds);
 }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions