😎 Give your xaringan slides some style
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

116 lines
5.9KB

  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_font_google Use `google_font()` to specify body font, defaults to `NULL`
  24. #' @param text_font_family Body Text Font Family, defaults to 'Droid Serif'
  25. #' @param text_font_weight Body Text Font Weight, defaults to normal
  26. #' @param text_font_url Body Text Font URL(s), defaults to https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic
  27. #' @param text_font_family_fallback Body Text Font Fallbacks, defaults to 'Palatino Linotype', 'Book Antiqua', Palatino, 'Microsoft YaHei', 'Songti SC'
  28. #' @param text_font_base Body Text Base Font (Total Failure Fallback), defaults to serif
  29. #' @param header_font_google Use `google_font()` to specify header font, defaults to `NULL`
  30. #' @param header_font_family Header Font Family, defaults to 'Yanone Kaffeesatz'
  31. #' @param header_font_weight Header Font Weight, defaults to normal
  32. #' @param header_font_url Header Font URL, defaults to https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz
  33. #' @param code_font_google Use `google_font()` to specify code font, defaults to `NULL`
  34. #' @param code_font_family Code Font Family, defaults to 'Source Code Pro'
  35. #' @param code_font_url Code Font URL, defaults to https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700
  36. #' @param code_font_family_fallback Code Font Fallback, defaults to 'Lucida Console', Monaco
  37. #' @param outfile Customized xaringan CSS output file name
  38. #' @template write_xaringan_theme
  39. #' @export
  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 = inverse_background_color,
  47. code_highlight_color = "rgba(255,255,0,0.5)",
  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 = inverse_text_color,
  55. title_slide_background_color = inverse_background_color,
  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. }