Author Topic: Super/Subscript values from .net xml  (Read 2611 times)

0 Members and 1 Guest are viewing this topic.

DJBalli

  • Mosquito
  • Posts: 1
Super/Subscript values from .net xml
« on: September 27, 2023, 02:58:55 AM »
This block of code checks from XML input for Super/Subscript values.

1. AddFormatting this method is used to add font formatting to the fragment values.
But this method doesn't get applied to string secondfragmentFormattedText only to the firstfragmentFormattedText.
2. Super/SubScript is working without using this method AddFormatting, but we need the font formatting to every fragment values.
3. Below code is applying only color,bold to the both first and second text, but not getting sub/superscript property.
4. So, I want to apply font formatting to both of the text and second text should get superscript/subscript.

Code - C#: [Select]
  1. if (textBlockSuperscript || textBlockSubscript)
  2. {
  3.     //Sample
  4.     ////////string firstFragmentText = "abc";
  5.     ////////string secondFragmentText = "123";
  6.     ////////string format1 = ApplyFormattingSubScriptSuperScript(firstFragmentText, "Arial", 3, true, true, true, true, true, true, "left", 10);
  7.     ////////string format2 = ApplyFormattingSubScriptSuperScript(secondFragmentText, "Arial", 3, true, true, true, true, true, true, "left", 10);
  8.  
  9.     //////////firstFragmentText = "{\\A1;" + firstFragmentText + "\\H0.7x;\\S" + secondFragmentText + "^";
  10.     ////////firstFragmentText = "{\\A1;" + format1 + "\\H0.7x;\\S" + secondFragmentText + "^";
  11.     ////////mtContents = firstFragmentText;
  12.  
  13.  
  14.     if (fragment.Count() >= 2)
  15.     {
  16.         var firstFragment = fragment[0];
  17.         var secondFragment = fragment[1];
  18.  
  19.         bool firstfragmentBold, firstfragmentItalic, firstfragmentUnderline, firstfragmentStrikethrough, firstfragmentSuperscript, firstfragmentSubscript, firstfragmentUpperCase, firstfragmentLowerCase;
  20.         string firstfragmentFont, firstfragmentText;
  21.         int firstcolor;
  22.  
  23.         Global.GetFragmentDetails(xdoc, firstFragment, out firstfragmentBold, out firstfragmentItalic, out firstfragmentFont, out firstfragmentUnderline, out firstcolor, out firstfragmentText, out firstfragmentStrikethrough, out firstfragmentSuperscript, out firstfragmentSubscript, out firstfragmentUpperCase, out firstfragmentLowerCase);
  24.  
  25.         bool secondfragmentBold, secondfragmentItalic, secondfragmentUnderline, secondfragmentStrikethrough, secondfragmentSuperscript, secondfragmentSubscript, secondfragmentUpperCase, secondfragmentLowerCase;
  26.         string secondfragmentFont, secondfragmentText;
  27.         int secondcolor;
  28.  
  29.         Global.GetFragmentDetails(xdoc, secondFragment, out secondfragmentBold, out secondfragmentItalic, out secondfragmentFont, out secondfragmentUnderline, out secondcolor, out secondfragmentText, out secondfragmentStrikethrough, out secondfragmentSuperscript, out secondfragmentSubscript, out secondfragmentUpperCase, out secondfragmentLowerCase);
  30.  
  31.         string firstfragmentFormattedText = Global.ApplyFormattingSubScriptSuperScript(firstfragmentText, firstfragmentFont, textBlockAlignment, firstfragmentSubscript, firstfragmentSuperscript, firstcolor, firstfragmentBold, firstfragmentItalic, firstfragmentStrikethrough, firstfragmentUnderline, textBlockHeight);
  32.         string secondfragmentFormattedText = Global.ApplyFormattingSubScriptSuperScript(secondfragmentText, secondfragmentFont, textBlockAlignment, secondfragmentSubscript, secondfragmentSuperscript, secondcolor, secondfragmentBold, secondfragmentItalic, secondfragmentStrikethrough, secondfragmentUnderline, textBlockHeight);
  33.  
  34.         if (textBlockSuperscript)
  35.         {
  36.             firstfragmentText = "{\\A1;" + firstfragmentFormattedText + "\\H0.7x;\\S" + secondfragmentFormattedText + "^";
  37.  
  38.             mtContents = firstfragmentText;
  39.         }
  40.         else if (textBlockSubscript)
  41.         {
  42.             firstfragmentText = "{\\A1;" + firstfragmentFormattedText + "\\H0.7x;\\S^" + secondfragmentFormattedText;
  43.             mtContents = firstfragmentText;
  44.         }
  45.     }
  46. }
  47.  
  48. public static string ApplyFormattingSubScriptSuperScript(string content, string font, string alignment, bool isSubscript, bool isSuperscript, int color, bool isBold, bool isItalic, bool isStrikethrough, bool isUnderline, double textHeight)
  49. {
  50.     string formattedContent = AddFormatting(content, font, color, isBold, isItalic, isStrikethrough, isUnderline, alignment);
  51.  
  52.     return formattedContent;
  53. }
  54.  
  55. public static string AddFormatting(string content, string font, int color, bool isBold, bool isItalic, bool isStrikethrough, bool isUnderline, string alignment)
  56. {
  57.     string formattedContent = content;
  58.  
  59.     if (!string.IsNullOrEmpty(font))
  60.         formattedContent = "{\\f" + font + ";" + formattedContent + "}";
  61.  
  62.     //formattedContent = GetAlignment(alignment, formattedContent);
  63.  
  64.     formattedContent = "{\\C" + color + ";" + formattedContent;
  65.  
  66.     if (isBold)
  67.         formattedContent = "{\\B" + formattedContent + "}";
  68.  
  69.     if (isItalic)
  70.         formattedContent = "{\\I" + formattedContent + "}";
  71.  
  72.     if (isStrikethrough)
  73.         formattedContent = "{\\K" + formattedContent + "}";
  74.  
  75.     if (isUnderline)
  76.         formattedContent = "{\\L" + formattedContent + "}";
  77.  
  78.     return formattedContent;
  79. }
  80.  
  81.  

edit:kdub:: formatted & C#code tags added
« Last Edit: September 27, 2023, 05:16:57 AM by kdub_nz »

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2166
  • class keyThumper<T>:ILazy<T>
Re: Super/Subscript values from .net xml
« Reply #1 on: September 27, 2023, 05:26:45 AM »
@DJBalli

Refer to your mirror post on t5, and the reply by Gilles

https://forums.autodesk.com/t5/net/super-subscript-values/m-p/12269086#M78826

added:
Please learn how to post formatted code to the forums you post assistance requests to.

Regards,
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.