Git Product home page Git Product logo

Comments (13)

davidgohel avatar davidgohel commented on June 8, 2024

Hi

I can't reproduce the issue, sorry. All is OK for me

from officer.

hafen avatar hafen commented on June 8, 2024

I'm experiencing the same issue. For me, it has to do with a non-default pptx template. I don't know what it is about the template that causes this, but the default for adding text using officer is bold (note that when adding a text box directly in powerpoint, however, the default text is not bold) and it is not overridden by using fp_text(bold = FALSE).

from officer.

hafen avatar hafen commented on June 8, 2024

For a little more detail, I have a slide for which the master is just a header and no content. I first add a header to the slide. Then I add a custom element to the slide using ph_empty_at(). If I leave the content of this blank and view the result, it shows that it is a placeholder for another header. Using ph_add_par(... type = "body") on this element doesn't make it act like a body element which doesn't have bold styling, it stays bold even when I explicitly use fp_text(bold = FALSE). Is there any way to make ph_empty_at() be able to specify which type of element it is creating?

from officer.

hafen avatar hafen commented on June 8, 2024

Oh sorry I think it looks like you just fixed this here: #47

from officer.

davidgohel avatar davidgohel commented on June 8, 2024

This is the code I used to test this case:

library(magrittr)
library(officer)

style_txt <- fp_text(font.size = 16, bold = FALSE,
                     font.family = "Calibri", vertical.align = 'baseline')
my_pres <- read_pptx() %>%
  add_slide(layout = "Title and Content", master = "Office Theme") %>%
  ph_empty(type = "body") %>% 
  ph_add_par() %>% 
  ph_add_text(str = "Title - text", type = "body", style = style_txt) %>%
  add_slide(layout = "Title and Content", master = "Office Theme") %>%
  ph_empty_at(left = 1, top = 2, width = 5, height = 4, template_type = "body") %>% 
  ph_add_par() %>% 
  ph_add_text(str = "Title - text", type = "body", style = style_txt)
print(my_pres, target = "test.pptx")

Could you show me the code you are using?

from officer.

hafen avatar hafen commented on June 8, 2024

Yes sorry I meant to say by my last comment that your latest commit fixed this for me. The ability to specify template_type = "body" solves the problem, as before then it was using the title template. Although it would seem like fp_text() should be able to override the boldness of a title template as well.

from officer.

davidgohel avatar davidgohel commented on June 8, 2024

Although it would seem like fp_text() should be able to override the boldness of a title template as well.

Really sorry, I don't understand. The following code works for me, I made the text red and bold:

library(magrittr)
library(officer)

style_txt <- fp_text(font.size = 16, bold = TRUE, color = "red",
                     font.family = "Calibri", vertical.align = 'baseline')
my_pres <- read_pptx() %>%
  add_slide(layout = "Title and Content", master = "Office Theme") %>%
  ph_empty(type = "body") %>% 
  ph_add_par() %>% 
  ph_add_text(str = "Title - text", type = "body", style = style_txt) %>%
  add_slide(layout = "Title and Content", master = "Office Theme") %>%
  ph_empty_at(left = 1, top = 2, width = 5, height = 4, template_type = "title") %>% 
  ph_add_par() %>% 
  ph_add_text(str = "Title - text", type = "title", style = style_txt)
print(my_pres, target = "test.pptx") 

Don't you get the same result?
test.pptx

from officer.

JW900 avatar JW900 commented on June 8, 2024

I saw this chain is old, but I'm still having the same issue. Here is the code that should reproduce the issue. Use any template that uses bold face font in the title placeholder. When I add a new text placeholder, all of the other control works except for "bold=False".

my_pres <- read_pptx("test_template.pptx") 
mytmp <- layout_summary(my_pres)[[2]][1]

style_txt <- fp_text(font.size = 16, bold = FALSE, color = "red",
                     font.family = "Calibri")

my_pres <- my_pres %>%
        add_slide(layout = "Title and Content", master = mytmp) %>%
        ph_with("Bold as expected", location=ph_location_type("title")) %>%
        ph_empty(location = ph_location(left = 1, top = 2, width = 5, height = 2, label = "new")) %>% 
        ph_add_par(ph_label = "new") %>% 
        ph_add_text(str = "shouldn't be bold", ph_label = "new", style = style_txt) 
 
print(my_pres, target = "test.pptx")

Is there anything wrong with the code? Thanks.

from officer.

imamanatee avatar imamanatee commented on June 8, 2024

I don't think I ever got that bold function to disable properly...

from officer.

davidgohel avatar davidgohel commented on June 8, 2024

I think it is solved now:

library(officer)
library(magrittr)

my_pres <- read_pptx() 

style_bold <- fp_text(font.size = 16, bold = TRUE, color = "red",
                     font.family = "Calibri")
style_notbold <- fp_text(font.size = 16, bold = FALSE, color = "red",
                     font.family = "Calibri")

my_pres <- my_pres %>%
  add_slide(layout = "Title and Content") %>%
  ph_with(empty_content(), location = ph_location(left = 1, top = 2, width = 5, height = 2, newlabel = "new") ) %>% 
  ph_add_par(ph_label = "new") %>% 
  ph_add_text(str = "should be bold", ph_label = "new", style = style_bold) %>% 
  ph_add_par(ph_label = "new") %>% 
  ph_add_text(str = "shouldn't be bold", ph_label = "new", style = style_notbold)

print(my_pres, target = "test.pptx")

Capture d’écran 2020-01-05 à 18 35 59

test.pptx

from officer.

matyas-k avatar matyas-k commented on June 8, 2024

Hi, I came across the same issue (working with officer 0.3.8). Your example above is working perfectly, but if I use my own template (attached), both text are bold and I can't figure out how to input no bold text without creating predefined placeholder in the template.

I figured out that this behaviour is emerging when the titles in presentation template are set to bold (same issue as JW900 was reporting earlier in this thread)

`my_pres <- read_pptx("PATH_TO_MY_TEMPLATE_PPTX")
layout_summary(my_pres)

style_bold <- fp_text(font.size = 16, bold = TRUE, color = "red",
font.family = "Calibri")
style_notbold <- fp_text(font.size = 16, bold = FALSE, color = "red",
font.family = "Calibri")

my_pres <- my_pres %>%
add_slide(layout = "title and graph", master = "My template") %>%
ph_with(empty_content(), location = ph_location(left = 1, top = 2, width = 5, height = 2, newlabel = "new") ) %>%
ph_add_par(ph_label = "new") %>%
ph_add_text(str = "should be bold", ph_label = "new", style = style_bold) %>%
ph_add_par(ph_label = "new") %>%
ph_add_text(str = "shouldn't be bold", ph_label = "new", style = style_notbold)

print(my_pres, target = "test.pptx")`

test_template.pptx

from officer.

ameshkoff avatar ameshkoff commented on June 8, 2024

I have the same issue as @matyas-k. If the title in the layout is set to bold, the bold setting for any text paragraphs could not be overwritten, all texts are bold.

I have investigated the issue a bit. Looks like bold = FALSE option doesn't have any effect on a:rPr node of the paragraph and the bold setting is inherited from the a:defRPr node from the layout. For example:

(slide)

    <p:txBody>
      <a:bodyPr/>
      <a:lstStyle/>
      <a:p>
        <a:pPr algn="l" marL="0" marR="0">
          <a:spcBef>
            <a:spcPts val="0"/>
          </a:spcBef>
          <a:spcAft>
            <a:spcPts val="0"/>
          </a:spcAft>
          <a:buNone/>
        </a:pPr>
        <a:r>
          <a:rPr cap="none" sz="1000">
            <a:solidFill>
              <a:srgbClr val="070707">
                <a:alpha val="100000"/>
              </a:srgbClr>
            </a:solidFill>
            <a:latin typeface="Calibri"/>
            <a:cs typeface="Calibri"/>
          </a:rPr>
          <a:t>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</a:t>
        </a:r>
      </a:p>
    </p:txBody>

(layout)

    <p:txBody>
      <a:bodyPr wrap="square" anchor="t">
        <a:spAutoFit/>
      </a:bodyPr>
      <a:lstStyle>
        <a:lvl1pPr>
          <a:lnSpc>
            <a:spcPct val="80000"/>
          </a:lnSpc>
          <a:defRPr sz="2400" b="1">
            <a:solidFill>
              <a:schemeClr val="accent6"/>
            </a:solidFill>
          </a:defRPr>
        </a:lvl1pPr>
      </a:lstStyle>
      <a:p>
        <a:r>
          <a:rPr dirty="0"/>
          <a:t>Title</a:t>
        </a:r>
      </a:p>
    </p:txBody>

The result is b="1" is inherited from the layout. The strange thing is this property is always inherited from the title (the first text chunk in the layout?) and not following text paragraphs, but I'm not good in OOXML so let it be.

But when bold = TRUE the b="1" attribute is added to the a:rPr node and all is fine. May be it is possible to force set b="0" when bold = FALSE?

(slide)

<p:txBody> ... <a:r> <a:rPr cap="none" sz="1000" b="1"> ... </a:rPr> <a:t>Lorem ipsum ...</a:t> </a:r> </a:p> </p:txBody>

from officer.

github-actions avatar github-actions commented on June 8, 2024

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

from officer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.