😎 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.

116 lines
5.2KB

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