Mike Ryan Posted July 14, 2008 Share Posted July 14, 2008 Adding Font Types to WhichSymbol A Codelab Tutorial for Non Code Lab users First of all, before we get started I wanted to say that I am not going to use any coding jargon or make references to the coding language used, C#. However, you must have the plugin Code Lab succesfully installed. For more information about how to install plugins, please visit this thread. Alright, so with that aside let us go ahead and get started. First, let's take a look at the original code, graciously provided by Ego Eram Reputo, which can be found here. Because we are not going to even mess around with all of the code, I am not going to post all of it here. Just the nibbles we will be working with First part we have to do is edit the 'controls'. These are just some numerical additions and nothing more, take a look: #region UICode int Amount1=42; // [32,255] Character int Amount2=150; // [8,255] FontSize int Amount3 = 1; // [1,4] Webdings Wingdings Wingdings2 Wingdings3 bool Amount4 = true; // [0,1] Show Entire Font #endregion Look at line four of that code: it specifies which font we are going to work with. So, the part that contains '[1,4] specifies the range in fonts. So, the only work there is change the number 4 to the number of font types you wish to add. In my case, I am just adding one. Next, we need to specify the font. Which font are you adding? First, find the true name (the name that is in the list of fonts) of the font you wish to add. In my case, I am adding Carbon Black as I often use it for single letter designs. So, take a look next at this part of the code: Webdings Wingdings Wingdings2 Wingdings3. After the word Wingdings3, add the true name of your font. By personal preference, I have spiffed mine up a bit for general purpose of neatness. Take a look: int Amount3 = 5; // [1,5] 1) Webdings, 2) Wingdings, 3) Wingdings2, 4) Wingdings3, 5) Carbon Black With that taken care of, it is time to perform the direct code modifications. The first part is we have to add our font to the font lists. Find this part of the code: Font F1 = new Font("Webdings", Amount2); Font F2 = new Font("Wingdings", Amount2); Font F3 = new Font("Wingdings 2", Amount2); Font F4 = new Font("Wingdings 3", Amount2); After the fourth line, create a new line and type: Font F5 = new Font("TRUE NAME", Amount2); Replace the words TRUE NAME with the true name of your added font type. Now, your code should look similar to mine: Font F1 = new Font("Webdings", Amount2); Font F2 = new Font("Wingdings", Amount2); Font F3 = new Font("Wingdings 2", Amount2); Font F4 = new Font("Wingdings 3", Amount2); Font F5 = new Font("Carbon Black", Amount2); Now we have to reapply the previous steps. Excuse the copy and past Find this part of the code: Font F11 = new Font("Webdings", 16); Font F12 = new Font("Wingdings", 16); Font F13 = new Font("Wingdings 2", 16); Font F14 = new Font("Wingdings 3", 16); After the fourth line, create a new line and type: Font F15 = new Font("TRUE NAME", 16); Replace the words TRUE NAME with the true name of your added font type. Now, your code should look similar to mine: Font F11 = new Font("Webdings", 16); Font F12 = new Font("Wingdings", 16); Font F13 = new Font("Wingdings 2", 16); Font F14 = new Font("Wingdings 3", 16); Font F15 = new Font("Carbon Black", 16); Now that we have added our font, it is time to make just two more revisions (Hurrah!). Find the following code: switch (Amount3) { case 1: symbol = Convert.ToString((char)Amount1); g.DrawString(symbol, F1, B1, selection.Left, selection.Top); break; case 2: symbol = Convert.ToString((char)Amount1); g.DrawString(symbol, F2, B1, selection.Left, selection.Top); break; case 3: symbol = Convert.ToString((char)Amount1); g.DrawString(symbol, F3, B1, selection.Left, selection.Top); break; case 4: symbol = Convert.ToString((char)Amount1); g.DrawString(symbol, F4, B1, selection.Left, selection.Top); break; } If you looked hard enough, you should have found that there are two sections of code that look just like that, almost. So pay certain attention when finding the code. Alright, after the block that looks like this: case 4: symbol = Convert.ToString((char)Amount1); g.DrawString(symbol, F4, B1, selection.Left, selection.Top); break; We are going to add a very similar set of lines. Go ahead and create a new line beneath the above code, and type this: case 5: symbol = Convert.ToString((char)Amount1); g.DrawString(symbol, F5, B1, selection.Left, selection.Top); break; Easy, right? Although, let it be known that if you are adding multiple fonts you must type that in multiple times. Simply change the word case 5: to the next number in the series. Do the same for the word F5 Now we just have to reapply. Again, I am going to copy and paste the above and modify it as fit. So I apologize Find the following code: switch (Amount3) { case 1: symbol = Convert.ToString((char)(32+(Rank*15)+File)); g.DrawString(symbol, F11, B1, selection.Left+((File+1)*32), selection.Top+((Rank+1)*2*16)); break; case 2: symbol = Convert.ToString((char)(32+(Rank*15)+File)); g.DrawString(symbol, F12, B1, selection.Left+((File+1)*32), selection.Top+((Rank+1)*2*16)); break; case 3: symbol = Convert.ToString((char)(32+(Rank*15)+File)); g.DrawString(symbol, F13, B1, selection.Left+((File+1)*32), selection.Top+((Rank+1)*2*16)); break; case 4: symbol = Convert.ToString((char)(32+(Rank*15)+File)); g.DrawString(symbol, F14, B1, selection.Left+((File+1)*32), selection.Top+((Rank+1)*2*16)); break; } If you looked hard enough, you should have found that there are two sections of code that look just like that, almost. So pay certain attention when finding the code. Alright, after the block that looks like this: case 4: symbol = Convert.ToString((char)(32+(Rank*15)+File)); g.DrawString(symbol, F14, B1, selection.Left+((File+1)*32), selection.Top+((Rank+1)*2*16)); break; We are going to add a very similar set of lines. Go ahead and create a new line beneath the above code, and type this: case 5: symbol = Convert.ToString((char)(32+(Rank*15)+File)); g.DrawString(symbol, F15, B1, selection.Left+((File+1)*32), selection.Top+((Rank+1)*2*16)); break; Easy, right? Although, let it be known that if you are adding multiple fonts you must type that in multiple times. Simply change the word case 5: to the next number in the series. Do the same for the word F5 Alright, you are finished! From here, I am going to presume you know how to build the code. If not, I recommend reading this article. If you need any more assistance, please post it in this thread. Happy modding! Quote Link to comment Share on other sites More sharing options...
Simon Brown Posted July 14, 2008 Share Posted July 14, 2008 I do have one question for EER, why not allow the user to select a font from those installed? Quote Link to comment Share on other sites More sharing options...
Mike Ryan Posted July 14, 2008 Author Share Posted July 14, 2008 That is not available through IndirectUI. Quote Link to comment Share on other sites More sharing options...
Simon Brown Posted July 14, 2008 Share Posted July 14, 2008 That is not available through IndirectUI. Can items not be added dynamically? Also, why not simply port it to the traditional system? Quote Link to comment Share on other sites More sharing options...
Simon Brown Posted July 14, 2008 Share Posted July 14, 2008 Given the source was provided I am currently adding this feature to the source which I will give to EER. Quote Link to comment Share on other sites More sharing options...
Mike Ryan Posted July 14, 2008 Author Share Posted July 14, 2008 So I can request this tutorial be locked and trash the upgraded code i was working on? Quote Link to comment Share on other sites More sharing options...
Mike Ryan Posted July 14, 2008 Author Share Posted July 14, 2008 And besides, this was made for symbols. Not every font in the whole wide world Quote Link to comment Share on other sites More sharing options...
I Like Pi Posted July 14, 2008 Share Posted July 14, 2008 About IndirectUI: You can use a textbox (which codelab supports) or a combobox populated with a list of fonts at runtime (which codelab does not support). Tip for reducing duplicate code: You may want to consider putting all the fonts in a string[] (lets call it fonts) and then use fonts[Amount3] instead of all the switches. Quote Link to comment Share on other sites More sharing options...
Simon Brown Posted July 14, 2008 Share Posted July 14, 2008 I have already adapted the source and removed some switches, which I have offered to EER and am waiting for a response. Quote Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted July 14, 2008 Share Posted July 14, 2008 I have already adapted the source and removed some switches, which I have offered to EER and am waiting for a response. I've just pm'd you a reply. Please publish what you've developed Simon, its looks great! Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
Rick Brewster Posted July 14, 2008 Share Posted July 14, 2008 That is not available through IndirectUI. Sure it is. Use the StaticListChoiceProperty. string[] fontNames = ... you figure this part out ...; StaticListChoiceProperty fontNamesProperty = new StaticListChoiceProperty(YourPropertyName, fontNames); Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
Simon Brown Posted July 14, 2008 Share Posted July 14, 2008 I have already adapted the source and removed some switches, which I have offered to EER and am waiting for a response. I've just pm'd you a reply. Please publish what you've developed Simon, its looks great! Changes Emailed Quote Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted July 15, 2008 Share Posted July 15, 2008 That is not available through IndirectUI. Sure it is. Use the StaticListChoiceProperty. string[] fontNames = ... you figure this part out ...; StaticListChoiceProperty fontNamesProperty = new StaticListChoiceProperty(YourPropertyName, fontNames); I do all my development in CodeLab, and I've never seen a combobox used codelab source files before. I guess my question is....., can this be done in CodeLab? Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
Rick Brewster Posted July 15, 2008 Share Posted July 15, 2008 I don't think CodeLab supports the StaticListChoiceProperty (combobox/radiobutton). Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
BoltBait Posted July 15, 2008 Share Posted July 15, 2008 CodeLab does not currently support a drop-down or radio button control. I will be adding the drop-down next release. Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.