😎 Give your xaringan slides some style
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

130 lines
6.5KB

  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 text_size_h1 h1 Header Text Size, defaults to 55px
  25. #' @param text_size_h2 h2 Header Text Size, defaults to 45px
  26. #' @param text_size_h3 h3 Header Text Size, defaults to 35px
  27. #' @param text_size_slide_number Slide Number Text Size, defaults to 20px
  28. #' @param text_size_code_inline Inline Code Text Size, defaults to 20px
  29. #' @param text_size_code Code Text Size, defaults to 18px
  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. #' @param outfile Customized xaringan CSS output file name
  45. #' @template write_xaringan_theme
  46. #' @export
  47. write_xaringan_theme <- function(
  48. text_color = "#000",
  49. header_color = "#000",
  50. background_color = "#FFF",
  51. link_color = "rgb(249, 38, 114)",
  52. text_bold_color = NA,
  53. text_slide_number_color = inverse_background_color,
  54. code_highlight_color = "rgba(255,255,0,0.5)",
  55. code_inline_color = "#000",
  56. code_inline_background_color = NA,
  57. inverse_background_color = "#272822",
  58. inverse_text_color = "#d6d6d6",
  59. inverse_text_shadow = FALSE,
  60. inverse_header_color = "#f3f3f3",
  61. title_slide_text_color = inverse_text_color,
  62. title_slide_background_color = inverse_background_color,
  63. title_slide_background_image = NA,
  64. left_column_subtle_color = "#777",
  65. left_column_selected_color = "#000",
  66. blockquote_left_color = "lightgray",
  67. table_border_color = "#666",
  68. table_row_border_color = "#ddd",
  69. table_row_even_background_color = "#eee",
  70. text_size = "20px",
  71. text_size_h1 = "55px",
  72. text_size_h2 = "45px",
  73. text_size_h3 = "35px",
  74. text_size_slide_number = "20px",
  75. text_size_code_inline = "20px",
  76. text_size_code = "18px",
  77. text_font_google = NULL,
  78. text_font_family = "'Droid Serif'",
  79. text_font_weight = "normal",
  80. text_font_url = "https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic",
  81. text_font_family_fallback = "'Palatino Linotype', 'Book Antiqua', Palatino, 'Microsoft YaHei', 'Songti SC'",
  82. text_font_base = "serif",
  83. header_font_google = NULL,
  84. header_font_family = "'Yanone Kaffeesatz'",
  85. header_font_weight = "normal",
  86. header_font_url = "https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz",
  87. code_font_google = NULL,
  88. code_font_family = "'Source Code Pro'",
  89. code_font_url = "https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700",
  90. code_font_family_fallback = "'Lucida Console', Monaco",
  91. outfile = "xaringan-themed.css"
  92. ) {
  93. # Make sure font names are wrapped in quotes if they have spaces
  94. f_args <- names(formals(sys.function()))
  95. for (var in f_args[grepl("font_family$", f_args)]) {
  96. eval(parse(text = paste0(
  97. var, "<-quote_elements_w_spaces(", var, ")"
  98. )))
  99. }
  100. # Use font_..._google args to overwrite font args
  101. for (var in f_args[grepl("font_google$", f_args)]) {
  102. gf <- eval(parse(text = var))
  103. if (is.null(gf)) next
  104. if (!inherits(gf, "google_font")) stop(
  105. "`", var, "` must be set using `google_font()`."
  106. )
  107. group <- stringr::str_split(var, "_")[[1]][1]
  108. if (group == "text") {
  109. text_font_family <- gf$family
  110. text_font_weight <- gf$weights %||% "normal"
  111. text_font_weight <- substr(text_font_weight, 1, regexpr(",", text_font_weight)[1]-1)
  112. text_font_url <- gf$url
  113. } else {
  114. for (thing in c("family", "url")) {
  115. eval(parse(text = paste0(
  116. group, "_font_", thing, " <- gf$", thing
  117. )))
  118. }
  119. }
  120. }
  121. tf <- system.file("resources", "template.css", package = "xaringanthemer")
  122. template <- readLines(tf, warn = FALSE)
  123. template <- paste(template, collapse = "\n")
  124. x <- glue::glue(template, .open = "{{", .close = "}}")
  125. cat(x, file = outfile)
  126. outfile
  127. }