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_P2EP_PS1_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 { // 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_Dialogue(List <string>[] dialogue_lines) { // Create variables to store the width and height of the template. int template_width = 320; int template_height = 240; Bitmap base_template = new Bitmap(template_width, template_height); // Establish ints for the width and height of glyphs. int x_multiplier = 8; int y_multiplier = 12; string font_sheet = $@"{AssetDirectoryConfig.assetDirectory.assetFolderPath}//SceneMaker//Templates//P2EP-PS1//Font//p2ep-ps1_font_sheet.png"; Bitmap current_glyph; // Iterate over each line of the dialogue string list with a loop. for (int i = 0; i < dialogue_lines.Length; i++) { // Specify X and Y coordinates for where the glyphs should start rendering on the template. int render_position_x = 21; int render_position_y = 185 + (14 * i); // Take the input dialogue and convert it into a char array. char[] char_array = String_List_To_String(dialogue_lines[i]).ToCharArray(); // Iterate through each character of the array. for (int j = 0; j < char_array.Length; j++) { //Retrieve glyph information from the JSON file var glyph = ParsingMethods.Get_P2EP_PS1_Glyph(char_array[j]); // If the glyph info returns null, we have a rendering error. // A warning message should have already been sent to the user in the Measure_Word_Pixel_Length method. if (glyph == null) { // Do nothing } if (glyph != null) { int x = x_multiplier * glyph.Column; int y = 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, x_multiplier, y_multiplier); current_glyph = originalImage.Clone(crop, originalImage.PixelFormat); // Draw the glyph to the base bitmap. Some hanging letters will need to be drawn a bit lower to appear natural. if (char_array[j] == 'g' || char_array[j] == 'j' || char_array[j] == 'p' || char_array[j] == 'q' || char_array[j] == 'y') { graphics.DrawImage(current_glyph, (render_position_x - glyph.LeftCut), render_position_y + 1, x_multiplier, y_multiplier); } else { graphics.DrawImage(current_glyph, (render_position_x - glyph.LeftCut), render_position_y, x_multiplier, y_multiplier); } } } // Set the next X value at the end of the current glyph's right width. render_position_x += (glyph.RightCut - glyph.LeftCut) + 1; } } } return(base_template); }
public static Bitmap Render_Name(BustupData bustup_data) { // Create variables to store the width and height of the template. int template_width = 320; int template_height = 240; Bitmap base_template = new Bitmap(template_width, template_height); // Establish ints for the width and height of glyphs. int x_multiplier = 8; int y_multiplier = 12; // Load the bitmap font. string font_sheet = $@"{AssetDirectoryConfig.assetDirectory.assetFolderPath}//SceneMaker//Templates//P2EP-PS1//Font//p2ep-ps1_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 = 16; int render_position_y = 171; // Take the sprite's display name and convert it into a char array. char[] char_array = bustup_data.Default_Name_EN.ToCharArray(); // Iterate through each character of the array. for (int i = 0; i < char_array.Length; i++) { // Retrieve glyph information from the JSON file. var glyph = ParsingMethods.Get_P2EP_PS1_Glyph(char_array[i]); // Check if the character is a line break. if (char_array[i] == '\u000a') { // Set the X coordinate to the start of the row. render_position_x = 16; // Move the Y coordinate down to the next line. render_position_y += 14; } else { int x = x_multiplier * glyph.Column; int y = 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, x_multiplier, y_multiplier); current_glyph = originalImage.Clone(crop, originalImage.PixelFormat); // Draw the glyph to the base bitmap. Some hanging letters will need to be drawn a bit lower to appear natural. if (char_array[i] == 'g' || char_array[i] == 'j' || char_array[i] == 'p' || char_array[i] == 'q' || char_array[i] == 'y') { graphics.DrawImage(current_glyph, (render_position_x - glyph.LeftCut), render_position_y + 1, x_multiplier, y_multiplier); } else { graphics.DrawImage(current_glyph, (render_position_x - glyph.LeftCut), render_position_y, x_multiplier, y_multiplier); } } } // Set the next X value at the end of the current glyph's right width. render_position_x += (glyph.RightCut - glyph.LeftCut) + 1; } } return(base_template); }