Ejemplo n.º 1
0
        //build packed characters' bitmap for ASCII/Chinese/Japanse/Korean characters etc.
        public static bool PrepareCommonGlyphMapInfo()
        {
            bool result = false;

            var assemblyDir  = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var solutionDir  = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyDir)));
            var ttfSampleDir = solutionDir + @"\FontSamples\";
            var ttfPath      = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts) + "\\msyh.ttf";

            Common = new Dictionary <string, TTF>(3);

            TTF asciiTTF = new TTF();

            result = asciiTTF.LoadTTFFont(ttfPath, "msyh.ttf");//Fixed font for simplicity
            if (!result)
            {
                Debug.WriteLine("LoadTTFFont msyh.ttf failed.");
                return(false);
            }
            const string asciiCharacters = @" !""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

            asciiTTF.FirstCharCode = asciiCharacters[0];
            result = asciiTTF.CreatePackedGlyphMap(asciiCharacters, 14, 512, 512);//Fixed font size for simplicity
            if (!result)
            {
                Debug.WriteLine("CreatePackedGlyphMap for ASCII Characters failed.");
                return(false);
            }
            Common["ASCII"] = asciiTTF;

            TTF japaneseTTF = new TTF();

            result = japaneseTTF.LoadTTFFont(ttfPath, "msyh.ttf");
            if (!result)
            {
                Debug.WriteLine("LoadTTFFont msyh.ttf failed.");
                return(false);
            }
            //Ref:
            //http://symbolcodes.tlt.psu.edu/bylanguage/japanesecharthiragana.html
            //http://symbolcodes.tlt.psu.edu/bylanguage/japanesechartkatakana.html
            const string japaneseCharacters =
                "ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをんゔ" +        //Hiragana Syllable Entity Codes
                "ゞ゛゜ーー" +                                                                                       //Hiragana and Katakana Punctuation/Symbols
                "ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶヷヸヹヺ・" + //Katakana Syllable Entity Codes
                "゛゜ーヽヾ" +                                                                                       //Katakana Punctuation
                "ㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ" +                                                                            //Ainu Phonetic Extensions
                "㋐㋑㋒㋓㋔㋕㋖㋗㋘㋙㋚㋛㋜㋝㋞㋟㋠㋡㋢㋣㋤㋥㋦㋧㋨㋩㋪㋫㋬㋭㋮㋯㋰㋱㋲㋳㋴㋵㋶㋷㋸㋹㋺㋻㋼㋽㋾" +                                             //Katakana in Circles
                "・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚";                                  //Katakana Half Width Forms

            japaneseTTF.FirstCharCode = japaneseCharacters[0];
            result = japaneseTTF.CreatePackedGlyphMap(japaneseCharacters, 14, 512, 512);
            if (!result)
            {
                Debug.WriteLine("CreatePackedGlyphMap for Japanese Characters failed.");
                return(false);
            }
            Common["Japanese"] = japaneseTTF;


            return(true);
        }
Ejemplo n.º 2
0
 private void CharacterTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     CurrentTTF = TTF.Common[CharacterTypeComboBox.SelectedItem.ToString()];
 }