1

I have wrote some code to get the Font name out of ttf file. But when it run on English-windows OS, all the Japanese font return its name in English Ex: instead of <リュウミン>. I would like to get the the font name in Japanese when i run the program on my English-windows OS. If you can give some advice, i will be appreciated!

I searched for System.Globalization namespace but it gets me no-where.

private void getFile_Click(object sender, EventArgs e)
        {
            fontFilePath.Text = openFolder();
        }

        private void print_Click(object sender, EventArgs e)
        {
            StringBuilder strb = new StringBuilder();
            DirectoryInfo d = new DirectoryInfo(fontFilePath.Text);
            //convert to jp
            //System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("ja-JP", true);
            //culture. = new System.Globalization.JapaneseCalendar();
            FileInfo[] fil = d.GetFiles();
            foreach (FileInfo _fil in fil)
            {
                PrivateFontCollection fonts = new PrivateFontCollection();
                fonts.AddFontFile(_fil.FullName);
                try { strb.Append(fonts.Families[0].Name).AppendLine(); }
                catch (Exception ex) { }
            }
            FileStream fs = new FileStream(System.IO.Directory.GetCurrentDirectory() + "/path.txt" , FileMode.Create, FileAccess.ReadWrite);
            StreamWriter strw = new StreamWriter(fs);
            strw.Write(strb);
            strw.Close();
            strb.Clear();

        }

        private string openFolder()
        {
            FolderBrowserDialog fol = new FolderBrowserDialog();
            if (fol.ShowDialog() == DialogResult.OK)
            {
                string folName = fol.SelectedPath;
                return folName;
            }
            else
                return "";
        }
MarioWu
  • 73
  • 1
  • 13
  • 1
    I tested [this answer](https://stackoverflow.com/questions/41053962/how-to-always-get-english-font-name-via-privatefontcollection-in-c) (with the Japanese LCID code), which I'd expect to work, but it doesn't work on my English system. Perhaps I don't have any fonts with Japanese names, I guess. – ProgrammingLlama Apr 18 '19 at 04:30
  • 1
    Thank you very much for helping me solve this problem! Thank you! – MarioWu Apr 18 '19 at 04:30
  • Sorry I can't be more help m(_ _)m – ProgrammingLlama Apr 18 '19 at 04:32
  • it worked, thank you very much! m(_ _)m ありがとうございました。 – MarioWu Apr 18 '19 at 04:38
  • Can you not look into the font itself? All the strings are stored in the OpenType `name` table, so you should be able to just consult that table, get the full name NameRecord, and have exactly what you were looking for. – Mike 'Pomax' Kamermans Apr 18 '19 at 17:06
  • Thank for your advise, I have already found the way to solve that prob! – MarioWu Apr 19 '19 at 02:28
  • Possible duplicate of [How to always get English font name via PrivateFontCollection in C#?](https://stackoverflow.com/questions/41053962/how-to-always-get-english-font-name-via-privatefontcollection-in-c) – Mike 'Pomax' Kamermans Apr 22 '19 at 14:23

0 Answers0