none
Font change in PPT Comment for empty bullet content RRS feed

  • Question

  • Hi

    From my WPF application, I am generating PPT using open XML.

    below is the attached XML

    <t:RadDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:t="clr-namespace:Telerik.Windows.Documents.Model;assembly=Telerik.Windows.Documents" xmlns:s="clr-namespace:Telerik.Windows.Documents.Model.Styles;assembly=Telerik.Windows.Documents" xmlns:r="clr-namespace:Telerik.Windows.Documents.Model.Revisions;assembly=Telerik.Windows.Documents" xmlns:n="clr-namespace:Telerik.Windows.Documents.Model.Notes;assembly=Telerik.Windows.Documents" xmlns:th="clr-namespace:Telerik.Windows.Documents.Model.Themes;assembly=Telerik.Windows.Documents" version="1.4" LayoutMode="Flow" LineSpacing="1" LineSpacingType="Auto" ParagraphDefaultSpacingAfter="0" ParagraphDefaultSpacingBefore="0" SelectedBibliographicStyleName="\APA.XSL" StyleName="defaultDocumentStyle">
      <t:RadDocument.Captions>
        <t:CaptionDefinition IsDefault="True" IsLinkedToHeading="False" Label="Figure" LinkedHeadingLevel="0" NumberingFormat="Arabic" SeparatorType="Hyphen" />
        <t:CaptionDefinition IsDefault="True" IsLinkedToHeading="False" Label="Table" LinkedHeadingLevel="0" NumberingFormat="Arabic" SeparatorType="Hyphen" />
      </t:RadDocument.Captions>
      <t:RadDocument.Lists>
        <t:ListSerializationData ID="2" StyleID="1" />
      </t:RadDocument.Lists>
      <t:RadDocument.ListStyles>
        <t:ListStyle ID="1" IsDefault="True">
          <t:ListLevelStyle HangingIndent="24" Indent="48" LevelText="" NumberingFormat="Bullet" StartingIndex="1">
            <t:ListLevelStyle.SpanStyle>
              <s:SpanProperties FontFamily="Symbol" FontWeight="Normal" />
            </t:ListLevelStyle.SpanStyle>
          </t:ListLevelStyle>
          <t:ListLevelStyle HangingIndent="24" Indent="72" LevelText="o" NumberingFormat="Bullet" StartingIndex="1">
            <t:ListLevelStyle.SpanStyle>
              <s:SpanProperties FontFamily="Courier New" FontWeight="Normal" />
            </t:ListLevelStyle.SpanStyle>
          </t:ListLevelStyle>
          <t:ListLevelStyle HangingIndent="24" Indent="96" LevelText="" NumberingFormat="Bullet" StartingIndex="1">
            <t:ListLevelStyle.SpanStyle>
              <s:SpanProperties FontFamily="Wingdings" FontWeight="Normal" />
            </t:ListLevelStyle.SpanStyle>
          </t:ListLevelStyle>
          <t:ListLevelStyle HangingIndent="24" Indent="120" LevelText="" NumberingFormat="Bullet" StartingIndex="1">
            <t:ListLevelStyle.SpanStyle>
              <s:SpanProperties FontFamily="Symbol" FontWeight="Normal" />
            </t:ListLevelStyle.SpanStyle>
          </t:ListLevelStyle>
          <t:ListLevelStyle HangingIndent="24" Indent="144" LevelText="o" NumberingFormat="Bullet" StartingIndex="1">
            <t:ListLevelStyle.SpanStyle>
              <s:SpanProperties FontFamily="Courier New" FontWeight="Normal" />
            </t:ListLevelStyle.SpanStyle>
          </t:ListLevelStyle>
          <t:ListLevelStyle HangingIndent="24" Indent="168" LevelText="" NumberingFormat="Bullet" StartingIndex="1">
            <t:ListLevelStyle.SpanStyle>
              <s:SpanProperties FontFamily="Wingdings" FontWeight="Normal" />
            </t:ListLevelStyle.SpanStyle>
          </t:ListLevelStyle>
          <t:ListLevelStyle HangingIndent="24" Indent="192" LevelText="" NumberingFormat="Bullet" StartingIndex="1">
            <t:ListLevelStyle.SpanStyle>
              <s:SpanProperties FontFamily="Symbol" FontWeight="Normal" />
            </t:ListLevelStyle.SpanStyle>
          </t:ListLevelStyle>
          <t:ListLevelStyle HangingIndent="24" Indent="216" LevelText="o" NumberingFormat="Bullet" StartingIndex="1">
            <t:ListLevelStyle.SpanStyle>
              <s:SpanProperties FontFamily="Courier New" FontWeight="Normal" />
            </t:ListLevelStyle.SpanStyle>
          </t:ListLevelStyle>
          <t:ListLevelStyle HangingIndent="24" Indent="240" LevelText="" NumberingFormat="Bullet" StartingIndex="1">
            <t:ListLevelStyle.SpanStyle>
              <s:SpanProperties FontFamily="Wingdings" FontWeight="Normal" />
            </t:ListLevelStyle.SpanStyle>
          </t:ListLevelStyle>
        </t:ListStyle>
      </t:RadDocument.ListStyles>
      <t:RadDocument.ProtectionSettings>
        <t:DocumentProtectionSettings EnableDocumentProtection="False" Enforce="False" HashingAlgorithm="None" HashingSpinCount="0" ProtectionMode="ReadOnly" />
      </t:RadDocument.ProtectionSettings>
      <t:RadDocument.Styles>
        <s:StyleDefinition DisplayName="Document Default Style" IsCustom="False" IsDefault="False" IsPrimary="True" Name="defaultDocumentStyle" Type="Default">
          <s:StyleDefinition.ParagraphStyle>
            <s:ParagraphProperties LineSpacing="1" />
          </s:StyleDefinition.ParagraphStyle>
          <s:StyleDefinition.SpanStyle>
            <s:SpanProperties FontFamily="Georgia (Body)" FontSize="11" FontStyle="Normal" FontWeight="Normal" />
          </s:StyleDefinition.SpanStyle>
        </s:StyleDefinition>
        <s:StyleDefinition DisplayName="Normal" IsCustom="False" IsDefault="True" IsPrimary="True" Name="Normal" Type="Paragraph" UIPriority="0" />
        <s:StyleDefinition DisplayName="Table Normal" IsCustom="False" IsDefault="True" IsPrimary="False" Name="TableNormal" Type="Table" UIPriority="59">
          <s:StyleDefinition.TableStyle>
            <s:TableProperties CellPadding="5,0,5,0">
              <s:TableProperties.TableLook>
                <t:TableLook />
              </s:TableProperties.TableLook>
            </s:TableProperties>
          </s:StyleDefinition.TableStyle>
        </s:StyleDefinition>
      </t:RadDocument.Styles>
      <t:Section>
        <t:Paragraph FontSize="11" LeftIndent="0" LineSpacing="1" ListId="2" SpacingAfter="0" SpacingBefore="0">
          <t:Paragraph.ParagraphSymbolPropertiesStyle>
            <s:SpanProperties FontSize="11" />
          </t:Paragraph.ParagraphSymbolPropertiesStyle>
        </t:Paragraph>
        <t:Paragraph FontSize="11" LeftIndent="0" LineSpacing="1" ListId="2" RightIndent="0" SpacingAfter="0" SpacingBefore="0">
          <t:Paragraph.ParagraphSymbolPropertiesStyle>
            <s:SpanProperties FontSize="11" />
          </t:Paragraph.ParagraphSymbolPropertiesStyle>
        </t:Paragraph>
        <t:Paragraph FontSize="11" LeftIndent="0" LineSpacing="1" ListId="2" RightIndent="0" SpacingAfter="0" SpacingBefore="0">
          <t:Paragraph.ParagraphSymbolPropertiesStyle>
            <s:SpanProperties FontSize="11" />
          </t:Paragraph.ParagraphSymbolPropertiesStyle>
        </t:Paragraph>
        <t:Paragraph FontSize="11" LeftIndent="0" LineSpacing="1" ListId="2" RightIndent="0" SpacingAfter="0" SpacingBefore="0">
          <t:Paragraph.ParagraphSymbolPropertiesStyle>
            <s:SpanProperties FontSize="11" />
          </t:Paragraph.ParagraphSymbolPropertiesStyle>
        </t:Paragraph>
        <t:Paragraph FontSize="11" LeftIndent="0" LineSpacing="1" ListId="2" RightIndent="0" SpacingAfter="0" SpacingBefore="0">
          <t:Paragraph.ParagraphSymbolPropertiesStyle>
            <s:SpanProperties FlowDirection="LeftToRight" FontSize="11" />
          </t:Paragraph.ParagraphSymbolPropertiesStyle>
          <t:Span FontSize="11" Text="Test  840" />
        </t:Paragraph>
        <t:Paragraph FontSize="11" LeftIndent="0" LineSpacing="1" ListId="2" RightIndent="0" SpacingAfter="0" SpacingBefore="0">
          <t:Paragraph.ParagraphSymbolPropertiesStyle>
            <s:SpanProperties FontSize="11" />
          </t:Paragraph.ParagraphSymbolPropertiesStyle>
        </t:Paragraph>
        <t:Paragraph FontSize="11" LeftIndent="0" LineSpacing="1" ListId="2" RightIndent="0" SpacingAfter="0" SpacingBefore="0">
          <t:Paragraph.ParagraphSymbolPropertiesStyle>
            <s:SpanProperties FlowDirection="LeftToRight" FontSize="11" />
          </t:Paragraph.ParagraphSymbolPropertiesStyle>
          <t:Span FontSize="11" Text="Test420" />
        </t:Paragraph>
      </t:Section>
    </t:RadDocument>

    We are using following code to generate Comment Textbox

      StyledTextContent styledTextContent = new StyledTextContent() { xamlData = this.textValue, textColor = this.textColor, fontSize = this.fontSize };
                    styledTextContent.render();
    
                    text.Append(styledTextContent.pptParagraphs);

    Render code of StyledTextContent as below

    public override void render()
            {
                // render produces a list for openxml paragraphs
                //List<OpenXmlElement> pptParagraphs = new List<OpenXmlElement>();
    
                if (this.xamlData != null && this.xamlData.Length > 0)
                {
                    RadDocument document = new XamlFormatProvider().Import(xamlData);
                    MemoryStream memStrm = new MemoryStream();
                    new DocxFormatProvider().Export(document, memStrm);
                    // open the docx in memory and get the paragraphs, bullets, runs, etc
                    using (Package docxPackage = Package.Open(memStrm, FileMode.Open, FileAccess.Read))
                    using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(docxPackage))
                    {
                        // docx paragraphs
                        var paragraphs = wordDoc.MainDocumentPart.Document.Body.Elements<W.Paragraph>();
    
                        // iterate docx paragraphs and create Powerpoint paragraphs with same data
                        foreach (var docxPara in paragraphs)
                        {
                            // make a new pptx paragraph for each docx paragraph
                            var docxProps = docxPara.ParagraphProperties;
                            bool hasBulletPoint = false;
                            int indentLevel = 0;
    
                            if (docxProps.NumberingProperties != null)
                            {// bullet point
                                hasBulletPoint = true;
                                //indentLevel = docxProps.NumberingProperties.NumberingLevelReference.Val;
                            }
    
                            /////////////////////////////////////////////////////
                            // Setup pptx Paragraph properties
                            //
                            //
    
                            // Define indentation for bullet points. XAML and Docx indents are defined differently from pptx
                            // Indentation from XAML examples seems to be defined by left indentation twips
                            // 1440 tiwps per inch
                            //pptx indent is defined by indent level so we have to convert twips to indent level
                            //					twip	inch	indent
                            // no indent =		0		0		0
                            // first indent =	360		.25		1
                            // second indent =	720		.50		2
                            // third =			1080	.75		3
                            //
    
                            if (docxProps.Elements<W.Indentation>().Count() > 0)
                            {
                                int indentAmount = 0;
                                var indentOb = docxProps.Elements<W.Indentation>().FirstOrDefault();
                                if (indentOb != null)
                                {
                                    Int32.TryParse(indentOb.Left, out indentAmount);
                                }
    
                                indentLevel = indentAmount / 360; // this has to change if they change the bullet indent amount in the UI
                            }
    
                            D.BulletFont bulletFont = null;
                            D.CharacterBullet bulletChar = null;
    
                            if (hasBulletPoint == true)
                            {
                                bulletFont = new D.BulletFont() { Typeface = "Arial", PitchFamily = 34, CharacterSet = 0 };
                                //bulletChar =  new D.CharacterBullet() { Char = bulletChars[indentLevel % 3]};
                                bulletChar = new D.CharacterBullet() { Char = bulletChars[0] }; // ppt only does a single kind of bullet
                            }
    
                            // the default indent and margin are too big for the AD powerpoint. they like tight spacing
                            int leftMargin = baseBulletMargin;
    
                            var paragraphProps = new D.ParagraphProperties() { Alignment = this.textAlignment, LeftMargin = leftMargin, Indent = hasBulletPoint ? bulletIndent : 0, Level = indentLevel };
    
                            paragraphProps.Append(new D.LineSpacing(new D.SpacingPercent() { Val = lineSpacing }));
                            paragraphProps.Append(new D.SpaceBefore(new D.SpacingPoints() { Val = spaceBefore }));
                            paragraphProps.Append(new D.SpaceAfter(new D.SpacingPoints() { Val = spaceAfter }));
    
                            if (bulletFont != null)
                            {
                                paragraphProps.Append(bulletFont);
                                paragraphProps.Append(bulletChar);
                            }
    
                            // add the paragraph properties
                            var pptParagraph = new D.Paragraph(paragraphProps);
    
                            /////////////////////////////////////////////////////////////
                            // Build pptx Runs. Paragraphs are made of runs.
                            // A separate run is needed for each style change.
                            // Unneeded run breaks sometimes come from the editor but are copied into the PPT
                            //
                            var docxRuns = docxPara.Elements<W.Run>();
    
                            foreach (var docxRun in docxRuns)
                            {	// we dont care about font since it is fixed to Georgia 9 (specified in the master slide)
                                // both docxRun.RunProperties.Italic and docxRun.RunProperties.Bold properties dont seem to work so we have to check the child elements
                                bool isItalic = false;
                               
                                // DISABLE ITALIC: // Comment the below code to enable italic in code
                                if (docxRun.RunProperties != null && docxRun.RunProperties.Elements<W.Italic>().Count() > 0) // these may or may not be present with a true/false value
                                {
                                    isItalic = docxRun.RunProperties.Elements<W.Italic>().First().Val.Value;
                                }
    
                                bool isBold = false;
                                if (docxRun.RunProperties != null && docxRun.RunProperties.Elements<W.Bold>().Count() > 0)
                                {
                                    isBold = docxRun.RunProperties.Elements<W.Bold>().First().Val.Value;
                                }
    
                                // only supporting solid underline.
                                // if we need more, have to map from docx to pptx underline -- the Enum int values are not the same (of course).
                                D.TextUnderlineValues pptxUnderline = D.TextUnderlineValues.None;
                                // dont care about the underline type -- only supporting solid at the moment
    
                                // DISABLE UNDERLINE: // Comment the below code to enable underline in code
                                bool isUnderline = false;
                                if (docxRun.RunProperties != null && docxRun.RunProperties.Elements<W.Underline>().Count() > 0)
                                {
                                    isUnderline = docxRun.RunProperties.Elements<W.Underline>().First().Val.Value != W.UnderlineValues.None;
    
                                    // Only set the Undeline Property in PPTX if it is set in the XAML
                                    if (isUnderline)
                                        pptxUnderline = D.TextUnderlineValues.Single;
                                }
    
                                int fontSize = defaultFontSize;
                                if (this.fontSize != 0)
                                {
                                    fontSize = this.fontSize;
                                }
    
                                D.RunProperties pptxRunProps = new D.RunProperties() { FontSize = fontSize, Underline = pptxUnderline, Bold = isBold, Italic = isItalic };
                                pptxRunProps.SetAttribute(new OpenXmlAttribute("", "smtClean", "", "0"));
    
                                D.SolidFill fill = new D.SolidFill(new D.RgbColorModelHex() { Val = this.textColor.ToRGBHex() });
                                pptxRunProps.InsertAt(fill, 0);
    
                                string textVal = "";
                                var txt = docxRun.Elements<W.Text>().FirstOrDefault();
                                if (txt == null)
                                {
                                    //textVal = "ERROR";
                                    textVal = "";
                                }
                                else
                                {
                                    textVal = txt.Text;
                                }
    
                                D.Text pptxText = new D.Text(textVal);
                                // add each run
                                pptParagraph.Append(new D.Run(pptxRunProps, pptxText));
                            }
    
                            // add each paragraph to our list
                            pptParagraphs.Add(pptParagraph);
                        }
                    }
                }
            }


     See the comment box: yellow highlights part, font size of the nontext bullet is 18 and rest text in same comment box is small than 18 

    Please let me know, why it is happing and how to solve this issue?

    Thanks

    Ankur R.


    • Edited by ankurastogi Tuesday, February 20, 2018 2:49 PM
    Monday, February 19, 2018 2:02 PM

Answers

  • Hi Ankur,

    >> yellow highlights part, font size of the nontext bullet is 18 and rest text in same comment box is small than 18 

    Do you mean the font size is not right according the actual result?

    If you change it to other value and reset it ot 18 manually, will it show correctly? I would suggest you

    1. Create two documents with one is original file and one is the target file;

    2. Use Open XML SDK 2.5 productivity Tool for Microsoft Office

    3. Click the Compare Files, generate the code, and then you could get the code what you want

    For more information about Open XML SDK 2.5 productivity Tool for Microsoft Office, you could refer the link below:

    # Open XML SDK 2.5 for Microsoft Office

    https://www.microsoft.com/en-us/download/details.aspx?id=30425

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ankurastogi Monday, March 5, 2018 7:20 AM
    Wednesday, February 28, 2018 7:24 AM

All replies

  • Hello ankurastogi,

    To be honestly, I'm not familiarly with WPF and I would suggest you share a simply project file so we could try to use it to reproduce your issue.

    For sharing file, you could share it via Cloud Storage, such as One Drive, and then put link address here.

    Thanks for understanding.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 22, 2018 6:20 AM
  • Hi Ankur,

    >> yellow highlights part, font size of the nontext bullet is 18 and rest text in same comment box is small than 18 

    Do you mean the font size is not right according the actual result?

    If you change it to other value and reset it ot 18 manually, will it show correctly? I would suggest you

    1. Create two documents with one is original file and one is the target file;

    2. Use Open XML SDK 2.5 productivity Tool for Microsoft Office

    3. Click the Compare Files, generate the code, and then you could get the code what you want

    For more information about Open XML SDK 2.5 productivity Tool for Microsoft Office, you could refer the link below:

    # Open XML SDK 2.5 for Microsoft Office

    https://www.microsoft.com/en-us/download/details.aspx?id=30425

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ankurastogi Monday, March 5, 2018 7:20 AM
    Wednesday, February 28, 2018 7:24 AM