How to display Mongolian Baiti string in c# with GDI+?

Fiona 105 Reputation points
2023-05-10T03:23:16.0566667+00:00

When I want to display a mongolian font like “ ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭ”, I got the result as the following picture,

How can I get the charactors that I type in ?

1683688681993


 protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            StringFormat myMeasureFormat = new System.Drawing.StringFormat(System.Drawing.StringFormat.GenericTypographic);
            myMeasureFormat.FormatFlags = System.Drawing.StringFormatFlags.FitBlackBox | System.Drawing.StringFormatFlags.MeasureTrailingSpaces;
            myMeasureFormat.FormatFlags |= StringFormatFlags.DirectionVertical;

            e.Graphics.DrawString("ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭ", new Font("Mongolian Baiti", 12), new SolidBrush(Color.Red), new PointF(0, 0), myMeasureFormat);
        }
Windows for business | Windows Client for IT Pros | User experience | Other
Developer technologies | Visual Studio | Other
Developer technologies | C#
{count} votes

Accepted answer
  1. Anonymous
    2023-05-10T09:10:35.16+00:00

    Hi @Fiona , Welcome to Microsoft Q&A.

    I'm not an expert in Mongolian, so I can only give you my opinion.

    The character "ᠭ᠌" can only appear at the end of a sentence, and if it appears in a word, there will be a drawing error.

    enter image description here

    The character "ᠭ᠌" has three variants. Their encodings are different, and I can't distinguish them from the appearance.

    You need to use replace to replace all "ᠭ᠌" with "ᠭ".

    StringFormat myMeasureFormat = new System.Drawing.StringFormat(System.Drawing.StringFormat.GenericTypographic);
    myMeasureFormat.FormatFlags = System.Drawing.StringFormatFlags.FitBlackBox | System.Drawing.StringFormatFlags.MeasureTrailingSpaces;
    myMeasureFormat.FormatFlags |= StringFormatFlags.DirectionVertical;
    string originalText = "ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭ";
    string modifiedText = originalText.Replace("ᠭ᠌", "ᠭ");
    // e.Graphics.DrawString("ᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭᠭ ᠭᠭᠭ ᠮᠤᠩᠭᠤᠯ ᠬᠡᠯᠡ", new Font("Mongolian Baiti", 12), new SolidBrush(Color.Red), new PointF(0, 0), myMeasureFormat);
    e.Graphics.DrawString(modifiedText, new Font("Mongolian Baiti", 12), new SolidBrush(Color.Red), new PointF(0, 0), myMeasureFormat);
    

    enter image description here

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Limitless Technology 44,776 Reputation points
    2023-05-10T11:04:14.79+00:00
    Hi,
    
    I'd be happy to help you out with your question. Sorry for the inconvenience caused.
    
    To do this, please ensure that you have the Mongolian Baiti font installed on your computer. If you don't have the font installed, you can download it from a trusted source and install it on your system.
    
    Once you have the font installed, you can use the following code snippet in your C# application to display Mongolian Baiti characters:
    
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        
        string text = "ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭᠭ᠌ᠭ";
        Font font = new Font("Mongolian Baiti", 12);
        SolidBrush brush = new SolidBrush(Color.Red);
        PointF location = new PointF(0, 0);
        
        e.Graphics.DrawString(text, font, brush, location);
    }
    
    Please note that you should verify that the font name "Mongolian Baiti" matches the actual font name installed on your system. Also, feel free to adjust the font size, color, and position as per your requirements.
    
    Keep in mind that rendering complex scripts like Mongolian can be influenced by various factors, including system settings, the text rendering engine, and the application you're using. If you encounter any issues with rendering, it may be necessary to investigate further or consider utilizing a more specialized library or framework that provides enhanced support for complex scripts.
    
    If you have any other questions or need assistance with anything, please don't hesitate to let me know. I'm here to help.
     
    If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.
    
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.