😎 Give your xaringan slides some style
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

136 lines
6.8KB

  1. #' @param text_color Text Color, defaults to #000
  2. #' @param header_color Header Color, defaults to #000
  3. #' @param background_color Slide Background Color, defaults to #FFF
  4. #' @param link_color Link Color, defaults to rgb(249, 38, 114)
  5. #' @param text_bold_color Bold Text Color, defaults to NA
  6. #' @param text_slide_number_color Slide Number Color, defaults to `inverse_background_color`
  7. #' @param code_highlight_color Code Line Highlight, defaults to rgba(255,255,0,0.5)
  8. #' @param code_inline_color Inline Code Color, defaults to #000
  9. #' @param code_inline_background_color Inline Code Background Color, defaults to NA
  10. #' @param inverse_background_color Inverse Background Color, defaults to #272822
  11. #' @param inverse_text_color Inverse Text Color, defaults to #d6d6d6
  12. #' @param inverse_text_shadow Enables Shadow on text of inverse slides, defaults to `FALSE`
  13. #' @param inverse_header_color Inverse Header Color, defaults to #f3f3f3
  14. #' @param title_slide_text_color Title Slide Text Color, defaults to `inverse_text_color`
  15. #' @param title_slide_background_color Title Slide Background Color, defaults to `inverse_background_color`
  16. #' @param title_slide_background_image Title Slide Background Image URL, defaults to NA
  17. #' @param left_column_subtle_color Left Column Text (not last), defaults to #777
  18. #' @param left_column_selected_color Left Column Current Selection, defaults to #000
  19. #' @param blockquote_left_color Blockquote Left Border Color, defaults to lightgray
  20. #' @param table_border_color Table top/bottom border, defaults to #666
  21. #' @param table_row_border_color Table row inner bottom border, defaults to #ddd
  22. #' @param table_row_even_background_color Table Even Row Background Color, defaults to #eee
  23. #' @param text_size Slide Body Text Size, defaults to 20px
  24. #' @param header_h1_font_size h1 Header Text Size, defaults to 55px
  25. #' @param header_h2_font_size h2 Header Text Size, defaults to 45px
  26. #' @param header_h3_font_size h3 Header Text Size, defaults to 35px
  27. #' @param text_slide_number_font_size Slide Number Text Size, defaults to 20px
  28. #' @param code_inline_font_size Inline Code Text Size, defaults to 1em
  29. #' @param code_font_size Code Text Size, defaults to 0.9em
  30. #' @param text_font_google Use `google_font()` to specify body font, defaults to `NULL`
  31. #' @param text_font_family Body Text Font Family, defaults to 'Droid Serif'
  32. #' @param text_font_weight Body Text Font Weight, defaults to normal
  33. #' @param text_font_url Body Text Font URL(s), defaults to https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic
  34. #' @param text_font_family_fallback Body Text Font Fallbacks, defaults to 'Palatino Linotype', 'Book Antiqua', Palatino, 'Microsoft YaHei', 'Songti SC'
  35. #' @param text_font_base Body Text Base Font (Total Failure Fallback), defaults to serif
  36. #' @param header_font_google Use `google_font()` to specify header font, defaults to `NULL`
  37. #' @param header_font_family Header Font Family, defaults to 'Yanone Kaffeesatz'
  38. #' @param header_font_weight Header Font Weight, defaults to normal
  39. #' @param header_font_url Header Font URL, defaults to https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz
  40. #' @param code_font_google Use `google_font()` to specify code font, defaults to `NULL`
  41. #' @param code_font_family Code Font Family, defaults to 'Source Code Pro'
  42. #' @param code_font_url Code Font URL, defaults to https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700
  43. #' @param code_font_family_fallback Code Font Fallback, defaults to 'Lucida Console', Monaco
  44. #' @template extra_css
  45. #' @param outfile Customized xaringan CSS output file name, default is "xaringan-themer.css"
  46. #' @template write_xaringan_theme
  47. #' @export
  48. write_xaringan_theme <- function(
  49. text_color = "#000",
  50. header_color = "#000",
  51. background_color = "#FFF",
  52. link_color = "rgb(249, 38, 114)",
  53. text_bold_color = NA,
  54. text_slide_number_color = inverse_background_color,
  55. code_highlight_color = "rgba(255,255,0,0.5)",
  56. code_inline_color = "#000",
  57. code_inline_background_color = NA,
  58. inverse_background_color = "#272822",
  59. inverse_text_color = "#d6d6d6",
  60. inverse_text_shadow = FALSE,
  61. inverse_header_color = "#f3f3f3",
  62. title_slide_text_color = inverse_text_color,
  63. title_slide_background_color = inverse_background_color,
  64. title_slide_background_image = NA,
  65. left_column_subtle_color = "#777",
  66. left_column_selected_color = "#000",
  67. blockquote_left_color = "lightgray",
  68. table_border_color = "#666",
  69. table_row_border_color = "#ddd",
  70. table_row_even_background_color = "#eee",
  71. text_size = "20px",
  72. header_h1_font_size = "55px",
  73. header_h2_font_size = "45px",
  74. header_h3_font_size = "35px",
  75. text_slide_number_font_size = "20px",
  76. code_inline_font_size = "1em",
  77. code_font_size = "0.9em",
  78. text_font_google = NULL,
  79. text_font_family = "'Droid Serif'",
  80. text_font_weight = "normal",
  81. text_font_url = "https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic",
  82. text_font_family_fallback = "'Palatino Linotype', 'Book Antiqua', Palatino, 'Microsoft YaHei', 'Songti SC'",
  83. text_font_base = "serif",
  84. header_font_google = NULL,
  85. header_font_family = "'Yanone Kaffeesatz'",
  86. header_font_weight = "normal",
  87. header_font_url = "https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz",
  88. code_font_google = NULL,
  89. code_font_family = "'Source Code Pro'",
  90. code_font_url = "https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700",
  91. code_font_family_fallback = "'Lucida Console', Monaco",
  92. extra_css = NULL,
  93. extra_fonts = NULL,
  94. outfile = "xaringan-themer.css"
  95. ) {
  96. # Make sure font names are wrapped in quotes if they have spaces
  97. f_args <- names(formals(sys.function()))
  98. for (var in f_args[grepl("font_family$", f_args)]) {
  99. eval(parse(text = paste0(
  100. var, "<-quote_elements_w_spaces(", var, ")"
  101. )))
  102. }
  103. # Use font_..._google args to overwrite font args
  104. for (var in f_args[grepl("font_google$", f_args)]) {
  105. gf <- eval(parse(text = var))
  106. if (is.null(gf)) next
  107. if (!inherits(gf, "google_font")) stop(
  108. "`", var, "` must be set using `google_font()`."
  109. )
  110. group <- stringr::str_split(var, "_")[[1]][1]
  111. if (group == "text") {
  112. text_font_family <- gf$family
  113. text_font_weight <- gf$weights %||% "normal"
  114. text_font_weight <- substr(text_font_weight, 1, regexpr(",", text_font_weight)[1]-1)
  115. text_font_url <- gf$url
  116. } else {
  117. for (thing in c("family", "url")) {
  118. eval(parse(text = paste0(
  119. group, "_font_", thing, " <- gf$", thing
  120. )))
  121. }
  122. }
  123. }
  124. extra_font_imports <- if (is.null(extra_fonts)) "" else list2fonts(extra_fonts)
  125. tf <- system.file("resources", "template.css", package = "xaringanthemer")
  126. template <- readLines(tf, warn = FALSE)
  127. template <- paste(template, collapse = "\n")
  128. x <- glue::glue(template, .open = "{{", .close = "}}")
  129. cat(x, file = outfile)
  130. if (!is.null(extra_css)) write_extra_css(extra_css, outfile)
  131. outfile
  132. }