Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Convert String to GlyphIndices

$
0
0

Hi: What is the best way to convert a string to the unicode numbers in order to create a string of them so you can place them into the

GlyphIndices property of a glyphrun?

Here is the method I will be using it in.

 public static XElement DrawingTextXml(string userText, int userThickness, SolidColorBrush userColor)
        {
            //string for color
            String strColor = userColor.ToString();
            //convert user text to unicode numbers
            String convertedIndices = ConvertTextToIndices(userText);
            //glyph indices
            //String indices = "43 72 79 79 82 3 58 82 85 79 71";
            //base line origin
            String baseLine = "0,12.29";
            // font rendering EM size
            String emSize = "13.333333333333334";
            //device font name
            String dfName = "{x:Null}";
            //advanced widths
            String advancedWidths = "9.62666666666667 7.41333333333333 2.96 2.96 7.41333333333333 3.70666666666667 12.5866666666667 7.41333333333333 4.44 2.96 7.41333333333333";
            //BidiLevel
            String bidiLevel = "0";
            //font URI
            String fontURI = @"C:\WINDOWS\Fonts\TIMES.TTF"; 

            XElement myXml = new XElement(rootNS + "GlyphRunDrawing",
                                                        new XAttribute("ForegroundBrush", strColor),
                                                        new XElement(rootNS + "GlyphRunDrawing.GlyphRun",
                                                            new XElement(rootNS + "GlyphRun",
                                                                new XAttribute("CaretStops", "{x:Null}"),
                                                                new XAttribute("ClusterMap", "{x:Null}"),
                                                                new XAttribute("IsSideways", "False"),
                                                                new XAttribute("GlyphOffsets", "{x:Null}"),
                                                                new XAttribute("GlyphIndices", convertedIndices),
                                                                new XAttribute("BaselineOrigin", baseLine),
                                                                new XAttribute("FontRenderingEmSize", emSize),
                                                                new XAttribute("DeviceFontName", dfName),
                                                                new XAttribute("AdvanceWidths", advancedWidths),
                                                                new XAttribute("BidiLevel", bidiLevel),
                                                                new XElement(rootNS + "GlyphRun.GlyphTypeface",
                                                                    new XElement(rootNS + "GlyphTypeface",
                                                                        new XAttribute("FontUri", fontURI))))));


            return myXml;


        }

This is the method I am trying to create.

 private static String ConvertTextToIndices(String userText)
        {
            String outputString;
            Encoding unicode = Encoding.Unicode;
            Double charNumber;
            StringBuilder myIndiceString = new StringBuilder(userText.Length+1);
            myIndiceString.Length = userText.Length;
            //char myChar;

            //SByte[] arrayUniChar = new SByte[userText.Length+1];
            try
            {
                // Convert the string into a byte array. 
                //byte[] unicodeBytes = unicode.GetBytes(userText);
                char[] charNumArray;
                // Convert the new byte[] into a char[] and then into a string.
                //create the char array
               //char[] unicodeChars = new char[unicode.GetCharCount(unicodeBytes, 0, unicodeBytes.Length)];
                //put the string into the char array
               // unicode.GetChars(unicodeBytes, 0, unicodeBytes.Length, unicodeChars, 0);
                //convert each char numeric value to a string and add it to the output string
                for (int charIndex = 0; charIndex < userText.Length; charIndex++)
                {
                    charNumber = char.GetNumericValue(userText, charIndex);
                    charNumArray[charIndex] = Convert.ToChar(charNumber);

                }
                
                
                
               // string unicodeString = new string(unicodeChars);
               // return unicodeString;
                              
            }


Mike Gallinger C.Tech. Cutting Edge Computing Software Developer


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>