public static int Measure_Word_Pixel_Length(SocialLinkerCommand sl_command, string input_word) { // Create an int to keep track of how many pixels a glyph is wide in. int pixel_counter = 0; // Create another int to count the number of times a character comes up null from the font sheet. // We'll want to keep track of this number so we can ensure there's only one error message sent. int error_counter = 0; // Take the input string and turn it into a char array. char[] char_array = input_word.ToCharArray(); // Now, let's iterate through the char array. for (int i = 0; i < char_array.Length; i++) { // Retrieve glyph information for the current character from the JSON file. var glyph = ParsingMethods.Get_P4G_Glyph(char_array[i]); // Make sure that the glyph info doesn't return null. if (glyph != null) { // Check if the current character is a line break. // If it is, do nothing. Line breaks take up no pixel width space. if (char_array[i] == '\u000a') { // Do nothing } else { // Check if the current iterated index is less than the number of indicies available. if (i < char_array.Length - 1) { // If so, edit the position of the X coordinate according to specific kerning pairs. if (char_array[i] == 'Y' && Char.IsLower(char_array[i + 1])) { pixel_counter += -6; } else if (char_array[i] == 'v' && Char.IsLower(char_array[i + 1])) { pixel_counter += -1; } else if (char_array[i] == 'T' && Char.IsLower(char_array[i + 1]) && (char_array[i + 1] != 'h')) { pixel_counter += -6; } } // Set the pixel counter to the appropriate width of the string so far. pixel_counter += glyph.RightCut - glyph.LeftCut; } } // If the character returns null, it's not supported by the template's font set. // Send a warning message to the user. else { // Increase the error counter by one. error_counter++; // If the error counter is at exactly 1, send a warning message to the user. if (error_counter == 1) { _ = ErrorHandling.Unsupported_Character(sl_command); } } } return(pixel_counter); }
public static Bitmap Render_Name(BustupData bustup_data) { // Create a bitmap as large as the template. Bitmap base_template = new Bitmap(1920, 1080); // Establish an int for the width and height glyphs should be rendered at. int multiplier = 64; // Load the bitmap font. string font_sheet = $@"{AssetDirectoryConfig.assetDirectory.assetFolderPath}//SceneMaker//Templates//P4G//Font//p4g_font_sheet.png"; // Create a variable to iterate through sections of the bitmap font. Bitmap current_glyph; // Specify X and Y coordinates for where the glyphs should start rendering on the template. int render_position_x = 102; int render_position_y = 748; char[] charArr = bustup_data.Default_Name_EN.ToCharArray(); for (int i = 0; i < charArr.Length; i++) { // Retrieve glyph information from the JSON file. var glyph = ParsingMethods.Get_P4G_Glyph(charArr[i]); // Check if the character is a line break. if (charArr[i] == '\u000a') { // Set the X coordinate to the start of the row. render_position_x = 124; // Move the Y coordinate down to the next line. render_position_y += 68; } else { int x = multiplier * glyph.Column; int y = multiplier * glyph.Row; using (Graphics graphics = Graphics.FromImage(base_template)) { using (var originalImage = new Bitmap(font_sheet)) { // Copy the section of the bitmap font needed. Rectangle crop = new Rectangle(x, y, multiplier, multiplier); current_glyph = originalImage.Clone(crop, originalImage.PixelFormat); // Draw the glyph to the base bitmap. graphics.DrawImage(current_glyph, (render_position_x - glyph.LeftCut), render_position_y, multiplier, multiplier); } } // Set the next X value at the end of the current glyph's right width. render_position_x += (glyph.RightCut - glyph.LeftCut); // Check if the current iterated index is less than the number of indicies available. if (i < charArr.Length - 1) { // If so, edit the position of the X coordinate according to specific kerning pairs. if (charArr[i] == 'Y' && Char.IsLower(charArr[i + 1])) { render_position_x += -6; } else if (charArr[i] == 'v' && Char.IsLower(charArr[i + 1])) { render_position_x += -1; } else if (charArr[i] == 'T' && Char.IsLower(charArr[i + 1]) && charArr[i + 1] != 'h') { render_position_x += -6; } } } } return(base_template); }